大网数据广告活动
Web 标准与前端开发

OES_draw_buffers_indexed

· 52CE 我爱测

The **`OES_draw_buffers_indexed`** extension is part of the WebGL API and enables the use of different blend options when writing to multiple color buffers simultaneously.

WebGL

The OES_draw_buffers_indexed extension is part of the WebGL API and enables the use of different blend options when writing to multiple color buffers simultaneously.

WebGL extensions are available using the WebGLRenderingContext.getExtension() method. For more information, see Using WebGL extensions.

[!NOTE] This extension is only available to WebGL2RenderingContext contexts.

Instance methods

  • OES_draw_buffers_indexed.blendEquationiOES()
    • : Sets both the RGB and alpha blend equations for a particular draw buffer.
  • OES_draw_buffers_indexed.blendEquationSeparateiOES()
    • : Sets the RGB and alpha blend equations separately for a particular draw buffer.
  • OES_draw_buffers_indexed.blendFunciOES()
    • : Defines which function is used when blending pixels for a particular draw buffer.
  • OES_draw_buffers_indexed.blendFuncSeparateiOES()
    • : Defines which function is used when blending pixels for RGB and alpha components separately for a particular draw buffer.
  • OES_draw_buffers_indexed.colorMaskiOES()
    • : Sets which color components to enable or to disable when drawing or rendering for a particular draw buffer.
  • OES_draw_buffers_indexed.disableiOES()
    • : Disables blending for a particular draw buffer.
  • OES_draw_buffers_indexed.enableiOES()
    • : Enables blending for a particular draw buffer.

Examples

Using the OES_draw_buffers_indexed extension

Enable the extension with a call to WebGLRenderingContext.getExtension().

const ext = gl.getExtension("OES_draw_buffers_indexed");

You can now enable blending, set blending equation, blending function, and color mask for a particular draw buffer.

// For gl.DRAW_BUFFER0
ext.enableiOES(gl.BLEND, 0);
ext.blendEquationiOES(0, gl.FUNC_ADD);
ext.blendFunciOES(0, gl.ONE, gl.ONE);
ext.colorMaskiOES(0, 1, 0, 0, 0);

// For gl.DRAW_BUFFER1
ext.enableiOES(gl.BLEND, 1);
ext.blendEquationSeparateiOES(1, gl.FUNC_ADD, gl.FUNC_SUBTRACT);
ext.blendFuncSeparateiOES(
  1,
  gl.SRC_ALPHA,
  gl.ONE_MINUS_SRC_ALPHA,
  gl.ZERO,
  gl.ZERO,
);
ext.colorMaskiOES(1, 0, 1, 0, 0);

To retrieve settings for a particular draw buffer, use WebGL2RenderingContext.getIndexedParameter().

// For gl.DRAW_BUFFER0
gl.getIndexedParameter(gl.BLEND_EQUATION_RGB, 0);
gl.getIndexedParameter(gl.BLEND_EQUATION_ALPHA, 0);
gl.getIndexedParameter(gl.BLEND_SRC_RGB, 0);
gl.getIndexedParameter(gl.BLEND_SRC_ALPHA, 0);
gl.getIndexedParameter(gl.BLEND_DST_RGB, 0);
gl.getIndexedParameter(gl.BLEND_DST_ALPHA, 0);
gl.getIndexedParameter(gl.COLOR_WRITEMASK, 0);

// For gl.DRAW_BUFFER1
gl.getIndexedParameter(gl.BLEND_EQUATION_RGB, 1);
gl.getIndexedParameter(gl.BLEND_EQUATION_ALPHA, 1);
gl.getIndexedParameter(gl.BLEND_SRC_RGB, 1);
gl.getIndexedParameter(gl.BLEND_SRC_ALPHA, 1);
gl.getIndexedParameter(gl.BLEND_DST_RGB, 1);
gl.getIndexedParameter(gl.BLEND_DST_ALPHA, 1);
gl.getIndexedParameter(gl.COLOR_WRITEMASK, 1);

You can use WebGLRenderingContext.getParameter() to see how many draw buffers are available.

const maxDrawBuffers = gl.getParameter(gl.MAX_DRAW_BUFFERS);

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。