diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index f7731ca4f..2489b3d38 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -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(M_GRAPHICS); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 7bb497685..0eef69fdc 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -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(); diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index a6f53f640..153394b0a 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -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(); diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 4bf34b200..cc9cbe1b4 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -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;