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
/*
   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 VEGETATION_H_
#define VEGETATION_H_

#include "Utility/Headers/ImageTools.h"
#include "Graphs/Headers/SceneNode.h"
#include "Platform/Threading/Headers/Task.h"
#include "Platform/Video/Headers/RenderAPIWrapper.h"

namespace Divide {

class Terrain;
class Texture;
class Transform;
class SceneState;
class Framebuffer;
class ShaderBuffer;
class TerrainChunk;
class ShaderProgram;
class SceneGraphNode;
class RenderStateBlock;
class GenericVertexData;
enum class RenderStage : U32;

struct VegetationDetails {
    U16 billboardCount;
    F32 grassDensity;
    F32 grassScale;
    F32 treeDensity;
    F32 treeScale;
    stringImpl map;
    stringImpl name;
    stringImpl grassShaderName;
    Terrain* parentTerrain;
    Texture* grassBillboards;
};

/// Generates grass and trees on the terrain.
/// Grass VB's + all resources are stored locally in the class.
/// Trees are added to the SceneGraph and handled by the scene.
class Vegetation : public SceneNode {
   public:
    Vegetation(const VegetationDetails& details);
    ~Vegetation();

    void initialize(TerrainChunk* const terrainChunk);

    inline void toggleRendering(bool state) { _render = state; }

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

    inline bool isInView(const SceneRenderState& sceneRenderState,
                         SceneGraphNode& sgn,
                         const bool distanceCheck = true) override {
        return true;
    }

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

    bool onDraw(SceneGraphNode& sgn, RenderStage renderStage)  override;

    void gpuCull();

   private:
    void uploadGrassData();
    void generateTrees();
    void generateGrass();

    U32 getQueryID();

   private:
    enum class CullType : U32 {
        PASS_THROUGH = 0,
        INSTANCE_CLOUD_REDUCTION = 1,
        HI_Z_CULL = 2,
        COUNT
    };
    // variables
    bool _render;  ///< Toggle vegetation rendering On/Off
    bool _success;
    std::atomic_bool _threadedLoadComplete;
    std::atomic_bool _stopLoadingRequest;
    Terrain* _terrain;
    TerrainChunk* _terrainChunk;
    F32 _grassDensity, _treeDensity;
    U16 _billboardCount;  ///< Vegetation cumulated density
    F32 _grassSize, _grassScale, _treeScale;
    F32 _windX, _windZ, _windS, _time;
    U64 _stateRefreshInterval;
    U64 _stateRefreshIntervalBuffer;
    ImageTools::ImageData _map;  ///< Dispersion map for vegetation placement
    Texture* _grassBillboards;
    ShaderProgram* _cullShader;
    stringImpl _grassShaderName;
    bool _shadowMapped;
    U32  _grassStateBlockHash;
    bool _culledFinal;
    U32 _readBuffer;
    U32 _writeBuffer;
    U32 _instanceCountGrass;
    U32 _instanceCountTrees;
    std::array<U32, to_const_uint(CullType::COUNT)> _instanceRoutineIdx;
    vectorImpl<F32> _grassScales;
    vectorImpl<vec4<F32> > _grassPositions;
    GenericVertexData* _grassGPUBuffer[2];
    GenericVertexData* _treeGPUBuffer[2];
    Task_ptr _generateVegetation;
    ShaderBuffer* _grassMatrices;
    static bool _staticDataUpdated;
    GenericDrawCommand _cullDrawCommand;
};

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Environment/Vegetation/Headers/Vegetation.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)

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

499 Diff Diff IonutCava picture IonutCava Thu 20 Aug, 2015 21:22:10 +0000

[IonutCava]
- UBO/SSBO proper alignment fixed (finally)
- ShaderBuffer class cleanup

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

395 Diff Diff IonutCava picture IonutCava Wed 01 Apr, 2015 16:06:28 +0000

[Ionut]
- Shader management improvements
- More singleton fixes
- Automatic core count detection and threadpool adjustment at startup
- Replaced most static C-arrays with std::array
- Replace most file manipulation code from C-style FILE based system to ifstream/ofstream

379 Diff Diff IonutCava picture IonutCava Thu 19 Mar, 2015 17:13:02 +0000

[Ionut]
- More batching work:
— Implemented a RenderQueue where all draw commands are gathered but only sent to the GPU on a “flush” command. (currently, one flush per render bin pass)
— RenderQueue holds RenderPackage (former NodeRenderData) and tries to batch the draw commands into the previous package if ShaderBuffer and TextureData between the 2 packages is compatible (currently disabled as some ShaderBuffer rendering glitches appear with animated data)
— RenderingComponent looses the “render” member as rendering commands are queued and postDraw calls are delegated to the renderbin pass

374 Diff Diff IonutCava picture IonutCava Tue 17 Mar, 2015 00:07:27 +0000

[Ionut]
- Streamlined the rendering pipeline:
— Removed the “render” method from all SceneNode derived classes. All pre-draw operations should be handled in “onDraw”.
— Modified the RenderPassCuller to use a custom culling function to determine if a node should be rendered or not (not affecting the visibility test result).
- Modified projects to use AVX instructions if available.

366 Diff Diff IonutCava picture IonutCava Tue 10 Mar, 2015 16:56:30 +0000

[Ionut]
- More type safe enum replacement

364 IonutCava picture IonutCava Fri 06 Mar, 2015 16:55:21 +0000

[Ionut]
- Part 1 of type safe enum replacement (does not compile)