Skip to content

Commit c3843e3

Browse files
committed
Convert webgl2 tests to C. NFC
1 parent 55ed267 commit c3843e3

16 files changed

+54
-64
lines changed
File renamed without changes.

test/browser/webgl2_garbage_free_entrypoints.cpp renamed to test/browser/webgl2_garbage_free_entrypoints.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
#include <emscripten/html5.h>
1111
#include <GLES2/gl2.h>
1212

13-
GLuint CompileShader(GLenum type, const char *src)
14-
{
13+
GLuint CompileShader(GLenum type, const char *src) {
1514
GLuint shader = glCreateShader(type);
1615
glShaderSource(shader, 1, &src, NULL);
1716
glCompileShader(shader);
1817
assert(glGetError() == GL_NO_ERROR && "Shader compilation failed!");
1918
return shader;
2019
}
2120

22-
int main(int argc, char *argv[])
23-
{
21+
int main(int argc, char *argv[]) {
2422
emscripten_set_canvas_element_size("#canvas", 256, 256);
2523
EmscriptenWebGLContextAttributes attr;
2624
emscripten_webgl_init_context_attributes(&attr);

test/browser/webgl2_get_buffer_sub_data.cpp renamed to test/browser/webgl2_get_buffer_sub_data.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include <stdio.h>
66
#include <assert.h>
77

8-
int main()
9-
{
8+
int main() {
109
EmscriptenWebGLContextAttributes attr;
1110
emscripten_webgl_init_context_attributes(&attr);
1211
attr.majorVersion = 2;

test/browser/webgl2_invalid_teximage2d_type.cpp renamed to test/browser/webgl2_invalid_teximage2d_type.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// WebGL 2 core does not support GL_UNSIGNED_SHORT_5_6_5_REV extension.
1616
#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
1717

18-
int main()
19-
{
18+
int main() {
2019
EmscriptenWebGLContextAttributes attrs;
2120
emscripten_webgl_init_context_attributes(&attrs);
2221
attrs.majorVersion = 2;
@@ -30,7 +29,7 @@ int main()
3029
GLuint tex;
3130
glGenTextures(1, &tex);
3231
glBindTexture(GL_TEXTURE_2D, tex);
33-
void* data = new char[512];
32+
char data[512];
3433
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, data);
3534
assert(glGetError() != 0); // We should be getting an error
3635
return 0;

test/browser/webgl2_objects.cpp renamed to test/browser/webgl2_objects.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
{ \
1717
x; \
1818
GLenum error = glGetError(); \
19-
if( error != GL_NO_ERROR ) { \
20-
printf( "GL ERROR: %d, %s\n", (int)error, #x ); \
19+
if (error != GL_NO_ERROR) { \
20+
printf("GL ERROR: %d, %s\n", (int)error, #x); \
2121
assert(false); \
2222
} \
2323
} \
2424

2525

26-
int main()
27-
{
28-
emscripten_set_canvas_element_size( "#canvas", 100, 100 );
26+
int main() {
27+
emscripten_set_canvas_element_size("#canvas", 100, 100);
2928

3029
EmscriptenWebGLContextAttributes attrs;
3130
emscripten_webgl_init_context_attributes(&attrs);
@@ -34,9 +33,8 @@ int main()
3433
attrs.majorVersion = 2;
3534
attrs.minorVersion = 0;
3635

37-
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( "#canvas", &attrs );
38-
if (!context)
39-
{
36+
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);
37+
if (!context) {
4038
printf("Skipped: WebGL 2 is not supported.\n");
4139
return 0;
4240
}
@@ -45,27 +43,27 @@ int main()
4543
// Anisotropy
4644
//
4745
GLfloat maxAnisotropy;
48-
GL_CALL( glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy) );
46+
GL_CALL(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy));
4947
printf("max anisotropy: %f\n", maxAnisotropy);
5048
assert(maxAnisotropy > 1.f);
5149

5250
// Vertex Arrays
5351
//
5452
GLuint vao1;
55-
GL_CALL( glGenVertexArrays( 1, &vao1 ) );
56-
GL_CALL( glBindVertexArray( vao1 ) );
57-
printf( "vao1: %d\n", vao1 );
53+
GL_CALL(glGenVertexArrays(1, &vao1));
54+
GL_CALL(glBindVertexArray(vao1));
55+
printf("vao1: %d\n", vao1);
5856
assert(vao1 > 0);
5957

6058
GLint vao2;
61-
GL_CALL( glGetIntegerv( GL_VERTEX_ARRAY_BINDING, &vao2 ) );
62-
printf( "vao2: %d\n", vao2 );
59+
GL_CALL(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &vao2));
60+
printf("vao2: %d\n", vao2);
6361
assert(vao2 == vao1);
6462

6563
// Sampler Objects
6664
//
6765
GLuint sampler;
68-
GL_CALL( glGenSamplers( 1, &sampler ) );
66+
GL_CALL(glGenSamplers(1, &sampler));
6967
assert(sampler > 0);
7068

7169
#if 0 // TODO: Disabled due to https://github.com/KhronosGroup/WebGL/issues/2006
@@ -77,11 +75,11 @@ int main()
7775
assert(maxAnisotropy2 == maxAnisotropy);
7876
#endif
7977

80-
GL_CALL( glBindSampler( 0, sampler ) );
78+
GL_CALL(glBindSampler(0, sampler));
8179

8280
GLint sampler2;
83-
GL_CALL( glGetIntegerv( GL_SAMPLER_BINDING, &sampler2 ) );
84-
printf( "sampler2: %d\n", sampler2 );
81+
GL_CALL(glGetIntegerv(GL_SAMPLER_BINDING, &sampler2));
82+
printf("sampler2: %d\n", sampler2);
8583
assert(sampler2 == sampler);
8684

8785
return 0;

test/browser/webgl2_pbo.cpp renamed to test/browser/webgl2_pbo.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
#include <GLES3/gl3.h>
1010
#include <stdio.h>
1111
#include <stdlib.h>
12+
#include <string.h>
1213
#include <emscripten.h>
1314
#include <emscripten/html5.h>
1415
#include <assert.h>
1516

16-
#include <string>
17-
1817
#define GL_CALL( x ) \
1918
{ \
2019
x; \
@@ -58,7 +57,7 @@ int main()
5857
glBufferData(GL_PIXEL_UNPACK_BUFFER, 4*4, pixels, GL_STATIC_DRAW);
5958

6059
/* This should use the unpack buffer */
61-
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr));
60+
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
6261

6362
glDeleteBuffers(1, &buffer);
6463

@@ -67,9 +66,8 @@ int main()
6766
}
6867

6968
/* Verify that unpack buffer is used for compressed image upload as well */
70-
const std::string exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
71-
if(exts.find("WEBGL_compressed_texture_s3tc") != std::string::npos)
72-
{
69+
const char* exts = (const char*)glGetString(GL_EXTENSIONS);
70+
if (strstr(exts, "WEBGL_compressed_texture_s3tc") != NULL) {
7371
printf("WEBGL_compressed_texture_s3tc is supported, testing ...\n");
7472

7573
glBindTexture(GL_TEXTURE_2D, tex[1]);
@@ -81,17 +79,18 @@ int main()
8179
glBufferData(GL_PIXEL_UNPACK_BUFFER, 8, pixels, GL_STATIC_DRAW);
8280

8381
/* This should all use the unpack buffer */
84-
GL_CALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 0, 8, nullptr));
85-
GL_CALL(glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8, nullptr));
82+
GL_CALL(glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 0, 8, NULL));
83+
GL_CALL(glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8, NULL));
8684

8785
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
8886

8987
/* This not anymore */
9088
GL_CALL(glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8, pixels));
9189

9290
glDeleteBuffers(1, &buffer);
91+
} else {
92+
printf("WEBGL_compressed_texture_s3tc is NOT supported\n");
9393
}
94-
else printf("WEBGL_compressed_texture_s3tc is NOT supported\n");
9594

9695
glDeleteTextures(2, tex);
9796

File renamed without changes.

0 commit comments

Comments
 (0)