-
Notifications
You must be signed in to change notification settings - Fork 3.5k
workaround_old_chromium_webgl_bug #7459
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3864,6 +3864,11 @@ def test_webgl_from_client_side_memory_without_default_enabled_extensions(self): | |
| def test_webgl_offscreen_framebuffer(self): | ||
| self.btest('webgl_draw_triangle.c', '0', args=['-lGL', '-s', 'OFFSCREEN_FRAMEBUFFER=1', '-DEXPLICIT_SWAP=1']) | ||
|
|
||
| # Tests that -s WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG=1 rendering works. | ||
| @requires_graphics_hardware | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually test that code path - does it force the polyfill on somehow?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just tests that code compiles with that flag enabled. I don't think it is worth spending time to maintaining a test infrastructure where we would enforce the path to kick in. |
||
| def test_webgl_workaround_webgl_uniform_upload_bug(self): | ||
| self.btest('webgl_draw_triangle_with_uniform_color.c', '0', args=['-lGL', '-s', 'WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG=1']) | ||
|
|
||
| # Tests the feature that shell html page can preallocate the typed array and place it to Module.buffer before loading the script page. | ||
| # In this build mode, the -s TOTAL_MEMORY=xxx option will be ignored. | ||
| # Preallocating the buffer in this was is asm.js only (wasm needs a Memory). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* | ||
| * Copyright 2018 The Emscripten Authors. All rights reserved. | ||
| * Emscripten is available under two separate licenses, the MIT license and the | ||
| * University of Illinois/NCSA Open Source License. Both these licenses can be | ||
| * found in the LICENSE file. | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <emscripten/emscripten.h> | ||
| #include <emscripten/html5.h> | ||
| #include <GLES2/gl2.h> | ||
|
|
||
| GLuint compile_shader(GLenum shaderType, const char *src) | ||
| { | ||
| GLuint shader = glCreateShader(shaderType); | ||
| glShaderSource(shader, 1, &src, NULL); | ||
| glCompileShader(shader); | ||
|
|
||
| GLint isCompiled = 0; | ||
| glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled); | ||
| if (!isCompiled) | ||
| { | ||
| GLint maxLength = 0; | ||
| glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); | ||
| char *buf = (char*)malloc(maxLength+1); | ||
| glGetShaderInfoLog(shader, maxLength, &maxLength, buf); | ||
| printf("%s\n", buf); | ||
| free(buf); | ||
| return 0; | ||
| } | ||
|
|
||
| return shader; | ||
| } | ||
|
|
||
| GLuint create_program(GLuint vertexShader, GLuint fragmentShader) | ||
| { | ||
| GLuint program = glCreateProgram(); | ||
| glAttachShader(program, vertexShader); | ||
| glAttachShader(program, fragmentShader); | ||
| glBindAttribLocation(program, 0, "apos"); | ||
| glBindAttribLocation(program, 1, "acolor"); | ||
| glLinkProgram(program); | ||
| return program; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| EmscriptenWebGLContextAttributes attr; | ||
| emscripten_webgl_init_context_attributes(&attr); | ||
| #ifdef EXPLICIT_SWAP | ||
| attr.explicitSwapControl = 1; | ||
| #endif | ||
| #ifdef DRAW_FROM_CLIENT_MEMORY | ||
| // This test verifies that drawing from client-side memory when enableExtensionsByDefault==false works. | ||
| attr.enableExtensionsByDefault = 0; | ||
| #endif | ||
|
|
||
| EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr); | ||
| emscripten_webgl_make_context_current(ctx); | ||
|
|
||
| static const char vertex_shader[] = | ||
| "attribute vec4 apos;" | ||
| "attribute vec4 acolor;" | ||
| "varying vec4 color;" | ||
| "void main() {" | ||
| "color = acolor;" | ||
| "gl_Position = apos;" | ||
| "}"; | ||
| GLuint vs = compile_shader(GL_VERTEX_SHADER, vertex_shader); | ||
|
|
||
| static const char fragment_shader[] = | ||
| "precision lowp float;" | ||
| "varying vec4 color;" | ||
| "uniform vec4 color2;" | ||
| "void main() {" | ||
| "gl_FragColor = color*color2;" | ||
| "}"; | ||
| GLuint fs = compile_shader(GL_FRAGMENT_SHADER, fragment_shader); | ||
|
|
||
| GLuint program = create_program(vs, fs); | ||
| glUseProgram(program); | ||
|
|
||
| static const float pos_and_color[] = { | ||
| // x, y, r, g, b | ||
| -0.6f, -0.6f, 1, 0, 0, | ||
| 0.6f, -0.6f, 0, 1, 0, | ||
| 0.f, 0.6f, 0, 0, 1, | ||
| }; | ||
|
|
||
| #ifdef DRAW_FROM_CLIENT_MEMORY | ||
| glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, pos_and_color); | ||
| glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (void*)(pos_and_color+2)); | ||
| #else | ||
| GLuint vbo; | ||
| glGenBuffers(1, &vbo); | ||
| glBindBuffer(GL_ARRAY_BUFFER, vbo); | ||
| glBufferData(GL_ARRAY_BUFFER, sizeof(pos_and_color), pos_and_color, GL_STATIC_DRAW); | ||
| glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 20, 0); | ||
| glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 20, (void*)8); | ||
| #endif | ||
| glEnableVertexAttribArray(0); | ||
| glEnableVertexAttribArray(1); | ||
|
|
||
| float color2[4] = { 0.0f, 1.f, 0.0f, 1.0f }; | ||
| glUniform4fv(glGetUniformLocation(program, "color2"), 1, color2); | ||
| glClearColor(0.3f,0.3f,0.3f,1); | ||
| glClear(GL_COLOR_BUFFER_BIT); | ||
| glDrawArrays(GL_TRIANGLES, 0, 3); | ||
|
|
||
| #ifdef EXPLICIT_SWAP | ||
| emscripten_webgl_commit_frame(); | ||
| #endif | ||
|
|
||
| #ifdef REPORT_RESULT | ||
| REPORT_RESULT(0); | ||
| #endif | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed for every single F32 heap view?
How about creating a helper function to avoid all the code duplication,
makeGLHEAPView(adding "GL" in the name, and it adds this check)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is needed only specifically for these views that it was added to. I would not want to craft any abstractions for this. If I added a
makeGLHEAPView()(which lives in coresrc/parseTools.js) that we'd have to maintain just for this case, then someone would wonder why only parts ofsrc/library_gl.jsusedmakeGLHEAPView()and others used regularmakeHEAPView()and it might leak to being used everywhere. I'd prefer to do this as KISS as possible, not building any complexity on top of this.