diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index 641b6b14c..47a08af83 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -356,14 +356,6 @@ void InitGLRMapinfoData() glset.map_notexturefill = opt->notexturefill; glset.skyrotatevector = opt->skyrotatevector; glset.skyrotatevector2 = opt->skyrotatevector2; - if (!gl.hasGLSL()) - { - // light modes 2 and 8 require shaders - if (glset.map_lightmode == 2 || glset.map_lightmode == 8) - { - glset.map_lightmode = 3; - } - } } else { diff --git a/src/gl/dynlights/gl_dynlight1.cpp b/src/gl/dynlights/gl_dynlight1.cpp index f13f24ab6..42053e8a5 100644 --- a/src/gl/dynlights/gl_dynlight1.cpp +++ b/src/gl/dynlights/gl_dynlight1.cpp @@ -72,11 +72,7 @@ CUSTOM_CVAR (Bool, gl_dynlight_shader, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | { if (self) { - if (!gl.hasGLSL()) - { - self = false; - } - else if (gl.maxuniforms < 1024 && !(gl.flags & RFL_SHADER_STORAGE_BUFFER)) + if (gl.maxuniforms < 1024 && !(gl.flags & RFL_SHADER_STORAGE_BUFFER)) { self = false; } diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index fc248b2cc..0ee9c563f 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -744,17 +744,9 @@ void gl_RenderModel(GLSprite * spr) if(smf->flags & MDL_INHERITACTORPITCH) pitch += float(static_cast(spr->actor->pitch >> 16) / (1 << 13) * 45 + static_cast(spr->actor->pitch & 0x0000FFFF) / (1 << 29) * 45); if(smf->flags & MDL_INHERITACTORROLL) roll += float(static_cast(spr->actor->roll >> 16) / (1 << 13) * 45 + static_cast(spr->actor->roll & 0x0000FFFF) / (1 << 29) * 45); - if (!gl.hasGLSL()) - { - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - } - else - { - glActiveTexture(GL_TEXTURE7); // Hijack the otherwise unused seventh texture matrix for the model to world transformation. - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - } + glActiveTexture(GL_TEXTURE7); // Hijack the otherwise unused seventh texture matrix for the model to world transformation. + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); // Model space => World space glTranslatef(spr->x, spr->z, spr->y ); @@ -786,7 +778,7 @@ void gl_RenderModel(GLSprite * spr) glRotatef(smf->pitchoffset, 0, 0, 1); glRotatef(-smf->rolloffset, 1, 0, 0); - if (gl.hasGLSL()) glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE0); #if 0 if (gl_light_models) @@ -805,19 +797,11 @@ void gl_RenderModel(GLSprite * spr) gl_RenderFrameModels( smf, spr->actor->state, spr->actor->tics, RUNTIME_TYPE(spr->actor), NULL, translation ); - if (!gl.hasGLSL()) - { - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - } - else - { - glActiveTexture(GL_TEXTURE7); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glActiveTexture(GL_TEXTURE0); - glMatrixMode(GL_MODELVIEW); - } + glActiveTexture(GL_TEXTURE7); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glActiveTexture(GL_TEXTURE0); + glMatrixMode(GL_MODELVIEW); glDepthFunc(GL_LESS); if (!( spr->actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] )) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 60ecf70be..29013f280 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -109,7 +109,6 @@ CUSTOM_CVAR(Int,gl_fogmode,1,CVAR_ARCHIVE|CVAR_NOINITCALL) { if (self>2) self=2; if (self<0) self=0; - if (self == 2 && !gl.hasGLSL()) self = 1; } CUSTOM_CVAR(Int, gl_lightmode, 3 ,CVAR_ARCHIVE|CVAR_NOINITCALL) @@ -117,7 +116,6 @@ CUSTOM_CVAR(Int, gl_lightmode, 3 ,CVAR_ARCHIVE|CVAR_NOINITCALL) int newself = self; if (newself > 4) newself=8; // use 8 for software lighting to avoid conflicts with the bit mask if (newself < 0) newself=0; - if ((newself == 2 || newself == 8) && !gl.hasGLSL()) newself = 3; if (self != newself) self = newself; glset.lightmode = newself; } diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index a51e1fc37..97cf6d10f 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -216,13 +216,9 @@ void FGLRenderer::FlushTextures() bool FGLRenderer::StartOffscreen() { - if (gl.flags & RFL_FRAMEBUFFER) - { - if (mFBID == 0) glGenFramebuffers(1, &mFBID); - glBindFramebuffer(GL_FRAMEBUFFER, mFBID); - return true; - } - return false; + if (mFBID == 0) glGenFramebuffers(1, &mFBID); + glBindFramebuffer(GL_FRAMEBUFFER, mFBID); + return true; } //=========================================================================== @@ -233,10 +229,7 @@ bool FGLRenderer::StartOffscreen() void FGLRenderer::EndOffscreen() { - if (gl.flags & RFL_FRAMEBUFFER) - { - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } + glBindFramebuffer(GL_FRAMEBUFFER, 0); } //=========================================================================== diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 673c201b8..8ce695cbc 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -94,22 +94,10 @@ void FRenderState::Reset() // //========================================================================== -int FRenderState::SetupShader(int &shaderindex, float warptime) +void FRenderState::SetupShader(int &shaderindex, float warptime) { - int softwarewarp = 0; - - if (gl.hasGLSL()) - { - mEffectState = shaderindex; - if (shaderindex > 0) GLRenderer->mShaderManager->SetWarpSpeed(shaderindex, warptime); - } - else - { - softwarewarp = shaderindex > 0 && shaderindex < 3? shaderindex : 0; - shaderindex = 0; - } - - return softwarewarp; + mEffectState = shaderindex; + if (shaderindex > 0) GLRenderer->mShaderManager->SetWarpSpeed(shaderindex, warptime); } @@ -121,124 +109,119 @@ int FRenderState::SetupShader(int &shaderindex, float warptime) bool FRenderState::ApplyShader() { - - if (gl.hasGLSL()) + FShader *activeShader; + if (mSpecialEffect > EFF_NONE) { - FShader *activeShader; - if (mSpecialEffect > EFF_NONE) + activeShader = GLRenderer->mShaderManager->BindEffect(mSpecialEffect); + } + else + { + activeShader = GLRenderer->mShaderManager->Get(mTextureEnabled ? mEffectState : 4); + activeShader->Bind(); + } + + int fogset = 0; + //glColor4fv(mColor.vec); + if (mFogEnabled) + { + if ((mFogColor & 0xffffff) == 0) { - activeShader = GLRenderer->mShaderManager->BindEffect(mSpecialEffect); + fogset = gl_fogmode; } else { - activeShader = GLRenderer->mShaderManager->Get(mTextureEnabled ? mEffectState : 4); - activeShader->Bind(); + fogset = -gl_fogmode; } + } - int fogset = 0; - //glColor4fv(mColor.vec); - if (mFogEnabled) + glColor4fv(mColor.vec); + + activeShader->muDesaturation.Set(mDesaturation / 255.f); + activeShader->muFogEnabled.Set(fogset); + activeShader->muTextureMode.Set(mTextureMode); + activeShader->muCameraPos.Set(mCameraPos.vec); + activeShader->muLightParms.Set(mLightParms); + activeShader->muFogColor.Set(mFogColor); + activeShader->muObjectColor.Set(mObjectColor); + activeShader->muDynLightColor.Set(mDynColor); + + if (mGlowEnabled) + { + activeShader->muGlowTopColor.Set(mGlowTop.vec); + activeShader->muGlowBottomColor.Set(mGlowBottom.vec); + activeShader->muGlowTopPlane.Set(mGlowTopPlane.vec); + activeShader->muGlowBottomPlane.Set(mGlowBottomPlane.vec); + activeShader->currentglowstate = 1; + } + else if (activeShader->currentglowstate) + { + // if glowing is on, disable it. + static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; + activeShader->muGlowTopColor.Set(nulvec); + activeShader->muGlowBottomColor.Set(nulvec); + activeShader->muGlowTopPlane.Set(nulvec); + activeShader->muGlowBottomPlane.Set(nulvec); + activeShader->currentglowstate = 0; + } + + if (mLightEnabled) + { + activeShader->muLightRange.Set(mNumLights); + glUniform4fv(activeShader->lights_index, mNumLights[3], mLightData); + } + else + { + static const int nulint[] = { 0, 0, 0, 0 }; + activeShader->muLightRange.Set(nulint); + } + + if (mColormapState != activeShader->currentfixedcolormap) + { + float r, g, b; + activeShader->currentfixedcolormap = mColormapState; + if (mColormapState == CM_DEFAULT) { - if ((mFogColor & 0xffffff) == 0) + activeShader->muFixedColormap.Set(0); + } + else if (mColormapState < CM_MAXCOLORMAP) + { + FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP]; + float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0], + scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f }; + + activeShader->muFixedColormap.Set(1); + activeShader->muColormapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f); + activeShader->muColormapRange.Set(m); + } + else if (mColormapState == CM_FOGLAYER) + { + activeShader->muFixedColormap.Set(3); + } + else if (mColormapState == CM_LITE) + { + if (gl_enhanced_nightvision) { - fogset = gl_fogmode; + r = 0.375f, g = 1.0f, b = 0.375f; } else { - fogset = -gl_fogmode; + r = g = b = 1.f; } + activeShader->muFixedColormap.Set(2); + activeShader->muColormapStart.Set(r, g, b, 1.f); } - - glColor4fv(mColor.vec); - - activeShader->muDesaturation.Set(mDesaturation / 255.f); - activeShader->muFogEnabled.Set(fogset); - activeShader->muTextureMode.Set(mTextureMode); - activeShader->muCameraPos.Set(mCameraPos.vec); - activeShader->muLightParms.Set(mLightParms); - activeShader->muFogColor.Set(mFogColor); - activeShader->muObjectColor.Set(mObjectColor); - activeShader->muDynLightColor.Set(mDynColor); - - if (mGlowEnabled) + else if (mColormapState >= CM_TORCH) { - activeShader->muGlowTopColor.Set(mGlowTop.vec); - activeShader->muGlowBottomColor.Set(mGlowBottom.vec); - activeShader->muGlowTopPlane.Set(mGlowTopPlane.vec); - activeShader->muGlowBottomPlane.Set(mGlowBottomPlane.vec); - activeShader->currentglowstate = 1; + int flicker = mColormapState - CM_TORCH; + r = (0.8f + (7 - flicker) / 70.0f); + if (r > 1.0f) r = 1.0f; + b = g = r; + if (gl_enhanced_nightvision) b = g * 0.75f; + activeShader->muFixedColormap.Set(2); + activeShader->muColormapStart.Set(r, g, b, 1.f); } - else if (activeShader->currentglowstate) - { - // if glowing is on, disable it. - static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; - activeShader->muGlowTopColor.Set(nulvec); - activeShader->muGlowBottomColor.Set(nulvec); - activeShader->muGlowTopPlane.Set(nulvec); - activeShader->muGlowBottomPlane.Set(nulvec); - activeShader->currentglowstate = 0; - } - - if (mLightEnabled) - { - activeShader->muLightRange.Set(mNumLights); - glUniform4fv(activeShader->lights_index, mNumLights[3], mLightData); - } - else - { - static const int nulint[] = { 0, 0, 0, 0 }; - activeShader->muLightRange.Set(nulint); - } - - if (mColormapState != activeShader->currentfixedcolormap) - { - float r, g, b; - activeShader->currentfixedcolormap = mColormapState; - if (mColormapState == CM_DEFAULT) - { - activeShader->muFixedColormap.Set(0); - } - else if (mColormapState < CM_MAXCOLORMAP) - { - FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP]; - float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0], - scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f }; - - activeShader->muFixedColormap.Set(1); - activeShader->muColormapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f); - activeShader->muColormapRange.Set(m); - } - else if (mColormapState == CM_FOGLAYER) - { - activeShader->muFixedColormap.Set(3); - } - else if (mColormapState == CM_LITE) - { - if (gl_enhanced_nightvision) - { - r = 0.375f, g = 1.0f, b = 0.375f; - } - else - { - r = g = b = 1.f; - } - activeShader->muFixedColormap.Set(2); - activeShader->muColormapStart.Set(r, g, b, 1.f); - } - else if (mColormapState >= CM_TORCH) - { - int flicker = mColormapState - CM_TORCH; - r = (0.8f + (7 - flicker) / 70.0f); - if (r > 1.0f) r = 1.0f; - b = g = r; - if (gl_enhanced_nightvision) b = g * 0.75f; - activeShader->muFixedColormap.Set(2); - activeShader->muColormapStart.Set(r, g, b, 1.f); - } - } - return true; } - return false; + return true; } @@ -248,7 +231,7 @@ bool FRenderState::ApplyShader() // //========================================================================== -void FRenderState::Apply(bool forcenoshader) +void FRenderState::Apply() { if (!gl_direct_state_change) { @@ -283,78 +266,6 @@ void FRenderState::Apply(bool forcenoshader) else mVertexBuffer->BindVBO(); mCurrentVertexBuffer = mVertexBuffer; } - if (forcenoshader || !ApplyShader()) - { - //if (mColor.vec[0] >= 0.f) glColor4fv(mColor.vec); - - GLRenderer->mShaderManager->SetActiveShader(NULL); - if (mTextureMode != ffTextureMode) - { - gl_SetTextureMode((ffTextureMode = mTextureMode)); - } - if (mTextureEnabled != ffTextureEnabled) - { - if ((ffTextureEnabled = mTextureEnabled)) glEnable(GL_TEXTURE_2D); - else glDisable(GL_TEXTURE_2D); - } - if (mFogEnabled != ffFogEnabled) - { - if ((ffFogEnabled = mFogEnabled)) - { - glEnable(GL_FOG); - } - else glDisable(GL_FOG); - } - if (mFogEnabled) - { - if (ffFogColor != mFogColor) - { - ffFogColor = mFogColor; - GLfloat FogColor[4]={mFogColor.r/255.0f,mFogColor.g/255.0f,mFogColor.b/255.0f,0.0f}; - glFogfv(GL_FOG_COLOR, FogColor); - } - if (ffFogDensity != mLightParms[2]) - { - const float LOG2E = 1.442692f; // = 1/log(2) - glFogf(GL_FOG_DENSITY, -mLightParms[2] / LOG2E); - ffFogDensity = mLightParms[2]; - } - } - if (mSpecialEffect != ffSpecialEffect) - { - switch (ffSpecialEffect) - { - case EFF_SPHEREMAP: - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_S); - - default: - break; - } - switch (mSpecialEffect) - { - case EFF_SPHEREMAP: - // Use sphere mapping for this - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_S); - glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); - glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); - break; - - default: - break; - } - ffSpecialEffect = mSpecialEffect; - } - // Now compose the final color for this... - float realcolor[4]; - realcolor[0] = clamp((mColor.vec[0] + mDynColor.r / 255.f), 0.f, 1.f) * (mObjectColor.r / 255.f); - realcolor[1] = clamp((mColor.vec[1] + mDynColor.g / 255.f), 0.f, 1.f) * (mObjectColor.g / 255.f); - realcolor[2] = clamp((mColor.vec[2] + mDynColor.b / 255.f), 0.f, 1.f) * (mObjectColor.b / 255.f); - realcolor[3] = mColor.vec[3] * (mObjectColor.a / 255.f); - glColor4fv(realcolor); - - } - + ApplyShader(); } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 8bcedcac7..c3ca1e273 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -92,8 +92,8 @@ public: void Reset(); - int SetupShader(int &shaderindex, float warptime); - void Apply(bool forcenoshader = false); + void SetupShader(int &shaderindex, float warptime); + void Apply(); void SetVertexBuffer(FVertexBuffer *vb) { diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 56d2bd8d6..7e327ab9c 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -501,7 +501,7 @@ inline void GLFlat::PutFlat(bool fog) else foggy = false; list = list_indices[light][masked][foggy]; - if (list == GLDL_LIGHT && gltexture->tex->gl_info.Brightmap && gl.hasGLSL()) list = GLDL_LIGHTBRIGHT; + if (list == GLDL_LIGHT && gltexture->tex->gl_info.Brightmap) list = GLDL_LIGHTBRIGHT; gl_drawinfo->drawlists[list].AddFlat (this); } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index b1bf9e343..4868d07bd 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -287,12 +287,10 @@ void FGLRenderer::SetProjection(float fov, float ratio, float fovratio) void FGLRenderer::SetViewMatrix(bool mirror, bool planemirror) { - if (gl.hasGLSL()) - { - glActiveTexture(GL_TEXTURE7); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - } + glActiveTexture(GL_TEXTURE7); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glActiveTexture(GL_TEXTURE0); glMatrixMode(GL_TEXTURE); glLoadIdentity(); @@ -725,69 +723,6 @@ void FGLRenderer::DrawBlend(sector_t * viewsector) V_AddBlend(blendv.r / 255.f, blendv.g / 255.f, blendv.b / 255.f, blendv.a / 255.0f, blend); } } - else if (!gl.hasGLSL()) - { - float r, g, b; - bool inverse = false; - const float BLACK_THRESH = 0.05f; - const float WHITE_THRESH = 0.95f; - - // for various reasons (performance and keeping the lighting code clean) - // we no longer do colormapped textures on pre GL 3.0 hardware and instead do - // just a fullscreen overlay to emulate the inverse invulnerability effect or similar fullscreen blends. - if (gl_fixedcolormap >= (DWORD)CM_FIRSTSPECIALCOLORMAP && gl_fixedcolormap < (DWORD)CM_MAXCOLORMAP) - { - FSpecialColormap *scm = &SpecialColormaps[gl_fixedcolormap - CM_FIRSTSPECIALCOLORMAP]; - - if (scm->ColorizeEnd[0] < BLACK_THRESH && scm->ColorizeEnd[1] < BLACK_THRESH && scm->ColorizeEnd[2] < BLACK_THRESH) - { - r = scm->ColorizeStart[0]; - g = scm->ColorizeStart[1]; - b = scm->ColorizeStart[2]; - inverse = true; - } - else - { - r = scm->ColorizeEnd[0]; - g = scm->ColorizeEnd[1]; - b = scm->ColorizeEnd[2]; - } - } - else if (gl_enhanced_nightvision) - { - if (gl_fixedcolormap == CM_LITE) - { - r = 0.375f; - g = 1.0f; - b = 0.375f; - } - else if (gl_fixedcolormap >= CM_TORCH) - { - int flicker = gl_fixedcolormap - CM_TORCH; - r = (0.8f + (7 - flicker) / 70.0f); - if (r > 1.0f) r = 1.0f; - g = r; - b = g * 0.75f; - } - else r = g = b = 1.f; - } - else r = g = b = 1.f; - - if (inverse) - { - gl_RenderState.BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - gl_RenderState.ResetColor(); - FillScreen(); - } - - if (r < WHITE_THRESH || g < WHITE_THRESH || b < WHITE_THRESH) - { - gl_RenderState.BlendFunc(GL_DST_COLOR, GL_ZERO); - gl_RenderState.SetColor(r, g, b, 1.0f); - FillScreen(); - } - } - // This mostly duplicates the code in shared_sbar.cpp // When I was writing this the original was called too late so that I @@ -1245,15 +1180,7 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, in gl_fixedcolormap=CM_DEFAULT; gl_RenderState.SetFixedColormap(CM_DEFAULT); - bool usefb; - - if (gl.flags & RFL_FRAMEBUFFER) - { - usefb = gl_usefb || width > screen->GetWidth() || height > screen->GetHeight(); - } - else usefb = false; - - + bool usefb = gl_usefb || width > screen->GetWidth() || height > screen->GetHeight(); if (!usefb) { glFlush(); diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index d36e5fdba..ad3b1c90b 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -232,8 +232,6 @@ void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode) // The caps only get drawn for the main layer but not for the overlay. if (mode == SKYMODE_MAINLAYER && tex != NULL) { - // if there's no shader we cannot use the default color from the buffer because the object color is part of the preset vertex attribute. - if (!gl.hasGLSL()) glDisableClientState(GL_COLOR_ARRAY); PalEntry pe = tex->tex->GetSkyCapColor(false); gl_RenderState.SetObjectColor(pe); gl_RenderState.EnableTexture(false); @@ -245,7 +243,6 @@ void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode) gl_RenderState.Apply(); RenderRow(GL_TRIANGLE_FAN, rc); gl_RenderState.EnableTexture(true); - if (!gl.hasGLSL()) glEnableClientState(GL_COLOR_ARRAY); } gl_RenderState.SetObjectColor(0xffffffff); gl_RenderState.Apply(); @@ -522,9 +519,7 @@ void GLSkyPortal::DrawContents() gl_RenderState.EnableTexture(false); gl_RenderState.SetObjectColor(FadeColor); gl_RenderState.Apply(); - if (!gl.hasGLSL()) glDisableClientState(GL_COLOR_ARRAY); glDrawArrays(GL_TRIANGLES, 0, 12); - if (!gl.hasGLSL()) glEnableClientState(GL_COLOR_ARRAY); gl_RenderState.EnableTexture(true); } gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 00f2ccada..ab0586f58 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -199,18 +199,9 @@ void GLSprite::Draw(int pass) // non-black fog with subtractive style needs special treatment if (!gl_isBlack(Colormap.FadeColor)) { - if (gl.hasGLSL() && !gl_nolayer) - { - // fog layer only works on modern hardware. - foglayer = true; - // Due to the two-layer approach we need to force an alpha test that lets everything pass - gl_RenderState.AlphaFunc(GL_GREATER, 0); - } - else - { - // this at least partially handles the fog issue - Colormap.FadeColor = Colormap.FadeColor.InverseColor(); - } + foglayer = true; + // Due to the two-layer approach we need to force an alpha test that lets everything pass + gl_RenderState.AlphaFunc(GL_GREATER, 0); } } else RenderStyle.BlendOp = STYLEOP_Fuzz; // subtractive with models is not going to work. @@ -668,7 +659,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector) // allow disabling of the fullbright flag by a brightmap definition // (e.g. to do the gun flashes of Doom's zombies correctly. fullbright = (thing->flags5 & MF5_BRIGHT) || - ((thing->renderflags & RF_FULLBRIGHT) && (!gl.hasGLSL() || !gltexture || !gltexture->tex->gl_info.bBrightmapDisablesFullbright)); + ((thing->renderflags & RF_FULLBRIGHT) && (!gltexture || !gltexture->tex->gl_info.bBrightmapDisablesFullbright)); lightlevel=fullbright? 255 : gl_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? @@ -737,7 +728,7 @@ void GLSprite::Process(AActor* thing,sector_t * sector) RenderStyle.CheckFuzz(); if (RenderStyle.BlendOp == STYLEOP_Fuzz) { - if (gl.hasGLSL() && gl_fuzztype != 0) + if (gl_fuzztype != 0) { // Todo: implement shader selection here RenderStyle = LegacyRenderStyles[STYLE_Translucent]; diff --git a/src/gl/scene/gl_walls.cpp b/src/gl/scene/gl_walls.cpp index 2d6b78fd5..bf9d52066 100644 --- a/src/gl/scene/gl_walls.cpp +++ b/src/gl/scene/gl_walls.cpp @@ -71,7 +71,7 @@ void GLWall::CheckGlowing() { bottomglowcolor[3] = topglowcolor[3] = 0; - if (!gl_isFullbright(Colormap.LightColor, lightlevel) && gl.hasGLSL()) + if (!gl_isFullbright(Colormap.LightColor, lightlevel)) { FTexture *tex = TexMan[topflat]; if (tex != NULL && tex->isGlowing()) @@ -184,7 +184,7 @@ void GLWall::PutWall(bool translucent) list = list_indices[light][masked][!!(flags&GLWF_FOGGY)]; if (list == GLDL_LIGHT) { - if (gltexture->tex->gl_info.Brightmap && gl.hasGLSL()) list = GLDL_LIGHTBRIGHT; + if (gltexture->tex->gl_info.Brightmap) list = GLDL_LIGHTBRIGHT; if (flags & GLWF_GLOW) list = GLDL_LIGHTBRIGHT; } gl_drawinfo->drawlists[list].AddWall(this); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 2879ade62..8e3a4b955 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -291,60 +291,13 @@ void GLWall::RenderFogBoundary() { if (gl_fogmode && gl_fixedcolormap == 0) { - // with shaders this can be done properly - if (gl.hasGLSL()) - { - int rel = rellight + getExtraLight(); - gl_SetFog(lightlevel, rel, &Colormap, false); - gl_RenderState.SetEffect(EFF_FOGBOUNDARY); - gl_RenderState.EnableAlphaTest(false); - RenderWall(RWF_BLANK); - gl_RenderState.EnableAlphaTest(true); - gl_RenderState.SetEffect(EFF_NONE); - } - else - { - // If we use the fixed function pipeline (GL 2.x) - // some approximation is needed. This won't look as good - // as the shader version but it's an acceptable compromise. - float fogdensity=gl_GetFogDensity(lightlevel, Colormap.FadeColor); - - float xcamera=FIXED2FLOAT(viewx); - float ycamera=FIXED2FLOAT(viewy); - - float dist1=Dist2(xcamera,ycamera, glseg.x1,glseg.y1); - float dist2=Dist2(xcamera,ycamera, glseg.x2,glseg.y2); - - - // these values were determined by trial and error and are scale dependent! - float fogd1=(0.95f-exp(-fogdensity*dist1/62500.f)) * 1.05f; - float fogd2=(0.95f-exp(-fogdensity*dist2/62500.f)) * 1.05f; - - float fc[4]={Colormap.FadeColor.r/255.0f,Colormap.FadeColor.g/255.0f,Colormap.FadeColor.b/255.0f,fogd2}; - - gl_RenderState.EnableTexture(false); - gl_RenderState.EnableFog(false); - gl_RenderState.AlphaFunc(GL_GREATER,0); - glDepthFunc(GL_LEQUAL); - gl_RenderState.SetColor(fc[0], fc[1], fc[2], fogd1); - - // this case is special because it needs to change the color in the middle of the polygon so it cannot use the standard function - // This also needs no splits so it's relatively simple. - gl_RenderState.Apply(); - glBegin(GL_TRIANGLE_FAN); // only used on GL 2.x! - glVertex3f(glseg.x1, zbottom[0], glseg.y1); - glVertex3f(glseg.x1, ztop[0], glseg.y1); - glColor4fv(fc); - glVertex3f(glseg.x2, ztop[1], glseg.y2); - glVertex3f(glseg.x2, zbottom[1], glseg.y2); - glEnd(); - vertexcount += 4; - - glDepthFunc(GL_LESS); - gl_RenderState.EnableFog(true); - gl_RenderState.AlphaFunc(GL_GEQUAL,0.5f); - gl_RenderState.EnableTexture(true); - } + int rel = rellight + getExtraLight(); + gl_SetFog(lightlevel, rel, &Colormap, false); + gl_RenderState.SetEffect(EFF_FOGBOUNDARY); + gl_RenderState.EnableAlphaTest(false); + RenderWall(RWF_BLANK); + gl_RenderState.EnableAlphaTest(true); + gl_RenderState.SetEffect(EFF_NONE); } } diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 8f76b0571..219eaf115 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -208,7 +208,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) { bool disablefullbright = false; FTextureID lump = gl_GetSpriteFrame(psp->sprite, psp->frame, 0, 0, NULL); - if (lump.isValid() && gl.hasGLSL()) + if (lump.isValid()) { FMaterial * tex=FMaterial::ValidateTexture(lump, false); if (tex) @@ -316,7 +316,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) vis.RenderStyle.CheckFuzz(); if (vis.RenderStyle.BlendOp == STYLEOP_Fuzz) { - if (gl.hasGLSL() && gl_fuzztype != 0) + if (gl_fuzztype != 0) { // Todo: implement shader selection here vis.RenderStyle = LegacyRenderStyles[STYLE_Translucent]; diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index b90974222..ca7f8be72 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -68,146 +68,142 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * static char buffer[10000]; FString error; - if (gl.hasGLSL()) + int i_lump = Wads.CheckNumForFullName("shaders/glsl/shaderdefs.i"); + if (i_lump == -1) I_Error("Unable to load 'shaders/glsl/shaderdefs.i'"); + FMemLump i_data = Wads.ReadLump(i_lump); + + int vp_lump = Wads.CheckNumForFullName(vert_prog_lump); + if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump); + FMemLump vp_data = Wads.ReadLump(vp_lump); + + int fp_lump = Wads.CheckNumForFullName(frag_prog_lump); + if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump); + FMemLump fp_data = Wads.ReadLump(fp_lump); + + + +// +// The following code uses GetChars on the strings to get rid of terminating 0 characters. Do not remove or the code may break! +// + + FString vp_comb = "#version 130\n"; + if (gl.glslversion >= 3.3f) vp_comb = "#version 330 compatibility\n"; // I can't shut up the deprecation warnings in GLSL 1.3 so if available use a version with compatibility profile. + // todo when using shader storage buffers, add + // "#version 400 compatibility\n#extension GL_ARB_shader_storage_buffer_object : require\n" instead. + vp_comb << defines << i_data.GetString().GetChars(); + FString fp_comb = vp_comb; + + vp_comb << vp_data.GetString().GetChars() << "\n"; + fp_comb << fp_data.GetString().GetChars() << "\n"; + + if (proc_prog_lump != NULL) { - int i_lump = Wads.CheckNumForFullName("shaders/glsl/shaderdefs.i"); - if (i_lump == -1) I_Error("Unable to load 'shaders/glsl/shaderdefs.i'"); - FMemLump i_data = Wads.ReadLump(i_lump); - - int vp_lump = Wads.CheckNumForFullName(vert_prog_lump); - if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump); - FMemLump vp_data = Wads.ReadLump(vp_lump); - - int fp_lump = Wads.CheckNumForFullName(frag_prog_lump); - if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump); - FMemLump fp_data = Wads.ReadLump(fp_lump); - - - - // - // The following code uses GetChars on the strings to get rid of terminating 0 characters. Do not remove or the code may break! - // - - FString vp_comb = "#version 130\n"; - if (gl.glslversion >= 3.3f) vp_comb = "#version 330 compatibility\n"; // I can't shut up the deprecation warnings in GLSL 1.3 so if available use a version with compatibility profile. - // todo when using shader storage buffers, add - // "#version 400 compatibility\n#extension GL_ARB_shader_storage_buffer_object : require\n" instead. - vp_comb << defines << i_data.GetString().GetChars(); - FString fp_comb = vp_comb; - - vp_comb << vp_data.GetString().GetChars() << "\n"; - fp_comb << fp_data.GetString().GetChars() << "\n"; - - if (proc_prog_lump != NULL) + if (*proc_prog_lump != '#') { - if (*proc_prog_lump != '#') + int pp_lump = Wads.CheckNumForFullName(proc_prog_lump); + if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump); + FMemLump pp_data = Wads.ReadLump(pp_lump); + + if (pp_data.GetString().IndexOf("ProcessTexel") < 0) { - int pp_lump = Wads.CheckNumForFullName(proc_prog_lump); - if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump); - FMemLump pp_data = Wads.ReadLump(pp_lump); + // this looks like an old custom hardware shader. + // We need to replace the ProcessTexel call to make it work. - if (pp_data.GetString().IndexOf("ProcessTexel") < 0) - { - // this looks like an old custom hardware shader. - // We need to replace the ProcessTexel call to make it work. - - fp_comb.Substitute("vec4 frag = ProcessTexel();", "vec4 frag = Process(vec4(1.0));"); - } - fp_comb << pp_data.GetString().GetChars(); - - if (pp_data.GetString().IndexOf("ProcessLight") < 0) - { - int pl_lump = Wads.CheckNumForFullName("shaders/glsl/func_defaultlight.fp"); - if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp"); - FMemLump pl_data = Wads.ReadLump(pl_lump); - fp_comb << "\n" << pl_data.GetString().GetChars(); - } + fp_comb.Substitute("vec4 frag = ProcessTexel();", "vec4 frag = Process(vec4(1.0));"); } - else + fp_comb << pp_data.GetString().GetChars(); + + if (pp_data.GetString().IndexOf("ProcessLight") < 0) { - // Proc_prog_lump is not a lump name but the source itself (from generated shaders) - fp_comb << proc_prog_lump + 1; + int pl_lump = Wads.CheckNumForFullName("shaders/glsl/func_defaultlight.fp"); + if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp"); + FMemLump pl_data = Wads.ReadLump(pl_lump); + fp_comb << "\n" << pl_data.GetString().GetChars(); } } - - hVertProg = glCreateShader(GL_VERTEX_SHADER); - hFragProg = glCreateShader(GL_FRAGMENT_SHADER); - - - int vp_size = (int)vp_comb.Len(); - int fp_size = (int)fp_comb.Len(); - - const char *vp_ptr = vp_comb.GetChars(); - const char *fp_ptr = fp_comb.GetChars(); - - glShaderSource(hVertProg, 1, &vp_ptr, &vp_size); - glShaderSource(hFragProg, 1, &fp_ptr, &fp_size); - - glCompileShader(hVertProg); - glCompileShader(hFragProg); - - hShader = glCreateProgram(); - - glAttachShader(hShader, hVertProg); - glAttachShader(hShader, hFragProg); - - glLinkProgram(hShader); - - glGetShaderInfoLog(hVertProg, 10000, NULL, buffer); - if (*buffer) + else { - error << "Vertex shader:\n" << buffer << "\n"; + // Proc_prog_lump is not a lump name but the source itself (from generated shaders) + fp_comb << proc_prog_lump + 1; } - glGetShaderInfoLog(hFragProg, 10000, NULL, buffer); - if (*buffer) - { - error << "Fragment shader:\n" << buffer << "\n"; - } - - glGetProgramInfoLog(hShader, 10000, NULL, buffer); - if (*buffer) - { - error << "Linking:\n" << buffer << "\n"; - } - int linked; - glGetProgramiv(hShader, GL_LINK_STATUS, &linked); - if (linked == 0) - { - // only print message if there's an error. - I_Error("Init Shader '%s':\n%s\n", name, error.GetChars()); - } - - - muDesaturation.Init(hShader, "uDesaturationFactor"); - muFogEnabled.Init(hShader, "uFogEnabled"); - muTextureMode.Init(hShader, "uTextureMode"); - muCameraPos.Init(hShader, "uCameraPos"); - muLightParms.Init(hShader, "uLightAttr"); - muColormapStart.Init(hShader, "uFixedColormapStart"); - muColormapRange.Init(hShader, "uFixedColormapRange"); - muLightRange.Init(hShader, "uLightRange"); - muFogColor.Init(hShader, "uFogColor"); - muDynLightColor.Init(hShader, "uDynLightColor"); - muObjectColor.Init(hShader, "uObjectColor"); - muGlowBottomColor.Init(hShader, "uGlowBottomColor"); - muGlowTopColor.Init(hShader, "uGlowTopColor"); - muGlowBottomPlane.Init(hShader, "uGlowBottomPlane"); - muGlowTopPlane.Init(hShader, "uGlowTopPlane"); - muFixedColormap.Init(hShader, "uFixedColormap"); - - timer_index = glGetUniformLocation(hShader, "timer"); - lights_index = glGetUniformLocation(hShader, "lights"); - - - glUseProgram(hShader); - - int texture_index = glGetUniformLocation(hShader, "texture2"); - if (texture_index > 0) glUniform1i(texture_index, 1); - - glUseProgram(0); - return !!linked; } - return false; + + hVertProg = glCreateShader(GL_VERTEX_SHADER); + hFragProg = glCreateShader(GL_FRAGMENT_SHADER); + + + int vp_size = (int)vp_comb.Len(); + int fp_size = (int)fp_comb.Len(); + + const char *vp_ptr = vp_comb.GetChars(); + const char *fp_ptr = fp_comb.GetChars(); + + glShaderSource(hVertProg, 1, &vp_ptr, &vp_size); + glShaderSource(hFragProg, 1, &fp_ptr, &fp_size); + + glCompileShader(hVertProg); + glCompileShader(hFragProg); + + hShader = glCreateProgram(); + + glAttachShader(hShader, hVertProg); + glAttachShader(hShader, hFragProg); + + glLinkProgram(hShader); + + glGetShaderInfoLog(hVertProg, 10000, NULL, buffer); + if (*buffer) + { + error << "Vertex shader:\n" << buffer << "\n"; + } + glGetShaderInfoLog(hFragProg, 10000, NULL, buffer); + if (*buffer) + { + error << "Fragment shader:\n" << buffer << "\n"; + } + + glGetProgramInfoLog(hShader, 10000, NULL, buffer); + if (*buffer) + { + error << "Linking:\n" << buffer << "\n"; + } + int linked; + glGetProgramiv(hShader, GL_LINK_STATUS, &linked); + if (linked == 0) + { + // only print message if there's an error. + I_Error("Init Shader '%s':\n%s\n", name, error.GetChars()); + } + + + muDesaturation.Init(hShader, "uDesaturationFactor"); + muFogEnabled.Init(hShader, "uFogEnabled"); + muTextureMode.Init(hShader, "uTextureMode"); + muCameraPos.Init(hShader, "uCameraPos"); + muLightParms.Init(hShader, "uLightAttr"); + muColormapStart.Init(hShader, "uFixedColormapStart"); + muColormapRange.Init(hShader, "uFixedColormapRange"); + muLightRange.Init(hShader, "uLightRange"); + muFogColor.Init(hShader, "uFogColor"); + muDynLightColor.Init(hShader, "uDynLightColor"); + muObjectColor.Init(hShader, "uObjectColor"); + muGlowBottomColor.Init(hShader, "uGlowBottomColor"); + muGlowTopColor.Init(hShader, "uGlowTopColor"); + muGlowBottomPlane.Init(hShader, "uGlowBottomPlane"); + muGlowTopPlane.Init(hShader, "uGlowTopPlane"); + muFixedColormap.Init(hShader, "uFixedColormap"); + + timer_index = glGetUniformLocation(hShader, "timer"); + lights_index = glGetUniformLocation(hShader, "lights"); + + + glUseProgram(hShader); + + int texture_index = glGetUniformLocation(hShader, "texture2"); + if (texture_index > 0) glUniform1i(texture_index, 1); + + glUseProgram(0); + return !!linked; } //========================================================================== @@ -218,12 +214,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * FShader::~FShader() { - if (gl.hasGLSL()) - { - glDeleteProgram(hShader); - glDeleteShader(hVertProg); - glDeleteShader(hFragProg); - } + glDeleteProgram(hShader); + glDeleteShader(hVertProg); + glDeleteShader(hFragProg); } @@ -351,33 +344,30 @@ void FShaderManager::CompileShaders() try { mActiveShader = mEffectShaders[0] = mEffectShaders[1] = NULL; - if (gl.hasGLSL()) + for (int i = 0; defaultshaders[i].ShaderName != NULL; i++) { - for (int i = 0; defaultshaders[i].ShaderName != NULL; i++) - { - FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc); - mTextureEffects.Push(shc); - } + FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc); + mTextureEffects.Push(shc); + } - for (unsigned i = 0; i < usershaders.Size(); i++) - { - FString name = ExtractFileBase(usershaders[i]); - FName sfn = name; + for (unsigned i = 0; i < usershaders.Size(); i++) + { + FString name = ExtractFileBase(usershaders[i]); + FName sfn = name; - FShader *shc = Compile(sfn, usershaders[i]); - mTextureEffects.Push(shc); - } + FShader *shc = Compile(sfn, usershaders[i]); + mTextureEffects.Push(shc); + } - for (int i = 0; i < MAX_EFFECTS; i++) + for (int i = 0; i < MAX_EFFECTS; i++) + { + FShader *eff = new FShader(effectshaders[i].ShaderName); + if (!eff->Load(effectshaders[i].ShaderName, effectshaders[i].vp, effectshaders[i].fp1, + effectshaders[i].fp2, effectshaders[i].defines)) { - FShader *eff = new FShader(effectshaders[i].ShaderName); - if (!eff->Load(effectshaders[i].ShaderName, effectshaders[i].vp, effectshaders[i].fp1, - effectshaders[i].fp2, effectshaders[i].defines)) - { - delete eff; - } - else mEffectShaders[i] = eff; + delete eff; } + else mEffectShaders[i] = eff; } } catch (CRecoverableError &err) @@ -398,22 +388,19 @@ void FShaderManager::CompileShaders() void FShaderManager::Clean() { - if (gl.hasGLSL()) - { - glUseProgram(0); - mActiveShader = NULL; + glUseProgram(0); + mActiveShader = NULL; - for (unsigned int i = 0; i < mTextureEffects.Size(); i++) - { - if (mTextureEffects[i] != NULL) delete mTextureEffects[i]; - } - for (int i = 0; i < MAX_EFFECTS; i++) - { - if (mEffectShaders[i] != NULL) delete mEffectShaders[i]; - mEffectShaders[i] = NULL; - } - mTextureEffects.Clear(); + for (unsigned int i = 0; i < mTextureEffects.Size(); i++) + { + if (mTextureEffects[i] != NULL) delete mTextureEffects[i]; } + for (int i = 0; i < MAX_EFFECTS; i++) + { + if (mEffectShaders[i] != NULL) delete mEffectShaders[i]; + mEffectShaders[i] = NULL; + } + mTextureEffects.Clear(); } //========================================================================== @@ -444,7 +431,7 @@ int FShaderManager::Find(const char * shn) void FShaderManager::SetActiveShader(FShader *sh) { - if (gl.hasGLSL() && mActiveShader != sh) + if (mActiveShader != sh) { glUseProgram(sh!= NULL? sh->GetHandle() : 0); mActiveShader = sh; diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 7d979f921..aaa9568f9 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -127,17 +127,13 @@ void gl_LoadExtensions() else Printf("Emulating OpenGL v %s\n", version); - // Don't even start if it's lower than 1.3 - if (strcmp(version, "2.0") < 0) + // Don't even start if it's lower than 3.0 + if (strcmp(version, "3.0") < 0) { - I_FatalError("Unsupported OpenGL version.\nAt least GL 2.0 is required to run " GAMENAME ".\n"); + I_FatalError("Unsupported OpenGL version.\nAt least GL 3.0 is required to run " GAMENAME ".\n"); } gl.version = strtod(version, NULL); gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL); - if (gl.version < 3.f) gl.glslversion = 0.f; - - // This loads any function pointers and flags that require a vaild render context to - // initialize properly gl.vendorstring=(char*)glGetString(GL_VENDOR); @@ -148,11 +144,6 @@ void gl_LoadExtensions() glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl.max_texturesize); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - if (gl.version >= 3.f) - { - gl.flags|=RFL_FRAMEBUFFER; - } } //========================================================================== @@ -176,7 +167,7 @@ void gl_PrintStartupLog() Printf ("Max. texture units: %d\n", v); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &v); Printf ("Max. fragment uniforms: %d\n", v); - if (gl.hasGLSL()) gl.maxuniforms = v; + gl.maxuniforms = v; glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &v); Printf ("Max. vertex uniforms: %d\n", v); glGetIntegerv(GL_MAX_VARYING_FLOATS, &v); diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h index d5346fa7d..74beb72a4 100644 --- a/src/gl/system/gl_interface.h +++ b/src/gl/system/gl_interface.h @@ -9,7 +9,6 @@ enum RenderFlags RFL_TEXTURE_COMPRESSION=1, RFL_TEXTURE_COMPRESSION_S3TC=2, - RFL_FRAMEBUFFER = 4, RFL_BUFFER_STORAGE = 8, RFL_SHADER_STORAGE_BUFFER = 16, RFL_BASEINDEX = 32, @@ -36,16 +35,6 @@ struct RenderContext { return maxuniforms>=2048? 128:64; } - - bool hasGLSL() const - { - return glslversion >= 1.3f; - } - - bool hasCompatibility() // will return false, once transition to a core profile is possible and a core profile is used. - { - return true; - } }; extern RenderContext gl; diff --git a/src/gl/system/gl_menu.cpp b/src/gl/system/gl_menu.cpp index 0518606b9..972b9421e 100644 --- a/src/gl/system/gl_menu.cpp +++ b/src/gl/system/gl_menu.cpp @@ -59,40 +59,4 @@ CUSTOM_CVAR (Float, vid_contrast, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // when they are actually valid. void gl_SetupMenu() { - if (!gl.hasGLSL()) - { - // Radial fog and Doom lighting are not available in SM < 4 cards - // The way they are implemented does not work well on older hardware. - - FOptionValues **opt = OptionValues.CheckKey("LightingModes"); - if (opt != NULL) - { - for(int i = (*opt)->mValues.Size()-1; i>=0; i--) - { - // Delete 'Doom' lighting mode - if ((*opt)->mValues[i].Value == 2.0 || (*opt)->mValues[i].Value == 8.0) - { - (*opt)->mValues.Delete(i); - } - } - } - - opt = OptionValues.CheckKey("FogMode"); - if (opt != NULL) - { - for(int i = (*opt)->mValues.Size()-1; i>=0; i--) - { - // Delete 'Radial' fog mode - if ((*opt)->mValues[i].Value == 2.0) - { - (*opt)->mValues.Delete(i); - } - } - } - - // disable features that don't work without shaders. - if (gl_lightmode == 2 || gl_lightmode == 8) gl_lightmode = 3; - if (gl_fogmode == 2) gl_fogmode = 1; - if (gl_dynlight_shader) gl_dynlight_shader = false; - } } diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index 28cfa0e6d..18c4ebfdf 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -505,52 +505,7 @@ bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb) glVertex2i(fb->Width, fb->Height); glEnd(); - gl_RenderState.SetTextureMode(TM_MODULATE); - gl_RenderState.Apply(true); - glActiveTexture(GL_TEXTURE1); - glEnable(GL_TEXTURE_2D); - - // mask out the alpha channel of the wipeendscreen. - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); - glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); - glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); - glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); - - glActiveTexture(GL_TEXTURE0); - - // Burn the new screen on top of it. - fb->wipeendscreen->Bind(1); - //BurnTexture->Bind(0, CM_DEFAULT); - - BurnTexture->CreateTexture(rgb_buffer, WIDTH, HEIGHT, false, 0); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - - glBegin(GL_TRIANGLE_STRIP); - glMultiTexCoord2f(GL_TEXTURE0, 0, 0); - glMultiTexCoord2f(GL_TEXTURE1, 0, vb); - glVertex2i(0, 0); - glMultiTexCoord2f(GL_TEXTURE0, 0, 1); - glMultiTexCoord2f(GL_TEXTURE1, 0, 0); - glVertex2i(0, fb->Height); - glMultiTexCoord2f(GL_TEXTURE0, 1, 0); - glMultiTexCoord2f(GL_TEXTURE1, ur, vb); - glVertex2i(fb->Width, 0); - glMultiTexCoord2f(GL_TEXTURE0, 1, 1); - glMultiTexCoord2f(GL_TEXTURE1, ur, 0); - glVertex2i(fb->Width, fb->Height); - glEnd(); - - glActiveTexture(GL_TEXTURE1); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glDisable(GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); + // the old burn warp code is obsolete and has to be replaced. // The fire may not always stabilize, so the wipe is forced to end // after an arbitrary maximum time. diff --git a/src/gl/textures/gl_hqresize.cpp b/src/gl/textures/gl_hqresize.cpp index 837977145..59e84051e 100644 --- a/src/gl/textures/gl_hqresize.cpp +++ b/src/gl/textures/gl_hqresize.cpp @@ -224,10 +224,6 @@ unsigned char *gl_CreateUpsampledTextureBuffer ( const FTexture *inputTexture, u if ( inputTexture->bHasCanvas ) return inputBuffer; - // [BB] Don't upsample non-shader handled warped textures. Needs too much memory and time - if (inputTexture->bWarped && !gl.hasGLSL()) - return inputBuffer; - switch (inputTexture->UseType) { case FTexture::TEX_Sprite: diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index a2a83e5db..3330d1f0c 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -54,7 +54,6 @@ extern TexFilter_s TexFilter[]; extern int TexFormat[]; -EXTERN_CVAR(Bool, gl_clamp_per_texture) //=========================================================================== @@ -197,10 +196,6 @@ void FHardwareTexture::LoadImage(unsigned char * buffer,int w, int h, unsigned i { texformat = GL_R8; } - else if (gl.version <= 3.0f || gl.hasCompatibility()) - { - texformat = GL_ALPHA8; - } else { texformat = GL_RGBA8; @@ -251,16 +246,17 @@ void FHardwareTexture::LoadImage(unsigned char * buffer,int w, int h, unsigned i if (deletebuffer) free(buffer); - // When using separate samplers the stuff below is not needed. - // if (gl.flags & RFL_SAMPLER_OBJECTS) return; - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT); if (alphatexture && gl.version >= 3.3f) { static const GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_RED}; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); } + + // When using separate samplers the stuff below is not needed. + // if (gl.flags & RFL_SAMPLER_OBJECTS) return; + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapparam==GL_CLAMP? GL_CLAMP_TO_EDGE : GL_REPEAT); clampmode = wrapparam==GL_CLAMP? GLT_CLAMPX|GLT_CLAMPY : 0; if (forcenofiltering) @@ -439,19 +435,15 @@ void FHardwareTexture::UnbindAll() int FHardwareTexture::GetDepthBuffer() { - if (gl.flags & RFL_FRAMEBUFFER) + if (glDepthID == 0) { - if (glDepthID == 0) - { - glGenRenderbuffers(1, &glDepthID); - glBindRenderbuffer(GL_RENDERBUFFER, glDepthID); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, - GetTexDimension(texwidth), GetTexDimension(texheight)); - glBindRenderbuffer(GL_RENDERBUFFER, 0); - } - return glDepthID; + glGenRenderbuffers(1, &glDepthID); + glBindRenderbuffer(GL_RENDERBUFFER, glDepthID); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, + GetTexDimension(texwidth), GetTexDimension(texheight)); + glBindRenderbuffer(GL_RENDERBUFFER, 0); } - return 0; + return glDepthID; } @@ -463,11 +455,8 @@ int FHardwareTexture::GetDepthBuffer() void FHardwareTexture::BindToFrameBuffer() { - if (gl.flags & RFL_FRAMEBUFFER) - { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glDefTexID, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer()); - } + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glDefTexID, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer()); } diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index d949addc8..b6d83eb52 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -85,7 +85,6 @@ FGLTexture::FGLTexture(FTexture * tx, bool expandpatches) for(int i=0;i<5;i++) gltexture[i]=NULL; HiresLump=-1; hirestexture = NULL; - currentwarp = 0; bHasColorkey = false; bIsTransparent = -1; bExpand = expandpatches; @@ -186,84 +185,6 @@ void FGLTexture::Clean(bool all) } } -//=========================================================================== -// -// FGLTex::WarpBuffer -// -//=========================================================================== - -BYTE *FGLTexture::WarpBuffer(BYTE *buffer, int Width, int Height, int warp) -{ - if (Width > 256 || Height > 256) return buffer; - - DWORD *in = (DWORD*)buffer; - DWORD *out = (DWORD*)new BYTE[4*Width*Height]; - float Speed = static_cast(tex)->GetSpeed(); - - static_cast(tex)->GenTime = r_FrameTime; - - static DWORD linebuffer[256]; // anything larger will bring down performance so it is excluded above. - DWORD timebase = DWORD(r_FrameTime*Speed*23/28); - int xsize = Width; - int ysize = Height; - int xmask = xsize - 1; - int ymask = ysize - 1; - int ds_xbits; - int i,x; - - if (warp == 1) - { - for(ds_xbits=-1,i=Width; i; i>>=1, ds_xbits++); - - for (x = xsize-1; x >= 0; x--) - { - int yt, yf = (finesine[(timebase+(x+17)*128)&FINEMASK]>>13) & ymask; - const DWORD *source = in + x; - DWORD *dest = out + x; - for (yt = ysize; yt; yt--, yf = (yf+1)&ymask, dest += xsize) - { - *dest = *(source+(yf<= 0; y--) - { - int xt, xf = (finesine[(timebase+y*128)&FINEMASK]>>13) & xmask; - DWORD *source = out + (y<>=1, ybits++); - - DWORD timebase = (r_FrameTime * Speed * 40 / 28); - for (x = xsize-1; x >= 0; x--) - { - for (int y = ysize-1; y >= 0; y--) - { - int xt = (x + 128 - + ((finesine[(y*128 + timebase*5 + 900) & 8191]*2)>>FRACBITS) - + ((finesine[(x*256 + timebase*4 + 300) & 8191]*2)>>FRACBITS)) & xmask; - int yt = (y + 128 - + ((finesine[(y*128 + timebase*3 + 700) & 8191]*2)>>FRACBITS) - + ((finesine[(x*256 + timebase*4 + 1200) & 8191]*2)>>FRACBITS)) & ymask; - const DWORD *source = in + (xt << ybits) + yt; - DWORD *dest = out + (x << ybits) + y; - *dest = *source; - } - } - } - delete [] buffer; - return (BYTE*)out; -} //=========================================================================== // @@ -271,7 +192,7 @@ BYTE *FGLTexture::WarpBuffer(BYTE *buffer, int Width, int Height, int warp) // //=========================================================================== -unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp, bool alphatexture) +unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, bool alphatexture) { unsigned char * buffer; int W, H; @@ -329,21 +250,9 @@ unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, b bIsTransparent = 0; } - if (warp != 0) - { - buffer = WarpBuffer(buffer, W, H, warp); - } // [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it. - // Also don't upsample warped textures. - else //if (bIsTransparent != 1) - { - // [BB] Potentially upsample the buffer. - buffer = gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, bIsTransparent || alphatexture); - } - currentwarp = warp; - currentwarptime = gl_frameMS; - - return buffer; + // [BB] Potentially upsample the buffer. + return gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, bIsTransparent || alphatexture); } @@ -387,7 +296,7 @@ bool FGLTexture::CreatePatch() // //=========================================================================== -const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int translation, FTexture *hirescheck, int warp) +const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int translation, FTexture *hirescheck) { int usebright = false; @@ -414,15 +323,8 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla if (hwtex) { - if ((warp != 0 || currentwarp != warp) && currentwarptime != gl_frameMS) - { - // must recreate the texture - Clean(true); - hwtex = CreateTexture(clampmode); - } - - // Texture has become invalid - this is only for special textures, not the regular warping, which is handled above - else if ((warp == 0 && !tex->bHasCanvas && !tex->bWarped) && tex->CheckModified()) + // Texture has become invalid + if ((!tex->bHasCanvas && !tex->bWarped) && tex->CheckModified()) { Clean(true); hwtex = CreateTexture(clampmode); @@ -439,7 +341,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla if (!tex->bHasCanvas) { - buffer = CreateTexBuffer(translation, w, h, false, hirescheck, warp); + buffer = CreateTexBuffer(translation, w, h, false, hirescheck); tex->ProcessData(buffer, w, h, false); } if (!hwtex->CreateTexture(buffer, w, h, true, texunit, translation)) @@ -464,7 +366,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla // Binds a sprite to the renderer // //=========================================================================== -const FHardwareTexture * FGLTexture::BindPatch(int texunit, int translation, int warp, bool alphatexture) +const FHardwareTexture * FGLTexture::BindPatch(int texunit, int translation, bool alphatexture) { bool usebright = false; int transparm = translation; @@ -474,15 +376,8 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int translation, int if (CreatePatch()) { - if (warp != 0 || currentwarp != warp) - { - // must recreate the texture - Clean(true); - CreatePatch(); - } - // Texture has become invalid - this is only for special textures, not the regular warping, which is handled above - else if ((warp == 0 && !tex->bHasCanvas && !tex->bWarped) && tex->CheckModified()) + if ((!tex->bHasCanvas && !tex->bWarped) && tex->CheckModified()) { Clean(true); CreatePatch(); @@ -495,7 +390,7 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int translation, int int w, h; // Create this texture - unsigned char * buffer = CreateTexBuffer(translation, w, h, bExpand, NULL, warp, alphatexture); + unsigned char * buffer = CreateTexBuffer(translation, w, h, bExpand, NULL, alphatexture); tex->ProcessData(buffer, w, h, true); if (!glpatch->CreateTexture(buffer, w, h, false, texunit, translation, alphatexture)) { @@ -625,7 +520,7 @@ FMaterial::FMaterial(FTexture * tx, bool forceexpand) { expanded = false; } - else if (gl.hasGLSL()) + else { if (tx->gl_info.shaderindex >= FIRST_USER_SHADER) { @@ -671,7 +566,7 @@ FMaterial::FMaterial(FTexture * tx, bool forceexpand) tex = tx; tx->gl_info.mExpanded = expanded; - FTexture *basetex = tx->GetRedirect(!gl.hasGLSL()); + FTexture *basetex = tx->GetRedirect(false); if (!expanded && !basetex->gl_info.mExpanded && basetex->UseType != FTexture::TEX_Sprite) { // check if the texture is just a simple redirect to a patch @@ -842,13 +737,13 @@ void FMaterial::Bind(int clampmode, int translation, int overrideshader) int maxbound = 0; bool allowhires = tex->xScale == FRACUNIT && tex->yScale == FRACUNIT; - int softwarewarp = gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed); + gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed); if (tex->bHasCanvas || tex->bWarped) clampmode = 0; else if (clampmode != -1) clampmode &= 3; else clampmode = 4; - const FHardwareTexture *gltexture = mBaseLayer->Bind(0, clampmode, translation, allowhires? tex:NULL, softwarewarp); + const FHardwareTexture *gltexture = mBaseLayer->Bind(0, clampmode, translation, allowhires? tex:NULL); if (gltexture != NULL && shaderindex > 0 && overrideshader == 0) { for(unsigned i=0;igl_info.SystemTexture->Bind(i+1, clampmode, 0, NULL, false); + layer->gl_info.SystemTexture->Bind(i+1, clampmode, 0, NULL); maxbound = i+1; } } @@ -889,13 +784,13 @@ void FMaterial::BindPatch(int translation, int overrideshader, bool alphatexture int shaderindex = overrideshader > 0? overrideshader : mShaderIndex; int maxbound = 0; - int softwarewarp = gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed); + gl_RenderState.SetupShader(shaderindex, tex->gl_info.shaderspeed); - const FHardwareTexture *glpatch = mBaseLayer->BindPatch(0, translation, softwarewarp, alphatexture); + const FHardwareTexture *glpatch = mBaseLayer->BindPatch(0, translation, alphatexture); // The only multitexture effect usable on sprites is the brightmap. if (glpatch != NULL && shaderindex == 3) { - mTextureLayers[0].texture->gl_info.SystemTexture->BindPatch(1, 0, 0, false); + mTextureLayers[0].texture->gl_info.SystemTexture->BindPatch(1, 0, false); maxbound = 1; } // unbind everything from the last texture that's still active @@ -1013,7 +908,7 @@ void FMaterial::BindToFrameBuffer() if (mBaseLayer->gltexture[0] == NULL) { // must create the hardware texture first - mBaseLayer->Bind(0, 0, 0, NULL, 0); + mBaseLayer->Bind(0, 0, 0, NULL); FHardwareTexture::Unbind(0); } mBaseLayer->gltexture[0]->BindToFrameBuffer(); diff --git a/src/gl/textures/gl_material.h b/src/gl/textures/gl_material.h index e1a5e93cd..81f4dd10f 100644 --- a/src/gl/textures/gl_material.h +++ b/src/gl/textures/gl_material.h @@ -61,28 +61,24 @@ private: FHardwareTexture *gltexture[5]; FHardwareTexture *glpatch; - int currentwarp; - int currentwarptime; - bool bHasColorkey; // only for hires bool bExpand; float AlphaThreshold; unsigned char * LoadHiresTexture(FTexture *hirescheck, int *width, int *height, bool alphatexture); - BYTE *WarpBuffer(BYTE *buffer, int Width, int Height, int warp); FHardwareTexture *CreateTexture(int clampmode); //bool CreateTexture(); bool CreatePatch(); - const FHardwareTexture *Bind(int texunit, int clamp, int translation, FTexture *hirescheck, int warp); - const FHardwareTexture *BindPatch(int texunit, int translation, int warp, bool alphatexture); + const FHardwareTexture *Bind(int texunit, int clamp, int translation, FTexture *hirescheck); + const FHardwareTexture *BindPatch(int texunit, int translation, bool alphatexture); public: FGLTexture(FTexture * tx, bool expandpatches); ~FGLTexture(); - unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp, bool alphatexture = false); + unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, bool alphatexture = false); void Clean(bool all); int Dump(int i); diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 53adb9551..a864c7e3e 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -94,7 +94,6 @@ CUSTOM_CVAR(Bool, gl_texture_usehires, true, CVAR_ARCHIVE|CVAR_NOINITCALL) } CVAR(Bool, gl_precache, false, CVAR_ARCHIVE) -CVAR(Bool, gl_clamp_per_texture, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Bool, gl_trimsprites, true, CVAR_ARCHIVE);