试图在深度纹理中绘制模型Chrome会出错: WebGL的: INVALID_FRAMEBUFFER_OPERATION:drawArrays:附加纹理的内部格式不可着色
创建纹理和帧缓冲区:
var fb=self.gl.createFramebuffer();
self.gl.bindFramebuffer(self.gl.FRAMEBUFFER, fb);
var rb=self.gl.createRenderbuffer();
self.gl.bindRenderbuffer(self.gl.RENDERBUFFER, rb);
self.gl.renderbufferStorage(self.gl.RENDERBUFFER, self.gl.DEPTH_COMPONENT16,256,256);
self.gl.framebufferRenderbuffer(self.gl.FRAMEBUFFER, self.gl.DEPTH_ATTACHMENT,self.gl.RENDERBUFFER, rb);
var texture_rtt=self.gl.createTexture();
self.gl.bindTexture(self.gl.TEXTURE_2D, texture_rtt);
self.gl.texParameteri(self.gl.TEXTURE_2D, self.gl.TEXTURE_MAG_FILTER, self.gl.LINEAR);
self.gl.texParameteri(self.gl.TEXTURE_2D, self.gl.TEXTURE_MIN_FILTER, self.gl.LINEAR);
self.gl.texParameteri(self.gl.TEXTURE_2D, self.gl.TEXTURE_WRAP_S, self.gl.CLAMP_TO_EDGE);
self.gl.texParameteri(self.gl.TEXTURE_2D, self.gl.TEXTURE_WRAP_T, self.gl.CLAMP_TO_EDGE);
self.gl.texImage2D(self.gl.TEXTURE_2D, 0, self.gl.DEPTH_COMPONENT, 256, 256,0, self.gl.DEPTH_COMPONENT, self.gl.UNSIGNED_SHORT, null);
self.gl.framebufferTexture2D(self.gl.FRAMEBUFFER, self.gl.COLOR_ATTACHMENT0,self.gl.TEXTURE_2D, texture_rtt, 0);
self.gl.bindTexture(self.gl.TEXTURE_2D, null);
self.gl.bindFramebuffer(self.gl.FRAMEBUFFER, null);
可以找到示例:here
答案 0 :(得分:3)
您无法将深度纹理附加为颜色:
framebufferTexture2D(self.gl.FRAMEBUFFER, self.gl.COLOR_ATTACHMENT0
错了。您只能将深度纹理附加到深度。 DEPTH_ATTACHMENT。如果要将深度渲染为颜色,则必须在着色器中执行此操作。
答案 1 :(得分:1)
看看:http://learningwebgl.com/blog/?p=1786
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
var rb = gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 256, 256);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, rb);
var rttTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, rttTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 256, 256, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, rttTexture, 0);