mirror of
https://github.com/love2d/love.git
synced 2026-08-14 10:13:46 +02:00
Add (low level) functionality to allow rendering 3D Meshes.
- Add love.graphics.setDepthMode(testcomparison, enablewrites). - Add love.graphics.setMeshCullMode. - Add love.graphics.setFrontFaceWinding. Depth testing and depth writes require a depth buffer to work. The mesh cull mode controls whether front/back faces of a mesh are culled. The front face winding determines whether a clockwise or counterclockwise-oriented face in a mesh is considered front facing. --HG-- branch : minor
This commit is contained in:
@@ -374,6 +374,10 @@ void Graphics::restoreState(const DisplayState &s)
|
||||
setScissor();
|
||||
|
||||
setStencilTest(s.stencilCompare, s.stencilTestValue);
|
||||
setDepthMode(s.depthTest, s.depthWrite);
|
||||
|
||||
setMeshCullMode(s.meshCullMode);
|
||||
setFrontFaceWinding(s.winding);
|
||||
|
||||
setFont(s.font.get());
|
||||
setShader(s.shader.get());
|
||||
@@ -417,6 +421,14 @@ void Graphics::restoreStateChecked(const DisplayState &s)
|
||||
if (s.stencilCompare != cur.stencilCompare || s.stencilTestValue != cur.stencilTestValue)
|
||||
setStencilTest(s.stencilCompare, s.stencilTestValue);
|
||||
|
||||
if (s.depthTest != cur.depthTest || s.depthWrite != cur.depthWrite)
|
||||
setDepthMode(s.depthTest, s.depthWrite);
|
||||
|
||||
setMeshCullMode(s.meshCullMode);
|
||||
|
||||
if (s.winding != cur.winding)
|
||||
setFrontFaceWinding(s.winding);
|
||||
|
||||
setFont(s.font.get());
|
||||
setShader(s.shader.get());
|
||||
|
||||
@@ -788,13 +800,46 @@ bool Graphics::getScissor(Rect &rect) const
|
||||
return state.scissor;
|
||||
}
|
||||
|
||||
void Graphics::getStencilTest(CompareMode &compare, int &value)
|
||||
void Graphics::setStencilTest()
|
||||
{
|
||||
setStencilTest(COMPARE_ALWAYS, 0);
|
||||
}
|
||||
|
||||
void Graphics::getStencilTest(CompareMode &compare, int &value) const
|
||||
{
|
||||
const DisplayState &state = states.back();
|
||||
compare = state.stencilCompare;
|
||||
value = state.stencilTestValue;
|
||||
}
|
||||
|
||||
void Graphics::setDepthMode()
|
||||
{
|
||||
setDepthMode(COMPARE_ALWAYS, false);
|
||||
}
|
||||
|
||||
void Graphics::getDepthMode(CompareMode &compare, bool &write) const
|
||||
{
|
||||
const DisplayState &state = states.back();
|
||||
compare = state.depthTest;
|
||||
write = state.depthWrite;
|
||||
}
|
||||
|
||||
void Graphics::setMeshCullMode(CullMode cull)
|
||||
{
|
||||
// Handled inside the draw() graphics API implementations.
|
||||
states.back().meshCullMode = cull;
|
||||
}
|
||||
|
||||
CullMode Graphics::getMeshCullMode() const
|
||||
{
|
||||
return states.back().meshCullMode;
|
||||
}
|
||||
|
||||
vertex::Winding Graphics::getFrontFaceWinding() const
|
||||
{
|
||||
return states.back().winding;
|
||||
}
|
||||
|
||||
Graphics::ColorMask Graphics::getColorMask() const
|
||||
{
|
||||
return states.back().colorMask;
|
||||
@@ -1051,14 +1096,26 @@ void Graphics::flushStreamDraws()
|
||||
if (sbstate.indexCount > 0)
|
||||
{
|
||||
usedsizes[2] = sizeof(uint16) * sbstate.indexCount;
|
||||
size_t offset = sbstate.indexBuffer->unmap(usedsizes[2]);
|
||||
|
||||
DrawIndexedCommand cmd(&attributes, &buffers, sbstate.indexBuffer);
|
||||
cmd.primitiveType = sbstate.primitiveMode;
|
||||
cmd.indexCount = sbstate.indexCount;
|
||||
cmd.indexType = INDEX_UINT16;
|
||||
cmd.indexBufferOffset = sbstate.indexBuffer->unmap(usedsizes[2]);
|
||||
cmd.texture = sbstate.texture;
|
||||
draw(cmd);
|
||||
|
||||
sbstate.indexBufferMap = StreamBuffer::MapInfo();
|
||||
|
||||
drawIndexed(sbstate.primitiveMode, sbstate.indexCount, 1, INDEX_UINT16, sbstate.indexBuffer, offset, attributes, buffers, sbstate.texture);
|
||||
}
|
||||
else
|
||||
draw(sbstate.primitiveMode, 0, sbstate.vertexCount, 1, attributes, buffers, sbstate.texture);
|
||||
{
|
||||
DrawCommand cmd(&attributes, &buffers);
|
||||
cmd.primitiveType = sbstate.primitiveMode;
|
||||
cmd.vertexStart = 0;
|
||||
cmd.vertexCount = sbstate.vertexCount;
|
||||
cmd.texture = sbstate.texture;
|
||||
draw(cmd);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user