2012-10-05 00:35:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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/. */
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
#include "WebGLContext.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
|
2016-11-30 05:30:28 +03:00
|
|
|
: WebGLRefCountedObject(webgl)
|
2015-05-22 08:49:30 +03:00
|
|
|
, mGLName(buf)
|
2015-05-21 02:59:14 +03:00
|
|
|
, mContent(Kind::Undefined)
|
2016-09-28 00:03:48 +03:00
|
|
|
, mUsage(LOCAL_GL_STATIC_DRAW)
|
2012-11-21 01:38:20 +04:00
|
|
|
, mByteLength(0)
|
2016-12-29 11:08:39 +03:00
|
|
|
, mTFBindCount(0)
|
|
|
|
, mNonTFBindCount(0)
|
2012-11-21 01:38:20 +04:00
|
|
|
{
|
|
|
|
mContext->mBuffers.insertBack(this);
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::~WebGLBuffer()
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
2015-05-21 02:59:14 +03:00
|
|
|
void
|
2016-09-10 07:02:54 +03:00
|
|
|
WebGLBuffer::SetContentAfterBind(GLenum target)
|
2015-05-21 02:59:14 +03:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
if (mContent != Kind::Undefined)
|
|
|
|
return;
|
|
|
|
|
2015-05-21 02:59:14 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
|
|
|
mContent = Kind::ElementArray;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ARRAY_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_PACK_BUFFER:
|
|
|
|
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER:
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_READ_BUFFER:
|
|
|
|
case LOCAL_GL_COPY_WRITE_BUFFER:
|
2016-09-10 07:02:54 +03:00
|
|
|
mContent = Kind::OtherData;
|
2015-05-21 02:59:14 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: invalid target");
|
2015-05-21 02:59:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::Delete()
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
2017-10-21 01:40:12 +03:00
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
mByteLength = 0;
|
2017-10-21 01:40:12 +03:00
|
|
|
mFetchInvalidator.InvalidateCaches();
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
mIndexCache = nullptr;
|
|
|
|
mIndexRanges.clear();
|
2012-11-21 01:38:20 +04:00
|
|
|
LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
static bool
|
2018-07-27 07:46:33 +03:00
|
|
|
ValidateBufferUsageEnum(WebGLContext* webgl, GLenum usage)
|
2016-09-10 07:02:54 +03:00
|
|
|
{
|
|
|
|
switch (usage) {
|
|
|
|
case LOCAL_GL_STREAM_DRAW:
|
|
|
|
case LOCAL_GL_STATIC_DRAW:
|
|
|
|
case LOCAL_GL_DYNAMIC_DRAW:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_DYNAMIC_COPY:
|
|
|
|
case LOCAL_GL_DYNAMIC_READ:
|
|
|
|
case LOCAL_GL_STATIC_COPY:
|
|
|
|
case LOCAL_GL_STATIC_READ:
|
|
|
|
case LOCAL_GL_STREAM_COPY:
|
|
|
|
case LOCAL_GL_STREAM_READ:
|
|
|
|
if (MOZ_LIKELY(webgl->IsWebGL2()))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
webgl->ErrorInvalidEnumInfo("usage", usage);
|
2016-09-10 07:02:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLBuffer::BufferData(GLenum target, size_t size, const void* data, GLenum usage)
|
|
|
|
{
|
2016-10-12 01:40:34 +03:00
|
|
|
// Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
|
|
|
|
// is like intptr_t.
|
|
|
|
if (!CheckedInt<GLsizeiptr>(size).isValid())
|
2018-07-27 07:46:33 +03:00
|
|
|
return mContext->ErrorOutOfMemory("bad size");
|
2016-10-12 01:40:34 +03:00
|
|
|
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateBufferUsageEnum(mContext, usage))
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// bug 790879
|
2017-02-10 07:32:58 +03:00
|
|
|
if (mContext->gl->WorkAroundDriverBugs() &&
|
2016-09-10 07:02:54 +03:00
|
|
|
size > INT32_MAX)
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorOutOfMemory("Allocation size too large.");
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
const void* uploadData = data;
|
|
|
|
|
|
|
|
UniqueBuffer newIndexCache;
|
|
|
|
if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER &&
|
|
|
|
mContext->mNeedsIndexValidation)
|
|
|
|
{
|
|
|
|
newIndexCache = malloc(size);
|
|
|
|
if (!newIndexCache) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorOutOfMemory("Failed to alloc index cache.");
|
2017-02-10 07:32:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(newIndexCache.get(), data, size);
|
|
|
|
uploadData = newIndexCache.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
const ScopedLazyBind lazyBind(gl, target, this);
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const bool sizeChanges = (size != ByteLength());
|
|
|
|
if (sizeChanges) {
|
|
|
|
gl::GLContext::LocalErrorScope errorScope(*gl);
|
2017-02-10 07:32:58 +03:00
|
|
|
gl->fBufferData(target, size, uploadData, usage);
|
2016-09-10 07:02:54 +03:00
|
|
|
const auto error = errorScope.GetError();
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
MOZ_ASSERT(error == LOCAL_GL_OUT_OF_MEMORY);
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorOutOfMemory("Error from driver: 0x%04x", error);
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-10 07:32:58 +03:00
|
|
|
gl->fBufferData(target, size, uploadData, usage);
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
|
2017-06-22 21:32:00 +03:00
|
|
|
mContext->OnDataAllocCall();
|
|
|
|
|
2016-09-28 00:03:48 +03:00
|
|
|
mUsage = usage;
|
2016-09-10 07:02:54 +03:00
|
|
|
mByteLength = size;
|
2017-10-21 01:40:12 +03:00
|
|
|
mFetchInvalidator.InvalidateCaches();
|
2018-05-30 22:15:35 +03:00
|
|
|
mIndexCache = std::move(newIndexCache);
|
2016-09-10 07:02:54 +03:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
if (mIndexCache) {
|
2017-08-03 13:01:38 +03:00
|
|
|
if (!mIndexRanges.empty()) {
|
2017-02-10 07:32:58 +03:00
|
|
|
mContext->GeneratePerfWarning("[%p] Invalidating %u ranges.", this,
|
|
|
|
uint32_t(mIndexRanges.size()));
|
|
|
|
mIndexRanges.clear();
|
|
|
|
}
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
2017-12-21 03:31:58 +03:00
|
|
|
|
|
|
|
ResetLastUpdateFenceId();
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
void
|
|
|
|
WebGLBuffer::BufferSubData(GLenum target, size_t dstByteOffset, size_t dataLen,
|
|
|
|
const void* data) const
|
|
|
|
{
|
2018-07-27 07:46:33 +03:00
|
|
|
if (!ValidateRange(dstByteOffset, dataLen))
|
2017-02-10 07:32:58 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!CheckedInt<GLintptr>(dataLen).isValid())
|
2018-07-27 07:46:33 +03:00
|
|
|
return mContext->ErrorOutOfMemory("Size too large.");
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const void* uploadData = data;
|
|
|
|
if (mIndexCache) {
|
|
|
|
const auto cachedDataBegin = (uint8_t*)mIndexCache.get() + dstByteOffset;
|
|
|
|
memcpy(cachedDataBegin, data, dataLen);
|
|
|
|
uploadData = cachedDataBegin;
|
|
|
|
|
|
|
|
InvalidateCacheRange(dstByteOffset, dataLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
const auto& gl = mContext->gl;
|
|
|
|
const ScopedLazyBind lazyBind(gl, target, this);
|
|
|
|
|
|
|
|
gl->fBufferSubData(target, dstByteOffset, dataLen, uploadData);
|
2017-12-21 03:31:58 +03:00
|
|
|
|
|
|
|
ResetLastUpdateFenceId();
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 03:37:29 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLBuffer::ValidateRange(size_t byteOffset, size_t byteLen) const
|
2016-10-12 03:37:29 +03:00
|
|
|
{
|
|
|
|
auto availLength = mByteLength;
|
|
|
|
if (byteOffset > availLength) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidValue("Offset passes the end of the buffer.");
|
2016-10-12 03:37:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
availLength -= byteOffset;
|
|
|
|
|
|
|
|
if (byteLen > availLength) {
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidValue("Offset+size passes the end of the buffer.");
|
2016-10-12 03:37:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
static uint8_t
|
|
|
|
IndexByteSizeByType(GLenum type)
|
2014-11-14 07:03:50 +03:00
|
|
|
{
|
2017-02-10 07:32:58 +03:00
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE: return 1;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT: return 2;
|
|
|
|
case LOCAL_GL_UNSIGNED_INT: return 4;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-10-21 01:40:12 +03:00
|
|
|
WebGLBuffer::InvalidateCacheRange(uint64_t byteOffset, uint64_t byteLength) const
|
2014-11-14 07:03:50 +03:00
|
|
|
{
|
2017-02-10 07:32:58 +03:00
|
|
|
MOZ_ASSERT(mIndexCache);
|
|
|
|
|
|
|
|
std::vector<IndexRange> invalids;
|
2017-10-21 01:40:12 +03:00
|
|
|
const uint64_t updateBegin = byteOffset;
|
|
|
|
const uint64_t updateEnd = updateBegin + byteLength;
|
2017-02-10 07:32:58 +03:00
|
|
|
for (const auto& cur : mIndexRanges) {
|
|
|
|
const auto& range = cur.first;
|
|
|
|
const auto& indexByteSize = IndexByteSizeByType(range.type);
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto rangeBegin = range.byteOffset * indexByteSize;
|
|
|
|
const auto rangeEnd = rangeBegin + uint64_t(range.indexCount) * indexByteSize;
|
2017-02-10 07:32:58 +03:00
|
|
|
if (rangeBegin >= updateEnd || rangeEnd <= updateBegin)
|
|
|
|
continue;
|
|
|
|
invalids.push_back(range);
|
|
|
|
}
|
2016-12-21 05:44:28 +03:00
|
|
|
|
2017-08-03 13:01:38 +03:00
|
|
|
if (!invalids.empty()) {
|
2017-02-10 07:32:58 +03:00
|
|
|
mContext->GeneratePerfWarning("[%p] Invalidating %u/%u ranges.", this,
|
|
|
|
uint32_t(invalids.size()),
|
|
|
|
uint32_t(mIndexRanges.size()));
|
|
|
|
|
|
|
|
for (const auto& cur : invalids) {
|
|
|
|
mIndexRanges.erase(cur);
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 01:38:20 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 18:52:56 +04:00
|
|
|
size_t
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
2014-03-17 18:52:56 +04:00
|
|
|
{
|
2017-02-10 07:32:58 +03:00
|
|
|
size_t size = mallocSizeOf(this);
|
|
|
|
if (mIndexCache) {
|
|
|
|
size += mByteLength;
|
|
|
|
}
|
|
|
|
return size;
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
template<typename T>
|
2017-10-21 01:40:12 +03:00
|
|
|
static Maybe<uint32_t>
|
|
|
|
MaxForRange(const void* const start, const uint32_t count,
|
|
|
|
const Maybe<uint32_t>& untypedIgnoredVal)
|
2014-03-17 18:52:56 +04:00
|
|
|
{
|
2017-10-21 01:40:12 +03:00
|
|
|
const Maybe<T> ignoredVal = (untypedIgnoredVal ? Some(T(untypedIgnoredVal.value()))
|
|
|
|
: Nothing());
|
|
|
|
Maybe<uint32_t> maxVal;
|
2016-12-21 05:44:28 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
auto itr = (const T*)start;
|
2017-02-10 07:32:58 +03:00
|
|
|
const auto end = itr + count;
|
|
|
|
|
|
|
|
for (; itr != end; ++itr) {
|
|
|
|
const auto& val = *itr;
|
2017-10-21 01:40:12 +03:00
|
|
|
if (ignoredVal && val == ignoredVal.value())
|
2017-02-10 07:32:58 +03:00
|
|
|
continue;
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
if (maxVal && val <= maxVal.value())
|
2017-02-10 07:32:58 +03:00
|
|
|
continue;
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
maxVal = Some(val);
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
return maxVal;
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
static const uint32_t kMaxIndexRanges = 256;
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
Maybe<uint32_t>
|
|
|
|
WebGLBuffer::GetIndexedFetchMaxVert(const GLenum type, const uint64_t byteOffset,
|
|
|
|
const uint32_t indexCount) const
|
2014-06-03 00:30:00 +04:00
|
|
|
{
|
2017-02-10 07:32:58 +03:00
|
|
|
if (!mIndexCache)
|
2017-10-21 01:40:12 +03:00
|
|
|
return Nothing();
|
2017-02-10 07:32:58 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
const IndexRange range = { type, byteOffset, indexCount };
|
|
|
|
auto res = mIndexRanges.insert({ range, Nothing() });
|
2017-02-10 07:32:58 +03:00
|
|
|
if (mIndexRanges.size() > kMaxIndexRanges) {
|
|
|
|
mContext->GeneratePerfWarning("[%p] Clearing mIndexRanges after exceeding %u.",
|
|
|
|
this, kMaxIndexRanges);
|
|
|
|
mIndexRanges.clear();
|
2017-10-21 01:40:12 +03:00
|
|
|
res = mIndexRanges.insert({ range, Nothing() });
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto& itr = res.first;
|
|
|
|
const auto& didInsert = res.second;
|
|
|
|
|
|
|
|
auto& maxFetchIndex = itr->second;
|
|
|
|
if (didInsert) {
|
|
|
|
const auto& data = mIndexCache.get();
|
2017-10-21 01:40:12 +03:00
|
|
|
|
|
|
|
const auto start = (const uint8_t*)data + byteOffset;
|
|
|
|
|
|
|
|
Maybe<uint32_t> ignoredVal;
|
|
|
|
if (mContext->IsWebGL2()) {
|
|
|
|
ignoredVal = Some(UINT32_MAX);
|
|
|
|
}
|
2017-02-10 07:32:58 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint8_t>(start, indexCount, ignoredVal);
|
2017-02-10 07:32:58 +03:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint16_t>(start, indexCount, ignoredVal);
|
2017-02-10 07:32:58 +03:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
2017-10-21 01:40:12 +03:00
|
|
|
maxFetchIndex = MaxForRange<uint32_t>(start, indexCount, ignoredVal);
|
2017-02-10 07:32:58 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2017-10-21 01:40:12 +03:00
|
|
|
const auto displayMaxVertIndex = maxFetchIndex ? int64_t(maxFetchIndex.value())
|
|
|
|
: -1;
|
|
|
|
mContext->GeneratePerfWarning("[%p] New range #%u: (0x%04x, %" PRIu64 ", %u):"
|
|
|
|
" %" PRIi64,
|
|
|
|
this, uint32_t(mIndexRanges.size()), range.type,
|
|
|
|
range.byteOffset, range.indexCount,
|
|
|
|
displayMaxVertIndex);
|
2017-02-10 07:32:58 +03:00
|
|
|
}
|
2016-12-21 05:44:28 +03:00
|
|
|
|
2017-10-21 01:40:12 +03:00
|
|
|
return maxFetchIndex;
|
2014-06-03 00:30:00 +04:00
|
|
|
}
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2016-12-21 05:44:28 +03:00
|
|
|
////
|
|
|
|
|
2016-09-18 02:44:56 +03:00
|
|
|
bool
|
2018-07-27 07:46:33 +03:00
|
|
|
WebGLBuffer::ValidateCanBindToTarget(GLenum target)
|
2016-09-18 02:44:56 +03:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (mContent == 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 (mContent == 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 (mContent == WebGLBuffer::Kind::OtherData)
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dataType = (mContent == WebGLBuffer::Kind::OtherData) ? "other"
|
|
|
|
: "element";
|
2018-07-27 07:46:33 +03:00
|
|
|
mContext->ErrorInvalidOperation("Buffer already contains %s data.",
|
2016-09-18 02:44:56 +03:00
|
|
|
dataType);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-21 03:31:58 +03:00
|
|
|
void
|
|
|
|
WebGLBuffer::ResetLastUpdateFenceId() const
|
|
|
|
{
|
|
|
|
mLastUpdateFenceId = mContext->mNextFenceId;
|
|
|
|
}
|
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
JSObject*
|
2015-07-15 03:37:28 +03:00
|
|
|
WebGLBuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
|
2014-11-14 07:03:50 +03:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return dom::WebGLBuffer_Binding::Wrap(cx, this, givenProto);
|
2012-10-05 00:35:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
|
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|