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
57
64
70 SDL_GPUTextureFormat colorFormats[GPU_MAX_COLOR_TARGETS];
71
76
81 SDL_GPUTextureFormat depthFormat;
82
88 SDL_GPUSampleCount sampleCount;
89
91
128
132 Object object;
133
138 FramebufferInterface *interface;
139
144
152 SDL_GPUSampleCount sampleCount;
153
158
162 SDL_GPUTextureFormat colorFormats[GPU_MAX_COLOR_TARGETS];
163
170
177
181 SDL_GPUTextureFormat depthFormat;
182
191 Texture *depthTexture;
192
199 Texture *resolveDepthTexture;
200
205 RenderDevice *device;
206
210 ident data;
211};
212
216struct FramebufferInterface {
217
221 ObjectInterface objectInterface;
222
237 SDL_GPUColorTargetInfo (*colorTargetInfo)(const Framebuffer *self, Uint32 index,
238 SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp, const SDL_FColor *clearColor);
239
252 SDL_GPUDepthStencilTargetInfo (*depthTargetInfo)(const Framebuffer *self,
253 SDL_GPULoadOp loadOp, SDL_GPUStoreOp storeOp, float clearDepth);
254
264 Framebuffer *(*initWithDevice)(Framebuffer *self, RenderDevice *device, const GPU_FramebufferCreateInfo *info);
265
275 Texture *(*resolveColorTexture)(const Framebuffer *self, Uint32 index);
276
287 Texture *(*resolveDepthTexture)(const Framebuffer *self);
288
299 bool (*resize)(Framebuffer *self, const SDL_Size *size);
300};
301
#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:243
#define OBJECTIVELYGPU_EXPORT
Definition Types.h:35
An off-screen render target grouping a color and/or depth texture.
Definition Framebuffer.h:127
Uint32 numColorTargets
The number of color attachments; indices [0, numColorTargets) are valid.
Definition Framebuffer.h:157
SDL_Size size
The framebuffer dimensions.
Definition Framebuffer.h:143
Object object
The superclass.
Definition Framebuffer.h:132
Texture * colorTextures[GPU_MAX_COLOR_TARGETS]
The color attachment textures, indices [0, numColorTargets).
Definition Framebuffer.h:169
SDL_GPUTextureFormat depthFormat
The depth attachment texture format, or SDL_GPU_TEXTUREFORMAT_INVALID if none.
Definition Framebuffer.h:181
Texture * resolveTextures[GPU_MAX_COLOR_TARGETS]
The single-sample resolve targets, or all NULL unless sampleCount > SDL_GPU_SAMPLECOUNT_1.
Definition Framebuffer.h:176
ident data
User data.
Definition Framebuffer.h:210
SDL_GPUTextureFormat colorFormats[GPU_MAX_COLOR_TARGETS]
The color attachment texture formats, indices [0, numColorTargets).
Definition Framebuffer.h:162
FramebufferInterface * interface
The interface.
Definition Framebuffer.h:138
SDL_GPUSampleCount sampleCount
The MSAA sample count of all attachments.
Definition Framebuffer.h:152
Parameters for creating a Framebuffer.
Definition Framebuffer.h:56
SDL_GPUTextureFormat colorFormats[GPU_MAX_COLOR_TARGETS]
The color attachment formats, one per render target (MRT).
Definition Framebuffer.h:70
SDL_GPUTextureFormat depthFormat
Depth attachment format, or SDL_GPU_TEXTUREFORMAT_INVALID to omit.
Definition Framebuffer.h:81
SDL_Size size
Initial framebuffer dimensions.
Definition Framebuffer.h:63
Uint32 numColorTargets
The number of color attachments; 0 to omit color entirely.
Definition Framebuffer.h:75
SDL_GPUSampleCount sampleCount
MSAA sample count; SDL_GPU_SAMPLECOUNT_1 for no multisampling.
Definition Framebuffer.h:88
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