2012-03-16 02:50:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-09-17 23:01:12 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
|
|
|
* Mark Steele <mwsteele@gmail.com>
|
2010-05-15 06:55:45 -07:00
|
|
|
* Cedric Vivier <cedricv@neonux.com>
|
2009-09-17 23:01:12 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
//#include "nsIDOMHTMLCanvasElement.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#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"
|
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"
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
using namespace mozilla;
|
2012-03-11 00:54:24 -08:00
|
|
|
using namespace mozilla::dom;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool BaseTypeAndSizeFromUniformType(WebGLenum uType, WebGLenum *baseType, WebGLint *unitSize);
|
2011-05-20 12:53:53 -07:00
|
|
|
static WebGLenum InternalFormatForFormatAndType(WebGLenum format, WebGLenum type, bool isGLES2);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
/* Helper macros for when we're just wrapping a gl method, so that
|
|
|
|
* we can avoid having to type this 500 times. Note that these MUST
|
|
|
|
* NOT BE USED if we need to check any of the parameters.
|
|
|
|
*/
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#define GL_SAME_METHOD_0(glname, name) \
|
|
|
|
NS_IMETHODIMP WebGLContext::Moz##name() { \
|
|
|
|
name(); \
|
|
|
|
return NS_OK; \
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#define GL_SAME_METHOD_1(glname, name, t1) \
|
|
|
|
NS_IMETHODIMP WebGLContext::Moz##name(t1 a1) { \
|
|
|
|
name(a1); \
|
|
|
|
return NS_OK; \
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#define GL_SAME_METHOD_2(glname, name, t1, t2) \
|
|
|
|
NS_IMETHODIMP WebGLContext::Moz##name(t1 a1, t2 a2) { \
|
|
|
|
name(a1, a2); \
|
|
|
|
return NS_OK; \
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#define GL_SAME_METHOD_3(glname, name, t1, t2, t3) \
|
|
|
|
NS_IMETHODIMP WebGLContext::Moz##name(t1 a1, t2 a2, t3 a3) { \
|
|
|
|
name(a1, a2, a3); \
|
|
|
|
return NS_OK; \
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
#define GL_SAME_METHOD_4(glname, name, t1, t2, t3, t4) \
|
|
|
|
NS_IMETHODIMP WebGLContext::Moz##name(t1 a1, t2 a2, t3 a3, t4 a4) { \
|
|
|
|
name(a1, a2, a3, a4); \
|
|
|
|
return NS_OK; \
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// WebGL API
|
|
|
|
//
|
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-05-28 15:52:39 -07:00
|
|
|
/* void GlActiveTexture (in GLenum texture); */
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozActiveTexture(WebGLenum texture)
|
|
|
|
{
|
|
|
|
ActiveTexture(texture);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::ActiveTexture(WebGLenum texture)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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-04-10 09:23:23 -07:00
|
|
|
texture >= LOCAL_GL_TEXTURE0 + PRUint32(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::AttachShader(nsIWebGLProgram *pobj, nsIWebGLShader *shobj)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
AttachShader(static_cast<WebGLProgram*>(pobj),
|
|
|
|
static_cast<WebGLShader*>(shobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::AttachShader(WebGLProgram *program, WebGLShader *shader)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
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()))
|
|
|
|
return ErrorInvalidOperation("AttachShader: only one of each type of shader may be attached to a program");
|
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
if (!program->AttachShader(shader))
|
|
|
|
return ErrorInvalidOperation("AttachShader: shader is already attached");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::BindAttribLocation(nsIWebGLProgram *pobj, WebGLuint location, const nsAString& name)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
BindAttribLocation(static_cast<WebGLProgram*>(pobj), location, name);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BindAttribLocation(WebGLProgram *prog, WebGLuint location,
|
|
|
|
const nsAString& name)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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;
|
|
|
|
|
|
|
|
WebGLuint 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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::BindBuffer(WebGLenum target, nsIWebGLBuffer *bobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
BindBuffer(target, static_cast<WebGLBuffer*>(bobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BindBuffer(WebGLenum target, WebGLBuffer *buf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-04-21 13:48:22 -07:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindBuffer", buf))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLuint bufname = buf ? buf->GLName() : 0;
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// silently ignore a deleted buffer
|
2012-05-04 09:38:44 -07:00
|
|
|
if (buf && buf->IsDeleted())
|
|
|
|
return;
|
2009-12-06 16:07:58 -08:00
|
|
|
|
2011-05-16 14:18:04 -07:00
|
|
|
if (target != LOCAL_GL_ARRAY_BUFFER &&
|
|
|
|
target != LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
{
|
|
|
|
return ErrorInvalidEnumInfo("bindBuffer: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (buf) {
|
2010-06-01 23:09:18 -07:00
|
|
|
if ((buf->Target() != LOCAL_GL_NONE) && (target != buf->Target()))
|
|
|
|
return ErrorInvalidOperation("BindBuffer: buffer already bound to a different target");
|
|
|
|
buf->SetTarget(target);
|
2011-10-17 07:59:28 -07:00
|
|
|
buf->SetHasEverBeenBound(true);
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 14:18:04 -07:00
|
|
|
// we really want to do this AFTER all the validation is done, otherwise our bookkeeping could get confused.
|
|
|
|
// see bug 656752
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
mBoundArrayBuffer = buf;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
mBoundElementArrayBuffer = buf;
|
|
|
|
}
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fBindBuffer(target, bufname);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::BindFramebuffer(WebGLenum target, nsIWebGLFramebuffer *fbobj)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
BindFramebuffer(target, static_cast<WebGLFramebuffer*>(fbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BindFramebuffer(WebGLenum target, WebGLFramebuffer *wfb)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 05:07:30 -07:00
|
|
|
if (target != LOCAL_GL_FRAMEBUFFER)
|
2010-09-02 07:38:26 -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) {
|
2010-07-18 22:01:14 -07:00
|
|
|
gl->fBindFramebuffer(target, gl->GetOffscreenFBO());
|
|
|
|
} else {
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::BindRenderbuffer(WebGLenum target, nsIWebGLRenderbuffer *rbobj)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
BindRenderbuffer(target, static_cast<WebGLRenderbuffer*>(rbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BindRenderbuffer(WebGLenum target, WebGLRenderbuffer *wrb)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
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();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint renderbuffername = wrb ? wrb->GLName() : 0;
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fBindRenderbuffer(target, renderbuffername);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::BindTexture(WebGLenum target, nsIWebGLTexture *tobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
BindTexture(target, static_cast<WebGLTexture*>(tobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BindTexture(WebGLenum target, WebGLTexture *tex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-04-21 13:48:22 -07:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowDeletedOrNull("bindTexture", tex))
|
|
|
|
return;
|
2011-09-01 12:28:34 -07:00
|
|
|
|
|
|
|
// silently ignore a deleted texture
|
2012-05-04 09:38:44 -07:00
|
|
|
if (tex && tex->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
if (target == LOCAL_GL_TEXTURE_2D) {
|
2010-05-19 13:46:08 -07:00
|
|
|
mBound2DTextures[mActiveTexture] = tex;
|
2009-09-02 17:47:49 -07:00
|
|
|
} else if (target == LOCAL_GL_TEXTURE_CUBE_MAP) {
|
2010-05-19 13:46:08 -07:00
|
|
|
mBoundCubeMapTextures[mActiveTexture] = tex;
|
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
|
|
|
}
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
if (tex)
|
|
|
|
tex->Bind(target);
|
|
|
|
else
|
|
|
|
gl->fBindTexture(target, 0 /* == texturename */);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
GL_SAME_METHOD_4(BlendColor, BlendColor, WebGLclampf, WebGLclampf, WebGLclampf, WebGLclampf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP WebGLContext::MozBlendEquation(WebGLenum mode)
|
|
|
|
{
|
|
|
|
BlendEquation(mode);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void WebGLContext::BlendEquation(WebGLenum mode)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP WebGLContext::MozBlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha)
|
|
|
|
{
|
|
|
|
BlendEquationSeparate(modeRGB, modeAlpha);
|
2010-06-19 07:48:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void WebGLContext::BlendEquationSeparate(WebGLenum modeRGB, WebGLenum modeAlpha)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP WebGLContext::MozBlendFunc(WebGLenum sfactor, WebGLenum dfactor)
|
|
|
|
{
|
|
|
|
BlendFunc(sfactor, dfactor);
|
2010-06-19 07:48:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void WebGLContext::BlendFunc(WebGLenum sfactor, WebGLenum dfactor)
|
2010-06-19 07:48:44 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozBlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
|
|
|
|
WebGLenum srcAlpha, WebGLenum dstAlpha)
|
|
|
|
{
|
|
|
|
BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-19 07:48:44 -07:00
|
|
|
WebGLContext::BlendFuncSeparate(WebGLenum srcRGB, WebGLenum dstRGB,
|
|
|
|
WebGLenum srcAlpha, WebGLenum dstAlpha)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
GLenum WebGLContext::CheckedBufferData(GLenum target,
|
|
|
|
GLsizeiptr size,
|
|
|
|
const GLvoid *data,
|
|
|
|
GLenum usage)
|
|
|
|
{
|
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(boundBuffer != nsnull, "no buffer bound for this target");
|
|
|
|
|
|
|
|
bool sizeChanges = PRUint32(size) != boundBuffer->ByteLength();
|
|
|
|
if (sizeChanges) {
|
|
|
|
UpdateWebGLErrorAndClearGLError();
|
|
|
|
gl->fBufferData(target, size, data, usage);
|
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
return error;
|
|
|
|
} else {
|
|
|
|
gl->fBufferData(target, size, data, usage);
|
|
|
|
return LOCAL_GL_NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-03-16 02:50:00 -07:00
|
|
|
WebGLContext::BufferData(PRInt32 target, const JS::Value& data, PRInt32 usage,
|
|
|
|
JSContext* cx)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-03-16 02:50:00 -07:00
|
|
|
if (data.isNull()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
BufferData(target, static_cast<ArrayBuffer*>(nsnull), usage);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:00 -07:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-03-16 02:50:00 -07:00
|
|
|
if (data.isObject()) {
|
|
|
|
JSObject& dataObj = data.toObject();
|
2012-01-14 09:43:00 -08:00
|
|
|
if (JS_IsArrayBufferObject(&dataObj, cx)) {
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBuffer buf(cx, &dataObj);
|
|
|
|
BufferData(target, &buf, usage);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:00 -07:00
|
|
|
}
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
if (JS_IsTypedArrayObject(&dataObj, cx)) {
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBufferView view(cx, &dataObj);
|
|
|
|
BufferData(target, view, usage);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:00 -07:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidValue("bufferData: object passed that is not an "
|
|
|
|
"ArrayBufferView or ArrayBuffer");
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:00 -07:00
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2012-03-16 02:50:00 -07:00
|
|
|
MOZ_ASSERT(data.isPrimitive());
|
|
|
|
int32_t size;
|
|
|
|
// ToInt32 cannot fail for primitives.
|
|
|
|
MOZ_ALWAYS_TRUE(JS_ValueToECMAInt32(cx, data, &size));
|
2012-05-04 09:38:44 -07:00
|
|
|
BufferData(target, WebGLsizeiptr(size), usage);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:00 -07:00
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BufferData(WebGLenum target, WebGLsizeiptr size,
|
|
|
|
WebGLenum usage)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bufferData: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-07-03 15:34:07 -07:00
|
|
|
if (size < 0)
|
|
|
|
return ErrorInvalidValue("bufferData: negative size");
|
|
|
|
|
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-03 15:34:07 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("BufferData: no buffer bound!");
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2011-07-07 17:01:16 -07:00
|
|
|
|
|
|
|
GLenum error = CheckedBufferData(target, size, 0, usage);
|
|
|
|
if (error) {
|
|
|
|
LogMessageIfVerbose("bufferData generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
boundBuffer->SetByteLength(size);
|
2011-07-07 17:01:16 -07:00
|
|
|
boundBuffer->InvalidateCachedMaxElements();
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!boundBuffer->ZeroDataIfElementArray())
|
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BufferData(WebGLenum target, ArrayBuffer *data, WebGLenum usage)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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 (!data) {
|
|
|
|
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
|
|
|
return ErrorInvalidValue("bufferData: null object passed");
|
|
|
|
}
|
2012-01-14 09:43:00 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
2009-11-01 16:33:39 -08:00
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bufferData: target", target);
|
2009-11-01 16:33:39 -08:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-03 15:34:07 -07:00
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-03 15:34:07 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("BufferData: no buffer bound!");
|
2010-01-22 13:34:25 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
GLenum error = CheckedBufferData(target, data->mLength, data->mData, usage);
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (error) {
|
|
|
|
LogMessageIfVerbose("bufferData generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
boundBuffer->SetByteLength(data->mLength);
|
2011-07-07 17:01:16 -07:00
|
|
|
boundBuffer->InvalidateCachedMaxElements();
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!boundBuffer->CopyDataIfElementArray(data->mData))
|
2011-02-24 14:17:34 -08:00
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BufferData(WebGLenum target, ArrayBufferView& data, WebGLenum usage)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bufferData: target", target);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2010-07-03 15:34:07 -07:00
|
|
|
if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-03 15:34:07 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("BufferData: no buffer bound!");
|
2010-01-22 13:34:25 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
GLenum error = CheckedBufferData(target, data.mLength, data.mData, usage);
|
2011-07-07 17:01:16 -07:00
|
|
|
if (error) {
|
|
|
|
LogMessageIfVerbose("bufferData generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
boundBuffer->SetByteLength(data.mLength);
|
2011-07-07 17:01:16 -07:00
|
|
|
boundBuffer->InvalidateCachedMaxElements();
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!boundBuffer->CopyDataIfElementArray(data.mData))
|
2011-02-24 14:17:34 -08:00
|
|
|
return ErrorOutOfMemory("bufferData: out of memory");
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
NS_IMETHODIMP
|
2012-01-14 09:43:00 -08:00
|
|
|
WebGLContext::BufferSubData(PRInt32 target, PRInt32 offset, const JS::Value& data, JSContext *cx)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-04-21 13:48:22 -07:00
|
|
|
if (!IsContextStable())
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-03-16 02:50:18 -07:00
|
|
|
if (data.isNull()) {
|
2012-05-04 09:38:44 -07:00
|
|
|
BufferSubData(target, offset, nsnull);
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
2012-03-16 02:50:18 -07:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-03-16 02:50:18 -07:00
|
|
|
if (!data.isObject()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-03-16 02:50:18 -07:00
|
|
|
JSObject& dataObj = data.toObject();
|
2012-01-14 09:43:00 -08:00
|
|
|
if (JS_IsArrayBufferObject(&dataObj, cx)) {
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBuffer buf(cx, &dataObj);
|
|
|
|
BufferSubData(target, offset, &buf);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:18 -07:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
if (JS_IsTypedArrayObject(&dataObj, cx)) {
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBufferView view(cx, &dataObj);
|
|
|
|
BufferSubData(target, offset, view);
|
|
|
|
return NS_OK;
|
2012-03-16 02:50:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BufferSubData(GLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
ArrayBuffer *data)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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 (!data) {
|
|
|
|
// see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
|
|
|
|
return;
|
|
|
|
}
|
2012-01-14 09:43:00 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
if (byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("bufferSubData: negative offset");
|
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (!boundBuffer)
|
|
|
|
return ErrorInvalidOperation("BufferData: no buffer bound!");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data->mLength;
|
2010-07-03 15:32:19 -07:00
|
|
|
if (!checked_neededByteLength.valid())
|
|
|
|
return ErrorInvalidOperation("bufferSubData: integer overflow computing the needed byte length");
|
|
|
|
|
|
|
|
if (checked_neededByteLength.value() > boundBuffer->ByteLength())
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidOperation("BufferSubData: not enough data - operation requires %d bytes, but buffer only has %d bytes",
|
2012-05-04 09:38:44 -07:00
|
|
|
checked_neededByteLength.value(), boundBuffer->ByteLength());
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
MakeContextCurrent();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
boundBuffer->CopySubDataIfElementArray(byteOffset, data->mLength, data->mData);
|
2011-01-25 19:19:46 -08:00
|
|
|
boundBuffer->InvalidateCachedMaxElements();
|
2010-06-01 23:09:18 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
gl->fBufferSubData(target, byteOffset, data->mLength, data->mData);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::BufferSubData(WebGLenum target, WebGLsizeiptr byteOffset,
|
|
|
|
ArrayBufferView& data)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2012-01-14 09:43:00 -08:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
WebGLBuffer *boundBuffer = NULL;
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundArrayBuffer;
|
|
|
|
} else if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER) {
|
|
|
|
boundBuffer = mBoundElementArrayBuffer;
|
2009-11-01 16:33:39 -08:00
|
|
|
} else {
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("bufferSubData: target", target);
|
2009-11-01 16:33:39 -08:00
|
|
|
}
|
2009-10-30 01:09:24 -07:00
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
if (byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("bufferSubData: negative offset");
|
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (!boundBuffer)
|
2012-05-04 09:38:44 -07:00
|
|
|
return ErrorInvalidOperation("BufferSubData: no buffer bound!");
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
CheckedUint32 checked_neededByteLength = CheckedUint32(byteOffset) + data.mLength;
|
2010-07-03 15:32:19 -07:00
|
|
|
if (!checked_neededByteLength.valid())
|
|
|
|
return ErrorInvalidOperation("bufferSubData: integer overflow computing the needed byte length");
|
|
|
|
|
|
|
|
if (checked_neededByteLength.value() > boundBuffer->ByteLength())
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidOperation("BufferSubData: not enough data -- operation requires %d bytes, but buffer only has %d bytes",
|
2012-05-04 09:38:44 -07:00
|
|
|
checked_neededByteLength.value(), boundBuffer->ByteLength());
|
2010-01-22 13:34:25 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
boundBuffer->CopySubDataIfElementArray(byteOffset, data.mLength, data.mData);
|
2011-01-25 19:19:46 -08:00
|
|
|
boundBuffer->InvalidateCachedMaxElements();
|
2010-06-01 23:09:18 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
gl->fBufferSubData(target, byteOffset, data.mLength, data.mData);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::CheckFramebufferStatus(WebGLenum target, WebGLenum *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = CheckFramebufferStatus(target);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLenum
|
|
|
|
WebGLContext::CheckFramebufferStatus(WebGLenum target)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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;
|
|
|
|
if(!mBoundFramebuffer->ColorAttachment().IsDefined())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
|
|
if(mBoundFramebuffer->HasIncompleteAttachment())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
|
|
if(mBoundFramebuffer->HasAttachmentsOfMismatchedDimensions())
|
|
|
|
return LOCAL_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
|
|
|
|
return gl->fCheckFramebufferStatus(target);
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozClear(PRUint32 mask)
|
|
|
|
{
|
|
|
|
Clear(mask);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::Clear(WebGLbitfield mask)
|
2009-11-01 16:33:39 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2009-11-01 16:33:39 -08:00
|
|
|
MakeContextCurrent();
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2010-11-16 20:33:04 -08:00
|
|
|
PRUint32 m = mask & (LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mask != m)
|
2010-11-16 20:33:04 -08:00
|
|
|
return ErrorInvalidValue("clear: invalid mask bits");
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needClearCallHere = true;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
|
|
if (mBoundFramebuffer) {
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("clear: incomplete framebuffer");
|
2011-05-20 12:53:53 -07:00
|
|
|
} else {
|
|
|
|
// no FBO is bound, so we are clearing the backbuffer here
|
|
|
|
EnsureBackbufferClearedAsNeeded();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool valuesAreDefault = mColorClearValue[0] == 0.0f &&
|
2011-05-20 12:53:53 -07:00
|
|
|
mColorClearValue[1] == 0.0f &&
|
|
|
|
mColorClearValue[2] == 0.0f &&
|
|
|
|
mColorClearValue[3] == 0.0f &&
|
|
|
|
mDepthClearValue == 1.0f &&
|
|
|
|
mStencilClearValue == 0;
|
|
|
|
if (valuesAreDefault &&
|
|
|
|
mBackbufferClearingStatus == BackbufferClearingStatus::ClearedToDefaultValues)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
needClearCallHere = false;
|
2011-05-20 12:53:53 -07:00
|
|
|
}
|
2010-11-16 20:33:04 -08:00
|
|
|
}
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (needClearCallHere) {
|
|
|
|
gl->fClear(mask);
|
|
|
|
mBackbufferClearingStatus = BackbufferClearingStatus::HasBeenDrawnTo;
|
|
|
|
Invalidate();
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-11-01 16:33:39 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozClearColor(WebGLfloat r, WebGLfloat g, WebGLfloat b, WebGLfloat a)
|
|
|
|
{
|
|
|
|
ClearColor(r, g, b, a);
|
2009-11-01 16:33:39 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ClearColor(WebGLclampf r, WebGLclampf g,
|
|
|
|
WebGLclampf b, WebGLclampf a)
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
mColorClearValue[0] = r;
|
|
|
|
mColorClearValue[1] = g;
|
|
|
|
mColorClearValue[2] = b;
|
|
|
|
mColorClearValue[3] = a;
|
|
|
|
gl->fClearColor(r, g, b, a);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozClearDepth(WebGLfloat v)
|
|
|
|
{
|
|
|
|
ClearDepth(v);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ClearDepth(WebGLclampf v)
|
2011-05-20 12:53:53 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
mDepthClearValue = v;
|
|
|
|
gl->fClearDepth(v);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozClearStencil(WebGLint v)
|
|
|
|
{
|
|
|
|
ClearStencil(v);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-20 12:53:53 -07:00
|
|
|
WebGLContext::ClearStencil(WebGLint v)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
mStencilClearValue = v;
|
|
|
|
gl->fClearStencil(v);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a)
|
|
|
|
{
|
|
|
|
ColorMask(r, g, b, a);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-20 12:53:53 -07:00
|
|
|
WebGLContext::ColorMask(WebGLboolean r, WebGLboolean g, WebGLboolean b, WebGLboolean a)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
mColorWriteMask[0] = r;
|
|
|
|
mColorWriteMask[1] = g;
|
|
|
|
mColorWriteMask[2] = b;
|
|
|
|
mColorWriteMask[3] = a;
|
|
|
|
gl->fColorMask(r, g, b, a);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2011-01-06 14:07:13 -08:00
|
|
|
WebGLContext::CopyTexSubImage2D_base(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLenum internalformat,
|
|
|
|
WebGLint xoffset,
|
|
|
|
WebGLint yoffset,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height,
|
|
|
|
bool sub)
|
|
|
|
{
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject();
|
|
|
|
WebGLsizei framebufferWidth = framebufferRect ? framebufferRect->Width() : 0;
|
|
|
|
WebGLsizei framebufferHeight = framebufferRect ? framebufferRect->Height() : 0;
|
2011-01-06 14:07:13 -08:00
|
|
|
|
|
|
|
const char *info = sub ? "copyTexSubImage2D" : "copyTexImage2D";
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
PRUint32 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
|
|
|
|
|
|
|
if (!checked_neededByteLength.valid())
|
|
|
|
return ErrorInvalidOperation("%s: integer overflow computing the needed buffer size", info);
|
|
|
|
|
|
|
|
PRUint32 bytesNeeded = checked_neededByteLength.value();
|
|
|
|
|
|
|
|
// now that the size is known, create the buffer
|
|
|
|
|
|
|
|
// We need some zero pages, because GL doesn't guarantee the
|
|
|
|
// contents of a texture allocated with NULL data.
|
|
|
|
// 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-05-04 09:38:44 -07:00
|
|
|
}
|
2011-01-06 14:07:13 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozCopyTexImage2D(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLenum internalformat,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height,
|
|
|
|
WebGLint border)
|
|
|
|
{
|
|
|
|
CopyTexImage2D(target, level, internalformat, x, y, width, height, border);
|
2011-01-06 14:07:13 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::CopyTexImage2D(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLenum internalformat,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height,
|
|
|
|
WebGLint border)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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:
|
2010-07-16 07:31:48 -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
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
|
|
|
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;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment().HasAlpha()
|
|
|
|
: bool(gl->ActualFormat().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-01-24 13:12:31 -08:00
|
|
|
if (mBoundFramebuffer)
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
|
|
|
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;
|
|
|
|
size_t face = WebGLTexture::FaceForTarget(target);
|
|
|
|
if (tex->HasImageInfoAt(level, face)) {
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(level, face);
|
|
|
|
|
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) {
|
|
|
|
LogMessageIfVerbose("copyTexImage2D generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:17 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CopyTexSubImage2D_base(target, level, internalformat, 0, 0, x, y, width, height, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex->SetImageInfo(target, level, width, height, internalformat, type);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozCopyTexSubImage2D(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLint xoffset,
|
|
|
|
WebGLint yoffset,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height)
|
|
|
|
{
|
|
|
|
CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::CopyTexSubImage2D(WebGLenum target,
|
|
|
|
WebGLint level,
|
|
|
|
WebGLint xoffset,
|
|
|
|
WebGLint yoffset,
|
|
|
|
WebGLint x,
|
|
|
|
WebGLint y,
|
|
|
|
WebGLsizei width,
|
|
|
|
WebGLsizei height)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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("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");
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
|
|
|
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");
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLint face = WebGLTexture::FaceForTarget(target);
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!tex->HasImageInfoAt(level, face))
|
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
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(level, face);
|
|
|
|
WebGLsizei texWidth = imageInfo.Width();
|
|
|
|
WebGLsizei 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");
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLenum 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;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool fboFormatHasAlpha = mBoundFramebuffer ? mBoundFramebuffer->ColorAttachment().HasAlpha()
|
|
|
|
: bool(gl->ActualFormat().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-01-24 13:12:31 -08:00
|
|
|
if (mBoundFramebuffer)
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
|
|
|
return ErrorInvalidFramebufferOperation("copyTexSubImage2D: incomplete framebuffer");
|
2010-12-06 03:34:35 -08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::CreateProgram(nsIWebGLProgram **retval)
|
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = CreateProgram().get();
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLProgram>
|
|
|
|
WebGLContext::CreateProgram()
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
|
|
|
nsRefPtr<WebGLProgram> globj = new WebGLProgram(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::CreateShader(WebGLenum type, nsIWebGLShader **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = CreateShader(type).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLShader>
|
|
|
|
WebGLContext::CreateShader(WebGLenum type)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
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);
|
|
|
|
return nsnull;
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozCullFace(WebGLenum face)
|
|
|
|
{
|
|
|
|
CullFace(face);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-07-03 15:33:05 -07:00
|
|
|
WebGLContext::CullFace(WebGLenum face)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteBuffer(nsIWebGLBuffer *bobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteBuffer(static_cast<WebGLBuffer*>(bobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteBuffer(WebGLBuffer *buf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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("deleteBuffer", buf))
|
|
|
|
return;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!buf || buf->IsDeleted())
|
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
if (mBoundArrayBuffer == buf)
|
2012-05-04 09:38:44 -07:00
|
|
|
BindBuffer(LOCAL_GL_ARRAY_BUFFER,
|
|
|
|
static_cast<WebGLBuffer*>(nsnull));
|
2011-12-04 11:15:42 -08:00
|
|
|
if (mBoundElementArrayBuffer == buf)
|
2012-05-04 09:38:44 -07:00
|
|
|
BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER,
|
|
|
|
static_cast<WebGLBuffer*>(nsnull));
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
for (int i = 0; i < mGLMaxVertexAttribs; i++) {
|
|
|
|
if (mAttribBuffers[i].buf == buf)
|
|
|
|
mAttribBuffers[i].buf = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf->RequestDelete();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteFramebuffer(nsIWebGLFramebuffer *fbobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteFramebuffer(static_cast<WebGLFramebuffer*>(fbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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,
|
|
|
|
static_cast<WebGLFramebuffer*>(nsnull));
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteRenderbuffer(nsIWebGLRenderbuffer *rbobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteRenderbuffer(static_cast<WebGLRenderbuffer*>(rbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer *rbuf)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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,
|
|
|
|
static_cast<WebGLRenderbuffer*>(nsnull));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteTexture(nsIWebGLTexture *tobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteTexture(static_cast<WebGLTexture*>(tobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteTexture(WebGLTexture *tex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
|
2011-12-04 11:15:42 -08:00
|
|
|
for (int i = 0; i < mGLMaxTextureUnits; i++) {
|
|
|
|
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-05-04 09:38:44 -07:00
|
|
|
BindTexture(tex->Target(), static_cast<WebGLTexture*>(nsnull));
|
2011-12-04 11:15:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteProgram(nsIWebGLProgram *pobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteProgram(static_cast<WebGLProgram*>(pobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DeleteShader(nsIWebGLShader *sobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DeleteShader(static_cast<WebGLShader*>(sobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DeleteShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::DetachShader(nsIWebGLProgram *pobj, nsIWebGLShader *shobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
DetachShader(static_cast<WebGLProgram*>(pobj),
|
|
|
|
static_cast<WebGLShader*>(shobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::DetachShader(WebGLProgram *program, WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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))
|
|
|
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozDepthFunc(WebGLenum func)
|
|
|
|
{
|
|
|
|
DepthFunc(func);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::DepthFunc(WebGLenum func)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozDepthMask(WebGLboolean b)
|
|
|
|
{
|
|
|
|
DepthMask(b);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-20 12:53:53 -07:00
|
|
|
WebGLContext::DepthMask(WebGLboolean b)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
mDepthWriteMask = b;
|
|
|
|
gl->fDepthMask(b);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozDepthRange(WebGLclampf zNear, WebGLclampf zFar)
|
|
|
|
{
|
|
|
|
DepthRange(zNear, zFar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLContext::DepthRange(WebGLfloat zNear, WebGLfloat zFar)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozDisableVertexAttribArray(WebGLuint index)
|
|
|
|
{
|
|
|
|
DisableVertexAttribArray(index);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::DisableVertexAttribArray(WebGLuint index)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(index, "disableVertexAttribArray"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
if (index || gl->IsGLES2())
|
|
|
|
gl->fDisableVertexAttribArray(index);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mAttribBuffers[index].enabled = false;
|
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() &&
|
|
|
|
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
|
|
|
|
|
|
|
|
return (gl->IsGLES2() || mAttribBuffers[0].enabled) ? VertexAttrib0Status::Default
|
|
|
|
: mCurrentProgram->IsAttribInUse(0) ? VertexAttrib0Status::EmulatedInitializedArray
|
|
|
|
: VertexAttrib0Status::EmulatedUninitializedArray;
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-21 23:55:10 -07:00
|
|
|
bool
|
2010-09-02 07:34:08 -07:00
|
|
|
WebGLContext::DoFakeVertexAttrib0(WebGLuint vertexCount)
|
|
|
|
{
|
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
|
|
|
|
2011-09-21 23:55:10 -07:00
|
|
|
CheckedUint32 checked_dataSize = CheckedUint32(vertexCount) * 4 * sizeof(WebGLfloat);
|
|
|
|
|
|
|
|
if (!checked_dataSize.valid()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLuint 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) {
|
|
|
|
nsAutoArrayPtr<WebGLfloat> array(new WebGLfloat[4 * vertexCount]);
|
|
|
|
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 {
|
|
|
|
gl->fBufferData(LOCAL_GL_ARRAY_BUFFER, dataSize, nsnull, LOCAL_GL_DYNAMIC_DRAW);
|
|
|
|
}
|
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
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
gl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mAttribBuffers[0].buf ? mAttribBuffers[0].buf->GLName() : 0);
|
2010-09-02 07:34:08 -07:00
|
|
|
gl->fVertexAttribPointer(0,
|
|
|
|
mAttribBuffers[0].size,
|
|
|
|
mAttribBuffers[0].type,
|
|
|
|
mAttribBuffers[0].normalized,
|
|
|
|
mAttribBuffers[0].stride,
|
2012-01-16 14:07:18 -08:00
|
|
|
reinterpret_cast<const GLvoid *>(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
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-23 14:03:53 -07:00
|
|
|
WebGLContext::NeedFakeBlack()
|
|
|
|
{
|
|
|
|
// handle this case first, it's the generic case
|
|
|
|
if (mFakeBlackStatus == DoNotNeedFakeBlack)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-23 14:03:53 -07:00
|
|
|
|
|
|
|
if (mFakeBlackStatus == DontKnowIfNeedFakeBlack) {
|
2011-01-31 13:10:49 -08:00
|
|
|
for (PRInt32 i = 0; i < mGLMaxTextureUnits; ++i) {
|
2010-08-23 14:03:53 -07:00
|
|
|
if ((mBound2DTextures[i] && mBound2DTextures[i]->NeedFakeBlack()) ||
|
|
|
|
(mBoundCubeMapTextures[i] && mBoundCubeMapTextures[i]->NeedFakeBlack()))
|
|
|
|
{
|
|
|
|
mFakeBlackStatus = DoNeedFakeBlack;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (mFakeBlackStatus == DontKnowIfNeedFakeBlack)
|
|
|
|
mFakeBlackStatus = DoNotNeedFakeBlack;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFakeBlackStatus == DoNeedFakeBlack;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::BindFakeBlackTextures()
|
|
|
|
{
|
|
|
|
// this is the generic case: try to return early
|
|
|
|
if (!NeedFakeBlack())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mBlackTexturesAreInitialized) {
|
2011-10-31 16:55:01 -07:00
|
|
|
GLuint bound2DTex = 0;
|
|
|
|
GLuint boundCubeTex = 0;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_2D, (GLint*) &bound2DTex);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, (GLint*) &boundCubeTex);
|
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
const PRUint8 black[] = {0, 0, 0, 255};
|
|
|
|
|
|
|
|
gl->fGenTextures(1, &mBlackTexture2D);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mBlackTexture2D);
|
|
|
|
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, 1, 1,
|
|
|
|
0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, &black);
|
|
|
|
|
|
|
|
gl->fGenTextures(1, &mBlackTextureCubeMap);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBlackTextureCubeMap);
|
|
|
|
for (WebGLuint i = 0; i < 6; ++i) {
|
|
|
|
gl->fTexImage2D(LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, LOCAL_GL_RGBA, 1, 1,
|
|
|
|
0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, &black);
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
// Reset bound textures
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, bound2DTex);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, boundCubeTex);
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mBlackTexturesAreInitialized = true;
|
2010-08-23 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
2011-01-31 13:10:49 -08:00
|
|
|
for (PRInt32 i = 0; i < mGLMaxTextureUnits; ++i) {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mBound2DTextures[i] && mBound2DTextures[i]->NeedFakeBlack()) {
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mBlackTexture2D);
|
|
|
|
}
|
|
|
|
if (mBoundCubeMapTextures[i] && mBoundCubeMapTextures[i]->NeedFakeBlack()) {
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBlackTextureCubeMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UnbindFakeBlackTextures()
|
|
|
|
{
|
|
|
|
// this is the generic case: try to return early
|
|
|
|
if (!NeedFakeBlack())
|
|
|
|
return;
|
|
|
|
|
2011-01-31 13:10:49 -08:00
|
|
|
for (PRInt32 i = 0; i < mGLMaxTextureUnits; ++i) {
|
2010-08-23 14:03:53 -07:00
|
|
|
if (mBound2DTextures[i] && mBound2DTextures[i]->NeedFakeBlack()) {
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mBound2DTextures[i]->GLName());
|
|
|
|
}
|
|
|
|
if (mBoundCubeMapTextures[i] && mBoundCubeMapTextures[i]->NeedFakeBlack()) {
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_CUBE_MAP, mBoundCubeMapTextures[i]->GLName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0 + mActiveTexture);
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozDrawArrays(GLenum mode, WebGLint first, WebGLsizei count)
|
|
|
|
{
|
|
|
|
DrawArrays(mode, first, count);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-01 23:09:18 -07:00
|
|
|
WebGLContext::DrawArrays(GLenum mode, WebGLint first, WebGLsizei count)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-07-16 07:31:48 -07:00
|
|
|
if (!ValidateDrawModeEnum(mode, "drawArrays: mode"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-08 15:14:43 -07:00
|
|
|
if (first < 0 || count < 0)
|
|
|
|
return ErrorInvalidValue("DrawArrays: negative first or count");
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ValidateStencilParamsForDrawCall())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2010-11-25 06:00:00 -08:00
|
|
|
// If count is 0, there's nothing to do.
|
|
|
|
if (count == 0)
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-11-25 06:00:00 -08:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
// If there is no current program, this is silently ignored.
|
|
|
|
// Any checks below this depend on a program being available.
|
|
|
|
if (!mCurrentProgram)
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2011-01-25 19:19:46 -08:00
|
|
|
PRInt32 maxAllowedCount = 0;
|
|
|
|
if (!ValidateBuffers(&maxAllowedCount, "drawArrays"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-01-25 19:19:46 -08:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedInt32 checked_firstPlusCount = CheckedInt32(first) + count;
|
|
|
|
|
|
|
|
if (!checked_firstPlusCount.valid())
|
|
|
|
return ErrorInvalidOperation("drawArrays: overflow in first+count");
|
2010-06-08 15:14:43 -07:00
|
|
|
|
2011-01-25 19:19:46 -08:00
|
|
|
if (checked_firstPlusCount.value() > maxAllowedCount)
|
|
|
|
return ErrorInvalidOperation("drawArrays: bound vertex attribute buffers do not have sufficient size for given first and count");
|
2010-07-16 07:30:31 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mBoundFramebuffer) {
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("drawArrays: incomplete framebuffer");
|
2011-05-20 12:53:53 -07:00
|
|
|
} else {
|
|
|
|
EnsureBackbufferClearedAsNeeded();
|
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
BindFakeBlackTextures();
|
2011-09-21 23:55:10 -07:00
|
|
|
if (!DoFakeVertexAttrib0(checked_firstPlusCount.value()))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
SetupContextLossTimer();
|
2010-06-01 23:09:18 -07:00
|
|
|
gl->fDrawArrays(mode, first, count);
|
2010-09-02 07:34:08 -07:00
|
|
|
|
|
|
|
UndoFakeVertexAttrib0();
|
2010-08-23 14:03:53 -07:00
|
|
|
UnbindFakeBlackTextures();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
mBackbufferClearingStatus = BackbufferClearingStatus::HasBeenDrawnTo;
|
2009-09-02 17:47:49 -07:00
|
|
|
Invalidate();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozDrawElements(WebGLenum mode, WebGLsizei count, WebGLenum type, WebGLintptr byteOffset)
|
|
|
|
{
|
|
|
|
DrawElements(mode, count, type, byteOffset);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::DrawElements(WebGLenum mode, WebGLsizei count, WebGLenum type,
|
|
|
|
WebGLintptr byteOffset)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-07-16 07:31:48 -07:00
|
|
|
if (!ValidateDrawModeEnum(mode, "drawElements: mode"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-08 15:14:43 -07:00
|
|
|
if (count < 0 || byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("DrawElements: negative count or offset");
|
2009-12-06 16:07:56 -08:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ValidateStencilParamsForDrawCall())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
2010-11-25 06:00:00 -08:00
|
|
|
// If count is 0, there's nothing to do.
|
|
|
|
if (count == 0)
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-11-25 06:00:00 -08:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedUint32 checked_byteCount;
|
2009-12-06 16:07:56 -08:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (type == LOCAL_GL_UNSIGNED_SHORT) {
|
|
|
|
checked_byteCount = 2 * CheckedUint32(count);
|
2010-06-08 15:14:43 -07:00
|
|
|
if (byteOffset % 2 != 0)
|
2011-01-06 14:07:13 -08:00
|
|
|
return ErrorInvalidOperation("DrawElements: invalid byteOffset for UNSIGNED_SHORT (must be a multiple of 2)");
|
2010-06-08 15:14:43 -07:00
|
|
|
} else if (type == LOCAL_GL_UNSIGNED_BYTE) {
|
2010-07-03 15:32:19 -07:00
|
|
|
checked_byteCount = count;
|
2010-06-08 15:14:43 -07:00
|
|
|
} else {
|
|
|
|
return ErrorInvalidEnum("DrawElements: type must be UNSIGNED_SHORT or UNSIGNED_BYTE");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (!checked_byteCount.valid())
|
|
|
|
return ErrorInvalidValue("DrawElements: overflow in byteCount");
|
|
|
|
|
2010-06-08 15:14:43 -07:00
|
|
|
// If there is no current program, this is silently ignored.
|
|
|
|
// Any checks below this depend on a program being available.
|
|
|
|
if (!mCurrentProgram)
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-08 15:14:43 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
if (!mBoundElementArrayBuffer)
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidOperation("DrawElements: must have element array buffer binding");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-11-14 09:26:26 -08:00
|
|
|
if (!mBoundElementArrayBuffer->Data())
|
|
|
|
return ErrorInvalidOperation("drawElements: bound element array buffer doesn't have any data");
|
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedUint32 checked_neededByteCount = checked_byteCount + byteOffset;
|
|
|
|
|
|
|
|
if (!checked_neededByteCount.valid())
|
2010-06-08 15:14:43 -07:00
|
|
|
return ErrorInvalidOperation("DrawElements: overflow in byteOffset+byteCount");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (checked_neededByteCount.value() > mBoundElementArrayBuffer->ByteLength())
|
2010-06-01 23:09:18 -07:00
|
|
|
return ErrorInvalidOperation("DrawElements: bound element array buffer is too small for given count and offset");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-01-25 19:19:46 -08:00
|
|
|
PRInt32 maxAllowedCount = 0;
|
|
|
|
if (!ValidateBuffers(&maxAllowedCount, "drawElements"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-01-25 19:19:46 -08:00
|
|
|
|
|
|
|
PRInt32 maxIndex
|
|
|
|
= type == LOCAL_GL_UNSIGNED_SHORT
|
|
|
|
? mBoundElementArrayBuffer->FindMaxUshortElement()
|
|
|
|
: mBoundElementArrayBuffer->FindMaxUbyteElement();
|
|
|
|
|
|
|
|
CheckedInt32 checked_maxIndexPlusOne = CheckedInt32(maxIndex) + 1;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-01-25 19:19:46 -08:00
|
|
|
if (!checked_maxIndexPlusOne.valid() ||
|
|
|
|
checked_maxIndexPlusOne.value() > maxAllowedCount)
|
|
|
|
{
|
|
|
|
// the index array contains invalid indices for the current drawing state, but they
|
|
|
|
// might not be used by the present drawElements call, depending on first and count.
|
|
|
|
|
|
|
|
PRInt32 maxIndexInSubArray
|
|
|
|
= type == LOCAL_GL_UNSIGNED_SHORT
|
|
|
|
? mBoundElementArrayBuffer->FindMaxElementInSubArray<GLushort>(count, byteOffset)
|
|
|
|
: mBoundElementArrayBuffer->FindMaxElementInSubArray<GLubyte>(count, byteOffset);
|
|
|
|
|
|
|
|
CheckedInt32 checked_maxIndexInSubArrayPlusOne = CheckedInt32(maxIndexInSubArray) + 1;
|
|
|
|
|
|
|
|
if (!checked_maxIndexInSubArrayPlusOne.valid() ||
|
|
|
|
checked_maxIndexInSubArrayPlusOne.value() > maxAllowedCount)
|
|
|
|
{
|
|
|
|
return ErrorInvalidOperation(
|
|
|
|
"DrawElements: bound vertex attribute buffers do not have sufficient "
|
|
|
|
"size for given indices from the bound element array");
|
|
|
|
}
|
2010-06-01 23:09:18 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:18 -07:00
|
|
|
MakeContextCurrent();
|
2009-12-06 16:07:56 -08:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
if (mBoundFramebuffer) {
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("drawElements: incomplete framebuffer");
|
2011-05-20 12:53:53 -07:00
|
|
|
} else {
|
|
|
|
EnsureBackbufferClearedAsNeeded();
|
|
|
|
}
|
2010-11-05 12:57:58 -07:00
|
|
|
|
2010-08-23 14:03:53 -07:00
|
|
|
BindFakeBlackTextures();
|
2011-09-21 23:55:10 -07:00
|
|
|
if (!DoFakeVertexAttrib0(checked_maxIndexPlusOne.value()))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
SetupContextLossTimer();
|
2012-01-16 14:07:18 -08:00
|
|
|
gl->fDrawElements(mode, count, type, reinterpret_cast<GLvoid*>(byteOffset));
|
2010-09-02 07:34:08 -07:00
|
|
|
|
|
|
|
UndoFakeVertexAttrib0();
|
2010-08-23 14:03:53 -07:00
|
|
|
UnbindFakeBlackTextures();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
mBackbufferClearingStatus = BackbufferClearingStatus::HasBeenDrawnTo;
|
2009-09-02 17:47:49 -07:00
|
|
|
Invalidate();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP WebGLContext::MozEnable(WebGLenum cap)
|
|
|
|
{
|
|
|
|
Enable(cap);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::Enable(WebGLenum cap)
|
2010-06-08 11:45:23 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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 (!ValidateCapabilityEnum(cap, "enable"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-08 11:45:23 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
switch(cap) {
|
|
|
|
case LOCAL_GL_SCISSOR_TEST:
|
|
|
|
mScissorTestEnabled = 1;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DITHER:
|
|
|
|
mDitherEnabled = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-08 11:45:23 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fEnable(cap);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP WebGLContext::MozDisable(WebGLenum cap)
|
|
|
|
{
|
|
|
|
Disable(cap);
|
2010-06-08 11:45:23 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::Disable(WebGLenum cap)
|
2010-06-08 11:45:23 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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 (!ValidateCapabilityEnum(cap, "disable"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-08 11:45:23 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
switch(cap) {
|
|
|
|
case LOCAL_GL_SCISSOR_TEST:
|
|
|
|
mScissorTestEnabled = 0;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DITHER:
|
|
|
|
mDitherEnabled = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-08 11:45:23 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fDisable(cap);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozEnableVertexAttribArray(WebGLuint index)
|
|
|
|
{
|
|
|
|
EnableVertexAttribArray(index);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::EnableVertexAttribArray(WebGLuint index)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(index, "enableVertexAttribArray"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fEnableVertexAttribArray(index);
|
2011-10-17 07:59:28 -07:00
|
|
|
mAttribBuffers[index].enabled = true;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::FramebufferRenderbuffer(WebGLenum target, WebGLenum attachment, WebGLenum rbtarget, nsIWebGLRenderbuffer *rbobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
FramebufferRenderbuffer(target, attachment, rbtarget,
|
|
|
|
static_cast<WebGLRenderbuffer*>(rbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::FramebufferRenderbuffer(WebGLenum target, WebGLenum attachment, WebGLenum rbtarget, WebGLRenderbuffer *wrb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::FramebufferTexture2D(WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum textarget,
|
2010-05-19 13:46:08 -07:00
|
|
|
nsIWebGLTexture *tobj,
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLint level)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
FramebufferTexture2D(target, attachment, textarget,
|
|
|
|
static_cast<WebGLTexture*>(tobj), level);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::FramebufferTexture2D(WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum textarget,
|
|
|
|
WebGLTexture *tobj,
|
|
|
|
WebGLint level)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-09-29 07:13:49 -07:00
|
|
|
if (mBoundFramebuffer)
|
|
|
|
return mBoundFramebuffer->FramebufferTexture2D(target, attachment, textarget, tobj, level);
|
|
|
|
else
|
2010-11-05 12:57:58 -07:00
|
|
|
return ErrorInvalidOperation("framebufferTexture2D: cannot modify framebuffer 0");
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_SAME_METHOD_0(Flush, Flush)
|
|
|
|
|
|
|
|
GL_SAME_METHOD_0(Finish, Finish)
|
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozFrontFace(WebGLenum mode)
|
|
|
|
{
|
|
|
|
FrontFace(mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::FrontFace(WebGLenum mode)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
|
|
|
// returns an object: { size: ..., type: ..., name: ... }
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetActiveAttrib(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLActiveInfo **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetActiveAttrib(static_cast<WebGLProgram*>(pobj), index).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
|
|
WebGLContext::GetActiveAttrib(WebGLProgram *prog, PRUint32 index)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getActiveAttrib: program", prog))
|
|
|
|
return nsnull;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLint len = 0;
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozGenerateMipmap(WebGLenum target)
|
|
|
|
{
|
|
|
|
GenerateMipmap(target);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::GenerateMipmap(WebGLenum target)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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.");
|
2010-08-23 14:03:53 -07:00
|
|
|
|
2012-04-03 16:42:06 -07:00
|
|
|
if (!tex->HasImageInfoAt(0, 0))
|
|
|
|
return ErrorInvalidOperation("generateMipmap: Level zero of texture is not defined.");
|
2010-09-02 07:29:41 -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.");
|
|
|
|
|
|
|
|
GLenum format = tex->ImageInfoAt(0, 0).Format();
|
|
|
|
if (IsTextureFormatCompressed(format))
|
|
|
|
return ErrorInvalidOperation("generateMipmap: Texture data at level zero is compressed.");
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetActiveUniform(nsIWebGLProgram *pobj, PRUint32 index, nsIWebGLActiveInfo **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetActiveUniform(static_cast<WebGLProgram*>(pobj), index).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
|
|
|
WebGLContext::GetActiveUniform(WebGLProgram *prog, PRUint32 index)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getActiveUniform: program", prog))
|
|
|
|
return nsnull;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLint len = 0;
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-15 08:49:34 -07:00
|
|
|
WebGLContext::GetAttachedShaders(nsIWebGLProgram *pobj, nsIVariant **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
Nullable< nsTArray<WebGLShader*> > arr;
|
|
|
|
GetAttachedShaders(static_cast<WebGLProgram*>(pobj), arr);
|
|
|
|
if (arr.IsNull()) {
|
|
|
|
*retval = nsnull;
|
2010-07-16 07:30:32 -07:00
|
|
|
return NS_OK;
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-15 08:49:34 -07:00
|
|
|
nsCOMPtr<nsIWritableVariant> wrval = do_CreateInstance("@mozilla.org/variant;1");
|
|
|
|
NS_ENSURE_TRUE(wrval, NS_ERROR_FAILURE);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (arr.Value().IsEmpty()) {
|
2010-06-15 08:49:34 -07:00
|
|
|
wrval->SetAsEmptyArray();
|
2010-09-13 08:55:07 -07:00
|
|
|
} else {
|
2010-06-15 08:49:34 -07:00
|
|
|
wrval->SetAsArray(nsIDataType::VTYPE_INTERFACE,
|
2012-05-04 09:38:44 -07:00
|
|
|
&NS_GET_IID(nsIWebGLShader),
|
|
|
|
arr.Value().Length(),
|
|
|
|
const_cast<void*>( // @#$% SetAsArray doesn't accept a const void*
|
|
|
|
static_cast<const void*>(
|
|
|
|
arr.Value().Elements()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
wrval.forget(retval);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::GetAttachedShaders(WebGLProgram *prog,
|
|
|
|
Nullable< nsTArray<WebGLShader*> > &retval)
|
|
|
|
{
|
|
|
|
retval.SetNull();
|
|
|
|
if (!IsContextStable())
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetAttribLocation(nsIWebGLProgram *pobj,
|
2010-01-22 13:34:25 -08:00
|
|
|
const nsAString& name,
|
|
|
|
PRInt32 *retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetAttribLocation(static_cast<WebGLProgram*>(pobj), name);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-03-02 12:42:49 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLint
|
|
|
|
WebGLContext::GetAttribLocation(WebGLProgram *prog, const nsAString& name)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint progname = prog->GLName();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetParameter(PRUint32 pname, JSContext* cx, JS::Value *retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value v = GetParameter(cx, pname, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = v;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
static JS::Value
|
2012-05-05 18:15:11 -07:00
|
|
|
StringValue(JSContext* cx, const char* chars, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JSString* str = JS_NewStringCopyZ(cx, chars);
|
|
|
|
if (!str) {
|
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::NullValue();
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::StringValue(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLContext::GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return JS::NullValue();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
switch(pname) {
|
|
|
|
//
|
|
|
|
// Single-value params
|
|
|
|
//
|
|
|
|
|
|
|
|
// int
|
|
|
|
case LOCAL_GL_MAX_VERTEX_ATTRIBS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_VERTEX_ATTRIBS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_VARYING_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_VARYING_VECTORS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_TEXTURE_SIZE:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_TEXTURE_SIZE);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_CUBE_MAP_TEXTURE_SIZE);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_RENDERBUFFER_SIZE:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(MINVALUE_GL_MAX_RENDERBUFFER_SIZE);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
// Return the real value; we're not overriding this one
|
|
|
|
break;
|
2011-10-13 05:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
switch (pname) {
|
|
|
|
//
|
|
|
|
// String params
|
|
|
|
//
|
|
|
|
case LOCAL_GL_VENDOR:
|
2012-05-04 09:38:44 -07:00
|
|
|
return StringValue(cx, "Mozilla", rv);
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_RENDERER:
|
2012-05-04 09:38:44 -07:00
|
|
|
return StringValue(cx, "Mozilla", rv);
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_VERSION:
|
2012-05-04 09:38:44 -07:00
|
|
|
return StringValue(cx, "WebGL 1.0", rv);
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_SHADING_LANGUAGE_VERSION:
|
2012-05-04 09:38:44 -07:00
|
|
|
return StringValue(cx, "WebGL GLSL ES 1.0", rv);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Single-value params
|
|
|
|
//
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
// unsigned int
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_CULL_FACE_MODE:
|
|
|
|
case LOCAL_GL_FRONT_FACE:
|
|
|
|
case LOCAL_GL_ACTIVE_TEXTURE:
|
|
|
|
case LOCAL_GL_STENCIL_FUNC:
|
|
|
|
case LOCAL_GL_STENCIL_FAIL:
|
|
|
|
case LOCAL_GL_STENCIL_PASS_DEPTH_FAIL:
|
|
|
|
case LOCAL_GL_STENCIL_PASS_DEPTH_PASS:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_FUNC:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_FAIL:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_PASS_DEPTH_FAIL:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_PASS_DEPTH_PASS:
|
|
|
|
case LOCAL_GL_DEPTH_FUNC:
|
|
|
|
case LOCAL_GL_BLEND_SRC_RGB:
|
|
|
|
case LOCAL_GL_BLEND_SRC_ALPHA:
|
|
|
|
case LOCAL_GL_BLEND_DST_RGB:
|
|
|
|
case LOCAL_GL_BLEND_DST_ALPHA:
|
|
|
|
case LOCAL_GL_BLEND_EQUATION_RGB:
|
|
|
|
case LOCAL_GL_BLEND_EQUATION_ALPHA:
|
2012-05-04 09:38:44 -07:00
|
|
|
case LOCAL_GL_GENERATE_MIPMAP_HINT:
|
|
|
|
{
|
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetIntegerv(pname, &i);
|
|
|
|
// Unsigned 32-bit values don't fit in Int32Value
|
|
|
|
return JS::DoubleValue(uint32_t(i));
|
|
|
|
}
|
|
|
|
// int
|
|
|
|
case LOCAL_GL_STENCIL_CLEAR_VALUE:
|
|
|
|
case LOCAL_GL_STENCIL_REF:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_REF:
|
2010-06-30 08:48:30 -07:00
|
|
|
case LOCAL_GL_UNPACK_ALIGNMENT:
|
|
|
|
case LOCAL_GL_PACK_ALIGNMENT:
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_SUBPIXEL_BITS:
|
|
|
|
case LOCAL_GL_MAX_TEXTURE_SIZE:
|
|
|
|
case LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE:
|
|
|
|
case LOCAL_GL_SAMPLE_BUFFERS:
|
|
|
|
case LOCAL_GL_SAMPLES:
|
|
|
|
case LOCAL_GL_MAX_VERTEX_ATTRIBS:
|
|
|
|
case LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
|
|
|
|
case LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
|
|
|
|
case LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS:
|
|
|
|
case LOCAL_GL_MAX_RENDERBUFFER_SIZE:
|
|
|
|
case LOCAL_GL_RED_BITS:
|
|
|
|
case LOCAL_GL_GREEN_BITS:
|
|
|
|
case LOCAL_GL_BLUE_BITS:
|
|
|
|
case LOCAL_GL_ALPHA_BITS:
|
|
|
|
case LOCAL_GL_DEPTH_BITS:
|
|
|
|
case LOCAL_GL_STENCIL_BITS:
|
|
|
|
{
|
2010-06-08 07:40:23 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetIntegerv(pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(i);
|
2010-06-08 07:40:23 -07:00
|
|
|
}
|
2011-09-30 21:45:50 -07:00
|
|
|
case LOCAL_GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
|
|
|
|
if (mEnabledExtensions[WebGL_OES_standard_derivatives]) {
|
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetIntegerv(pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(i);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ErrorInvalidEnum("getParameter: parameter", pname);
|
|
|
|
return JS::NullValue();
|
2011-09-30 21:45:50 -07:00
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
case LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(mGLMaxVertexUniformVectors);
|
2011-02-11 15:11:30 -08:00
|
|
|
|
|
|
|
case LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(mGLMaxFragmentUniformVectors);
|
2011-02-11 15:11:30 -08:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
case LOCAL_GL_MAX_VARYING_VECTORS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(mGLMaxVaryingVectors);
|
2010-06-30 08:48:30 -07:00
|
|
|
|
2010-06-11 14:36:34 -07:00
|
|
|
case LOCAL_GL_NUM_COMPRESSED_TEXTURE_FORMATS:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(0);
|
2010-06-30 08:48:30 -07:00
|
|
|
case LOCAL_GL_COMPRESSED_TEXTURE_FORMATS:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JSObject* obj = Uint32Array::Create(cx, 0);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
|
|
|
}
|
2010-06-11 14:36:34 -07:00
|
|
|
|
2010-06-08 07:40:23 -07:00
|
|
|
// unsigned int. here we may have to return very large values like 2^32-1 that can't be represented as
|
2010-06-11 14:36:34 -07:00
|
|
|
// javascript integer values. We just return them as doubles and javascript doesn't care.
|
2010-06-08 07:40:23 -07:00
|
|
|
case LOCAL_GL_STENCIL_BACK_VALUE_MASK:
|
|
|
|
case LOCAL_GL_STENCIL_BACK_WRITEMASK:
|
|
|
|
case LOCAL_GL_STENCIL_VALUE_MASK:
|
|
|
|
case LOCAL_GL_STENCIL_WRITEMASK:
|
|
|
|
{
|
|
|
|
GLint i = 0; // the GL api (glGetIntegerv) only does signed ints
|
|
|
|
gl->fGetIntegerv(pname, &i);
|
|
|
|
GLuint i_unsigned(i); // this is where -1 becomes 2^32-1
|
2010-06-11 14:36:34 -07:00
|
|
|
double i_double(i_unsigned); // pass as FP value to allow large values such as 2^32-1.
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(i_double);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// float
|
2012-02-23 05:43:57 -08:00
|
|
|
case LOCAL_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
|
|
|
|
if (mEnabledExtensions[WebGL_EXT_texture_filter_anisotropic]) {
|
|
|
|
GLfloat f = 0.f;
|
|
|
|
gl->fGetFloatv(pname, &f);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(f);
|
2012-02-23 05:43:57 -08:00
|
|
|
} else {
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnum("getParameter: parameter", pname);
|
|
|
|
return JS::NullValue();
|
2012-02-23 05:43:57 -08:00
|
|
|
}
|
2010-11-16 20:33:03 -08:00
|
|
|
case LOCAL_GL_DEPTH_CLEAR_VALUE:
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_LINE_WIDTH:
|
|
|
|
case LOCAL_GL_POLYGON_OFFSET_FACTOR:
|
|
|
|
case LOCAL_GL_POLYGON_OFFSET_UNITS:
|
|
|
|
case LOCAL_GL_SAMPLE_COVERAGE_VALUE:
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
GLfloat f = 0.f;
|
|
|
|
gl->fGetFloatv(pname, &f);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(f);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
// bool
|
2010-06-08 07:40:23 -07:00
|
|
|
case LOCAL_GL_BLEND:
|
|
|
|
case LOCAL_GL_DEPTH_TEST:
|
|
|
|
case LOCAL_GL_STENCIL_TEST:
|
|
|
|
case LOCAL_GL_CULL_FACE:
|
|
|
|
case LOCAL_GL_DITHER:
|
|
|
|
case LOCAL_GL_POLYGON_OFFSET_FILL:
|
|
|
|
case LOCAL_GL_SCISSOR_TEST:
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_SAMPLE_COVERAGE_INVERT:
|
|
|
|
case LOCAL_GL_DEPTH_WRITEMASK:
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
realGLboolean b = 0;
|
|
|
|
gl->fGetBooleanv(pname, &b);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(bool(b));
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
// bool, WebGL-specific
|
|
|
|
case UNPACK_FLIP_Y_WEBGL:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(mPixelStoreFlipY);
|
2010-06-30 08:48:30 -07:00
|
|
|
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(mPixelStorePremultiplyAlpha);
|
2010-06-30 08:48:30 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
// uint, WebGL-specific
|
|
|
|
case UNPACK_COLORSPACE_CONVERSION_WEBGL:
|
2012-05-04 09:38:44 -07:00
|
|
|
// uint doesn't fit in Int32Value
|
|
|
|
return JS::DoubleValue(uint32_t(mPixelStoreColorspaceConversion));
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
//
|
|
|
|
// Complex values
|
|
|
|
//
|
|
|
|
case LOCAL_GL_DEPTH_RANGE: // 2 floats
|
|
|
|
case LOCAL_GL_ALIASED_POINT_SIZE_RANGE: // 2 floats
|
|
|
|
case LOCAL_GL_ALIASED_LINE_WIDTH_RANGE: // 2 floats
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
GLfloat fv[2] = { 0 };
|
|
|
|
gl->fGetFloatv(pname, fv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Float32Array::Create(cx, 2, fv);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case LOCAL_GL_COLOR_CLEAR_VALUE: // 4 floats
|
|
|
|
case LOCAL_GL_BLEND_COLOR: // 4 floats
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
GLfloat fv[4] = { 0 };
|
|
|
|
gl->fGetFloatv(pname, fv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Float32Array::Create(cx, 4, fv);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case LOCAL_GL_MAX_VIEWPORT_DIMS: // 2 ints
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
GLint iv[2] = { 0 };
|
|
|
|
gl->fGetIntegerv(pname, iv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Int32Array::Create(cx, 2, iv);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case LOCAL_GL_SCISSOR_BOX: // 4 ints
|
|
|
|
case LOCAL_GL_VIEWPORT: // 4 ints
|
|
|
|
{
|
2010-11-01 13:13:00 -07:00
|
|
|
GLint iv[4] = { 0 };
|
2010-06-11 14:36:34 -07:00
|
|
|
gl->fGetIntegerv(pname, iv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Int32Array::Create(cx, 4, iv);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-06-08 07:40:23 -07:00
|
|
|
case LOCAL_GL_COLOR_WRITEMASK: // 4 bools
|
|
|
|
{
|
2010-06-11 14:36:34 -07:00
|
|
|
realGLboolean gl_bv[4] = { 0 };
|
|
|
|
gl->fGetBooleanv(pname, gl_bv);
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value vals[4] = { JS::BooleanValue(bool(gl_bv[0])),
|
|
|
|
JS::BooleanValue(bool(gl_bv[1])),
|
|
|
|
JS::BooleanValue(bool(gl_bv[2])),
|
|
|
|
JS::BooleanValue(bool(gl_bv[3])) };
|
|
|
|
JSObject* obj = JS_NewArrayObject(cx, 4, vals);
|
|
|
|
if (!obj) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
2010-06-11 14:36:34 -07:00
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2010-06-11 14:36:34 -07:00
|
|
|
case LOCAL_GL_ARRAY_BUFFER_BINDING:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBoundArrayBuffer.get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2010-06-11 14:36:34 -07:00
|
|
|
case LOCAL_GL_ELEMENT_ARRAY_BUFFER_BINDING:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBoundElementArrayBuffer.get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2010-06-11 14:36:34 -07:00
|
|
|
case LOCAL_GL_RENDERBUFFER_BINDING:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBoundRenderbuffer.get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2010-06-11 14:36:34 -07:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_BINDING:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBoundFramebuffer.get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-11 14:36:34 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_CURRENT_PROGRAM:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(), mCurrentProgram.get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-11 14:36:34 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_BINDING_2D:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBound2DTextures[mActiveTexture].get(), &v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-11 14:36:34 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_TEXTURE_BINDING_CUBE_MAP:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mBoundCubeMapTextures[mActiveTexture].get(),
|
|
|
|
&v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-06-08 07:40:23 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getParameter: parameter", pname);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-11 14:36:34 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::GetBufferParameter(WebGLenum target, WebGLenum pname, JS::Value *retval)
|
|
|
|
{
|
|
|
|
*retval = GetBufferParameter(target, pname);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetBufferParameter(WebGLenum target, WebGLenum pname)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
// 32-bit unsigned ints don't fit in Int32 values in JS
|
|
|
|
return JS::DoubleValue(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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::GetFramebufferAttachmentParameter(WebGLenum target, WebGLenum attachment, WebGLenum pname, JSContext* cx, JS::Value *retval)
|
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value v =
|
|
|
|
GetFramebufferAttachmentParameter(cx, target, attachment, pname, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = v;
|
2009-11-18 12:42:35 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
|
|
|
|
WebGLenum target,
|
|
|
|
WebGLenum attachment,
|
|
|
|
WebGLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
|
|
|
switch (attachment) {
|
|
|
|
case LOCAL_GL_COLOR_ATTACHMENT0:
|
|
|
|
case LOCAL_GL_DEPTH_ATTACHMENT:
|
|
|
|
case LOCAL_GL_STENCIL_ATTACHMENT:
|
2011-01-05 13:08:53 -08:00
|
|
|
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
|
2009-11-18 12:42:35 -08:00
|
|
|
break;
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: attachment", attachment);
|
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!mBoundFramebuffer) {
|
|
|
|
ErrorInvalidOperation("GetFramebufferAttachmentParameter: cannot query framebuffer 0");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
const WebGLFramebufferAttachment& 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-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(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
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
const_cast<WebGLRenderbuffer*>(fba.Renderbuffer()),
|
|
|
|
&v)) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname);
|
|
|
|
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-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(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
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
const_cast<WebGLTexture*>(fba.Texture()),
|
|
|
|
&v)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(fba.TextureLevel());
|
2011-01-05 13:08:53 -08:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(fba.TextureCubeMapFace());
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname);
|
|
|
|
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-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(uint32_t(LOCAL_GL_NONE));
|
2010-09-02 07:38:26 -07:00
|
|
|
|
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("GetFramebufferAttachmentParameter: pname", pname);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetRenderbufferParameter(WebGLenum target, WebGLenum pname, JS::Value *retval)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetRenderbufferParameter(target, pname);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetRenderbufferParameter(WebGLenum target, WebGLenum pname)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return JS::NullValue();
|
2009-11-18 12:42:35 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER) {
|
|
|
|
ErrorInvalidEnumInfo("GetRenderbufferParameter: 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_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:
|
|
|
|
{
|
2010-06-19 07:42:43 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetRenderbufferParameteriv(target, pname, &i);
|
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:
|
|
|
|
{
|
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetRenderbufferParameteriv(target, pname, &i);
|
|
|
|
if (i == LOCAL_GL_DEPTH24_STENCIL8)
|
|
|
|
{
|
|
|
|
i = LOCAL_GL_DEPTH_STENCIL;
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
// unsigned 32-bit ints need to become double jsvals
|
|
|
|
return JS::DoubleValue(uint32_t(i));
|
2010-12-06 03:34:35 -08:00
|
|
|
}
|
2009-11-18 12:42:35 -08:00
|
|
|
default:
|
2012-05-04 09:38:44 -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
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2009-09-17 23:01:07 -07:00
|
|
|
WebGLContext::CreateBuffer(nsIWebGLBuffer **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = CreateBuffer().get();
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLBuffer>
|
|
|
|
WebGLContext::CreateBuffer()
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
|
|
|
nsRefPtr<WebGLBuffer> globj = new WebGLBuffer(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::CreateTexture(nsIWebGLTexture **retval)
|
|
|
|
{
|
|
|
|
*retval = CreateTexture().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLTexture>
|
|
|
|
WebGLContext::CreateTexture()
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
|
|
|
nsRefPtr<WebGLTexture> globj = new WebGLTexture(this);
|
|
|
|
return globj.forget();
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozGetError(WebGLenum *_retval)
|
|
|
|
{
|
|
|
|
*_retval = GetError();
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLenum
|
|
|
|
WebGLContext::GetError()
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:03 -08:00
|
|
|
if (mContextStatus == ContextStable) {
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLenum 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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::GetProgramParameter(nsIWebGLProgram *pobj, PRUint32 pname, JS::Value *retval)
|
|
|
|
{
|
|
|
|
*retval = GetProgramParameter(static_cast<WebGLProgram*>(pobj), pname);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetProgramParameter(WebGLProgram *prog, WebGLenum pname)
|
2009-11-18 12:42:35 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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
|
|
|
{
|
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetProgramiv(progname, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(bool(i));
|
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-04 09:38:44 -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
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetProgramInfoLog(nsIWebGLProgram *pobj, nsAString& retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
GetProgramInfoLog(static_cast<WebGLProgram*>(pobj), retval, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsAString& retval,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLuint 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) {
|
|
|
|
// XXX GL error? shouldn't happen!
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString log;
|
|
|
|
log.SetCapacity(k);
|
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
gl->fGetProgramInfoLog(progname, k, &k, (char*) log.BeginWriting());
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
log.SetLength(k);
|
|
|
|
|
|
|
|
CopyASCIItoUTF16(log, retval);
|
|
|
|
}
|
|
|
|
|
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
|
2012-05-04 09:38:44 -07:00
|
|
|
void WebGLContext::TexParameter_base(WebGLenum target, WebGLenum pname,
|
|
|
|
WebGLint *intParamPtr,
|
|
|
|
WebGLfloat *floatParamPtr)
|
2009-09-17 23:01:07 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
MOZ_ASSERT(intParamPtr || floatParamPtr);
|
|
|
|
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
2009-09-17 23:01:07 -07:00
|
|
|
|
2010-10-09 12:44:25 -07:00
|
|
|
WebGLint intParam = intParamPtr ? *intParamPtr : WebGLint(*floatParamPtr);
|
|
|
|
WebGLfloat floatParam = floatParamPtr ? *floatParamPtr : WebGLfloat(*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:
|
|
|
|
if (mEnabledExtensions[WebGL_EXT_texture_filter_anisotropic]) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozTexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
TexParameterf(target, pname, param);
|
|
|
|
return NS_OK;
|
2010-08-23 14:03:44 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-08-23 14:03:44 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozTexParameteri(WebGLenum target, WebGLenum pname, WebGLint param)
|
2010-08-23 14:03:44 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
TexParameteri(target, pname, param);
|
|
|
|
return NS_OK;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname, JS::Value *retval)
|
2009-09-17 23:01:07 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetTexParameter(target, pname);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetTexParameter(WebGLenum target, WebGLenum pname)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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-04 09:38:44 -07:00
|
|
|
// Unsigned values don't fit in JS Int32 values
|
|
|
|
return JS::DoubleValue(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:
|
|
|
|
if (mEnabledExtensions[WebGL_EXT_texture_filter_anisotropic]) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-18 12:42:35 -08:00
|
|
|
/* any getUniform(in WebGLProgram program, in WebGLUniformLocation location) raises(DOMException); */
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetUniform(nsIWebGLProgram *pobj, nsIWebGLUniformLocation *ploc,
|
|
|
|
JSContext *cx, JS::Value *retval)
|
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value v = GetUniform(cx, static_cast<WebGLProgram*>(pobj),
|
|
|
|
static_cast<WebGLUniformLocation*>(ploc), rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = v;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -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
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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) {
|
|
|
|
ErrorInvalidValue("GetUniform: this uniform location corresponds to another program");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-01 23:09:19 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (location->ProgramGeneration() != prog->Generation()) {
|
|
|
|
ErrorInvalidOperation("GetUniform: this uniform location is obsolete since the program has been relinked");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-06-08 14:25:27 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Float32Array::Create(cx, unitSize, fv);
|
|
|
|
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-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Int32Array::Create(cx, unitSize, iv);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-01 23:09:19 -07:00
|
|
|
WebGLContext::GetUniformLocation(nsIWebGLProgram *pobj, const nsAString& name, nsIWebGLUniformLocation **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetUniformLocation(static_cast<WebGLProgram*>(pobj), name).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
|
|
|
WebGLContext::GetUniformLocation(WebGLProgram *prog, const nsAString& name)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObject("getUniformLocation: program", prog))
|
|
|
|
return nsnull;
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
if (!ValidateGLSLVariableName(name, "getUniformLocation"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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
|
|
|
|
2011-12-04 11:15:43 -08:00
|
|
|
WebGLUniformLocation *loc = nsnull;
|
2012-04-16 12:56:12 -07:00
|
|
|
if (intlocation >= 0) {
|
|
|
|
WebGLUniformInfo info = prog->GetUniformInfoForMappedIdentifier(mappedName);
|
|
|
|
loc = new WebGLUniformLocation(this,
|
|
|
|
prog,
|
|
|
|
intlocation,
|
|
|
|
info);
|
|
|
|
NS_ADDREF(loc);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
return loc;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetVertexAttrib(WebGLuint index, WebGLenum pname, JSContext* cx,
|
|
|
|
JS::Value *retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value v = GetVertexAttrib(cx, index, pname, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = v;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-21 13:48:22 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(index, "getVertexAttrib"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
2010-09-13 08:55:07 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
if (!dom::WrapObject(cx, GetWrapper(),
|
|
|
|
mAttribBuffers[index].buf.get(), &v)) {
|
2012-05-05 18:15:11 -07:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2011-10-31 19:02:50 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::Int32Value(mAttribBuffers[index].stride);
|
2011-11-03 07:50:40 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE:
|
2009-09-02 17:47:49 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE:
|
|
|
|
{
|
2011-06-27 10:27:04 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetVertexAttribiv(index, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
if (pname == LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE)
|
|
|
|
return JS::Int32Value(i);
|
|
|
|
MOZ_ASSERT(pname == LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE);
|
|
|
|
// Unsigned long doesn't fit in Int32Value
|
|
|
|
return JS::DoubleValue(uint32_t(i));
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
case LOCAL_GL_CURRENT_VERTEX_ATTRIB:
|
|
|
|
{
|
2010-09-02 07:34:08 -07:00
|
|
|
WebGLfloat vec[4] = {0, 0, 0, 1};
|
|
|
|
if (index) {
|
|
|
|
gl->fGetVertexAttribfv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, &vec[0]);
|
|
|
|
} else {
|
|
|
|
vec[0] = mVertexAttrib0Vector[0];
|
|
|
|
vec[1] = mVertexAttrib0Vector[1];
|
|
|
|
vec[2] = mVertexAttrib0Vector[2];
|
|
|
|
vec[3] = mVertexAttrib0Vector[3];
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
JSObject* obj = Float32Array::Create(cx, 4, vec);
|
|
|
|
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);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED:
|
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
|
|
|
|
{
|
2011-06-27 10:27:04 -07:00
|
|
|
GLint i = 0;
|
|
|
|
gl->fGetVertexAttribiv(index, pname, &i);
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::BooleanValue(bool(i));
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER:
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::DoubleValue(uint32_t(mAttribBuffers[index].byteOffset));
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
default:
|
2012-05-04 09:38:44 -07:00
|
|
|
ErrorInvalidEnumInfo("getVertexAttrib: parameter", pname);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return JS::NullValue();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
/* GLuint getVertexAttribOffset (in GLuint index, in GLenum pname); */
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::GetVertexAttribOffset(WebGLuint index, WebGLenum pname, WebGLuint *retval)
|
2009-09-17 23:01:07 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetVertexAttribOffset(index, pname);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLsizeiptr
|
|
|
|
WebGLContext::GetVertexAttribOffset(WebGLuint index, WebGLenum pname)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return 0;
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(index, "getVertexAttribOffset"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return 0;
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (pname != LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER) {
|
|
|
|
ErrorInvalidEnum("getVertexAttribOffset: bad parameter");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-13 08:55:07 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
return mAttribBuffers[index].byteOffset;
|
2009-09-17 23:01:07 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozHint(WebGLenum target, WebGLenum mode)
|
|
|
|
{
|
|
|
|
Hint(target, mode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-30 21:45:50 -07:00
|
|
|
WebGLContext::Hint(WebGLenum target, WebGLenum mode)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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:
|
|
|
|
if (mEnabledExtensions[WebGL_OES_standard_derivatives])
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsBuffer(nsIWebGLBuffer *bobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsBuffer(static_cast<WebGLBuffer*>(bobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsBuffer(WebGLBuffer *buffer)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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("isBuffer", buffer) &&
|
|
|
|
!buffer->IsDeleted() &&
|
|
|
|
buffer->HasEverBeenBound();
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsFramebuffer(nsIWebGLFramebuffer *fbobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsFramebuffer(static_cast<WebGLFramebuffer*>(fbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsFramebuffer(WebGLFramebuffer *fb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsProgram(nsIWebGLProgram *pobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsProgram(static_cast<WebGLProgram*>(pobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsRenderbuffer(nsIWebGLRenderbuffer *rbobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsRenderbuffer(static_cast<WebGLRenderbuffer*>(rbobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsRenderbuffer(WebGLRenderbuffer *rb)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsShader(nsIWebGLShader *sobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsShader(static_cast<WebGLShader*>(sobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::IsTexture(nsIWebGLTexture *tobj, WebGLboolean *retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
*retval = IsTexture(static_cast<WebGLTexture*>(tobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsTexture(WebGLTexture *tex)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-08 11:45:23 -07:00
|
|
|
WebGLContext::IsEnabled(WebGLenum cap, WebGLboolean *retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = IsEnabled(cap);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsEnabled(WebGLenum cap)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return false;
|
2010-08-25 05:17:08 -07:00
|
|
|
|
|
|
|
if (!ValidateCapabilityEnum(cap, "isEnabled"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return false;
|
2010-06-08 11:45:23 -07:00
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2012-05-04 09:38:44 -07:00
|
|
|
return gl->fIsEnabled(cap);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-07-03 15:33:05 -07:00
|
|
|
GL_SAME_METHOD_1(LineWidth, LineWidth, WebGLfloat)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::LinkProgram(nsIWebGLProgram *pobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
LinkProgram(static_cast<WebGLProgram*>(pobj), rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLContext::LinkProgram(WebGLProgram *program, ErrorResult& rv)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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;
|
|
|
|
|
|
|
|
GLuint progname = program->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!program->NextGeneration()) {
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.Throw(NS_ERROR_FAILURE);
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-06-15 08:49:34 -07:00
|
|
|
|
|
|
|
if (!program->HasBothShaderTypesAttached()) {
|
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
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fLinkProgram(progname);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-04 12:03:33 -07:00
|
|
|
GLint ok;
|
|
|
|
gl->fGetProgramiv(progname, LOCAL_GL_LINK_STATUS, &ok);
|
2010-06-10 10:45:00 -07:00
|
|
|
if (ok) {
|
2012-03-02 12:42:49 -08:00
|
|
|
bool updateInfoSucceeded = program->UpdateInfo();
|
|
|
|
program->SetLinkStatus(updateInfoSucceeded);
|
2010-06-10 10:45:00 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
program->SetLinkStatus(false);
|
2010-06-10 10:45:00 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozPixelStorei(WebGLenum pname, WebGLint param)
|
|
|
|
{
|
|
|
|
PixelStorei(pname, param);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::PixelStorei(WebGLenum pname, WebGLint param)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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)
|
|
|
|
return ErrorInvalidValue("PixelStorei: invalid pack/unpack alignment value");
|
|
|
|
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:
|
2010-07-16 07:31:48 -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
|
|
|
|
2010-07-03 15:33:05 -07:00
|
|
|
GL_SAME_METHOD_2(PolygonOffset, PolygonOffset, WebGLfloat, WebGLfloat)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-16 02:50:51 -07:00
|
|
|
WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height,
|
2012-01-14 09:43:00 -08:00
|
|
|
WebGLenum format, WebGLenum type, const JS::Value& pixelsVal, JSContext *cx)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-14 09:43:00 -08:00
|
|
|
if (!pixelsVal.isObject()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_IsTypedArrayObject(&pixelsVal.toObject(), cx)) {
|
2012-03-16 02:50:51 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBufferView pixels(cx, &pixelsVal.toObject());
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
ReadPixels(x, y, width, height, format, type, &pixels, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2012-03-16 02:50:51 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width,
|
|
|
|
WebGLsizei height, WebGLenum format,
|
|
|
|
WebGLenum type, ArrayBufferView* pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-03-16 02:50:51 -07:00
|
|
|
if (!IsContextStable()) {
|
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
|
|
|
|
2010-06-15 14:38:05 -07:00
|
|
|
if (HTMLCanvasElement()->IsWriteOnly() && !nsContentUtils::IsCallerTrustedForRead()) {
|
2010-10-15 14:50:15 -07:00
|
|
|
LogMessageIfVerbose("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)
|
|
|
|
return ErrorInvalidValue("ReadPixels: negative size passed");
|
|
|
|
|
2012-01-24 13:12:31 -08:00
|
|
|
const WebGLRectangleObject *framebufferRect = FramebufferRectangleObject();
|
|
|
|
WebGLsizei framebufferWidth = framebufferRect ? framebufferRect->Width() : 0;
|
|
|
|
WebGLsizei framebufferHeight = framebufferRect ? framebufferRect->Height() : 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void* data = pixels->mData;
|
|
|
|
PRUint32 dataByteLen = JS_GetTypedArrayByteLength(pixels->mObj, NULL);
|
|
|
|
int dataType = JS_GetTypedArrayType(pixels->mObj, NULL);
|
2011-10-31 16:55:01 -07:00
|
|
|
|
|
|
|
PRUint32 channels = 0;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
PRUint32 bytesPerPixel = 0;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (!checked_neededByteLength.valid())
|
|
|
|
return ErrorInvalidOperation("ReadPixels: integer overflow computing the needed buffer size");
|
2010-06-19 07:46:12 -07:00
|
|
|
|
2011-10-31 16:55:01 -07:00
|
|
|
if (checked_neededByteLength.value() > dataByteLen)
|
2010-06-19 07:46:12 -07:00
|
|
|
return ErrorInvalidOperation("ReadPixels: buffer too small");
|
|
|
|
|
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!
|
|
|
|
if (!mBoundFramebuffer->CheckAndInitializeRenderbuffers())
|
2012-01-24 13:12:31 -08:00
|
|
|
return ErrorInvalidFramebufferOperation("readPixels: incomplete framebuffer");
|
2011-05-20 12:53:53 -07:00
|
|
|
} else {
|
|
|
|
EnsureBackbufferClearedAsNeeded();
|
|
|
|
}
|
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).
|
|
|
|
|
|
|
|
// zero the whole destination buffer. Too bad for the part that's going to be overwritten, we're not
|
|
|
|
// 100% efficient here, but in practice this is a quite rare case anyway.
|
2011-10-31 16:55:01 -07:00
|
|
|
memset(data, 0, dataByteLen);
|
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
|
2011-06-02 05:56:50 -07:00
|
|
|
GLint subrect_x = NS_MAX(x, 0);
|
2012-01-24 13:12:31 -08:00
|
|
|
GLint subrect_end_x = NS_MIN(x+width, framebufferWidth);
|
2010-06-19 07:46:12 -07:00
|
|
|
GLsizei subrect_width = subrect_end_x - subrect_x;
|
|
|
|
|
2011-06-02 05:56:50 -07:00
|
|
|
GLint subrect_y = NS_MAX(y, 0);
|
2012-01-24 13:12:31 -08:00
|
|
|
GLint subrect_end_y = NS_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)
|
2010-07-03 15:32:19 -07:00
|
|
|
return ErrorInvalidOperation("ReadPixels: integer overflow computing clipped rect size");
|
|
|
|
|
|
|
|
// 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
|
2011-10-31 16:55:01 -07:00
|
|
|
PRUint32 subrect_plainRowSize = subrect_width * bytesPerPixel;
|
2011-09-01 12:28:34 -07:00
|
|
|
// There are checks above to ensure that this doesn't overflow.
|
|
|
|
PRUint32 subrect_alignedRowSize =
|
|
|
|
RoundedToNextMultipleOf(subrect_plainRowSize, mPixelStorePackAlignment).value();
|
2010-06-19 07:46:12 -07:00
|
|
|
PRUint32 subrect_byteLength = (subrect_height-1)*subrect_alignedRowSize + subrect_plainRowSize;
|
|
|
|
|
|
|
|
// 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) {
|
2010-12-06 03:34:35 -08:00
|
|
|
needAlphaFixup = !mBoundFramebuffer->ColorAttachment().HasAlpha();
|
2010-11-16 20:33:03 -08:00
|
|
|
} else {
|
|
|
|
needAlphaFixup = gl->ActualFormat().alpha == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needAlphaFixup) {
|
|
|
|
if (format == LOCAL_GL_ALPHA && type == LOCAL_GL_UNSIGNED_BYTE) {
|
|
|
|
// this is easy; it's an 0xff memset per row
|
|
|
|
PRUint8 *row = (PRUint8*)data;
|
|
|
|
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
|
|
|
|
PRUint8 *row = (PRUint8*)data;
|
|
|
|
for (GLint j = 0; j < height; ++j) {
|
|
|
|
PRUint8 *rowp = row;
|
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
|
|
|
// offset to get the alpha byte; we're always going to
|
|
|
|
// move by 4 bytes
|
|
|
|
rowp += 3;
|
|
|
|
#endif
|
|
|
|
PRUint8 *endrowp = rowp + 4 * width;
|
|
|
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozRenderbufferStorage(WebGLenum target, WebGLenum internalformat, WebGLsizei width, WebGLsizei height)
|
|
|
|
{
|
|
|
|
RenderbufferStorage(target, internalformat, width, height);
|
2010-06-19 07:46:12 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::RenderbufferStorage(WebGLenum target, WebGLenum internalformat, WebGLsizei width, WebGLsizei height)
|
2010-05-15 05:07:30 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
if (!mBoundRenderbuffer || !mBoundRenderbuffer->GLName())
|
|
|
|
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
|
|
|
|
2010-11-05 12:57:58 -07:00
|
|
|
if (!mBoundRenderbuffer || !mBoundRenderbuffer->GLName())
|
|
|
|
return ErrorInvalidOperation("renderbufferStorage called on renderbuffer 0");
|
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
|
|
|
|
WebGLenum internalformatForGL = internalformat;
|
|
|
|
|
|
|
|
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:
|
|
|
|
// this one is available in newer OpenGL (at least since 3.1); will probably become available
|
|
|
|
// in OpenGL ES 3 (at least it will have some DEPTH_STENCIL) and is the same value that
|
|
|
|
// is otherwise provided by EXT_packed_depth_stencil and OES_packed_depth_stencil extensions
|
|
|
|
// which means it's supported on most GL and GL ES systems already.
|
|
|
|
//
|
|
|
|
// So we just use it hoping that it's available (perhaps as an extension) and if it's not available,
|
|
|
|
// we just let the GL generate an error and don't do anything about it ourselves.
|
|
|
|
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();
|
|
|
|
gl->fRenderbufferStorage(target, internalformatForGL, width, height);
|
|
|
|
GLenum error = LOCAL_GL_NO_ERROR;
|
|
|
|
UpdateWebGLErrorAndClearGLError(&error);
|
|
|
|
if (error) {
|
2012-01-24 13:12:31 -08:00
|
|
|
LogMessageIfVerbose("renderbufferStorage generated error %s", ErrorName(error));
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-07-07 17:01:16 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gl->fRenderbufferStorage(target, internalformatForGL, width, height);
|
|
|
|
}
|
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);
|
2011-10-17 07:59:28 -07:00
|
|
|
mBoundRenderbuffer->SetInitialized(false);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
GL_SAME_METHOD_2(SampleCoverage, SampleCoverage, WebGLclampf, WebGLboolean)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozScissor(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
|
|
|
|
{
|
|
|
|
Scissor(x, y, width, height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::Scissor(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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)
|
|
|
|
return ErrorInvalidValue("Scissor: negative size");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fScissor(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilFunc(WebGLenum func, WebGLint ref, WebGLuint mask)
|
|
|
|
{
|
|
|
|
StencilFunc(func, ref, mask);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::StencilFunc(WebGLenum func, WebGLint ref, WebGLuint mask)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilFuncSeparate(WebGLenum face, WebGLenum func, WebGLint ref, WebGLuint mask)
|
|
|
|
{
|
|
|
|
StencilFuncSeparate(face, func, ref, mask);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::StencilFuncSeparate(WebGLenum face, WebGLenum func, WebGLint ref, WebGLuint mask)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilMask(WebGLuint mask)
|
|
|
|
{
|
|
|
|
StencilMask(mask);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-06 03:34:35 -08:00
|
|
|
WebGLContext::StencilMask(WebGLuint mask)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
mStencilWriteMaskFront = mask;
|
|
|
|
mStencilWriteMaskBack = mask;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilMask(mask);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilMaskSeparate(WebGLenum face, WebGLuint mask)
|
|
|
|
{
|
|
|
|
StencilMaskSeparate(face, mask);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::StencilMaskSeparate(WebGLenum face, WebGLuint mask)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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, "stencilMaskSeparate: face"))
|
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:
|
|
|
|
mStencilWriteMaskFront = mask;
|
|
|
|
mStencilWriteMaskBack = mask;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_FRONT:
|
|
|
|
mStencilWriteMaskFront = mask;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_BACK:
|
|
|
|
mStencilWriteMaskBack = mask;
|
|
|
|
break;
|
|
|
|
}
|
2010-12-06 03:34:35 -08:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilMaskSeparate(face, mask);
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-30 08:48:30 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilOp(WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
|
|
|
|
{
|
|
|
|
StencilOp(sfail, dpfail, dppass);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::StencilOp(WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozStencilOpSeparate(WebGLenum face, WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
|
|
|
|
{
|
|
|
|
StencilOpSeparate(face, sfail, dpfail, dppass);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::StencilOpSeparate(WebGLenum face, WebGLenum sfail, WebGLenum dpfail, WebGLenum dppass)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
struct WebGLImageConverter
|
2010-06-19 07:47:53 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool flip;
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t width, height, srcStride, dstStride, srcTexelSize, dstTexelSize;
|
|
|
|
const PRUint8 *src;
|
|
|
|
PRUint8 *dst;
|
2010-06-19 07:47:53 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLImageConverter()
|
|
|
|
{
|
|
|
|
memset(this, 0, sizeof(WebGLImageConverter));
|
|
|
|
}
|
2010-06-19 07:47:53 -07:00
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
template<typename SrcType, typename DstType, typename UnpackType,
|
|
|
|
void unpackingFunc(const SrcType*, UnpackType*),
|
|
|
|
void packingFunc(const UnpackType*, DstType*)>
|
2010-10-15 14:50:15 -07:00
|
|
|
void run()
|
|
|
|
{
|
2011-05-20 12:53:53 -07:00
|
|
|
// Note -- even though the functions take UnpackType, the
|
|
|
|
// pointers below are all in terms of PRUint8; otherwise
|
|
|
|
// pointer math starts getting tricky.
|
2010-10-15 14:50:15 -07:00
|
|
|
for (size_t src_row = 0; src_row < height; ++src_row) {
|
|
|
|
size_t dst_row = flip ? (height - 1 - src_row) : src_row;
|
|
|
|
PRUint8 *dst_row_ptr = dst + dst_row * dstStride;
|
|
|
|
const PRUint8 *src_row_ptr = src + src_row * srcStride;
|
|
|
|
const PRUint8 *src_row_end = src_row_ptr + width * srcTexelSize; // != src_row_ptr + byteStride
|
|
|
|
while (src_row_ptr != src_row_end) {
|
2011-05-20 12:53:53 -07:00
|
|
|
UnpackType tmp[4];
|
2010-10-15 14:50:15 -07:00
|
|
|
unpackingFunc(reinterpret_cast<const SrcType*>(src_row_ptr), tmp);
|
|
|
|
packingFunc(tmp, reinterpret_cast<DstType*>(dst_row_ptr));
|
|
|
|
src_row_ptr += srcTexelSize;
|
|
|
|
dst_row_ptr += dstTexelSize;
|
|
|
|
}
|
2010-06-19 07:47:53 -07:00
|
|
|
}
|
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
};
|
2010-06-19 07:47:53 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
void
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLContext::ConvertImage(size_t width, size_t height, size_t srcStride, size_t dstStride,
|
2010-10-15 14:50:15 -07:00
|
|
|
const PRUint8*src, PRUint8 *dst,
|
2011-09-28 23:19:26 -07:00
|
|
|
int srcFormat, bool srcPremultiplied,
|
|
|
|
int dstFormat, bool dstPremultiplied,
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t dstTexelSize)
|
|
|
|
{
|
|
|
|
if (width <= 0 || height <= 0)
|
|
|
|
return;
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
if (srcFormat == dstFormat &&
|
|
|
|
srcPremultiplied == dstPremultiplied)
|
|
|
|
{
|
|
|
|
// fast exit path: we just have to memcpy all the rows.
|
|
|
|
//
|
|
|
|
// The case where absolutely nothing needs to be done is supposed to have
|
|
|
|
// been handled earlier (in TexImage2D_base, etc).
|
|
|
|
//
|
|
|
|
// So the case we're handling here is when even though no format conversion is needed,
|
|
|
|
// we still might have to flip vertically and/or to adjust to a different stride.
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
NS_ASSERTION(mPixelStoreFlipY || srcStride != dstStride, "Performance trap -- should handle this case earlier, to avoid memcpy");
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t row_size = width * dstTexelSize; // doesn't matter, src and dst formats agree
|
|
|
|
const PRUint8* src_row = src;
|
|
|
|
const PRUint8* src_end = src + height * srcStride;
|
|
|
|
|
|
|
|
PRUint8* dst_row = mPixelStoreFlipY ? dst + (height-1) * dstStride : dst;
|
2011-01-03 09:01:16 -08:00
|
|
|
ptrdiff_t dstStrideSigned(dstStride);
|
|
|
|
ptrdiff_t dst_delta = mPixelStoreFlipY ? -dstStrideSigned : dstStrideSigned;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
|
|
|
while(src_row != src_end) {
|
|
|
|
memcpy(dst_row, src_row, row_size);
|
|
|
|
src_row += srcStride;
|
|
|
|
dst_row += dst_delta;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
|
|
|
|
WebGLImageConverter converter;
|
|
|
|
converter.flip = mPixelStoreFlipY;
|
|
|
|
converter.width = width;
|
|
|
|
converter.height = height;
|
|
|
|
converter.srcStride = srcStride;
|
|
|
|
converter.dstStride = dstStride;
|
|
|
|
converter.dstTexelSize = dstTexelSize;
|
|
|
|
converter.src = src;
|
|
|
|
converter.dst = dst;
|
|
|
|
|
|
|
|
int premultiplicationOp = (!srcPremultiplied && dstPremultiplied) ? WebGLTexelPremultiplicationOp::Premultiply
|
|
|
|
: (srcPremultiplied && !dstPremultiplied) ? WebGLTexelPremultiplicationOp::Unmultiply
|
|
|
|
: WebGLTexelPremultiplicationOp::None;
|
|
|
|
|
|
|
|
#define HANDLE_DSTFORMAT(format, SrcType, DstType, unpackFunc, packFunc) \
|
|
|
|
case WebGLTexelFormat::format: \
|
|
|
|
switch (premultiplicationOp) { \
|
|
|
|
case WebGLTexelPremultiplicationOp::Premultiply: \
|
2011-05-20 12:53:53 -07:00
|
|
|
converter.run<SrcType, DstType, PRUint8, \
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packFunc##Premultiply>(); \
|
|
|
|
break; \
|
|
|
|
case WebGLTexelPremultiplicationOp::Unmultiply: \
|
2011-05-20 12:53:53 -07:00
|
|
|
converter.run<SrcType, DstType, PRUint8, \
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packFunc##Unmultiply>(); \
|
|
|
|
break; \
|
|
|
|
default: \
|
2011-05-20 12:53:53 -07:00
|
|
|
converter.run<SrcType, DstType, PRUint8, \
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packFunc>(); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
|
|
|
|
#define HANDLE_SRCFORMAT(format, size, SrcType, unpackFunc) \
|
|
|
|
case WebGLTexelFormat::format: \
|
|
|
|
converter.srcTexelSize = size; \
|
|
|
|
switch (dstFormat) { \
|
|
|
|
HANDLE_DSTFORMAT(RGBA8, SrcType, PRUint8, unpackFunc, packRGBA8ToRGBA8) \
|
|
|
|
HANDLE_DSTFORMAT(RGB8, SrcType, PRUint8, unpackFunc, packRGBA8ToRGB8) \
|
|
|
|
HANDLE_DSTFORMAT(R8, SrcType, PRUint8, unpackFunc, packRGBA8ToR8) \
|
|
|
|
HANDLE_DSTFORMAT(RA8, SrcType, PRUint8, unpackFunc, packRGBA8ToRA8) \
|
|
|
|
HANDLE_DSTFORMAT(RGBA5551, SrcType, PRUint16, unpackFunc, packRGBA8ToUnsignedShort5551) \
|
|
|
|
HANDLE_DSTFORMAT(RGBA4444, SrcType, PRUint16, unpackFunc, packRGBA8ToUnsignedShort4444) \
|
|
|
|
HANDLE_DSTFORMAT(RGB565, SrcType, PRUint16, unpackFunc, packRGBA8ToUnsignedShort565) \
|
|
|
|
/* A8 needs to be special-cased as it doesn't have color channels to premultiply */ \
|
|
|
|
case WebGLTexelFormat::A8: \
|
2011-05-20 12:53:53 -07:00
|
|
|
converter.run<SrcType, PRUint8, PRUint8, \
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packRGBA8ToA8>(); \
|
|
|
|
break; \
|
|
|
|
default: \
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding error?! Should never reach this point."); \
|
2010-10-15 14:50:15 -07:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
|
2011-05-20 12:53:53 -07:00
|
|
|
#define HANDLE_FLOAT_DSTFORMAT(format, unpackFunc, packFunc) \
|
|
|
|
case WebGLTexelFormat::format: \
|
|
|
|
switch (premultiplicationOp) { \
|
|
|
|
case WebGLTexelPremultiplicationOp::Premultiply: \
|
|
|
|
converter.run<float, float, float, \
|
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packFunc##Premultiply>(); \
|
|
|
|
break; \
|
|
|
|
case WebGLTexelPremultiplicationOp::Unmultiply: \
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Floating point can't be un-premultiplied -- we have no premultiplied source data!"); \
|
2011-05-20 12:53:53 -07:00
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
converter.run<float, float, float, \
|
|
|
|
WebGLTexelConversions::unpackFunc, \
|
|
|
|
WebGLTexelConversions::packFunc>(); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
|
|
|
|
#define HANDLE_FLOAT_SRCFORMAT(format, size, unpackFunc) \
|
|
|
|
case WebGLTexelFormat::format: \
|
|
|
|
converter.srcTexelSize = size; \
|
|
|
|
switch (dstFormat) { \
|
|
|
|
HANDLE_FLOAT_DSTFORMAT(RGB32F, unpackFunc, packRGBA32FToRGB32F) \
|
|
|
|
HANDLE_FLOAT_DSTFORMAT(A32F, unpackFunc, packRGBA32FToA32F) \
|
|
|
|
HANDLE_FLOAT_DSTFORMAT(R32F, unpackFunc, packRGBA32FToR32F) \
|
|
|
|
HANDLE_FLOAT_DSTFORMAT(RA32F, unpackFunc, packRGBA32FToRA32F) \
|
|
|
|
default: \
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding error?! Should never reach this point."); \
|
2011-05-20 12:53:53 -07:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
break;
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
switch (srcFormat) {
|
|
|
|
HANDLE_SRCFORMAT(RGBA8, 4, PRUint8, unpackRGBA8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RGBX8, 4, PRUint8, unpackRGB8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RGB8, 3, PRUint8, unpackRGB8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(BGRA8, 4, PRUint8, unpackBGRA8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(BGRX8, 4, PRUint8, unpackBGR8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(BGR8, 3, PRUint8, unpackBGR8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(R8, 1, PRUint8, unpackR8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(A8, 1, PRUint8, unpackA8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RA8, 2, PRUint8, unpackRA8ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RGBA5551, 2, PRUint16, unpackRGBA5551ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RGBA4444, 2, PRUint16, unpackRGBA4444ToRGBA8)
|
|
|
|
HANDLE_SRCFORMAT(RGB565, 2, PRUint16, unpackRGB565ToRGBA8)
|
2011-05-20 12:53:53 -07:00
|
|
|
HANDLE_FLOAT_SRCFORMAT(RGB32F, 12, unpackRGB32FToRGBA32F)
|
|
|
|
HANDLE_FLOAT_SRCFORMAT(RA32F, 8, unpackRA32FToRGBA32F)
|
|
|
|
HANDLE_FLOAT_SRCFORMAT(R32F, 4, unpackR32FToRGBA32F)
|
|
|
|
HANDLE_FLOAT_SRCFORMAT(A32F, 4, unpackA32FToRGBA32F)
|
2010-10-15 14:50:15 -07:00
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding error?! Should never reach this point.");
|
2010-10-15 14:50:15 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-06-19 07:47:53 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
nsresult
|
2012-03-11 00:54:24 -08:00
|
|
|
WebGLContext::DOMElementToImageSurface(Element* imageOrCanvas,
|
2010-10-15 14:50:15 -07:00
|
|
|
gfxImageSurface **imageOut, int *format)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-03-11 00:54:24 -08:00
|
|
|
if (!imageOrCanvas) {
|
2011-12-03 13:50:16 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2011-01-12 17:45:13 -08:00
|
|
|
PRUint32 flags =
|
|
|
|
nsLayoutUtils::SFE_WANT_NEW_SURFACE |
|
|
|
|
nsLayoutUtils::SFE_WANT_IMAGE_SURFACE;
|
|
|
|
|
|
|
|
if (mPixelStoreColorspaceConversion == LOCAL_GL_NONE)
|
|
|
|
flags |= nsLayoutUtils::SFE_NO_COLORSPACE_CONVERSION;
|
|
|
|
if (!mPixelStorePremultiplyAlpha)
|
|
|
|
flags |= nsLayoutUtils::SFE_NO_PREMULTIPLY_ALPHA;
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult res =
|
2012-03-11 00:54:24 -08:00
|
|
|
nsLayoutUtils::SurfaceFromElement(imageOrCanvas, flags);
|
2009-09-02 17:47:49 -07:00
|
|
|
if (!res.mSurface)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (res.mSurface->GetType() != gfxASurface::SurfaceTypeImage) {
|
|
|
|
// 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;
|
2011-06-07 10:47:54 -07:00
|
|
|
nsresult rv = HTMLCanvasElement()->NodePrincipal()->Subsumes(res.mPrincipal, &subsumes);
|
|
|
|
if (NS_FAILED(rv) || !subsumes) {
|
2011-09-09 14:58:35 -07:00
|
|
|
LogMessageIfVerbose("It is forbidden to load a WebGL texture from a cross-domain element that has not been validated with CORS. "
|
|
|
|
"See https://developer.mozilla.org/en/WebGL/Cross-Domain_Textures");
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2011-06-07 10:47:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-03 13:50:16 -08:00
|
|
|
// part 2: if the DOM element is a canvas, check that it's not write-only.
|
|
|
|
// That would indicate a tainted canvas, i.e. a canvas that could contain
|
|
|
|
// cross-domain image data.
|
2012-03-11 00:54:24 -08:00
|
|
|
if (nsHTMLCanvasElement* canvas = nsHTMLCanvasElement::FromContent(imageOrCanvas)) {
|
2011-06-07 10:47:54 -07:00
|
|
|
if (canvas->IsWriteOnly()) {
|
|
|
|
LogMessageIfVerbose("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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
|
|
|
*format = WebGLTexelFormat::BGRA8; // careful, our ARGB means BGRA
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatRGB24:
|
|
|
|
*format = WebGLTexelFormat::BGRX8; // careful, our RGB24 is not tightly packed. Whence BGRX8.
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatA8:
|
|
|
|
*format = WebGLTexelFormat::A8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
*format = WebGLTexelFormat::RGB565;
|
|
|
|
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-01-14 09:43:00 -08:00
|
|
|
template<JSBool TypedArrayTest(JSObject* obj, JSContext* cx),
|
|
|
|
JSObject* TypedArrayCopy(JSContext* cx, JSObject* src)>
|
2012-03-16 02:52:42 -07:00
|
|
|
static JSObject*
|
|
|
|
GetTypedArray(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
|
|
|
if (!aValue.isObject()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject& value = aValue.toObject();
|
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
if (TypedArrayTest(&value, aCx)) {
|
2012-03-16 02:52:42 -07:00
|
|
|
return &value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JS_IsArrayObject(aCx, &value)) {
|
2012-01-14 09:43:00 -08:00
|
|
|
return TypedArrayCopy(aCx, &value);
|
2012-03-16 02:52:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSObject*
|
|
|
|
GetFloat32Array(JSContext* aCx, const JS::Value& aValue)
|
|
|
|
{
|
2012-01-14 09:43:00 -08:00
|
|
|
return GetTypedArray<JS_IsFloat32Array, JS_NewFloat32ArrayFromArray>(aCx, aValue);
|
2012-03-16 02:52:42 -07:00
|
|
|
}
|
|
|
|
|
2010-07-16 07:30:32 -07:00
|
|
|
#define OBTAIN_UNIFORM_LOCATION(info) \
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!ValidateObjectAllowNull(info, location_object)) \
|
|
|
|
return; \
|
|
|
|
if (!location_object) \
|
|
|
|
return; \
|
2011-05-20 12:53:54 -07:00
|
|
|
/* the need to check specifically for !mCurrentProgram here is explained in bug 657556 */ \
|
|
|
|
if (!mCurrentProgram) \
|
|
|
|
return ErrorInvalidOperation("%s: no program is currently bound", info); \
|
|
|
|
if (mCurrentProgram != location_object->Program()) \
|
2010-07-16 07:31:53 -07:00
|
|
|
return ErrorInvalidOperation("%s: this uniform location doesn't correspond to the current program", info); \
|
2010-06-08 14:25:27 -07:00
|
|
|
if (mCurrentProgram->Generation() != location_object->ProgramGeneration()) \
|
2010-07-16 07:31:53 -07:00
|
|
|
return ErrorInvalidOperation("%s: This uniform location is obsolete since the program has been relinked", info); \
|
2010-06-01 23:09:19 -07:00
|
|
|
GLint location = location_object->Location();
|
|
|
|
|
2012-05-03 13:54:14 -07:00
|
|
|
#define SIMPLE_ARRAY_METHOD_UNIFORM(name, cnt, arrayType, ptrType) \
|
2012-03-16 02:52:42 -07:00
|
|
|
NS_IMETHODIMP \
|
|
|
|
WebGLContext::name(nsIWebGLUniformLocation *aLocation, const JS::Value& aValue, \
|
|
|
|
JSContext* aCx) \
|
|
|
|
{ \
|
2012-01-14 09:43:00 -08:00
|
|
|
JSObject* wa = GetTypedArray<JS_Is ## arrayType ## Array, JS_New ## arrayType ## ArrayFromArray>(aCx, aValue); \
|
2012-03-16 02:52:42 -07:00
|
|
|
if (!wa) { \
|
|
|
|
return NS_ERROR_FAILURE; \
|
|
|
|
} \
|
2012-05-04 09:38:44 -07:00
|
|
|
arrayType ## Array arr(aCx, wa); \
|
|
|
|
name(static_cast<WebGLUniformLocation*>(aLocation), arr); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void \
|
|
|
|
WebGLContext::name##_base(WebGLUniformLocation *location_object, \
|
|
|
|
uint32_t arrayLength, ptrType* data) { \
|
2012-03-16 02:52:42 -07:00
|
|
|
if (!IsContextStable()) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
return; \
|
2012-03-16 02:52:42 -07:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
2012-05-03 13:54:14 -07:00
|
|
|
int elementSize = location_object->ElementSize(); \
|
|
|
|
if (cnt != elementSize) { \
|
2012-04-16 12:56:12 -07:00
|
|
|
return ErrorInvalidOperation( \
|
|
|
|
#name ": this function expected a uniform of element size %d," \
|
|
|
|
" got a uniform of element size %d", \
|
2012-05-03 13:54:14 -07:00
|
|
|
cnt, \
|
|
|
|
elementSize); \
|
2012-04-16 12:56:12 -07:00
|
|
|
} \
|
|
|
|
const WebGLUniformInfo& info = location_object->Info(); \
|
2012-05-03 13:54:14 -07:00
|
|
|
PRUint32 expectedArrayLength = cnt * info.arraySize; \
|
|
|
|
if (arrayLength < expectedArrayLength || \
|
|
|
|
(arrayLength % cnt)) \
|
2012-04-16 12:56:12 -07:00
|
|
|
{ \
|
|
|
|
return ErrorInvalidValue("%s: expected an array of length a multiple of" \
|
2012-05-03 13:54:14 -07:00
|
|
|
" %d and at least %d, got an array of length %d", \
|
2012-04-16 12:56:12 -07:00
|
|
|
#name, \
|
2012-05-03 13:54:14 -07:00
|
|
|
cnt, \
|
|
|
|
expectedArrayLength, \
|
2012-04-16 12:56:12 -07:00
|
|
|
arrayLength); \
|
|
|
|
} \
|
|
|
|
if (!info.isArray && \
|
2012-05-03 13:54:14 -07:00
|
|
|
arrayLength > expectedArrayLength) { \
|
2012-04-16 12:56:12 -07:00
|
|
|
return ErrorInvalidOperation("%s: expected an array of length exactly %d" \
|
|
|
|
" (since this uniform is not an array uniform)," \
|
2012-05-03 13:54:14 -07:00
|
|
|
" got an array of length %d", \
|
2012-04-16 12:56:12 -07:00
|
|
|
#name, \
|
2012-05-03 13:54:14 -07:00
|
|
|
expectedArrayLength, \
|
2012-04-16 12:56:12 -07:00
|
|
|
arrayLength); \
|
2012-03-16 02:52:42 -07:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
MakeContextCurrent(); \
|
2012-05-04 09:38:44 -07:00
|
|
|
gl->f##name(location, info.arraySize, data); \
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
|
|
|
|
2012-03-16 02:52:42 -07:00
|
|
|
#define SIMPLE_MATRIX_METHOD_UNIFORM(name, dim) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
WebGLContext::name(nsIWebGLUniformLocation* aLocation, bool aTranspose, \
|
|
|
|
const JS::Value& aValue, JSContext* aCx) \
|
|
|
|
{ \
|
|
|
|
JSObject* wa = GetFloat32Array(aCx, aValue); \
|
|
|
|
if (!wa) { \
|
|
|
|
return NS_ERROR_FAILURE; \
|
|
|
|
} \
|
2012-05-04 09:38:44 -07:00
|
|
|
Float32Array arr(aCx, wa); \
|
|
|
|
name(static_cast<WebGLUniformLocation*>(aLocation), aTranspose, arr); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void \
|
|
|
|
WebGLContext::name##_base(WebGLUniformLocation* location_object, \
|
|
|
|
WebGLboolean aTranspose, uint32_t arrayLength, \
|
|
|
|
float* data) \
|
|
|
|
{ \
|
2012-03-16 02:52:42 -07:00
|
|
|
if (!IsContextStable()) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
return; \
|
2012-03-16 02:52:42 -07:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
2012-05-03 13:54:14 -07:00
|
|
|
int elementSize = location_object->ElementSize(); \
|
|
|
|
if (dim*dim != elementSize) { \
|
2012-04-16 12:56:12 -07:00
|
|
|
return ErrorInvalidOperation( \
|
|
|
|
#name ": this function expected a uniform of element size %d," \
|
|
|
|
" got a uniform of element size %d", \
|
2012-05-03 13:54:14 -07:00
|
|
|
dim*dim, \
|
|
|
|
elementSize); \
|
2012-04-16 12:56:12 -07:00
|
|
|
} \
|
|
|
|
const WebGLUniformInfo& info = location_object->Info(); \
|
2012-05-03 13:54:14 -07:00
|
|
|
PRUint32 expectedArrayLength = dim * dim * info.arraySize; \
|
|
|
|
if (arrayLength < expectedArrayLength || \
|
|
|
|
(arrayLength % (dim*dim))) \
|
2012-04-16 12:56:12 -07:00
|
|
|
{ \
|
|
|
|
return ErrorInvalidValue("%s: expected an array of length a multiple of" \
|
2012-05-03 13:54:14 -07:00
|
|
|
" %d and at least %d, got an array of length %d", \
|
2012-04-16 12:56:12 -07:00
|
|
|
#name, \
|
2012-05-03 13:54:14 -07:00
|
|
|
dim*dim, \
|
|
|
|
expectedArrayLength, \
|
2012-04-16 12:56:12 -07:00
|
|
|
arrayLength); \
|
|
|
|
} \
|
2012-05-03 13:54:14 -07:00
|
|
|
if (!info.isArray && \
|
|
|
|
arrayLength > expectedArrayLength) { \
|
2012-04-16 12:56:12 -07:00
|
|
|
return ErrorInvalidOperation("%s: expected an array of length exactly %d" \
|
|
|
|
" (since this uniform is not an array uniform)," \
|
|
|
|
" got an array of length %d", \
|
|
|
|
#name, \
|
2012-05-03 13:54:14 -07:00
|
|
|
expectedArrayLength, \
|
2012-04-16 12:56:12 -07:00
|
|
|
arrayLength); \
|
2012-03-16 02:52:42 -07:00
|
|
|
} \
|
|
|
|
if (aTranspose) { \
|
|
|
|
return ErrorInvalidValue(#name ": transpose must be FALSE as per the " \
|
|
|
|
"OpenGL ES 2.0 spec"); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
MakeContextCurrent(); \
|
2012-05-04 09:38:44 -07:00
|
|
|
gl->f##name(location, info.arraySize, false, data); \
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
#define SIMPLE_METHOD_UNIFORM_1(glname, name, t1) \
|
|
|
|
NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
name(static_cast<WebGLUniformLocation*>(ploc), a1); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void WebGLContext::name(WebGLUniformLocation *location_object, t1 a1) { \
|
|
|
|
if (!IsContextStable()) \
|
|
|
|
return; \
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
|
|
|
MakeContextCurrent(); gl->f##glname(location, a1); \
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SIMPLE_METHOD_UNIFORM_2(glname, name, t1, t2) \
|
|
|
|
NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
name(static_cast<WebGLUniformLocation*>(ploc), a1, a2); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void WebGLContext::name(WebGLUniformLocation *location_object, t1 a1, t2 a2) {\
|
|
|
|
if (!IsContextStable()) \
|
|
|
|
return; \
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
|
|
|
MakeContextCurrent(); gl->f##glname(location, a1, a2); \
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SIMPLE_METHOD_UNIFORM_3(glname, name, t1, t2, t3) \
|
|
|
|
NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2, t3 a3) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
name(static_cast<WebGLUniformLocation*>(ploc), a1, a2, a3); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void WebGLContext::name(WebGLUniformLocation *location_object, t1 a1, t2 a2, t3 a3) {\
|
|
|
|
if (!IsContextStable()) \
|
|
|
|
return; \
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
|
|
|
MakeContextCurrent(); gl->f##glname(location, a1, a2, a3); \
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SIMPLE_METHOD_UNIFORM_4(glname, name, t1, t2, t3, t4) \
|
|
|
|
NS_IMETHODIMP WebGLContext::name(nsIWebGLUniformLocation *ploc, t1 a1, t2 a2, t3 a3, t4 a4) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
name(static_cast<WebGLUniformLocation*>(ploc), a1, a2, a3, a4); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void WebGLContext::name(WebGLUniformLocation *location_object, t1 a1, t2 a2, t3 a3, t4 a4) {\
|
|
|
|
if (!IsContextStable()) \
|
|
|
|
return; \
|
|
|
|
OBTAIN_UNIFORM_LOCATION(#name ": location") \
|
|
|
|
MakeContextCurrent(); gl->f##glname(location, a1, a2, a3, a4); \
|
2010-06-01 23:09:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SIMPLE_METHOD_UNIFORM_1(Uniform1i, Uniform1i, WebGLint)
|
|
|
|
SIMPLE_METHOD_UNIFORM_2(Uniform2i, Uniform2i, WebGLint, WebGLint)
|
|
|
|
SIMPLE_METHOD_UNIFORM_3(Uniform3i, Uniform3i, WebGLint, WebGLint, WebGLint)
|
|
|
|
SIMPLE_METHOD_UNIFORM_4(Uniform4i, Uniform4i, WebGLint, WebGLint, WebGLint, WebGLint)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-01 23:09:19 -07:00
|
|
|
SIMPLE_METHOD_UNIFORM_1(Uniform1f, Uniform1f, WebGLfloat)
|
|
|
|
SIMPLE_METHOD_UNIFORM_2(Uniform2f, Uniform2f, WebGLfloat, WebGLfloat)
|
|
|
|
SIMPLE_METHOD_UNIFORM_3(Uniform3f, Uniform3f, WebGLfloat, WebGLfloat, WebGLfloat)
|
|
|
|
SIMPLE_METHOD_UNIFORM_4(Uniform4f, Uniform4f, WebGLfloat, WebGLfloat, WebGLfloat, WebGLfloat)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform1iv, 1, Int32, WebGLint)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform2iv, 2, Int32, WebGLint)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform3iv, 3, Int32, WebGLint)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform4iv, 4, Int32, WebGLint)
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform1fv, 1, Float32, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform2fv, 2, Float32, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform3fv, 3, Float32, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_UNIFORM(Uniform4fv, 4, Float32, WebGLfloat)
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-03-16 02:52:42 -07:00
|
|
|
SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix2fv, 2)
|
|
|
|
SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix3fv, 3)
|
|
|
|
SIMPLE_MATRIX_METHOD_UNIFORM(UniformMatrix4fv, 4)
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::MozVertexAttrib1f(PRUint32 index, WebGLfloat x0)
|
|
|
|
{
|
|
|
|
VertexAttrib1f(index, x0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::VertexAttrib1f(WebGLuint index, WebGLfloat x0)
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib1f(index, x0);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = 0;
|
|
|
|
mVertexAttrib0Vector[2] = 0;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
|
|
|
if (gl->IsGLES2())
|
|
|
|
gl->fVertexAttrib1f(index, x0);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozVertexAttrib2f(PRUint32 index, WebGLfloat x0, WebGLfloat x1)
|
|
|
|
{
|
|
|
|
VertexAttrib2f(index, x0, x1);
|
2010-09-02 07:34:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::VertexAttrib2f(WebGLuint index, WebGLfloat x0, WebGLfloat x1)
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib2f(index, x0, x1);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = 0;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
|
|
|
if (gl->IsGLES2())
|
|
|
|
gl->fVertexAttrib2f(index, x0, x1);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozVertexAttrib3f(PRUint32 index, WebGLfloat x0, WebGLfloat x1, WebGLfloat x2)
|
|
|
|
{
|
|
|
|
VertexAttrib3f(index, x0, x1, x2);
|
2010-09-02 07:34:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::VertexAttrib3f(WebGLuint index, WebGLfloat x0, WebGLfloat x1, WebGLfloat x2)
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib3f(index, x0, x1, x2);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = x2;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
|
|
|
if (gl->IsGLES2())
|
|
|
|
gl->fVertexAttrib3f(index, x0, x1, x2);
|
|
|
|
}
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2010-09-02 07:34:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozVertexAttrib4f(PRUint32 index, WebGLfloat x0, WebGLfloat x1,
|
|
|
|
WebGLfloat x2, WebGLfloat x3)
|
|
|
|
{
|
|
|
|
VertexAttrib4f(index, x0, x1, x2, x3);
|
2010-09-02 07:34:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::VertexAttrib4f(WebGLuint index, WebGLfloat x0, WebGLfloat x1,
|
|
|
|
WebGLfloat x2, WebGLfloat x3)
|
2010-09-02 07:34:08 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = x2;
|
|
|
|
mVertexAttrib0Vector[3] = x3;
|
|
|
|
if (gl->IsGLES2())
|
|
|
|
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
#define SIMPLE_ARRAY_METHOD_NO_COUNT(name, cnt, ptrType) \
|
2012-03-16 02:53:41 -07:00
|
|
|
NS_IMETHODIMP \
|
|
|
|
WebGLContext::name(WebGLuint idx, const JS::Value& aValue, JSContext* aCx) \
|
|
|
|
{ \
|
|
|
|
JSObject* wa = GetFloat32Array(aCx, aValue); \
|
|
|
|
if (!wa) { \
|
|
|
|
return NS_ERROR_FAILURE; \
|
|
|
|
} \
|
2012-05-04 09:38:44 -07:00
|
|
|
Float32Array arr(aCx, wa); \
|
|
|
|
name(idx, arr); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
void \
|
|
|
|
WebGLContext::name##_base(WebGLuint idx, uint32_t arrayLength, \
|
|
|
|
WebGLfloat* ptr) \
|
|
|
|
{ \
|
2012-03-16 02:53:41 -07:00
|
|
|
if (!IsContextStable()) { \
|
2012-05-04 09:38:44 -07:00
|
|
|
return; \
|
2012-03-16 02:53:41 -07:00
|
|
|
} \
|
2012-05-04 09:38:44 -07:00
|
|
|
if (arrayLength < cnt) { \
|
2012-03-16 02:53:41 -07:00
|
|
|
return ErrorInvalidOperation(#name ": array must be >= %d elements", \
|
|
|
|
cnt); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
MakeContextCurrent(); \
|
|
|
|
if (idx) { \
|
|
|
|
gl->f##name(idx, ptr); \
|
|
|
|
} else { \
|
|
|
|
mVertexAttrib0Vector[0] = ptr[0]; \
|
|
|
|
mVertexAttrib0Vector[1] = cnt > 1 ? ptr[1] : ptrType(0); \
|
|
|
|
mVertexAttrib0Vector[2] = cnt > 2 ? ptr[2] : ptrType(0); \
|
|
|
|
mVertexAttrib0Vector[3] = cnt > 3 ? ptr[3] : ptrType(1); \
|
|
|
|
if (gl->IsGLES2()) \
|
|
|
|
gl->f##name(idx, ptr); \
|
|
|
|
} \
|
2010-09-02 07:34:08 -07:00
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib1fv, 1, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib2fv, 2, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib3fv, 3, WebGLfloat)
|
|
|
|
SIMPLE_ARRAY_METHOD_NO_COUNT(VertexAttrib4fv, 4, WebGLfloat)
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::UseProgram(nsIWebGLProgram *pobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
UseProgram(static_cast<WebGLProgram*>(pobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::UseProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint progname = prog ? prog->GLName() : 0;;
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2011-01-05 13:08:53 -08:00
|
|
|
if (prog && !prog->LinkStatus())
|
|
|
|
return ErrorInvalidOperation("UseProgram: program was not linked successfully");
|
|
|
|
|
|
|
|
gl->fUseProgram(progname);
|
|
|
|
|
2011-10-26 15:13:39 -07:00
|
|
|
mCurrentProgram = prog;
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::ValidateProgram(nsIWebGLProgram *pobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
ValidateProgram(static_cast<WebGLProgram*>(pobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ValidateProgram(WebGLProgram *prog)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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()) {
|
|
|
|
LogMessageIfVerbose("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
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint progname = prog->GLName();
|
2010-05-19 13:46:08 -07:00
|
|
|
gl->fValidateProgram(progname);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-09-17 23:01:07 -07:00
|
|
|
WebGLContext::CreateFramebuffer(nsIWebGLFramebuffer **retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = CreateFramebuffer().get();
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLFramebuffer>
|
|
|
|
WebGLContext::CreateFramebuffer()
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
|
|
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::CreateRenderbuffer(nsIWebGLRenderbuffer **retval)
|
|
|
|
{
|
|
|
|
*retval = CreateRenderbuffer().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-25 05:17:08 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
already_AddRefed<WebGLRenderbuffer>
|
|
|
|
WebGLContext::CreateRenderbuffer()
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return nsnull;
|
|
|
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozViewport(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
|
|
|
|
{
|
|
|
|
Viewport(x, y, width, height);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-06-30 08:48:30 -07:00
|
|
|
WebGLContext::Viewport(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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)
|
2011-01-06 14:07:13 -08: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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::CompileShader(nsIWebGLShader *sobj)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
CompileShader(static_cast<WebGLShader*>(sobj));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::CompileShader(WebGLShader *shader)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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;
|
|
|
|
|
|
|
|
WebGLuint shadername = shader->GLName();
|
2011-01-05 13:08:53 -08:00
|
|
|
|
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-08-09 23:51:56 -07:00
|
|
|
#if defined(USE_ANGLE)
|
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;
|
|
|
|
resources.MaxDrawBuffers = 1;
|
2011-09-30 21:45:50 -07:00
|
|
|
if (mEnabledExtensions[WebGL_OES_standard_derivatives])
|
|
|
|
resources.OES_standard_derivatives = 1;
|
2010-10-09 12:44:25 -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(shader->Source());
|
|
|
|
const nsAString& cleanSource = nsString(stripComments.result().Elements(), stripComments.length());
|
|
|
|
if (!ValidateGLSLString(cleanSource, "compileShader"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-09-07 14:17:44 -07:00
|
|
|
|
|
|
|
const nsPromiseFlatString& flatSource = PromiseFlatString(cleanSource);
|
|
|
|
|
|
|
|
// shaderSource() already checks that the source stripped of comments is in the
|
|
|
|
// 7-bit ASCII range, so we can skip the NS_IsAscii() check.
|
|
|
|
const nsCString& sourceCString = NS_LossyConvertUTF16toASCII(flatSource);
|
2012-03-02 12:42:49 -08:00
|
|
|
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs()) {
|
|
|
|
const PRUint32 maxSourceLength = (PRUint32(1)<<18) - 1;
|
|
|
|
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
|
|
|
|
|
|
|
compiler = ShConstructCompiler((ShShaderType) shader->ShaderType(),
|
|
|
|
SH_WEBGL_SPEC,
|
|
|
|
targetShaderSourceLanguage,
|
|
|
|
&resources);
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
int compileOptions = SH_ATTRIBUTES_UNIFORMS;
|
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;
|
2011-11-07 16:33:51 -08:00
|
|
|
#ifdef XP_MACOSX
|
2012-03-02 12:42:49 -08:00
|
|
|
// work around bug 665578
|
2012-04-10 08:49:10 -07:00
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
!nsCocoaFeatures::OnLionOrLater() &&
|
|
|
|
gl->Vendor() == gl::GLContext::VendorATI)
|
|
|
|
{
|
2012-03-02 12:42:49 -08:00
|
|
|
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
|
|
|
|
2011-10-23 19:46:40 -07:00
|
|
|
if (!ShCompile(compiler, &s, 1, compileOptions)) {
|
2010-10-09 12:44:25 -07:00
|
|
|
int len = 0;
|
|
|
|
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &len);
|
|
|
|
|
|
|
|
if (len) {
|
2010-10-10 20:10:16 -07:00
|
|
|
nsCAutoString info;
|
|
|
|
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-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
int num_attributes = 0;
|
|
|
|
ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTES, &num_attributes);
|
|
|
|
int num_uniforms = 0;
|
|
|
|
ShGetInfo(compiler, SH_ACTIVE_UNIFORMS, &num_uniforms);
|
|
|
|
int attrib_max_length = 0;
|
|
|
|
ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &attrib_max_length);
|
|
|
|
int uniform_max_length = 0;
|
|
|
|
ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &uniform_max_length);
|
|
|
|
int mapped_max_length = 0;
|
|
|
|
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]);
|
|
|
|
|
2012-04-16 12:56:12 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < num_uniforms; i++) {
|
|
|
|
int length, size;
|
|
|
|
ShDataType type;
|
|
|
|
ShGetActiveUniform(compiler, i,
|
|
|
|
&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.
|
|
|
|
shader->mUniformInfos.AppendElement(WebGLUniformInfo(
|
|
|
|
size,
|
|
|
|
length > 1 && mapped_name[length - 1] == ']',
|
|
|
|
type));
|
|
|
|
}
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
if (useShaderSourceTranslation) {
|
2012-04-16 12:56:12 -07:00
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
for (int i = 0; i < num_attributes; i++) {
|
|
|
|
int length, size;
|
|
|
|
ShDataType type;
|
|
|
|
ShGetActiveAttrib(compiler, i,
|
|
|
|
&length, &size, &type,
|
|
|
|
attribute_name,
|
|
|
|
mapped_name);
|
|
|
|
shader->mAttributes.AppendElement(WebGLMappedIdentifier(
|
|
|
|
nsDependentCString(attribute_name),
|
|
|
|
nsDependentCString(mapped_name)));
|
|
|
|
}
|
|
|
|
|
2010-10-09 12:44:25 -07:00
|
|
|
int len = 0;
|
|
|
|
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &len);
|
|
|
|
|
2010-10-10 20:10:16 -07:00
|
|
|
nsCAutoString translatedSrc;
|
|
|
|
translatedSrc.SetLength(len);
|
2010-10-09 12:44:25 -07:00
|
|
|
ShGetObjectCode(compiler, translatedSrc.BeginWriting());
|
|
|
|
|
|
|
|
nsPromiseFlatCString translatedSrc2(translatedSrc);
|
|
|
|
const char *ts = translatedSrc2.get();
|
|
|
|
|
|
|
|
gl->fShaderSource(shadername, 1, &ts, NULL);
|
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.
|
2010-10-09 12:44:25 -07:00
|
|
|
gl->fShaderSource(shadername, 1, &s, NULL);
|
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);
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-01-28 13:15:27 -08:00
|
|
|
NS_IMETHODIMP
|
2012-03-16 02:50:33 -07:00
|
|
|
WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border,
|
2012-01-14 09:43:00 -08:00
|
|
|
const JS::Value& pixels, JSContext *cx)
|
2012-01-28 13:15:27 -08:00
|
|
|
{
|
2012-01-14 09:43:00 -08:00
|
|
|
if (!pixels.isObject() || !JS_IsTypedArrayObject(&pixels.toObject(), cx)) {
|
2012-03-16 02:50:33 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBufferView view(cx, &pixels.toObject());
|
|
|
|
CompressedTexImage2D(target, level, internalformat, width, height, border, view);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::CompressedTexImage2D(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border,
|
|
|
|
ArrayBufferView& view)
|
|
|
|
{
|
2012-03-16 02:50:33 -07:00
|
|
|
if (!IsContextStable()) {
|
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
|
|
|
|
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
|
|
|
if (!tex)
|
|
|
|
return ErrorInvalidOperation("compressedTexImage2D: no texture is bound to this target");
|
|
|
|
|
|
|
|
return ErrorInvalidEnum("compressedTexImage2D: compressed textures are not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-16 02:50:33 -07:00
|
|
|
WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset,
|
|
|
|
WebGLint yoffset, WebGLsizei width, WebGLsizei height,
|
2012-01-14 09:43:00 -08:00
|
|
|
WebGLenum format, const JS::Value& pixels, JSContext *cx)
|
2012-01-28 13:15:27 -08:00
|
|
|
{
|
2012-01-14 09:43:00 -08:00
|
|
|
if (!pixels.isObject() || !JS_IsTypedArrayObject(&pixels.toObject(), cx)) {
|
2012-03-16 02:50:33 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
ArrayBufferView view(cx, &pixels.toObject());
|
|
|
|
CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height,
|
|
|
|
format, view);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::CompressedTexSubImage2D(WebGLenum target, WebGLint level, WebGLint xoffset,
|
|
|
|
WebGLint yoffset, WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, ArrayBufferView& view)
|
|
|
|
{
|
2012-03-16 02:50:33 -07:00
|
|
|
if (!IsContextStable()) {
|
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
|
|
|
|
|
|
|
WebGLTexture *tex = activeBoundTextureForTarget(target);
|
2012-03-16 02:50:33 -07:00
|
|
|
if (!tex) {
|
2012-01-28 13:15:27 -08:00
|
|
|
return ErrorInvalidOperation("compressedTexSubImage2D: no texture is bound to this target");
|
2012-03-16 02:50:33 -07:00
|
|
|
}
|
2012-01-28 13:15:27 -08:00
|
|
|
|
|
|
|
return ErrorInvalidEnum("compressedTexSubImage2D: compressed textures are not supported");
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2009-09-17 23:01:07 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLContext::GetShaderParameter(nsIWebGLShader *sobj, WebGLenum pname, JS::Value *retval)
|
2009-09-17 23:01:07 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetShaderParameter(static_cast<WebGLShader*>(sobj), pname);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetShaderParameter(WebGLShader *shader, WebGLenum pname)
|
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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-04 09:38:44 -07:00
|
|
|
// uint32_t doesn't fit in Int32Value
|
|
|
|
return JS::DoubleValue(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-04 09:38:44 -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
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetShaderInfoLog(nsIWebGLShader *sobj, nsAString& retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
GetShaderInfoLog(static_cast<WebGLShader*>(sobj), retval, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval,
|
|
|
|
ErrorResult& rv)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
const nsCString& tlog = shader->TranslationLog();
|
|
|
|
if (!tlog.IsVoid()) {
|
|
|
|
CopyASCIItoUTF16(tlog, retval);
|
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();
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLuint 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-05-05 18:15:11 -07:00
|
|
|
return rv.Throw(NS_ERROR_FAILURE); // XXX GL Error? should never happen.
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString log;
|
|
|
|
log.SetCapacity(k);
|
|
|
|
|
2011-06-27 10:27:04 -07:00
|
|
|
gl->fGetShaderInfoLog(shadername, k, &k, (char*) log.BeginWriting());
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
log.SetLength(k);
|
|
|
|
|
|
|
|
CopyASCIItoUTF16(log, retval);
|
|
|
|
}
|
|
|
|
|
2011-12-16 13:11:59 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype, nsIWebGLShaderPrecisionFormat **retval)
|
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
*retval = GetShaderPrecisionFormat(shadertype, precisiontype).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
|
|
|
WebGLContext::GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype)
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return nsnull;
|
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);
|
|
|
|
return nsnull;
|
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);
|
|
|
|
return nsnull;
|
2011-12-16 13:11:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GLint range[2], precision;
|
|
|
|
gl->fGetShaderPrecisionFormat(shadertype, precisiontype, range, &precision);
|
|
|
|
|
|
|
|
WebGLShaderPrecisionFormat *retShaderPrecisionFormat
|
|
|
|
= new WebGLShaderPrecisionFormat(range[0], range[1], precision);
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_ADDREF(retShaderPrecisionFormat);
|
|
|
|
return retShaderPrecisionFormat;
|
2011-12-16 13:11:59 -08:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::GetShaderSource(nsIWebGLShader *sobj, nsAString& retval)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
GetShaderSource(static_cast<WebGLShader*>(sobj), retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::GetShaderSource(WebGLShader *shader, nsAString& retval)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-19 13:46:08 -07:00
|
|
|
WebGLContext::ShaderSource(nsIWebGLShader *sobj, const nsAString& source)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
ShaderSource(static_cast<WebGLShader*>(sobj), source);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ShaderSource(WebGLShader *shader, const nsAString& source)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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);
|
|
|
|
const nsAString& cleanSource = nsString(stripComments.result().Elements(), stripComments.length());
|
|
|
|
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
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::MozVertexAttribPointer(WebGLuint index, WebGLint size, WebGLenum type,
|
|
|
|
WebGLboolean normalized, WebGLsizei stride,
|
|
|
|
WebGLintptr byteOffset)
|
|
|
|
{
|
|
|
|
VertexAttribPointer(index, size, type, normalized, stride, byteOffset);
|
2009-09-02 17:47:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::VertexAttribPointer(WebGLuint index, WebGLint size, WebGLenum type,
|
2010-09-02 07:38:26 -07:00
|
|
|
WebGLboolean normalized, WebGLsizei stride,
|
2012-05-04 09:38:44 -07:00
|
|
|
WebGLintptr byteOffset)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-04 09:38:44 -07:00
|
|
|
// XXXbz Preserving the old (buggy) behavior for now. See bug 749497.
|
|
|
|
byteOffset = int32_t(byteOffset);
|
|
|
|
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
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
|
|
|
if (mBoundArrayBuffer == nsnull)
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidOperation("VertexAttribPointer: must have valid GL_ARRAY_BUFFER binding");
|
|
|
|
|
2010-09-02 07:38:26 -07:00
|
|
|
WebGLsizei requiredAlignment = 1;
|
2010-05-15 06:55:45 -07:00
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
2010-09-02 07:38:26 -07:00
|
|
|
requiredAlignment = 1;
|
|
|
|
break;
|
2010-05-15 06:55:45 -07:00
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
2010-09-02 07:38:26 -07:00
|
|
|
requiredAlignment = 2;
|
|
|
|
break;
|
2010-05-15 06:55:45 -07:00
|
|
|
// XXX case LOCAL_GL_FIXED:
|
|
|
|
case LOCAL_GL_FLOAT:
|
2010-09-02 07:38:26 -07:00
|
|
|
requiredAlignment = 4;
|
2010-05-15 06:55:45 -07:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("VertexAttribPointer: type", type);
|
2010-05-15 06:55:45 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-09-02 07:38:26 -07:00
|
|
|
// requiredAlignment should always be a power of two.
|
|
|
|
WebGLsizei requiredAlignmentMask = requiredAlignment - 1;
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttribPointer"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
if (size < 1 || size > 4)
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidValue("VertexAttribPointer: invalid element size");
|
|
|
|
|
2010-09-02 07:38:26 -07:00
|
|
|
if (stride < 0 || stride > 255) // see WebGL spec section 6.6 "Vertex Attribute Data Stride"
|
2011-01-05 13:08:53 -08:00
|
|
|
return ErrorInvalidValue("VertexAttribPointer: negative or too large stride");
|
2010-09-02 07:38:26 -07:00
|
|
|
|
|
|
|
if (byteOffset < 0)
|
|
|
|
return ErrorInvalidValue("VertexAttribPointer: negative offset");
|
|
|
|
|
|
|
|
if (stride & requiredAlignmentMask) {
|
2011-01-05 13:08:53 -08:00
|
|
|
return ErrorInvalidOperation("VertexAttribPointer: stride doesn't satisfy the alignment "
|
|
|
|
"requirement of given type");
|
2010-09-02 07:38:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (byteOffset & requiredAlignmentMask) {
|
2011-01-05 13:08:53 -08:00
|
|
|
return ErrorInvalidOperation("VertexAttribPointer: byteOffset doesn't satisfy the alignment "
|
|
|
|
"requirement of given type");
|
2010-09-02 07:38:26 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-01 16:33:39 -08:00
|
|
|
/* XXX make work with bufferSubData & heterogeneous types
|
2009-09-02 17:47:49 -07:00
|
|
|
if (type != mBoundArrayBuffer->GLType())
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidOperation("VertexAttribPointer: type must match bound VBO type: %d != %d", type, mBoundArrayBuffer->GLType());
|
2009-11-01 16:33:39 -08:00
|
|
|
*/
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
WebGLVertexAttribData &vd = mAttribBuffers[index];
|
|
|
|
|
|
|
|
vd.buf = mBoundArrayBuffer;
|
|
|
|
vd.stride = stride;
|
|
|
|
vd.size = size;
|
2010-06-01 23:09:18 -07:00
|
|
|
vd.byteOffset = byteOffset;
|
|
|
|
vd.type = type;
|
2010-09-02 07:34:08 -07:00
|
|
|
vd.normalized = normalized;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fVertexAttribPointer(index, size, type, normalized,
|
2009-11-01 16:33:39 -08:00
|
|
|
stride,
|
2012-01-16 14:07:18 -08:00
|
|
|
reinterpret_cast<void*>(byteOffset));
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-06-27 10:27:04 -07:00
|
|
|
WebGLContext::TexImage2D(PRInt32)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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);
|
|
|
|
NS_ABORT_IF_FALSE(tex != nsnull, "no texture bound");
|
2011-09-21 23:57:26 -07:00
|
|
|
|
|
|
|
bool sizeMayChange = true;
|
|
|
|
size_t face = WebGLTexture::FaceForTarget(target);
|
|
|
|
|
|
|
|
if (tex->HasImageInfoAt(level, face)) {
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(level, face);
|
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
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::TexImage2D_base(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLsizei width, WebGLsizei height, WebGLsizei srcStrideOrZero,
|
|
|
|
WebGLint border,
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLenum format, WebGLenum type,
|
2010-10-15 14:50:15 -07:00
|
|
|
void *data, PRUint32 byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
int jsArrayType, // a TypedArray format enum, or -1 if not relevant
|
2011-09-28 23:19:26 -07:00
|
|
|
int srcFormat, bool srcPremultiplied)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
2010-08-23 14:03:35 -07:00
|
|
|
break;
|
2010-01-22 13:34:25 -08:00
|
|
|
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:
|
2010-08-23 14:03:35 -07:00
|
|
|
if (width != height)
|
|
|
|
return ErrorInvalidValue("texImage2D: with cube map targets, width and height must be equal");
|
2010-01-22 13:34:25 -08:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
return ErrorInvalidEnumInfo("texImage2D: target", target);
|
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:
|
|
|
|
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");
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
2010-08-23 14:03:35 -07:00
|
|
|
|
|
|
|
if (level < 0)
|
|
|
|
return ErrorInvalidValue("texImage2D: level must be >= 0");
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!(maxTextureSize >> level))
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texImage2D: 2^level exceeds maximum texture size");
|
|
|
|
|
2010-05-19 13:46:08 -07:00
|
|
|
if (width < 0 || height < 0)
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texImage2D: width and height must be >= 0");
|
|
|
|
|
|
|
|
if (width > maxTextureSize || height > maxTextureSize)
|
|
|
|
return ErrorInvalidValue("texImage2D: width or height exceeds maximum texture size");
|
|
|
|
|
|
|
|
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)
|
2010-05-15 06:55:45 -07:00
|
|
|
return ErrorInvalidValue("TexImage2D: border must be 0");
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRUint32 texelSize = 0;
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ValidateTexFormatAndType(format, type, jsArrayType, &texelSize, "texImage2D"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2009-11-01 16:33:47 -08:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_neededByteLength =
|
|
|
|
GetImageSize(height, width, texelSize, mPixelStoreUnpackAlignment);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * texelSize;
|
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
|
|
|
|
|
|
|
if (!checked_neededByteLength.valid())
|
2010-07-03 15:32:19 -07:00
|
|
|
return ErrorInvalidOperation("texImage2D: integer overflow computing the needed buffer size");
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
PRUint32 bytesNeeded = checked_neededByteLength.value();
|
2010-08-23 14:03:35 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (byteLength && byteLength < bytesNeeded)
|
2010-07-03 15:32:19 -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;
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (byteLength) {
|
2010-10-15 14:50:15 -07:00
|
|
|
int dstFormat = GetWebGLTexelFormat(format, type);
|
|
|
|
int actualSrcFormat = srcFormat == WebGLTexelFormat::Auto ? dstFormat : srcFormat;
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t srcStride = srcStrideOrZero ? srcStrideOrZero : checked_alignedRowSize.value();
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t dstPlainRowSize = texelSize * width;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
nsAutoArrayPtr<PRUint8> convertedData(new PRUint8[bytesNeeded]);
|
|
|
|
ConvertImage(width, height, srcStride, dstStride,
|
2011-07-07 17:01:16 -07:00
|
|
|
(PRUint8*)data, convertedData,
|
|
|
|
actualSrcFormat, srcPremultiplied,
|
|
|
|
dstFormat, mPixelStorePremultiplyAlpha, texelSize);
|
|
|
|
error = CheckedTexImage2D(target, level, internalformat,
|
|
|
|
width, height, border, format, type, convertedData);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
2010-01-22 13:34:25 -08:00
|
|
|
} else {
|
2010-05-19 13:46:08 -07:00
|
|
|
// We need some zero pages, because GL doesn't guarantee the
|
|
|
|
// contents of a texture allocated with NULL data.
|
|
|
|
// 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("texImage2D: could not allocate %d bytes (for zero fill)", bytesNeeded);
|
2010-05-19 13:46:08 -07:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
error = CheckedTexImage2D(target, level, internalformat,
|
|
|
|
width, height, border, format, type, tempZeroData);
|
2010-05-19 13:46:08 -07:00
|
|
|
|
|
|
|
free(tempZeroData);
|
2009-11-01 16:33:47 -08:00
|
|
|
}
|
2011-07-07 17:01:16 -07:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
LogMessageIfVerbose("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
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
tex->SetImageInfo(target, level, width, height, format, type);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::TexImage2D_array(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2012-01-14 09:43:00 -08:00
|
|
|
JSObject *pixels, JSContext *cx)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!pixels) {
|
|
|
|
TexImage2D(cx, target, level, internalformat, width, height, border,
|
|
|
|
format, type, nsnull, rv);
|
|
|
|
} else {
|
|
|
|
ArrayBufferView view(cx, pixels);
|
|
|
|
TexImage2D(cx, target, level, internalformat, width, height, border,
|
|
|
|
format, type, &view, rv);
|
|
|
|
}
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
|
|
|
WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLsizei width,
|
|
|
|
WebGLsizei height, WebGLint border, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, ArrayBufferView *pixels, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
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,
|
2012-05-04 09:38:44 -07:00
|
|
|
pixels ? pixels->mData : 0,
|
|
|
|
pixels ? pixels->mLength : 0,
|
|
|
|
pixels ? (int)JS_GetTypedArrayType(pixels->mObj, cx) : -1,
|
2011-10-17 07:59:28 -07:00
|
|
|
WebGLTexelFormat::Auto, false);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::TexImage2D_imageData(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
2012-01-14 09:43:00 -08:00
|
|
|
WebGLsizei width, WebGLsizei height, WebGLint border,
|
|
|
|
WebGLenum format, WebGLenum type,
|
|
|
|
JSObject *pixels, JSContext *cx)
|
2010-10-15 14:50:15 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
NS_ABORT_IF_FALSE(JS_IsTypedArrayObject(pixels, cx), "bad pixels object");
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
TexImage2D_base(target, level, internalformat, width, height, 4*width, border, format, type,
|
|
|
|
pixels ? JS_GetArrayBufferViewData(pixels, cx) : 0,
|
|
|
|
pixels ? JS_GetArrayBufferViewByteLength(pixels, cx) : 0,
|
|
|
|
-1,
|
|
|
|
WebGLTexelFormat::RGBA8, false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLenum internalformat, WebGLenum format,
|
2012-05-05 18:15:11 -07:00
|
|
|
WebGLenum type, ImageData* pixels, ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pixels) {
|
|
|
|
// Spec says to generate an INVALID_VALUE error
|
|
|
|
return ErrorInvalidValue("texImage2D: null ImageData");
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint8ClampedArray arr(cx, pixels->GetDataObject());
|
|
|
|
return TexImage2D_base(target, level, internalformat, pixels->GetWidth(),
|
|
|
|
pixels->GetHeight(), 4*pixels->GetWidth(), 0,
|
|
|
|
format, type, arr.mData, arr.mLength, -1,
|
2011-10-17 07:59:28 -07:00
|
|
|
WebGLTexelFormat::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
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
NS_IMETHODIMP
|
2010-06-15 08:54:03 -07:00
|
|
|
WebGLContext::TexImage2D_dom(WebGLenum target, WebGLint level, WebGLenum internalformat,
|
2012-03-11 00:54:24 -08:00
|
|
|
WebGLenum format, GLenum type, Element* elt)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
TexImage2D(NULL, target, level, internalformat, format, type, elt, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::TexImage2D(JSContext* /* unused */, WebGLenum target,
|
|
|
|
WebGLint level, WebGLenum internalformat,
|
|
|
|
WebGLenum format, WebGLenum type, Element* elt,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
int srcFormat;
|
2012-05-04 09:38:44 -07:00
|
|
|
rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-15 08:54:03 -07:00
|
|
|
|
|
|
|
PRUint32 byteLength = isurf->Stride() * isurf->Height();
|
|
|
|
|
|
|
|
return TexImage2D_base(target, level, internalformat,
|
2010-10-15 14:50:15 -07:00
|
|
|
isurf->Width(), isurf->Height(), isurf->Stride(), 0,
|
2010-06-15 08:54:03 -07:00
|
|
|
format, type,
|
2010-10-15 14:50:15 -07:00
|
|
|
isurf->Data(), byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
-1,
|
2011-01-12 17:45:13 -08:00
|
|
|
srcFormat, mPixelStorePremultiplyAlpha);
|
2010-06-15 08:54:03 -07:00
|
|
|
}
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
NS_IMETHODIMP
|
2011-06-27 10:27:04 -07:00
|
|
|
WebGLContext::TexSubImage2D(PRInt32)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::TexSubImage2D_base(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLsizei width, WebGLsizei height, WebGLsizei srcStrideOrZero,
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLenum format, WebGLenum type,
|
2010-10-15 14:50:15 -07:00
|
|
|
void *pixels, PRUint32 byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
int jsArrayType,
|
2011-09-28 23:19:26 -07:00
|
|
|
int 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
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLsizei maxTextureSize = MaxTextureSizeForTarget(target);
|
2010-08-23 14:03:35 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (level < 0)
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: level must be >= 0");
|
|
|
|
|
2011-02-24 14:17:34 -08:00
|
|
|
if (!(maxTextureSize >> level))
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: 2^level exceeds maximum texture size");
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
if (width < 0 || height < 0)
|
2010-08-23 14:03:35 -07:00
|
|
|
return ErrorInvalidValue("texSubImage2D: width and height must be >= 0");
|
|
|
|
|
|
|
|
if (width > maxTextureSize || height > maxTextureSize)
|
|
|
|
return ErrorInvalidValue("texSubImage2D: width or height exceeds maximum texture size");
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRUint32 texelSize = 0;
|
2011-05-20 12:53:53 -07:00
|
|
|
if (!ValidateTexFormatAndType(format, type, jsArrayType, &texelSize, "texSubImage2D"))
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-06-30 08:49:59 -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 =
|
|
|
|
GetImageSize(height, width, texelSize, mPixelStoreUnpackAlignment);
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * texelSize;
|
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
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
if (!checked_neededByteLength.valid())
|
2010-07-03 15:32:19 -07:00
|
|
|
return ErrorInvalidOperation("texSubImage2D: integer overflow computing the needed buffer size");
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
PRUint32 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");
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
size_t face = WebGLTexture::FaceForTarget(target);
|
2011-09-21 23:57:26 -07:00
|
|
|
|
|
|
|
if (!tex->HasImageInfoAt(level, face))
|
|
|
|
return ErrorInvalidOperation("texSubImage2D: no texture image previously defined for this level and face");
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
const WebGLTexture::ImageInfo &imageInfo = tex->ImageInfoAt(level, face);
|
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
|
|
|
|
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
|
|
|
int dstFormat = GetWebGLTexelFormat(format, type);
|
|
|
|
int actualSrcFormat = srcFormat == WebGLTexelFormat::Auto ? dstFormat : srcFormat;
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t srcStride = srcStrideOrZero ? srcStrideOrZero : checked_alignedRowSize.value();
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
size_t dstPlainRowSize = texelSize * 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
|
|
|
|
{
|
|
|
|
nsAutoArrayPtr<PRUint8> convertedData(new PRUint8[bytesNeeded]);
|
|
|
|
ConvertImage(width, height, srcStride, dstStride,
|
|
|
|
(const PRUint8*)pixels, convertedData,
|
|
|
|
actualSrcFormat, srcPremultiplied,
|
|
|
|
dstFormat, mPixelStorePremultiplyAlpha, texelSize);
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::TexSubImage2D_array(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2012-01-14 09:43:00 -08:00
|
|
|
JSObject *pixels, JSContext *cx)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!pixels) {
|
|
|
|
TexSubImage2D(cx, target, level, xoffset, yoffset, width, height,
|
|
|
|
format, type, nsnull, rv);
|
|
|
|
} else {
|
|
|
|
ArrayBufferView view(cx, pixels);
|
|
|
|
TexSubImage2D(cx, target, level, xoffset, yoffset, width, height,
|
|
|
|
format, type, &view, rv);
|
|
|
|
}
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type,
|
|
|
|
ArrayBufferView* pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
if (!pixels)
|
2010-05-15 06:55:45 -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,
|
2012-05-04 09:38:44 -07:00
|
|
|
pixels->mData, pixels->mLength,
|
|
|
|
JS_GetTypedArrayType(pixels->mObj, cx),
|
2011-10-17 07:59:28 -07:00
|
|
|
WebGLTexelFormat::Auto, false);
|
2010-10-15 14:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLContext::TexSubImage2D_imageData(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLsizei width, WebGLsizei height,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2012-01-14 09:43:00 -08:00
|
|
|
JSObject *pixels, JSContext *cx)
|
2010-10-15 14:50:15 -07:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2011-10-26 13:00:44 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
if (!pixels) {
|
|
|
|
ErrorInvalidValue("TexSubImage2D: pixels must not be null!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
NS_ABORT_IF_FALSE(JS_IsTypedArrayObject(pixels, cx), "bad pixels object");
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
TexSubImage2D_base(target, level, xoffset, yoffset,
|
|
|
|
width, height, 4*width, format, type,
|
|
|
|
JS_GetArrayBufferViewData(pixels, cx), JS_GetArrayBufferViewByteLength(pixels, cx),
|
|
|
|
-1,
|
|
|
|
WebGLTexelFormat::RGBA8, false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLenum format, WebGLenum type, ImageData* pixels,
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult& rv)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
|
|
|
if (!IsContextStable())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!pixels)
|
|
|
|
return ErrorInvalidValue("TexSubImage2D: pixels must not be null!");
|
|
|
|
|
|
|
|
Uint8ClampedArray arr(cx, pixels->GetDataObject());
|
2010-10-15 14:50:15 -07:00
|
|
|
return TexSubImage2D_base(target, level, xoffset, yoffset,
|
2012-05-04 09:38:44 -07:00
|
|
|
pixels->GetWidth(), pixels->GetHeight(),
|
|
|
|
4*pixels->GetWidth(), format, type,
|
|
|
|
arr.mData, arr.mLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
-1,
|
2011-10-17 07:59:28 -07:00
|
|
|
WebGLTexelFormat::RGBA8, false);
|
2010-01-22 13:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::TexSubImage2D_dom(WebGLenum target, WebGLint level,
|
|
|
|
WebGLint xoffset, WebGLint yoffset,
|
2010-06-15 08:54:03 -07:00
|
|
|
WebGLenum format, WebGLenum type,
|
2012-03-11 00:54:24 -08:00
|
|
|
Element *elt)
|
2012-05-04 09:38:44 -07:00
|
|
|
{
|
2012-05-05 18:15:11 -07:00
|
|
|
ErrorResult rv;
|
2012-05-04 09:38:44 -07:00
|
|
|
TexSubImage2D(NULL, target, level, xoffset, yoffset, format, type, elt, rv);
|
2012-05-05 18:15:11 -07:00
|
|
|
return rv.ErrorCode();
|
2012-05-04 09:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::TexSubImage2D(JSContext* /* unused */, WebGLenum target,
|
|
|
|
WebGLint level, WebGLint xoffset, WebGLint yoffset,
|
|
|
|
WebGLenum format, WebGLenum type,
|
2012-05-05 18:15:11 -07:00
|
|
|
dom::Element* elt, ErrorResult& rv)
|
2010-01-22 13:34:25 -08:00
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2011-10-26 13:00:44 -07:00
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
nsRefPtr<gfxImageSurface> isurf;
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
int srcFormat;
|
2012-05-04 09:38:44 -07:00
|
|
|
rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat);
|
2012-05-05 18:15:11 -07:00
|
|
|
if (rv.Failed())
|
2012-05-04 09:38:44 -07:00
|
|
|
return;
|
2010-01-22 13:34:25 -08:00
|
|
|
|
2010-06-15 08:54:03 -07:00
|
|
|
PRUint32 byteLength = isurf->Stride() * isurf->Height();
|
|
|
|
|
2010-01-22 13:34:25 -08:00
|
|
|
return TexSubImage2D_base(target, level,
|
|
|
|
xoffset, yoffset,
|
2010-10-15 14:50:15 -07:00
|
|
|
isurf->Width(), isurf->Height(), isurf->Stride(),
|
|
|
|
format, type,
|
|
|
|
isurf->Data(), byteLength,
|
2011-05-20 12:53:53 -07:00
|
|
|
-1,
|
2011-12-16 14:24:46 -08:00
|
|
|
srcFormat, mPixelStorePremultiplyAlpha);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2011-10-26 13:00:44 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::LoseContext()
|
|
|
|
{
|
2012-01-04 13:12:05 -08:00
|
|
|
if (!IsContextStable())
|
2011-10-26 13:00:44 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ForceLoseContext();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::RestoreContext()
|
|
|
|
{
|
2012-01-04 13:12:03 -08:00
|
|
|
if (IsContextStable() || !mAllowRestore) {
|
2011-10-26 13:00:44 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ForceRestoreContext();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-05-28 15:52:39 -07:00
|
|
|
BaseTypeAndSizeFromUniformType(WebGLenum uType, WebGLenum *baseType, WebGLint *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
|
|
|
|
|
|
|
|
|
|
|
int mozilla::GetWebGLTexelFormat(GLenum format, GLenum type)
|
|
|
|
{
|
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:
|
|
|
|
return WebGLTexelFormat::RGBA8;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
return WebGLTexelFormat::RGB8;
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
return WebGLTexelFormat::A8;
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
return WebGLTexelFormat::R8;
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
return WebGLTexelFormat::RA8;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding mistake?! Should never reach this point.");
|
2010-10-15 14:50:15 -07:00
|
|
|
return WebGLTexelFormat::Generic;
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
} else if (type == LOCAL_GL_FLOAT) {
|
|
|
|
// OES_texture_float
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
return WebGLTexelFormat::RGBA32F;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
return WebGLTexelFormat::RGB32F;
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
return WebGLTexelFormat::A32F;
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
return WebGLTexelFormat::R32F;
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
return WebGLTexelFormat::RA32F;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding mistake?! Should never reach this point.");
|
2011-05-20 12:53:53 -07:00
|
|
|
return WebGLTexelFormat::Generic;
|
|
|
|
}
|
2010-10-15 14:50:15 -07:00
|
|
|
} else {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
return WebGLTexelFormat::RGBA4444;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
return WebGLTexelFormat::RGBA5551;
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
return WebGLTexelFormat::RGB565;
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "Coding mistake?! Should never reach this point.");
|
2010-10-15 14:50:15 -07:00
|
|
|
return WebGLTexelFormat::Generic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
|
|
WebGLenum
|
|
|
|
InternalFormatForFormatAndType(WebGLenum format, WebGLenum type, bool isGLES2)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|