Move dirty DX constant tracking from Context to the Renderers.

TRAC #22308
Signed-off-by: Geoff Lang
Signed-off-by: Daniel Koch
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1713 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Context.cpp b/src/libGLESv2/Context.cpp
index ad4a140..a51a14c 100644
--- a/src/libGLESv2/Context.cpp
+++ b/src/libGLESv2/Context.cpp
@@ -178,8 +178,6 @@
     mSupportsEventQueries = false;
     mSupportsOcclusionQueries = false;
     mNumCompressedTextureFormats = 0;
-
-    markAllStateDirty();
 }
 
 Context::~Context()
@@ -314,19 +312,6 @@
     Framebuffer *framebufferZero = new DefaultFramebuffer(mRenderer, colorbufferZero, depthStencilbufferZero);
 
     setFramebufferZero(framebufferZero);
-    
-    markAllStateDirty();
-}
-
-// This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
-void Context::markAllStateDirty()
-{
-    mDxUniformsDirty = true;
-}
-
-void Context::markDxUniformsDirty()
-{
-    mDxUniformsDirty = true;
 }
 
 // NOTE: this function should not assume that this context is current!
@@ -933,7 +918,6 @@
         Program *newProgram = mResourceManager->getProgram(program);
         Program *oldProgram = mResourceManager->getProgram(priorProgram);
         mCurrentProgramBinary.set(NULL);
-        mDxUniformsDirty = true;
 
         if (newProgram)
         {
@@ -959,7 +943,6 @@
     if (linked && program == mState.currentProgram)
     {
         mCurrentProgramBinary.set(programObject->getProgramBinary());
-        mDxUniformsDirty = true;
     }
 }
 
@@ -974,7 +957,6 @@
     if (loaded && program == mState.currentProgram)
     {
         mCurrentProgramBinary.set(programObject->getProgramBinary());
-        mDxUniformsDirty = true;
     }
 
 }
@@ -1719,11 +1701,10 @@
 
     ProgramBinary *programBinary = mState.currentProgram ? getCurrentProgramBinary() : NULL;
     if (!mRenderer->setViewport(mState.viewport, mState.zNear, mState.zFar, drawMode, mState.rasterizer.frontFace,
-                                ignoreViewport, programBinary, mDxUniformsDirty))
+                                ignoreViewport, programBinary))
     {
         return false;
     }
-    mDxUniformsDirty = false;
 
     mRenderer->setScissorRectangle(mState.scissor, mState.scissorTest);
 
diff --git a/src/libGLESv2/Context.h b/src/libGLESv2/Context.h
index 3eceed8..c288b7d 100644
--- a/src/libGLESv2/Context.h
+++ b/src/libGLESv2/Context.h
@@ -191,9 +191,6 @@
 
     void makeCurrent(egl::Surface *surface);
 
-    virtual void markAllStateDirty();
-    void markDxUniformsDirty();
-
     virtual void markContextLost();
     bool isContextLost();
 
@@ -486,7 +483,6 @@
     GLenum mResetStrategy;
     bool mRobustAccess;
 
-    bool mDxUniformsDirty;
     BindingPointer<ProgramBinary> mCurrentProgramBinary;
     Framebuffer *mBoundDrawFramebuffer;
 
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 93102d0..6e5cd9e 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -1000,7 +1000,7 @@
         }
     }
 
-    mRenderer->applyUniforms(&mUniforms, mVertexConstants, mPixelConstants);
+    mRenderer->applyUniforms(&mUniforms);
 }
 
 // Packs varyings into generic varying registers, using the algorithm from [OpenGL ES Shading Language 1.00 rev. 17] appendix A section 7 page 111
@@ -1813,9 +1813,6 @@
         success = false;
     }
 
-    Context *context = getContext();
-    context->markDxUniformsDirty();
-
     return success;
 }
 
@@ -2241,38 +2238,6 @@
     return true;
 }
 
-void ProgramBinary::applyDxDepthRange(float near, float far, float diff)
-{
-    mVertexConstants.depthRange[0] = near;
-    mVertexConstants.depthRange[1] = far;
-    mVertexConstants.depthRange[2] = diff;
-
-    mPixelConstants.depthRange[0] = near;
-    mPixelConstants.depthRange[1] = far;
-    mPixelConstants.depthRange[2] = diff;
-}
-
-void ProgramBinary::applyDxDepthFront(float range, float start, float frontCCW)
-{
-    mPixelConstants.depthFront[0] = range;
-    mPixelConstants.depthFront[1] = start;
-    mPixelConstants.depthFront[2] = frontCCW;
-}
-
-void ProgramBinary::applyDxCoord(float halfWidth, float halfHeight, float x0, float y0)
-{
-    mPixelConstants.coord[0] = halfWidth;
-    mPixelConstants.coord[1] = halfHeight;
-    mPixelConstants.coord[2] = x0;
-    mPixelConstants.coord[3] = y0;
-}
-
-void ProgramBinary::applyDxHalfPixelSize(float width, float height)
-{
-    mVertexConstants.halfPixelSize[0] = width;
-    mVertexConstants.halfPixelSize[1] = height;
-}
-
 ProgramBinary::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(TEXTURE_2D)
 {
 }
diff --git a/src/libGLESv2/ProgramBinary.h b/src/libGLESv2/ProgramBinary.h
index 2f910fd..782d3f9 100644
--- a/src/libGLESv2/ProgramBinary.h
+++ b/src/libGLESv2/ProgramBinary.h
@@ -78,11 +78,6 @@
     bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
     bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
 
-    void applyDxDepthRange(float near, float far, float diff);
-    void applyDxDepthFront(float range, float start, float frontCCW);
-    void applyDxCoord(float halfWidth, float halfHeight, float x0, float y0);
-    void applyDxHalfPixelSize(float width, float height);
-
     void dirtyAllUniforms();
     void applyUniforms();
 
@@ -147,9 +142,6 @@
     typedef std::vector<UniformLocation> UniformIndex;
     UniformIndex mUniformIndex;
 
-    rx::dx_VertexConstants mVertexConstants;
-    rx::dx_PixelConstants mPixelConstants;
-
     bool mValidated;
 
     const unsigned int mSerial;
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index ae86b9e..8f21844 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -107,11 +107,11 @@
 
     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
     virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
-                             bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
+                             bool ignoreViewport, gl::ProgramBinary *currentProgram) = 0;
 
     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
     virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
-    virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants) = 0;
+    virtual void applyUniforms(const gl::UniformArray *uniformArray) = 0;
     virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
     virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
     virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index 9fb9f40..8315164 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -489,7 +489,7 @@
 }
 
 bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, 
-                             bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
+                             bool ignoreViewport, gl::ProgramBinary *currentProgram)
 {
     gl::Rectangle actualViewport = viewport;
     float actualZNear = gl::clamp01(zNear);
@@ -517,8 +517,8 @@
         return false;   // Nothing to render
     }
 
-    bool viewportChanged =  mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
-                            actualZNear != mCurNear || actualZFar != mCurFar;
+    bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
+                           actualZNear != mCurNear || actualZFar != mCurFar;
 
     if (viewportChanged)
     {
@@ -529,20 +529,42 @@
         mCurFar = actualZFar;
     }
 
-    if (currentProgram && (viewportChanged || forceSetUniforms))
+    if (currentProgram)
     {
-        currentProgram->applyDxHalfPixelSize(0.0f, 0.0f);
+        dx_VertexConstants vc = {0};
+        dx_PixelConstants pc = {0};
 
-        // These values are used for computing gl_FragCoord in Program::linkVaryings().
-        currentProgram->applyDxCoord(actualViewport.width  * 0.5f,
-                                     actualViewport.height * 0.5f,
-                                     actualViewport.x + (actualViewport.width  * 0.5f),
-                                     actualViewport.y + (actualViewport.height * 0.5f));
+        vc.halfPixelSize[0] = 0.0f;
+        vc.halfPixelSize[1] = 0.0f;
 
-        GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
-        currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw);
+        pc.coord[0] = actualViewport.width  * 0.5f;
+        pc.coord[1] = actualViewport.height * 0.5f;
+        pc.coord[2] = actualViewport.x + (actualViewport.width  * 0.5f);
+        pc.coord[3] = actualViewport.y + (actualViewport.height * 0.5f);
 
-        currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear);
+        pc.depthFront[0] = (actualZFar - actualZNear) * 0.5f;
+        pc.depthFront[1] = (actualZNear + actualZFar) * 0.5f;
+        pc.depthFront[2] = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);;
+
+        vc.depthRange[0] = actualZNear;
+        vc.depthRange[1] = actualZFar;
+        vc.depthRange[2] = actualZFar - actualZNear;
+
+        pc.depthRange[0] = actualZNear;
+        pc.depthRange[1] = actualZFar;
+        pc.depthRange[2] = actualZFar - actualZNear;
+
+        if (memcmp(&vc, &mVertexConstants, sizeof(dx_VertexConstants)) != 0)
+        {
+            mVertexConstants = vc;
+            mDxUniformsDirty = true;
+        }
+
+        if (memcmp(&pc, &mPixelConstants, sizeof(dx_PixelConstants)) != 0)
+        {
+            mPixelConstants = pc;
+            mDxUniformsDirty = true;
+        }
     }
 
     mForceSetViewport = false;
@@ -999,12 +1021,13 @@
         mDeviceContext->PSSetShader(pixelShader, NULL, 0);
         mDeviceContext->VSSetShader(vertexShader, NULL, 0);
         programBinary->dirtyAllUniforms();
+        mDxUniformsDirty = true;
 
         mAppliedProgramBinarySerial = programBinarySerial;
     }
 }
 
-void Renderer11::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
+void Renderer11::applyUniforms(const gl::UniformArray *uniformArray)
 {
     D3D11_BUFFER_DESC constantBufferDescription = {0};
     constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]);
@@ -1145,8 +1168,8 @@
     }
 
     // Driver uniforms
-    memcpy(mapVS.pData, &vertexConstants, sizeof(dx_VertexConstants));
-    memcpy(mapPS.pData, &pixelConstants, sizeof(dx_PixelConstants));
+    memcpy(mapVS.pData, &mVertexConstants, sizeof(dx_VertexConstants));
+    memcpy(mapPS.pData, &mPixelConstants, sizeof(dx_PixelConstants));
 
     mDeviceContext->Unmap(constantBufferVS, 0);
     mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS);
@@ -1302,6 +1325,7 @@
     mAppliedIBOffset = 0;
 
     mAppliedProgramBinarySerial = 0;
+    mDxUniformsDirty = true;
 }
 
 void Renderer11::releaseDeviceResources()
diff --git a/src/libGLESv2/renderer/Renderer11.h b/src/libGLESv2/renderer/Renderer11.h
index eebe85b..871751d 100644
--- a/src/libGLESv2/renderer/Renderer11.h
+++ b/src/libGLESv2/renderer/Renderer11.h
@@ -62,12 +62,12 @@
 
     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
     virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
-                             bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
+                             bool ignoreViewport, gl::ProgramBinary *currentProgram);
 
     virtual bool applyPrimitiveType(GLenum mode, GLsizei count);
     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
     virtual void applyShaders(gl::ProgramBinary *programBinary);
-    virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
+    virtual void applyUniforms(const gl::UniformArray *uniformArray);
     virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
     virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
 
@@ -230,6 +230,10 @@
 
     unsigned int mAppliedProgramBinarySerial;
 
+    rx::dx_VertexConstants mVertexConstants;
+    rx::dx_PixelConstants mPixelConstants;
+    bool mDxUniformsDirty;
+
     // Vertex, index and input layouts
     VertexDataManager *mVertexDataManager;
     IndexDataManager *mIndexDataManager;
diff --git a/src/libGLESv2/renderer/Renderer9.cpp b/src/libGLESv2/renderer/Renderer9.cpp
index 7fbc3f4..f60c992 100644
--- a/src/libGLESv2/renderer/Renderer9.cpp
+++ b/src/libGLESv2/renderer/Renderer9.cpp
@@ -1027,7 +1027,7 @@
 }
 
 bool Renderer9::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
-                            bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms)
+                            bool ignoreViewport, gl::ProgramBinary *currentProgram)
 {
     gl::Rectangle actualViewport = viewport;
     float actualZNear = gl::clamp01(zNear);
@@ -1055,8 +1055,8 @@
         return false;   // Nothing to render
     }
 
-    bool viewportChanged =  mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
-                            actualZNear != mCurNear || actualZFar != mCurFar;
+    bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 ||
+                           actualZNear != mCurNear || actualZFar != mCurFar;
     if (viewportChanged)
     {
         mDevice->SetViewport(&dxViewport);
@@ -1066,20 +1066,42 @@
         mCurFar = actualZFar;
     }
 
-    if (currentProgram && (viewportChanged || forceSetUniforms))
+    if (currentProgram)
     {
-        currentProgram->applyDxHalfPixelSize(1.0f / dxViewport.Width, -1.0f / dxViewport.Height);
+        dx_VertexConstants vc = {0};
+        dx_PixelConstants pc = {0};
 
-        // These values are used for computing gl_FragCoord in Program::linkVaryings().
-        currentProgram->applyDxCoord(actualViewport.width  * 0.5f,
-                                     actualViewport.height * 0.5f,
-                                     actualViewport.x + (actualViewport.width  * 0.5f),
-                                     actualViewport.y + (actualViewport.height * 0.5f));
+        vc.halfPixelSize[0] = 1.0f / dxViewport.Width;
+        vc.halfPixelSize[1] = -1.0f / dxViewport.Height;
 
-        GLfloat ccw = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);
-        currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw);
+        pc.coord[0] = actualViewport.width  * 0.5f;
+        pc.coord[1] = actualViewport.height * 0.5f;
+        pc.coord[2] = actualViewport.x + (actualViewport.width  * 0.5f);
+        pc.coord[3] = actualViewport.y + (actualViewport.height * 0.5f);
 
-        currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear);
+        pc.depthFront[0] = (actualZFar - actualZNear) * 0.5f;
+        pc.depthFront[1] = (actualZNear + actualZFar) * 0.5f;
+        pc.depthFront[2] = !gl::IsTriangleMode(drawMode) ? 0.0f : (frontFace == GL_CCW ? 1.0f : -1.0f);;
+
+        vc.depthRange[0] = actualZNear;
+        vc.depthRange[1] = actualZFar;
+        vc.depthRange[2] = actualZFar - actualZNear;
+
+        pc.depthRange[0] = actualZNear;
+        pc.depthRange[1] = actualZFar;
+        pc.depthRange[2] = actualZFar - actualZNear;
+
+        if (memcmp(&vc, &mVertexConstants, sizeof(dx_VertexConstants)) != 0)
+        {
+            mVertexConstants = vc;
+            mDxUniformsDirty = true;
+        }
+
+        if (memcmp(&pc, &mPixelConstants, sizeof(dx_PixelConstants)) != 0)
+        {
+            mPixelConstants = pc;
+            mDxUniformsDirty = true;
+        }
     }
 
     mForceSetViewport = false;
@@ -1579,12 +1601,13 @@
         mDevice->SetPixelShader(pixelShader);
         mDevice->SetVertexShader(vertexShader);
         programBinary->dirtyAllUniforms();
+        mDxUniformsDirty = true;
 
         mAppliedProgramBinarySerial = programBinarySerial;
     }
 }
 
-void Renderer9::applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants)
+void Renderer9::applyUniforms(const gl::UniformArray *uniformArray)
 {
     for (std::vector<gl::Uniform*>::const_iterator ub = uniformArray->begin(), ue = uniformArray->end(); ub != ue; ++ub)
     {
@@ -1626,8 +1649,12 @@
     }
 
     // Driver uniforms
-    mDevice->SetVertexShaderConstantF(0, (float*)&vertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4]));
-    mDevice->SetPixelShaderConstantF(0, (float*)&pixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
+    if (mDxUniformsDirty)
+    {
+        mDevice->SetVertexShaderConstantF(0, (float*)&mVertexConstants, sizeof(dx_VertexConstants) / sizeof(float[4]));
+        mDevice->SetPixelShaderConstantF(0, (float*)&mPixelConstants, sizeof(dx_PixelConstants) / sizeof(float[4]));
+        mDxUniformsDirty = false;
+    }
 }
 
 void Renderer9::applyUniformnbv(gl::Uniform *targetUniform, GLsizei count, int width, const GLboolean *v)
@@ -1938,6 +1965,7 @@
 
     mAppliedIBSerial = 0;
     mAppliedProgramBinarySerial = 0;
+    mDxUniformsDirty = true;
 
     mVertexDeclarationCache.markStateDirty();
 }
diff --git a/src/libGLESv2/renderer/Renderer9.h b/src/libGLESv2/renderer/Renderer9.h
index a3408a9..f9116d9 100644
--- a/src/libGLESv2/renderer/Renderer9.h
+++ b/src/libGLESv2/renderer/Renderer9.h
@@ -86,11 +86,11 @@
 
     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled);
     virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
-                             bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms);
+                             bool ignoreViewport, gl::ProgramBinary *currentProgram);
 
     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer);
     virtual void applyShaders(gl::ProgramBinary *programBinary);
-    virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants);
+    virtual void applyUniforms(const gl::UniformArray *uniformArray);
     virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
     virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances);
     virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
@@ -308,6 +308,10 @@
 
     unsigned int mAppliedIBSerial;
     unsigned int mAppliedProgramBinarySerial;
+    
+    rx::dx_VertexConstants mVertexConstants;
+    rx::dx_PixelConstants mPixelConstants;
+    bool mDxUniformsDirty;
 
     // A pool of event queries that are currently unused.
     std::vector<IDirect3DQuery9*> mEventQueryPool;
diff --git a/src/libGLESv2/renderer/SwapChain11.cpp b/src/libGLESv2/renderer/SwapChain11.cpp
index 536b6ee..dc148ee 100644
--- a/src/libGLESv2/renderer/SwapChain11.cpp
+++ b/src/libGLESv2/renderer/SwapChain11.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -472,12 +472,6 @@
     static ID3D11RenderTargetView *const nullRTV = NULL;
     deviceContext->OMSetRenderTargets(1, &nullRTV, NULL);
 
-    // Mark context and renderer dirty flags
-    gl::Context *glContext = static_cast<gl::Context*>(glGetCurrentContext());
-    if (glContext)
-    {
-        glContext->markAllStateDirty();
-    }
     mRenderer->markAllStateDirty();
 
     return EGL_SUCCESS;
diff --git a/src/libGLESv2/renderer/SwapChain9.cpp b/src/libGLESv2/renderer/SwapChain9.cpp
index 069e65c..d2ac019 100644
--- a/src/libGLESv2/renderer/SwapChain9.cpp
+++ b/src/libGLESv2/renderer/SwapChain9.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
@@ -337,11 +337,6 @@
 
     HRESULT result = mSwapChain->Present(&rect, &rect, NULL, NULL, 0);
 
-    gl::Context *context = static_cast<gl::Context*>(glGetCurrentContext());
-    if (context)
-    {
-        context->markAllStateDirty();
-    }
     mRenderer->markAllStateDirty();
 
     if (isDeviceLostError(result))