![]() |
FPLBase
An open source project by
FPL.
|
Manages the rendering system, handling the window and resources. More...
#include <renderer.h>
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,
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... | |
Shader * | CompileAndLinkShader (const char *vs_source, const char *ps_source) |
Create a shader object from two strings containing glsl code. More... | |
Shader * | RecompileShader (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... | |
Environment & | environment () |
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 RendererBase * | Get () |
Friends | |
class | Renderer |
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).
minimized | If the window is considered to be minimized. |
time | The 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.
vs_source | The source code of the vertex shader. |
ps_source | The source code of the fragment shader. |
|
inline |
The supported OpenGL ES feature level.
|
inline |
The blend that will be used for all draw calls.
|
inline |
Get the size of the viewport.
This may be larger than the framebuffer/window on Android if the hardware scalar is enabled.
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.
window_size | The default size to initialize the window to. |
window_title | The title of the created window. |
window_mode | Determines whether the window will use the window size, enter fullscreen mode, or enter fullscreen mode with the HW scaler disabled. |
|
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.
|
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.
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().
shader | The old shader to replace with the recompiled shader. |
vs_source | The source code of the vertex shader. |
ps_source | The source code of the fragment shader. |
|
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.
bm | The blend mode to be used. |
|
inline |
Set this force any shader that gets loaded to use this pixel shader instead (for debugging purposes).
ps | The pixel shader that will be used. |
|
inline |
Sets the window size.
Sets the window_size member variable to the given parameter
ws | The 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.
bone_transforms | Array of transforms to pass to the shader. |
num_bones | The length of the provided array. |
|
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.
window_size | The size to set the window to. |
|
inline |
Time in seconds since program start.
Used by animated shaders, updated once per frame only.
|
inline |
The device's current framebuffer size.
May change from frame to frame due to window resizing or Android navigation buttons turning on/off.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.