Use gl_RenderState to manipulate OpenGL color mask for anaglyph modes, to avoid glGet...

This commit is contained in:
Christopher Bruns 2015-12-31 11:57:21 -05:00
parent 95f4134630
commit ac6e2f4979
4 changed files with 71 additions and 12 deletions

View file

@ -70,6 +70,8 @@ void FRenderState::Reset()
{ {
mTextureEnabled = true; mTextureEnabled = true;
mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mColorMask[0] = mColorMask[1] = mColorMask[2] = mColorMask[3] = true;
currentColorMask[0] = currentColorMask[1] = currentColorMask[2] = currentColorMask[3] = true;
mFogColor.d = -1; mFogColor.d = -1;
mTextureMode = -1; mTextureMode = -1;
mLightIndex = -1; mLightIndex = -1;
@ -257,6 +259,8 @@ void FRenderState::Apply()
} }
} }
ApplyColorMask();
if (mVertexBuffer != mCurrentVertexBuffer) if (mVertexBuffer != mCurrentVertexBuffer)
{ {
if (mVertexBuffer == NULL) glBindBuffer(GL_ARRAY_BUFFER, 0); if (mVertexBuffer == NULL) glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -268,6 +272,21 @@ void FRenderState::Apply()
void FRenderState::ApplyColorMask()
{
if ((mColorMask[0] != currentColorMask[0]) ||
(mColorMask[1] != currentColorMask[1]) ||
(mColorMask[2] != currentColorMask[2]) ||
(mColorMask[3] != currentColorMask[3]))
{
glColorMask(mColorMask[0], mColorMask[1], mColorMask[2], mColorMask[3]);
currentColorMask[0] = mColorMask[0];
currentColorMask[1] = mColorMask[1];
currentColorMask[2] = mColorMask[2];
currentColorMask[3] = mColorMask[3];
}
}
void FRenderState::ApplyMatrices() void FRenderState::ApplyMatrices()
{ {
if (GLRenderer->mShaderManager != NULL) if (GLRenderer->mShaderManager != NULL)

View file

@ -47,6 +47,8 @@ class FRenderState
bool mFogEnabled; bool mFogEnabled;
bool mGlowEnabled; bool mGlowEnabled;
bool mBrightmapEnabled; bool mBrightmapEnabled;
bool mColorMask[4];
bool currentColorMask[4];
int mLightIndex; int mLightIndex;
int mSpecialEffect; int mSpecialEffect;
int mTextureMode; int mTextureMode;
@ -116,6 +118,7 @@ public:
} }
void Apply(); void Apply();
void ApplyColorMask();
void ApplyMatrices(); void ApplyMatrices();
void ApplyLightIndex(int index); void ApplyLightIndex(int index);
@ -174,6 +177,28 @@ public:
mDesaturation = 0; mDesaturation = 0;
} }
void GetColorMask(bool& r, bool &g, bool& b, bool& a) const
{
r = mColorMask[0];
g = mColorMask[1];
b = mColorMask[2];
a = mColorMask[3];
}
void SetColorMask(bool r, bool g, bool b, bool a)
{
mColorMask[0] = r;
mColorMask[1] = g;
mColorMask[2] = b;
mColorMask[3] = a;
}
void ResetColorMask()
{
for (int i = 0; i < 4; ++i)
mColorMask[i] = true;
}
void SetTextureMode(int mode) void SetTextureMode(int mode)
{ {
mTextureMode = mode; mTextureMode = mode;

View file

@ -39,6 +39,7 @@
#include "gl_stereo3d.h" #include "gl_stereo3d.h"
#include "gl_stereo_leftright.h" #include "gl_stereo_leftright.h"
#include "gl/system/gl_system.h" #include "gl/system/gl_system.h"
#include "gl/renderer/gl_renderstate.h"
namespace s3d { namespace s3d {
@ -50,9 +51,9 @@ public:
ColorMask(bool r, bool g, bool b) : r(r), g(g), b(b) {} ColorMask(bool r, bool g, bool b) : r(r), g(g), b(b) {}
ColorMask inverse() const { return ColorMask(!r, !g, !b); } ColorMask inverse() const { return ColorMask(!r, !g, !b); }
GLboolean r; bool r;
GLboolean g; bool g;
GLboolean b; bool b;
}; };
@ -60,8 +61,14 @@ class AnaglyphLeftPose : public LeftEyePose
{ {
public: public:
AnaglyphLeftPose(const ColorMask& colorMask, float ipd) : LeftEyePose(ipd), colorMask(colorMask) {} AnaglyphLeftPose(const ColorMask& colorMask, float ipd) : LeftEyePose(ipd), colorMask(colorMask) {}
virtual void SetUp() const { glColorMask(colorMask.r, colorMask.g, colorMask.b, true); } virtual void SetUp() const {
virtual void TearDown() const { glColorMask(1,1,1,1); } gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
gl_RenderState.ApplyColorMask();
}
virtual void TearDown() const {
gl_RenderState.ResetColorMask();
gl_RenderState.ApplyColorMask();
}
private: private:
ColorMask colorMask; ColorMask colorMask;
}; };
@ -70,8 +77,14 @@ class AnaglyphRightPose : public RightEyePose
{ {
public: public:
AnaglyphRightPose(const ColorMask& colorMask, float ipd) : RightEyePose(ipd), colorMask(colorMask) {} AnaglyphRightPose(const ColorMask& colorMask, float ipd) : RightEyePose(ipd), colorMask(colorMask) {}
virtual void SetUp() const { glColorMask(colorMask.r, colorMask.g, colorMask.b, true); } virtual void SetUp() const {
virtual void TearDown() const { glColorMask(1,1,1,1); } gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
gl_RenderState.ApplyColorMask();
}
virtual void TearDown() const {
gl_RenderState.ResetColorMask();
gl_RenderState.ApplyColorMask();
}
private: private:
ColorMask colorMask; ColorMask colorMask;
}; };

View file

@ -44,16 +44,18 @@
class ScopedColorMask class ScopedColorMask
{ {
public: public:
ScopedColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) ScopedColorMask(bool r, bool g, bool b, bool a)
{ {
glGetBooleanv(GL_COLOR_WRITEMASK, saved); gl_RenderState.GetColorMask(saved[0], saved[1], saved[2], saved[3]);
glColorMask(r, g, b, a); gl_RenderState.SetColorMask(r, g, b, a);
gl_RenderState.ApplyColorMask();
} }
~ScopedColorMask() { ~ScopedColorMask() {
glColorMask(saved[0], saved[1], saved[2], saved[3]); gl_RenderState.SetColorMask(saved[0], saved[1], saved[2], saved[3]);
gl_RenderState.ApplyColorMask();
} }
private: private:
GLboolean saved[4]; bool saved[4];
}; };