mirror of https://github.com/axmolengine/axmol.git
Not using static value to save previous render state since other commands like custom command could change them
This commit is contained in:
parent
8f539a0107
commit
c364323bbc
|
@ -42,12 +42,6 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
//render state
|
||||
static bool s_cullFaceEnabled = false;
|
||||
static GLenum s_cullFace = 0;
|
||||
static bool s_depthTestEnabled = false;
|
||||
static bool s_depthWriteEnabled = false;
|
||||
|
||||
static const char *s_dirLightUniformColorName = "u_DirLightSourceColor";
|
||||
static std::vector<Vec3> s_dirLightUniformColorValues;
|
||||
static const char *s_dirLightUniformDirName = "u_DirLightSourceDirection";
|
||||
|
@ -185,46 +179,48 @@ MeshCommand::~MeshCommand()
|
|||
|
||||
void MeshCommand::applyRenderState()
|
||||
{
|
||||
if (_cullFaceEnabled && !s_cullFaceEnabled)
|
||||
_renderStateCullFace = glIsEnabled(GL_CULL_FACE);
|
||||
_renderStateDepthTest = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, &_renderStateDepthWrite);
|
||||
|
||||
if (_cullFaceEnabled && !_renderStateCullFace)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
s_cullFaceEnabled = true;
|
||||
}
|
||||
if (s_cullFace != _cullFace)
|
||||
{
|
||||
glCullFace(_cullFace);
|
||||
s_cullFace = _cullFace;
|
||||
}
|
||||
if (_depthTestEnabled && !s_depthTestEnabled)
|
||||
|
||||
glCullFace(_cullFace);
|
||||
|
||||
if (_depthTestEnabled && !_renderStateDepthTest)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
s_depthTestEnabled = true;
|
||||
}
|
||||
if (_depthWriteEnabled && !s_depthWriteEnabled)
|
||||
if (_depthWriteEnabled && !_renderStateDepthWrite)
|
||||
{
|
||||
glDepthMask(GL_TRUE);
|
||||
s_depthWriteEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void MeshCommand::restoreRenderState()
|
||||
{
|
||||
if (s_cullFaceEnabled)
|
||||
if (_renderStateCullFace)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
s_cullFaceEnabled = false;
|
||||
}
|
||||
if (s_depthTestEnabled)
|
||||
|
||||
if (_renderStateDepthTest)
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
s_depthTestEnabled = false;
|
||||
}
|
||||
if (s_depthWriteEnabled)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
s_depthWriteEnabled = false;
|
||||
}
|
||||
s_cullFace = 0;
|
||||
|
||||
glDepthMask(_renderStateDepthTest);
|
||||
}
|
||||
|
||||
void MeshCommand::genMaterialID(GLuint texID, void* glProgramState, GLuint vertexBuffer, GLuint indexBuffer, const BlendFunc& blend)
|
||||
|
|
|
@ -127,6 +127,10 @@ protected:
|
|||
GLenum _cullFace;
|
||||
bool _depthTestEnabled;
|
||||
bool _depthWriteEnabled;
|
||||
|
||||
bool _renderStateCullFace;
|
||||
bool _renderStateDepthTest;
|
||||
GLboolean _renderStateDepthWrite;
|
||||
|
||||
// ModelView transform
|
||||
Mat4 _mv;
|
||||
|
|
Loading…
Reference in New Issue