group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Boilerplate.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <SDL3/SDL.h>
7#include <SDL3/SDL_gpu.h>
8
9#include <backends/imgui_impl_sdlgpu3.h>
10#include <cstddef>
11#include <vector>
12
13namespace Boilerplate
14{
17{
18 const char* path = nullptr;
19 SDL_GPUShaderStage stage = SDL_GPU_SHADERSTAGE_VERTEX;
20 Uint32 samplerCount = 0;
24};
25
28{
29 // Uint32 vertexPitch = 0;
30 std::vector<SDL_GPUVertexBufferDescription> bufferDescriptions;
31 std::vector<SDL_GPUVertexAttribute> attributes;
32};
33
36{
37 SDL_GPUBuffer* buffer = nullptr;
38 const void* data = nullptr;
39 size_t size = 0;
40};
41
46ImGui_ImplSDLGPU3_InitInfo createImGuiInfo(SDL_GPUDevice* device, SDL_Window* window);
47
54SDL_GPUVertexAttribute
55makeAttribute(Uint32 location, SDL_GPUVertexElementFormat format, Uint32 offset, Uint32 bufferSlot = 0);
56
61SDL_GPUColorTargetInfo makeColorTargetClear(SDL_GPUTexture* texture, SDL_FColor clearColor);
62
66SDL_GPUColorTargetInfo makeColorTargetLoad(SDL_GPUTexture* texture);
67
71SDL_GPUDepthStencilTargetInfo makeDepthTarget(SDL_GPUTexture* texture);
72
77SDL_GPUTextureSamplerBinding makeTextureSamplerBinding(SDL_GPUTexture* texture, SDL_GPUSampler* sampler);
78
82SDL_GPUShaderFormat selectShaderFormat(SDL_GPUDevice* device);
83
94SDL_GPUShader* loadShader(SDL_GPUDevice* device,
95 const char* path,
96 SDL_GPUShaderFormat format,
97 SDL_GPUShaderStage stage,
98 Uint32 samplerCount,
99 Uint32 uniformBufferCount,
100 Uint32 storageBufferCount,
101 Uint32 storageTextureCount);
102
108SDL_GPUShader* loadShader(SDL_GPUDevice* device, const ShaderInfo& shaderInfo, SDL_GPUShaderFormat format);
109
120SDL_GPUGraphicsPipeline* createGraphicsPipeline(SDL_GPUDevice* device,
121 SDL_GPUTextureFormat& colorFormat,
122 SDL_GPUShaderFormat shaderFormat,
123 const ShaderInfo& vertexShaderInfo,
124 const ShaderInfo& fragmentShaderInfo,
125 const VertexInputLayout& vertexInputLayout,
126 bool enableDepth = true,
127 bool overBlending = false);
128
134SDL_GPUBuffer* createBuffer(SDL_GPUDevice* device, size_t bufferSize, SDL_GPUBufferUsageFlags usage);
135
141SDL_GPUTransferBuffer* createTransferBuffer(SDL_GPUDevice* device, size_t transferBufferSize, bool upload);
142
147SDL_GPUTransferBuffer* createUploadBuffer(SDL_GPUDevice* device, size_t transferBufferSize);
148
153void uploadBuffers(SDL_GPUDevice* device, SDL_GPUCommandBuffer* cmd, const std::vector<BufferUpload>& uploads);
154
161SDL_GPUTexture* createTextureRGBA8(SDL_GPUDevice* device, Uint32 width, Uint32 height, const void* data);
162
167SDL_GPUTexture* loadTexture(SDL_GPUDevice* device, const char* path);
168
174SDL_GPUTexture* createDepthTexture(SDL_GPUDevice* device, Uint32 width, Uint32 height);
175
179SDL_GPUSampler* createLinearRepeatSampler(SDL_GPUDevice* device);
180
181} // namespace Boilerplate
Definition Boilerplate.cpp:12
SDL_GPUTexture * createTextureRGBA8(SDL_GPUDevice *device, Uint32 width, Uint32 height, const void *data)
Create a 2D RGBA8 texture and upload pixel data to it.
Definition Boilerplate.cpp:294
SDL_GPUColorTargetInfo makeColorTargetLoad(SDL_GPUTexture *texture)
Create a color render-target info with a clear color.
Definition Boilerplate.cpp:43
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:94
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:243
SDL_GPUColorTargetInfo makeColorTargetClear(SDL_GPUTexture *texture, SDL_FColor clearColor)
Create a color render-target info with a clear color.
Definition Boilerplate.cpp:33
SDL_GPUTransferBuffer * createUploadBuffer(SDL_GPUDevice *device, size_t transferBufferSize)
Allocate a GPU transfer buffer for uploading data.
Definition Boilerplate.cpp:238
SDL_GPUSampler * createLinearRepeatSampler(SDL_GPUDevice *device)
Create a linear-filtering, repeat-addressing sampler.
Definition Boilerplate.cpp:395
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:220
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:354
SDL_GPUTransferBuffer * createTransferBuffer(SDL_GPUDevice *device, size_t transferBufferSize, bool upload)
Allocate a GPU transfer buffer for upload or download.
Definition Boilerplate.cpp:229
SDL_GPUDepthStencilTargetInfo makeDepthTarget(SDL_GPUTexture *texture)
Create a depth/stencil render-target info that clears to depth 1.0.
Definition Boilerplate.cpp:52
SDL_GPUVertexAttribute makeAttribute(Uint32 location, SDL_GPUVertexElementFormat format, Uint32 offset, Uint32 bufferSlot)
Build an SDL_GPUVertexAttribute descriptor.
Definition Boilerplate.cpp:23
SDL_GPUTextureSamplerBinding makeTextureSamplerBinding(SDL_GPUTexture *texture, SDL_GPUSampler *sampler)
Create a texture-sampler binding pair for fragment shader use.
Definition Boilerplate.cpp:66
ImGui_ImplSDLGPU3_InitInfo createImGuiInfo(SDL_GPUDevice *device, SDL_Window *window)
Create an ImGui initialization info struct for SDL3 GPU rendering.
Definition Boilerplate.cpp:13
SDL_GPUShaderFormat selectShaderFormat(SDL_GPUDevice *device)
Pick the best available shader format for the given device.
Definition Boilerplate.cpp:74
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:152
SDL_GPUTexture * createDepthTexture(SDL_GPUDevice *device, Uint32 width, Uint32 height)
Create a D32_FLOAT depth texture of the given dimensions.
Definition Boilerplate.cpp:376
Describes a pending CPU-to-GPU buffer upload: target buffer, source data, and byte size.
Definition Boilerplate.hpp:36
SDL_GPUBuffer * buffer
Definition Boilerplate.hpp:37
const void * data
Definition Boilerplate.hpp:38
size_t size
Definition Boilerplate.hpp:39
Descriptor for a single shader stage: file path, stage, and resource counts.
Definition Boilerplate.hpp:17
SDL_GPUShaderStage stage
Definition Boilerplate.hpp:19
Uint32 uniformBufferCount
Definition Boilerplate.hpp:21
Uint32 storageBufferCount
Definition Boilerplate.hpp:22
const char * path
Definition Boilerplate.hpp:18
Uint32 storageTextureCount
Definition Boilerplate.hpp:23
Uint32 samplerCount
Definition Boilerplate.hpp:20
Vertex buffer layout: stride (pitch) and per-attribute descriptions.
Definition Boilerplate.hpp:28
std::vector< SDL_GPUVertexAttribute > attributes
Definition Boilerplate.hpp:31
std::vector< SDL_GPUVertexBufferDescription > bufferDescriptions
Definition Boilerplate.hpp:30