metal renderer: optimize SDL_RenderFillRect slightly.

This commit is contained in:
Alex Szpakowski 2019-08-18 10:38:32 -03:00
parent ff7888e698
commit bfdb0e9743

View File

@ -1403,17 +1403,21 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
const size_t count = cmd->data.draw.count; const size_t count = cmd->data.draw.count;
const size_t maxcount = UINT16_MAX / 4; const size_t maxcount = UINT16_MAX / 4;
SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache); SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache);
/* Our index buffer has 16 bit indices, so we can only draw 65k if (count == 1) {
* vertices (16k rects) at a time. */ [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
for (size_t i = 0; i < count; i += maxcount) { } else {
/* Set the vertex buffer offset for our current positions. /* Our index buffer has 16 bit indices, so we can only draw
* The vertex buffer itself was bound in SetDrawState. */ * 65k vertices (16k rects) at a time. */
[data.mtlcmdencoder setVertexBufferOffset:cmd->data.draw.first + i*sizeof(float)*8 atIndex:0]; for (size_t i = 0; i < count; i += maxcount) {
[data.mtlcmdencoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle /* Set the vertex buffer offset for our current positions.
indexCount:SDL_min(maxcount, count - i) * 6 * The vertex buffer itself was bound in SetDrawState. */
indexType:MTLIndexTypeUInt16 [data.mtlcmdencoder setVertexBufferOffset:cmd->data.draw.first + i*sizeof(float)*8 atIndex:0];
indexBuffer:data.mtlbufquadindices [data.mtlcmdencoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexBufferOffset:0]; indexCount:SDL_min(maxcount, count - i) * 6
indexType:MTLIndexTypeUInt16
indexBuffer:data.mtlbufquadindices
indexBufferOffset:0];
}
} }
break; break;
} }