Coverage Report

Created: 2025-10-10 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/Components/Terrain/include/OgreTerrainMaterialGenerator.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
29
#ifndef __Ogre_TerrainMaterialGenerator_H__
30
#define __Ogre_TerrainMaterialGenerator_H__
31
32
#include "OgreTerrainPrerequisites.h"
33
#include "OgrePixelFormat.h"
34
#include "OgreSharedPtr.h"
35
36
namespace Ogre
37
{
38
    class Rectangle2D;
39
    class Terrain;
40
41
    /** \addtogroup Optional
42
    *  @{
43
    */
44
    /** \addtogroup Terrain
45
    *  Some details on the terrain component
46
    *  @{
47
    */
48
49
    /** Description of a sampler that will be used with each layer. 
50
    */
51
    struct _OgreTerrainExport TerrainLayerSampler
52
    {
53
        /// A descriptive name that is merely used to assist in recognition
54
        String alias;
55
        /// The format required of this texture
56
        PixelFormat format;
57
58
        TerrainLayerSampler()
59
0
            : alias(""), format(PF_UNKNOWN)
60
0
        {
61
0
        }
62
63
        TerrainLayerSampler(const String& aliasName, PixelFormat fmt)
64
0
            : alias(aliasName), format(fmt)
65
0
        {
66
0
        }
67
    };
68
    /** The definition of the information each layer will contain in this terrain.
69
    All layers must contain the same structure of information, although the
70
    input textures can be different per layer instance. 
71
    */
72
    typedef std::vector<TerrainLayerSampler> TerrainLayerDeclaration;
73
74
    /** Class that provides functionality to generate materials for use with a terrain.
75
76
        Terrains are composed of one or more layers of texture information, and
77
        require that a material is generated to render them. There are various approaches
78
        to rendering the terrain, which may vary due to:
79
        <ul><li>Hardware support (static)</li>
80
        <li>Texture instances assigned to a particular terrain (dynamic in an editor)</li>
81
        <li>User selection (e.g. changing to a cheaper option in order to increase performance, 
82
        or in order to test how the material might look on other hardware (dynamic)</li>
83
        </ul>
84
        Subclasses of this class are responsible for responding to these factors and
85
        to generate a terrain material.
86
    */
87
    class _OgreTerrainExport TerrainMaterialGenerator : public TerrainAlloc
88
    {
89
    public:
90
        struct Profile
91
        {
92
0
            virtual ~Profile() {}
93
        };
94
95
        TerrainMaterialGenerator();
96
        virtual ~TerrainMaterialGenerator();
97
    
98
        /// Get the active profile
99
0
        virtual Profile* getActiveProfile() const { return NULL; }
100
101
        /// Internal method - indicates that a change has been made that would require material regeneration
102
0
        void _markChanged() { ++mChangeCounter; }
103
104
        /** Returns the number of times the generator has undergone a change which 
105
            would require materials to be regenerated.
106
        */
107
0
        unsigned long long int getChangeCount() const { return mChangeCounter; }
108
109
        /** Get the layer declaration that this material generator operates with.
110
        */
111
0
        const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
112
113
        /** Return whether this material generator supports using a compressed
114
            vertex format. This is only possible when using shaders.
115
        */
116
0
        virtual bool isVertexCompressionSupported() const { return false; }
117
118
        /** Triggers the generator to request the options that it needs.
119
        */
120
0
        virtual void requestOptions(Terrain* terrain) {}
121
        /** Generate a material for the given terrain using the active profile.
122
        */
123
        virtual MaterialPtr generate(const Terrain* terrain) = 0;
124
        /** Generate a material for the given composite map of the terrain using the active profile.
125
        */
126
        virtual MaterialPtr generateForCompositeMap(const Terrain* terrain) = 0;
127
        /** Whether to support a light map over the terrain in the shader,
128
        if it's present (default true). 
129
        */
130
0
        virtual void setLightmapEnabled(bool enabled) {}
131
        /** Get the maximum number of layers supported with the given terrain. 
132
        @note When you change the options on the terrain, this value can change. 
133
        */
134
0
        virtual uint8 getMaxLayers(const Terrain* terrain) const { return 0; }
135
136
        /** Update the composite map for a terrain.
137
        The composite map for a terrain must match what the terrain should look like
138
        at distance. This method will only be called in the render thread so the
139
        generator is free to render into a texture to support this, so long as 
140
        the results are blitted into the Terrain's own composite map afterwards.
141
        */
142
        void updateCompositeMap(const Terrain* terrain, const Rect& rect);
143
144
        /** Update parameters for the given terrain using the active profile.
145
        */
146
0
        virtual void updateParams(const MaterialPtr& mat, const Terrain* terrain) {}
147
        /** Update parameters for the given terrain composite map using the active profile.
148
        */
149
0
        virtual void updateParamsForCompositeMap(const MaterialPtr& mat, const Terrain* terrain) {}
150
151
        /** Set the debug level of the material. 
152
153
            Sets the level of debug display for this material.
154
            What this debug level means is entirely depdendent on the generator, 
155
            the only constant is that 0 means 'no debug' and non-zero means 
156
            'some level of debugging', with any graduations in non-zero values
157
            being generator-specific.
158
        */
159
        void setDebugLevel(unsigned int dbg)
160
0
        {
161
0
            if (mDebugLevel != dbg)
162
0
            {
163
0
                mDebugLevel = dbg;
164
0
                _markChanged();
165
0
            }
166
0
        }
167
        /// Get the debug level of the material. 
168
0
        unsigned int getDebugLevel() const { return mDebugLevel; }
169
170
        /** Helper method to render a composite map.
171
        @param size The requested composite map size
172
        @param rect The region of the composite map to update, in image space
173
        @param mat The material to use to render the map
174
        @param destCompositeMap A TexturePtr for the composite map to be written into
175
        */
176
        void _renderCompositeMap(size_t size, const Rect& rect, const MaterialPtr& mat,
177
                                 const TexturePtr& destCompositeMap);
178
179
0
        Texture* _getCompositeMapRTT() { return mCompositeMapRTT; }
180
    protected:
181
        unsigned long long int mChangeCounter;
182
        TerrainLayerDeclaration mLayerDecl;
183
        unsigned int mDebugLevel;
184
        SceneManager* mCompositeMapSM;
185
        Camera* mCompositeMapCam;
186
        Texture* mCompositeMapRTT; // deliberately holding this by raw pointer to avoid shutdown issues
187
        Rectangle2D* mCompositeMapPlane;
188
        Light* mCompositeMapLight;
189
        SceneNode* mLightNode;
190
191
192
    };
193
194
    typedef SharedPtr<TerrainMaterialGenerator> TerrainMaterialGeneratorPtr;
195
196
    /** @} */
197
    /** @} */
198
199
}
200
#endif
201