summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/glwrapper.cc
blob: ae46568ecfb355d3db778d9e3cfc2097800ee2f1 (plain) (blame)
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
#include "AppHdr.h"

#ifdef USE_TILE_LOCAL

#include "glwrapper.h"

/////////////////////////////////////////////////////////////////////////////
// VColour

VColour VColour::white(255, 255, 255, 255);
VColour VColour::black(0, 0, 0, 255);
VColour VColour::transparent(0, 0, 0, 0);

bool VColour::operator==(const VColour &vc) const
{
    return r == vc.r && g == vc.g && b == vc.b && a == vc.a;
}

bool VColour::operator!=(const VColour &vc) const
{
    return r != vc.r || g != vc.g || b != vc.b || a != vc.a;
}

/////////////////////////////////////////////////////////////////////////////
// GLState

// Note: these defaults should match the OpenGL defaults
GLState::GLState() :
    array_vertex(false),
    array_texcoord(false),
    array_colour(false),
    blend(false),
    texture(false),
    depthtest(false),
    alphatest(false),
    alpharef(0),
    colour(VColour::white)
{
}

GLState::GLState(const GLState &state) :
    array_vertex(state.array_vertex),
    array_texcoord(state.array_texcoord),
    array_colour(state.array_colour),
    blend(state.blend),
    texture(state.texture),
    depthtest(state.depthtest),
    alphatest(state.alphatest),
    alpharef(state.alpharef),
    colour(state.colour)
{
}

const GLState &GLState::operator=(const GLState &state)
{
    array_vertex = state.array_vertex;
    array_texcoord = state.array_texcoord;
    array_colour = state.array_colour;
    blend = state.blend;
    texture = state.texture;
    depthtest = state.depthtest;
    alphatest = state.alphatest;
    alpharef = state.alpharef;
    colour = state.colour;

    return *this;
}

bool GLState::operator==(const GLState &state) const
{
    return array_vertex == state.array_vertex
           && array_texcoord == state.array_texcoord
           && array_colour == state.array_colour
           && blend == state.blend
           && texture == state.texture
           && depthtest == state.depthtest
           && alphatest == state.alphatest
           && alpharef == state.alpharef
           && colour == state.colour;
}

/////////////////////////////////////////////////////////////////////////////
// GLStateManager

#ifdef ASSERTS
bool GLStateManager::_valid(int num_verts, drawing_modes mode)
{
    switch (mode)
    {
    case GLW_RECTANGLE:
        return num_verts % 4 == 0;
    case GLW_LINES:
        return num_verts % 2 == 0;
    default:
        return false;
    }
}
#endif // ASSERTS

#endif // USE_TILE_LOCAL