2012-10-04 13:35:54 -07: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-20 13:38:20 -08:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLElementArrayCache.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-11-20 13:38:20 -08:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext *context)
|
2014-09-26 13:11:51 -07:00
|
|
|
: WebGLBindableName<BufferBinding>()
|
2014-05-06 20:11:18 -07:00
|
|
|
, WebGLContextBoundObject(context)
|
2012-11-20 13:38:20 -08:00
|
|
|
, mByteLength(0)
|
|
|
|
{
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fGenBuffers(1, &mGLName);
|
|
|
|
mContext->mBuffers.insertBack(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLBuffer::~WebGLBuffer() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLBuffer::Delete() {
|
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
|
|
|
mByteLength = 0;
|
|
|
|
mCache = nullptr;
|
|
|
|
LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-06 20:11:18 -07:00
|
|
|
WebGLBuffer::OnTargetChanged() {
|
2012-11-20 13:38:20 -08:00
|
|
|
if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
mCache = new WebGLElementArrayCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
|
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
return mCache->BufferData(ptr, buffer_size_in_bytes);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
|
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
mCache->BufferSubData(pos, ptr, update_size_in_bytes);
|
|
|
|
}
|
|
|
|
|
2014-03-17 07:52:56 -07:00
|
|
|
size_t
|
|
|
|
WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
return aMallocSizeOf(this) + sizeOfCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
|
|
|
|
size_t first, size_t count,
|
|
|
|
uint32_t* out_upperBound)
|
|
|
|
{
|
|
|
|
return mCache->Validate(type, max_allowed, first, count, out_upperBound);
|
|
|
|
}
|
|
|
|
|
2014-06-02 13:30:00 -07:00
|
|
|
bool
|
|
|
|
WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
|
|
|
|
{
|
|
|
|
return mCache->BeenUsedWithMultipleTypes();
|
|
|
|
}
|
2014-03-17 07:52:56 -07:00
|
|
|
|
2012-10-04 13:35:54 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
WebGLBuffer::WrapObject(JSContext *cx) {
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::WebGLBufferBinding::Wrap(cx, this);
|
2012-10-04 13:35:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
|
|
|
|
|
2013-08-29 08:39:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
|