Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get access to depth texture #170

Open
X-skyer opened this issue Aug 12, 2020 · 3 comments
Open

how to get access to depth texture #170

X-skyer opened this issue Aug 12, 2020 · 3 comments

Comments

@X-skyer
Copy link

X-skyer commented Aug 12, 2020

Hi, I am working in WebGL1.0 using twgl, recently I want to use this extension;"WEBGL_depth_texture", and create frame buffer using these code:

const attachments = [
{ format: Constants.RGBA, type: Constants.UNSIGNED_BYTE, min: Constants.NEAREST, mag: Constants.NEAREST, wrap: Constants.REPEAT },
{ format: Constants.DEPTH_COMPONENT16, type: Constants.UNSIGNED_SHORT, min: Constants.NEAREST, mag: Constants.NEAREST, wrap: Constants.REPEAT },
];

this.frameBufferInfo = createFramebufferInfo(WebGLContext.getInstance(), attachments, this.width, this.height);

but when i want to use the depth texture as input in anthor shader:

this.frameBufferInfo.attachments[1];

it goes wrong, does any one can tell me where i'm wrong.

@greggman
Copy link
Owner

greggman commented Aug 12, 2020

DEPTH_COMPONENT16 is not a depth texture it's a renderbuffer, DEPTH_COMPONENT is a texture, and the valid types are gl.UNSIGNED_SHORT and gl.UNSIGNED_INT

And of course you need to check for and enable 'WEBGL_depth_texture' either manually or by calling twgl.addExtensionsToContext (though even if you call that you still need to check the extension exists if you want to handle failure

@X-skyer
Copy link
Author

X-skyer commented Aug 24, 2020

{ format: Constants.DEPTH_COMPONENT, type: Constants.UNSIGNED_SHORT, min: Constants.NEAREST, mag: Constants.NEAREST, wrap: Constants.REPEAT }
Thanks! I tried this, but got an error : "unknown internal format". which is from function twgl.getTextureInternalFormatInfo().

but in this function, i found no support for DEPTH_COMPONENT

@greggman
Copy link
Owner

Color me embarrassed. Apparently I've never made a depth texture with twgl in WebGL1

4.16.0 should work

Example:

https://twgljs.org/examples/depthtexture-webgl1.html

Relevant code

  const attachments = [
    { format: gl.RGBA, },
    { format: gl.DEPTH_COMPONENT },
  ];
  const fbi = twgl.createFramebufferInfo(gl, attachments, 256, 256);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants