Hello all. I've been taking some wonderful tutorials on making water with OpenGL (I'm using WebGL2), but I'm a little confused about FBO's. I'm trying to get a depth texture attachment, but unfortunately getting the following warning:
"[.Offscreen-For-WebGL-0x7fcd65022600]GL ERROR :GL_INVALID_VALUE : glTexImage2D: invalid internal_format GL_FALSE"
This is what I got for gl.texImage2D:
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT32, this.width, this.height, 0, gl.DEPTH_COMPONENT, gl.FLOAT, null);
I'm using gl.DEPTH_COMPONENT32 since that's what the tutorial is using. I'm trying to get that grayish looking image that represents the depth in my scene but not sure what format to use. There's definitely something I'm doing wrong :(
Btw, if I comment out "this.makeDepthTextureAttachment(gl);" I get no warnings. I've also never had trouble getting a color texture attachment, Depth texture is what I have problem with.
This is my FBO implementation, thank you very much in advanced:
class FBO {
constructor (width, height) {
const gl = Core.getRenderer().gl;
this._fbo = gl.createFramebuffer();
this.bind(gl);
this._width = width;
this._height = height;
this._depthTexture = false;
this._colorTexture = false;
this.makeDepthTextureAttachment(gl);
this.makeColorTextureAttachment(gl);
this.unbind(gl);
}
get fbo () { return this._fbo; }
get depthTexture () { return this._depthTexture; }
get colorTexture () { return this._colorTexture; }
get width () { return this._width; }
get height () { return this._height; }
makeDepthTextureAttachment (gl) {
this._depthTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.depthTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT32, this.width, this.height, 0, gl.DEPTH_COMPONENT, gl.FLOAT, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, this.depthTexture, 0);
}
makeColorTextureAttachment (gl) {
this._colorTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this._colorTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, this.width, this.height, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._colorTexture, 0);
}
bindColorTexture () {
const gl = Core.getRenderer().gl;
gl.bindTexture(gl.TEXTURE_2D, this._colorTexture);
}
bind (gl) {
gl.bindFramebuffer(gl.FRAMEBUFFER, this.fbo);
}
unbind(gl) {
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
}
}