mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Move the implementation for Graphics::flushStreamDraws out of the opengl backend
--HG-- branch : minor
This commit is contained in:
@@ -1006,6 +1006,73 @@ Graphics::StreamVertexData Graphics::requestStreamDraw(const StreamDrawCommand &
|
||||
return d;
|
||||
}
|
||||
|
||||
void Graphics::flushStreamDraws()
|
||||
{
|
||||
using namespace vertex;
|
||||
|
||||
auto &sbstate = streamBufferState;
|
||||
|
||||
if (sbstate.vertexCount == 0 && sbstate.indexCount == 0)
|
||||
return;
|
||||
|
||||
Attributes attributes;
|
||||
Buffers buffers;
|
||||
|
||||
size_t usedsizes[3] = {0, 0, 0};
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (sbstate.formats[i] == CommonFormat::NONE)
|
||||
continue;
|
||||
|
||||
attributes.setCommonFormat(sbstate.formats[i], (uint8) i);
|
||||
|
||||
usedsizes[i] = getFormatStride(sbstate.formats[i]) * sbstate.vertexCount;
|
||||
|
||||
size_t offset = sbstate.vb[i]->unmap(usedsizes[i]);
|
||||
buffers.set(i, sbstate.vb[i], offset);
|
||||
sbstate.vbMap[i] = StreamBuffer::MapInfo();
|
||||
}
|
||||
|
||||
if (attributes.enablebits == 0)
|
||||
return;
|
||||
|
||||
Colorf nc = getColor();
|
||||
if (attributes.isEnabled(ATTRIB_COLOR))
|
||||
setColor(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
pushIdentityTransform();
|
||||
|
||||
if (sbstate.indexCount > 0)
|
||||
{
|
||||
usedsizes[2] = sizeof(uint16) * sbstate.indexCount;
|
||||
size_t offset = sbstate.indexBuffer->unmap(usedsizes[2]);
|
||||
|
||||
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);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (usedsizes[i] > 0)
|
||||
sbstate.vb[i]->markUsed(usedsizes[i]);
|
||||
}
|
||||
|
||||
if (usedsizes[2] > 0)
|
||||
sbstate.indexBuffer->markUsed(usedsizes[2]);
|
||||
|
||||
popTransform();
|
||||
|
||||
if (attributes.isEnabled(ATTRIB_COLOR))
|
||||
setColor(nc);
|
||||
|
||||
streamBufferState.vertexCount = 0;
|
||||
streamBufferState.indexCount = 0;
|
||||
}
|
||||
|
||||
void Graphics::flushStreamDrawsGlobal()
|
||||
{
|
||||
Graphics *instance = getInstance<Graphics>(M_GRAPHICS);
|
||||
|
||||
@@ -762,7 +762,7 @@ public:
|
||||
virtual void draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) = 0;
|
||||
virtual void drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) = 0;
|
||||
|
||||
virtual void flushStreamDraws() = 0;
|
||||
void flushStreamDraws();
|
||||
StreamVertexData requestStreamDraw(const StreamDrawCommand &command);
|
||||
|
||||
static void flushStreamDrawsGlobal();
|
||||
|
||||
@@ -316,84 +316,6 @@ void Graphics::setActive(bool enable)
|
||||
active = enable;
|
||||
}
|
||||
|
||||
void Graphics::flushStreamDraws()
|
||||
{
|
||||
using namespace vertex;
|
||||
|
||||
auto &sbstate = streamBufferState;
|
||||
|
||||
if (sbstate.vertexCount == 0 && sbstate.indexCount == 0)
|
||||
return;
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Stream vertices flush and draw");
|
||||
|
||||
Attributes attributes;
|
||||
Buffers buffers;
|
||||
|
||||
size_t usedsizes[3] = {0, 0, 0};
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (sbstate.formats[i] == CommonFormat::NONE)
|
||||
continue;
|
||||
|
||||
attributes.setCommonFormat(sbstate.formats[i], (uint8) i);
|
||||
|
||||
usedsizes[i] = getFormatStride(sbstate.formats[i]) * sbstate.vertexCount;
|
||||
|
||||
size_t offset = sbstate.vb[i]->unmap(usedsizes[i]);
|
||||
buffers.set(i, sbstate.vb[i], offset);
|
||||
sbstate.vbMap[i] = StreamBuffer::MapInfo();
|
||||
}
|
||||
|
||||
if (attributes.enablebits == 0)
|
||||
return;
|
||||
|
||||
Colorf nc = gl.getConstantColor();
|
||||
if (attributes.isEnabled(ATTRIB_COLOR))
|
||||
gl.setConstantColor(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
pushIdentityTransform();
|
||||
|
||||
gl.prepareDraw();
|
||||
gl.bindTextureToUnit(sbstate.texture, 0, false);
|
||||
|
||||
gl.setVertexAttributes(attributes, buffers);
|
||||
|
||||
GLenum glprimitivetype = OpenGL::getGLPrimitiveType(sbstate.primitiveMode);
|
||||
|
||||
if (sbstate.indexCount > 0)
|
||||
{
|
||||
usedsizes[2] = sizeof(uint16) * sbstate.indexCount;
|
||||
|
||||
gl.bindBuffer(BUFFER_INDEX, (GLuint) sbstate.indexBuffer->getHandle());
|
||||
size_t offset = sbstate.indexBuffer->unmap(usedsizes[2]);
|
||||
|
||||
sbstate.indexBufferMap = StreamBuffer::MapInfo();
|
||||
|
||||
gl.drawElements(glprimitivetype, sbstate.indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(offset));
|
||||
}
|
||||
else
|
||||
gl.drawArrays(glprimitivetype, 0, sbstate.vertexCount);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (usedsizes[i] > 0)
|
||||
sbstate.vb[i]->markUsed(usedsizes[i]);
|
||||
}
|
||||
|
||||
if (usedsizes[2] > 0)
|
||||
sbstate.indexBuffer->markUsed(usedsizes[2]);
|
||||
|
||||
popTransform();
|
||||
|
||||
if (attributes.isEnabled(ATTRIB_COLOR))
|
||||
gl.setConstantColor(nc);
|
||||
|
||||
streamBufferState.vertexCount = 0;
|
||||
streamBufferState.indexCount = 0;
|
||||
}
|
||||
|
||||
void Graphics::draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, love::graphics::Texture *texture)
|
||||
{
|
||||
gl.prepareDraw();
|
||||
|
||||
@@ -69,8 +69,6 @@ public:
|
||||
|
||||
void setActive(bool active) override;
|
||||
|
||||
void flushStreamDraws() override;
|
||||
|
||||
void draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) override;
|
||||
void drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user