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"
|
|
|
|
#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>*
|
|
|
|
WebGLContext::ValidateBufferSlot(const char* funcName, 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:
|
|
|
|
slot = &(mBoundTransformFeedback->mGenericBufferBinding);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
slot = &mBoundUniformBuffer;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!slot) {
|
|
|
|
ErrorInvalidEnum("%s: Bad `target`: 0x%04x", funcName, target);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return slot;
|
2014-12-05 10:04:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLBuffer*
|
|
|
|
WebGLContext::ValidateBufferSelection(const char* funcName, GLenum target)
|
|
|
|
{
|
|
|
|
const auto& slot = ValidateBufferSlot(funcName, target);
|
|
|
|
if (!slot)
|
|
|
|
return nullptr;
|
|
|
|
const auto& buffer = *slot;
|
|
|
|
|
|
|
|
if (!buffer) {
|
|
|
|
ErrorInvalidOperation("%s: Buffer for `target` is null.", funcName);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedBufferBinding*
|
|
|
|
WebGLContext::ValidateIndexedBufferSlot(const char* funcName, 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:
|
|
|
|
ErrorInvalidEnum("%s: Bad `target`: 0x%04x", funcName, target);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= bindings->size()) {
|
|
|
|
ErrorInvalidOperation("%s: `index` >= %s.", funcName, maxIndexEnum);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(*bindings)[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ValidateCanBindToTarget(WebGLContext* webgl, const char* funcName, GLenum target,
|
|
|
|
WebGLBuffer* buffer)
|
|
|
|
{
|
|
|
|
if (!buffer)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.1
|
|
|
|
*
|
|
|
|
* In the WebGL 2 API, buffers have their WebGL buffer type
|
|
|
|
* initially set to undefined. Calling bindBuffer, bindBufferRange
|
|
|
|
* or bindBufferBase with the target argument set to any buffer
|
|
|
|
* binding point except COPY_READ_BUFFER or COPY_WRITE_BUFFER will
|
|
|
|
* then set the WebGL buffer type of the buffer being bound
|
|
|
|
* according to the table above.
|
|
|
|
*
|
|
|
|
* Any call to one of these functions which attempts to bind a
|
|
|
|
* WebGLBuffer that has the element array WebGL buffer type to a
|
|
|
|
* binding point that falls under other data, or bind a
|
|
|
|
* WebGLBuffer which has the other data WebGL buffer type to
|
|
|
|
* ELEMENT_ARRAY_BUFFER will generate an INVALID_OPERATION error,
|
|
|
|
* and the state of the binding point will remain untouched.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const auto& content = buffer->Content();
|
|
|
|
if (content == WebGLBuffer::Kind::Undefined)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_COPY_READ_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_WRITE_BUFFER:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
|
|
|
if (content == WebGLBuffer::Kind::ElementArray)
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
if (content == WebGLBuffer::Kind::OtherData)
|
|
|
|
return true;
|
|
|
|
break;
|
2014-12-05 10:04:55 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
webgl->ErrorInvalidOperation("%s: buffer already contains %s data.", funcName,
|
|
|
|
content == WebGLBuffer::Kind::OtherData ? "other"
|
|
|
|
: "element");
|
|
|
|
return false;
|
2014-12-05 10:04:55 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bindBuffer";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull(funcName, buffer))
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
|
|
|
if (buffer && buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& slot = ValidateBufferSlot(funcName, target);
|
|
|
|
if (!slot)
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateCanBindToTarget(this, funcName, target, buffer))
|
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->MakeCurrent();
|
|
|
|
gl->fBindBuffer(target, buffer ? buffer->mGLName : 0);
|
|
|
|
|
|
|
|
*slot = buffer;
|
|
|
|
if (buffer) {
|
|
|
|
buffer->SetContentAfterBind(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::ValidateIndexedBufferBinding(const char* funcName, GLenum target,
|
|
|
|
GLuint index,
|
|
|
|
WebGLRefPtr<WebGLBuffer>** const out_genericBinding,
|
|
|
|
IndexedBufferBinding** const out_indexedBinding)
|
|
|
|
{
|
|
|
|
*out_genericBinding = ValidateBufferSlot(funcName, target);
|
|
|
|
if (!*out_genericBinding)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*out_indexedBinding = ValidateIndexedBufferSlot(funcName, target, index);
|
|
|
|
if (!*out_indexedBinding)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER &&
|
|
|
|
mBoundTransformFeedback->mIsActive)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("%s: Cannot update indexed buffer bindings on active"
|
|
|
|
" transform feedback objects.",
|
|
|
|
funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ValidateCanBindToTarget(this, funcName, target, (*out_genericBinding)->get()))
|
|
|
|
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
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bindBufferBase";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull(funcName, buffer))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
2014-12-05 10:04:55 +03:00
|
|
|
if (buffer && buffer->IsDeleted())
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLRefPtr<WebGLBuffer>* genericBinding;
|
|
|
|
IndexedBufferBinding* indexedBinding;
|
|
|
|
if (!ValidateIndexedBufferBinding(funcName, target, index, &genericBinding,
|
|
|
|
&indexedBinding))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-08-20 19:36:20 +04:00
|
|
|
|
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->MakeCurrent();
|
|
|
|
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-09-10 07:02:54 +03:00
|
|
|
*genericBinding = buffer;
|
|
|
|
indexedBinding->mBufferBinding = buffer;
|
|
|
|
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)
|
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bindBufferRange";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull(funcName, buffer))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
|
|
|
if (buffer && buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateNonNegative(funcName, "offset", offset) ||
|
|
|
|
!ValidateNonNegative(funcName, "size", size))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLBuffer>* genericBinding;
|
|
|
|
IndexedBufferBinding* indexedBinding;
|
|
|
|
if (!ValidateIndexedBufferBinding(funcName, target, index, &genericBinding,
|
|
|
|
&indexedBinding))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->MakeCurrent();
|
|
|
|
|
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) {
|
|
|
|
ErrorInvalidValue("%s: For %s, `offset` and `size` must be multiples of 4.",
|
|
|
|
funcName, "TRANSFORM_FEEDBACK_BUFFER");
|
|
|
|
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) {
|
|
|
|
ErrorInvalidValue("%s: For %s, `offset` must be a multiple of %s.",
|
|
|
|
funcName, "UNIFORM_BUFFER",
|
|
|
|
"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-09-10 07:02:54 +03:00
|
|
|
*genericBinding = buffer;
|
|
|
|
indexedBinding->mBufferBinding = buffer;
|
|
|
|
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
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bufferData";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateNonNegative(funcName, "size", size))
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2013-09-04 16:14:39 +04:00
|
|
|
// careful: WebGLsizeiptr is always 64-bit, but GLsizeiptr is like intptr_t.
|
|
|
|
if (!CheckedInt<GLsizeiptr>(size).isValid())
|
2016-09-10 07:02:54 +03:00
|
|
|
return ErrorOutOfMemory("%s: bad size", funcName);
|
2013-09-04 16:14:39 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(funcName, target);
|
|
|
|
if (!buffer)
|
|
|
|
return;
|
2013-08-20 19:36:20 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-02-19 07:51:06 +03:00
|
|
|
UniquePtr<uint8_t> zeroBuffer((uint8_t*)calloc(size, 1));
|
2013-08-20 19:36:19 +04:00
|
|
|
if (!zeroBuffer)
|
2016-09-10 07:02:54 +03:00
|
|
|
return ErrorOutOfMemory("%s: Failed to allocate zeros.", funcName);
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
buffer->BufferData(target, size_t(size), zeroBuffer.get(), usage);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
// BufferT may be one of
|
|
|
|
// const dom::ArrayBuffer&
|
|
|
|
// const dom::SharedArrayBuffer&
|
|
|
|
// const dom::ArrayBufferView&
|
|
|
|
template<typename BufferT>
|
2013-08-20 19:36:19 +04:00
|
|
|
void
|
2015-10-14 08:48:19 +03:00
|
|
|
WebGLContext::BufferDataT(GLenum target,
|
|
|
|
const BufferT& data,
|
|
|
|
GLenum usage)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bufferData";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
data.ComputeLengthAndData();
|
2013-08-20 19:36:20 +04:00
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
// Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
|
|
|
|
// is like intptr_t.
|
2015-11-26 14:47:53 +03:00
|
|
|
if (!CheckedInt<GLsizeiptr>(data.LengthAllowShared()).isValid())
|
2013-09-04 16:14:39 +04:00
|
|
|
return ErrorOutOfMemory("bufferData: bad size");
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(funcName, target);
|
|
|
|
if (!buffer)
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
2016-01-01 22:00:48 +03:00
|
|
|
|
2015-11-26 14:47:53 +03:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2016-09-10 07:02:54 +03:00
|
|
|
buffer->BufferData(target, data.LengthAllowShared(), data.DataAllowShared(), usage);
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-14 08:48:19 +03:00
|
|
|
WebGLContext::BufferData(GLenum target,
|
|
|
|
const dom::SharedArrayBuffer& data,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLenum usage)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2015-10-14 08:48:19 +03:00
|
|
|
BufferDataT(target, data, usage);
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
|
|
|
WebGLContext::BufferData(GLenum target,
|
|
|
|
const dom::Nullable<dom::ArrayBuffer>& maybeData,
|
|
|
|
GLenum usage)
|
|
|
|
{
|
|
|
|
if (maybeData.IsNull()) {
|
|
|
|
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
|
|
|
return ErrorInvalidValue("bufferData: null object passed");
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
2015-10-14 08:48:19 +03:00
|
|
|
BufferDataT(target, maybeData.Value(), usage);
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
|
|
|
WebGLContext::BufferData(GLenum target, const dom::ArrayBufferView& data,
|
|
|
|
GLenum usage)
|
|
|
|
{
|
|
|
|
BufferDataT(target, data, 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
|
|
|
// BufferT may be one of
|
|
|
|
// const dom::ArrayBuffer&
|
|
|
|
// const dom::SharedArrayBuffer&
|
|
|
|
// const dom::ArrayBufferView&
|
|
|
|
template<typename BufferT>
|
|
|
|
void
|
|
|
|
WebGLContext::BufferSubDataT(GLenum target,
|
|
|
|
WebGLsizeiptr byteOffset,
|
|
|
|
const BufferT& data)
|
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "bufferSubData";
|
2015-10-14 08:48:19 +03:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (!ValidateNonNegative(funcName, "byteOffset", byteOffset))
|
2013-08-20 19:36:20 +04:00
|
|
|
return;
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(funcName, target);
|
|
|
|
if (!buffer)
|
|
|
|
return;
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (buffer->mNumActiveTFOs) {
|
|
|
|
ErrorInvalidOperation("%s: Buffer is bound to an active transform feedback"
|
|
|
|
" object.",
|
|
|
|
"bufferSubData");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
data.ComputeLengthAndData();
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto checked_neededByteLength =
|
|
|
|
CheckedInt<size_t>(byteOffset) + data.LengthAllowShared();
|
2014-12-05 10:04:55 +03:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!checked_neededByteLength.isValid()) {
|
|
|
|
ErrorInvalidValue("bufferSubData: Integer overflow computing the needed"
|
|
|
|
" byte length.");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
if (checked_neededByteLength.value() > buffer->ByteLength()) {
|
2014-11-14 07:03:50 +03:00
|
|
|
ErrorInvalidValue("bufferSubData: Not enough data. Operation requires"
|
|
|
|
" %d bytes, but buffer only has %d bytes.",
|
|
|
|
checked_neededByteLength.value(),
|
2016-09-10 07:02:54 +03:00
|
|
|
buffer->ByteLength());
|
2014-11-14 07:03:50 +03:00
|
|
|
return;
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
MakeContextCurrent();
|
2015-11-26 14:47:53 +03:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2016-09-10 07:02:54 +03:00
|
|
|
gl->fBufferSubData(target, byteOffset, data.LengthAllowShared(),
|
|
|
|
data.DataAllowShared());
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-11-26 14:47:53 +03:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2016-09-10 07:02:54 +03:00
|
|
|
buffer->ElementArrayCacheBufferSubData(byteOffset, data.DataAllowShared(),
|
|
|
|
data.LengthAllowShared());
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
2015-10-14 08:48:19 +03:00
|
|
|
const dom::Nullable<dom::ArrayBuffer>& maybeData)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2015-10-14 08:48:19 +03:00
|
|
|
if (maybeData.IsNull()) {
|
2016-07-07 03:42:00 +03:00
|
|
|
ErrorInvalidValue("BufferSubData: returnedData is null.");
|
2014-11-14 07:03:50 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-10-14 08:48:19 +03:00
|
|
|
BufferSubDataT(target, byteOffset, maybeData.Value());
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
const dom::SharedArrayBuffer& data)
|
|
|
|
{
|
|
|
|
BufferSubDataT(target, byteOffset, data);
|
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2015-10-14 08:48:19 +03:00
|
|
|
void
|
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
const dom::ArrayBufferView& data)
|
|
|
|
{
|
|
|
|
BufferSubDataT(target, byteOffset, data);
|
|
|
|
}
|
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()
|
|
|
|
{
|
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;
|
|
|
|
MakeContextCurrent();
|
|
|
|
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
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!buffer || buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////
|
2013-08-20 19:36:19 +04:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto fnClearIfBuffer = [&](WebGLRefPtr<WebGLBuffer>& bindPoint) {
|
|
|
|
if (bindPoint == buffer) {
|
|
|
|
bindPoint = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fnClearIfBuffer(mBoundArrayBuffer);
|
|
|
|
fnClearIfBuffer(mBoundVertexArray->mElementArrayBuffer);
|
2015-06-02 04:08:55 +03:00
|
|
|
|
|
|
|
// WebGL binding points
|
|
|
|
if (IsWebGL2()) {
|
2016-09-10 07:02:54 +03:00
|
|
|
fnClearIfBuffer(mBoundCopyReadBuffer);
|
|
|
|
fnClearIfBuffer(mBoundCopyWriteBuffer);
|
|
|
|
fnClearIfBuffer(mBoundPixelPackBuffer);
|
|
|
|
fnClearIfBuffer(mBoundPixelUnpackBuffer);
|
|
|
|
fnClearIfBuffer(mBoundUniformBuffer);
|
|
|
|
fnClearIfBuffer(mBoundTransformFeedback->mGenericBufferBinding);
|
|
|
|
|
|
|
|
for (auto& binding : mBoundTransformFeedback->mIndexedBindings) {
|
|
|
|
fnClearIfBuffer(binding.mBufferBinding);
|
2015-06-02 04:08:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
for (auto& binding : mIndexedUniformBufferBindings) {
|
|
|
|
fnClearIfBuffer(binding.mBufferBinding);
|
2015-06-02 04:08:55 +03:00
|
|
|
}
|
2013-08-20 19:36:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < mGLMaxVertexAttribs; i++) {
|
2016-09-10 07:02:54 +03:00
|
|
|
if (mBoundVertexArray->HasAttrib(i)) {
|
|
|
|
fnClearIfBuffer(mBoundVertexArray->mAttribs[i].buf);
|
2014-11-14 07:03:50 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::IsBuffer(WebGLBuffer* buffer)
|
2013-08-20 19:36:19 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-20 19:36:19 +04:00
|
|
|
return false;
|
|
|
|
|
2015-05-21 02:59:14 +03:00
|
|
|
if (!ValidateObjectAllowDeleted("isBuffer", buffer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (buffer->IsDeleted())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
return gl->fIsBuffer(buffer->mGLName);
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|