summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/py/tex_image_test_generator.py
blob: 37b4022738d244a7836c924d599e2325289a5d4f (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
181
182
#!/usr/bin/env python2

# Copyright (c) 2019 The Khronos Group Inc.
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE.txt file.

"""
  Generator for tex-2d* and tex-3d* tests.
  This file needs to be run in its folder.
"""

import os
import os.path
import sys

_LICENSE = """<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

"""

_DO_NOT_EDIT_WARNING = """<!--

This file is auto-generated from py/tex_image_test_generator.py
DO NOT EDIT!

-->

"""

_ELEMENT_TYPES = [
  'canvas',
  'canvas-sub-rectangle',
  'image',
  'image-data',
  'svg-image',
  'video',
  'webgl-canvas',
  'image-bitmap-from-image-data',
  'image-bitmap-from-image',
  'image-bitmap-from-video',
  'image-bitmap-from-canvas',
  'image-bitmap-from-blob',
  'image-bitmap-from-image-bitmap'
]

_FORMATS_TYPES_WEBGL1 = [
  {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' },
  {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' },
  {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' },
  {'internal_format': 'LUMINANCE',       'format': 'LUMINANCE',       'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'ALPHA',           'format': 'ALPHA',           'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'LUMINANCE_ALPHA', 'format': 'LUMINANCE_ALPHA', 'type': 'UNSIGNED_BYTE' },
]

_FORMATS_TYPES_WEBGL2 = [
  {'internal_format': 'R8', 'format': 'RED', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'R16F', 'format': 'RED', 'type': 'HALF_FLOAT' },
  {'internal_format': 'R16F', 'format': 'RED', 'type': 'FLOAT' },
  {'internal_format': 'R32F', 'format': 'RED', 'type': 'FLOAT' },
  {'internal_format': 'R8UI', 'format': 'RED_INTEGER', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RG8', 'format': 'RG', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RG16F', 'format': 'RG', 'type': 'HALF_FLOAT' },
  {'internal_format': 'RG16F', 'format': 'RG', 'type': 'FLOAT' },
  {'internal_format': 'RG32F', 'format': 'RG', 'type': 'FLOAT' },
  {'internal_format': 'RG8UI', 'format': 'RG_INTEGER', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'SRGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' },
  {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'UNSIGNED_INT_10F_11F_11F_REV' },
  {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'HALF_FLOAT' },
  {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'FLOAT' },
  {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'HALF_FLOAT' },
  {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'FLOAT' },
  {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'HALF_FLOAT' },
  {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'FLOAT' },
  {'internal_format': 'RGB32F', 'format': 'RGB', 'type': 'FLOAT' },
  {'internal_format': 'RGB8UI', 'format': 'RGB_INTEGER', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGBA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'SRGB8_ALPHA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' },
  {'internal_format': 'RGB10_A2', 'format': 'RGBA', 'type': 'UNSIGNED_INT_2_10_10_10_REV' },
  {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
  {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' },
  {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'HALF_FLOAT' },
  {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'FLOAT' },
  {'internal_format': 'RGBA32F', 'format': 'RGBA', 'type': 'FLOAT' },
  {'internal_format': 'RGBA8UI', 'format': 'RGBA_INTEGER', 'type': 'UNSIGNED_BYTE' },
]

def GenerateFilename(dimension, element_type, internal_format, format, type):
  """Generate test filename."""
  filename = ("tex-" + dimension + "d-" +
              internal_format + "-" + format + "-" + type + ".html")
  return filename.lower()

def WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version):
  """Write one test."""
  file = open(filename, "wb")
  file.write(_LICENSE)
  file.write(_DO_NOT_EDIT_WARNING)
  code = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"></script>
<script src="../../../js/tests/tex-image-and-sub-image-utils.js"></script>"""
  if element_type == 'image-bitmap-from-image-data' or element_type == 'image-bitmap-from-image' or \
     element_type == 'image-bitmap-from-video' or element_type == 'image-bitmap-from-canvas' or \
     element_type == 'image-bitmap-from-blob' or element_type == 'image-bitmap-from-image-bitmap':
    code += """
<script src="../../../js/tests/tex-image-and-sub-image-with-image-bitmap-utils.js"></script>"""
  code += """
<script src="../../../js/tests/tex-image-and-sub-image-%(dimension)sd-with-%(element_type)s.js"></script>
</head>
<body>"""
  if element_type == 'image-data':
    code += """
<canvas id="texcanvas" width="2" height="2"></canvas>"""
  code += """
<canvas id="example" width="32" height="32"></canvas>"""
  code += """
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
function testPrologue(gl) {
    return true;
}

generateTest("%(internal_format)s", "%(format)s", "%(type)s", testPrologue, "../../../resources/", %(default_context_version)s)();
</script>
</body>
</html>
"""
  file.write(code % {
    'dimension': dimension,
    'element_type': element_type,
    'internal_format': internal_format,
    'format': format,
    'type': type,
    'default_context_version': default_context_version,
  })
  file.close()

def GenerateTests(test_dir, test_cases, dimension, default_context_version):
  test_dir_template = test_dir + '/%s'
  for element_type in _ELEMENT_TYPES:
    os.chdir(test_dir_template % element_type.replace('-', '_'))
    if dimension == '3':
      # Assume we write 2D tests first.
      index_file = open("00_test_list.txt", "ab")
    else:
      index_file = open("00_test_list.txt", "wb")
    for tex_info in test_cases:
      internal_format = tex_info['internal_format']
      format = tex_info['format']
      type = tex_info['type']
      filename = GenerateFilename(dimension, element_type, internal_format, format, type)
      index_file.write(filename)
      index_file.write('\n')
      WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version)
    index_file.close();

def main(argv):
  """This is the main function."""
  py_dir = os.path.dirname(os.path.realpath(__file__))
  GenerateTests(os.path.realpath(py_dir + '/../conformance/textures'), _FORMATS_TYPES_WEBGL1, '2', '1')
  GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '2', '2')
  GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '3', '2')

if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))