Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
#!/usr/bin/env python
2
 
3
# Copyright (C) 2012 Intel Corporation
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining a
6
# copy of this software and associated documentation files (the "Software"),
7
# to deal in the Software without restriction, including without limitation
8
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
# and/or sell copies of the Software, and to permit persons to whom the
10
# Software is furnished to do so, subject to the following conditions:
11
#
12
# The above copyright notice and this permission notice (including the next
13
# paragraph) shall be included in all copies or substantial portions of the
14
# Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
# IN THE SOFTWARE.
23
 
24
# This script generates the file api_exec.c, which contains
25
# _mesa_initialize_exec_table().  It is responsible for populating all
26
# entries in the "exec" dispatch table that aren't dynamic.
27
 
28
import collections
29
import license
30
import gl_XML
31
import sys, getopt
32
 
33
 
34
exec_flavor_map = {
35
    'dynamic': None,
36
    'mesa': '_mesa_',
37
    'skip': None,
38
    }
39
 
40
 
41
header = """/**
42
 * \\file api_exec.c
43
 * Initialize dispatch table.
44
 */
45
 
46
 
47
#include "main/accum.h"
48
#include "main/api_loopback.h"
49
#include "main/api_exec.h"
50
#include "main/arbprogram.h"
51
#include "main/atifragshader.h"
52
#include "main/attrib.h"
53
#include "main/blend.h"
54
#include "main/bufferobj.h"
55
#include "main/arrayobj.h"
56
#include "main/buffers.h"
57
#include "main/clear.h"
58
#include "main/clip.h"
59
#include "main/colortab.h"
60
#include "main/condrender.h"
61
#include "main/context.h"
62
#include "main/convolve.h"
63
#include "main/depth.h"
64
#include "main/dlist.h"
65
#include "main/drawpix.h"
66
#include "main/drawtex.h"
67
#include "main/rastpos.h"
68
#include "main/enable.h"
69
#include "main/errors.h"
70
#include "main/es1_conversion.h"
71
#include "main/eval.h"
72
#include "main/get.h"
73
#include "main/feedback.h"
74
#include "main/fog.h"
75
#include "main/fbobject.h"
76
#include "main/framebuffer.h"
77
#include "main/hint.h"
78
#include "main/histogram.h"
79
#include "main/imports.h"
80
#include "main/light.h"
81
#include "main/lines.h"
82
#include "main/matrix.h"
83
#include "main/multisample.h"
84
#include "main/pixel.h"
85
#include "main/pixelstore.h"
86
#include "main/points.h"
87
#include "main/polygon.h"
88
#include "main/querymatrix.h"
89
#include "main/queryobj.h"
90
#include "main/readpix.h"
91
#include "main/samplerobj.h"
92
#include "main/scissor.h"
93
#include "main/stencil.h"
94
#include "main/texenv.h"
95
#include "main/texgetimage.h"
96
#include "main/teximage.h"
97
#include "main/texgen.h"
98
#include "main/texobj.h"
99
#include "main/texparam.h"
100
#include "main/texstate.h"
101
#include "main/texstorage.h"
102
#include "main/texturebarrier.h"
103
#include "main/transformfeedback.h"
104
#include "main/mtypes.h"
105
#include "main/varray.h"
106
#include "main/viewport.h"
107
#include "main/shaderapi.h"
108
#include "main/uniforms.h"
109
#include "main/syncobj.h"
110
#include "main/formatquery.h"
111
#include "main/dispatch.h"
112
#include "vbo/vbo.h"
113
 
114
 
115
/**
116
 * Initialize a context's exec table with pointers to Mesa's supported
117
 * GL functions.
118
 *
119
 * This function depends on ctx->Version.
120
 *
121
 * \param ctx  GL context to which \c exec belongs.
122
 */
123
void
124
_mesa_initialize_exec_table(struct gl_context *ctx)
125
{
126
   struct _glapi_table *exec;
127
 
128
   exec = ctx->Exec;
129
   assert(exec != NULL);
130
 
131
   assert(ctx->Version > 0);
132
 
133
   vbo_initialize_exec_dispatch(ctx, exec);
134
"""
135
 
136
 
137
footer = """
138
}
139
"""
140
 
141
 
142
class PrintCode(gl_XML.gl_print_base):
143
 
144
    def __init__(self):
145
        gl_XML.gl_print_base.__init__(self)
146
 
147
        self.name = 'gl_genexec.py'
148
        self.license = license.bsd_license_template % (
149
            'Copyright (C) 2012 Intel Corporation',
150
            'Intel Corporation')
151
 
152
    def printRealHeader(self):
153
        print header
154
 
155
    def printRealFooter(self):
156
        print footer
157
 
158
    def printBody(self, api):
159
        # Collect SET_* calls by the condition under which they should
160
        # be called.
161
        settings_by_condition = collections.defaultdict(lambda: [])
162
        for f in api.functionIterateAll():
163
            if f.exec_flavor not in exec_flavor_map:
164
                raise Exception(
165
                    'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
166
            condition_parts = []
167
            if f.desktop:
168
                if f.deprecated:
169
                    condition_parts.append('ctx->API == API_OPENGL_COMPAT')
170
                else:
171
                    condition_parts.append('_mesa_is_desktop_gl(ctx)')
172
            if 'es1' in f.api_map:
173
                condition_parts.append('ctx->API == API_OPENGLES')
174
            if 'es2' in f.api_map:
175
                if f.api_map['es2'] == 3:
176
                    condition_parts.append('_mesa_is_gles3(ctx)')
177
                else:
178
                    condition_parts.append('ctx->API == API_OPENGLES2')
179
            if not condition_parts:
180
                # This function does not exist in any API.
181
                continue
182
            condition = ' || '.join(condition_parts)
183
            prefix = exec_flavor_map[f.exec_flavor]
184
            if prefix is None:
185
                # This function is not implemented, or is dispatched
186
                # dynamically.
187
                continue
188
            settings_by_condition[condition].append(
189
                'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
190
        # Print out an if statement for each unique condition, with
191
        # the SET_* calls nested inside it.
192
        for condition in sorted(settings_by_condition.keys()):
193
            print '   if ({0}) {{'.format(condition)
194
            for setting in sorted(settings_by_condition[condition]):
195
                print '      {0}'.format(setting)
196
            print '   }'
197
 
198
 
199
def show_usage():
200
    print "Usage: %s [-f input_file_name]" % sys.argv[0]
201
    sys.exit(1)
202
 
203
 
204
if __name__ == '__main__':
205
    file_name = "gl_and_es_API.xml"
206
 
207
    try:
208
        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
209
    except Exception,e:
210
        show_usage()
211
 
212
    for (arg,val) in args:
213
        if arg == "-f":
214
            file_name = val
215
 
216
    printer = PrintCode()
217
 
218
    api = gl_XML.parse_GL_API(file_name)
219
    printer.Print(api)