Page 1 of 1

Render targets in emscripten

Posted: Sat Nov 09, 2024 10:59 pm
by n00bc0de
I am trying to render to a texture in the emscripten port and I always get a black screen. It works find if just using the default render target.

Are render targets just not supported through emscripten?

Re: Render targets in emscripten

Posted: Sun Nov 10, 2024 1:06 am
by CuteAlien
Sorry didn't try RTT's back then and it's been a few years since I experimented with emscripten. I just run a quick test and it seems emscripten will need either power of two textures (so like 128, 256, 512 etc) or CLAMP_TO_EDGE has to be set when drawing textures. As a workaround - either use a power of two render target texture or set the following lines before drawing your RTT:

Code: Select all

SMaterial& matRtt = driver->getMaterial2D();
matRtt.TextureLayer[0].TextureWrapU = ETC_CLAMP_TO_EDGE;
matRtt.TextureLayer[0].TextureWrapV = ETC_CLAMP_TO_EDGE;
driver->enableMaterial2D(true);
It's probably a good idea to just make this the default for InitMaterial2D in the WebGL driver, but as usual I checked the forum before going to sleep, so not digging deeper anymore today ;-)

Also warning - emscripten was pretty experimental. Also by now some of it is a bit outdated (haven't touched that in 3-4 years). Some stuff will not work yet ,for example particles. If you have other bugs always a good idea to check the console output in the browser (F12 in Firefox).

Re: Render targets in emscripten

Posted: Sun Nov 10, 2024 2:40 pm
by n00bc0de
Thanks. That instantly fixed my issue.

Re: Render targets in emscripten

Posted: Sun Nov 10, 2024 10:14 pm
by CuteAlien
If you update to svn ogl-es [r6674] you can now remove those lines again if you did draw the RTT with drawTexture functions.
I had hoped I could make clamp to edge default for 2D, but turns out that can break stuff, so now WebGL driver doing checks.
Interestingly enough we already convert all other textures to power of two. Which may not really be necessary in all cases I suppose, but I won't touch that for now.