SDL_DrawGPUPrimitives(3)

πŸ’– SDL_DrawGPUPrimitives πŸ’–

okay bestie, so this is a page from the SDL3 FUNCTIONS corner of the SDL_DrawGPUPrimitives(3) manual, and it is literally about drawing data using bound graphics state. slay. let's get into it πŸŽ€


✨ NAME ✨

SDL_DrawGPUPrimitives β€” Draws data using bound graphics state. that's it, that's the whole job πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_gpu.h>

void SDL_DrawGPUPrimitives(
    SDL_GPURenderPass *render_pass,
    Uint32 num_vertices,
    Uint32 num_instances,
    Uint32 first_vertex,
    Uint32 first_instance);

copy that include and that signature exactly, no improvising, iykyk πŸ¦‹


πŸ’€ DESCRIPTION πŸ’€

first things first, and this is the big one: you must not call this function before binding a graphics pipeline. like, not even a little. bind first, draw second, periodt. πŸ‘‘

now the tea β˜• β€” first_vertex and first_instance are NOT compatible with the built-in vertex/instance ID variables in shaders (think SV_VertexID and friends). why? because GPU APIs and shader languages do not define these built-in variables consistently across the board. so if your shader depends on them, the only way to keep behavior consistent and portable is to always pass 0 for the correlating parameter in the draw calls. no cap, that's the move. πŸ™ˆ


🫢 FUNCTION PARAMETERS 🫢

  • render_pass β€” a render pass handle. your lil ticket to the render party 🎟️
  • num_vertices β€” the number of vertices to draw. count 'em πŸ’…
  • num_instances β€” the number of instances that will be drawn. yes, instances, plural, we're fancy ✨
  • first_vertex β€” the index of the first vertex to draw. where the vertex party starts πŸŽ€
  • first_instance β€” the ID of the first instance to draw. where the instance party starts πŸ¦‹

⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. if you're on anything older, bestie, it's giving ✨not yet✨ 😭


quick vibe check: bind your graphics pipeline first, and if your shader leans on built-in vertex/instance IDs, pass 0 for the correlating parameter. that's the whole portability survival kit 🧚

and that's the page!! brought to you by Simple Directmedia Layer, running on SDL 3.4.18 β€” mwah, go draw some primitives, you absolute icon πŸ’œπŸŒˆπŸ‘‘

πŸ“¦ where this page comes from