Skip to content

Commit d3fd009

Browse files
committed
Add more fine-grained gl test reporting (emscripten-core#8346)
I've noticed that on Firefox the gl tests seem to fail sporadically, hopefully this will help narrow down exactly what is failing.
1 parent 6af55a6 commit d3fd009

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

tests/test_webgl_context_attributes_common.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdlib.h>
1010
#include <string.h>
1111
#include <stdbool.h>
12+
#include <assert.h>
1213

1314
#include <emscripten.h>
1415

@@ -128,7 +129,7 @@ static void drawTriangle(GLuint verticesVBO, unsigned char r, unsigned char g, u
128129
// Draw a red triangle on a white background. If antialiasing is disabled, resulting pixels
129130
// will only have white and red colors. If antialiasing is enabled, there will be pixels
130131
// whose color is different from red and white.
131-
static int testAntiAliasing(bool activated) {
132+
static bool testAntiAliasing(bool activated) {
132133
glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
133134
glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
134135
glClear(GL_COLOR_BUFFER_BIT);
@@ -162,7 +163,7 @@ static int testAntiAliasing(bool activated) {
162163
// Draw a red triangle with depth equals to 0 then a green triangle whose depth equals -1.
163164
// If there is an attached depth buffer, the resulting image will be a red triangle. If not,
164165
// the resulting image will be a green triangle.
165-
static int testDepth(bool activated) {
166+
static bool testDepth(bool activated) {
166167
glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
167168
glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
168169
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -195,7 +196,7 @@ static int testDepth(bool activated) {
195196
// Then draw a green triangle whose stencil ref value is 0xFF.
196197
// If there is an attached stencil buffer, the resulting image will be a red triangle. If not,
197198
// the resulting image will be a green triangle.
198-
static int testStencil(bool activated) {
199+
static bool testStencil(bool activated) {
199200
glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
200201
glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, backgroundColor[3]/255.f);
201202
glClearStencil(0xFF);
@@ -226,7 +227,7 @@ static int testStencil(bool activated) {
226227

227228
// Clear to a color with alpha = 0. If alpha is enabled then all pixels will have alpha = 0.
228229
// If alpha is disabled then pixels will have alpha of 255
229-
static int testAlpha(bool activated) {
230+
static bool testAlpha(bool activated) {
230231
glViewport(0, 0, WINDOWS_SIZE, WINDOWS_SIZE);
231232
glClearColor(backgroundColor[0]/255.f, backgroundColor[1]/255.f, backgroundColor[2]/255.f, 0.0);
232233
glClear(GL_COLOR_BUFFER_BIT);
@@ -259,24 +260,26 @@ static bool depthActivated = false;
259260
static bool stencilActivated = false;
260261
static bool alphaActivated = false;
261262

262-
static int result = 0;
263-
static int resultAA = 0;
264-
static int resultDepth = 0;
265-
static int resultStencil = 0;
266-
static int resultAlpha = 0;
263+
static bool result = 0;
264+
static bool resultAA = 0;
265+
static bool resultDepth = 0;
266+
static bool resultStencil = 0;
267+
static bool resultAlpha = 0;
267268

268269
static void draw() {
269-
270270
if (!resultAA) resultAA = testAntiAliasing(antiAliasingActivated);
271+
assert(resultAA);
271272

272273
if (!resultDepth) resultDepth = testDepth(depthActivated);
274+
assert(resultDepth);
273275

274276
if (!resultStencil) resultStencil = testStencil(stencilActivated);
277+
assert(resultStencil);
275278

276279
if (!resultAlpha) resultAlpha = testAlpha(alphaActivated);
280+
assert(resultAlpha);
277281

278282
result = resultAA && resultDepth && resultStencil && resultAlpha;
279-
280283
}
281284

282285
extern int webglAntialiasSupported(void);
@@ -288,19 +291,19 @@ extern int webglAlphaSupported(void);
288291
// Tests will succeed if they are not.
289292
static void checkContextAttributesSupport() {
290293
if (!webglAntialiasSupported()) {
291-
resultAA = 1;
294+
resultAA = true;
292295
EM_ASM(out('warning: no antialiasing\n'));
293296
}
294297
if (!webglDepthSupported()) {
295-
resultDepth = 1;
298+
resultDepth = true;
296299
EM_ASM(out('warning: no depth\n'));
297300
}
298301
if (!webglStencilSupported()) {
299-
resultStencil = 1;
302+
resultStencil = true;
300303
EM_ASM(out('warning: no stencil\n'));
301304
}
302305
if (!webglAlphaSupported()) {
303-
resultAlpha = 1;
306+
resultAlpha = true;
304307
EM_ASM(out('warning: no alpha\n'));
305308
}
306309
}

0 commit comments

Comments
 (0)