The vanilla shader sources are moved out of r_opengl.c. All shaders are given to the backend instead by a new file, hw_shaders.c. As an exception, the backend will contain a fallback shader that is used when the backend user tries to use a broken shader. ("backend user" refers to the SRB2 code that uses the backend)
Handling of switching between custom and non-custom shaders is moved out of r_opengl.c. This may also help possible future efforts of making custom shaders more flexible. (like toggling each shader during runtime from Lua)
***
The functions of the new API for shader handling in the backend:
-`boolean InitShaders(void)`
Prepares the shader system for use. Compiles the fallback shader. Returns false if shaders cannot be used. (either because of lack of support on the gpu or shader support being disabled during compiling SRB2)
Loads shader source code from the null-terminated string `code` into `slot`. Slots start from 1, the first slot 0 is reserved for the fallback shader. `stage` is either fragment or vertex. (Perhaps in the future the rest of the stages could be added)
-`boolean CompileShader(int slot)`
Compiles the shader in `slot` using the sources given with `LoadShader`. Returns false on failure.
***
Functions that remain mostly the same: (`SetShader` description and behaviour is slightly different)
-`void SetShader(int slot)`
If shaders are enabled, the currently used shader is set to `slot`. The shader must be loaded and compiled successfully to use it, otherwise the fallback shader is used.
-`void UnSetShader(void)`
The fixed function pipeline is used for draw calls instead of shaders. (used for most/all non-3d stuff?)
Sets certain values that are given to shader uniform variables. (currently only level time)
The shader "pre-preprocessor"
-----------------------------
All shaders (except for the fallback shader) will go through a new preprocessor before being handed over to the backend. This preprocessor serves the purpose of communicating relevant graphics settings to the shader by adding `#define` lines to the source code of the shaders. (this new preprocessor is ran before the standard GLSL preprocessor, hence the "pre-preprocessor" name)
If a `#version` line is present, the `#define` lines are added after it. Otherwise they are added to the beginning of the shader.
The following definitions are added:
-`#define MODEL_LIGHTING`: Added if model lighting is enabled.
-`#define PALETTE_RENDERING`: Planned definition that is to be used if palette rendering is enabled.
- Perhaps some definitions about the current environment could be added, for example a definition for the OpenGL version.
When the graphics settings are changed, the shaders are reprocessed and recompiled if needed.
This change merges the previously used "model" and "lit model" shaders together, eliminating the need for keeping separate shaders for every possible graphics setting configuration.
This change will also make the implementation of palette shaders easier by providing a clear mechanism for switching them on or off. Custom shaders will also be able to support palette rendering.