reflectionManager.h
Engine/source/scene/reflectionManager.h
Classes:
class
class
Public Defines
define
REFLECTMGR() <>::instance()
Returns the ReflectionManager singleton.
Public Enumerations
enum
ReflectMode { ReflectNever = 0 ReflectDynamic ReflectAlways }
Public Functions
GFX_DeclareTextureProfile(ReflectRenderTargetProfile )
GFX_DeclareTextureProfile(RefractTextureProfile )
Detailed Description
Public Defines
REFLECTMGR() <>::instance()
Returns the ReflectionManager singleton.
Public Enumerations
ReflectMode
Enumerator
- ReflectNever = 0
- ReflectDynamic
- ReflectAlways
Public Typedefs
typedef Delegate< bool(bool)> ReflectDelegate
typedef Vector< Reflector > ReflectorVec
Public Functions
GFX_DeclareTextureProfile(ReflectRenderTargetProfile )
GFX_DeclareTextureProfile(RefractTextureProfile )
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 _REFLECTIONMANAGER_H_ 25#define _REFLECTIONMANAGER_H_ 26 27#ifndef _GFXDEVICE_H_ 28#include "gfx/gfxDevice.h" 29#endif 30#ifndef _TVECTOR_H_ 31#include "core/util/tVector.h" 32#endif 33#ifndef _UTIL_DELEGATE_H_ 34#include "core/util/delegate.h" 35#endif 36#ifndef _GFXTEXTUREHANDLE_H_ 37#include "gfx/gfxTextureHandle.h" 38#endif 39#ifndef _TSINGLETON_H_ 40#include "core/util/tSingleton.h" 41#endif 42#ifndef _REFLECTOR_H_ 43#include "scene/reflector.h" 44#endif 45 46class PlatformTimer; 47class BaseMatInstance; 48 49enum ReflectMode 50{ 51 ReflectNever = 0, 52 ReflectDynamic, 53 ReflectAlways 54}; 55 56typedef Delegate<bool(bool)> ReflectDelegate; 57class SceneObject; 58 59struct Reflector 60{ 61 SceneObject *object; 62 ReflectDelegate updateFn; 63 F32 priority; 64 U32 maxRateMs; 65 F32 maxDist; 66 U32 lastUpdateMs; 67 F32 score; 68 bool updated; 69 bool tried; 70 bool hasTexture; 71}; 72 73typedef Vector<Reflector> ReflectorVec; 74 75GFX_DeclareTextureProfile( ReflectRenderTargetProfile ); 76GFX_DeclareTextureProfile( RefractTextureProfile ); 77 78class ReflectionManager 79{ 80public: 81 82 ReflectionManager(); 83 virtual ~ReflectionManager(); 84 85 static void initConsole(); 86 87 /// Called to change the reflection texture format. 88 void setReflectFormat( GFXFormat format ) { mReflectFormat = format; } 89 90 /// Returns the current reflection format. 91 GFXFormat getReflectFormat() const { return mReflectFormat; } 92 93 /// Doll out callbacks to registered objects based on 94 /// scoring and elapsed time. This should be called 95 /// once for each viewport that renders. 96 void update( F32 timeSlice, 97 const Point2I &resolution, 98 const CameraQuery &query ); 99 100 void registerReflector( ReflectorBase *reflector ); 101 void unregisterReflector( ReflectorBase *reflector ); 102 103 GFXTexHandle allocRenderTarget( const Point2I &size ); 104 105 GFXTextureObject* getRefractTex( bool forceUpdate = false ); 106 107 BaseMatInstance* getReflectionMaterial( BaseMatInstance *inMat ) const; 108 109 const U32& getLastUpdateMs() const { return mLastUpdateMs; } 110 111protected: 112 113 bool _handleDeviceEvent( GFXDevice::GFXDeviceEventType evt ); 114 115protected: 116 117 /// ReflectionManager tries not to spend more than this amount of time 118 /// updating reflections per frame. 119 static U32 smFrameReflectionMS; 120 121 /// RefractTex has dimensions equal to the active render target scaled in 122 /// both x and y by this float. 123 static F32 smRefractTexScale; 124 125 /// A timer used for tracking update time. 126 PlatformTimer *mTimer; 127 128 /// All registered reflections which we handle updating. 129 ReflectorList mReflectors; 130 131 /// Refraction texture copied from the backbuffer once per frame that 132 /// gets used by all WaterObjects. 133 GFXTexHandle mRefractTex; 134 135 /// The texture format to use for reflection and 136 /// refraction texture sources. 137 GFXFormat mReflectFormat; 138 139 /// Set when the refraction texture is dirty 140 /// and requires an update. 141 bool mUpdateRefract; 142 143 /// Platform time in milliseconds of the last update. 144 U32 mLastUpdateMs; 145 146public: 147 // For ManagedSingleton. 148 static const char* getSingletonName() { return "ReflectionManager"; } 149}; 150 151 152/// Returns the ReflectionManager singleton. 153#define REFLECTMGR ManagedSingleton<ReflectionManager>::instance() 154 155#endif // _REFLECTIONMANAGER_H_ 156