15 #ifndef FPLBASE_RENDERER_H
16 #define FPLBASE_RENDERER_H
18 #include "fplbase/config.h"
20 #include "fplbase/environment.h"
23 #include "fplbase/render_state.h"
26 #include "fplbase/version.h"
27 #include "fplutil/mutex.h"
28 #include "mathfu/glsl_mappings.h"
32 struct RendererBaseImpl;
91 WindowMode window_mode = kWindowModeWindowedScaled);
111 environment_.SetWindowSize(window_size);
147 void SetAnimation(
const mathfu::AffineTransform *bone_transforms,
156 const std::string &
last_error()
const {
return last_error_; }
157 void set_last_error(
const std::string &
last_error) {
168 return environment_.window_size();
171 mathfu::vec2i &
window_size() {
return environment_.window_size(); }
178 environment_.SetWindowSize(ws);
189 Environment &environment() {
return environment_; }
196 double time()
const {
return time_; }
217 override_pixel_shader_ = ps;
242 RendererBaseImpl* impl() {
return impl_; }
245 static RendererBase *Get() {
246 assert(!the_base_weak_.expired());
247 return the_base_raw_;
251 friend class Renderer;
253 ShaderHandle CompileShader(
bool is_vertex_shader, ShaderHandle program,
255 Shader *CompileAndLinkShaderHelper(
const char *vs_source,
256 const char *ps_source, Shader *shader);
260 static RendererBaseImpl *CreateRendererBaseImpl();
261 static void DestroyRendererBaseImpl(RendererBaseImpl *impl);
264 RendererBaseImpl* impl_;
268 bool InitializeRenderingState();
272 std::string last_error_;
274 Environment environment_;
276 int64_t supports_texture_format_;
278 bool supports_texture_npot_;
280 Shader *force_shader_;
282 std::string override_pixel_shader_;
284 int max_vertex_uniform_components_;
287 const FplBaseVersion *version_;
293 static std::weak_ptr<RendererBase> the_base_weak_;
297 static RendererBase* the_base_raw_;
300 static fplutil::Mutex the_base_mutex_;
318 return model_view_projection_;
323 model_view_projection_ = mvp;
328 const mathfu::mat4 &
model()
const {
return model_; }
335 const mathfu::vec4 &
color()
const {
return color_; }
342 const mathfu::vec3 &
light_pos()
const {
return light_pos_; }
349 const mathfu::vec3 &
camera_pos()
const {
return camera_pos_; }
359 return bone_transforms_;
431 void ScissorOn(
const mathfu::vec2i &ops,
const mathfu::vec2i &size);
438 bool Initialize(
const mathfu::vec2i &window_size,
const char *window_title,
439 const WindowMode window_mode = kWindowModeWindowedScaled) {
440 return base_->Initialize(window_size, window_title, window_mode);
451 base_->SetWindowSize(window_size);
456 return base_->CompileAndLinkShader(vs_source, ps_source);
462 return base_->RecompileShader(vs_source, ps_source, shader);
467 return (base_->AllowMultiThreading());
473 base_->SetAnimation(bone_transforms, num_bones);
478 return base_->last_error();
480 void set_last_error(
const std::string &
last_error) {
481 base_->set_last_error(last_error);
486 return base_->window_size();
493 base_->set_window_size(ws);
499 return base_->GetViewportSize();
502 Environment &environment() {
return base_->environment(); }
505 double time()
const {
return base_->time(); }
509 return base_->feature_level();
514 return base_->force_blend_mode();
518 base_->set_force_blend_mode(bm);
523 base_->set_override_pixel_shader(ps);
528 return base_->max_vertex_uniform_components();
533 return base_->GetFplBaseVersion();
538 return base_->SupportsTextureFormat(texture_format);
543 return base_->SupportsTextureNpot();
565 RendererImpl* impl() {
return impl_; }
567 MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
572 static RendererImpl *CreateRendererImpl();
573 static void DestroyRendererImpl(RendererImpl *impl);
580 std::shared_ptr<fplbase::RendererBase> base_;
584 mathfu::mat4 model_view_projection_;
587 mathfu::vec3 light_pos_;
588 mathfu::vec3 camera_pos_;
589 const mathfu::AffineTransform *bone_transforms_;
593 RenderState render_state_;
601 uint32_t stencil_mask_;
608 #endif // FPLBASE_RENDERER_H
Shader * GetActiveShader()
Returns the active shader, or nullptr if no active shader.
Definition: renderer.h:562
void SetCulling(CullingMode mode)
Sets the culling mode. By default, no culling happens.
const mathfu::vec2i & window_size() const
The device's current framebuffer size.
Definition: renderer.h:167
const std::string & last_error() const
Contains the last error that occurred, if there is one.
Definition: renderer.h:477
bool SupportsTextureFormat(TextureFormat texture_format) const
Returns if a texture format is supported by the hardware.
Definition: renderer.h:537
const mathfu::vec4 & color() const
Shader uniform: color.
Definition: renderer.h:335
void ScissorOff()
Turn off the scissor region.
int max_vertex_uniform_components()
Get the max number of uniforms components.
Definition: renderer.h:527
Shader * RecompileShader(const char *vs_source, const char *ps_source, Shader *shader)
Like CompileAndLinkShader, but pass in an old shader to replace.
Definition: renderer.h:460
double time() const
Time in seconds since program start.
Definition: renderer.h:505
BlendMode
Specifies the blending mode used by the blend function.
Definition: render_state.h:40
CullingMode
Specifies the which face is culled when rendering.
Definition: render_state.h:80
const mathfu::vec2i & window_size() const
The device's current framebuffer size.
Definition: renderer.h:485
Definition: detailed_render_state.h:142
bool AllowMultiThreading()
Checks for multithreading API.
Definition: renderer.h:466
StencilMode
Specifies stencil modes for the stencil test.
Definition: render_state.h:27
void set_override_pixel_shader(const std::string &ps)
Set this force any shader that gets loaded to use this pixel shader.
Definition: renderer.h:522
Shader * RecompileShader(const char *vs_source, const char *ps_source, Shader *shader)
Like CompileAndLinkShader, but pass in an old shader to replace.
const mathfu::vec3 & light_pos() const
Shader uniform: light_pos.
Definition: renderer.h:342
Represents a shader consisting of a vertex and pixel shader.
Definition: shader.h:42
void set_light_pos(const mathfu::vec3 &light_pos)
Sets the shader uniform light position.
Definition: renderer.h:345
void set_force_blend_mode(BlendMode bm)
Set to override the blend mode used for all draw calls.
Definition: renderer.h:517
void SetBoneTransforms(const mathfu::AffineTransform *bone_transforms, int num_bones)
Sets the shader uniform bone transforms.
Definition: renderer.h:367
uint32_t StencilMask
Specifies the type for the Stencil Mask.
Definition: render_state.h:24
bool SupportsTextureNpot() const
Returns if a NPOT textures are supported by the hardware. see: https://www.opengl.org/wiki/NPOT_Texture.
const FplBaseVersion * GetFplBaseVersion() const
Returns the version of the FPL Base Library.
Definition: renderer.h:232
mathfu::vec2i & window_size()
Definition: renderer.h:489
Manages the rendering system, handling the window and resources.
Definition: renderer.h:66
void set_color(const mathfu::vec4 &color)
Sets the shader uniform color.
Definition: renderer.h:338
void BeginRendering()
Begin rendering commands. This must be called before any rendering commands are done.
DepthFunction
Specifies the depth function used for rendering.
Definition: render_state.h:64
const mathfu::vec3 & camera_pos() const
Shader uniform: camera_pos.
Definition: renderer.h:349
void SetDepthFunction(DepthFunction func)
Set function used for the depth test.
FeatureLevel feature_level() const
The supported OpenGL ES feature level.
Definition: renderer.h:508
void set_window_size(const mathfu::vec2i &ws)
Sets the window size.
Definition: renderer.h:177
bool Initialize(const mathfu::vec2i &window_size, const char *window_title, const WindowMode window_mode=kWindowModeWindowedScaled)
Initializes the renderer by initializing the Environment object.
Definition: renderer.h:438
void EndRendering()
End rendering commands. This is called after all of the rendering commands are done.
void SetWindowSize(const mathfu::vec2i &window_size)
Sets the window size, for when window is not owned by the renderer.
Definition: renderer.h:110
TextureFormat
Definition: texture.h:36
Definition: environment.h:56
Shader * CompileAndLinkShader(const char *vs_source, const char *ps_source)
Create a shader object from two strings containing glsl code.
Definition: renderer.h:455
void SetWindowSize(const mathfu::vec2i &window_size)
Sets the window size, for when window is not owned by the renderer.
Definition: renderer.h:450
void set_model_view_projection(const mathfu::mat4 &mvp)
Sets the shader uniform model_view_projection.
Definition: renderer.h:322
mathfu::vec2i GetViewportSize()
Get the size of the viewport.
Definition: renderer.h:498
BlendMode force_blend_mode() const
The blend that will be used for all draw calls.
Definition: renderer.h:513
void UpdateCachedRenderState(const RenderState &render_state)
Updates the cached render state with the given render state.
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.
int max_vertex_uniform_components()
Get the max number of uniforms components (i.e. individual floats, so a mat4 needs 16 of them)...
Definition: renderer.h:229
const FplBaseVersion * GetFplBaseVersion() const
Returns the version of the FPL Base Library.
Definition: renderer.h:532
mathfu::vec2i GetViewportSize()
Get the size of the viewport.
Definition: renderer.h:187
const mathfu::mat4 & model() const
Shader uniform: model (object to world transform only)
Definition: renderer.h:328
mathfu::vec2i & window_size()
Definition: renderer.h:171
double time() const
Time in seconds since program start.
Definition: renderer.h:196
const RenderState & GetRenderState() const
Returns the current render state.
Definition: renderer.h:547
void set_model(const mathfu::mat4 &model)
Sets the shader uniform model transform.
Definition: renderer.h:331
void set_window_size(const mathfu::vec2i &ws)
Sets the window size.
Definition: renderer.h:492
void AdvanceFrame(bool minimized, double time)
Swaps frames. Call this once per frame inside your main loop.
void ScissorOn(const mathfu::vec2i &ops, const mathfu::vec2i &size)
Turn on a scissor region. Arguments are in screen pixels.
void ClearDepthBuffer()
Clears the depthbuffer. Leaves the colorbuffer untouched.
FeatureLevel feature_level() const
The supported OpenGL ES feature level.
Definition: renderer.h:200
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)...
Definition: renderer.h:216
const mathfu::mat4 & model_view_projection() const
Shader uniform: model_view_projection.
Definition: renderer.h:317
bool SupportsTextureNpot() const
Returns if a NPOT textures are supported by the hardware.
Definition: renderer.h:542
void SetBlendMode(BlendMode blend_mode, float amount)
Sets the blend mode used by the renderer.
void set_camera_pos(const mathfu::vec3 &camera_pos)
Sets the shader uniform camera position.
Definition: renderer.h:352
const Shader * GetActiveShader() const
Returns the active shader, or nullptr if no active shader.
Definition: renderer.h:559
mathfu::recti Viewport
Specifies the region of the surface to be used for rendering.
Definition: renderer_common.h:23
void set_force_blend_mode(BlendMode bm)
Set to override the blend mode used for all draw calls.
Definition: renderer.h:211
bool SupportsTextureFormat(TextureFormat texture_format) const
Returns if a texture format is supported by the hardware.
void ClearFrameBuffer(const mathfu::vec4 &color)
Clears the framebuffer.
void SetAnimation(const mathfu::AffineTransform *bone_transforms, int num_bones)
Set bone transforms in vertex shader uniforms.
Definition: renderer.h:471
void SetStencilMode(StencilMode mode, int ref, StencilMask mask)
Sets the stencil mode. By default, the stencil test is off.
bool Initialize(const mathfu::vec2i &window_size, const char *window_title, WindowMode window_mode=kWindowModeWindowedScaled)
Initializes the renderer by initializing the Environment object.
const std::string & last_error() const
Contains the last error that occurred, if there is one.
Definition: renderer.h:156
void ShutDown()
Cleans up the resources initialized by the renderer.
Definition: renderer.h:103
int num_bones() const
The number of bones in the bone_transforms() array.
Definition: renderer.h:363
void AdvanceFrame(bool minimized, double time)
Swaps frames. Call this once per frame inside your main loop.
Renderer is the main API class for rendering commands.
Definition: renderer.h:310
BlendMode force_blend_mode() const
The blend that will be used for all draw calls.
Definition: renderer.h:204
Shader * CompileAndLinkShader(const char *vs_source, const char *ps_source)
Create a shader object from two strings containing glsl code.
void ShutDown()
Cleans up the resources initialized by the renderer.
Definition: renderer.h:447
void SetViewport(const Viewport &viewport)
Sets the viewport region.
const mathfu::AffineTransform * bone_transforms() const
Shader uniform: bone_transforms.
Definition: renderer.h:358