diff --git a/files/en-us/web/api/webgl2renderingcontext/bufferdata/index.md b/files/en-us/web/api/webgl2renderingcontext/bufferdata/index.md new file mode 100644 index 000000000000000..59e32f37123da10 --- /dev/null +++ b/files/en-us/web/api/webgl2renderingcontext/bufferdata/index.md @@ -0,0 +1,132 @@ +--- +title: "WebGL2RenderingContext: bufferData() method" +short-title: bufferData() +slug: Web/API/WebGL2RenderingContext/bufferData +page-type: web-api-instance-method +browser-compat: api.WebGL2RenderingContext.bufferData +--- + +{{APIRef("WebGL")}} + +The **`WebGL2RenderingContext.bufferData()`** method of the [WebGL API](/en-US/docs/Web/API/WebGL_API) creates and initializes the buffer object's data store. + +## Syntax + +```js-nolint +bufferData(target, size, usage) +bufferData(target, srcData, usage) +bufferData(target, srcData, usage, srcOffset) +bufferData(target, srcData, usage, srcOffset, length) +``` + +### Parameters + +- `target` + + - : A {{domxref("WebGL_API/Types", "GLenum")}} specifying the binding point (target). Possible values: + + - `gl.ARRAY_BUFFER` + - : Buffer containing vertex attributes, such as + vertex coordinates, texture coordinate data, or vertex color data. + - `gl.ELEMENT_ARRAY_BUFFER` + - : Buffer used for element indices. + - `gl.COPY_READ_BUFFER` + - : Buffer for copying from one buffer object to another. + - `gl.COPY_WRITE_BUFFER` + - : Buffer for copying from one buffer object to another. + - `gl.TRANSFORM_FEEDBACK_BUFFER` + - : Buffer for transform feedback operations. + - `gl.UNIFORM_BUFFER` + - : Buffer used for storing uniform blocks. + - `gl.PIXEL_PACK_BUFFER` + - : Buffer used for pixel transfer operations. + - `gl.PIXEL_UNPACK_BUFFER` + - : Buffer used for pixel transfer operations. + +- `size` {{optional_inline}} + - : A {{domxref("WebGL_API/Types", "GLsizeiptr")}} setting the size in bytes of the buffer object's data + store. + One of `size` and `srcData` must be provided. +- `srcData` {{optional_inline}} + - : An {{jsxref("ArrayBuffer")}}, {{jsxref("SharedArrayBuffer")}}, a {{jsxref("TypedArray")}} or a {{jsxref("DataView")}} + that will be copied into the data store. + If `null`, a data store is still created, but the content is uninitialized and undefined. + One of `size` and `srcData` must be provided. +- `usage` + + - : A {{domxref("WebGL_API/Types", "GLenum")}} specifying the intended usage pattern of the data store + for optimization purposes. Possible values: + + - `gl.STATIC_DRAW` + - : The contents are intended to be specified + once by the application, and used many times as the source for WebGL + drawing and image specification commands. + - `gl.DYNAMIC_DRAW` + - : The contents are intended to be respecified + repeatedly by the application, and used many times as the source for WebGL + drawing and image specification commands. + - `gl.STREAM_DRAW` + - : The contents are intended to be specified + once by the application, and used at most a few times as the source for + WebGL drawing and image specification commands. + - `gl.STATIC_READ` + - : The contents are intended to be + specified once by reading data from WebGL, and queried many times + by the application. + - `gl.DYNAMIC_READ` + - : The contents are intended to be + respecified repeatedly by reading data from WebGL, and queried + many times by the application. + - `gl.STREAM_READ` + - : The contents are intended to be + specified once by reading data from WebGL, and queried at most a + few times by the application + - `gl.STATIC_COPY` + - : The contents are intended to be + specified once by reading data from WebGL, and used many times as + the source for WebGL drawing and image specification commands. + - `gl.DYNAMIC_COPY` + - : The contents are intended to be + respecified repeatedly by reading data from WebGL, and used many + times as the source for WebGL drawing and image specification + commands. + - `gl.STREAM_COPY` + - : The contents are intended to be + specified once by reading data from WebGL, and used at most a few + times as the source for WebGL drawing and image specification + commands. + +- `srcOffset` {{optional_inline}} + - : A {{domxref("WebGL_API/Types", "GLuint")}} specifying the element index offset where to start reading + the buffer. + Only allowed if `srcData` is provided. +- `length` {{optional_inline}} + - : A {{domxref("WebGL_API/Types", "GLuint")}} defaulting to 0. + Only allowed if `srcOffset` is given. + +### Return value + +None ({{jsxref("undefined")}}). + +### Exceptions + +- A `gl.OUT_OF_MEMORY` error is thrown if the context is unable to create + a data store with the given `size`. +- A `gl.INVALID_VALUE` error is thrown if `size` is negative. +- A `gl.INVALID_ENUM` error is thrown if `target` or + `usage` are not one of the allowed enums. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("WebGLRenderingContext.bufferData()")}} +- {{domxref("WebGLRenderingContext.createBuffer()")}} +- {{domxref("WebGLRenderingContext.bufferSubData()")}} +- Other buffers: {{domxref("WebGLFramebuffer")}}, {{domxref("WebGLRenderbuffer")}} diff --git a/files/en-us/web/api/webgl2renderingcontext/buffersubdata/index.md b/files/en-us/web/api/webgl2renderingcontext/buffersubdata/index.md new file mode 100644 index 000000000000000..05231c7461810c1 --- /dev/null +++ b/files/en-us/web/api/webgl2renderingcontext/buffersubdata/index.md @@ -0,0 +1,83 @@ +--- +title: "WebGL2RenderingContext: bufferSubData() method" +short-title: bufferSubData() +slug: Web/API/WebGL2RenderingContext/bufferSubData +page-type: web-api-instance-method +browser-compat: api.WebGL2RenderingContext.bufferSubData +--- + +{{APIRef("WebGL")}} + +The **`WebGL2RenderingContext.bufferSubData()`** method of the +[WebGL API](/en-US/docs/Web/API/WebGL_API) updates a subset of a buffer +object's data store. + +## Syntax + +```js-nolint +bufferSubData(target, dstByteOffset, srcData) +bufferSubData(target, dstByteOffset, srcData, srcOffset) +bufferSubData(target, dstByteOffset, srcData, srcOffset, length) +``` + +### Parameters + +- `target` + + - : A {{domxref("WebGL_API/Types", "GLenum")}} specifying the binding point (target). Possible values: + + - `gl.ARRAY_BUFFER` + - : Buffer containing vertex attributes, such as + vertex coordinates, texture coordinate data, or vertex color data. + - `gl.ELEMENT_ARRAY_BUFFER` + - : Buffer used for element indices. + - `gl.COPY_READ_BUFFER` + - : Buffer for copying from one buffer object to another. + - `gl.COPY_WRITE_BUFFER` + - : Buffer for copying from one buffer object to another. + - `gl.TRANSFORM_FEEDBACK_BUFFER` + - : Buffer for transform feedback operations. + - `gl.UNIFORM_BUFFER` + - : Buffer used for storing uniform blocks. + - `gl.PIXEL_PACK_BUFFER` + - : Buffer used for pixel transfer operations. + - `gl.PIXEL_UNPACK_BUFFER` + - : Buffer used for pixel transfer operations. + +- `dstByteOffset` + - : A {{domxref("WebGL_API/Types", "GLintptr")}} specifying an offset in bytes where the data replacement + will start. +- `srcData` {{optional_inline}} + - : An {{jsxref("ArrayBuffer")}}, {{jsxref("SharedArrayBuffer")}}, a {{jsxref("DataView")}}, or a {{jsxref("TypedArray")}} + that will be copied into the data store. +- `srcOffset` {{optional_inline}} + - : A {{domxref("WebGL_API/Types", "GLuint")}} specifying the element index offset where to start reading + the buffer. +- `length` {{optional_inline}} + - : A {{domxref("WebGL_API/Types", "GLuint")}} defaulting to 0, where 0 means `bufferSubData` should calculate the length. + +### Return value + +None ({{jsxref("undefined")}}). + +### Exceptions + +- A `gl.INVALID_VALUE` error is thrown if the data would be written past + the end of the buffer or if `data` is `null`. +- A `gl.INVALID_ENUM` error is thrown if `target` is not one of + the allowed enums. + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{domxref("WebGLRenderingContext.bufferSubData()")}} +- {{domxref("WebGLRenderingContext.createBuffer()")}} +- {{domxref("WebGLRenderingContext.bufferData()")}} +- Other buffers: {{domxref("WebGLFramebuffer")}}, {{domxref("WebGLRenderbuffer")}} diff --git a/files/en-us/web/api/webglrenderingcontext/bufferdata/index.md b/files/en-us/web/api/webglrenderingcontext/bufferdata/index.md index 0414bbc2798d772..7659ef23de12d47 100644 --- a/files/en-us/web/api/webglrenderingcontext/bufferdata/index.md +++ b/files/en-us/web/api/webglrenderingcontext/bufferdata/index.md @@ -14,15 +14,8 @@ buffer object's data store. ## Syntax ```js-nolint -// WebGL1 -bufferData(target, usage) bufferData(target, size, usage) bufferData(target, srcData, usage) - -// WebGL2 -bufferData(target, usage, srcOffset) -bufferData(target, srcData, usage, srcOffset) -bufferData(target, srcData, usage, srcOffset, length) ``` ### Parameters @@ -106,12 +99,6 @@ bufferData(target, srcData, usage, srcOffset, length) times as the source for WebGL drawing and image specification commands. -- `srcOffset` - - : A {{domxref("WebGL_API/Types", "GLuint")}} specifying the element index offset where to start reading - the buffer. -- `length` {{optional_inline}} - - : A {{domxref("WebGL_API/Types", "GLuint")}} defaulting to 0. - ### Return value None ({{jsxref("undefined")}}). @@ -165,6 +152,7 @@ const sizeInBytes = dataArray.length * dataArray.BYTES_PER_ELEMENT; ## See also +- {{domxref("WebGL2RenderingContext.bufferData()")}} - {{domxref("WebGLRenderingContext.createBuffer()")}} - {{domxref("WebGLRenderingContext.bufferSubData()")}} - Other buffers: {{domxref("WebGLFramebuffer")}}, {{domxref("WebGLRenderbuffer")}} diff --git a/files/en-us/web/api/webglrenderingcontext/buffersubdata/index.md b/files/en-us/web/api/webglrenderingcontext/buffersubdata/index.md index aab15d84f8c7b81..46b9d46bf7094b1 100644 --- a/files/en-us/web/api/webglrenderingcontext/buffersubdata/index.md +++ b/files/en-us/web/api/webglrenderingcontext/buffersubdata/index.md @@ -15,14 +15,8 @@ object's data store. ## Syntax ```js-nolint -// WebGL1 bufferSubData(target, offset) bufferSubData(target, offset, srcData) - -// WebGL2 -bufferSubData(target, dstByteOffset, srcOffset) -bufferSubData(target, dstByteOffset, srcData, srcOffset) -bufferSubData(target, dstByteOffset, srcData, srcOffset, length) ``` ### Parameters @@ -100,6 +94,7 @@ gl.bufferSubData(gl.ARRAY_BUFFER, 512, data); ## See also +- {{domxref("WebGL2RenderingContext.bufferSubData()")}} - {{domxref("WebGLRenderingContext.createBuffer()")}} - {{domxref("WebGLRenderingContext.bufferData()")}} - Other buffers: {{domxref("WebGLFramebuffer")}}, {{domxref("WebGLRenderbuffer")}}