From 736544360983eed57a5762c6c6e54f9ea5e9a565 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sun, 16 Mar 2025 14:29:30 -0500 Subject: [PATCH] Use new shader lookup in RHI GL2 --- src/sdl/rhi_gl2_platform.cpp | 52 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/sdl/rhi_gl2_platform.cpp b/src/sdl/rhi_gl2_platform.cpp index e22fdceaf..98a87f222 100644 --- a/src/sdl/rhi_gl2_platform.cpp +++ b/src/sdl/rhi_gl2_platform.cpp @@ -36,40 +36,25 @@ void SdlGl2Platform::present() static std::array glsllist_lump_names(const char* name) { - std::string vertex_list_name = fmt::format("rhi_glsllist_{}_vertex", name); - std::string fragment_list_name = fmt::format("rhi_glsllist_{}_fragment", name); + std::string vertex_list_name = fmt::format("rhi_glsllist_{}_vertex.txt", name); + std::string fragment_list_name = fmt::format("rhi_glsllist_{}_fragment.txt", name); return {std::move(vertex_list_name), std::move(fragment_list_name)}; } static std::vector get_sources_from_glsllist_lump(const char* lumpname) { - std::string shaderspk3 = "shaders.pk3"; - INT32 shaderwadnum = -1; - for (INT32 wadnum = 0; wadnum <= mainwads; wadnum++) - { - std::string wadname = std::string(wadfiles[wadnum]->filename); - if (wadname.find(shaderspk3) != std::string::npos) - { - shaderwadnum = wadnum; - break; - } - } - - if (shaderwadnum < 0) - { - throw std::runtime_error("Unable to identify the shaders.pk3 wadnum"); - } - - UINT16 glsllist_lump_num = W_CheckNumForLongNamePwad(lumpname, shaderwadnum, 0); - if (glsllist_lump_num == INT16_MAX) + size_t buffer_size; + if (!W_ReadShader(lumpname, &buffer_size, nullptr)) { throw std::runtime_error(fmt::format("Unable to find glsllist lump {}", lumpname)); } - std::string glsllist_lump_data; - glsllist_lump_data.resize(W_LumpLengthPwad(shaderwadnum, glsllist_lump_num)); - W_ReadLumpPwad(shaderwadnum, glsllist_lump_num, glsllist_lump_data.data()); + glsllist_lump_data.resize(buffer_size); + if (!W_ReadShader(lumpname, &buffer_size, glsllist_lump_data.data())) + { + throw std::runtime_error(fmt::format("Unable to read glsllist lump {}", lumpname)); + } std::istringstream glsllist(glsllist_lump_data); std::vector sources; @@ -90,15 +75,24 @@ static std::vector get_sources_from_glsllist_lump(const char* lumpn line.pop_back(); } - UINT16 source_lump_num = W_CheckNumForLongNamePwad(line.c_str(), shaderwadnum, 0); - if (source_lump_num == INT16_MAX) + // Compat: entries not ending in .glsl should append, for new shader file lookup system + size_t glsl_pos = line.find(".glsl"); + if (line.size() < 5 || glsl_pos == line.npos || glsl_pos != line.size() - 5) { - throw std::runtime_error(fmt::format("Unable to find glsl source lump lump {}", lumpname)); + line.append(".glsl"); } + size_t source_lump_size; + if (!W_ReadShader(line.c_str(), &source_lump_size, nullptr)) + { + throw std::runtime_error(fmt::format("Unable to find glsl source lump lump {}", line)); + } std::string source_lump; - source_lump.resize(W_LumpLengthPwad(shaderwadnum, source_lump_num)); - W_ReadLumpPwad(shaderwadnum, source_lump_num, source_lump.data()); + source_lump.resize(source_lump_size); + if (!W_ReadShader(line.c_str(), &source_lump_size, source_lump.data())) + { + throw std::runtime_error(fmt::format("Unable to read glsl source lump lump {}", line)); + } sources.emplace_back(source_lump); }