| [148] | 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
|---|
| 8 | |
|---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
|---|
| 11 | in the Software without restriction, including without limitation the rights |
|---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
|---|
| 14 | furnished to do so, subject to the following conditions: |
|---|
| 15 | |
|---|
| 16 | The above copyright notice and this permission notice shall be included in |
|---|
| 17 | all copies or substantial portions of the Software. |
|---|
| 18 | |
|---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 25 | THE SOFTWARE. |
|---|
| 26 | ----------------------------------------------------------------------------- |
|---|
| 27 | */ |
|---|
| 28 | #ifndef __AutoParamDataSource_H_ |
|---|
| 29 | #define __AutoParamDataSource_H_ |
|---|
| 30 | |
|---|
| 31 | #include "OgrePrerequisites.h" |
|---|
| 32 | #include "OgreCommon.h" |
|---|
| 33 | #include "OgreMatrix4.h" |
|---|
| 34 | #include "OgreVector4.h" |
|---|
| 35 | #include "OgreLight.h" |
|---|
| 36 | #include "OgreColourValue.h" |
|---|
| 37 | |
|---|
| 38 | namespace Ogre { |
|---|
| 39 | |
|---|
| 40 | // forward decls |
|---|
| 41 | struct VisibleObjectsBoundsInfo; |
|---|
| 42 | /** \addtogroup Core |
|---|
| 43 | * @{ |
|---|
| 44 | */ |
|---|
| 45 | /** \addtogroup Materials |
|---|
| 46 | * @{ |
|---|
| 47 | */ |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | /** This utility class is used to hold the information used to generate the matrices |
|---|
| 51 | and other information required to automatically populate GpuProgramParameters. |
|---|
| 52 | @remarks |
|---|
| 53 | This class exercises a lazy-update scheme in order to avoid having to update all |
|---|
| 54 | the information a GpuProgramParameters class could possibly want all the time. |
|---|
| 55 | It relies on the SceneManager to update it when the base data has changed, and |
|---|
| 56 | will calculate concatenated matrices etc only when required, passing back precalculated |
|---|
| 57 | matrices when they are requested more than once when the underlying information has |
|---|
| 58 | not altered. |
|---|
| 59 | */ |
|---|
| 60 | class _OgreExport AutoParamDataSource : public SceneMgtAlloc |
|---|
| 61 | { |
|---|
| 62 | protected: |
|---|
| 63 | const Light& getLight(size_t index) const; |
|---|
| 64 | mutable Matrix4 mWorldMatrix[256]; |
|---|
| 65 | mutable size_t mWorldMatrixCount; |
|---|
| 66 | mutable const Matrix4* mWorldMatrixArray; |
|---|
| 67 | mutable Matrix4 mWorldViewMatrix; |
|---|
| 68 | mutable Matrix4 mViewProjMatrix; |
|---|
| 69 | mutable Matrix4 mWorldViewProjMatrix; |
|---|
| 70 | mutable Matrix4 mInverseWorldMatrix; |
|---|
| 71 | mutable Matrix4 mInverseWorldViewMatrix; |
|---|
| 72 | mutable Matrix4 mInverseViewMatrix; |
|---|
| 73 | mutable Matrix4 mInverseTransposeWorldMatrix; |
|---|
| 74 | mutable Matrix4 mInverseTransposeWorldViewMatrix; |
|---|
| 75 | mutable Vector4 mCameraPosition; |
|---|
| 76 | mutable Vector4 mCameraPositionObjectSpace; |
|---|
| 77 | mutable Matrix4 mTextureViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 78 | mutable Matrix4 mTextureWorldViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 79 | mutable Matrix4 mSpotlightViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 80 | mutable Matrix4 mSpotlightWorldViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 81 | mutable Vector4 mShadowCamDepthRanges[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 82 | mutable Matrix4 mViewMatrix; |
|---|
| 83 | mutable Matrix4 mProjectionMatrix; |
|---|
| 84 | mutable Real mDirLightExtrusionDistance; |
|---|
| 85 | mutable Vector4 mLodCameraPosition; |
|---|
| 86 | mutable Vector4 mLodCameraPositionObjectSpace; |
|---|
| 87 | |
|---|
| 88 | mutable bool mWorldMatrixDirty; |
|---|
| 89 | mutable bool mViewMatrixDirty; |
|---|
| 90 | mutable bool mProjMatrixDirty; |
|---|
| 91 | mutable bool mWorldViewMatrixDirty; |
|---|
| 92 | mutable bool mViewProjMatrixDirty; |
|---|
| 93 | mutable bool mWorldViewProjMatrixDirty; |
|---|
| 94 | mutable bool mInverseWorldMatrixDirty; |
|---|
| 95 | mutable bool mInverseWorldViewMatrixDirty; |
|---|
| 96 | mutable bool mInverseViewMatrixDirty; |
|---|
| 97 | mutable bool mInverseTransposeWorldMatrixDirty; |
|---|
| 98 | mutable bool mInverseTransposeWorldViewMatrixDirty; |
|---|
| 99 | mutable bool mCameraPositionDirty; |
|---|
| 100 | mutable bool mCameraPositionObjectSpaceDirty; |
|---|
| 101 | mutable bool mTextureViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 102 | mutable bool mTextureWorldViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 103 | mutable bool mSpotlightViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 104 | mutable bool mSpotlightWorldViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 105 | mutable bool mShadowCamDepthRangesDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 106 | mutable ColourValue mAmbientLight; |
|---|
| 107 | mutable ColourValue mFogColour; |
|---|
| 108 | mutable Vector4 mFogParams; |
|---|
| 109 | mutable int mPassNumber; |
|---|
| 110 | mutable Vector4 mSceneDepthRange; |
|---|
| 111 | mutable bool mSceneDepthRangeDirty; |
|---|
| 112 | mutable bool mLodCameraPositionDirty; |
|---|
| 113 | mutable bool mLodCameraPositionObjectSpaceDirty; |
|---|
| 114 | |
|---|
| 115 | const Renderable* mCurrentRenderable; |
|---|
| 116 | const Camera* mCurrentCamera; |
|---|
| 117 | bool mCameraRelativeRendering; |
|---|
| 118 | Vector3 mCameraRelativePosition; |
|---|
| 119 | const LightList* mCurrentLightList; |
|---|
| 120 | const Frustum* mCurrentTextureProjector[OGRE_MAX_SIMULTANEOUS_LIGHTS]; |
|---|
| 121 | const RenderTarget* mCurrentRenderTarget; |
|---|
| 122 | const Viewport* mCurrentViewport; |
|---|
| 123 | const SceneManager* mCurrentSceneManager; |
|---|
| 124 | const VisibleObjectsBoundsInfo* mMainCamBoundsInfo; |
|---|
| 125 | const Pass* mCurrentPass; |
|---|
| 126 | |
|---|
| 127 | Light mBlankLight; |
|---|
| 128 | public: |
|---|
| 129 | AutoParamDataSource(); |
|---|
| 130 | virtual ~AutoParamDataSource(); |
|---|
| 131 | /** Updates the current renderable */ |
|---|
| 132 | virtual void setCurrentRenderable(const Renderable* rend); |
|---|
| 133 | /** Sets the world matrices, avoid query from renderable again */ |
|---|
| 134 | virtual void setWorldMatrices(const Matrix4* m, size_t count); |
|---|
| 135 | /** Updates the current camera */ |
|---|
| 136 | virtual void setCurrentCamera(const Camera* cam, bool useCameraRelative); |
|---|
| 137 | /** Sets the light list that should be used, and it's base index from the global list */ |
|---|
| 138 | virtual void setCurrentLightList(const LightList* ll); |
|---|
| 139 | /** Sets the current texture projector for a index */ |
|---|
| 140 | virtual void setTextureProjector(const Frustum* frust, size_t index); |
|---|
| 141 | /** Sets the current render target */ |
|---|
| 142 | virtual void setCurrentRenderTarget(const RenderTarget* target); |
|---|
| 143 | /** Sets the current viewport */ |
|---|
| 144 | virtual void setCurrentViewport(const Viewport* viewport); |
|---|
| 145 | /** Sets the shadow extrusion distance to be used for point lights. */ |
|---|
| 146 | virtual void setShadowDirLightExtrusionDistance(Real dist); |
|---|
| 147 | /** Sets the main camera's scene bounding information */ |
|---|
| 148 | virtual void setMainCamBoundsInfo(VisibleObjectsBoundsInfo* info); |
|---|
| 149 | /** Set the current scene manager for enquiring on demand */ |
|---|
| 150 | virtual void setCurrentSceneManager(const SceneManager* sm); |
|---|
| 151 | /** Sets the current pass */ |
|---|
| 152 | virtual void setCurrentPass(const Pass* pass); |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | virtual const Matrix4& getWorldMatrix(void) const; |
|---|
| 157 | virtual const Matrix4* getWorldMatrixArray(void) const; |
|---|
| 158 | virtual size_t getWorldMatrixCount(void) const; |
|---|
| 159 | virtual const Matrix4& getViewMatrix(void) const; |
|---|
| 160 | virtual const Matrix4& getViewProjectionMatrix(void) const; |
|---|
| 161 | virtual const Matrix4& getProjectionMatrix(void) const; |
|---|
| 162 | virtual const Matrix4& getWorldViewProjMatrix(void) const; |
|---|
| 163 | virtual const Matrix4& getWorldViewMatrix(void) const; |
|---|
| 164 | virtual const Matrix4& getInverseWorldMatrix(void) const; |
|---|
| 165 | virtual const Matrix4& getInverseWorldViewMatrix(void) const; |
|---|
| 166 | virtual const Matrix4& getInverseViewMatrix(void) const; |
|---|
| 167 | virtual const Matrix4& getInverseTransposeWorldMatrix(void) const; |
|---|
| 168 | virtual const Matrix4& getInverseTransposeWorldViewMatrix(void) const; |
|---|
| 169 | virtual const Vector4& getCameraPosition(void) const; |
|---|
| 170 | virtual const Vector4& getCameraPositionObjectSpace(void) const; |
|---|
| 171 | virtual const Vector4& getLodCameraPosition(void) const; |
|---|
| 172 | virtual const Vector4& getLodCameraPositionObjectSpace(void) const; |
|---|
| 173 | virtual bool hasLightList() const { return mCurrentLightList != 0; } |
|---|
| 174 | /** Get the light which is 'index'th closest to the current object */ |
|---|
| 175 | virtual float getLightNumber(size_t index) const; |
|---|
| 176 | virtual float getLightCount() const; |
|---|
| 177 | virtual float getLightCastsShadows(size_t index) const; |
|---|
| 178 | virtual const ColourValue& getLightDiffuseColour(size_t index) const; |
|---|
| 179 | virtual const ColourValue& getLightSpecularColour(size_t index) const; |
|---|
| 180 | virtual const ColourValue getLightDiffuseColourWithPower(size_t index) const; |
|---|
| 181 | virtual const ColourValue getLightSpecularColourWithPower(size_t index) const; |
|---|
| 182 | virtual const Vector3& getLightPosition(size_t index) const; |
|---|
| 183 | virtual Vector4 getLightAs4DVector(size_t index) const; |
|---|
| 184 | virtual const Vector3& getLightDirection(size_t index) const; |
|---|
| 185 | virtual Real getLightPowerScale(size_t index) const; |
|---|
| 186 | virtual Vector4 getLightAttenuation(size_t index) const; |
|---|
| 187 | virtual Vector4 getSpotlightParams(size_t index) const; |
|---|
| 188 | virtual void setAmbientLightColour(const ColourValue& ambient); |
|---|
| 189 | virtual const ColourValue& getAmbientLightColour(void) const; |
|---|
| 190 | virtual const ColourValue& getSurfaceAmbientColour(void) const; |
|---|
| 191 | virtual const ColourValue& getSurfaceDiffuseColour(void) const; |
|---|
| 192 | virtual const ColourValue& getSurfaceSpecularColour(void) const; |
|---|
| 193 | virtual const ColourValue& getSurfaceEmissiveColour(void) const; |
|---|
| 194 | virtual Real getSurfaceShininess(void) const; |
|---|
| 195 | virtual Real getSurfaceAlphaRejectionValue(void) const; |
|---|
| 196 | virtual ColourValue getDerivedAmbientLightColour(void) const; |
|---|
| 197 | virtual ColourValue getDerivedSceneColour(void) const; |
|---|
| 198 | virtual void setFog(FogMode mode, const ColourValue& colour, Real expDensity, Real linearStart, Real linearEnd); |
|---|
| 199 | virtual const ColourValue& getFogColour(void) const; |
|---|
| 200 | virtual const Vector4& getFogParams(void) const; |
|---|
| 201 | virtual const Matrix4& getTextureViewProjMatrix(size_t index) const; |
|---|
| 202 | virtual const Matrix4& getTextureWorldViewProjMatrix(size_t index) const; |
|---|
| 203 | virtual const Matrix4& getSpotlightViewProjMatrix(size_t index) const; |
|---|
| 204 | virtual const Matrix4& getSpotlightWorldViewProjMatrix(size_t index) const; |
|---|
| 205 | virtual const Matrix4& getTextureTransformMatrix(size_t index) const; |
|---|
| 206 | virtual const RenderTarget* getCurrentRenderTarget(void) const; |
|---|
| 207 | virtual const Renderable* getCurrentRenderable(void) const; |
|---|
| 208 | virtual const Pass* getCurrentPass(void) const; |
|---|
| 209 | virtual Vector4 getTextureSize(size_t index) const; |
|---|
| 210 | virtual Vector4 getInverseTextureSize(size_t index) const; |
|---|
| 211 | virtual Vector4 getPackedTextureSize(size_t index) const; |
|---|
| 212 | virtual Real getShadowExtrusionDistance(void) const; |
|---|
| 213 | virtual const Vector4& getSceneDepthRange() const; |
|---|
| 214 | virtual const Vector4& getShadowSceneDepthRange(size_t index) const; |
|---|
| 215 | virtual const ColourValue& getShadowColour() const; |
|---|
| 216 | virtual Matrix4 getInverseViewProjMatrix(void) const; |
|---|
| 217 | virtual Matrix4 getInverseTransposeViewProjMatrix() const; |
|---|
| 218 | virtual Matrix4 getTransposeViewProjMatrix() const; |
|---|
| 219 | virtual Matrix4 getTransposeViewMatrix() const; |
|---|
| 220 | virtual Matrix4 getInverseTransposeViewMatrix() const; |
|---|
| 221 | virtual Matrix4 getTransposeProjectionMatrix() const; |
|---|
| 222 | virtual Matrix4 getInverseProjectionMatrix() const; |
|---|
| 223 | virtual Matrix4 getInverseTransposeProjectionMatrix() const; |
|---|
| 224 | virtual Matrix4 getTransposeWorldViewProjMatrix() const; |
|---|
| 225 | virtual Matrix4 getInverseWorldViewProjMatrix() const; |
|---|
| 226 | virtual Matrix4 getInverseTransposeWorldViewProjMatrix() const; |
|---|
| 227 | virtual Matrix4 getTransposeWorldViewMatrix() const; |
|---|
| 228 | virtual Matrix4 getTransposeWorldMatrix() const; |
|---|
| 229 | virtual Real getTime(void) const; |
|---|
| 230 | virtual Real getTime_0_X(Real x) const; |
|---|
| 231 | virtual Real getCosTime_0_X(Real x) const; |
|---|
| 232 | virtual Real getSinTime_0_X(Real x) const; |
|---|
| 233 | virtual Real getTanTime_0_X(Real x) const; |
|---|
| 234 | virtual Vector4 getTime_0_X_packed(Real x) const; |
|---|
| 235 | virtual Real getTime_0_1(Real x) const; |
|---|
| 236 | virtual Real getCosTime_0_1(Real x) const; |
|---|
| 237 | virtual Real getSinTime_0_1(Real x) const; |
|---|
| 238 | virtual Real getTanTime_0_1(Real x) const; |
|---|
| 239 | virtual Vector4 getTime_0_1_packed(Real x) const; |
|---|
| 240 | virtual Real getTime_0_2Pi(Real x) const; |
|---|
| 241 | virtual Real getCosTime_0_2Pi(Real x) const; |
|---|
| 242 | virtual Real getSinTime_0_2Pi(Real x) const; |
|---|
| 243 | virtual Real getTanTime_0_2Pi(Real x) const; |
|---|
| 244 | virtual Vector4 getTime_0_2Pi_packed(Real x) const; |
|---|
| 245 | virtual Real getFrameTime(void) const; |
|---|
| 246 | virtual Real getFPS() const; |
|---|
| 247 | virtual Real getViewportWidth() const; |
|---|
| 248 | virtual Real getViewportHeight() const; |
|---|
| 249 | virtual Real getInverseViewportWidth() const; |
|---|
| 250 | virtual Real getInverseViewportHeight() const; |
|---|
| 251 | virtual Vector3 getViewDirection() const; |
|---|
| 252 | virtual Vector3 getViewSideVector() const; |
|---|
| 253 | virtual Vector3 getViewUpVector() const; |
|---|
| 254 | virtual Real getFOV() const; |
|---|
| 255 | virtual Real getNearClipDistance() const; |
|---|
| 256 | virtual Real getFarClipDistance() const; |
|---|
| 257 | virtual int getPassNumber(void) const; |
|---|
| 258 | virtual void setPassNumber(const int passNumber); |
|---|
| 259 | virtual void incPassNumber(void); |
|---|
| 260 | virtual void updateLightCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry& constantEntry, GpuProgramParameters *params) const; |
|---|
| 261 | }; |
|---|
| 262 | /** @} */ |
|---|
| 263 | /** @} */ |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | #endif |
|---|