I'm trying to render an environment map to a separate cube map mip levels.
const levels = 8;
const width = 128;
const height = 128;
const internalFormat = gl.RGBA8;
const type = gl.UNSIGNED_BYTE;
const format = gl.RGBA;
const bindingPoint = gl.TEXTURE_CUBE_MAP;
const level = 1;
const target = gl.TEXTURE_CUBE_MAP_POSITIVE_X + 0;
const magFilter = gl.LINEAR;
const minFilter = gl.LINEAR_MIPMAP_LINEAR;
const wrapS = gl.CLAMP_TO_EDGE;
const wrapT = gl.CLAMP_TO_EDGE;
const texId = gl.createTexture();
gl.bindTexture(bindingPoint, texId);
gl.texParameteri(bindingPoint, gl.TEXTURE_WRAP_S, wrapS);
gl.texParameteri(bindingPoint, gl.TEXTURE_WRAP_T, wrapT);
gl.texParameteri(bindingPoint, gl.TEXTURE_MIN_FILTER, minFilter);
gl.texParameteri(bindingPoint, gl.TEXTURE_MAG_FILTER, magFilter);
gl.texStorage2D(bindingPoint, levels, internalFormat, width, height);
const framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, texId, level);
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
console.assert(status === gl.FRAMEBUFFER_COMPLETE, 'incomplete!');
gl.viewport(0, 0, width/2, height/2);
// cube rendering
After all I read it inside fragment shader via textureLod()
passing level as third argument. But result is black color instead of proper environment color.
According to this it has to work, but it doesn't.
Tested on Chromium 70.0.3538.110 version, on Firefox 63.0.3.