Skip to content

Commit 1e40e2d

Browse files
committed
[wasm64] Fix reading/writing of gl attributes
See #21177
1 parent a12f228 commit 1e40e2d

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ jobs:
817817
browser64_4gb.test_audio_worklet*
818818
browser64_4gb.test_emscripten_log
819819
browser64_4gb.test_clientside_vertex_arrays_es3
820+
browser64_4gb.test_emscripten_animate_canvas_element_size*
820821
"
821822
test-browser-firefox:
822823
executor: bionic

src/library_html5_webgl.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@ var LibraryHtml5WebGL = {
5555
#if ASSERTIONS
5656
assert(attributes);
5757
#endif
58-
var a = attributes >> 2;
59-
var powerPreference = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference }}}>>2)];
58+
var powerPreference = {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference, 'i32') }}};
6059
var contextAttributes = {
61-
'alpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)],
62-
'depth': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)],
63-
'stencil': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.stencil }}}>>2)],
64-
'antialias': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)],
65-
'premultipliedAlpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)],
66-
'preserveDrawingBuffer': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer }}}>>2)],
60+
'alpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.alpha, 'i32') }}},
61+
'depth': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.depth, 'i32') }}},
62+
'stencil': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.stencil, 'i32') }}},
63+
'antialias': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.antialias, 'i32') }}},
64+
'premultipliedAlpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha, 'i32') }}},
65+
'preserveDrawingBuffer': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, 'i32') }}},
6766
'powerPreference': emscripten_webgl_power_preferences[powerPreference],
68-
'failIfMajorPerformanceCaveat': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat }}}>>2)],
67+
'failIfMajorPerformanceCaveat': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat, 'i32') }}},
6968
// The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure.
70-
majorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)],
71-
minorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion }}}>>2)],
72-
enableExtensionsByDefault: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)],
73-
explicitSwapControl: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl }}}>>2)],
74-
proxyContextToMainThread: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread }}}>>2)],
75-
renderViaOffscreenBackBuffer: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer }}}>>2)]
69+
majorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'i32') }}},
70+
minorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 'i32') }}},
71+
enableExtensionsByDefault: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'i32') }}},
72+
explicitSwapControl: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl, 'i32') }}},
73+
proxyContextToMainThread: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread, 'i32') }}},
74+
renderViaOffscreenBackBuffer: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, 'i32') }}}
7675
};
76+
err(contextAttributes);
7777

7878
var canvas = findCanvasEventTarget(target);
7979

test/code_size/hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4593,
5-
"a.js.gz": 2372,
4+
"a.js": 4654,
5+
"a.js.gz": 2382,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15613,
9-
"total_gz": 9475
8+
"total": 15674,
9+
"total_gz": 9485
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17937,
5-
"a.js.gz": 8077,
4+
"a.js": 17997,
5+
"a.js.gz": 8095,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21627,
9-
"total_gz": 11149
8+
"total": 21687,
9+
"total_gz": 11167
1010
}

test/code_size/hello_webgl_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4080,
5-
"a.js.gz": 2201,
4+
"a.js": 4140,
5+
"a.js.gz": 2210,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15100,
9-
"total_gz": 9304
8+
"total": 15160,
9+
"total_gz": 9313
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17415,
5-
"a.js.gz": 7894,
4+
"a.js": 17475,
5+
"a.js.gz": 7913,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21105,
9-
"total_gz": 10966
8+
"total": 21165,
9+
"total_gz": 10985
1010
}

test/float_tex.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#include <cmath>
1010
#include <iostream>
1111
#include <vector>
12-
extern "C" {
1312
#include <GL/gl.h>
1413
#include <GL/glut.h>
15-
}
14+
1615
static const char vertex_shader[] =
1716
"#ifdef GL_ES\n"
1817
"precision lowp float;\n"
@@ -44,6 +43,7 @@ static const char fragment_shader[] =
4443
"}\n"
4544
"if ( dst > 0.5) discard;\n"
4645
"}";
46+
4747
struct NodeInfo { //structure that we want to transmit to our shaders
4848
float x;
4949
float y;
@@ -55,8 +55,9 @@ GLuint nodeSamplerLocation; //shader sampler address
5555
GLuint indicesAttributeLocation; //shader attribute address
5656
GLuint indicesVBO; //Vertex Buffer Object Id;
5757
const int nbNodes = 512;
58-
NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
58+
NodeInfo data[nbNodes]; //our data that will be transmitted using float texture.
5959
double alpha = 0; //use to make a simple funny effect;
60+
6061
static void updateFloatTexture() {
6162
int count = 0;
6263
for (float x=0; x < nbNodes; ++x ) {
@@ -79,7 +80,9 @@ static void updateFloatTexture() {
7980
glBindTexture(GL_TEXTURE_2D, 0);
8081
alpha -= 0.001;
8182
}
83+
8284
static void glut_draw_callback(void) {
85+
printf("glut_draw_callback\n");
8386
glDisable(GL_CULL_FACE);
8487
glDisable(GL_DEPTH_TEST);
8588
glEnable(GL_BLEND);
@@ -96,6 +99,7 @@ static void glut_draw_callback(void) {
9699
glDrawArrays(GL_POINTS, 0, nbNodes);
97100
glutSwapBuffers();
98101
}
102+
99103
GLuint createShader(const char source[], int type) {
100104
GLint status;
101105
char msg[512];
@@ -110,6 +114,7 @@ GLuint createShader(const char source[], int type) {
110114
assert(status == GL_TRUE);
111115
return shader;
112116
}
117+
113118
static void gl_init(void) {
114119
GLuint program = glCreateProgram();
115120
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
@@ -145,6 +150,7 @@ static void gl_init(void) {
145150
glEnable(GL_POINT_SPRITE);
146151
#endif
147152
}
153+
148154
int main(int argc, char *argv[]) {
149155
glutInit(&argc, argv);
150156
glutInitWindowSize(640, 480);
@@ -153,6 +159,7 @@ int main(int argc, char *argv[]) {
153159
/* Set up glut callback functions */
154160
glutDisplayFunc(glut_draw_callback );
155161
gl_init();
162+
printf("done setup\n");
156163
glutMainLoop();
157164
return 0;
158165
}

0 commit comments

Comments
 (0)