2
0
Эх сурвалжийг харах

Fixed access to OpenGL commands before the context was initialized.

Lasse Öörni 13 жил өмнө
parent
commit
0b69846402

+ 2 - 3
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -181,7 +181,6 @@ Graphics::Graphics(Context* context) :
     numBatches_(0),
     defaultTextureFilterMode_(FILTER_BILINEAR)
 {
-    ResetCachedState();
     SetTextureUnitMappings();
     
     // If first instance in this process, initialize SDL under static mutex. Note that Graphics subsystem will also be in charge
@@ -2090,8 +2089,6 @@ void Graphics::OnDeviceLost()
 
 void Graphics::OnDeviceReset()
 {
-    ResetCachedState();
-    
     for (unsigned i = 0; i < gpuObjects_.Size(); ++i)
         gpuObjects_[i]->OnDeviceReset();
     
@@ -2116,6 +2113,8 @@ void Graphics::OnDeviceReset()
         // When AutoDepthStencil is not used, depth buffering must be enabled manually
         impl_->device_->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
     }
+    
+    ResetCachedState();
 }
 
 void Graphics::ResetCachedState()

+ 7 - 7
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -149,7 +149,6 @@ Graphics::Graphics(Context* context_) :
     hiresShadowMapFormat_(GL_DEPTH_COMPONENT24),
     shaderParameterFrame_(0)
 {
-    ResetCachedState();
     SetTextureUnitMappings();
     
     // If first instance in this process, initialize SDL under static mutex. Note that Graphics subsystem will also be in charge
@@ -1782,7 +1781,6 @@ void Graphics::Restore()
         (*i)->OnDeviceReset();
     
     ResetCachedState();
-    ClearParameterSources();
 }
 
 void Graphics::CleanupRenderSurface(RenderSurface* surface)
@@ -2202,16 +2200,18 @@ void Graphics::ResetCachedState()
     stencilRef_ = 0;
     stencilCompareMask_ = M_MAX_UNSIGNED;
     stencilWriteMask_ = M_MAX_UNSIGNED;
-    
     impl_->activeTexture_ = 0;
     impl_->enabledAttributes_ = 0;
     impl_->boundFbo_ = 0;
     
     // Set initial state to match Direct3D
-    glEnable(GL_DEPTH_TEST);
-    SetCullMode(CULL_CCW);
-    SetDepthTest(CMP_LESSEQUAL);
-    SetDepthWrite(true);
+    if (impl_->context_)
+    {
+        glEnable(GL_DEPTH_TEST);
+        SetCullMode(CULL_CCW);
+        SetDepthTest(CMP_LESSEQUAL);
+        SetDepthWrite(true);
+    }
 }
 
 void Graphics::SetTextureUnitMappings()