FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fplbase::RendererBase Class Reference

Manages the rendering system, handling the window and resources. More...

#include <renderer.h>

Detailed Description

Manages the rendering system, handling the window and resources.

The core of the rendering system. Deals with setting up and shutting down the window + OpenGL context, and creating/using resources such as shaders, textures, and geometry.

This is a singleton that has shared ownership amongst all Renderer classes. When the first Renderer class is created, this RendererBase class is also created. When the last Renderer class is destroyed, this RendererBase class is also destroyed.

Users should instantiate one or more Renderer classes. Users should not instantiate RendererBase.

Users can call a subset of Renderer functionality via the RendererBase singleton. For example,

if (RendererBase::Get()->feature_level() >= kFeatureLevel30) {
// Go ahead and use VAOs (vertex array objects).
}

But all of the RendererBase functionality is also in Renderer, and using it may (potentially) be faster since each thread has its own Renderer and there is only one shared RendererBase. So prefer using Renderer over the RendererBase singleton, when you have a Renderer around.

Public Member Functions

bool Initialize (const mathfu::vec2i &window_size, const char *window_title, WindowMode window_mode=kWindowModeWindowedScaled)
 Initializes the renderer by initializing the Environment object. More...
 
void AdvanceFrame (bool minimized, double time)
 Swaps frames. Call this once per frame inside your main loop. More...
 
void ShutDown ()
 Cleans up the resources initialized by the renderer.
 
void SetWindowSize (const mathfu::vec2i &window_size)
 Sets the window size, for when window is not owned by the renderer. More...
 
ShaderCompileAndLinkShader (const char *vs_source, const char *ps_source)
 Create a shader object from two strings containing glsl code. More...
 
ShaderRecompileShader (const char *vs_source, const char *ps_source, Shader *shader)
 Like CompileAndLinkShader, but pass in an old shader to replace. More...
 
bool AllowMultiThreading ()
 Checks for multithreading API. Returns true if the graphics API allows multi-threading.
 
void SetAnimation (const mathfu::AffineTransform *bone_transforms, int num_bones)
 Set bone transforms in vertex shader uniforms. More...
 
const std::string & last_error () const
 Contains the last error that occurred, if there is one. More...
 
void set_last_error (const std::string &last_error)
 
const mathfu::vec2i & window_size () const
 The device's current framebuffer size. More...
 
mathfu::vec2i & window_size ()
 
void set_window_size (const mathfu::vec2i &ws)
 Sets the window size. More...
 
mathfu::vec2i GetViewportSize ()
 Get the size of the viewport. More...
 
Environmentenvironment ()
 
double time () const
 Time in seconds since program start. More...
 
FeatureLevel feature_level () const
 The supported OpenGL ES feature level. More...
 
BlendMode force_blend_mode () const
 The blend that will be used for all draw calls. More...
 
void set_force_blend_mode (BlendMode bm)
 Set to override the blend mode used for all draw calls. More...
 
void set_override_pixel_shader (const std::string &ps)
 Set this force any shader that gets loaded to use this pixel shader instead (for debugging purposes). More...
 
int max_vertex_uniform_components ()
 Get the max number of uniforms components (i.e. individual floats, so a mat4 needs 16 of them). More...
 
const FplBaseVersion * GetFplBaseVersion () const
 Returns the version of the FPL Base Library.
 
bool SupportsTextureFormat (TextureFormat texture_format) const
 Returns if a texture format is supported by the hardware.
 
bool SupportsTextureNpot () const
 Returns if a NPOT textures are supported by the hardware. see: https://www.opengl.org/wiki/NPOT_Texture.
 
RendererBaseImpl * impl ()
 

Static Public Member Functions

static RendererBaseGet ()
 

Friends

class Renderer
 

Member Function Documentation

void fplbase::RendererBase::AdvanceFrame ( bool  minimized,
double  time 
)

Swaps frames. Call this once per frame inside your main loop.

The two arguments are typically the result of the InputManager's minimized() and Time() (seconds since the start of the program).

Parameters
minimizedIf the window is considered to be minimized.
timeThe seconds since the start of the program.
Shader* fplbase::RendererBase::CompileAndLinkShader ( const char *  vs_source,
const char *  ps_source 
)

Create a shader object from two strings containing glsl code.

Returns nullptr upon error, with a descriptive message in glsl_error(). Attribute names in the vertex shader should be aPosition, aNormal, aTexCoord, aColor, aBoneIndices and aBoneWeights, to match whatever attributes your vertex data has.

Parameters
vs_sourceThe source code of the vertex shader.
ps_sourceThe source code of the fragment shader.
FeatureLevel fplbase::RendererBase::feature_level ( ) const
inline

The supported OpenGL ES feature level.

Returns
Returns the supported OpenGL ES feature level.
BlendMode fplbase::RendererBase::force_blend_mode ( ) const
inline

The blend that will be used for all draw calls.

Returns
Returns the blend mode that will be used.
mathfu::vec2i fplbase::RendererBase::GetViewportSize ( )
inline

Get the size of the viewport.

This may be larger than the framebuffer/window on Android if the hardware scalar is enabled.

Returns
Returns the current viewport size.
bool fplbase::RendererBase::Initialize ( const mathfu::vec2i &  window_size,
const char *  window_title,
WindowMode  window_mode = kWindowModeWindowedScaled 
)

Initializes the renderer by initializing the Environment object.

both parameters are used on desktop platforms, but may be ignored on mobile platforms or certain environment backends in favor of the native resolution. Whether this actually still needs to create an context depends on the backend. A descriptive error is in last_error() if it returns false.

Parameters
window_sizeThe default size to initialize the window to.
window_titleThe title of the created window.
window_modeDetermines whether the window will use the window size, enter fullscreen mode, or enter fullscreen mode with the HW scaler disabled.
Returns
Returns true on success, false if there was an error.
const std::string& fplbase::RendererBase::last_error ( ) const
inline

Contains the last error that occurred, if there is one.

If any of the more complex loading operations (shaders, textures etc.) fail, this sting will contain a more informative error message.

Returns the last error that occurred.

int fplbase::RendererBase::max_vertex_uniform_components ( )
inline

Get the max number of uniforms components (i.e. individual floats, so a mat4 needs 16 of them).

The value is in individual floats, so a mat4 needs 16 of them. This variable is also available in the shader as GL_MAX_VERTEX_UNIFORM_COMPONENTS. From this, you can compute safe sizes of uniform arrays etc.

Returns
Returns the max number of uniform components.
Shader* fplbase::RendererBase::RecompileShader ( const char *  vs_source,
const char *  ps_source,
Shader shader 
)

Like CompileAndLinkShader, but pass in an old shader to replace.

Use placement new to use the same memory for the new shader. Returns nullptr upon error, with a descriptive message in glsl_error().

Note
Only call this at the start of the frame.
Parameters
shaderThe old shader to replace with the recompiled shader.
vs_sourceThe source code of the vertex shader.
ps_sourceThe source code of the fragment shader.
void fplbase::RendererBase::set_force_blend_mode ( BlendMode  bm)
inline

Set to override the blend mode used for all draw calls.

Overrides the blend that was set by calling SetBlendMode. Set to kBlendModeCount to disable.

Parameters
bmThe blend mode to be used.
void fplbase::RendererBase::set_override_pixel_shader ( const std::string &  ps)
inline

Set this force any shader that gets loaded to use this pixel shader instead (for debugging purposes).

Parameters
psThe pixel shader that will be used.
void fplbase::RendererBase::set_window_size ( const mathfu::vec2i &  ws)
inline

Sets the window size.

Sets the window_size member variable to the given parameter

Parameters
wsThe 2D vector for the window size
void fplbase::RendererBase::SetAnimation ( const mathfu::AffineTransform *  bone_transforms,
int  num_bones 
)

Set bone transforms in vertex shader uniforms.

Allows vertex shader to skin each vertex to the bone position.

Parameters
bone_transformsArray of transforms to pass to the shader.
num_bonesThe length of the provided array.
void fplbase::RendererBase::SetWindowSize ( const mathfu::vec2i &  window_size)
inline

Sets the window size, for when window is not owned by the renderer.

In the non-window-owning use case, call to update the window size whenever it changes.

Parameters
window_sizeThe size to set the window to.
double fplbase::RendererBase::time ( ) const
inline

Time in seconds since program start.

Used by animated shaders, updated once per frame only.

Returns
Returns the time in seconds since program start.
const mathfu::vec2i& fplbase::RendererBase::window_size ( ) const
inline

The device's current framebuffer size.

May change from frame to frame due to window resizing or Android navigation buttons turning on/off.

Returns
Returns the current framebuffer size.
mathfu::vec2i& fplbase::RendererBase::window_size ( )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


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