summaryrefslogtreecommitdiff
path: root/src/VBox/GuestHost/OpenGL/state_tracker/state_polygon.c
blob: 611e2f188ae955dc5f1d9b03b76b00416204c316 (plain)
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
/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "cr_mem.h"
#include "state.h"
#include "state/cr_statetypes.h"
#include "state_internals.h"
#include "cr_pixeldata.h"

void crStatePolygonInit(CRContext *ctx)
{
    CRPolygonState *p = &ctx->polygon;
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);
    int i;

    p->polygonSmooth = GL_FALSE;
    p->polygonOffsetFill = GL_FALSE;
    p->polygonOffsetLine = GL_FALSE;
    p->polygonOffsetPoint = GL_FALSE;
    p->polygonStipple = GL_FALSE;
    p->cullFace = GL_FALSE;
    RESET(pb->enable, ctx->bitid);

    p->offsetFactor = 0;
    p->offsetUnits = 0;
    RESET(pb->offset, ctx->bitid);

    p->cullFaceMode = GL_BACK;
    p->frontFace = GL_CCW;
    p->frontMode = GL_FILL;
    p->backMode = GL_FILL;
    RESET(pb->mode, ctx->bitid);

    for (i=0; i<32; i++)
        p->stipple[i] = 0xFFFFFFFF;
    RESET(pb->stipple, ctx->bitid);

    RESET(pb->dirty, ctx->bitid);
}

void STATE_APIENTRY crStateCullFace(GLenum mode) 
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *p = &(g->polygon);
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glCullFace called in begin/end");
        return;
    }

    FLUSH();

    if (mode != GL_FRONT && mode != GL_BACK && mode != GL_FRONT_AND_BACK)
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
                "glCullFace called with bogus mode: 0x%x", mode);
        return;
    }

    p->cullFaceMode = mode;
    DIRTY(pb->mode, g->neg_bitid);
    DIRTY(pb->dirty, g->neg_bitid);
}

void STATE_APIENTRY crStateFrontFace (GLenum mode) 
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *p = &(g->polygon);
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glFrontFace called in begin/end");
        return;
    }

    FLUSH();

    if (mode != GL_CW && mode != GL_CCW)
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
                "glFrontFace called with bogus mode: 0x%x", mode);
        return;
    }

    p->frontFace = mode;
    DIRTY(pb->mode, g->neg_bitid);
    DIRTY(pb->dirty, g->neg_bitid);
}

void  STATE_APIENTRY crStatePolygonMode (GLenum face, GLenum mode) 
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *p = &(g->polygon);
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glPolygonMode called in begin/end");
        return;
    }

    FLUSH();

    if (mode != GL_POINT && mode != GL_LINE && mode != GL_FILL)
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
                "glPolygonMode called with bogus mode: 0x%x", mode);
        return;
    }

    switch (face) {
        case GL_FRONT:
            p->frontMode = mode;
            break;
        case GL_FRONT_AND_BACK:
            p->frontMode = mode;
        case GL_BACK:
            p->backMode = mode;
            break;
        default:
            crStateError(__LINE__, __FILE__, GL_INVALID_ENUM,
                    "glPolygonMode called with bogus face: 0x%x", face);
            return;
    }
    DIRTY(pb->mode, g->neg_bitid);
    DIRTY(pb->dirty, g->neg_bitid);
}

void STATE_APIENTRY crStatePolygonOffset (GLfloat factor, GLfloat units) 
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *p = &(g->polygon);
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glPolygonOffset called in begin/end");
        return;
    }

    FLUSH();

    p->offsetFactor = factor;
    p->offsetUnits = units;

    DIRTY(pb->offset, g->neg_bitid);
    DIRTY(pb->dirty, g->neg_bitid);
}

void STATE_APIENTRY crStatePolygonStipple (const GLubyte *p) 
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *poly = &(g->polygon);
        CRStateBits *sb = GetCurrentBits();
    CRPolygonBits *pb = &(sb->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glPolygonStipple called in begin/end");
        return;
    }

    FLUSH();

    if (!p && !crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
    {
        crDebug("Void pointer passed to PolygonStipple");
        return;
    }

    /*@todo track mask if buffer is bound?*/
    if (!crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
    {
        crMemcpy((char*)poly->stipple, (char*)p, 128);
    }

    DIRTY(pb->dirty, g->neg_bitid);
    DIRTY(pb->stipple, g->neg_bitid);
}

void STATE_APIENTRY crStateGetPolygonStipple( GLubyte *b )
{
    CRContext *g = GetCurrentContext();
    CRPolygonState *poly = &(g->polygon);

    if (g->current.inBeginEnd) 
    {
        crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
                "glGetPolygonStipple called in begin/end");
        return;
    }

    crMemcpy((char*)b, (char*)poly->stipple, 128);
}