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
|
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.
from __future__ import print_function
import sys, re, string
import apiutil
line_re = re.compile (r'^(\S+)\s+(GL_\S+)\s+(.*)\s*$')
extensions_line_re = re.compile(r'^(\S+)\s+(GL_\S+)\s+(GL_\S+)\s+(.*)\s*$')
params = {}
extended_params = {}
input = open( sys.argv[2]+"/state_get.txt", 'r' )
for line in input.readlines():
if line[0] == '#':
continue
match = line_re.match( line )
if match:
type = match.group(1)
pname = match.group(2)
fields = match.group(3).split()
params[pname] = ( type, fields )
input = open( sys.argv[2]+"/state_extensions_get.txt", 'r' )
for line in input.readlines():
if line[0] == '#':
continue
match = extensions_line_re.match( line )
if match:
type = match.group(1)
pname = match.group(2)
ifdef = match.group(3)
fields = match.group(4).split()
extended_params[pname] = ( type, ifdef, fields )
convert = {
'GLenum' : {
'Boolean' : '(GLboolean) (%s != 0)',
'Double' : '(GLdouble) %s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLboolean' : {
'Boolean' : '(GLboolean) (%s != 0)',
'Double' : '(GLdouble) %s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLint' : {
'Boolean' : '(GLboolean) (%s != 0)',
'Double' : '(GLdouble) %s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLuint' : {
'Boolean' : '(GLboolean) (%s != 0)',
'Double' : '(GLdouble) %s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLfloat' : {
'Boolean' : '(GLboolean) (%s != 0.0f)',
'Double' : '(GLdouble) %s',
'Float' : '%s',
'Integer' : '(GLint) %s'
},
'GLdouble' : {
'Boolean' : '(GLboolean) (%s != 0.0)',
'Double' : '%s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLdefault' : {
'Boolean' : '(GLboolean) (%s != (GLdefault) 0.0)',
'Double' : '(GLdouble) %s',
'Float' : '(GLfloat) %s',
'Integer' : '(GLint) %s'
},
'GLclampd' : {
'Boolean' : '(GLboolean) (%s != 0.0)',
'Double' : '%s',
'Float' : '(GLfloat) %s',
'Integer' : '__clampd_to_int(%s)'
},
'GLclampf' : {
'Boolean' : '(GLboolean) (%s != 0.0f)',
'Double' : '(GLdouble) %s',
'Float' : '%s',
'Integer' : '__clampf_to_int(%s)'
}
}
types = [ "Boolean", "Double", "Float", "Integer" ]
ctypes = {
'Boolean' : 'GLboolean',
'Double' : 'GLdouble',
'Float' : 'GLfloat',
'Integer' : 'GLint'
}
apiutil.CopyrightC()
print("""
/* DO NOT EDIT - THIS FILE GENERATED BY state_get.txt AND THE state_get.py SCRIPT */
#include <stdio.h>
#include <math.h>
#include "state.h"
#include "state/cr_statetypes.h"
static GLint __clampd_to_int(GLdouble d)
{
/* -1.0 -> MIN_INT, 1.0 -> MAX_INT */
if (d > 1.0)
return 0x7fffffff;
if (d < -1.0)
return 0x80000000;
return (GLint) floor(d * 2147483647.5);
}
static GLint __clampf_to_int(GLfloat f)
{
/* -1.0f -> MIN_INT, 1.0f -> MAX_INT */
if (f > 1.0f)
return 0x7fffffff;
if (f < -1.0f)
return 0x80000000;
return (GLint) floor(f * 2147483647.5f);
}
static GLenum __getDrawBuffer(CRContext *g)
{
return g->framebufferobject.drawFB ? g->framebufferobject.drawFB->drawbuffer[0] : g->buffer.drawBuffer;
}
static GLenum __getReadBuffer(CRContext *g)
{
return g->framebufferobject.readFB ? g->framebufferobject.readFB->readbuffer : g->buffer.readBuffer;
}
""")
header = """
{
CRContext *g = GetCurrentContext();
if (g->current.inBeginEnd)
{
crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
"glGet called in Begin/End");
return;
}
if (pname == GL_CURRENT_INDEX || pname == GL_CURRENT_COLOR ||
pname == GL_CURRENT_SECONDARY_COLOR_EXT ||
pname == GL_CURRENT_FOG_COORDINATE_EXT ||
pname == GL_CURRENT_NORMAL || pname == GL_EDGE_FLAG ||
pname == GL_CURRENT_TEXTURE_COORDS )
{
#if 0
crStateError(__LINE__,__FILE__, GL_INVALID_OPERATION,
"Unimplemented glGet of a 'current' value" );
#else
crStateCurrentRecover();/* &g->current, &sb->current, g->bitID );*/
#endif
}
switch (pname) {
"""
for rettype in types:
print('')
print('void STATE_APIENTRY crStateGet%sv( GLenum pname, %s *params )' % ( rettype, ctypes[rettype] ))
print(header)
for pname in sorted(params.keys()):
print('\t\tcase %s:' % pname)
(srctype,fields) = params[pname]
try:
cvt = convert[srctype][rettype]
i = 0
for field in fields:
expr = cvt % field
print('\t\t\tparams[%d] = %s;' % (i,expr))
i += 1
except:
print('\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
print("\t\t\tbreak;")
for pname in sorted(extended_params.keys()):
(srctype,ifdef,fields) = extended_params[pname]
ext = ifdef[3:] # the extension name with the "GL_" prefix removed
#print '#ifdef %s' % ifdef
print('#ifdef CR_%s' % ext)
print('\t\tcase %s:' % pname)
if ext != 'OPENGL_VERSION_1_2':
print('\t\t\tif (g->extensions.%s) {' % ext)
try:
cvt = convert[srctype][rettype]
i = 0
for field in fields:
expr = cvt % field
if field[0] == '%':
command = string.split(field, '%')
print('\t\t\t\t%s;' % command[1])
continue
elif ext != 'OPENGL_VERSION_1_2':
print('\t\t\t\tparams[%d] = %s;' % (i,expr))
else:
print('\t\t\tparams[%d] = %s;' % (i,expr))
i += 1
except:
print('\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");')
if ext != 'OPENGL_VERSION_1_2':
print("\t\t\t}")
print("\t\t\telse {")
print('\t\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "glGet%sv");' % rettype)
print("\t\t\t}")
print("\t\t\tbreak;")
#print '#endif /* %s */' % ifdef
print('#endif /* CR_%s */' % ext)
print('\t\tdefault:')
print('\t\t\tcrStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGet: Unknown enum: 0x%x", pname);')
print('\t\t\treturn;')
print('\t}')
print('}')
from get_components import *
|