Skip to content

Commit b7826a8

Browse files
authored
Fix shader paths again (#44)
* you can't call terminate() without an exception... * Fix problem with linking + static and shader paths
1 parent 109762b commit b7826a8

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/candlewick/core/Shader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
namespace candlewick {
1212

13+
std::string g_shader_dir = g_default_shader_dir;
14+
15+
void setShadersDirectory(const char *path) { g_shader_dir = path; }
16+
const char *currentShaderDirectory() { return g_shader_dir.c_str(); }
17+
1318
SDL_GPUShaderStage detect_shader_stage(const char *filename) {
1419
SDL_GPUShaderStage stage;
1520
if (SDL_strstr(filename, ".vert"))
@@ -38,6 +43,9 @@ ShaderCode loadShaderFile(const char *filename, const char *shader_ext) {
3843
char shader_path[256];
3944
SDL_snprintf(shader_path, sizeof(shader_path), "%s/%s.%s",
4045
g_shader_dir.c_str(), filename, shader_ext);
46+
#ifndef NDEBUG
47+
SDL_Log("Loading shader file %s", shader_path);
48+
#endif
4149

4250
size_t code_size;
4351
void *code = SDL_LoadFile(shader_path, &code_size);

src/candlewick/core/Shader.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
namespace candlewick {
88

9-
namespace {
10-
static const char *g_default_shader_dir = CANDLEWICK_SHADER_BIN_DIR;
11-
static std::string g_shader_dir = g_default_shader_dir;
12-
} // namespace
9+
constexpr const char *g_default_shader_dir = CANDLEWICK_SHADER_BIN_DIR;
1310

14-
inline void setShadersDirectory(const char *path) { g_shader_dir = path; }
15-
inline const char *currentShaderDirectory() { return g_shader_dir.c_str(); }
11+
/// \brief Set the current (global) directory where shaders are to be found.
12+
/// \sa currentShaderDirectory()
13+
void setShadersDirectory(const char *path);
14+
/// \brief Get the current (global) directory where shaders are found.
15+
const char *currentShaderDirectory();
1616

1717
SDL_GPUShaderStage detect_shader_stage(const char *filename);
1818

src/candlewick/core/errors.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ namespace detail {
3838
inline void terminate_with_message(
3939
std::string_view msg,
4040
std::source_location location = std::source_location::current()) {
41-
SDL_LogError(
42-
SDL_LOG_CATEGORY_APPLICATION, "%s",
41+
throw std::runtime_error(
4342
detail::error_message_format(location.function_name(), "{:s}", msg)
4443
.c_str());
45-
::std::terminate();
4644
}
4745

4846
[[noreturn]]

0 commit comments

Comments
 (0)