Re-enable line drawing path in render drivers

This is still used for scaled line drawing in RenderDrawLinesWithRects()
This commit is contained in:
Sam Lantinga 2022-01-08 09:02:25 -08:00
parent dca281e810
commit 18e4d9fed1
7 changed files with 301 additions and 12 deletions

View file

@ -941,6 +941,47 @@ GL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
return 0;
}
static int
GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
int i;
GLfloat prevx, prevy;
const size_t vertlen = (sizeof (GLfloat) * 2) * count;
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
if (!verts) {
return -1;
}
cmd->data.draw.count = count;
/* 0.5f offset to hit the center of the pixel. */
prevx = 0.5f + points->x;
prevy = 0.5f + points->y;
*(verts++) = prevx;
*(verts++) = prevy;
/* bump the end of each line segment out a quarter of a pixel, to provoke
the diamond-exit rule. Without this, you won't just drop the last
pixel of the last line segment, but you might also drop pixels at the
edge of any given line segment along the way too. */
for (i = 1; i < count; i++) {
const GLfloat xstart = prevx;
const GLfloat ystart = prevy;
const GLfloat xend = points[i].x + 0.5f; /* 0.5f to hit pixel center. */
const GLfloat yend = points[i].y + 0.5f;
/* bump a little in the direction we are moving in. */
const GLfloat deltax = xend - xstart;
const GLfloat deltay = yend - ystart;
const GLfloat angle = SDL_atan2f(deltay, deltax);
prevx = xend + (SDL_cosf(angle) * 0.25f);
prevy = yend + (SDL_sinf(angle) * 0.25f);
*(verts++) = prevx;
*(verts++) = prevy;
}
return 0;
}
static int
GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
@ -1070,6 +1111,7 @@ SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const GL_Shader
}
vertex_array = cmd->command == SDL_RENDERCMD_DRAW_POINTS
|| cmd->command == SDL_RENDERCMD_DRAW_LINES
|| cmd->command == SDL_RENDERCMD_GEOMETRY;
color_array = cmd->command == SDL_RENDERCMD_GEOMETRY;
texture_array = cmd->data.draw.texture != NULL;
@ -1244,8 +1286,17 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
break;
}
case SDL_RENDERCMD_DRAW_LINES: /* unused */
case SDL_RENDERCMD_DRAW_LINES: {
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
const size_t count = cmd->data.draw.count;
SDL_assert(count >= 2);
SetDrawState(data, cmd, SHADER_SOLID);
/* SetDrawState handles glEnableClientState. */
data->glVertexPointer(2, GL_FLOAT, sizeof(float) * 2, verts);
data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) count);
break;
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
@ -1643,6 +1694,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueSetViewport = GL_QueueSetViewport;
renderer->QueueSetDrawColor = GL_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = GL_QueueDrawPoints;
renderer->QueueDrawLines = GL_QueueDrawLines;
renderer->QueueGeometry = GL_QueueGeometry;
renderer->RunCommandQueue = GL_RunCommandQueue;
renderer->RenderReadPixels = GL_RenderReadPixels;