setupDepthTexture method
void
setupDepthTexture(
- dynamic framebuffer,
- RenderTarget renderTarget
)
Implementation
void setupDepthTexture(framebuffer, RenderTarget renderTarget) {
var isCube = (renderTarget.isWebGLCubeRenderTarget);
if (isCube) {
throw ('Depth Texture with cube render targets is not supported');
}
state.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
if (!(renderTarget.depthTexture != null && renderTarget.depthTexture is DepthTexture)) {
throw ('renderTarget.depthTexture must be an instance of three.DepthTexture');
}
// upload an empty depth texture with framebuffer size
final depthTexture = renderTarget.depthTexture!;
if (properties.get(depthTexture)["__webglTexture"] == null ||
depthTexture.image.width != renderTarget.width ||
depthTexture.image.height != renderTarget.height) {
depthTexture.image.width = renderTarget.width;
depthTexture.image.height = renderTarget.height;
depthTexture.needsUpdate = true;
}
setTexture2D(depthTexture, 0);
var webglDepthTexture = properties.get(depthTexture)["__webglTexture"];
var samples = getRenderTargetSamples(renderTarget);
if (depthTexture.format == DepthFormat) {
if (useMultisampledRenderToTexture(renderTarget)) {
multisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT(
gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, webglDepthTexture, 0, samples);
} else {
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, webglDepthTexture, 0);
}
} else if (depthTexture.format == DepthStencilFormat) {
if (useMultisampledRenderToTexture(renderTarget)) {
multisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT(
_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples);
} else {
_gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0);
}
} else {
throw ('Unknown depthTexture format');
}
}