diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 83303d61e7..56b319f008 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -80,19 +80,44 @@ void FRenderState::Reset() mDstBlend = GL_ONE_MINUS_SRC_ALPHA; mAlphaThreshold = 0.5f; mBlendEquation = GL_FUNC_ADD; + mModelMatrixEnabled = false; + mTextureMatrixEnabled = false; mObjectColor = 0xffffffff; mVertexBuffer = mCurrentVertexBuffer = NULL; mColormapState = CM_DEFAULT; + mSoftLight = 0; + mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f; mLightParms[3] = -1.f; mSpecialEffect = EFF_NONE; mClipHeight = 0.f; mClipHeightDirection = 0.f; + mShaderTimer = 0.0f; ClearClipSplit(); stSrcBlend = stDstBlend = -1; stBlendEquation = -1; stAlphaThreshold = -1.f; + stAlphaTest = 0; mLastDepthClamp = true; + mInterpolationFactor = 0.0f; + + mColor.Set(0.0f, 0.0f, 0.0f, 0.0f); + mCameraPos.Set(0.0f, 0.0f, 0.0f, 0.0f); + mGlowTop.Set(0.0f, 0.0f, 0.0f, 0.0f); + mGlowBottom.Set(0.0f, 0.0f, 0.0f, 0.0f); + mGlowTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); + mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); + mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); + mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f); + mClipLine.Set(0.0f, 0.0f, 0.0f, 0.0f); + mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f); + mClipSplit[0] = mClipSplit[1] = 0.0f; + mEffectState = 0; + activeShader = nullptr; + mProjectionMatrix.loadIdentity(); + mViewMatrix.loadIdentity(); + mModelMatrix.loadIdentity(); + mTextureMatrix.loadIdentity(); } //========================================================================== diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 6d56c1b27f..ec8b3f599e 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -99,6 +99,11 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int // If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed! SetVSync(vid_vsync); + // Make sure all global variables tracking OpenGL context state are reset.. + FHardwareTexture::InitGlobalState(); + FMaterial::InitGlobalState(); + gl_RenderState.Reset(); + GLRenderer = new FGLRenderer(this); memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256); UpdatePalette (); diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 9b7028f8cd..4c00af272c 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -48,11 +48,11 @@ private: public: static unsigned int lastbound[MAX_TEXTURES]; - static int lastactivetexture; - static int max_texturesize; static int GetTexDimension(int value); + static void InitGlobalState() { for (int i = 0; i < MAX_TEXTURES; i++) lastbound[i] = 0; } + private: short texwidth, texheight; diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 8e0ab73e69..6ba1fe4b0c 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -669,6 +669,12 @@ static FMaterial *last; static int lastclamp; static int lasttrans; +void FMaterial::InitGlobalState() +{ + last = nullptr; + lastclamp = 0; + lasttrans = 0; +} void FMaterial::Bind(int clampmode, int translation) { diff --git a/src/gl/textures/gl_material.h b/src/gl/textures/gl_material.h index dea0d4cf57..d44a845f6f 100644 --- a/src/gl/textures/gl_material.h +++ b/src/gl/textures/gl_material.h @@ -263,6 +263,7 @@ public: static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans); static void ClearLastTexture(); + static void InitGlobalState(); }; #endif