diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 239: SceneJellyfish: Save and restore custom GL state so other scenes are unaffected

Message ID 20120726160910.18281.39047.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Jesse Barker July 26, 2012, 4:09 p.m. UTC
------------------------------------------------------------
revno: 239
committer: Jesse Barker <jesse.barker@linaro.org>
branch nick: trunk
timestamp: Thu 2012-07-26 09:07:43 -0700
message:
  SceneJellyfish: Save and restore custom GL state so other scenes are unaffected
  when "reuse-context" is enabled.
modified:
  src/scene-jellyfish.cpp
  src/scene-jellyfish.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/scene-jellyfish.cpp'
--- src/scene-jellyfish.cpp	2012-07-11 07:54:17 +0000
+++ src/scene-jellyfish.cpp	2012-07-26 16:07:43 +0000
@@ -348,7 +348,12 @@ 
     fresnelPower_(1.0),
     rotation_(0.0),
     currentTime_(0.0),
-    lastUpdateTime_(0.0)
+    lastUpdateTime_(0.0),
+    cullFace_(0),
+    depthTest_(0),
+    blend_(0),
+    blendFuncSrc_(0),
+    blendFuncDst_(0)
 {
     static const string modelFilename(GLMARK_DATA_PATH"/models/jellyfish.jobj");
     if (!load_obj(modelFilename))
@@ -467,6 +472,18 @@ 
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
         glBindTexture(GL_TEXTURE_2D, 0);
     }
+
+    // Save the GL state we are changing so we can restore it later.
+    cullFace_ = glIsEnabled(GL_CULL_FACE);
+    depthTest_ = glIsEnabled(GL_DEPTH_TEST);
+    blend_ = glIsEnabled(GL_BLEND);
+    glGetIntegerv(GL_BLEND_SRC_RGB, &blendFuncSrc_);
+    glGetIntegerv(GL_BLEND_DST_RGB, &blendFuncDst_);
+
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glEnable(GL_BLEND);
+    glDisable(GL_CULL_FACE);
+    glDisable(GL_DEPTH_TEST);
 }
 
 void
@@ -495,6 +512,21 @@ 
 void
 JellyfishPrivate::cleanup()
 {
+    // Restore the GL state we changed for the scene.
+    glBlendFunc(blendFuncSrc_, blendFuncDst_);
+    if (GL_FALSE == blend_)
+    {
+        glDisable(GL_BLEND);
+    }
+    if (GL_TRUE == cullFace_)
+    {
+        glEnable(GL_CULL_FACE);
+    }
+    if (GL_TRUE == depthTest_)
+    {
+        glEnable(GL_DEPTH_TEST);
+    }
+
     program_.stop();
     program_.release();
 
@@ -554,12 +586,6 @@ 
     glBindTexture(GL_TEXTURE_2D, textureObjects_[whichCaustic_]);
     program_["uSampler1"] = 1;
 
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-    glDisable(GL_CULL_FACE);
-    glDisable(GL_DEPTH_TEST);
-
     glBindBuffer(GL_ARRAY_BUFFER, bufferObjects_[0]);
     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjects_[1]);
 

=== modified file 'src/scene-jellyfish.h'
--- src/scene-jellyfish.h	2012-07-09 15:00:06 +0000
+++ src/scene-jellyfish.h	2012-07-26 16:07:43 +0000
@@ -104,6 +104,12 @@ 
     float rotation_;
     float currentTime_;
     double lastUpdateTime_;
+    // GL state we plan to override, so we can restore it cleanly.
+    unsigned int cullFace_;
+    unsigned int depthTest_;
+    unsigned int blend_;
+    int blendFuncSrc_;
+    int blendFuncDst_;
 
 public:
     JellyfishPrivate();