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
#include "Headers/GenericDrawCommand.h"

#include "Core/Math/Headers/MathHelper.h"
#include "Platform/Video/Headers/RenderAPIEnums.h"

namespace Divide {

IndirectDrawCommand::IndirectDrawCommand()
    : indexCount(0),
      primCount(1),
      firstIndex(0),
      baseVertex(0),
      baseInstance(0)
{
}

void IndirectDrawCommand::set(const IndirectDrawCommand& other) {
    indexCount = other.indexCount;
    primCount = other.primCount;
    firstIndex = other.firstIndex;
    baseVertex = other.baseVertex;
    baseInstance = other.baseInstance;
}

bool IndirectDrawCommand::operator==(const IndirectDrawCommand &other) const {
    return indexCount == other.indexCount &&
           primCount == other.primCount &&
           firstIndex == other.firstIndex &&
           baseVertex == other.baseVertex &&
           baseInstance == other.baseInstance;
}

GenericDrawCommand::GenericDrawCommand()
    : GenericDrawCommand(PrimitiveType::TRIANGLE_STRIP, 0, 0)
{
}

GenericDrawCommand::GenericDrawCommand(PrimitiveType type,
                                       U32 firstIndex,
                                       U32 indexCount,
                                       U32 primCount)
  : _lodIndex(0),
    _drawCount(1),
    _drawToBuffer(0),
    _stateHash(0),
    _type(type),
    _commandOffset(0),
    _shaderProgram(nullptr),
    _sourceBuffer(nullptr),
    _renderOptions(to_const_uint(RenderOptions::RENDER_GEOMETRY))
{
    _cmd.indexCount = indexCount;
    _cmd.firstIndex = firstIndex;
    _cmd.primCount = primCount;

    static_assert(sizeof(IndirectDrawCommand) == 20, "Size of IndirectDrawCommand is incorrect!");
    static_assert(sizeof(GenericDrawCommand) == 64, "Size of GenericDrawCommand is incorrect!");
}

void GenericDrawCommand::set(const GenericDrawCommand& base) {
    _cmd.set(base._cmd);
    _lodIndex = base._lodIndex;
    _drawCount = base._drawCount;
    _drawToBuffer = base._drawToBuffer;
    _renderOptions = base._renderOptions;
    _stateHash = base._stateHash;
    _type = base._type;
    _shaderProgram = base._shaderProgram;
    _sourceBuffer = base._sourceBuffer;
    _commandOffset = base._commandOffset;
}

void GenericDrawCommand::reset() {
    set(GenericDrawCommand());
}

bool GenericDrawCommand::compatible(const GenericDrawCommand& other) const {
    return _lodIndex == other._lodIndex &&
           _drawToBuffer == other._drawToBuffer &&
           _renderOptions == other._renderOptions &&
           _stateHash == other._stateHash && _type == other._type &&
           (_shaderProgram != nullptr) == (other._shaderProgram != nullptr) &&
           (_sourceBuffer != nullptr) == (other._sourceBuffer != nullptr);
}

void GenericDrawCommand::renderMask(U32 mask) {
    if (Config::Build::IS_DEBUG_BUILD) {
        auto validateMask = [mask]() -> U32 {
            U32 validMask = 0;
            for (U32 stateIt = 1; stateIt <= to_const_uint(RenderOptions::COUNT); ++stateIt) {
                U32 bitState = toBit(stateIt);

                if (BitCompare(mask, bitState)) {
                    SetBit(validMask, bitState);
                }
            }
            return validMask;
        };

        U32 parsedMask = validateMask();
        DIVIDE_ASSERT(parsedMask != 0 && parsedMask == mask,
                      "GenericDrawCommand::renderMask error: Invalid state specified!");
        _renderOptions = parsedMask;
    } else {
        _renderOptions = mask;
    }
}

bool GenericDrawCommand::isEnabledOption(RenderOptions option) const {
    return BitCompare(_renderOptions, to_uint(option));
}

void GenericDrawCommand::enableOption(RenderOptions option) {
    SetBit(_renderOptions, to_uint(option));
}

void GenericDrawCommand::disableOption(RenderOptions option) {
    ClearBit(_renderOptions, to_uint(option));
}

void GenericDrawCommand::toggleOption(RenderOptions option) {
    toggleOption(option, !isEnabledOption(option));
}

void GenericDrawCommand::toggleOption(RenderOptions option, const bool state) {
    if (state) {
        enableOption(option);
    } else {
        disableOption(option);
    }
}

}; //namespace Divide

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

Diff revisions: vs.
Revision Author Commited Message
767 IonutCava picture IonutCava Mon 22 Aug, 2016 16:25:37 +0000

[IonutCava]
- Descriptor/State cleanup part 3/3: GenericDrawCommand cleanup