ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
RenderDevice.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 <stdlib.h>
27
28#include <SDL3/SDL_gpu.h>
29#include <SDL3/SDL_surface.h>
30
31#include <Objectively/Data.h>
32#include <Objectively/Object.h>
33
37
43typedef struct Buffer Buffer;
46typedef struct Framebuffer Framebuffer;
49typedef struct QueryPool QueryPool;
51typedef struct RenderDeviceInterface RenderDeviceInterface;
52typedef struct Sampler Sampler;
53typedef struct Shader Shader;
54typedef struct Texture Texture;
56
64
68 Object object;
69
74 RenderDeviceInterface *interface;
75
79 SDL_GPUDevice *device;
80
84 SDL_Window *window;
85
89 SDL_GPUShaderFormat shaderFormats;
90
98
105
112 CommandBuffer *commands;
113
120 SwapchainTexture swapchain;
121
127 TransferBuffer *scratch;
128
132 ident data;
133};
134
138struct RenderDeviceInterface {
139
143 ObjectInterface objectInterface;
144
155 CommandBuffer *(*acquireCommandBuffer)(const RenderDevice *self);
156
177 CommandBuffer *(*beginFrame)(RenderDevice *self);
178
189 Buffer *(*createBuffer)(RenderDevice *self, const SDL_GPUBufferCreateInfo *info);
190
203 Buffer *(*createBufferWithConstMem)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size);
204
216 Buffer *(*createBufferWithData)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const Data *data);
217
228 ComputePipeline *(*createComputePipeline)(RenderDevice *self, const SDL_GPUComputePipelineCreateInfo *info);
229
240 Framebuffer *(*createFramebuffer)(RenderDevice *self, const GPU_FramebufferCreateInfo *info);
241
252 GraphicsPipeline *(*createGraphicsPipeline)(RenderDevice *self, const SDL_GPUGraphicsPipelineCreateInfo *info);
253
265 QueryPool *(*createQueryPool)(RenderDevice *self, const SDL_GPUQueryPoolCreateInfo *info);
266
277 Sampler *(*createSampler)(RenderDevice *self, const SDL_GPUSamplerCreateInfo *info);
278
289 Sampler *(*createSamplerLinearRepeat)(RenderDevice *self);
290
303 Sampler *(*createSamplerLinearClamp)(RenderDevice *self);
304
316 Sampler *(*createSamplerNearestClamp)(RenderDevice *self);
317
327 Sampler *(*createSamplerShadowCompare)(RenderDevice *self);
328
341 Shader *(*createShader)(RenderDevice *self, const SDL_GPUShaderCreateInfo *info);
342
355 Texture *(*createTexture)(RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels);
356
370 Texture *(*createTextureFromSurface)(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps);
371
387 Texture *(*createSolidColorTexture)(RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba);
388
397 TransferBuffer *(*createTransferBuffer)(RenderDevice *self, const SDL_GPUTransferBufferCreateInfo *info);
398
413 void (*endFrame)(RenderDevice *self);
414
426 Fence *(*endFrameAndFence)(RenderDevice *self);
427
437 SDL_GPUTextureFormat (*getSwapchainTextureFormat)(const RenderDevice *self);
438
449 RenderDevice *(*init)(RenderDevice *self, const char *driverName);
450
460 RenderDevice *(*initWithWindow)(RenderDevice *self, SDL_Window *window, const char *driverName);
461
481 Shader *(*loadShader)(RenderDevice *self, const char *name, const SDL_GPUShaderCreateInfo *info);
482
502 ComputePipeline *(*loadComputePipeline)(RenderDevice *self, const char *name, const SDL_GPUComputePipelineCreateInfo *info);
503
524 GraphicsPipeline *(*loadGraphicsPipeline)(RenderDevice *self,
525 const char *vertexShaderName, const SDL_GPUShaderCreateInfo *vertexShaderInfo,
526 const char *fragmentShaderName, const SDL_GPUShaderCreateInfo *fragmentShaderInfo,
527 SDL_GPUGraphicsPipelineCreateInfo *info);
528
539 bool (*setAllowedFramesInFlight)(const RenderDevice *self, Uint32 allowed);
540
551 void (*setFramebuffer)(RenderDevice *self, Framebuffer *framebuffer);
552
564 bool (*setSwapchainParameters)(const RenderDevice *self, SDL_GPUSwapchainComposition composition, SDL_GPUPresentMode mode);
565
576 void (*setWindow)(RenderDevice *self, SDL_Window *window);
577
591 TransferBuffer *(*stageData)(RenderDevice *self, const void *data, Uint32 size);
592
601 bool (*supportsPresentMode)(const RenderDevice *self, SDL_GPUPresentMode mode);
602
611 bool (*supportsSwapchainComposition)(const RenderDevice *self, SDL_GPUSwapchainComposition composition);
612
623 bool (*textureSupportsFormat)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUTextureType type, SDL_GPUTextureUsageFlags usage);
624
634 bool (*textureSupportsSampleCount)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUSampleCount sample_count);
635
645 bool (*waitForIdle)(const RenderDevice *self);
646
654 bool (*waitForSwapchain)(const RenderDevice *self);
655};
656
static void generateMipmaps(const CommandBuffer *self, SDL_GPUTexture *texture)
Definition CommandBuffer.c:183
CommandBuffer wraps an SDL_GPUCommandBuffer for a single frame.
QueryPool wraps an SDL_GPUQueryPool, owning its handle and metadata.
OBJECTIVELYGPU_EXPORT Class * _RenderDevice(void)
Definition RenderDevice.c:743
#define OBJECTIVELYGPU_EXPORT
Definition Types.h:35
An SDL_GPUBuffer (vertex, index, indirect, storage, etc.) and its metadata.
Definition Buffer.h:61
A recorded sequence of GPU commands for a single frame.
Definition CommandBuffer.h:81
An SDL_GPUComputePipeline: a compiled compute program and its binding layout.
Definition ComputePipeline.h:50
An SDL_GPUFence, signaled once a submitted CommandBuffer's GPU work completes.
Definition Fence.h:55
An off-screen render target grouping a color and/or depth texture.
Definition Framebuffer.h:177
Parameters for creating a Framebuffer.
Definition Framebuffer.h:108
An SDL_GPUGraphicsPipeline: the compiled vertex/fragment program plus all fixed-function render state...
Definition GraphicsPipeline.h:51
An SDL_GPUQueryPool and its metadata.
Definition QueryPool.h:86
The RenderDevice encapsulates an SDL_GPUDevice and provides methods for allocating GPU resources,...
Definition RenderDevice.h:63
SDL_GPUShaderFormat shaderFormats
Definition RenderDevice.h:89
float maxAnisotropy
The anisotropic filtering level applied by createSamplerLinearRepeat and createSamplerLinearClamp....
Definition RenderDevice.h:97
SDL_GPUDevice * device
The SDL_GPUDevice.
Definition RenderDevice.h:79
Object object
The superclass.
Definition RenderDevice.h:68
RenderDeviceInterface * interface
The interface.
Definition RenderDevice.h:74
Framebuffer * framebuffer
The present-target Framebuffer driven by beginFrame/endFrame, or NULL.
Definition RenderDevice.h:104
SDL_Window * window
The SDL_Window associated with device.
Definition RenderDevice.h:84
ident data
User data.
Definition RenderDevice.h:132
Definition QueryPool.h:52
An SDL_GPUSampler describing texture filter and address modes.
Definition Sampler.h:51
An SDL_GPUShader: one compiled programmable stage of a graphics pipeline.
Definition Shader.h:51
The swapchain texture acquired for a single frame.
Definition CommandBuffer.h:50
An SDL_GPUTexture and the metadata describing it.
Definition Texture.h:60
A CPU-accessible SDL_GPUTransferBuffer for staging data to or from the GPU.
Definition TransferBuffer.h:59