VirtualBox

source: vbox/trunk/src/VBox/Additions/common/crOpenGL/entrypoints.py@ 68643

Last change on this file since 68643 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: 8.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
6
7"""
8This module generates C entrypoints for all the OpenGL functions
9and the special Chromium meta/glue functions.
10"""
11
12
13from __future__ import print_function
14import sys
15
16import apiutil
17
18
19def GenerateEntrypoints(hacks = []):
20 """Emit code for all the OpenGL/Chromium entrypoints.
21 hacks is an optional list of functions which are special cased.
22 """
23
24 apiutil.CopyrightC()
25
26 print('#define GL_GLEXT_PROTOTYPES')
27 print('#include <stdio.h>')
28 print('#include <stdlib.h>')
29 print('#include <GL/gl.h>')
30 print('#include "chromium.h"')
31 print('#include "stub.h"')
32 print('#include "dri_glx.h"')
33 print('')
34 print('#ifdef __GNUC__')
35 print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002')
36 print('# pragma GCC diagnostic ignored "-Wunused-parameter"')
37 print('# endif')
38 print('#endif')
39
40
41 # Get sorted list of dispatched functions.
42 # The order is very important - it must match cr_opcodes.h
43 # and spu_dispatch_table.h
44 keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
45
46 for index in range(len(keys)):
47 func_name = keys[index]
48 if apiutil.Category(func_name) == "Chromium":
49 # this function is defined in stub.c
50 continue
51
52 return_type = apiutil.ReturnType(func_name)
53 params = apiutil.Parameters(func_name)
54
55 if func_name in hacks:
56 print("/* hacked entrypoint: %s */" % func_name)
57 if func_name == "TexImage3D":
58 # Pretty common: internalformat is GLenum, not GLint
59 print("void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
60 print("{")
61 print("\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );")
62 print("}")
63 elif func_name == "TexImage2D":
64 # Pretty common: internalformat is GLenum, not GLint
65 print("void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
66 print("{")
67 print("\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );")
68 print("}")
69 elif func_name == "TexImage1D":
70 # Pretty common: internalformat is GLenum, not GLint
71 print("void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
72 print("{")
73 print("\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );")
74 print("}")
75 elif func_name == "EdgeFlagPointer":
76 # second arg is GLboolean instead of GLvoid
77 print("void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )")
78 print("{")
79 print("\tglim.EdgeFlagPointer( stride, pointer );")
80 print("}")
81 elif func_name == "ProgramParameters4fvNV":
82 print("void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )")
83 print("{")
84 print("\tglim.ProgramParameters4fvNV( target, index, num, params );")
85 print("}")
86 elif func_name == "MultiDrawElementsEXT":
87 print("void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)")
88 print("{")
89 print("\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);")
90 print("}")
91 elif func_name == "ProgramParameters4dvNV":
92 print("void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )")
93 print("{")
94 print("\tglim.ProgramParameters4dvNV( target, index, num, params );")
95 print("}")
96 else:
97 # the usual path
98 print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
99 print("")
100 print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
101 print("{")
102 print("\t", end="")
103 if return_type != "void":
104 print("return ", end=" ")
105 print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params)))
106 print("}")
107 print("")
108
109 print('/*')
110 print('* Aliases')
111 print('*/')
112
113 # Now loop over all the functions and take care of any aliases
114 allkeys = apiutil.GetAllFunctions(sys.argv[1]+"/APIspec.txt")
115 for func_name in allkeys:
116 if "omit" in apiutil.ChromiumProps(func_name):
117 continue
118
119 if func_name in keys:
120 # we already processed this function earlier
121 continue
122
123 # alias is the function we're aliasing
124 alias = apiutil.Alias(func_name)
125 if alias:
126 if func_name in hacks:
127 print("/* hacked entrypoint: %s */" % func_name)
128 if func_name == "MultiDrawArrays":
129 print("void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )")
130 print("{")
131 print("\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );")
132 print("}")
133 elif func_name == "BufferData":
134 print("void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)")
135 print("{")
136 print("\tglim.BufferDataARB(target, size, data, usage);")
137 print("}")
138 elif func_name == "BufferSubData":
139 print("void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)")
140 print("{")
141 print("\tglim.BufferSubDataARB(target, offset, size, data);")
142 print("}")
143 elif func_name == "GetBufferSubData":
144 print("void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)")
145 print("{")
146 print("\tglim.GetBufferSubDataARB(target, offset, size, data);")
147 print("}")
148 else:
149 return_type = apiutil.ReturnType(func_name)
150 params = apiutil.Parameters(func_name)
151 print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
152 print("")
153 print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
154 print("{")
155 print("\t", end="")
156 if return_type != "void":
157 print("return ", end=" ")
158 print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params)))
159 print("}")
160 print("")
161
162 print('/*')
163 print('* No-op stubs')
164 print('*/')
165
166 # Now generate no-op stub functions
167 for func_name in allkeys:
168 if "stub" in apiutil.ChromiumProps(func_name):
169 return_type = apiutil.ReturnType(func_name)
170 params = apiutil.Parameters(func_name)
171
172 print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
173 print("")
174 print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
175 print("{")
176 if return_type != "void":
177 print("return (%s) 0" % return_type)
178 print("}")
179 print("")
180
181
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