Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GLUP::Context Class Referenceabstract

GLUP context stores a Uniform Buffer Object with state variables similar to OpenGL's fixed functionality pipeline, and a set of Vertex Buffer Objects to emulate OpenGL's immediate mode. More...

#include <geogram_gfx/GLUP/GLUP_context.h>

Inheritance diagram for GLUP::Context:
GEO::GLSL::PseudoFileProvider

Public Member Functions

 Context ()
 Context constructor.
 
 ~Context () override
 Context destructor.
 
virtual const char * profile_name () const =0
 Gets the profile name associated with this context.
 
virtual bool primitive_supports_array_mode (GLUPprimitive prim) const
 Tests whether a given GLUP primitive supports array mode. More...
 
virtual void setup ()
 Creates the uniform state and GLSL programs. More...
 
virtual void bind_uniform_state (GLuint program)
 Binds GLUP uniform state to a program. More...
 
void load_matrix (const GLfloat m[16])
 Replaces the top of the current matrix stack with the specified matrix. More...
 
void load_matrix (const GLdouble m[16])
 Replaces the top of the current matrix stack with the specified matrix. More...
 
void load_identity ()
 Replaces the top of the current matrix stack with the identity matrix.
 
void mult_matrix (const GLdouble m[16])
 Post-multiplies the top of the current matrix stack with the specified matrix. More...
 
void push_matrix ()
 Pushes a copy of the top of the current stack matrix onto the current stack matrix. More...
 
void pop_matrix ()
 Pops the top of the current stack matrix.
 
void set_matrix_mode (GLUPmatrix matrix)
 Sets the current matrix stack. More...
 
GLUPmatrix get_matrix_mode () const
 Gets the current matrix stack. More...
 
void immediate_vertex (GLfloat x, GLfloat y, GLfloat z=0.0f, GLfloat w=1.0f)
 Creates a new vertex in the immediate mode buffers. More...
 
void immediate_color (GLfloat r, GLfloat g, GLfloat b, GLfloat a=1.0f)
 Specifies the current color for the immediate mode buffers. More...
 
void immediate_tex_coord (GLfloat s, GLfloat t=0.0f, GLfloat u=0.0f, GLfloat v=1.0f)
 Specifies the current texture coordinates for the immediate mode buffers. More...
 
void immediate_normal (GLfloat x, GLfloat y, GLfloat z)
 Specifies the current normal vector for the immediate mode buffers. More...
 
void set_user_program (GLuint program)
 Sets the user program, to be used instead of the default GLUP programs for drawing the primitives.
 
virtual void begin (GLUPprimitive primitive)
 Begins rendering in immediate mode. More...
 
virtual void end ()
 Ends rendering in immediate mode. More...
 
virtual void draw_arrays (GLUPprimitive primitive, GLUPint first, GLUPsizei count)
 Draws primitives using current OpenGL array bindings. More...
 
virtual void draw_elements (GLUPprimitive primitive, GLUPsizei count, GLUPenum type, const GLUPvoid *indices)
 Draws primitives using current OpenGL array bindings. More...
 
virtual Memory::pointer get_state_variable_address (const char *name)
 Gets a pointer to the representation of a uniform state variable in host memory from its (unqualified) name. More...
 
UniformStateuniform_state ()
 Gets the uniform state. More...
 
const UniformStateuniform_state () const
 Gets the uniform state. More...
 
void flag_uniform_buffer_as_dirty ()
 Indicates that the OpenGL representation of the uniform state is no longer in sync with the local copy.
 
void flag_lighting_as_dirty ()
 Indicates that cached lighting information needs to be recomputed.
 
void flag_matrices_as_dirty ()
 Indicates that cached matrix information needs to be recomputed.
 
GLUPdouble * get_matrix (GLUPmatrix matrix)
 Gets a pointer to the values of the matrix at the top of a given stack. More...
 
virtual void get_vertex_shader_preamble_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/vertex_shader_preamble.h. More...
 
virtual void get_fragment_shader_preamble_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/fragment_shader_preamble.h. More...
 
virtual void get_geometry_shader_preamble_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/geometry_shader_preamble.h. More...
 
virtual void get_tess_control_shader_preamble_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/tess_control_shader_preamble.h. More...
 
virtual void get_tess_evaluation_shader_preamble_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/tess_evaluation_shader_preamble.h. More...
 
virtual void get_toggles_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/toggles.h. More...
 
virtual void get_primitive_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/primitive.h. More...
 
virtual void get_marching_cells_pseudo_file (std::vector< GLSL::Source > &sources)
 Gets the content of the virtual file GLUP/current_profile/marching_cells.h. More...
 
void setup_shaders_source_for_toggles (GLUPbitfield toggles_state, GLUPbitfield toggles_undetermined=0)
 Sets the string that describes the settings of the toggles for a given configuration. More...
 
virtual void setup_shaders_source_for_primitive (GLUPprimitive primitive)
 Sets the configurable GLSL sources for a given primitive type. More...
 
ImmediateStateimmediate_state ()
 Gets the immediate state. More...
 
virtual void flush_immediate_buffers ()
 Flushes the immediate mode buffers.
 
- Public Member Functions inherited from GEO::GLSL::PseudoFileProvider
virtual ~PseudoFileProvider ()
 PseudoFileProvider destructor.
 

Static Public Member Functions

static const char * uniform_state_declaration ()
 Gets the GLSL declaration of GLUP uniform state. More...
 
static const char * glup_primitive_name (GLUPprimitive prim)
 Gets the name of a primitive by GLUPprimitive. More...
 

Protected Member Functions

const MarchingCellget_marching_cell () const
 Gets the MarchingCell that corresponds to the current primitive. More...
 
bool extension_is_supported (const std::string &extension)
 Tests whether an OpenGL extension is supported. More...
 
virtual void prepare_to_draw (GLUPprimitive primitive)
 This function is called before starting to render primitives. It is called by begin(), draw_arrays() and draw_elements(). More...
 
virtual void done_draw (GLUPprimitive primitive)
 This function is called right after rendering primitives. It is called by end(), draw_arrays() and draw_elements(). More...
 
virtual void setup_state_variables ()
 Initializes the representation of the uniform state.
 
virtual void setup_immediate_buffers ()
 Set-ups the buffers for immediate rendering. More...
 
virtual void stream_immediate_buffers ()
 Sends all the active immediate buffers to the GPU. More...
 
virtual void setup_primitives ()
 Setups the programs and VAOs used for each primitive.
 
virtual void setup_GLUP_POINTS ()
 Setups GLSL programs for points.
 
virtual void setup_GLUP_LINES ()
 Setups GLSL programs for lines.
 
virtual void setup_GLUP_THICK_LINES ()
 Setups GLSL programs for lines with width > 1.
 
virtual void setup_GLUP_TRIANGLES ()
 Setups GLSL programs for triangles.
 
virtual void setup_GLUP_QUADS ()
 Setups GLSL programs for quads.
 
virtual void setup_GLUP_TETRAHEDRA ()
 Setups GLSL programs for tetrahedra.
 
virtual void setup_GLUP_HEXAHEDRA ()
 Setups GLSL programs for hexahedra.
 
virtual void setup_GLUP_PRISMS ()
 Setups GLSL programs for prisms.
 
virtual void setup_GLUP_PYRAMIDS ()
 Setups GLSL programs for pyramids.
 
virtual void setup_GLUP_CONNECTORS ()
 Setups GLSL programs for connectors.
 
virtual void setup_GLUP_SPHERES ()
 Setups GLSL programs for spheres.
 
virtual void set_primitive_info (GLUPprimitive glup_primitive, GLenum gl_primitive, GLuint program, bool bind_attrib_loc_and_link=true)
 Initializes the PrimitiveInfo associated with a given GLUP primitive. More...
 
virtual void set_primitive_info_vertex_gather_mode (GLUPprimitive glup_primitive, GLenum gl_primitive, GLuint program)
 Initializes the PrimitiveInfo associated with a given GLUP primitive in vertex-gather mode. More...
 
virtual void set_primitive_info_immediate_index_mode (GLUPprimitive glup_primitive, GLenum gl_primitive, GLuint program, index_t nb_elements_per_glup_primitive, index_t *element_indices)
 Initializes the PrimitiveInfo associated with a given GLUP primitive in immediate mode when an element index buffer is required. More...
 
void update_uniform_buffer ()
 Copies GLUP uniform state to OpenGL if required.
 
virtual void do_update_uniform_buffer ()
 Copies GLUP uniform state to OpenGL. More...
 
virtual void update_matrices ()
 Updates the matrices in the uniform state from the matrices in the stacks.
 
virtual void update_lighting ()
 Updates the lighting in the uniform state. More...
 
virtual void update_base_picking_id (GLint new_value)
 Updates the base picking id and sends it to OpenGL.
 
std::string primitive_declaration (GLUPprimitive prim) const
 Gets the GLSL declaration of the constant that indicates the current primitive. More...
 
void setup_shaders_source_for_toggles_config (PrimitiveInfo::ShaderKey toggles_config)
 Sets the string that describes the settings of the toggles for a given configuration. More...
 
void update_toggles_config ()
 Updates the toggles_config_ state variable from the individual state of each toggle.
 
void create_program_if_needed (GLUPprimitive primitive)
 Creates the GLSL shader that corresponds to the specified primitive and current toggles configuration if not already initialized. More...
 
void shrink_cells_in_immediate_buffers ()
 Shrinks the cells in the immediate buffer. More...
 
void create_CPU_side_uniform_buffer ()
 Creates a buffer for uniform variables for implementations that do not support uniform buffer objects. More...
 
void bind_immediate_state_buffers_to_VAO ()
 Binds the VBOs associated with the immediate state buffers to the currently bound VAO.
 
void classify_vertices_in_immediate_buffers ()
 Updates v_is_visible_[] according to current clipping plane. More...
 
bool cell_is_clipped (index_t first_v)
 Tests whether the cell starting at a given vertex in the immediate buffer is clipped, according to current clipping mode and current primitive type. More...
 
index_t get_config (index_t first_v, index_t nb_v)
 Assemble the configuration code of a primitive relative to the clipping plane. More...
 
void compute_intersection (index_t v1, index_t v2, index_t vi)
 Computes the intersection between the clipping plane and a segment. More...
 
virtual void copy_uniform_state_to_current_program ()
 Copies the uniform state from client-side memory into the currently bound program, or does nothing if uniform buffer objects are supported.
 
void use_program (GLuint program)
 A wrapper around glUseProgram that tests whether uniform state needs to be sent to the program. More...
 
void create_vertex_id_VBO ()
 Creates a vertex buffer object with 16 bits integers between 0 and 65535. More...
 

Static Protected Member Functions

static void initialize ()
 

Protected Attributes

GLuint default_program_
 
GLuint uniform_buffer_
 
GLuint uniform_binding_point_
 
GLint uniform_buffer_size_
 
bool uniform_buffer_dirty_
 
Memory::byteuniform_buffer_data_
 
UniformState uniform_state_
 
bool lighting_dirty_
 
GLUPmatrix matrix_mode_
 
MatrixStack matrix_stack_ [3]
 
bool matrices_dirty_
 
index_t nb_vertices_per_primitive_ [GLUP_NB_PRIMITIVES]
 Number of vertices per primitive (3 for GLUP_TRIANGLES, 4 for GLUP_QUADS etc...) More...
 
ImmediateState immediate_state_
 
vector< PrimitiveInfoprimitive_info_
 
MarchingCell marching_tet_
 
MarchingCell marching_hex_
 
MarchingCell marching_prism_
 
MarchingCell marching_pyramid_
 
MarchingCell marching_connector_
 
GLuint user_program_
 
PrimitiveInfo::ShaderKey toggles_config_
 
GLUPprimitive primitive_source_
 
GLUPbitfield toggles_source_state_
 
GLUPbitfield toggles_source_undetermined_
 
bool precompile_shaders_
 
bool use_core_profile_
 
bool use_ES_profile_
 
GLUPfloat * world_clip_plane_
 Cached pointer to uniform state variable. More...
 
std::map< std::string, GLsizei > variable_to_offset_
 Used by GPU-side uniform buffer. More...
 
bool v_is_visible_ [IMMEDIATE_BUFFER_SIZE]
 Indicates for a given vertex whether it is clipped or is visible, according to the current clipping plane. More...
 
GLUPfloat isect_vertex_attribute_ [3][12 *4]
 computed intersections. More...
 
GLuint latest_program_
 Latest used GLSL program. More...
 
GLuint vertex_id_VBO_
 A vertex buffer object with 65536 16 bits integers. More...
 

Detailed Description

GLUP context stores a Uniform Buffer Object with state variables similar to OpenGL's fixed functionality pipeline, and a set of Vertex Buffer Objects to emulate OpenGL's immediate mode.

Definition at line 1093 of file GLUP_context.h.

Member Function Documentation

◆ begin()

virtual void GLUP::Context::begin ( GLUPprimitive  primitive)
virtual

Begins rendering in immediate mode.

Parameters
[in]primitivethe primitive to be rendered.
See also
immediate_vertex(), immediate_color(), immediate_tex_coord()

◆ bind_uniform_state()

virtual void GLUP::Context::bind_uniform_state ( GLuint  program)
virtual

Binds GLUP uniform state to a program.

Parameters
[in]programthe id of the GLSL program

If the program uses GLUP, then it binds the program to GLUP uniform state, else this function does nothing.

◆ cell_is_clipped()

bool GLUP::Context::cell_is_clipped ( index_t  first_v)
protected

Tests whether the cell starting at a given vertex in the immediate buffer is clipped, according to current clipping mode and current primitive type.

Parameters
[in]first_vindex of the first vertex of the cell in the immediate buffer
Return values
trueif the cell starting at first_v in the immediate buffer is clipped-out
falseotherwise

◆ classify_vertices_in_immediate_buffers()

void GLUP::Context::classify_vertices_in_immediate_buffers ( )
protected

Updates v_is_visible_[] according to current clipping plane.

Used by implementations of Context that do not support clipping by shaders (ES2).

◆ compute_intersection()

void GLUP::Context::compute_intersection ( index_t  v1,
index_t  v2,
index_t  vi 
)
inlineprotected

Computes the intersection between the clipping plane and a segment.

Parameters
[in]v1index of the first extremity of the segment in the immediate buffer
[in]v2index of the second extremity of the segment in the immediate buffer
[in]viindex of where to wrote the intersection in the isect_xxx arrays

Definition at line 1867 of file GLUP_context.h.

◆ create_CPU_side_uniform_buffer()

void GLUP::Context::create_CPU_side_uniform_buffer ( )
protected

Creates a buffer for uniform variables for implementations that do not support uniform buffer objects.

This function is used by ES2.

◆ create_program_if_needed()

void GLUP::Context::create_program_if_needed ( GLUPprimitive  primitive)
protected

Creates the GLSL shader that corresponds to the specified primitive and current toggles configuration if not already initialized.

Parameters
[in]primitivethe primitive to be displayed

◆ create_vertex_id_VBO()

void GLUP::Context::create_vertex_id_VBO ( )
protected

Creates a vertex buffer object with 16 bits integers between 0 and 65535.

It is used to emulate gl_VertexID if GLSL does not support it.

◆ do_update_uniform_buffer()

virtual void GLUP::Context::do_update_uniform_buffer ( )
protectedvirtual

Copies GLUP uniform state to OpenGL.

This is the implementation of update_uniform_buffer().

◆ done_draw()

virtual void GLUP::Context::done_draw ( GLUPprimitive  primitive)
protectedvirtual

This function is called right after rendering primitives. It is called by end(), draw_arrays() and draw_elements().

Default implementation does nothing. This function is meant to be overloaded by derived Context classes.

◆ draw_arrays()

virtual void GLUP::Context::draw_arrays ( GLUPprimitive  primitive,
GLUPint  first,
GLUPsizei  count 
)
virtual

Draws primitives using current OpenGL array bindings.

This function operates just like glDrawArrays(), except that its primitive argument is a GLUPprimitive instead of regular OpenGL primitive. Internally it uses a (possibly different) OpenGL primitive, as well as a GLSL program to reinterpret it.

Parameters
[in]primitivethe GLUP primitive type
[in]firstfirst index to be rendered
[in]countnumber of vertices to be rendered

◆ draw_elements()

virtual void GLUP::Context::draw_elements ( GLUPprimitive  primitive,
GLUPsizei  count,
GLUPenum  type,
const GLUPvoid *  indices 
)
virtual

Draws primitives using current OpenGL array bindings.

This function operates just like glDrawElements(), except that its primitive argument is a GLUPprimitive instead of regular OpenGL primitive. Internally it uses a (possibly different) OpenGL primitive, as well as a GLSL program to reinterpret it.

Parameters
[in]primitivethe GLUP primitive type
[in]countnumber of vertices to be rendered
[in]typetype of element indices, as one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT
[in]indicesa pointer to where the indices are stored.

◆ end()

virtual void GLUP::Context::end ( )
virtual

Ends rendering in immediate mode.

See also
begin()

◆ extension_is_supported()

bool GLUP::Context::extension_is_supported ( const std::string &  extension)
protected

Tests whether an OpenGL extension is supported.

Parameters
[in]extensionthe name fo the extension to be tested.

This function needs to be called before starting using the extension, even if you are sure that it is supported. In particular, WebGL specification requires that.

Return values
trueif the extension is supported.
falseotherwise.

◆ get_config()

index_t GLUP::Context::get_config ( index_t  first_v,
index_t  nb_v 
)
inlineprotected

Assemble the configuration code of a primitive relative to the clipping plane.

Parameters
[in]first_vindex of the first vertex of the primitive in the immediate buffer
[in]nb_vnumber of vertices of the primitive
Returns
an integer with the i-th bit set if vertex i is visible, and unset if it is clipped.

Definition at line 1847 of file GLUP_context.h.

◆ get_fragment_shader_preamble_pseudo_file()

virtual void GLUP::Context::get_fragment_shader_preamble_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/fragment_shader_preamble.h.

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_geometry_shader_preamble_pseudo_file()

virtual void GLUP::Context::get_geometry_shader_preamble_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/geometry_shader_preamble.h.

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_marching_cell()

const MarchingCell& GLUP::Context::get_marching_cell ( ) const
protected

Gets the MarchingCell that corresponds to the current primitive.

The current primitive is defined by the argument of the previous call of setup_shaders_source_for_primitive().

Returns
A const reference to the current MarchingCell.

◆ get_marching_cells_pseudo_file()

virtual void GLUP::Context::get_marching_cells_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/marching_cells.h.

The current primitive is defined by the argument of the previous call of setup_shaders_source_for_primitive().

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_matrix()

GLUPdouble* GLUP::Context::get_matrix ( GLUPmatrix  matrix)
inline

Gets a pointer to the values of the matrix at the top of a given stack.

Parameters
[in]matrixname of the stack, one of GLUP_MODELVIEW_MATRIX, GLUP_PROJECTION_MATRIX, GLUP_TEXTURE_MATRIX

Definition at line 1394 of file GLUP_context.h.

◆ get_matrix_mode()

GLUPmatrix GLUP::Context::get_matrix_mode ( ) const
inline

Gets the current matrix stack.

Returns
The current matrix stack, i.e. one of GLUP_MODELVIEW, GLUP_PROJECT

Definition at line 1223 of file GLUP_context.h.

◆ get_primitive_pseudo_file()

virtual void GLUP::Context::get_primitive_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/primitive.h.

The current primitive is defined by the argument of the previous call of setup_shaders_source_for_primitive().

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_state_variable_address()

virtual Memory::pointer GLUP::Context::get_state_variable_address ( const char *  name)
virtual

Gets a pointer to the representation of a uniform state variable in host memory from its (unqualified) name.

Parameters
[in]namethe name of the variable, without the suffix "GLUPStateBlock."
Returns
a pointer to where the variable is represented in client side.

◆ get_tess_control_shader_preamble_pseudo_file()

virtual void GLUP::Context::get_tess_control_shader_preamble_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/tess_control_shader_preamble.h.

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_tess_evaluation_shader_preamble_pseudo_file()

virtual void GLUP::Context::get_tess_evaluation_shader_preamble_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/tess_evaluation_shader_preamble.h.

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_toggles_pseudo_file()

virtual void GLUP::Context::get_toggles_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/toggles.h.

The toggles are generated in function of the parameters of the previous call to setup_shaders_source_for_toggles() current configuration defined by prepare_sources_for_toggles()

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ get_vertex_shader_preamble_pseudo_file()

virtual void GLUP::Context::get_vertex_shader_preamble_pseudo_file ( std::vector< GLSL::Source > &  sources)
virtual

Gets the content of the virtual file GLUP/current_profile/vertex_shader_preamble.h.

Parameters
[in,out]sourceswhere the content of the virtual file should be appended

◆ glup_primitive_name()

static const char* GLUP::Context::glup_primitive_name ( GLUPprimitive  prim)
static

Gets the name of a primitive by GLUPprimitive.

Parameters
[in]prima GLUPprimitive
Returns
the name of the primitive, as a const char pointer

◆ immediate_color()

void GLUP::Context::immediate_color ( GLfloat  r,
GLfloat  g,
GLfloat  b,
GLfloat  a = 1.0f 
)
inline

Specifies the current color for the immediate mode buffers.

Parameters
[in]r,g,b,athe components of the current color.

Definition at line 1250 of file GLUP_context.h.

◆ immediate_normal()

void GLUP::Context::immediate_normal ( GLfloat  x,
GLfloat  y,
GLfloat  z 
)
inline

Specifies the current normal vector for the immediate mode buffers.

Parameters
[in]x,y,zthe current normal vector coordinates.

Definition at line 1274 of file GLUP_context.h.

◆ immediate_state()

ImmediateState& GLUP::Context::immediate_state ( )
inline

Gets the immediate state.

Returns
a reference to the immediate state.

Definition at line 1516 of file GLUP_context.h.

◆ immediate_tex_coord()

void GLUP::Context::immediate_tex_coord ( GLfloat  s,
GLfloat  t = 0.0f,
GLfloat  u = 0.0f,
GLfloat  v = 1.0f 
)
inline

Specifies the current texture coordinates for the immediate mode buffers.

Parameters
[in]s,t,u,vthe current texture coordinates.

Definition at line 1261 of file GLUP_context.h.

◆ immediate_vertex()

void GLUP::Context::immediate_vertex ( GLfloat  x,
GLfloat  y,
GLfloat  z = 0.0f,
GLfloat  w = 1.0f 
)
inline

Creates a new vertex in the immediate mode buffers.

Parameters
[in]x,y,z,wthe coordinates of the vertex

The color and texture coordinates of the new vertex are initialized from the current color and current texture coordinates.

Definition at line 1235 of file GLUP_context.h.

◆ load_matrix() [1/2]

void GLUP::Context::load_matrix ( const GLdouble  m[16])
inline

Replaces the top of the current matrix stack with the specified matrix.

Parameters
[in]mthe matrix that will replace the top of the current matrix stack

Definition at line 1164 of file GLUP_context.h.

◆ load_matrix() [2/2]

void GLUP::Context::load_matrix ( const GLfloat  m[16])
inline

Replaces the top of the current matrix stack with the specified matrix.

Parameters
[in]mthe matrix that will replace the top of the current matrix stack

Definition at line 1153 of file GLUP_context.h.

◆ mult_matrix()

void GLUP::Context::mult_matrix ( const GLdouble  m[16])
inline

Post-multiplies the top of the current matrix stack with the specified matrix.

Parameters
[in]mthe matrix that will post-multiply the top of the current matrix stack.
See also
matrix_mode()

Definition at line 1185 of file GLUP_context.h.

◆ prepare_to_draw()

virtual void GLUP::Context::prepare_to_draw ( GLUPprimitive  primitive)
protectedvirtual

This function is called before starting to render primitives. It is called by begin(), draw_arrays() and draw_elements().

Some primitives require to change some parameters in OpenGL. For instance, when we use GL_PATCH to gather the vertices of hexahedra and tetrahedra, the number of vertices per patch needs to be specified to OpenGL.

◆ primitive_declaration()

std::string GLUP::Context::primitive_declaration ( GLUPprimitive  prim) const
protected

Gets the GLSL declaration of the constant that indicates the current primitive.

Returns
a string with the GLSL declaration.

◆ primitive_supports_array_mode()

virtual bool GLUP::Context::primitive_supports_array_mode ( GLUPprimitive  prim) const
virtual

Tests whether a given GLUP primitive supports array mode.

If array mode is supported, then one can use glupDrawArray() and glupDrawElements() with the specified primitive.

Parameters
[in]primthe primitive to be tested.
Return values
trueif array mode is supported with prim
falseotherwise

◆ push_matrix()

void GLUP::Context::push_matrix ( )
inline

Pushes a copy of the top of the current stack matrix onto the current stack matrix.

See also
matrix_mode(), pop_matrix()

Definition at line 1196 of file GLUP_context.h.

◆ set_matrix_mode()

void GLUP::Context::set_matrix_mode ( GLUPmatrix  matrix)
inline

Sets the current matrix stack.

Parameters
[in]matrixone of GLUP_MODELVIEW, GLUP_PROJECT

This determines on which matrix stack set_matrix(), mult_matrix(), push_matrix() and pop_matrix() operate.

Definition at line 1214 of file GLUP_context.h.

◆ set_primitive_info()

virtual void GLUP::Context::set_primitive_info ( GLUPprimitive  glup_primitive,
GLenum  gl_primitive,
GLuint  program,
bool  bind_attrib_loc_and_link = true 
)
protectedvirtual

Initializes the PrimitiveInfo associated with a given GLUP primitive.

Parameters
[in]glup_primitivethe GLUP primitive.
[in]gl_primitivethe GL primitive used by the implementation
[in]programthe GLSL program used by the implementation
[in]bind_attrib_loc_and_linkif true, binds attribute location and links the shader

◆ set_primitive_info_immediate_index_mode()

virtual void GLUP::Context::set_primitive_info_immediate_index_mode ( GLUPprimitive  glup_primitive,
GLenum  gl_primitive,
GLuint  program,
index_t  nb_elements_per_glup_primitive,
index_t element_indices 
)
protectedvirtual

Initializes the PrimitiveInfo associated with a given GLUP primitive in immediate mode when an element index buffer is required.

An element index buffer is required when geometry shaders are not supported, for instance when using OpenGL ES in webGL.

Parameters
[in]glup_primitivethe GLUP primitive.
[in]gl_primitivethe GL primitive used to display the GLUP primitive.
[in]programthe GLSL program used by the implementation.
[in]nb_elements_per_glup_primitivethe number of element indices for each glup primitive. For instance, when drawing GLUP tetrahedra using OpenGL triangles, there are 4*3 = 12 elements per primitive.
[in]element_indicesa pointer to an array of nb_elements_per_glup_primitive integers that encode the indexing of one element. This array is replicated and shifted to generate the element index buffer.

◆ set_primitive_info_vertex_gather_mode()

virtual void GLUP::Context::set_primitive_info_vertex_gather_mode ( GLUPprimitive  glup_primitive,
GLenum  gl_primitive,
GLuint  program 
)
protectedvirtual

Initializes the PrimitiveInfo associated with a given GLUP primitive in vertex-gather mode.

In vertex-gather mode, all the coordinates of all vertices and all attributes of the primitive are gathered into a small number of vertices. This is required by primitives that have a number of vertices that corresponds to no existing OpenGL primitive (i.e., hexahedron and pyramid).

Parameters
[in]glup_primitivethe GLUP primitive.
[in]gl_primitivethe GL primitive used to display the GLUP primitive. The number of vertices of the GL primitive needs to be a divisor of the number of vertices of the GLUP primitive.
[in]programthe GLSL program used by the implementation

◆ setup()

virtual void GLUP::Context::setup ( )
virtual

Creates the uniform state and GLSL programs.

This function may throw exceptions if GLSL functionalities are not implemented in the OpenGL driver.

◆ setup_immediate_buffers()

virtual void GLUP::Context::setup_immediate_buffers ( )
protectedvirtual

Set-ups the buffers for immediate rendering.

This creates VBOs and the VAO.

◆ setup_shaders_source_for_primitive()

virtual void GLUP::Context::setup_shaders_source_for_primitive ( GLUPprimitive  primitive)
virtual

Sets the configurable GLSL sources for a given primitive type.

This function needs to be called before compiling the GLSL program.

Parameters
[in]primitivethe GLUP primitive

◆ setup_shaders_source_for_toggles()

void GLUP::Context::setup_shaders_source_for_toggles ( GLUPbitfield  toggles_state,
GLUPbitfield  toggles_undetermined = 0 
)

Sets the string that describes the settings of the toggles for a given configuration.

Parameters
[in]toggles_statean unsigned integer, with its bits corresponding to the state of each toggle
[in]toggles_undeterminedan unsigned integer, with its bits set if the corresponding toggle state needs to be determined dynamically from GLUP state

◆ setup_shaders_source_for_toggles_config()

void GLUP::Context::setup_shaders_source_for_toggles_config ( PrimitiveInfo::ShaderKey  toggles_config)
inlineprotected

Sets the string that describes the settings of the toggles for a given configuration.

Parameters
[in]toggles_configthe identifier of the toggles configurations, used to index the GLSL program in the PrimitiveInfo class

Definition at line 1764 of file GLUP_context.h.

◆ shrink_cells_in_immediate_buffers()

void GLUP::Context::shrink_cells_in_immediate_buffers ( )
protected

Shrinks the cells in the immediate buffer.

Applies the shrinking factor (state variable "cells_shrink") to all the cells stored in the current immediate buffer. Since there is no function to query the content of the current buffer, modidying it is acceptable. This function is used by derived classes (VanillaGL and ES2) that cannot shrink the cells with a shader.

◆ stream_immediate_buffers()

virtual void GLUP::Context::stream_immediate_buffers ( )
protectedvirtual

Sends all the active immediate buffers to the GPU.

Overwrites the VBOs with the contents of the buffers.

◆ uniform_state() [1/2]

UniformState& GLUP::Context::uniform_state ( )
inline

Gets the uniform state.

Returns
a reference to the uniform state

Definition at line 1348 of file GLUP_context.h.

◆ uniform_state() [2/2]

const UniformState& GLUP::Context::uniform_state ( ) const
inline

Gets the uniform state.

Returns
a const reference to the uniform state

Definition at line 1356 of file GLUP_context.h.

◆ uniform_state_declaration()

static const char* GLUP::Context::uniform_state_declaration ( )
static

Gets the GLSL declaration of GLUP uniform state.

Returns
a pointer to GLSL source code that declares GLUP uniform state.

Can be used by client-code shaders that need to have access to the GLUP uniform state. This corresponds to the contents of GLUPGLSL/state.h

◆ update_lighting()

virtual void GLUP::Context::update_lighting ( )
protectedvirtual

Updates the lighting in the uniform state.

Computes the half vector from the lighting vector.

◆ use_program()

void GLUP::Context::use_program ( GLuint  program)
inlineprotected

A wrapper around glUseProgram that tests whether uniform state needs to be sent to the program.

Each time a different program is used, the uniform state can be sent to it through the virtual function update_program_state(). If UBOs are supported, update_program_state() does nothing.

Definition at line 1925 of file GLUP_context.h.

Member Data Documentation

◆ isect_vertex_attribute_

GLUPfloat GLUP::Context::isect_vertex_attribute_[3][12 *4]
protected

computed intersections.

Used when clipping mode is GLUP_CLIP_SLICE_CELLS and clipping is done by software.

Definition at line 2030 of file GLUP_context.h.

◆ latest_program_

GLuint GLUP::Context::latest_program_
protected

Latest used GLSL program.

Used to check whether it changed and whether some uniform variables need to be sent to it.

Definition at line 2037 of file GLUP_context.h.

◆ nb_vertices_per_primitive_

index_t GLUP::Context::nb_vertices_per_primitive_[GLUP_NB_PRIMITIVES]
protected

Number of vertices per primitive (3 for GLUP_TRIANGLES, 4 for GLUP_QUADS etc...)

It is stored as a class member array rather than a static array so that particular implementations can change it according to the needs (for instance, GLUPES profile temporarily uses quads with for vertices to render GLUP_THICK_LINES).

Definition at line 1973 of file GLUP_context.h.

◆ v_is_visible_

bool GLUP::Context::v_is_visible_[IMMEDIATE_BUFFER_SIZE]
protected

Indicates for a given vertex whether it is clipped or is visible, according to the current clipping plane.

Used when clipping is done by software.

Definition at line 2023 of file GLUP_context.h.

◆ variable_to_offset_

std::map<std::string, GLsizei> GLUP::Context::variable_to_offset_
protected

Used by GPU-side uniform buffer.

It is initialized by create_GPU_side_uniform_buffer(), used only by VanillaGL and ES2 implementations.

Definition at line 2016 of file GLUP_context.h.

◆ vertex_id_VBO_

GLuint GLUP::Context::vertex_id_VBO_
protected

A vertex buffer object with 65536 16 bits integers.

It is used to emulate gl_VertexID in shaders.

Definition at line 2043 of file GLUP_context.h.

◆ world_clip_plane_

GLUPfloat* GLUP::Context::world_clip_plane_
protected

Cached pointer to uniform state variable.

It is initialized by create_GPU_side_uniform_buffer(), used only by VanillaGL and ES2 implementations.

Definition at line 2009 of file GLUP_context.h.


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