2012-03-16 02:50:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-09-17 23:01:12 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "WebGLContext.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
#include "WebGLContextUtils.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
|
|
|
#include "WebGLShader.h"
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
#include "WebGLUniformLocation.h"
|
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
#include "WebGLShaderPrecisionFormat.h"
|
|
|
|
#include "WebGLTexture.h"
|
2013-06-21 16:44:17 -07:00
|
|
|
#include "WebGLExtensions.h"
|
2013-06-27 14:07:21 -07:00
|
|
|
#include "WebGLVertexArray.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#include "nsString.h"
|
2011-07-07 17:01:16 -07:00
|
|
|
#include "nsDebug.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
|
|
|
#include "CanvasUtils.h"
|
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
#include "jsfriendapi.h"
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
#include "WebGLTexelConversions.h"
|
2011-09-07 14:17:44 -07:00
|
|
|
#include "WebGLValidateStrings.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2011-11-07 16:33:51 -08:00
|
|
|
// needed to check if current OS is lower than 10.7
|
|
|
|
#if defined(MOZ_WIDGET_COCOA)
|
|
|
|
#include "nsCocoaFeatures.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-08-22 22:17:11 -07:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
using namespace mozilla;
|
2012-03-11 00:54:24 -08:00
|
|
|
using namespace mozilla::dom;
|
2013-06-21 16:42:32 -07:00
|
|
|
using namespace mozilla::gl;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
static bool BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize);
|
|
|
|
static GLenum InternalFormatForFormatAndType(GLenum format, GLenum type, bool isGLES2);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-06-10 13:00:35 -07:00
|
|
|
inline const WebGLRectangleObject *WebGLContext::FramebufferRectangleObject() const {
|
|
|
|
return mBoundFramebuffer ? mBoundFramebuffer->RectangleObject()
|
|
|
|
: static_cast<const WebGLRectangleObject*>(this);
|
|
|
|
}
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLContext::FakeBlackTexture::FakeBlackTexture(GLContext *gl, GLenum target, GLenum format)
|
|
|
|
: mGL(gl)
|
|
|
|
, mGLName(0)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D || target == LOCAL_GL_TEXTURE_CUBE_MAP);
|
|
|
|
MOZ_ASSERT(format == LOCAL_GL_RGB || format == LOCAL_GL_RGBA);
|
|
|
|
|
|
|
|
mGL->MakeCurrent();
|
|
|
|
GLuint formerBinding = 0;
|
|
|
|
gl->GetUIntegerv(target == LOCAL_GL_TEXTURE_2D
|
|
|
|
? LOCAL_GL_TEXTURE_BINDING_2D
|
|
|
|
: LOCAL_GL_TEXTURE_BINDING_CUBE_MAP,
|
|
|
|
&formerBinding);
|
|
|
|
gl->fGenTextures(1, &mGLName);
|
|
|
|
gl->fBindTexture(target, mGLName);
|
|
|
|
|
|
|
|
// we allocate our zeros on the heap, and we overallocate (16 bytes instead of 4)
|
|
|
|
// to minimize the risk of running into a driver bug in texImage2D, as it is
|
|
|
|
// a bit unusual maybe to create 1x1 textures, and the stack may not have the alignment
|
|
|
|
// that texImage2D expects.
|
|
|
|
void* zeros = calloc(1, 16);
|
|
|
|
if (target == LOCAL_GL_TEXTURE_2D) {
|
|
|
|
gl->fTexImage2D(target, 0, format, 1, 1,
|
|
|
|
0, format, LOCAL_GL_UNSIGNED_BYTE, zeros);
|
|
|
|
} else {
|
|
|
|
for (GLuint i = 0; i < 6; ++i) {
|
|
|
|
gl->fTexImage2D(LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, 1, 1,
|
|
|
|
0, format, LOCAL_GL_UNSIGNED_BYTE, zeros);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(zeros);
|
|
|
|
|
|
|
|
gl->fBindTexture(target, formerBinding);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLContext::FakeBlackTexture::~FakeBlackTexture()
|
|
|
|
{
|
|
|
|
if (mGL) {
|
|
|
|
mGL->MakeCurrent();
|
|
|
|
mGL->fDeleteTextures(1, &mGLName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// WebGL API
|
|
|
|
//
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::ActiveTexture(GLenum texture)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-04-10 08:51:30 -07:00
|
|
|
if (texture < LOCAL_GL_TEXTURE0 ||
|
2012-05-23 09:07:01 -07:00
|
|
|
texture >= LOCAL_GL_TEXTURE0 + uint32_t(mGLMaxTextureUnits))
|
2012-04-10 08:51:30 -07:00
|
|
|
{
|
|
|
|
return ErrorInvalidEnum(
|
|
|
|
"ActiveTexture: texture unit %d out of range. "
|
|
|
|
"Accepted values range from TEXTURE0 to TEXTURE0 + %d. "
|
|
|
|
"Notice that TEXTURE0 != 0.",
|
|
|
|
texture, mGLMaxTextureUnits);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
mActiveTexture = texture - LOCAL_GL_TEXTURE0;
|
|
|
|
gl->fActiveTexture(texture);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::AttachShader(WebGLProgram *program, WebGLShader *shader)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-09-13 08:57:25 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("attachShader: program", program) ||
|
|
|
|
!ValidateObject("attachShader: shader", shader))
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-16 20:33:04 -08:00
|
|
|
// Per GLSL ES 2.0, we can only have one of each type of shader
|
|
|
|
// attached. This renders the next test somewhat moot, but we'll
|
|
|
|
// leave it for when we support more than one shader of each type.
|
|
|
|
if (program->HasAttachedShaderOfType(shader->ShaderType()))
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("attachShader: only one of each type of shader may be attached to a program");
|
2010-11-16 20:33:04 -08:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
if (!program->AttachShader(shader))
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("attachShader: shader is already attached");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindAttribLocation(WebGLProgram *prog, GLuint location,
|
2012-05-04 09:38:44 -07:00
|
|
|
const nsAString& name)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("bindAttribLocation: program", prog))
|
|
|
|
return;
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLVariableName(name, "bindAttribLocation"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(location, "bindAttribLocation"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-02-24 14:17:34 -08:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
NS_LossyConvertUTF16toASCII cname(name);
|
|
|
|
nsCString mappedName;
|
|
|
|
prog->MapIdentifier(cname, &mappedName);
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2012-03-02 12:42:49 -08:00
|
|
|
gl->fBindAttribLocation(progname, location, mappedName.get());
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer *wfb)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 05:07:30 -07:00
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidEnum("bindFramebuffer: target must be GL_FRAMEBUFFER");
|
2010-05-15 05:07:30 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindFramebuffer", wfb))
|
|
|
|
return;
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// silently ignore a deleted frame buffer
|
2012-05-04 09:38:44 -07:00
|
|
|
if (wfb && wfb->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!wfb) {
|
2013-02-13 15:26:24 -08:00
|
|
|
gl->fBindFramebuffer(target, 0);
|
2010-07-18 22:01:14 -07:00
|
|
|
} else {
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint framebuffername = wfb->GLName();
|
2010-07-18 22:01:14 -07:00
|
|
|
gl->fBindFramebuffer(target, framebuffername);
|
2011-10-17 07:59:28 -07:00
|
|
|
wfb->SetHasEverBeenBound(true);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 05:07:30 -07:00
|
|
|
mBoundFramebuffer = wfb;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BindRenderbuffer(GLenum target, WebGLRenderbuffer *wrb)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-05-15 05:07:30 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER)
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bindRenderbuffer: target", target);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindRenderbuffer", wrb))
|
|
|
|
return;
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
2012-05-04 09:38:44 -07:00
|
|
|
if (wrb && wrb->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (wrb)
|
2011-10-17 07:59:28 -07:00
|
|
|
wrb->SetHasEverBeenBound(true);
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2013-10-01 17:31:09 -07:00
|
|
|
// Sometimes we emulate renderbuffers (depth-stencil emu), so there's not
|
|
|
|
// always a 1-1 mapping from `wrb` to GL name. Just have `wrb` handle it.
|
|
|
|
if (wrb) {
|
|
|
|
wrb->BindRenderbuffer();
|
|
|
|
} else {
|
|
|
|
gl->fBindRenderbuffer(target, 0);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 05:07:30 -07:00
|
|
|
mBoundRenderbuffer = wrb;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLContext::BindTexture(GLenum target, WebGLTexture *newTex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindTexture", newTex))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// silently ignore a deleted texture
|
2013-10-11 06:16:43 -07:00
|
|
|
if (newTex && newTex->IsDeleted())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLRefPtr<WebGLTexture>* currentTexPtr = nullptr;
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
if (target == LOCAL_GL_TEXTURE_2D) {
|
2013-10-11 06:16:43 -07:00
|
|
|
currentTexPtr = &mBound2DTextures[mActiveTexture];
|
2009-09-02 17:47:49 -07:00
|
|
|
} else if (target == LOCAL_GL_TEXTURE_CUBE_MAP) {
|
2013-10-11 06:16:43 -07:00
|
|
|
currentTexPtr = &mBoundCubeMapTextures[mActiveTexture];
|
2009-09-02 17:47:49 -07:00
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bindTexture: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLTextureFakeBlackStatus currentTexFakeBlackStatus = WebGLTextureFakeBlackStatus::NotNeeded;
|
|
|
|
if (*currentTexPtr) {
|
|
|
|
currentTexFakeBlackStatus = (*currentTexPtr)->ResolvedFakeBlackStatus();
|
|
|
|
}
|
|
|
|
WebGLTextureFakeBlackStatus newTexFakeBlackStatus = WebGLTextureFakeBlackStatus::NotNeeded;
|
|
|
|
if (newTex) {
|
|
|
|
newTexFakeBlackStatus = newTex->ResolvedFakeBlackStatus();
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
|
|
|
*currentTexPtr = newTex;
|
|
|
|
|
|
|
|
if (currentTexFakeBlackStatus != newTexFakeBlackStatus) {
|
|
|
|
SetFakeBlackStatus(WebGLContextFakeBlackStatus::Unknown);
|
|
|
|
}
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (newTex)
|
|
|
|
newTex->Bind(target);
|
2010-08-23 14:03:53 -07:00
|
|
|
else
|
|
|
|
gl->fBindTexture(target, 0 /* == texturename */);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void WebGLContext::BlendEquation(GLenum mode)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateBlendEquationEnum(mode, "blendEquation: mode"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendEquation(mode);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void WebGLContext::BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateBlendEquationEnum(modeRGB, "blendEquationSeparate: modeRGB") ||
|
|
|
|
!ValidateBlendEquationEnum(modeAlpha, "blendEquationSeparate: modeAlpha"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-19 07:48:44 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendEquationSeparate(modeRGB, modeAlpha);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
void WebGLContext::BlendFunc(GLenum sfactor, GLenum dfactor)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateBlendFuncSrcEnum(sfactor, "blendFunc: sfactor") ||
|
|
|
|
!ValidateBlendFuncDstEnum(dfactor, "blendFunc: dfactor"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
if (!ValidateBlendFuncEnumsCompatibility(sfactor, dfactor, "blendFuncSeparate: srcRGB and dstRGB"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-06-19 07:48:44 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendFunc(sfactor, dfactor);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
|
|
|
|
GLenum srcAlpha, GLenum dstAlpha)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateBlendFuncSrcEnum(srcRGB, "blendFuncSeparate: srcRGB") ||
|
|
|
|
!ValidateBlendFuncSrcEnum(srcAlpha, "blendFuncSeparate: srcAlpha") ||
|
|
|
|
!ValidateBlendFuncDstEnum(dstRGB, "blendFuncSeparate: dstRGB") ||
|
|
|
|
!ValidateBlendFuncDstEnum(dstAlpha, "blendFuncSeparate: dstAlpha"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
// note that we only check compatibity for the RGB enums, no need to for the Alpha enums, see
|
|
|
|
// "Section 6.8 forgetting to mention alpha factors?" thread on the public_webgl mailing list
|
|
|
|
if (!ValidateBlendFuncEnumsCompatibility(srcRGB, dstRGB, "blendFuncSeparate: srcRGB and dstRGB"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-06-19 07:48:44 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum
|
|
|
|
WebGLContext::CheckFramebufferStatus(GLenum target)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2012-05-04 09:38:44 -07:00
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER) {
|
|
|
|
ErrorInvalidEnum("checkFramebufferStatus: target must be FRAMEBUFFER");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
if (!mBoundFramebuffer)
|
2012-05-04 09:38:44 -07:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
|
|
|
if(mBoundFramebuffer->HasDepthStencilConflict())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
2013-06-21 16:44:17 -07:00
|
|
|
|
|
|
|
bool hasImages = false;
|
|
|
|
hasImages |= mBoundFramebuffer->DepthAttachment().IsDefined();
|
|
|
|
hasImages |= mBoundFramebuffer->StencilAttachment().IsDefined();
|
|
|
|
hasImages |= mBoundFramebuffer->DepthStencilAttachment().IsDefined();
|
|
|
|
|
|
|
|
if (!hasImages) {
|
|
|
|
int32_t colorAttachmentCount = mBoundFramebuffer->mColorAttachments.Length();
|
|
|
|
|
|
|
|
for(int32_t i = 0; i < colorAttachmentCount; i++) {
|
|
|
|
if (mBoundFramebuffer->ColorAttachment(i).IsDefined()) {
|
|
|
|
hasImages = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf section 4.4.5 (page 118)
|
|
|
|
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
|
|
|
|
No images are attached to the framebuffer.
|
|
|
|
*/
|
|
|
|
if (!hasImages) {
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if(mBoundFramebuffer->HasIncompleteAttachment())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
|
|
if(mBoundFramebuffer->HasAttachmentsOfMismatchedDimensions())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
|
2013-10-01 17:30:05 -07:00
|
|
|
|
|
|
|
// Ok, attach our chosen flavor of {DEPTH, STENCIL, DEPTH_STENCIL}.
|
|
|
|
mBoundFramebuffer->FinalizeAttachments();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return gl->fCheckFramebufferStatus(target);
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CopyTexSubImage2D_base(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLenum internalformat,
|
|
|
|
GLint xoffset,
|
|
|
|
GLint yoffset,
|
|
|
|
GLint x,
|
|
|
|
GLint y,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
2011-01-06 14:07:13 -08:00
|
|
|
bool sub)
|
|
|
|
{
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject();
|
2013-09-04 05:14:43 -07:00
|
|
|
GLsizei framebufferWidth = framebufferRect ? framebufferRect->Width() : 0;
|
|
|
|
GLsizei framebufferHeight = framebufferRect ? framebufferRect->Height() : 0;
|
2011-01-06 14:07:13 -08:00
|
|
|
|
|
|
|
const char *info = sub ? "copyTexSubImage2D" : "copyTexImage2D";
|
|
|
|
|
2012-11-09 13:48:54 -08:00
|
|
|
if (!ValidateLevelWidthHeightForTarget(target, level, width, height, info)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-09-28 04:41:45 -07:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("%s: no texture is bound to this target");
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
if (CanvasUtils::CheckSaneSubrectSize(x, y, width, height, framebufferWidth, framebufferHeight)) {
|
|
|
|
if (sub)
|
2011-07-07 17:01:17 -07:00
|
|
|
gl->fCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
2011-01-06 14:07:13 -08:00
|
|
|
else
|
2011-07-07 17:01:17 -07:00
|
|
|
gl->fCopyTexImage2D(target, level, internalformat, x, y, width, height, 0);
|
2011-01-06 14:07:13 -08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// the rect doesn't fit in the framebuffer
|
|
|
|
|
|
|
|
/*** first, we initialize the texture as black ***/
|
|
|
|
|
|
|
|
// first, compute the size of the buffer we should allocate to initialize the texture as black
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t texelSize = 0;
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ValidateTexFormatAndType(internalformat, LOCAL_GL_UNSIGNED_BYTE, -1, &texelSize, info))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-01-06 14:07:13 -08:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_neededByteLength =
|
|
|
|
GetImageSize(height, width, texelSize, mPixelStoreUnpackAlignment);
|
2011-01-06 14:07:13 -08:00
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
2011-01-06 14:07:13 -08:00
|
|
|
return ErrorInvalidOperation("%s: integer overflow computing the needed buffer size", info);
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t bytesNeeded = checked_neededByteLength.value();
|
2011-01-06 14:07:13 -08:00
|
|
|
|
|
|
|
// now that the size is known, create the buffer
|
|
|
|
|
|
|
|
// We need some zero pages, because GL doesn't guarantee the
|
2013-04-02 18:14:24 -07:00
|
|
|
// contents of a texture allocated with nullptr data.
|
2011-01-06 14:07:13 -08:00
|
|
|
// Hopefully calloc will just mmap zero pages here.
|
|
|
|
void *tempZeroData = calloc(1, bytesNeeded);
|
|
|
|
if (!tempZeroData)
|
2011-02-24 14:17:34 -08:00
|
|
|
return ErrorOutOfMemory("%s: could not allocate %d bytes (for zero fill)", info, bytesNeeded);
|
2011-01-06 14:07:13 -08:00
|
|
|
|
|
|
|
// now initialize the texture as black
|
|
|
|
|
|
|
|
if (sub)
|
2011-07-07 17:01:17 -07:00
|
|
|
gl->fTexSubImage2D(target, level, 0, 0, width, height,
|
|
|
|
internalformat, LOCAL_GL_UNSIGNED_BYTE, tempZeroData);
|
2011-01-06 14:07:13 -08:00
|
|
|
else
|
2011-07-07 17:01:17 -07:00
|
|
|
gl->fTexImage2D(target, level, internalformat, width, height,
|
|
|
|
0, internalformat, LOCAL_GL_UNSIGNED_BYTE, tempZeroData);
|
2011-01-06 14:07:13 -08:00
|
|
|
free(tempZeroData);
|
|
|
|
|
|
|
|
// if we are completely outside of the framebuffer, we can exit now with our black texture
|
|
|
|
if ( x >= framebufferWidth
|
|
|
|
|| x+width <= 0
|
|
|
|
|| y >= framebufferHeight
|
|
|
|
|| y+height <= 0)
|
|
|
|
{
|
|
|
|
// we are completely outside of range, can exit now with buffer filled with zeros
|
2012-01-24 13:12:31 -08:00
|
|
|
return DummyFramebufferOperation(info);
|
2011-01-06 14:07:13 -08:00
|
|
|
}
|
|
|
|
|
2011-10-28 11:33:28 -07:00
|
|
|
GLint actual_x = clamped(x, 0, framebufferWidth);
|
|
|
|
GLint actual_x_plus_width = clamped(x + width, 0, framebufferWidth);
|
2011-01-06 14:07:13 -08:00
|
|
|
GLsizei actual_width = actual_x_plus_width - actual_x;
|
|
|
|
GLint actual_xoffset = xoffset + actual_x - x;
|
|
|
|
|
2011-10-28 11:33:28 -07:00
|
|
|
GLint actual_y = clamped(y, 0, framebufferHeight);
|
|
|
|
GLint actual_y_plus_height = clamped(y + height, 0, framebufferHeight);
|
2011-01-06 14:07:13 -08:00
|
|
|
GLsizei actual_height = actual_y_plus_height - actual_y;
|
|
|
|
GLint actual_yoffset = yoffset + actual_y - y;
|
|
|
|
|
|
|
|
gl->fCopyTexSubImage2D(target, level, actual_xoffset, actual_yoffset, actual_x, actual_y, actual_width, actual_height);
|
|
|
|
}
|
2012-12-11 13:57:30 -08:00
|
|
|
|
|
|
|
if (!sub)
|
|
|
|
ReattachTextureToAnyFramebufferToWorkAroundBugs(tex, level);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2011-01-06 14:07:13 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CopyTexImage2D(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLenum internalformat,
|
|
|
|
GLint x,
|
|
|
|
GLint y,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLint border)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("copyTexImage2D: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (internalformat) {
|
|
|
|
case LOCAL_GL_RGB:
|
2010-12-06 03:34:35 -08:00
|
|
|
case LOCAL_GL_LUMINANCE:
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidEnumInfo("copyTexImage2D: internal format", internalformat);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
if (border != 0)
|
|
|
|
return ErrorInvalidValue("copyTexImage2D: border must be 0");
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
if (width < 0 || height < 0)
|
|
|
|
return ErrorInvalidValue("copyTexImage2D: width and height may not be negative");
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
if (level < 0)
|
|
|
|
return ErrorInvalidValue("copyTexImage2D: level may not be negative");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!(maxTextureSize >> level))
|
|
|
|
return ErrorInvalidValue("copyTexImage2D: 2^level exceeds maximum texture size");
|
|
|
|
|
2010-09-02 07:28:38 -07:00
|
|
|
if (level >= 1) {
|
|
|
|
if (!(is_pot_assuming_nonnegative(width) &&
|
|
|
|
is_pot_assuming_nonnegative(height)))
|
|
|
|
return ErrorInvalidValue("copyTexImage2D: with level > 0, width and height must be powers of two");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool texFormatRequiresAlpha = internalformat == LOCAL_GL_RGBA ||
|
2010-12-06 03:34:35 -08:00
|
|
|
internalformat == LOCAL_GL_ALPHA ||
|
|
|
|
internalformat == LOCAL_GL_LUMINANCE_ALPHA;
|
2013-06-21 16:44:17 -07:00
|
|
|
bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment(0).HasAlpha()
|
|
|
|
: bool(gl->GetPixelFormat().alpha > 0);
|
2010-12-06 03:34:35 -08:00
|
|
|
if (texFormatRequiresAlpha && !fboFormatHasAlpha)
|
|
|
|
return ErrorInvalidOperation("copyTexImage2D: texture format requires an alpha channel "
|
|
|
|
"but the framebuffer doesn't have one");
|
|
|
|
|
2012-08-13 18:17:55 -07:00
|
|
|
if (internalformat == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
internalformat == LOCAL_GL_DEPTH_STENCIL)
|
|
|
|
return ErrorInvalidOperation("copyTexImage2D: a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL isn't supported");
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
if (mBoundFramebuffer)
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeAttachments())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("copyTexImage2D: incomplete framebuffer");
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
if (!tex)
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidOperation("copyTexImage2D: no texture bound to this target");
|
|
|
|
|
2011-07-07 17:01:17 -07:00
|
|
|
// copyTexImage2D only generates textures with type = UNSIGNED_BYTE
|
|
|
|
GLenum type = LOCAL_GL_UNSIGNED_BYTE;
|
|
|
|
|
2011-09-21 23:57:26 -07:00
|
|
|
// check if the memory size of this texture may change with this call
|
|
|
|
bool sizeMayChange = true;
|
2013-10-01 17:30:38 -07:00
|
|
|
if (tex->HasImageInfoAt(target, level)) {
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(target, level);
|
2011-09-21 23:57:26 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
sizeMayChange = width != imageInfo.Width() ||
|
|
|
|
height != imageInfo.Height() ||
|
|
|
|
internalformat != imageInfo.Format() ||
|
|
|
|
type != imageInfo.Type();
|
2011-09-21 23:57:26 -07:00
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2011-07-07 17:01:17 -07:00
|
|
|
if (sizeMayChange) {
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
|
|
|
CopyTexSubImage2D_base(target, level, internalformat, 0, 0, x, y, width, height, false);
|
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
if (error) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("copyTexImage2D generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
2011-07-07 17:01:17 -07:00
|
|
|
} else {
|
|
|
|
CopyTexSubImage2D_base(target, level, internalformat, 0, 0, x, y, width, height, false);
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
|
|
|
|
tex->SetImageInfo(target, level, width, height, internalformat, type,
|
|
|
|
WebGLImageDataStatus::InitializedImageData);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CopyTexSubImage2D(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLint xoffset,
|
|
|
|
GLint yoffset,
|
|
|
|
GLint x,
|
|
|
|
GLint y,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidEnumInfo("copyTexSubImage2D: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
if (level < 0)
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: level may not be negative");
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!(maxTextureSize >> level))
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: 2^level exceeds maximum texture size");
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
if (width < 0 || height < 0)
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: width and height may not be negative");
|
|
|
|
|
|
|
|
if (xoffset < 0 || yoffset < 0)
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: xoffset and yoffset may not be negative");
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("copyTexSubImage2D: no texture bound to this target");
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
if (!tex->HasImageInfoAt(target, level))
|
2011-09-21 23:57:26 -07:00
|
|
|
return ErrorInvalidOperation("copyTexSubImage2D: no texture image previously defined for this level and face");
|
2011-02-24 14:17:34 -08:00
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(target, level);
|
2013-09-04 05:14:43 -07:00
|
|
|
GLsizei texWidth = imageInfo.Width();
|
|
|
|
GLsizei texHeight = imageInfo.Height();
|
2011-01-06 14:07:13 -08:00
|
|
|
|
|
|
|
if (xoffset + width > texWidth || xoffset + width < 0)
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: xoffset+width is too large");
|
|
|
|
|
|
|
|
if (yoffset + height > texHeight || yoffset + height < 0)
|
|
|
|
return ErrorInvalidValue("copyTexSubImage2D: yoffset+height is too large");
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum format = imageInfo.Format();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool texFormatRequiresAlpha = format == LOCAL_GL_RGBA ||
|
2012-01-24 13:12:31 -08:00
|
|
|
format == LOCAL_GL_ALPHA ||
|
|
|
|
format == LOCAL_GL_LUMINANCE_ALPHA;
|
2013-06-21 16:44:17 -07:00
|
|
|
bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment(0).HasAlpha()
|
|
|
|
: bool(gl->GetPixelFormat().alpha > 0);
|
2010-12-06 03:34:35 -08:00
|
|
|
|
|
|
|
if (texFormatRequiresAlpha && !fboFormatHasAlpha)
|
|
|
|
return ErrorInvalidOperation("copyTexSubImage2D: texture format requires an alpha channel "
|
|
|
|
"but the framebuffer doesn't have one");
|
|
|
|
|
2012-08-13 18:17:55 -07:00
|
|
|
if (format == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
format == LOCAL_GL_DEPTH_STENCIL)
|
|
|
|
return ErrorInvalidOperation("copyTexSubImage2D: a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL isn't supported");
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
if (mBoundFramebuffer)
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeAttachments())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("copyTexSubImage2D: incomplete framebuffer");
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (imageInfo.HasUninitializedImageData()) {
|
|
|
|
tex->DoDeferredImageInitialization(target, level);
|
|
|
|
}
|
|
|
|
|
2011-01-06 14:07:13 -08:00
|
|
|
return CopyTexSubImage2D_base(target, level, format, xoffset, yoffset, x, y, width, height, true);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLProgram>
|
|
|
|
WebGLContext::CreateProgram()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLProgram> globj = new WebGLProgram(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLShader>
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CreateShader(GLenum type)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
if (type != LOCAL_GL_VERTEX_SHADER &&
|
|
|
|
type != LOCAL_GL_FRAGMENT_SHADER)
|
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("createShader: type", type);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-04 12:03:33 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLShader> shader = new WebGLShader(this, type);
|
|
|
|
return shader.forget();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CullFace(GLenum face)
|
2010-07-03 15:33:05 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-07-03 15:33:05 -07:00
|
|
|
if (!ValidateFaceEnum(face, "cullFace"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-03 15:33:05 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fCullFace(face);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteFramebuffer", fbuf))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!fbuf || fbuf->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
fbuf->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
if (mBoundFramebuffer == fbuf)
|
2012-05-04 09:38:44 -07:00
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER,
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<WebGLFramebuffer*>(nullptr));
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer *rbuf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteRenderbuffer", rbuf))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!rbuf || rbuf->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
if (mBoundFramebuffer)
|
|
|
|
mBoundFramebuffer->DetachRenderbuffer(rbuf);
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
if (mBoundRenderbuffer == rbuf)
|
2012-05-04 09:38:44 -07:00
|
|
|
BindRenderbuffer(LOCAL_GL_RENDERBUFFER,
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<WebGLRenderbuffer*>(nullptr));
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
rbuf->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteTexture(WebGLTexture *tex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteTexture", tex))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!tex || tex->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
if (mBoundFramebuffer)
|
|
|
|
mBoundFramebuffer->DetachTexture(tex);
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint activeTexture = mActiveTexture;
|
2012-05-23 09:07:01 -07:00
|
|
|
for (int32_t i = 0; i < mGLMaxTextureUnits; i++) {
|
2011-12-04 11:15:42 -08:00
|
|
|
if ((tex->Target() == LOCAL_GL_TEXTURE_2D && mBound2DTextures[i] == tex) ||
|
|
|
|
(tex->Target() == LOCAL_GL_TEXTURE_CUBE_MAP && mBoundCubeMapTextures[i] == tex))
|
|
|
|
{
|
|
|
|
ActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
2012-07-30 07:20:58 -07:00
|
|
|
BindTexture(tex->Target(), static_cast<WebGLTexture*>(nullptr));
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 19:23:03 -08:00
|
|
|
ActiveTexture(LOCAL_GL_TEXTURE0 + activeTexture);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
tex->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteProgram", prog))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!prog || prog->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
prog->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("deleteShader", shader))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!shader || shader->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
shader->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DetachShader(WebGLProgram *program, WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("detachShader: program", program) ||
|
|
|
|
// it's valid to attempt to detach a deleted shader, since it's
|
|
|
|
// still a shader
|
|
|
|
!ValidateObjectAllowDeleted("detashShader: shader", shader))
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
if (!program->DetachShader(shader))
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("detachShader: shader is not attached");
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::DepthFunc(GLenum func)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateComparisonEnum(func, "depthFunc"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fDepthFunc(func);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::DepthRange(GLfloat zNear, GLfloat zFar)
|
2010-12-06 03:34:35 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
if (zNear > zFar)
|
|
|
|
return ErrorInvalidOperation("depthRange: the near value is greater than the far value!");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fDepthRange(zNear, zFar);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
int
|
|
|
|
WebGLContext::WhatDoesVertexAttrib0Need()
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2011-02-24 14:17:34 -08:00
|
|
|
// here we may assume that mCurrentProgram != null
|
|
|
|
|
|
|
|
// work around Mac OSX crash, see bug 631420
|
|
|
|
#ifdef XP_MACOSX
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
2013-06-27 14:07:21 -07:00
|
|
|
mBoundVertexArray->mAttribBuffers[0].enabled &&
|
2011-02-24 14:17:34 -08:00
|
|
|
!mCurrentProgram->IsAttribInUse(0))
|
2012-04-10 08:49:10 -07:00
|
|
|
{
|
2011-02-24 14:17:34 -08:00
|
|
|
return VertexAttrib0Status::EmulatedUninitializedArray;
|
2012-04-10 08:49:10 -07:00
|
|
|
}
|
2011-02-24 14:17:34 -08:00
|
|
|
#endif
|
|
|
|
|
2013-06-27 14:07:21 -07:00
|
|
|
return (gl->IsGLES2() || mBoundVertexArray->mAttribBuffers[0].enabled) ? VertexAttrib0Status::Default
|
2011-02-24 14:17:34 -08:00
|
|
|
: mCurrentProgram->IsAttribInUse(0) ? VertexAttrib0Status::EmulatedInitializedArray
|
|
|
|
: VertexAttrib0Status::EmulatedUninitializedArray;
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-21 23:55:10 -07:00
|
|
|
bool
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::DoFakeVertexAttrib0(GLuint vertexCount)
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2011-02-24 14:17:34 -08:00
|
|
|
int whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
|
|
|
|
|
|
|
|
if (whatDoesAttrib0Need == VertexAttrib0Status::Default)
|
2011-09-21 23:55:10 -07:00
|
|
|
return true;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-07-25 09:13:45 -07:00
|
|
|
if (!mAlreadyWarnedAboutFakeVertexAttrib0) {
|
|
|
|
GenerateWarning("Drawing without vertex attrib 0 array enabled forces the browser "
|
|
|
|
"to do expensive emulation work when running on desktop OpenGL "
|
|
|
|
"platforms, for example on Mac. It is preferable to always draw "
|
|
|
|
"with vertex attrib 0 array enabled, by using bindAttribLocation "
|
|
|
|
"to bind some always-used attribute to location 0.");
|
|
|
|
mAlreadyWarnedAboutFakeVertexAttrib0 = true;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
CheckedUint32 checked_dataSize = CheckedUint32(vertexCount) * 4 * sizeof(GLfloat);
|
2012-07-25 09:13:45 -07:00
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!checked_dataSize.isValid()) {
|
2011-09-21 23:55:10 -07:00
|
|
|
ErrorOutOfMemory("Integer overflow trying to construct a fake vertex attrib 0 array for a draw-operation "
|
|
|
|
"with %d vertices. Try reducing the number of vertices.", vertexCount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint dataSize = checked_dataSize.value();
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!mFakeVertexAttrib0BufferObject) {
|
|
|
|
gl->fGenBuffers(1, &mFakeVertexAttrib0BufferObject);
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
// if the VBO status is already exactly what we need, or if the only difference is that it's initialized and
|
|
|
|
// we don't need it to be, then consider it OK
|
2011-09-28 23:19:26 -07:00
|
|
|
bool vertexAttrib0BufferStatusOK =
|
2011-02-24 14:17:34 -08:00
|
|
|
mFakeVertexAttrib0BufferStatus == whatDoesAttrib0Need ||
|
|
|
|
(mFakeVertexAttrib0BufferStatus == VertexAttrib0Status::EmulatedInitializedArray &&
|
|
|
|
whatDoesAttrib0Need == VertexAttrib0Status::EmulatedUninitializedArray);
|
|
|
|
|
|
|
|
if (!vertexAttrib0BufferStatusOK ||
|
|
|
|
mFakeVertexAttrib0BufferObjectSize < dataSize ||
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[0] != mVertexAttrib0Vector[0] ||
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[1] != mVertexAttrib0Vector[1] ||
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[2] != mVertexAttrib0Vector[2] ||
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[3] != mVertexAttrib0Vector[3])
|
|
|
|
{
|
|
|
|
mFakeVertexAttrib0BufferStatus = whatDoesAttrib0Need;
|
|
|
|
mFakeVertexAttrib0BufferObjectSize = dataSize;
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[0] = mVertexAttrib0Vector[0];
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[1] = mVertexAttrib0Vector[1];
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[2] = mVertexAttrib0Vector[2];
|
|
|
|
mFakeVertexAttrib0BufferObjectVector[3] = mVertexAttrib0Vector[3];
|
|
|
|
|
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mFakeVertexAttrib0BufferObject);
|
|
|
|
|
2011-09-21 23:55:10 -07:00
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
2011-02-24 14:17:34 -08:00
|
|
|
|
|
|
|
if (mFakeVertexAttrib0BufferStatus == VertexAttrib0Status::EmulatedInitializedArray) {
|
2013-09-04 05:14:43 -07:00
|
|
|
nsAutoArrayPtr<GLfloat> array(new GLfloat[4 * vertexCount]);
|
2011-02-24 14:17:34 -08:00
|
|
|
for(size_t i = 0; i < vertexCount; ++i) {
|
|
|
|
array[4 * i + 0] = mVertexAttrib0Vector[0];
|
|
|
|
array[4 * i + 1] = mVertexAttrib0Vector[1];
|
|
|
|
array[4 * i + 2] = mVertexAttrib0Vector[2];
|
|
|
|
array[4 * i + 3] = mVertexAttrib0Vector[3];
|
|
|
|
}
|
|
|
|
gl->fBufferData(LOCAL_GL_ARRAY_BUFFER, dataSize, array, LOCAL_GL_DYNAMIC_DRAW);
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
gl->fBufferData(LOCAL_GL_ARRAY_BUFFER, dataSize, nullptr, LOCAL_GL_DYNAMIC_DRAW);
|
2011-02-24 14:17:34 -08:00
|
|
|
}
|
2011-09-21 23:55:10 -07:00
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundArrayBuffer ? mBoundArrayBuffer->GLName() : 0);
|
2011-09-21 23:55:10 -07:00
|
|
|
|
|
|
|
// note that we do this error checking and early return AFTER having restored the buffer binding above
|
|
|
|
if (error) {
|
|
|
|
ErrorOutOfMemory("Ran out of memory trying to construct a fake vertex attrib 0 array for a draw-operation "
|
|
|
|
"with %d vertices. Try reducing the number of vertices.", vertexCount);
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-24 14:17:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mFakeVertexAttrib0BufferObject);
|
|
|
|
gl->fVertexAttribPointer(0, 4, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0);
|
2011-09-21 23:55:10 -07:00
|
|
|
|
|
|
|
return true;
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UndoFakeVertexAttrib0()
|
|
|
|
{
|
2011-02-24 14:17:34 -08:00
|
|
|
int whatDoesAttrib0Need = WhatDoesVertexAttrib0Need();
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (whatDoesAttrib0Need == VertexAttrib0Status::Default)
|
|
|
|
return;
|
2010-09-05 14:27:04 -07:00
|
|
|
|
2013-06-27 14:07:21 -07:00
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundVertexArray->mAttribBuffers[0].buf ? mBoundVertexArray->mAttribBuffers[0].buf->GLName() : 0);
|
2010-09-02 07:34:08 -07:00
|
|
|
gl->fVertexAttribPointer(0,
|
2013-06-27 14:07:21 -07:00
|
|
|
mBoundVertexArray->mAttribBuffers[0].size,
|
|
|
|
mBoundVertexArray->mAttribBuffers[0].type,
|
|
|
|
mBoundVertexArray->mAttribBuffers[0].normalized,
|
|
|
|
mBoundVertexArray->mAttribBuffers[0].stride,
|
|
|
|
reinterpret_cast<const GLvoid *>(mBoundVertexArray->mAttribBuffers[0].byteOffset));
|
2010-09-05 14:27:04 -07:00
|
|
|
|
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundArrayBuffer ? mBoundArrayBuffer->GLName() : 0);
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLContextFakeBlackStatus
|
|
|
|
WebGLContext::ResolvedFakeBlackStatus()
|
2010-08-23 14:03:53 -07:00
|
|
|
{
|
|
|
|
// handle this case first, it's the generic case
|
2013-10-11 06:16:43 -07:00
|
|
|
if (MOZ_LIKELY(mFakeBlackStatus == WebGLContextFakeBlackStatus::NotNeeded))
|
|
|
|
return mFakeBlackStatus;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (mFakeBlackStatus == WebGLContextFakeBlackStatus::Needed)
|
|
|
|
return mFakeBlackStatus;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-06-10 13:00:46 -07:00
|
|
|
for (int32_t i = 0; i < mGLMaxTextureUnits; ++i) {
|
2013-10-11 06:16:43 -07:00
|
|
|
if ((mBound2DTextures[i] && mBound2DTextures[i]->ResolvedFakeBlackStatus() != WebGLTextureFakeBlackStatus::NotNeeded) ||
|
|
|
|
(mBoundCubeMapTextures[i] && mBoundCubeMapTextures[i]->ResolvedFakeBlackStatus() != WebGLTextureFakeBlackStatus::NotNeeded))
|
2013-06-10 13:00:46 -07:00
|
|
|
{
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLContextFakeBlackStatus::Needed;
|
|
|
|
return mFakeBlackStatus;
|
2013-06-10 13:00:46 -07:00
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2013-06-10 13:00:46 -07:00
|
|
|
// we have exhausted all cases where we do need fakeblack, so if the status is still unknown,
|
|
|
|
// that means that we do NOT need it.
|
2013-10-11 06:16:43 -07:00
|
|
|
mFakeBlackStatus = WebGLContextFakeBlackStatus::NotNeeded;
|
|
|
|
return mFakeBlackStatus;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLContext::BindFakeBlackTexturesHelper(
|
|
|
|
GLenum target,
|
|
|
|
const nsTArray<WebGLRefPtr<WebGLTexture> > & boundTexturesArray,
|
|
|
|
ScopedDeletePtr<FakeBlackTexture> & opaqueTextureScopedPtr,
|
|
|
|
ScopedDeletePtr<FakeBlackTexture> & transparentTextureScopedPtr)
|
2010-08-23 14:03:53 -07:00
|
|
|
{
|
2013-10-11 06:16:43 -07:00
|
|
|
for (int32_t i = 0; i < mGLMaxTextureUnits; ++i) {
|
|
|
|
if (!boundTexturesArray[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLTextureFakeBlackStatus s = boundTexturesArray[i]->ResolvedFakeBlackStatus();
|
|
|
|
MOZ_ASSERT(s != WebGLTextureFakeBlackStatus::Unknown);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (MOZ_LIKELY(s == WebGLTextureFakeBlackStatus::NotNeeded)) {
|
|
|
|
continue;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
bool alpha = s == WebGLTextureFakeBlackStatus::UninitializedImageData &&
|
|
|
|
FormatHasAlpha(boundTexturesArray[i]->ImageInfoBase().Format());
|
2013-10-11 06:16:43 -07:00
|
|
|
ScopedDeletePtr<FakeBlackTexture>&
|
2013-10-11 06:16:43 -07:00
|
|
|
blackTexturePtr = alpha
|
|
|
|
? transparentTextureScopedPtr
|
|
|
|
: opaqueTextureScopedPtr;
|
2013-10-11 06:16:43 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!blackTexturePtr) {
|
2013-10-11 06:16:43 -07:00
|
|
|
GLenum format = alpha ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
|
2013-10-11 06:16:43 -07:00
|
|
|
blackTexturePtr
|
|
|
|
= new FakeBlackTexture(gl, target, format);
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(target,
|
|
|
|
blackTexturePtr->GLName());
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
}
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BindFakeBlackTextures()
|
|
|
|
{
|
|
|
|
// this is the generic case: try to return early
|
|
|
|
if (MOZ_LIKELY(ResolvedFakeBlackStatus() == WebGLContextFakeBlackStatus::NotNeeded))
|
|
|
|
return;
|
|
|
|
|
|
|
|
BindFakeBlackTexturesHelper(LOCAL_GL_TEXTURE_2D,
|
|
|
|
mBound2DTextures,
|
|
|
|
mBlackOpaqueTexture2D,
|
|
|
|
mBlackTransparentTexture2D);
|
|
|
|
BindFakeBlackTexturesHelper(LOCAL_GL_TEXTURE_CUBE_MAP,
|
|
|
|
mBoundCubeMapTextures,
|
|
|
|
mBlackOpaqueTextureCubeMap,
|
|
|
|
mBlackTransparentTextureCubeMap);
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UnbindFakeBlackTextures()
|
|
|
|
{
|
|
|
|
// this is the generic case: try to return early
|
2013-10-11 06:16:43 -07:00
|
|
|
if (MOZ_LIKELY(ResolvedFakeBlackStatus() == WebGLContextFakeBlackStatus::NotNeeded))
|
2010-08-23 14:03:53 -07:00
|
|
|
return;
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
for (int32_t i = 0; i < mGLMaxTextureUnits; ++i) {
|
2013-10-11 06:16:43 -07:00
|
|
|
if (mBound2DTextures[i] && mBound2DTextures[i]->ResolvedFakeBlackStatus() != WebGLTextureFakeBlackStatus::NotNeeded) {
|
2010-08-23 14:03:53 -07:00
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mBound2DTextures[i]->GLName());
|
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
if (mBoundCubeMapTextures[i] && mBoundCubeMapTextures[i]->ResolvedFakeBlackStatus() != WebGLTextureFakeBlackStatus::NotNeeded) {
|
2010-08-23 14:03:53 -07:00
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBoundCubeMapTextures[i]->GLName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum rbtarget, WebGLRenderbuffer *wrb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
if (!mBoundFramebuffer)
|
2010-11-05 12:57:58 -07:00
|
|
|
return ErrorInvalidOperation("framebufferRenderbuffer: cannot modify framebuffer 0");
|
2011-01-05 13:08:53 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return mBoundFramebuffer->FramebufferRenderbuffer(target, attachment, rbtarget, wrb);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::FramebufferTexture2D(GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum textarget,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLTexture *tobj,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint level)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
if (!mBoundFramebuffer)
|
|
|
|
return ErrorInvalidOperation("framebufferRenderbuffer: cannot modify framebuffer 0");
|
|
|
|
|
|
|
|
return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::FrontFace(GLenum mode)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
switch (mode) {
|
|
|
|
case LOCAL_GL_CW:
|
|
|
|
case LOCAL_GL_CCW:
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("frontFace: mode", mode);
|
2010-06-30 08:48:30 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFrontFace(mode);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
2012-05-23 09:07:01 -07:00
|
|
|
WebGLContext::GetActiveAttrib(WebGLProgram *prog, uint32_t index)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getActiveAttrib: program", prog))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLint len = 0;
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();;
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &len);
|
2010-08-25 05:17:08 -07:00
|
|
|
if (len == 0)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
nsAutoArrayPtr<char> name(new char[len]);
|
2011-06-27 10:27:04 -07:00
|
|
|
GLint attrsize = 0;
|
|
|
|
GLuint attrtype = 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
gl->fGetActiveAttrib(progname, index, len, &len, &attrsize, &attrtype, name);
|
2010-06-08 15:14:43 -07:00
|
|
|
if (attrsize == 0 || attrtype == 0) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-08 15:14:43 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
nsCString reverseMappedName;
|
|
|
|
prog->ReverseMapIdentifier(nsDependentCString(name), &reverseMappedName);
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLActiveInfo> retActiveInfo =
|
|
|
|
new WebGLActiveInfo(attrsize, attrtype, reverseMappedName);
|
|
|
|
return retActiveInfo.forget();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GenerateMipmap(GLenum target)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateTextureTargetEnum(target, "generateMipmap"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
2010-08-23 14:03:35 -07:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
if (!tex)
|
2012-04-03 16:42:06 -07:00
|
|
|
return ErrorInvalidOperation("generateMipmap: No texture is bound to this target.");
|
2013-10-01 17:30:38 -07:00
|
|
|
|
|
|
|
GLenum imageTarget = (target == LOCAL_GL_TEXTURE_2D) ? LOCAL_GL_TEXTURE_2D
|
|
|
|
: LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
|
|
|
if (!tex->HasImageInfoAt(imageTarget, 0))
|
|
|
|
{
|
2012-04-03 16:42:06 -07:00
|
|
|
return ErrorInvalidOperation("generateMipmap: Level zero of texture is not defined.");
|
2013-10-01 17:30:38 -07:00
|
|
|
}
|
|
|
|
|
2012-04-03 16:42:06 -07:00
|
|
|
if (!tex->IsFirstImagePowerOfTwo())
|
|
|
|
return ErrorInvalidOperation("generateMipmap: Level zero of texture does not have power-of-two width and height.");
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
GLenum format = tex->ImageInfoAt(imageTarget, 0).Format();
|
2012-04-03 16:42:06 -07:00
|
|
|
if (IsTextureFormatCompressed(format))
|
|
|
|
return ErrorInvalidOperation("generateMipmap: Texture data at level zero is compressed.");
|
|
|
|
|
2012-10-03 14:13:05 -07:00
|
|
|
if (IsExtensionEnabled(WEBGL_depth_texture) &&
|
2012-08-13 18:17:55 -07:00
|
|
|
(format == LOCAL_GL_DEPTH_COMPONENT || format == LOCAL_GL_DEPTH_STENCIL))
|
|
|
|
return ErrorInvalidOperation("generateMipmap: "
|
|
|
|
"A texture that has a base internal format of "
|
|
|
|
"DEPTH_COMPONENT or DEPTH_STENCIL isn't supported");
|
|
|
|
|
2012-04-03 16:42:06 -07:00
|
|
|
if (!tex->AreAllLevel0ImageInfosEqual())
|
|
|
|
return ErrorInvalidOperation("generateMipmap: The six faces of this cube map have different dimensions, format, or type.");
|
2010-08-23 14:03:35 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
tex->SetGeneratedMipmap();
|
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
MakeContextCurrent();
|
2012-04-19 20:28:01 -07:00
|
|
|
|
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
|
|
// bug 696495 - to work around failures in the texture-mips.html test on various drivers, we
|
|
|
|
// set the minification filter before calling glGenerateMipmap. This should not carry a significant performance
|
|
|
|
// overhead so we do it unconditionally.
|
|
|
|
//
|
|
|
|
// note that the choice of GL_NEAREST_MIPMAP_NEAREST really matters. See Chromium bug 101105.
|
|
|
|
gl->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST_MIPMAP_NEAREST);
|
|
|
|
gl->fGenerateMipmap(target);
|
|
|
|
gl->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, tex->MinFilter());
|
|
|
|
} else {
|
|
|
|
gl->fGenerateMipmap(target);
|
|
|
|
}
|
2010-06-30 08:48:30 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
2012-05-23 09:07:01 -07:00
|
|
|
WebGLContext::GetActiveUniform(WebGLProgram *prog, uint32_t index)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getActiveUniform: program", prog))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLint len = 0;
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, &len);
|
2010-08-25 05:17:08 -07:00
|
|
|
if (len == 0)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
nsAutoArrayPtr<char> name(new char[len]);
|
2010-07-16 07:31:53 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
GLint usize = 0;
|
|
|
|
GLuint utype = 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
gl->fGetActiveUniform(progname, index, len, &len, &usize, &utype, name);
|
|
|
|
if (len == 0 || usize == 0 || utype == 0) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-10 10:45:00 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
nsCString reverseMappedName;
|
|
|
|
prog->ReverseMapIdentifier(nsDependentCString(name), &reverseMappedName);
|
|
|
|
|
2010-07-16 07:31:53 -07:00
|
|
|
// OpenGL ES 2.0 specifies that if foo is a uniform array, GetActiveUniform returns its name as "foo[0]".
|
|
|
|
// See section 2.10 page 35 in the OpenGL ES 2.0.24 specification:
|
|
|
|
//
|
|
|
|
// > If the active uniform is an array, the uniform name returned in name will always
|
|
|
|
// > be the name of the uniform array appended with "[0]".
|
|
|
|
//
|
|
|
|
// There is no such requirement in the OpenGL (non-ES) spec and indeed we have OpenGL implementations returning
|
|
|
|
// "foo" instead of "foo[0]". So, when implementing WebGL on top of desktop OpenGL, we must check if the
|
|
|
|
// returned name ends in [0], and if it doesn't, append that.
|
|
|
|
//
|
|
|
|
// In principle we don't need to do that on OpenGL ES, but this is such a tricky difference between the ES and non-ES
|
|
|
|
// specs that it seems probable that some ES implementers will overlook it. Since the work-around is quite cheap,
|
|
|
|
// we do it unconditionally.
|
2012-03-02 12:42:49 -08:00
|
|
|
if (usize > 1 && reverseMappedName.CharAt(reverseMappedName.Length()-1) != ']')
|
|
|
|
reverseMappedName.AppendLiteral("[0]");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLActiveInfo> retActiveInfo =
|
|
|
|
new WebGLActiveInfo(usize, utype, reverseMappedName);
|
|
|
|
return retActiveInfo.forget();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::GetAttachedShaders(WebGLProgram *prog,
|
|
|
|
Nullable< nsTArray<WebGLShader*> > &retval)
|
|
|
|
{
|
|
|
|
retval.SetNull();
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ValidateObjectAllowNull("getAttachedShaders", prog))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (!prog) {
|
|
|
|
retval.SetNull();
|
|
|
|
ErrorInvalidValue("getAttachedShaders: invalid program");
|
|
|
|
} else if (prog->AttachedShaders().Length() == 0) {
|
|
|
|
retval.SetValue().TruncateLength(0);
|
|
|
|
} else {
|
|
|
|
retval.SetValue().AppendElements(prog->AttachedShaders());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetAttribLocation(WebGLProgram *prog, const nsAString& name)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return -1;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getAttribLocation: program", prog))
|
|
|
|
return -1;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLVariableName(name, "getAttribLocation"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return -1;
|
2011-07-28 14:12:31 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
NS_LossyConvertUTF16toASCII cname(name);
|
|
|
|
nsCString mappedName;
|
|
|
|
prog->MapIdentifier(cname, &mappedName);
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2012-05-04 09:38:44 -07:00
|
|
|
return gl->fGetAttribLocation(progname, mappedName.get());
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetBufferParameter(GLenum target, GLenum pname)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (target != LOCAL_GL_ARRAY_BUFFER && target != LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
ErrorInvalidEnumInfo("getBufferParameter: target", target);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2009-11-18 12:42:35 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_BUFFER_SIZE:
|
|
|
|
case LOCAL_GL_BUFFER_USAGE:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetBufferParameteriv(target, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (pname == LOCAL_GL_BUFFER_SIZE) {
|
|
|
|
return JS::Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(pname == LOCAL_GL_BUFFER_USAGE);
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(i));
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getBufferParameter: parameter", pname);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-19 07:42:43 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER) {
|
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: target", target);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2009-11-18 12:42:35 -08:00
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
if (attachment != LOCAL_GL_DEPTH_ATTACHMENT &&
|
|
|
|
attachment != LOCAL_GL_STENCIL_ATTACHMENT &&
|
|
|
|
attachment != LOCAL_GL_DEPTH_STENCIL_ATTACHMENT)
|
|
|
|
{
|
|
|
|
if (IsExtensionEnabled(WEBGL_draw_buffers))
|
|
|
|
{
|
|
|
|
if (attachment < LOCAL_GL_COLOR_ATTACHMENT0 ||
|
2013-09-04 05:14:43 -07:00
|
|
|
attachment >= GLenum(LOCAL_GL_COLOR_ATTACHMENT0 + mGLMaxColorAttachments))
|
2013-06-21 16:44:17 -07:00
|
|
|
{
|
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: attachment", attachment);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
mBoundFramebuffer->EnsureColorAttachments(attachment - LOCAL_GL_COLOR_ATTACHMENT0);
|
|
|
|
}
|
|
|
|
else if (attachment != LOCAL_GL_COLOR_ATTACHMENT0)
|
|
|
|
{
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: attachment", attachment);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2013-06-21 16:44:17 -07:00
|
|
|
}
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!mBoundFramebuffer) {
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidOperation("getFramebufferAttachmentParameter: cannot query framebuffer 0");
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-12-09 03:58:41 -08:00
|
|
|
const WebGLFramebuffer::Attachment& fba = mBoundFramebuffer->GetAttachment(attachment);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
if (fba.Renderbuffer()) {
|
2010-07-18 22:01:14 -07:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(LOCAL_GL_RENDERBUFFER));
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-10-04 13:35:54 -07:00
|
|
|
return WebGLObjectAsJSValue(cx, fba.Renderbuffer(), rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: pname", pname);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
2011-01-05 13:08:53 -08:00
|
|
|
} else if (fba.Texture()) {
|
2010-07-18 22:01:14 -07:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(LOCAL_GL_TEXTURE));
|
2009-11-18 12:42:35 -08:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-10-04 13:35:54 -07:00
|
|
|
return WebGLObjectAsJSValue(cx, fba.Texture(), rv);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
|
2013-10-01 17:30:38 -07:00
|
|
|
return JS::Int32Value(fba.TexImageLevel());
|
2011-01-05 13:08:53 -08:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
|
2013-10-01 17:30:38 -07:00
|
|
|
{
|
|
|
|
GLenum face = fba.TexImageTarget();
|
|
|
|
if (face == LOCAL_GL_TEXTURE_2D)
|
|
|
|
face = 0;
|
|
|
|
return JS::Int32Value(face);
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: pname", pname);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2011-01-05 13:08:53 -08:00
|
|
|
} else {
|
2010-09-02 07:38:26 -07:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(LOCAL_GL_NONE));
|
2010-09-02 07:38:26 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: pname", pname);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2010-09-02 07:38:26 -07:00
|
|
|
}
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetRenderbufferParameter(GLenum target, GLenum pname)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER) {
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getRenderbufferParameter: target", target);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-07-26 16:58:53 -07:00
|
|
|
if (!mBoundRenderbuffer) {
|
|
|
|
ErrorInvalidOperation("getRenderbufferParameter: no render buffer is bound");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:42:35 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_RENDERBUFFER_WIDTH:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_HEIGHT:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_RED_SIZE:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_GREEN_SIZE:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_BLUE_SIZE:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_ALPHA_SIZE:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_DEPTH_SIZE:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_STENCIL_SIZE:
|
|
|
|
{
|
2013-10-01 17:31:09 -07:00
|
|
|
// RB emulation means we have to ask the RB itself.
|
|
|
|
GLint i = mBoundRenderbuffer->GetRenderbufferParameter(target, pname);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(i);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
case LOCAL_GL_RENDERBUFFER_INTERNAL_FORMAT:
|
|
|
|
{
|
2012-07-26 16:58:53 -07:00
|
|
|
return JS::NumberValue(mBoundRenderbuffer->InternalFormat());
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
2009-11-18 12:42:35 -08:00
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getRenderbufferParameter: parameter", pname);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLTexture>
|
|
|
|
WebGLContext::CreateTexture()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLTexture> globj = new WebGLTexture(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetError()
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (mContextStatus == ContextNotLost) {
|
2011-10-26 13:00:44 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
2012-01-04 13:12:03 -08:00
|
|
|
} else if (!mContextLostErrorSet) {
|
|
|
|
mWebGLError = LOCAL_GL_CONTEXT_LOST;
|
|
|
|
mContextLostErrorSet = true;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum err = mWebGLError;
|
2011-07-07 17:01:16 -07:00
|
|
|
mWebGLError = LOCAL_GL_NO_ERROR;
|
2012-05-04 09:38:44 -07:00
|
|
|
return err;
|
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetProgramParameter(WebGLProgram *prog, GLenum pname)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeleted("getProgramParameter: program", prog))
|
|
|
|
return JS::NullValue();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2009-11-18 12:42:35 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_ATTACHED_SHADERS:
|
|
|
|
case LOCAL_GL_ACTIVE_UNIFORMS:
|
|
|
|
case LOCAL_GL_ACTIVE_ATTRIBUTES:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetProgramiv(progname, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(i);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_DELETE_STATUS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(prog->IsDeleteRequested());
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_LINK_STATUS:
|
2011-11-03 07:50:40 -07:00
|
|
|
{
|
2012-07-26 16:58:52 -07:00
|
|
|
return JS::BooleanValue(prog->LinkStatus());
|
2011-11-03 07:50:40 -07:00
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_VALIDATE_STATUS:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
2011-01-25 14:23:55 -08:00
|
|
|
#ifdef XP_MACOSX
|
2011-09-01 12:28:34 -07:00
|
|
|
// See comment in ValidateProgram below.
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs())
|
|
|
|
i = 1;
|
|
|
|
else
|
|
|
|
gl->fGetProgramiv(progname, pname, &i);
|
2011-01-25 14:23:55 -08:00
|
|
|
#else
|
2010-06-19 07:42:43 -07:00
|
|
|
gl->fGetProgramiv(progname, pname, &i);
|
2011-01-25 14:23:55 -08:00
|
|
|
#endif
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(bool(i));
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
break;
|
2009-11-18 12:42:35 -08:00
|
|
|
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getProgramParameter: parameter", pname);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsAString& retval)
|
2012-05-29 11:44:31 -07:00
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString s;
|
2012-09-17 01:37:20 -07:00
|
|
|
GetProgramInfoLog(prog, s);
|
2012-05-29 11:44:31 -07:00
|
|
|
if (s.IsVoid())
|
|
|
|
retval.SetIsVoid(true);
|
|
|
|
else
|
|
|
|
CopyASCIItoUTF16(s, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsACString& retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
{
|
|
|
|
retval.SetIsVoid(true);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getProgramInfoLog: program", prog)) {
|
|
|
|
retval.Truncate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
GLint k = -1;
|
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_INFO_LOG_LENGTH, &k);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (k == -1) {
|
2012-05-30 16:05:37 -07:00
|
|
|
// If GetProgramiv doesn't modify |k|,
|
|
|
|
// it's because there was a GL error.
|
|
|
|
// GetProgramInfoLog should return null on error. (Bug 746740)
|
|
|
|
retval.SetIsVoid(true);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
if (k == 0) {
|
|
|
|
retval.Truncate();
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
retval.SetCapacity(k);
|
|
|
|
gl->fGetProgramInfoLog(progname, k, &k, (char*) retval.BeginWriting());
|
|
|
|
retval.SetLength(k);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
// here we have to support all pnames with both int and float params.
|
|
|
|
// See this discussion:
|
|
|
|
// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html
|
2013-09-04 05:14:43 -07:00
|
|
|
void WebGLContext::TexParameter_base(GLenum target, GLenum pname,
|
|
|
|
GLint *intParamPtr,
|
|
|
|
GLfloat *floatParamPtr)
|
2009-09-17 23:01:07 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
MOZ_ASSERT(intParamPtr || floatParamPtr);
|
|
|
|
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint intParam = intParamPtr ? *intParamPtr : GLint(*floatParamPtr);
|
|
|
|
GLfloat floatParam = floatParamPtr ? *floatParamPtr : GLfloat(*intParamPtr);
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
if (!ValidateTextureTargetEnum(target, "texParameter: target"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("texParameter: no texture is bound to this target");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool pnameAndParamAreIncompatible = false;
|
2012-02-23 05:43:57 -08:00
|
|
|
bool paramValueInvalid = false;
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_FILTER:
|
|
|
|
switch (intParam) {
|
|
|
|
case LOCAL_GL_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR:
|
|
|
|
case LOCAL_GL_NEAREST_MIPMAP_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR_MIPMAP_NEAREST:
|
|
|
|
case LOCAL_GL_NEAREST_MIPMAP_LINEAR:
|
|
|
|
case LOCAL_GL_LINEAR_MIPMAP_LINEAR:
|
2010-08-23 14:03:53 -07:00
|
|
|
tex->SetMinFilter(intParam);
|
2010-08-23 14:03:44 -07:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
pnameAndParamAreIncompatible = true;
|
2010-08-23 14:03:44 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_TEXTURE_MAG_FILTER:
|
|
|
|
switch (intParam) {
|
|
|
|
case LOCAL_GL_NEAREST:
|
|
|
|
case LOCAL_GL_LINEAR:
|
2010-08-23 14:03:53 -07:00
|
|
|
tex->SetMagFilter(intParam);
|
2010-08-23 14:03:44 -07:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
pnameAndParamAreIncompatible = true;
|
2010-08-23 14:03:44 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_S:
|
2010-08-23 14:03:53 -07:00
|
|
|
switch (intParam) {
|
|
|
|
case LOCAL_GL_CLAMP_TO_EDGE:
|
|
|
|
case LOCAL_GL_MIRRORED_REPEAT:
|
|
|
|
case LOCAL_GL_REPEAT:
|
|
|
|
tex->SetWrapS(intParam);
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
pnameAndParamAreIncompatible = true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-08-23 14:03:44 -07:00
|
|
|
case LOCAL_GL_TEXTURE_WRAP_T:
|
|
|
|
switch (intParam) {
|
|
|
|
case LOCAL_GL_CLAMP_TO_EDGE:
|
|
|
|
case LOCAL_GL_MIRRORED_REPEAT:
|
|
|
|
case LOCAL_GL_REPEAT:
|
2010-08-23 14:03:53 -07:00
|
|
|
tex->SetWrapT(intParam);
|
2010-08-23 14:03:44 -07:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
pnameAndParamAreIncompatible = true;
|
2010-08-23 14:03:44 -07:00
|
|
|
}
|
|
|
|
break;
|
2012-02-23 05:43:57 -08:00
|
|
|
case LOCAL_GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
2012-06-15 22:12:30 -07:00
|
|
|
if (IsExtensionEnabled(EXT_texture_filter_anisotropic)) {
|
2012-02-23 05:43:57 -08:00
|
|
|
if (floatParamPtr && floatParam < 1.f)
|
|
|
|
paramValueInvalid = true;
|
|
|
|
else if (intParamPtr && intParam < 1)
|
|
|
|
paramValueInvalid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pnameAndParamAreIncompatible = true;
|
|
|
|
break;
|
2010-08-23 14:03:44 -07:00
|
|
|
default:
|
|
|
|
return ErrorInvalidEnumInfo("texParameter: pname", pname);
|
|
|
|
}
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
if (pnameAndParamAreIncompatible) {
|
|
|
|
if (intParamPtr)
|
|
|
|
return ErrorInvalidEnum("texParameteri: pname %x and param %x (decimal %d) are mutually incompatible",
|
|
|
|
pname, intParam, intParam);
|
|
|
|
else
|
2012-02-23 05:43:57 -08:00
|
|
|
return ErrorInvalidEnum("texParameterf: pname %x and param %g are mutually incompatible",
|
|
|
|
pname, floatParam);
|
|
|
|
} else if (paramValueInvalid) {
|
|
|
|
if (intParamPtr)
|
|
|
|
return ErrorInvalidValue("texParameteri: pname %x and param %x (decimal %d) is invalid",
|
|
|
|
pname, intParam, intParam);
|
|
|
|
else
|
|
|
|
return ErrorInvalidValue("texParameterf: pname %x and param %g is invalid",
|
2010-08-23 14:03:44 -07:00
|
|
|
pname, floatParam);
|
|
|
|
}
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
if (intParamPtr)
|
2011-09-29 07:13:49 -07:00
|
|
|
gl->fTexParameteri(target, pname, intParam);
|
2010-08-23 14:03:44 -07:00
|
|
|
else
|
2011-09-29 07:13:49 -07:00
|
|
|
gl->fTexParameterf(target, pname, floatParam);
|
2009-09-17 23:01:07 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetTexParameter(GLenum target, GLenum pname)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateTextureTargetEnum(target, "getTexParameter: target"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2010-09-13 08:57:25 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!activeBoundTextureForTarget(target)) {
|
|
|
|
ErrorInvalidOperation("getTexParameter: no texture bound");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-09-13 08:57:25 -07:00
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_FILTER:
|
|
|
|
case LOCAL_GL_TEXTURE_MAG_FILTER:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_S:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_T:
|
2011-09-29 07:13:49 -07:00
|
|
|
{
|
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetTexParameteriv(target, pname, &i);
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(i));
|
2011-09-29 07:13:49 -07:00
|
|
|
}
|
2012-02-23 05:43:57 -08:00
|
|
|
case LOCAL_GL_TEXTURE_MAX_ANISOTROPY_EXT:
|
2012-06-15 22:12:30 -07:00
|
|
|
if (IsExtensionEnabled(EXT_texture_filter_anisotropic)) {
|
2012-02-23 05:43:57 -08:00
|
|
|
GLfloat f = 0.f;
|
|
|
|
gl->fGetTexParameterfv(target, pname, &f);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(f);
|
2012-02-23 05:43:57 -08:00
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
ErrorInvalidEnumInfo("getTexParameter: parameter", pname);
|
2012-02-23 05:43:57 -08:00
|
|
|
break;
|
2009-09-17 23:01:07 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getTexParameter: parameter", pname);
|
2009-09-17 23:01:07 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-09-17 23:01:07 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLUniformLocation *location, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getUniform: program", prog))
|
|
|
|
return JS::NullValue();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getUniform: location", location))
|
|
|
|
return JS::NullValue();
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (location->Program() != prog) {
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidValue("getUniform: this uniform location corresponds to another program");
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (location->ProgramGeneration() != prog->Generation()) {
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidOperation("getUniform: this uniform location is obsolete since the program has been relinked");
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-08 14:25:27 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
GLint uniforms = 0;
|
2010-06-10 10:45:00 -07:00
|
|
|
GLint uniformNameMaxLength = 0;
|
2010-06-01 23:09:19 -07:00
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_ACTIVE_UNIFORMS, &uniforms);
|
2010-06-10 10:45:00 -07:00
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, &uniformNameMaxLength);
|
2010-06-01 23:09:19 -07:00
|
|
|
|
|
|
|
// we now need the type info to switch between fGetUniformfv and fGetUniformiv
|
|
|
|
// the only way to get that is to iterate through all active uniforms by index until
|
|
|
|
// one matches the given uniform location.
|
|
|
|
GLenum uniformType = 0;
|
2010-06-10 10:45:00 -07:00
|
|
|
nsAutoArrayPtr<GLchar> uniformName(new GLchar[uniformNameMaxLength]);
|
2010-07-16 07:31:53 -07:00
|
|
|
// this buffer has 16 more bytes to be able to store [index] at the end.
|
|
|
|
nsAutoArrayPtr<GLchar> uniformNameBracketIndex(new GLchar[uniformNameMaxLength + 16]);
|
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
GLint index;
|
|
|
|
for (index = 0; index < uniforms; ++index) {
|
2010-07-16 07:31:53 -07:00
|
|
|
GLsizei length;
|
|
|
|
GLint size;
|
|
|
|
gl->fGetActiveUniform(progname, index, uniformNameMaxLength, &length,
|
|
|
|
&size, &uniformType, uniformName);
|
2010-06-01 23:09:19 -07:00
|
|
|
if (gl->fGetUniformLocation(progname, uniformName) == location->Location())
|
|
|
|
break;
|
2010-07-16 07:31:53 -07:00
|
|
|
|
|
|
|
// now we handle the case of array uniforms. In that case, fGetActiveUniform returned as 'size'
|
|
|
|
// the biggest index used plus one, so we need to loop over that. The 0 index has already been handled above,
|
|
|
|
// so we can start at one. For each index, we construct the string uniformName + "[" + index + "]".
|
|
|
|
if (size > 1) {
|
|
|
|
bool found_it = false;
|
|
|
|
if (uniformName[length - 1] == ']') { // if uniformName ends in [0]
|
|
|
|
// remove the [0] at the end
|
|
|
|
length -= 3;
|
|
|
|
uniformName[length] = 0;
|
|
|
|
}
|
|
|
|
for (GLint arrayIndex = 1; arrayIndex < size; arrayIndex++) {
|
|
|
|
sprintf(uniformNameBracketIndex.get(), "%s[%d]", uniformName.get(), arrayIndex);
|
|
|
|
if (gl->fGetUniformLocation(progname, uniformNameBracketIndex) == location->Location()) {
|
|
|
|
found_it = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found_it) break;
|
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (index == uniforms) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_FAILURE); // XXX GL error? shouldn't happen.
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
GLenum baseType;
|
|
|
|
GLint unitSize;
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!BaseTypeAndSizeFromUniformType(uniformType, &baseType, &unitSize)) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
// this should never happen
|
2012-05-04 09:38:44 -07:00
|
|
|
if (unitSize > 16) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
if (baseType == LOCAL_GL_FLOAT) {
|
2010-08-25 05:17:08 -07:00
|
|
|
GLfloat fv[16] = { GLfloat(0) };
|
2010-06-01 23:09:19 -07:00
|
|
|
gl->fGetUniformfv(progname, location->Location(), fv);
|
2010-06-19 07:43:40 -07:00
|
|
|
if (unitSize == 1) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(fv[0]);
|
2010-06-19 07:43:40 -07:00
|
|
|
} else {
|
2012-06-25 09:37:46 -07:00
|
|
|
JSObject* obj = Float32Array::Create(cx, this, unitSize, fv);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!obj) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2010-06-19 07:43:40 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
} else if (baseType == LOCAL_GL_INT) {
|
2010-08-25 05:17:08 -07:00
|
|
|
GLint iv[16] = { 0 };
|
2010-06-01 23:09:19 -07:00
|
|
|
gl->fGetUniformiv(progname, location->Location(), iv);
|
2010-06-19 07:43:40 -07:00
|
|
|
if (unitSize == 1) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(iv[0]);
|
2010-06-19 07:43:40 -07:00
|
|
|
} else {
|
2012-06-25 09:37:46 -07:00
|
|
|
JSObject* obj = Int32Array::Create(cx, this, unitSize, iv);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!obj) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2010-06-19 07:43:40 -07:00
|
|
|
}
|
|
|
|
} else if (baseType == LOCAL_GL_BOOL) {
|
2010-08-25 05:17:08 -07:00
|
|
|
GLint iv[16] = { 0 };
|
2010-06-19 07:43:40 -07:00
|
|
|
gl->fGetUniformiv(progname, location->Location(), iv);
|
|
|
|
if (unitSize == 1) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(iv[0] ? true : false);
|
2010-06-19 07:43:40 -07:00
|
|
|
} else {
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value uv[16];
|
2010-06-19 07:43:40 -07:00
|
|
|
for (int k = 0; k < unitSize; k++)
|
2012-05-04 09:38:44 -07:00
|
|
|
uv[k] = JS::BooleanValue(iv[k] ? true : false);
|
|
|
|
JSObject* obj = JS_NewArrayObject(cx, unitSize, uv);
|
|
|
|
if (!obj) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2010-06-19 07:43:40 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// Else preserving behavior, but I'm not sure this is correct per spec
|
|
|
|
return JS::UndefinedValue();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
|
|
|
WebGLContext::GetUniformLocation(WebGLProgram *prog, const nsAString& name)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getUniformLocation: program", prog))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLVariableName(name, "getUniformLocation"))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-07-28 14:12:31 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
NS_LossyConvertUTF16toASCII cname(name);
|
|
|
|
nsCString mappedName;
|
|
|
|
prog->MapIdentifier(cname, &mappedName);
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2012-03-02 12:42:49 -08:00
|
|
|
MakeContextCurrent();
|
|
|
|
GLint intlocation = gl->fGetUniformLocation(progname, mappedName.get());
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<WebGLUniformLocation> loc;
|
2012-04-16 12:56:12 -07:00
|
|
|
if (intlocation >= 0) {
|
|
|
|
WebGLUniformInfo info = prog->GetUniformInfoForMappedIdentifier(mappedName);
|
|
|
|
loc = new WebGLUniformLocation(this,
|
|
|
|
prog,
|
|
|
|
intlocation,
|
|
|
|
info);
|
|
|
|
}
|
2013-04-22 04:15:59 -07:00
|
|
|
return loc.forget();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Hint(GLenum target, GLenum mode)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-09-30 21:45:50 -07:00
|
|
|
bool isValid = false;
|
|
|
|
|
|
|
|
switch (target) {
|
2012-04-04 18:57:35 -07:00
|
|
|
case LOCAL_GL_GENERATE_MIPMAP_HINT:
|
|
|
|
isValid = true;
|
|
|
|
break;
|
2011-09-30 21:45:50 -07:00
|
|
|
case LOCAL_GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
|
2012-06-15 22:12:30 -07:00
|
|
|
if (IsExtensionEnabled(OES_standard_derivatives))
|
2011-09-30 21:45:50 -07:00
|
|
|
isValid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-04 18:57:35 -07:00
|
|
|
if (!isValid)
|
|
|
|
return ErrorInvalidEnum("hint: invalid hint");
|
2011-09-30 21:45:50 -07:00
|
|
|
|
2012-04-04 18:57:35 -07:00
|
|
|
gl->fHint(target, mode);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsFramebuffer(WebGLFramebuffer *fb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return ValidateObjectAllowDeleted("isFramebuffer", fb) &&
|
|
|
|
!fb->IsDeleted() &&
|
|
|
|
fb->HasEverBeenBound();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return ValidateObjectAllowDeleted("isProgram", prog) && !prog->IsDeleted();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsRenderbuffer(WebGLRenderbuffer *rb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return ValidateObjectAllowDeleted("isRenderBuffer", rb) &&
|
|
|
|
!rb->IsDeleted() &&
|
|
|
|
rb->HasEverBeenBound();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return ValidateObjectAllowDeleted("isShader", shader) &&
|
|
|
|
!shader->IsDeleted();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsTexture(WebGLTexture *tex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return ValidateObjectAllowDeleted("isTexture", tex) &&
|
|
|
|
!tex->IsDeleted() &&
|
|
|
|
tex->HasEverBeenBound();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2013-08-27 06:01:44 -07:00
|
|
|
// Try to bind an attribute that is an array to location 0:
|
|
|
|
bool WebGLContext::BindArrayAttribToLocation0(WebGLProgram *program)
|
|
|
|
{
|
|
|
|
if (mBoundVertexArray->mAttribBuffers[0].enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint leastArrayLocation = -1;
|
|
|
|
|
|
|
|
std::map<GLint, nsCString>::iterator itr;
|
|
|
|
for (itr = program->mActiveAttribMap.begin();
|
|
|
|
itr != program->mActiveAttribMap.end();
|
|
|
|
itr++) {
|
|
|
|
int32_t index = itr->first;
|
|
|
|
if (mBoundVertexArray->mAttribBuffers[index].enabled &&
|
|
|
|
index < leastArrayLocation)
|
|
|
|
{
|
|
|
|
leastArrayLocation = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leastArrayLocation > 0) {
|
|
|
|
nsCString& attrName = program->mActiveAttribMap.find(leastArrayLocation)->second;
|
|
|
|
const char* attrNameCStr = attrName.get();
|
|
|
|
gl->fBindAttribLocation(program->GLName(), 0, attrNameCStr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
WebGLContext::LinkProgram(WebGLProgram *program)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("linkProgram", program))
|
|
|
|
return;
|
2012-08-23 11:56:17 -07:00
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
InvalidateBufferFetching(); // we do it early in this function
|
2012-09-21 10:44:35 -07:00
|
|
|
// as some of the validation below changes program state
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
GLuint progname = program->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!program->NextGeneration()) {
|
2012-09-17 01:37:20 -07:00
|
|
|
// XXX throw?
|
|
|
|
return;
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-06-15 08:49:34 -07:00
|
|
|
|
|
|
|
if (!program->HasBothShaderTypesAttached()) {
|
2012-05-29 11:44:31 -07:00
|
|
|
GenerateWarning("linkProgram: this program doesn't have both a vertex shader"
|
|
|
|
" and a fragment shader");
|
2011-10-17 07:59:28 -07:00
|
|
|
program->SetLinkStatus(false);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-15 08:49:34 -07:00
|
|
|
}
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2012-08-09 19:30:17 -07:00
|
|
|
// bug 777028
|
|
|
|
// Mesa can't handle more than 16 samplers per program, counting each array entry.
|
2012-08-23 11:56:17 -07:00
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
mIsMesa &&
|
|
|
|
program->UpperBoundNumSamplerUniforms() > 16)
|
|
|
|
{
|
|
|
|
GenerateWarning("Programs with more than 16 samplers are disallowed on Mesa drivers " "to avoid a Mesa crasher.");
|
|
|
|
program->SetLinkStatus(false);
|
|
|
|
return;
|
2012-08-09 19:30:17 -07:00
|
|
|
}
|
|
|
|
|
2013-08-27 06:01:44 -07:00
|
|
|
bool updateInfoSucceeded = false;
|
|
|
|
GLint ok = 0;
|
2012-07-26 16:58:52 -07:00
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
program->HasBadShaderAttached())
|
|
|
|
{
|
|
|
|
// it's a common driver bug, caught by program-test.html, that linkProgram doesn't
|
|
|
|
// correctly preserve the state of an in-use program that has been attached a bad shader
|
|
|
|
// see bug 777883
|
|
|
|
ok = false;
|
|
|
|
} else {
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fLinkProgram(progname);
|
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_LINK_STATUS, &ok);
|
2013-08-27 06:01:44 -07:00
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
updateInfoSucceeded = program->UpdateInfo();
|
|
|
|
program->SetLinkStatus(updateInfoSucceeded);
|
|
|
|
|
|
|
|
if (BindArrayAttribToLocation0(program)) {
|
|
|
|
GenerateWarning("linkProgram: relinking program to make attrib0 an "
|
|
|
|
"array.");
|
|
|
|
gl->fLinkProgram(progname);
|
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_LINK_STATUS, &ok);
|
|
|
|
if (ok) {
|
|
|
|
updateInfoSucceeded = program->UpdateInfo();
|
|
|
|
program->SetLinkStatus(updateInfoSucceeded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 16:58:52 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
if (ok) {
|
2012-05-30 17:00:38 -07:00
|
|
|
// Bug 750527
|
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
updateInfoSucceeded &&
|
|
|
|
gl->Vendor() == gl::GLContext::VendorNVIDIA)
|
|
|
|
{
|
|
|
|
if (program == mCurrentProgram)
|
|
|
|
gl->fUseProgram(progname);
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
program->SetLinkStatus(false);
|
2012-05-29 11:44:31 -07:00
|
|
|
|
|
|
|
if (ShouldGenerateWarnings()) {
|
|
|
|
|
|
|
|
// report shader/program infoLogs as warnings.
|
|
|
|
// note that shader compilation errors can be deferred to linkProgram,
|
|
|
|
// which is why we can't do anything in compileShader. In practice we could
|
|
|
|
// report in compileShader the translation errors generated by ANGLE,
|
|
|
|
// but it seems saner to keep a single way of obtaining shader infologs.
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString log;
|
2012-05-29 11:44:31 -07:00
|
|
|
|
|
|
|
bool alreadyReportedShaderInfoLog = false;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < program->AttachedShaders().Length(); i++) {
|
|
|
|
|
|
|
|
WebGLShader* shader = program->AttachedShaders()[i];
|
2012-07-26 16:58:52 -07:00
|
|
|
|
|
|
|
if (shader->CompileStatus())
|
2012-05-29 11:44:31 -07:00
|
|
|
continue;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *shaderTypeName = nullptr;
|
2012-05-29 11:44:31 -07:00
|
|
|
if (shader->ShaderType() == LOCAL_GL_VERTEX_SHADER) {
|
|
|
|
shaderTypeName = "vertex";
|
|
|
|
} else if (shader->ShaderType() == LOCAL_GL_FRAGMENT_SHADER) {
|
|
|
|
shaderTypeName = "fragment";
|
|
|
|
} else {
|
|
|
|
// should have been validated earlier
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(false);
|
2012-05-29 11:44:31 -07:00
|
|
|
shaderTypeName = "<unknown>";
|
|
|
|
}
|
|
|
|
|
2012-09-17 01:37:20 -07:00
|
|
|
GetShaderInfoLog(shader, log);
|
2012-07-26 16:58:52 -07:00
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
GenerateWarning("linkProgram: a %s shader used in this program failed to "
|
|
|
|
"compile, with this log:\n%s\n",
|
|
|
|
shaderTypeName,
|
|
|
|
log.get());
|
|
|
|
alreadyReportedShaderInfoLog = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!alreadyReportedShaderInfoLog) {
|
2012-09-17 01:37:20 -07:00
|
|
|
GetProgramInfoLog(program, log);
|
|
|
|
if (!log.IsEmpty()) {
|
2012-05-29 11:44:31 -07:00
|
|
|
GenerateWarning("linkProgram failed, with this log:\n%s\n",
|
|
|
|
log.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::PixelStorei(GLenum pname, GLint param)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-15 08:59:39 -07:00
|
|
|
switch (pname) {
|
|
|
|
case UNPACK_FLIP_Y_WEBGL:
|
|
|
|
mPixelStoreFlipY = (param != 0);
|
|
|
|
break;
|
|
|
|
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
|
|
|
|
mPixelStorePremultiplyAlpha = (param != 0);
|
|
|
|
break;
|
2010-12-06 03:34:35 -08:00
|
|
|
case UNPACK_COLORSPACE_CONVERSION_WEBGL:
|
|
|
|
if (param == LOCAL_GL_NONE || param == BROWSER_DEFAULT_WEBGL)
|
|
|
|
mPixelStoreColorspaceConversion = param;
|
|
|
|
else
|
|
|
|
return ErrorInvalidEnumInfo("pixelStorei: colorspace conversion parameter", param);
|
|
|
|
break;
|
2010-06-15 08:59:39 -07:00
|
|
|
case LOCAL_GL_PACK_ALIGNMENT:
|
|
|
|
case LOCAL_GL_UNPACK_ALIGNMENT:
|
2010-10-15 14:50:15 -07:00
|
|
|
if (param != 1 &&
|
|
|
|
param != 2 &&
|
|
|
|
param != 4 &&
|
|
|
|
param != 8)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("pixelStorei: invalid pack/unpack alignment value");
|
2010-10-15 14:50:15 -07:00
|
|
|
if (pname == LOCAL_GL_PACK_ALIGNMENT)
|
|
|
|
mPixelStorePackAlignment = param;
|
|
|
|
else if (pname == LOCAL_GL_UNPACK_ALIGNMENT)
|
|
|
|
mPixelStoreUnpackAlignment = param;
|
2010-06-15 08:59:39 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPixelStorei(pname, param);
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidEnumInfo("pixelStorei: parameter", pname);
|
2010-06-15 08:59:39 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-06-15 08:59:39 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
|
|
|
|
GLsizei height, GLenum format,
|
|
|
|
GLenum type, const Nullable<ArrayBufferView> &pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-03-16 02:50:51 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-10-25 16:10:53 -07:00
|
|
|
if (mCanvasElement->IsWriteOnly() && !nsContentUtils::IsCallerChrome()) {
|
2012-05-23 09:07:35 -07:00
|
|
|
GenerateWarning("readPixels: Not allowed");
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-06-19 07:46:12 -07:00
|
|
|
if (width < 0 || height < 0)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("readPixels: negative size passed");
|
2010-06-19 07:46:12 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
if (pixels.IsNull())
|
2012-06-15 14:36:48 -07:00
|
|
|
return ErrorInvalidValue("readPixels: null destination buffer");
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject();
|
2013-09-04 05:14:43 -07:00
|
|
|
GLsizei framebufferWidth = framebufferRect ? framebufferRect->Width() : 0;
|
|
|
|
GLsizei framebufferHeight = framebufferRect ? framebufferRect->Height() : 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t channels = 0;
|
2011-10-31 16:55:01 -07:00
|
|
|
|
|
|
|
// Check the format param
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (format) {
|
2011-10-31 16:55:01 -07:00
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
channels = 1;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
channels = 3;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
channels = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ErrorInvalidEnum("readPixels: Bad format");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t bytesPerPixel = 0;
|
2011-10-31 16:55:01 -07:00
|
|
|
int requiredDataType = 0;
|
|
|
|
|
|
|
|
// Check the type param
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (type) {
|
2011-10-31 16:55:01 -07:00
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
bytesPerPixel = 1 * channels;
|
2012-01-14 09:43:00 -08:00
|
|
|
requiredDataType = js::ArrayBufferView::TYPE_UINT8;
|
2011-10-31 16:55:01 -07:00
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
bytesPerPixel = 2;
|
2012-01-14 09:43:00 -08:00
|
|
|
requiredDataType = js::ArrayBufferView::TYPE_UINT16;
|
2011-10-31 16:55:01 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ErrorInvalidEnum("readPixels: Bad type");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
int dataType = JS_GetArrayBufferViewType(pixels.Value().Obj());
|
2013-01-07 15:12:06 -08:00
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
// Check the pixels param type
|
|
|
|
if (dataType != requiredDataType)
|
|
|
|
return ErrorInvalidOperation("readPixels: Mismatched type/pixels types");
|
2010-11-16 20:33:04 -08:00
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
// Check the pixels param size
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_neededByteLength =
|
2011-10-31 16:55:01 -07:00
|
|
|
GetImageSize(height, width, bytesPerPixel, mPixelStorePackAlignment);
|
2010-05-26 16:53:15 -07:00
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * bytesPerPixel;
|
2010-07-03 15:32:19 -07:00
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
CheckedUint32 checked_alignedRowSize =
|
2011-09-01 12:28:34 -07:00
|
|
|
RoundedToNextMultipleOf(checked_plainRowSize, mPixelStorePackAlignment);
|
2010-05-26 16:53:15 -07:00
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("readPixels: integer overflow computing the needed buffer size");
|
2010-06-19 07:46:12 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
uint32_t dataByteLen = JS_GetTypedArrayByteLength(pixels.Value().Obj());
|
2011-10-31 16:55:01 -07:00
|
|
|
if (checked_neededByteLength.value() > dataByteLen)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("readPixels: buffer too small");
|
2010-06-19 07:46:12 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
void* data = pixels.Value().Data();
|
2012-11-22 10:53:11 -08:00
|
|
|
if (!data) {
|
|
|
|
ErrorOutOfMemory("readPixels: buffer storage is null. Did we run out of memory?");
|
|
|
|
return rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
// Check the format and type params to assure they are an acceptable pair (as per spec)
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA: {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ErrorInvalidOperation("readPixels: Invalid format/type pair");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return ErrorInvalidOperation("readPixels: Invalid format/type pair");
|
|
|
|
}
|
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mBoundFramebuffer) {
|
|
|
|
// prevent readback of arbitrary video memory through uninitialized renderbuffers!
|
2013-10-11 06:16:43 -07:00
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeAttachments())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("readPixels: incomplete framebuffer");
|
2011-05-20 12:53:53 -07:00
|
|
|
}
|
2011-10-31 16:55:01 -07:00
|
|
|
// Now that the errors are out of the way, on to actually reading
|
|
|
|
|
|
|
|
// If we won't be reading any pixels anyways, just skip the actual reading
|
|
|
|
if (width == 0 || height == 0)
|
2012-01-24 13:12:31 -08:00
|
|
|
return DummyFramebufferOperation("readPixels");
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
if (CanvasUtils::CheckSaneSubrectSize(x, y, width, height, framebufferWidth, framebufferHeight)) {
|
2010-06-19 07:46:12 -07:00
|
|
|
// the easy case: we're not reading out-of-range pixels
|
|
|
|
gl->fReadPixels(x, y, width, height, format, type, data);
|
|
|
|
} else {
|
|
|
|
// the rectangle doesn't fit entirely in the bound buffer. We then have to set to zero the part
|
|
|
|
// of the buffer that correspond to out-of-range pixels. We don't want to rely on system OpenGL
|
|
|
|
// to do that for us, because passing out of range parameters to a buggy OpenGL implementation
|
|
|
|
// could conceivably allow to read memory we shouldn't be allowed to read. So we manually initialize
|
|
|
|
// the buffer to zero and compute the parameters to pass to OpenGL. We have to use an intermediate buffer
|
|
|
|
// to accomodate the potentially different strides (widths).
|
|
|
|
|
2013-05-30 18:54:00 -07:00
|
|
|
// Zero the whole pixel dest area in the destination buffer.
|
|
|
|
memset(data, 0, checked_neededByteLength.value());
|
2010-06-19 07:46:12 -07:00
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
if ( x >= framebufferWidth
|
2010-06-19 07:46:12 -07:00
|
|
|
|| x+width <= 0
|
2012-01-24 13:12:31 -08:00
|
|
|
|| y >= framebufferHeight
|
2010-06-19 07:46:12 -07:00
|
|
|
|| y+height <= 0)
|
|
|
|
{
|
|
|
|
// we are completely outside of range, can exit now with buffer filled with zeros
|
2012-01-24 13:12:31 -08:00
|
|
|
return DummyFramebufferOperation("readPixels");
|
2010-06-19 07:46:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// compute the parameters of the subrect we're actually going to call glReadPixels on
|
2013-01-15 04:22:03 -08:00
|
|
|
GLint subrect_x = std::max(x, 0);
|
|
|
|
GLint subrect_end_x = std::min(x+width, framebufferWidth);
|
2010-06-19 07:46:12 -07:00
|
|
|
GLsizei subrect_width = subrect_end_x - subrect_x;
|
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
GLint subrect_y = std::max(y, 0);
|
|
|
|
GLint subrect_end_y = std::min(y+height, framebufferHeight);
|
2010-06-19 07:46:12 -07:00
|
|
|
GLsizei subrect_height = subrect_end_y - subrect_y;
|
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (subrect_width < 0 || subrect_height < 0 ||
|
2010-08-25 05:16:04 -07:00
|
|
|
subrect_width > width || subrect_height > height)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("readPixels: integer overflow computing clipped rect size");
|
2010-07-03 15:32:19 -07:00
|
|
|
|
|
|
|
// now we know that subrect_width is in the [0..width] interval, and same for heights.
|
|
|
|
|
2010-06-19 07:46:12 -07:00
|
|
|
// now, same computation as above to find the size of the intermediate buffer to allocate for the subrect
|
2010-07-03 15:32:19 -07:00
|
|
|
// no need to check again for integer overflow here, since we already know the sizes aren't greater than before
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t subrect_plainRowSize = subrect_width * bytesPerPixel;
|
2013-10-01 17:30:05 -07:00
|
|
|
// There are checks above to ensure that this doesn't overflow.
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t subrect_alignedRowSize =
|
2011-09-01 12:28:34 -07:00
|
|
|
RoundedToNextMultipleOf(subrect_plainRowSize, mPixelStorePackAlignment).value();
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t subrect_byteLength = (subrect_height-1)*subrect_alignedRowSize + subrect_plainRowSize;
|
2010-06-19 07:46:12 -07:00
|
|
|
|
|
|
|
// create subrect buffer, call glReadPixels, copy pixels into destination buffer, delete subrect buffer
|
|
|
|
GLubyte *subrect_data = new GLubyte[subrect_byteLength];
|
|
|
|
gl->fReadPixels(subrect_x, subrect_y, subrect_width, subrect_height, format, type, subrect_data);
|
2010-07-03 15:32:19 -07:00
|
|
|
|
|
|
|
// notice that this for loop terminates because we already checked that subrect_height is at most height
|
2010-06-19 07:46:12 -07:00
|
|
|
for (GLint y_inside_subrect = 0; y_inside_subrect < subrect_height; ++y_inside_subrect) {
|
|
|
|
GLint subrect_x_in_dest_buffer = subrect_x - x;
|
|
|
|
GLint subrect_y_in_dest_buffer = subrect_y - y;
|
|
|
|
memcpy(static_cast<GLubyte*>(data)
|
2010-07-03 15:32:19 -07:00
|
|
|
+ checked_alignedRowSize.value() * (subrect_y_in_dest_buffer + y_inside_subrect)
|
2011-10-31 16:55:01 -07:00
|
|
|
+ bytesPerPixel * subrect_x_in_dest_buffer, // destination
|
2010-06-19 07:46:12 -07:00
|
|
|
subrect_data + subrect_alignedRowSize * y_inside_subrect, // source
|
|
|
|
subrect_plainRowSize); // size
|
|
|
|
}
|
|
|
|
delete [] subrect_data;
|
|
|
|
}
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2010-12-22 15:31:02 -08:00
|
|
|
// if we're reading alpha, we may need to do fixup. Note that we don't allow
|
|
|
|
// GL_ALPHA to readpixels currently, but we had the code written for it already.
|
2010-11-16 20:33:03 -08:00
|
|
|
if (format == LOCAL_GL_ALPHA ||
|
|
|
|
format == LOCAL_GL_RGBA)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needAlphaFixup;
|
2010-11-16 20:33:03 -08:00
|
|
|
if (mBoundFramebuffer) {
|
2013-06-21 16:44:17 -07:00
|
|
|
needAlphaFixup = !mBoundFramebuffer->ColorAttachment(0).HasAlpha();
|
2010-11-16 20:33:03 -08:00
|
|
|
} else {
|
2013-02-13 15:26:24 -08:00
|
|
|
needAlphaFixup = gl->GetPixelFormat().alpha == 0;
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (needAlphaFixup) {
|
|
|
|
if (format == LOCAL_GL_ALPHA && type == LOCAL_GL_UNSIGNED_BYTE) {
|
|
|
|
// this is easy; it's an 0xff memset per row
|
2012-05-23 09:07:01 -07:00
|
|
|
uint8_t *row = static_cast<uint8_t*>(data);
|
2010-11-16 20:33:03 -08:00
|
|
|
for (GLint j = 0; j < height; ++j) {
|
|
|
|
memset(row, 0xff, checked_plainRowSize.value());
|
|
|
|
row += checked_alignedRowSize.value();
|
|
|
|
}
|
|
|
|
} else if (format == LOCAL_GL_RGBA && type == LOCAL_GL_UNSIGNED_BYTE) {
|
|
|
|
// this is harder, we need to just set the alpha byte here
|
2012-05-23 09:07:01 -07:00
|
|
|
uint8_t *row = static_cast<uint8_t*>(data);
|
2010-11-16 20:33:03 -08:00
|
|
|
for (GLint j = 0; j < height; ++j) {
|
2012-05-23 09:07:01 -07:00
|
|
|
uint8_t *rowp = row;
|
2010-11-16 20:33:03 -08:00
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
|
|
|
// offset to get the alpha byte; we're always going to
|
|
|
|
// move by 4 bytes
|
|
|
|
rowp += 3;
|
|
|
|
#endif
|
2012-05-23 09:07:01 -07:00
|
|
|
uint8_t *endrowp = rowp + 4 * width;
|
2010-11-16 20:33:03 -08:00
|
|
|
while (rowp != endrowp) {
|
|
|
|
*rowp = 0xff;
|
|
|
|
rowp += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
row += checked_alignedRowSize.value();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Unhandled case, how'd we get here?");
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.Throw(NS_ERROR_FAILURE);
|
2010-11-16 20:33:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-11-16 20:33:03 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
|
2010-05-15 05:07:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2013-10-01 17:31:09 -07:00
|
|
|
if (!mBoundRenderbuffer)
|
2010-11-05 12:57:58 -07:00
|
|
|
return ErrorInvalidOperation("renderbufferStorage called on renderbuffer 0");
|
|
|
|
|
|
|
|
if (target != LOCAL_GL_RENDERBUFFER)
|
|
|
|
return ErrorInvalidEnumInfo("renderbufferStorage: target", target);
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2011-08-25 11:28:59 -07:00
|
|
|
if (width < 0 || height < 0)
|
|
|
|
return ErrorInvalidValue("renderbufferStorage: width and height must be >= 0");
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-12-11 13:57:30 -08:00
|
|
|
if (width > mGLMaxRenderbufferSize || height > mGLMaxRenderbufferSize)
|
|
|
|
return ErrorInvalidValue("renderbufferStorage: width or height exceeds maximum renderbuffer size");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
// certain OpenGL ES renderbuffer formats may not exist on desktop OpenGL
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum internalformatForGL = internalformat;
|
2010-11-05 12:57:58 -07:00
|
|
|
|
|
|
|
switch (internalformat) {
|
|
|
|
case LOCAL_GL_RGBA4:
|
|
|
|
case LOCAL_GL_RGB5_A1:
|
|
|
|
// 16-bit RGBA formats are not supported on desktop GL
|
|
|
|
if (!gl->IsGLES2()) internalformatForGL = LOCAL_GL_RGBA8;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_RGB565:
|
|
|
|
// the RGB565 format is not supported on desktop GL
|
|
|
|
if (!gl->IsGLES2()) internalformatForGL = LOCAL_GL_RGB8;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT16:
|
2011-01-25 19:20:35 -08:00
|
|
|
if (!gl->IsGLES2() || gl->IsExtensionSupported(gl::GLContext::OES_depth24))
|
|
|
|
internalformatForGL = LOCAL_GL_DEPTH_COMPONENT24;
|
|
|
|
else if (gl->IsExtensionSupported(gl::GLContext::OES_packed_depth_stencil))
|
|
|
|
internalformatForGL = LOCAL_GL_DEPTH24_STENCIL8;
|
2010-12-06 03:34:35 -08:00
|
|
|
break;
|
2010-11-05 12:57:58 -07:00
|
|
|
case LOCAL_GL_STENCIL_INDEX8:
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
2013-10-01 17:31:09 -07:00
|
|
|
// We emulate this in WebGLRenderbuffer if we don't have the requisite extension.
|
2010-11-05 12:57:58 -07:00
|
|
|
internalformatForGL = LOCAL_GL_DEPTH24_STENCIL8;
|
|
|
|
break;
|
|
|
|
default:
|
2010-12-03 14:44:01 -08:00
|
|
|
return ErrorInvalidEnumInfo("renderbufferStorage: internalformat", internalformat);
|
2010-11-05 12:57:58 -07:00
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
bool sizeChanges = width != mBoundRenderbuffer->Width() ||
|
|
|
|
height != mBoundRenderbuffer->Height() ||
|
2011-07-07 17:01:16 -07:00
|
|
|
internalformat != mBoundRenderbuffer->InternalFormat();
|
|
|
|
if (sizeChanges) {
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
2013-10-01 17:31:09 -07:00
|
|
|
mBoundRenderbuffer->RenderbufferStorage(internalformatForGL, width, height);
|
2011-07-07 17:01:16 -07:00
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
if (error) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("renderbufferStorage generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
|
|
|
} else {
|
2013-10-01 17:31:09 -07:00
|
|
|
mBoundRenderbuffer->RenderbufferStorage(internalformatForGL, width, height);
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
|
|
|
|
mBoundRenderbuffer->SetInternalFormat(internalformat);
|
2011-07-07 17:01:16 -07:00
|
|
|
mBoundRenderbuffer->SetInternalFormatForGL(internalformatForGL);
|
2010-11-05 12:57:58 -07:00
|
|
|
mBoundRenderbuffer->setDimensions(width, height);
|
2013-10-11 06:16:43 -07:00
|
|
|
mBoundRenderbuffer->SetImageDataStatus(WebGLImageDataStatus::UninitializedImageData);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
if (width < 0 || height < 0)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("scissor: negative size");
|
2010-06-30 08:48:30 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fScissor(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::StencilFunc(GLenum func, GLint ref, GLuint mask)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateComparisonEnum(func, "stencilFunc: func"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
mStencilRefFront = ref;
|
|
|
|
mStencilRefBack = ref;
|
|
|
|
mStencilValueMaskFront = mask;
|
|
|
|
mStencilValueMaskBack = mask;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilFunc(func, ref, mask);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateFaceEnum(face, "stencilFuncSeparate: face") ||
|
|
|
|
!ValidateComparisonEnum(func, "stencilFuncSeparate: func"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
switch (face) {
|
|
|
|
case LOCAL_GL_FRONT_AND_BACK:
|
|
|
|
mStencilRefFront = ref;
|
|
|
|
mStencilRefBack = ref;
|
|
|
|
mStencilValueMaskFront = mask;
|
|
|
|
mStencilValueMaskBack = mask;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRONT:
|
|
|
|
mStencilRefFront = ref;
|
|
|
|
mStencilValueMaskFront = mask;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_BACK:
|
|
|
|
mStencilRefBack = ref;
|
|
|
|
mStencilValueMaskBack = mask;
|
|
|
|
break;
|
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilFuncSeparate(face, func, ref, mask);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateStencilOpEnum(sfail, "stencilOp: sfail") ||
|
|
|
|
!ValidateStencilOpEnum(dpfail, "stencilOp: dpfail") ||
|
|
|
|
!ValidateStencilOpEnum(dppass, "stencilOp: dppass"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilOp(sfail, dpfail, dppass);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
if (!ValidateFaceEnum(face, "stencilOpSeparate: face") ||
|
|
|
|
!ValidateStencilOpEnum(sfail, "stencilOpSeparate: sfail") ||
|
|
|
|
!ValidateStencilOpEnum(dpfail, "stencilOpSeparate: dpfail") ||
|
|
|
|
!ValidateStencilOpEnum(dppass, "stencilOpSeparate: dppass"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilOpSeparate(face, sfail, dpfail, dppass);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
nsresult
|
2012-05-31 11:16:48 -07:00
|
|
|
WebGLContext::SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,
|
|
|
|
gfxImageSurface **imageOut, WebGLTexelFormat *format)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
|
|
|
if (!res.mSurface)
|
|
|
|
return NS_ERROR_FAILURE;
|
2013-09-24 13:45:13 -07:00
|
|
|
if (res.mSurface->GetType() != gfxSurfaceTypeImage) {
|
2009-09-02 17:47:49 -07:00
|
|
|
// SurfaceFromElement lied!
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-25 14:31:30 -08:00
|
|
|
// We disallow loading cross-domain images and videos that have not been validated
|
2011-07-14 11:47:37 -07:00
|
|
|
// with CORS as WebGL textures. The reason for doing that is that timing
|
|
|
|
// attacks on WebGL shaders are able to retrieve approximations of the
|
|
|
|
// pixel values in WebGL textures; see bug 655987.
|
2011-06-07 10:47:54 -07:00
|
|
|
//
|
2011-07-14 11:47:37 -07:00
|
|
|
// To prevent a loophole where a Canvas2D would be used as a proxy to load
|
|
|
|
// cross-domain textures, we also disallow loading textures from write-only
|
|
|
|
// Canvas2D's.
|
2011-06-07 10:47:54 -07:00
|
|
|
|
2011-07-14 11:47:37 -07:00
|
|
|
// part 1: check that the DOM element is same-origin, or has otherwise been
|
|
|
|
// validated for cross-domain use.
|
2011-09-20 14:00:42 -07:00
|
|
|
if (!res.mCORSUsed) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool subsumes;
|
2012-06-06 00:42:47 -07:00
|
|
|
nsresult rv = mCanvasElement->NodePrincipal()->Subsumes(res.mPrincipal, &subsumes);
|
2011-06-07 10:47:54 -07:00
|
|
|
if (NS_FAILED(rv) || !subsumes) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("It is forbidden to load a WebGL texture from a cross-domain element that has not been validated with CORS. "
|
2011-09-09 14:58:35 -07:00
|
|
|
"See https://developer.mozilla.org/en/WebGL/Cross-Domain_Textures");
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2011-06-07 10:47:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 11:16:48 -07:00
|
|
|
// part 2: if the DOM element is write-only, it might contain
|
2011-12-03 13:50:16 -08:00
|
|
|
// cross-domain image data.
|
2012-05-31 11:16:48 -07:00
|
|
|
if (res.mIsWriteOnly) {
|
|
|
|
GenerateWarning("The canvas used as source for texImage2D here is tainted (write-only). It is forbidden "
|
|
|
|
"to load a WebGL texture from a tainted canvas. A Canvas becomes tainted for example "
|
|
|
|
"when a cross-domain image is drawn on it. "
|
|
|
|
"See https://developer.mozilla.org/en/WebGL/Cross-Domain_Textures");
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2011-06-07 10:47:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of security checks, now we should be safe regarding cross-domain images
|
|
|
|
// Notice that there is never a need to mark the WebGL canvas as write-only, since we reject write-only/cross-domain
|
|
|
|
// texture sources in the first place.
|
|
|
|
|
2011-12-03 13:50:16 -08:00
|
|
|
gfxImageSurface* surf = static_cast<gfxImageSurface*>(res.mSurface.get());
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2009-11-01 16:33:47 -08:00
|
|
|
res.mSurface.forget();
|
|
|
|
*imageOut = surf;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
switch (surf->Format()) {
|
2013-09-24 13:45:13 -07:00
|
|
|
case gfxImageFormatARGB32:
|
2012-05-07 10:05:32 -07:00
|
|
|
*format = WebGLTexelConversions::BGRA8; // careful, our ARGB means BGRA
|
2010-10-15 14:50:15 -07:00
|
|
|
break;
|
2013-09-24 13:45:13 -07:00
|
|
|
case gfxImageFormatRGB24:
|
2012-05-07 10:05:32 -07:00
|
|
|
*format = WebGLTexelConversions::BGRX8; // careful, our RGB24 is not tightly packed. Whence BGRX8.
|
2010-10-15 14:50:15 -07:00
|
|
|
break;
|
2013-09-24 13:45:13 -07:00
|
|
|
case gfxImageFormatA8:
|
2012-05-07 10:05:32 -07:00
|
|
|
*format = WebGLTexelConversions::A8;
|
2010-10-15 14:50:15 -07:00
|
|
|
break;
|
2013-09-24 13:45:13 -07:00
|
|
|
case gfxImageFormatRGB16_565:
|
2012-05-07 10:05:32 -07:00
|
|
|
*format = WebGLTexelConversions::RGB565;
|
2010-10-15 14:50:15 -07:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Unsupported image format. Unimplemented.");
|
2010-10-15 14:50:15 -07:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
|
2013-03-04 16:44:31 -08:00
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform1i(WebGLUniformLocation *location_object, GLint a1)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform1i", location_object, location))
|
|
|
|
return;
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform1i", location_object, a1))
|
|
|
|
return;
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform1i(location, a1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform2i(WebGLUniformLocation *location_object, GLint a1,
|
|
|
|
GLint a2)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform2i", location_object, location))
|
|
|
|
return;
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform2i", location_object, a1) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform2i", location_object, a2))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform2i(location, a1, a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform3i(WebGLUniformLocation *location_object, GLint a1,
|
|
|
|
GLint a2, GLint a3)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform3i", location_object, location))
|
|
|
|
return;
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform3i", location_object, a1) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform3i", location_object, a2) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform3i", location_object, a3))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform3i(location, a1, a2, a3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform4i(WebGLUniformLocation *location_object, GLint a1,
|
|
|
|
GLint a2, GLint a3, GLint a4)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform4i", location_object, location))
|
|
|
|
return;
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform4i", location_object, a1) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4i", location_object, a2) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4i", location_object, a3) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4i", location_object, a4))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform4i(location, a1, a2, a3, a4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform1f(WebGLUniformLocation *location_object, GLfloat a1)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform1f", location_object, location))
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform1f(location, a1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform2f(WebGLUniformLocation *location_object, GLfloat a1,
|
|
|
|
GLfloat a2)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform2f", location_object, location))
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform2f(location, a1, a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform3f(WebGLUniformLocation *location_object, GLfloat a1,
|
|
|
|
GLfloat a2, GLfloat a3)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform3f", location_object, location))
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform3f(location, a1, a2, a3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Uniform4f(WebGLUniformLocation *location_object, GLfloat a1,
|
|
|
|
GLfloat a2, GLfloat a3, GLfloat a4)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformSetter("Uniform4f", location_object, location))
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform4f(location, a1, a2, a3, a4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform1iv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLint* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform1iv", 1, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform1iv", location_object, data[0]))
|
|
|
|
return;
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform1iv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform2iv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLint* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform2iv", 2, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform2iv", location_object, data[0]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform2iv", location_object, data[1]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform2iv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform3iv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLint* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform3iv", 3, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform3iv", location_object, data[0]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform3iv", location_object, data[1]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform3iv", location_object, data[2]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform3iv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform4iv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLint* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform4iv", 4, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-04 16:44:31 -08:00
|
|
|
|
|
|
|
if (!ValidateSamplerUniformSetter("Uniform4iv", location_object, data[0]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4iv", location_object, data[1]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4iv", location_object, data[2]) ||
|
|
|
|
!ValidateSamplerUniformSetter("Uniform4iv", location_object, data[3]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform4iv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform1fv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLfloat* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform1fv", 1, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform1fv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform2fv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLfloat* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform2fv", 2, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform2fv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform3fv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLfloat* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform3fv", 3, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform3fv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Uniform4fv_base(WebGLUniformLocation *location_object,
|
2013-09-04 05:14:43 -07:00
|
|
|
uint32_t arrayLength, const GLfloat* data)
|
2012-10-16 05:17:01 -07:00
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformArraySetter("Uniform4fv", 4, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniform4fv(location, numElementsToUpload, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UniformMatrix2fv_base(WebGLUniformLocation* location_object,
|
|
|
|
WebGLboolean aTranspose, uint32_t arrayLength,
|
|
|
|
const float* data)
|
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformMatrixArraySetter("UniformMatrix2fv", 2, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength, aTranspose)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniformMatrix2fv(location, numElementsToUpload, false, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UniformMatrix3fv_base(WebGLUniformLocation* location_object,
|
|
|
|
WebGLboolean aTranspose, uint32_t arrayLength,
|
|
|
|
const float* data)
|
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformMatrixArraySetter("UniformMatrix3fv", 3, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength, aTranspose)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniformMatrix3fv(location, numElementsToUpload, false, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UniformMatrix4fv_base(WebGLUniformLocation* location_object,
|
|
|
|
WebGLboolean aTranspose, uint32_t arrayLength,
|
|
|
|
const float* data)
|
|
|
|
{
|
|
|
|
uint32_t numElementsToUpload;
|
|
|
|
GLint location;
|
|
|
|
if (!ValidateUniformMatrixArraySetter("UniformMatrix4fv", 4, location_object, location,
|
|
|
|
numElementsToUpload, arrayLength, aTranspose)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fUniformMatrix4fv(location, numElementsToUpload, false, data);
|
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::UseProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowNull("useProgram", prog))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
InvalidateBufferFetching();
|
2012-09-21 10:44:35 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog ? prog->GLName() : 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
if (prog && !prog->LinkStatus())
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("useProgram: program was not linked successfully");
|
2011-01-05 13:08:53 -08:00
|
|
|
|
|
|
|
gl->fUseProgram(progname);
|
|
|
|
|
2011-10-26 15:13:39 -07:00
|
|
|
mCurrentProgram = prog;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ValidateProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("validateProgram", prog))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
#ifdef XP_MACOSX
|
2011-05-20 12:53:53 -07:00
|
|
|
// see bug 593867 for NVIDIA and bug 657201 for ATI. The latter is confirmed with Mac OS 10.6.7
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("validateProgram: implemented as a no-operation on Mac to work around crashes");
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-04-10 08:49:10 -07:00
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
#endif
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint progname = prog->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fValidateProgram(progname);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLFramebuffer>
|
|
|
|
WebGLContext::CreateFramebuffer()
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLFramebuffer> globj = new WebGLFramebuffer(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLRenderbuffer>
|
|
|
|
WebGLContext::CreateRenderbuffer()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-04 09:38:44 -07:00
|
|
|
nsRefPtr<WebGLRenderbuffer> globj = new WebGLRenderbuffer(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
|
2010-06-30 08:48:30 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
if (width < 0 || height < 0)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("viewport: negative size");
|
2010-06-30 08:48:30 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fViewport(x, y, width, height);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::CompileShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("compileShader", shader))
|
|
|
|
return;
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint shadername = shader->GLName();
|
2011-01-05 13:08:53 -08:00
|
|
|
|
2012-07-26 16:58:52 -07:00
|
|
|
shader->SetCompileStatus(false);
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
ShShaderOutput targetShaderSourceLanguage = gl->IsGLES2() ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT;
|
|
|
|
bool useShaderSourceTranslation = true;
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
if (shader->NeedsTranslation() && mShaderValidation) {
|
|
|
|
ShHandle compiler = 0;
|
2010-10-09 12:44:25 -07:00
|
|
|
ShBuiltInResources resources;
|
|
|
|
memset(&resources, 0, sizeof(ShBuiltInResources));
|
|
|
|
|
|
|
|
resources.MaxVertexAttribs = mGLMaxVertexAttribs;
|
|
|
|
resources.MaxVertexUniformVectors = mGLMaxVertexUniformVectors;
|
|
|
|
resources.MaxVaryingVectors = mGLMaxVaryingVectors;
|
|
|
|
resources.MaxVertexTextureImageUnits = mGLMaxVertexTextureImageUnits;
|
|
|
|
resources.MaxCombinedTextureImageUnits = mGLMaxTextureUnits;
|
|
|
|
resources.MaxTextureImageUnits = mGLMaxTextureImageUnits;
|
|
|
|
resources.MaxFragmentUniformVectors = mGLMaxFragmentUniformVectors;
|
2013-06-21 16:44:17 -07:00
|
|
|
resources.MaxDrawBuffers = mGLMaxDrawBuffers;
|
2013-05-15 14:50:52 -07:00
|
|
|
|
2012-06-15 22:12:30 -07:00
|
|
|
if (IsExtensionEnabled(OES_standard_derivatives))
|
2011-09-30 21:45:50 -07:00
|
|
|
resources.OES_standard_derivatives = 1;
|
2010-10-09 12:44:25 -07:00
|
|
|
|
2013-06-21 16:44:17 -07:00
|
|
|
if (IsExtensionEnabled(WEBGL_draw_buffers))
|
|
|
|
resources.EXT_draw_buffers = 1;
|
|
|
|
|
2013-05-15 14:50:52 -07:00
|
|
|
// Tell ANGLE to allow highp in frag shaders. (unless disabled)
|
|
|
|
// If underlying GLES doesn't have highp in frag shaders, it should complain anyways.
|
|
|
|
resources.FragmentPrecisionHigh = mDisableFragHighP ? 0 : 1;
|
|
|
|
|
2013-09-19 14:59:44 -07:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (gl->Vendor() == gl::GLContext::VendorNVIDIA) {
|
|
|
|
// Work around bug 890432
|
|
|
|
resources.MaxExpressionComplexity = 1000;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
// We're storing an actual instance of StripComments because, if we don't, the
|
|
|
|
// cleanSource nsAString instance will be destroyed before the reference is
|
|
|
|
// actually used.
|
|
|
|
StripComments stripComments(shader->Source());
|
2012-12-22 12:40:37 -08:00
|
|
|
const nsAString& cleanSource = Substring(stripComments.result().Elements(), stripComments.length());
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLString(cleanSource, "compileShader"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-09-07 14:17:44 -07:00
|
|
|
|
|
|
|
// shaderSource() already checks that the source stripped of comments is in the
|
|
|
|
// 7-bit ASCII range, so we can skip the NS_IsAscii() check.
|
2012-12-22 12:40:37 -08:00
|
|
|
NS_LossyConvertUTF16toASCII sourceCString(cleanSource);
|
2012-03-02 12:42:49 -08:00
|
|
|
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
2012-05-23 09:07:01 -07:00
|
|
|
const uint32_t maxSourceLength = 0x3ffff;
|
2012-04-10 08:49:10 -07:00
|
|
|
if (sourceCString.Length() > maxSourceLength)
|
|
|
|
return ErrorInvalidValue("compileShader: source has more than %d characters",
|
|
|
|
maxSourceLength);
|
|
|
|
}
|
2011-09-07 14:17:44 -07:00
|
|
|
|
|
|
|
const char *s = sourceCString.get();
|
2012-03-02 12:42:49 -08:00
|
|
|
|
2013-07-18 07:31:01 -07:00
|
|
|
#define WEBGL2_BYPASS_ANGLE
|
|
|
|
#ifdef WEBGL2_BYPASS_ANGLE
|
|
|
|
/*
|
|
|
|
* The bypass don't bring a full support for GLSL ES 3.0, but the main purpose
|
|
|
|
* is to natively bring gl_InstanceID (to do instanced rendering) and gl_FragData
|
|
|
|
*
|
|
|
|
* To remove the bypass code, just comment #define WEBGL2_BYPASS_ANGLE above
|
|
|
|
*
|
|
|
|
* To bypass angle, the context must be a WebGL 2 and the shader must have the
|
|
|
|
* following line at the very top :
|
|
|
|
* #version proto-200
|
|
|
|
*
|
|
|
|
* In this case, byPassANGLE == true and here is what we do :
|
|
|
|
* We create two shader source code:
|
|
|
|
* - one for the driver, that enable GL_EXT_gpu_shader4
|
|
|
|
* - one for the angle compilor, to get informations about vertex attributes
|
|
|
|
* and uniforms
|
|
|
|
*/
|
|
|
|
static const char *bypassPrefixSearch = "#version proto-200";
|
|
|
|
static const char *bypassANGLEPrefix[2] = {"precision mediump float;\n"
|
|
|
|
"#define gl_VertexID 0\n"
|
|
|
|
"#define gl_InstanceID 0\n",
|
|
|
|
|
|
|
|
"precision mediump float;\n"
|
|
|
|
"#extension GL_EXT_draw_buffers : enable\n"
|
|
|
|
"#define gl_PrimitiveID 0\n"};
|
|
|
|
|
|
|
|
const bool bypassANGLE = IsWebGL2() && (strstr(s, bypassPrefixSearch) != 0);
|
|
|
|
|
|
|
|
const char *angleShaderCode = s;
|
|
|
|
nsTArray<char> bypassANGLEShaderCode;
|
|
|
|
nsTArray<char> bypassDriverShaderCode;
|
|
|
|
|
|
|
|
if (bypassANGLE) {
|
|
|
|
const int bypassStage = (shader->ShaderType() == LOCAL_GL_FRAGMENT_SHADER) ? 1 : 0;
|
|
|
|
const char *originalShader = strstr(s, bypassPrefixSearch) + strlen(bypassPrefixSearch);
|
|
|
|
int originalShaderSize = strlen(s) - (originalShader - s);
|
|
|
|
int bypassShaderCodeSize = originalShaderSize + 4096 + 1;
|
|
|
|
|
|
|
|
bypassANGLEShaderCode.SetLength(bypassShaderCodeSize);
|
|
|
|
strcpy(bypassANGLEShaderCode.Elements(), bypassANGLEPrefix[bypassStage]);
|
|
|
|
strcat(bypassANGLEShaderCode.Elements(), originalShader);
|
|
|
|
|
|
|
|
bypassDriverShaderCode.SetLength(bypassShaderCodeSize);
|
|
|
|
strcpy(bypassDriverShaderCode.Elements(), "#extension GL_EXT_gpu_shader4 : enable\n");
|
|
|
|
strcat(bypassDriverShaderCode.Elements(), originalShader);
|
|
|
|
|
|
|
|
angleShaderCode = bypassANGLEShaderCode.Elements();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
compiler = ShConstructCompiler((ShShaderType) shader->ShaderType(),
|
|
|
|
SH_WEBGL_SPEC,
|
|
|
|
targetShaderSourceLanguage,
|
|
|
|
&resources);
|
|
|
|
|
2012-12-11 13:57:30 -08:00
|
|
|
int compileOptions = SH_ATTRIBUTES_UNIFORMS |
|
|
|
|
SH_ENFORCE_PACKING_RESTRICTIONS;
|
2013-02-05 17:53:41 -08:00
|
|
|
|
2013-09-19 14:59:44 -07:00
|
|
|
if (resources.MaxExpressionComplexity > 0) {
|
|
|
|
compileOptions |= SH_LIMIT_EXPRESSION_COMPLEXITY;
|
|
|
|
}
|
|
|
|
|
2013-05-19 19:10:47 -07:00
|
|
|
// We want to do this everywhere, but:
|
|
|
|
#ifndef XP_MACOSX // To do this on Mac, we need to do it only on Mac OSX > 10.6 as this
|
2013-02-05 17:53:41 -08:00
|
|
|
// causes the shader compiler in 10.6 to crash
|
|
|
|
compileOptions |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
|
|
|
|
#endif
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
if (useShaderSourceTranslation) {
|
|
|
|
compileOptions |= SH_OBJECT_CODE
|
2012-04-16 12:56:12 -07:00
|
|
|
| SH_MAP_LONG_VARIABLE_NAMES;
|
2013-09-19 14:59:44 -07:00
|
|
|
|
2011-11-07 16:33:51 -08:00
|
|
|
#ifdef XP_MACOSX
|
2012-07-05 19:34:01 -07:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
|
|
// Work around bug 665578 and bug 769810
|
|
|
|
if (gl->Vendor() == gl::GLContext::VendorATI) {
|
|
|
|
compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work around bug 735560
|
|
|
|
if (gl->Vendor() == gl::GLContext::VendorIntel) {
|
|
|
|
compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS;
|
|
|
|
}
|
2012-04-10 08:49:10 -07:00
|
|
|
}
|
2011-11-07 16:33:51 -08:00
|
|
|
#endif
|
2012-03-02 12:42:49 -08:00
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2013-07-18 07:31:01 -07:00
|
|
|
#ifdef WEBGL2_BYPASS_ANGLE
|
|
|
|
if (!ShCompile(compiler, &angleShaderCode, 1, compileOptions)) {
|
|
|
|
#else
|
2011-10-23 19:46:40 -07:00
|
|
|
if (!ShCompile(compiler, &s, 1, compileOptions)) {
|
2013-07-18 07:31:01 -07:00
|
|
|
#endif
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t len = 0;
|
2010-10-09 12:44:25 -07:00
|
|
|
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &len);
|
|
|
|
|
|
|
|
if (len) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString info;
|
2010-10-10 20:10:16 -07:00
|
|
|
info.SetLength(len);
|
2010-10-09 12:44:25 -07:00
|
|
|
ShGetInfoLog(compiler, info.BeginWriting());
|
|
|
|
shader->SetTranslationFailure(info);
|
2010-08-09 23:51:56 -07:00
|
|
|
} else {
|
|
|
|
shader->SetTranslationFailure(NS_LITERAL_CSTRING("Internal error: failed to get shader info log"));
|
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
ShDestruct(compiler);
|
2012-07-26 16:58:52 -07:00
|
|
|
shader->SetCompileStatus(false);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t num_attributes = 0;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTES, &num_attributes);
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t num_uniforms = 0;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShGetInfo(compiler, SH_ACTIVE_UNIFORMS, &num_uniforms);
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t attrib_max_length = 0;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attrib_max_length);
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t uniform_max_length = 0;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &uniform_max_length);
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t mapped_max_length = 0;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mapped_max_length);
|
|
|
|
|
|
|
|
shader->mAttribMaxNameLength = attrib_max_length;
|
|
|
|
|
|
|
|
shader->mAttributes.Clear();
|
|
|
|
shader->mUniforms.Clear();
|
2012-04-16 12:56:12 -07:00
|
|
|
shader->mUniformInfos.Clear();
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
nsAutoArrayPtr<char> attribute_name(new char[attrib_max_length+1]);
|
|
|
|
nsAutoArrayPtr<char> uniform_name(new char[uniform_max_length+1]);
|
|
|
|
nsAutoArrayPtr<char> mapped_name(new char[mapped_max_length+1]);
|
|
|
|
|
2013-05-13 05:12:37 -07:00
|
|
|
for (size_t i = 0; i < num_uniforms; i++) {
|
|
|
|
size_t length;
|
|
|
|
int size;
|
2012-04-16 12:56:12 -07:00
|
|
|
ShDataType type;
|
2013-05-13 05:12:37 -07:00
|
|
|
ShGetActiveUniform(compiler, (int)i,
|
2012-04-16 12:56:12 -07:00
|
|
|
&length, &size, &type,
|
|
|
|
uniform_name,
|
|
|
|
mapped_name);
|
|
|
|
if (useShaderSourceTranslation) {
|
|
|
|
shader->mUniforms.AppendElement(WebGLMappedIdentifier(
|
|
|
|
nsDependentCString(uniform_name),
|
|
|
|
nsDependentCString(mapped_name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// we always query uniform info, regardless of useShaderSourceTranslation,
|
|
|
|
// as we need it to validate uniform setter calls, and it doesn't rely on
|
|
|
|
// shader translation.
|
2012-07-25 09:13:45 -07:00
|
|
|
char mappedNameLength = strlen(mapped_name);
|
|
|
|
char mappedNameLastChar = mappedNameLength > 1
|
|
|
|
? mapped_name[mappedNameLength - 1]
|
|
|
|
: 0;
|
2012-04-16 12:56:12 -07:00
|
|
|
shader->mUniformInfos.AppendElement(WebGLUniformInfo(
|
|
|
|
size,
|
2012-07-25 09:13:45 -07:00
|
|
|
mappedNameLastChar == ']',
|
2012-04-16 12:56:12 -07:00
|
|
|
type));
|
|
|
|
}
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
if (useShaderSourceTranslation) {
|
2012-04-16 12:56:12 -07:00
|
|
|
|
2013-05-13 05:12:37 -07:00
|
|
|
for (size_t i = 0; i < num_attributes; i++) {
|
|
|
|
size_t length;
|
|
|
|
int size;
|
2012-03-02 12:42:49 -08:00
|
|
|
ShDataType type;
|
2013-05-13 05:12:37 -07:00
|
|
|
ShGetActiveAttrib(compiler, (int)i,
|
2012-03-02 12:42:49 -08:00
|
|
|
&length, &size, &type,
|
|
|
|
attribute_name,
|
|
|
|
mapped_name);
|
|
|
|
shader->mAttributes.AppendElement(WebGLMappedIdentifier(
|
|
|
|
nsDependentCString(attribute_name),
|
|
|
|
nsDependentCString(mapped_name)));
|
|
|
|
}
|
|
|
|
|
2013-05-13 05:12:37 -07:00
|
|
|
size_t len = 0;
|
2010-10-09 12:44:25 -07:00
|
|
|
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &len);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString translatedSrc;
|
2010-10-10 20:10:16 -07:00
|
|
|
translatedSrc.SetLength(len);
|
2010-10-09 12:44:25 -07:00
|
|
|
ShGetObjectCode(compiler, translatedSrc.BeginWriting());
|
|
|
|
|
2012-12-22 12:40:37 -08:00
|
|
|
const char *ts = translatedSrc.get();
|
2010-10-09 12:44:25 -07:00
|
|
|
|
2013-07-18 07:31:01 -07:00
|
|
|
#ifdef WEBGL2_BYPASS_ANGLE
|
|
|
|
if (bypassANGLE) {
|
|
|
|
const char* driverShaderCode = bypassDriverShaderCode.Elements();
|
|
|
|
gl->fShaderSource(shadername, 1, (const GLchar**) &driverShaderCode, nullptr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gl->fShaderSource(shadername, 1, &ts, nullptr);
|
|
|
|
}
|
|
|
|
#else
|
2013-04-02 18:14:24 -07:00
|
|
|
gl->fShaderSource(shadername, 1, &ts, nullptr);
|
2013-07-18 07:31:01 -07:00
|
|
|
#endif
|
2012-03-02 12:42:49 -08:00
|
|
|
} else { // not useShaderSourceTranslation
|
|
|
|
// we just pass the raw untranslated shader source. We then can't use ANGLE idenfier mapping.
|
|
|
|
// that's really bad, as that means we can't be 100% conformant. We should work towards always
|
|
|
|
// using ANGLE identifier mapping.
|
2013-04-02 18:14:24 -07:00
|
|
|
gl->fShaderSource(shadername, 1, &s, nullptr);
|
2010-08-30 16:56:40 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
shader->SetTranslationSuccess();
|
|
|
|
|
|
|
|
ShDestruct(compiler);
|
2011-09-07 15:20:26 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
gl->fCompileShader(shadername);
|
2012-07-26 16:58:52 -07:00
|
|
|
GLint ok;
|
|
|
|
gl->fGetShaderiv(shadername, LOCAL_GL_COMPILE_STATUS, &ok);
|
|
|
|
shader->SetCompileStatus(ok);
|
2011-09-07 14:17:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat,
|
|
|
|
GLsizei width, GLsizei height, GLint border,
|
2013-08-05 10:40:01 -07:00
|
|
|
const ArrayBufferView& view)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-03-16 02:50:33 -07:00
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!ValidateTexImage2DTarget(target, width, height, "compressedTexImage2D")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-28 13:15:27 -08:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!tex) {
|
|
|
|
ErrorInvalidOperation("compressedTexImage2D: no texture is bound to this target");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCompressedTextureFormats.Contains(internalformat)) {
|
|
|
|
ErrorInvalidEnum("compressedTexImage2D: compressed texture format 0x%x is not supported", internalformat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (border) {
|
|
|
|
ErrorInvalidValue("compressedTexImage2D: border is not 0");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 20:45:20 -07:00
|
|
|
uint32_t byteLength = view.Length();
|
2012-09-25 05:49:28 -07:00
|
|
|
if (!ValidateCompressedTextureSize(target, level, internalformat, width, height, byteLength, "compressedTexImage2D")) {
|
2012-05-08 10:29:31 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-07-31 20:45:20 -07:00
|
|
|
gl->fCompressedTexImage2D(target, level, internalformat, width, height, border, byteLength, view.Data());
|
2013-10-11 06:16:43 -07:00
|
|
|
tex->SetImageInfo(target, level, width, height, internalformat, LOCAL_GL_UNSIGNED_BYTE,
|
|
|
|
WebGLImageDataStatus::InitializedImageData);
|
2012-12-11 13:57:30 -08:00
|
|
|
|
|
|
|
ReattachTextureToAnyFramebufferToWorkAroundBugs(tex, level);
|
2012-01-28 13:15:27 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset,
|
|
|
|
GLint yoffset, GLsizei width, GLsizei height,
|
|
|
|
GLenum format, const ArrayBufferView& view)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-03-16 02:50:33 -07:00
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ErrorInvalidEnumInfo("texSubImage2D: target", target);
|
|
|
|
}
|
|
|
|
|
2012-01-28 13:15:27 -08:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
2012-03-16 02:50:33 -07:00
|
|
|
if (!tex) {
|
2012-05-08 10:29:31 -07:00
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: no texture is bound to this target");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCompressedTextureFormats.Contains(format)) {
|
|
|
|
ErrorInvalidEnum("compressedTexSubImage2D: compressed texture format 0x%x is not supported", format);
|
|
|
|
return;
|
2012-03-16 02:50:33 -07:00
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!ValidateLevelWidthHeightForTarget(target, level, width, height, "compressedTexSubImage2D")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 20:45:20 -07:00
|
|
|
uint32_t byteLength = view.Length();
|
2012-09-25 05:49:28 -07:00
|
|
|
if (!ValidateCompressedTextureSize(target, level, format, width, height, byteLength, "compressedTexSubImage2D")) {
|
2012-05-08 10:29:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
if (!tex->HasImageInfoAt(target, level)) {
|
2012-05-08 10:29:31 -07:00
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: no texture image previously defined for this level and face");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(target, level);
|
2012-05-08 10:29:31 -07:00
|
|
|
|
|
|
|
if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, imageInfo.Width(), imageInfo.Height())) {
|
|
|
|
ErrorInvalidValue("compressedTexSubImage2D: subtexture rectangle out of bounds");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
{
|
|
|
|
if (xoffset < 0 || xoffset % 4 != 0) {
|
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: xoffset is not a multiple of 4");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (yoffset < 0 || yoffset % 4 != 0) {
|
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: yoffset is not a multiple of 4");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (width % 4 != 0 && width != imageInfo.Width()) {
|
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: width is not a multiple of 4 or equal to texture width");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (height % 4 != 0 && height != imageInfo.Height()) {
|
|
|
|
ErrorInvalidOperation("compressedTexSubImage2D: height is not a multiple of 4 or equal to texture height");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-09-25 05:49:28 -07:00
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
{
|
|
|
|
if (xoffset || yoffset ||
|
|
|
|
width != imageInfo.Width() ||
|
|
|
|
height != imageInfo.Height())
|
|
|
|
{
|
|
|
|
ErrorInvalidValue("compressedTexSubImage2D: the update rectangle doesn't match the existing image");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-05-08 10:29:31 -07:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (imageInfo.HasUninitializedImageData()) {
|
|
|
|
tex->DoDeferredImageInitialization(target, level);
|
|
|
|
}
|
|
|
|
|
2012-07-31 20:45:20 -07:00
|
|
|
gl->fCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, byteLength, view.Data());
|
2012-05-08 10:29:31 -07:00
|
|
|
|
|
|
|
return;
|
2012-01-28 13:15:27 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetShaderParameter(WebGLShader *shader, GLenum pname)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getShaderParameter: shader", shader))
|
|
|
|
return JS::NullValue();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint shadername = shader->GLName();
|
2009-11-18 12:42:35 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_SHADER_TYPE:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetShaderiv(shadername, pname, &i);
|
2012-05-23 09:44:48 -07:00
|
|
|
return JS::NumberValue(uint32_t(i));
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
|
|
|
break;
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_DELETE_STATUS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(shader->IsDeleteRequested());
|
2011-12-04 11:15:43 -08:00
|
|
|
break;
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_COMPILE_STATUS:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetShaderiv(shadername, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(bool(i));
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
break;
|
2009-11-18 12:42:35 -08:00
|
|
|
default:
|
2012-05-23 09:07:35 -07:00
|
|
|
ErrorInvalidEnumInfo("getShaderParameter: parameter", pname);
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-09-17 23:01:07 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval)
|
2012-05-29 11:44:31 -07:00
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString s;
|
2012-09-17 01:37:20 -07:00
|
|
|
GetShaderInfoLog(shader, s);
|
2012-05-29 11:44:31 -07:00
|
|
|
if (s.IsVoid())
|
|
|
|
retval.SetIsVoid(true);
|
|
|
|
else
|
|
|
|
CopyASCIItoUTF16(s, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsACString& retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
{
|
|
|
|
retval.SetIsVoid(true);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getShaderInfoLog: shader", shader))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
retval = shader->TranslationLog();
|
|
|
|
if (!retval.IsVoid()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLuint shadername = shader->GLName();
|
2011-06-27 10:27:04 -07:00
|
|
|
GLint k = -1;
|
|
|
|
gl->fGetShaderiv(shadername, LOCAL_GL_INFO_LOG_LENGTH, &k);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (k == -1) {
|
2012-09-17 01:37:20 -07:00
|
|
|
// XXX GL Error? should never happen.
|
|
|
|
return;
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
if (k == 0) {
|
|
|
|
retval.Truncate();
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
retval.SetCapacity(k);
|
|
|
|
gl->fGetShaderInfoLog(shadername, k, &k, (char*) retval.BeginWriting());
|
|
|
|
retval.SetLength(k);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-16 13:11:59 -08:00
|
|
|
|
|
|
|
switch (shadertype) {
|
|
|
|
case LOCAL_GL_FRAGMENT_SHADER:
|
|
|
|
case LOCAL_GL_VERTEX_SHADER:
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getShaderPrecisionFormat: shadertype", shadertype);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-16 13:11:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (precisiontype) {
|
|
|
|
case LOCAL_GL_LOW_FLOAT:
|
|
|
|
case LOCAL_GL_MEDIUM_FLOAT:
|
|
|
|
case LOCAL_GL_HIGH_FLOAT:
|
|
|
|
case LOCAL_GL_LOW_INT:
|
|
|
|
case LOCAL_GL_MEDIUM_INT:
|
|
|
|
case LOCAL_GL_HIGH_INT:
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getShaderPrecisionFormat: precisiontype", precisiontype);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-16 13:11:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
GLint range[2], precision;
|
2013-05-15 14:50:52 -07:00
|
|
|
|
|
|
|
if (mDisableFragHighP &&
|
|
|
|
shadertype == LOCAL_GL_FRAGMENT_SHADER &&
|
|
|
|
(precisiontype == LOCAL_GL_HIGH_FLOAT ||
|
|
|
|
precisiontype == LOCAL_GL_HIGH_INT))
|
|
|
|
{
|
|
|
|
precision = 0;
|
|
|
|
range[0] = 0;
|
|
|
|
range[1] = 0;
|
|
|
|
} else {
|
|
|
|
gl->fGetShaderPrecisionFormat(shadertype, precisiontype, range, &precision);
|
|
|
|
}
|
2011-12-16 13:11:59 -08:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<WebGLShaderPrecisionFormat> retShaderPrecisionFormat
|
2012-10-03 14:13:05 -07:00
|
|
|
= new WebGLShaderPrecisionFormat(this, range[0], range[1], precision);
|
2013-04-22 04:15:59 -07:00
|
|
|
return retShaderPrecisionFormat.forget();
|
2011-12-16 13:11:59 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::GetShaderSource(WebGLShader *shader, nsAString& retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
{
|
|
|
|
retval.SetIsVoid(true);
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getShaderSource: shader", shader))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
retval.Assign(shader->Source());
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ShaderSource(WebGLShader *shader, const nsAString& source)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("shaderSource: shader", shader))
|
|
|
|
return;
|
2010-07-16 07:30:32 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
// We're storing an actual instance of StripComments because, if we don't, the
|
|
|
|
// cleanSource nsAString instance will be destroyed before the reference is
|
|
|
|
// actually used.
|
|
|
|
StripComments stripComments(source);
|
2012-12-22 12:40:37 -08:00
|
|
|
const nsAString& cleanSource = Substring(stripComments.result().Elements(), stripComments.length());
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLString(cleanSource, "compileShader"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-01-06 14:07:13 -08:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
shader->SetSource(source);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
shader->SetNeedsTranslation();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
GLenum WebGLContext::CheckedTexImage2D(GLenum target,
|
|
|
|
GLint level,
|
|
|
|
GLenum internalFormat,
|
|
|
|
GLsizei width,
|
|
|
|
GLsizei height,
|
|
|
|
GLint border,
|
|
|
|
GLenum format,
|
|
|
|
GLenum type,
|
|
|
|
const GLvoid *data)
|
|
|
|
{
|
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(tex != nullptr, "no texture bound");
|
2011-09-21 23:57:26 -07:00
|
|
|
|
|
|
|
bool sizeMayChange = true;
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
if (tex->HasImageInfoAt(target, level)) {
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(target, level);
|
2012-01-24 13:12:31 -08:00
|
|
|
sizeMayChange = width != imageInfo.Width() ||
|
|
|
|
height != imageInfo.Height() ||
|
|
|
|
format != imageInfo.Format() ||
|
|
|
|
type != imageInfo.Type();
|
2011-09-21 23:57:26 -07:00
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (sizeMayChange) {
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
|
|
|
gl->fTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
|
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
gl->fTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
|
|
|
|
return LOCAL_GL_NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexImage2D_base(GLenum target, GLint level, GLenum internalformat,
|
|
|
|
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
|
|
|
|
GLint border,
|
|
|
|
GLenum format, GLenum type,
|
2012-05-23 09:07:01 -07:00
|
|
|
void *data, uint32_t byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
int jsArrayType, // a TypedArray format enum, or -1 if not relevant
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat srcFormat, bool srcPremultiplied)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!ValidateTexImage2DTarget(target, width, height, "texImage2D")) {
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
switch (format) {
|
2010-01-22 13:34:25 -08:00
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
2012-08-13 18:17:55 -07:00
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
2010-01-22 13:34:25 -08:00
|
|
|
break;
|
|
|
|
default:
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidEnumInfo("texImage2D: internal format", internalformat);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-08-23 14:03:35 -07:00
|
|
|
if (format != internalformat)
|
|
|
|
return ErrorInvalidOperation("texImage2D: format does not match internalformat");
|
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!ValidateLevelWidthHeightForTarget(target, level, width, height, "texImage2D")) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-23 14:03:35 -07:00
|
|
|
|
|
|
|
if (level >= 1) {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (!(is_pot_assuming_nonnegative(width) &&
|
|
|
|
is_pot_assuming_nonnegative(height)))
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texImage2D: with level > 0, width and height must be powers of two");
|
|
|
|
}
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (border != 0)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("texImage2D: border must be 0");
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2013-09-30 17:58:57 -07:00
|
|
|
const bool isDepthTexture = format == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
format == LOCAL_GL_DEPTH_STENCIL;
|
|
|
|
|
|
|
|
if (isDepthTexture) {
|
2012-08-13 18:17:55 -07:00
|
|
|
if (IsExtensionEnabled(WEBGL_depth_texture)) {
|
2013-04-02 18:14:24 -07:00
|
|
|
if (target != LOCAL_GL_TEXTURE_2D || data != nullptr || level != 0)
|
2012-08-13 18:17:55 -07:00
|
|
|
return ErrorInvalidOperation("texImage2D: "
|
2013-09-30 17:58:57 -07:00
|
|
|
"with format of DEPTH_COMPONENT or DEPTH_STENCIL, "
|
2012-08-13 18:17:55 -07:00
|
|
|
"target must be TEXTURE_2D, "
|
2013-04-02 18:14:24 -07:00
|
|
|
"data must be nullptr, "
|
2013-09-30 17:58:57 -07:00
|
|
|
"level must be zero"); // Haiku by unknown Zen master
|
|
|
|
} else {
|
|
|
|
return ErrorInvalidEnum("texImage2D: attempt to create a depth texture "
|
|
|
|
"without having enabled the WEBGL_depth_texture extension.");
|
2012-08-13 18:17:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t dstTexelSize = 0;
|
2012-05-07 10:05:32 -07:00
|
|
|
if (!ValidateTexFormatAndType(format, type, jsArrayType, &dstTexelSize, "texImage2D"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat dstFormat = GetWebGLTexelFormat(format, type);
|
|
|
|
WebGLTexelFormat actualSrcFormat = srcFormat == WebGLTexelConversions::Auto ? dstFormat : srcFormat;
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t srcTexelSize = WebGLTexelConversions::TexelBytesForFormat(actualSrcFormat);
|
2012-05-07 10:05:32 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_neededByteLength =
|
2012-05-07 10:05:32 -07:00
|
|
|
GetImageSize(height, width, srcTexelSize, mPixelStoreUnpackAlignment);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * srcTexelSize;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_alignedRowSize =
|
|
|
|
RoundedToNextMultipleOf(checked_plainRowSize.value(), mPixelStoreUnpackAlignment);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
2010-07-03 15:32:19 -07:00
|
|
|
return ErrorInvalidOperation("texImage2D: integer overflow computing the needed buffer size");
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t bytesNeeded = checked_neededByteLength.value();
|
2010-08-23 14:03:35 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (byteLength && byteLength < bytesNeeded)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidOperation("texImage2D: not enough data for operation (need %d, have %d)",
|
2010-05-15 06:55:45 -07:00
|
|
|
bytesNeeded, byteLength);
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2010-08-23 14:03:35 -07:00
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("texImage2D: no texture is bound to this target");
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
MakeContextCurrent();
|
2009-12-02 13:38:39 -08:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
// Handle ES2 and GL differences in floating point internal formats. Note that
|
|
|
|
// format == internalformat, as checked above and as required by ES.
|
|
|
|
internalformat = InternalFormatForFormatAndType(format, type, gl->IsGLES2());
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
WebGLImageDataStatus imageInfoStatusIfSuccess = WebGLImageDataStatus::NoImageData;
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (byteLength) {
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t srcStride = srcStrideOrZero ? srcStrideOrZero : checked_alignedRowSize.value();
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
size_t dstPlainRowSize = dstTexelSize * width;
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t unpackAlignment = mPixelStoreUnpackAlignment;
|
|
|
|
size_t dstStride = ((dstPlainRowSize + unpackAlignment-1) / unpackAlignment) * unpackAlignment;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
if (actualSrcFormat == dstFormat &&
|
|
|
|
srcPremultiplied == mPixelStorePremultiplyAlpha &&
|
|
|
|
srcStride == dstStride &&
|
|
|
|
!mPixelStoreFlipY)
|
|
|
|
{
|
|
|
|
// no conversion, no flipping, so we avoid copying anything and just pass the source pointer
|
2011-07-07 17:01:16 -07:00
|
|
|
error = CheckedTexImage2D(target, level, internalformat,
|
|
|
|
width, height, border, format, type, data);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-07 10:05:32 -07:00
|
|
|
size_t convertedDataSize = height * dstStride;
|
2012-05-23 09:07:01 -07:00
|
|
|
nsAutoArrayPtr<uint8_t> convertedData(new uint8_t[convertedDataSize]);
|
2010-10-15 14:50:15 -07:00
|
|
|
ConvertImage(width, height, srcStride, dstStride,
|
2012-05-23 09:07:01 -07:00
|
|
|
static_cast<uint8_t*>(data), convertedData,
|
2011-07-07 17:01:16 -07:00
|
|
|
actualSrcFormat, srcPremultiplied,
|
2012-05-07 10:05:32 -07:00
|
|
|
dstFormat, mPixelStorePremultiplyAlpha, dstTexelSize);
|
2011-07-07 17:01:16 -07:00
|
|
|
error = CheckedTexImage2D(target, level, internalformat,
|
|
|
|
width, height, border, format, type, convertedData);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
2013-10-11 06:16:43 -07:00
|
|
|
imageInfoStatusIfSuccess = WebGLImageDataStatus::InitializedImageData;
|
2010-01-22 13:34:25 -08:00
|
|
|
} else {
|
2013-10-11 06:16:43 -07:00
|
|
|
error = CheckedTexImage2D(target, level, internalformat,
|
|
|
|
width, height, border, format, type, nullptr);
|
|
|
|
imageInfoStatusIfSuccess = WebGLImageDataStatus::UninitializedImageData;
|
2009-11-01 16:33:47 -08:00
|
|
|
}
|
2012-12-11 13:57:30 -08:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (error) {
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning("texImage2D generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
// in all of the code paths above, we should have either initialized data,
|
|
|
|
// or allocated data and left it uninitialized, but in any case we shouldn't
|
|
|
|
// have NoImageData at this point.
|
|
|
|
MOZ_ASSERT(imageInfoStatusIfSuccess != WebGLImageDataStatus::NoImageData);
|
|
|
|
|
|
|
|
tex->SetImageInfo(target, level, width, height, format, type, imageInfoStatusIfSuccess);
|
2012-12-11 13:57:30 -08:00
|
|
|
|
|
|
|
ReattachTextureToAnyFramebufferToWorkAroundBugs(tex, level);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLsizei width,
|
|
|
|
GLsizei height, GLint border, GLenum format,
|
|
|
|
GLenum type, const Nullable<ArrayBufferView> &pixels, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-01-14 09:43:00 -08:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
return TexImage2D_base(target, level, internalformat, width, height, 0, border, format, type,
|
2013-08-05 10:40:01 -07:00
|
|
|
pixels.IsNull() ? 0 : pixels.Value().Data(),
|
|
|
|
pixels.IsNull() ? 0 : pixels.Value().Length(),
|
|
|
|
pixels.IsNull() ? -1 : (int)JS_GetArrayBufferViewType(pixels.Value().Obj()),
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelConversions::Auto, false);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexImage2D(GLenum target, GLint level,
|
|
|
|
GLenum internalformat, GLenum format,
|
|
|
|
GLenum type, ImageData* pixels, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pixels) {
|
|
|
|
// Spec says to generate an INVALID_VALUE error
|
|
|
|
return ErrorInvalidValue("texImage2D: null ImageData");
|
|
|
|
}
|
|
|
|
|
2012-11-14 09:56:26 -08:00
|
|
|
Uint8ClampedArray arr(pixels->GetDataObject());
|
2012-10-22 10:08:52 -07:00
|
|
|
return TexImage2D_base(target, level, internalformat, pixels->Width(),
|
|
|
|
pixels->Height(), 4*pixels->Width(), 0,
|
2012-07-31 20:45:20 -07:00
|
|
|
format, type, arr.Data(), arr.Length(), -1,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelConversions::RGBA8, false);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexSubImage2D_base(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLsizei width, GLsizei height, GLsizei srcStrideOrZero,
|
|
|
|
GLenum format, GLenum type,
|
2012-05-23 09:07:01 -07:00
|
|
|
void *pixels, uint32_t byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
int jsArrayType,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat srcFormat, bool srcPremultiplied)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
|
|
|
switch (target) {
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("texSubImage2D: target", target);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-08 10:29:31 -07:00
|
|
|
if (!ValidateLevelWidthHeightForTarget(target, level, width, height, "texSubImage2D")) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-23 14:03:35 -07:00
|
|
|
|
|
|
|
if (level >= 1) {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (!(is_pot_assuming_nonnegative(width) &&
|
|
|
|
is_pot_assuming_nonnegative(height)))
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: with level > 0, width and height must be powers of two");
|
|
|
|
}
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2012-10-03 14:13:05 -07:00
|
|
|
if (IsExtensionEnabled(WEBGL_depth_texture) &&
|
2012-08-13 18:17:55 -07:00
|
|
|
(format == LOCAL_GL_DEPTH_COMPONENT || format == LOCAL_GL_DEPTH_STENCIL)) {
|
|
|
|
return ErrorInvalidOperation("texSubImage2D: format");
|
|
|
|
}
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t dstTexelSize = 0;
|
2012-05-07 10:05:32 -07:00
|
|
|
if (!ValidateTexFormatAndType(format, type, jsArrayType, &dstTexelSize, "texSubImage2D"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:49:59 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat dstFormat = GetWebGLTexelFormat(format, type);
|
|
|
|
WebGLTexelFormat actualSrcFormat = srcFormat == WebGLTexelConversions::Auto ? dstFormat : srcFormat;
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t srcTexelSize = WebGLTexelConversions::TexelBytesForFormat(actualSrcFormat);
|
2012-05-07 10:05:32 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (width == 0 || height == 0)
|
2012-05-04 09:38:44 -07:00
|
|
|
return; // ES 2.0 says it has no effect, we better return right now
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_neededByteLength =
|
2012-05-07 10:05:32 -07:00
|
|
|
GetImageSize(height, width, srcTexelSize, mPixelStoreUnpackAlignment);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * srcTexelSize;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_alignedRowSize =
|
|
|
|
RoundedToNextMultipleOf(checked_plainRowSize.value(), mPixelStoreUnpackAlignment);
|
2010-07-03 15:32:19 -07:00
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
if (!checked_neededByteLength.isValid())
|
2010-07-03 15:32:19 -07:00
|
|
|
return ErrorInvalidOperation("texSubImage2D: integer overflow computing the needed buffer size");
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t bytesNeeded = checked_neededByteLength.value();
|
2010-07-03 15:32:19 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (byteLength < bytesNeeded)
|
2010-11-16 20:33:04 -08:00
|
|
|
return ErrorInvalidOperation("texSubImage2D: not enough data for operation (need %d, have %d)", bytesNeeded, byteLength);
|
2010-08-23 14:03:35 -07:00
|
|
|
|
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("texSubImage2D: no texture is bound to this target");
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
if (!tex->HasImageInfoAt(target, level))
|
2011-09-21 23:57:26 -07:00
|
|
|
return ErrorInvalidOperation("texSubImage2D: no texture image previously defined for this level and face");
|
|
|
|
|
2013-10-01 17:30:38 -07:00
|
|
|
const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(target, level);
|
2012-01-24 13:12:31 -08:00
|
|
|
if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, imageInfo.Width(), imageInfo.Height()))
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: subtexture rectangle out of bounds");
|
2011-07-27 11:46:14 -07:00
|
|
|
|
|
|
|
// Require the format and type in texSubImage2D to match that of the existing texture as created by texImage2D
|
2012-01-24 13:12:31 -08:00
|
|
|
if (imageInfo.Format() != format || imageInfo.Type() != type)
|
2011-07-27 11:46:14 -07:00
|
|
|
return ErrorInvalidOperation("texSubImage2D: format or type doesn't match the existing texture");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2013-10-11 06:16:43 -07:00
|
|
|
if (imageInfo.HasUninitializedImageData()) {
|
|
|
|
tex->DoDeferredImageInitialization(target, level);
|
|
|
|
}
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
MakeContextCurrent();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t srcStride = srcStrideOrZero ? srcStrideOrZero : checked_alignedRowSize.value();
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
size_t dstPlainRowSize = dstTexelSize * width;
|
2011-09-01 12:28:34 -07:00
|
|
|
// There are checks above to ensure that this won't overflow.
|
|
|
|
size_t dstStride = RoundedToNextMultipleOf(dstPlainRowSize, mPixelStoreUnpackAlignment).value();
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
if (actualSrcFormat == dstFormat &&
|
|
|
|
srcPremultiplied == mPixelStorePremultiplyAlpha &&
|
|
|
|
srcStride == dstStride &&
|
|
|
|
!mPixelStoreFlipY)
|
|
|
|
{
|
|
|
|
// no conversion, no flipping, so we avoid copying anything and just pass the source pointer
|
|
|
|
gl->fTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-07 10:05:32 -07:00
|
|
|
size_t convertedDataSize = height * dstStride;
|
2012-05-23 09:07:01 -07:00
|
|
|
nsAutoArrayPtr<uint8_t> convertedData(new uint8_t[convertedDataSize]);
|
2010-10-15 14:50:15 -07:00
|
|
|
ConvertImage(width, height, srcStride, dstStride,
|
2012-05-23 09:07:01 -07:00
|
|
|
static_cast<const uint8_t*>(pixels), convertedData,
|
2010-10-15 14:50:15 -07:00
|
|
|
actualSrcFormat, srcPremultiplied,
|
2012-05-07 10:05:32 -07:00
|
|
|
dstFormat, mPixelStorePremultiplyAlpha, dstTexelSize);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
|
|
|
gl->fTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, convertedData);
|
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
GLenum format, GLenum type,
|
2013-08-05 10:40:01 -07:00
|
|
|
const Nullable<ArrayBufferView> &pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2013-08-05 10:40:01 -07:00
|
|
|
if (pixels.IsNull())
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: pixels must not be null!");
|
2010-01-22 13:34:25 -08:00
|
|
|
|
|
|
|
return TexSubImage2D_base(target, level, xoffset, yoffset,
|
2010-10-15 14:50:15 -07:00
|
|
|
width, height, 0, format, type,
|
2013-08-05 10:40:01 -07:00
|
|
|
pixels.Value().Data(), pixels.Value().Length(),
|
|
|
|
JS_GetArrayBufferViewType(pixels.Value().Obj()),
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelConversions::Auto, false);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::TexSubImage2D(GLenum target, GLint level,
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
GLenum format, GLenum type, ImageData* pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pixels)
|
2012-05-23 09:07:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: pixels must not be null!");
|
2012-05-04 09:38:44 -07:00
|
|
|
|
2012-11-14 09:56:26 -08:00
|
|
|
Uint8ClampedArray arr(pixels->GetDataObject());
|
2010-10-15 14:50:15 -07:00
|
|
|
return TexSubImage2D_base(target, level, xoffset, yoffset,
|
2012-10-22 10:08:52 -07:00
|
|
|
pixels->Width(), pixels->Height(),
|
|
|
|
4*pixels->Width(), format, type,
|
2012-07-31 20:45:20 -07:00
|
|
|
arr.Data(), arr.Length(),
|
2011-05-20 12:53:53 -07:00
|
|
|
-1,
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelConversions::RGBA8, false);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::LoseContext()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2011-10-26 13:00:44 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ForceLoseContext();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::RestoreContext()
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (!IsContextLost() || !mAllowRestore) {
|
2011-10-26 13:00:44 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ForceRestoreContext();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-09-04 05:14:43 -07:00
|
|
|
BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2010-06-19 07:43:40 -07:00
|
|
|
switch (uType) {
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_INT:
|
|
|
|
case LOCAL_GL_INT_VEC2:
|
|
|
|
case LOCAL_GL_INT_VEC3:
|
|
|
|
case LOCAL_GL_INT_VEC4:
|
|
|
|
case LOCAL_GL_SAMPLER_2D:
|
|
|
|
case LOCAL_GL_SAMPLER_CUBE:
|
|
|
|
*baseType = LOCAL_GL_INT;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
case LOCAL_GL_FLOAT_VEC2:
|
|
|
|
case LOCAL_GL_FLOAT_VEC3:
|
|
|
|
case LOCAL_GL_FLOAT_VEC4:
|
|
|
|
case LOCAL_GL_FLOAT_MAT2:
|
|
|
|
case LOCAL_GL_FLOAT_MAT3:
|
|
|
|
case LOCAL_GL_FLOAT_MAT4:
|
|
|
|
*baseType = LOCAL_GL_FLOAT;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_BOOL:
|
|
|
|
case LOCAL_GL_BOOL_VEC2:
|
|
|
|
case LOCAL_GL_BOOL_VEC3:
|
|
|
|
case LOCAL_GL_BOOL_VEC4:
|
2010-06-19 07:43:40 -07:00
|
|
|
*baseType = LOCAL_GL_BOOL; // pretend these are int
|
2009-09-02 17:47:49 -07:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (uType) {
|
|
|
|
case LOCAL_GL_INT:
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
case LOCAL_GL_BOOL:
|
|
|
|
case LOCAL_GL_SAMPLER_2D:
|
|
|
|
case LOCAL_GL_SAMPLER_CUBE:
|
|
|
|
*unitSize = 1;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_INT_VEC2:
|
|
|
|
case LOCAL_GL_FLOAT_VEC2:
|
|
|
|
case LOCAL_GL_BOOL_VEC2:
|
|
|
|
*unitSize = 2;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_INT_VEC3:
|
|
|
|
case LOCAL_GL_FLOAT_VEC3:
|
|
|
|
case LOCAL_GL_BOOL_VEC3:
|
|
|
|
*unitSize = 3;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_INT_VEC4:
|
|
|
|
case LOCAL_GL_FLOAT_VEC4:
|
|
|
|
case LOCAL_GL_BOOL_VEC4:
|
|
|
|
*unitSize = 4;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FLOAT_MAT2:
|
|
|
|
*unitSize = 4;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FLOAT_MAT3:
|
|
|
|
*unitSize = 9;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FLOAT_MAT4:
|
|
|
|
*unitSize = 16;
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
|
|
|
|
|
2012-05-07 10:05:32 -07:00
|
|
|
WebGLTexelFormat mozilla::GetWebGLTexelFormat(GLenum format, GLenum type)
|
2010-10-15 14:50:15 -07:00
|
|
|
{
|
2012-08-13 18:17:55 -07:00
|
|
|
//
|
|
|
|
// WEBGL_depth_texture
|
|
|
|
if (format == LOCAL_GL_DEPTH_COMPONENT) {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
return WebGLTexelConversions::D16;
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
return WebGLTexelConversions::D32;
|
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Invalid WebGL texture format/type?");
|
2012-08-13 18:17:55 -07:00
|
|
|
}
|
|
|
|
} else if (format == LOCAL_GL_DEPTH_STENCIL) {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_24_8_EXT:
|
|
|
|
return WebGLTexelConversions::D24S8;
|
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Invalid WebGL texture format/type?");
|
2012-08-13 18:17:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (type == LOCAL_GL_UNSIGNED_BYTE) {
|
2010-10-15 14:50:15 -07:00
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGBA8;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_RGB:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGB8;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_ALPHA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::A8;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_LUMINANCE:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::R8;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RA8;
|
2010-10-15 14:50:15 -07:00
|
|
|
default:
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(false, "Coding mistake?! Should never reach this point.");
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::BadFormat;
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
} else if (type == LOCAL_GL_FLOAT) {
|
|
|
|
// OES_texture_float
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGBA32F;
|
2011-05-20 12:53:53 -07:00
|
|
|
case LOCAL_GL_RGB:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGB32F;
|
2011-05-20 12:53:53 -07:00
|
|
|
case LOCAL_GL_ALPHA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::A32F;
|
2011-05-20 12:53:53 -07:00
|
|
|
case LOCAL_GL_LUMINANCE:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::R32F;
|
2011-05-20 12:53:53 -07:00
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RA32F;
|
2011-05-20 12:53:53 -07:00
|
|
|
default:
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(false, "Coding mistake?! Should never reach this point.");
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::BadFormat;
|
2011-05-20 12:53:53 -07:00
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
} else {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGBA4444;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGBA5551;
|
2010-10-15 14:50:15 -07:00
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::RGB565;
|
2010-10-15 14:50:15 -07:00
|
|
|
default:
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(false, "Coding mistake?! Should never reach this point.");
|
2012-05-07 10:05:32 -07:00
|
|
|
return WebGLTexelConversions::BadFormat;
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
GLenum
|
|
|
|
InternalFormatForFormatAndType(GLenum format, GLenum type, bool isGLES2)
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
|
|
|
// ES2 requires that format == internalformat; floating-point is
|
|
|
|
// indicated purely by the type that's loaded. For desktop GL, we
|
|
|
|
// have to specify a floating point internal format.
|
|
|
|
if (isGLES2)
|
|
|
|
return format;
|
|
|
|
|
2012-08-13 18:17:55 -07:00
|
|
|
if (format == LOCAL_GL_DEPTH_COMPONENT) {
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_SHORT)
|
|
|
|
return LOCAL_GL_DEPTH_COMPONENT16;
|
|
|
|
else if (type == LOCAL_GL_UNSIGNED_INT)
|
|
|
|
return LOCAL_GL_DEPTH_COMPONENT32;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == LOCAL_GL_DEPTH_STENCIL) {
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_INT_24_8_EXT)
|
|
|
|
return LOCAL_GL_DEPTH24_STENCIL8;
|
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
return format;
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
return LOCAL_GL_RGBA32F_ARB;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
return LOCAL_GL_RGB32F_ARB;
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
return LOCAL_GL_ALPHA32F_ARB;
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
return LOCAL_GL_LUMINANCE32F_ARB;
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
return LOCAL_GL_LUMINANCE_ALPHA32F_ARB;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding mistake -- bad format/type passed?");
|
2011-05-20 12:53:53 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-11 13:57:30 -08:00
|
|
|
void
|
|
|
|
WebGLContext::ReattachTextureToAnyFramebufferToWorkAroundBugs(WebGLTexture *tex,
|
2013-09-04 05:14:43 -07:00
|
|
|
GLint level)
|
2012-12-11 13:57:30 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(tex);
|
|
|
|
|
|
|
|
if (!gl->WorkAroundDriverBugs())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mIsMesa)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2013-08-05 15:11:43 -07:00
|
|
|
WebGLFramebuffer* curFB = mBoundFramebuffer;
|
2012-12-11 13:57:30 -08:00
|
|
|
|
|
|
|
for(WebGLFramebuffer *framebuffer = mFramebuffers.getFirst();
|
|
|
|
framebuffer;
|
|
|
|
framebuffer = framebuffer->getNext())
|
|
|
|
{
|
2013-06-21 16:44:17 -07:00
|
|
|
size_t colorAttachmentCount = framebuffer->mColorAttachments.Length();
|
|
|
|
for (size_t i = 0; i < colorAttachmentCount; i++)
|
|
|
|
{
|
|
|
|
if (framebuffer->ColorAttachment(i).Texture() == tex) {
|
2013-08-05 15:11:43 -07:00
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER, framebuffer);
|
2013-06-21 16:44:17 -07:00
|
|
|
framebuffer->FramebufferTexture2D(
|
|
|
|
LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0 + i,
|
|
|
|
tex->Target(), tex, level);
|
|
|
|
}
|
2012-12-11 13:57:30 -08:00
|
|
|
}
|
|
|
|
if (framebuffer->DepthAttachment().Texture() == tex) {
|
2013-08-05 15:11:43 -07:00
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER, framebuffer);
|
2012-12-11 13:57:30 -08:00
|
|
|
framebuffer->FramebufferTexture2D(
|
|
|
|
LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_ATTACHMENT,
|
|
|
|
tex->Target(), tex, level);
|
|
|
|
}
|
|
|
|
if (framebuffer->StencilAttachment().Texture() == tex) {
|
2013-08-05 15:11:43 -07:00
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER, framebuffer);
|
2012-12-11 13:57:30 -08:00
|
|
|
framebuffer->FramebufferTexture2D(
|
|
|
|
LOCAL_GL_FRAMEBUFFER, LOCAL_GL_STENCIL_ATTACHMENT,
|
|
|
|
tex->Target(), tex, level);
|
|
|
|
}
|
|
|
|
if (framebuffer->DepthStencilAttachment().Texture() == tex) {
|
2013-08-05 15:11:43 -07:00
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER, framebuffer);
|
2012-12-11 13:57:30 -08:00
|
|
|
framebuffer->FramebufferTexture2D(
|
|
|
|
LOCAL_GL_FRAMEBUFFER, LOCAL_GL_DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
tex->Target(), tex, level);
|
|
|
|
}
|
|
|
|
}
|
2013-08-05 15:11:43 -07:00
|
|
|
|
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER, curFB);
|
2012-12-11 13:57:30 -08:00
|
|
|
}
|
2013-09-04 05:14:50 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BlendColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendColor(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Flush() {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Finish() {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::LineWidth(GLfloat width) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fLineWidth(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::PolygonOffset(GLfloat factor, GLfloat units) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPolygonOffset(factor, units);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::SampleCoverage(GLclampf value, WebGLboolean invert) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fSampleCoverage(value, invert);
|
2013-09-19 14:59:44 -07:00
|
|
|
}
|