Coverage Report

Created: 2026-01-17 06:50

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
    public:
140
        AutoParamDataSource();
141
        /** Updates the current renderable */
142
        void setCurrentRenderable(const Renderable* rend);
143
        /** Sets the world matrices, avoid query from renderable again */
144
        void setWorldMatrices(const Affine3* m, size_t count);
145
        /** Updates the current camera */
146
        void setCurrentCamera(const Camera* cam, bool useCameraRelative);
147
        void setCameraArray(const std::vector<const Camera*> cameras);
148
        /** Sets the light list that should be used, and it's base index from the global list */
149
        void setCurrentLightList(const LightList* ll);
150
        /** Sets the current texture projector for a index */
151
        void setTextureProjector(const Frustum* frust, size_t index);
152
        /** Sets the current render target */
153
        void setCurrentRenderTarget(const RenderTarget* target);
154
        /** Sets the current viewport */
155
        void setCurrentViewport(const Viewport* viewport);
156
        /** Sets the shadow extrusion distance to be used for dir lights. */
157
        void setShadowDirLightExtrusionDistance(Real dist);
158
        /** Sets the shadow extrusion distance to be used for point lights. */
159
        void setShadowPointLightExtrusionDistance(Real dist);
160
        /** Sets the main camera's scene bounding information */
161
        void setMainCamBoundsInfo(VisibleObjectsBoundsInfo* info);
162
        /** Set the current scene manager for enquiring on demand */
163
        void setCurrentSceneManager(const SceneManager* sm);
164
        /** Sets the current pass */
165
        void setCurrentPass(const Pass* pass);
166
167
    /** Returns the current bounded camera */
168
    const Camera* getCurrentCamera() const;
169
170
        const Affine3& getWorldMatrix(void) const;
171
        const Affine3* getBoneMatrixArray(void) const;
172
0
        OGRE_DEPRECATED const Affine3* getWorldMatrixArray(void) const { return getBoneMatrixArray(); }
173
        size_t getBoneMatrixCount(void) const;
174
0
        OGRE_DEPRECATED size_t getWorldMatrixCount(void) const { return getBoneMatrixCount(); }
175
        const Affine3& getViewMatrix(void) const;
176
        Affine3 getViewMatrix(const Camera* cam) const;
177
        const Matrix4& getViewProjectionMatrix(void) const;
178
        const Matrix4& getProjectionMatrix(void) const;
179
        Matrix4 getProjectionMatrix(const Camera* cam) const;
180
        const Matrix4& getWorldViewProjMatrix(void) const;
181
        Matrix4 getWorldViewProjMatrix(size_t index) const;
182
        const Affine3& getWorldViewMatrix(void) const;
183
        const Affine3& getInverseWorldMatrix(void) const;
184
        const Affine3& getInverseWorldViewMatrix(void) const;
185
        const Affine3& getInverseViewMatrix(void) const;
186
        const Matrix4& getInverseTransposeWorldMatrix(void) const;
187
        const Matrix4& getInverseTransposeWorldViewMatrix(void) const;
188
        const Vector4& getCameraPosition(void) const;
189
        const Vector4& getCameraPositionObjectSpace(void) const;
190
        const Vector4  getCameraRelativePosition(void) const;
191
        const Vector4& getLodCameraPosition(void) const;
192
        const Vector4& getLodCameraPositionObjectSpace(void) const;
193
0
        bool hasLightList() const { return mCurrentLightList != 0; }
194
        /** Get the light which is 'index'th closest to the current object */        
195
        float getLightNumber(size_t index) const;
196
        float getLightCount() const;
197
        float getLightCastsShadows(size_t index) const;
198
        const ColourValue& getLightDiffuseColour(size_t index) const;
199
        const ColourValue& getLightSpecularColour(size_t index) const;
200
        const ColourValue getLightDiffuseColourWithPower(size_t index) const;
201
        const ColourValue getLightSpecularColourWithPower(size_t index) const;
202
        Vector3 getLightPosition(size_t index) const;
203
        Vector4 getLightAs4DVector(size_t index) const;
204
        Vector3 getLightDirection(size_t index) const;
205
        Real getLightPowerScale(size_t index) const;
206
        Vector4f getLightAttenuation(size_t index) const;
207
        Vector4f getSpotlightParams(size_t index) const;
208
        // Light arrays fastpath
209
        const Vector4f* getLightPositionViewSpaceArray(size_t size) const;
210
        const Vector4f* getLightAttenuationArray(size_t size) const;
211
        const Vector4f* getSpotlightParamsArray(size_t size) const;
212
        const Vector4f* getLightDirectionViewSpaceArray(size_t size) const;
213
        const ColourValue* getLightDiffuseColourPowerScaledArray(size_t size) const;
214
215
        void setAmbientLightColour(const ColourValue& ambient);
216
        const ColourValue& getAmbientLightColour(void) const;
217
        const ColourValue& getSurfaceAmbientColour(void) const;
218
        const ColourValue& getSurfaceDiffuseColour(void) const;
219
        const ColourValue& getSurfaceSpecularColour(void) const;
220
        const ColourValue& getSurfaceEmissiveColour(void) const;
221
        Real getSurfaceShininess(void) const;
222
        Real getSurfaceAlphaRejectionValue(void) const;
223
        ColourValue getDerivedAmbientLightColour(void) const;
224
        ColourValue getDerivedSceneColour(void) const;
225
        void setFog(FogMode mode, const ColourValue& colour, Real expDensity, Real linearStart, Real linearEnd);
226
        const ColourValue& getFogColour(void) const;
227
        const Vector4f& getFogParams(void) const;
228
        void setPointParameters(bool attenuation, const Vector4f& params);
229
        const Vector4f& getPointParams() const;
230
        const Matrix4& getTextureViewProjMatrix(size_t index) const;
231
        const Matrix4& getTextureWorldViewProjMatrix(size_t index) const;
232
        const Matrix4& getSpotlightViewProjMatrix(size_t index) const;
233
        const Matrix4& getSpotlightWorldViewProjMatrix(size_t index) const;
234
        const Matrix4& getTextureTransformMatrix(size_t index) const;
235
        const RenderTarget* getCurrentRenderTarget(void) const;
236
        const Renderable* getCurrentRenderable(void) const;
237
        const Pass* getCurrentPass(void) const;
238
        Vector4f getTextureSize(size_t index) const;
239
        Vector4f getInverseTextureSize(size_t index) const;
240
        Vector4f getPackedTextureSize(size_t index) const;
241
        Real getShadowExtrusionDistance(void) const;
242
        const Vector4& getSceneDepthRange() const;
243
        const Vector4& getShadowSceneDepthRange(size_t index) const;
244
        void setShadowColour(const ColourValue& colour);
245
        const ColourValue& getShadowColour() const;
246
        Matrix4 getInverseViewProjMatrix(void) const;
247
        Matrix4 getInverseTransposeViewProjMatrix() const;
248
        Matrix4 getTransposeViewProjMatrix() const;
249
        Matrix4 getTransposeViewMatrix() const;
250
        Matrix4 getInverseTransposeViewMatrix() const;
251
        Matrix4 getTransposeProjectionMatrix() const;
252
        Matrix4 getInverseProjectionMatrix() const;
253
        Matrix4 getInverseTransposeProjectionMatrix() const;
254
        Matrix4 getTransposeWorldViewProjMatrix() const;
255
        Matrix4 getInverseWorldViewProjMatrix() const;
256
        Matrix4 getInverseTransposeWorldViewProjMatrix() const;
257
        Matrix4 getTransposeWorldViewMatrix() const;
258
        Matrix4 getTransposeWorldMatrix() const;
259
        Real getTime(void) const;
260
        Real getTime_0_X(Real x) const;
261
        Real getCosTime_0_X(Real x) const;
262
        Real getSinTime_0_X(Real x) const;
263
        Real getTanTime_0_X(Real x) const;
264
        Vector4f getTime_0_X_packed(Real x) const;
265
        Real getTime_0_1(Real x) const;
266
        Real getCosTime_0_1(Real x) const;
267
        Real getSinTime_0_1(Real x) const;
268
        Real getTanTime_0_1(Real x) const;
269
        Vector4f getTime_0_1_packed(Real x) const;
270
        Real getTime_0_2Pi(Real x) const;
271
        Real getCosTime_0_2Pi(Real x) const;
272
        Real getSinTime_0_2Pi(Real x) const;
273
        Real getTanTime_0_2Pi(Real x) const;
274
        Vector4f getTime_0_2Pi_packed(Real x) const;
275
        Real getFrameTime(void) const;
276
        Real getFPS() const;
277
        Real getViewportWidth() const;
278
        Real getViewportHeight() const;
279
        Real getInverseViewportWidth() const;
280
        Real getInverseViewportHeight() const;
281
        Vector3 getViewDirection() const;
282
        Vector3 getViewSideVector() const;
283
        Vector3 getViewUpVector() const;
284
        float getFOV() const;
285
        float getNearClipDistance() const;
286
        float getFarClipDistance() const;
287
        int getPassNumber(void) const;
288
        int getMaterialLodIndex() const;
289
        void setPassNumber(const int passNumber);
290
        void incPassNumber(void);
291
        void updateLightCustomGpuParameter(const GpuProgramParameters::AutoConstantEntry& constantEntry, GpuProgramParameters *params) const;
292
    };
293
    /** @} */
294
    /** @} */
295
}
296
297
#endif