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

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

#include <vclib/bgfx/canvas.h>

Public Types

using CallbackReadBuffer = ReadBufferTypes::CallbackReadBuffer
 

Public Member Functions

 CanvasBGFX (void *winId, uint width, uint height, void *displayId=nullptr)
 
Point2< uint > size () const
 
bgfx::ViewId viewId () const
 
bgfx::FrameBufferHandle frameBuffer () const
 
void setDefaultClearColor (const Color &color)
 
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 onResize (uint width, uint height)
 Automatically called by the DerivedRenderApp when the window is resized.
 
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 onScreenshot (const std::string &filename, uint width=0, uint height=0)
 Automatically called by the DerivedRenderApp when a drawer asks for a screenshot.
 

Protected Types

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

Private Types

using ReadFramebufferRequest = detail::ReadFramebufferRequest
 

Private Member Functions

void offscreenFrame ()
 
autoderived ()
 
const autoderived () const
 

Private Attributes

voidmWinId = nullptr
 
bgfx::ViewId mViewId = BGFX_INVALID_VIEW
 
bgfx::FrameBufferHandle mFbh = BGFX_INVALID_HANDLE
 
Point2< uint > mSize = {0, 0}
 
vcl::Color mDefaultClearColor = vcl::Color::Black
 
uint32_t mCurrFrame = 0
 
std::optional< ReadFramebufferRequest > mReadRequest = std::nullopt
 

Detailed Description

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

The Canvas class describes a canvas on which bgfx 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 bgfx rendering code should be implemented in the virtual member function draw(uint viewId), that must be reimplemented in the derived classes. This method is called by the frame() method (that must be called in the render loop), and its argument is the bgfx view ID.

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 bgfx rendering commands have been issued;
  • onResize(width, height): this function must be called by the derived classes whenever the window is resized.

Member Function Documentation

◆ onReadDepth()

bool vcl::CanvasBGFX< 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

◆ onResize()

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

Automatically called by the DerivedRenderApp when the window is resized.

Parameters
width
height

◆ onScreenshot()

bool vcl::CanvasBGFX< DerivedRenderApp >::onScreenshot ( const std::string &  filename,
uint  width = 0,
uint  height = 0 
)
inline

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

Parameters
filename
width
height
Returns

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