OES_texture_float extension use

你说的曾经没有我的故事 提交于 2019-12-11 21:15:34

问题


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 "???"


回答1:


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);

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
}

to check if you can actually render to float textures after you attach the textures to FBO.

Source: spent hours to figure out why the thing isnt working in IE even though it supports OES_texture_float extension.

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



来源:https://stackoverflow.com/questions/31973148/oes-texture-float-extension-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!