1#!/usr/bin/env python 2 3# Copyright (c) 2015 The Khronos Group Inc. 4# 5# Permission is hereby granted, free of charge, to any person obtaining a 6# copy of this software and/or associated documentation files (the 7# "Materials"), to deal in the Materials without restriction, including 8# without limitation the rights to use, copy, modify, merge, publish, 9# distribute, sublicense, and/or sell copies of the Materials, and to 10# permit persons to whom the Materials are furnished to do so, subject to 11# the following conditions: 12# 13# The above copyright notice and this permission notice shall be included 14# in all copies or substantial portions of the Materials. 15# 16# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 23 24""" 25 Generator for tex-2d* and tex-3d* tests. 26 This file needs to be run in its folder. 27""" 28 29import os 30import os.path 31import sys 32 33_LICENSE = """<!-- 34 35Copyright (c) 2015 The Khronos Group Inc. 36 37Permission is hereby granted, free of charge, to any person obtaining a 38copy of this software and/or associated documentation files (the 39"Materials"), to deal in the Materials without restriction, including 40without limitation the rights to use, copy, modify, merge, publish, 41distribute, sublicense, and/or sell copies of the Materials, and to 42permit persons to whom the Materials are furnished to do so, subject to 43the following conditions: 44 45The above copyright notice and this permission notice shall be included 46in all copies or substantial portions of the Materials. 47 48THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 49EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 50MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 51IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 52CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 53TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 54MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 55 56--> 57 58""" 59 60_DO_NOT_EDIT_WARNING = """<!-- 61 62This file is auto-generated from py/tex_image_test_generator.py 63DO NOT EDIT! 64 65--> 66 67""" 68 69_ELEMENT_TYPES = [ 70 'canvas', 71 'canvas-sub-rectangle', 72 'image', 73 'image-data', 74 'svg-image', 75 'video', 76 'webgl-canvas', 77 'image-bitmap-from-image-data', 78 'image-bitmap-from-image', 79 'image-bitmap-from-video', 80 'image-bitmap-from-canvas', 81 'image-bitmap-from-blob', 82 'image-bitmap-from-image-bitmap' 83] 84 85_FORMATS_TYPES_WEBGL1 = [ 86 {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' }, 87 {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' }, 88 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' }, 89 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' }, 90 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' }, 91] 92 93_FORMATS_TYPES_WEBGL2 = [ 94 {'internal_format': 'R8', 'format': 'RED', 'type': 'UNSIGNED_BYTE' }, 95 {'internal_format': 'R16F', 'format': 'RED', 'type': 'HALF_FLOAT' }, 96 {'internal_format': 'R16F', 'format': 'RED', 'type': 'FLOAT' }, 97 {'internal_format': 'R32F', 'format': 'RED', 'type': 'FLOAT' }, 98 {'internal_format': 'R8UI', 'format': 'RED_INTEGER', 'type': 'UNSIGNED_BYTE' }, 99 {'internal_format': 'RG8', 'format': 'RG', 'type': 'UNSIGNED_BYTE' }, 100 {'internal_format': 'RG16F', 'format': 'RG', 'type': 'HALF_FLOAT' }, 101 {'internal_format': 'RG16F', 'format': 'RG', 'type': 'FLOAT' }, 102 {'internal_format': 'RG32F', 'format': 'RG', 'type': 'FLOAT' }, 103 {'internal_format': 'RG8UI', 'format': 'RG_INTEGER', 'type': 'UNSIGNED_BYTE' }, 104 {'internal_format': 'RGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' }, 105 {'internal_format': 'SRGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' }, 106 {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' }, 107 {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' }, 108 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'UNSIGNED_INT_10F_11F_11F_REV' }, 109 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'HALF_FLOAT' }, 110 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'FLOAT' }, 111 {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'HALF_FLOAT' }, 112 {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'FLOAT' }, 113 {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'HALF_FLOAT' }, 114 {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'FLOAT' }, 115 {'internal_format': 'RGB32F', 'format': 'RGB', 'type': 'FLOAT' }, 116 {'internal_format': 'RGB8UI', 'format': 'RGB_INTEGER', 'type': 'UNSIGNED_BYTE' }, 117 {'internal_format': 'RGBA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' }, 118 {'internal_format': 'SRGB8_ALPHA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' }, 119 {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' }, 120 {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' }, 121 {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' }, 122 {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' }, 123 {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'HALF_FLOAT' }, 124 {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'FLOAT' }, 125 {'internal_format': 'RGBA32F', 'format': 'RGBA', 'type': 'FLOAT' }, 126 {'internal_format': 'RGBA8UI', 'format': 'RGBA_INTEGER', 'type': 'UNSIGNED_BYTE' }, 127] 128 129def GenerateFilename(dimension, element_type, internal_format, format, type): 130 """Generate test filename.""" 131 filename = ("tex-" + dimension + "d-" + 132 internal_format + "-" + format + "-" + type + ".html") 133 return filename.lower() 134 135def WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version): 136 """Write one test.""" 137 file = open(filename, "wb") 138 file.write(_LICENSE) 139 file.write(_DO_NOT_EDIT_WARNING) 140 code = """ 141<!DOCTYPE html> 142<html> 143<head> 144<meta charset="utf-8"> 145<link rel="stylesheet" href="../../../resources/js-test-style.css"/> 146<script src="../../../js/js-test-pre.js"></script> 147<script src="../../../js/webgl-test-utils.js"></script> 148<script src="../../../js/tests/tex-image-and-sub-image-utils.js"></script>""" 149 if element_type == 'image-bitmap-from-image-data' or element_type == 'image-bitmap-from-image' or \ 150 element_type == 'image-bitmap-from-video' or element_type == 'image-bitmap-from-canvas' or \ 151 element_type == 'image-bitmap-from-blob' or element_type == 'image-bitmap-from-image-bitmap': 152 code += """ 153<script src="../../../js/tests/tex-image-and-sub-image-with-image-bitmap-utils.js"></script>""" 154 code += """ 155<script src="../../../js/tests/tex-image-and-sub-image-%(dimension)sd-with-%(element_type)s.js"></script> 156</head> 157<body>""" 158 if element_type == 'image-data': 159 code += """ 160<canvas id="texcanvas" width="2" height="2"></canvas>""" 161 code += """ 162<canvas id="example" width="32" height="32"></canvas>""" 163 code += """ 164<div id="description"></div> 165<div id="console"></div> 166<script> 167"use strict"; 168function testPrologue(gl) { 169 return true; 170} 171 172generateTest("%(internal_format)s", "%(format)s", "%(type)s", testPrologue, "../../../resources/", %(default_context_version)s)(); 173</script> 174</body> 175</html> 176""" 177 file.write(code % { 178 'dimension': dimension, 179 'element_type': element_type, 180 'internal_format': internal_format, 181 'format': format, 182 'type': type, 183 'default_context_version': default_context_version, 184 }) 185 file.close() 186 187def GenerateTests(test_dir, test_cases, dimension, default_context_version): 188 test_dir_template = test_dir + '/%s' 189 for element_type in _ELEMENT_TYPES: 190 os.chdir(test_dir_template % element_type.replace('-', '_')) 191 if dimension == '3': 192 # Assume we write 2D tests first. 193 index_file = open("00_test_list.txt", "ab") 194 else: 195 index_file = open("00_test_list.txt", "wb") 196 for tex_info in test_cases: 197 internal_format = tex_info['internal_format'] 198 format = tex_info['format'] 199 type = tex_info['type'] 200 filename = GenerateFilename(dimension, element_type, internal_format, format, type) 201 index_file.write(filename) 202 index_file.write('\n') 203 WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version) 204 index_file.close(); 205 206def main(argv): 207 """This is the main function.""" 208 py_dir = os.path.dirname(os.path.realpath(__file__)) 209 GenerateTests(os.path.realpath(py_dir + '/../conformance/textures'), _FORMATS_TYPES_WEBGL1, '2', '1') 210 GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '2', '2') 211 GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '3', '2') 212 213if __name__ == '__main__': 214 sys.exit(main(sys.argv[1:])) 215