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