Skip to content

Commit 8b71824

Browse files
committedMar 28, 2025
use argument struct, rename to RenderGeometryEx
1 parent 989c55b commit 8b71824

File tree

2 files changed

+80
-35
lines changed

2 files changed

+80
-35
lines changed
 

Diff for: ‎include/SDL3/SDL_render.h

+28-21
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9GridTiled(SDL_Renderer *rende
22942294
* \since This function is available since SDL 3.2.0.
22952295
*
22962296
* \sa SDL_RenderGeometryRaw
2297-
* \sa SDL_RenderGeometryRawEx
2297+
* \sa SDL_RenderGeometryEx
22982298
*/
22992299
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
23002300
SDL_Texture *texture,
@@ -2327,7 +2327,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
23272327
* \since This function is available since SDL 3.2.0.
23282328
*
23292329
* \sa SDL_RenderGeometry
2330-
* \sa SDL_RenderGeometryRawEx
2330+
* \sa SDL_RenderGeometryEx
23312331
*/
23322332
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
23332333
SDL_Texture *texture,
@@ -2337,6 +2337,29 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
23372337
int num_vertices,
23382338
const void *indices, int num_indices, int size_indices);
23392339

2340+
/**
2341+
* Argument struct for SDL_RenderGeometryEx.
2342+
*
2343+
* \since This struct is available since SDL 3.4.0.
2344+
*/
2345+
typedef struct SDL_RenderGeometryEx_Arg
2346+
{
2347+
size_t arg_size /**< the size of this struct, must be set with sizeof() */
2348+
int ver_len; /**< number of vertices. */
2349+
2350+
const void *map; /**< (optional) An array of indices into the 'vertices' arrays, if NULL all vertices will be rendered in sequential order. */
2351+
int map_size; /**< index size: 1 (byte), 2 (short), 4 (int). */
2352+
int map_len; /**< number of indices. */
2353+
const float *pos; /**< vertex positions. */
2354+
int pos_stride; /**< byte size to move from one element to the next element. */
2355+
int pos_len; /**< how many vertext position coordinates, must be 2, 3, or 4. */
2356+
const SDL_FColor *col; /**< vertex colors (as SDL_FColor). */
2357+
int col_stride; /**< byte size to move from one element to the next element. */
2358+
2359+
const float *tex; /**< vertex normalized texture coordinates. */
2360+
int tex_stride; /**< byte size to move from one element to the next element. */
2361+
2362+
} SDL_RenderGeometryEx_Arg;
23402363

23412364
/**
23422365
* Render a list of triangles, optionally using a texture and indices into the
@@ -2346,18 +2369,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
23462369
*
23472370
* \param renderer the rendering context.
23482371
* \param texture (optional) The SDL texture to use.
2349-
* \param pos vertex positions.
2350-
* \param pos_stride byte size to move from one element to the next element.
2351-
* \param pos_len how many vertext position coordinates, must be 2, 3, or 4.
2352-
* \param color vertex colors (as SDL_FColor).
2353-
* \param color_stride byte size to move from one element to the next element.
2354-
* \param uv vertex normalized texture coordinates.
2355-
* \param uv_stride byte size to move from one element to the next element.
2356-
* \param num_vertices number of vertices.
2357-
* \param indices (optional) An array of indices into the 'vertices' arrays,
2358-
* if NULL all vertices will be rendered in sequential order.
2359-
* \param num_indices number of indices.
2360-
* \param size_indices index size: 1 (byte), 2 (short), 4 (int).
2372+
* \param arg pointer to an SDL_RenderGeometryEx_Arg struct of vertex info.
23612373
* \returns true on success or false on failure; call SDL_GetError() for more
23622374
* information.
23632375
*
@@ -2368,13 +2380,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
23682380
* \sa SDL_RenderGeometry
23692381
* \sa SDL_RenderGeometryRaw
23702382
*/
2371-
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRawEx(SDL_Renderer *renderer,
2372-
SDL_Texture *texture,
2373-
const float *pos, int pos_stride, Uint8 pos_len,
2374-
const SDL_FColor *color, int color_stride,
2375-
const float *uv, int uv_stride,
2376-
int num_vertices,
2377-
const void *indices, int num_indices, int size_indices);
2383+
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryEx(SDL_Renderer *renderer,
2384+
SDL_Texture *texture, const SDL_RenderGeometryEx_Arg *arg);
23782385

23792386
/**
23802387
* Read pixels from the current rendering target.

Diff for: ‎src/render/SDL_render.c

+52-14
Original file line numberDiff line numberDiff line change
@@ -5083,22 +5083,60 @@ bool SDL_RenderGeometryRaw(SDL_Renderer *renderer,
50835083
int num_vertices,
50845084
const void *indices, int num_indices, int size_indices)
50855085
{
5086-
return SDL_RenderGeometryRawEx(renderer, texture,
5087-
xy, xy_stride, 2,
5088-
color, color_stride,
5089-
uv, uv_stride,
5090-
num_vertices,
5091-
indices, num_indices, size_indices);
5092-
}
5093-
5094-
bool SDL_RenderGeometryRawEx(SDL_Renderer *renderer,
5086+
SDL_RenderGeometryEx_Arg arg;
5087+
arg.arg_size = sizeof(SDL_RenderGeometryEx_Arg);
5088+
arg.pos = xy;
5089+
arg.pos_stride = xy_stride;
5090+
arg.pos_len = 2;
5091+
arg.col = color;
5092+
arg.col_stride = color_stride;
5093+
arg.tex = uv;
5094+
arg.tex_stride = uv_stride;
5095+
arg.ver_len = num_vertices;
5096+
arg.map = indices;
5097+
arg.map_len = num_indices;
5098+
arg.map_size = size_indices;
5099+
return SDL_RenderGeometryEx(renderer, texture, &arg);
5100+
}
5101+
5102+
bool SDL_RenderGeometryEx(SDL_Renderer *renderer,
50955103
SDL_Texture *texture,
5096-
const float *xy, int xy_stride, Uint8 pos_len,
5097-
const SDL_FColor *color, int color_stride,
5098-
const float *uv, int uv_stride,
5099-
int num_vertices,
5100-
const void *indices, int num_indices, int size_indices)
5104+
const SDL_RenderGeometryEx_Arg *arg)
51015105
{
5106+
if (!arg) {
5107+
return false;
5108+
}
5109+
5110+
const float *xy;
5111+
int xy_stride;
5112+
int pos_len;
5113+
const SDL_FColor *color;
5114+
int color_stride;
5115+
const float *uv;
5116+
int uv_stride;
5117+
int num_vertices;
5118+
const void *indices;
5119+
int num_indices;
5120+
int size_indices;
5121+
5122+
if (arg->arg_size < sizeof(SDL_RenderGeometryEx_Arg)) {
5123+
// older ABI with fewer arguments, set fallback values
5124+
return false; // placeholder for now
5125+
} else {
5126+
xy = arg->pos;
5127+
xy_stride = arg->pos_stride;
5128+
pos_len = arg->pos_len;
5129+
color = arg->col;
5130+
color_stride = arg->col_stride;
5131+
uv = arg->tex;
5132+
uv_stride = arg->tex_stride;
5133+
num_vertices = arg->ver_len;
5134+
indices = arg->map;
5135+
num_indices = arg->map_len;
5136+
size_indices = arg->map_size;
5137+
}
5138+
5139+
51025140
int i;
51035141
int count = indices ? num_indices : num_vertices;
51045142
SDL_TextureAddressMode texture_address_mode;

0 commit comments

Comments
 (0)