7#include <SDL3/SDL_gpu.h>
9#include <backends/imgui_impl_sdlgpu3.h>
13#define MAX_POINT_LIGHTS 8
19#define MAX_MOVING_POINT_LIGHTS 56
21#define MAX_MOVING_POINT_LIGHTS 64
23#define MAX_SHADOW_COUNT MAX_POINT_LIGHTS
28 .src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
29 .dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
30 .color_blend_op = SDL_GPU_BLENDOP_ADD,
32 .src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
33 .dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
34 .alpha_blend_op = SDL_GPU_BLENDOP_ADD,
40 const char*
path =
nullptr;
41 SDL_GPUShaderStage
stage = SDL_GPU_SHADERSTAGE_VERTEX;
78 const void*
data =
nullptr;
86ImGui_ImplSDLGPU3_InitInfo
createImGuiInfo(SDL_GPUDevice* device, SDL_Window* window);
95makeAttribute(Uint32 location, SDL_GPUVertexElementFormat format, Uint32 offset, Uint32 bufferSlot = 0);
111SDL_GPUDepthStencilTargetInfo
makeDepthTarget(SDL_GPUTexture* texture, Uint8 layer,
bool store,
bool reverseZ);
134SDL_GPUShader*
loadShader(SDL_GPUDevice* device,
136 SDL_GPUShaderFormat format,
137 SDL_GPUShaderStage stage,
139 Uint32 uniformBufferCount,
140 Uint32 storageBufferCount,
141 Uint32 storageTextureCount);
148SDL_GPUShader*
loadShader(SDL_GPUDevice* device,
const ShaderInfo& shaderInfo, SDL_GPUShaderFormat format);
161 SDL_GPUTextureFormat& colorFormat,
162 SDL_GPUShaderFormat shaderFormat,
166 bool enableDepth =
true,
167 bool overBlending =
false);
171 const std::vector<SDL_GPUTextureFormat>& colorFormats,
172 SDL_GPUShaderFormat shaderFormat,
176 bool enableDepth =
true,
177 bool overBlending =
false);
185SDL_GPUBuffer*
createBuffer(SDL_GPUDevice* device,
size_t bufferSize, SDL_GPUBufferUsageFlags usage);
192SDL_GPUTransferBuffer*
createTransferBuffer(SDL_GPUDevice* device,
size_t transferBufferSize,
bool upload);
198SDL_GPUTransferBuffer*
createUploadBuffer(SDL_GPUDevice* device,
size_t transferBufferSize);
204void uploadBuffers(SDL_GPUDevice* device, SDL_GPUCommandBuffer* cmd,
const std::vector<BufferUpload>& uploads);
213SDL_GPUTexture*
createEmptyTextureD32F(SDL_GPUDevice* device, Uint32 width, Uint32 height,
bool cube, Uint32 arraySize);
226 SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
228SDL_GPUTexture*
createTextureRGBA32(SDL_GPUDevice* device, Uint32 width, Uint32 height,
const void* data, SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT);
234SDL_GPUTexture*
loadTexture(SDL_GPUDevice* device,
const char* path);
241SDL_GPUTexture*
createDepthTexture(SDL_GPUDevice* device, Uint32 width, Uint32 height);
Definition Boilerplate.cpp:12
SDL_GPUColorTargetInfo makeColorTargetLoad(SDL_GPUTexture *texture)
Create a color render-target info with a clear color.
Definition Boilerplate.cpp:49
SDL_GPUShader * loadShader(SDL_GPUDevice *device, const char *path, SDL_GPUShaderFormat format, SDL_GPUShaderStage stage, Uint32 samplerCount, Uint32 uniformBufferCount, Uint32 storageBufferCount, Uint32 storageTextureCount)
Load and compile a shader from disk (explicit parameters).
Definition Boilerplate.cpp:101
SDL_GPUSampler * createLinearClampSampler(SDL_GPUDevice *device)
Create a linear-filtering, clamp-to-edge sampler.
Definition Boilerplate.cpp:632
void uploadBuffers(SDL_GPUDevice *device, SDL_GPUCommandBuffer *cmd, const std::vector< BufferUpload > &uploads)
Batch-upload multiple CPU buffers to their corresponding GPU buffers.
Definition Boilerplate.cpp:321
SDL_GPUDepthStencilTargetInfo makeDepthTarget(SDL_GPUTexture *texture, Uint8 layer, bool store, bool reverseZ)
Create a depth/stencil render-target info that clears to depth 1.0.
Definition Boilerplate.cpp:58
SDL_GPUColorTargetInfo makeColorTargetClear(SDL_GPUTexture *texture, SDL_FColor clearColor)
Create a color render-target info with a clear color.
Definition Boilerplate.cpp:39
SDL_GPUTransferBuffer * createUploadBuffer(SDL_GPUDevice *device, size_t transferBufferSize)
Allocate a GPU transfer buffer for uploading data.
Definition Boilerplate.cpp:316
SDL_GPUGraphicsPipeline * createGraphicsDepthPipeline(SDL_GPUDevice *device, PipelineDescription pipelineDesc)
Definition Boilerplate.cpp:159
constexpr SDL_GPUColorTargetBlendState OVER_BLEND_MODE
Definition Boilerplate.hpp:27
SDL_GPUBuffer * createBuffer(SDL_GPUDevice *device, size_t bufferSize, SDL_GPUBufferUsageFlags usage)
Allocate a GPU buffer of the given size and usage.
Definition Boilerplate.cpp:298
SDL_GPUTexture * createSampledColorTarget(SDL_GPUDevice *device, Uint32 width, Uint32 height, SDL_GPUTextureFormat format)
Create a sampleable 2D color render target of the given dimensions.
Definition Boilerplate.cpp:584
SDL_GPUSampler * createLinearRepeatSampler(SDL_GPUDevice *device, bool nearest)
Create a linear-filtering, repeat-addressing sampler.
Definition Boilerplate.cpp:603
SDL_GPUTexture * loadTexture(SDL_GPUDevice *device, const char *path)
Load an image file from disk and create a GPU texture from it.
Definition Boilerplate.cpp:539
SDL_GPUTransferBuffer * createTransferBuffer(SDL_GPUDevice *device, size_t transferBufferSize, bool upload)
Allocate a GPU transfer buffer for upload or download.
Definition Boilerplate.cpp:307
SDL_GPUTexture * createTextureRGBA32(SDL_GPUDevice *device, Uint32 width, Uint32 height, const void *data, SDL_GPUTextureFormat format)
Definition Boilerplate.cpp:418
SDL_GPUVertexAttribute makeAttribute(Uint32 location, SDL_GPUVertexElementFormat format, Uint32 offset, Uint32 bufferSlot)
Build an SDL_GPUVertexAttribute descriptor.
Definition Boilerplate.cpp:29
SDL_GPUTextureSamplerBinding makeTextureSamplerBinding(SDL_GPUTexture *texture, SDL_GPUSampler *sampler)
Create a texture-sampler binding pair for fragment shader use.
Definition Boilerplate.cpp:73
SDL_GPUTexture * createEmptyTextureD32F(SDL_GPUDevice *device, Uint32 width, Uint32 height, bool cube, Uint32 arraySize)
Create an empty depth texture, optionally cube/cube-array shaped.
Definition Boilerplate.cpp:372
SDL_GPUTexture * createTextureRGBA8(SDL_GPUDevice *device, Uint32 width, Uint32 height, const void *data, SDL_GPUTextureFormat format)
Create a 2D RGBA8 texture and upload pixel data to it.
Definition Boilerplate.cpp:479
ImGui_ImplSDLGPU3_InitInfo createImGuiInfo(SDL_GPUDevice *device, SDL_Window *window)
Create an ImGui initialization info struct for SDL3 GPU rendering.
Definition Boilerplate.cpp:19
SDL_GPUSampler * createLinearComparisonSampler(SDL_GPUDevice *device, SDL_GPUFilter filterMode, bool reverseZ)
Create a linear-filtering, comparison sampler (for shadow map depth comparison).
Definition Boilerplate.cpp:616
SDL_GPUShaderFormat selectShaderFormat(SDL_GPUDevice *device)
Pick the best available shader format for the given device.
Definition Boilerplate.cpp:81
SDL_GPUGraphicsPipeline * createGraphicsPipeline(SDL_GPUDevice *device, SDL_GPUTextureFormat &colorFormat, SDL_GPUShaderFormat shaderFormat, const ShaderInfo &vertexShaderInfo, const ShaderInfo &fragmentShaderInfo, const VertexInputLayout &vertexInputLayout, bool enableDepth, bool overBlending)
Create a full graphics pipeline from vertex/fragment shaders and vertex layout.
Definition Boilerplate.cpp:209
SDL_GPUTexture * createDepthTexture(SDL_GPUDevice *device, Uint32 width, Uint32 height)
Create a D32_FLOAT depth texture of the given dimensions.
Definition Boilerplate.cpp:564
Describes a pending CPU-to-GPU buffer upload: target buffer, source data, and byte size.
Definition Boilerplate.hpp:76
SDL_GPUBuffer * buffer
Definition Boilerplate.hpp:77
const void * data
Definition Boilerplate.hpp:78
size_t size
Definition Boilerplate.hpp:79
Definition Boilerplate.hpp:57
SDL_GPURasterizerState rasterizer_state
Definition Boilerplate.hpp:71
const ShaderInfo * fragmentShaderInfo
Definition Boilerplate.hpp:59
const VertexInputLayout * vertexInputLayout
Definition Boilerplate.hpp:63
bool depthTest
Definition Boilerplate.hpp:67
bool reverseZ
Definition Boilerplate.hpp:66
const SDL_GPUColorTargetDescription * colorTarget
Definition Boilerplate.hpp:64
SDL_GPUShaderFormat shaderFormat
Definition Boilerplate.hpp:61
const ShaderInfo * vertexShaderInfo
Definition Boilerplate.hpp:58
bool depthWrite
Definition Boilerplate.hpp:68
Descriptor for a single shader stage: file path, stage, and resource counts.
Definition Boilerplate.hpp:39
SDL_GPUShaderStage stage
Definition Boilerplate.hpp:41
Uint32 uniformBufferCount
Definition Boilerplate.hpp:43
Uint32 storageBufferCount
Definition Boilerplate.hpp:44
const char * path
Definition Boilerplate.hpp:40
Uint32 storageTextureCount
Definition Boilerplate.hpp:45
Uint32 samplerCount
Definition Boilerplate.hpp:42