Skip to content

Commit 14e8757

Browse files
committed
fix depth state
1 parent a3f0b99 commit 14e8757

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

cocos/base/CCDirector.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,20 @@ void Director::setAlphaBlending(bool on)
727727

728728
void Director::setDepthTest(bool on)
729729
{
730-
_renderer->setDepthTest(on);
730+
if (on)
731+
{
732+
_renderer->setDepthTest(true);
733+
_renderer->setDepthCompareFunction(backend::CompareFunction::LESS_EQUAL);
734+
}
735+
else
736+
_renderer->setDepthTest(false);
737+
731738
_renderer->setDepthWrite(on);
732739
}
733740

734741
void Director::setClearColor(const Color4F& clearColor)
735742
{
736743
_clearColor = clearColor;
737-
// _renderer->setClearColor(clearColor);
738744
}
739745

740746
static void GLToClipTransform(Mat4 *transformOut)

cocos/renderer/CCRenderer.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ void Renderer::processRenderCommand(RenderCommand* command)
289289
CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command");
290290
CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command");
291291
drawBatchedTriangles();
292+
293+
// TODO: should create a new buffer for it.
292294
}
293295

294296
// queue it
@@ -459,10 +461,22 @@ void Renderer::setDepthWrite(bool value)
459461
_depthStencilDescriptor.depthWriteEnabled = value;
460462
_renderPassDescriptor.needDepthAttachment = value;
461463
}
462-
bool Renderer::getDepthTest() const
464+
465+
void Renderer::setDepthCompareFunction(backend::CompareFunction func)
466+
{
467+
_depthStencilDescriptor.depthCompareFunction = func;
468+
}
469+
470+
backend::CompareFunction Renderer::getDepthCompareFunction() const
471+
{
472+
return _depthStencilDescriptor.depthCompareFunction;
473+
}
474+
475+
bool Renderer::Renderer::getDepthTest() const
463476
{
464477
return _depthStencilDescriptor.depthTestEnabled;
465478
}
479+
466480
bool Renderer::getDepthWrite() const
467481
{
468482
return _depthStencilDescriptor.depthWriteEnabled;

cocos/renderer/CCRenderer.h

+2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ class CC_DLL Renderer
209209

210210
void setDepthTest(bool value);
211211
void setDepthWrite(bool value);
212+
void setDepthCompareFunction(backend::CompareFunction func);
212213
bool getDepthTest() const;
213214
bool getDepthWrite() const;
215+
backend::CompareFunction getDepthCompareFunction() const;
214216

215217
void setStencilTest(bool value);
216218
void setStencilCompareFunction(backend::CompareFunction func, unsigned int ref, unsigned int readMask);

tests/cpp-tests/Classes/TileMapTest/TileMapTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ void TMXIsoVertexZ::onExit()
10841084
{
10851085
// At exit use any other projection.
10861086
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
1087-
Director::getInstance()->setDepthTest(false);
1087+
Director::getInstance()->setDepthTest(false);
10881088
TileDemo::onExit();
10891089
}
10901090

0 commit comments

Comments
 (0)