mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-18 18:58:27 +00:00
Use SDL_Color for SDL_RenderGeometryRaw() and add SDL_RenderGeometryRawFloat()
Eventually we can re-add a fast path for that data down to the individual renderers. Setting color scale would still require converting to float, and most hardware accelerated renderers prefer to consume colors as float, so this requires some thought and performance testing. Fixes https://github.com/libsdl-org/SDL/issues/9009
This commit is contained in:
parent
9e194c1a1d
commit
3158342441
7 changed files with 77 additions and 6 deletions
|
@ -3704,7 +3704,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_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
|
||||
return SDL_RenderGeometryRawFloat(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
|
||||
} else {
|
||||
return SDL_InvalidParamError("vertices");
|
||||
}
|
||||
|
@ -4079,7 +4079,7 @@ end:
|
|||
return retval;
|
||||
}
|
||||
|
||||
int SDL_RenderGeometryRaw(SDL_Renderer *renderer,
|
||||
int SDL_RenderGeometryRawFloat(SDL_Renderer *renderer,
|
||||
SDL_Texture *texture,
|
||||
const float *xy, int xy_stride,
|
||||
const SDL_FColor *color, int color_stride,
|
||||
|
@ -4189,6 +4189,40 @@ int SDL_RenderGeometryRaw(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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue