Coverage Report

Created: 2026-07-16 06:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgreAutoParamDataSource.h
Line
Count
Source
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-2014 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 "OgreLight.h"
34
#include "OgreSceneNode.h"
35
36
namespace Ogre {
37
38
    // forward decls
39
    struct VisibleObjectsBoundsInfo;
40
41
    /** \addtogroup Core
42
    *  @{
43
    */
44
    /** \addtogroup Materials
45
    *  @{
46
    */
47
48
49
    /** This utility class is used to hold the information used to generate the matrices
50
    and other information required to automatically populate GpuProgramParameters.
51
52
    This class exercises a lazy-update scheme in order to avoid having to update all
53
    the information a GpuProgramParameters class could possibly want all the time.
54
    It relies on the SceneManager to update it when the base data has changed, and
55
    will calculate concatenated matrices etc only when required, passing back precalculated
56
    matrices when they are requested more than once when the underlying information has
57
    not altered.
58
    */
59
    class _OgreExport AutoParamDataSource : public SceneMgtAlloc
60
    {
61
    private:
62
        const Light& getLight(size_t index) const;
63
        mutable Affine3 mWorldMatrix[OGRE_MAX_NUM_BONES + 1];
64
        mutable size_t mWorldMatrixCount;
65
        mutable const Affine3* mWorldMatrixArray;
66
        mutable Affine3 mWorldViewMatrix;
67
        mutable Matrix4 mViewProjMatrix;
68
        mutable Matrix4 mWorldViewProjMatrix;
69
        mutable Affine3 mInverseWorldMatrix;
70
        mutable Affine3 mInverseWorldViewMatrix;
71
        mutable Affine3 mInverseViewMatrix;
72
        mutable Matrix4 mInverseTransposeWorldMatrix;
73
        mutable Matrix4 mInverseTransposeWorldViewMatrix;
74
        mutable Vector4 mCameraPosition;
75
        mutable Vector4 mCameraPositionObjectSpace;
76
        mutable Matrix4 mTextureViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS];
77
        mutable Matrix4 mTextureWorldViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS];
78
        mutable Matrix4 mSpotlightViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS];
79
        mutable Matrix4 mSpotlightWorldViewProjMatrix[OGRE_MAX_SIMULTANEOUS_LIGHTS];
80
        mutable Vector4 mShadowCamDepthRanges[OGRE_MAX_SIMULTANEOUS_LIGHTS];
81
        mutable Affine3 mViewMatrix;
82
        mutable Matrix4 mProjectionMatrix;
83
        mutable Real mDirLightExtrusionDistance;
84
        mutable Real mPointLightExtrusionDistance;
85
        mutable Vector4 mLodCameraPosition;
86
        mutable Vector4 mLodCameraPositionObjectSpace;
87
88
        // Light arrays fastpath
89
        mutable std::vector<Vector4f> mLightPosViewSpaceArray;
90
        mutable std::vector<Vector4f> mLightAttenuationArray;
91
        mutable std::vector<Vector4f> mSpotlightParamsArray;
92
        mutable std::vector<Vector4f> mLightDirViewSpaceArray;
93
        mutable std::vector<ColourValue> mLightDiffuseColourPowerScaledArray;
94
95
        mutable bool mWorldMatrixDirty;
96
        mutable bool mViewMatrixDirty;
97
        mutable bool mProjMatrixDirty;
98
        mutable bool mWorldViewMatrixDirty;
99
        mutable bool mViewProjMatrixDirty;
100
        mutable bool mWorldViewProjMatrixDirty;
101
        mutable bool mInverseWorldMatrixDirty;
102
        mutable bool mInverseWorldViewMatrixDirty;
103
        mutable bool mInverseViewMatrixDirty;
104
        mutable bool mInverseTransposeWorldMatrixDirty;
105
        mutable bool mInverseTransposeWorldViewMatrixDirty;
106
        mutable bool mCameraPositionDirty;
107
        mutable bool mCameraPositionObjectSpaceDirty;
108
        mutable bool mTextureViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS];
109
        mutable bool mTextureWorldViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS];
110
        mutable bool mSpotlightViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS];
111
        mutable bool mSpotlightWorldViewProjMatrixDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS];
112
        mutable bool mShadowCamDepthRangesDirty[OGRE_MAX_SIMULTANEOUS_LIGHTS];
113
        ColourValue mAmbientLight;
114
        ColourValue mFogColour;
115
        ColourValue mShadowColour;
116
        Vector4f mFogParams;
117
        Vector4f mPointParams;
118
        int mPassNumber;
119
        mutable Vector4 mSceneDepthRange;
120
        mutable bool mSceneDepthRangeDirty;
121
        mutable bool mLodCameraPositionDirty;
122
        mutable bool mLodCameraPositionObjectSpaceDirty;
123
124
        const Renderable* mCurrentRenderable;
125
        const Camera* mCurrentCamera;
126
        std::vector<const Camera*> mCameraArray;
127
        bool mCameraRelativeRendering;
128
        Vector3 mCameraRelativePosition;
129
        const LightList* mCurrentLightList;
130
        const Frustum* mCurrentTextureProjector[OGRE_MAX_SIMULTANEOUS_LIGHTS];
131
        const RenderTarget* mCurrentRenderTarget;
132
        const Viewport* mCurrentViewport;
133
        const SceneManager* mCurrentSceneManager;
134
        const VisibleObjectsBoundsInfo* mMainCamBoundsInfo;
135
        const Pass* mCurrentPass;
136
137
        SceneNode mDummyNode;
138
        Light mBlankLight;
139
        /// Last light sets
140
        uint32 mLastLightHash;
141
        /// Gpu params that need rebinding (mask of GpuParamVariability)
142
        uint16 mGpuParamsDirty;
143
        bool mCurrentUseIdentityView;
144
        bool mCurrentUseIdentityProj;
145
    public:
146
        AutoParamDataSource();
147
        /** Updates the current renderable */
148
        void setCurrentRenderable(const Renderable* rend);
149
        /** Sets the world matrices, avoid query from renderable again */
150
        void setWorldMatrices(const Affine3* m, size_t count);
151
        /** Updates the current camera */
152
        void setCurrentCamera(const Camera* cam, bool useCameraRelative);
153
        void setCameraArray(const std::vector<const Camera*> cameras);
154
        /** Sets the light list that should be used, and it's base index from the global list */
155
        void setCurrentLightList(const LightList* ll);
156
        /** Sets the current texture projector for a index */
157
        void setTextureProjector(const Frustum* frust, size_t index);
158
        /** Sets the current render target */
159
        void setCurrentRenderTarget(const RenderTarget* target);
160
        /** Sets the current viewport */
161
        void setCurrentViewport(const Viewport* viewport);
162
        /** Sets the shadow extrusion distance to be used for dir lights. */
163
        void setShadowDirLightExtrusionDistance(Real dist);
164
        /** Sets the shadow extrusion distance to be used for point lights. */
165
        void setShadowPointLightExtrusionDistance(Real dist);
166
        /** Sets the main camera's scene bounding information */
167
        void setMainCamBoundsInfo(VisibleObjectsBoundsInfo* info);
168
        /** Set the current scene manager for enquiring on demand */
169
        void setCurrentSceneManager(const SceneManager* sm);
170
        /** Sets the current pass */
171
        void setCurrentPass(const Pass* pass);
172
173
    /** Returns the current bounded camera */
174
    const Camera* getCurrentCamera() const;
175
176
        const Affine3& getWorldMatrix(void) const;
177
        const Affine3* getBoneMatrixArray(void) const;
178
0
        OGRE_DEPRECATED const Affine3* getWorldMatrixArray(void) const { return getBoneMatrixArray(); }
179
        size_t getBoneMatrixCount(void) const;
180
0
        OGRE_DEPRECATED size_t getWorldMatrixCount(void) const { return getBoneMatrixCount(); }
181
        const Affine3& getViewMatrix(void) const;
182
        Affine3 getViewMatrix(const Camera* cam) const;
183
        const Matrix4& getViewProjectionMatrix(void) const;
184
        const Matrix4& getProjectionMatrix(void) const;
185
        Matrix4 getProjectionMatrix(const Camera* cam) const;
186
        const Matrix4& getWorldViewProjMatrix(void) const;
187
        Matrix4 getWorldViewProjMatrix(size_t index) const;
188
        const Affine3& getWorldViewMatrix(void) const;
189
        const Affine3& getInverseWorldMatrix(void) const;
190
        const Affine3& getInverseWorldViewMatrix(void) const;
191
        const Affine3& getInverseViewMatrix(void) const;
192
        const Matrix4& getInverseTransposeWorldMatrix(void) const;
193
        const Matrix4& getInverseTransposeWorldViewMatrix(void) const;
194
        const Vector4& getCameraPosition(void) const;
195
        const Vector4& getCameraPositionObjectSpace(void) const;
196
        const Vector4  getCameraRelativePosition(void) const;
197
        const Vector4& getLodCameraPosition(void) const;
198
        const Vector4& getLodCameraPositionObjectSpace(void) const;
199
0
        bool hasLightList() const { return mCurrentLightList != 0; }
200
        /** Get the light which is 'index'th closest to the current object */        
201
        float getLightNumber(size_t index) const;
202
        float getLightCount() const;
203
        float getLightCastsShadows(size_t index) const;
204
        const ColourValue& getLightDiffuseColour(size_t index) const;
205
        const ColourValue& getLightSpecularColour(size_t index) const;
206
        const ColourValue getLightDiffuseColourWithPower(size_t index) const;
207
        const ColourValue getLightSpecularColourWithPower(size_t index) const;
208
        Vector3 getLightPosition(size_t index) const;
209
        Vector4 getLightAs4DVector(size_t index) const;
210
        Vector3 getLightDirection(size_t index) const;
211
        Real getLightPowerScale(size_t index) const;
212
        Vector4f getLightAttenuation(size_t index) const;
213
        Vector4f getSpotlightParams(size_t index) const;
214
        // Light arrays fastpath
215
        const Vector4f* getLightPositionViewSpaceArray(size_t size) const;
216
        const Vector4f* getLightAttenuationArray(size_t size) const;
217
        const Vector4f* getSpotlightParamsArray(size_t size) const;
218
        const Vector4f* getLightDirectionViewSpaceArray(size_t size) const;
219
        const ColourValue* getLightDiffuseColourPowerScaledArray(size_t size) const;
220
221
        void setAmbientLightColour(const ColourValue& ambient);
222
        const ColourValue& getAmbientLightColour(void) const;
223
        const ColourValue& getSurfaceAmbientColour(void) const;
224
        const ColourValue& getSurfaceDiffuseColour(void) const;
225
        const ColourValue& getSurfaceSpecularColour(void) const;
226
        const ColourValue& getSurfaceEmissiveColour(void) const;
227
        Real getSurfaceShininess(void) const;
228
        Real getSurfaceAlphaRejectionValue(void) const;
229
        ColourValue getDerivedAmbientLightColour(void) const;
230
        ColourValue getDerivedSceneColour(void) const;
231
        void setFog(FogMode mode, const ColourValue& colour, Real expDensity, Real linearStart, Real linearEnd);
232
        const ColourValue& getFogColour(void) const;
233
        const Vector4f& getFogParams(void) const;
234
        void setPointParameters(bool attenuation, const Vector4f& params);
235
        const Vector4f& getPointParams() const;
236
        const Matrix4& getTextureViewProjMatrix(size_t index) const;
237
        const Matrix4& getTextureWorldViewProjMatrix(size_t index) const;
238
        const Matrix4& getSpotlightViewProjMatrix(size_t index) const;
239
        const Matrix4& getSpotlightWorldViewProjMatrix(size_t index) const;
240
        const Matrix4& getTextureTransformMatrix(size_t index) const;
241
        const RenderTarget* getCurrentRenderTarget(void) const;
242
        const Renderable* getCurrentRenderable(void) const;
243
        const Pass* getCurrentPass(void) const;
244
        Vector4f getTextureSize(size_t index) const;
245
        Vector4f getInverseTextureSize(size_t index) const;
246
        Vector4f getPackedTextureSize(size_t index) const;
247
        Real getShadowExtrusionDistance(void) const;
248
        const Vector4& getSceneDepthRange() const;
249
        const Vector4& getShadowSceneDepthRange(size_t index) const;
250
        void setShadowColour(const ColourValue& colour);
251
        const ColourValue& getShadowColour() const;
252
        Matrix4 getInverseViewProjMatrix(void) const;
253
        Matrix4 getInverseTransposeViewProjMatrix() const;
254
        Matrix4 getTransposeViewProjMatrix() const;
255
        Matrix4 getTransposeViewMatrix() const;
256
        Matrix4 getInverseTransposeViewMatrix() const;
257
        Matrix4 getTransposeProjectionMatrix() const;
258
        Matrix4 getInverseProjectionMatrix() const;
259
        Matrix4 getInverseTransposeProjectionMatrix() const;
260
        Matrix4 getTransposeWorldViewProjMatrix() const;
261
        Matrix4 getInverseWorldViewProjMatrix() const;
262
        Matrix4 getInverseTransposeWorldViewProjMatrix() const;
263
        Matrix4 getTransposeWorldViewMatrix() const;
264
        Matrix4 getTransposeWorldMatrix() const;
265
        Real getTime(void) const;
266
        Real getTime_0_X(Real x) const;
267
        Real getCosTime_0_X(Real x) const;
268
        Real getSinTime_0_X(Real x) const;
269
        Real getTanTime_0_X(Real x) const;
270
        Vector4f getTime_0_X_packed(Real x) const;
271
        Real getTime_0_1(Real x) const;
272
        Real getCosTime_0_1(Real x) const;
273
        Real getSinTime_0_1(Real x) const;
274
        Real getTanTime_0_1(Real x) const;
275
        Vector4f getTime_0_1_packed(Real x) const;
276
        Real getTime_0_2Pi(Real x) const;
277
        Real getCosTime_0_2Pi(Real x) const;
278
        Real getSinTime_0_2Pi(Real x) const;
279
        Real getTanTime_0_2Pi(Real x) const;
280
        Vector4f getTime_0_2Pi_packed(Real x) const;
281
        Real getFrameTime(void) const;
282
        Real getFPS() const;
283
        Real getViewportWidth() const;
284
        Real getViewportHeight() const;
285
        Real getInverseViewportWidth() const;
286
        Real getInverseViewportHeight() const;
287
        Vector3 getViewDirection() const;
288
        Vector3 getViewSideVector() const;
289
        Vector3 getViewUpVector() const;
290
        float getFOV() const;
291
        float getNearClipDistance() const;
292
        float getFarClipDistance() const;
293
        int getPassNumber(void) const;
294
        int getMaterialLodIndex() const;
295
        void setPassNumber(const int passNumber);
296
        void incPassNumber(void);
297
0
        void markGpuParamsDirty(uint16 mask) { mGpuParamsDirty |= mask; }
298
0
        uint16 getGpuParamsDirty() const { return mGpuParamsDirty; }
299
0
        void resetGpuParamsDirty() { mGpuParamsDirty = 0; }
300
        void updateLightCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry& constantEntry, GpuProgramParameters *params) const;
301
    };
302
    /** @} */
303
    /** @} */
304
}
305
306
#endif