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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
   Copyright (c) 2016 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 _HARDWARE_VIDEO_GFX_DEVICE_INL_H_
#define _HARDWARE_VIDEO_GFX_DEVICE_INL_H_

namespace Divide {

#define GFX_DEVICE GFXDevice::instance()
#define GFX_RENDER_BIN_SIZE \
    RenderPassManager::instance().getLastTotalBinSize(RenderStage::DISPLAY)
#define GFX_HIZ_CULL_COUNT \
    GFX_DEVICE.getLastCullCount()

inline F32 GFXDevice::GPUBlock::GPUData::aspectRatio() const {
    return _cameraPosition.w;
}

inline vec2<F32> GFXDevice::GPUBlock::GPUData::currentZPlanes() const {
    return _ZPlanesCombined.xy();
}

inline F32 GFXDevice::GPUBlock::GPUData::FoV() const {
    return _renderProperties.z;
}

inline F32 GFXDevice::GPUBlock::GPUData::tanHFoV() const {
    return _renderProperties.w;
}

inline void 
GFXDevice::NodeData::set(const GFXDevice::NodeData& other) {
    this->_worldMatrix.set(other._worldMatrix);
    this->_normalMatrixWV.set(other._normalMatrixWV);
    this->_colourMatrix.set(other._colourMatrix);
    this->_properties.set(other._properties);
}

inline void 
GFXDevice::ShaderBufferBinding::set(const GFXDevice::ShaderBufferBinding& other) {
    set(other._slot, other._buffer, other._range);
}

inline void
GFXDevice::ShaderBufferBinding::set(ShaderBufferLocation slot,
                                    ShaderBuffer* buffer,
                                    const vec2<U32>& range) {
    _slot = slot;
    _buffer = buffer;
    _range.set(range);
}

inline void 
GFXDevice::RenderPackage::clear() {
    _shaderBuffers.resize(0);
    _textureData.resize(0);
    _drawCommands.resize(0);
}

inline void 
GFXDevice::RenderPackage::set(const GFXDevice::RenderPackage& other) {
#if 0
    size_t shaderBufferSize = other._shaderBuffers.size();
    size_t textureDataSize = other._textureData.size();
    size_t drawCommandSize = other._drawCommands.size();

    _shaderBuffers.resize(shaderBufferSize);
    _textureData.resize(textureDataSize);
    _drawCommands.resize(drawCommandSize);
    for (size_t i = 0; i < shaderBufferSize; ++i) {
        _shaderBuffers.at(i).set(other._shaderBuffers.at(i));
    }

    for (size_t i = 0; i < textureDataSize; ++i) {
        _textureData.at(i).set(other._textureData.at(i));
    }

    for (size_t i = 0; i < drawCommandSize; ++i) {
        _drawCommands.at(i).set(other._drawCommands.at(i));
    }
#else
    _shaderBuffers = other._shaderBuffers;
    _textureData = other._textureData;
    _drawCommands = other._drawCommands;
#endif
}

inline void 
GFXDevice::RenderQueue::clear() {
    for (U32 idx = 0; idx < _currentCount; ++idx) {
        //_packages[idx].clear();
    }
    _currentCount = 0;
}

inline U32 
GFXDevice::RenderQueue::size() const {
    return _currentCount;
}

inline bool
GFXDevice::RenderQueue::locked() const {
    return _locked;
}

inline bool 
GFXDevice::RenderQueue::empty() const {
    return _currentCount == 0;
}

inline const GFXDevice::RenderPackage& 
GFXDevice::RenderQueue::getPackage(U32 idx) const {
    assert(idx < Config::MAX_VISIBLE_NODES);
    return _packages[idx];
}

inline GFXDevice::RenderPackage&
GFXDevice::RenderQueue::getPackage(U32 idx) {
    return _packages.at(idx);
}

inline GFXDevice::RenderPackage&
GFXDevice::RenderQueue::back() {
    return _packages.at(std::max(to_int(_currentCount) - 1, 0));
}

inline bool
GFXDevice::RenderQueue::push_back(const RenderPackage& package) {
    if (_currentCount <= Config::MAX_VISIBLE_NODES) {
        _packages.at(_currentCount++).set(package);
        return true;
    }
    return false;
}

inline void
GFXDevice::RenderQueue::reserve(U16 size) {
    _packages.resize(size);
}

inline void
GFXDevice::RenderQueue::lock() {
    _locked = true;
}

inline void
GFXDevice::RenderQueue::unlock() {
    _locked = false;
}

inline void
GFXDevice::RenderTargetWrapper::cacheSettings() {
    _renderSettings._aspectRatio = GFX_DEVICE.renderingData().aspectRatio();
    _renderSettings._zPlanes.set(GFX_DEVICE.renderingData().currentZPlanes());
    GFX_DEVICE.getMatrix(MATRIX::PROJECTION, _renderSettings._projectionMatrix);
    GFX_DEVICE.getMatrix(MATRIX::VIEW, _renderSettings._viewMatrix);
}

inline const GFXDevice::GPUBlock::GPUData&
GFXDevice::renderingData() const {
    return _gpuBlock._data;
}

inline void
GFXDevice::setViewport(I32 x, I32 y, I32 width, I32 height) {
    setViewport(vec4<I32>(x, y, width, height));
}

inline bool 
GFXDevice::isDepthStage() const {
    return getRenderStage() == RenderStage::SHADOW ||
           getRenderStage() == RenderStage::Z_PRE_PASS;
}

/// Query rasterization state
inline bool 
GFXDevice::rasterizationState() { 
    return _rasterizationEnabled; 
}

/// Toggle writes to the depth buffer on or off
inline void 
GFXDevice::toggleDepthWrites(bool state) {
    if(_zWriteEnabled == state) {
        return;
    }
    _zWriteEnabled = state;

    _api->toggleDepthWrites(state);
}


/// Toggle hardware rasterization on or off.
inline void 
GFXDevice::toggleRasterization(bool state) {
    if (_rasterizationEnabled == state) {
        return;
    }
    _rasterizationEnabled = state;

    _api->toggleRasterization(state);
}
/// Register a function to be called in the 2D rendering fase of the GFX Flush
/// routine. Use callOrder for sorting purposes
inline void 
GFXDevice::add2DRenderFunction(const DELEGATE_CBK<>& callback, U32 callOrder) {
    WriteLock w_lock(_2DRenderQueueLock);
    _2dRenderQueue.push_back(std::make_pair(callOrder, callback));

    std::sort(std::begin(_2dRenderQueue), std::end(_2dRenderQueue),
              [](const std::pair<U32, DELEGATE_CBK<> >& a,
                 const std::pair<U32, DELEGATE_CBK<> >& b)
                  -> bool { return a.first < b.first; });
}

/// Sets the current render stage.
///@param stage Is used to inform the rendering pipeline what we are rendering.
/// Shadows? reflections? etc
inline RenderStage 
GFXDevice::setRenderStage(RenderStage stage) {
    _prevRenderStage = _renderStage;
    _renderStage = stage;
    return stage;
}
/// disable or enable a clip plane by index
inline void 
GFXDevice::toggleClipPlane(ClipPlaneIndex index, const bool state) {
    assert(index != ClipPlaneIndex::COUNT);
    U32 idx = to_uint(index);
    if (state != _clippingPlanes[idx].active()) {
        _clippingPlanes[idx].active(state);
        _api->updateClipPlanes();
    }
}
/// modify a single clip plane by index
inline void 
GFXDevice::setClipPlane(ClipPlaneIndex index, const Plane<F32>& p) {
    assert(index != ClipPlaneIndex::COUNT);
    _clippingPlanes[to_uint(index)] = p;
    updateClipPlanes();
}
/// set a new list of clipping planes. The old one is discarded
inline void 
GFXDevice::setClipPlanes(const PlaneList& clipPlanes) {
    if (clipPlanes != _clippingPlanes) {
        _clippingPlanes = clipPlanes;
        updateClipPlanes();
        _api->updateClipPlanes();
    }
}
/// clear all clipping planes
inline void 
GFXDevice::resetClipPlanes() {
    _clippingPlanes.resize(Config::MAX_CLIP_PLANES, Plane<F32>(0, 0, 0, 0));
    updateClipPlanes();
    _api->updateClipPlanes();
}
/// Alternative to the normal version of getMatrix
inline const mat4<F32>& 
GFXDevice::getMatrix(const MATRIX& mode) {
    getMatrix(mode, _mat4Cache);
    return _mat4Cache;
}

/// Submit multiple draw commands that use the same source buffer (e.g. terrain or batched meshes)
inline void
GFXDevice::submitCommands(const vectorImpl<GenericDrawCommand>& cmds, bool useIndirectRender) {
    for (const GenericDrawCommand& cmd : cmds) {
        // Data validation is handled in the single command version
        submitCommand(cmd, useIndirectRender);
    }
}

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Platform/Video/Headers/GFXDevice.inl

Diff revisions: vs.
Revision Author Commited Message
727 Diff Diff IonutCava picture IonutCava Tue 14 Jun, 2016 16:01:38 +0000

[IonutCava]
- Remove node and cmd buffers from GFXDevice and add them as a new BufferData struct to RenderPass class.
— Each render pass holds its own buffers
- Improvements / fixes to the CSM code
- Added a global toggle to enable/disable custom memory allocators

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

718 Diff Diff IonutCava picture IonutCava Thu 02 Jun, 2016 16:02:48 +0000

[IonutCava]
- Code cleanup:
— Rename Framebuffer to RenderTarget. Only OpenGL uses the Framebuffer nomenclature.
— Remove base Shader class as only OpenGL will have separate shaders (and eventually move to pipeline objects) as Direct3D uses FX files and may end up with different structure
— Remove drawBox3D, drawSphere3D and drawLines from GFXDevice class and add them as member functions to the IMPrimitive class (renamed to fromXYZ)
— Pull some elements from SceneManager and move them to standalone classes (W.I.P.)

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

670 Diff Diff IonutCava picture IonutCava Wed 06 Apr, 2016 16:21:35 +0000

[IonutCava]
- getInstance() renamed to instance() for simplicity (should really go away altogether, but that’s a different issue)
- some particle emitter threading updates

664 Diff Diff IonutCava picture IonutCava Wed 30 Mar, 2016 16:23:51 +0000

[IonutCava]
- Split some render bin loops into multiple tasks
- Cleaned up the Task class
- Attempt to improve Console multithreaded performance (does not compile yet)

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

625 Diff Diff IonutCava picture IonutCava Mon 18 Jan, 2016 17:19:59 +0000

[IonutCava]
- Limit number of shader compilations per frame
- Add initial support for deferred SGN postLoad calls (think multi-threaded loading support in the future)
- Various small profile-guided optimizations
- Removed some indirections in draw command submission

621 IonutCava picture IonutCava Tue 12 Jan, 2016 16:39:50 +0000

[IonutCava]
- Terrain rendering updates
- Framebuffer optimizations