Skip to content

Commit

Permalink
[wasm64] Fix reading/writing of gl attributes
Browse files Browse the repository at this point in the history
See #21177
  • Loading branch information
sbc100 committed Jan 27, 2024
1 parent 72c3be3 commit c8381c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ jobs:
browser64_4gb.test_audio_worklet*
browser64_4gb.test_emscripten_log
browser64_4gb.test_clientside_vertex_arrays_es3
browser64_4gb.test_emscripten_animate_canvas_element_size*
"
test-browser-firefox:
executor: bionic
Expand Down
42 changes: 21 additions & 21 deletions src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ var LibraryHtml5WebGL = {
HEAP32[a+i] = 0;
}

HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)] =
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)] =
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)] =
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)] =
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)] =
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)] = 1;
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}})] =
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}})] =
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}})] =
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}})] =
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}})] =
HEAP8[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}})] = 1;

#if PTHREADS
// Default context initialization state (user can override):
Expand Down Expand Up @@ -80,25 +80,25 @@ var LibraryHtml5WebGL = {
#if ASSERTIONS
assert(attributes);
#endif
var a = attributes >> 2;
var powerPreference = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference }}}>>2)];
var powerPreference = {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference, 'i32') }}};
var contextAttributes = {
'alpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)],
'depth': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)],
'stencil': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.stencil }}}>>2)],
'antialias': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)],
'premultipliedAlpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)],
'preserveDrawingBuffer': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer }}}>>2)],
'alpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.alpha, 'i32') }}},
'depth': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.depth, 'i32') }}},
'stencil': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.stencil, 'i32') }}},
'antialias': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.antialias, 'i32') }}},
'premultipliedAlpha': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha, 'i32') }}},
'preserveDrawingBuffer': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, 'i32') }}},
'powerPreference': emscripten_webgl_power_preferences[powerPreference],
'failIfMajorPerformanceCaveat': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat }}}>>2)],
'failIfMajorPerformanceCaveat': !!{{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat, 'i32') }}},
// The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure.
majorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)],
minorVersion: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion }}}>>2)],
enableExtensionsByDefault: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)],
explicitSwapControl: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl }}}>>2)],
proxyContextToMainThread: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread }}}>>2)],
renderViaOffscreenBackBuffer: HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer }}}>>2)]
majorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion, 'i32') }}},
minorVersion: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.minorVersion, 'i32') }}},
enableExtensionsByDefault: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault, 'i32') }}},
explicitSwapControl: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.explicitSwapControl, 'i32') }}},
proxyContextToMainThread: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread, 'i32') }}},
renderViaOffscreenBackBuffer: {{{ makeGetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, 'i32') }}}
};
err(contextAttributes);

var canvas = findCanvasEventTarget(target);

Expand Down
13 changes: 10 additions & 3 deletions test/float_tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include <cmath>
#include <iostream>
#include <vector>
extern "C" {
#include <GL/gl.h>
#include <GL/glut.h>
}

static const char vertex_shader[] =
"#ifdef GL_ES\n"
"precision lowp float;\n"
Expand Down Expand Up @@ -44,6 +43,7 @@ static const char fragment_shader[] =
"}\n"
"if ( dst > 0.5) discard;\n"
"}";

struct NodeInfo { //structure that we want to transmit to our shaders
float x;
float y;
Expand All @@ -55,8 +55,9 @@ GLuint nodeSamplerLocation; //shader sampler address
GLuint indicesAttributeLocation; //shader attribute address
GLuint indicesVBO; //Vertex Buffer Object Id;
const int nbNodes = 512;
NodeInfo * data = new NodeInfo[nbNodes]; //our data that will be transmitted using float texture.
NodeInfo data[nbNodes]; //our data that will be transmitted using float texture.
double alpha = 0; //use to make a simple funny effect;

static void updateFloatTexture() {
int count = 0;
for (float x=0; x < nbNodes; ++x ) {
Expand All @@ -79,7 +80,9 @@ static void updateFloatTexture() {
glBindTexture(GL_TEXTURE_2D, 0);
alpha -= 0.001;
}

static void glut_draw_callback(void) {
printf("glut_draw_callback\n");
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
Expand All @@ -96,6 +99,7 @@ static void glut_draw_callback(void) {
glDrawArrays(GL_POINTS, 0, nbNodes);
glutSwapBuffers();
}

GLuint createShader(const char source[], int type) {
GLint status;
char msg[512];
Expand All @@ -110,6 +114,7 @@ GLuint createShader(const char source[], int type) {
assert(status == GL_TRUE);
return shader;
}

static void gl_init(void) {
GLuint program = glCreateProgram();
glAttachShader(program, createShader(vertex_shader , GL_VERTEX_SHADER));
Expand Down Expand Up @@ -145,6 +150,7 @@ static void gl_init(void) {
glEnable(GL_POINT_SPRITE);
#endif
}

int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
Expand All @@ -153,6 +159,7 @@ int main(int argc, char *argv[]) {
/* Set up glut callback functions */
glutDisplayFunc(glut_draw_callback );
gl_init();
printf("done setup\n");
glutMainLoop();
return 0;
}
Expand Down

0 comments on commit c8381c5

Please sign in to comment.