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
#include "stdafx.h"

#include "Headers/RenderStateBlock.h"

#include "Platform/Video/Headers/GFXDevice.h"

namespace Divide {

RenderStateBlock::RenderStateMap RenderStateBlock::s_stateBlockMap;
SharedLock RenderStateBlock::s_stateBlockMapMutex;
size_t RenderStateBlock::s_defaultCacheValue = 0;

RenderStateBlock::RenderStateBlock()
    : GUIDWrapper(), 
     _cachedHash(0)
{
    setDefaultValues();
    clean();
    if (s_defaultCacheValue == 0) {
        s_defaultCacheValue = _cachedHash;
    }
}

RenderStateBlock::RenderStateBlock(const RenderStateBlock& other)
    : GUIDWrapper(other),
     _colourWrite(other._colourWrite),
     _cullMode(other._cullMode),
     _cullEnabled(other._cullEnabled),
     _zEnable(other._zEnable),
     _zFunc(other._zFunc),
     _zBias(other._zBias),
     _zUnits(other._zUnits),
     _stencilEnable(other._stencilEnable),
     _stencilRef(other._stencilRef),
     _stencilMask(other._stencilMask),
     _stencilWriteMask(other._stencilWriteMask),
     _stencilFailOp(other._stencilFailOp),
     _stencilZFailOp(other._stencilZFailOp),
     _stencilPassOp(other._stencilPassOp),
     _stencilFunc(other._stencilFunc),
     _fillMode(other._fillMode),
     _cachedHash(other._cachedHash)
{
}

void RenderStateBlock::flipCullMode() {
    if (_cullMode == CullMode::NONE) {
        _cullMode = CullMode::ALL;
    }
    if (_cullMode == CullMode::ALL) {
        _cullMode = CullMode::NONE;
    }
    if (_cullMode == CullMode::CW) {
        _cullMode = CullMode::CCW;
    }
    if (_cullMode == CullMode::CCW) {
        _cullMode = CullMode::CW;
    }
    clean();
}

void RenderStateBlock::setCullMode(CullMode mode) {
    _cullMode = mode;
    _cullEnabled = _cullMode == CullMode::NONE ? false : true;
    clean();
}

void RenderStateBlock::setZRead(const bool enable) {
    _zEnable = enable;

    clean();
}

void RenderStateBlock::setColourWrites(bool red,
                                       bool green,
                                       bool blue,
                                       bool alpha) {
    _colourWrite.b[0] = red ? 1 : 0;
    _colourWrite.b[1] = green ? 1 : 0;
    _colourWrite.b[2] = blue ? 1 : 0;
    _colourWrite.b[3] = alpha ? 1 : 0;

    clean();
}

void RenderStateBlock::setZBias(F32 zBias, F32 zUnits) {
    _zBias = zBias;
    _zUnits = zUnits;

    clean();
}

void RenderStateBlock::setZFunc(ComparisonFunction zFunc) {
    _zFunc = zFunc;

    clean();
}

void RenderStateBlock::setFillMode(FillMode mode) {
    _fillMode = mode;

    clean();
}

void RenderStateBlock::setStencilReadWriteMask(U32 read, U32 write) {
    _stencilMask = read;
    _stencilWriteMask = write;

    clean();
}

void RenderStateBlock::setStencil(bool enable,
                                  U32 stencilRef,
                                  StencilOperation stencilFailOp,
                                  StencilOperation stencilZFailOp,
                                  StencilOperation stencilPassOp,
                                  ComparisonFunction stencilFunc) {
    _stencilEnable = enable;
    _stencilRef = stencilRef;
    _stencilFailOp = stencilFailOp;
    _stencilZFailOp = stencilZFailOp;
    _stencilPassOp = stencilPassOp;
    _stencilFunc = stencilFunc;

    clean();
}

void RenderStateBlock::setDefaultValues() {
    _zBias = 0.0f;
    _zUnits = 1.0f;
    _zFunc = ComparisonFunction::LEQUAL;
    _colourWrite.b[0] = _colourWrite.b[1] = _colourWrite.b[2] = _colourWrite.b[3] = 1;
    _zEnable = true;
    _cullMode = CullMode::CW;
    _cullEnabled = true;
    _fillMode = FillMode::SOLID;
    _stencilMask = 0xFFFFFFFF;
    _stencilWriteMask = 0xFFFFFFFF;
    _stencilEnable = false;
    _stencilRef = 0;
    _stencilFailOp = StencilOperation::KEEP;
    _stencilZFailOp = StencilOperation::KEEP;
    _stencilPassOp = StencilOperation::KEEP;
    _stencilFunc = ComparisonFunction::NEVER;
    _cachedHash = s_defaultCacheValue;
}

void RenderStateBlock::clean() {
    size_t previousCache = _cachedHash;

    // Avoid small float rounding errors offsetting the general hash value
    U32 zBias = to_U32(std::floor((_zBias * 1000.0f) + 0.5f));
    U32 zUnits = to_U32(std::floor((_zUnits * 1000.0f) + 0.5f));

    _cachedHash = 0;
    Util::Hash_combine(_cachedHash, _colourWrite.i);
    Util::Hash_combine(_cachedHash, to_U32(_cullMode));
    Util::Hash_combine(_cachedHash, _cullEnabled);
    Util::Hash_combine(_cachedHash, _zEnable);
    Util::Hash_combine(_cachedHash, to_U32(_zFunc));
    Util::Hash_combine(_cachedHash, zBias);
    Util::Hash_combine(_cachedHash, zUnits);
    Util::Hash_combine(_cachedHash, _stencilEnable);
    Util::Hash_combine(_cachedHash, _stencilRef);
    Util::Hash_combine(_cachedHash, _stencilMask);
    Util::Hash_combine(_cachedHash, _stencilWriteMask);
    Util::Hash_combine(_cachedHash, to_U32(_stencilFailOp));
    Util::Hash_combine(_cachedHash, to_U32(_stencilZFailOp));
    Util::Hash_combine(_cachedHash, to_U32(_stencilPassOp));
    Util::Hash_combine(_cachedHash, to_U32(_stencilFunc));
    Util::Hash_combine(_cachedHash, to_U32(_fillMode));

    if (previousCache != _cachedHash) {
        WriteLock w_lock(s_stateBlockMapMutex);
        hashAlg::emplace(s_stateBlockMap, _cachedHash, *this);
    }
}

void RenderStateBlock::init() {
}

void RenderStateBlock::clear() {
    WriteLock w_lock(s_stateBlockMapMutex);
    s_stateBlockMap.clear();
}

/// Return the render state block defined by the specified hash value.
const RenderStateBlock& RenderStateBlock::get(size_t renderStateBlockHash) {
    bool blockFound = false;
    const RenderStateBlock& block = get(renderStateBlockHash, blockFound);
    // Assert if it doesn't exist. Avoids programming errors.
    DIVIDE_ASSERT(blockFound, "RenderStateBlock error: Invalid render state block hash specified for getRenderStateBlock!");
    // Return the state block's descriptor
    return block;
}

const RenderStateBlock& RenderStateBlock::get(size_t renderStateBlockHash, bool& blockFound) {
    blockFound = false;

    ReadLock r_lock(s_stateBlockMapMutex);
    // Find the render state block associated with the received hash value
    RenderStateMap::const_iterator it = s_stateBlockMap.find(renderStateBlockHash);
    if(it != std::cend(s_stateBlockMap) ) {
        blockFound = true;
        return it->second;
    }

    return s_stateBlockMap.find(s_defaultCacheValue)->second;
}

};

Commits for Divide-Framework/trunk/Source Code/Platform/Video/RenderStateBlock.cpp

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

821 Diff Diff IonutCava picture IonutCava Tue 17 Jan, 2017 17:15:45 +0000

[IonutCava]
- Profile guided optimizations

818 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations

799 Diff Diff IonutCava picture IonutCava Thu 24 Nov, 2016 22:55:23 +0000

[IonutCava]
- Performance analysis guided optimizations.

771 Diff Diff IonutCava picture IonutCava Tue 27 Sep, 2016 15:39:49 +0000

[IonutCava]
- Modify GFXDevice::flushRenderQueues so that it creates command buffers instead of directly calling rendering calls:
— Command buffers contain buffer, shader, texture and geometry info
— Command buffer state is now parsed and set at the API level instead of GFXDevice level
— This will allow easier porting to low level APIs later on
- Indirect draw is now a GenericDrawCommand render option instead of an explicit buffer draw parameter

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

721 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