| 1 |
<?xml version="1.0"?> |
| 2 |
|
| 3 |
<ratified href="WEBGL_draw_buffers/"> |
| 4 |
<name>WEBGL_draw_buffers</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>Members of the WebGL working group</contributor> |
| 10 |
</contributors> |
| 11 |
<number>18</number> |
| 12 |
<depends> |
| 13 |
<api version="1.0"/> |
| 14 |
<core version="2.0"> |
| 15 |
<glsl version="300 es"/> |
| 16 |
</core> |
| 17 |
</depends> |
| 18 |
<overview> |
| 19 |
<mirrors href="https://www.khronos.org/registry/gles/extensions/EXT/EXT_draw_buffers.txt" name="EXT_draw_buffers"> |
| 20 |
<addendum> |
| 21 |
The implementation must support a minimum of 4 color attachments. |
| 22 |
</addendum> |
| 23 |
<addendum> |
| 24 |
The value of the <code>MAX_COLOR_ATTACHMENTS_WEBGL</code> parameter must be greater than or |
| 25 |
equal to that of the <code>MAX_DRAW_BUFFERS_WEBGL</code> parameter. |
| 26 |
</addendum> |
| 27 |
<addendum> |
| 28 |
If: |
| 29 |
<ul> |
| 30 |
<li> A framebuffer's color attachments are all textures allocated with format <code>RGBA</code> |
| 31 |
and type <code>UNSIGNED_BYTE</code>, and </li> |
| 32 |
<li> The framebuffer has either: |
| 33 |
<ul> |
| 34 |
<li> No depth or stencil attachment </li> |
| 35 |
<li> A valid <code>DEPTH</code> or <code>DEPTH_STENCIL</code> attachment </li> |
| 36 |
</ul></li> |
| 37 |
</ul> |
| 38 |
Then a call to <code>checkFramebufferStatus</code> against this framebuffer must not return |
| 39 |
<code>FRAMEBUFFER_UNSUPPORTED</code>. (In other words, the implementation must support the |
| 40 |
use of <code>RGBA/UNSIGNED_BYTE</code> textures as color attachments, plus either a |
| 41 |
<code>DEPTH</code> or <code>DEPTH_STENCIL</code> attachment.) |
| 42 |
</addendum> |
| 43 |
<addendum> |
| 44 |
Attaching <code>n</code> consecutive color attachments starting at COLOR_ATTACHMENT0_WEBGL, |
| 45 |
where <code>n</code> is between 1 and <code>MAX_DRAW_BUFFERS_WEBGL</code>, must not return |
| 46 |
<code>FRAMEBUFFER_UNSUPPORTED</code> from a call to <code>checkFramebufferStatus</code>. In |
| 47 |
other words, if <code>MAX_DRAW_BUFFERS_WEBGL</code> is 4, then the implementation is |
| 48 |
required to support the following combinations of color attachments: |
| 49 |
|
| 50 |
<ul> |
| 51 |
<li> <code>COLOR_ATTACHMENT0_WEBGL = RGBA/UNSIGNED_BYTE</code></li> |
| 52 |
<li> <code>COLOR_ATTACHMENT0_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 53 |
<code>COLOR_ATTACHMENT1_WEBGL = RGBA/UNSIGNED_BYTE</code><br/></li> |
| 54 |
<li> <code>COLOR_ATTACHMENT0_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 55 |
<code>COLOR_ATTACHMENT1_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 56 |
<code>COLOR_ATTACHMENT2_WEBGL = RGBA/UNSIGNED_BYTE</code><br/></li> |
| 57 |
<li> <code>COLOR_ATTACHMENT0_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 58 |
<code>COLOR_ATTACHMENT1_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 59 |
<code>COLOR_ATTACHMENT2_WEBGL = RGBA/UNSIGNED_BYTE</code><br/> |
| 60 |
<code>COLOR_ATTACHMENT3_WEBGL = RGBA/UNSIGNED_BYTE</code><br/></li> |
| 61 |
</ul> |
| 62 |
</addendum> |
| 63 |
<addendum> |
| 64 |
Although the extension name is prefixed with WEBGL the extension must be enabled with the |
| 65 |
<code>#extension GL_EXT_draw_buffers</code> directive, as shown in the sample code, to use |
| 66 |
the extension in a shader. |
| 67 |
|
| 68 |
Likewise the shading language preprocessor <code>#define GL_EXT_draw_buffers</code>, will be defined to 1 if the extension is supported. |
| 69 |
</addendum> |
| 70 |
<addendum> |
| 71 |
The value of <code>gl_MaxDrawBuffers</code> must match <code>MAX_DRAW_BUFFERS_WEBGL</code> from the API if the extension is enabled in a WebGL context; otherwise, the value must be 1. Whether or not the extension is enabled with the <code>#extension GL_EXT_draw_buffers</code> directive in a shader does not affect the value of <code>gl_MaxDrawBuffers</code>. The value of <code>gl_MaxDrawBuffers</code> is a constant in the shader, and is guaranteed to be frozen at program link time. It is implementation-dependent whether it is frozen at shader compile time. (A consequence is that if a program is linked, and later the WEBGL_draw_buffers extension is enabled, the value of <code>gl_MaxDrawBuffers</code> seen by that program will still be 1.) |
| 72 |
</addendum> |
| 73 |
<addendum> |
| 74 |
If the WEBGL_draw_buffers extension is enabled, but the fragment shader does not contain the <code>#extension GL_EXT_draw_buffers</code> directive to enable it, then writes to <code>gl_FragColor</code> are only written to <code>COLOR_ATTACHMENT0_WEBGL</code>, and not broadcast to all color attachments. In this scenario, other color attachments are guaranteed to remain untouched. |
| 75 |
</addendum> |
| 76 |
<addendum> |
| 77 |
If a fragment shader writes to neither <code>gl_FragColor</code> nor <code>gl_FragData</code>, the values of |
| 78 |
the fragment colors following shader execution are untouched. |
| 79 |
|
| 80 |
If a fragment shader contains the <code>#extension GL_EXT_draw_buffers</code> directive, all |
| 81 |
<code>gl_FragData</code> variables (from <code>gl_FragData[0]</code> to <code>gl_FragData[MAX_DRAW_BUFFERS_WEBGL - 1]</code>) |
| 82 |
default to zero if no values are written to them during a shader execution. |
| 83 |
</addendum> |
| 84 |
<addendum> |
| 85 |
If an image is attached to more than one color attachment point in a framebuffer, <code>checkFramebufferStatus</code> |
| 86 |
returns <code>FRAMEBUFFER_UNSUPPORTED</code>. An image can be an individual mip level, or a face of cube map. |
| 87 |
</addendum> |
| 88 |
</mirrors> |
| 89 |
<features> |
| 90 |
<feature> |
| 91 |
Adds support for multiple color buffers and color outputs from fragment shaders. |
| 92 |
</feature> |
| 93 |
</features> |
| 94 |
</overview> |
| 95 |
<idl xml:space="preserve"> |
| 96 |
[NoInterfaceObject] |
| 97 |
interface WEBGL_draw_buffers { |
| 98 |
const GLenum COLOR_ATTACHMENT0_WEBGL = 0x8CE0; |
| 99 |
const GLenum COLOR_ATTACHMENT1_WEBGL = 0x8CE1; |
| 100 |
const GLenum COLOR_ATTACHMENT2_WEBGL = 0x8CE2; |
| 101 |
const GLenum COLOR_ATTACHMENT3_WEBGL = 0x8CE3; |
| 102 |
const GLenum COLOR_ATTACHMENT4_WEBGL = 0x8CE4; |
| 103 |
const GLenum COLOR_ATTACHMENT5_WEBGL = 0x8CE5; |
| 104 |
const GLenum COLOR_ATTACHMENT6_WEBGL = 0x8CE6; |
| 105 |
const GLenum COLOR_ATTACHMENT7_WEBGL = 0x8CE7; |
| 106 |
const GLenum COLOR_ATTACHMENT8_WEBGL = 0x8CE8; |
| 107 |
const GLenum COLOR_ATTACHMENT9_WEBGL = 0x8CE9; |
| 108 |
const GLenum COLOR_ATTACHMENT10_WEBGL = 0x8CEA; |
| 109 |
const GLenum COLOR_ATTACHMENT11_WEBGL = 0x8CEB; |
| 110 |
const GLenum COLOR_ATTACHMENT12_WEBGL = 0x8CEC; |
| 111 |
const GLenum COLOR_ATTACHMENT13_WEBGL = 0x8CED; |
| 112 |
const GLenum COLOR_ATTACHMENT14_WEBGL = 0x8CEE; |
| 113 |
const GLenum COLOR_ATTACHMENT15_WEBGL = 0x8CEF; |
| 114 |
|
| 115 |
const GLenum DRAW_BUFFER0_WEBGL = 0x8825; |
| 116 |
const GLenum DRAW_BUFFER1_WEBGL = 0x8826; |
| 117 |
const GLenum DRAW_BUFFER2_WEBGL = 0x8827; |
| 118 |
const GLenum DRAW_BUFFER3_WEBGL = 0x8828; |
| 119 |
const GLenum DRAW_BUFFER4_WEBGL = 0x8829; |
| 120 |
const GLenum DRAW_BUFFER5_WEBGL = 0x882A; |
| 121 |
const GLenum DRAW_BUFFER6_WEBGL = 0x882B; |
| 122 |
const GLenum DRAW_BUFFER7_WEBGL = 0x882C; |
| 123 |
const GLenum DRAW_BUFFER8_WEBGL = 0x882D; |
| 124 |
const GLenum DRAW_BUFFER9_WEBGL = 0x882E; |
| 125 |
const GLenum DRAW_BUFFER10_WEBGL = 0x882F; |
| 126 |
const GLenum DRAW_BUFFER11_WEBGL = 0x8830; |
| 127 |
const GLenum DRAW_BUFFER12_WEBGL = 0x8831; |
| 128 |
const GLenum DRAW_BUFFER13_WEBGL = 0x8832; |
| 129 |
const GLenum DRAW_BUFFER14_WEBGL = 0x8833; |
| 130 |
const GLenum DRAW_BUFFER15_WEBGL = 0x8834; |
| 131 |
|
| 132 |
const GLenum MAX_COLOR_ATTACHMENTS_WEBGL = 0x8CDF; |
| 133 |
const GLenum MAX_DRAW_BUFFERS_WEBGL = 0x8824; |
| 134 |
|
| 135 |
void drawBuffersWEBGL(sequence<GLenum> buffers); |
| 136 |
}; |
| 137 |
</idl> |
| 138 |
<samplecode xml:space="preserve"> |
| 139 |
<pre> |
| 140 |
#extension GL_EXT_draw_buffers : require |
| 141 |
precision mediump float; |
| 142 |
void main() { |
| 143 |
gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0); |
| 144 |
gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0); |
| 145 |
gl_FragData[2] = vec4(0.0, 0.0, 1.0, 1.0); |
| 146 |
gl_FragData[3] = vec4(1.0, 1.0, 1.0, 1.0); |
| 147 |
} |
| 148 |
</pre> |
| 149 |
</samplecode> |
| 150 |
<history> |
| 151 |
<revision date="2012/10/16"> |
| 152 |
<change>Initial revision.</change> |
| 153 |
</revision> |
| 154 |
<revision date="2012/11/05"> |
| 155 |
<change>Corrected typo in drawBuffersWEBGL. Changed referenced spec version to 1.0 to fix broken link.</change> |
| 156 |
</revision> |
| 157 |
<revision date="2013/02/02"> |
| 158 |
<change>Renamed to EXT_draw_buffers per plan of OpenGL ES working group. Moved to draft status. Assigned number.</change> |
| 159 |
</revision> |
| 160 |
<revision date="2013/03/05"> |
| 161 |
<change>Renamed to WEBGL_draw_buffers per discussion on public_webgl list. Added guarantees to make it easier for developers to use the extension.</change> |
| 162 |
</revision> |
| 163 |
<revision date="2013/06/07"> |
| 164 |
<change>Clarified naming of shader directives.</change> |
| 165 |
</revision> |
| 166 |
<revision date="2014/07/15"> |
| 167 |
<change>Added NoInterfaceObject extended attribute.</change> |
| 168 |
</revision> |
| 169 |
<revision date="2014/08/08"> |
| 170 |
<change>Ratified by Khronos Board of Promoters.</change> |
| 171 |
</revision> |
| 172 |
<revision date="2016/06/28"> |
| 173 |
<change>Revised behavior of gl_MaxDrawBuffers and gl_FragColor broadcasting, to avoid significant performance impact for WebGL 1.0 implementations running on top of the desktop OpenGL API.</change> |
| 174 |
</revision> |
| 175 |
<revision date="2016/07/08"> |
| 176 |
<change>Removed undefined behaviors.</change> |
| 177 |
</revision> |
| 178 |
<revision date="2016/07/11"> |
| 179 |
<change>Revised user-defined variable behavior to default to zero.</change> |
| 180 |
</revision> |
| 181 |
<revision date="2016/07/23"> |
| 182 |
<change>Revised behavior of the same image is attached to more than one color attachment point.</change> |
| 183 |
</revision> |
| 184 |
</history> |
| 185 |
</ratified> |