Skip to content

Commit

Permalink
[wasm64] Fix reading/writing of gl attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Jan 28, 2024
1 parent 4fc9f72 commit e7ab4e3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 38 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
30 changes: 15 additions & 15 deletions src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,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
12 changes: 6 additions & 6 deletions test/code_size/hello_webgl2_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 569,
"a.html.gz": 379,
"a.js": 4593,
"a.js.gz": 2372,
"a.wasm": 10458,
"a.wasm.gz": 6726,
"total": 15620,
"total_gz": 9477
"a.js": 4654,
"a.js.gz": 2382,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15674,
"total_gz": 9485
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl2_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 567,
"a.html.gz": 379,
"a.js": 17950,
"a.js.gz": 8081,
"a.js": 17997,
"a.js.gz": 8095,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 21640,
"total_gz": 11153
"total": 21687,
"total_gz": 11167
}
12 changes: 6 additions & 6 deletions test/code_size/hello_webgl_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 569,
"a.html.gz": 379,
"a.js": 4080,
"a.js.gz": 2201,
"a.wasm": 10458,
"a.wasm.gz": 6726,
"total": 15107,
"total_gz": 9306
"a.js": 4140,
"a.js.gz": 2210,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15160,
"total_gz": 9313
}
8 changes: 4 additions & 4 deletions test/code_size/hello_webgl_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 567,
"a.html.gz": 379,
"a.js": 17428,
"a.js.gz": 7898,
"a.js": 17475,
"a.js.gz": 7913,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 21118,
"total_gz": 10970
"total": 21165,
"total_gz": 10985
}
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 e7ab4e3

Please sign in to comment.