From 6caa8218acf94647f3ce1951164db22ec0f6060a Mon Sep 17 00:00:00 2001 From: Rik Cabanier Date: Sun, 10 Oct 2021 08:19:01 -0700 Subject: [PATCH] Initial submit of WEBGL_multisampled_render_to_texture proposal --- .../extension.xml | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 extensions/proposals/WEBGL_multisampled_render_to_texture/extension.xml diff --git a/extensions/proposals/WEBGL_multisampled_render_to_texture/extension.xml b/extensions/proposals/WEBGL_multisampled_render_to_texture/extension.xml new file mode 100644 index 0000000000..7e96fcc6f1 --- /dev/null +++ b/extensions/proposals/WEBGL_multisampled_render_to_texture/extension.xml @@ -0,0 +1,160 @@ + + + + WEBGL_multisampled_render_to_texture + + WebGL working group (public_webgl 'at' khronos.org) + + + Rik Cabanier, Facebook + + ?? + + + + + + + + + Adds support for rendering multisampled to a color renderable texture, without requiring an explicit resolve of multisample data. + + + + +[Exposed=(Window,Worker), LegacyNoInterfaceObject] +interface WEBGL_multisampled_render_to_texture { + const GLenum RENDERBUFFER_SAMPLES_EXT = 0x8CAB; + const GLenum FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT = 0x8D56; + const GLenum MAX_SAMPLES_EXT = 0x8D57; + const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT = 0x8D6C; + + undefined renderbufferStorageMultisampleEXT( + GLenum target, GLsizei samples, + GLenum internalformat, + GLsizei width, GLsizei height); + + undefined framebufferTexture2DMultisampleEXT( + GLenum target, GLenum attachment, + GLenum textarget, WebGLTexture? texture, + GLint level, GLsizei samples); +}; + + + + + + + + + + + + + + + + + + + + + + + + + Calling with the pname set to RENDERBUFFER_SAMPLES_EXT returns the number of samples. +
+ + The return type depends on the parameter queried: + + + +
pnamereturned type
RENDERBUFFER_SAMPLES_EXTGLint
+
+ + + + + + Calling with the pname set to MAX_SAMPLES_EXT returns the maximum number of samples. +
+ + The return type depends on the parameter queried: + + + +
pnamereturned type
MAX_SAMPLES_EXTGLint
+
+ + + + + Calling with the pname set to FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT returns the number of samples in the multisampled texture. +
+ The return type depends on the parameter queried: + + + +
pnamereturned type
MAX_SAMPLES_EXTGLint
+
+
+ + + The error OUT_OF_MEMORY is generated when RenderbufferStorageMultisampleEXT cannot create storage of the specified size. + + + If RenderbufferStorageMultisampleEXT is called with a value of samples that is greater than MAX_SAMPLES_EXT, then the error INVALID_VALUE is generated. + + + The error INVALID_ENUM is generated if FramebufferTexture2DMultisampleEXT is called with a target that is not FRAMEBUFFER, DRAW_FRAMEBUFFER, or READ_FRAMEBUFFER. + + + The error INVALID_ENUM is generated if FramebufferTexture2DMultisampleEXT is called with an attachment that is not COLOR_ATTACHMENT0. + + + The error INVALID_ENUM is generated if FramebufferTexture2DMultisampleEXT is called with a textarget that is not TEXTURE_2D, TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_Y, or TEXTURE_CUBE_MAP_NEGATIVE_Z. + + + The error INVALID_OPERATION is generated if FramebufferTexture2DMultisampleEXT is called with samples greater than the maximum number of samples supported for target and its internalformat. + + + +
+    var gl = document.createElement('canvas').getContext('webgl2');
+    var ext = gl.getExtension('WEBGL_multisampled_render_to_texture');
+    var samples = gl.getParameter(ext.MAX_SAMPLES_EXT);
+    var fb = gl.createFramebuffer();
+    gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fb);
+
+    // Create color texture and storage.
+    var colorTex = gl.createTexture();
+    gl.bindTexture(gl.TEXTURE_2D, colorTex);
+    gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, 512, 512);
+    ext.framebufferTexture2DMultisampleEXT(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0, samples);
+
+    // Create depth texture and storage.
+    var depthStencilTex = gl.createTexture();
+    gl.bindTexture(gl.TEXTURE_2D, depthStencilTex);
+    ext.renderbufferStorageMultisampleEXT(gl.RENDER_BUFFER, samples, gl.DEPTH32F_STENCIL8, 512, 512);
+    ext.framebufferTexture2DMultisampleEXT(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, depthStencilTex, 0, samples);
+
+    gl.drawElements(...);  // Draw will be done with multisampling and flushed to the non-multisample texture.
+    
+
+ + + Initial revision. + + +