Skip to content

Commit 58794a2

Browse files
committed
[wasm64] Fix reading/writing of gl attributes
See #21177
1 parent 72c3be3 commit 58794a2

File tree

5 files changed

+71
-37
lines changed

5 files changed

+71
-37
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: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ var LibraryHtml5WebGL = {
3030
HEAP32[a+i] = 0;
3131
}
3232

33-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)] =
34-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)] =
35-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)] =
36-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)] =
37-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)] =
38-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)] = 1;
33+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}})] =
34+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}})] =
35+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}})] =
36+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}})] =
37+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}})] =
38+
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}})] = 1;
3939

4040
#if PTHREADS
4141
// Default context initialization state (user can override):
@@ -80,25 +80,25 @@ var LibraryHtml5WebGL = {
8080
#if ASSERTIONS
8181
assert(attributes);
8282
#endif
83-
var a = attributes >> 2;
84-
var powerPreference = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference }}}>>2)];
83+
var powerPreference = {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference, 'i32') }}};
8584
var contextAttributes = {
86-
'alpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)],
87-
'depth': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)],
88-
'stencil': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.stencil }}}>>2)],
89-
'antialias': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)],
90-
'premultipliedAlpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)],
91-
'preserveDrawingBuffer': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer }}}>>2)],
85+
'alpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.alpha, 'i32') }}},
86+
'depth': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.depth, 'i32') }}},
87+
'stencil': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.stencil, 'i32') }}},
88+
'antialias': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.antialias, 'i32') }}},
89+
'premultipliedAlpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha, 'i32') }}},
90+
'preserveDrawingBuffer': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, 'i32') }}},
9291
'powerPreference': emscripten_webgl_power_preferences[powerPreference],
93-
'failIfMajorPerformanceCaveat': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat }}}>>2)],
92+
'failIfMajorPerformanceCaveat': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat, 'i32') }}},
9493
// The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure.
95-
majorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)],
96-
minorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion }}}>>2)],
97-
enableExtensionsByDefault: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)],
98-
explicitSwapControl: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl }}}>>2)],
99-
proxyContextToMainThread: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread }}}>>2)],
100-
renderViaOffscreenBackBuffer: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer }}}>>2)]
94+
majorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'i32') }}},
95+
minorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 'i32') }}},
96+
enableExtensionsByDefault: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'i32') }}},
97+
explicitSwapControl: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl, 'i32') }}},
98+
proxyContextToMainThread: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread, 'i32') }}},
99+
renderViaOffscreenBackBuffer: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, 'i32') }}}
101100
};
101+
err(contextAttributes);
102102

103103
var canvas = findCanvasEventTarget(target);
104104

@@ -243,10 +243,8 @@ var LibraryHtml5WebGL = {
243243
},
244244

245245
emscripten_webgl_do_commit_frame: () => {
246-
#if TRACE_WEBGL_CALLS
247246
var threadId = (typeof _pthread_self != 'undefined') ? _pthread_self : () => 1;
248247
err(`[Thread ${threadId()}, GL ctx: ${GL.currentContext.handle}]: emscripten_webgl_do_commit_frame()`);
249-
#endif
250248
if (!GL.currentContext || !GL.currentContext.GLctx) {
251249
#if GL_DEBUG
252250
dbg('emscripten_webgl_commit_frame() failed: no GL context set current via emscripten_webgl_make_context_current()!');

src/library_webgl.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
136136
emscripten_webgl_enable_WEBGL_multi_draw: (ctx) => webgl_enable_WEBGL_multi_draw(GL.contexts[ctx].GLctx),
137137

138138
$getEmscriptenSupportedExtensions__internal: true,
139-
$getEmscriptenSupportedExtensions: function(ctx) {
139+
$getEmscriptenSupportedExtensions: (ctx) => {
140140
// Restrict the list of advertised extensions to those that we actually
141141
// support.
142142
var supportedExtensions = [
@@ -280,7 +280,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
280280
// glGetError() to fetch it. As per GLES2 spec, only the first error is
281281
// remembered, and subsequent errors are discarded until the user has
282282
// cleared the stored error by a call to glGetError().
283-
recordError: function recordError(errorCode) {
283+
recordError: (errorCode) => {
284284
#if GL_TRACK_ERRORS
285285
if (!GL.lastError) {
286286
GL.lastError = errorCode;
@@ -370,7 +370,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
370370
}
371371
},
372372

373-
getTempVertexBuffer: function getTempVertexBuffer(sizeBytes) {
373+
getTempVertexBuffer: (sizeBytes) => {
374374
var idx = GL.log2ceilLookup(sizeBytes);
375375
var ringbuffer = GL.currentContext.tempVertexBuffers1[idx];
376376
var nextFreeBufferIndex = GL.currentContext.tempVertexBufferCounters1[idx];
@@ -387,7 +387,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
387387
return ringbuffer[nextFreeBufferIndex];
388388
},
389389

390-
getTempIndexBuffer: function getTempIndexBuffer(sizeBytes) {
390+
getTempIndexBuffer: (sizeBytes) => {
391391
var idx = GL.log2ceilLookup(sizeBytes);
392392
var ibo = GL.currentContext.tempIndexBuffers[idx];
393393
if (ibo) {
@@ -405,7 +405,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
405405
// doublebuffered temp VB memory pointers, so that every second frame
406406
// utilizes different set of temp buffers. The aim is to keep the set of
407407
// buffers being rendered, and the set of buffers being updated disjoint.
408-
newRenderingFrameStarted: function newRenderingFrameStarted() {
408+
newRenderingFrameStarted: () => {
409409
if (!GL.currentContext) {
410410
return;
411411
}
@@ -450,13 +450,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
450450

451451
#if GL_FFP_ONLY
452452
enabledClientAttribIndices: [],
453-
enableVertexAttribArray: function enableVertexAttribArray(index) {
453+
enableVertexAttribArray: (index) => {
454454
if (!GL.enabledClientAttribIndices[index]) {
455455
GL.enabledClientAttribIndices[index] = true;
456456
GLctx.enableVertexAttribArray(index);
457457
}
458458
},
459-
disableVertexAttribArray: function disableVertexAttribArray(index) {
459+
disableVertexAttribArray: (index) => {
460460
if (GL.enabledClientAttribIndices[index]) {
461461
GL.enabledClientAttribIndices[index] = false;
462462
GLctx.disableVertexAttribArray(index);
@@ -465,7 +465,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
465465
#endif
466466

467467
#if FULL_ES2
468-
calcBufLength: function calcBufLength(size, type, stride, count) {
468+
calcBufLength: (size, type, stride, count) => {
469469
if (stride > 0) {
470470
return count * stride; // XXXvlad this is not exactly correct I don't think
471471
}
@@ -475,7 +475,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
475475

476476
usedTempBuffers: [],
477477

478-
preDrawHandleClientVertexAttribBindings: function preDrawHandleClientVertexAttribBindings(count) {
478+
preDrawHandleClientVertexAttribBindings: (count) => {
479479
GL.resetBufferBinding = false;
480480

481481
// TODO: initial pass to detect ranges we need to upload, might not need
@@ -499,7 +499,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
499499
}
500500
},
501501

502-
postDrawHandleClientVertexAttribBindings: function postDrawHandleClientVertexAttribBindings() {
502+
postDrawHandleClientVertexAttribBindings: () => {
503503
if (GL.resetBufferBinding) {
504504
GLctx.bindBuffer(0x8892 /*GL_ARRAY_BUFFER*/, GL.buffers[GLctx.currentArrayBufferBinding]);
505505
}
@@ -1607,6 +1607,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
16071607
#endif
16081608
],
16091609
glTexImage2D: (target, level, internalFormat, width, height, border, format, type, pixels) => {
1610+
err("glTexImage2D", pixels);
16101611
#if MAX_WEBGL_VERSION >= 2
16111612
#if WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION
16121613
if ({{{ isCurrentContextWebGL2() }}}) {
@@ -3100,6 +3101,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
31003101
#if GL_ASSERTIONS
31013102
GL.validateGLObjectID(GL.shaders, shader, 'glShaderSource', 'shader');
31023103
#endif
3104+
out('glShaderSource', shader, count, string, length);
31033105
var source = GL.getSource(shader, count, string, length);
31043106

31053107
#if WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION
@@ -3673,7 +3675,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36733675
, '$emulGlGenVertexArrays'
36743676
#endif
36753677
],
3676-
glGenVertexArrays: function (n, arrays) {
3678+
glGenVertexArrays: (n, arrays) => {
36773679
#if LEGACY_GL_EMULATION
36783680
emulGlGenVertexArrays(n, arrays);
36793681
#else

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)