UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"

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) More...
 

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. More...
 
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. More...
 
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. More...
 
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. More...
 
static r_shader_tR_LoadShader (const GLenum type, const char *name)
 Reads/Preprocesses/Compiles the specified shader into a program. More...
 
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. More...
 
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. More...
 

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

#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().

#define SHADER_BUF_SIZE   16384

Definition at line 33 of file r_program.cpp.

Referenced by R_LoadShader(), and R_PreprocessShaderR().

Enumeration Type Documentation

Enumerator
SHQ_LOW 
SHQ_MID 
SHQ_HIGH 
SHQ_NUM 

Definition at line 35 of file r_program.cpp.

Function Documentation

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

Definition at line 211 of file r_program.cpp.

References GL_ATTRIBUTE, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_BindArray().

void R_DisableAttribute ( const char *  name)

Definition at line 231 of file r_program.cpp.

References GL_ATTRIBUTE, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_EnableAnimation(), and R_EnableModelLights().

void R_EnableAttribute ( const char *  name)
static 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().

static 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().

static void R_InitConvolveProgram ( r_program_t prog)
static
static 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().

static 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(), viddef_t::context, ERR_FATAL, GL_FRAGMENT_SHADER, GL_VERTEX_SHADER, GLHW_ATI, GLHW_GENERIC, GLHW_INTEL, GLHW_MESA, GLHW_NVIDIA, rconfig_t::hardwareType, viddefContext_t::height, int(), r_config, r_glsl_version, R_PreprocessShaderAddToShaderBuf(), va(), cvar_s::value, viddef, and viddefContext_t::width.

Referenced by R_LoadShader().

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().

static 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().

static 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, i, r_shader_s::id, length, MAX_QPATH, MAX_SHADERS, MAX_STRING_CHARS, Mem_Free, Mem_PoolAllocTypeN, r_shader_s::name, OBJZERO, Q_strncpyz(), R_InitializeShader(), R_PreprocessShader(), r_state, SHADER_BUF_SIZE, rstate_s::shaders, r_shader_s::type, type, and vid_imagePool.

Referenced by R_LoadProgram().

static 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.

Referenced by R_InitConvolveProgram().

static 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 R_PreprocessShaderR().

Referenced by R_LoadShader().

static 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.

Referenced by R_InitializeShader().

static 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, SHADER_BUF_SIZE, and vid_imagePool.

Referenced by R_PreprocessShader().

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

Definition at line 131 of file r_program.cpp.

References GL_UNIFORM, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_InitConvolveProgram().

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

Definition at line 151 of file r_program.cpp.

References GL_UNIFORM, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_UseConvolveProgram().

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

Definition at line 171 of file r_program.cpp.

References GL_UNIFORM, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_EnableModelLights(), and R_EnableWorldLights().

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

Definition at line 191 of file r_program.cpp.

References GL_UNIFORM, r_progvar_s::location, R_ProgramVariable(), and v.

Referenced by R_EnableModelLights(), and R_EnableWorldLights().

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

Definition at line 201 of file r_program.cpp.

References GL_UNIFORM, r_progvar_s::location, R_ProgramVariable(), and v.

void R_RestartPrograms_f ( void  )

Reloads the glsl shaders.

Definition at line 1058 of file r_program.cpp.

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

Referenced by R_BeginFrame().

static void R_ShutdownProgram ( r_program_t prog)
static
static void R_ShutdownShader ( r_shader_t sh)
static

Definition at line 241 of file r_program.cpp.

References r_shader_s::id, and OBJZERO.

Referenced by R_ShutdownProgram().

static 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_s::userdata.

Referenced by R_InitPrograms().

void R_UseParticleProgram ( r_program_t prog)

Definition at line 1017 of file r_program.cpp.

Referenced by CL_ParseMapParticle(), and CL_ParticleFunction().

Variable Documentation

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().