FS2_Open
Open source remastering of the Freespace 2 engine
gropenglshader.cpp File Reference

Go to the source code of this file.

Functions

GLhandleARB opengl_shader_create (const SCP_vector< SCP_string > &vs, const SCP_vector< SCP_string > &fs, const SCP_vector< SCP_string > &gs)
 
void opengl_shader_check_info_log (GLhandleARB shader_object)
 
void opengl_shader_set_current (opengl_shader_t *shader_obj)
 
void opengl_shader_set_current (int handle)
 
int gr_opengl_maybe_create_shader (shader_type shader_t, unsigned int flags)
 
void opengl_delete_shader (int sdr_handle)
 
void opengl_shader_shutdown ()
 
int opengl_compile_shader (shader_type sdr, uint flags)
 
void opengl_shader_init ()
 
GLhandleARB opengl_shader_compile_object (const SCP_vector< SCP_string > &shader_source, GLenum shader_type)
 
GLhandleARB opengl_shader_link_object (GLhandleARB vertex_object, GLhandleARB fragment_object, GLhandleARB geometry_object)
 
void opengl_shader_init_attribute (const char *attribute_text)
 
GLint opengl_shader_get_attribute (const char *attribute_text)
 
void opengl_shader_init_uniform (const char *uniform_text)
 
GLint opengl_shader_get_uniform (const char *uniform_text)
 
void opengl_shader_init_uniform_block (const char *uniform_text)
 
GLint opengl_shader_get_uniform_block (const char *uniform_text)
 
void gr_opengl_shader_set_animated_effect (int effect, float timer)
 
int opengl_shader_get_animated_effect ()
 
float opengl_shader_get_animated_timer ()
 
void opengl_shader_compile_deferred_light_shader ()
 

Variables

SCP_vector< opengl_shader_tGL_shader
 
GLuint Framebuffer_fallback_texture_id = 0
 
geometry_sdr_paramsCurrent_geo_sdr_params = NULL
 
opengl_shader_tCurrent_shader = NULL
 

Function Documentation

int gr_opengl_maybe_create_shader ( shader_type  shader_t,
unsigned int  flags 
)

Given a set of flags, determine whether a shader with these flags exists within the GL_shader vector. If no shader with the requested flags exists, attempt to compile one.

Parameters
shader_tshader_type variable, a reference to the shader program needed
flagsInteger variable, holding a combination of SDR_* flags
Returns
Index into GL_shader, referencing a valid shader, or -1 if shader compilation failed

Definition at line 229 of file gropenglshader.cpp.

void gr_opengl_shader_set_animated_effect ( int  effect,
float  timer 
)

Sets the currently active animated effect.

Parameters
effectEffect ID, needs to be implemented and checked for in the shader
timerTimer value to be passed to the shader

Definition at line 876 of file gropenglshader.cpp.

int opengl_compile_shader ( shader_type  sdr,
uint  flags 
)

Compiles a new shader, and creates an opengl_shader_t that will be put into the GL_shader vector if compilation is successful.

Parameters
sdrIdentifier defined with the program we wish to compile
flagsCombination of SDR_* flags

Definition at line 372 of file gropenglshader.cpp.

void opengl_delete_shader ( int  sdr_handle)

Definition at line 247 of file gropenglshader.cpp.

void opengl_shader_check_info_log ( GLhandleARB  shader_object)

Retrieve the compilation log for a given shader object, and store it in the GLshader_info_log global variable

Parameters
shader_objectOpenGL handle of a shader object

Definition at line 526 of file gropenglshader.cpp.

void opengl_shader_compile_deferred_light_shader ( )

Compile the deferred light shader.

Definition at line 903 of file gropenglshader.cpp.

GLhandleARB opengl_shader_compile_object ( const SCP_vector< SCP_string > &  shader_source,
GLenum  shader_type 
)

Pass a GLSL shader source to OpenGL and compile it into a usable shader object. Prints compilation errors (if any) to the log. Note that this will only compile shaders into objects, linking them into executables happens later

Parameters
shader_sourceGLSL sourcecode for the shader
shader_typeOpenGL ID for the type of shader being used, like GL_FRAGMENT_SHADER_ARB, GL_VERTEX_SHADER_ARB
Returns
OpenGL handle for the compiled shader object

Definition at line 546 of file gropenglshader.cpp.

GLhandleARB opengl_shader_create ( const SCP_vector< SCP_string > &  vs,
const SCP_vector< SCP_string > &  fs,
const SCP_vector< SCP_string > &  gs 
)

Creates an executable shader.

Parameters
vsVertex shader source code
fsFragment shader source code
gsGeometry shader source code
Returns
Internal ID of compiled and linked shader generated by OpenGL

Definition at line 663 of file gropenglshader.cpp.

int opengl_shader_get_animated_effect ( )

Returns the currently active animated effect ID.

Returns
Currently active effect ID

Definition at line 887 of file gropenglshader.cpp.

float opengl_shader_get_animated_timer ( )

Get the timer for animated effects.

Definition at line 895 of file gropenglshader.cpp.

GLint opengl_shader_get_attribute ( const char *  attribute_text)

Get the internal OpenGL location for a given attribute. Requires that the Current_shader global variable is valid

Parameters
attribute_textName of the attribute
Returns
Internal OpenGL location for the attribute

Definition at line 750 of file gropenglshader.cpp.

GLint opengl_shader_get_uniform ( const char *  uniform_text)

Get the internal OpenGL location for a given uniform. Requires that the Current_shader global variable is valid

Parameters
uniform_textName of the uniform
Returns
Internal OpenGL location for the uniform

Definition at line 799 of file gropenglshader.cpp.

GLint opengl_shader_get_uniform_block ( const char *  uniform_text)

Get the internal OpenGL location for a given uniform. Requires that the Current_shader global variable is valid

Parameters
uniform_textName of the uniform
Returns
Internal OpenGL location for the uniform

Definition at line 852 of file gropenglshader.cpp.

void opengl_shader_init ( )

Initializes the shader system. Creates a 1x1 texture that can be used as a fallback texture when framebuffer support is missing. Also compiles the shaders used for particle rendering.

Definition at line 487 of file gropenglshader.cpp.

void opengl_shader_init_attribute ( const char *  attribute_text)

Initialize a shader attribute. Requires that the Current_shader global variable is valid.

Parameters
attribute_textName of the attribute to be initialized

Definition at line 724 of file gropenglshader.cpp.

void opengl_shader_init_uniform ( const char *  uniform_text)

Initialize a shader uniform. Requires that the Current_shader global variable is valid.

Parameters
uniform_textName of the uniform to be initialized

Definition at line 773 of file gropenglshader.cpp.

void opengl_shader_init_uniform_block ( const char *  uniform_text)

Initialize a shader uniform. Requires that the Current_shader global variable is valid.

Parameters
uniform_textName of the uniform to be initialized

Definition at line 823 of file gropenglshader.cpp.

GLhandleARB opengl_shader_link_object ( GLhandleARB  vertex_object,
GLhandleARB  fragment_object,
GLhandleARB  geometry_object 
)

Link vertex shader, fragment shader and geometry shader objects into a usable shader executable.

Prints linker errors (if any) to the log.

Parameters
vertex_objectCompiled vertex shader object
fragment_objectCompiled fragment shader object
geometry_objectCompiled geometry shader object
Returns
Shader executable

Definition at line 599 of file gropenglshader.cpp.

void opengl_shader_set_current ( opengl_shader_t shader_obj)

Set the currently active shader

Parameters
shader_objPointer to an opengl_shader_t object. This function calls glUseProgramARB with parameter 0 if shader_obj is NULL or if function is called without parameters, causing OpenGL to revert to fixed-function processing

Definition at line 180 of file gropenglshader.cpp.

void opengl_shader_set_current ( int  handle)

Definition at line 214 of file gropenglshader.cpp.

void opengl_shader_shutdown ( )

Go through GL_shader and call glDeleteObject() for all created shaders, then clear GL_shader

Definition at line 269 of file gropenglshader.cpp.

Variable Documentation

geometry_sdr_params* Current_geo_sdr_params = NULL

Definition at line 37 of file gropenglshader.cpp.

opengl_shader_t* Current_shader = NULL

Definition at line 170 of file gropenglshader.cpp.

GLuint Framebuffer_fallback_texture_id = 0

Definition at line 32 of file gropenglshader.cpp.

Definition at line 28 of file gropenglshader.cpp.