Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::CanvasOpenGL2< DerivedRenderApp > Class Template Reference

The Canvas class describes a canvas on which opengl2 can draw. More...

#include <vclib/opengl2/canvas.h>

Public Types

using CallbackReadBuffer = ReadBufferTypes::CallbackReadBuffer
 

Public Member Functions

 CanvasOpenGL2 (void *winId, uint width, uint height, void *displayId=nullptr)
 
void onInit ()
 Automatically called by the DerivedRenderApp when the window initializes. Initialization is requires in some backends+window manager combinations, and therefore it must be implemented (also if empty) in every Canvas class.
 
void onPaint ()
 Automatically called by the DerivedRenderApp when the window asks to repaint.
 
bool onReadDepth (const Point2i &point, CallbackReadBuffer callback=nullptr)
 Automatically called by the DerivedRenderApp when a drawer asks to read the depth buffer at a specific point.
 
bool onReadId (const Point2i &point, CallbackReadBuffer callback=nullptr)
 Automatically called by the DerivedRenderApp when a drawer asks to read the ID at a specific point.
 
void onResize (uint width, uint height)
 Automatically called by the DerivedRenderApp when the window is resized.
 
bool onScreenshot (const std::string &filename, uint multiplier=1)
 Automatically called by the DerivedRenderApp when a drawer asks for a screenshot.
 
bool screenshot (const std::string &filename, uint multiplier=1)
 Request a screenshot of the canvas. The screenshot will be saved asynchronously.
 
void setDefaultClearColor (const Color &color)
 
Point2< uint > size () const
 
uint viewId () const
 

Protected Types

using ByteData = ReadBufferTypes::ByteData
 
using FloatData = ReadBufferTypes::FloatData
 
using ReadData = ReadBufferTypes::ReadData
 

Private Member Functions

autoderived ()
 
const autoderived () const
 
void readDepthData ()
 

Private Attributes

vcl::Color mDefaultClearColor = vcl::Color::Black
 
CallbackReadBuffer mReadBufferCallback = nullptr
 
Point2i mReadDepthPoint = Point2i(-1, -1)
 
Point2< uint > mSize = {0, 0}
 
voidmWinId = nullptr
 

Detailed Description

template<typename DerivedRenderApp>
class vcl::CanvasOpenGL2< DerivedRenderApp >

The Canvas class describes a canvas on which opengl2 can draw.

Its usage requires to have a window object that can be used to initialize the canvas. The window object is not managed by the Canvas class, and can be managed by any of the windowing systems or libraries that allow to retrieve the native window handle (e.g. Qt, GLFW...).

You can create your custom bgfx canvas class by inheriting from this class and passing to the constructor the native window handle and the window size. Alternatively to the constructor, you can also use the init() method to initialize the canvas (if the required parameters are not available at construction time).

This class does not provide a render loop, that must be implemented in one of the derived classes. The render loop must call the frame() member function at the end of each frame, after all the bgfx rendering commands have been issued.

The opengl2 rendering code should be implemented in the virtual member function draw(), that must be reimplemented in the derived classes. This method is called by the frame() method (that must be called in the render loop).

The class provides two important member functions:

  • frame(): this function must be called by the derived classes at the end of each frame, after all the opengl2 rendering commands have been issued;

Member Function Documentation

◆ onReadDepth()

bool vcl::CanvasOpenGL2< DerivedRenderApp >::onReadDepth ( const Point2i point,
CallbackReadBuffer  callback = nullptr 
)
inline

Automatically called by the DerivedRenderApp when a drawer asks to read the depth buffer at a specific point.

Parameters
point
callback
Returns

◆ onReadId()

bool vcl::CanvasOpenGL2< DerivedRenderApp >::onReadId ( const Point2i point,
CallbackReadBuffer  callback = nullptr 
)
inline

Automatically called by the DerivedRenderApp when a drawer asks to read the ID at a specific point.

Parameters
pointThe point where the ID must be read.
callbackThe callback function that will be called when the ID is read.
Returns
always false
Note
this function is not supported in opengl2

◆ onResize()

void vcl::CanvasOpenGL2< DerivedRenderApp >::onResize ( uint  width,
uint  height 
)
inline

Automatically called by the DerivedRenderApp when the window is resized.

Parameters
width
height

◆ onScreenshot()

bool vcl::CanvasOpenGL2< DerivedRenderApp >::onScreenshot ( const std::string &  filename,
uint  multiplier = 1 
)
inline

Automatically called by the DerivedRenderApp when a drawer asks for a screenshot.

Parameters
filename
width
height
Returns

◆ screenshot()

bool vcl::CanvasOpenGL2< DerivedRenderApp >::screenshot ( const std::string &  filename,
uint  multiplier = 1 
)
inline

Request a screenshot of the canvas. The screenshot will be saved asynchronously.

Parameters
filenameThe filename where the screenshot will be saved.
multiplierThe multiplier applied to the canvas image.
Returns
true if the screenshot is requested, false otherwise.

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