mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 903481 - step 1 - Move WebGL buffers function into GLContextBuffers.cpp - r=jgilbert
This commit is contained in:
parent
c80fcf5fa4
commit
3175b5af43
@ -322,7 +322,6 @@ public:
|
||||
void AttachShader(WebGLProgram* program, WebGLShader* shader);
|
||||
void BindAttribLocation(WebGLProgram* program, WebGLuint location,
|
||||
const nsAString& name);
|
||||
void BindBuffer(WebGLenum target, WebGLBuffer* buf);
|
||||
void BindFramebuffer(WebGLenum target, WebGLFramebuffer* wfb);
|
||||
void BindRenderbuffer(WebGLenum target, WebGLRenderbuffer* wrb);
|
||||
void BindTexture(WebGLenum target, WebGLTexture *tex);
|
||||
@ -338,16 +337,6 @@ public:
|
||||
void BlendFunc(WebGLenum sfactor, WebGLenum dfactor);
|
||||
void BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
|
||||
WebGLenum srcAlpha, WebGLenum dstAlpha);
|
||||
void BufferData(WebGLenum target, WebGLsizeiptr size, WebGLenum usage);
|
||||
void BufferData(WebGLenum target, const dom::ArrayBufferView &data,
|
||||
WebGLenum usage);
|
||||
void BufferData(WebGLenum target,
|
||||
const Nullable<dom::ArrayBuffer> &maybeData,
|
||||
WebGLenum usage);
|
||||
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const dom::ArrayBufferView &data);
|
||||
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const Nullable<dom::ArrayBuffer> &maybeData);
|
||||
WebGLenum CheckFramebufferStatus(WebGLenum target);
|
||||
void Clear(WebGLbitfield mask);
|
||||
void ClearColor(WebGLclampf r, WebGLclampf g, WebGLclampf b, WebGLclampf a);
|
||||
@ -370,7 +359,6 @@ public:
|
||||
void CopyTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset,
|
||||
WebGLint yoffset, WebGLint x, WebGLint y,
|
||||
WebGLsizei width, WebGLsizei height);
|
||||
already_AddRefed<WebGLBuffer> CreateBuffer();
|
||||
already_AddRefed<WebGLFramebuffer> CreateFramebuffer();
|
||||
already_AddRefed<WebGLProgram> CreateProgram();
|
||||
already_AddRefed<WebGLRenderbuffer> CreateRenderbuffer();
|
||||
@ -378,7 +366,6 @@ public:
|
||||
already_AddRefed<WebGLShader> CreateShader(WebGLenum type);
|
||||
already_AddRefed<WebGLVertexArray> CreateVertexArray();
|
||||
void CullFace(WebGLenum face);
|
||||
void DeleteBuffer(WebGLBuffer *buf);
|
||||
void DeleteFramebuffer(WebGLFramebuffer *fbuf);
|
||||
void DeleteProgram(WebGLProgram *prog);
|
||||
void DeleteRenderbuffer(WebGLRenderbuffer *rbuf);
|
||||
@ -459,7 +446,6 @@ public:
|
||||
already_AddRefed<WebGLUniformLocation>
|
||||
GetUniformLocation(WebGLProgram *prog, const nsAString& name);
|
||||
void Hint(WebGLenum target, WebGLenum mode);
|
||||
bool IsBuffer(WebGLBuffer *buffer);
|
||||
bool IsFramebuffer(WebGLFramebuffer *fb);
|
||||
bool IsProgram(WebGLProgram *prog);
|
||||
bool IsRenderbuffer(WebGLRenderbuffer *rb);
|
||||
@ -754,6 +740,31 @@ private:
|
||||
bool ValidateTargetParameter(WebGLenum target, const char* infos);
|
||||
WebGLRefPtr<WebGLQuery>& GetActiveQueryByTarget(WebGLenum target);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Buffer Objects (WebGLContextBuffers.cpp)
|
||||
public:
|
||||
void BindBuffer(WebGLenum target, WebGLBuffer* buf);
|
||||
void BufferData(WebGLenum target, WebGLsizeiptr size, WebGLenum usage);
|
||||
void BufferData(WebGLenum target, const dom::ArrayBufferView &data,
|
||||
WebGLenum usage);
|
||||
void BufferData(WebGLenum target,
|
||||
const Nullable<dom::ArrayBuffer> &maybeData,
|
||||
WebGLenum usage);
|
||||
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const dom::ArrayBufferView &data);
|
||||
void BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const Nullable<dom::ArrayBuffer> &maybeData);
|
||||
already_AddRefed<WebGLBuffer> CreateBuffer();
|
||||
void DeleteBuffer(WebGLBuffer *buf);
|
||||
bool IsBuffer(WebGLBuffer *buffer);
|
||||
|
||||
private:
|
||||
// ARRAY_BUFFER binding point
|
||||
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
||||
|
||||
bool ValidateBufferTarget(GLenum target, const char* infos);
|
||||
bool ValidateBufferUsageEnum(WebGLenum target, const char* infos);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// State and State Requests (WebGLContextState.cpp)
|
||||
public:
|
||||
@ -979,7 +990,6 @@ protected:
|
||||
bool ValidateComparisonEnum(WebGLenum target, const char *info);
|
||||
bool ValidateStencilOpEnum(WebGLenum action, const char *info);
|
||||
bool ValidateFaceEnum(WebGLenum face, const char *info);
|
||||
bool ValidateBufferUsageEnum(WebGLenum target, const char *info);
|
||||
bool ValidateTexFormatAndType(WebGLenum format, WebGLenum type, int jsArrayType,
|
||||
uint32_t *texelSize, const char *info);
|
||||
bool ValidateDrawModeEnum(WebGLenum mode, const char *info);
|
||||
@ -1110,8 +1120,6 @@ protected:
|
||||
nsTArray<WebGLRefPtr<WebGLTexture> > mBound2DTextures;
|
||||
nsTArray<WebGLRefPtr<WebGLTexture> > mBoundCubeMapTextures;
|
||||
|
||||
WebGLRefPtr<WebGLBuffer> mBoundArrayBuffer;
|
||||
|
||||
WebGLRefPtr<WebGLProgram> mCurrentProgram;
|
||||
|
||||
uint32_t mMaxFramebufferColorAttachments;
|
||||
|
346
content/canvas/src/WebGLContextBuffers.cpp
Normal file
346
content/canvas/src/WebGLContextBuffers.cpp
Normal file
@ -0,0 +1,346 @@
|
||||
/* -*- 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"
|
||||
#include "WebGLBuffer.h"
|
||||
#include "WebGLVertexArray.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
void
|
||||
WebGLContext::BindBuffer(WebGLenum target, WebGLBuffer *buffer)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (!ValidateObjectAllowDeletedOrNull("bindBuffer", buffer))
|
||||
return;
|
||||
|
||||
// silently ignore a deleted buffer
|
||||
if (buffer && buffer->IsDeleted())
|
||||
return;
|
||||
|
||||
if (!ValidateBufferTarget(target, "bindBuffer")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
if ((buffer->Target() != LOCAL_GL_NONE) && (target != buffer->Target()))
|
||||
return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
|
||||
buffer->SetTarget(target);
|
||||
buffer->SetHasEverBeenBound(true);
|
||||
}
|
||||
|
||||
// we really want to do this AFTER all the validation is done, otherwise our bookkeeping could get confused.
|
||||
// see bug 656752
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
mBoundArrayBuffer = buffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
mBoundVertexArray->mBoundElementArrayBuffer = buffer;
|
||||
}
|
||||
|
||||
MakeContextCurrent();
|
||||
|
||||
gl->fBindBuffer(target, buffer ? buffer->GLName() : 0);
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::BufferData(WebGLenum target, WebGLsizeiptr size,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (size < 0)
|
||||
return ErrorInvalidValue("bufferData: negative size");
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
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
|
||||
WebGLContext::BufferData(WebGLenum target,
|
||||
const Nullable<ArrayBuffer> &maybeData,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (maybeData.IsNull()) {
|
||||
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
||||
return ErrorInvalidValue("bufferData: null object passed");
|
||||
}
|
||||
|
||||
const ArrayBuffer& data = maybeData.Value();
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
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
|
||||
WebGLContext::BufferData(WebGLenum target, const ArrayBufferView& data,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
||||
|
||||
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)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (maybeData.IsNull()) {
|
||||
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
||||
return;
|
||||
}
|
||||
|
||||
const ArrayBuffer& data = maybeData.Value();
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
||||
}
|
||||
|
||||
if (byteOffset < 0)
|
||||
return ErrorInvalidValue("bufferSubData: negative offset");
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
||||
|
||||
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
|
||||
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
|
||||
WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const ArrayBufferView& data)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
||||
}
|
||||
|
||||
if (byteOffset < 0)
|
||||
return ErrorInvalidValue("bufferSubData: negative offset");
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferSubData: no buffer bound!");
|
||||
|
||||
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
|
||||
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()
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return nullptr;
|
||||
|
||||
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this);
|
||||
return globj.forget();
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::DeleteBuffer(WebGLBuffer *buffer)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buffer))
|
||||
return;
|
||||
|
||||
if (!buffer || buffer->IsDeleted())
|
||||
return;
|
||||
|
||||
if (mBoundArrayBuffer == buffer) {
|
||||
BindBuffer(LOCAL_GL_ARRAY_BUFFER,
|
||||
static_cast<WebGLBuffer*>(nullptr));
|
||||
}
|
||||
|
||||
if (mBoundVertexArray->mBoundElementArrayBuffer == buffer) {
|
||||
BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER,
|
||||
static_cast<WebGLBuffer*>(nullptr));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < mGLMaxVertexAttribs; i++) {
|
||||
if (mBoundVertexArray->mAttribBuffers[i].buf == buffer)
|
||||
mBoundVertexArray->mAttribBuffers[i].buf = nullptr;
|
||||
}
|
||||
|
||||
buffer->RequestDelete();
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::IsBuffer(WebGLBuffer *buffer)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return false;
|
||||
|
||||
return ValidateObjectAllowDeleted("isBuffer", buffer) &&
|
||||
!buffer->IsDeleted() &&
|
||||
buffer->HasEverBeenBound();
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::ValidateBufferTarget(WebGLenum target, const char* infos)
|
||||
{
|
||||
switch(target)
|
||||
{
|
||||
case LOCAL_GL_ARRAY_BUFFER:
|
||||
case LOCAL_GL_ELEMENT_ARRAY_BUFFER:
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ErrorInvalidEnum("%s: target: invalid enum value 0x%x", infos, target);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::ValidateBufferUsageEnum(WebGLenum target, const char *infos)
|
||||
{
|
||||
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;
|
||||
}
|
@ -127,47 +127,6 @@ WebGLContext::BindAttribLocation(WebGLProgram *prog, WebGLuint location,
|
||||
gl->fBindAttribLocation(progname, location, mappedName.get());
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::BindBuffer(WebGLenum target, WebGLBuffer *buf)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (!ValidateObjectAllowDeletedOrNull("bindBuffer", buf))
|
||||
return;
|
||||
|
||||
WebGLuint bufname = buf ? buf->GLName() : 0;
|
||||
|
||||
// silently ignore a deleted buffer
|
||||
if (buf && buf->IsDeleted())
|
||||
return;
|
||||
|
||||
if (target != LOCAL_GL_ARRAY_BUFFER &&
|
||||
target != LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
||||
{
|
||||
return ErrorInvalidEnumInfo("bindBuffer: target", target);
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
if ((buf->Target() != LOCAL_GL_NONE) && (target != buf->Target()))
|
||||
return ErrorInvalidOperation("bindBuffer: buffer already bound to a different target");
|
||||
buf->SetTarget(target);
|
||||
buf->SetHasEverBeenBound(true);
|
||||
}
|
||||
|
||||
// we really want to do this AFTER all the validation is done, otherwise our bookkeeping could get confused.
|
||||
// see bug 656752
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
mBoundArrayBuffer = buf;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
mBoundVertexArray->mBoundElementArrayBuffer = buf;
|
||||
}
|
||||
|
||||
MakeContextCurrent();
|
||||
|
||||
gl->fBindBuffer(target, bufname);
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::BindFramebuffer(WebGLenum target, WebGLFramebuffer *wfb)
|
||||
{
|
||||
@ -352,220 +311,6 @@ GLenum WebGLContext::CheckedBufferData(GLenum target,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::BufferData(WebGLenum target, WebGLsizeiptr size,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (size < 0)
|
||||
return ErrorInvalidValue("bufferData: negative size");
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
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
|
||||
WebGLContext::BufferData(WebGLenum target,
|
||||
const Nullable<ArrayBuffer> &maybeData,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (maybeData.IsNull()) {
|
||||
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
||||
return ErrorInvalidValue("bufferData: null object passed");
|
||||
}
|
||||
|
||||
const ArrayBuffer& data = maybeData.Value();
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
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
|
||||
WebGLContext::BufferData(WebGLenum target, const ArrayBufferView& data,
|
||||
WebGLenum usage)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferData: target", target);
|
||||
}
|
||||
|
||||
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
||||
return;
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
||||
|
||||
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)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (maybeData.IsNull()) {
|
||||
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
||||
return;
|
||||
}
|
||||
|
||||
const ArrayBuffer& data = maybeData.Value();
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
||||
}
|
||||
|
||||
if (byteOffset < 0)
|
||||
return ErrorInvalidValue("bufferSubData: negative offset");
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferData: no buffer bound!");
|
||||
|
||||
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
|
||||
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
|
||||
WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
||||
const ArrayBufferView& data)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
WebGLBuffer *boundBuffer = nullptr;
|
||||
|
||||
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundArrayBuffer;
|
||||
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
||||
boundBuffer = mBoundVertexArray->mBoundElementArrayBuffer;
|
||||
} else {
|
||||
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
||||
}
|
||||
|
||||
if (byteOffset < 0)
|
||||
return ErrorInvalidValue("bufferSubData: negative offset");
|
||||
|
||||
if (!boundBuffer)
|
||||
return ErrorInvalidOperation("bufferSubData: no buffer bound!");
|
||||
|
||||
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.Length();
|
||||
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());
|
||||
}
|
||||
|
||||
WebGLenum
|
||||
WebGLContext::CheckFramebufferStatus(WebGLenum target)
|
||||
{
|
||||
@ -944,34 +689,6 @@ WebGLContext::CullFace(WebGLenum face)
|
||||
gl->fCullFace(face);
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::DeleteBuffer(WebGLBuffer *buf)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return;
|
||||
|
||||
if (!ValidateObjectAllowDeletedOrNull("deleteBuffer", buf))
|
||||
return;
|
||||
|
||||
if (!buf || buf->IsDeleted())
|
||||
return;
|
||||
|
||||
if (mBoundArrayBuffer == buf)
|
||||
BindBuffer(LOCAL_GL_ARRAY_BUFFER,
|
||||
static_cast<WebGLBuffer*>(nullptr));
|
||||
|
||||
if (mBoundVertexArray->mBoundElementArrayBuffer == buf)
|
||||
BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER,
|
||||
static_cast<WebGLBuffer*>(nullptr));
|
||||
|
||||
for (int32_t i = 0; i < mGLMaxVertexAttribs; i++) {
|
||||
if (mBoundVertexArray->mAttribBuffers[i].buf == buf)
|
||||
mBoundVertexArray->mAttribBuffers[i].buf = nullptr;
|
||||
}
|
||||
|
||||
buf->RequestDelete();
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf)
|
||||
{
|
||||
@ -1731,15 +1448,6 @@ WebGLContext::GetRenderbufferParameter(WebGLenum target, WebGLenum pname)
|
||||
return JS::NullValue();
|
||||
}
|
||||
|
||||
already_AddRefed<WebGLBuffer>
|
||||
WebGLContext::CreateBuffer()
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return nullptr;
|
||||
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this);
|
||||
return globj.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<WebGLTexture>
|
||||
WebGLContext::CreateTexture()
|
||||
{
|
||||
@ -2205,17 +1913,6 @@ WebGLContext::Hint(WebGLenum target, WebGLenum mode)
|
||||
gl->fHint(target, mode);
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::IsBuffer(WebGLBuffer *buffer)
|
||||
{
|
||||
if (!IsContextStable())
|
||||
return false;
|
||||
|
||||
return ValidateObjectAllowDeleted("isBuffer", buffer) &&
|
||||
!buffer->IsDeleted() &&
|
||||
buffer->HasEverBeenBound();
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLContext::IsFramebuffer(WebGLFramebuffer *fb)
|
||||
{
|
||||
|
@ -223,19 +223,6 @@ bool WebGLContext::ValidateFaceEnum(WebGLenum face, const char *info)
|
||||
}
|
||||
}
|
||||
|
||||
bool WebGLContext::ValidateBufferUsageEnum(WebGLenum target, const char *info)
|
||||
{
|
||||
switch (target) {
|
||||
case LOCAL_GL_STREAM_DRAW:
|
||||
case LOCAL_GL_STATIC_DRAW:
|
||||
case LOCAL_GL_DYNAMIC_DRAW:
|
||||
return true;
|
||||
default:
|
||||
ErrorInvalidEnumInfo(info, target);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool WebGLContext::ValidateDrawModeEnum(WebGLenum mode, const char *info)
|
||||
{
|
||||
switch (mode) {
|
||||
|
@ -32,6 +32,7 @@ if CONFIG['MOZ_WEBGL']:
|
||||
'WebGL2Context.cpp',
|
||||
'WebGLContext.cpp',
|
||||
'WebGLContextAsyncQueries.cpp',
|
||||
'WebGLContextBuffers.cpp',
|
||||
'WebGLContextGL.cpp',
|
||||
'WebGLContextUtils.cpp',
|
||||
'WebGLContextReporter.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user