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
99 Uint32 layerCount;
100
110 Texture *textures[2];
111
117 Texture *resolveTextures[2];
118
120
161
195
199 Object object;
200
205 FramebufferInterface *interface[0];
206
212
217
221 SDL_GPUSampleCount sampleCount;
222
227
232
237
242 Uint32 frame;
243
247 ident data;
248};
249
253struct FramebufferInterface {
254
258 ObjectInterface objectInterface;
259
275 SDL_GPUColorTargetInfo (*colorTargetInfo)(const Framebuffer *self, Uint32 index, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp);
276
292 SDL_GPUColorTargetInfo (*colorTargetInfoForLayer)(const Framebuffer *self, Uint32 index, Uint32 layer, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp);
293
306 SDL_GPUDepthStencilTargetInfo (*depthTargetInfo)(const Framebuffer *self, SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp);
307
321 void (*pipelineTargetInfo)(const Framebuffer *self, const SDL_GPUColorTargetBlendState *blendStates,
322 SDL_GPUColorTargetDescription *descriptions, SDL_GPUGraphicsPipelineTargetInfo *targetInfo);
323
333 Framebuffer *(*initWithDevice)(Framebuffer *self, RenderDevice *device, const GPU_FramebufferCreateInfo *info);
334
346 Texture *(*resolveColorTexture)(const Framebuffer *self, Uint32 index);
347
361 Texture *(*previousColorTexture)(const Framebuffer *self, Uint32 index);
362
373 Texture *(*resolveDepthTexture)(const Framebuffer *self);
374
385 bool (*resize)(Framebuffer *self, const SDL_Size *size);
386
397 void (*swap)(Framebuffer *self);
398};
399
#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:346
#define OBJECTIVELYGPU_EXPORT
Definition Types.h:35
An off-screen render target grouping a color and/or depth texture.
Definition Framebuffer.h:194
SDL_Size size
The framebuffer dimensions.
Definition Framebuffer.h:216
Object object
The superclass.
Definition Framebuffer.h:199
GPU_FramebufferAttachment colorAttachments[GPU_MAX_COLOR_TARGETS]
The color attachments, indices [0, numColorTargets).
Definition Framebuffer.h:226
Uint32 numColorAttachments
The number of color attachments; indices [0, numColorTargets) are valid.
Definition Framebuffer.h:231
RenderDevice * device
The owning RenderDevice, used for texture allocation and dealloc.
Definition Framebuffer.h:211
FramebufferInterface * interface[0]
The interface type.
Definition Framebuffer.h:205
GPU_FramebufferAttachment depthAttachment
The depth attachment, or format SDL_GPU_TEXTUREFORMAT_INVALID if none.
Definition Framebuffer.h:236
ident data
User data.
Definition Framebuffer.h:247
SDL_GPUSampleCount sampleCount
The MSAA sample count of all color and depth attachments.
Definition Framebuffer.h:221
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
Uint32 layerCount
The number of array layers, or 0 or 1 for a plain 2D attachment.
Definition Framebuffer.h:99
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:124
GPU_FramebufferAttachment colorAttachments[GPU_MAX_COLOR_TARGETS]
The color attachments, one per render target (MRT).
Definition Framebuffer.h:139
SDL_Size size
Initial framebuffer dimensions.
Definition Framebuffer.h:131
GPU_FramebufferAttachment depthAttachment
The depth attachment, or format SDL_GPU_TEXTUREFORMAT_INVALID to omit.
Definition Framebuffer.h:151
Uint32 numColorTargets
The number of color attachments; 0 to omit color entirely.
Definition Framebuffer.h:144
SDL_GPUSampleCount sampleCount
MSAA sample count; SDL_GPU_SAMPLECOUNT_1 for no multisampling.
Definition Framebuffer.h:158
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