File size: 8,268 Bytes
dec7e7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* -*- tab-width: 4; -*- */
/* vi: set sw=2 ts=4 expandtab: */

/*
 * Copyright 2015-2020 Mark Callow.
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @internal
 * @file
 * @~English
 *
 * @brief Instantiate GLLoadTests app with set of tests for OpenGL 3.3+ and
 *        OpenGL ES 3.x
 */

#include <string>
#include <regex>

#include "GLLoadTests.h"
#include "EncodeTexture.h"
#include "DrawTexture.h"
#include "TexturedCube.h"
#include "Texture3d.h"
#include "TextureCubemap.h"
#include "TextureArray.h"
#include "TextureMipmap.h"

#if !defined TEST_COMPRESSION
#define TEST_COMPRESSION 1
#endif

LoadTestSample*
GLLoadTests::showFile(const std::string& filename)
{
    KTX_error_code ktxresult;
    ktxTexture* kTexture;
    ktxresult = ktxTexture_CreateFromNamedFile(filename.c_str(),
                                        KTX_TEXTURE_CREATE_NO_FLAGS,
                                        &kTexture);
    if (KTX_SUCCESS != ktxresult) {
        std::stringstream message;

        message << "Creation of ktxTexture from \"" << filename
                << "\" failed: " << ktxErrorString(ktxresult);
        throw std::runtime_error(message.str());
    }

    LoadTestSample::PFN_create createViewer;
    LoadTestSample* pViewer;
    if (kTexture->numDimensions == 3)
       createViewer = Texture3d::create;
    else if (kTexture->isArray && kTexture->isCubemap) {
        // TODO: Add cubemap array app.
        std::stringstream message;
        message << "Display of cubemap array textures not yet implemented.";
        throw std::runtime_error(message.str());
    } else if (kTexture->isArray) {
        createViewer = TextureArray::create;
    } else if (kTexture->isCubemap) {
#if !defined(__EMSCRIPTEN__)
        createViewer = TextureCubemap::create;
#else
        throw std::runtime_error("Emscripten viewer can't display cube maps"
                                 " because there is no libassimp support.");
#endif
    } else if (kTexture->numLevels > 1 || kTexture->generateMipmaps) {
        // TODO: Add option to choose to display showing the individual
        // mipmaps vs. DrawTexture that displays a single rect using the
        // mipmaps, if present.
        createViewer = TextureMipmap::create;
    } else {
        createViewer = DrawTexture::create;
    }
    ktxTexture_Destroy(kTexture);

    // Escape any spaces in filename.
    std::string args = "--external " + std::regex_replace( filename, std::regex(" "), "\\ " );
    pViewer = createViewer(w_width, w_height, args.c_str(), sBasePath);
    return pViewer;
}

const GLLoadTests::sampleInvocation siSamples[] = {
    { DrawTexture::create,
      "etc1s_Iron_Bars_001_normal.ktx2",
      "Transcode of ETC1S+BasisLZ Compressed KTX2 XY normal map mipmapped"
    },
    { DrawTexture::create,
      "uastc_Iron_Bars_001_normal.ktx2",
      "Transcode of UASTC+zstd Compressed KTX2 XY normal map mipmapped"
    },
    { DrawTexture::create,
      "color_grid_uastc_zstd.ktx2",
      "Transcode of UASTC+Zstd Compressed KTX2 RGB not mipmapped "
    },
    { DrawTexture::create,
      "color_grid_zstd.ktx2",
      "Zstd Compressed KTX2 RGB not mipmapped"
    },
    { DrawTexture::create,
      "color_grid_uastc.ktx2",
      "Transcode of UASTC Compressed KTX2 RGB not mipmapped"
    },
    { DrawTexture::create,
      "color_grid_basis.ktx2",
      "Transcode of ETC1S+BasisLZ Compressed KTX2 RGB not mipmapped"
    },
    { DrawTexture::create,
      "kodim17_basis.ktx2",
      "Transcode of ETC1S+BasisLZ Compressed KTX2 RGB not mipmapped"
    },
    { DrawTexture::create,
      "--transcode-target RGBA4444 kodim17_basis.ktx2",
      "Transcode of ETC1S+BasisLZ Compressed KTX2 RGB not mipmapped to RGBA4444"
    },
    { EncodeTexture::create,
      "FlightHelmet_baseColor_basis.ktx2",
      "Transcode of ETC1S+BasisLZ Compressed KTX2 RGBA not mipmapped"
    },
#if TEST_COMPRESSION
    { EncodeTexture::create,
      "--encode etc1s rgba-reference-u.ktx2",
      "Encode to ETC1S+BasisLZ then Transcode of Compressed KTX2 RGBA not mipmapped"
    },
    { EncodeTexture::create,
      "--encode uastc rgba-reference-u.ktx2",
      "Encode to UASTC then Transcode of Compressed KTX2 RGBA not mipmapped"
    },
    { EncodeTexture::create,
      "--encode astc rgba-reference-u.ktx2",
      "Encode to ASTC then display RGBA not mipmapped"
    },
#endif
#if !defined(__EMSCRIPTEN__)
    { TextureCubemap::create,
      "cubemap_goldengate_uastc_rdo4_zstd5_rd.ktx2",
      "Transcode of UASTC+rdo+zstd Compressed KTX2 Cube Map Transcoded"
    },
    { TextureCubemap::create,
      "cubemap_yokohama_basis_rd.ktx2",
      "Transcode of ETC1S/BasisLZ Compressed KTX2 mipmapped cube map",
    },
#endif
    { DrawTexture::create,
      "orient-down-metadata-u.ktx2",
      "KTX2: RGB8 + KTXOrientation down"
    },
    { DrawTexture::create,
      "--preload orient-down-metadata-u.ktx2",
      "KTX2: RGB8 + KTXOrientation down with pre-loaded images"
    },
    { TextureArray::create,
      "texturearray_bc3_unorm.ktx2",
      "KTX2: BC3 (S3TC DXT5) Compressed Texture Array"
    },
    { TextureArray::create,
      "texturearray_astc_8x8_unorm.ktx2",
      "KTX2: ASTC 8x8 Compressed Texture Array"
    },
    { TextureArray::create,
      "texturearray_etc2_unorm.ktx2",
      "KTX2: ETC2 Compressed Texture Array"
    },
    { Texture3d::create,
      "3dtex_7_reference_u.ktx2",
      "RGBA8 3d Texture, Depth == 7"
    },
    { TexturedCube::create,
      "rgb-mipmap-reference-u.ktx2",
      "KTX2: RGB8 Color/level mipmap"
    },
    { DrawTexture::create,
      "hi_mark.ktx",
      "RGB8 NPOT HI Logo"
    },
    { DrawTexture::create,
      "orient-up-metadata.ktx",
      "RGB8 + KTXOrientation up"
    },
    { DrawTexture::create,
      "orient-down-metadata.ktx",
      "RGB8 + KTXOrientation down"
    },
    { DrawTexture::create,
      "not4_rgb888_srgb.ktx",
      "RGB8 2D, Row length not Multiple of 4"
    },
    { DrawTexture::create,
      "etc1.ktx",
      "ETC1 RGB8"
    },
    { DrawTexture::create,
      "etc2-rgb.ktx",
      "ETC2 RGB8"
    },
    { DrawTexture::create,
      "etc2-rgba1.ktx",
      "ETC2 RGB8A1"
    },
    { DrawTexture::create,
      "etc2-rgba8.ktx",
      "ETC2 RGB8A8"
    },
    { DrawTexture::create,
      "etc2-sRGB.ktx",
      "ETC2 sRGB8"
    },
    { DrawTexture::create,
      "etc2-sRGBa1.ktx",
      "ETC2 sRGB8A1"
    },
    { DrawTexture::create,
      "etc2-sRGBa8.ktx",
      "ETC2 sRGB8A8"
    },
    { DrawTexture::create,
      "rgba-reference.ktx",
      "RGBA8"
    },
    { DrawTexture::create,
      "rgb-reference.ktx",
      "RGB8"
    },
    { DrawTexture::create,
      "conftestimage_R11_EAC.ktx",
      "ETC2 R11"
    },
    { DrawTexture::create,
      "conftestimage_SIGNED_R11_EAC.ktx",
      "ETC2 Signed R11"
    },
    { DrawTexture::create,
      "conftestimage_RG11_EAC.ktx",
      "ETC2 RG11"
    },
    { DrawTexture::create,
      "conftestimage_SIGNED_RG11_EAC.ktx",
      "ETC2 Signed RG11"
    },
    { TextureArray::create,
      "texturearray_bc3_unorm.ktx",
      "BC3 (S3TC DXT5) Compressed Texture Array"
    },
    { TextureArray::create,
      "texturearray_astc_8x8_unorm.ktx",
      "ASTC 8x8 Compressed Texture Array"
    },
    { TextureArray::create,
      "texturearray_etc2_unorm.ktx",
      "ETC2 Compressed Texture Array"
    },
    { TexturedCube::create,
      "rgb-amg-reference.ktx",
      "RGB8 + Auto Mipmap"
    },
    { TexturedCube::create,
      "rgb-mipmap-reference.ktx",
      "RGB8 Color/level mipmap"
    },
    { TexturedCube::create,
      "hi_mark_sq.ktx",
      "RGB8 NPOT HI Logo"
    },
};

const uint32_t uNumSamples = sizeof(siSamples) / sizeof(GLLoadTests::sampleInvocation);

#if !(defined(GL_CONTEXT_PROFILE) && defined(GL_CONTEXT_MAJOR_VERSION) && defined(GL_CONTEXT_MINOR_VERSION))
  #error GL_CONTEXT_PROFILE, GL_CONTEXT_MAJOR_VERSION & GL_CONTEXT_MINOR_VERSION must be defined.
#endif

AppBaseSDL* theApp = new GLLoadTests(siSamples, uNumSamples,
                                         "KTX Loader Tests for GL3 & ES3",
                                         GL_CONTEXT_PROFILE,
                                         GL_CONTEXT_MAJOR_VERSION,
                                         GL_CONTEXT_MINOR_VERSION);