cgv
|
OpenGL helper class to simplify transparent rendering. More...
#include <gl_transparent_renderer.h>
Public Member Functions | |
gl_transparent_renderer (bool front_to_back=true, float _depth_bias=0.001) | |
construct uninitialized depth peeler | |
bool | init (context &ctx) |
checks for extensions and init depth peeler, return success | |
void | init_frame (context &ctx) |
configure frame buffer and textures | |
int | render_transparent (context &ctx, int max_nr_layers, int tex_unit=-1) |
perform transparent rendering by considering a maximum of the specified number of depth layers | |
void | destruct (context &ctx) |
destruct the transparent renderer | |
![]() | |
gl_depth_peeler (bool front_to_back=true, float _depth_bias=0.001) | |
construct uninitialized depth peeler | |
virtual | ~gl_depth_peeler () |
destruct the depth peeler | |
void | invert_t (bool enable=true) |
set the sign for the vertical texture coordinate. In case of some ATI-cards this needs to be enabled to avoid flipping intermediate textures. | |
void | set_back_to_front () |
enable back to front mode | |
void | set_front_to_back () |
enable front to back mode | |
bool | is_front_to_back () const |
return whether the mode is front to back | |
void | set_depth_bias (float bias) |
the depth bias is used as epsilon for the test against the second depth buffer and is initialized to 0.0005f | |
float | get_depth_bias () const |
return the current depth bias | |
bool | is_initialized () const |
check whether the depth peeler has been initialized, i.e. the init method has been called successfully before | |
void | copy_depth_buffer (context &ctx) |
copies the current depth buffer to the second depth buffer, what is typically done before peeling a layer | |
void | begin_layer (context &ctx, int tex_unit=-1) |
start to extract the next layer. Within begin_layer and end_layer the following OpenGL features are used: texture generation functions, 2D texturing and the alpha Test | |
unsigned int | end_layer (context &ctx) |
finish the layer and return the number of drawn fragments in the layer. All OpenGL settings are restored. | |
Public Attributes | |
std::string | last_error |
a string that contains the last error, which is only set by the init method | |
cgv::signal::signal< context & > | render_callback |
signal called to render the transparent content for first layer without additional depth test | |
cgv::signal::signal< context &, texture & > | render_callback_2 |
signal called to render the transparent content for second and further layers with additional depth test against texture given in second argument | |
![]() | |
std::string | last_error |
a string that contains the last error, which is only set by the init method | |
Protected Member Functions | |
void | create_and_attach_texture (context &ctx, texture &tex, int w, int h, int i=-1) |
ensure that texture has the correct dimensions and is created | |
void | blend_texture_over_viewport (context &ctx, texture &tex) |
renders the given texture over the current viewport | |
Protected Attributes | |
gl_depth_peeler | peeler |
depth peeler used for visibility sorting | |
texture | depth_buffer |
texture | layer_tex |
texture | color_tex |
texture used as color buffer in front to back mode to blend together all transparent layers before blending the result over the current color buffer | |
frame_buffer | fb |
![]() | |
unsigned int | query |
texture | depth_texture |
float | depth_bias |
bool | front_to_back |
context * | ctx_ptr |
bool | _invert_t |
OpenGL helper class to simplify transparent rendering.
It is derived from a depth peeler whose functionality is used for the visibility sorting according to the approach described in the "order independent transparency" paper of Cass Everit. Call the init method after your OpenGL context has been created. Transparent rendering is done such that the rendered objects are blended over the rendered scene in the current color and depth buffer. Rendering of transparent objects should be done in the finish_frame method of a drawable. A sample implementation looks like this:
Definition at line 25 of file gl_transparent_renderer.h.
cgv::render::gl::gl_transparent_renderer::gl_transparent_renderer | ( | bool | front_to_back = true , |
float | _depth_bias = 0.001 |
||
) |
construct uninitialized depth peeler
Definition at line 12 of file gl_transparent_renderer.cxx.
|
protected |
renders the given texture over the current viewport
Definition at line 81 of file gl_transparent_renderer.cxx.
References cgv::math::fvec< T, N >::data(), cgv::render::texture::disable(), cgv::render::texture::enable(), cgv::render::context::get_modelview_matrix(), and cgv::render::context::get_projection_matrix().
Referenced by render_transparent().
|
protected |
ensure that texture has the correct dimensions and is created
Definition at line 33 of file gl_transparent_renderer.cxx.
References cgv::render::frame_buffer::attach(), cgv::render::texture::create(), cgv::render::texture::destruct(), cgv::data::data_format::get_height(), cgv::data::data_format::get_width(), cgv::render::render_component::is_created(), cgv::data::data_format::set_height(), and cgv::data::data_format::set_width().
Referenced by init_frame().
|
virtual |
destruct the transparent renderer
Reimplemented from cgv::render::gl::gl_depth_peeler.
Definition at line 229 of file gl_transparent_renderer.cxx.
References color_tex, cgv::render::frame_buffer::destruct(), cgv::render::texture::destruct(), and cgv::render::gl::gl_depth_peeler::destruct().
|
virtual |
checks for extensions and init depth peeler, return success
Reimplemented from cgv::render::gl::gl_depth_peeler.
Definition at line 21 of file gl_transparent_renderer.cxx.
References cgv::render::gl::gl_depth_peeler::init(), and last_error.
|
virtual |
configure frame buffer and textures
Reimplemented from cgv::render::gl::gl_depth_peeler.
Definition at line 51 of file gl_transparent_renderer.cxx.
References color_tex, cgv::render::frame_buffer::create(), create_and_attach_texture(), cgv::render::frame_buffer::destruct(), cgv::render::texture::destruct(), cgv::render::frame_buffer::get_height(), cgv::render::frame_buffer::get_width(), cgv::render::gl::gl_depth_peeler::init_frame(), cgv::render::frame_buffer::is_complete(), cgv::render::render_component::is_created(), and cgv::render::gl::gl_depth_peeler::is_front_to_back().
int cgv::render::gl::gl_transparent_renderer::render_transparent | ( | context & | ctx, |
int | max_nr_layers, | ||
int | tex_unit = -1 |
||
) |
perform transparent rendering by considering a maximum of the specified number of depth layers
Definition at line 120 of file gl_transparent_renderer.cxx.
References cgv::render::gl::gl_depth_peeler::begin_layer(), blend_texture_over_viewport(), color_tex, cgv::render::gl::gl_depth_peeler::copy_depth_buffer(), cgv::render::frame_buffer::disable(), cgv::render::frame_buffer::enable(), cgv::render::gl::gl_depth_peeler::end_layer(), render_callback, render_callback_2, and cgv::render::texture::replace_from_buffer().
|
protected |
texture used as color buffer in front to back mode to blend together all transparent layers before blending the result over the current color buffer
Definition at line 35 of file gl_transparent_renderer.h.
Referenced by destruct(), init_frame(), and render_transparent().
|
protected |
Definition at line 31 of file gl_transparent_renderer.h.
|
protected |
Definition at line 37 of file gl_transparent_renderer.h.
|
mutable |
a string that contains the last error, which is only set by the init method
Definition at line 44 of file gl_transparent_renderer.h.
Referenced by init().
|
protected |
Definition at line 33 of file gl_transparent_renderer.h.
|
protected |
depth peeler used for visibility sorting
Definition at line 29 of file gl_transparent_renderer.h.
cgv::signal::signal<context&> cgv::render::gl::gl_transparent_renderer::render_callback |
signal called to render the transparent content for first layer without additional depth test
Definition at line 46 of file gl_transparent_renderer.h.
Referenced by render_transparent().
signal called to render the transparent content for second and further layers with additional depth test against texture given in second argument
Definition at line 48 of file gl_transparent_renderer.h.
Referenced by render_transparent().