Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions include/SDL3/SDL_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,46 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
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
* (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
*
* This variant takes SDL_Color (8-bit per channel) instead of SDL_FColor,
* converting to floating-point internally.
*
* \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 true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety This function should only be called on the main thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderGeometry
* \sa SDL_RenderGeometryRaw
* \sa SDL_SetRenderTextureAddressMode
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRawColor8Bits(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);

/**
* Set the texture addressing mode used in SDL_RenderGeometry().
*
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ SDL3_0.0.0 {
SDL_OpenXR_UnloadLibrary;
SDL_OpenXR_GetXrGetInstanceProcAddr;
SDL_CreateTrayWithProperties;
SDL_RenderGeometryRawColor8Bits;
# extra symbols go here (don't modify this line)
local: *;
};
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -1306,3 +1306,4 @@
#define SDL_OpenXR_UnloadLibrary SDL_OpenXR_UnloadLibrary_REAL
#define SDL_OpenXR_GetXrGetInstanceProcAddr SDL_OpenXR_GetXrGetInstanceProcAddr_REAL
#define SDL_CreateTrayWithProperties SDL_CreateTrayWithProperties_REAL
#define SDL_RenderGeometryRawColor8Bits SDL_RenderGeometryRawColor8Bits_REAL
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,4 @@ SDL_DYNAPI_PROC(bool,SDL_OpenXR_LoadLibrary,(void),(),return)
SDL_DYNAPI_PROC(void,SDL_OpenXR_UnloadLibrary,(void),(),)
SDL_DYNAPI_PROC(PFN_xrGetInstanceProcAddr,SDL_OpenXR_GetXrGetInstanceProcAddr,(void),(),return)
SDL_DYNAPI_PROC(SDL_Tray*,SDL_CreateTrayWithProperties,(SDL_PropertiesID a),(a),return)
SDL_DYNAPI_PROC(bool,SDL_RenderGeometryRawColor8Bits,(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)
68 changes: 68 additions & 0 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -5287,6 +5287,74 @@ static bool SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
}
#endif // SDL_VIDEO_RENDER_SW

bool SDL_RenderGeometryRawColor8Bits(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)
{
CHECK_RENDERER_MAGIC(renderer, false);

if (texture) {
CHECK_TEXTURE_MAGIC(texture, false);

CHECK_PARAM(renderer != texture->renderer) {
return SDL_SetError("Texture was not created with this renderer");
}
}

CHECK_PARAM(!xy) {
return SDL_InvalidParamError("xy");
}

CHECK_PARAM(!color) {
return SDL_InvalidParamError("color");
}

CHECK_PARAM(texture && !uv) {
return SDL_InvalidParamError("uv");
}

int count = indices ? num_indices : num_vertices;
CHECK_PARAM(count % 3 != 0) {
return SDL_InvalidParamError(indices ? "num_indices" : "num_vertices");
}

if (indices) {
CHECK_PARAM(size_indices != 1 && size_indices != 2 && size_indices != 4) {
return SDL_InvalidParamError("size_indices");
}
}

SDL_FColor *fcolors = (SDL_FColor *)SDL_stack_alloc(SDL_FColor, num_vertices);
if (!fcolors) {
return SDL_OutOfMemory();
}

const float inv255 = 1.0f / 255.0f;
const Uint8 *c = (const Uint8 *)color;
for (int i = 0; i < num_vertices; ++i) {
const SDL_Color *src = (const SDL_Color *)c;
fcolors[i].r = src->r * inv255;
fcolors[i].g = src->g * inv255;
fcolors[i].b = src->b * inv255;
fcolors[i].a = src->a * inv255;
c += color_stride;
}

bool result = SDL_RenderGeometryRaw(renderer, texture,
xy, xy_stride,
fcolors, sizeof(SDL_FColor),
uv, uv_stride,
num_vertices,
indices, num_indices, size_indices);

SDL_stack_free(fcolors);
return result;
}

bool SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride,
Expand Down
Loading