Merge pull request #10274 from darkdukey/forceDepthTest

Force depth test
This commit is contained in:
minggo 2015-01-29 16:29:13 +08:00
commit 73e8026336
3 changed files with 56 additions and 2 deletions

View File

@ -83,6 +83,10 @@ MeshCommand::MeshCommand()
, _cullFace(GL_BACK)
, _depthTestEnabled(false)
, _depthWriteEnabled(false)
, _forceDepthWrite(false)
, _renderStateCullFace(false)
, _renderStateDepthTest(false)
, _renderStateDepthWrite(GL_FALSE)
, _lightMask(-1)
{
_type = RenderCommand::Type::MESH_COMMAND;
@ -168,7 +172,11 @@ void MeshCommand::setTransparent(bool value)
//Skip batching for transparent mesh
_skipBatching = value;
if (!_forceDepthWrite)
if (_isTransparent && !_forceDepthWrite)
{
_depthWriteEnabled = false;
}
else
{
_depthWriteEnabled = true;
}

View File

@ -70,7 +70,8 @@ static std::function<Layer*()> createFunctions[] =
CL(Sprite3DMirrorTest),
CL(QuaternionTest),
CL(Sprite3DEmptyTest),
CL(UseCaseSprite3D)
CL(UseCaseSprite3D),
CL(Sprite3DForceDepthTest)
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
@ -156,6 +157,42 @@ void Sprite3DTestDemo::backCallback(Ref* sender)
s->release();
}
//------------------------------------------------------------------
//
// Sprite3DForceDepthTest
//
//------------------------------------------------------------------
Sprite3DForceDepthTest::Sprite3DForceDepthTest()
{
auto orc = Sprite3D::create("Sprite3DTest/orc.c3b");
orc->setScale(5);
orc->setNormalizedPosition(Vec2(.5,.3));
orc->setPositionZ(40);
orc->setRotation3D(Vec3(0,180,0));
orc->setGlobalZOrder(-1);
addChild(orc);
auto ship = Sprite3D::create("Sprite3DTest/boss1.obj");
ship->setScale(5);
ship->setTexture("Sprite3DTest/boss.png");
ship->setNormalizedPosition(Vec2(.5,.5));
ship->setRotation3D(Vec3(90,0,0));
ship->setForceDepthWrite(true);
addChild(ship);
}
std::string Sprite3DForceDepthTest::title() const
{
return "Force Depth Write Error Test";
}
std::string Sprite3DForceDepthTest::subtitle() const
{
return "Ship should always appear behind orc";
}
//------------------------------------------------------------------
//
// Sprite3DEmptyTest

View File

@ -54,6 +54,15 @@ public:
virtual void onEnter() override;
};
class Sprite3DForceDepthTest : public Sprite3DTestDemo
{
public:
CREATE_FUNC(Sprite3DForceDepthTest);
Sprite3DForceDepthTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class Sprite3DEmptyTest : public Sprite3DTestDemo
{
public: