Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
   Copyright (c) 2015 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _TERRAIN_H_
#define _TERRAIN_H_

#include "Geometry/Shapes/Headers/Object3D.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Core/Math/BoundingVolumes/Headers/BoundingBox.h"
#include "Environment/Vegetation/Headers/Vegetation.h"
#include "Environment/Terrain/Quadtree/Headers/Quadtree.h"
#include "Platform/Video/Buffers/VertexBuffer/Headers/VertexBuffer.h"

namespace Divide {

class TerrainLoader;

struct TerrainTextureLayer {
    TerrainTextureLayer() {
        _lastOffset = 0;
        _blendMap = nullptr;
        _tileMaps = nullptr;
        _normalMaps = nullptr;
    }

    ~TerrainTextureLayer();

    enum class TerrainTextureChannel : U32 {
        TEXTURE_RED_CHANNEL = 0,
        TEXTURE_GREEN_CHANNEL = 1,
        TEXTURE_BLUE_CHANNEL = 2,
        TEXTURE_ALPHA_CHANNEL = 3
    };

    inline void setBlendMap(Texture* const texture) { _blendMap = texture; }
    inline void setTileMaps(Texture* const texture) { _tileMaps = texture; }
    inline void setNormalMaps(Texture* const texture) { _normalMaps = texture; }
    inline void setDiffuseScale(TerrainTextureChannel textureChannel,
                                F32 scale) {
        _diffuseUVScale[to_uint(textureChannel)] = scale;
    }
    inline void setDetailScale(TerrainTextureChannel textureChannel,
                               F32 scale) {
        _detailUVScale[to_uint(textureChannel)] = scale;
    }

    inline const vec4<F32>& getDiffuseScales() const { return _diffuseUVScale; }
    inline const vec4<F32>& getDetailScales() const { return _detailUVScale; }

    Texture* const blendMap() const { return _blendMap; }
    Texture* const tileMaps() const { return _tileMaps; }
    Texture* const normalMaps() const { return _normalMaps; }

   private:
    U32 _lastOffset;
    vec4<F32> _diffuseUVScale;
    vec4<F32> _detailUVScale;
    Texture* _blendMap;
    Texture* _tileMaps;
    Texture* _normalMaps;
};

class Quad3D;
class Quadtree;
class Transform;
class VertexBuffer;
class ShaderProgram;
class SamplerDescriptor;
class TerrainDescriptor;

namespace Attorney {
    class TerrainChunk;
    class TerrainLoader;
};

class Terrain : public Object3D {
    friend class Attorney::TerrainChunk;
    friend class Attorney::TerrainLoader;

   public:
    Terrain();
    ~Terrain();

    bool unload();

    void postDrawBoundingBox(SceneGraphNode& sgn) const;
    inline void toggleBoundingBoxes() { _drawBBoxes = !_drawBBoxes; }

    vec3<F32> getPositionFromGlobal(F32 x, F32 z) const;
    vec3<F32> getPosition(F32 x_clampf, F32 z_clampf) const;
    vec3<F32> getNormal(F32 x_clampf, F32 z_clampf) const;
    vec3<F32> getTangent(F32 x_clampf, F32 z_clampf) const;
    const vec2<F32> getDimensions() {
        return vec2<F32>(_terrainDimensions.x, _terrainDimensions.y);
    }

    inline const Quadtree& getQuadtree() const { return _terrainQuadtree; }

    bool computeBoundingBox(SceneGraphNode& sgn);

   protected:
    bool getDrawCommands(SceneGraphNode& sgn,
                         RenderStage renderStage,
                         const SceneRenderState& sceneRenderState,
                         vectorImpl<GenericDrawCommand>& drawCommandsOut) override;

    void sceneUpdate(const U64 deltaTime, SceneGraphNode& sgn,
                     SceneState& sceneState);

    void buildQuadtree();
    void postLoad(SceneGraphNode& sgn);

    bool isInView(const SceneRenderState& sceneRenderState,
                  SceneGraphNode& sgn, const bool distanceCheck = true);

   protected:
    VegetationDetails _vegDetails;

    U8 _lightCount;
    vec2<U16> _terrainDimensions;
    U32 _chunkSize;
    Quadtree _terrainQuadtree;

    vec2<F32> _terrainScaleFactor;
    F32 _farPlane;
    bool _alphaTexturePresent;
    bool _drawBBoxes;
    bool _terrainInView;
    bool _planeInView;
    SceneGraphNode_wptr _vegetationGrassNode;
    BoundingBox _boundingBox;
    Quad3D* _plane;
    F32 _underwaterDiffuseScale;
    vectorImpl<TerrainTextureLayer*> _terrainTextures;
    SamplerDescriptor* _albedoSampler;
    SamplerDescriptor* _normalSampler;

    vectorImpl<TerrainChunk*> _terrainChunks;
    std::array<U32, to_const_uint(RenderStage::COUNT)> _terrainStateHash;
};

namespace Attorney {
class TerrainChunk {
   private:
    static VegetationDetails& vegetationDetails(Terrain& terrain) {
        return terrain._vegDetails;
    }
    static void registerTerrainChunk(Terrain& terrain,
                                     Divide::TerrainChunk* const chunk) {
        terrain._terrainChunks.push_back(chunk);
    }
    friend class Divide::TerrainChunk;
};

class TerrainLoader {
   private:
    static void setUnderwaterDiffuseScale(Terrain& terrain, F32 diffuseScale) {
        terrain._underwaterDiffuseScale = diffuseScale;
    }
    /// Per terrain albedo sampler
    static const SamplerDescriptor& getAlbedoSampler(Terrain& terrain) {
        return *terrain._albedoSampler;
    }
    static const SamplerDescriptor& getNormalSampler(Terrain& terrain) {
        return *terrain._normalSampler;
    }
    static void addTextureLayer(Terrain& terrain,
                                TerrainTextureLayer* textureLayer) {
        terrain._terrainTextures.push_back(textureLayer);
    }
    static U32 textureLayerCount(Terrain& terrain) {
        return to_uint(terrain._terrainTextures.size());
    }

    static void setRenderStateHashes(Terrain& terrain,
                                     U32 normalStateHash,
                                     U32 reflectionStateHash,
                                     U32 depthStateHash) {
        terrain._terrainStateHash[to_uint(RenderStage::DISPLAY)] = normalStateHash;
        terrain._terrainStateHash[to_uint(RenderStage::Z_PRE_PASS)] = normalStateHash;
        terrain._terrainStateHash[to_uint(RenderStage::REFLECTION)] = reflectionStateHash;
        terrain._terrainStateHash[to_uint(RenderStage::SHADOW)] = depthStateHash;
    }
    static VegetationDetails& vegetationDetails(Terrain& terrain) {
        return terrain._vegDetails;
    }
    static void buildQuadtree(Terrain& terrain) { terrain.buildQuadtree(); }
    static BoundingBox& boundingBox(Terrain& terrain) {
        return terrain._boundingBox;
    }
    static F32& farPlane(Terrain& terrain) { return terrain._farPlane; }
    static Quad3D* plane(Terrain& terrain) { return terrain._plane; }
    static vec2<U16>& dimensions(Terrain& terrain) {
        return terrain._terrainDimensions;
    }
    static vec2<F32>& scaleFactor(Terrain& terrain) {
        return terrain._terrainScaleFactor;
    }
    static U32& chunkSize(Terrain& terrain) { return terrain._chunkSize; }

    friend class Divide::TerrainLoader;
};

};  // namespace Attorney
};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Environment/Terrain/Headers/Terrain.h

Diff revisions: vs.
Revision Author Commited Message
557 Diff Diff IonutCava picture IonutCava Tue 10 Nov, 2015 12:00:20 +0000

[IonutCava]
- Gather all rendering calls from glVertexArray and glGenericVertexData into a single function in glResources: submitRenderCommand.
— This allows both classes to interpret GenericDrawCommands in the same way
- Use unsigned ints for all hasehs instead of size_t to avoid negative number hashes (useful for debugging)

524 Diff Diff IonutCava picture IonutCava Thu 08 Oct, 2015 16:14:58 +0000

[IonutCava]
- Profiler guided optimizations:
— Replace most hashMaps with vectors where the common access pattern is linear (e.g. SceneGraphNode’s child list)
— Specify ShaderBuffer access patters at creation time to properly inform the rendering API
— Fix and optimise the LockManager & BufferLockManager classes
— Add a AtomicWrapper class that allows assignment and copy-constructions for atomic variables
-— This allows us to use vector of atomic bools for BB creation for SkinnedSubMesh objects

505 Diff Diff IonutCava picture IonutCava Tue 25 Aug, 2015 22:15:49 +0000

[IonutCava]
- Finish the draw command caching System
- Cleanup AnimationComponent class

504 Diff Diff IonutCava picture IonutCava Tue 25 Aug, 2015 16:17:38 +0000

[IonutCava]
- Better caching of draw commands (W.I.P.)
- Remove unused occlusion culling code. Will be replaced with Hi-Z based culling

484 Diff Diff IonutCava picture IonutCava Sun 09 Aug, 2015 13:48:51 +0000

[Ionut]
- Use explicit attribute locations with IMPrimitive objects (reducing the number of glGetAttribLocation calls to zero)
- Remove “renderCallback” system in scenes as it wasn’t used and caused unnecessary indirections
- A few cleanups and const correctness changes

444 Diff Diff IonutCava picture IonutCava Thu 21 May, 2015 16:06:53 +0000

[Ionut]
- More platform independent code cleanup:
— Moved platform specific defines to their respective header files (e.g. THREAD_LOCAL)
— Moved most preprocessor defines from the VisualC++ projects into source code
— Removed compiler specific code (e.g. warning disables) and fixed most warning resulting from this

438 Diff Diff IonutCava picture IonutCava Fri 15 May, 2015 15:46:43 +0000

[Ionut]
- SceneGraphNodes are now stored as shared pointers and Units/AI entities reference them with std::weak_ptr
— ToDo: Make constructor/destructor private again. (made public as a temporary hack to make it work with std::shared_ptr)
- SceneGraphNode’s children map is now read/updated with proper locking mechanism to avoid threading issues (e.g. AI tries to delete a node and rendering thread tries to read material data from it at the same time)
- GL_API does not need to store the previous shader program, just the previous shader program handle.
— Previous responsibilities shifted to glShaderProgram

422 Diff Diff IonutCava picture IonutCava Tue 05 May, 2015 20:33:47 +0000

[Ionut]
- Bug fixes for the previous commit
- Replace most static_cast<U32/I32> with to_int / to_uint

389 Diff Diff IonutCava picture IonutCava Thu 26 Mar, 2015 17:14:11 +0000

[Ionut]
- More rendering pipeline refactoring:
— Implemented temporary hack of binding a subrange of the nodebuffer to avoid using gl_BaseInstanceARB and just use gl_DrawIDARB for indexing data (works fine)
— Matrix data is only generated if we got valid rendering commands from a certain node
- Moved all *Attorney classes to an Attorney namespace
- Fixed a bug with caching uniform values in glShaderProgram
- Added some robustness checks to glUniformBuffer

384 IonutCava picture IonutCava Mon 23 Mar, 2015 22:29:00 +0000

[Ionut]
- More work on the material system and shader generation