@@ -43,6 +43,7 @@ static void dealloc(Object *self) {
4343 release (this -> resolveTextures [i ]);
4444 }
4545 release (this -> depthTexture );
46+ release (this -> resolveDepthTexture );
4647
4748 release (this -> device );
4849
@@ -146,16 +147,15 @@ static bool resize(Framebuffer *self, const SDL_Size *size) {
146147 }
147148 release (self -> depthTexture );
148149 self -> depthTexture = NULL ;
150+ release (self -> resolveDepthTexture );
151+ self -> resolveDepthTexture = NULL ;
149152
150153 self -> size = * size ;
151154
152155 const bool multisampled = self -> sampleCount > SDL_GPU_SAMPLECOUNT_1 ;
153156
154157 for (Uint32 i = 0 ; i < self -> numColorTargets ; i ++ ) {
155158
156- // A multisampled color target is resolved before sampling, so it needs only
157- // COLOR_TARGET usage; the single-sample paths (no MSAA, or the resolve target)
158- // also carry SAMPLER so they can be blit/sampled.
159159 self -> colorTextures [i ] = $ (self -> device , createTexture , & (SDL_GPUTextureCreateInfo ) {
160160 .type = SDL_GPU_TEXTURETYPE_2D ,
161161 .format = self -> colorFormats [i ],
@@ -182,10 +182,15 @@ static bool resize(Framebuffer *self, const SDL_Size *size) {
182182 }
183183
184184 if (self -> depthFormat != SDL_GPU_TEXTUREFORMAT_INVALID ) {
185+
186+ // Single-sample depth carries SAMPLER so it can be read directly via
187+ // resolveDepthTexture (e.g. soft particles). Multisampled depth is a plain
188+ // depth-stencil target; sampling it requires the separate resolveDepthTexture,
189+ // populated by a resolve pass (SDL has no depth store-op resolve) — TODO when MSAA lands.
185190 self -> depthTexture = $ (self -> device , createTexture , & (SDL_GPUTextureCreateInfo ) {
186191 .type = SDL_GPU_TEXTURETYPE_2D ,
187192 .format = self -> depthFormat ,
188- .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET ,
193+ .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | ( multisampled ? 0 : SDL_GPU_TEXTUREUSAGE_SAMPLER ) ,
189194 .width = (Uint32 ) self -> size .w ,
190195 .height = (Uint32 ) self -> size .h ,
191196 .layer_count_or_depth = 1 ,
@@ -198,14 +203,22 @@ static bool resize(Framebuffer *self, const SDL_Size *size) {
198203}
199204
200205/**
201- * @fn Texture *Framebuffer::resolvedColorTexture (const Framebuffer *self, Uint32 index)
206+ * @fn Texture *Framebuffer::resolveColorTexture (const Framebuffer *self, Uint32 index)
202207 * @memberof Framebuffer
203208 */
204- static Texture * resolvedColorTexture (const Framebuffer * self , Uint32 index ) {
209+ static Texture * resolveColorTexture (const Framebuffer * self , Uint32 index ) {
205210 assert (index < self -> numColorTargets );
206211 return self -> resolveTextures [index ] ?: self -> colorTextures [index ];
207212}
208213
214+ /**
215+ * @fn Texture *Framebuffer::resolveDepthTexture(const Framebuffer *self)
216+ * @memberof Framebuffer
217+ */
218+ static Texture * resolveDepthTexture (const Framebuffer * self ) {
219+ return self -> resolveDepthTexture ?: self -> depthTexture ;
220+ }
221+
209222#pragma mark - Class lifecycle
210223
211224/**
@@ -219,7 +232,8 @@ static void initialize(Class *clazz) {
219232 ((FramebufferInterface * ) clazz -> interface )-> depthTargetInfo = depthTargetInfo ;
220233 ((FramebufferInterface * ) clazz -> interface )-> initWithDevice = initWithDevice ;
221234 ((FramebufferInterface * ) clazz -> interface )-> resize = resize ;
222- ((FramebufferInterface * ) clazz -> interface )-> resolvedColorTexture = resolvedColorTexture ;
235+ ((FramebufferInterface * ) clazz -> interface )-> resolveColorTexture = resolveColorTexture ;
236+ ((FramebufferInterface * ) clazz -> interface )-> resolveDepthTexture = resolveDepthTexture ;
223237}
224238
225239/**
0 commit comments