![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GL/GlView.h>
Base class for implementing OpenGL views. More...
Base class for implementing OpenGL views.
A GlView represents an OpenGL Viewport, i.e. a rectangular drawing area on the screen. Each GlView contains a matrix that converts view coordinates to world coordinates (camera located in the origin, looking down the negative z-axis). In order to map the 3D view coordinates to the 2D screen, each view internally uses a projection matrix converting view coordinates to clip coordinates (visible objects will be in a cube of -1 to 1 side length). You can access view and projection matrices through the GL::ViewState object that is updated during every render call.
The view is aware of the width and height of the viewport but it will not set glViewport. Thus, the actual glViewport must be set before calling render().
Derived classes shall draw all GlObjects of the view with the current view- and projection matrix in the current viewport on render(). Furthermore, they must set the GL::ViewState correctly.
Usually a GlView is wrapped by an InteractiveView to allow for handling user input events and for putting it into a DisplayWidget.
Classes | |
class | ViewStateGuard |
Temporarily changes the GL::ViewState of a GlView and resetting to the original value on destruction. More... | |
Public Types | |
enum | Type { SLICE2D = 0 , SLICE3D = 1 , SPACE3D = 2 , OTHER = 3 } |
Type of the view. More... | |
Public Member Functions | |
virtual bool | render ()=0 |
Render scene. glViewport must be set before. Called with valid OpenGL context. | |
virtual Type | type () const =0 |
Return the type of this view. | |
virtual void | setMatrix (const mat4 &mat) |
Sets the view matrix (view coordinates to world coordinates). | |
virtual const mat4 & | matrix () const |
Returns the current view matrix (view coordinates to world coordinates). | |
virtual void | resize (int width, int height) |
Set a new viewport size for this view. | |
virtual const GL::OrderIndependentTransparency * | orderIndependentTransparency () const |
Returns the optional OIT manager instance of the view if the feature is supported and enabled. | |
int | height () const |
Current viewport height of the view. | |
int | width () const |
Current viewport width of the view. | |
void | addObject (GlObject *object) |
Add a reference to a GlObject to be drawn by this view. | |
void | removeObject (GlObject *object) |
Remove a reference to a GlObject drawn by this view. | |
const std::vector< GlObject * > & | objects () const |
Return the set of GlObjects that are drawn by this view. | |
const GL::ViewState & | state () const |
Return the view state that was set during the last render() call. | |
Protected Member Functions | |
GL::OrderIndependentTransparency * | sharedOitInstance () const |
Offers support for GlViews sharing GL::OrderIndependentTransparency instances to reduce GPU memory consumption. | |
Protected Attributes | |
std::vector< GlObject * > | m_objects |
Other objects to consider during rendering. | |
mat4 | m_matrix = mat4::Identity() |
Matrix converting view coordinates to world coords (inverse of a traditional OpenGL view matrix) | |
GL::ViewState | m_state |
OpenGL state describing viewport, projection and model-view matrix of last render call. | |
int | m_width = 0 |
int | m_height = 0 |
enum Type |
Type of the view.
Enumerator | |
---|---|
SLICE2D | 2D slice view |
SLICE3D | 3D MPR slice view |
SPACE3D | 3D volume view |
OTHER | Other/unknown kind of view. |
|
pure virtual |
Render scene. glViewport must be set before. Called with valid OpenGL context.
Implemented in GlGeometryView, GlCurvedView, GlPlotView, GlSliceView, and GlVolumeView.
|
pure virtual |
Return the type of this view.
Implemented in GlGeometryView, GlCurvedView, GlPlotView, GlSliceView, and GlVolumeView.
|
inlinevirtual |
Sets the view matrix (view coordinates to world coordinates).
Reimplemented in GlSliceView, and GlVolumeView.
|
inlinevirtual |
Returns the current view matrix (view coordinates to world coordinates).
Reimplemented in GlVolumeView.
|
virtual |
Set a new viewport size for this view.
Updates the width and height properties but does not change the glViewport. Depending on the view type, this may also update the view matrix.
Reimplemented in GlSliceView.
|
inlinevirtual |
Returns the optional OIT manager instance of the view if the feature is supported and enabled.
A GlView may choose to support correct order-independent blending of semi-transparent surfaces of scene objects. In this case it should override this function to return its corresponding GL::OrderIndependentTransparency instance. Draw calls of GlObjects can query OIT support through this function and use the pointer to setup their shaders so that it writes semi-transparent fragments to the OIT buffer which the view will ultimately resolve at the end of the render pass.
Reimplemented in GlSliceView, and GlVolumeView.
|
protected |
Offers support for GlViews sharing GL::OrderIndependentTransparency instances to reduce GPU memory consumption.
Internally, this function will use the GL::InstanceManager interface to manage the internal caching. Usage of this class must be limited to a single GlView::render() call in order to ensure that multiple views sharing the same instance do not compromise each other. This function will return nullptr
if OIT is not supported.