From 20a8974f9b88bec1686c0a4bf0b6ace9850bdda3 Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 11 Apr 2024 00:12:02 -0400 Subject: [PATCH] fix issue with shader compiler --- CMakeLists.txt | 2 +- include/blt/gfx/shader.h | 3 ++- libraries/BLT | 2 +- src/blt/gfx/shader.cpp | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 372585a..87a3427 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.9.3) +set(BLT_GRAPHICS_VERSION 0.9.4) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/shader.h b/include/blt/gfx/shader.h index 30ab1b2..1cbfa46 100644 --- a/include/blt/gfx/shader.h +++ b/include/blt/gfx/shader.h @@ -151,7 +151,8 @@ namespace blt::gfx GLuint fragmentShaderID = 0; static unsigned int createShader(const std::string& source, int type); - + + static std::string loadShader(std::string_view file); public: /** * Creates a shader diff --git a/libraries/BLT b/libraries/BLT index 0ec0548..9db3f12 160000 --- a/libraries/BLT +++ b/libraries/BLT @@ -1 +1 @@ -Subproject commit 0ec0548661bbacbe7849b37c4019693dbfb47279 +Subproject commit 9db3f120489ff27aa560e488d82b5ae0d64019df diff --git a/src/blt/gfx/shader.cpp b/src/blt/gfx/shader.cpp index 684eafa..8f56174 100644 --- a/src/blt/gfx/shader.cpp +++ b/src/blt/gfx/shader.cpp @@ -93,6 +93,7 @@ namespace blt::gfx // loads the shader code for later complication and uploading into the graphics card // TODO: defines can be added here by sending them as additional strings. No need to edit the source string glShaderSource(shaderID, 1, &shader_code, nullptr); + // Compile it glCompileShader(shaderID); @@ -129,8 +130,8 @@ namespace blt::gfx if (!load_as_string) { // BLT provides a recursive file loader for glsl shaders. It's pretty much just a recursive function looking for include statements. - vertex_source = blt::fs::loadShaderFile(vertex); - fragment_source = blt::fs::loadShaderFile(fragment); + vertex_source = loadShader(vertex); + fragment_source = loadShader(fragment); } else { vertex_source = removeEmptyFirstLines(vertex_source); @@ -221,6 +222,15 @@ namespace blt::gfx move.programID = -1; } + std::string shader_t::loadShader(std::string_view file) + { + auto lines = blt::fs::recursiveInclude(file); + std::string str; + for (const auto& v : lines) + str += v; + return str; + } + shader_base_t& shader_base_t::setBool(const std::string& name, bool value) { if (auto i = getUniformLocation(name))