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
119 SwapchainTexture swapchain;
120
124 ident data;
125};
126
130struct RenderDeviceInterface {
131
135 ObjectInterface objectInterface;
136
147 CommandBuffer *(*acquireCommandBuffer)(const RenderDevice *self);
148
165 CommandBuffer *(*beginFrame)(RenderDevice *self);
166
177 Buffer *(*createBuffer)(RenderDevice *self, const SDL_GPUBufferCreateInfo *info);
178
191 Buffer *(*createBufferWithConstMem)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size);
192
204 Buffer *(*createBufferWithData)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const Data *data);
205
216 ComputePipeline *(*createComputePipeline)(RenderDevice *self, const SDL_GPUComputePipelineCreateInfo *info);
217
228 Framebuffer *(*createFramebuffer)(RenderDevice *self, const GPU_FramebufferCreateInfo *info);
229
240 GraphicsPipeline *(*createGraphicsPipeline)(RenderDevice *self, const SDL_GPUGraphicsPipelineCreateInfo *info);
241
253 QueryPool *(*createQueryPool)(RenderDevice *self, const SDL_GPUQueryPoolCreateInfo *info);
254
265 Sampler *(*createSampler)(RenderDevice *self, const SDL_GPUSamplerCreateInfo *info);
266
277 Sampler *(*createSamplerLinearRepeat)(RenderDevice *self);
278
291 Sampler *(*createSamplerLinearClamp)(RenderDevice *self);
292
304 Sampler *(*createSamplerNearestClamp)(RenderDevice *self);
305
315 Sampler *(*createSamplerShadowCompare)(RenderDevice *self);
316
329 Shader *(*createShader)(RenderDevice *self, const SDL_GPUShaderCreateInfo *info);
330
343 Texture *(*createTexture)(RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels);
344
358 Texture *(*createTextureFromSurface)(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps);
359
375 Texture *(*createSolidColorTexture)(RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba);
376
385 TransferBuffer *(*createTransferBuffer)(RenderDevice *self, const SDL_GPUTransferBufferCreateInfo *info);
386
397 void (*endFrame)(RenderDevice *self);
398
410 Fence *(*endFrameAndFence)(RenderDevice *self);
411
421 SDL_GPUTextureFormat (*getSwapchainTextureFormat)(const RenderDevice *self);
422
432 RenderDevice *(*init)(RenderDevice *self);
433
442 RenderDevice *(*initWithWindow)(RenderDevice *self, SDL_Window *window);
443
463 Shader *(*loadShader)(RenderDevice *self, const char *name, const SDL_GPUShaderCreateInfo *info);
464
484 ComputePipeline *(*loadComputePipeline)(RenderDevice *self, const char *name, const SDL_GPUComputePipelineCreateInfo *info);
485
506 GraphicsPipeline *(*loadGraphicsPipeline)(RenderDevice *self,
507 const char *vertexShaderName, const SDL_GPUShaderCreateInfo *vertexShaderInfo,
508 const char *fragmentShaderName, const SDL_GPUShaderCreateInfo *fragmentShaderInfo,
509 SDL_GPUGraphicsPipelineCreateInfo *info);
510
521 bool (*setAllowedFramesInFlight)(const RenderDevice *self, Uint32 allowed);
522
533 void (*setFramebuffer)(RenderDevice *self, Framebuffer *framebuffer);
534
546 bool (*setSwapchainParameters)(const RenderDevice *self, SDL_GPUSwapchainComposition composition, SDL_GPUPresentMode mode);
547
558 void (*setWindow)(RenderDevice *self, SDL_Window *window);
559
568 bool (*supportsPresentMode)(const RenderDevice *self, SDL_GPUPresentMode mode);
569
578 bool (*supportsSwapchainComposition)(const RenderDevice *self, SDL_GPUSwapchainComposition composition);
579
590 bool (*textureSupportsFormat)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUTextureType type, SDL_GPUTextureUsageFlags usage);
591
601 bool (*textureSupportsSampleCount)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUSampleCount sample_count);
602
612 bool (*waitForIdle)(const RenderDevice *self);
613
621 bool (*waitForSwapchain)(const RenderDevice *self);
622};
623
static void generateMipmaps(const CommandBuffer *self, SDL_GPUTexture *texture)
Definition CommandBuffer.c:157
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:716
#define OBJECTIVELYGPU_EXPORT
Definition Types.h:35
An SDL_GPUBuffer (vertex, index, indirect, storage, etc.) and its metadata.
Definition Buffer.h:60
A recorded sequence of GPU commands for a single frame.
Definition CommandBuffer.h:80
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:127
Parameters for creating a Framebuffer.
Definition Framebuffer.h:56
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:96
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:124
Definition QueryPool.h:61
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:49
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