Skip to content
Snippets Groups Projects
Commit 24b4fce3 authored by Alexander Rose's avatar Alexander Rose
Browse files

improve RG texture format handling

parent f506210b
No related branches found
No related tags found
No related merge requests found
...@@ -233,14 +233,13 @@ export class DpoitPass { ...@@ -233,14 +233,13 @@ export class DpoitPass {
const { resources, extensions: { colorBufferHalfFloat, textureHalfFloat } } = webgl; const { resources, extensions: { colorBufferHalfFloat, textureHalfFloat } } = webgl;
// textures // textures
if (isWebGL2(webgl.gl)) {
this.depthTextures = [ this.depthTextures = [
resources.texture('image-float32', 'rg', 'float', 'nearest'), resources.texture('image-float32', 'rg', 'float', 'nearest'),
resources.texture('image-float32', 'rg', 'float', 'nearest') resources.texture('image-float32', 'rg', 'float', 'nearest')
]; ];
this.depthTextures[0].define(width, height);
this.depthTextures[1].define(width, height);
if (isWebGL2(webgl.gl)) {
this.colorFrontTextures = colorBufferHalfFloat && textureHalfFloat ? [ this.colorFrontTextures = colorBufferHalfFloat && textureHalfFloat ? [
resources.texture('image-float16', 'rgba', 'fp16', 'nearest'), resources.texture('image-float16', 'rgba', 'fp16', 'nearest'),
resources.texture('image-float16', 'rgba', 'fp16', 'nearest') resources.texture('image-float16', 'rgba', 'fp16', 'nearest')
...@@ -259,6 +258,11 @@ export class DpoitPass { ...@@ -259,6 +258,11 @@ export class DpoitPass {
} else { } else {
// in webgl1 drawbuffers must be in the same format for some reason // in webgl1 drawbuffers must be in the same format for some reason
this.depthTextures = [
resources.texture('image-float32', 'rgba', 'float', 'nearest'),
resources.texture('image-float32', 'rgba', 'float', 'nearest')
];
this.colorFrontTextures = [ this.colorFrontTextures = [
resources.texture('image-float32', 'rgba', 'float', 'nearest'), resources.texture('image-float32', 'rgba', 'float', 'nearest'),
resources.texture('image-float32', 'rgba', 'float', 'nearest') resources.texture('image-float32', 'rgba', 'float', 'nearest')
...@@ -270,6 +274,9 @@ export class DpoitPass { ...@@ -270,6 +274,9 @@ export class DpoitPass {
]; ];
} }
this.depthTextures[0].define(width, height);
this.depthTextures[1].define(width, height);
this.colorFrontTextures[0].define(width, height); this.colorFrontTextures[0].define(width, height);
this.colorFrontTextures[1].define(width, height); this.colorFrontTextures[1].define(width, height);
...@@ -277,10 +284,12 @@ export class DpoitPass { ...@@ -277,10 +284,12 @@ export class DpoitPass {
this.colorBackTextures[1].define(width, height); this.colorBackTextures[1].define(width, height);
// framebuffers // framebuffers
this.depthFramebuffers = [resources.framebuffer(), resources.framebuffer()]; this.depthFramebuffers = [resources.framebuffer(), resources.framebuffer()];
this.colorFramebuffers = [resources.framebuffer(), resources.framebuffer()]; this.colorFramebuffers = [resources.framebuffer(), resources.framebuffer()];
// renderables // renderables
this.blendBackRenderable = getBlendBackDpoitRenderable(webgl, this.colorBackTextures[0]); this.blendBackRenderable = getBlendBackDpoitRenderable(webgl, this.colorBackTextures[0]);
this.renderable = getEvaluateDpoitRenderable(webgl, this.colorFrontTextures[0]); this.renderable = getEvaluateDpoitRenderable(webgl, this.colorFrontTextures[0]);
......
...@@ -66,7 +66,8 @@ export function getFormat(gl: GLRenderingContext, format: TextureFormat, type: T ...@@ -66,7 +66,8 @@ export function getFormat(gl: GLRenderingContext, format: TextureFormat, type: T
return gl.RGB; return gl.RGB;
case 'rg': case 'rg':
if (isWebGL2(gl) && type === 'float') return gl.RG; if (isWebGL2(gl) && type === 'float') return gl.RG;
return gl.RGBA; else if (isWebGL2(gl) && type === 'int') return gl.RG_INTEGER;
else throw new Error('texture format "rg" requires webgl2 and type "float" or int"');
case 'rgba': case 'rgba':
if (isWebGL2(gl) && type === 'int') return gl.RGBA_INTEGER; if (isWebGL2(gl) && type === 'int') return gl.RGBA_INTEGER;
return gl.RGBA; return gl.RGBA;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment