@@ -87,6 +87,23 @@ typedef struct GPU_FramebufferCreateInfo {
8787 */
8888 SDL_GPUSampleCount sampleCount ;
8989
90+ /**
91+ * @brief The clear color for each color attachment, indices `[0, numColorTargets)`.
92+ * @details Stashed on the Framebuffer and used as the default `clearColor` by
93+ * `colorTargetInfo` (when passed `NULL`) and by
94+ * `CommandBuffer::beginRenderPassWithFramebuffer`. Omitted entries default to
95+ * opaque black.
96+ */
97+ SDL_FColor clearColors [GPU_MAX_COLOR_TARGETS ];
98+
99+ /**
100+ * @brief The clear depth value for the depth attachment, if any.
101+ * @details Stashed on the Framebuffer and used by
102+ * `CommandBuffer::beginRenderPassWithFramebuffer`. Typically `1.f` (the far plane);
103+ * omitted defaults to `0.f`.
104+ */
105+ float clearDepth ;
106+
90107} GPU_FramebufferCreateInfo ;
91108
92109/**
@@ -105,18 +122,15 @@ typedef struct GPU_FramebufferCreateInfo {
105122 * .size = { 1920, 1080 },
106123 * .colorFormats = { SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT },
107124 * .numColorTargets = 1,
125+ * .clearColors = { { 0.f, 0.f, 0.f, 1.f } },
108126 * .depthFormat = SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
127+ * .clearDepth = 1.f,
109128 * .sampleCount = SDL_GPU_SAMPLECOUNT_1,
110129 * });
111130 *
112- * SDL_GPUColorTargetInfo color = $(fb, colorTargetInfo, 0,
113- * SDL_GPU_LOADOP_CLEAR, SDL_GPU_STOREOP_STORE,
114- * &(SDL_FColor) { 0, 0, 0, 1 });
115- *
116- * SDL_GPUDepthStencilTargetInfo depth = $(fb, depthTargetInfo,
117- * SDL_GPU_LOADOP_CLEAR, SDL_GPU_STOREOP_DONT_CARE, 1.f);
118- *
119- * RenderPass *pass = $(commands, beginRenderPass, &color, 1, &depth);
131+ * // Renders into all of fb's targets, clearing to its own clearColors/clearDepth.
132+ * RenderPass *pass = $(commands, beginRenderPassWithFramebuffer, fb,
133+ * SDL_GPU_LOADOP_CLEAR, SDL_GPU_STOREOP_STORE);
120134 * // ...
121135 * release(pass);
122136 * release(fb);
@@ -180,6 +194,19 @@ struct Framebuffer {
180194 */
181195 SDL_GPUTextureFormat depthFormat ;
182196
197+ /**
198+ * @brief The clear color for each color attachment, indices `[0, numColorTargets)`.
199+ * @details Used as the default `clearColor` by `colorTargetInfo` (when passed `NULL`)
200+ * and by `CommandBuffer::beginRenderPassWithFramebuffer`.
201+ */
202+ SDL_FColor clearColors [GPU_MAX_COLOR_TARGETS ];
203+
204+ /**
205+ * @brief The clear depth value for the depth attachment, if any.
206+ * @details Used by `CommandBuffer::beginRenderPassWithFramebuffer`.
207+ */
208+ float clearDepth ;
209+
183210 /**
184211 * @brief The depth attachment texture, or `NULL` if `depthFormat` is invalid.
185212 * @details Single-sample depth also carries `SAMPLER` and is returned directly by
@@ -230,7 +257,7 @@ struct FramebufferInterface {
230257 * @param index The color attachment index, in `[0, numColorTargets)`.
231258 * @param loadOp Load operation at the start of the pass.
232259 * @param storeOp Store operation at the end of the pass.
233- * @param clearColor Clear color used when `loadOp` is `SDL_GPU_LOADOP_CLEAR`, or NULL for black .
260+ * @param clearColor Clear color used when `loadOp` is `SDL_GPU_LOADOP_CLEAR`, or NULL to use the framebuffer's own `clearColors[index]` .
234261 * @return A stack-allocated `SDL_GPUColorTargetInfo`.
235262 * @memberof Framebuffer
236263 */
0 commit comments