From aa5f88ae0f9441edebfd73eee4816cddb27ec165 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 28 Jul 2020 02:43:58 -0700 Subject: [PATCH] WebGL: Add workaround for skinning with Emscripten. So...we use integers for bone indices, and that makes them special. :) On May 26, the emsdk WebGL 2.0 wrapper for the integer variant of VertexAttribPointer was broken due to an incomplete renaming operation from an emscripten contributor. I have a pending upstream fix to the emscripten repo (#11742) but for now we can workaround this with a simple monkeypatch. Fixes #2856. --- filament/backend/src/opengl/OpenGLDriver.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/filament/backend/src/opengl/OpenGLDriver.cpp b/filament/backend/src/opengl/OpenGLDriver.cpp index 345da16cc3..67a7982380 100644 --- a/filament/backend/src/opengl/OpenGLDriver.cpp +++ b/filament/backend/src/opengl/OpenGLDriver.cpp @@ -31,6 +31,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + // To emulate EXT_multisampled_render_to_texture properly we need to be able to copy from // a non-ms texture to an ms attachment. This is only allowed with OpenGL (not GLES), which // would be fine for us. However, this is also not trivial to implement in Metal so for now @@ -2271,6 +2275,13 @@ void OpenGLDriver::setRenderPrimitiveBuffer(Handle rph, assert(bi != 0xFF); gl.bindBuffer(GL_ARRAY_BUFFER, eb->gl.buffers[bi]); if (UTILS_UNLIKELY(eb->attributes[i].flags & Attribute::FLAG_INTEGER_TARGET)) { + + // Emscripten regressed at the following PR so we work around it for now. + // https://github.com/emscripten-core/emscripten/pull/11225 + #ifdef __EMSCRIPTEN__ + EM_ASM_INT({ GL.currArrayBuffer = GLctx.currentArrayBufferBinding; }); + #endif + glVertexAttribIPointer(GLuint(i), getComponentCount(eb->attributes[i].type), getComponentType(eb->attributes[i].type),