Coverage Report

Created: 2026-08-13 06:03

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