Graphite
Version 3
An experimental 3D geometry processing program
|
Helper class for OpenGL context management. More...
#include <OGF/renderer/context/rendering_context.h>
Public Member Functions | |
RenderingContext (GLUPcontext glup_context=nullptr) | |
RenderingContext constructor. More... | |
~RenderingContext () | |
RenderingContext destructor. | |
index_t | get_width () const |
Gets the width. More... | |
index_t | get_height () const |
Gets the height. More... | |
bool | initialized () const |
Tests whether this RenderingContext is initialized. More... | |
virtual void | make_current () |
Makes this RenderingContext the current one. More... | |
virtual void | done_current () |
This function should be called when client code is done with rendering to the current context. More... | |
virtual void | swap_buffers () |
Meant to make the rendered frame visible. More... | |
void | clear () |
Clears this RenderingContext. More... | |
void | load_viewing_matrix (const mat4 &m) |
Sets the current viewing matrix. More... | |
void | mul_viewing_matrix (const mat4 &m) |
Multiplies the current viewing matrix by another one. More... | |
const mat4 & | viewing_matrix () const |
Gets the current viewing matrix. More... | |
const mat4 & | inverse_viewing_matrix () const |
Gets the inverse of the current viewing matrix. More... | |
void | load_projection_matrix (const mat4 &m) |
Sets the projection matrix and sends it to OpenGL. More... | |
mat4 | projection_matrix () const |
Gets the projection matrix. More... | |
virtual void | begin_frame () |
Begins a new frame. More... | |
virtual void | end_frame () |
Terminates a frame. | |
const Color & | background_color () const |
Gets the primary background color. More... | |
void | set_background_color (const Color &c) |
Sets the primary background color. More... | |
const Color & | background_color_2 () const |
Gets the secondary background color. More... | |
void | set_background_color_2 (const Color &c) |
Sets the secondary background color. More... | |
void | set_background_image (Image *image) |
Sets the background image. More... | |
void | update_background_image_from_data (Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width, index_t height) |
Updates the background image from raw data pointer. More... | |
void | set_lighting_matrix (const mat4 &m) |
Sets the lighting matrix. More... | |
const mat4 & | lighting_matrix () const |
Gets the lighting matrix. More... | |
mat4 | clipping_matrix () const |
Gets the clipping matrix. More... | |
void | set_clipping_matrix (const mat4 &m) |
Sets the lighting matrix. More... | |
void | set_clipping (bool x) |
Activates or deactivates clipping. More... | |
bool | get_clipping () const |
Tests whether clipping is active. More... | |
void | set_clipping_equation (const vec4 &x) |
Sets the clipping equation. More... | |
const vec4 & | get_clipping_translation () const |
Gets the clipping equation. More... | |
void | set_clipping_viewer (bool x) |
Sets whether clipping translation and rotation are applied in object bounding box or in viewer coordinates. More... | |
bool | get_clipping_viewer () const |
Tests whether clipping translation and rotation are applied in object bounding box or in viewer coordinates. More... | |
GLUPclipMode | get_clipping_mode () const |
Gets the current clipping mode. More... | |
void | set_clipping_mode (GLUPclipMode mode) |
Sets the current clipping mode. More... | |
bool | double_buffer () const |
Tests whether this RenderingContext uses double buffering. More... | |
bool | stereo () const |
Tests whether this RenderingContext uses stereo rendering. More... | |
virtual void | set_double_buffer (bool b) |
Specifies whether double buffering should be used. More... | |
virtual void | snapshot (Image *image, bool make_current=true, index_t x0=0, index_t y0=0, index_t width=0, index_t height=0) |
std::string | gl_vendor () const |
Gets the OpenGL vendor. More... | |
std::string | gl_renderer () const |
Gets the OpenGL renderer. More... | |
std::string | gl_version () const |
Gets the OpenGL version. More... | |
std::string | gl_extensions () const |
Gets the OpenGL extension. More... | |
std::string | get_gpu_information () const |
Gets the information on the GPU. More... | |
std::string | get_gpu_extensions () const |
Gets the GPU extensions. More... | |
void | set_full_screen_effect (FullScreenEffectImpl *fse) |
Sets the full screen effect. More... | |
FullScreenEffectImpl * | get_full_screen_effect () const |
Gets the current full screen effect. More... | |
virtual void | resize (index_t w, index_t h) |
Must be called whenever the rendering context is resized. More... | |
vec2 | screen_to_ndc (index_t x, index_t y) const |
Transforms screen coordinates to normalized device coordinates (viewport transform). More... | |
void | ndc_to_screen (const vec2 &ndc, index_t &x, index_t &y) const |
Transforms normalized device coordinates to screen coordinates (inverse viewport transform). \parma[in] ndc the normalized device coordinates of the point (x and y between -1.0 and 1.0). More... | |
virtual void | begin_picking (const vec2 &ndc) |
Enters picking mode. More... | |
virtual void | end_picking () |
Exits picking mode. More... | |
index_t | picked_id () const |
Gets the picked id that was encoded in the pixel color under the mouse pointer. More... | |
double | picked_depth () const |
Gets the depth of the picked point in screen coordinates. More... | |
const vec3 & | picked_point () const |
Gets the picked point in world coordinates. More... | |
bool | picked_background () const |
Tests whether the background was picked. More... | |
vec3 | unproject (const vec2 &p_ndc, double depth) const |
Back-transforms a point given by its normalized device coordinates and depth. More... | |
void | check_gl () const |
Tests whether there was any OpenGL error. More... | |
GLuint | frame_buffer_id () const |
Gets the default frame buffer id. More... | |
bool | contains_picking_image () const |
Tests whether the image is a picking image. More... | |
Overlay & | overlay () |
Gets the Overlay. More... | |
Public Member Functions inherited from GEO::Counted | |
void | ref () const |
Increments the reference count. More... | |
void | unref () const |
Decrements the reference count. More... | |
bool | is_shared () const |
Check if the object is shared. More... | |
int | nb_refs () const |
Gets the number of references that point to this object. More... | |
Static Public Member Functions | |
static RenderingContext * | current () |
Gets the current RenderingContext. More... | |
static bool | is_currently_rendering () |
Tests whether a rendering operation is occuring. More... | |
static bool | is_currently_picking () |
Tests whether a picking operation is occuring. More... | |
Static Public Member Functions inherited from GEO::Counted | |
static void | ref (const Counted *counted) |
Increments the reference count. More... | |
static void | unref (const Counted *counted) |
Decrements the reference count. More... | |
Protected Member Functions | |
virtual void | draw_background () |
Draws the background. More... | |
void | setup_viewport () |
Setups the viewport transform. More... | |
void | setup_projection_ortho (double zNear, double zFar) |
Setups the OpenGL projection matrix in orthographic mode. More... | |
void | setup_projection_perspective (double zScreen, double zNear, double zFar, double eye_offset=0.0) |
Setups the OpenGL projection matrix in orthographic mode. More... | |
void | setup_modelview (double zScreen) |
Setups the OpenGL model view transform from the viewing parameters. More... | |
void | setup_lighting () |
Setups OpenGL lighting parameters. | |
void | update_clipping () |
Create a clipping plane perpendicular to the Z axis, transformed by the current clipping matrix and the modelview matrix. | |
Texture * | background_texture () const |
Gets the background texture. More... | |
void | set_initialized (bool x=true) |
Indicates whether this RenderingContext is initialized. More... | |
void | set_width (index_t w) |
Sets the width. More... | |
void | set_height (index_t h) |
Sets the height. More... | |
void | get_view_parameters () |
Queries the Graphite environment for global rendering parameters, e.g. stereo & perspective, and updates member variables if this RenderingContext accordingly. | |
void | get_picked_point () |
In picking mode, this function gets all the information about the picked point, by reading the depth buffer and the color buffer with color-coded id. | |
Protected Member Functions inherited from GEO::Counted | |
Counted () | |
Creates a reference counted object. More... | |
virtual | ~Counted () |
Destroys a reference counted object. More... | |
Static Protected Member Functions | |
static const double * | convert_matrix (const mat4 &M) |
Converts (transposes) a Graphite matrix for OpenGL use. More... | |
Protected Attributes | |
bool | initialized_ |
index_t | width_ |
index_t | height_ |
bool | double_buffer_ |
int | viewport_x_ |
int | viewport_y_ |
int | viewport_width_ |
int | viewport_height_ |
mat4 | viewing_matrix_ |
mat4 | inverse_viewing_matrix_ |
bool | inverse_viewing_matrix_dirty_ |
bool | lighting_ |
mat4 | lighting_matrix_ |
bool | clipping_ |
mat4 | clipping_matrix_ |
vec4 | clipping_equation_ |
bool | clipping_viewer_ |
GLUPclipMode | clipping_mode_ |
Color | background_color_ |
Color | background_color_2_ |
Texture_var | background_texture_ |
FullScreenEffectImpl_var | full_screen_effect_ |
bool | perspective_ |
bool | stereo_ |
bool | stereo_odd_frame_ |
double | stereo_eye_dist_ |
vec3 | head_position_ |
double | head_tilt_ |
bool | picking_mode_ |
vec2 | picked_ndc_ |
double | picked_depth_ |
index_t | picked_id_ |
vec3 | picked_point_ |
bool | picked_background_ |
bool | last_frame_was_picking_ |
GLuint | frame_buffer_id_ |
The identifier of the default frame buffer associated with this RenderingContext. More... | |
bool | frame_buffer_id_init_ |
GLUPcontext | glup_context_ |
The GLUP context. More... | |
bool | owns_glup_context_ |
bool | use_core_profile_ |
bool | use_ES_profile_ |
bool | transparent_ |
Overlay | overlay_ |
Static Protected Attributes | |
static RenderingContext * | current_ |
static bool | geogram_gfx_initialized_ |
static index_t | nb_render_locks_ |
The number of RenderingContext instances that are currently rendering something, i.e. between begin_frame() and end_frame(). | |
static index_t | nb_picking_locks_ |
The number of RenderingContext instances that are currently picking something, or that contain a picking image in their color buffer. | |
Friends | |
class | RenderArea |
Helper class for OpenGL context management.
RenderingContext manages the viewing matrices and light sources. It also provides functionalities for picking.
Definition at line 67 of file rendering_context.h.
OGF::RenderingContext::RenderingContext | ( | GLUPcontext | glup_context = nullptr | ) |
RenderingContext constructor.
[in] | glup_context | the GLUP context to be used for rendering, or 0. If 0, then RenderingContext will create and manage its own GLUP context. |
const Color& OGF::RenderingContext::background_color | ( | ) | const |
Gets the primary background color.
The primary background color is used to clear the color buffer.
const Color& OGF::RenderingContext::background_color_2 | ( | ) | const |
Gets the secondary background color.
If the secondary background color is different from the primary background color, then a vertical colorramp is generated in the background.
|
inlineprotected |
Gets the background texture.
Definition at line 698 of file rendering_context.h.
|
virtual |
Begins a new frame.
This clears the color and depth buffer, and setups the viewing matrix. This function calls make_current() before issuing any OpenGL call.
Reimplemented in OGF::SkinImGUIRenderingContext.
|
virtual |
Enters picking mode.
This function should be called before begin_frame()
[in] | ndc | ndc the normalized device coordinates of the picked point (x and y between -1.0 and 1.0). |
void OGF::RenderingContext::check_gl | ( | ) | const |
Tests whether there was any OpenGL error.
Displays error messages in the console as obtained by glGetError()
void OGF::RenderingContext::clear | ( | ) |
Clears this RenderingContext.
This clears both the color buffer and the frame buffer.
mat4 OGF::RenderingContext::clipping_matrix | ( | ) | const |
Gets the clipping matrix.
The clipping matrix transforms the clipping plane.
|
inline |
Tests whether the image is a picking image.
Graphite picking uses images made of picking IDs (instead of colors). This function tests whether the last rendering operation generated such images. In this case, the image should not be displayed to the user.
true | if the contained image has picking ids. |
false | otherwise. |
Definition at line 611 of file rendering_context.h.
|
staticprotected |
Converts (transposes) a Graphite matrix for OpenGL use.
[in] | M | a const reference to the matrix to be converted |
|
inlinestatic |
Gets the current RenderingContext.
Definition at line 87 of file rendering_context.h.
|
virtual |
This function should be called when client code is done with rendering to the current context.
Some implementations of make_current() acquire a lock, that is released by done_current()
|
inline |
Tests whether this RenderingContext uses double buffering.
true | if double buffering is used \retvavl false otherwise |
Definition at line 404 of file rendering_context.h.
|
protectedvirtual |
Draws the background.
If a background texture was specified, uses the texture, else generates a colorramp between the primary background color and the secondary background color.
|
virtual |
Exits picking mode.
This function should be called after end_frame().
|
inline |
Gets the default frame buffer id.
Some versions of Qt use a FrameBufferObject instead of a full OpenGL context in rendering widgets.
Definition at line 598 of file rendering_context.h.
bool OGF::RenderingContext::get_clipping | ( | ) | const |
Tests whether clipping is active.
true | if clipping is active |
false | otherwise |
|
inline |
Gets the current clipping mode.
Definition at line 385 of file rendering_context.h.
|
inline |
Gets the clipping equation.
Definition at line 355 of file rendering_context.h.
|
inline |
Tests whether clipping translation and rotation are applied in object bounding box or in viewer coordinates.
true | if clipping plane is fixed in viewer space |
false | if clipping is defined in object space |
Definition at line 375 of file rendering_context.h.
|
inline |
Gets the current full screen effect.
Definition at line 492 of file rendering_context.h.
std::string OGF::RenderingContext::get_gpu_extensions | ( | ) | const |
Gets the GPU extensions.
std::string OGF::RenderingContext::get_gpu_information | ( | ) | const |
Gets the information on the GPU.
|
inline |
Gets the height.
Definition at line 128 of file rendering_context.h.
|
inline |
Gets the width.
Definition at line 120 of file rendering_context.h.
std::string OGF::RenderingContext::gl_extensions | ( | ) | const |
Gets the OpenGL extension.
std::string OGF::RenderingContext::gl_renderer | ( | ) | const |
Gets the OpenGL renderer.
std::string OGF::RenderingContext::gl_vendor | ( | ) | const |
Gets the OpenGL vendor.
std::string OGF::RenderingContext::gl_version | ( | ) | const |
Gets the OpenGL version.
|
inline |
Tests whether this RenderingContext is initialized.
A RenderingContext is initialized once the first drawing event was processed.
true | if this RenderingContext is initialized |
false | otherwise |
Definition at line 139 of file rendering_context.h.
const mat4& OGF::RenderingContext::inverse_viewing_matrix | ( | ) | const |
Gets the inverse of the current viewing matrix.
|
static |
Tests whether a picking operation is occuring.
This concerns all the rendering contexts (this a static method).
true | if the content of one of the framebuffers is a picking image |
false | otherwise |
|
static |
Tests whether a rendering operation is occuring.
This concerns all the rendering contexts (thus a static method).
true | if a rendering operation is currently occuring |
false | otherwise |
const mat4& OGF::RenderingContext::lighting_matrix | ( | ) | const |
Gets the lighting matrix.
void OGF::RenderingContext::load_projection_matrix | ( | const mat4 & | m | ) |
Sets the projection matrix and sends it to OpenGL.
[in] | m | a const reference to the projection matrix. |
void OGF::RenderingContext::load_viewing_matrix | ( | const mat4 & | m | ) |
Sets the current viewing matrix.
This just changes the stored viewing matrix, nothing is sent to OpenGL. The viewing matrix is sent to OpenGL when begin_frame() is called.
[in] | m | a const reference to the viewing matrix |
|
virtual |
Makes this RenderingContext the current one.
OpenGL uses global variables. Since several 3D graphic windows may be opened at the same time, the corresponding renderer has to be 'made current' before issuing 3D drawing commands to it. Note that begin_frame() automatically calls make_current() and clear().
void OGF::RenderingContext::mul_viewing_matrix | ( | const mat4 & | m | ) |
Multiplies the current viewing matrix by another one.
This just changes the stored viewing matrix, nothing is sent to OpenGL. The viewing matrix is sent to OpenGL when begin_frame() is called. This replaces the viewing matrix with m times the viewing matrix (mutliplies m on the left).
[in] | m | a const reference to the viewing matrix |
Transforms normalized device coordinates to screen coordinates (inverse viewport transform). \parma[in] ndc the normalized device coordinates of the point (x and y between -1.0 and 1.0).
[out] | x,y | the integer coordinates of the point, in screen space |
|
inline |
Gets the Overlay.
The Overlay has a couple of basic drawing primitives for displaying graphics over the rendering window.
Definition at line 620 of file rendering_context.h.
|
inline |
Tests whether the background was picked.
This tests whether the picked depth is equal to 1.0
true | if the background was picked (i.e. no object was picked) |
false | otherwise (i.e. an object was picked) |
Definition at line 573 of file rendering_context.h.
|
inline |
Gets the depth of the picked point in screen coordinates.
Definition at line 555 of file rendering_context.h.
|
inline |
Gets the picked id that was encoded in the pixel color under the mouse pointer.
Some specialized shaders replace the color with (color-coded) identifiers.
Definition at line 546 of file rendering_context.h.
|
inline |
Gets the picked point in world coordinates.
Definition at line 563 of file rendering_context.h.
mat4 OGF::RenderingContext::projection_matrix | ( | ) | const |
Gets the projection matrix.
Must be called whenever the rendering context is resized.
Updates the viewport transform.
[in] | w | the new width |
[in] | h | the new height |
Reimplemented in OGF::SkinImGUIRenderingContext.
Transforms screen coordinates to normalized device coordinates (viewport transform).
[in] | x,y | the integer coordinates of a point, in screen space. |
void OGF::RenderingContext::set_background_color | ( | const Color & | c | ) |
Sets the primary background color.
[in] | c | a const reference to the primary background color |
void OGF::RenderingContext::set_background_color_2 | ( | const Color & | c | ) |
Sets the secondary background color.
If the secondary background color is different from the primary background color, then a vertical colorramp is generated in the background.
[in] | c | a const reference to the secondary background color |
void OGF::RenderingContext::set_background_image | ( | Image * | image | ) |
Sets the background image.
If a background image is defined, then it is used to fill the background. This generates an OpenGL texture from the image.
[in] | image | a pointer to the image |
void OGF::RenderingContext::set_clipping | ( | bool | x | ) |
Activates or deactivates clipping.
[in] | x | true if clipping should be used, false otherwise |
|
inline |
Sets the clipping equation.
[in] | x | a const reference to the clipping equation, stored in a vec4. |
Definition at line 346 of file rendering_context.h.
void OGF::RenderingContext::set_clipping_matrix | ( | const mat4 & | m | ) |
Sets the lighting matrix.
The clipping matrix transforms the clipping plane. Nothing is sent to OpenGL, this is taken into account by begin_frame().
[in] | m | a const reference to the clipping matrix. |
|
inline |
Sets the current clipping mode.
[in] | mode | one of GLUP_CLIP_STANDARD, GLUP_CLIP_WHOLE_CELLS, GLUP_CLIP_STRADDLING_CELLS, GLUP_CLIP_SLICE_CELLS |
Definition at line 395 of file rendering_context.h.
|
inline |
Sets whether clipping translation and rotation are applied in object bounding box or in viewer coordinates.
[in] | x | true if clipping plane is fixed in viewer space, false if clipping is defined in object space |
Definition at line 365 of file rendering_context.h.
|
virtual |
Specifies whether double buffering should be used.
[in] | b | true if double buffering should be used, false otherwise |
void OGF::RenderingContext::set_full_screen_effect | ( | FullScreenEffectImpl * | fse | ) |
Sets the full screen effect.
Full screen effects are shaders that operate on the content of the color buffer and depth buffer.
[in] | fse | a pointer to the FullScreenEffectImpl that implements the full screen effect or nil if no full screen effect should be used. |
|
inlineprotected |
Sets the height.
This function is just used to indicate to this RenderingContext what is its current height (it does not resize the RenderingContext).
[in] | h | the height |
Definition at line 733 of file rendering_context.h.
|
inlineprotected |
Indicates whether this RenderingContext is initialized.
This function is called by the RenderArea widget, after the first repaint event, once the RenderingContext is ready for rendering.
[in] | x | true if this rendering context is initialized, false otherwise |
Definition at line 711 of file rendering_context.h.
void OGF::RenderingContext::set_lighting_matrix | ( | const mat4 & | m | ) |
Sets the lighting matrix.
The lighting matrix transforms the light sources. Nothing is sent to OpenGL, this is taken into account by begin_frame().
[in] | m | a const reference to the lighting matrix. |
|
inlineprotected |
Sets the width.
This function is just used to indicate to this RenderingContext what is its current width (it does not resize the RenderingContext).
[in] | w | the width |
Definition at line 722 of file rendering_context.h.
|
protected |
Setups the OpenGL model view transform from the viewing parameters.
[in] | zScreen | screen projection plane |
|
protected |
Setups the OpenGL projection matrix in orthographic mode.
[in] | zNear | depth coordinate of the near plane |
[in] | zFar | depth coordinate of the far plane |
|
protected |
Setups the OpenGL projection matrix in orthographic mode.
[in] | zScreen | screen projection plane, used to compute the frustrum angle |
[in] | zNear | depth coordinate of the near plane |
[in] | zFar | depth coordinate of the far plane |
[in] | eye_offset | distance between the eyes, used in stereo rendering |
|
protected |
Setups the viewport transform.
Sends the stored viewport parameters to OpenGL.
|
virtual |
Copies the color buffer onto the specified image.
[out] | image | The image, it should have the same size as this RenderingContext and should be in RGB mode. |
[in] | make_current | if true, makes this rendering context the current rendering context before reading the pixels. |
[in] | x0,y0,width,height | optional image bounds. If let unspecified, the entire picking buffer is copied. |
|
inline |
Tests whether this RenderingContext uses stereo rendering.
true | if stereo rendering is used |
false | otherwise |
Definition at line 413 of file rendering_context.h.
|
virtual |
Meant to make the rendered frame visible.
Base class implementation does nothing. In most cases, this operation is already done by the toolkit (e.g. Qt), therefore this function does not need to be overloaded in most cases.
Back-transforms a point given by its normalized device coordinates and depth.
void OGF::RenderingContext::update_background_image_from_data | ( | Memory::pointer | ptr, |
Image::ColorEncoding | color_encoding, | ||
Image::ComponentEncoding | component_encoding, | ||
index_t | width, | ||
index_t | height | ||
) |
Updates the background image from raw data pointer.
If a background texture is already present, then it updates it with the data, else it creates a new background texture.
[in] | ptr | a pointer to image data |
[in] | color_encoding | the color encoding of the data |
[in] | component_encoding | the data type used for the color components |
[in] | width | image width |
[in] | height | image height |
const mat4& OGF::RenderingContext::viewing_matrix | ( | ) | const |
Gets the current viewing matrix.
|
protected |
The identifier of the default frame buffer associated with this RenderingContext.
QOpenGLWidget in Qt5.4 does not use a real OpenGL context, it uses a FrameBuffer object. Therefore, when we want to unbind a FrameBuffer object, we need to restore the binding to the one used by Qt instead.
Definition at line 810 of file rendering_context.h.
|
protected |
The GLUP context.
The GLUP API provides immediate-mode OpenGL-like primitives and other ones, such as tetrahedra, hexahedra etc...
Definition at line 835 of file rendering_context.h.