use argument struct, rename to RenderGeometryEx

This commit is contained in:
expikr 2025-03-28 12:51:29 +08:00
parent 989c55b564
commit 72c0fd1017
2 changed files with 78 additions and 33 deletions

View file

@ -2294,7 +2294,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderTexture9GridTiled(SDL_Renderer *rende
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderGeometryRaw
* \sa SDL_RenderGeometryRawEx
* \sa SDL_RenderGeometryEx
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
SDL_Texture *texture,
@ -2327,7 +2327,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_RenderGeometry
* \sa SDL_RenderGeometryRawEx
* \sa SDL_RenderGeometryEx
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Texture *texture,
@ -2337,6 +2337,29 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
int num_vertices,
const void *indices, int num_indices, int size_indices);
/**
* Argument struct for SDL_RenderGeometryEx.
*
* \since This struct is available since SDL 3.4.0.
*/
typedef struct SDL_RenderGeometryEx_Arg
{
size_t arg_size; /**< the size of this struct, must be set with sizeof() */
int ver_len; /**< number of vertices. */
const void *map; /**< (optional) An array of indices into the 'vertices' arrays, if NULL all vertices will be rendered in sequential order. */
int map_size; /**< index size: 1 (byte), 2 (short), 4 (int). */
int map_len; /**< number of indices. */
const float *pos; /**< vertex positions. */
int pos_stride; /**< byte size to move from one element to the next element. */
int pos_len; /**< how many vertext position coordinates, must be 2, 3, or 4. */
const SDL_FColor *col; /**< vertex colors (as SDL_FColor). */
int col_stride; /**< byte size to move from one element to the next element. */
const float *tex; /**< vertex normalized texture coordinates. */
int tex_stride; /**< byte size to move from one element to the next element. */
} SDL_RenderGeometryEx_Arg;
/**
* 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,
*
* \param renderer the rendering context.
* \param texture (optional) The SDL texture to use.
* \param pos vertex positions.
* \param pos_stride byte size to move from one element to the next element.
* \param pos_len how many vertext position coordinates, must be 2, 3, or 4.
* \param color vertex colors (as SDL_FColor).
* \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).
* \param arg pointer to an SDL_RenderGeometryEx_Arg struct of vertex info.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
@ -2368,13 +2380,8 @@ extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
* \sa SDL_RenderGeometry
* \sa SDL_RenderGeometryRaw
*/
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryRawEx(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *pos, int pos_stride, Uint8 pos_len,
const SDL_FColor *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices);
extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometryEx(SDL_Renderer *renderer,
SDL_Texture *texture, const SDL_RenderGeometryEx_Arg *arg);
/**
* Read pixels from the current rendering target.

View file

@ -5083,22 +5083,60 @@ bool SDL_RenderGeometryRaw(SDL_Renderer *renderer,
int num_vertices,
const void *indices, int num_indices, int size_indices)
{
return SDL_RenderGeometryRawEx(renderer, texture,
xy, xy_stride, 2,
color, color_stride,
uv, uv_stride,
num_vertices,
indices, num_indices, size_indices);
SDL_RenderGeometryEx_Arg arg;
arg.arg_size = sizeof(SDL_RenderGeometryEx_Arg);
arg.pos = xy;
arg.pos_stride = xy_stride;
arg.pos_len = 2;
arg.col = color;
arg.col_stride = color_stride;
arg.tex = uv;
arg.tex_stride = uv_stride;
arg.ver_len = num_vertices;
arg.map = indices;
arg.map_len = num_indices;
arg.map_size = size_indices;
return SDL_RenderGeometryEx(renderer, texture, &arg);
}
bool SDL_RenderGeometryRawEx(SDL_Renderer *renderer,
bool SDL_RenderGeometryEx(SDL_Renderer *renderer,
SDL_Texture *texture,
const float *xy, int xy_stride, Uint8 pos_len,
const SDL_FColor *color, int color_stride,
const float *uv, int uv_stride,
int num_vertices,
const void *indices, int num_indices, int size_indices)
const SDL_RenderGeometryEx_Arg *arg)
{
if (!arg) {
return false;
}
const float *xy;
int xy_stride;
int pos_len;
const SDL_FColor *color;
int color_stride;
const float *uv;
int uv_stride;
int num_vertices;
const void *indices;
int num_indices;
int size_indices;
if (arg->arg_size < sizeof(SDL_RenderGeometryEx_Arg)) {
// older ABI with fewer arguments, set fallback values
return false; // placeholder for now
} else {
xy = arg->pos;
xy_stride = arg->pos_stride;
pos_len = arg->pos_len;
color = arg->col;
color_stride = arg->col_stride;
uv = arg->tex;
uv_stride = arg->tex_stride;
num_vertices = arg->ver_len;
indices = arg->map;
num_indices = arg->map_len;
size_indices = arg->map_size;
}
int i;
int count = indices ? num_indices : num_vertices;
SDL_TextureAddressMode texture_address_mode;