2013-08-20 19:36:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGLContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2013-08-20 19:36:19 +04:00
|
|
|
#include "WebGLBuffer.h"
|
2017-01-12 02:57:29 +03:00
|
|
|
#include "WebGLTransformFeedback.h"
|
2013-08-20 19:36:19 +04:00
|
|
|
#include "WebGLVertexArray.h"
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>*
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateBufferSlot(GLenum target)
|
2014-12-05 10:04:55 +03:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>* slot = nullptr;
|
2014-12-05 10:04:55 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
|
|
|
slot = &mBoundArrayBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
|
|
|
slot = &(mBoundVertexArray->mElementArrayBuffer);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-05 10:04:55 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (IsWebGL2()) {
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_COPY_READ_BUFFER:
|
|
|
|
slot = &mBoundCopyReadBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_COPY_WRITE_BUFFER:
|
|
|
|
slot = &mBoundCopyWriteBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
slot = &mBoundPixelPackBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
slot = &mBoundPixelUnpackBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
2018-03-30 02:43:58 +03:00
|
|
|
slot = &mBoundTransformFeedbackBuffer;
|
2016-09-10 07:02:54 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
slot = &mBoundUniformBuffer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!slot) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidEnumInfo("target", target);
|
2016-09-10 07:02:54 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return slot;
|
2014-12-05 10:04:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLBuffer*
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateBufferSelection(GLenum target)
|
2016-09-10 07:02:54 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto& slot = ValidateBufferSlot(target);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!slot)
|
|
|
|
return nullptr;
|
|
|
|
const auto& buffer = *slot;
|
|
|
|
|
|
|
|
if (!buffer) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Buffer for `target` is null.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER) {
|
|
|
|
if (mBoundTransformFeedback->IsActiveAndNotPaused()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Cannot select TRANSFORM_FEEDBACK_BUFFER when"
|
|
|
|
" transform feedback is active and unpaused.");
|
2016-12-29 11:08:39 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (buffer->IsBoundForNonTF()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Specified WebGLBuffer is currently bound for"
|
|
|
|
" non-transform-feedback.");
|
2016-12-29 11:08:39 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (buffer->IsBoundForTF()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Specified WebGLBuffer is currently bound for"
|
|
|
|
" transform feedback.");
|
2016-12-29 11:08:39 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2016-11-18 04:50:38 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
return buffer.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedBufferBinding*
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateIndexedBufferSlot(GLenum target, GLuint index)
|
2014-12-05 10:04:55 +03:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
decltype(mIndexedUniformBufferBindings)* bindings;
|
|
|
|
const char* maxIndexEnum;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
bindings = &(mBoundTransformFeedback->mIndexedBindings);
|
|
|
|
maxIndexEnum = "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
bindings = &mIndexedUniformBufferBindings;
|
|
|
|
maxIndexEnum = "MAX_UNIFORM_BUFFER_BINDINGS";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidEnumInfo("target", target);
|
2016-09-10 07:02:54 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= bindings->size()) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("`index` >= %s.", maxIndexEnum);
|
2016-09-10 07:02:54 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(*bindings)[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::BindBuffer(GLenum target, WebGLBuffer* buffer)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bindBuffer");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !ValidateObject("buffer", *buffer))
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto& slot = ValidateBufferSlot(target);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!slot)
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !buffer->ValidateCanBindToTarget(target))
|
2014-12-05 10:04:55 +03:00
|
|
|
return;
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
gl->fBindBuffer(target, buffer ? buffer->mGLName : 0);
|
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
WebGLBuffer::SetSlot(target, buffer, slot);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (buffer) {
|
|
|
|
buffer->SetContentAfterBind(target);
|
|
|
|
}
|
2016-09-26 23:38:56 +03:00
|
|
|
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
gl->fBindBuffer(target, 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLContext::ValidateIndexedBufferBinding(GLenum target, GLuint index,
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>** const out_genericBinding,
|
|
|
|
IndexedBufferBinding** const out_indexedBinding)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
*out_genericBinding = ValidateBufferSlot(target);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!*out_genericBinding)
|
|
|
|
return false;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
*out_indexedBinding = ValidateIndexedBufferSlot(target, index);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!*out_indexedBinding)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER &&
|
|
|
|
mBoundTransformFeedback->mIsActive)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidOperation("Cannot update indexed buffer bindings on active"
|
|
|
|
" transform feedback objects.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 19:36:20 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer)
|
2013-08-20 19:36:20 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bindBufferBase");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !ValidateObject("buffer", *buffer))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>* genericBinding;
|
|
|
|
IndexedBufferBinding* indexedBinding;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateIndexedBufferBinding(target, index, &genericBinding,
|
2016-09-10 07:02:54 +03:00
|
|
|
&indexedBinding))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !buffer->ValidateCanBindToTarget(target))
|
2016-09-18 02:44:56 +03:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
2014-05-07 07:11:18 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
gl->fBindBufferBase(target, index, buffer ? buffer->mGLName : 0);
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
WebGLBuffer::SetSlot(target, buffer, genericBinding);
|
|
|
|
WebGLBuffer::SetSlot(target, buffer, &indexedBinding->mBufferBinding);
|
2016-09-10 07:02:54 +03:00
|
|
|
indexedBinding->mRangeStart = 0;
|
|
|
|
indexedBinding->mRangeSize = 0;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (buffer) {
|
|
|
|
buffer->SetContentAfterBind(target);
|
|
|
|
}
|
2013-08-20 19:36:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer,
|
2013-08-20 19:36:20 +04:00
|
|
|
WebGLintptr offset, WebGLsizeiptr size)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bindBufferRange");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !ValidateObject("buffer", *buffer))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateNonNegative("offset", offset) ||
|
|
|
|
!ValidateNonNegative("size", size))
|
2016-09-10 07:02:54 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLBuffer>* genericBinding;
|
|
|
|
IndexedBufferBinding* indexedBinding;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateIndexedBufferBinding(target, index, &genericBinding,
|
2016-09-10 07:02:54 +03:00
|
|
|
&indexedBinding))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (buffer && !buffer->ValidateCanBindToTarget(target))
|
2016-09-18 02:44:56 +03:00
|
|
|
return;
|
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
if (buffer && !size) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("Size must be non-zero for non-null buffer.");
|
2016-12-23 04:08:35 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:44:56 +03:00
|
|
|
////
|
|
|
|
|
2014-11-26 05:00:06 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
2016-09-10 07:02:54 +03:00
|
|
|
if (offset % 4 != 0 || size % 4 != 0) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("For %s, `offset` and `size` must be multiples of 4.",
|
|
|
|
"TRANSFORM_FEEDBACK_BUFFER");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-04-21 04:02:34 +03:00
|
|
|
break;
|
2014-11-26 05:00:06 +03:00
|
|
|
|
2014-12-05 10:04:55 +03:00
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
2016-09-10 07:02:54 +03:00
|
|
|
{
|
|
|
|
GLuint offsetAlignment = 0;
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &offsetAlignment);
|
|
|
|
if (offset % offsetAlignment != 0) {
|
2018-07-27 07:46:33 +03:00
|
|
|
ErrorInvalidValue("For %s, `offset` must be a multiple of %s.",
|
|
|
|
"UNIFORM_BUFFER",
|
2016-09-10 07:02:54 +03:00
|
|
|
"UNIFORM_BUFFER_OFFSET_ALIGNMENT");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-04-21 04:02:34 +03:00
|
|
|
break;
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
2015-04-21 04:02:34 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (buffer && buffer->Content() == WebGLBuffer::Kind::Undefined &&
|
|
|
|
gl->WorkAroundDriverBugs())
|
|
|
|
{
|
|
|
|
// BindBufferRange will fail if the buffer's contents is undefined.
|
|
|
|
// Bind so driver initializes the buffer.
|
|
|
|
gl->fBindBuffer(target, buffer->mGLName);
|
2014-11-26 05:00:06 +03:00
|
|
|
}
|
2016-09-10 07:02:54 +03:00
|
|
|
#endif
|
2014-11-26 05:00:06 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
gl->fBindBufferRange(target, index, buffer ? buffer->mGLName : 0, offset, size);
|
|
|
|
|
|
|
|
////
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
WebGLBuffer::SetSlot(target, buffer, genericBinding);
|
|
|
|
WebGLBuffer::SetSlot(target, buffer, &indexedBinding->mBufferBinding);
|
2016-09-10 07:02:54 +03:00
|
|
|
indexedBinding->mRangeStart = offset;
|
|
|
|
indexedBinding->mRangeSize = size;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (buffer) {
|
|
|
|
buffer->SetContentAfterBind(target);
|
|
|
|
}
|
2013-08-20 19:36:20 +04:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferDataImpl(GLenum target, size_t dataLen, const uint8_t* data,
|
|
|
|
GLenum usage)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2013-09-04 16:14:39 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(target);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!buffer)
|
|
|
|
return;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-10-12 01:40:34 +03:00
|
|
|
buffer->BufferData(target, dataLen, data, usage);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2016-10-12 01:40:34 +03:00
|
|
|
////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferData");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateNonNegative("size", size))
|
2016-10-12 01:40:34 +03:00
|
|
|
return;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-10-12 01:40:34 +03:00
|
|
|
////
|
2013-09-04 16:14:39 +04:00
|
|
|
|
2016-10-12 01:40:34 +03:00
|
|
|
const UniqueBuffer zeroBuffer(calloc(size, 1));
|
|
|
|
if (!zeroBuffer)
|
2018-07-27 07:46:33 +03:00
|
|
|
return ErrorOutOfMemory("Failed to allocate zeros.");
|
2016-01-01 22:00:48 +03:00
|
|
|
|
2016-10-12 03:38:45 +03:00
|
|
|
BufferDataImpl(target, size_t(size), (const uint8_t*)zeroBuffer.get(), usage);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferData(GLenum target, const dom::Nullable<dom::ArrayBuffer>& maybeSrc,
|
2015-10-14 08:48:19 +03:00
|
|
|
GLenum usage)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferData");
|
2016-10-12 01:40:34 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateNonNull("src", maybeSrc))
|
2016-11-02 00:58:07 +03:00
|
|
|
return;
|
|
|
|
const auto& src = maybeSrc.Value();
|
2016-10-12 01:40:34 +03:00
|
|
|
|
|
|
|
src.ComputeLengthAndData();
|
|
|
|
BufferDataImpl(target, src.LengthAllowShared(), src.DataAllowShared(), usage);
|
2015-10-14 08:48:19 +03:00
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferData(GLenum target, const dom::ArrayBufferView& src, GLenum usage,
|
|
|
|
GLuint srcElemOffset, GLuint srcElemCountOverride)
|
2015-10-14 08:48:19 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferData");
|
2016-10-12 01:40:34 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint8_t* bytes;
|
|
|
|
size_t byteLen;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateArrayBufferView(src, srcElemOffset, srcElemCountOverride,
|
2016-10-12 01:40:34 +03:00
|
|
|
&bytes, &byteLen))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferDataImpl(target, byteLen, bytes, usage);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferSubDataImpl(GLenum target, WebGLsizeiptr dstByteOffset,
|
|
|
|
size_t dataLen, const uint8_t* data)
|
2015-10-14 08:48:19 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferSubData");
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateNonNegative("byteOffset", dstByteOffset))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(target);
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!buffer)
|
|
|
|
return;
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
buffer->BufferSubData(target, size_t(dstByteOffset), dataLen, data);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
|
2016-11-02 00:58:07 +03:00
|
|
|
const dom::ArrayBuffer& src)
|
2015-10-14 08:48:19 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferSubData");
|
2016-10-12 01:40:34 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
src.ComputeLengthAndData();
|
|
|
|
BufferSubDataImpl(target, dstByteOffset, src.LengthAllowShared(),
|
|
|
|
src.DataAllowShared());
|
2015-10-14 08:48:19 +03:00
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
2016-10-12 01:40:34 +03:00
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr dstByteOffset,
|
|
|
|
const dom::ArrayBufferView& src, GLuint srcElemOffset,
|
|
|
|
GLuint srcElemCountOverride)
|
2015-10-14 08:48:19 +03:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "bufferSubData");
|
2016-10-12 01:40:34 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint8_t* bytes;
|
|
|
|
size_t byteLen;
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateArrayBufferView(src, srcElemOffset, srcElemCountOverride,
|
2016-10-12 01:40:34 +03:00
|
|
|
&bytes, &byteLen))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferSubDataImpl(target, dstByteOffset, byteLen, bytes);
|
2015-10-14 08:48:19 +03:00
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
already_AddRefed<WebGLBuffer>
|
|
|
|
WebGLContext::CreateBuffer()
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "createBuffer");
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return nullptr;
|
|
|
|
|
2014-11-17 05:21:04 +03:00
|
|
|
GLuint buf = 0;
|
|
|
|
gl->fGenBuffers(1, &buf);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLBuffer> globj = new WebGLBuffer(this, buf);
|
2013-08-20 19:36:19 +04:00
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteBuffer(WebGLBuffer* buffer)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
const FuncScope funcScope(*this, "deleteBuffer");
|
|
|
|
if (!ValidateDeleteObject(buffer))
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
const auto fnClearIfBuffer = [&](GLenum target, WebGLRefPtr<WebGLBuffer>& bindPoint) {
|
2016-09-10 07:02:54 +03:00
|
|
|
if (bindPoint == buffer) {
|
2016-12-29 11:08:39 +03:00
|
|
|
WebGLBuffer::SetSlot(target, nullptr, &bindPoint);
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
fnClearIfBuffer(0, mBoundArrayBuffer);
|
|
|
|
fnClearIfBuffer(0, mBoundVertexArray->mElementArrayBuffer);
|
|
|
|
|
|
|
|
for (auto& cur : mBoundVertexArray->mAttribs) {
|
|
|
|
fnClearIfBuffer(0, cur.mBuf);
|
|
|
|
}
|
2015-06-02 04:08:55 +03:00
|
|
|
|
|
|
|
// WebGL binding points
|
|
|
|
if (IsWebGL2()) {
|
2016-12-29 11:08:39 +03:00
|
|
|
fnClearIfBuffer(0, mBoundCopyReadBuffer);
|
|
|
|
fnClearIfBuffer(0, mBoundCopyWriteBuffer);
|
|
|
|
fnClearIfBuffer(0, mBoundPixelPackBuffer);
|
|
|
|
fnClearIfBuffer(0, mBoundPixelUnpackBuffer);
|
|
|
|
fnClearIfBuffer(0, mBoundUniformBuffer);
|
|
|
|
fnClearIfBuffer(LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER,
|
2018-03-30 02:43:58 +03:00
|
|
|
mBoundTransformFeedbackBuffer);
|
2016-09-10 07:02:54 +03:00
|
|
|
|
2016-09-19 23:25:06 +03:00
|
|
|
if (!mBoundTransformFeedback->mIsActive) {
|
|
|
|
for (auto& binding : mBoundTransformFeedback->mIndexedBindings) {
|
2016-12-29 11:08:39 +03:00
|
|
|
fnClearIfBuffer(LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER,
|
|
|
|
binding.mBufferBinding);
|
2016-09-19 23:25:06 +03:00
|
|
|
}
|
2015-06-02 04:08:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
for (auto& binding : mIndexedUniformBufferBindings) {
|
2016-12-29 11:08:39 +03:00
|
|
|
fnClearIfBuffer(0, binding.mBufferBinding);
|
2015-06-02 04:08:55 +03:00
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
|
|
|
|
2013-08-20 19:36:19 +04:00
|
|
|
buffer->RequestDelete();
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|