summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/common/crOpenGL/entrypoints.py
blob: bdd93e75b6b5a3c6ef807ace43841d1ab9afec7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Copyright (c) 2001, Stanford University
# All rights reserved.
#
# See the file LICENSE.txt for information on redistributing this software.


"""
This module generates C entrypoints for all the OpenGL functions
and the special Chromium meta/glue functions.
"""


from __future__ import print_function
import sys

import apiutil


def GenerateEntrypoints(hacks = []):
    """Emit code for all the OpenGL/Chromium entrypoints.
    hacks is an optional list of functions which are special cased.
    """

    apiutil.CopyrightC()

    print('#define GL_GLEXT_PROTOTYPES')
    print('#include <stdio.h>')
    print('#include <stdlib.h>')
    print('#include <GL/gl.h>')
    print('#include "chromium.h"')
    print('#include "stub.h"')
    print('#include "dri_glx.h"')
    print('')
    print('#ifdef __GNUC__')
    print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002')
    print('#  pragma GCC diagnostic ignored "-Wunused-parameter"')
    print('# endif')
    print('#endif')


    # Get sorted list of dispatched functions.
    # The order is very important - it must match cr_opcodes.h
    # and spu_dispatch_table.h
    keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")

    for index in range(len(keys)):
        func_name = keys[index]
        if apiutil.Category(func_name) == "Chromium":
            # this function is defined in stub.c
            continue

        return_type = apiutil.ReturnType(func_name)
        params = apiutil.Parameters(func_name)

        if func_name in hacks:
            print("/* hacked entrypoint: %s */" % func_name)
            if func_name == "TexImage3D":
                # Pretty common: internalformat is GLenum, not GLint
                print("void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
                print("{")
                print("\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );")
                print("}")
            elif func_name == "TexImage2D":
                # Pretty common: internalformat is GLenum, not GLint
                print("void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
                print("{")
                print("\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );")
                print("}")
            elif func_name == "TexImage1D":
                # Pretty common: internalformat is GLenum, not GLint
                print("void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )")
                print("{")
                print("\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );")
                print("}")
            elif func_name == "EdgeFlagPointer":
                # second arg is GLboolean instead of GLvoid
                print("void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )")
                print("{")
                print("\tglim.EdgeFlagPointer( stride, pointer );")
                print("}")
            elif func_name == "ProgramParameters4fvNV":
                print("void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )")
                print("{")
                print("\tglim.ProgramParameters4fvNV( target, index, num, params );")
                print("}")
            elif func_name == "MultiDrawElementsEXT":
                print("void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)")
                print("{")
                print("\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);")
                print("}")
            elif func_name == "ProgramParameters4dvNV":
                print("void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )")
                print("{")
                print("\tglim.ProgramParameters4dvNV( target, index, num, params );")
                print("}")
        else:
            # the usual path
            print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
            print("")
            print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
            print("{")
            print("\t", end="")
            if return_type != "void":
                print("return ", end=" ")
            print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params)))
            print("}")
            print("")

    print('/*')
    print('* Aliases')
    print('*/')

    # Now loop over all the functions and take care of any aliases
    allkeys = apiutil.GetAllFunctions(sys.argv[1]+"/APIspec.txt")
    for func_name in allkeys:
        if "omit" in apiutil.ChromiumProps(func_name):
            continue

        if func_name in keys:
            # we already processed this function earlier
            continue

        # alias is the function we're aliasing
        alias = apiutil.Alias(func_name)
        if alias:
            if func_name in hacks:
                print("/* hacked entrypoint: %s */" % func_name)
                if func_name == "MultiDrawArrays":
                    print("void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )")
                    print("{")
                    print("\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );")
                    print("}")
                elif func_name == "BufferData":
                    print("void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)")
                    print("{")
                    print("\tglim.BufferDataARB(target, size, data, usage);")
                    print("}")
                elif func_name == "BufferSubData":
                    print("void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)")
                    print("{")
                    print("\tglim.BufferSubDataARB(target, offset, size, data);")
                    print("}")
                elif func_name == "GetBufferSubData":
                    print("void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)")
                    print("{")
                    print("\tglim.GetBufferSubDataARB(target, offset, size, data);")
                    print("}")
            else:
                return_type = apiutil.ReturnType(func_name)
                params = apiutil.Parameters(func_name)
                print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
                print("")
                print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
                print("{")
                print("\t", end="")
                if return_type != "void":
                    print("return ", end=" ")
                print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params)))
                print("}")
                print("")

    print('/*')
    print('* No-op stubs')
    print('*/')

    # Now generate no-op stub functions
    for func_name in allkeys:
        if "stub" in apiutil.ChromiumProps(func_name):
            return_type = apiutil.ReturnType(func_name)
            params = apiutil.Parameters(func_name)

            print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
            print("")
            print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params)))
            print("{")
            if return_type != "void":
                print("return (%s) 0" % return_type)
            print("}")
            print("")