Helper classes/functions for GL state handling.
authormtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 25 Mar 2007 17:48:51 +0000 (17:48 +0000)
committermtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 25 Mar 2007 17:48:51 +0000 (17:48 +0000)
EVE/Reve/GLUtilNS.h [new file with mode: 0644]

diff --git a/EVE/Reve/GLUtilNS.h b/EVE/Reve/GLUtilNS.h
new file mode 100644 (file)
index 0000000..6790be5
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef Reve_GLUtilNS_H
+#define Reve_GLUtilNS_H
+#ifndef __CINT__
+
+#include <TGLIncludes.h>
+
+namespace GLUtilNS
+{
+
+class GL_Capability_Switch {
+  GLenum    fWhat;
+  GLboolean fState;
+  bool      fFlip;
+
+  void set_state(GLboolean s)
+  { if(s) glEnable(fWhat); else glDisable(fWhat); }
+
+public:
+  GL_Capability_Switch(GLenum what, GLboolean state) : fWhat(what)
+  {
+    fState = glIsEnabled(fWhat);
+    fFlip  = (fState != state);
+    if(fFlip)  set_state(state);
+  }
+  ~GL_Capability_Switch()
+  { if(fFlip) set_state(fState); }
+};
+
+class GL_Float_Holder
+{
+  GLenum    fWhat;
+  GLfloat   fState;
+  bool      fFlip;
+  void    (*fFoo)(GLfloat);
+
+public:
+  GL_Float_Holder(GLenum what, GLfloat state, void (*foo)(GLfloat)) :
+    fWhat(what), fFoo(foo)
+  {
+    glGetFloatv(fWhat, &fState);
+    fFlip = (fState != state);
+    if(fFlip) fFoo(state);
+  }
+  ~GL_Float_Holder()
+  { if(fFlip) fFoo(fState); }
+};
+
+}
+
+#endif
+#endif