opengl: Use GL_LINE_STRIP instead of breaking down into seperate GL_LINES. Surely GL drivers have improved in the last seven years. I hope...?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 3b10ed0..f749ce3 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -851,21 +851,21 @@ GL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
static int
GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
- GLfloat *verts;
int i;
-
- SDL_assert(count >= 2); /* should have been checked at the higher level. */
-
- verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, (count-1) * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
+ 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;
- /* GL_LINE_STRIP seems to be unreliable on various drivers, so try
- to build out our own GL_LINES. :(
- If the line segment is completely horizontal or vertical,
+ /* Offset to hit the center of the pixel. */
+ for (i = 0; i < count; i++) {
+ *(verts++) = 0.5f + points[i].x;
+ *(verts++) = 0.5f + points[i].y;
+ }
+
+ /* If the line segment is completely horizontal or vertical,
make it one pixel longer, to satisfy the diamond-exit rule.
We should probably do this for diagonal lines too, but we'd have to
do some trigonometry to figure out the correct pixel and generally
@@ -873,30 +873,19 @@ GL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPo
that are missing a pixel that frames something and not arbitrary
angles. Maybe !!! FIXME for later, though. */
- for (i = 0; i < count-1; i++, points++) {
- GLfloat xstart = 0.5f + points[0].x; /* 0.5f to get to the center of the pixel. */
- GLfloat ystart = 0.5f + points[0].y;
- GLfloat xend = 0.5f + points[1].x;
- GLfloat yend = 0.5f + points[1].y;
-
- if (xstart == xend) { /* vertical line */
- if (yend > ystart) {
- yend += 1.0f;
- } else {
- ystart += 1.0f;
- }
- } else if (ystart == yend) { /* horizontal line */
- if (xend > xstart) {
- xend += 1.0f;
- } else {
- xstart += 1.0f;
- }
+ /* update the last line. */
+ verts -= 4;
+ {
+ const GLfloat xstart = verts[0];
+ const GLfloat ystart = verts[1];
+ const GLfloat xend = verts[2];
+ const GLfloat yend = verts[3];
+
+ if (ystart == yend) { /* horizontal line */
+ verts[2] += (xend > xstart) ? 1.0f : -1.0f;
+ } else if (xstart == xend) { /* vertical line */
+ verts[3] += (yend > ystart) ? 1.0f : -1.0f;
}
-
- *(verts++) = xstart;
- *(verts++) = ystart;
- *(verts++) = xend;
- *(verts++) = yend;
}
return 0;
@@ -1267,10 +1256,9 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
const size_t count = cmd->data.draw.count;
SDL_assert(count >= 2);
SetDrawState(data, cmd, SHADER_SOLID);
- data->glBegin(GL_LINES);
- for (i = 0; i < count-1; ++i, verts += 4) {
+ data->glBegin(GL_LINE_STRIP);
+ for (i = 0; i < count; ++i, verts += 2) {
data->glVertex2f(verts[0], verts[1]);
- data->glVertex2f(verts[2], verts[3]);
}
data->glEnd();
break;
diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c
index 387acf3..40648d1 100644
--- a/src/render/opengles/SDL_render_gles.c
+++ b/src/render/opengles/SDL_render_gles.c
@@ -564,21 +564,21 @@ GLES_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
static int
GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
- GLfloat *verts;
int i;
-
- SDL_assert(count >= 2); /* should have been checked at the higher level. */
-
- verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, (count-1) * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
+ 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;
- /* GL_LINE_STRIP seems to be unreliable on various drivers, so try
- to build out our own GL_LINES. :(
- If the line segment is completely horizontal or vertical,
+ /* Offset to hit the center of the pixel. */
+ for (i = 0; i < count; i++) {
+ *(verts++) = 0.5f + points[i].x;
+ *(verts++) = 0.5f + points[i].y;
+ }
+
+ /* If the line segment is completely horizontal or vertical,
make it one pixel longer, to satisfy the diamond-exit rule.
We should probably do this for diagonal lines too, but we'd have to
do some trigonometry to figure out the correct pixel and generally
@@ -586,30 +586,19 @@ GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
that are missing a pixel that frames something and not arbitrary
angles. Maybe !!! FIXME for later, though. */
- for (i = 0; i < count-1; i++, points++) {
- GLfloat xstart = 0.5f + points[0].x; /* 0.5f to get to the center of the pixel. */
- GLfloat ystart = 0.5f + points[0].y;
- GLfloat xend = 0.5f + points[1].x;
- GLfloat yend = 0.5f + points[1].y;
-
- if (xstart == xend) { /* vertical line */
- if (yend > ystart) {
- yend += 1.0f;
- } else {
- ystart += 1.0f;
- }
- } else if (ystart == yend) { /* horizontal line */
- if (xend > xstart) {
- xend += 1.0f;
- } else {
- xstart += 1.0f;
- }
+ /* update the last line. */
+ verts -= 4;
+ {
+ const GLfloat xstart = verts[0];
+ const GLfloat ystart = verts[1];
+ const GLfloat xend = verts[2];
+ const GLfloat yend = verts[3];
+
+ if (ystart == yend) { /* horizontal line */
+ verts[2] += (xend > xstart) ? 1.0f : -1.0f;
+ } else if (xstart == xend) { /* vertical line */
+ verts[3] += (yend > ystart) ? 1.0f : -1.0f;
}
-
- *(verts++) = xstart;
- *(verts++) = ystart;
- *(verts++) = xend;
- *(verts++) = yend;
}
return 0;
@@ -958,7 +947,7 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
SDL_assert(count >= 2);
SetDrawState(data, cmd);
data->glVertexPointer(2, GL_FLOAT, 0, verts);
- data->glDrawArrays(GL_LINES, 0, (GLsizei) ((count-1) * 2));
+ data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) ((count-1) * 2));
break;
}
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 0a432e0..eda52f0 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -786,21 +786,21 @@ GLES2_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
static int
GLES2_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
{
- GLfloat *verts;
int i;
-
- SDL_assert(count >= 2); /* should have been checked at the higher level. */
-
- verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, (count-1) * 4 * sizeof (GLfloat), 0, &cmd->data.draw.first);
+ 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;
- /* GL_LINE_STRIP seems to be unreliable on various drivers, so try
- to build out our own GL_LINES. :(
- If the line segment is completely horizontal or vertical,
+ /* Offset to hit the center of the pixel. */
+ for (i = 0; i < count; i++) {
+ *(verts++) = 0.5f + points[i].x;
+ *(verts++) = 0.5f + points[i].y;
+ }
+
+ /* If the line segment is completely horizontal or vertical,
make it one pixel longer, to satisfy the diamond-exit rule.
We should probably do this for diagonal lines too, but we'd have to
do some trigonometry to figure out the correct pixel and generally
@@ -808,30 +808,19 @@ GLES2_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
that are missing a pixel that frames something and not arbitrary
angles. Maybe !!! FIXME for later, though. */
- for (i = 0; i < count-1; i++, points++) {
- GLfloat xstart = 0.5f + points[0].x; /* 0.5f to get to the center of the pixel. */
- GLfloat ystart = 0.5f + points[0].y;
- GLfloat xend = 0.5f + points[1].x;
- GLfloat yend = 0.5f + points[1].y;
-
- if (xstart == xend) { /* vertical line */
- if (yend > ystart) {
- yend += 1.0f;
- } else {
- ystart += 1.0f;
- }
- } else if (ystart == yend) { /* horizontal line */
- if (xend > xstart) {
- xend += 1.0f;
- } else {
- xstart += 1.0f;
- }
+ /* update the last line. */
+ verts -= 4;
+ {
+ const GLfloat xstart = verts[0];
+ const GLfloat ystart = verts[1];
+ const GLfloat xend = verts[2];
+ const GLfloat yend = verts[3];
+
+ if (ystart == yend) { /* horizontal line */
+ verts[2] += (xend > xstart) ? 1.0f : -1.0f;
+ } else if (xstart == xend) { /* vertical line */
+ verts[3] += (yend > ystart) ? 1.0f : -1.0f;
}
-
- *(verts++) = xstart;
- *(verts++) = ystart;
- *(verts++) = xend;
- *(verts++) = yend;
}
return 0;
@@ -1351,7 +1340,7 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
const size_t count = cmd->data.draw.count;
SDL_assert(count >= 2);
if (SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID) == 0) {
- data->glDrawArrays(GL_LINES, 0, (GLsizei) ((count-1) * 2));
+ data->glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) ((count-1) * 2));
}
break;
}