Urho3D
Public Member Functions | Private Member Functions | Private Attributes
Urho3D::Renderer Class Reference

High-level rendering subsystem. Manages drawing of 3D views. More...

#include <Renderer.h>

Inheritance diagram for Urho3D::Renderer:
Urho3D::Object Urho3D::RefCounted

List of all members.

Public Member Functions

 Renderer (Context *context)
 Construct.
virtual ~Renderer ()
 Destruct.
void SetNumViewports (unsigned num)
 Set number of viewports to render.
bool SetViewport (unsigned index, Viewport *viewport)
 Set a viewport. Return true if successful.
void SetDefaultRenderPath (RenderPath *renderPath)
 Set default renderpath.
void SetDefaultRenderPath (XMLFile *file)
 Set default renderpath from an XML file.
void SetSpecularLighting (bool enable)
 Set specular lighting on/off.
void SetTextureAnisotropy (int level)
 Set texture anisotropy.
void SetTextureFilterMode (TextureFilterMode mode)
 Set texture filtering.
void SetTextureQuality (int quality)
 Set texture quality level.
void SetMaterialQuality (int quality)
 Set material quality level.
void SetDrawShadows (bool enable)
 Set shadows on/off.
void SetShadowMapSize (int size)
 Set shadow map resolution.
void SetShadowQuality (int quality)
 Set shadow quality (amount of samples and bit depth.)
void SetReuseShadowMaps (bool enable)
 Set reuse of shadow maps. Default is true. If disabled, also transparent geometry can be shadowed.
void SetMaxShadowMaps (int shadowMaps)
 Set maximum number of shadow maps created for one resolution. Only has effect if reuse of shadow maps is disabled.
void SetMaxShadowCascades (int cascades)
 Set maximum number of directional light shadow map cascades. Affects the size of directional light shadow maps.
void SetDynamicInstancing (bool enable)
 Set dynamic instancing on/off.
void SetMaxInstanceTriangles (int triangles)
 Set maximum number of triangles per object for instancing.
void SetMaxSortedInstances (int instances)
 Set maximum number of sorted instances per batch group. If exceeded, instances are rendered unsorted.
void SetMaxOccluderTriangles (int triangles)
 Set maximum number of occluder trianges.
void SetOcclusionBufferSize (int size)
 Set occluder buffer width.
void SetOccluderSizeThreshold (float screenSize)
 Set required screen size (1.0 = full screen) for occluders.
void ReloadShaders ()
 Force reload of shaders.
unsigned GetNumViewports () const
 Return number of viewports.
ViewportGetViewport (unsigned index) const
 Return viewport.
RenderPathGetDefaultRenderPath () const
 Return default renderpath.
bool GetSpecularLighting () const
 Return whether specular lighting is enabled.
bool GetDrawShadows () const
 Return whether drawing shadows is enabled.
int GetTextureAnisotropy () const
 Return texture anisotropy.
TextureFilterMode GetTextureFilterMode () const
 Return texture filtering.
int GetTextureQuality () const
 Return texture quality level.
int GetMaterialQuality () const
 Return material quality level.
int GetShadowMapSize () const
 Return shadow map resolution.
int GetShadowQuality () const
 Return shadow quality.
bool GetReuseShadowMaps () const
 Return whether shadow maps are reused.
int GetMaxShadowMaps () const
 Return maximum number of shadow maps per resolution.
int GetMaxShadowCascades () const
 Return maximum number of directional light shadow map cascades.
bool GetDynamicInstancing () const
 Return whether dynamic instancing is in use.
int GetMaxInstanceTriangles () const
 Return maximum number of triangles per object for instancing.
int GetMaxSortedInstances () const
 Return maximum number of sorted instances per batch group.
int GetMaxOccluderTriangles () const
 Return maximum number of occluder triangles.
int GetOcclusionBufferSize () const
 Return occlusion buffer width.
float GetOccluderSizeThreshold () const
 Return occluder screen size threshold.
unsigned GetNumViews () const
 Return number of views rendered.
unsigned GetNumPrimitives () const
 Return number of primitives rendered.
unsigned GetNumBatches () const
 Return number of batches rendered.
unsigned GetNumGeometries (bool allViews=false) const
 Return number of geometries rendered.
unsigned GetNumLights (bool allViews=false) const
 Return number of lights rendered.
unsigned GetNumShadowMaps (bool allViews=false) const
 Return number of shadow maps rendered.
unsigned GetNumOccluders (bool allViews=false) const
 Return number of occluders rendered.
ZoneGetDefaultZone () const
 Return the default zone.
LightGetQuadDirLight () const
 Return the directional light for fullscreen quad rendering.
MaterialGetDefaultMaterial () const
 Return the default material.
Texture2DGetDefaultLightRamp () const
 Return the default range attenuation texture.
Texture2DGetDefaultLightSpot () const
 Return the default spotlight attenuation texture.
TextureCubeGetFaceSelectCubeMap () const
 Return the shadowed pointlight face selection cube map.
TextureCubeGetIndirectionCubeMap () const
 Return the shadowed pointlight indirection cube map.
VertexBufferGetInstancingBuffer () const
 Return the instancing vertex buffer.
ShaderVariationGetVertexShader (const String &name, bool checkExists=false) const
 Return a vertex shader by name.
ShaderVariationGetPixelShader (const String &name, bool checkExists=false) const
 Return a pixel shader by name.
ShaderVariationGetStencilVS () const
 Return the stencil vertex shader.
ShaderVariationGetStencilPS () const
 Return the stencil pixel shader.
const FrameInfoGetFrameInfo ()
 Return the frame update parameters.
void Update (float timeStep)
 Update for rendering. Called by HandleRenderUpdate().
void Render ()
 Render. Called by Engine.
void DrawDebugGeometry (bool depthTest)
 Add debug geometry to the debug renderer.
bool AddView (RenderSurface *renderTarget, Viewport *viewport)
 Add a view. Return true if successful.
void GetLightVolumeShaders (PODVector< ShaderVariation * > &lightVS, PODVector< ShaderVariation * > &lightPS, const String &vsName, const String &psName)
 Populate light volume shaders.
GeometryGetLightGeometry (Light *light)
 Return volume geometry for a light.
Texture2DGetShadowMap (Light *light, Camera *camera, unsigned viewWidth, unsigned viewHeight)
 Allocate a shadow map. If shadow map reuse is disabled, a different map is returned each time.
Texture2DGetScreenBuffer (int width, int height, unsigned format, bool filtered=false)
 Allocate a rendertarget or depth-stencil texture for deferred rendering or postprocessing. Should only be called during actual rendering, not before.
RenderSurfaceGetDepthStencil (int width, int height)
 Allocate a depth-stencil surface that does not need to be readable. Should only be called during actual rendering, not before.
OcclusionBufferGetOcclusionBuffer (Camera *camera)
 Allocate an occlusion buffer.
CameraGetShadowCamera ()
 Allocate a temporary shadow camera and a scene node for it. Is thread-safe.
ShaderVariationGetShader (ShaderType type, const String &name, bool checkExists) const
 Get a shader program.
void SetBatchShaders (Batch &batch, Technique *tech, bool allowShadows=true)
 Choose shaders for a forward rendering batch.
void SetLightVolumeBatchShaders (Batch &batch, PODVector< ShaderVariation * > &lightVS, PODVector< ShaderVariation * > &lightPS)
 Choose shaders for a light volume batch.
void SetCullMode (CullMode mode, Camera *camera)
 Set cull mode while taking possible projection flipping into account.
bool ResizeInstancingBuffer (unsigned numInstances)
 Ensure sufficient size of the instancing vertex buffer. Return true if successful.
void SaveScreenBufferAllocations ()
 Save the screen buffer allocation status. Called by View.
void RestoreScreenBufferAllocations ()
 Restore the screen buffer allocation status. Called by View.
void OptimizeLightByScissor (Light *light, Camera *camera)
 Optimize a light by scissor rectangle.
void OptimizeLightByStencil (Light *light, Camera *camera)
 Optimize a light by marking it to the stencil buffer and setting a stencil test.
const RectGetLightScissor (Light *light, Camera *camera)
 Return a scissor rectangle for a light.
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
virtual ShortStringHash GetType () const =0
 Return type hash.
virtual const StringGetTypeName () const =0
 Return type name.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
ContextGetContext () const
 Return execution context.
ObjectGetSubsystem (ShortStringHash type) const
 Return subsystem by type.
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
int Refs () const
 Return reference count.
int WeakRefs () const
 Return weak reference count.
RefCountRefCountPtr ()
 Return pointer to the reference count structure.

Private Member Functions

 OBJECT (Object)
void Initialize ()
 Initialize when screen mode initially set.
void ResetViews ()
 Clear views from previous frame.
void LoadShaders ()
 Reload shaders.
void LoadPassShaders (Technique *tech, StringHash passType)
 Reload shaders for a material pass.
void ReleaseMaterialShaders ()
 Release shaders used in materials.
void ReloadTextures ()
 Reload textures.
void CreateGeometries ()
 Create light volume geometries.
void CreateInstancingBuffer ()
 Create instancing vertex buffer.
void SetIndirectionTextureData ()
 Create point light shadow indirection texture data.
void PrepareViewRender ()
 Prepare for rendering of a new view.
void RemoveUnusedBuffers ()
 Remove unused occlusion and screen buffers.
void ResetShadowMapAllocations ()
 Reset shadow map allocation counts.
void ResetScreenBufferAllocations ()
 Reset screem buffer allocation counts.
void ResetShadowMaps ()
 Remove all shadow maps. Called when global shadow map resolution or format is changed.
void ResetBuffers ()
 Remove all occlusion and screen buffers.
void HandleScreenMode (StringHash eventType, VariantMap &eventData)
 Handle screen mode event.
void HandleGraphicsFeatures (StringHash eventType, VariantMap &eventData)
 Handle graphics features (re)check event. Event only sent by D3D9Graphics class.
void HandleRenderUpdate (StringHash eventType, VariantMap &eventData)
 Handle render update event.

Private Attributes

WeakPtr< Graphicsgraphics_
 Graphics subsystem.
WeakPtr< ResourceCachecache_
 Resource cache subsystem.
SharedPtr< RenderPathdefaultRenderPath_
 Default renderpath.
SharedPtr< ZonedefaultZone_
 Default zone.
SharedPtr< LightquadDirLight_
 Directional light for drawing fullscreen quads.
SharedPtr< GeometrydirLightGeometry_
 Directional light quad geometry.
SharedPtr< GeometryspotLightGeometry_
 Spot light volume geometry.
SharedPtr< GeometrypointLightGeometry_
 Point light volume geometry.
SharedPtr< VertexBufferinstancingBuffer_
 Instance stream vertex buffer.
SharedPtr< MaterialdefaultMaterial_
 Default material.
SharedPtr< Texture2DdefaultLightRamp_
 Default range attenuation texture.
SharedPtr< Texture2DdefaultLightSpot_
 Default spotlight attenuation texture.
SharedPtr< TextureCubefaceSelectCubeMap_
 Face selection cube map for shadowed pointlights.
SharedPtr< TextureCubeindirectionCubeMap_
 Indirection cube map for shadowed pointlights.
SharedPtr< ShaderVariationstencilVS_
 Stencil rendering vertex shader.
SharedPtr< ShaderVariationstencilPS_
 Stencil rendering pixel shader.
Vector< SharedPtr< Node > > shadowCameraNodes_
 Reusable scene nodes with shadow camera components.
Vector< SharedPtr
< OcclusionBuffer > > 
occlusionBuffers_
 Reusable occlusion buffers.
HashMap< int, Vector
< SharedPtr< Texture2D > > > 
shadowMaps_
 Shadow maps by resolution.
HashMap< int, SharedPtr
< Texture2D > > 
colorShadowMaps_
 Shadow map dummy color buffers by resolution.
HashMap< int, PODVector< Light * > > shadowMapAllocations_
 Shadow map allocations by resolution.
HashMap< long long, Vector
< SharedPtr< Texture2D > > > 
screenBuffers_
 Screen buffers by resolution and format.
HashMap< long long, unsigned > screenBufferAllocations_
 Current screen buffer allocations by resolution and format.
HashMap< long long, unsigned > savedScreenBufferAllocations_
 Saved status of screen buffer allocations for restoring.
HashMap< Pair< Light *, Camera * >
, Rect
lightScissorCache_
 Cache for light scissor queries.
Vector< SharedPtr< Viewport > > viewports_
 Viewports.
Vector< SharedPtr< View > > views_
 Views.
HashSet< Octree * > updatedOctrees_
 Octrees that have been updated during the frame.
HashSet< Technique * > shaderErrorDisplayed_
 Techniques for which missing shader error has been displayed.
Mutex rendererMutex_
 Mutex for shadow camera allocation.
String shaderPath_
 Base directory for shaders.
FrameInfo frame_
 Frame info for rendering.
int textureAnisotropy_
 Texture anisotropy level.
TextureFilterMode textureFilterMode_
 Texture filtering mode.
int textureQuality_
 Texture quality level.
int materialQuality_
 Material quality level.
int shadowMapSize_
 Shadow map resolution.
int shadowQuality_
 Shadow quality.
int maxShadowMaps_
 Maximum number of shadow maps per resolution.
int maxShadowCascades_
 Maximum number of directional light shadow cascades.
int maxInstanceTriangles_
 Maximum triangles per object for instancing.
int maxSortedInstances_
 Maximum sorted instances per batch group.
int maxOccluderTriangles_
 Maximum occluder triangles.
int occlusionBufferSize_
 Occlusion buffer width.
float occluderSizeThreshold_
 Occluder screen size threshold.
unsigned numViews_
 Number of views.
unsigned numOcclusionBuffers_
 Number of occlusion buffers in use.
unsigned numShadowCameras_
 Number of temporary shadow cameras in use.
unsigned numPrimitives_
 Number of primitives (3D geometry only.)
unsigned numBatches_
 Number of batches (3D geometry only.)
unsigned shadersChangedFrameNumber_
 Frame number on which shaders last changed.
unsigned char lightStencilValue_
 Current stencil value for light optimization.
bool specularLighting_
 Specular lighting flag.
bool drawShadows_
 Draw shadows flag.
bool reuseShadowMaps_
 Shadow map reuse flag.
bool dynamicInstancing_
 Dynamic instancing flag.
bool shadersDirty_
 Shaders need reloading flag.
bool initialized_
 Initialized flag.

Additional Inherited Members

- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.

Detailed Description

High-level rendering subsystem. Manages drawing of 3D views.


Member Function Documentation

void Urho3D::Renderer::DrawDebugGeometry ( bool  depthTest)

Add debug geometry to the debug renderer.

Todo:
Because debug geometry is per-scene, if two cameras show views of the same area, occlusion is not shown correctly
Texture2D * Urho3D::Renderer::GetShadowMap ( Light light,
Camera camera,
unsigned  viewWidth,
unsigned  viewHeight 
)

Allocate a shadow map. If shadow map reuse is disabled, a different map is returned each time.

Todo:
Allow to specify maximum shadow maps per resolution, as smaller shadow maps take less memory
void Urho3D::Renderer::Update ( float  timeStep)

Update for rendering. Called by HandleRenderUpdate().

Todo:
May result in incorrect debug geometry culling if the same scene is drawn from multiple viewports

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