WebGLRenderingContext

Интерфейс WebGLRenderingContext обеспечивает доступ к контексту рендеринга OpenGL ES 2.0 (OpenGL for Embedded Systems — OpenGL для встраиваемых систем) для использования его с помощью HTML <canvas> элемента.

Чтобы получить объект с помощью этого интерфейса вызовите метод getContext() элемента <canvas> , используя "webgl" в качестве аргумента.

js
var canvas = document.getElementById("myCanvas");
var gl = canvas.getContext("webgl");

После того, как вы получили WebGL контекст, вы можете его использовать для рендеринга.

WebGL tutorial содержит больше информации, примеров, ссылок на ресурсы которые помогут начать использовать WebGL.

Константы

Смотрите на WebGL constants (en-US).

WebGL контекст

Ниже перечислены свойства и методы которые дают общую информацию и функциональность при работе с WebGL контекстом:

WebGLRenderingContext.canvas

Доступная только для чтения обратная ссылка на HTMLCanvasElement. Может быть null если будет применятся в контексте элемента иного типа чем <canvas>.

WebGLRenderingContext.commit() Экспериментальная возможность

Вставляет окна в первоначальный HTMLCanvasElement , если контекст не привязан к конкретному холсту.

WebGLRenderingContext.drawingBufferWidth (en-US)

Доступная только для чтения ширина текущего буфера отрисовки. Должна совпадать с шириной холста связанного с данным контекстом.

WebGLRenderingContext.drawingBufferHeight (en-US)

Доступная только для чтения высота текущего буфера отрисовки. Должна совпадать с высотой холста связанного с данным контекстом.

WebGLRenderingContext.getContextAttributes() (en-US)

Возвращает `WebGLContextAttributes объект который содержит атрибуты текущего контекста. Может возвращать null если контекст утерян.

WebGLRenderingContext.isContextLost() (en-US)

Возвращает true если контекст утерян, в противном случае возвращает false.

Просмотр и обрезка

WebGLRenderingContext.scissor() (en-US)

Устанавливает обрезанный контейнер.

WebGLRenderingContext.viewport() (en-US)

Устанавливает окно просмотра.

Информация о состоянии

WebGLRenderingContext.activeTexture()

Выбирает активную текстуру.

WebGLRenderingContext.blendColor() (en-US)

Устанавливает параметры смешивания источника и назначения

WebGLRenderingContext.blendEquation() (en-US)

Уравнение смешивания RGB и уравнение альфа-смешивания сводит к одному уравнению.

WebGLRenderingContext.blendEquationSeparate() (en-US)

Устанавливает уравнение смешивания RGB и уравнение альфа-смешивания отдельно.

WebGLRenderingContext.blendFunc() (en-US)

Определяет, какая арифметическая функция используется для смешивания пикселей.

WebGLRenderingContext.blendFuncSeparate() (en-US)

Определяет, какая арифметическая функция используется для смешивания пикселей для RGB и альфа-компонентов по отдельности.

WebGLRenderingContext.clearColor()

Задаёт значения цвета, используемые при очистке цветовых буферов.

WebGLRenderingContext.clearDepth() (en-US)

Задаёт значение глубины, используемый при очистке буфера глубины.

WebGLRenderingContext.clearStencil() (en-US)

Задаёт значение шаблона, используемый при очистке буфера шаблона.

WebGLRenderingContext.colorMask() (en-US)

Устанавливает какие цветовые компоненты для включены или выключены при отрисовке или рендеринге наWebGLFramebuffer (en-US).

WebGLRenderingContext.cullFace() (en-US)

Определяет, будет видима или нет передняя- и / или обратная сторона многоугольника.

WebGLRenderingContext.depthFunc() (en-US)

Определяет функцию, которая сравнивает входящую глубину пикселей к текущему значению глубины буфера.

WebGLRenderingContext.depthMask() (en-US)

Включает или выключает запись в буфер глубины.

WebGLRenderingContext.depthRange() (en-US)

Определяет диапазон отображения глубины согласно стандартных координат к координатам окна устройства.

WebGLRenderingContext.disable() (en-US)

Отключает конкретные возможности WebGL.

WebGLRenderingContext.enable()

Включает конкретные возможности WebGL.

WebGLRenderingContext.frontFace() (en-US)

Определяет видимость передней или задней стороны многоугольника, при его вращении.

WebGLRenderingContext.getParameter() (en-US)

Возвращает значение переданного параметра по имени.

WebGLRenderingContext.getError() (en-US)

Возвращает информацию об ошибках.

WebGLRenderingContext.hint() (en-US)

Указывает подсказки для определённого поведения. Интерпретация этих подсказок зависит от реализации.

WebGLRenderingContext.isEnabled() (en-US)

Проверяет, включена или нет конкретная способность WebG.

WebGLRenderingContext.lineWidth() (en-US)

Устанавливает ширину растровой линии.

WebGLRenderingContext.pixelStorei() (en-US)

Определяет режимы хранилища пикселей

WebGLRenderingContext.polygonOffset() (en-US)

Определяет факторы масштабирования и единицы для расчёта значения глубины.

WebGLRenderingContext.sampleCoverage() (en-US)

Определяет составные параметры для сглаживания эффектов.

WebGLRenderingContext.stencilFunc() (en-US)

Sets the both front and back function and reference value for stencil testing.

WebGLRenderingContext.stencilFuncSeparate() (en-US)

Sets the front and/or back function and reference value for stencil testing.

WebGLRenderingContext.stencilMask() (en-US)

Controls enabling and disabling of both the front and back writing of individual bits in the stencil planes.

WebGLRenderingContext.stencilMaskSeparate() (en-US)

Controls enabling and disabling of front and/or back writing of individual bits in the stencil planes.

WebGLRenderingContext.stencilOp() (en-US)

Sets both the front and back-facing stencil test actions.

WebGLRenderingContext.stencilOpSeparate() (en-US)

Sets the front and/or back-facing stencil test actions.

Buffers

WebGLRenderingContext.bindBuffer()

Binds a WebGLBuffer object to a given target.

WebGLRenderingContext.bufferData() (en-US)

Updates buffer data.

WebGLRenderingContext.bufferSubData() (en-US)

Updates buffer data starting at a passed offset.

WebGLRenderingContext.createBuffer() (en-US)

Creates a WebGLBuffer object.

WebGLRenderingContext.deleteBuffer() (en-US)

Deletes a WebGLBuffer object.

WebGLRenderingContext.getBufferParameter() (en-US)

Returns information about the buffer.

WebGLRenderingContext.isBuffer() (en-US)

Returns a Boolean indicating if the passed buffer is valid.

Framebuffers

WebGLRenderingContext.bindFramebuffer() (en-US)

Binds a WebGLFrameBuffer object to a given target.

WebGLRenderingContext.checkFramebufferStatus() (en-US)

Returns the status of the framebuffer.

WebGLRenderingContext.createFramebuffer() (en-US)

Creates a WebGLFrameBuffer object.

WebGLRenderingContext.deleteFramebuffer() (en-US)

Deletes a WebGLFrameBuffer object.

WebGLRenderingContext.framebufferRenderbuffer() (en-US)

Attaches a WebGLRenderingBuffer object to a WebGLFrameBuffer object.

WebGLRenderingContext.framebufferTexture2D() (en-US)

Attaches a textures image to a WebGLFrameBuffer object.

WebGLRenderingContext.getFramebufferAttachmentParameter() (en-US)

Returns information about the framebuffer.

WebGLRenderingContext.isFramebuffer() (en-US)

Returns a Boolean indicating if the passed WebGLFrameBuffer object is valid.

WebGLRenderingContext.readPixels() (en-US)

Reads a block of pixels from the WebGLFrameBuffer.

Renderbuffers

WebGLRenderingContext.bindRenderbuffer() (en-US)

Binds a WebGLRenderBuffer object to a given target.

WebGLRenderingContext.createRenderbuffer() (en-US)

Creates a WebGLRenderBuffer object.

WebGLRenderingContext.deleteRenderbuffer() (en-US)

Deletes a WebGLRenderBuffer object.

WebGLRenderingContext.getRenderbufferParameter() (en-US)

Returns information about the renderbuffer.

WebGLRenderingContext.isRenderbuffer() (en-US)

Returns a Boolean indicating if the passed WebGLRenderingBuffer is valid.

WebGLRenderingContext.renderbufferStorage() (en-US)

Creates a renderbuffer data store.

Textures

WebGLRenderingContext.bindTexture()

Binds a WebGLTexture object to a given target.

WebGLRenderingContext.compressedTexImage2D() (en-US)

Specifies a 2D texture image in a compressed format.

WebGLRenderingContext.compressedTexSubImage2D() (en-US)

Specifies a 2D texture sub-image in a compressed format.

WebGLRenderingContext.copyTexImage2D() (en-US)

Copies a 2D texture image.

WebGLRenderingContext.copyTexSubImage2D() (en-US)

Copies a 2D texture sub-image.

WebGLRenderingContext.createTexture() (en-US)

Creates a WebGLTexture object.

WebGLRenderingContext.deleteTexture() (en-US)

Deletes a WebGLTexture object.

WebGLRenderingContext.generateMipmap() (en-US)

Generates a set of mipmaps for a WebGLTexture object.

WebGLRenderingContext.getTexParameter() (en-US)

Returns information about the texture.

WebGLRenderingContext.isTexture() (en-US)

Returns a Boolean indicating if the passed WebGLTexture is valid.

WebGLRenderingContext.texImage2D() (en-US)

Specifies a 2D texture image.

WebGLRenderingContext.texSubImage2D() (en-US)

Updates a sub-rectangle of the current WebGLTexture.

WebGLRenderingContext.texParameterf() (en-US)

Sets texture parameters.

WebGLRenderingContext.texParameteri() (en-US)

Sets texture parameters.

Programs and shaders

WebGLRenderingContext.attachShader() (en-US)

Attaches a WebGLShader to a WebGLProgram.

WebGLRenderingContext.bindAttribLocation() (en-US)

Binds a generic vertex index to a named attribute variable.

WebGLRenderingContext.compileShader()

Compiles a WebGLShader.

WebGLRenderingContext.createProgram() (en-US)

Creates a WebGLProgram.

WebGLRenderingContext.createShader() (en-US)

Creates a WebGLShader.

WebGLRenderingContext.deleteProgram() (en-US)

Deletes a WebGLProgram.

WebGLRenderingContext.deleteShader() (en-US)

Deletes a WebGLShader.

WebGLRenderingContext.detachShader() (en-US)

Detaches a WebGLShader.

WebGLRenderingContext.getAttachedShaders() (en-US)

Returns a list of WebGLShader objects attached to a WebGLProgram.

WebGLRenderingContext.getProgramParameter() (en-US)

Returns information about the program.

WebGLRenderingContext.getProgramInfoLog() (en-US)

Returns the information log for a WebGLProgram object.

WebGLRenderingContext.getShaderParameter() (en-US)

Returns information about the shader.

WebGLRenderingContext.getShaderPrecisionFormat() (en-US)

Returns a WebGLShaderPrecisionFormat object describing the precision for the numeric format of the shader.

WebGLRenderingContext.getShaderInfoLog()

Returns the information log for a WebGLShader object.

WebGLRenderingContext.getShaderSource() (en-US)

Returns the source code of a WebGLShader as a string.

WebGLRenderingContext.isProgram() (en-US)

Returns a Boolean indicating if the passed WebGLProgram is valid.

WebGLRenderingContext.isShader() (en-US)

Returns a Boolean indicating if the passed WebGLShader is valid.

WebGLRenderingContext.linkProgram() (en-US)

Links the passed WebGLProgram object.

WebGLRenderingContext.shaderSource()

Sets the source code in a WebGLShader.

WebGLRenderingContext.useProgram() (en-US)

Uses the specified WebGLProgram as part the current rendering state.

WebGLRenderingContext.validateProgram() (en-US)

Validates a WebGLProgram.

Uniforms and attributes

WebGLRenderingContext.disableVertexAttribArray() (en-US)

Disables a vertex attribute array at a given position.

WebGLRenderingContext.enableVertexAttribArray() (en-US)

Enables a vertex attribute array at a given position.

WebGLRenderingContext.getActiveAttrib() (en-US)

Returns information about an active attribute variable.

WebGLRenderingContext.getActiveUniform() (en-US)

Returns information about an active uniform variable.

WebGLRenderingContext.getAttribLocation() (en-US)

Returns the location of an attribute variable.

WebGLRenderingContext.getUniform() (en-US)

Returns the value of a uniform variable at a given location.

WebGLRenderingContext.getUniformLocation() (en-US)

Returns the location of a uniform variable.

WebGLRenderingContext.getVertexAttrib() (en-US)

Returns information about a vertex attribute at a given position.

WebGLRenderingContext.getVertexAttribOffset() (en-US)

Returns the address of a given vertex attribute.

WebGLRenderingContext.uniform[1234][fi][v]()

Specifies a value for a uniform variable.

WebGLRenderingContext.uniformMatrix[234]fv() (en-US)

Specifies a matrix value for a uniform variable.

WebGLRenderingContext.vertexAttrib[1234]f[v]() (en-US)

Specifies a value for a generic vertex attribute.

WebGLRenderingContext.vertexAttribPointer() (en-US)

Specifies the data formats and locations of vertex attributes in a vertex attributes array.

Drawing buffers

WebGLRenderingContext.clear()

Clears specified buffers to preset values.

WebGLRenderingContext.drawArrays() (en-US)

Renders primitives from array data.

WebGLRenderingContext.drawElements() (en-US)

Renders primitives from element array data.

WebGLRenderingContext.finish() (en-US)

Blocks execution until all previously called commands are finished.

WebGLRenderingContext.flush() (en-US)

Empties different buffer commands, causing all commands to be executed as quickly as possible.

Working with extensions

These methods manage WebGL extensions:

WebGLRenderingContext.getSupportedExtensions() (en-US)

Returns an Array of DOMString elements with all the supported WebGL extensions.

WebGLRenderingContext.getExtension() (en-US)

Returns an extension object.

Specifications

Specification
WebGL Specification
# 5.14

Совместимость с браузерами

BCD tables only load in the browser

See also