1 | # Copyright (c) 2001, Stanford University
|
---|
2 | # All rights reserved.
|
---|
3 | #
|
---|
4 | # See the file LICENSE.txt for information on redistributing this software.
|
---|
5 |
|
---|
6 | import sys, re, string
|
---|
7 | import apiutil
|
---|
8 |
|
---|
9 | line_re = re.compile (r'^(\S+)\s+(GL_\S+)\s+(.*)\s*$')
|
---|
10 | extensions_line_re = re.compile(r'^(\S+)\s+(GL_\S+)\s+(GL_\S+)\s+(.*)\s*$')
|
---|
11 |
|
---|
12 | params = {}
|
---|
13 | extended_params = {}
|
---|
14 |
|
---|
15 | input = open( sys.argv[2]+"/state_get.txt", 'r' )
|
---|
16 | for line in input.readlines():
|
---|
17 | if line[0] == '#':
|
---|
18 | continue
|
---|
19 | match = line_re.match( line )
|
---|
20 | if match:
|
---|
21 | type = match.group(1)
|
---|
22 | pname = match.group(2)
|
---|
23 | fields = string.split( match.group(3) )
|
---|
24 | params[pname] = ( type, fields )
|
---|
25 |
|
---|
26 | input = open( sys.argv[2]+"/state_extensions_get.txt", 'r' )
|
---|
27 | for line in input.readlines():
|
---|
28 | if line[0] == '#':
|
---|
29 | continue
|
---|
30 | match = extensions_line_re.match( line )
|
---|
31 | if match:
|
---|
32 | type = match.group(1)
|
---|
33 | pname = match.group(2)
|
---|
34 | ifdef = match.group(3)
|
---|
35 | fields = string.split( match.group(4) )
|
---|
36 | extended_params[pname] = ( type, ifdef, fields )
|
---|
37 |
|
---|
38 | convert = {
|
---|
39 | 'GLenum' : {
|
---|
40 | 'Boolean' : '(GLboolean) ( %s != 0 )',
|
---|
41 | 'Double' : '(GLdouble) %s',
|
---|
42 | 'Float' : '(GLfloat) %s',
|
---|
43 | 'Integer' : '(GLint) %s'
|
---|
44 | },
|
---|
45 | 'GLboolean' : {
|
---|
46 | 'Boolean' : '(GLboolean) ( %s != 0 )',
|
---|
47 | 'Double' : '(GLdouble) %s',
|
---|
48 | 'Float' : '(GLfloat) %s',
|
---|
49 | 'Integer' : '(GLint) %s'
|
---|
50 | },
|
---|
51 | 'GLint' : {
|
---|
52 | 'Boolean' : '(GLboolean) ( %s != 0 )',
|
---|
53 | 'Double' : '(GLdouble) %s',
|
---|
54 | 'Float' : '(GLfloat) %s',
|
---|
55 | 'Integer' : '(GLint) %s'
|
---|
56 | },
|
---|
57 | 'GLuint' : {
|
---|
58 | 'Boolean' : '(GLboolean) ( %s != 0 )',
|
---|
59 | 'Double' : '(GLdouble) %s',
|
---|
60 | 'Float' : '(GLfloat) %s',
|
---|
61 | 'Integer' : '(GLint) %s'
|
---|
62 | },
|
---|
63 | 'GLfloat' : {
|
---|
64 | 'Boolean' : '(GLboolean) ( %s != 0.0f )',
|
---|
65 | 'Double' : '(GLdouble) %s',
|
---|
66 | 'Float' : '%s',
|
---|
67 | 'Integer' : '(GLint) %s'
|
---|
68 | },
|
---|
69 | 'GLdouble' : {
|
---|
70 | 'Boolean' : '(GLboolean) ( %s != 0.0 )',
|
---|
71 | 'Double' : '%s',
|
---|
72 | 'Float' : '(GLfloat) %s',
|
---|
73 | 'Integer' : '(GLint) %s'
|
---|
74 | },
|
---|
75 | 'GLdefault' : {
|
---|
76 | 'Boolean' : '(GLboolean) ( %s != (GLdefault) 0.0 )',
|
---|
77 | 'Double' : '(GLdouble) %s',
|
---|
78 | 'Float' : '(GLfloat) %s',
|
---|
79 | 'Integer' : '(GLint) %s'
|
---|
80 | },
|
---|
81 | 'GLclampd' : {
|
---|
82 | 'Boolean' : '(GLboolean) ( %s != 0.0 )',
|
---|
83 | 'Double' : '%s',
|
---|
84 | 'Float' : '(GLfloat) %s',
|
---|
85 | 'Integer' : '__clampd_to_int(%s)'
|
---|
86 | },
|
---|
87 | 'GLclampf' : {
|
---|
88 | 'Boolean' : '(GLboolean) ( %s != 0.0f )',
|
---|
89 | 'Double' : '(GLdouble) %s',
|
---|
90 | 'Float' : '%s',
|
---|
91 | 'Integer' : '__clampf_to_int(%s)'
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | types = [ "Boolean", "Double", "Float", "Integer" ]
|
---|
96 |
|
---|
97 | ctypes = {
|
---|
98 | 'Boolean' : 'GLboolean',
|
---|
99 | 'Double' : 'GLdouble',
|
---|
100 | 'Float' : 'GLfloat',
|
---|
101 | 'Integer' : 'GLint'
|
---|
102 | }
|
---|
103 |
|
---|
104 | apiutil.CopyrightC()
|
---|
105 |
|
---|
106 | print """
|
---|
107 | /* DO NOT EDIT - THIS FILE GENERATED BY state_get.txt AND THE state_get.py SCRIPT */
|
---|
108 | #include <stdio.h>
|
---|
109 | #include <math.h>
|
---|
110 |
|
---|
111 | #include "state.h"
|
---|
112 | #include "state/cr_statetypes.h"
|
---|
113 |
|
---|
114 | static GLint __clampd_to_int( GLdouble d )
|
---|
115 | {
|
---|
116 | /* -1.0 -> MIN_INT, 1.0 -> MAX_INT */
|
---|
117 | if ( d > 1.0 )
|
---|
118 | return 0x7fffffff;
|
---|
119 | if ( d < -1.0 )
|
---|
120 | return 0x80000000;
|
---|
121 | return (GLint) floor( d * 2147483647.5 );
|
---|
122 | }
|
---|
123 |
|
---|
124 | static GLint __clampf_to_int( GLfloat f )
|
---|
125 | {
|
---|
126 | /* -1.0f -> MIN_INT, 1.0f -> MAX_INT */
|
---|
127 | if ( f > 1.0f )
|
---|
128 | return 0x7fffffff;
|
---|
129 | if ( f < -1.0f )
|
---|
130 | return 0x80000000;
|
---|
131 | return (GLint) floor( f * 2147483647.5f );
|
---|
132 | }
|
---|
133 |
|
---|
134 | static GLenum __getDrawBuffer(CRContext *g)
|
---|
135 | {
|
---|
136 | return g->framebufferobject.drawFB ? g->framebufferobject.drawFB->drawbuffer[0] : g->buffer.drawBuffer;
|
---|
137 | }
|
---|
138 |
|
---|
139 | static GLenum __getReadBuffer(CRContext *g)
|
---|
140 | {
|
---|
141 | return g->framebufferobject.readFB ? g->framebufferobject.readFB->readbuffer : g->buffer.readBuffer;
|
---|
142 | }
|
---|
143 | """
|
---|
144 |
|
---|
145 | header = """
|
---|
146 | {
|
---|
147 | CRContext *g = GetCurrentContext();
|
---|
148 |
|
---|
149 | if (g->current.inBeginEnd)
|
---|
150 | {
|
---|
151 | crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
|
---|
152 | "glGet called in Begin/End");
|
---|
153 | return;
|
---|
154 | }
|
---|
155 |
|
---|
156 | if ( pname == GL_CURRENT_INDEX || pname == GL_CURRENT_COLOR ||
|
---|
157 | pname == GL_CURRENT_SECONDARY_COLOR_EXT ||
|
---|
158 | pname == GL_CURRENT_FOG_COORDINATE_EXT ||
|
---|
159 | pname == GL_CURRENT_NORMAL || pname == GL_EDGE_FLAG ||
|
---|
160 | pname == GL_CURRENT_TEXTURE_COORDS )
|
---|
161 | {
|
---|
162 | #if 0
|
---|
163 | crStateError(__LINE__,__FILE__, GL_INVALID_OPERATION,
|
---|
164 | "Unimplemented glGet of a 'current' value" );
|
---|
165 | #else
|
---|
166 | crStateCurrentRecover();/* &g->current, &sb->current, g->bitID );*/
|
---|
167 |
|
---|
168 | #endif
|
---|
169 | }
|
---|
170 |
|
---|
171 | switch ( pname ) {
|
---|
172 | """
|
---|
173 |
|
---|
174 | for rettype in types:
|
---|
175 | print ''
|
---|
176 | print 'void STATE_APIENTRY crStateGet%sv( GLenum pname, %s *params )' % ( rettype, ctypes[rettype] )
|
---|
177 | print header
|
---|
178 |
|
---|
179 | keys = params.keys()
|
---|
180 | keys.sort()
|
---|
181 | for pname in keys:
|
---|
182 | print '\t\tcase %s:' % pname
|
---|
183 | (srctype,fields) = params[pname]
|
---|
184 | try:
|
---|
185 | cvt = convert[srctype][rettype]
|
---|
186 | i = 0
|
---|
187 | for field in fields:
|
---|
188 | expr = cvt % field
|
---|
189 | print '\t\t\tparams[%d] = %s;' % (i,expr)
|
---|
190 | i += 1
|
---|
191 | except:
|
---|
192 | print '\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");'
|
---|
193 | print "\t\t\tbreak;"
|
---|
194 |
|
---|
195 |
|
---|
196 | keys = extended_params.keys();
|
---|
197 | keys.sort()
|
---|
198 | for pname in keys:
|
---|
199 | (srctype,ifdef,fields) = extended_params[pname]
|
---|
200 | ext = ifdef[3:] # the extension name with the "GL_" prefix removed
|
---|
201 | #print '#ifdef %s' % ifdef
|
---|
202 | print '#ifdef CR_%s' % ext
|
---|
203 | print '\t\tcase %s:' % pname
|
---|
204 | if ext != 'OPENGL_VERSION_1_2':
|
---|
205 | print '\t\t\tif (g->extensions.%s) {' % ext
|
---|
206 | try:
|
---|
207 | cvt = convert[srctype][rettype]
|
---|
208 | i = 0
|
---|
209 | for field in fields:
|
---|
210 | expr = cvt % field
|
---|
211 | if field[0] == '%':
|
---|
212 | command = string.split(field, '%')
|
---|
213 | print '\t\t\t\t%s;' % command[1]
|
---|
214 | continue
|
---|
215 | elif ext != 'OPENGL_VERSION_1_2':
|
---|
216 | print '\t\t\t\tparams[%d] = %s;' % (i,expr)
|
---|
217 | else:
|
---|
218 | print '\t\t\tparams[%d] = %s;' % (i,expr)
|
---|
219 | i += 1
|
---|
220 | except:
|
---|
221 | print '\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");'
|
---|
222 | if ext != 'OPENGL_VERSION_1_2':
|
---|
223 | print "\t\t\t}"
|
---|
224 | print "\t\t\telse {"
|
---|
225 | print '\t\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "glGet%sv");' % rettype
|
---|
226 | print "\t\t\t}"
|
---|
227 | print "\t\t\tbreak;"
|
---|
228 | #print '#endif /* %s */' % ifdef
|
---|
229 | print '#endif /* CR_%s */' % ext
|
---|
230 |
|
---|
231 | print '\t\tdefault:'
|
---|
232 | print '\t\t\tcrStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGet: Unknown enum: 0x%x", pname);'
|
---|
233 | print '\t\t\treturn;'
|
---|
234 | print '\t}'
|
---|
235 | print '}'
|
---|
236 |
|
---|
237 | from get_components import *
|
---|