depth texture

204 views
Skip to first unread message

Bram Stolk

unread,
Jan 15, 2014, 1:13:39 AM1/15/14
to emscripte...@googlegroups.com
My emscripted OpenGL-ES2 game fails to create a depth texture.
The extension is supported on my machine, yet:

I try to create the depth texture with:
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOWBUFFERSIZE, SHADOWBUFFERSIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, depthbuffermem );

This results in:
GL_INVALID_OPERATION

I guess it could be a limit of WebGL not supporting depth textures?
Or could it be something emscripten does not tolerate?

I use firefox to load the HTML created with ASM_JS=1.
Also, my frag+vert GLSL shaders get compiled and linked just fine.

My OpenGL context is created via SDL:
SDL_Surface* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL );

Thx,

 bram

zephon

unread,
Jan 16, 2014, 11:38:41 AM1/16/14
to emscripte...@googlegroups.com
have you tried something like this?

#ifdef EMSCRIPTEN
  char req[] = "var ctx = Module.canvas.getContext('experimental-webgl');\n"
"if(ctx.getExtension('WEBKIT_WEBGL_depth_texture') != NULL) return 1;\n"
  "else if (ctx.getExtension('MOZ_WEBGL_depth_texture') != NULL) return 1;\n"
  "else return 0;\n";

int res = emscripten_run_script(req);
#endif

WebGL extensions must be activated with getExtension() before being used...

Bram Stolk

unread,
Jan 16, 2014, 1:05:59 PM1/16/14
to emscripte...@googlegroups.com
Thanks Zephon,


I tried your suggestion (although emscripten_run_script seems to be a void func, and cannot return an int.)

When added, and running in firefox, the application seems to hang, and never draws anything in the canvas.
I added it after setting the SDL video mode.

Bram Stolk

unread,
Jan 16, 2014, 2:35:34 PM1/16/14
to emscripte...@googlegroups.com
After modifying the script a bit, I can see that MOZ_WEBGL_depth_texture is there.
But the depth texture creation still fails.
I found the console feature in firefox (I'm new to web dev) and saw this output:

11:30:34.395 [object WebGLExtensionDepthTexture] swaag.js:5923
11:30:35.146 "ignoring setsockopt command" swaag.js:7672
11:30:35.103 Error: WebGL: texImage2D: with format of DEPTH_COMPONENT or DEPTH_STENCIL target must be TEXTURE_2D, data must be nullptr, level must be zero

Modified script:

        char req[] =
                "var ctx = Module.canvas.getContext('experimental-webgl');\n"
                "var wk_dt = ctx.getExtension('WEBKIT_WEBGL_depth_texture');\n"
                "var mz_dt = ctx.getExtension('MOZ_WEBGL_depth_texture');\n"
                "console.log( wk_dt );\n"
                "console.log( mz_dt );\n";
        emscripten_run_script(req);

I don't understand why it claims that data must be null pointer?
I use this code on many different devices, yet WEBGL does not like it.

 Bram

Mark Callow

unread,
Jan 16, 2014, 2:53:11 PM1/16/14
to emscripte...@googlegroups.com, Bram Stolk

On 2014/01/16 11:35, Bram Stolk wrote:
After modifying the script a bit, I can see that MOZ_WEBGL_depth_texture is there.
But the depth texture creation still fails.
I found the console feature in firefox (I'm new to web dev) and saw this output:

11:30:34.395 [object WebGLExtensionDepthTexture] swaag.js:5923
11:30:35.146 "ignoring setsockopt command" swaag.js:7672
11:30:35.103 Error: WebGL: texImage2D: with format of DEPTH_COMPONENT or DEPTH_STENCIL target must be TEXTURE_2D, data must be nullptr, level must be zero

Modified script:

        char req[] =
                "var ctx = Module.canvas.getContext('experimental-webgl');\n"
                "var wk_dt = ctx.getExtension('WEBKIT_WEBGL_depth_texture');\n"
                "var mz_dt = ctx.getExtension('MOZ_WEBGL_depth_texture');\n"
                "console.log( wk_dt );\n"
                "console.log( mz_dt );\n";
        emscripten_run_script(req);

I don't understand why it claims that data must be null pointer?
I use this code on many different devices, yet WEBGL does not like it.

Because WEBGL_depth_texture and ANGLE_depth_texture on which it is based say they do not support loading image data via the TexImage or TexSubImage commands. They do not give a reason, which is in my view a flaw in the ANGLE_depth_texture's issues list.

A couple of notes on the script: WEBGL_depth_texture has been a ratified extension since 2013.05. There should be no need to use WEBKIT and MOZ prefixes any more; Several browsers have passed WebGL conformance so getContext('webgl') should be tried before 'webgl-experimental'.

Regards

    -Mark

--
注意:この電子メールには、株式会社エイチアイの機密情報が含まれている場合が有ります。正式なメール受信者では無い場合はメール複製、 再配信または情報の使用を固く禁じております。エラー、手違いでこのメールを受け取られましたら削除を行い配信者にご連絡をお願いいたし ます.

NOTE: This electronic mail message may contain confidential and privileged information from HI Corporation. If you are not the intended recipient, any disclosure, photocopying, distribution or use of the contents of the received information is prohibited. If you have received this e-mail in error, please notify the sender immediately and permanently delete this message and all related copies.

Floh

unread,
Jan 16, 2014, 3:00:15 PM1/16/14
to emscripte...@googlegroups.com
This bug might be related:


I got 24.8 depth textures (but combined with a color buffer texture) working like this:

glGenTextures(1, &glDepthRenderTexture);
glBindTexture(GL_TEXTURE_2D, glDepthRenderTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);    // no mipmap filtering!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
n_printf("GLTextureFactory: creating 24.8 depth stencil texture\n");
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
GL_CHECK_ERROR();

This fails on current Nightly with a framebuffer completeness check (see bugzilla bug above).

Cheers,
-Floh.

Bram Stolk

unread,
Jan 16, 2014, 4:30:47 PM1/16/14
to emscripte...@googlegroups.com
Thanks guys!

My depth texture now works! Yeah! See screenshot.

So yes, passing '0' as data for glTexImage3D works, but the check framebuffer status indeed fails.
I use firefox 26.0 from Ubuntu.
But ignoring this failed framebuffer status seems to be fine, because my shadows show up just fine.

About webgl vs experimental-webgl:
Error: WebGL: Retrieving a WebGL context from a canvas via a request id ('webgl') different from the id used to create the context ('experimental-webgl') is not allowed.

So far I am really impressed by emscripten.
The only major issue left is with sockets, but apart from that, graphics, sound, keyb, mouse are all fine.

  Bram

Mark Callow

unread,
Jan 17, 2014, 12:17:20 PM1/17/14
to emscripte...@googlegroups.com, Bram Stolk

On 2014/01/16 13:30, Bram Stolk wrote:

About webgl vs experimental-webgl:
Error: WebGL: Retrieving a WebGL context from a canvas via a request id ('webgl') different from the id used to create the context ('experimental-webgl') is not allowed.

I suspected that might happen. Emscripten can't keep using 'experimental-webgl'. In theory it should go away but its continued use, such as this by Emscripten, makes that difficult. Emscripten should try 'webgl' first and only use 'experimental-webgl' if that fails. If Emscripten provides a way for the app. to get the context it created, without needing to call getContext, then it will not need to know which id was used at creation.

Alon Zakai

unread,
Jan 17, 2014, 8:21:39 PM1/17/14
to emscripte...@googlegroups.com
It looks like emscripten currently looks for webgl-experimental and then tries webgl if the first failed.

I don't understand the situation here though, what causes the two different ids? We just do canvas.getContext with the id once, I'm not sure where another id could get into the picture and cause confusion?

- Alon



--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Mark Callow

unread,
Jan 18, 2014, 1:23:12 PM1/18/14
to emscripte...@googlegroups.com, Alon Zakai

On 2014/01/17 17:21, Alon Zakai wrote:
It looks like emscripten currently looks for webgl-experimental and then tries webgl if the first failed.

I don't understand the situation here though, what causes the two different ids? We just do canvas.getContext with the id once, I'm not sure where another id could get into the picture and cause confusion?

The OP added JS to enable the depth texture extension and that JS is calling canvas.getContext(). Is there a better way to get the context that Emscripten created?

Alon Zakai

unread,
Jan 18, 2014, 9:51:07 PM1/18/14
to emscripte...@googlegroups.com
Oh, I see, so that was extra handwritten JS.

Yes, you can get the emscripten context from Module.ctx (recent emscripten also defines var GLctx for it).

- Alon



--
Reply all
Reply to author
Forward
0 new messages