Skip to content

Commit

Permalink
Removed SDL_RenderGeometryRawFloat()
Browse files Browse the repository at this point in the history
After discussion with @orconut, SDL_RenderGeometryRaw() will take floating point colors and conversion from 8-bit color can happen on the application side.  We can always add an 8-bit color fast path in the future if we need it on handheld platforms.

If you need code to do this in your application, you can use the following:

int SDL_RenderGeometryRaw8BitColor(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_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)
{
    int i, retval, isstack;
    const Uint8 *color2 = (const Uint8 *)color;
    SDL_FColor *color3;

    if (num_vertices <= 0) {
        return SDL_InvalidParamError("num_vertices");
    }
    if (!color) {
        return SDL_InvalidParamError("color");
    }

    color3 = (SDL_FColor *)SDL_small_alloc(SDL_FColor, num_vertices, &isstack);
    if (!color3) {
        return -1;
    }

    for (i = 0; i < num_vertices; ++i) {
        color3[i].r = color->r / 255.0f;
        color3[i].g = color->g / 255.0f;
        color3[i].b = color->b / 255.0f;
        color3[i].a = color->a / 255.0f;
        color2 += color_stride;
        color = (const SDL_Color *)color2;
    }

    retval = SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);

    SDL_small_free(color3, isstack);

    return retval;
}

Fixes libsdl-org#9009
  • Loading branch information
slouken committed Jun 29, 2024
1 parent b93129c commit 5c7e80a
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 76 deletions.
36 changes: 1 addition & 35 deletions include/SDL3/SDL_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -1877,39 +1877,6 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
const SDL_Vertex *vertices, int num_vertices,
const int *indices, int num_indices);

/**
* Render a list of triangles, optionally using a texture and indices into the
* vertex arrays Color and alpha modulation is done per vertex
* (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
*
* \param renderer the rendering context.
* \param texture (optional) The SDL texture to use.
* \param xy vertex positions.
* \param xy_stride byte size to move from one element to the next element.
* \param color vertex colors (as SDL_Color).
* \param color_stride byte size to move from one element to the next element.
* \param uv vertex normalized texture coordinates.
* \param uv_stride byte size to move from one element to the next element.
* \param num_vertices number of vertices.
* \param indices (optional) An array of indices into the 'vertices' arrays,
* if NULL all vertices will be rendered in sequential order.
* \param num_indices number of indices.
* \param size_indices index size: 1 (byte), 2 (short), 4 (int).
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_RenderGeometry
*/
extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_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);

/**
* Render a list of triangles, optionally using a texture and indices into the
* vertex arrays Color and alpha modulation is done per vertex
Expand All @@ -1934,9 +1901,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_RenderGeometry
* \sa SDL_RenderGeometryRaw
*/
extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometryRawFloat(SDL_Renderer *renderer,
extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
const SDL_FColor *color, int color_stride,
Expand Down
1 change: 0 additions & 1 deletion src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ SDL3_0.0.0 {
SDL_RenderFillRects;
SDL_RenderGeometry;
SDL_RenderGeometryRaw;
SDL_RenderGeometryRawFloat;
SDL_RenderLine;
SDL_RenderLines;
SDL_RenderPoint;
Expand Down
1 change: 0 additions & 1 deletion src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@
#define SDL_RenderFillRects SDL_RenderFillRects_REAL
#define SDL_RenderGeometry SDL_RenderGeometry_REAL
#define SDL_RenderGeometryRaw SDL_RenderGeometryRaw_REAL
#define SDL_RenderGeometryRawFloat SDL_RenderGeometryRawFloat_REAL
#define SDL_RenderLine SDL_RenderLine_REAL
#define SDL_RenderLines SDL_RenderLines_REAL
#define SDL_RenderPoint SDL_RenderPoint_REAL
Expand Down
3 changes: 1 addition & 2 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,7 @@ SDL_DYNAPI_PROC(int,SDL_RenderCoordinatesToWindow,(SDL_Renderer *a, float b, flo
SDL_DYNAPI_PROC(int,SDL_RenderFillRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_RenderFillRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),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 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_RenderGeometryRawFloat,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_FColor *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_FColor *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_RenderLine,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_RenderLines,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_RenderPoint,(SDL_Renderer *a, float b, float c),(a,b,c),return)
Expand Down
38 changes: 2 additions & 36 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -3849,7 +3849,7 @@ int SDL_RenderGeometry(SDL_Renderer *renderer,
const float *uv = &vertices->tex_coord.x;
int uv_stride = sizeof(SDL_Vertex);
int size_indices = 4;
return SDL_RenderGeometryRawFloat(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
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");
}
Expand Down Expand Up @@ -4226,7 +4226,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
}
#endif /* SDL_VIDEO_RENDER_SW */

int SDL_RenderGeometryRawFloat(SDL_Renderer *renderer,
int SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
const SDL_FColor *color, int color_stride,
Expand Down Expand Up @@ -4338,40 +4338,6 @@ int SDL_RenderGeometryRawFloat(SDL_Renderer *renderer,
renderer->view->scale.y);
}

int SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_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)
{
int i, retval, isstack;
const Uint8 *color2 = (const Uint8 *)color;
SDL_FColor *color3;

if (num_vertices <= 0) {
return SDL_InvalidParamError("num_vertices");
}
if (!color) {
return SDL_InvalidParamError("color");
}

color3 = (SDL_FColor *)SDL_small_alloc(SDL_FColor, num_vertices, &isstack);
if (!color3) {
return -1;
}

for (i = 0; i < num_vertices; ++i) {
color3[i].r = color->r / 255.0f;
color3[i].g = color->g / 255.0f;
color3[i].b = color->b / 255.0f;
color3[i].a = color->a / 255.0f;
color2 += color_stride;
color = (const SDL_Color *)color2;
}

retval = SDL_RenderGeometryRawFloat(renderer, texture, xy, xy_stride, color3, sizeof(*color3), uv, uv_stride, num_vertices, indices, num_indices, size_indices);

SDL_small_free(color3, isstack);

return retval;
}

SDL_Surface *SDL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
SDL_Rect real_rect;
Expand Down
2 changes: 1 addition & 1 deletion test/testcolorspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static void DrawGradient(float x, float y, float width, float height, float star
color[2] = max_color;
color[3] = min_color;

SDL_RenderGeometryRawFloat(renderer, NULL, xy, xy_stride, color, color_stride, NULL, 0, num_vertices, indices, num_indices, size_indices);
SDL_RenderGeometryRaw(renderer, NULL, xy, xy_stride, color, color_stride, NULL, 0, num_vertices, indices, num_indices, size_indices);
}

static void RenderGradientDrawing(void)
Expand Down

0 comments on commit 5c7e80a

Please sign in to comment.