VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_get.py@ 16939

Last change on this file since 16939 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.7 KB
Line 
1# Copyright (c) 2001, Stanford University
2# All rights reserved.
3#
4# See the file LICENSE.txt for information on redistributing this software.
5
6import sys, re, string
7import apiutil
8
9line_re = re.compile (r'^(\S+)\s+(GL_\S+)\s+(.*)\s*$')
10extensions_line_re = re.compile(r'^(\S+)\s+(GL_\S+)\s+(GL_\S+)\s+(.*)\s*$')
11
12params = {}
13extended_params = {}
14
15input = open( sys.argv[2]+"/state_get.txt", 'r' )
16for 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
26input = open( sys.argv[2]+"/state_extensions_get.txt", 'r' )
27for 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
38convert = {
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
95types = [ "Boolean", "Double", "Float", "Integer" ]
96
97ctypes = {
98 'Boolean' : 'GLboolean',
99 'Double' : 'GLdouble',
100 'Float' : 'GLfloat',
101 'Integer' : 'GLint'
102 }
103
104apiutil.CopyrightC()
105
106print """
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
114static 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
124static 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
135header = """
136{
137 CRContext *g = GetCurrentContext();
138
139 if (g->current.inBeginEnd)
140 {
141 crStateError(__LINE__, __FILE__, GL_INVALID_OPERATION,
142 "glGet called in Begin/End");
143 return;
144 }
145
146 if ( pname == GL_CURRENT_INDEX || pname == GL_CURRENT_COLOR ||
147 pname == GL_CURRENT_SECONDARY_COLOR_EXT ||
148 pname == GL_CURRENT_FOG_COORDINATE_EXT ||
149 pname == GL_CURRENT_NORMAL || pname == GL_EDGE_FLAG ||
150 pname == GL_CURRENT_TEXTURE_COORDS )
151 {
152#if 0
153 crStateError(__LINE__,__FILE__, GL_INVALID_OPERATION,
154 "Unimplemented glGet of a 'current' value" );
155#else
156 crStateCurrentRecover();/* &g->current, &sb->current, g->bitID );*/
157
158#endif
159 }
160
161 switch ( pname ) {
162"""
163
164for rettype in types:
165 print ''
166 print 'void STATE_APIENTRY crStateGet%sv( GLenum pname, %s *params )' % ( rettype, ctypes[rettype] )
167 print header
168
169 keys = params.keys()
170 keys.sort()
171 for pname in keys:
172 print '\t\tcase %s:' % pname
173 (srctype,fields) = params[pname]
174 try:
175 cvt = convert[srctype][rettype]
176 i = 0
177 for field in fields:
178 expr = cvt % field
179 print '\t\t\tparams[%d] = %s;' % (i,expr)
180 i += 1
181 except:
182 print '\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");'
183 print "\t\t\tbreak;"
184
185
186 keys = extended_params.keys();
187 keys.sort()
188 for pname in keys:
189 (srctype,ifdef,fields) = extended_params[pname]
190 ext = ifdef[3:] # the extension name with the "GL_" prefix removed
191 #print '#ifdef %s' % ifdef
192 print '#ifdef CR_%s' % ext
193 print '\t\tcase %s:' % pname
194 if ext != 'OPENGL_VERSION_1_2':
195 print '\t\t\tif (g->extensions.%s) {' % ext
196 try:
197 cvt = convert[srctype][rettype]
198 i = 0
199 for field in fields:
200 expr = cvt % field
201 if field[0] == '%':
202 command = string.split(field, '%')
203 print '\t\t\t\t%s;' % command[1]
204 continue
205 elif ext != 'OPENGL_VERSION_1_2':
206 print '\t\t\t\tparams[%d] = %s;' % (i,expr)
207 else:
208 print '\t\t\tparams[%d] = %s;' % (i,expr)
209 i += 1
210 except:
211 print '\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_OPERATION, "Unimplemented glGet!");'
212 if ext != 'OPENGL_VERSION_1_2':
213 print "\t\t\t}"
214 print "\t\t\telse {"
215 print '\t\t\t\tcrStateError(__LINE__,__FILE__,GL_INVALID_ENUM, "glGet%sv");' % rettype
216 print "\t\t\t}"
217 print "\t\t\tbreak;"
218 #print '#endif /* %s */' % ifdef
219 print '#endif /* CR_%s */' % ext
220
221 print '\t\tdefault:'
222 print '\t\t\tcrStateError(__LINE__, __FILE__, GL_INVALID_ENUM, "glGet: Unknown enum: 0x%x", pname);'
223 print '\t\t\treturn;'
224 print '\t}'
225 print '}'
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette