Skip to content

Commit

Permalink
xrRender_GL: improve shader generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jun 1, 2024
1 parent 87ae41b commit 72e5e58
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Layers/xrRenderPC_GL/rgl_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class shader_options_holder
string512 m_options[128];

public:
void add(cpcstr string)
{
strconcat(m_options[pos++], string, "\n");
}

void add(cpcstr name, cpcstr value)
{
// It's important to have postfix increment!
Expand Down Expand Up @@ -191,15 +196,10 @@ class shader_sources_manager
void apply_options(shader_options_holder& options)
{
// Compile sources list
const size_t head_lines = 2; // "#version" line + name_comment line
constexpr size_t head_lines = 1; // name_comment line
m_sources_lines = m_source.size() + options.size() + head_lines;
m_sources = xr_alloc<pcstr>(m_sources_lines);
#ifdef DEBUG
m_sources[0] = "#version 410\n#pragma optimize (off)\n";
#else
m_sources[0] = "#version 410\n";
#endif
m_sources[1] = m_name_comment;
m_sources[0] = m_name_comment;

// Make define lines
for (size_t i = 0; i < options.size(); ++i)
Expand Down Expand Up @@ -238,6 +238,18 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
sh_name.append(option);
};

options.add("#version 410");

#ifdef DEBUG
options.add("#pragma optimize (off)");
sh_name.append(0u);
#else
options.add("#pragma optimize (on)");
sh_name.append(1u);
#endif

options.add("#extension GL_ARB_separate_shader_objects : enable");

// Shadow map size
{
xr_itoa(m_SMAPSize, c_smapsize, 10);
Expand Down Expand Up @@ -483,9 +495,6 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
sh_name.append(static_cast<u32>(0)); // DX10_1_NATIVE off
}

// Don't mix optimized and unoptimized shaders
sh_name.append(static_cast<u32>(shader_sources_manager::optimized()));

// finish
options.finish();
sh_name.finish();
Expand Down

0 comments on commit 72e5e58

Please sign in to comment.