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[0];
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
125 ident data;
126};
127
131struct RenderDeviceInterface {
132
136 ObjectInterface objectInterface;
137
148 CommandBuffer *(*acquireCommandBuffer)(const RenderDevice *self);
149
170 CommandBuffer *(*beginFrame)(RenderDevice *self);
171
182 Buffer *(*createBuffer)(RenderDevice *self, const SDL_GPUBufferCreateInfo *info);
183
196 Buffer *(*createBufferWithConstMem)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const void *mem, Uint32 size);
197
209 Buffer *(*createBufferWithData)(RenderDevice *self, SDL_GPUBufferUsageFlags usage, const Data *data);
210
221 ComputePipeline *(*createComputePipeline)(RenderDevice *self, const SDL_GPUComputePipelineCreateInfo *info);
222
233 Framebuffer *(*createFramebuffer)(RenderDevice *self, const GPU_FramebufferCreateInfo *info);
234
245 GraphicsPipeline *(*createGraphicsPipeline)(RenderDevice *self, const SDL_GPUGraphicsPipelineCreateInfo *info);
246
258 QueryPool *(*createQueryPool)(RenderDevice *self, const SDL_GPUQueryPoolCreateInfo *info);
259
270 Sampler *(*createSampler)(RenderDevice *self, const SDL_GPUSamplerCreateInfo *info);
271
282 Sampler *(*createSamplerLinearRepeat)(RenderDevice *self);
283
296 Sampler *(*createSamplerLinearClamp)(RenderDevice *self);
297
309 Sampler *(*createSamplerNearestClamp)(RenderDevice *self);
310
320 Sampler *(*createSamplerShadowCompare)(RenderDevice *self);
321
334 Shader *(*createShader)(RenderDevice *self, const SDL_GPUShaderCreateInfo *info);
335
348 Texture *(*createTexture)(RenderDevice *self, const SDL_GPUTextureCreateInfo *info, const void *pixels);
349
363 Texture *(*createTextureFromSurface)(RenderDevice *self, SDL_Surface *surface, SDL_GPUTextureUsageFlags usage, bool generateMipmaps);
364
381 Texture *(*createSolidColorTexture)(RenderDevice *self, SDL_GPUTextureType type, Uint32 layerCount, Uint32 rgba);
382
391 TransferBuffer *(*createTransferBuffer)(RenderDevice *self, const SDL_GPUTransferBufferCreateInfo *info);
392
407 void (*endFrame)(RenderDevice *self);
408
420 Fence *(*endFrameAndFence)(RenderDevice *self);
421
431 SDL_GPUTextureFormat (*getSwapchainTextureFormat)(const RenderDevice *self);
432
443 RenderDevice *(*init)(RenderDevice *self, const char *driverName);
444
454 RenderDevice *(*initWithWindow)(RenderDevice *self, SDL_Window *window, const char *driverName);
455
475 Shader *(*loadShader)(RenderDevice *self, const char *name, const SDL_GPUShaderCreateInfo *info);
476
496 ComputePipeline *(*loadComputePipeline)(RenderDevice *self, const char *name, const SDL_GPUComputePipelineCreateInfo *info);
497
518 GraphicsPipeline *(*loadGraphicsPipeline)(RenderDevice *self,
519 const char *vertexShaderName, const SDL_GPUShaderCreateInfo *vertexShaderInfo,
520 const char *fragmentShaderName, const SDL_GPUShaderCreateInfo *fragmentShaderInfo,
521 SDL_GPUGraphicsPipelineCreateInfo *info);
522
533 bool (*setAllowedFramesInFlight)(const RenderDevice *self, Uint32 allowed);
534
545 void (*setFramebuffer)(RenderDevice *self, Framebuffer *framebuffer);
546
558 bool (*setSwapchainParameters)(const RenderDevice *self, SDL_GPUSwapchainComposition composition, SDL_GPUPresentMode mode);
559
570 void (*setWindow)(RenderDevice *self, SDL_Window *window);
571
572
581 bool (*supportsPresentMode)(const RenderDevice *self, SDL_GPUPresentMode mode);
582
591 bool (*supportsSwapchainComposition)(const RenderDevice *self, SDL_GPUSwapchainComposition composition);
592
603 bool (*textureSupportsFormat)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUTextureType type, SDL_GPUTextureUsageFlags usage);
604
614 bool (*textureSupportsSampleCount)(const RenderDevice *self, SDL_GPUTextureFormat format, SDL_GPUSampleCount sample_count);
615
625 bool (*waitForIdle)(const RenderDevice *self);
626
634 bool (*waitForSwapchain)(const RenderDevice *self);
635};
636
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:719
#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:194
Parameters for creating a Framebuffer.
Definition Framebuffer.h:124
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
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
RenderDeviceInterface * interface[0]
The interface type.
Definition RenderDevice.h:74
ident data
User data.
Definition RenderDevice.h:125
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