mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10225 from darkdukey/saveRenderState
save/restore render state
This commit is contained in:
commit
2be140fccc
|
@ -131,6 +131,41 @@ void RenderQueue::clear()
|
||||||
_queuePosZ.clear();
|
_queuePosZ.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderQueue::saveRenderState()
|
||||||
|
{
|
||||||
|
_isDepthEnabled = glIsEnabled(GL_DEPTH_TEST);
|
||||||
|
_isCullEnabled = glIsEnabled(GL_CULL_FACE);
|
||||||
|
glGetBooleanv(GL_DEPTH_WRITEMASK, &_isDepthWrite);
|
||||||
|
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderQueue::restoreRenderState()
|
||||||
|
{
|
||||||
|
if (_isCullEnabled)
|
||||||
|
{
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_isDepthEnabled)
|
||||||
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDepthMask(_isDepthWrite);
|
||||||
|
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -465,10 +500,12 @@ void Renderer::processRenderCommand(RenderCommand* command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::visitRenderQueue(const RenderQueue& queue)
|
void Renderer::visitRenderQueue(RenderQueue& queue)
|
||||||
{
|
{
|
||||||
ssize_t size = queue.size();
|
ssize_t size = queue.size();
|
||||||
|
|
||||||
|
queue.saveRenderState();
|
||||||
|
|
||||||
//Process Opaque Object
|
//Process Opaque Object
|
||||||
const std::vector<RenderCommand*>& opaqueQueue = queue.getOpaqueCommands();
|
const std::vector<RenderCommand*>& opaqueQueue = queue.getOpaqueCommands();
|
||||||
if (opaqueQueue.size() > 0)
|
if (opaqueQueue.size() > 0)
|
||||||
|
@ -507,6 +544,8 @@ void Renderer::visitRenderQueue(const RenderQueue& queue)
|
||||||
processRenderCommand(queue[index]);
|
processRenderCommand(queue[index]);
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
|
queue.restoreRenderState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::render()
|
void Renderer::render()
|
||||||
|
|
|
@ -57,12 +57,20 @@ public:
|
||||||
ssize_t getOpaqueQueueSize() const { return _queue3DOpaque.size(); }
|
ssize_t getOpaqueQueueSize() const { return _queue3DOpaque.size(); }
|
||||||
const std::vector<RenderCommand*>& getOpaqueCommands() const { return _queue3DOpaque; }
|
const std::vector<RenderCommand*>& getOpaqueCommands() const { return _queue3DOpaque; }
|
||||||
|
|
||||||
|
void saveRenderState();
|
||||||
|
void restoreRenderState();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<RenderCommand*> _queue3DOpaque;
|
std::vector<RenderCommand*> _queue3DOpaque;
|
||||||
std::vector<RenderCommand*> _queue3DTransparent;
|
std::vector<RenderCommand*> _queue3DTransparent;
|
||||||
std::vector<RenderCommand*> _queueNegZ;
|
std::vector<RenderCommand*> _queueNegZ;
|
||||||
std::vector<RenderCommand*> _queue0;
|
std::vector<RenderCommand*> _queue0;
|
||||||
std::vector<RenderCommand*> _queuePosZ;
|
std::vector<RenderCommand*> _queuePosZ;
|
||||||
|
|
||||||
|
//Render State related
|
||||||
|
bool _isCullEnabled;
|
||||||
|
bool _isDepthEnabled;
|
||||||
|
GLboolean _isDepthWrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenderStackElement
|
struct RenderStackElement
|
||||||
|
@ -162,7 +170,7 @@ protected:
|
||||||
void flushTriangles();
|
void flushTriangles();
|
||||||
|
|
||||||
void processRenderCommand(RenderCommand* command);
|
void processRenderCommand(RenderCommand* command);
|
||||||
void visitRenderQueue(const RenderQueue& queue);
|
void visitRenderQueue(RenderQueue& queue);
|
||||||
|
|
||||||
void fillVerticesAndIndices(const TrianglesCommand* cmd);
|
void fillVerticesAndIndices(const TrianglesCommand* cmd);
|
||||||
void fillQuads(const QuadCommand* cmd);
|
void fillQuads(const QuadCommand* cmd);
|
||||||
|
|
Loading…
Reference in New Issue