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

Renderer is the main API class for rendering commands. More...

#include <renderer.h>

Detailed Description

Renderer is the main API class for rendering commands.

Graphics APIs that support multi-threading (e.g. Vulkan) can have multiple Renderer classes, one for each thread. Non-multi-threaded APIs (e.g. OpenGL) should avoid using two Renderer classes at the same time, though it's valid for more than one to exist.

Public Member Functions

const mathfu::mat4 & model_view_projection () const
 Shader uniform: model_view_projection. More...
 
void set_model_view_projection (const mathfu::mat4 &mvp)
 Sets the shader uniform model_view_projection. More...
 
const mathfu::mat4 & model () const
 Shader uniform: model (object to world transform only) More...
 
void set_model (const mathfu::mat4 &model)
 Sets the shader uniform model transform. More...
 
const mathfu::vec4 & color () const
 Shader uniform: color. More...
 
void set_color (const mathfu::vec4 &color)
 Sets the shader uniform color. More...
 
const mathfu::vec3 & light_pos () const
 Shader uniform: light_pos. More...
 
void set_light_pos (const mathfu::vec3 &light_pos)
 Sets the shader uniform light position. More...
 
const mathfu::vec3 & camera_pos () const
 Shader uniform: camera_pos. More...
 
void set_camera_pos (const mathfu::vec3 &camera_pos)
 Sets the shader uniform camera position. More...
 
const mathfu::AffineTransform * bone_transforms () const
 Shader uniform: bone_transforms. More...
 
int num_bones () const
 The number of bones in the bone_transforms() array. More...
 
void SetBoneTransforms (const mathfu::AffineTransform *bone_transforms, int num_bones)
 Sets the shader uniform bone transforms. More...
 
void ClearFrameBuffer (const mathfu::vec4 &color)
 Clears the framebuffer. More...
 
void ClearDepthBuffer ()
 Clears the depthbuffer. Leaves the colorbuffer untouched. More...
 
void BeginRendering ()
 Begin rendering commands. This must be called before any rendering commands are done.
 
void EndRendering ()
 End rendering commands. This is called after all of the rendering commands are done.
 
void SetBlendMode (BlendMode blend_mode, float amount)
 Sets the blend mode used by the renderer. More...
 
void SetBlendMode (BlendMode blend_mode)
 
void SetStencilMode (StencilMode mode, int ref, StencilMask mask)
 Sets the stencil mode. By default, the stencil test is off. More...
 
void SetCulling (CullingMode mode)
 Sets the culling mode. By default, no culling happens. More...
 
void SetViewport (const Viewport &viewport)
 Sets the viewport region. More...
 
void SetDepthFunction (DepthFunction func)
 Set function used for the depth test. More...
 
void ScissorOn (const mathfu::vec2i &ops, const mathfu::vec2i &size)
 Turn on a scissor region. Arguments are in screen pixels. More...
 
void ScissorOff ()
 Turn off the scissor region.
 
bool Initialize (const mathfu::vec2i &window_size, const char *window_title, const WindowMode window_mode=kWindowModeWindowedScaled)
 Initializes the renderer by initializing the Environment object.
 
void AdvanceFrame (bool minimized, double time)
 Swaps frames. Call this once per frame inside your main loop.
 
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.
 
ShaderCompileAndLinkShader (const char *vs_source, const char *ps_source)
 Create a shader object from two strings containing glsl code.
 
ShaderRecompileShader (const char *vs_source, const char *ps_source, Shader *shader)
 Like CompileAndLinkShader, but pass in an old shader to replace.
 
bool AllowMultiThreading ()
 Checks for multithreading API.
 
void SetAnimation (const mathfu::AffineTransform *bone_transforms, int num_bones)
 Set bone transforms in vertex shader uniforms.
 
const std::string & last_error () const
 Contains the last error that occurred, if there is one.
 
void set_last_error (const std::string &last_error)
 
const mathfu::vec2i & window_size () const
 The device's current framebuffer size.
 
mathfu::vec2i & window_size ()
 
void set_window_size (const mathfu::vec2i &ws)
 Sets the window size.
 
mathfu::vec2i GetViewportSize ()
 Get the size of the viewport.
 
Environmentenvironment ()
 
double time () const
 Time in seconds since program start.
 
FeatureLevel feature_level () const
 The supported OpenGL ES feature level.
 
BlendMode force_blend_mode () const
 The blend that will be used for all draw calls.
 
void set_force_blend_mode (BlendMode bm)
 Set to override the blend mode used for all draw calls.
 
void set_override_pixel_shader (const std::string &ps)
 Set this force any shader that gets loaded to use this pixel shader.
 
int max_vertex_uniform_components ()
 Get the max number of uniforms components.
 
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.
 
const RenderStateGetRenderState () const
 Returns the current render state.
 
void UpdateCachedRenderState (const RenderState &render_state)
 Updates the cached render state with the given render state. More...
 
const ShaderGetActiveShader () const
 Returns the active shader, or nullptr if no active shader.
 
ShaderGetActiveShader ()
 Returns the active shader, or nullptr if no active shader.
 
RendererImpl * impl ()
 

Member Function Documentation

const mathfu::AffineTransform* fplbase::Renderer::bone_transforms ( ) const
inline

Shader uniform: bone_transforms.

Returns
Returns the current array of bone transforms being used.
const mathfu::vec3& fplbase::Renderer::camera_pos ( ) const
inline

Shader uniform: camera_pos.

Returns
Returns the current camera position being used.
void fplbase::Renderer::ClearDepthBuffer ( )

Clears the depthbuffer. Leaves the colorbuffer untouched.

Parameters
render_contextPointer to the render context
void fplbase::Renderer::ClearFrameBuffer ( const mathfu::vec4 &  color)

Clears the framebuffer.

Call this after AdvanceFrame if desired.

Parameters
colorThe color to clear the buffer to.
const mathfu::vec4& fplbase::Renderer::color ( ) const
inline

Shader uniform: color.

Returns
Returns the current color being used.
const mathfu::vec3& fplbase::Renderer::light_pos ( ) const
inline

Shader uniform: light_pos.

Returns
Returns the current light position being used.
const mathfu::mat4& fplbase::Renderer::model ( ) const
inline

Shader uniform: model (object to world transform only)

Returns
Returns the current model transform being used.
const mathfu::mat4& fplbase::Renderer::model_view_projection ( ) const
inline

Shader uniform: model_view_projection.

Returns
Returns the current model view projection being used.
int fplbase::Renderer::num_bones ( ) const
inline

The number of bones in the bone_transforms() array.

Returns
Returns the length of the bone_transforms() array.
void fplbase::Renderer::ScissorOn ( const mathfu::vec2i &  ops,
const mathfu::vec2i &  size 
)

Turn on a scissor region. Arguments are in screen pixels.

Parameters
posThe lower left corner of the scissor box.
sizeThe width and height of the scissor box.s
void fplbase::Renderer::set_camera_pos ( const mathfu::vec3 &  camera_pos)
inline

Sets the shader uniform camera position.

Parameters
camera_posThe camera position to be passed to the shader.
void fplbase::Renderer::set_color ( const mathfu::vec4 &  color)
inline

Sets the shader uniform color.

Parameters
colorThe color to be passed to the shader.
void fplbase::Renderer::set_light_pos ( const mathfu::vec3 &  light_pos)
inline

Sets the shader uniform light position.

Parameters
light_posThe light position to be passed to the shader.
void fplbase::Renderer::set_model ( const mathfu::mat4 &  model)
inline

Sets the shader uniform model transform.

Parameters
modelThe model transform to be passed to the shader.
void fplbase::Renderer::set_model_view_projection ( const mathfu::mat4 &  mvp)
inline

Sets the shader uniform model_view_projection.

Parameters
mvpThe model view projection to be passed to the shader.
void fplbase::Renderer::SetBlendMode ( BlendMode  blend_mode,
float  amount 
)

Sets the blend mode used by the renderer.

Set alpha test (cull pixels with alpha below amount) vs alpha blend (blend with framebuffer pixel regardedless).

Parameters
blend_modeThe type of blend mode, see materials.h for valid enum values.
amountThe value used with kBlendModeTest, defaults to 0.5f.
void fplbase::Renderer::SetBlendMode ( BlendMode  blend_mode)

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

void fplbase::Renderer::SetBoneTransforms ( const mathfu::AffineTransform *  bone_transforms,
int  num_bones 
)
inline

Sets the shader uniform bone transforms.

Parameters
bone_transformsThe bone transforms to be passed to the shader.
num_bonesThe length of the bone_transforms array provided.
void fplbase::Renderer::SetCulling ( CullingMode  mode)

Sets the culling mode. By default, no culling happens.

Parameters
modeThe type of culling mode to use.
void fplbase::Renderer::SetDepthFunction ( DepthFunction  func)

Set function used for the depth test.

Parameters
depth_funcThe depth function to use.
void fplbase::Renderer::SetStencilMode ( StencilMode  mode,
int  ref,
StencilMask  mask 
)

Sets the stencil mode. By default, the stencil test is off.

Parameters
modeThe stencil mode to use.
refThe reference value to test against or write.
maskValue that is ANDed with both the ref value and the stored stencil value when the test is done.
void fplbase::Renderer::SetViewport ( const Viewport viewport)

Sets the viewport region.

Parameters
viewportThe viewport region to set.
void fplbase::Renderer::UpdateCachedRenderState ( const RenderState render_state)

Updates the cached render state with the given render state.

This should be used to avoid mismatch between the expected render state and the actual state of the graphics API. The situation tends to happen when using the graphics API directly outside of the renderer. (Note that no operations will be called in here, only the cached state will be updated.)

mathfu::vec2i& fplbase::Renderer::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: