Having trouble calling glBlitFrameBuffer

106 views
Skip to first unread message

Tim Luther Lewis

unread,
Feb 9, 2020, 3:31:49 PM2/9/20
to emscripten-discuss
Hi, 
  I'm porting my engine to WASM and it's all going well so far but I've hit a snag with this.  I'm linking with -s FULL_ES2=1  -s FULL_ES3=1 but it still gives me 'missing function: glBlitFramebuffer' whenever I call it. 
I noticed there was a discussion about this function on github back in February 2019 (https://github.com/emscripten-core/emscripten/pull/7588). Does anybody know if it's broken or perhaps I've missed something vital?

Thanks in advance,
Tim.

Message has been deleted

שחר לנגבהיים

unread,
Feb 10, 2020, 12:17:02 AM2/10/20
to emscripten-discuss


 Blitting only works in WebGL2. Link with -s MAX_WEBGL_VERSION=2 (or -s USE_WEBGL2=1 on older emscripten versions). Also make sure that you use WebGL2 contexts in your web app.

キャロウ マーク

unread,
Feb 10, 2020, 2:12:23 AM2/10/20
to emscripte...@googlegroups.com


On Feb 10, 2020, at 14:17, ⁨שחר לנגבהיים⁩ <⁨nih...@gmail.com⁩> wrote:

Link with -s MAX_WEBGL_VERSION=2 (or -s USE_WEBGL2=1 on older emscripten versions)

If emscripten has indeed changed in this fashion, I find the new version very confusing. MAX_WEBGL_VERSION=2 means to me use no version greater than 2. It does not mean must use WebGL 2 at minimum.

Regards

    -Mark

signature.asc

Shachar Langbeheim

unread,
Feb 10, 2020, 2:57:20 AM2/10/20
to emscripten-discuss
There is also the MIN_WEBGL_VERSION argument that can be passed, to complement that. See the PR that introduced this change: https://github.com/emscripten-core/emscripten/pull/10020

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CCA926B7-F100-4973-91EA-2EF9FC0A1C8C%40callow.im.

キャロウ マーク

unread,
Feb 10, 2020, 3:13:57 AM2/10/20
to emscripten-discuss

On Feb 10, 2020, at 16:57, Shachar Langbeheim <nih...@gmail.com> wrote:

There is also the MIN_WEBGL_VERSION argument that can be passed, to complement that. See the PR that introduced this change: https://github.com/emscripten-core/emscripten/pull/10020

In that case you will have to specify -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2 to limit the build to WEBGL 2 which is what the OP needs. If only the latter is sufficient, someone’s idea of the meaning of these terms is very different from mine.

Regards

    -Mark
signature.asc

Tim Luther Lewis

unread,
Feb 10, 2020, 4:01:11 AM2/10/20
to emscripten-discuss
Thanks for the responses guys but unfortunately, I'm still getting 'anthraciteWASM.js:8995 missing function: glBlitFramebuffer'

I've added both '-s MIN_WEBGL_VERSION=2' and '-s MAX_WEBGL_VERSION=2' and I'm creating my context with 'const context = canvas.getContext("webgl2", {antialias: false, depth: true});'

I do get a bunch of linker warnings when I build, however:

---8<-------------------------------
warning: undefined symbol: emscripten_glBeginQuery
warning: undefined symbol: emscripten_glBeginTransformFeedback
warning: undefined symbol: emscripten_glBindBufferBase
warning: undefined symbol: emscripten_glBindBufferRange
warning: undefined symbol: emscripten_glBindSampler
warning: undefined symbol: emscripten_glBindTransformFeedback
warning: undefined symbol: emscripten_glBlitFramebuffer
warning: undefined symbol: emscripten_glClearBufferfi
warning: undefined symbol: emscripten_glClearBufferfv
warning: undefined symbol: emscripten_glClearBufferiv
warning: undefined symbol: emscripten_glClearBufferuiv
warning: undefined symbol: emscripten_glClientWaitSync
warning: undefined symbol: emscripten_glCompressedTexImage3D
...
--8<--------------------------------------------
but seeing as everything ran fine, other than the blit, I assumed this was just some sort of late binding issue for external functions.

Is it possible that there's a problem with glBlitFramebuffer that hasn't been picked up?

Charles Vaughn

unread,
Feb 10, 2020, 3:23:17 PM2/10/20
to emscripten-discuss
Looks like you're missing a linker input, do you have -lGLESv2 on your link command?

Tim Luther Lewis

unread,
Feb 10, 2020, 7:07:22 PM2/10/20
to emscripten-discuss
I tried that, although I hadn't thought of linking libraries directly like that (emscripten seems to do it's own thing with '-s USE_WEBGL2=1', which probably resolves to some library using internal magic that I haven't deep dived on yet) 

In my generated WASM.js file, I still see this:

 function _glBlitFramebuffer(
  ) {
  err('missing function: glBlitFramebuffer'); abort(-1);
  }

Which is clearly why it's not working: it's not there! Why it's not there though, is still a mystery to me :/

Alon Zakai

unread,
Feb 11, 2020, 12:42:00 PM2/11/20
to emscripte...@googlegroups.com
Looking in src/*, it seems like that function is not implemented yet - it needs to be added there. A PR would be very welcome if someone is interested! It should be in src/library_webgl2.js.

Linking with -s MAX_WEBGL_VERSION=2 should have been enough for this to work, if the function were there (that says "the max version that will be used is 2, so anything between the min version - default 1 - and the max is supported; the default max is 1, so raising the max is necessary).

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Jukka Jylänki

unread,
Feb 11, 2020, 1:26:16 PM2/11/20
to emscripte...@googlegroups.com
I think Alon was looking too quickly: glBlitFramebuffer is
implemented, but it is one of those trivial "pass-through" functions
(functions that have only primitive numbers as args) so you'll find it
by searching for 'blitframebuffer' rather than 'glblitframebuffer'.
Its implementation is done on this line:

https://github.com/emscripten-core/emscripten/blob/7b2d3d0a3fc0d5238d5dee0371de7cc24d3542a7/src/library_webgl2.js#L1015

There is one test in the test suite that does touch glBlitframebuffer,
see https://github.com/emscripten-core/emscripten/blob/7b2d3d0a3fc0d5238d5dee0371de7cc24d3542a7/tests/webgl_with_closure.cpp#L176
.

See https://github.com/emscripten-core/emscripten/blob/7b2d3d0a3fc0d5238d5dee0371de7cc24d3542a7/tests/test_browser.py#L2659
for the test. It can be run from command line with "python
tests/runner.py browser.test_webgl_with_closure"

The flag -s USE_WEBGL2=1 is an alias/synonym to -s
MAX_WEBGL_VERSION=2. (passing either one has identical behavior)

-s MAX_WEBGL_VERSION=2 means that the generated build supports
creating WebGL 2 contexts (in addition to supporting WebGL 1
contexts). Some of the emulated libraries (SDL,GLUT,GLFW,GLEW,...
emulation stubs in src/library_x.js) will default to creating WebGL 2
contexts if -s MAX_WEBGL_VERSION=2 is passed. The html5.h API WebGL
context creation function has a version field that is set to specify
the desired context versoin.

Passing -s MIN_WEBGL_VERSION=2 drops support for WebGL 1 altogether,
to get a size micro-optimization for the build output. This is
intended for pages that know they cannot operate with WebGL 1, and
wish not to have to pay code size for generated WebGL 1 support
functions.

Try passing -lwebgl2.js explicitly on the link line if there is any
oddness. Running with environment variable EMCC_DEBUG=1 and linker
flag -s VERBOSE=1 may help troubleshooting some linking decisions that
are being made.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpT9mrc%3DczjFbhVBaG1fdChUn7WKnLnHEa9EBOg_LH6nbA%40mail.gmail.com.

Tim Luther Lewis

unread,
Feb 11, 2020, 7:11:16 PM2/11/20
to emscripten-discuss
Thanks for the reply JJ. So, it seems like the link's not implemented yet then.  
I tried hacking my own in ealier and it failed but I gave it another go just now,
hacking in this line in my generated 'anthraciteWASM.js' file and lo and behold it kinda worked. The buffer's being copied alright: it looks a little off but I think that might be down to other small discrepancies between my desktop build and WASM.
Progress though: I've got some full screen effects now. Is there any chance that somebody can implement the function in the library as below?

function _glBlitFramebuffer(a,b,c,d,e,f,g,h,i,j) {
    GLctx["blitFramebuffer"](a,b,c,d,e,f,g,h,i,j);
>> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/9c7adf13-64e9-4993-8f87-f6f669a5b787%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Jukka Jylänki

unread,
Feb 12, 2020, 7:59:28 AM2/12/20
to emscripte...@googlegroups.com
There is no such thing as the link not being implemented. The function
is implemented in library_webgl2.js, there is nothing more to
implement.

Trying out a test program test.c with

#include <GLES3/gl3.h>
#include <emscripten/html5.h>

int main()
{
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.majorVersion = 2;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx =
emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);
glBlitFramebuffer(0, 0, 0, 0, 1, 1, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}

build with emcc test.c -s MAX_WEBGL_VERSION=2 -o a.html

does succeed for me, and the resulting a.js has

function _glBlitFramebuffer(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)
{ GLctx['blitFramebuffer'](x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) }

The issue is somewhere else. Perhaps you can correlate your build
against the test build, and/or verify that the test build works for
you?

ke 12. helmik. 2020 klo 2.11 Tim Luther Lewis (luther...@gmail.com)
kirjoitti:
>> >> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
>> >> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/9c7adf13-64e9-4993-8f87-f6f669a5b787%40googlegroups.com.
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
>> > To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/0db7c526-95c7-4619-b366-8912ae71f1b1%40googlegroups.com.

Floh

unread,
Feb 13, 2020, 9:39:20 AM2/13/20
to emscripten-discuss
FWIW, I've been using glBlitFramebuffer() since forever to resolve MSAA render target textures into a non-MSAA texture, only supported in GLES3/WebGL2 though.

I have the call in an #ifdef though, so that it's not being used when compiled against the GLES2 headers.

It works with USE_WEBGL2 and a dynamic fallback to WebGL1 if WebGL2 could not be initialized (that's what the check for !_sg.gl.gles2 check is for):


Also make sure to include the matching GL headers (GLES3/gl3.h with USE_WEBGL2, and GLES2/gl2.h otherwise).

Cheers,
-Floh.

Floh

unread,
Feb 13, 2020, 9:50:10 AM2/13/20
to emscripten-discuss
PS: looking at the linker errors you're getting it looks like you're including and using the GLES3 headers, but then somehow end up with linking against the GLES2 JS shim.

As far as I can see in my build scripts, just a "-s USE_WEBGL2=1" on the linker command line should do the trick (my build scripts are quite old, so I'm not using MIN/MAX_WEBGL_VERSION and -lGLESv2 etc, not sure what's the current recommend procedure is).

Tim Luther Lewis

unread,
Feb 13, 2020, 5:24:27 PM2/13/20
to emscripten-discuss
Hi Floh,
  Thanks very much for that little test program - I can confirm that compiled fine and showed the blit function in the right place. My code, not so fortunate.

This is what I use to build my project. I've simplified it as per your suggestion but still no joy:

call emcc -o ./anthraciteWASM.js ../src/UnityBuildWASM.cpp -O3 --pre-js ./pre_init.js --post-js ./post_init.js -fno-rtti -fno-cxx-exceptions -msimd128 -s ASSERTIONS=2 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1  -I..\include --js-library utils.js -s USE_WEBGL2=1 -s USE_BULLET=1 -s USE_FREETYPE=1 -s USE_LIBJPEG=1 -s USE_LIBPNG=1 -s WASM=1 -s NO_EXIT_RUNTIME=1 -std=c++1z -s "EXPORTED_FUNCTIONS=['_main', '_resizeDisplay']" -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap','stringToUTF8','resizeDisplay']" -DGOLD -DUSEOGL -DWASM -DUSING_GL3 -DUSING_PHYSICS -DUSING_OLD_BULLET -DNO_FREE_IMAGE -DTHREADING_DISABLED -Wno-inconsistent-missing-override -Wno-overloaded-virtual -Wno-unused-variable -Wno-unused-private-field -Wno-deprecated-register -Wno-switch -s FORCE_FILESYSTEM=1 

There's a lot of stuff there that's probably not relevant to our problem but it's a big project, takes a while to compile, so I haven't been able to try too many permutations yet.

Just looking at that, any clues?

Thanks again,
Tim. 
Reply all
Reply to author
Forward
0 new messages