FastUIDraw
Classes | Public Types | Public Member Functions | List of all members
fastuidraw::gl::Program Class Reference

Class for creating and using GLSL programs. More...

#include <gl_program.hpp>

Inheritance diagram for fastuidraw::gl::Program:
Inheritance graph
[legend]

Classes

class  atomic_buffer_info
 An atomic_buffer_info represents an object from which one can query the data of an atomic buffer. More...
 
class  block_info
 A block_info represents an object from which one can query the members of a uniform or shader storage block. More...
 
class  shader_variable_info
 A shader_variable_info holds the type, size and name of a uniform or an attribute of a GL program. More...
 

Public Types

enum  shader_variable_src_t {
  src_default_uniform_block, src_abo, src_uniform_block, src_shader_storage_block,
  src_shader_input, src_shader_output, src_shader_transform_feedback, src_null
}
 Enumeration to describe the backing of a shader variable's value. More...
 

Public Member Functions

 Program (c_array< const reference_counted_ptr< Shader > > pshaders, const PreLinkActionArray &action=PreLinkActionArray(), const ProgramInitializerArray &initers=ProgramInitializerArray())
 
 Program (reference_counted_ptr< Shader > vert_shader, reference_counted_ptr< Shader > frag_shader, const PreLinkActionArray &action=PreLinkActionArray(), const ProgramInitializerArray &initers=ProgramInitializerArray())
 
 Program (const glsl::ShaderSource &vert_shader, const glsl::ShaderSource &frag_shader, const PreLinkActionArray &action=PreLinkActionArray(), const ProgramInitializerArray &initers=ProgramInitializerArray())
 
 Program (GLuint pname, bool take_ownership)
 
shader_variable_info active_attribute (unsigned int I)
 
atomic_buffer_info atomic_buffer (unsigned int I)
 
unsigned int atomic_buffer_id (unsigned int binding_point)
 
GLint attribute_location (c_string attribute_name)
 
block_info default_uniform_block (void)
 
shader_variable_info find_shader_variable (c_string name, unsigned int *out_array_index=nullptr, unsigned int *out_leading_array_index=nullptr)
 
c_string link_log (void)
 
bool link_success (void)
 
c_string log (void)
 
GLuint name (void)
 
unsigned int num_shaders (GLenum tp) const
 
unsigned int number_active_atomic_buffers (void)
 
unsigned int number_active_attributes (void)
 
unsigned int number_active_shader_storage_blocks (void)
 
unsigned int number_active_uniform_blocks (void)
 
unsigned int number_transform_feedback_buffers (void)
 
unsigned int number_transform_feedbacks (void)
 
float program_build_time (void)
 
c_string shader_compile_log (GLenum tp, unsigned int i) const
 
bool shader_compile_success (GLenum tp, unsigned int i) const
 
c_string shader_src_code (GLenum tp, unsigned int i) const
 
block_info shader_storage_block (unsigned int I)
 
block_info shader_storage_block (c_string shader_storage_block_name)
 
unsigned int shader_storage_block_id (c_string shader_storage_block_name)
 
shader_variable_info transform_feedback (unsigned int I)
 
unsigned int transform_feedback_buffer_stride (unsigned int B)
 
block_info uniform_block (unsigned int I)
 
block_info uniform_block (c_string uniform_block_name)
 
unsigned int uniform_block_id (c_string uniform_block_name)
 
GLint uniform_location (c_string name)
 
void use_program (void)
 
- Public Member Functions inherited from fastuidraw::reference_counted_base< T, Counter >
 reference_counted_base (void)
 

Additional Inherited Members

- Static Public Member Functions inherited from fastuidraw::reference_counted_base< T, Counter >
static void add_reference (const reference_counted_base< T, Counter > *p)
 
static void remove_reference (const reference_counted_base< T, Counter > *p)
 

Detailed Description

Class for creating and using GLSL programs.

A Program delays the GL commands to create the actual GL program until the first time it is bound with use_program(). In addition to proving the GL code to create the GLSL code, Program also provides queries GL for all active uniforms and attributes (see active_attributes(), active_uniforms(), find_uniform() and find_attribute()). Also, provides an interface so that a sequence of GL commands are executed the first time it is bound and also an interface so a sequence of actions is executed every time it is bound. Program's are considered a resource, as such have a resource manager.

Definition at line 559 of file gl_program.hpp.

Member Enumeration Documentation

◆ shader_variable_src_t

Enumeration to describe the backing of a shader variable's value.

Enumerator
src_default_uniform_block 

Indicates that the shader variable is from the default uniform block; the variable's value is not sourced from a backing buffer object.

src_abo 

Indicats that the shader variable is an atomic buffer counter and sourced from a backing buffer object.

src_uniform_block 

Indicats that the shader variable is from the a uniform block; the variable's value is sourced from a backing buffer object.

src_shader_storage_block 

Indicats that the shader variable is from the a shader storage block; the variable is backed by a buffer object.

src_shader_input 

Indicates that the shader variable is an input (i.e an 'in' of GLSL).

src_shader_output 

Indicates that the shader variable is an output (i.e an 'out' of GLSL).

src_shader_transform_feedback 

Indicates that the shader variable is a transform feedback variable

src_null 

Indicates that the shader variable is a nullptr value; such values are returned when a query for a shader variable is made and there is no such shader variable.

Definition at line 568 of file gl_program.hpp.

Constructor & Destructor Documentation

◆ Program() [1/4]

fastuidraw::gl::Program::Program ( c_array< const reference_counted_ptr< Shader > >  pshaders,
const PreLinkActionArray action = PreLinkActionArray(),
const ProgramInitializerArray initers = ProgramInitializerArray() 
)

Ctor.

Parameters
pshadersshaders used to create the Program
actionspecifies actions to perform before linking of the Program
initersone-time initialization actions to perform at GLSL program creation

◆ Program() [2/4]

fastuidraw::gl::Program::Program ( reference_counted_ptr< Shader vert_shader,
reference_counted_ptr< Shader frag_shader,
const PreLinkActionArray action = PreLinkActionArray(),
const ProgramInitializerArray initers = ProgramInitializerArray() 
)

Ctor.

Parameters
vert_shaderpointer to vertex shader to use for the Program
frag_shaderpointer to fragment shader to use for the Program
actionspecifies actions to perform before and after linking of the Program.
initersone-time initialization actions to perform at GLSL program creation

◆ Program() [3/4]

fastuidraw::gl::Program::Program ( const glsl::ShaderSource vert_shader,
const glsl::ShaderSource frag_shader,
const PreLinkActionArray action = PreLinkActionArray(),
const ProgramInitializerArray initers = ProgramInitializerArray() 
)

Ctor.

Parameters
vert_shaderpointer to vertex shader to use for the Program
frag_shaderpointer to fragment shader to use for the Program
actionspecifies actions to perform before and after linking of the Program.
initersone-time initialization actions to perform at GLSL program creation

◆ Program() [4/4]

fastuidraw::gl::Program::Program ( GLuint  pname,
bool  take_ownership 
)

Ctor. Create a Program from a previously linked GL shader.

Parameters
pnameGL ID of previously linked shader
take_ownershipif true when dtor is called glDeleteProgram is called as well

Member Function Documentation

◆ active_attribute()

shader_variable_info fastuidraw::gl::Program::active_attribute ( unsigned int  I)

Returns the indexed attribute. This function should only be called either after use_program() has been called or only when the GL context is current. The values are sorted in alphabetical order of shader_variable_info::name().

Parameters
I-ID- (not location) of attribute, if I is not less than number_active_attributes(), returns a shader_variable_info indicating no attribute (i.e. shader_variable_info::name() is an empty string and shader_variable_info::index() is -1).

◆ atomic_buffer()

atomic_buffer_info fastuidraw::gl::Program::atomic_buffer ( unsigned int  I)

Returns the indexed atomic buffer. the index passed is the index as used by the GL API to query the uniform block (and thus the same as shader_variable_info::abo_index()). This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
Iwhich one to fetch, if I is not less than number_active_atomic_buffers(), then returns a null atomic_buffer_info

◆ atomic_buffer_id()

unsigned int fastuidraw::gl::Program::atomic_buffer_id ( unsigned int  binding_point)

Returns the index to feed to atomic_buffer(unsigned int) to fetch the atomic buffer with the value of atomic_buffer_info::buffer_binding().

Parameters
binding_pointvalue for atomic_buffer_info::buffer_binding() to search for.

◆ attribute_location()

GLint fastuidraw::gl::Program::attribute_location ( c_string  attribute_name)

Searches active_attribute() to find the named attribute, including named elements of an array. This function should only be called either after use_program() has been called or only when the GL context is current. Returns value -1 indicated that the attribute could not be found.

Parameters
attribute_namename of attribute to find

◆ default_uniform_block()

block_info fastuidraw::gl::Program::default_uniform_block ( void  )

Returns a block_info of the default uniform block, the default uniform block does NOT include shader variables coming from atomic buffer counters.

◆ find_shader_variable()

shader_variable_info fastuidraw::gl::Program::find_shader_variable ( c_string  name,
unsigned int *  out_array_index = nullptr,
unsigned int *  out_leading_array_index = nullptr 
)

Searches the default uniform block, all uniform blocks and all shader storage blocks for a shader variable.

◆ link_log()

c_string fastuidraw::gl::Program::link_log ( void  )

Returns the link log of this Program, essentially the value returned by glGetProgramInfoLog. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ link_success()

bool fastuidraw::gl::Program::link_success ( void  )

Returns true if and only if this Program successfully linked. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ log()

c_string fastuidraw::gl::Program::log ( void  )

Returns the full log (including shader source code and link_log()) of this Program. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ name()

GLuint fastuidraw::gl::Program::name ( void  )

Returns the GL name (i.e. ID assigned by GL, for use in glUseProgram) of this Program. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ num_shaders()

unsigned int fastuidraw::gl::Program::num_shaders ( GLenum  tp) const

Returns the number of shaders of a given type attached to the Program.

Parameters
tpGL enumeration of the shader type, see Shader::shader_type()

◆ number_active_atomic_buffers()

unsigned int fastuidraw::gl::Program::number_active_atomic_buffers ( void  )

Returns the number of active atomic buffers. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ number_active_attributes()

unsigned int fastuidraw::gl::Program::number_active_attributes ( void  )

Returns the number of active attributes. Note that an array of uniforms is classified as a single uniform. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ number_active_shader_storage_blocks()

unsigned int fastuidraw::gl::Program::number_active_shader_storage_blocks ( void  )

Returns the number of active shader storage blocks. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ number_active_uniform_blocks()

unsigned int fastuidraw::gl::Program::number_active_uniform_blocks ( void  )

Returns the number of active uniform blocks (not including the default uniform block). This function should only be called either after use_program() has been called or only when the GL context is current.

◆ number_transform_feedback_buffers()

unsigned int fastuidraw::gl::Program::number_transform_feedback_buffers ( void  )

Returns the number of transform feedback buffers.

◆ number_transform_feedbacks()

unsigned int fastuidraw::gl::Program::number_transform_feedbacks ( void  )

Returns the number of active transform feedbacks. Note that an array of transform feedback is classified as a single element. This will also include padding in the form of gl_SkipComponents1, gl_SkipComponents2, gl_SkipComponents3 and gl_SkipComponents4. In addition it will also include gl_NextBuffer to indicated advancing to the next buffer. This function should only be called either after use_program() has been called or only when the GL context is current.

◆ program_build_time()

float fastuidraw::gl::Program::program_build_time ( void  )

Returns how many seconds it took for the program to be assembled and linked.

◆ shader_compile_log()

c_string fastuidraw::gl::Program::shader_compile_log ( GLenum  tp,
unsigned int  i 
) const

Returns the compile log for a shader attached to the Program.

Parameters
tpGL enumeration of the shader type, see Shader::shader_type()
iwhich shader with 0 <= i < num_shaders(tp)

◆ shader_compile_success()

bool fastuidraw::gl::Program::shader_compile_success ( GLenum  tp,
unsigned int  i 
) const

Returns true if the source code string for a shader attached to the Program compiled successfully.

Parameters
tpGL enumeration of the shader type, see Shader::shader_type()
iwhich shader with 0 <= i < num_shaders(tp)

◆ shader_src_code()

c_string fastuidraw::gl::Program::shader_src_code ( GLenum  tp,
unsigned int  i 
) const

Returns the source code string for a shader attached to the Program.

Parameters
tpGL enumeration of the shader type, see Shader::shader_type()
iwhich shader with 0 <= i < num_shaders(tp)

◆ shader_storage_block() [1/2]

block_info fastuidraw::gl::Program::shader_storage_block ( unsigned int  I)

Returns the indexed shader_storage block; the index passed is the index as used by the GL API to query the uniform block (and thus the same as shader_variable_info::shader_storage_buffer_index()). This function should only be called either after use_program()

Parameters
Iwhich one to fetch, if I is not less than number_active_shader_storage_blocks(), then returns a nullptr block_info

◆ shader_storage_block() [2/2]

block_info fastuidraw::gl::Program::shader_storage_block ( c_string  shader_storage_block_name)
inline

Seaches shader_storage_block(unsigned int) to find the named uniform block. If no such uniform block has that name returns a null block_info object. Provided as a conveniance, equivalent to

shader_storage_block(shader_storage_block_id(shader_storage_block_name))

This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
shader_storage_block_namename of shader storage to find

Definition at line 1299 of file gl_program.hpp.

◆ shader_storage_block_id()

unsigned int fastuidraw::gl::Program::shader_storage_block_id ( c_string  shader_storage_block_name)

Searches shader_storage_block(unsigned int) to find the named shader_storage block. Return value ~0u indicates that the shader_storage block could not be found. This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
shader_storage_block_namename of shader storage to find

◆ transform_feedback()

shader_variable_info fastuidraw::gl::Program::transform_feedback ( unsigned int  I)

Returns the indexed transform-feedback. This function should only be called either after use_program() has been called or only when the GL context is current. The values are sorted in alphabetical order of shader_variable_info::name().

Parameters
I-ID- (not location or index) of transform feedbach, if I is not less than number_transform_feedbacks(), returns a shader_variable_info indicating null (i.e. shader_variable_info::name() is an empty string and shader_variable_info::index() is -1).

◆ transform_feedback_buffer_stride()

unsigned int fastuidraw::gl::Program::transform_feedback_buffer_stride ( unsigned int  B)

Returns the stride in bytes between each element in the named transform feedback buffer.

Parameters
Bwhich transform feedback buffer

◆ uniform_block() [1/2]

block_info fastuidraw::gl::Program::uniform_block ( unsigned int  I)

Returns the indexed uniform block; the index passed is the index as used by the GL API to query the uniform block (and thus the same as shader_variable_info::ubo_index()). This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
Iwhich one to fetch, if I is not less than number_active_uniform_blocks(), then returns a null block_info object.

◆ uniform_block() [2/2]

block_info fastuidraw::gl::Program::uniform_block ( c_string  uniform_block_name)
inline

Seaches uniform_block(unsigned int) to find the named uniform block. If no such uniform block has that name returns a null block_info object. Provided as a conveniance, equivalent to

uniform_block(uniform_block_id(uniform_block_name))

This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
uniform_block_namename of uniform block to find

Definition at line 1238 of file gl_program.hpp.

◆ uniform_block_id()

unsigned int fastuidraw::gl::Program::uniform_block_id ( c_string  uniform_block_name)

Searches uniform_block(unsigned int) to find the named uniform block. Return value ~0u indicates that the uniform block could not be found, otherwise returns the value to feed to uniform_block(unsigned int). This function should only be called either after use_program() has been called or only when the GL context is current.

Parameters
uniform_block_namename of uniform block to find

◆ uniform_location()

GLint fastuidraw::gl::Program::uniform_location ( c_string  name)

Returns the location of a uniform and also correctly handles fetching the uniform of an element of a uniform array. Returns -1 if there is no uniform on the default block with that name.

◆ use_program()

void fastuidraw::gl::Program::use_program ( void  )

Call to set GL to use the GLSLProgram of this Program. The GL context must be current.


The documentation for this class was generated from the following file: