sceneManager.h

Engine/source/scene/sceneManager.h

More...

Classes:

class

An object that manages the SceneObjects belonging to a scene.

Public Enumerations

enum
ScenePassType {
  SPT_Diffuse 
  SPT_Reflect 
  SPT_Shadow 
  SPT_Other 
}

The type of scene pass.

enum
SceneRenderStyle {
  SRS_Standard 
  SRS_SideBySide 
}

The type of scene render style.

Public Variables

The client-side scene graph.

The server-side scene graph.

Detailed Description

Public Enumerations

ScenePassType

Enumerator

SPT_Diffuse

The regular diffuse scene pass.

SPT_Reflect

The scene pass made for reflection rendering.

SPT_Shadow

The scene pass made for shadow map rendering.

SPT_Other

A scene pass that isn't one of the other predefined scene pass types.

The type of scene pass.

SceneRenderStyle

Enumerator

SRS_Standard

The regular style of rendering.

SRS_SideBySide

Side-by-side style rendering.

The type of scene render style.

Public Variables

SceneManager * gClientSceneGraph 

The client-side scene graph.

Not used if the engine is running as a dedicated server.

SceneManager * gServerSceneGraph 

The server-side scene graph.

Not used if the engine is running as a pure client.

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SCENEMANAGER_H_
 25#define _SCENEMANAGER_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30
 31#ifndef _SCENEZONESPACEMANAGER_H_
 32#include "scene/zones/sceneZoneSpaceManager.h"
 33#endif
 34
 35#ifndef _MRECT_H_
 36#include "math/mRect.h"
 37#endif
 38
 39#ifndef _COLOR_H_
 40#include "core/color.h"
 41#endif
 42
 43#ifndef _INTERPOLATEDCHANGEPROPERTY_H_
 44#include "util/interpolatedChangeProperty.h"
 45#endif
 46
 47#ifndef _GFXTEXTUREHANDLE_H_
 48#include "gfx/gfxTextureHandle.h"
 49#endif
 50
 51#ifndef _FOGSTRUCTS_H_
 52#include "scene/fogStructs.h"
 53#endif
 54
 55#ifndef _TVECTOR_H_
 56#include "core/util/tVector.h"
 57#endif
 58
 59#ifndef _TSIGNAL_H_
 60#include "core/util/tSignal.h"
 61#endif
 62
 63
 64class LightManager;
 65class SceneRootZone;
 66class SceneRenderState;
 67class SceneCameraState;
 68class SceneZoneSpace;
 69class NetConnection;
 70class RenderPassManager;
 71
 72
 73/// The type of scene pass.
 74/// @see SceneManager
 75/// @see SceneRenderState
 76enum ScenePassType
 77{
 78   /// The regular diffuse scene pass.
 79   SPT_Diffuse,
 80
 81   /// The scene pass made for reflection rendering.
 82   SPT_Reflect,
 83
 84   /// The scene pass made for shadow map rendering.
 85   SPT_Shadow,
 86
 87   /// A scene pass that isn't one of the other 
 88   /// predefined scene pass types.
 89   SPT_Other,
 90};
 91
 92
 93/// The type of scene render style
 94/// @see SceneRenderState
 95enum SceneRenderStyle
 96{
 97   /// The regular style of rendering
 98   SRS_Standard,
 99
100   /// Side-by-side style rendering
101   SRS_SideBySide,
102};
103
104
105/// An object that manages the SceneObjects belonging to a scene.
106class SceneManager
107{
108   public:
109
110      /// A signal used to notify of render passes.
111      typedef Signal< void( SceneManager*, const SceneRenderState* ) > RenderSignal;
112
113      /// If true use the last stored locked frustum for culling
114      /// the diffuse render pass.
115      /// @see smLockedDiffuseFrustum
116      static bool smLockDiffuseFrustum;
117
118      /// If true, render the AABBs of objects for debugging.
119      static bool smRenderBoundingBoxes;
120
121      //A cache list of objects that made it through culling, so we don't have to attempt to re-test
122      //visibility of objects later.
123      Vector< SceneObject*> mRenderedObjectsList;
124
125   protected:
126
127      /// Whether this is the client-side scene.
128      bool mIsClient;
129
130      /// Manager for the zones in this scene.
131      SceneZoneSpaceManager* mZoneManager;
132
133      // NonClipProjection is the projection matrix without oblique frustum clipping
134      // applied to it (in reflections)
135      MatrixF mNonClipProj;
136
137      ///
138      bool mUsePostEffectFog;
139
140      /// @see setDisplayTargetResolution
141      Point2I mDisplayTargetResolution;
142
143      /// The currently active render state or NULL if we're
144      /// not in the process of rendering.
145      SceneRenderState* mCurrentRenderState;
146
147      F32 mVisibleDistance;
148
149      F32 mVisibleGhostDistance;
150      F32 mNearClip;
151
152      FogData mFogData;
153
154      WaterFogData mWaterFogData;
155
156      /// The stored last diffuse pass frustum for locking the cull.
157      static SceneCameraState smLockedDiffuseCamera;
158
159      /// @name Lighting
160      /// @{
161
162      typedef InterpolatedChangeProperty< LinearColorF> AmbientLightInterpolator;
163
164      /// Light manager that is active for the scene.
165      LightManager* mLightManager;
166
167      /// Global ambient light level in the scene.
168      AmbientLightInterpolator mAmbientLightColor;
169
170      /// Deactivates the previous light manager and activates the new one.
171      bool _setLightManager( LightManager *lm );
172
173      /// @}
174
175      /// @name Rendering
176      /// @{
177
178      /// RenderPassManager for the default render pass.  This is set up
179      /// in script and looked up by getDefaultRenderPass().
180      mutable RenderPassManager* mDefaultRenderPass;
181
182      ///
183      Vector< SceneObject*> mBatchQueryList;
184
185      /// Render scene using the given state.
186      ///
187      /// @param state SceneManager render state.
188      /// @param objectMask Object type mask with which to filter scene objects.
189      /// @param baseObject Zone manager to start traversal in.  If null, the zone manager
190      ///   that contains @a state's camera position will be used.
191      /// @param baseZone Zone in @a zone manager in which to start traversal.  Ignored if
192      ///   @a baseObject is NULL.
193      void _renderScene(   SceneRenderState* state,
194                           U32 objectMask = ( U32 ) -1,
195                           SceneZoneSpace* baseObject = NULL,
196                           U32 baseZone = 0 );
197
198      /// Callback for the container query.
199      static void _batchObjectCallback( SceneObject* object, void* key );
200
201      /// @}
202
203   public:
204
205      SceneManager( bool isClient );
206      ~SceneManager();
207
208      /// Return the SceneContainer for this scene.
209      SceneContainer* getContainer() const { return mIsClient ? &gClientContainer : &gServerContainer; }
210
211      /// Return the manager for the zones in this scene.
212      /// @note Only client scenes have a zone manager as for the server, no zoning data is kept.
213      const SceneZoneSpaceManager* getZoneManager() const { return mZoneManager; }
214      SceneZoneSpaceManager* getZoneManager() { return mZoneManager; }
215
216      /// @name SceneObject Management
217      /// @{
218
219      /// Add the given object to the scene.
220      bool addObjectToScene( SceneObject* object );
221
222      /// Remove the given object from the scene.
223      void removeObjectFromScene( SceneObject* object );
224
225      /// Let the scene manager know that the given object has changed its transform or
226      /// sizing state.
227      void notifyObjectDirty( SceneObject* object );
228
229      /// @}
230
231      /// @name Rendering
232      /// @{
233
234      /// Return the default RenderPassManager for the scene.
235      RenderPassManager* getDefaultRenderPass() const;
236
237      /// Set the default render pass for the scene.
238      void setDefaultRenderPass( RenderPassManager* rpm ) { mDefaultRenderPass = rpm; }
239      
240      /// Render the scene with the default render pass.
241      /// @note This uses the current GFX state (transforms, viewport, frustum) to initialize
242      ///   the render state.
243      void renderScene( ScenePassType passType, U32 objectMask = DEFAULT_RENDER_TYPEMASK );
244
245      /// Render the scene with a custom rendering pass.
246      void renderScene( SceneRenderState *state, U32 objectMask = DEFAULT_RENDER_TYPEMASK, SceneZoneSpace* baseObject = NULL, U32 baseZone = 0 );
247
248      /// Render the scene with a custom rendering pass and no lighting set up.
249      void renderSceneNoLights( SceneRenderState *state, U32 objectMask = DEFAULT_RENDER_TYPEMASK, SceneZoneSpace* baseObject = NULL, U32 baseZone = 0 );
250
251      /// Returns the currently active scene state or NULL if no state is currently active.
252      SceneRenderState* getCurrentRenderState() const { return mCurrentRenderState; }
253
254      static RenderSignal& getPreRenderSignal() 
255      { 
256         static RenderSignal theSignal;
257         return theSignal;
258      }
259
260      static RenderSignal& getPostRenderSignal() 
261      { 
262         static RenderSignal theSignal;
263         return theSignal;
264      }
265
266      /// @}
267
268      /// @name Lighting
269      /// @{
270
271      /// Finds the light manager by name and activates it.
272      bool setLightManager( const char *lmName );
273
274      /// Return the current global ambient light color.
275      const LinearColorF& getAmbientLightColor() const { return mAmbientLightColor.getCurrentValue(); }
276
277      /// Set the time it takes for a new ambient light color to take full effect.
278      void setAmbientLightTransitionTime( SimTime time ) { mAmbientLightColor.setTransitionTime( time ); }
279
280      /// Set the interpolation curve to use for blending from one global ambient light
281      /// color to a different one.
282      void setAmbientLightTransitionCurve( const EaseF& ease ) { mAmbientLightColor.setTransitionCurve( ease ); }
283
284      /// @}
285
286      /// @name Networking
287      /// @{
288
289      /// Set the scoping states of the objects in the scene.
290      void scopeScene( CameraScopeQuery* query, NetConnection* netConnection );
291
292      /// @}
293
294      /// @name Fog/Visibility Management
295      /// @{
296
297      void setPostEffectFog( bool enable ) { mUsePostEffectFog = enable; }   
298      bool usePostEffectFog() const { return mUsePostEffectFog; }
299
300      /// Accessor for the FogData structure.
301      const FogData& getFogData() { return mFogData; }
302
303      /// Sets the FogData structure.
304      void setFogData( const FogData &data ) { mFogData = data; }
305
306      /// Accessor for the WaterFogData structure.
307      const WaterFogData& getWaterFogData() { return mWaterFogData; }
308
309      /// Sets the WaterFogData structure.
310      void setWaterFogData( const WaterFogData &data ) { mWaterFogData = data; }
311
312      /// Used by LevelInfo to set the default visible distance for
313      /// rendering the scene.
314      ///
315      /// Note this should not be used to alter culling which is
316      /// controlled by the active frustum when a SceneRenderState is created.
317      ///
318      /// @see SceneRenderState
319      /// @see GameProcessCameraQuery
320      /// @see LevelInfo
321      void setVisibleDistance( F32 dist ) { mVisibleDistance = dist; }
322
323      /// Returns the default visible distance for the scene.
324      F32 getVisibleDistance() { return mVisibleDistance; }
325
326      void setVisibleGhostDistance( F32 dist ) { mVisibleGhostDistance = dist; }
327      F32  getVisibleGhostDistance() { return mVisibleGhostDistance;}
328
329      /// Used by LevelInfo to set the default near clip plane 
330      /// for rendering the scene.
331      ///
332      /// @see GameProcessCameraQuery
333      /// @see LevelInfo
334      void setNearClip( F32 nearClip ) { mNearClip = nearClip; }
335
336      /// Returns the default near clip distance for the scene.
337      F32 getNearClip() { return mNearClip; }
338
339      /// @}
340
341      /// @name dtr Display Target Resolution
342      ///
343      /// Some rendering must be targeted at a specific display resolution.
344      /// This display resolution is distinct from the current RT's size
345      /// (such as when rendering a reflection to a texture, for instance)
346      /// so we store the size at which we're going to display the results of
347      /// the current render.
348      ///
349      /// @{
350
351      ///
352      void setDisplayTargetResolution(const Point2I &size);
353      const Point2I &getDisplayTargetResolution() const;
354
355      /// @}
356
357      // NonClipProjection is the projection matrix without oblique frustum clipping
358      // applied to it (in reflections)
359      void setNonClipProjection( const MatrixF &proj ) { mNonClipProj = proj; }
360      const MatrixF& getNonClipProjection() const { return mNonClipProj; }
361};
362
363//-----------------------------------------------------------------------------
364
365//TODO: these two need to go
366
367/// The client-side scene graph.  Not used if the engine is running
368/// as a dedicated server.
369extern SceneManager* gClientSceneGraph;
370
371/// The server-side scene graph.  Not used if the engine is running
372/// as a pure client.
373extern SceneManager* gServerSceneGraph;
374
375#endif //_SCENEMANAGER_H_
376