VirtualBox

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

Last change on this file since 68474 was 63942, checked in by vboxsync, 8 years ago

OpenGL: fixed the most annoying coding style flaws, mainly removing spaces after '(' and before ')', no semantic change

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