Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm64] Fix reading/writing of gl attributes #21187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)];
sbc100 marked this conversation as resolved.
Show resolved Hide resolved
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
8 changes: 4 additions & 4 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": 2369,
"a.js": 4654,
"a.js.gz": 2378,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15613,
"total_gz": 9472
"total": 15674,
"total_gz": 9481
}
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": 17937,
"a.js.gz": 8074,
"a.js": 17997,
"a.js.gz": 8093,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 21627,
"total_gz": 11146
"total": 21687,
"total_gz": 11165
}
8 changes: 4 additions & 4 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": 2198,
"a.js": 4140,
"a.js.gz": 2206,
"a.wasm": 10451,
"a.wasm.gz": 6724,
"total": 15100,
"total_gz": 9301
"total": 15160,
"total_gz": 9309
}
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": 17415,
"a.js.gz": 7891,
"a.js": 17475,
"a.js.gz": 7911,
"a.mem": 3123,
"a.mem.gz": 2693,
"total": 21105,
"total_gz": 10963
"total": 21165,
"total_gz": 10983
}
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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these changes look unrelated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just cleaned up the test a little while I was working on it.

#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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep these printfs in the test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think it better overall to have more print statements in the test.

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
Loading