VVISF & VVGL
VVGL::GLScene Class Reference

Manages drawing in a GLContext, provides a simple interface for orthographic rendering, render-to-texture operations, and loading vert/geo/frag shaders. More...

#include <GLScene.hpp>

Inherited by VVGL::GLTexToTexCopier, and VVISF::ISFScene.

Classes

struct  RenderTarget
 RenderTarget member vars are used to provide attachments for the GL framebuffer. These buffers need to be tracked so they can be bound/unbound appropriately, which is what this structure is for. More...
 

Public Types

using RenderCallback = std::function< void(const GLScene &inScene)>
 This defines the interface for a function/lambda that is used for encapsulating user-provided drawing code. Both the render callback and the render cleanup callback use this type. More...
 
using RenderPrepCallback = std::function< void(const GLScene &inScene, const bool &inSceneReshaped, const bool &inPgmChanged)>
 This defines the interface for the render prep callback, which is executed prior to the render callback. More...
 

Public Member Functions

 GLScene ()
 Creates a new OpenGL context that shares the global buffer pool's context.
 
 GLScene (const GLContextRef &inCtx)
 Creates a new GLScene instance, but not a new OpenGL context- instead it uses the passed GLContext.
 
GLContextRef context () const
 Returns the context used by this scene.
 
GLVersion glVersion () const
 Returns the version of OpenGL currently being used by this scene's GL context.
 
void setPrivatePool (const GLBufferPoolRef &n)
 Sets the receiver's private buffer pool (default is null). If non-null, this buffer pool will be used to generate any GL resources required by this scene. Handy if you have a variety of GL contexts that aren't shared and you have to switch between them rapidly on a per-frame basis.
 
GLBufferPoolRef privatePool () const
 Gets the receiver's private buffer pool- null by default, only non-null if something called setPrivatePool().
 
void setPrivateCopier (const GLTexToTexCopierRef &n)
 Sets the receiver's private buffer copier (which should default to null). If non-null, this copier will be used to copy any resources that need to be copied- like setPrivatePool(), handy if you have a variety of GL contexts that aren't shared and you have to switch between them rapidly on a per-frame basis.
 
GLTexToTexCopierRef privateCopier () const
 Gets the receiver's private buffer copier- null by default, only non-null if something called setPrivateCopier().
 
Render functions

These functions cause the scene to render.

virtual GLBufferRef createAndRenderABuffer (const Size &inSize=Size(640., 480.), const GLBufferPoolRef &inPool=nullptr)
 Creates an 8 bit per channel GL texture, uses it as a color attachment to the GL context and then renders into it. Calls setOrthoSize() with the size of the image in the passed buffer.
 
virtual void renderToBuffer (const GLBufferRef &inBuffer)
 Uses the passed buffer as a color attachment to the GL context and then renders into it. Calls setOrthoSize() with the size of the image in the passed buffer.
 
virtual void render (const RenderTarget &inRenderTarget=RenderTarget())
 Renders the GL scene, uses whatever attachments are present in the passed RenderTarget. Doesn't call setOrthoSize() before rendering!
 
virtual void renderBlackFrame (const RenderTarget &inRenderTarget=RenderTarget())
 Makes the scene render transparent black into whatever attachments are present in the passed RenderTarget.
 
virtual void renderOpaqueBlackFrame (const RenderTarget &inRenderTarget=RenderTarget())
 Makes the scene render opaque black into whatever attachments are present in the passed RenderTarget.
 
virtual void renderRedFrame (const RenderTarget &inRenderTarget=RenderTarget())
 Makes the scene render opaque red into whatever attachments are present in the passed RenderTarget.
 
Callback setup functions

These functions set the functions or lambdas to be executed at various stages during rendering.

void setRenderPreLinkCallback (const RenderCallback &n)
 The render pre-link callback is executed if there's a shader after the shader/shaders have been successfully compiled, but before they've been linked. Procedurally, this is the first callback to execute. You probably don't want to perform any draw calls in this callback- this is a good time to configure your geometry shader.
 
void setRenderPrepCallback (const RenderPrepCallback &n)
 The render prep callback is executed after any shaders have been compiled and linked, after the attachments have been made, and after the framebuffer has been cleared (assuming the scene is configured to perform a clear). Procedurally, this is the second callback to execute, and the last to execute before draw calls are expected. You probably don't want to perform any draw calls in this callback- this is a good time to do any ancillary setup outside of this scene that needs to occur before drawing begins.
 
void setRenderCallback (const RenderCallback &n)
 The render callback is expected to contain the drawing code that you want the scene to perform. Procedurally, this is the third callback to execute.
 
void setRenderCleanupCallback (const RenderCallback &n)
 The render cleanup callback is executed immediately after the render callback. Procedurally, this is the fourth and final callback to execute as a result of a render call. You probably don't want to perform any draw calls in this callback- the context has already been flushed and there isn't a framebuffer any more. This is a good time to do any ancillary teardown outside of this scene that needs to occur before you finish and return execution to whatever started rendering.
 
Viewport/camera setup

These functions configure orthogonal projection- GLScene was primarily written for 2d orthogonal rendering.

void setAlwaysNeedsReshape (const bool &n)
 Defaults to false. If set to true, the viewport and orthogonal projection setup is applied every single frame (GL2 uses glOrtho, GL3+ uses a 4x4 matrix uniform in the shader to pass a projection transform to the program). You can leave this false unless you plan on modifying the viewport or equivalent of projection matrices in your callbacks.
 
virtual void setOrthoSize (const Size &n)
 Sets the orthogonal render size. If the size is 0x0 then orthogonal rendering is skipped- any other positive values will cause the scene to configure itself for orthographic projection at the passed size during rendering.
 
Size orthoSize () const
 Gets the orthogonal render size. If the size is 0x0 then orthogonal rendering is disabled.
 
void setOrthoFlipped (const bool &n)
 The _orthoFlipped member variable defaults to false- if it's set to true, the orthographic projection or equivalent will be flipped vertically.
 
bool orthoFlipped () const
 Gets the value of the _orthoFlipped member variable. If this is true, the orthographic projection or equivalent will be flipped vertically.
 
Clear color setup

These functions configure whether or not the scene will clear prior to rendering, and what color it will use to clear.

void setClearColor (const GLColor &n)
 Sets the clear color to the passed color.
 
void setClearColor (const float &r, const float &g, const float &b, const float &a)
 Sets the color color using the passed float values.
 
void setClearColor (float *n)
 Sets the clear color using a pointer to enough memory to contain four float values.
 
void setPerformClear (const bool &n)
 Sets the '_performClear' member variable. If it's true (the default) the context will clear to its clear color prior to drawing. The clear is performed before the render prep callback.
 
Shader setup

These functions get and set the various shaders this scene uses to render.

virtual void setVertexShaderString (const string &n)
 Sets the vertex shader string.
 
virtual string vertexShaderString ()
 Gets the vertex shader string.
 
virtual void setGeometryShaderString (const string &n)
 Sets the geometry shader string.
 
virtual string geometryShaderString ()
 Gets the geometry shader string.
 
virtual void setFragmentShaderString (const string &n)
 Sets the fragment shader string.
 
virtual string fragmentShaderString ()
 Gets the fragment shader string.
 
uint32_t program () const
 Gets the program ID.
 

Related Functions

(Note that these are not member functions.)

using GLSceneRef = shared_ptr< GLScene >
 A GLSceneRef is a shared pointer around a GLScene.
 
GLSceneRef CreateGLSceneRef ()
 Creates and returns a GLScene. The scene makes a new GL context which shares the context of the global buffer pool.
 
GLSceneRef CreateGLSceneRefUsing (const GLContextRef &inCtx)
 Creates and returns a GLScene. The scene uses the passed GL context to do its drawing.
 

Detailed Description

Manages drawing in a GLContext, provides a simple interface for orthographic rendering, render-to-texture operations, and loading vert/geo/frag shaders.

A GLScene is a container for a GL context that lets you provide various callbacks which are executed at specific times during rendering. The interface is geared towards making it easy to load frag/vert/geo shaders, perform orthographic projection, providing customized drawing code, subclassing, and rendering to textures/buffers/GLBuffers. Used as a subclass of several other classes, also used in sample apps to perform GL rendering and output.

Member Typedef Documentation

◆ RenderCallback

using VVGL::GLScene::RenderCallback = std::function<void(const GLScene & inScene)>

This defines the interface for a function/lambda that is used for encapsulating user-provided drawing code. Both the render callback and the render cleanup callback use this type.

Parameters
inSceneThe scene executing the callback.

◆ RenderPrepCallback

using VVGL::GLScene::RenderPrepCallback = std::function<void(const GLScene & inScene, const bool & inSceneReshaped, const bool & inPgmChanged)>

This defines the interface for the render prep callback, which is executed prior to the render callback.

Parameters
inSceneThe scene executing the callback.
inSceneReshapedTrue if the scene has been reshaped (if orthographic projection has been enabled/disabled or if the orthographic size changed).
inPgmChangedTrue if the program has changed (if one of the shaders has been modified)

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