2012-03-16 13:50:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-18 10:01:12 +04:00
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
#include "WebGLContext.h"
|
2016-07-05 06:35:20 +03:00
|
|
|
#include "WebGL2Context.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
#include "WebGLActiveInfo.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
#include "WebGLContextUtils.h"
|
2013-06-11 00:00:35 +04:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
|
|
|
#include "WebGLShader.h"
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
#include "WebGLUniformLocation.h"
|
2015-07-17 03:28:14 +03:00
|
|
|
#include "WebGLFormats.h"
|
2013-06-11 00:00:35 +04:00
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
#include "WebGLShaderPrecisionFormat.h"
|
|
|
|
#include "WebGLTexture.h"
|
2013-06-22 03:44:17 +04:00
|
|
|
#include "WebGLExtensions.h"
|
2013-06-28 01:07:21 +04:00
|
|
|
#include "WebGLVertexArray.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-07-08 04:01:16 +04:00
|
|
|
#include "nsDebug.h"
|
2014-05-14 04:15:19 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "nsString.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
|
|
|
#include "CanvasUtils.h"
|
2014-04-17 09:29:52 +04:00
|
|
|
#include "gfxUtils.h"
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-01-14 21:43:00 +04:00
|
|
|
#include "jsfriendapi.h"
|
2010-01-23 00:34:25 +03:00
|
|
|
|
2010-10-16 01:50:15 +04:00
|
|
|
#include "WebGLTexelConversions.h"
|
2011-09-08 01:17:44 +04:00
|
|
|
#include "WebGLValidateStrings.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-10-16 01:50:15 +04:00
|
|
|
|
2011-11-08 04:33:51 +04:00
|
|
|
// needed to check if current OS is lower than 10.7
|
|
|
|
#if defined(MOZ_WIDGET_COCOA)
|
|
|
|
#include "nsCocoaFeatures.h"
|
|
|
|
#endif
|
|
|
|
|
2014-06-04 05:31:43 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2012-05-04 20:38:44 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-08-23 09:17:11 +04:00
|
|
|
#include "mozilla/dom/ImageData.h"
|
2014-04-10 22:57:42 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2016-05-22 23:31:11 +03:00
|
|
|
#include "mozilla/EndianUtils.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-11-06 00:24:24 +03:00
|
|
|
#include "mozilla/UniquePtrExtensions.h"
|
2012-05-04 20:38:44 +04:00
|
|
|
|
2015-07-15 03:37:28 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-12-01 02:27:20 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::ValidateObject(const char* funcName, const WebGLProgram& object)
|
|
|
|
{
|
|
|
|
return ValidateObject(funcName, object, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::ValidateObject(const char* funcName, const WebGLShader& object)
|
|
|
|
{
|
|
|
|
return ValidateObject(funcName, object, true);
|
|
|
|
}
|
|
|
|
|
2012-03-11 12:54:24 +04:00
|
|
|
using namespace mozilla::dom;
|
2015-01-13 11:07:26 +03:00
|
|
|
using namespace mozilla::gfx;
|
2015-01-16 02:40:39 +03:00
|
|
|
using namespace mozilla::gl;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
//
|
|
|
|
// WebGL API
|
|
|
|
//
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::ActiveTexture(GLenum texture)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2014-01-23 07:59:33 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2012-04-10 19:51:30 +04:00
|
|
|
if (texture < LOCAL_GL_TEXTURE0 ||
|
2017-07-27 10:49:21 +03:00
|
|
|
texture >= LOCAL_GL_TEXTURE0 + mGLMaxTextureUnits)
|
2012-04-10 19:51:30 +04: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-03 04:47:49 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
mActiveTexture = texture - LOCAL_GL_TEXTURE0;
|
|
|
|
gl->fActiveTexture(texture);
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::AttachShader(WebGLProgram& program, WebGLShader& shader)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-09-13 19:57:25 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("attachShader: program", program) ||
|
|
|
|
!ValidateObject("attachShader: shader", shader))
|
2015-01-16 02:40:39 +03:00
|
|
|
{
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2015-01-16 02:40:39 +03:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
program.AttachShader(&shader);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::BindAttribLocation(WebGLProgram& prog, GLuint location,
|
2012-05-04 20:38:44 +04:00
|
|
|
const nsAString& name)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("bindAttribLocation: program", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
prog.BindAttribLocation(location, name);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::BindFramebuffer(GLenum target, WebGLFramebuffer* wfb)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, "bindFramebuffer"))
|
|
|
|
return;
|
2010-05-15 16:07:30 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (wfb && !ValidateObject("bindFramebuffer", *wfb))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-09-01 23:28:34 +04:00
|
|
|
|
2010-05-20 00:46:08 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
if (!wfb) {
|
2013-02-14 03:26:24 +04:00
|
|
|
gl->fBindFramebuffer(target, 0);
|
2010-07-19 09:01:14 +04:00
|
|
|
} else {
|
2015-05-21 02:50:28 +03:00
|
|
|
GLuint framebuffername = wfb->mGLName;
|
2010-07-19 09:01:14 +04:00
|
|
|
gl->fBindFramebuffer(target, framebuffername);
|
2015-05-21 02:50:28 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
wfb->mIsFB = true;
|
|
|
|
#endif
|
2010-07-19 09:01:14 +04:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
mBoundDrawFramebuffer = wfb;
|
|
|
|
mBoundReadFramebuffer = wfb;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
mBoundDrawFramebuffer = wfb;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
mBoundReadFramebuffer = wfb;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::BindRenderbuffer(GLenum target, WebGLRenderbuffer* wrb)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-05-15 16:07:30 +04:00
|
|
|
|
2009-09-03 04:47:49 +04:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER)
|
2010-07-16 18:31:48 +04:00
|
|
|
return ErrorInvalidEnumInfo("bindRenderbuffer: target", target);
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (wrb && !ValidateObject("bindRenderbuffer", *wrb))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-09-01 23:28:34 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
// Usually, we would now call into glBindRenderbuffer. However, since we have to
|
|
|
|
// potentially emulate packed-depth-stencil, there's not a specific renderbuffer that
|
|
|
|
// we know we should bind here.
|
|
|
|
// Instead, we do all renderbuffer binding lazily.
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2013-10-02 04:31:09 +04:00
|
|
|
if (wrb) {
|
2016-02-13 06:31:58 +03:00
|
|
|
wrb->mHasBeenBound = true;
|
2013-10-02 04:31:09 +04:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-05-15 16:07:30 +04:00
|
|
|
mBoundRenderbuffer = wrb;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void WebGLContext::BlendEquation(GLenum mode)
|
2010-06-19 18:48:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateBlendEquationEnum(mode, "blendEquation: mode"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-06-19 18:48:44 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendEquation(mode);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void WebGLContext::BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
|
2010-06-19 18:48:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateBlendEquationEnum(modeRGB, "blendEquationSeparate: modeRGB") ||
|
|
|
|
!ValidateBlendEquationEnum(modeAlpha, "blendEquationSeparate: modeAlpha"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-06-19 18:48:44 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendEquationSeparate(modeRGB, modeAlpha);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
|
|
|
|
2017-06-24 03:31:05 +03:00
|
|
|
static bool
|
|
|
|
ValidateBlendFuncEnum(WebGLContext* webgl, GLenum factor, const char* funcName, const char* varName)
|
|
|
|
{
|
|
|
|
switch (factor) {
|
|
|
|
case LOCAL_GL_ZERO:
|
|
|
|
case LOCAL_GL_ONE:
|
|
|
|
case LOCAL_GL_SRC_COLOR:
|
|
|
|
case LOCAL_GL_ONE_MINUS_SRC_COLOR:
|
|
|
|
case LOCAL_GL_DST_COLOR:
|
|
|
|
case LOCAL_GL_ONE_MINUS_DST_COLOR:
|
|
|
|
case LOCAL_GL_SRC_ALPHA:
|
|
|
|
case LOCAL_GL_ONE_MINUS_SRC_ALPHA:
|
|
|
|
case LOCAL_GL_DST_ALPHA:
|
|
|
|
case LOCAL_GL_ONE_MINUS_DST_ALPHA:
|
|
|
|
case LOCAL_GL_CONSTANT_COLOR:
|
|
|
|
case LOCAL_GL_ONE_MINUS_CONSTANT_COLOR:
|
|
|
|
case LOCAL_GL_CONSTANT_ALPHA:
|
|
|
|
case LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA:
|
|
|
|
case LOCAL_GL_SRC_ALPHA_SATURATE:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
const nsPrintfCString err("%s: %s", funcName, varName);
|
|
|
|
webgl->ErrorInvalidEnumInfo(err.get(), factor);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-24 02:19:49 +03:00
|
|
|
static bool
|
|
|
|
ValidateBlendFuncEnums(WebGLContext* webgl, GLenum srcRGB, GLenum srcAlpha,
|
|
|
|
GLenum dstRGB, GLenum dstAlpha, const char* funcName)
|
|
|
|
{
|
|
|
|
if (!webgl->IsWebGL2()) {
|
|
|
|
if (dstRGB == LOCAL_GL_SRC_ALPHA_SATURATE || dstAlpha == LOCAL_GL_SRC_ALPHA_SATURATE) {
|
|
|
|
const nsPrintfCString err("%s: LOCAL_GL_SRC_ALPHA_SATURATE as a destination"
|
|
|
|
" blend function is disallowed in WebGL 1 (dstRGB ="
|
|
|
|
" 0x%04x, dstAlpha = 0x%04x).",
|
|
|
|
funcName, dstRGB, dstAlpha);
|
|
|
|
webgl->ErrorInvalidEnum("%s", err.get());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-24 03:31:05 +03:00
|
|
|
if (!ValidateBlendFuncEnum(webgl, srcRGB, funcName, "srcRGB") ||
|
|
|
|
!ValidateBlendFuncEnum(webgl, srcAlpha, funcName, "srcAlpha") ||
|
|
|
|
!ValidateBlendFuncEnum(webgl, dstRGB, funcName, "dstRGB") ||
|
|
|
|
!ValidateBlendFuncEnum(webgl, dstAlpha, funcName, "dstAlpha"))
|
2017-06-24 02:19:49 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
void WebGLContext::BlendFunc(GLenum sfactor, GLenum dfactor)
|
2010-06-19 18:48:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2017-06-24 02:19:49 +03:00
|
|
|
if (!ValidateBlendFuncEnums(this, sfactor, sfactor, dfactor, dfactor, "blendFunc"))
|
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-12-06 14:34:35 +03:00
|
|
|
if (!ValidateBlendFuncEnumsCompatibility(sfactor, dfactor, "blendFuncSeparate: srcRGB and dstRGB"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-12-06 14:34:35 +03:00
|
|
|
|
2010-06-19 18:48:44 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendFunc(sfactor, dfactor);
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
|
|
|
|
GLenum srcAlpha, GLenum dstAlpha)
|
2010-06-19 18:48:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2017-06-24 02:19:49 +03:00
|
|
|
if (!ValidateBlendFuncEnums(this, srcRGB, srcAlpha, dstRGB, dstAlpha, "blendFuncSeparate"))
|
|
|
|
return;
|
2010-06-19 18:48:44 +04:00
|
|
|
|
2010-12-06 14:34:35 +03: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 20:38:44 +04:00
|
|
|
return;
|
2010-12-06 14:34:35 +03:00
|
|
|
|
2010-06-19 18:48:44 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLenum
|
|
|
|
WebGLContext::CheckFramebufferStatus(GLenum target)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "checkFramebufferStatus";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_UNSUPPORTED;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2012-05-04 20:38:44 +04:00
|
|
|
return 0;
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
WebGLFramebuffer* fb;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2010-11-05 22:57:58 +03:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (!fb)
|
2012-05-04 20:38:44 +04:00
|
|
|
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
|
2013-10-02 04:30:05 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
return fb->CheckFramebufferStatus(funcName).get();
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLProgram>
|
|
|
|
WebGLContext::CreateProgram()
|
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLProgram> globj = new WebGLProgram(this);
|
2012-05-04 20:38:44 +04:00
|
|
|
return globj.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<WebGLShader>
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::CreateShader(GLenum type)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2010-06-04 23:03:33 +04:00
|
|
|
if (type != LOCAL_GL_VERTEX_SHADER &&
|
|
|
|
type != LOCAL_GL_FRAGMENT_SHADER)
|
|
|
|
{
|
2012-05-04 20:38:44 +04:00
|
|
|
ErrorInvalidEnumInfo("createShader: type", type);
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-04 23:03:33 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLShader> shader = new WebGLShader(this, type);
|
2012-05-04 20:38:44 +04:00
|
|
|
return shader.forget();
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::CullFace(GLenum face)
|
2010-07-04 02:33:05 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-07-04 02:33:05 +04:00
|
|
|
if (!ValidateFaceEnum(face, "cullFace"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-07-04 02:33:05 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fCullFace(face);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
|
|
|
WebGLContext::DeleteFramebuffer(WebGLFramebuffer* fbuf)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateDeleteObject("deleteFramebuffer", fbuf))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
fbuf->RequestDelete();
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (mBoundReadFramebuffer == mBoundDrawFramebuffer) {
|
|
|
|
if (mBoundDrawFramebuffer == fbuf) {
|
|
|
|
BindFramebuffer(LOCAL_GL_FRAMEBUFFER,
|
|
|
|
static_cast<WebGLFramebuffer*>(nullptr));
|
|
|
|
}
|
|
|
|
} else if (mBoundDrawFramebuffer == fbuf) {
|
|
|
|
BindFramebuffer(LOCAL_GL_DRAW_FRAMEBUFFER,
|
2012-07-30 18:20:58 +04:00
|
|
|
static_cast<WebGLFramebuffer*>(nullptr));
|
2015-01-13 02:05:21 +03:00
|
|
|
} else if (mBoundReadFramebuffer == fbuf) {
|
|
|
|
BindFramebuffer(LOCAL_GL_READ_FRAMEBUFFER,
|
|
|
|
static_cast<WebGLFramebuffer*>(nullptr));
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteRenderbuffer(WebGLRenderbuffer* rbuf)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2017-01-12 04:10:48 +03:00
|
|
|
const char funcName[] = "deleteRenderbuffer";
|
|
|
|
if (!ValidateDeleteObject(funcName, rbuf))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (mBoundDrawFramebuffer)
|
2017-01-12 04:10:48 +03:00
|
|
|
mBoundDrawFramebuffer->DetachRenderbuffer(funcName, rbuf);
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
if (mBoundReadFramebuffer)
|
2017-01-12 04:10:48 +03:00
|
|
|
mBoundReadFramebuffer->DetachRenderbuffer(funcName, rbuf);
|
2011-12-04 23:15:43 +04:00
|
|
|
|
2017-01-12 04:10:48 +03:00
|
|
|
rbuf->InvalidateStatusOfAttachedFBs(funcName);
|
2014-03-04 11:14:35 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
if (mBoundRenderbuffer == rbuf)
|
2015-03-25 02:00:28 +03:00
|
|
|
BindRenderbuffer(LOCAL_GL_RENDERBUFFER, nullptr);
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
rbuf->RequestDelete();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteTexture(WebGLTexture* tex)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2017-01-12 04:10:48 +03:00
|
|
|
const char funcName[] = "deleteTexture";
|
|
|
|
if (!ValidateDeleteObject(funcName, tex))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
if (mBoundDrawFramebuffer)
|
2017-01-12 04:10:48 +03:00
|
|
|
mBoundDrawFramebuffer->DetachTexture(funcName, tex);
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
if (mBoundReadFramebuffer)
|
2017-01-12 04:10:48 +03:00
|
|
|
mBoundReadFramebuffer->DetachTexture(funcName, tex);
|
2011-12-04 23:15:43 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint activeTexture = mActiveTexture;
|
2017-07-27 10:49:21 +03:00
|
|
|
for (uint32_t i = 0; i < mGLMaxTextureUnits; i++) {
|
2015-11-25 07:15:29 +03:00
|
|
|
if (mBound2DTextures[i] == tex ||
|
|
|
|
mBoundCubeMapTextures[i] == tex ||
|
|
|
|
mBound3DTextures[i] == tex ||
|
|
|
|
mBound2DArrayTextures[i] == tex)
|
2011-12-04 23:15:42 +04:00
|
|
|
{
|
|
|
|
ActiveTexture(LOCAL_GL_TEXTURE0 + i);
|
2015-11-25 07:15:29 +03:00
|
|
|
BindTexture(tex->Target().get(), nullptr);
|
2011-12-04 23:15:42 +04:00
|
|
|
}
|
|
|
|
}
|
2012-12-19 07:23:03 +04:00
|
|
|
ActiveTexture(LOCAL_GL_TEXTURE0 + activeTexture);
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
tex->RequestDelete();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteProgram(WebGLProgram* prog)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateDeleteObject("deleteProgram", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
prog->RequestDelete();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::DeleteShader(WebGLShader* shader)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateDeleteObject("deleteShader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-12-04 23:15:42 +04:00
|
|
|
shader->RequestDelete();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::DetachShader(WebGLProgram& program, const WebGLShader& shader)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
// It's valid to attempt to detach a deleted shader, since it's still a
|
|
|
|
// shader.
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("detachShader: program", program) ||
|
|
|
|
!ValidateObjectAllowDeleted("detachShader: shader", shader))
|
2015-01-16 02:40:39 +03:00
|
|
|
{
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2015-01-16 02:40:39 +03:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
program.DetachShader(&shader);
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2010-06-04 23:03:33 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::DepthFunc(GLenum func)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateComparisonEnum(func, "depthFunc"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-06-30 19:48:30 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fDepthFunc(func);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::DepthRange(GLfloat zNear, GLfloat zFar)
|
2010-12-06 14:34:35 +03:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-12-06 14:34:35 +03:00
|
|
|
if (zNear > zFar)
|
|
|
|
return ErrorInvalidOperation("depthRange: the near value is greater than the far value!");
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fDepthRange(zNear, zFar);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::FramebufferRenderbuffer(GLenum target, GLenum attachment,
|
|
|
|
GLenum rbtarget, WebGLRenderbuffer* wrb)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "framebufferRenderbuffer";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2015-01-13 02:05:21 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
WebGLFramebuffer* fb;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
break;
|
2011-01-06 00:08:53 +03:00
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2014-09-25 19:21:33 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!fb)
|
|
|
|
return ErrorInvalidOperation("%s: Cannot modify framebuffer 0.", funcName);
|
2014-09-25 19:21:33 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fb->FramebufferRenderbuffer(funcName, attachment, rbtarget, wrb);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::FramebufferTexture2D(GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum textarget,
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLTexture* tobj,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLint level)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-07-19 10:36:54 +03:00
|
|
|
const char funcName[] = "framebufferTexture2D";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2015-02-18 02:52:51 +03:00
|
|
|
return;
|
|
|
|
|
2015-01-13 02:05:21 +03:00
|
|
|
WebGLFramebuffer* fb;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
if (!fb)
|
|
|
|
return ErrorInvalidOperation("%s: Cannot modify framebuffer 0.", funcName);
|
2014-09-25 19:21:33 +04:00
|
|
|
|
2016-07-19 10:36:54 +03:00
|
|
|
fb->FramebufferTexture2D(funcName, attachment, textarget, tobj, level);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::FrontFace(GLenum mode)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
switch (mode) {
|
|
|
|
case LOCAL_GL_CW:
|
|
|
|
case LOCAL_GL_CCW:
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-16 18:31:48 +04:00
|
|
|
return ErrorInvalidEnumInfo("frontFace: mode", mode);
|
2010-06-30 19:48:30 +04:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFrontFace(mode);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetActiveAttrib(const WebGLProgram& prog, GLuint index)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getActiveAttrib: program", prog))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return prog.GetActiveAttrib(index);
|
2015-01-16 02:40:39 +03:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
already_AddRefed<WebGLActiveInfo>
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetActiveUniform(const WebGLProgram& prog, GLuint index)
|
2015-01-16 02:40:39 +03:00
|
|
|
{
|
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getActiveUniform: program", prog))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-01-10 08:03:54 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return prog.GetActiveUniform(index);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetAttachedShaders(const WebGLProgram& prog,
|
2015-10-18 08:24:48 +03:00
|
|
|
dom::Nullable<nsTArray<RefPtr<WebGLShader>>>& retval)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
|
|
|
retval.SetNull();
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getAttachedShaders", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
prog.GetAttachedShaders(&retval.SetValue());
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLint
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetAttribLocation(const WebGLProgram& prog, const nsAString& name)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return -1;
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getAttribLocation: program", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return -1;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return prog.GetAttribLocation(name);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::GetBufferParameter(GLenum target, GLenum pname)
|
2009-11-18 23:42:35 +03:00
|
|
|
{
|
2016-12-29 11:08:39 +03:00
|
|
|
const char funcName[] = "getBufferParameter";
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-12-29 11:08:39 +03:00
|
|
|
const auto& slot = ValidateBufferSlot(funcName, target);
|
|
|
|
if (!slot)
|
2014-10-24 02:10:57 +04:00
|
|
|
return JS::NullValue();
|
2016-12-29 11:08:39 +03:00
|
|
|
const auto& buffer = *slot;
|
|
|
|
|
|
|
|
if (!buffer) {
|
|
|
|
ErrorInvalidOperation("%s: Buffer for `target` is null.", funcName);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2009-11-18 23:42:35 +03:00
|
|
|
switch (pname) {
|
2016-09-28 00:03:48 +03:00
|
|
|
case LOCAL_GL_BUFFER_SIZE:
|
|
|
|
return JS::NumberValue(buffer->ByteLength());
|
2009-11-18 23:42:35 +03:00
|
|
|
|
2016-09-28 00:03:48 +03:00
|
|
|
case LOCAL_GL_BUFFER_USAGE:
|
|
|
|
return JS::NumberValue(buffer->Usage());
|
2009-11-18 23:42:35 +03:00
|
|
|
|
2016-09-28 00:03:48 +03:00
|
|
|
default:
|
|
|
|
ErrorInvalidEnumInfo("getBufferParameter: parameter", pname);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2010-06-19 18:42:43 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
|
|
|
WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
|
2013-09-04 16:14:43 +04:00
|
|
|
GLenum target,
|
|
|
|
GLenum attachment,
|
|
|
|
GLenum pname,
|
2012-05-06 05:15:11 +04:00
|
|
|
ErrorResult& rv)
|
2009-11-18 23:42:35 +03:00
|
|
|
{
|
2015-11-25 07:15:29 +03:00
|
|
|
const char funcName[] = "getFramebufferAttachmentParameter";
|
|
|
|
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2009-11-18 23:42:35 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (!ValidateFramebufferTarget(target, funcName))
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2015-01-13 02:05:21 +03:00
|
|
|
|
|
|
|
WebGLFramebuffer* fb;
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER:
|
|
|
|
case LOCAL_GL_DRAW_FRAMEBUFFER:
|
|
|
|
fb = mBoundDrawFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_READ_FRAMEBUFFER:
|
|
|
|
fb = mBoundReadFramebuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_CRASH("GFX: Bad target.");
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2009-11-18 23:42:35 +03:00
|
|
|
|
2016-04-27 19:58:47 +03:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (fb)
|
|
|
|
return fb->GetAttachmentParameter(funcName, cx, target, attachment, pname, &rv);
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
|
|
|
|
if (!IsWebGL2()) {
|
|
|
|
ErrorInvalidOperation("%s: Querying against the default framebuffer is not"
|
|
|
|
" allowed in WebGL 1.",
|
|
|
|
funcName);
|
2014-03-06 02:16:02 +04:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
switch (attachment) {
|
2016-01-11 21:56:00 +03:00
|
|
|
case LOCAL_GL_BACK:
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_DEPTH:
|
|
|
|
case LOCAL_GL_STENCIL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ErrorInvalidEnum("%s: For the default framebuffer, can only query COLOR, DEPTH,"
|
|
|
|
" or STENCIL.",
|
|
|
|
funcName);
|
2014-09-25 19:21:33 +04:00
|
|
|
return JS::NullValue();
|
2015-01-13 02:05:21 +03:00
|
|
|
}
|
2013-06-22 03:44:17 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
|
2016-07-22 14:42:00 +03:00
|
|
|
switch (attachment) {
|
|
|
|
case LOCAL_GL_BACK:
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH:
|
|
|
|
if (!mOptions.depth) {
|
|
|
|
return JS::Int32Value(LOCAL_GL_NONE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_STENCIL:
|
|
|
|
if (!mOptions.stencil) {
|
|
|
|
return JS::Int32Value(LOCAL_GL_NONE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ErrorInvalidEnum("%s: With the default framebuffer, can only query COLOR, DEPTH,"
|
|
|
|
" or STENCIL for GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE",
|
|
|
|
funcName);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::Int32Value(LOCAL_GL_FRAMEBUFFER_DEFAULT);
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////
|
2014-01-11 01:42:09 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
|
2016-01-11 21:56:00 +03:00
|
|
|
if (attachment == LOCAL_GL_BACK)
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(8);
|
|
|
|
return JS::NumberValue(0);
|
2014-03-08 01:26:17 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
|
2016-07-22 14:42:00 +03:00
|
|
|
if (attachment == LOCAL_GL_BACK) {
|
|
|
|
if (mOptions.alpha) {
|
|
|
|
return JS::NumberValue(8);
|
|
|
|
}
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an alpha buffer");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(0);
|
2014-01-11 01:42:09 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
|
2016-07-22 14:42:00 +03:00
|
|
|
if (attachment == LOCAL_GL_DEPTH) {
|
|
|
|
if (mOptions.depth) {
|
|
|
|
return JS::NumberValue(24);
|
|
|
|
}
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an depth buffer");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(0);
|
2010-09-02 18:38:26 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
|
2016-07-22 14:42:00 +03:00
|
|
|
if (attachment == LOCAL_GL_STENCIL) {
|
|
|
|
if (mOptions.stencil) {
|
|
|
|
return JS::NumberValue(8);
|
|
|
|
}
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an stencil buffer");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(0);
|
2015-11-24 06:27:13 +03:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
|
2016-07-22 14:42:00 +03:00
|
|
|
if (attachment == LOCAL_GL_STENCIL) {
|
|
|
|
if (mOptions.stencil) {
|
|
|
|
return JS::NumberValue(LOCAL_GL_UNSIGNED_INT);
|
|
|
|
}
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an stencil buffer");
|
|
|
|
} else if (attachment == LOCAL_GL_DEPTH) {
|
|
|
|
if (mOptions.depth) {
|
|
|
|
return JS::NumberValue(LOCAL_GL_UNSIGNED_NORMALIZED);
|
|
|
|
}
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an depth buffer");
|
|
|
|
} else { // LOCAL_GL_BACK
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(LOCAL_GL_UNSIGNED_NORMALIZED);
|
2016-07-22 14:42:00 +03:00
|
|
|
}
|
|
|
|
return JS::NullValue();
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
|
2016-07-22 14:42:00 +03:00
|
|
|
if (attachment == LOCAL_GL_STENCIL) {
|
|
|
|
if (!mOptions.stencil) {
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an stencil buffer");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
} else if (attachment == LOCAL_GL_DEPTH) {
|
|
|
|
if (!mOptions.depth) {
|
|
|
|
ErrorInvalidOperation("The default framebuffer doesn't contain an depth buffer");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
return JS::NumberValue(LOCAL_GL_LINEAR);
|
2009-11-18 23:42:35 +03:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
ErrorInvalidEnum("%s: Invalid pname: 0x%04x", funcName, pname);
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2009-11-18 23:42:35 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::GetRenderbufferParameter(GLenum target, GLenum pname)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2009-11-18 23:42:35 +03:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER) {
|
2012-05-23 20:07:35 +04:00
|
|
|
ErrorInvalidEnumInfo("getRenderbufferParameter: target", target);
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
|
|
|
}
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2012-07-27 03:58:53 +04:00
|
|
|
if (!mBoundRenderbuffer) {
|
|
|
|
ErrorInvalidOperation("getRenderbufferParameter: no render buffer is bound");
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
2009-11-18 23:42:35 +03:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
2016-02-06 03:41:21 +03:00
|
|
|
case LOCAL_GL_RENDERBUFFER_SAMPLES:
|
|
|
|
if (!IsWebGL2())
|
|
|
|
break;
|
2016-02-11 10:10:02 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2016-02-06 03:41:21 +03:00
|
|
|
|
|
|
|
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:
|
|
|
|
case LOCAL_GL_RENDERBUFFER_INTERNAL_FORMAT:
|
|
|
|
{
|
|
|
|
// RB emulation means we have to ask the RB itself.
|
|
|
|
GLint i = mBoundRenderbuffer->GetRenderbufferParameter(target, pname);
|
|
|
|
return JS::Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-11-18 23:42:35 +03:00
|
|
|
}
|
|
|
|
|
2016-02-06 03:41:21 +03:00
|
|
|
ErrorInvalidEnumInfo("getRenderbufferParameter: parameter", pname);
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2009-11-18 23:42:35 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLTexture>
|
|
|
|
WebGLContext::CreateTexture()
|
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-11-17 05:21:04 +03:00
|
|
|
|
|
|
|
GLuint tex = 0;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fGenTextures(1, &tex);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLTexture> globj = new WebGLTexture(this, tex);
|
2012-05-04 20:38:44 +04:00
|
|
|
return globj.forget();
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2014-03-08 01:16:34 +04:00
|
|
|
static GLenum
|
|
|
|
GetAndClearError(GLenum* errorVar)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(errorVar);
|
|
|
|
GLenum ret = *errorVar;
|
|
|
|
*errorVar = LOCAL_GL_NO_ERROR;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLenum
|
2012-05-04 20:38:44 +04:00
|
|
|
WebGLContext::GetError()
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2014-03-08 01:16:34 +04:00
|
|
|
/* WebGL 1.0: Section 5.14.3: Setting and getting state:
|
|
|
|
* If the context's webgl context lost flag is set, returns
|
|
|
|
* CONTEXT_LOST_WEBGL the first time this method is called.
|
|
|
|
* Afterward, returns NO_ERROR until the context has been
|
|
|
|
* restored.
|
|
|
|
*
|
|
|
|
* WEBGL_lose_context:
|
|
|
|
* [When this extension is enabled: ] loseContext and
|
|
|
|
* restoreContext are allowed to generate INVALID_OPERATION errors
|
|
|
|
* even when the context is lost.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (IsContextLost()) {
|
|
|
|
if (mEmitContextLostErrorOnce) {
|
|
|
|
mEmitContextLostErrorOnce = false;
|
2017-06-15 09:43:53 +03:00
|
|
|
return LOCAL_GL_CONTEXT_LOST_WEBGL;
|
2014-03-08 01:16:34 +04:00
|
|
|
}
|
|
|
|
// Don't return yet, since WEBGL_lose_contexts contradicts the
|
|
|
|
// original spec, and allows error generation while lost.
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2014-03-08 01:16:34 +04:00
|
|
|
GLenum err = GetAndClearError(&mWebGLError);
|
|
|
|
if (err != LOCAL_GL_NO_ERROR)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (IsContextLost())
|
|
|
|
return LOCAL_GL_NO_ERROR;
|
|
|
|
|
|
|
|
// Either no WebGL-side error, or it's already been cleared.
|
|
|
|
// UnderlyingGL-side errors, now.
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
GetAndFlushUnderlyingGLErrors();
|
|
|
|
|
|
|
|
err = GetAndClearError(&mUnderlyingGLError);
|
2012-05-04 20:38:44 +04:00
|
|
|
return err;
|
|
|
|
}
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetProgramParameter(const WebGLProgram& prog, GLenum pname)
|
2009-11-18 23:42:35 +03:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObjectAllowDeleted("getProgramParameter: program", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return prog.GetProgramParameter(pname);
|
2009-11-18 23:42:35 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetProgramInfoLog(const WebGLProgram& prog, nsAString& retval)
|
2012-05-29 22:44:31 +04:00
|
|
|
{
|
2015-01-16 02:40:39 +03:00
|
|
|
retval.SetIsVoid(true);
|
2012-05-29 22:44:31 +04:00
|
|
|
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2015-01-10 08:03:54 +03:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getProgramInfoLog: program", prog))
|
2015-01-10 08:03:54 +03:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
prog.GetProgramInfoLog(&retval);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetUniform(JSContext* js, const WebGLProgram& prog,
|
|
|
|
const WebGLUniformLocation& loc)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getUniform: `program`", prog))
|
2015-01-10 08:03:54 +03:00
|
|
|
return JS::NullValue();
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObjectAllowDeleted("getUniform: `location`", loc))
|
2015-01-10 08:03:54 +03:00
|
|
|
return JS::NullValue();
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
if (!loc.ValidateForProgram(&prog, "getUniform"))
|
2015-01-10 08:03:54 +03:00
|
|
|
return JS::NullValue();
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return loc.GetUniform(js);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLUniformLocation>
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetUniformLocation(const WebGLProgram& prog, const nsAString& name)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getUniformLocation: program", prog))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return prog.GetUniformLocation(name);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::Hint(GLenum target, GLenum mode)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2011-10-01 08:45:50 +04:00
|
|
|
bool isValid = false;
|
|
|
|
|
|
|
|
switch (target) {
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_GENERATE_MIPMAP_HINT:
|
2016-12-20 03:13:33 +03:00
|
|
|
mGenerateMipmapHint = mode;
|
|
|
|
|
2016-01-23 05:00:54 +03:00
|
|
|
// Deprecated and removed in desktop GL Core profiles.
|
|
|
|
if (gl->IsCoreProfile())
|
|
|
|
return;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
isValid = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
|
|
|
|
if (IsWebGL2() ||
|
|
|
|
IsExtensionEnabled(WebGLExtensionID::OES_standard_derivatives))
|
|
|
|
{
|
2012-04-05 05:57:35 +04:00
|
|
|
isValid = true;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
break;
|
2011-10-01 08:45:50 +04:00
|
|
|
}
|
|
|
|
|
2012-04-05 05:57:35 +04:00
|
|
|
if (!isValid)
|
|
|
|
return ErrorInvalidEnum("hint: invalid hint");
|
2011-10-01 08:45:50 +04:00
|
|
|
|
2014-02-15 03:52:38 +04:00
|
|
|
MakeContextCurrent();
|
2012-04-05 05:57:35 +04:00
|
|
|
gl->fHint(target, mode);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
bool
|
2016-11-30 05:30:28 +03:00
|
|
|
WebGLContext::IsFramebuffer(const WebGLFramebuffer* fb)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateIsObject("isFramebuffer", fb))
|
2015-05-21 02:50:28 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
gl->Renderer() == GLRenderer::AndroidEmulator)
|
|
|
|
{
|
|
|
|
return fb->mIsFB;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
return gl->fIsFramebuffer(fb->mGLName);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
bool
|
2016-11-30 05:30:28 +03:00
|
|
|
WebGLContext::IsProgram(const WebGLProgram* prog)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateIsObject("isProgram", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return false;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
return true;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
bool
|
2016-11-30 05:30:28 +03:00
|
|
|
WebGLContext::IsRenderbuffer(const WebGLRenderbuffer* rb)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateIsObject("isRenderbuffer", rb))
|
2015-05-21 02:53:02 +03:00
|
|
|
return false;
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
return rb->mHasBeenBound;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
bool
|
2016-11-30 05:30:28 +03:00
|
|
|
WebGLContext::IsShader(const WebGLShader* shader)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateIsObject("isShader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return false;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
return true;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::LinkProgram(WebGLProgram& prog)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("linkProgram", prog))
|
2015-01-13 11:07:26 +03:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
prog.LinkProgram();
|
2015-01-13 11:07:26 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
if (!prog.IsLinked()) {
|
2016-04-20 22:02:07 +03:00
|
|
|
// If we failed to link, but `prog == mCurrentProgram`, we are *not* supposed to
|
|
|
|
// null out mActiveProgramLinkInfo.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
if (&prog == mCurrentProgram) {
|
|
|
|
mActiveProgramLinkInfo = prog.LinkInfo();
|
2015-01-13 11:07:26 +03:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
|
|
|
gl->Vendor() == gl::GLVendor::NVIDIA)
|
|
|
|
{
|
2016-11-02 00:58:07 +03:00
|
|
|
gl->fUseProgram(prog.mGLName);
|
2015-01-13 11:07:26 +03:00
|
|
|
}
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::PixelStorei(GLenum pname, GLint param)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
if (IsWebGL2()) {
|
|
|
|
uint32_t* pValueSlot = nullptr;
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_UNPACK_IMAGE_HEIGHT:
|
|
|
|
pValueSlot = &mPixelStore_UnpackImageHeight;
|
2015-11-24 06:27:13 +03:00
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_UNPACK_SKIP_IMAGES:
|
|
|
|
pValueSlot = &mPixelStore_UnpackSkipImages;
|
2015-11-24 06:27:13 +03:00
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_UNPACK_ROW_LENGTH:
|
|
|
|
pValueSlot = &mPixelStore_UnpackRowLength;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNPACK_SKIP_ROWS:
|
|
|
|
pValueSlot = &mPixelStore_UnpackSkipRows;
|
2015-11-24 06:27:13 +03:00
|
|
|
break;
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_UNPACK_SKIP_PIXELS:
|
|
|
|
pValueSlot = &mPixelStore_UnpackSkipPixels;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_PACK_ROW_LENGTH:
|
|
|
|
pValueSlot = &mPixelStore_PackRowLength;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_PACK_SKIP_ROWS:
|
|
|
|
pValueSlot = &mPixelStore_PackSkipRows;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_PACK_SKIP_PIXELS:
|
|
|
|
pValueSlot = &mPixelStore_PackSkipPixels;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pValueSlot) {
|
|
|
|
if (param < 0) {
|
|
|
|
ErrorInvalidValue("pixelStorei: param must be >= 0.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPixelStorei(pname, param);
|
|
|
|
*pValueSlot = param;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case UNPACK_FLIP_Y_WEBGL:
|
|
|
|
mPixelStore_FlipY = bool(param);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case UNPACK_PREMULTIPLY_ALPHA_WEBGL:
|
|
|
|
mPixelStore_PremultiplyAlpha = bool(param);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case UNPACK_COLORSPACE_CONVERSION_WEBGL:
|
|
|
|
switch (param) {
|
|
|
|
case LOCAL_GL_NONE:
|
|
|
|
case BROWSER_DEFAULT_WEBGL:
|
|
|
|
mPixelStore_ColorspaceConversion = param;
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ErrorInvalidEnumInfo("pixelStorei: colorspace conversion parameter",
|
|
|
|
param);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-11 12:15:25 +03:00
|
|
|
case UNPACK_REQUIRE_FASTPATH:
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::MOZ_debug)) {
|
|
|
|
mPixelStore_RequireFastPath = bool(param);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
case LOCAL_GL_PACK_ALIGNMENT:
|
|
|
|
case LOCAL_GL_UNPACK_ALIGNMENT:
|
|
|
|
switch (param) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
2010-10-16 01:50:15 +04:00
|
|
|
if (pname == LOCAL_GL_PACK_ALIGNMENT)
|
2015-11-25 07:15:29 +03:00
|
|
|
mPixelStore_PackAlignment = param;
|
2010-10-16 01:50:15 +04:00
|
|
|
else if (pname == LOCAL_GL_UNPACK_ALIGNMENT)
|
2015-11-25 07:15:29 +03:00
|
|
|
mPixelStore_UnpackAlignment = param;
|
|
|
|
|
2010-06-15 19:59:39 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPixelStorei(pname, param);
|
2015-11-25 07:15:29 +03:00
|
|
|
return;
|
|
|
|
|
2010-06-15 19:59:39 +04:00
|
|
|
default:
|
2015-11-25 07:15:29 +03:00
|
|
|
ErrorInvalidValue("pixelStorei: invalid pack/unpack alignment value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-15 19:59:39 +04:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
ErrorInvalidEnumInfo("pixelStorei: parameter", pname);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
2010-06-15 19:59:39 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::DoReadPixelsAndConvert(const webgl::FormatInfo* srcFormat, GLint x, GLint y,
|
|
|
|
GLsizei width, GLsizei height, GLenum format,
|
2016-06-16 17:30:47 +03:00
|
|
|
GLenum destType, void* dest, uint32_t destSize,
|
|
|
|
uint32_t rowStride)
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
2016-06-16 17:30:47 +03:00
|
|
|
// On at least Win+NV, we'll get PBO errors if we don't have at least
|
|
|
|
// `rowStride * height` bytes available to read into.
|
|
|
|
const auto naiveBytesNeeded = CheckedUint32(rowStride) * height;
|
|
|
|
const bool isDangerCloseToEdge = (!naiveBytesNeeded.isValid() ||
|
|
|
|
naiveBytesNeeded.value() > destSize);
|
|
|
|
const bool useParanoidHandling = (gl->WorkAroundDriverBugs() &&
|
|
|
|
isDangerCloseToEdge &&
|
|
|
|
mBoundPixelPackBuffer);
|
|
|
|
if (!useParanoidHandling) {
|
|
|
|
gl->fReadPixels(x, y, width, height, format, destType, dest);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read everything but the last row.
|
|
|
|
const auto bodyHeight = height - 1;
|
|
|
|
if (bodyHeight) {
|
|
|
|
gl->fReadPixels(x, y, width, bodyHeight, format, destType, dest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now read the last row.
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 1);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, 0);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, 0);
|
|
|
|
|
|
|
|
const auto tailRowOffset = (char*)dest + rowStride * bodyHeight;
|
|
|
|
gl->fReadPixels(x, y+bodyHeight, width, 1, format, destType, tailRowOffset);
|
|
|
|
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, mPixelStore_PackAlignment);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, mPixelStore_PackRowLength);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, mPixelStore_PackSkipRows);
|
2015-11-25 07:15:29 +03:00
|
|
|
return true;
|
2015-02-25 01:09:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
static bool
|
|
|
|
GetJSScalarFromGLType(GLenum type, js::Scalar::Type* const out_scalarType)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_BYTE:
|
|
|
|
*out_scalarType = js::Scalar::Int8;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
*out_scalarType = js::Scalar::Uint8;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_SHORT:
|
|
|
|
*out_scalarType = js::Scalar::Int16;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
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:
|
|
|
|
*out_scalarType = js::Scalar::Uint16;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_5_9_9_9_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_10F_11F_11F_REV:
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_24_8:
|
|
|
|
*out_scalarType = js::Scalar::Uint32;
|
|
|
|
return true;
|
|
|
|
case LOCAL_GL_INT:
|
|
|
|
*out_scalarType = js::Scalar::Int32;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
*out_scalarType = js::Scalar::Float32;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-02-01 23:43:37 +03:00
|
|
|
WebGLContext::ReadPixels_SharedPrecheck(CallerType aCallerType,
|
|
|
|
ErrorResult& out_error)
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
|
|
|
if (IsContextLost())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (mCanvasElement &&
|
|
|
|
mCanvasElement->IsWriteOnly() &&
|
2017-02-01 23:43:37 +03:00
|
|
|
aCallerType != CallerType::System)
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
|
|
|
GenerateWarning("readPixels: Not allowed");
|
2017-02-01 23:43:37 +03:00
|
|
|
out_error.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
2016-07-05 06:35:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-17 01:46:01 +03:00
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::ValidatePackSize(const char* funcName, uint32_t width, uint32_t height,
|
|
|
|
uint8_t bytesPerPixel, uint32_t* const out_rowStride,
|
|
|
|
uint32_t* const out_endOffset)
|
2015-11-25 07:15:29 +03:00
|
|
|
{
|
|
|
|
if (!width || !height) {
|
|
|
|
*out_rowStride = 0;
|
2016-07-05 00:40:38 +03:00
|
|
|
*out_endOffset = 0;
|
|
|
|
return true;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GLES 3.0.4, p116 (PACK_ functions like UNPACK_)
|
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
const auto rowLength = (mPixelStore_PackRowLength ? mPixelStore_PackRowLength
|
|
|
|
: width);
|
|
|
|
const auto skipPixels = mPixelStore_PackSkipPixels;
|
|
|
|
const auto skipRows = mPixelStore_PackSkipRows;
|
|
|
|
const auto alignment = mPixelStore_PackAlignment;
|
|
|
|
|
|
|
|
const auto usedPixelsPerRow = CheckedUint32(skipPixels) + width;
|
|
|
|
const auto usedRowsPerImage = CheckedUint32(skipRows) + height;
|
|
|
|
|
|
|
|
if (!usedPixelsPerRow.isValid() || usedPixelsPerRow.value() > rowLength) {
|
|
|
|
ErrorInvalidOperation("%s: SKIP_PIXELS + width > ROW_LENGTH.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
const auto rowLengthBytes = CheckedUint32(rowLength) * bytesPerPixel;
|
|
|
|
const auto rowStride = RoundUpToMultipleOf(rowLengthBytes, alignment);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
const auto usedBytesPerRow = usedPixelsPerRow * bytesPerPixel;
|
|
|
|
const auto usedBytesPerImage = (usedRowsPerImage - 1) * rowStride + usedBytesPerRow;
|
|
|
|
|
|
|
|
if (!rowStride.isValid() || !usedBytesPerImage.isValid()) {
|
|
|
|
ErrorInvalidOperation("%s: Invalid UNPACK_ params.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_rowStride = rowStride.value();
|
|
|
|
*out_endOffset = usedBytesPerImage.value();
|
|
|
|
return true;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2015-11-25 07:15:29 +03:00
|
|
|
WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
2016-10-11 01:34:18 +03:00
|
|
|
GLenum type, const dom::ArrayBufferView& dstView,
|
2017-02-01 23:43:37 +03:00
|
|
|
GLuint dstElemOffset, CallerType aCallerType,
|
|
|
|
ErrorResult& out_error)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2016-10-11 01:34:18 +03:00
|
|
|
const char funcName[] = "readPixels";
|
2017-02-01 23:43:37 +03:00
|
|
|
if (!ReadPixels_SharedPrecheck(aCallerType, out_error))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
if (mBoundPixelPackBuffer) {
|
2016-10-11 01:34:18 +03:00
|
|
|
ErrorInvalidOperation("%s: PIXEL_PACK_BUFFER must be null.", funcName);
|
2015-11-25 07:15:29 +03:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2016-10-11 01:34:18 +03:00
|
|
|
////
|
2010-06-19 18:46:12 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
js::Scalar::Type reqScalarType;
|
|
|
|
if (!GetJSScalarFromGLType(type, &reqScalarType)) {
|
2016-10-11 01:34:18 +03:00
|
|
|
ErrorInvalidEnum("%s: Bad `type`.", funcName);
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2015-12-17 01:46:01 +03:00
|
|
|
}
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2016-10-11 01:34:18 +03:00
|
|
|
const auto& viewElemType = dstView.Type();
|
|
|
|
if (viewElemType != reqScalarType) {
|
|
|
|
ErrorInvalidOperation("%s: `pixels` type does not match `type`.", funcName);
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-11-01 03:55:01 +04:00
|
|
|
|
2016-10-11 01:34:18 +03:00
|
|
|
////
|
2016-07-05 06:35:20 +03:00
|
|
|
|
2016-10-11 01:34:18 +03:00
|
|
|
uint8_t* bytes;
|
|
|
|
size_t byteLen;
|
|
|
|
if (!ValidateArrayBufferView(funcName, dstView, dstElemOffset, 0, &bytes, &byteLen))
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2016-10-11 01:34:18 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
ReadPixelsImpl(x, y, width, height, format, type, bytes, byteLen);
|
2016-07-05 06:35:20 +03:00
|
|
|
}
|
2011-11-01 03:55:01 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
void
|
2016-10-11 01:34:18 +03:00
|
|
|
WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
|
2017-02-01 23:43:37 +03:00
|
|
|
GLenum type, WebGLsizeiptr offset,
|
|
|
|
CallerType aCallerType, ErrorResult& out_error)
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
2016-11-18 04:50:38 +03:00
|
|
|
const char funcName[] = "readPixels";
|
2017-02-01 23:43:37 +03:00
|
|
|
if (!ReadPixels_SharedPrecheck(aCallerType, out_error))
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2016-01-21 09:51:59 +03:00
|
|
|
|
2016-11-18 04:50:38 +03:00
|
|
|
const auto& buffer = ValidateBufferSelection(funcName, LOCAL_GL_PIXEL_PACK_BUFFER);
|
|
|
|
if (!buffer)
|
2016-09-10 07:02:54 +03:00
|
|
|
return;
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
//////
|
2016-01-21 09:51:59 +03:00
|
|
|
|
2016-11-18 04:50:38 +03:00
|
|
|
if (!ValidateNonNegative(funcName, "offset", offset))
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
|
|
|
const auto bytesPerType = webgl::BytesPerPixel({LOCAL_GL_RED, type});
|
2015-12-17 01:46:01 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
if (offset % bytesPerType != 0) {
|
2016-11-18 04:50:38 +03:00
|
|
|
ErrorInvalidOperation("%s: `offset` must be divisible by the size of `type`"
|
|
|
|
" in bytes.",
|
|
|
|
funcName);
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2016-11-18 04:50:38 +03:00
|
|
|
const auto bytesAvailable = buffer->ByteLength();
|
2016-07-05 06:35:20 +03:00
|
|
|
const auto checkedBytesAfterOffset = CheckedUint32(bytesAvailable) - offset;
|
|
|
|
|
|
|
|
uint32_t bytesAfterOffset = 0;
|
|
|
|
if (checkedBytesAfterOffset.isValid()) {
|
|
|
|
bytesAfterOffset = checkedBytesAfterOffset.value();
|
|
|
|
}
|
|
|
|
|
2016-09-26 23:38:56 +03:00
|
|
|
gl->MakeCurrent();
|
2016-11-18 04:50:38 +03:00
|
|
|
const ScopedLazyBind lazyBind(gl, LOCAL_GL_PIXEL_PACK_BUFFER, buffer);
|
2016-09-26 23:38:56 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
ReadPixelsImpl(x, y, width, height, format, type, (void*)offset, bytesAfterOffset);
|
|
|
|
}
|
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
static webgl::PackingInfo
|
|
|
|
DefaultReadPixelPI(const webgl::FormatUsageInfo* usage)
|
2016-07-05 06:35:20 +03:00
|
|
|
{
|
2016-12-23 04:08:35 +03:00
|
|
|
MOZ_ASSERT(usage->IsRenderable());
|
2016-01-21 09:51:59 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
switch (usage->format->componentType) {
|
2016-07-05 06:35:20 +03:00
|
|
|
case webgl::ComponentType::NormUInt:
|
2016-12-23 04:08:35 +03:00
|
|
|
return { LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE };
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
case webgl::ComponentType::Int:
|
|
|
|
return { LOCAL_GL_RGBA_INTEGER, LOCAL_GL_INT };
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
case webgl::ComponentType::UInt:
|
|
|
|
return { LOCAL_GL_RGBA_INTEGER, LOCAL_GL_UNSIGNED_INT };
|
2016-07-05 06:35:20 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
case webgl::ComponentType::Float:
|
|
|
|
return { LOCAL_GL_RGBA, LOCAL_GL_FLOAT };
|
2016-07-05 00:40:38 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
2016-07-05 06:35:20 +03:00
|
|
|
}
|
2016-12-23 04:08:35 +03:00
|
|
|
}
|
2015-11-26 14:47:53 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
static bool
|
|
|
|
ArePossiblePackEnums(const WebGLContext* webgl, const webgl::PackingInfo& pi)
|
|
|
|
{
|
2016-07-05 06:35:20 +03:00
|
|
|
// OpenGL ES 2.0 $4.3.1 - IMPLEMENTATION_COLOR_READ_{TYPE/FORMAT} is a valid
|
|
|
|
// combination for glReadPixels()...
|
2013-01-08 03:12:06 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
// So yeah, we are actually checking that these are valid as /unpack/ formats, instead
|
|
|
|
// of /pack/ formats here, but it should cover the INVALID_ENUM cases.
|
2016-12-23 04:08:35 +03:00
|
|
|
if (!webgl->mFormatUsage->AreUnpackEnumsValid(pi.format, pi.type))
|
2016-07-05 06:35:20 +03:00
|
|
|
return false;
|
2010-11-17 07:33:04 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
// Only valid when pulled from:
|
|
|
|
// * GLES 2.0.25 p105:
|
|
|
|
// "table 3.4, excluding formats LUMINANCE and LUMINANCE_ALPHA."
|
|
|
|
// * GLES 3.0.4 p193:
|
|
|
|
// "table 3.2, excluding formats DEPTH_COMPONENT and DEPTH_STENCIL."
|
|
|
|
switch (pi.format) {
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
return false;
|
2016-07-05 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
if (pi.type == LOCAL_GL_UNSIGNED_INT_24_8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
webgl::PackingInfo
|
|
|
|
WebGLContext::ValidImplementationColorReadPI(const webgl::FormatUsageInfo* usage) const
|
|
|
|
{
|
|
|
|
const auto defaultPI = DefaultReadPixelPI(usage);
|
|
|
|
|
|
|
|
// ES2_compatibility always returns RGBA/UNSIGNED_BYTE, so branch on actual IsGLES().
|
|
|
|
// Also OSX+NV generates an error here.
|
|
|
|
if (!gl->IsGLES())
|
|
|
|
return defaultPI;
|
|
|
|
|
|
|
|
webgl::PackingInfo implPI;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_IMPLEMENTATION_COLOR_READ_FORMAT, (GLint*)&implPI.format);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_IMPLEMENTATION_COLOR_READ_TYPE, (GLint*)&implPI.type);
|
|
|
|
|
|
|
|
if (!ArePossiblePackEnums(this, implPI))
|
|
|
|
return defaultPI;
|
|
|
|
|
|
|
|
return implPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ValidateReadPixelsFormatAndType(const webgl::FormatUsageInfo* srcUsage,
|
|
|
|
const webgl::PackingInfo& pi, gl::GLContext* gl,
|
|
|
|
WebGLContext* webgl)
|
|
|
|
{
|
|
|
|
const char funcName[] = "readPixels";
|
|
|
|
|
|
|
|
if (!ArePossiblePackEnums(webgl, pi)) {
|
|
|
|
webgl->ErrorInvalidEnum("%s: Unexpected format or type.", funcName);
|
2016-07-05 07:20:26 +03:00
|
|
|
return false;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
const auto defaultPI = DefaultReadPixelPI(srcUsage);
|
|
|
|
if (pi == defaultPI)
|
|
|
|
return true;
|
2016-07-05 00:40:38 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
// OpenGL ES 3.0.4 p194 - When the internal format of the rendering surface is
|
|
|
|
// RGB10_A2, a third combination of format RGBA and type UNSIGNED_INT_2_10_10_10_REV
|
|
|
|
// is accepted.
|
|
|
|
|
|
|
|
if (webgl->IsWebGL2() &&
|
|
|
|
srcUsage->format->effectiveFormat == webgl::EffectiveFormat::RGB10_A2 &&
|
|
|
|
pi.format == LOCAL_GL_RGBA &&
|
|
|
|
pi.type == LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV)
|
|
|
|
{
|
|
|
|
return true;
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
2010-06-19 18:46:12 +04:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
const auto implPI = webgl->ValidImplementationColorReadPI(srcUsage);
|
|
|
|
if (pi == implPI)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
////
|
2016-07-05 06:35:20 +03:00
|
|
|
|
2016-12-23 04:08:35 +03:00
|
|
|
webgl->ErrorInvalidOperation("%s: Incompatible format or type.", funcName);
|
2016-07-05 06:35:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::ReadPixelsImpl(GLint x, GLint y, GLsizei rawWidth, GLsizei rawHeight,
|
|
|
|
GLenum packFormat, GLenum packType, void* dest,
|
|
|
|
uint32_t dataLen)
|
|
|
|
{
|
|
|
|
if (rawWidth < 0 || rawHeight < 0) {
|
|
|
|
ErrorInvalidValue("readPixels: negative size passed");
|
2015-11-25 07:15:29 +03:00
|
|
|
return;
|
2012-11-22 22:53:11 +04:00
|
|
|
}
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
const uint32_t width(rawWidth);
|
|
|
|
const uint32_t height(rawHeight);
|
|
|
|
|
2016-07-05 00:40:38 +03:00
|
|
|
//////
|
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
const webgl::FormatUsageInfo* srcFormat;
|
|
|
|
uint32_t srcWidth;
|
|
|
|
uint32_t srcHeight;
|
2016-07-13 10:58:16 +03:00
|
|
|
if (!ValidateCurFBForRead("readPixels", &srcFormat, &srcWidth, &srcHeight))
|
2015-11-25 07:15:29 +03:00
|
|
|
return;
|
2015-11-24 08:55:59 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
//////
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
const webgl::PackingInfo pi = {packFormat, packType};
|
2016-12-23 04:08:35 +03:00
|
|
|
if (!ValidateReadPixelsFormatAndType(srcFormat, pi, gl, this))
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2014-06-20 21:43:20 +04:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
uint8_t bytesPerPixel;
|
|
|
|
if (!webgl::GetBytesPerPixel(pi, &bytesPerPixel)) {
|
|
|
|
ErrorInvalidOperation("readPixels: Unsupported format and type.");
|
|
|
|
return;
|
2014-06-20 21:43:20 +04:00
|
|
|
}
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
//////
|
2016-01-21 09:51:59 +03:00
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
uint32_t rowStride;
|
|
|
|
uint32_t bytesNeeded;
|
|
|
|
if (!ValidatePackSize("readPixels", width, height, bytesPerPixel, &rowStride,
|
|
|
|
&bytesNeeded))
|
2016-01-21 09:51:59 +03:00
|
|
|
{
|
2016-07-05 06:35:20 +03:00
|
|
|
return;
|
2016-01-21 09:51:59 +03:00
|
|
|
}
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
if (bytesNeeded > dataLen) {
|
|
|
|
ErrorInvalidOperation("readPixels: buffer too small");
|
|
|
|
return;
|
|
|
|
}
|
2015-02-25 01:09:09 +03:00
|
|
|
|
2017-02-28 02:24:14 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
int32_t readX, readY;
|
|
|
|
int32_t writeX, writeY;
|
|
|
|
int32_t rwWidth, rwHeight;
|
|
|
|
if (!Intersect(srcWidth, x, width, &readX, &writeX, &rwWidth) ||
|
|
|
|
!Intersect(srcHeight, y, height, &readY, &writeY, &rwHeight))
|
|
|
|
{
|
|
|
|
ErrorOutOfMemory("readPixels: Bad subrect selection.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
////////////////
|
2015-11-25 07:15:29 +03:00
|
|
|
// Now that the errors are out of the way, on to actually reading!
|
|
|
|
|
2016-12-24 05:54:04 +03:00
|
|
|
OnBeforeReadCall();
|
|
|
|
|
2017-02-28 02:24:14 +03:00
|
|
|
if (!rwWidth || !rwHeight) {
|
|
|
|
// Disjoint rects, so we're done already.
|
|
|
|
DummyReadFramebufferOperation("readPixels");
|
|
|
|
return;
|
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
2017-02-28 02:24:14 +03:00
|
|
|
if (uint32_t(rwWidth) == width &&
|
|
|
|
uint32_t(rwHeight) == height)
|
|
|
|
{
|
2016-07-05 06:35:20 +03:00
|
|
|
DoReadPixelsAndConvert(srcFormat->format, x, y, width, height, packFormat,
|
2016-06-16 17:30:47 +03:00
|
|
|
packType, dest, dataLen, rowStride);
|
2015-11-25 07:15:29 +03:00
|
|
|
return;
|
2014-06-20 21:43:20 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// Read request contains out-of-bounds pixels. Unfortunately:
|
|
|
|
// GLES 3.0.4 p194 "Obtaining Pixels from the Framebuffer":
|
|
|
|
// "If any of these pixels lies outside of the window allocated to the current GL
|
|
|
|
// context, or outside of the image attached to the currently bound framebuffer
|
|
|
|
// object, then the values obtained for those pixels are undefined."
|
2011-11-01 03:55:01 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// This is a slow-path, so warn people away!
|
|
|
|
GenerateWarning("readPixels: Out-of-bounds reads with readPixels are deprecated, and"
|
|
|
|
" may be slow.");
|
2011-05-20 23:53:53 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
////////////////////////////////////
|
|
|
|
// Read only the in-bounds pixels.
|
|
|
|
|
|
|
|
if (IsWebGL2()) {
|
|
|
|
if (!mPixelStore_PackRowLength) {
|
2016-07-05 06:35:20 +03:00
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH,
|
|
|
|
mPixelStore_PackSkipPixels + width);
|
2010-06-19 18:46:12 +04:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_PIXELS, mPixelStore_PackSkipPixels + writeX);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, mPixelStore_PackSkipRows + writeY);
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
DoReadPixelsAndConvert(srcFormat->format, readX, readY, rwWidth, rwHeight,
|
2016-06-16 17:30:47 +03:00
|
|
|
packFormat, packType, dest, dataLen, rowStride);
|
2010-06-19 18:46:12 +04:00
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_ROW_LENGTH, mPixelStore_PackRowLength);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_PIXELS, mPixelStore_PackSkipPixels);
|
|
|
|
gl->fPixelStorei(LOCAL_GL_PACK_SKIP_ROWS, mPixelStore_PackSkipRows);
|
|
|
|
} else {
|
|
|
|
// I *did* say "hilariously slow".
|
|
|
|
|
2016-07-05 06:35:20 +03:00
|
|
|
uint8_t* row = (uint8_t*)dest + writeX * bytesPerPixel;
|
2016-07-05 00:40:38 +03:00
|
|
|
row += writeY * rowStride;
|
2017-02-28 02:24:14 +03:00
|
|
|
for (uint32_t j = 0; j < uint32_t(rwHeight); j++) {
|
2016-07-05 06:35:20 +03:00
|
|
|
DoReadPixelsAndConvert(srcFormat->format, readX, readY+j, rwWidth, 1,
|
2016-06-16 17:30:47 +03:00
|
|
|
packFormat, packType, row, dataLen, rowStride);
|
2016-07-05 00:40:38 +03:00
|
|
|
row += rowStride;
|
2010-06-19 18:46:12 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-04 20:38:44 +04:00
|
|
|
}
|
2010-11-17 07:33:03 +03:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2015-02-19 03:57:05 +03:00
|
|
|
WebGLContext::RenderbufferStorage_base(const char* funcName, GLenum target,
|
2016-02-13 06:31:58 +03:00
|
|
|
GLsizei samples, GLenum internalFormat,
|
|
|
|
GLsizei width, GLsizei height)
|
2010-05-15 16:07:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
if (target != LOCAL_GL_RENDERBUFFER) {
|
|
|
|
ErrorInvalidEnumInfo("`target`", funcName, target);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
if (!mBoundRenderbuffer) {
|
|
|
|
ErrorInvalidOperation("%s: Called on renderbuffer 0.", funcName);
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
if (samples < 0) {
|
|
|
|
ErrorInvalidValue("%s: `samples` must be >= 0.", funcName);
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-05-15 17:55:45 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
if (width < 0 || height < 0) {
|
|
|
|
ErrorInvalidValue("%s: `width` and `height` must be >= 0.", funcName);
|
2015-02-19 03:57:05 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2016-02-13 06:31:58 +03:00
|
|
|
mBoundRenderbuffer->RenderbufferStorage(funcName, uint32_t(samples), internalFormat,
|
|
|
|
uint32_t(width), uint32_t(height));
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2015-02-19 03:57:05 +03:00
|
|
|
void
|
|
|
|
WebGLContext::RenderbufferStorage(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height)
|
|
|
|
{
|
2016-02-13 06:31:58 +03:00
|
|
|
RenderbufferStorage_base("renderbufferStorage", target, 0, internalFormat, width,
|
|
|
|
height);
|
2015-02-19 03:57:05 +03:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
if (width < 0 || height < 0)
|
2012-05-23 20:07:35 +04:00
|
|
|
return ErrorInvalidValue("scissor: negative size");
|
2010-06-30 19:48:30 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fScissor(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::StencilFunc(GLenum func, GLint ref, GLuint mask)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateComparisonEnum(func, "stencilFunc: func"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-06-30 19:48:30 +04:00
|
|
|
|
2011-05-20 23:53:53 +04:00
|
|
|
mStencilRefFront = ref;
|
|
|
|
mStencilRefBack = ref;
|
|
|
|
mStencilValueMaskFront = mask;
|
|
|
|
mStencilValueMaskBack = mask;
|
2010-12-06 14:34:35 +03:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilFunc(func, ref, mask);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateFaceEnum(face, "stencilFuncSeparate: face") ||
|
|
|
|
!ValidateComparisonEnum(func, "stencilFuncSeparate: func"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2011-05-20 23:53:53 +04: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 14:34:35 +03:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilFuncSeparate(face, func, ref, mask);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateStencilOpEnum(sfail, "stencilOp: sfail") ||
|
|
|
|
!ValidateStencilOpEnum(dpfail, "stencilOp: dpfail") ||
|
|
|
|
!ValidateStencilOpEnum(dppass, "stencilOp: dppass"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-06-30 19:48:30 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilOp(sfail, dpfail, dppass);
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:49:59 +04:00
|
|
|
if (!ValidateFaceEnum(face, "stencilOpSeparate: face") ||
|
|
|
|
!ValidateStencilOpEnum(sfail, "stencilOpSeparate: sfail") ||
|
|
|
|
!ValidateStencilOpEnum(dpfail, "stencilOpSeparate: dpfail") ||
|
|
|
|
!ValidateStencilOpEnum(dppass, "stencilOpSeparate: dppass"))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-06-30 19:48:30 +04:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fStencilOpSeparate(face, sfail, dpfail, dppass);
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Uniform setters.
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
class ValidateIfSampler
|
|
|
|
{
|
|
|
|
const WebGLUniformLocation* const mLoc;
|
|
|
|
const size_t mDataCount;
|
|
|
|
const GLint* const mData;
|
|
|
|
bool mIsValidatedSampler;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ValidateIfSampler(WebGLContext* webgl, const char* funcName,
|
|
|
|
WebGLUniformLocation* loc, size_t dataCount, const GLint* data,
|
|
|
|
bool* const out_error)
|
|
|
|
: mLoc(loc)
|
|
|
|
, mDataCount(dataCount)
|
|
|
|
, mData(data)
|
|
|
|
, mIsValidatedSampler(false)
|
|
|
|
{
|
|
|
|
if (!mLoc->mInfo->mSamplerTexList) {
|
|
|
|
*out_error = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mDataCount; i++) {
|
|
|
|
const auto& val = mData[i];
|
|
|
|
if (val < 0 || uint32_t(val) >= webgl->GLMaxTextureUnits()) {
|
|
|
|
webgl->ErrorInvalidValue("%s: This uniform location is a sampler, but %d"
|
|
|
|
" is not a valid texture unit.",
|
|
|
|
funcName, val);
|
|
|
|
*out_error = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsValidatedSampler = true;
|
|
|
|
*out_error = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ValidateIfSampler() {
|
|
|
|
if (!mIsValidatedSampler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto& samplerValues = mLoc->mInfo->mSamplerValues;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mDataCount; i++) {
|
|
|
|
const size_t curIndex = mLoc->mArrayIndex + i;
|
|
|
|
if (curIndex >= samplerValues.size())
|
|
|
|
break;
|
|
|
|
|
|
|
|
samplerValues[curIndex] = mData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform1i(WebGLUniformLocation* loc, GLint a1)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform1i";
|
|
|
|
if (!ValidateUniformSetter(loc, 1, LOCAL_GL_INT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
bool error;
|
|
|
|
const ValidateIfSampler validate(this, funcName, loc, 1, &a1, &error);
|
|
|
|
if (error)
|
2013-03-05 04:44:31 +04:00
|
|
|
return;
|
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform1i(loc->mLoc, a1);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform2i(WebGLUniformLocation* loc, GLint a1, GLint a2)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform2i";
|
|
|
|
if (!ValidateUniformSetter(loc, 2, LOCAL_GL_INT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform2i(loc->mLoc, a1, a2);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform3i(WebGLUniformLocation* loc, GLint a1, GLint a2, GLint a3)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform3i";
|
|
|
|
if (!ValidateUniformSetter(loc, 3, LOCAL_GL_INT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform3i(loc->mLoc, a1, a2, a3);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform4i(WebGLUniformLocation* loc, GLint a1, GLint a2, GLint a3,
|
|
|
|
GLint a4)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform4i";
|
|
|
|
if (!ValidateUniformSetter(loc, 4, LOCAL_GL_INT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform4i(loc->mLoc, a1, a2, a3, a4);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
//////////
|
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform1f(WebGLUniformLocation* loc, GLfloat a1)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform1f";
|
|
|
|
if (!ValidateUniformSetter(loc, 1, LOCAL_GL_FLOAT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform1f(loc->mLoc, a1);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform2f(WebGLUniformLocation* loc, GLfloat a1, GLfloat a2)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform2f";
|
|
|
|
if (!ValidateUniformSetter(loc, 2, LOCAL_GL_FLOAT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform2f(loc->mLoc, a1, a2);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform3f(WebGLUniformLocation* loc, GLfloat a1, GLfloat a2,
|
|
|
|
GLfloat a3)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform3f";
|
|
|
|
if (!ValidateUniformSetter(loc, 3, LOCAL_GL_FLOAT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform3f(loc->mLoc, a1, a2, a3);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::Uniform4f(WebGLUniformLocation* loc, GLfloat a1, GLfloat a2,
|
|
|
|
GLfloat a3, GLfloat a4)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
const char funcName[] = "uniform4f";
|
|
|
|
if (!ValidateUniformSetter(loc, 4, LOCAL_GL_FLOAT, funcName))
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform4f(loc->mLoc, a1, a2, a3, a4);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Array
|
|
|
|
|
2016-10-14 02:15:16 +03:00
|
|
|
static bool
|
|
|
|
ValidateArrOffsetAndCount(WebGLContext* webgl, const char* funcName, size_t elemsAvail,
|
|
|
|
GLuint elemOffset, GLuint elemCountOverride,
|
|
|
|
size_t* const out_elemCount)
|
|
|
|
{
|
|
|
|
if (elemOffset > elemsAvail) {
|
|
|
|
webgl->ErrorInvalidValue("%s: Bad offset into list.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elemsAvail -= elemOffset;
|
|
|
|
|
|
|
|
if (elemCountOverride) {
|
|
|
|
if (elemCountOverride > elemsAvail) {
|
|
|
|
webgl->ErrorInvalidValue("%s: Bad count override for sub-list.", funcName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elemsAvail = elemCountOverride;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_elemCount = elemsAvail;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
void
|
2016-07-14 22:13:47 +03:00
|
|
|
WebGLContext::UniformNiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
2016-10-14 02:15:16 +03:00
|
|
|
const Int32Arr& arr, GLuint elemOffset, GLuint elemCountOverride)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-10-14 02:15:16 +03:00
|
|
|
size_t elemCount;
|
|
|
|
if (!ValidateArrOffsetAndCount(this, funcName, arr.elemCount, elemOffset,
|
|
|
|
elemCountOverride, &elemCount))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto elemBytes = arr.elemBytes + elemOffset;
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
uint32_t numElementsToUpload;
|
2016-10-14 02:15:16 +03:00
|
|
|
if (!ValidateUniformArraySetter(loc, N, LOCAL_GL_INT, elemCount, funcName,
|
2014-10-24 02:10:57 +04:00
|
|
|
&numElementsToUpload))
|
|
|
|
{
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
bool error;
|
|
|
|
const ValidateIfSampler samplerValidator(this, funcName, loc, numElementsToUpload,
|
2016-10-14 02:15:16 +03:00
|
|
|
elemBytes, &error);
|
2016-07-14 22:13:47 +03:00
|
|
|
if (error)
|
2013-03-05 04:44:31 +04:00
|
|
|
return;
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
static const decltype(&gl::GLContext::fUniform1iv) kFuncList[] = {
|
|
|
|
&gl::GLContext::fUniform1iv,
|
|
|
|
&gl::GLContext::fUniform2iv,
|
|
|
|
&gl::GLContext::fUniform3iv,
|
|
|
|
&gl::GLContext::fUniform4iv
|
|
|
|
};
|
|
|
|
const auto func = kFuncList[N-1];
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-10-14 02:15:16 +03:00
|
|
|
(gl->*func)(loc->mLoc, numElementsToUpload, elemBytes);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 02:15:16 +03:00
|
|
|
WebGLContext::UniformNuiv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
|
|
|
const Uint32Arr& arr, GLuint elemOffset,
|
|
|
|
GLuint elemCountOverride)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-10-14 02:15:16 +03:00
|
|
|
size_t elemCount;
|
|
|
|
if (!ValidateArrOffsetAndCount(this, funcName, arr.elemCount, elemOffset,
|
|
|
|
elemCountOverride, &elemCount))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto elemBytes = arr.elemBytes + elemOffset;
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
uint32_t numElementsToUpload;
|
2016-10-14 02:15:16 +03:00
|
|
|
if (!ValidateUniformArraySetter(loc, N, LOCAL_GL_UNSIGNED_INT, elemCount, funcName,
|
|
|
|
&numElementsToUpload))
|
2014-10-24 02:10:57 +04:00
|
|
|
{
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-14 22:13:47 +03:00
|
|
|
MOZ_ASSERT(!loc->mInfo->mSamplerTexList, "Should not be a sampler.");
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
static const decltype(&gl::GLContext::fUniform1uiv) kFuncList[] = {
|
|
|
|
&gl::GLContext::fUniform1uiv,
|
|
|
|
&gl::GLContext::fUniform2uiv,
|
|
|
|
&gl::GLContext::fUniform3uiv,
|
|
|
|
&gl::GLContext::fUniform4uiv
|
|
|
|
};
|
|
|
|
const auto func = kFuncList[N-1];
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-10-14 02:15:16 +03:00
|
|
|
(gl->*func)(loc->mLoc, numElementsToUpload, elemBytes);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-14 22:13:47 +03:00
|
|
|
WebGLContext::UniformNfv(const char* funcName, uint8_t N, WebGLUniformLocation* loc,
|
2016-10-14 02:15:16 +03:00
|
|
|
const Float32Arr& arr, GLuint elemOffset,
|
|
|
|
GLuint elemCountOverride)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-10-14 02:15:16 +03:00
|
|
|
size_t elemCount;
|
|
|
|
if (!ValidateArrOffsetAndCount(this, funcName, arr.elemCount, elemOffset,
|
|
|
|
elemCountOverride, &elemCount))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto elemBytes = arr.elemBytes + elemOffset;
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
uint32_t numElementsToUpload;
|
2016-10-14 02:15:16 +03:00
|
|
|
if (!ValidateUniformArraySetter(loc, N, LOCAL_GL_FLOAT, elemCount, funcName,
|
2014-10-24 02:10:57 +04:00
|
|
|
&numElementsToUpload))
|
|
|
|
{
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-14 22:13:47 +03:00
|
|
|
MOZ_ASSERT(!loc->mInfo->mSamplerTexList, "Should not be a sampler.");
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
static const decltype(&gl::GLContext::fUniform1fv) kFuncList[] = {
|
|
|
|
&gl::GLContext::fUniform1fv,
|
|
|
|
&gl::GLContext::fUniform2fv,
|
|
|
|
&gl::GLContext::fUniform3fv,
|
|
|
|
&gl::GLContext::fUniform4fv
|
|
|
|
};
|
|
|
|
const auto func = kFuncList[N-1];
|
2013-03-05 04:44:31 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2016-10-14 02:15:16 +03:00
|
|
|
(gl->*func)(loc->mLoc, numElementsToUpload, elemBytes);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
|
|
|
|
2017-02-15 02:21:37 +03:00
|
|
|
static inline void
|
|
|
|
MatrixAxBToRowMajor(const uint8_t width, const uint8_t height,
|
|
|
|
const float* __restrict srcColMajor,
|
|
|
|
float* __restrict dstRowMajor)
|
|
|
|
{
|
|
|
|
for (uint8_t x = 0; x < width; ++x) {
|
|
|
|
for (uint8_t y = 0; y < height; ++y) {
|
|
|
|
dstRowMajor[y * width + x] = srcColMajor[x * height + y];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
void
|
2016-07-14 22:13:47 +03:00
|
|
|
WebGLContext::UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
|
2017-02-15 02:21:37 +03:00
|
|
|
WebGLUniformLocation* loc, const bool transpose,
|
2016-10-14 02:15:16 +03:00
|
|
|
const Float32Arr& arr, GLuint elemOffset,
|
|
|
|
GLuint elemCountOverride)
|
2012-10-16 16:17:01 +04:00
|
|
|
{
|
2016-10-14 02:15:16 +03:00
|
|
|
size_t elemCount;
|
|
|
|
if (!ValidateArrOffsetAndCount(this, funcName, arr.elemCount, elemOffset,
|
|
|
|
elemCountOverride, &elemCount))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto elemBytes = arr.elemBytes + elemOffset;
|
|
|
|
|
2017-02-15 02:21:37 +03:00
|
|
|
uint32_t numMatsToUpload;
|
2016-10-14 02:15:16 +03:00
|
|
|
if (!ValidateUniformMatrixArraySetter(loc, A, B, LOCAL_GL_FLOAT, elemCount,
|
2017-02-15 02:21:37 +03:00
|
|
|
transpose, funcName, &numMatsToUpload))
|
2014-10-24 02:10:57 +04:00
|
|
|
{
|
2012-10-16 16:17:01 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-07-14 22:13:47 +03:00
|
|
|
MOZ_ASSERT(!loc->mInfo->mSamplerTexList, "Should not be a sampler.");
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2017-02-15 02:21:37 +03:00
|
|
|
////
|
|
|
|
|
|
|
|
bool uploadTranspose = transpose;
|
|
|
|
const float* uploadBytes = elemBytes;
|
|
|
|
|
|
|
|
UniqueBuffer temp;
|
|
|
|
if (!transpose && gl->WorkAroundDriverBugs() && gl->IsANGLE() &&
|
|
|
|
gl->IsAtLeast(gl::ContextProfile::OpenGLES, 300))
|
|
|
|
{
|
|
|
|
// ANGLE is really slow at non-GL-transposed matrices.
|
|
|
|
const size_t kElemsPerMat = A * B;
|
|
|
|
|
|
|
|
temp = malloc(numMatsToUpload * kElemsPerMat * sizeof(float));
|
|
|
|
if (!temp) {
|
|
|
|
ErrorOutOfMemory("%s: Failed to alloc temporary buffer for transposition.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto srcItr = (const float*)elemBytes;
|
|
|
|
auto dstItr = (float*)temp.get();
|
|
|
|
const auto srcEnd = srcItr + numMatsToUpload * kElemsPerMat;
|
|
|
|
|
|
|
|
while (srcItr != srcEnd) {
|
|
|
|
MatrixAxBToRowMajor(A, B, srcItr, dstItr);
|
|
|
|
srcItr += kElemsPerMat;
|
|
|
|
dstItr += kElemsPerMat;
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadBytes = (const float*)temp.get();
|
|
|
|
uploadTranspose = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
static const decltype(&gl::GLContext::fUniformMatrix2fv) kFuncList[] = {
|
|
|
|
&gl::GLContext::fUniformMatrix2fv,
|
|
|
|
&gl::GLContext::fUniformMatrix2x3fv,
|
|
|
|
&gl::GLContext::fUniformMatrix2x4fv,
|
2012-10-16 16:17:01 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
&gl::GLContext::fUniformMatrix3x2fv,
|
|
|
|
&gl::GLContext::fUniformMatrix3fv,
|
|
|
|
&gl::GLContext::fUniformMatrix3x4fv,
|
2012-10-16 16:17:01 +04:00
|
|
|
|
2016-07-14 22:13:47 +03:00
|
|
|
&gl::GLContext::fUniformMatrix4x2fv,
|
|
|
|
&gl::GLContext::fUniformMatrix4x3fv,
|
|
|
|
&gl::GLContext::fUniformMatrix4fv
|
|
|
|
};
|
|
|
|
const auto func = kFuncList[3*(A-2) + (B-2)];
|
2014-10-24 02:10:57 +04:00
|
|
|
|
2012-10-16 16:17:01 +04:00
|
|
|
MakeContextCurrent();
|
2017-02-15 02:21:37 +03:00
|
|
|
(gl->*func)(loc->mLoc, numMatsToUpload, uploadTranspose, uploadBytes);
|
2012-10-16 16:17:01 +04:00
|
|
|
}
|
2010-01-23 00:34:25 +03:00
|
|
|
|
2014-10-24 02:10:57 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::UseProgram(WebGLProgram* prog)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
if (!prog) {
|
|
|
|
mCurrentProgram = nullptr;
|
|
|
|
mActiveProgramLinkInfo = nullptr;
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2015-01-16 02:40:39 +03:00
|
|
|
}
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("useProgram", *prog))
|
2015-01-16 02:40:39 +03:00
|
|
|
return;
|
2015-01-13 11:07:26 +03:00
|
|
|
|
2015-01-16 02:40:39 +03:00
|
|
|
if (prog->UseProgram()) {
|
|
|
|
mCurrentProgram = prog;
|
|
|
|
mActiveProgramLinkInfo = mCurrentProgram->LinkInfo();
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::ValidateProgram(const WebGLProgram& prog)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("validateProgram", prog))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
prog.ValidateProgram();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLFramebuffer>
|
|
|
|
WebGLContext::CreateFramebuffer()
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-11-17 05:21:04 +03:00
|
|
|
|
|
|
|
GLuint fbo = 0;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fGenFramebuffers(1, &fbo);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLFramebuffer> globj = new WebGLFramebuffer(this, fbo);
|
2012-05-04 20:38:44 +04:00
|
|
|
return globj.forget();
|
|
|
|
}
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLRenderbuffer>
|
|
|
|
WebGLContext::CreateRenderbuffer()
|
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2016-02-13 06:31:58 +03:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLRenderbuffer> globj = new WebGLRenderbuffer(this);
|
2012-05-04 20:38:44 +04:00
|
|
|
return globj.forget();
|
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
|
2010-06-30 19:48:30 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
if (width < 0 || height < 0)
|
2012-05-23 20:07:35 +04:00
|
|
|
return ErrorInvalidValue("viewport: negative size");
|
2010-06-30 19:48:30 +04:00
|
|
|
|
2017-07-27 10:48:58 +03:00
|
|
|
width = std::min(width, (GLsizei)mGLMaxViewportDims[0]);
|
|
|
|
height = std::min(height, (GLsizei)mGLMaxViewportDims[1]);
|
2017-01-10 22:15:00 +03:00
|
|
|
|
2010-06-30 19:48:30 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fViewport(x, y, width, height);
|
2014-01-10 17:41:04 +04:00
|
|
|
|
|
|
|
mViewportX = x;
|
|
|
|
mViewportY = y;
|
|
|
|
mViewportWidth = width;
|
|
|
|
mViewportHeight = height;
|
2010-06-30 19:48:30 +04:00
|
|
|
}
|
2009-09-03 04:47:49 +04:00
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::CompileShader(WebGLShader& shader)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("compileShader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
shader.CompileShader();
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
JS::Value
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetShaderParameter(const WebGLShader& shader, GLenum pname)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2010-08-25 16:17:08 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObjectAllowDeleted("getShaderParameter: shader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return JS::NullValue();
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return shader.GetShaderParameter(pname);
|
2009-09-18 10:01:07 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetShaderInfoLog(const WebGLShader& shader, nsAString& retval)
|
2012-05-29 22:44:31 +04:00
|
|
|
{
|
2015-01-16 02:40:39 +03:00
|
|
|
retval.SetIsVoid(true);
|
2012-05-29 22:44:31 +04:00
|
|
|
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getShaderInfoLog: shader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
shader.GetShaderInfoLog(&retval);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
already_AddRefed<WebGLShaderPrecisionFormat>
|
2013-09-04 16:14:43 +04:00
|
|
|
WebGLContext::GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype)
|
2012-05-04 20:38:44 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-17 01:11:59 +04:00
|
|
|
|
|
|
|
switch (shadertype) {
|
|
|
|
case LOCAL_GL_FRAGMENT_SHADER:
|
|
|
|
case LOCAL_GL_VERTEX_SHADER:
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-04 20:38:44 +04:00
|
|
|
ErrorInvalidEnumInfo("getShaderPrecisionFormat: shadertype", shadertype);
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-17 01:11:59 +04: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 20:38:44 +04:00
|
|
|
ErrorInvalidEnumInfo("getShaderPrecisionFormat: precisiontype", precisiontype);
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-17 01:11:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
GLint range[2], precision;
|
2013-05-16 01:50:52 +04:00
|
|
|
|
|
|
|
if (mDisableFragHighP &&
|
|
|
|
shadertype == LOCAL_GL_FRAGMENT_SHADER &&
|
|
|
|
(precisiontype == LOCAL_GL_HIGH_FLOAT ||
|
|
|
|
precisiontype == LOCAL_GL_HIGH_INT))
|
|
|
|
{
|
|
|
|
precision = 0;
|
|
|
|
range[0] = 0;
|
|
|
|
range[1] = 0;
|
|
|
|
} else {
|
|
|
|
gl->fGetShaderPrecisionFormat(shadertype, precisiontype, range, &precision);
|
|
|
|
}
|
2011-12-17 01:11:59 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebGLShaderPrecisionFormat> retShaderPrecisionFormat
|
2012-10-04 01:13:05 +04:00
|
|
|
= new WebGLShaderPrecisionFormat(this, range[0], range[1], precision);
|
2013-04-22 15:15:59 +04:00
|
|
|
return retShaderPrecisionFormat.forget();
|
2011-12-17 01:11:59 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::GetShaderSource(const WebGLShader& shader, nsAString& retval)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2015-01-16 02:40:39 +03:00
|
|
|
retval.SetIsVoid(true);
|
|
|
|
|
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getShaderSource: shader", shader))
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2010-05-20 00:46:08 +04:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
shader.GetShaderSource(&retval);
|
2009-09-03 04:47:49 +04:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:38:44 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGLContext::ShaderSource(WebGLShader& shader, const nsAString& source)
|
2009-09-03 04:47:49 +04:00
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2012-05-04 20:38:44 +04:00
|
|
|
return;
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("shaderSource: shader", shader))
|
2014-02-12 02:37:06 +04:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
shader.ShaderSource(source);
|
2014-02-12 02:37:06 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
void
|
2011-10-27 00:00:44 +04:00
|
|
|
WebGLContext::LoseContext()
|
|
|
|
{
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2014-06-03 01:40:15 +04:00
|
|
|
return ErrorInvalidOperation("loseContext: Context is already lost.");
|
2011-10-27 00:00:44 +04:00
|
|
|
|
2014-06-23 03:16:00 +04:00
|
|
|
ForceLoseContext(true);
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
void
|
2011-10-27 00:00:44 +04:00
|
|
|
WebGLContext::RestoreContext()
|
|
|
|
{
|
2014-06-03 01:40:15 +04:00
|
|
|
if (!IsContextLost())
|
|
|
|
return ErrorInvalidOperation("restoreContext: Context is not lost.");
|
|
|
|
|
|
|
|
if (!mLastLossWasSimulated) {
|
|
|
|
return ErrorInvalidOperation("restoreContext: Context loss was not simulated."
|
|
|
|
" Cannot simulate restore.");
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
2014-06-03 01:40:15 +04:00
|
|
|
// If we're currently lost, and the last loss was simulated, then
|
|
|
|
// we're currently only simulated-lost, allowing us to call
|
|
|
|
// restoreContext().
|
2014-05-13 06:11:08 +04:00
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
if (!mAllowContextRestore)
|
|
|
|
return ErrorInvalidOperation("restoreContext: Context cannot be restored.");
|
2014-05-29 22:33:28 +04:00
|
|
|
|
2014-06-03 01:40:15 +04:00
|
|
|
ForceRestoreContext();
|
2011-10-27 00:00:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:50 +04:00
|
|
|
void
|
2015-02-25 01:09:09 +03:00
|
|
|
WebGLContext::BlendColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
2013-09-04 16:14:50 +04:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fBlendColor(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Flush() {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::Finish() {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fFinish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-24 02:10:57 +04:00
|
|
|
WebGLContext::LineWidth(GLfloat width)
|
|
|
|
{
|
2013-09-04 16:14:50 +04:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
2014-10-24 02:10:57 +04:00
|
|
|
|
|
|
|
// Doing it this way instead of `if (width <= 0.0)` handles NaNs.
|
|
|
|
const bool isValid = width > 0.0;
|
|
|
|
if (!isValid) {
|
|
|
|
ErrorInvalidValue("lineWidth: `width` must be positive and non-zero.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-28 06:54:46 +03:00
|
|
|
mLineWidth = width;
|
|
|
|
|
|
|
|
if (gl->IsCoreProfile() && width > 1.0) {
|
|
|
|
width = 1.0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:50 +04:00
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fLineWidth(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::PolygonOffset(GLfloat factor, GLfloat units) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fPolygonOffset(factor, units);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::SampleCoverage(GLclampf value, WebGLboolean invert) {
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
MakeContextCurrent();
|
|
|
|
gl->fSampleCoverage(value, invert);
|
2013-09-20 01:59:44 +04:00
|
|
|
}
|
2015-07-15 03:37:28 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|