Compare commits

..

2 Commits

Author SHA1 Message Date
338c2f1bde Pipeline Changes 2026-03-24 12:49:09 +01:00
73fcd0be6b Shaders are compiled by CMake 2026-03-24 12:48:37 +01:00
6 changed files with 125 additions and 0 deletions

View File

@ -4,6 +4,34 @@ file(GLOB_RECURSE GRAPHICS_SOURCES CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
) )
set(SHADER_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
set(SHADER_OUT_DIR ${CMAKE_BINARY_DIR}/shaders)
file(GLOB_RECURSE SHADERS
${SHADER_SRC_DIR}/*.vert
${SHADER_SRC_DIR}/*.frag
)
find_program(GLSLC glslc REQUIRED)
set(SPIRV_SHADERS)
foreach(SHADER ${SHADERS})
get_filename_component(FILE_NAME ${SHADER} NAME)
set(SPIRV_FILE ${SHADER_OUT_DIR}/${FILE_NAME}.spv)
add_custom_command(
OUTPUT ${SPIRV_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADER_OUT_DIR}
COMMAND ${GLSLC} ${SHADER} -o ${SPIRV_FILE}
DEPENDS ${SHADER}
COMMENT "Compiling ${FILE_NAME} with glslc"
VERBATIM
)
list(APPEND SPIRV_SHADERS ${SPIRV_FILE})
endforeach()
add_custom_target(Shaders ALL DEPENDS ${SPIRV_SHADERS})
add_library(deerith_graphics ${GRAPHICS_SOURCES}) add_library(deerith_graphics ${GRAPHICS_SOURCES})
target_include_directories(deerith_graphics target_include_directories(deerith_graphics
@ -18,6 +46,8 @@ find_package(glfw3 REQUIRED)
find_package(glm REQUIRED) find_package(glm REQUIRED)
find_package(fmt REQUIRED) find_package(fmt REQUIRED)
add_dependencies(deerith_graphics Shaders)
target_link_libraries(deerith_graphics target_link_libraries(deerith_graphics
PUBLIC PUBLIC
deerith::core deerith::core

View File

@ -0,0 +1,9 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(fragColor, 1.0);
}

View File

@ -0,0 +1,20 @@
#version 450
layout(location = 0) out vec3 fragColor;
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
vec3 colors[3] = vec3[](
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(0.0, 0.0, 1.0)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragColor = colors[gl_VertexIndex];
}

View File

@ -0,0 +1,21 @@
#pragma once
#include <deerith/core/types.h>
#include <glm/glm.hpp>
#include <vulkan/vulkan.h>
namespace derith {
namespace graphics {
struct StaticMeshVertex {
glm::vec3 position;
glm::vec3 normal;
};
enum class VertexLayout : uint8_t {
StaticMesh = 0
};
extern VkPipelineVertexInputStateCreateInfo static_mesh_vertex_input_state;
void create_vulkan_vertex_inputs();
} // namespace graphics
} // namespace derith

View File

@ -1,4 +1,5 @@
#include "detail/graphics.h" #include "detail/graphics.h"
#include "detail/vertex_layout.h"
#include <fstream> #include <fstream>

View File

@ -0,0 +1,44 @@
#include "detail/vertex_layout.h"
#include <array>
namespace derith {
namespace graphics {
void create_vulkan_static_mesh_vertex_input_state();
VkPipelineVertexInputStateCreateInfo static_mesh_vertex_input_state;
VkVertexInputBindingDescription static_mesh_binding_description;
std::array<VkVertexInputAttributeDescription, 2> static_mesh_attribute_descriptors;
} // namespace graphics
void graphics::create_vulkan_vertex_inputs() {
create_vulkan_static_mesh_vertex_input_state();
}
void graphics::create_vulkan_static_mesh_vertex_input_state() {
VkVertexInputBindingDescription bindingDescription{};
bindingDescription.binding = 0;
bindingDescription.stride = sizeof(StaticMeshVertex);
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
static_mesh_attribute_descriptors[0] = {};
static_mesh_attribute_descriptors[0].binding = 0;
static_mesh_attribute_descriptors[0].location = 0;
static_mesh_attribute_descriptors[0].format = VK_FORMAT_R32G32B32_SFLOAT;
static_mesh_attribute_descriptors[0].offset = offsetof(StaticMeshVertex, position);
static_mesh_attribute_descriptors[1] = {};
static_mesh_attribute_descriptors[1].binding = 0;
static_mesh_attribute_descriptors[1].location = 1;
static_mesh_attribute_descriptors[1].format = VK_FORMAT_R32G32B32_SFLOAT;
static_mesh_attribute_descriptors[1].offset = offsetof(StaticMeshVertex, normal);
static_mesh_vertex_input_state = {};
static_mesh_vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
static_mesh_vertex_input_state.vertexBindingDescriptionCount = 1;
static_mesh_vertex_input_state.pVertexBindingDescriptions = &static_mesh_binding_description;
static_mesh_vertex_input_state.vertexAttributeDescriptionCount = static_cast<uint32_t>(static_mesh_attribute_descriptors.size());
static_mesh_vertex_input_state.pVertexAttributeDescriptions = static_mesh_attribute_descriptors.data();
}
} // namespace derith