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
|
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 const char *s_dirLightUniformColorName = "u_DirLightSourceColor";
|
||||||
static std::vector<Vec3> s_dirLightUniformColorValues;
|
static std::vector<Vec3> s_dirLightUniformColorValues;
|
||||||
static const char *s_dirLightUniformDirName = "u_DirLightSourceDirection";
|
static const char *s_dirLightUniformDirName = "u_DirLightSourceDirection";
|
||||||
|
@ -185,46 +179,48 @@ MeshCommand::~MeshCommand()
|
||||||
|
|
||||||
void MeshCommand::applyRenderState()
|
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);
|
glEnable(GL_CULL_FACE);
|
||||||
s_cullFaceEnabled = true;
|
|
||||||
}
|
}
|
||||||
if (s_cullFace != _cullFace)
|
|
||||||
{
|
glCullFace(_cullFace);
|
||||||
glCullFace(_cullFace);
|
|
||||||
s_cullFace = _cullFace;
|
if (_depthTestEnabled && !_renderStateDepthTest)
|
||||||
}
|
|
||||||
if (_depthTestEnabled && !s_depthTestEnabled)
|
|
||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
s_depthTestEnabled = true;
|
|
||||||
}
|
}
|
||||||
if (_depthWriteEnabled && !s_depthWriteEnabled)
|
if (_depthWriteEnabled && !_renderStateDepthWrite)
|
||||||
{
|
{
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
s_depthWriteEnabled = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshCommand::restoreRenderState()
|
void MeshCommand::restoreRenderState()
|
||||||
{
|
{
|
||||||
if (s_cullFaceEnabled)
|
if (_renderStateCullFace)
|
||||||
|
{
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
s_cullFaceEnabled = false;
|
|
||||||
}
|
}
|
||||||
if (s_depthTestEnabled)
|
|
||||||
|
if (_renderStateDepthTest)
|
||||||
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
s_depthTestEnabled = false;
|
|
||||||
}
|
}
|
||||||
if (s_depthWriteEnabled)
|
|
||||||
{
|
glDepthMask(_renderStateDepthTest);
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
s_depthWriteEnabled = false;
|
|
||||||
}
|
|
||||||
s_cullFace = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshCommand::genMaterialID(GLuint texID, void* glProgramState, GLuint vertexBuffer, GLuint indexBuffer, const BlendFunc& blend)
|
void MeshCommand::genMaterialID(GLuint texID, void* glProgramState, GLuint vertexBuffer, GLuint indexBuffer, const BlendFunc& blend)
|
||||||
|
|
|
@ -127,6 +127,10 @@ protected:
|
||||||
GLenum _cullFace;
|
GLenum _cullFace;
|
||||||
bool _depthTestEnabled;
|
bool _depthTestEnabled;
|
||||||
bool _depthWriteEnabled;
|
bool _depthWriteEnabled;
|
||||||
|
|
||||||
|
bool _renderStateCullFace;
|
||||||
|
bool _renderStateDepthTest;
|
||||||
|
GLboolean _renderStateDepthWrite;
|
||||||
|
|
||||||
// ModelView transform
|
// ModelView transform
|
||||||
Mat4 _mv;
|
Mat4 _mv;
|
||||||
|
|
Loading…
Reference in New Issue