GPU: device & frameSDL 3.2

SDL_BeginGPURenderPass

Starts a render pass: says which textures you draw into and how to treat their old contents.

Signature

SDL_GPURenderPass * SDL_BeginGPURenderPass(SDL_GPUCommandBuffer *command_buffer, const SDL_GPUColorTargetInfo *color_target_infos, Uint32 num_color_targets, const SDL_GPUDepthStencilTargetInfo *depth_stencil_target_info);

How it works

All drawing happens inside a render pass. Each color target says which texture (often the swapchain image), and two operations. load_op happens at the start: SDL_GPU_LOADOP_CLEAR fills with clear_color (this is how you clear the screen), LOAD keeps what was there, DONT_CARE lets the GPU skip it. store_op happens at the end: SDL_GPU_STOREOP_STORE keeps the result.

While a render pass is open you cannot start another pass. Close it with SDL_EndGPURenderPass.

Parameters

command_bufferSDL_GPUCommandBuffer *

This frame's command buffer.

color_target_infosconst SDL_GPUColorTargetInfo *

Array of color targets: texture, clear_color, load_op, store_op.

num_color_targetsUint32

How many color targets (1 for a plain window).

depth_stencil_target_infoconst SDL_GPUDepthStencilTargetInfo *

The depth buffer for 3D, or NULL.

Return value

The render pass handle.

Example

example.cpp
1SDL_GPUColorTargetInfo color{};
2color.texture     = swapchain;
3color.clear_color = SDL_FColor{0.06f, 0.07f, 0.10f, 1.0f};
4color.load_op     = SDL_GPU_LOADOP_CLEAR;
5color.store_op    = SDL_GPU_STOREOP_STORE;
6SDL_GPURenderPass* pass = SDL_BeginGPURenderPass(cmd, &color, 1, nullptr);
Official SDL wiki