问题描述
我正在尝试创建一个WebGL选择缓冲区;
I'm trying to create a WebGL pick buffer;
任何人都能看到我在这里做错了吗?
Can anyone see what I'm doing wrong here?
我在Mozilla / 5.0上获得Incomplete framebuffer:FRAMEBUFFER_UNSUPPORTED(X11; Linux x86_64; rv:2.0b3pre)Gecko / 20100724 Minefield / 4.0b3pre和Chrome 5.0 .375.99。必须是明显的,盯着我,但我看不到它。它显然是有效的,有纹理......但是不支持?
I'm getting "Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED" on Mozilla/5.0 (X11; Linux x86_64; rv:2.0b3pre) Gecko/20100724 Minefield/4.0b3pre and Chrome 5.0.375.99. Must be obvious and staring right at me but I cant see it. It's apparently valid, has a texture..but "unsupported"?
var gl = canvas.context;
var frameBuf = gl.createFramebuffer();
var renderBuf = gl.createRenderbuffer();
var pickTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, pickTexture);
var width = 400;
var height = 400;
try {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, width, height, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
} catch (e) {
// Null rejected
var tex = new WebGLUnsignedByteArray(width * height * 3);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, width, height, 0, gl.RGB, gl.UNSIGNED_BYTE, tex);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuf);
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuf);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, pickTexture, 0);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderBuf);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuf);
if (!gl.isFramebuffer(frameBuf)) {
throw("Invalid framebuffer");
}
var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
switch (status) {
case gl.FRAMEBUFFER_COMPLETE:
break;
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
throw("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
break;
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
throw("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
break;
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
throw("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
break;
case gl.FRAMEBUFFER_UNSUPPORTED:
throw("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");
break;
default:
throw("Incomplete framebuffer: " + status);
}
推荐答案
由Kenneth Russell提供的解决方案 - 通过为纹理指定这些设置来修复:
Solution provided by Kenneth Russell - fixed by specifying these settings for the texture:
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
这篇关于为什么这个WebGL帧缓冲区使用会抛出FRAMEBUFFER_UNSUPPORTED?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!