OES_texture_float扩展名的使用 [英] OES_texture_float extension use
问题描述
如何使用OES_texture_float扩展名? 我不明白是否有必要在texImage2D函数中指定参数.
How to use the OES_texture_float extension? I do not understand that it is necessary to specify the arguments the function texImage2D.
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,size[0],size[1]);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER, rb);
var texture=gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
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);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size[0], size[1],0, gl.RGBA, ???, ???);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D, texture, 0);
您需要写些什么而不是"???"
What you need to write instead of "???"
推荐答案
假设您启用了扩展名,则其gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size[0], size[1],0, gl.RGBA, gl.FLOAT, null);
Assuming you have the extension enabled, its gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size[0], size[1],0, gl.RGBA, gl.FLOAT, null);
但是,有一个大洞穴. OES_texture_float
扩展名不能保证您将能够渲染到浮点纹理.这只是意味着您可以创建和读取浮点纹理.允许您呈现浮动效果的实际扩展名是 WEBGL_color_buffer_float .但是,如果浏览器支持该扩展名,则不会显示该扩展名.因此,您必须
HOWEVER, there is a BIG CAVEAT. OES_texture_float
extension doesnt guarantee that you will be able to render to a floating point texture. It just means you can create and read from float point texture. The actual extension that allows you to render to float is WEBGL_color_buffer_float. BUT browsers do not bother to show this extension if they support it. So you have to do
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE){
// cant render
}
检查将纹理附加到FBO之后是否可以真正渲染浮动纹理.
to check if you can actually render to float textures after you attach the textures to FBO.
来源:花了几个小时来弄清楚为什么该事物即使支持OES_texture_float
扩展也无法在IE中工作.
Source: spent hours to figure out why the thing isnt working in IE even though it supports OES_texture_float
extension.
另外请注意,除非您同时启用了OES_texture_float_linear
扩展名(自2015年8月起在大多数移动设备上不可用),否则您不能对浮点纹理使用gl.LINEAR
过滤
Also be aware that you can not use gl.LINEAR
filtering with floating point textures unless you also enable the OES_texture_float_linear
extension which is not available on most mobile devices as of August 2015
这篇关于OES_texture_float扩展名的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!