UFO: Alien Invasion
Loading...
Searching...
No Matches
r_program.cpp File Reference

Shader (GLSL) backend functions. More...

#include "r_local.h"
#include "r_error.h"
#include "r_program.h"
#include "../../shared/parse.h"
#include "../../shared/shared.h"
Include dependency graph for r_program.cpp:

Go to the source code of this file.

Macros

#define SHADER_BUF_SIZE   16384
#define FILTER_SIZE   3
 width of convolution filter (for blur/bloom effects)

Enumerations

enum  shaderQualityLevel_t { SHQ_LOW , SHQ_MID , SHQ_HIGH , SHQ_NUM }

Functions

void R_UseProgram (r_program_t *prog)
static r_progvar_tR_ProgramVariable (int type, const char *name)
void R_ProgramParameter1i (const char *name, GLint value)
void R_ProgramParameter1f (const char *name, GLfloat value)
void R_ProgramParameter1fvs (const char *name, GLint size, GLfloat *value)
void R_ProgramParameter2fv (const char *name, GLfloat *value)
void R_ProgramParameter2fvs (const char *name, GLint size, GLfloat *value)
void R_ProgramParameter3fv (const char *name, GLfloat *value)
void R_ProgramParameter3fvs (const char *name, GLint size, GLfloat *value)
void R_ProgramParameter4fv (const char *name, GLfloat *value)
void R_ProgramParameter4fvs (const char *name, GLint size, GLfloat *value)
void R_ProgramParameterMatrix4fv (const char *name, GLfloat *value)
void R_AttributePointer (const char *name, GLuint size, const GLvoid *array)
void R_EnableAttribute (const char *name)
void R_DisableAttribute (const char *name)
static void R_ShutdownShader (r_shader_t *sh)
static void R_ShutdownProgram (r_program_t *prog)
void R_ShutdownPrograms (void)
static size_t R_PreprocessShaderAddToShaderBuf (const char *name, const char *in, char **out, size_t *len)
 Prefixes shader string (out) with in.
static size_t R_InitializeShader (const GLenum type, const char *name, char *out, size_t len)
 Prefixes the shader string with user settings and the video hardware manufacturer.
static size_t R_PreprocessShaderR (const char *name, const char **inPtr, char *out, long *remainingOutChars, bool nested, bool inElse)
 Do our own preprocessing to the shader file, before the GLSL implementation calls it's preprocessor.
static size_t R_PreprocessShader (const char *name, const char *in, char *out, size_t *remainingOutChars)
 Do our own preprocessing to the shader file, before the GLSL implementation calls it's preprocessor.
static r_shader_tR_LoadShader (const GLenum type, const char *name)
 Reads/Preprocesses/Compiles the specified shader into a program.
r_program_tR_LoadProgram (const char *name, programInitFunc_t init, programUseFunc_t use)
static void R_InitWorldProgram (r_program_t *prog)
static void R_UseWorldProgram (r_program_t *prog)
static void R_InitModelProgram (r_program_t *prog)
static void R_UseModelProgram (r_program_t *prog)
static void R_InitWarpProgram (r_program_t *prog)
static void R_UseWarpProgram (r_program_t *prog)
static void R_InitGeoscapeProgram (r_program_t *prog)
static int R_PascalTriangle (int row, int col)
static void R_InitConvolveProgram (r_program_t *prog)
static void R_UseConvolveProgram (r_program_t *prog)
 Use the filter convolution glsl program.
static void R_InitCombine2Program (r_program_t *prog)
static void R_InitAtmosphereProgram (r_program_t *prog)
static void R_InitSimpleGlowProgram (r_program_t *prog)
void R_InitParticleProgram (r_program_t *prog)
void R_UseParticleProgram (r_program_t *prog)
void R_InitPrograms (void)
void R_RestartPrograms_f (void)
 Reloads the glsl shaders.

Variables

const char * shaderQualityLevelNames [SHQ_NUM][2]
vec2_t fogRange

Detailed Description

Shader (GLSL) backend functions.

Definition in file r_program.cpp.

Macro Definition Documentation

◆ FILTER_SIZE

#define FILTER_SIZE   3

width of convolution filter (for blur/bloom effects)

Definition at line 941 of file r_program.cpp.

Referenced by R_InitConvolveProgram(), R_InitPrograms(), and R_UseConvolveProgram().

◆ SHADER_BUF_SIZE

#define SHADER_BUF_SIZE   16384

Definition at line 33 of file r_program.cpp.

Referenced by R_LoadShader(), and R_PreprocessShaderR().

Enumeration Type Documentation

◆ shaderQualityLevel_t

Enumerator
SHQ_LOW 
SHQ_MID 
SHQ_HIGH 
SHQ_NUM 

Definition at line 35 of file r_program.cpp.

Function Documentation

◆ R_AttributePointer()

void R_AttributePointer ( const char * name,
GLuint size,
const GLvoid * array )

Definition at line 211 of file r_program.cpp.

References GL_ATTRIBUTE, GLuint, name, R_ProgramVariable(), and v.

Referenced by R_BindArray().

◆ R_DisableAttribute()

void R_DisableAttribute ( const char * name)

Definition at line 231 of file r_program.cpp.

References GL_ATTRIBUTE, name, R_ProgramVariable(), and v.

Referenced by R_EnableAnimation(), and R_EnableModelLights().

◆ R_EnableAttribute()

void R_EnableAttribute ( const char * name)

Definition at line 221 of file r_program.cpp.

References GL_ATTRIBUTE, name, R_ProgramVariable(), and v.

Referenced by R_EnableAnimation(), R_EnableModelLights(), and R_EnableWorldLights().

◆ R_InitAtmosphereProgram()

void R_InitAtmosphereProgram ( r_program_t * prog)
static

Definition at line 993 of file r_program.cpp.

References R_ProgramParameter1i(), R_ProgramParameter2fv(), and R_ProgramParameter4fv().

Referenced by R_InitPrograms().

◆ R_InitCombine2Program()

void R_InitCombine2Program ( r_program_t * prog)
static

Definition at line 983 of file r_program.cpp.

References R_ProgramParameter1i(), and R_ProgramParameter4fv().

Referenced by R_InitPrograms().

◆ R_InitConvolveProgram()

void R_InitConvolveProgram ( r_program_t * prog)
static

◆ R_InitGeoscapeProgram()

void R_InitGeoscapeProgram ( r_program_t * prog)
static

Definition at line 914 of file r_program.cpp.

References R_ProgramParameter1i(), R_ProgramParameter2fv(), and R_ProgramParameter4fv().

Referenced by R_InitPrograms().

◆ R_InitializeShader()

size_t R_InitializeShader ( const GLenum type,
const char * name,
char * out,
size_t len )
static

Prefixes the shader string with user settings and the video hardware manufacturer.

The shader needs to know the rendered width & height, the glsl version, and the hardware manufacturer.

Parameters
[in]typeThe type of shader, currently either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
[in]nameThe name of the shader.
[in,out]out
[in,out]lenThe amount of space left in the buffer pointed to by *out.
Returns
The number of characters prefixed to the shader string.

Definition at line 309 of file r_program.cpp.

References Com_Error(), ERR_FATAL, GL_FRAGMENT_SHADER, GL_VERTEX_SHADER, GLenum, GLHW_ATI, GLHW_GENERIC, GLHW_INTEL, GLHW_MESA, GLHW_NVIDIA, int(), len, name, r_config, r_glsl_version, R_PreprocessShaderAddToShaderBuf(), type, va(), and viddef.

Referenced by R_LoadShader().

◆ R_InitModelProgram()

◆ R_InitParticleProgram()

void R_InitParticleProgram ( r_program_t * prog)

Definition at line 1012 of file r_program.cpp.

References R_ProgramParameter1i().

Referenced by CL_ParseMapParticle(), and CL_ParticleFunction().

◆ R_InitPrograms()

◆ R_InitSimpleGlowProgram()

void R_InitSimpleGlowProgram ( r_program_t * prog)
static

Definition at line 1005 of file r_program.cpp.

References R_ProgramParameter1f(), and R_ProgramParameter1i().

Referenced by R_InitPrograms().

◆ R_InitWarpProgram()

◆ R_InitWorldProgram()

◆ R_LoadProgram()

◆ R_LoadShader()

r_shader_t * R_LoadShader ( const GLenum type,
const char * name )
static

Reads/Preprocesses/Compiles the specified shader into a program.

Parameters
[in]typeThe type of shader, currently either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
[in]nameThe file name of the shader to load from ./base/shaders/ (e.g. "world_fs.glsl").
Returns
A structure used as a handle to the compiled shader (program).

Definition at line 595 of file r_program.cpp.

References Com_DPrintf(), Com_Printf(), DEBUG_RENDERER, FS_FreeFile(), FS_LoadFile(), GL_COMPILE_STATUS, GLenum, i, r_shader_t::id, length, MAX_QPATH, MAX_SHADERS, MAX_STRING_CHARS, Mem_Free, Mem_PoolAllocTypeN, name, r_shader_t::name, OBJZERO, Q_strncpyz(), R_InitializeShader(), R_PreprocessShader(), r_state, SHADER_BUF_SIZE, r_shader_t::type, type, and vid_imagePool.

Referenced by R_LoadProgram().

◆ R_PascalTriangle()

int R_PascalTriangle ( int row,
int col )
static
Note
this is a not-terribly-efficient recursive implementation, but it only happens once and shouldn't have to go very deep.

Definition at line 933 of file r_program.cpp.

References R_PascalTriangle().

Referenced by R_InitConvolveProgram(), and R_PascalTriangle().

◆ R_PreprocessShader()

size_t R_PreprocessShader ( const char * name,
const char * in,
char * out,
size_t * remainingOutChars )
static

Do our own preprocessing to the shader file, before the GLSL implementation calls it's preprocessor.

"#if/#endif" pairs, "#unroll", "#endunroll", "#include", "#replace" are handled by our preprocessor, not the GLSL implementation's preprocessor (except "#include" which may also be handled by the implementation's preprocessor). "#if" operates off of the value of a cvar interpreted as a bool. Note the GLSL implementation preprocessor handles "#ifdef" and "#ifndef", not "#if".

Parameters
[in]nameThe file name of the shader (e.g. "world_fs.glsl").
[in]inThe non-preprocessed shader string.
[in,out]outThe preprocessed shader string, nullptr if we don't want to write to it.
[in,out]remainingOutCharsThe number of characters left in the out buffer.
Returns
The number of characters added to the buffer pointed to by out.

Definition at line 581 of file r_program.cpp.

References name, and R_PreprocessShaderR().

Referenced by R_LoadShader().

◆ R_PreprocessShaderAddToShaderBuf()

size_t R_PreprocessShaderAddToShaderBuf ( const char * name,
const char * in,
char ** out,
size_t * len )
static

Prefixes shader string (out) with in.

Parameters
[in]nameThe name of the shader.
[in]inThe string to prefix onto the shader string (out).
[in,out]outThe shader string (initially was the whole shader file).
[in,out]lenThe amount of space left in the buffer pointed to by *out.
Returns
strlen(in)

Definition at line 289 of file r_program.cpp.

References len, and name.

Referenced by R_InitializeShader().

◆ R_PreprocessShaderR()

size_t R_PreprocessShaderR ( const char * name,
const char ** inPtr,
char * out,
long * remainingOutChars,
bool nested,
bool inElse )
static

Do our own preprocessing to the shader file, before the GLSL implementation calls it's preprocessor.

"#if/#endif" pairs, "#unroll", "#endunroll", "#include", "#replace" are handled by our preprocessor, not the GLSL implementation's preprocessor (except "#include" which may also be handled by the implementation's preprocessor). "#if" operates off of the value of a cvar interpreted as a bool. Note the GLSL implementation preprocessor handles "#ifdef" and "#ifndef", not "#if".

Parameters
[in]nameThe file name of the shader (e.g. "world_fs.glsl").
[in]inPtrThe non-preprocessed shader string.
[in,out]outThe preprocessed shader string, nullptr if we don't want to write to it.
[in,out]remainingOutCharsThe number of characters left in the out buffer.
[in]nestedIf true, parsing a part of "#if" clause, so "#else" and "#endif" tokens are allowed
[in]inElseIf true, parsing an "#else" clause and shouldn't expect another "#else"
Returns
The number of characters added to the buffer pointed to by out.

Definition at line 392 of file r_program.cpp.

References Com_Error(), Com_Parse(), Com_Printf(), Com_sprintf(), Cvar_GetValue(), ERR_DROP, ERR_FATAL, f, FS_FreeFile(), FS_LoadFile(), MAX_QPATH, Mem_Free, Mem_PoolAllocTypeN, name, R_PreprocessShaderR(), SHADER_BUF_SIZE, and vid_imagePool.

Referenced by R_PreprocessShader(), and R_PreprocessShaderR().

◆ R_ProgramParameter1f()

◆ R_ProgramParameter1fvs()

void R_ProgramParameter1fvs ( const char * name,
GLint size,
GLfloat * value )

Definition at line 131 of file r_program.cpp.

References GL_UNIFORM, GLint, name, R_ProgramVariable(), and v.

Referenced by R_InitConvolveProgram().

◆ R_ProgramParameter1i()

◆ R_ProgramParameter2fv()

◆ R_ProgramParameter2fvs()

void R_ProgramParameter2fvs ( const char * name,
GLint size,
GLfloat * value )

Definition at line 151 of file r_program.cpp.

References GL_UNIFORM, GLint, name, R_ProgramVariable(), and v.

Referenced by R_UseConvolveProgram().

◆ R_ProgramParameter3fv()

void R_ProgramParameter3fv ( const char * name,
GLfloat * value )

◆ R_ProgramParameter3fvs()

void R_ProgramParameter3fvs ( const char * name,
GLint size,
GLfloat * value )

Definition at line 171 of file r_program.cpp.

References GL_UNIFORM, GLint, name, R_ProgramVariable(), and v.

Referenced by R_EnableModelLights(), and R_EnableWorldLights().

◆ R_ProgramParameter4fv()

void R_ProgramParameter4fv ( const char * name,
GLfloat * value )

◆ R_ProgramParameter4fvs()

void R_ProgramParameter4fvs ( const char * name,
GLint size,
GLfloat * value )

Definition at line 191 of file r_program.cpp.

References GL_UNIFORM, GLint, name, R_ProgramVariable(), and v.

Referenced by R_EnableModelLights(), and R_EnableWorldLights().

◆ R_ProgramParameterMatrix4fv()

void R_ProgramParameterMatrix4fv ( const char * name,
GLfloat * value )

Definition at line 201 of file r_program.cpp.

References GL_UNIFORM, name, R_ProgramVariable(), and v.

◆ R_ProgramVariable()

◆ R_RestartPrograms_f()

void R_RestartPrograms_f ( void )

Reloads the glsl shaders.

Definition at line 1058 of file r_program.cpp.

References Com_Printf(), Cvar_Get(), R_InitFBObjects(), R_InitPrograms(), r_programs, and R_ShutdownPrograms().

Referenced by R_BeginFrame().

◆ R_ShutdownProgram()

void R_ShutdownProgram ( r_program_t * prog)
static

◆ R_ShutdownPrograms()

void R_ShutdownPrograms ( void )

◆ R_ShutdownShader()

void R_ShutdownShader ( r_shader_t * sh)
static

Definition at line 241 of file r_program.cpp.

References r_shader_t::id, and OBJZERO.

Referenced by R_ShutdownProgram().

◆ R_UseConvolveProgram()

void R_UseConvolveProgram ( r_program_t * prog)
static

Use the filter convolution glsl program.

Definition at line 966 of file r_program.cpp.

References FILTER_SIZE, i, R_ProgramParameter2fvs(), and r_program_t::userdata.

Referenced by R_InitPrograms().

◆ R_UseModelProgram()

void R_UseModelProgram ( r_program_t * prog)
static

◆ R_UseParticleProgram()

void R_UseParticleProgram ( r_program_t * prog)

Definition at line 1017 of file r_program.cpp.

Referenced by CL_ParseMapParticle(), and CL_ParticleFunction().

◆ R_UseProgram()

◆ R_UseWarpProgram()

void R_UseWarpProgram ( r_program_t * prog)
static

◆ R_UseWorldProgram()

void R_UseWorldProgram ( r_program_t * prog)
static

Variable Documentation

◆ fogRange

◆ shaderQualityLevelNames

const char* shaderQualityLevelNames[SHQ_NUM][2]
Initial value:
= {
{"world_low","model_low"},
{"world_med","model_med"},
{"world_med","model_high"}
}

Definition at line 37 of file r_program.cpp.

Referenced by R_InitPrograms().