sdlxRenderGeometry function render

bool sdlxRenderGeometry(
  1. Pointer<SdlRenderer> renderer,
  2. Pointer<SdlTexture> texture, {
  3. List<SdlxVertex>? vertices,
  4. List<int>? indices,
})

Render a list of triangles, optionally using a texture and indices into the vertex array.

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 vertices vertices. \param num_vertices number of vertices. \param indices (optional) An array of integer indices into the 'vertices' array, if NULL all vertices will be rendered in sequential order. \param num_indices number of indices. \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_RenderGeometryRaw \sa SDL_SetRenderTextureAddressMode

extern SDL_DECLSPEC bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Vertex *vertices, int num_vertices, const int *indices, int num_indices)

Implementation

bool sdlxRenderGeometry(
  Pointer<SdlRenderer> renderer,
  Pointer<SdlTexture> texture, {
  List<SdlxVertex>? vertices,
  List<int>? indices,
}) {
  Pointer<SdlVertex> verticesPointer = nullptr;
  var numVertices = 0;
  Pointer<Int32> indicesPointer = nullptr;
  var numIndices = 0;
  if (vertices != null) {
    verticesPointer = vertices.calloc();
    numVertices = vertices.length;
  }
  if (indices != null) {
    indicesPointer = calloc<Int32>(indices.length);
    for (var i = 0; i < indices.length; i++) {
      indicesPointer[i] = indices[i];
    }
    numIndices = indices.length;
  }
  final result = sdlRenderGeometry(
    renderer,
    texture,
    verticesPointer,
    numVertices,
    indicesPointer,
    numIndices,
  );
  if (verticesPointer != nullptr) {
    verticesPointer.callocFree();
  }
  if (indicesPointer != nullptr) {
    indicesPointer.callocFree();
  }
  return result;
}