mirror of https://github.com/encounter/SDL.git
Remove FillRects from back-end, where RenderGeometry can be used
This commit is contained in:
parent
70b10c753d
commit
f02ad2820f
|
@ -831,52 +831,6 @@ D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
|
||||
const size_t vertslen = count * sizeof (Vertex) * 4;
|
||||
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_memset(verts, '\0', vertslen);
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
const SDL_FRect *rect = &rects[i];
|
||||
const float minx = rect->x;
|
||||
const float maxx = rect->x + rect->w;
|
||||
const float miny = rect->y;
|
||||
const float maxy = rect->y + rect->h;
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = miny;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = miny;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = maxy;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = maxy;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
|
||||
|
@ -1277,23 +1231,8 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t first = cmd->data.draw.first;
|
||||
SetDrawState(data, cmd);
|
||||
if (vbo) {
|
||||
size_t offset = 0;
|
||||
for (i = 0; i < count; ++i, offset += 4) {
|
||||
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
|
||||
}
|
||||
} else {
|
||||
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
|
||||
for (i = 0; i < count; ++i, verts += 4) {
|
||||
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
|
||||
}
|
||||
}
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
@ -1622,7 +1561,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = D3D_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = D3D_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = D3D_QueueDrawPoints; /* lines and points queue vertices the same way. */
|
||||
renderer->QueueFillRects = D3D_QueueFillRects;
|
||||
renderer->QueueGeometry = D3D_QueueGeometry;
|
||||
renderer->RunCommandQueue = D3D_RunCommandQueue;
|
||||
renderer->RenderReadPixels = D3D_RenderReadPixels;
|
||||
|
|
|
@ -1633,71 +1633,6 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
const float r = (float)(cmd->data.draw.r / 255.0f);
|
||||
const float g = (float)(cmd->data.draw.g / 255.0f);
|
||||
const float b = (float)(cmd->data.draw.b / 255.0f);
|
||||
const float a = (float)(cmd->data.draw.a / 255.0f);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
verts->pos.x = rects[i].x;
|
||||
verts->pos.y = rects[i].y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = rects[i].x;
|
||||
verts->pos.y = rects[i].y + rects[i].h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = rects[i].x + rects[i].w;
|
||||
verts->pos.y = rects[i].y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = rects[i].x + rects[i].w;
|
||||
verts->pos.y = rects[i].y + rects[i].h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
|
||||
|
@ -2201,19 +2136,10 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t first = cmd->data.draw.first;
|
||||
const size_t start = first / sizeof (VertexPositionColor);
|
||||
size_t offset = 0;
|
||||
D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_SOLID], 0, NULL, NULL, NULL);
|
||||
for (i = 0; i < count; i++, offset += 4) {
|
||||
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start + offset, 4);
|
||||
}
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unsued */
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
|
|
|
@ -1145,52 +1145,6 @@ METAL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
const int color = (cmd->data.draw.r << 0) | (cmd->data.draw.g << 8) | (cmd->data.draw.b << 16) | (cmd->data.draw.a << 24);
|
||||
const size_t vertlen = 4 * (2 * sizeof (float) + sizeof (int)) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
/* Quads in the following vertex order (matches the quad index buffer):
|
||||
* 1---3
|
||||
* | \ |
|
||||
* 0---2
|
||||
*/
|
||||
for (int i = 0; i < count; i++, rects++) {
|
||||
if ((rects->w <= 0.0f) || (rects->h <= 0.0f)) {
|
||||
cmd->data.draw.count--;
|
||||
} else {
|
||||
*(verts++) = rects->x;
|
||||
*(verts++) = rects->y + rects->h;
|
||||
*((int *)verts++) = color;
|
||||
|
||||
*(verts++) = rects->x;
|
||||
*(verts++) = rects->y;
|
||||
*((int *)verts++) = color;
|
||||
|
||||
*(verts++) = rects->x + rects->w;
|
||||
*(verts++) = rects->y + rects->h;
|
||||
*((int *)verts++) = color;
|
||||
|
||||
*(verts++) = rects->x + rects->w;
|
||||
*(verts++) = rects->y;
|
||||
*((int *)verts++) = color;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->data.draw.count == 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP; // nothing to do, just skip this one later.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
|
||||
|
@ -1459,33 +1413,13 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t maxcount = UINT16_MAX / 4;
|
||||
SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache);
|
||||
if (count == 1) {
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||
} else {
|
||||
/* Our index buffer has 16 bit indices, so we can only draw
|
||||
* 65k vertices (16k rects) at a time. */
|
||||
for (size_t i = 0; i < count; i += maxcount) {
|
||||
/* Set the vertex buffer offset for our current positions.
|
||||
* The vertex buffer itself was bound in SetDrawState. */
|
||||
[data.mtlcmdencoder setVertexBufferOffset:cmd->data.draw.first + i*sizeof(float)*8 atIndex:0];
|
||||
[data.mtlcmdencoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
|
||||
indexCount:SDL_min(maxcount, count - i) * 6
|
||||
indexType:MTLIndexTypeUInt16
|
||||
indexBuffer:data.mtlbufquadindices
|
||||
indexBufferOffset:0];
|
||||
}
|
||||
}
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
|
@ -1881,7 +1815,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = METAL_QueueSetDrawColor;
|
||||
renderer->QueueDrawPoints = METAL_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = METAL_QueueDrawLines;
|
||||
renderer->QueueFillRects = METAL_QueueFillRects;
|
||||
renderer->QueueGeometry = METAL_QueueGeometry;
|
||||
renderer->RunCommandQueue = METAL_RunCommandQueue;
|
||||
renderer->RenderReadPixels = METAL_RenderReadPixels;
|
||||
|
|
|
@ -979,28 +979,6 @@ GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPo
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
for (i = 0; i < count; i++) {
|
||||
const SDL_FRect *rect = &rects[i];
|
||||
*(verts++) = rect->x;
|
||||
*(verts++) = rect->y;
|
||||
*(verts++) = rect->x + rect->w;
|
||||
*(verts++) = rect->y + rect->h;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
|
||||
|
@ -1282,15 +1260,8 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SetDrawState(data, cmd, SHADER_SOLID);
|
||||
for (i = 0; i < count; ++i, verts += 4) {
|
||||
data->glRectf(verts[0], verts[1], verts[2], verts[3]);
|
||||
}
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
@ -1676,7 +1647,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = GL_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = GL_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = GL_QueueDrawLines;
|
||||
renderer->QueueFillRects = GL_QueueFillRects;
|
||||
renderer->QueueGeometry = GL_QueueGeometry;
|
||||
renderer->RunCommandQueue = GL_RunCommandQueue;
|
||||
renderer->RenderReadPixels = GL_RenderReadPixels;
|
||||
|
|
|
@ -601,37 +601,6 @@ GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 8 * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
const SDL_FRect *rect = &rects[i];
|
||||
const GLfloat minx = rect->x;
|
||||
const GLfloat maxx = rect->x + rect->w;
|
||||
const GLfloat miny = rect->y;
|
||||
const GLfloat maxy = rect->y + rect->h;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = maxy;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = maxy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
|
||||
|
@ -892,17 +861,8 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
GLsizei offset = 0;
|
||||
SetDrawState(data, cmd);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
for (i = 0; i < count; ++i, offset += 4) {
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, offset, 4);
|
||||
}
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
@ -1164,7 +1124,6 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = GLES_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = GLES_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = GLES_QueueDrawLines;
|
||||
renderer->QueueFillRects = GLES_QueueFillRects;
|
||||
renderer->QueueGeometry = GLES_QueueGeometry;
|
||||
renderer->RunCommandQueue = GLES_RunCommandQueue;
|
||||
renderer->RenderReadPixels = GLES_RenderReadPixels;
|
||||
|
|
Loading…
Reference in New Issue