Skip to content

Commit 4378dcb

Browse files
committed
Initial submit of WEBGL_multisampled_render_to_texture proposal
1 parent 4857dac commit 4378dcb

File tree

1 file changed

+160
-0
lines changed
  • extensions/proposals/WEBGL_multisampled_render_to_texture

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0"?>
2+
3+
<extension href="WEBGL_multisampled_render_to_texture/">
4+
<name>WEBGL_multisampled_render_to_texture</name>
5+
<contact>
6+
<a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL working group</a> (public_webgl 'at' khronos.org)
7+
</contact>
8+
<contributors>
9+
<contributor>Rik Cabanier, Facebook</contributor>
10+
</contributors>
11+
<number>??</number>
12+
<depends>
13+
<api version="1.0"/>
14+
</depends>
15+
<overview>
16+
<mirrors href="https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture2.txt" name="EXT_multisampled_render_to_texture2">
17+
</mirrors>
18+
<features>
19+
<feature>
20+
Adds support for rendering multisampled to a color renderable texture, without requiring an explicit resolve of multisample data.
21+
</feature>
22+
</features>
23+
</overview>
24+
<idl xml:space="preserve">
25+
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
26+
interface WEBGL_multisampled_render_to_texture {
27+
const GLenum RENDERBUFFER_SAMPLES_EXT = 0x8CAB;
28+
const GLenum FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT = 0x8D56;
29+
const GLenum MAX_SAMPLES_EXT = 0x8D57;
30+
const GLenum FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT = 0x8D6C;
31+
32+
undefined renderbufferStorageMultisampleEXT(
33+
GLenum target, GLsizei samples,
34+
GLenum internalformat,
35+
GLsizei width, GLsizei height);
36+
37+
undefined framebufferTexture2DMultisampleEXT(
38+
GLenum target, GLenum attachment,
39+
GLenum textarget, WebGLTexture? texture,
40+
GLint level, GLsizei samples);
41+
};
42+
</idl>
43+
<newfun>
44+
<function name="renderbufferStorageMultisampleEXT" type="undefined">
45+
<param name="target" type="GLenum"/>
46+
<param name="samples" type="GLsizei"/>
47+
<param name="internalformat" type="GLenum"/>
48+
<param name="width" type="GLsizei"/>
49+
<param name="height" type="GLsizei"/>
50+
</function>
51+
</newfun>
52+
<newfun>
53+
<function name="framebufferTexture2DMultisampleEXT" type="undefined">
54+
<param name="target" type="GLenum"/>
55+
<param name="attachment" type="GLenum"/>
56+
<param name="textarget" type="GLenum"/>
57+
<param name="texture" type="GLuint"/>
58+
<param name="level" type="GLint"/>
59+
<param name="samples" type="GLsizei"/>
60+
</function>
61+
</newfun>
62+
<newtok>
63+
<function name="GetRenderbufferParameter" type="any">
64+
<param name="target" type="GLenum"/>
65+
<param name="pname" type="GLenum"/>
66+
Calling with the <code>pname</code> set to <code>RENDERBUFFER_SAMPLES_EXT</code> returns the number of samples.
67+
<br/>
68+
<!--
69+
If <code>renderbufferStorageMultisampleEXT</code> is called with <code>samples</code> is zero, then <code>RENDERBUFFER_SAMPLES_EXT</code> is set to zero.
70+
Otherwise <code>samples</code> represents a request for a desired minimum number
71+
of samples. Since different implementations may support different
72+
sample counts for multisampled rendering, the actual number of samples
73+
allocated for the renderbuffer image is implementation-dependent.
74+
However, the resulting value for <code>RENDERBUFFER_SAMPLES_EXT</code> is
75+
guaranteed to be greater than or equal to samples and no more than the
76+
next larger sample count supported by the implementation.
77+
<br/>
78+
-->
79+
The return type depends on the parameter queried:
80+
<table width="30%">
81+
<tr><th>pname</th><th>returned type</th></tr>
82+
<tr><td>RENDERBUFFER_SAMPLES_EXT</td><td>GLint</td></tr>
83+
</table>
84+
</function>
85+
<function name="checkFramebufferStatus" type="GLenum">
86+
<param name="target" type="GLenum"/>
87+
</function>
88+
<function name="getParameter" type="any">
89+
<param name="pname" type="GLenum"/>
90+
Calling with the <code>pname</code> set to <code>MAX_SAMPLES_EXT</code> returns the maximum number of samples.
91+
<br/>
92+
93+
The return type depends on the parameter queried:
94+
<table width="30%">
95+
<tr><th>pname</th><th>returned type</th></tr>
96+
<tr><td>MAX_SAMPLES_EXT</td><td>GLint</td></tr>
97+
</table>
98+
</function>
99+
<function name="getFramebufferAttachmentParameter" type="any">
100+
<param name="target" type="GLenum"/>
101+
<param name="attachment" type="GLenum"/>
102+
<param name="pname" type="GLenum"/>
103+
Calling with the <code>pname</code> set to <code>FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT</code> returns the number of samples in the multisampled texture.
104+
<br/>
105+
The return type depends on the parameter queried:
106+
<table width="30%">
107+
<tr><th>pname</th><th>returned type</th></tr>
108+
<tr><td>MAX_SAMPLES_EXT</td><td>GLint</td></tr>
109+
</table>
110+
</function>
111+
</newtok>
112+
<errors>
113+
<error>
114+
The error <code>OUT_OF_MEMORY</code> is generated when <code>RenderbufferStorageMultisampleEXT</code> cannot create storage of the specified size.
115+
</error>
116+
<error>
117+
If <code>RenderbufferStorageMultisampleEXT</code> is called with a value of <code>samples</code> that is greater than <code>MAX_SAMPLES_EXT</code>, then the error <code>INVALID_VALUE</code> is generated.
118+
</error>
119+
<error>
120+
The error <code>INVALID_ENUM</code> is generated if<code> FramebufferTexture2DMultisampleEXT</code> is called with a target that is not <code>FRAMEBUFFER</code>, <code>DRAW_FRAMEBUFFER</code>, or <code>READ_FRAMEBUFFER</code>.
121+
</error>
122+
<error>
123+
The error <code>INVALID_ENUM</code> is generated if <code>FramebufferTexture2DMultisampleEXT</code> is called with an <code>attachment</code> that is not <code>COLOR_ATTACHMENT0</code>.
124+
</error>
125+
<error>
126+
The error <code>INVALID_ENUM</code> is generated if <code>FramebufferTexture2DMultisampleEXT</code> is called with a textarget that is not <code>TEXTURE_2D</code>, <code>TEXTURE_CUBE_MAP_POSITIVE_X</code>, <code>TEXTURE_CUBE_MAP_POSITIVE_Y</code>, <code>TEXTURE_CUBE_MAP_POSITIVE_Z</code>, <code>TEXTURE_CUBE_MAP_NEGATIVE_X</code>, <code>TEXTURE_CUBE_MAP_NEGATIVE_Y</code>, or <code>TEXTURE_CUBE_MAP_NEGATIVE_Z</code>.
127+
</error>
128+
<error>
129+
The error <code>INVALID_OPERATION</code> is generated if <code>FramebufferTexture2DMultisampleEXT</code> is called with samples greater than the maximum number of samples supported for target and its internalformat.
130+
</error>
131+
</errors>
132+
<samplecode xml:space="preserve">
133+
<pre>
134+
var gl = document.createElement('canvas').getContext('webgl2');
135+
var ext = gl.getExtension('WEBGL_multisampled_render_to_texture');
136+
var samples = gl.getParameter(ext.MAX_SAMPLES_EXT);
137+
var fb = gl.createFramebuffer();
138+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fb);
139+
140+
// Create color texture and storage.
141+
var colorTex = gl.createTexture();
142+
gl.bindTexture(gl.TEXTURE_2D, colorTex);
143+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA8, 512, 512);
144+
ext.framebufferTexture2DMultisampleEXT(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorTex, 0, samples);
145+
146+
// Create depth texture and storage.
147+
var depthStencilTex = gl.createTexture();
148+
gl.bindTexture(gl.TEXTURE_2D, depthStencilTex);
149+
ext.renderbufferStorageMultisampleEXT(gl.RENDER_BUFFER, samples, gl.DEPTH32F_STENCIL8, 512, 512);
150+
ext.framebufferTexture2DMultisampleEXT(gl.DRAW_FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, depthStencilTex, 0, samples);
151+
152+
gl.drawElements(...); // Draw will be done with multisampling and flushed to the non-multisample texture.
153+
</pre>
154+
</samplecode>
155+
<history>
156+
<revision date="2021/10/09">
157+
<change>Initial revision.</change>
158+
</revision>
159+
</history>
160+
</extension>

0 commit comments

Comments
 (0)