emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.91k stars 3.32k forks source link

OpenGL ES 2.0 emulation with FULL_ES2=1 is not fully implemented? #4033

Closed akasilov closed 5 years ago

akasilov commented 8 years ago

Hi everybody! I am trying to compile my Qt application which uses OpenGL ES 2.0.
When I run it browser I get following error messages:

WebGL: INVALID_OPERATION: bindBuffer: buffers can not be used with multiple targets index.js:6297
WebGL: INVALID_OPERATION: drawElements: no ELEMENT_ARRAY_BUFFER bound

On the web I found a list of WebGL limitations with respect to OpenGL ES 2.0 : https://www.khronos.org/registry/webgl/specs/1.0/#webgl_gl_differences It looks like my problem comes from the section 6.1 Buffer Object Binding:

In the WebGL API, a given buffer object may only be bound to one of the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER binding points in its lifetime. This restriction implies that a given buffer object may contain either vertices or indices, but not both

So, apparently the application uses single buffer object to store both vertices and indexes which is forbidden by WebGL. Should Emscripten handle this automatically? If yes, maybe this feature is not fully implemented yet? Any ideas?

Thank you!

kripken commented 8 years ago

Yes, we should handle that - looks like a bug. Do you have a minimal testcase showing the issue?

juj commented 8 years ago

Handling this automatically in the emulation layer feels difficult and costly, because it means that we have to duplicate under the hood the full contents of such a buffer (and track the changes as well and apply them to both!) so that it can be dual-bound. One should expect that this kind of emulation will come with a performance tradeoff. I'd recommend looking at refactoring the usage of the application so that it doesn't need to bind the same buffer to both vertices and indices at the same time.

akasilov commented 8 years ago

Hi! Unfortunately I don't have a small piece of code which would reproduce the issue but I have a call stack of a single frame from Qt demo application "gallery" https://doc.qt.io/qt-5/qtquickextras-gallery-example.html. If you compile this application with emscripten you should see the same error.
screenshot from 2016-01-13 09 44 20

eukarpov commented 8 years ago

It can confuse a driver and it's not the best guidelines but otherwise it's legal to bind a buffer to any target and QT does it. But not in WebGL. simple example reproduces this problem

GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo);

WebGL: INVALID_OPERATION: bindBuffer: buffers can not be used with multiple targets

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.