Compare commits

..

No commits in common. "c0b78452155f2ad468d5061a98d9976f98816a79" and "fd310560f9b153eb8a454cb65b627af7e3454d8c" have entirely different histories.

26 changed files with 57 additions and 27 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

2
.gitignore vendored
View file

@ -5,4 +5,4 @@ build/
# MacOS Cache
.DS_Store
.cache/

View file

@ -2,7 +2,7 @@
#include <pch.h>
SDL_GPUCommandBuffer* CommandBufferAcquire(SDL_GPUDevice* device) {
SDL_assert(device != NULL);
assert(device != NULL);
SDL_GPUCommandBuffer* command_buffer = SDL_AcquireGPUCommandBuffer(device);
if(command_buffer == NULL) {
@ -13,7 +13,7 @@ SDL_GPUCommandBuffer* CommandBufferAcquire(SDL_GPUDevice* device) {
}
bool CommandBufferSubmit(SDL_GPUCommandBuffer* command_buffer) {
SDL_assert(command_buffer != NULL);
assert(command_buffer != NULL);
bool success = SDL_SubmitGPUCommandBuffer(command_buffer);
if(!success) {

View file

@ -1,11 +1,12 @@
#include <SDL3/SDL_gpu.h>
#include <pch.h>
SDL_GPUGraphicsPipeline* GraphicsPipelineCreate(SDL_GPUDevice* device, SDL_Window* window,
SDL_GPUShader* vertex_shader, SDL_GPUShader* fragment_shader) {
SDL_assert(device != NULL);
SDL_assert(window != NULL);
SDL_assert(vertex_shader != NULL);
SDL_assert(fragment_shader != NULL);
assert(device != NULL);
assert(window != NULL);
assert(vertex_shader != NULL);
assert(fragment_shader != NULL);
SDL_GPUGraphicsPipeline* pipeline = SDL_CreateGPUGraphicsPipeline(device,
&(SDL_GPUGraphicsPipelineCreateInfo){
@ -24,8 +25,14 @@ SDL_GPUGraphicsPipeline* GraphicsPipelineCreate(SDL_GPUDevice* device, SDL_Windo
.slot = 0,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
.instance_step_rate = 0,
.pitch = sizeof(Vertex),
.pitch = sizeof(float) * 3,
},
{
.slot = 1,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
.instance_step_rate = 0,
.pitch = sizeof(float) * 3,
}
},
.num_vertex_attributes = 2,
.vertex_attributes = (SDL_GPUVertexAttribute[]){
@ -33,13 +40,13 @@ SDL_GPUGraphicsPipeline* GraphicsPipelineCreate(SDL_GPUDevice* device, SDL_Windo
.buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
.location = 0,
.offset = offsetof(Vertex, pos),
.offset = 0,
},
{
.buffer_slot = 0,
.buffer_slot = 1,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
.location = 1,
.offset = offsetof(Vertex, color),
.offset = 0,
}
}
},

View file

@ -1,7 +1,7 @@
#include <pch.h>
SDL_GPUShader* ShaderLoad(SDL_GPUDevice* device, const char* filename, SDL_GPUShaderStage stage) {
SDL_assert(device != NULL);
assert(device != NULL);
FileData file = FileRead(filename);
SDL_GPUShader* shader = SDL_CreateGPUShader(device,

View file

@ -3,9 +3,9 @@
#include <pch.h>
bool UploadToBuffer(SDL_GPUDevice* device, const void* data, size_t byte_size, SDL_GPUBuffer* buffer) {
SDL_assert(device != NULL);
SDL_assert(data != NULL);
SDL_assert(buffer != NULL);
assert(device != NULL);
assert(data != NULL);
assert(buffer != NULL);
SDL_GPUTransferBuffer* transfer_buffer = SDL_CreateGPUTransferBuffer(device,
&(SDL_GPUTransferBufferCreateInfo){
@ -28,10 +28,10 @@ bool UploadToBuffer(SDL_GPUDevice* device, const void* data, size_t byte_size, S
SDL_UnmapGPUTransferBuffer(device, transfer_buffer);
SDL_GPUCommandBuffer* copy_command_buffer = CommandBufferAcquire(device);
SDL_assert(copy_command_buffer != NULL);
assert(copy_command_buffer != NULL);
SDL_GPUCopyPass* copy_pass = CopyPassBegin(copy_command_buffer);
SDL_assert(copy_pass != NULL);
assert(copy_pass != NULL);
SDL_UploadToGPUBuffer(copy_pass,
&(SDL_GPUTransferBufferLocation){

View file

@ -1,7 +1,7 @@
#include <pch.h>
SDL_GPUCopyPass* CopyPassBegin(SDL_GPUCommandBuffer* copy_command_buffer) {
SDL_assert(copy_command_buffer != NULL);
assert(copy_command_buffer != NULL);
SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(copy_command_buffer);
if(copy_pass == NULL) {
@ -12,7 +12,7 @@ SDL_GPUCopyPass* CopyPassBegin(SDL_GPUCommandBuffer* copy_command_buffer) {
}
void CopyPassEnd(SDL_GPUCopyPass* copy_pass) {
SDL_assert(copy_pass != NULL);
assert(copy_pass != NULL);
SDL_EndGPUCopyPass(copy_pass);
}

View file

@ -5,7 +5,7 @@ int main(int argc, char** argv) {
InitSystems();
SDL_GPUDevice* device = DeviceCreate();
SDL_assert(device != NULL);
assert(device != NULL);
SDL_Window* window = SDL_CreateWindow("Brimstone", 800, 600, 0);
if(window == NULL) {
@ -14,10 +14,21 @@ int main(int argc, char** argv) {
}
SDL_ClaimWindowForGPUDevice(device, window);
Vertex vertices[] = {
/*Vertex vertices[] = {
{ -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f },
};*/
float vertices[3][3] = {
{ -0.5f, -0.5f, 0.0f },
{ 0.5f, -0.5f, 0.0f },
{ 0.0f, 0.5f, 0.0f },
};
float colors[3][3] = {
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
};
SDL_GPUBuffer* vertex_buffer = SDL_CreateGPUBuffer(device,
@ -27,17 +38,26 @@ int main(int argc, char** argv) {
});
bool upload_successful = UploadToBuffer(device, vertices, sizeof(vertices), vertex_buffer);
SDL_assert(upload_successful);
assert(upload_successful);
SDL_GPUBuffer* color_buffer = SDL_CreateGPUBuffer(device,
&(SDL_GPUBufferCreateInfo){
.usage = SDL_GPU_BUFFERUSAGE_VERTEX,
.size = sizeof(colors),
});
upload_successful = UploadToBuffer(device, colors, sizeof(colors), color_buffer);
assert(upload_successful);
SDL_GPUShader* vertex_shader = ShaderLoad(device, "shader.vert.spv", SDL_GPU_SHADERSTAGE_VERTEX);
SDL_assert(vertex_shader != NULL);
assert(vertex_shader != NULL);
SDL_GPUShader* fragment_shader = ShaderLoad(device, "shader.frag.spv", SDL_GPU_SHADERSTAGE_FRAGMENT);
SDL_assert(fragment_shader != NULL);
assert(fragment_shader != NULL);
SDL_GPUGraphicsPipeline* pipeline = GraphicsPipelineCreate(
device, window, vertex_shader, fragment_shader);
SDL_assert(pipeline != NULL);
assert(pipeline != NULL);
bool running = true;
SDL_Event event;
@ -79,8 +99,12 @@ int main(int argc, char** argv) {
.buffer = vertex_buffer,
.offset = 0,
},
{
.buffer = color_buffer,
.offset = 0,
},
},
1);
2);
SDL_DrawGPUPrimitives(render_pass, 3, 1, 0, 0);
SDL_EndGPURenderPass(render_pass);

View file

@ -8,7 +8,6 @@
#include <stdlib.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_assert.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_gpu.h>