1e5c31af7Sopenharmony_ci# -*- coding: utf-8 -*-
2e5c31af7Sopenharmony_ci
3e5c31af7Sopenharmony_ci#-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci# drawElements Quality Program utilities
5e5c31af7Sopenharmony_ci# --------------------------------------
6e5c31af7Sopenharmony_ci#
7e5c31af7Sopenharmony_ci# Copyright 2015 The Android Open Source Project
8e5c31af7Sopenharmony_ci#
9e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci# You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci#
13e5c31af7Sopenharmony_ci#      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci#
15e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci# limitations under the License.
20e5c31af7Sopenharmony_ci#
21e5c31af7Sopenharmony_ci#-------------------------------------------------------------------------
22e5c31af7Sopenharmony_ci
23e5c31af7Sopenharmony_cifrom src_util import *
24e5c31af7Sopenharmony_ci
25e5c31af7Sopenharmony_cidef getExtensionCommands (registry, iface, api, extension):
26e5c31af7Sopenharmony_ci	commands = []
27e5c31af7Sopenharmony_ci
28e5c31af7Sopenharmony_ci	# Build interface with just the single extension and no core APIs.
29e5c31af7Sopenharmony_ci	# Aliases will not be set in this iface so we will use it only for
30e5c31af7Sopenharmony_ci	# slicing the complete (hybrid) iface.
31e5c31af7Sopenharmony_ci	extIface = getInterface(registry, api, version=False, profile='core', extensionNames=[extension])
32e5c31af7Sopenharmony_ci	if not extIface.commands:
33e5c31af7Sopenharmony_ci		return commands
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_ci	cmdMap = {}
36e5c31af7Sopenharmony_ci	for command in iface.commands:
37e5c31af7Sopenharmony_ci		cmdMap[command.name] = command
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_ci	for extCommand in extIface.commands:
40e5c31af7Sopenharmony_ci		assert extCommand.name in cmdMap
41e5c31af7Sopenharmony_ci		commands.append(cmdMap[extCommand.name])
42e5c31af7Sopenharmony_ci
43e5c31af7Sopenharmony_ci	return commands
44e5c31af7Sopenharmony_ci
45e5c31af7Sopenharmony_cidef genExtensions (registry, iface, api):
46e5c31af7Sopenharmony_ci	for extName in EXTENSIONS:
47e5c31af7Sopenharmony_ci		extCommands = getExtensionCommands(registry, iface, api, extName)
48e5c31af7Sopenharmony_ci		if len(extCommands) == 0:
49e5c31af7Sopenharmony_ci			continue # Not applicable for this api
50e5c31af7Sopenharmony_ci
51e5c31af7Sopenharmony_ci		yield ""
52e5c31af7Sopenharmony_ci		yield "if (de::contains(extSet, \"%s\"))" % extName
53e5c31af7Sopenharmony_ci		yield "{"
54e5c31af7Sopenharmony_ci
55e5c31af7Sopenharmony_ci		def genInit (command):
56e5c31af7Sopenharmony_ci			ifaceName = command.alias.name if command.alias and command.name not in ALIASING_EXCEPTIONS else command.name
57e5c31af7Sopenharmony_ci			return "gl->%s\t= (%s)\tloader->get(\"%s\");" % (
58e5c31af7Sopenharmony_ci				getFunctionMemberName(ifaceName),
59e5c31af7Sopenharmony_ci				getFunctionTypeName(ifaceName),
60e5c31af7Sopenharmony_ci				command.name)
61e5c31af7Sopenharmony_ci
62e5c31af7Sopenharmony_ci		for line in indentLines(genInit(command) for command in extCommands):
63e5c31af7Sopenharmony_ci			yield "\t" + line
64e5c31af7Sopenharmony_ci
65e5c31af7Sopenharmony_ci		yield "}"
66e5c31af7Sopenharmony_ci
67e5c31af7Sopenharmony_cidef genExtInit (registry, iface):
68e5c31af7Sopenharmony_ci	nonStrippedIface = getHybridInterface(stripAliasedExtCommands = False)
69e5c31af7Sopenharmony_ci
70e5c31af7Sopenharmony_ci	writeInlFile(os.path.join(OPENGL_INC_DIR, "glwInitExtES.inl"), genExtensions(registry, nonStrippedIface, 'gles2'))
71e5c31af7Sopenharmony_ci	writeInlFile(os.path.join(OPENGL_INC_DIR, "glwInitExtGL.inl"), genExtensions(registry, nonStrippedIface, 'gl'))
72e5c31af7Sopenharmony_ci
73e5c31af7Sopenharmony_ciif __name__ == '__main__':
74e5c31af7Sopenharmony_ci	genExtInit(getGLRegistry(), getHybridInterface())
75