cgv
cgv::render::gl Namespace Reference

namespace for opengl specific GPU programming More...

Classes

class  gl_context
 
class  gl_cursor
 
class  gl_depth_peeler
 
class  gl_implicit_surface_drawable_base
 
struct  gl_traits
 
class  gl_transparent_renderer
 
class  image_drawable
 base class of drawables that show static or animated images More...
 
class  mesh_drawable
 simple implementation of a drawable for a polygonal mesh with support for materials More...
 

Enumerations

enum  ContouringType
 type of contouring method >
 
enum  NormalComputationType
 normal computation type >
 

Functions

bool ensure_glew_initialized ()
 initialize glew in the first call to this function and always return whether this was successful
 
GLuint map_to_gl (MaterialSide ms)
 return OpenGL material side constant
 
void set_gl_format (texture &tex, GLuint gl_format, const std::string &component_format_description)
 set a very specific texture format. This should be called after the texture is constructed and before it is created. More...
 
GLuint get_gl_format (const texture &tex)
 return the texture format used for a given texture. If called before texture has been created, the function returns, which format would be chosen by the automatic format selection process.
 
void gl_set_material (const cgv::media::illum::phong_material &mat, MaterialSide ms, float alpha)
 enable a material without textures
 
CGV_API void set_material (const cgv::media::illum::phong_material &mat, MaterialSide ms, float alpha)
 set material in opengl state to given material
 
unsigned map_to_gl (cgv::data::ComponentFormat cf, cgv::data::ComponentIntegerInterpretation cii=cgv::data::CII_DEFAULT)
 map a component format to a gl enum, return -1 of this was not possible More...
 
unsigned map_to_gl (TypeId ti)
 map a type id to a gl enum More...
 
unsigned get_gl_cube_map_target (unsigned side)
 return one of the six cube map sides gl enums
 
bool generate_mipmaps (unsigned int dim, bool is_array=false, std::string *last_error=0)
 generate mipmaps for the currently bound texture, which has the given texture dimension; optionally pass a string to get information on failure
 
unsigned find_best_texture_format (const cgv::data::component_format &cf, cgv::data::component_format *best_cf=0, const std::vector< cgv::data::data_view > *palettes=0)
 map the given component format to the best matching available gl component format
 
bool load_texture (const cgv::data::const_data_view &data, unsigned gl_tex_format, unsigned level=-1, unsigned cube_side=-1, int num_array_layers=0, const std::vector< cgv::data::data_view > *palettes=0)
 load data to a texture with the glTexImage commands and generate mipmaps if the level parameter is -1, return whether mipmaps were created
 
bool replace_texture (const cgv::data::const_data_view &data, int level, int x, int y, int z, const std::vector< cgv::data::data_view > *palettes)
 replace part or complete data of currently bound texture with the data in the given data view More...
 
unsigned int create_texture (const cgv::data::const_data_view &dv, bool mipmap=true, const std::vector< cgv::data::data_view > *palettes=0, unsigned tex_id=-1)
 create a texture from the given data view creating a mipmap pyramid
 
unsigned int create_texture (const cgv::data::const_data_view &dv, unsigned level, unsigned cube_side, const std::vector< cgv::data::data_view > *palettes, unsigned tex_id)
 create a certain texture level from the given data view and optionally specify a cube side of a cube map
 
bool cover_screen (context &ctx, shader_program *prog_ptr, bool flip_tex_v_coord, float xmin, float ymin, float xmax, float ymax, float umin, float vmin, float umax, float vmax)
 cover the current viewport with a textured quad using the textured default shader program or the one passed in the third parameter More...
 
void gl_texture_to_screen (float xmin, float ymin, float xmax, float ymax, float umin, float vmin, float umax, float vmax)
 cover the current viewport with a textured quad
 
void gl_1D_texture_to_screen (bool vary_along_x=true, float xmin=-1.0f, float ymin=-1.0f, float xmax=1.0f, float ymax=1.0f)
 cover the current viewport or a rectangle with it with a quad textured by a 1D texture
 
bool complete_program_form_render_to_texture3D (cgv::render::context &ctx, cgv::render::shader_program &prog, std::string *error_message=0)
 complete the given shader program that is assumed to have a working fragment shader. More...
 
bool render_to_texture3D (context &ctx, shader_program &prog, TextureSampling texture_sampling, texture &target_tex, texture *target_tex2=0, texture *target_tex3=0, texture *target_tex4=0)
 Render to the given target 3D texture with the given shader program that must be completed with the function complete_program_form_render_to_texture3D(). More...
 
unsigned int read_image_to_texture (const std::string &file_name, bool mipmaps, double *aspect_ptr, bool *has_alpha_ptr)
 
bool read_image_to_textures (const std::string &file_name, std::vector< unsigned > &tex_ids, std::vector< float > &durations, bool mipmaps=true, double *aspect_ptr=0, bool *has_alpha_ptr=0)
 read several images from one image file that can contain an animation
 
void set_lighting_parameters (context &ctx, shader_program &prog)
 set the program variables needed by the lighting.glsl shader
 
void push_textured_material_prog (shader_program &prog)
 push a shader program onto the textured material stack
 
void pop_textured_material_prog ()
 pop a shader program from the textured material stack
 
CGV_API unsigned int create_texture (const cgv::data::const_data_view &dv, unsigned level, unsigned cube_side=-1, const std::vector< cgv::data::data_view > *palettes=0, unsigned tex_id=-1)
 create a certain texture level from the given data view and optionally specify a cube side of a cube map
 
CGV_API bool replace_texture (const cgv::data::const_data_view &data, int level=0, int x=0, int y=0, int z=-1, const std::vector< cgv::data::data_view > *palettes=0)
 replace part or complete data of currently bound texture with the data in the given data view More...
 
 DEPRECATED ("deprecated, use cgv::render::context based light management.") extern CGV_API void set_lighting_parameters(context &ctx
 set the program variables needed by the lighting.glsl shader
 
 DEPRECATED ("deprecated, use cgv::render::context::ref_surface_shader_prog() instead.") extern CGV_API shader_program &ref_textured_material_prog(context &ctx)
 return a reference to the singleton textured material shader program, which is constructed on demand only
 
 DEPRECATED ("deprecated, use automatic cgv::render::context based shader_program stack.") extern CGV_API void push_textured_material_prog(shader_program &prog)
 push a shader program onto the textured material stack
 
 DEPRECATED ("deprecated, use automatic cgv::render::context based shader_program stack.") extern CGV_API void pop_textured_material_prog()
 pop a shader program from the textured material stack
 

Detailed Description

namespace for opengl specific GPU programming

Function Documentation

◆ complete_program_form_render_to_texture3D()

CGV_API bool cgv::render::gl::complete_program_form_render_to_texture3D ( cgv::render::context ctx,
cgv::render::shader_program prog,
std::string *  error_message = 0 
)

complete the given shader program that is assumed to have a working fragment shader.

The function adds the rest of the pipeline and provides the input <in vec3 tex_coord> to the fragment shader. The output of the fragment shader is stored in the 3D texture passed to render_to_texture3D(). After this call the shader program is managed by the caller and can be used once or several times in the function render_to_texture3D(). In case of failure, false is returned and in case the error_message string is provided an error message is assigned to error_message.

◆ cover_screen()

CGV_API bool cgv::render::gl::cover_screen ( context ctx,
shader_program prog_ptr = 0,
bool  flip_tex_v_coord = false,
float  xmin = -1.0f,
float  ymin = -1.0f,
float  xmax = 1.0f,
float  ymax = 1.0f,
float  umin = 0.0f,
float  vmin = 0.0f,
float  umax = 1.0f,
float  vmax = 1.0f 
)

cover the current viewport with a textured quad using the textured default shader program or the one passed in the third parameter

A shader program passed in the third parameter must have the vertex attributes in vec4 position; in vec2 texcoord

◆ map_to_gl() [1/2]

CGV_API unsigned cgv::render::gl::map_to_gl ( cgv::data::ComponentFormat  cf,
cgv::data::ComponentIntegerInterpretation  cii 
)

map a component format to a gl enum, return -1 of this was not possible

undefinded format with no component

red channel of color format

green channel of color format

blue channel of color format

alpha format

color format with luminance component L

color format with intensity component I

color format with luminance and alpha components: L and A

color format with intensity and alpha components: I and A

color format with components R, G

color format with components R, G and B

color format with components R, G, B and A

color format with components B, G and R

color format with components B, G, R and A

depth component

stencil component

undefinded format with no component

red channel of color format

green channel of color format

blue channel of color format

alpha format

color format with luminance component L

color format with intensity component I

color format with luminance and alpha components: L and A

color format with intensity and alpha components: I and A

color format with components R, G

color format with components R, G and B

color format with components R, G, B and A

color format with components B, G and R

color format with components B, G, R and A

depth component

stencil component

◆ map_to_gl() [2/2]

CGV_API unsigned cgv::render::gl::map_to_gl ( TypeId  ti)

map a type id to a gl enum

used for undefined type

void

boolean

signed integer stored in 8 bits

signed integer stored in 16 bits

signed integer stored in 32 bits

signed integer stored in 64 bits

unsigned integer stored in 8 bits

unsigned integer stored in 16 bits

unsigned integer stored in 32 bits

unsigned integer stored in 64 bits

floating point type stored in 16 bits

floating point type stored in 32 bits

floating point type stored in 64 bits

wchar

string type

wstring type

always the index after the last type

◆ read_image_to_texture()

CGV_API unsigned int cgv::render::gl::read_image_to_texture ( const std::string &  file_name,
bool  mipmaps = true,
double *  aspect_ptr = 0,
bool *  has_alpha_ptr = 0 
)

read the given image file into a texture and return the texture id or -1 in case of failure. The aspect ratio of the texture is written into the value pointed to by aspect_ptr. In case has_alpha_ptr is provided a boolean telling whether the texture contains alpha values is written to this field.

◆ render_to_texture3D()

CGV_API bool cgv::render::gl::render_to_texture3D ( context ctx,
shader_program prog,
TextureSampling  texture_sampling,
texture target_tex,
texture target_tex2 = 0,
texture target_tex3 = 0,
texture target_tex4 = 0 
)

Render to the given target 3D texture with the given shader program that must be completed with the function complete_program_form_render_to_texture3D().

The program needs to be enabled before calling this function and all uniforms necessary to the fragment shader implementation of the caller should be set. The fragment shader is called once per texel with input tex_coord of type vec3 and the result is stored in the given texture, which cannot be enabled and used as input to the fragment shader. The texture_sampling parameter steers the computation of the tex_coord input. If additional textures are provided, they are attached as additional targets during render to texture. Then the fragment shader should access the different targets through the gl_FragData[] array. All target textures must have the same resolution.

◆ replace_texture() [1/2]

bool cgv::render::gl::replace_texture ( const cgv::data::const_data_view data,
int  level = 0,
int  x = 0,
int  y = 0,
int  z = -1,
const std::vector< cgv::data::data_view > *  palettes = 0 
)

replace part or complete data of currently bound texture with the data in the given data view

Texture dimension is derived from the dimension of data view. The level gives the mipmap level in which to replace. A level of -1 corresponds to level 0 with recomputation of the mipmaps after replacement. x,y and z are offsets for 1D, 2D and 3D textures. In case of a cube map, the z parameter must be between 0 and 5 and defines the cube side in which to replace. Return value tells whether mipmaps have been recomputed

◆ replace_texture() [2/2]

CGV_API bool cgv::render::gl::replace_texture ( const cgv::data::const_data_view data,
int  level = 0,
int  x = 0,
int  y = 0,
int  z = -1,
const std::vector< cgv::data::data_view > *  palettes = 0 
)

replace part or complete data of currently bound texture with the data in the given data view

Texture dimension is derived from the dimension of data view. The level gives the mipmap level in which to replace. A level of -1 corresponds to level 0 with recomputation of the mipmaps after replacement. x,y and z are offsets for 1D, 2D and 3D textures. In case of a cube map, the z parameter must be between 0 and 5 and defines the cube side in which to replace. Return value tells whether mipmaps have been recomputed

◆ set_gl_format()

CGV_API void cgv::render::gl::set_gl_format ( texture tex,
GLuint  gl_format,
const std::string &  component_format_description 
)

set a very specific texture format. This should be called after the texture is constructed and before it is created.

set a very specific texture format from a gl-constant and a component_format description. This should be called after the texture is constructed and before it is created.