Use new shader lookup in RHI GL2

This commit is contained in:
Eidolon 2025-03-16 14:29:30 -05:00
parent 014ea281b6
commit 7365443609

View file

@ -36,40 +36,25 @@ void SdlGl2Platform::present()
static std::array<std::string, 2> 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<std::string> 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<std::string> sources;
@ -90,15 +75,24 @@ static std::vector<std::string> 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);
}