From f4278247ed7f9d8db221bc2c1a062227442e99bc Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 25 Nov 2012 15:47:26 +0100 Subject: [PATCH] glstate: Support glBlendColor --- gfx_es2/gl_state.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gfx_es2/gl_state.h b/gfx_es2/gl_state.h index d2805bdf9c..66925754a3 100644 --- a/gfx_es2/gl_state.h +++ b/gfx_es2/gl_state.h @@ -12,7 +12,11 @@ #endif #endif #include +#include + +// OpenGL state cache. Should convert all code to use this instead of directly calling glEnable etc, +// as GL state changes can be expensive on some hardware. class OpenGLState { private: @@ -56,7 +60,7 @@ private: class SavedState1_##func { \ p1type p1; \ public: \ - SavedState1_##func() : p1(p1def) {}; \ + SavedState1_##func() : p1(p1def) {}; \ void set(p1type newp1) { \ if(newp1 != p1) { \ p1 = newp1; \ @@ -73,7 +77,7 @@ private: p1type p1; \ p2type p2; \ public: \ - SavedState2_##func() : p1(p1def), p2(p2def) {}; \ + SavedState2_##func() : p1(p1def), p2(p2def) {}; \ inline void set(p1type newp1, p2type newp2) { \ if(newp1 != p1 || newp2 != p2) { \ p1 = newp1; \ @@ -86,10 +90,26 @@ private: } \ } +#define STATEFLOAT4(func, def) \ + class SavedState4_##func { \ + float p[4]; \ + public: \ + SavedState4_##func() { \ + for (int i = 0; i < 4; i++) {p[i] = def;} \ + }; \ + inline void set(const float v[4]) { \ + if(memcmp(p,v,sizeof(float)*4)) { \ + memcpy(p,v,sizeof(float)*4); \ + func(p[0], p[1], p[2], p[3]); \ + } \ + } \ + inline void restore() { \ + func(p[0], p[1], p[2], p[3]); \ + } \ + } + bool initialized; - - public: OpenGLState() : initialized(false) {} void Initialize(); @@ -98,6 +118,7 @@ public: BoolState blend; STATE2(glBlendFunc, GLenum, GLenum, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blendFunc; STATE1(glBlendEquation, GLenum, GL_FUNC_ADD) blendEquation; + STATEFLOAT4(glBlendColor, 1.0f) blendColor; BoolState cullFace; STATE1(glCullFace, GLenum, GL_FRONT) cullFaceMode; @@ -105,6 +126,7 @@ public: BoolState depthTest; STATE1(glDepthFunc, GLenum, GL_LESS) depthFunc; STATE2(glDepthRangef, float, float, 0.f, 1.f) depthRange; + }; #undef STATE1