2013-08-20 08:36:19 -07: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"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2013-08-20 08:36:19 -07:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLVertexArray.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindBuffer(GLenum target, WebGLBuffer *buffer)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindBuffer", buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
|
|
|
if (buffer && buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
|
|
|
|
|
|
|
|
if (!bufferSlot) {
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer) {
|
2014-05-06 20:11:18 -07:00
|
|
|
if (!buffer->HasEverBeenBound()) {
|
|
|
|
buffer->BindTo(target);
|
2013-08-20 08:36:20 -07:00
|
|
|
} else if (target != buffer->Target()) {
|
2013-08-20 08:36:19 -07:00
|
|
|
return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
|
2013-08-20 08:36:20 -07:00
|
|
|
}
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
*bufferSlot = buffer;
|
2013-08-20 08:36:19 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fBindBuffer(target, buffer ? buffer->GLName() : 0);
|
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer)
|
2013-08-20 08:36:20 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:20 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindBufferBase", buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
|
|
|
if (buffer && buffer->IsDeleted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index, "bindBufferBase");
|
2013-08-20 08:36:20 -07:00
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
if (!indexedBufferSlot) {
|
2013-08-20 08:36:20 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer) {
|
2014-05-06 20:11:18 -07:00
|
|
|
if (!buffer->HasEverBeenBound())
|
|
|
|
buffer->BindTo(target);
|
|
|
|
|
|
|
|
if (target != buffer->Target())
|
2013-08-20 08:36:20 -07:00
|
|
|
return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
|
|
|
|
}
|
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
|
|
|
|
|
|
|
|
MOZ_ASSERT(bufferSlot, "GetBufferSlotByTarget(Indexed) mismatch");
|
|
|
|
|
|
|
|
*indexedBufferSlot = buffer;
|
2013-08-20 08:36:20 -07:00
|
|
|
*bufferSlot = buffer;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fBindBufferBase(target, index, buffer ? buffer->GLName() : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer,
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLintptr offset, WebGLsizeiptr size)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:20 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindBufferRange", buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
|
|
|
if (buffer && buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* indexedBufferSlot = GetBufferSlotByTargetIndexed(target, index, "bindBufferBase");
|
2013-08-20 08:36:20 -07:00
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
if (!indexedBufferSlot) {
|
2013-08-20 08:36:20 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer) {
|
2014-05-06 20:11:18 -07:00
|
|
|
if (!buffer->HasEverBeenBound())
|
|
|
|
buffer->BindTo(target);
|
|
|
|
|
|
|
|
if (target != buffer->Target())
|
2013-08-20 08:36:20 -07:00
|
|
|
return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
|
2014-05-06 20:11:18 -07:00
|
|
|
|
2013-09-04 05:14:37 -07:00
|
|
|
CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(offset) + size;
|
|
|
|
if (!checked_neededByteLength.isValid() ||
|
|
|
|
checked_neededByteLength.value() > buffer->ByteLength())
|
|
|
|
{
|
|
|
|
return ErrorInvalidValue("bindBufferRange: invalid range");
|
|
|
|
}
|
2013-08-20 08:36:20 -07:00
|
|
|
}
|
|
|
|
|
2013-08-26 13:03:32 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bindBuffer");
|
|
|
|
|
|
|
|
MOZ_ASSERT(bufferSlot, "GetBufferSlotByTarget(Indexed) mismatch");
|
|
|
|
|
|
|
|
*indexedBufferSlot = buffer;
|
2013-08-20 08:36:20 -07:00
|
|
|
*bufferSlot = buffer;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fBindBufferRange(target, index, buffer ? buffer->GLName() : 0, offset, size);
|
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BufferData(GLenum target, WebGLsizeiptr size,
|
|
|
|
GLenum usage)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferData");
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
if (!bufferSlot) {
|
|
|
|
return;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (size < 0)
|
|
|
|
return ErrorInvalidValue("bufferData: negative size");
|
|
|
|
|
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
|
|
|
return;
|
|
|
|
|
2013-09-04 05:14:39 -07:00
|
|
|
// careful: WebGLsizeiptr is always 64-bit, but GLsizeiptr is like intptr_t.
|
|
|
|
if (!CheckedInt<GLsizeiptr>(size).isValid())
|
|
|
|
return ErrorOutOfMemory("bufferData: bad size");
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLBuffer* boundBuffer = bufferSlot->get();
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
|
|
|
|
|
|
|
void* zeroBuffer = calloc(size, 1);
|
|
|
|
if (!zeroBuffer)
|
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
|
|
|
GLenum error = CheckedBufferData(target, size, zeroBuffer, usage);
|
|
|
|
free(zeroBuffer);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
GenerateWarning("bufferData generated error %s", ErrorName(error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boundBuffer->SetByteLength(size);
|
|
|
|
if (!boundBuffer->ElementArrayCacheBufferData(nullptr, size)) {
|
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BufferData(GLenum target,
|
2013-08-20 08:36:19 -07:00
|
|
|
const Nullable<ArrayBuffer> &maybeData,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum usage)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (maybeData.IsNull()) {
|
|
|
|
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
|
|
|
return ErrorInvalidValue("bufferData: null object passed");
|
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferData");
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
if (!bufferSlot) {
|
|
|
|
return;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
const ArrayBuffer& data = maybeData.Value();
|
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-27 14:32:41 -07:00
|
|
|
data.ComputeLengthAndData();
|
2013-08-20 08:36:20 -07: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-27 14:32:41 -07:00
|
|
|
// Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
|
|
|
|
// is like intptr_t.
|
2013-09-04 05:14:39 -07:00
|
|
|
if (!CheckedInt<GLsizeiptr>(data.Length()).isValid())
|
|
|
|
return ErrorOutOfMemory("bufferData: bad size");
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLBuffer* boundBuffer = bufferSlot->get();
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
|
|
|
GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
GenerateWarning("bufferData generated error %s", ErrorName(error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boundBuffer->SetByteLength(data.Length());
|
|
|
|
if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
|
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BufferData(GLenum target, const ArrayBufferView& data,
|
|
|
|
GLenum usage)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
if (!bufferSlot) {
|
|
|
|
return;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLBuffer* boundBuffer = bufferSlot->get();
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
|
|
|
|
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-27 14:32:41 -07:00
|
|
|
data.ComputeLengthAndData();
|
|
|
|
|
|
|
|
// Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
|
|
|
|
// is like intptr_t.
|
2013-09-04 05:14:39 -07:00
|
|
|
if (!CheckedInt<GLsizeiptr>(data.Length()).isValid())
|
|
|
|
return ErrorOutOfMemory("bufferData: bad size");
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
InvalidateBufferFetching();
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);
|
|
|
|
if (error) {
|
|
|
|
GenerateWarning("bufferData generated error %s", ErrorName(error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boundBuffer->SetByteLength(data.Length());
|
|
|
|
if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
|
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
const Nullable<ArrayBuffer> &maybeData)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (maybeData.IsNull()) {
|
|
|
|
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
if (!bufferSlot) {
|
|
|
|
return;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("bufferSubData: negative offset");
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLBuffer* boundBuffer = bufferSlot->get();
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
|
|
|
|
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-27 14:32:41 -07:00
|
|
|
const ArrayBuffer& data = maybeData.Value();
|
|
|
|
data.ComputeLengthAndData();
|
|
|
|
|
2013-09-04 05:14:35 -07:00
|
|
|
CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(byteOffset) + data.Length();
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
|
|
|
return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length");
|
|
|
|
|
|
|
|
if (checked_neededByteLength.value() > boundBuffer->ByteLength())
|
|
|
|
return ErrorInvalidValue("bufferSubData: not enough data - operation requires %d bytes, but buffer only has %d bytes",
|
|
|
|
checked_neededByteLength.value(), boundBuffer->ByteLength());
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(), data.Length());
|
|
|
|
|
|
|
|
gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
2013-08-20 08:36:19 -07:00
|
|
|
const ArrayBufferView& data)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferSubData");
|
2013-08-20 08:36:19 -07:00
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
if (!bufferSlot) {
|
|
|
|
return;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("bufferSubData: negative offset");
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLBuffer* boundBuffer = bufferSlot->get();
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("bufferSubData: no buffer bound!");
|
|
|
|
|
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-27 14:32:41 -07:00
|
|
|
data.ComputeLengthAndData();
|
|
|
|
|
2013-09-04 05:14:35 -07:00
|
|
|
CheckedInt<WebGLsizeiptr> checked_neededByteLength = CheckedInt<WebGLsizeiptr>(byteOffset) + data.Length();
|
2013-08-20 08:36:19 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
|
|
|
return ErrorInvalidValue("bufferSubData: integer overflow computing the needed byte length");
|
|
|
|
|
|
|
|
if (checked_neededByteLength.value() > boundBuffer->ByteLength())
|
|
|
|
return ErrorInvalidValue("bufferSubData: not enough data -- operation requires %d bytes, but buffer only has %d bytes",
|
|
|
|
checked_neededByteLength.value(), boundBuffer->ByteLength());
|
|
|
|
|
|
|
|
boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(), data.Length());
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLBuffer>
|
|
|
|
WebGLContext::CreateBuffer()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteBuffer(WebGLBuffer *buffer)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buffer))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!buffer || buffer->IsDeleted())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mBoundArrayBuffer == buffer) {
|
|
|
|
BindBuffer(LOCAL_GL_ARRAY_BUFFER,
|
|
|
|
static_cast<WebGLBuffer*>(nullptr));
|
|
|
|
}
|
|
|
|
|
2014-06-05 16:38:27 -07:00
|
|
|
if (mBoundVertexArray->mElementArrayBuffer == buffer) {
|
2013-08-20 08:36:19 -07:00
|
|
|
BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER,
|
|
|
|
static_cast<WebGLBuffer*>(nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < mGLMaxVertexAttribs; i++) {
|
2013-10-11 06:16:44 -07:00
|
|
|
if (mBoundVertexArray->HasAttrib(i) && mBoundVertexArray->mAttribs[i].buf == buffer)
|
|
|
|
mBoundVertexArray->mAttribs[i].buf = nullptr;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer->RequestDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsBuffer(WebGLBuffer *buffer)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-20 08:36:19 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return ValidateObjectAllowDeleted("isBuffer", buffer) &&
|
|
|
|
!buffer->IsDeleted() &&
|
|
|
|
buffer->HasEverBeenBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::ValidateBufferUsageEnum(GLenum target, const char *infos)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
2013-08-20 08:36:20 -07:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_STREAM_DRAW:
|
|
|
|
case LOCAL_GL_STATIC_DRAW:
|
|
|
|
case LOCAL_GL_DYNAMIC_DRAW:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorInvalidEnumInfo(infos, target);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLRefPtr<WebGLBuffer>*
|
|
|
|
WebGLContext::GetBufferSlotByTarget(GLenum target, const char* infos)
|
|
|
|
{
|
|
|
|
switch (target) {
|
2013-08-20 08:36:19 -07:00
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
2013-08-20 08:36:20 -07:00
|
|
|
return &mBoundArrayBuffer;
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
2014-06-05 16:38:27 -07:00
|
|
|
return &mBoundVertexArray->mElementArrayBuffer;
|
2013-08-20 08:36:20 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
if (!IsWebGL2()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return &mBoundTransformFeedbackBuffer;
|
2013-08-20 08:36:19 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorInvalidEnum("%s: target: invalid enum value 0x%x", infos, target);
|
2013-08-20 08:36:20 -07:00
|
|
|
return nullptr;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer>*
|
|
|
|
WebGLContext::GetBufferSlotByTargetIndexed(GLenum target, GLuint index, const char* infos)
|
2013-08-20 08:36:19 -07:00
|
|
|
{
|
|
|
|
switch (target) {
|
2013-08-20 08:36:20 -07:00
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
if (index >= mGLMaxTransformFeedbackSeparateAttribs) {
|
|
|
|
ErrorInvalidValue("%s: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", infos, index);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return nullptr; // See bug 903594
|
|
|
|
|
2013-08-20 08:36:19 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-20 08:36:20 -07:00
|
|
|
ErrorInvalidEnum("%s: target: invalid enum value 0x%x", infos, target);
|
|
|
|
return nullptr;
|
2013-08-20 08:36:19 -07:00
|
|
|
}
|
2013-09-04 05:14:46 -07:00
|
|
|
|
|
|
|
GLenum
|
|
|
|
WebGLContext::CheckedBufferData(GLenum target,
|
|
|
|
GLsizeiptr size,
|
|
|
|
const GLvoid *data,
|
|
|
|
GLenum usage)
|
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// bug 790879
|
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
int64_t(size) > INT32_MAX) // the cast avoids a potential always-true warning on 32bit
|
|
|
|
{
|
|
|
|
GenerateWarning("Rejecting valid bufferData call with size %lu to avoid a Mac bug", size);
|
|
|
|
return LOCAL_GL_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
WebGLBuffer *boundBuffer = nullptr;
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
2014-06-05 16:38:27 -07:00
|
|
|
boundBuffer = mBoundVertexArray->mElementArrayBuffer;
|
2013-09-04 05:14:46 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(boundBuffer != nullptr, "no buffer bound for this target");
|
2013-09-04 05:14:46 -07:00
|
|
|
|
|
|
|
bool sizeChanges = uint32_t(size) != boundBuffer->ByteLength();
|
|
|
|
if (sizeChanges) {
|
2014-03-07 13:16:34 -08:00
|
|
|
GetAndFlushUnderlyingGLErrors();
|
2013-09-04 05:14:46 -07:00
|
|
|
gl->fBufferData(target, size, data, usage);
|
2014-03-07 13:16:34 -08:00
|
|
|
GLenum error = GetAndFlushUnderlyingGLErrors();
|
2013-09-04 05:14:46 -07:00
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
gl->fBufferData(target, size, data, usage);
|
|
|
|
return LOCAL_GL_NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|