ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
Framebuffer.h
Go to the documentation of this file.
1/*
2 * ObjectivelyGPU: Object oriented graphics framework for SDL3 and C.
3 * Copyright (C) 2026 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <SDL3/SDL_gpu.h>
27
28#include <Objectively/Object.h>
29
31
38typedef struct Framebuffer Framebuffer;
39typedef struct FramebufferInterface FramebufferInterface;
40typedef struct Texture Texture;
41
47#define GPU_MAX_COLOR_TARGETS 4
48
63
67 SDL_GPUTextureFormat format;
68
69 union {
74 SDL_FColor clearColor;
75
81 };
82
87
94 Texture *textures[2];
95
101 Texture *resolveTextures[2];
102
104
144
178
182 Object object;
183
188 FramebufferInterface *interface;
189
194
199
203 SDL_GPUSampleCount sampleCount;
204
209
214
219
224 Uint32 frame;
225
229 ident data;
230};
231
235struct FramebufferInterface {
236
240 ObjectInterface objectInterface;
241
256 SDL_GPUColorTargetInfo (*colorTargetInfo)(const Framebuffer *self, Uint32 index, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp);
257
270 SDL_GPUDepthStencilTargetInfo (*depthTargetInfo)(const Framebuffer *self, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp);
271
285 void (*pipelineTargetInfo)(const Framebuffer *self, const SDL_GPUColorTargetBlendState *blendStates,
286 SDL_GPUColorTargetDescription *descriptions, SDL_GPUGraphicsPipelineTargetInfo *targetInfo);
287
297 Framebuffer *(*initWithDevice)(Framebuffer *self, RenderDevice *device, const GPU_FramebufferCreateInfo *info);
298
310 Texture *(*resolveColorTexture)(const Framebuffer *self, Uint32 index);
311
325 Texture *(*previousColorTexture)(const Framebuffer *self, Uint32 index);
326
337 Texture *(*resolveDepthTexture)(const Framebuffer *self);
338
349 bool (*resize)(Framebuffer *self, const SDL_Size *size);
350
361 void (*swap)(Framebuffer *self);
362};
363
#define GPU_MAX_COLOR_TARGETS
The maximum number of color attachments a Framebuffer may have.
Definition Framebuffer.h:47
OBJECTIVELYGPU_EXPORT Class * _Framebuffer(void)
Definition Framebuffer.c:317
#define OBJECTIVELYGPU_EXPORT
Definition Types.h:35
An off-screen render target grouping a color and/or depth texture.
Definition Framebuffer.h:177
SDL_Size size
The framebuffer dimensions.
Definition Framebuffer.h:198
Object object
The superclass.
Definition Framebuffer.h:182
GPU_FramebufferAttachment colorAttachments[GPU_MAX_COLOR_TARGETS]
The color attachments, indices [0, numColorTargets).
Definition Framebuffer.h:208
Uint32 numColorAttachments
The number of color attachments; indices [0, numColorTargets) are valid.
Definition Framebuffer.h:213
RenderDevice * device
The owning RenderDevice, used for texture allocation and dealloc.
Definition Framebuffer.h:193
GPU_FramebufferAttachment depthAttachment
The depth attachment, or format SDL_GPU_TEXTUREFORMAT_INVALID if none.
Definition Framebuffer.h:218
ident data
User data.
Definition Framebuffer.h:229
FramebufferInterface * interface
The interface.
Definition Framebuffer.h:188
SDL_GPUSampleCount sampleCount
The MSAA sample count of all color and depth attachments.
Definition Framebuffer.h:203
Describes, and backs, a single Framebuffer attachment (color or depth).
Definition Framebuffer.h:62
SDL_FColor clearColor
The clear color, for color attachments.
Definition Framebuffer.h:74
SDL_GPUTextureFormat format
The attachment format, or SDL_GPU_TEXTUREFORMAT_INVALID to omit (depth only).
Definition Framebuffer.h:67
bool doubleBuffered
If true, this attachment is double-buffered; see above.
Definition Framebuffer.h:86
float clearDepth
The clear depth value, for the depth attachment.
Definition Framebuffer.h:80
Parameters for creating a Framebuffer.
Definition Framebuffer.h:108
GPU_FramebufferAttachment colorAttachments[GPU_MAX_COLOR_TARGETS]
The color attachments, one per render target (MRT).
Definition Framebuffer.h:122
SDL_Size size
Initial framebuffer dimensions.
Definition Framebuffer.h:115
GPU_FramebufferAttachment depthAttachment
The depth attachment, or format SDL_GPU_TEXTUREFORMAT_INVALID to omit.
Definition Framebuffer.h:134
Uint32 numColorTargets
The number of color attachments; 0 to omit color entirely.
Definition Framebuffer.h:127
SDL_GPUSampleCount sampleCount
MSAA sample count; SDL_GPU_SAMPLECOUNT_1 for no multisampling.
Definition Framebuffer.h:141
The RenderDevice encapsulates an SDL_GPUDevice and provides methods for allocating GPU resources,...
Definition RenderDevice.h:63
The SDL_Size type.
Definition Types.h:47
An SDL_GPUTexture and the metadata describing it.
Definition Texture.h:60