Fixed bug #5087: SDL_RenderGeometryRaw() passes colors as int* instead of SDL_Color*
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
diff --git a/include/SDL_render.h b/include/SDL_render.h
index eed480b..1e73547 100644
--- a/include/SDL_render.h
+++ b/include/SDL_render.h
@@ -1645,7 +1645,7 @@ extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
extern DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices);
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index d110e31..a278885 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -883,7 +883,7 @@ SDL_DYNAPI_PROC(float,SDL_GameControllerGetSensorDataRate,(SDL_GameController *a
SDL_DYNAPI_PROC(int,SDL_SetTextureUserData,(SDL_Texture *a, void *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_GetTextureUserData,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_RenderGeometry,(SDL_Renderer *a, SDL_Texture *b, const SDL_Vertex *c, int d, const int *e, int f),(a,b,c,d,e,f),return)
-SDL_DYNAPI_PROC(int,SDL_RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const int *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
+SDL_DYNAPI_PROC(int,SDL_RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_Color *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
SDL_DYNAPI_PROC(int,SDL_RenderSetVSync,(SDL_Renderer *a, int b),(a,b),return)
#if !SDL_DYNAPI_PROC_NO_VARARGS
SDL_DYNAPI_PROC(int,SDL_asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),return)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 64c2a3b..3259c4a 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -628,7 +628,7 @@ QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture * texture,
static int
QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices,
@@ -639,7 +639,8 @@ QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_GEOMETRY, texture);
if (cmd != NULL) {
retval = renderer->QueueGeometry(renderer, cmd, texture,
- xy, xy_stride, color, color_stride, uv, uv_stride,
+ xy, xy_stride,
+ (const int *)color, color_stride, uv, uv_stride,
num_vertices, indices, num_indices, size_indices,
scale_x, scale_y);
if (retval < 0) {
@@ -2648,7 +2649,9 @@ RenderDrawPointsWithRects(SDL_Renderer * renderer,
frects[i].h = renderer->scale.y;
}
- retval = QueueCmdFillRects(renderer, frects, count);
+ if (count) {
+ retval = QueueCmdFillRects(renderer, frects, count);
+ }
SDL_small_free(frects, isstack);
@@ -2720,7 +2723,9 @@ RenderDrawPointsWithRectsF(SDL_Renderer * renderer,
frects[i].h = renderer->scale.y;
}
- retval = QueueCmdFillRects(renderer, frects, count);
+ if (count) {
+ retval = QueueCmdFillRects(renderer, frects, count);
+ }
SDL_small_free(frects, isstack);
@@ -3340,7 +3345,6 @@ SDL_RenderCopyF(SDL_Renderer * renderer, SDL_Texture * texture,
const int size_indices = 4;
float minu, minv, maxu, maxv;
float minx, miny, maxx, maxy;
- int color = (texture->color.r << 0) | (texture->color.g << 8) | (texture->color.b << 16) | ((Uint32)texture->color.a << 24);
minu = (float) (real_srcrect.x) / (float) texture->w;
minv = (float) (real_srcrect.y) / (float) texture->h;
@@ -3371,7 +3375,7 @@ SDL_RenderCopyF(SDL_Renderer * renderer, SDL_Texture * texture,
xy[7] = maxy;
retval = QueueCmdGeometry(renderer, texture,
- xy, xy_stride, &color, 0 /* color_stride */, uv, uv_stride,
+ xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride,
num_vertices,
indices, num_indices, size_indices,
renderer->scale.x, renderer->scale.y);
@@ -3497,7 +3501,6 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
const float radian_angle = (float)((M_PI * angle) / 180.0);
const float s = SDL_sinf(radian_angle);
const float c = SDL_cosf(radian_angle);
- int color = (texture->color.r << 0) | (texture->color.g << 8) | (texture->color.b << 16) | ((Uint32)texture->color.a << 24);
minu = (float) (real_srcrect.x) / (float) texture->w;
minv = (float) (real_srcrect.y) / (float) texture->h;
@@ -3557,7 +3560,7 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
xy[7] = (s_minx + c_maxy) + centery;
retval = QueueCmdGeometry(renderer, texture,
- xy, xy_stride, &color, 0 /* color_stride */, uv, uv_stride,
+ xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride,
num_vertices,
indices, num_indices, size_indices,
renderer->scale.x, renderer->scale.y);
@@ -3582,15 +3585,18 @@ SDL_RenderGeometry(SDL_Renderer *renderer,
const SDL_Vertex *vertices, int num_vertices,
const int *indices, int num_indices)
{
- const float *xy = &vertices[0].position.x;
- int xy_stride = sizeof (SDL_Vertex);
- const int *color = (int *)&vertices[0].color.r;
- int color_stride = sizeof (SDL_Vertex);
- const float *uv = &vertices[0].tex_coord.x;
- int uv_stride = sizeof (SDL_Vertex);
- int size_indices = 4;
-
- return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
+ if (vertices) {
+ const float *xy = &vertices[0].position.x;
+ int xy_stride = sizeof (SDL_Vertex);
+ const SDL_Color *color = &vertices[0].color;
+ int color_stride = sizeof (SDL_Vertex);
+ const float *uv = &vertices[0].tex_coord.x;
+ int uv_stride = sizeof (SDL_Vertex);
+ int size_indices = 4;
+ return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
+ } else {
+ return SDL_InvalidParamError("vertices");
+ }
}
static int
@@ -3599,7 +3605,7 @@ remap_one_indice(
int k,
SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride)
{
const float *xy0_, *xy1_, *uv0_, *uv1_;
@@ -3638,7 +3644,7 @@ remap_indices(
int k,
SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride)
{
int i;
@@ -3661,7 +3667,7 @@ static int SDLCALL
SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices)
@@ -3940,7 +3946,7 @@ int
SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
- const int *color, int color_stride,
+ const SDL_Color *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices)