/src/ogre/Components/Terrain/include/OgreTerrainLayerBlendMap.h
Line | Count | Source (jump to first uncovered line) |
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_TerrainLayerBlendMap_H__ |
30 | | #define __Ogre_TerrainLayerBlendMap_H__ |
31 | | |
32 | | #include "OgreTerrainPrerequisites.h" |
33 | | #include "OgreCommon.h" |
34 | | #include "OgreDataStream.h" |
35 | | #include "OgreImage.h" |
36 | | |
37 | | namespace Ogre |
38 | | { |
39 | | class Image; |
40 | | /** \addtogroup Optional |
41 | | * @{ |
42 | | */ |
43 | | /** \addtogroup Terrain |
44 | | * Some details on the terrain component |
45 | | * @{ |
46 | | */ |
47 | | |
48 | | |
49 | | /** Class exposing an interface to a blend map for a given layer. |
50 | | Each layer after the first layer in a terrain has a blend map which |
51 | | expresses how it is alpha blended with the layers beneath. Internally, this |
52 | | blend map is packed into one channel of an RGBA texture in |
53 | | order to use the smallest number of samplers, but this class allows |
54 | | a caller to manipulate the data more easily without worrying about |
55 | | this packing. Also, the values you use to interact with the blend map are |
56 | | floating point, which gives you full precision for updating, but in fact the |
57 | | values are packed into 8-bit integers in the actual blend map. |
58 | | @par |
59 | | You shouldn't construct this class directly, use Terrain::getLayerBlendMap(). |
60 | | */ |
61 | | class _OgreTerrainExport TerrainLayerBlendMap : public TerrainAlloc |
62 | | { |
63 | | Terrain* mParent; |
64 | | uint8 mLayerIdx; |
65 | | uint8 mChannel; // RGBA |
66 | | uint8 mChannelOffset; // in pixel format |
67 | | Box mDirtyBox; |
68 | | bool mDirty; |
69 | | HardwarePixelBuffer* mBuffer; |
70 | | Image mData; |
71 | | |
72 | | void download(); |
73 | | void upload(); |
74 | | |
75 | | public: |
76 | | /** Constructor |
77 | | @param parent The parent terrain |
78 | | @param layerIndex The layer index (should be 1 or higher) |
79 | | @param buf The buffer holding the data |
80 | | */ |
81 | | TerrainLayerBlendMap(Terrain* parent, uint8 layerIndex, HardwarePixelBuffer* buf); |
82 | | virtual ~TerrainLayerBlendMap(); |
83 | | /// Get the parent terrain |
84 | 0 | Terrain* getParent() const { return mParent; } |
85 | | /// Get the index of the layer this is targeting |
86 | 0 | uint8 getLayerIndex() const { return mLayerIdx; } |
87 | | |
88 | | /** Helper method - convert a point in world space to UV space based on the |
89 | | terrain settings. |
90 | | @param worldPos World position |
91 | | @param outX, outY Pointers to variables which will be filled in with the |
92 | | local UV space value. Note they are deliberately signed Real values, because the |
93 | | point you supply may be outside of image space and may be between texels. |
94 | | The values will range from 0 to 1, top/bottom, left/right. |
95 | | */ |
96 | | void convertWorldToUVSpace(const Vector3& worldPos, Real *outX, Real* outY); |
97 | | |
98 | | /** Helper method - convert a point in local space to worldspace based on the |
99 | | terrain settings. |
100 | | @param x,y Local position, ranging from 0 to 1, top/bottom, left/right. |
101 | | @param outWorldPos Pointer will be filled in with the world space value |
102 | | */ |
103 | | void convertUVToWorldSpace(Real x, Real y, Vector3* outWorldPos); |
104 | | |
105 | | /** Convert local space values (0,1) to image space (0, imageSize). |
106 | | */ |
107 | | void convertUVToImageSpace(Real x, Real y, size_t* outX, size_t* outY); |
108 | | /** Convert image space (0, imageSize) to local space values (0,1). |
109 | | */ |
110 | | void convertImageToUVSpace(size_t x, size_t y, Real* outX, Real* outY); |
111 | | /** Convert image space (0, imageSize) to terrain space values (0,1). |
112 | | */ |
113 | | void convertImageToTerrainSpace(size_t x, size_t y, Real* outX, Real* outY); |
114 | | /** Convert terrain space values (0,1) to image space (0, imageSize). |
115 | | */ |
116 | | void convertTerrainToImageSpace(Real x, Real y, size_t* outX, size_t* outY); |
117 | | |
118 | | /** Get a single value of blend information, in image space. |
119 | | @param x,y Coordinates of the point of data to get, in image space (top down) |
120 | | @return The blend data |
121 | | */ |
122 | | float getBlendValue(uint32 x, uint32 y); |
123 | | |
124 | | /** Set a single value of blend information (0 = transparent, 255 = solid) |
125 | | @param x,y Coordinates of the point of data to get, in image space (top down) |
126 | | @param val The blend value to set (0..1) |
127 | | */ |
128 | | void setBlendValue(uint32 x, uint32 y, float val); |
129 | | |
130 | | /** Get a pointer to the whole blend data. |
131 | | |
132 | | This method allows you to get a raw pointer to all the blend data, to |
133 | | update it as you like. However, you must then call dirtyRect manually |
134 | | if you want those changes to be recognised. |
135 | | */ |
136 | | float* getBlendPointer(); |
137 | | |
138 | | /** Indicate that all of the blend data is dirty and needs updating. |
139 | | */ |
140 | | void dirty(); |
141 | | |
142 | | /** Indicate that a portion of the blend data is dirty and needs updating. |
143 | | @param rect Rectangle in image space |
144 | | */ |
145 | | void dirtyRect(const Rect& rect); |
146 | | |
147 | | /** Blits a set of values into a region on the blend map. |
148 | | @param src PixelBox containing the source pixels and format |
149 | | @param dstBox Box describing the destination region in this map |
150 | | @remarks The source and destination regions dimensions don't have to match, in which |
151 | | case scaling is done. |
152 | | @note You can call this method in a background thread if you want. |
153 | | You still need to call update() to commit the changes to the GPU. |
154 | | */ |
155 | | void blit(const PixelBox &src, const Box &dstBox); |
156 | | |
157 | | /** Blits a set of values into the entire map. The source data is scaled if needed. |
158 | | @param src PixelBox containing the source pixels and format |
159 | | @note You can call this method in a background thread if you want. |
160 | | You still need to call update() to commit the changes to the GPU. |
161 | | |
162 | | */ |
163 | | void blit(const PixelBox &src); |
164 | | |
165 | | /** Load an image into this blend layer. |
166 | | */ |
167 | | void loadImage(const Image& img); |
168 | | |
169 | | /** Load an image into this blend layer. |
170 | | @param stream Stream containing the image data |
171 | | @param ext Extension identifying the image type, if the stream data doesn't identify |
172 | | */ |
173 | | void loadImage(DataStreamPtr& stream, const String& ext = BLANKSTRING); |
174 | | |
175 | | /** Load an image into this blend layer. |
176 | | */ |
177 | | void loadImage(const String& filename, const String& groupName); |
178 | | |
179 | | /** Publish any changes you made to the blend data back to the blend map. |
180 | | @note |
181 | | Can only be called in the main render thread. |
182 | | */ |
183 | | void update(); |
184 | | |
185 | | |
186 | | }; |
187 | | |
188 | | typedef std::vector<TerrainLayerBlendMap*> TerrainLayerBlendMapList; |
189 | | |
190 | | /** @} */ |
191 | | /** @} */ |
192 | | |
193 | | } |
194 | | |
195 | | |
196 | | |
197 | | #endif |