mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-12 07:34:36 +00:00
Use gl_RenderState to manipulate OpenGL color mask for anaglyph modes, to avoid glGet...
This commit is contained in:
parent
95f4134630
commit
ac6e2f4979
4 changed files with 71 additions and 12 deletions
|
@ -70,6 +70,8 @@ void FRenderState::Reset()
|
|||
{
|
||||
mTextureEnabled = true;
|
||||
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;
|
||||
mTextureMode = -1;
|
||||
mLightIndex = -1;
|
||||
|
@ -257,6 +259,8 @@ void FRenderState::Apply()
|
|||
}
|
||||
}
|
||||
|
||||
ApplyColorMask();
|
||||
|
||||
if (mVertexBuffer != mCurrentVertexBuffer)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (GLRenderer->mShaderManager != NULL)
|
||||
|
|
|
@ -47,6 +47,8 @@ class FRenderState
|
|||
bool mFogEnabled;
|
||||
bool mGlowEnabled;
|
||||
bool mBrightmapEnabled;
|
||||
bool mColorMask[4];
|
||||
bool currentColorMask[4];
|
||||
int mLightIndex;
|
||||
int mSpecialEffect;
|
||||
int mTextureMode;
|
||||
|
@ -116,6 +118,7 @@ public:
|
|||
}
|
||||
|
||||
void Apply();
|
||||
void ApplyColorMask();
|
||||
void ApplyMatrices();
|
||||
void ApplyLightIndex(int index);
|
||||
|
||||
|
@ -174,6 +177,28 @@ public:
|
|||
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)
|
||||
{
|
||||
mTextureMode = mode;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "gl_stereo3d.h"
|
||||
#include "gl_stereo_leftright.h"
|
||||
#include "gl/system/gl_system.h"
|
||||
#include "gl/renderer/gl_renderstate.h"
|
||||
|
||||
|
||||
namespace s3d {
|
||||
|
@ -50,9 +51,9 @@ public:
|
|||
ColorMask(bool r, bool g, bool b) : r(r), g(g), b(b) {}
|
||||
ColorMask inverse() const { return ColorMask(!r, !g, !b); }
|
||||
|
||||
GLboolean r;
|
||||
GLboolean g;
|
||||
GLboolean b;
|
||||
bool r;
|
||||
bool g;
|
||||
bool b;
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,8 +61,14 @@ class AnaglyphLeftPose : public LeftEyePose
|
|||
{
|
||||
public:
|
||||
AnaglyphLeftPose(const ColorMask& colorMask, float ipd) : LeftEyePose(ipd), colorMask(colorMask) {}
|
||||
virtual void SetUp() const { glColorMask(colorMask.r, colorMask.g, colorMask.b, true); }
|
||||
virtual void TearDown() const { glColorMask(1,1,1,1); }
|
||||
virtual void SetUp() const {
|
||||
gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
|
||||
gl_RenderState.ApplyColorMask();
|
||||
}
|
||||
virtual void TearDown() const {
|
||||
gl_RenderState.ResetColorMask();
|
||||
gl_RenderState.ApplyColorMask();
|
||||
}
|
||||
private:
|
||||
ColorMask colorMask;
|
||||
};
|
||||
|
@ -70,8 +77,14 @@ class AnaglyphRightPose : public RightEyePose
|
|||
{
|
||||
public:
|
||||
AnaglyphRightPose(const ColorMask& colorMask, float ipd) : RightEyePose(ipd), colorMask(colorMask) {}
|
||||
virtual void SetUp() const { glColorMask(colorMask.r, colorMask.g, colorMask.b, true); }
|
||||
virtual void TearDown() const { glColorMask(1,1,1,1); }
|
||||
virtual void SetUp() const {
|
||||
gl_RenderState.SetColorMask(colorMask.r, colorMask.g, colorMask.b, true);
|
||||
gl_RenderState.ApplyColorMask();
|
||||
}
|
||||
virtual void TearDown() const {
|
||||
gl_RenderState.ResetColorMask();
|
||||
gl_RenderState.ApplyColorMask();
|
||||
}
|
||||
private:
|
||||
ColorMask colorMask;
|
||||
};
|
||||
|
|
|
@ -44,16 +44,18 @@
|
|||
class ScopedColorMask
|
||||
{
|
||||
public:
|
||||
ScopedColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
|
||||
ScopedColorMask(bool r, bool g, bool b, bool a)
|
||||
{
|
||||
glGetBooleanv(GL_COLOR_WRITEMASK, saved);
|
||||
glColorMask(r, g, b, a);
|
||||
gl_RenderState.GetColorMask(saved[0], saved[1], saved[2], saved[3]);
|
||||
gl_RenderState.SetColorMask(r, g, b, a);
|
||||
gl_RenderState.ApplyColorMask();
|
||||
}
|
||||
~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:
|
||||
GLboolean saved[4];
|
||||
bool saved[4];
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue