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
/*
   Copyright (c) 2014 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 _GENERIC_VERTEX_DATA_H
#define _GENERIC_VERTEX_DATA_H

#include "VertexDataInterface.h"

/// This class is used to upload generic VB data to the GPU that can be rendered directly or instanced.
/// Use this class to create precise VB data with specific usage (such as particle systems)
/// Use IMPrimitive for on-the-fly geometry creation

namespace Divide {

class GenericVertexData : public VertexDataInterface {
public:

    struct AttributeDescriptor {
        AttributeDescriptor() : _index(0), _divisor(0), _parentBuffer(0), 
                                _componentsPerElement(0), _normalized(false),
                                _stride(0), _type(UNSIGNED_INT), 
                                _wasSet(false), _elementCountOffset(0), _dirty(false)
        {
        }

        void set(U32 bufferIndex, 
                 U32 instanceDivisor, 
                 U32 componentsPerElement, 
                 bool normalized, 
                 size_t stride, 
                 U32 elementCountOffset, 
                 GFXDataFormat dataType) {

            this->bufferIndex(bufferIndex);
            this->instanceDivisor(instanceDivisor);
            this->componentsPerElement(componentsPerElement);
            this->normalized(normalized);
            this->stride(stride);
            this->offset(elementCountOffset);
            this->dataType(dataType);
        }

        inline void attribIndex(U32 index) {
            _index = index; 
            _dirty = true; 
        }

        inline void offset(U32 elementCountOffset) { 
            _elementCountOffset = elementCountOffset; 
            _dirty = true; 
        }

        inline void bufferIndex(U32 bufferIndex) { 
            _parentBuffer = bufferIndex; 
            _dirty = true; 
        }

        inline void instanceDivisor(U32 instanceDivisor) { 
            _divisor = instanceDivisor; 
            _dirty = true; 
        }

        inline void componentsPerElement(U32 componentsPerElement) { 
            _componentsPerElement = componentsPerElement; 
            _dirty = true; 
        }

        inline void normalized(bool normalized) { 
            _normalized = normalized; 
            _dirty = true; 
        }

        inline void stride(size_t stride) {
            _stride = stride; 
            _dirty = true; 
        }

        inline void dataType(GFXDataFormat type) { 
            _type = type; 
            _dirty = true; 
        }

        inline void wasSet(bool wasSet) { 
            _wasSet = wasSet; 
        }

        inline void clean() { 
            _dirty = false; 
        }

        inline U32           attribIndex()          const { return _index; }
        inline U32           offset()               const { return _elementCountOffset; }
        inline U32           bufferIndex()          const { return _parentBuffer; }
        inline U32           instanceDivisor()      const { return _divisor; }
        inline U32           componentsPerElement() const { return _componentsPerElement; }
        inline bool          normalized()           const { return _normalized; }
        inline size_t        stride()               const { return _stride; }
        inline GFXDataFormat dataType()             const { return _type; }
        inline bool          wasSet()               const { return _wasSet; }
        inline bool          dirty()                const { return _dirty; }

    protected:
        U32 _index;
        U32 _divisor;
        U32 _parentBuffer;
        U32 _componentsPerElement;
        U32 _elementCountOffset;
        bool _wasSet;
        bool _dirty;
        bool _normalized;
        size_t _stride;
        GFXDataFormat _type;
    
    };

    GenericVertexData(bool persistentMapped) : VertexDataInterface(), 
                                               _persistentMapped(persistentMapped)
    {
        _doubleBufferedQuery = true;
    }

    virtual ~GenericVertexData()
    {
        _attributeMapDraw.clear();
        _attributeMapFdbk.clear();
    }

    virtual void Create(U8 numBuffers = 1, U8 numQueries = 1) = 0;
    virtual void SetFeedbackBuffer(U32 buffer, U32 bindPoint) = 0;

    virtual void Draw(const GenericDrawCommand& command, bool skipBind = false) = 0;
    
    inline void Draw(const vectorImpl<GenericDrawCommand>& commands, bool skipBind = false) {
        for (const GenericDrawCommand& cmd : commands) {
            Draw(cmd, skipBind);
        }
    }
    
    /// When reading and writing to the same buffer, we use a round-robin approach and 
    /// offset the reading and writing to multiple copies of the data
    virtual void SetBuffer(U32 buffer, 
                           U32 elementCount, 
                           size_t elementSize, 
                           U8 sizeFactor, 
                           void* data, 
                           bool dynamic, 
                           bool stream, 
                           bool persistentMapped = false) = 0;

    virtual void UpdateBuffer(U32 buffer, 
                              U32 elementCount, 
                              U32 elementCountOffset, 
                              void* data, 
                              bool invalidateRange = false) = 0;

    virtual void BindFeedbackBufferRange(U32 buffer, 
                                         U32 elementCountOffset, 
                                         size_t elementCount) = 0;

    virtual U32  GetFeedbackPrimitiveCount(U8 queryID) = 0;
    /// Just before we render the frame
    virtual bool frameStarted(const FrameEvent& evt) { return true; }

    inline void toggleDoubleBufferedQueries(const bool state) { 
        _doubleBufferedQuery = state; 
    }

    inline AttributeDescriptor& getDrawAttribDescriptor(U32 attribIndex) { 
        AttributeDescriptor& desc = _attributeMapDraw[attribIndex]; 
        desc.attribIndex(attribIndex); 
        return desc; 
    }

    inline AttributeDescriptor& getFdbkAttribDescriptor(U32 attribIndex) { 
        AttributeDescriptor& desc = _attributeMapFdbk[attribIndex]; 
        desc.attribIndex(attribIndex);
        return desc; 
    }

protected:
    typedef hashMapImpl<U32, AttributeDescriptor > attributeMap;
    bool _persistentMapped;
    bool _doubleBufferedQuery;
    vectorImpl<U32 > _feedbackBuffers;
    vectorImpl<U32 > _bufferObjects;
    attributeMap _attributeMapDraw;
    attributeMap _attributeMapFdbk;
};

}; //namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Hardware/Video/Buffers/VertexBuffer/Headers/GenericVertexData.h

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

302 Diff Diff IonutCava picture IonutCava Wed 06 Aug, 2014 22:09:55 +0000

[Ionut]
- GenericVertexData buffer size (for read/write buffering) is now configurable instead of a fixed 3x and also applies to non-persistently mapped buffers
- Moved OpenGL enum tables to Divide::GLUtil::GL_ENUM_TABLE
- More code cleanups (glResources, glError, glVertexArray, glGenericVertexData, glIMPrimitive)

292 Diff Diff k1ngp1n picture k1ngp1n Mon 28 Jul, 2014 20:23:56 +0000

[Ionut]
- More nVidia compatibility issues (including the ability to disable persistent mapped buffer altogether. Thanks nsight ....)
- Cross-platform compatibility fixes for types (custom types now mirror types in stdint.h and are now typdefed instead of defined)
- Removed redundant files

288 Diff Diff IonutCava picture IonutCava Wed 23 Jul, 2014 20:34:25 +0000

[Ionut]
- Added a common interface to GenericVertexData and VertexBuffer
- Removed deferred deletion of FrameListeners from FrameListenerManager. It complicated the code with no added benefit
- Added proper FrameListener unregister calls

286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

279 Diff Diff IonutCava picture IonutCava Sat 28 Jun, 2014 16:20:46 +0000

[Ionut][[BR]]
- Unified draw command system into GenericDrawCommand [[BR]]
- Fixed double VB creation in Object3D [[BR]]
- Reworked triangle data computation (now Object3D’s responsibility) [[BR]]
- VertexArrays can now render using the primitive type specified in the draw command instead of the fixed type specified at creation [[BR]]
- Optimized terrain shader [[BR]]

276 Diff Diff IonutCava picture IonutCava Fri 13 Jun, 2014 18:23:32 +0000

[Ionut][[BR]]
- Terrain now inherits from Object3D (instead of directly from SceneNode) [[BR]]
- Restructured RenderInstance to support multiple draw commands [[BR]]
— Multiple draw commands per instance are separated to different LoD batches automatically on render [[BR]]

274 IonutCava picture IonutCava Fri 13 Jun, 2014 12:56:03 +0000

[Ionut] [[BR]]
- Simplified buffer based rendering (VertexBuffer & GenericVertexData are now exclusively command based) [[BR]]
- Update bone buffer to persistent mapped-SSBO system with double-buffering [[BR]]
- Simplified sky rendering and (finally) reduced the sun’s radius [[BR]]