2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-17 23:01:12 -07:00
|
|
|
|
2014-05-12 19:11:40 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
|
2014-05-21 19:03:09 -07:00
|
|
|
#include <stdarg.h>
|
2014-05-12 19:11:40 -07:00
|
|
|
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "GLContext.h"
|
2010-10-15 14:50:15 -07:00
|
|
|
#include "jsapi.h"
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-05-12 19:11:40 -07:00
|
|
|
#include "nsIDOMDataContainerEvent.h"
|
2014-05-21 19:03:09 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLExtensions.h"
|
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
#include "WebGLTexture.h"
|
|
|
|
#include "WebGLVertexArray.h"
|
2014-08-20 13:38:42 -07:00
|
|
|
#include "WebGLContextUtils.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2014-08-14 18:47:15 -07:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
|
|
|
|
2014-01-23 19:53:53 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-05-01 20:15:58 -07:00
|
|
|
using namespace gl;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsGLDepthFormat(GLenum webGLFormat)
|
|
|
|
{
|
|
|
|
return (webGLFormat == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
webGLFormat == LOCAL_GL_DEPTH_COMPONENT16 ||
|
|
|
|
webGLFormat == LOCAL_GL_DEPTH_COMPONENT32);
|
|
|
|
}
|
|
|
|
|
2014-01-23 19:53:53 -08:00
|
|
|
bool
|
2014-05-01 20:15:58 -07:00
|
|
|
IsGLDepthStencilFormat(GLenum webGLFormat)
|
2014-01-23 19:53:53 -08:00
|
|
|
{
|
2014-05-01 20:15:58 -07:00
|
|
|
return (webGLFormat == LOCAL_GL_DEPTH_STENCIL ||
|
|
|
|
webGLFormat == LOCAL_GL_DEPTH24_STENCIL8);
|
2014-01-23 19:53:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-01 20:15:58 -07:00
|
|
|
FormatHasAlpha(GLenum webGLFormat)
|
|
|
|
{
|
|
|
|
return webGLFormat == LOCAL_GL_RGBA ||
|
|
|
|
webGLFormat == LOCAL_GL_LUMINANCE_ALPHA ||
|
|
|
|
webGLFormat == LOCAL_GL_ALPHA ||
|
|
|
|
webGLFormat == LOCAL_GL_RGBA4 ||
|
|
|
|
webGLFormat == LOCAL_GL_RGB5_A1 ||
|
|
|
|
webGLFormat == LOCAL_GL_SRGB_ALPHA;
|
|
|
|
}
|
2014-08-20 13:38:42 -07:00
|
|
|
|
|
|
|
GLComponents::GLComponents(GLenum format)
|
|
|
|
{
|
|
|
|
mComponents = 0;
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_RGBA4:
|
|
|
|
case LOCAL_GL_RGBA8:
|
|
|
|
case LOCAL_GL_RGB5_A1:
|
|
|
|
// Luminance + Alpha can be converted
|
|
|
|
// to and from RGBA
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
mComponents |= Components::Alpha;
|
|
|
|
// Drops through
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
case LOCAL_GL_RGB565:
|
|
|
|
// Luminance can be converted to and from RGB
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
mComponents |= Components::Red | Components::Green | Components::Blue;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
mComponents |= Components::Alpha;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
mComponents |= Components::Depth;
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
mComponents |= Components::Stencil;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Unhandled case - GLComponents");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLComponents::IsSubsetOf(const GLComponents& other) const
|
|
|
|
{
|
|
|
|
return (mComponents | other.mComponents) == other.mComponents;
|
|
|
|
}
|
2014-05-01 20:15:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert WebGL/ES format and type into GL format and GL internal
|
|
|
|
* format valid for underlying driver.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DriverFormatsFromFormatAndType(GLContext* gl, GLenum webGLFormat, GLenum webGLType,
|
|
|
|
GLenum* out_driverInternalFormat, GLenum* out_driverFormat)
|
2014-01-23 19:53:53 -08:00
|
|
|
{
|
2014-05-01 20:15:58 -07:00
|
|
|
MOZ_ASSERT(out_driverInternalFormat, "out_driverInternalFormat can't be nullptr.");
|
|
|
|
MOZ_ASSERT(out_driverFormat, "out_driverFormat can't be nullptr.");
|
|
|
|
if (!out_driverInternalFormat || !out_driverFormat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// ES2 requires that format == internalformat; floating-point is
|
|
|
|
// indicated purely by the type that's loaded. For desktop GL, we
|
|
|
|
// have to specify a floating point internal format.
|
|
|
|
if (gl->IsGLES()) {
|
|
|
|
*out_driverInternalFormat = webGLFormat;
|
|
|
|
*out_driverFormat = webGLFormat;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum format = webGLFormat;
|
|
|
|
GLenum internalFormat = LOCAL_GL_NONE;
|
|
|
|
|
|
|
|
if (format == LOCAL_GL_DEPTH_COMPONENT) {
|
|
|
|
if (webGLType == LOCAL_GL_UNSIGNED_SHORT)
|
|
|
|
internalFormat = LOCAL_GL_DEPTH_COMPONENT16;
|
|
|
|
else if (webGLType == LOCAL_GL_UNSIGNED_INT)
|
|
|
|
internalFormat = LOCAL_GL_DEPTH_COMPONENT32;
|
|
|
|
} else if (format == LOCAL_GL_DEPTH_STENCIL) {
|
|
|
|
if (webGLType == LOCAL_GL_UNSIGNED_INT_24_8_EXT)
|
|
|
|
internalFormat = LOCAL_GL_DEPTH24_STENCIL8;
|
|
|
|
} else {
|
|
|
|
switch (webGLType) {
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
internalFormat = format;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
internalFormat = LOCAL_GL_RGBA32F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
internalFormat = LOCAL_GL_RGB32F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
internalFormat = LOCAL_GL_ALPHA32F_ARB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
internalFormat = LOCAL_GL_LUMINANCE32F_ARB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
internalFormat = LOCAL_GL_LUMINANCE_ALPHA32F_ARB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
internalFormat = LOCAL_GL_RGBA16F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
internalFormat = LOCAL_GL_RGB16F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
internalFormat = LOCAL_GL_ALPHA16F_ARB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
internalFormat = LOCAL_GL_LUMINANCE16F_ARB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
internalFormat = LOCAL_GL_LUMINANCE_ALPHA16F_ARB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle ES2 and GL differences when supporting sRGB internal formats. GL ES
|
|
|
|
// requires that format == internalformat, but GL will fail in this case.
|
|
|
|
// GL requires:
|
|
|
|
// format -> internalformat
|
|
|
|
// GL_RGB GL_SRGB_EXT
|
|
|
|
// GL_RGBA GL_SRGB_ALPHA_EXT
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_SRGB:
|
|
|
|
internalFormat = format;
|
|
|
|
format = LOCAL_GL_RGB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_SRGB_ALPHA:
|
|
|
|
internalFormat = format;
|
|
|
|
format = LOCAL_GL_RGBA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(format != LOCAL_GL_NONE && internalFormat != LOCAL_GL_NONE,
|
|
|
|
"Coding mistake -- bad format/type passed?");
|
|
|
|
|
|
|
|
*out_driverInternalFormat = internalFormat;
|
|
|
|
*out_driverFormat = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum
|
|
|
|
DriverTypeFromType(GLContext* gl, GLenum webGLType)
|
|
|
|
{
|
|
|
|
if (gl->IsGLES())
|
|
|
|
return webGLType;
|
|
|
|
|
|
|
|
// convert type for half float if not on GLES2
|
|
|
|
GLenum type = webGLType;
|
|
|
|
if (type == LOCAL_GL_HALF_FLOAT_OES) {
|
|
|
|
if (gl->IsSupported(gl::GLFeature::texture_half_float)) {
|
|
|
|
return LOCAL_GL_HALF_FLOAT;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return webGLType;
|
2014-01-23 19:53:53 -08:00
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
void
|
2012-05-23 09:07:29 -07:00
|
|
|
WebGLContext::GenerateWarning(const char *fmt, ...)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2010-09-13 08:40:01 -07:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, ap);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
va_end(ap);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
void
|
2012-05-23 09:07:29 -07:00
|
|
|
WebGLContext::GenerateWarning(const char *fmt, va_list ap)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-29 11:44:31 -07:00
|
|
|
if (!ShouldGenerateWarnings())
|
2012-05-23 09:07:10 -07:00
|
|
|
return;
|
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
mAlreadyGeneratedWarnings++;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
char buf[1024];
|
2010-10-15 14:50:15 -07:00
|
|
|
PR_vsnprintf(buf, 1024, fmt, ap);
|
2010-09-13 08:40:01 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
// no need to print to stderr, as JS_ReportWarning takes care of this for us.
|
|
|
|
|
2013-04-29 11:16:17 -07:00
|
|
|
AutoJSContext cx;
|
|
|
|
JS_ReportWarning(cx, "WebGL: %s", buf);
|
|
|
|
if (!ShouldGenerateWarnings()) {
|
|
|
|
JS_ReportWarning(cx,
|
|
|
|
"WebGL: No further warnings will be reported for this WebGL context "
|
|
|
|
"(already reported %d warnings)", mAlreadyGeneratedWarnings);
|
2012-05-23 09:07:10 -07:00
|
|
|
}
|
2010-09-13 08:40:01 -07:00
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::ShouldGenerateWarnings() const
|
|
|
|
{
|
|
|
|
if (mMaxWarnings == -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAlreadyGeneratedWarnings < mMaxWarnings;
|
|
|
|
}
|
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32
|
2014-01-23 19:52:33 -08:00
|
|
|
WebGLContext::GetImageSize(GLsizei height,
|
|
|
|
GLsizei width,
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t pixelSize,
|
|
|
|
uint32_t packOrUnpackAlignment)
|
2011-09-01 12:28:34 -07:00
|
|
|
{
|
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * pixelSize;
|
|
|
|
|
|
|
|
// alignedRowSize = row size rounded up to next multiple of packAlignment
|
|
|
|
CheckedUint32 checked_alignedRowSize = RoundedToNextMultipleOf(checked_plainRowSize, packOrUnpackAlignment);
|
|
|
|
|
|
|
|
// if height is 0, we don't need any memory to store this; without this check, we'll get an overflow
|
|
|
|
CheckedUint32 checked_neededByteLength
|
|
|
|
= height <= 0 ? 0 : (height-1) * checked_alignedRowSize + checked_plainRowSize;
|
|
|
|
|
|
|
|
return checked_neededByteLength;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::SynthesizeGLError(GLenum err)
|
2010-05-15 06:55:45 -07:00
|
|
|
{
|
2014-03-07 13:16:34 -08:00
|
|
|
/* ES2 section 2.5 "GL Errors" states that implementations can have
|
|
|
|
* multiple 'flags', as errors might be caught in different parts of
|
|
|
|
* a distributed implementation.
|
|
|
|
* We're signing up as a distributed implementation here, with
|
|
|
|
* separate flags for WebGL and the underlying GLContext.
|
|
|
|
*/
|
2011-07-07 17:01:16 -07:00
|
|
|
if (!mWebGLError)
|
|
|
|
mWebGLError = err;
|
2010-05-15 06:55:45 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::SynthesizeGLError(GLenum err, const char *fmt, ...)
|
2010-05-15 06:55:45 -07:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(err);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidEnum(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
|
|
|
|
}
|
|
|
|
|
2013-09-04 05:14:50 -07:00
|
|
|
void
|
|
|
|
WebGLContext::ErrorInvalidEnumInfo(const char *info, GLenum enumvalue)
|
|
|
|
{
|
|
|
|
return ErrorInvalidEnum("%s: invalid enum value 0x%x", info, enumvalue);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidValue(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_VALUE);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2011-02-24 14:17:34 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLContext::ErrorInvalidFramebufferOperation(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2012-01-24 13:12:31 -08:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLContext::ErrorOutOfMemory(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2011-02-24 14:17:34 -08:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
const char *
|
|
|
|
WebGLContext::ErrorName(GLenum error)
|
|
|
|
{
|
|
|
|
switch(error) {
|
|
|
|
case LOCAL_GL_INVALID_ENUM:
|
|
|
|
return "INVALID_ENUM";
|
|
|
|
case LOCAL_GL_INVALID_OPERATION:
|
|
|
|
return "INVALID_OPERATION";
|
|
|
|
case LOCAL_GL_INVALID_VALUE:
|
|
|
|
return "INVALID_VALUE";
|
|
|
|
case LOCAL_GL_OUT_OF_MEMORY:
|
|
|
|
return "OUT_OF_MEMORY";
|
|
|
|
case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
|
|
|
|
return "INVALID_FRAMEBUFFER_OPERATION";
|
|
|
|
case LOCAL_GL_NO_ERROR:
|
|
|
|
return "NO_ERROR";
|
|
|
|
default:
|
2013-10-11 06:16:43 -07:00
|
|
|
MOZ_ASSERT(false);
|
2011-07-07 17:01:16 -07:00
|
|
|
return "[unknown WebGL error!]";
|
|
|
|
}
|
2012-04-03 16:42:06 -07:00
|
|
|
}
|
|
|
|
|
2014-06-02 13:30:00 -07:00
|
|
|
const char*
|
|
|
|
WebGLContext::EnumName(GLenum glenum)
|
|
|
|
{
|
|
|
|
switch (glenum) {
|
|
|
|
#define XX(x) case LOCAL_GL_##x: return #x
|
|
|
|
XX(ALPHA);
|
|
|
|
XX(ATC_RGB);
|
|
|
|
XX(ATC_RGBA_EXPLICIT_ALPHA);
|
|
|
|
XX(ATC_RGBA_INTERPOLATED_ALPHA);
|
|
|
|
XX(COMPRESSED_RGBA_PVRTC_2BPPV1);
|
|
|
|
XX(COMPRESSED_RGBA_PVRTC_4BPPV1);
|
|
|
|
XX(COMPRESSED_RGBA_S3TC_DXT1_EXT);
|
|
|
|
XX(COMPRESSED_RGBA_S3TC_DXT3_EXT);
|
|
|
|
XX(COMPRESSED_RGBA_S3TC_DXT5_EXT);
|
|
|
|
XX(COMPRESSED_RGB_PVRTC_2BPPV1);
|
|
|
|
XX(COMPRESSED_RGB_PVRTC_4BPPV1);
|
|
|
|
XX(COMPRESSED_RGB_S3TC_DXT1_EXT);
|
|
|
|
XX(DEPTH_COMPONENT);
|
|
|
|
XX(DEPTH_COMPONENT16);
|
|
|
|
XX(DEPTH_COMPONENT32);
|
|
|
|
XX(DEPTH_STENCIL);
|
|
|
|
XX(DEPTH24_STENCIL8);
|
|
|
|
XX(ETC1_RGB8_OES);
|
|
|
|
XX(FLOAT);
|
|
|
|
XX(HALF_FLOAT);
|
|
|
|
XX(LUMINANCE);
|
|
|
|
XX(LUMINANCE_ALPHA);
|
|
|
|
XX(RGB);
|
|
|
|
XX(RGB16F);
|
|
|
|
XX(RGB32F);
|
|
|
|
XX(RGBA);
|
|
|
|
XX(RGBA16F);
|
|
|
|
XX(RGBA32F);
|
|
|
|
XX(SRGB);
|
|
|
|
XX(SRGB_ALPHA);
|
|
|
|
XX(TEXTURE_2D);
|
|
|
|
XX(TEXTURE_3D);
|
|
|
|
XX(TEXTURE_CUBE_MAP);
|
|
|
|
XX(TEXTURE_CUBE_MAP_NEGATIVE_X);
|
|
|
|
XX(TEXTURE_CUBE_MAP_NEGATIVE_Y);
|
|
|
|
XX(TEXTURE_CUBE_MAP_NEGATIVE_Z);
|
|
|
|
XX(TEXTURE_CUBE_MAP_POSITIVE_X);
|
|
|
|
XX(TEXTURE_CUBE_MAP_POSITIVE_Y);
|
|
|
|
XX(TEXTURE_CUBE_MAP_POSITIVE_Z);
|
|
|
|
XX(UNSIGNED_BYTE);
|
|
|
|
XX(UNSIGNED_INT);
|
|
|
|
XX(UNSIGNED_INT_24_8);
|
|
|
|
XX(UNSIGNED_SHORT);
|
|
|
|
XX(UNSIGNED_SHORT_4_4_4_4);
|
|
|
|
XX(UNSIGNED_SHORT_5_5_5_1);
|
|
|
|
XX(UNSIGNED_SHORT_5_6_5);
|
|
|
|
#undef XX
|
|
|
|
}
|
|
|
|
|
|
|
|
return "[Unknown enum name]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-03 16:42:06 -07:00
|
|
|
bool
|
|
|
|
WebGLContext::IsTextureFormatCompressed(GLenum format)
|
|
|
|
{
|
2014-01-23 19:53:53 -08:00
|
|
|
switch (format) {
|
2012-04-03 16:42:06 -07:00
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
2012-09-25 05:49:28 -07:00
|
|
|
case LOCAL_GL_ATC_RGB:
|
|
|
|
case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
2012-09-25 05:49:28 -07:00
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
2014-03-10 15:42:58 -07:00
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
2012-04-03 16:42:06 -07:00
|
|
|
return true;
|
2014-01-23 19:53:53 -08:00
|
|
|
default:
|
|
|
|
return false;
|
2012-04-03 16:42:06 -07:00
|
|
|
}
|
|
|
|
}
|
2013-09-04 05:14:50 -07:00
|
|
|
|
2014-03-07 13:16:34 -08:00
|
|
|
GLenum
|
|
|
|
WebGLContext::GetAndFlushUnderlyingGLErrors()
|
2013-09-04 05:14:50 -07:00
|
|
|
{
|
2014-03-07 13:16:34 -08:00
|
|
|
// Get and clear GL error in ALL cases.
|
2013-09-04 05:14:50 -07:00
|
|
|
GLenum error = gl->GetAndClearError();
|
2014-03-07 13:16:34 -08:00
|
|
|
|
|
|
|
// Only store in mUnderlyingGLError if is hasn't already recorded an
|
|
|
|
// error.
|
|
|
|
if (!mUnderlyingGLError)
|
|
|
|
mUnderlyingGLError = error;
|
|
|
|
|
|
|
|
return error;
|
2013-09-04 05:14:50 -07:00
|
|
|
}
|
2014-05-21 19:03:09 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// For NaNs, etc.
|
|
|
|
static bool
|
|
|
|
IsCacheCorrect(float cached, float actual)
|
|
|
|
{
|
|
|
|
if (IsNaN(cached)) {
|
|
|
|
// GL is allowed to do anything it wants for NaNs, so if we're shadowing
|
|
|
|
// a NaN, then whatever `actual` is might be correct.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cached == actual;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow)
|
|
|
|
{
|
|
|
|
GLuint val = 0;
|
|
|
|
gl->GetUIntegerv(pname, &val);
|
|
|
|
if (val != shadow) {
|
|
|
|
printf_stderr("Failed 0x%04x shadow: Cached 0x%x/%u, should be 0x%x/%u.\n",
|
|
|
|
pname, shadow, shadow, val, val);
|
|
|
|
MOZ_ASSERT(false, "Bad cached value.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
AssertUintParamCorrect(gl::GLContext*, GLenum, GLuint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::AssertCachedBindings()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GetAndFlushUnderlyingGLErrors();
|
|
|
|
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::OES_vertex_array_object)) {
|
|
|
|
GLuint bound = mBoundVertexArray ? mBoundVertexArray->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_VERTEX_ARRAY_BINDING, bound);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bound object state
|
|
|
|
GLuint bound = mBoundFramebuffer ? mBoundFramebuffer->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_FRAMEBUFFER_BINDING, bound);
|
|
|
|
|
|
|
|
bound = mCurrentProgram ? mCurrentProgram->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_CURRENT_PROGRAM, bound);
|
|
|
|
|
|
|
|
// Textures
|
|
|
|
GLenum activeTexture = mActiveTexture + LOCAL_GL_TEXTURE0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_ACTIVE_TEXTURE, activeTexture);
|
|
|
|
|
|
|
|
WebGLTexture* curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_2D);
|
|
|
|
bound = curTex ? curTex->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_2D, bound);
|
|
|
|
|
|
|
|
curTex = activeBoundTextureForTarget(LOCAL_GL_TEXTURE_CUBE_MAP);
|
|
|
|
bound = curTex ? curTex->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_TEXTURE_BINDING_CUBE_MAP, bound);
|
|
|
|
|
|
|
|
// Buffers
|
|
|
|
bound = mBoundArrayBuffer ? mBoundArrayBuffer->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_ARRAY_BUFFER_BINDING, bound);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
2014-06-05 16:38:27 -07:00
|
|
|
WebGLBuffer* curBuff = mBoundVertexArray->mElementArrayBuffer;
|
2014-05-21 19:03:09 -07:00
|
|
|
bound = curBuff ? curBuff->GLName() : 0;
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_ELEMENT_ARRAY_BUFFER_BINDING, bound);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!GetAndFlushUnderlyingGLErrors());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::AssertCachedState()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
GetAndFlushUnderlyingGLErrors();
|
|
|
|
|
|
|
|
// extensions
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers)) {
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_MAX_COLOR_ATTACHMENTS, mGLMaxColorAttachments);
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_MAX_DRAW_BUFFERS, mGLMaxDrawBuffers);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw state
|
|
|
|
MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_SCISSOR_TEST) == mScissorTestEnabled);
|
|
|
|
MOZ_ASSERT(gl->fIsEnabled(LOCAL_GL_DITHER) == mDitherEnabled);
|
|
|
|
MOZ_ASSERT_IF(IsWebGL2(),
|
|
|
|
gl->fIsEnabled(LOCAL_GL_RASTERIZER_DISCARD) == mRasterizerDiscardEnabled);
|
|
|
|
|
|
|
|
|
|
|
|
realGLboolean colorWriteMask[4] = {0, 0, 0, 0};
|
|
|
|
gl->fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorWriteMask);
|
|
|
|
MOZ_ASSERT(colorWriteMask[0] == mColorWriteMask[0] &&
|
|
|
|
colorWriteMask[1] == mColorWriteMask[1] &&
|
|
|
|
colorWriteMask[2] == mColorWriteMask[2] &&
|
|
|
|
colorWriteMask[3] == mColorWriteMask[3]);
|
|
|
|
|
|
|
|
GLfloat colorClearValue[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, colorClearValue);
|
|
|
|
MOZ_ASSERT(IsCacheCorrect(mColorClearValue[0], colorClearValue[0]) &&
|
|
|
|
IsCacheCorrect(mColorClearValue[1], colorClearValue[1]) &&
|
|
|
|
IsCacheCorrect(mColorClearValue[2], colorClearValue[2]) &&
|
|
|
|
IsCacheCorrect(mColorClearValue[3], colorClearValue[3]));
|
|
|
|
|
|
|
|
realGLboolean depthWriteMask = 0;
|
|
|
|
gl->fGetBooleanv(LOCAL_GL_DEPTH_WRITEMASK, &depthWriteMask);
|
|
|
|
MOZ_ASSERT(depthWriteMask == mDepthWriteMask);
|
|
|
|
|
|
|
|
GLfloat depthClearValue = 0.0f;
|
|
|
|
gl->fGetFloatv(LOCAL_GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
|
|
|
MOZ_ASSERT(IsCacheCorrect(mDepthClearValue, depthClearValue));
|
|
|
|
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_CLEAR_VALUE, mStencilClearValue);
|
|
|
|
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_REF, mStencilRefFront);
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_REF, mStencilRefBack);
|
|
|
|
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_VALUE_MASK, mStencilValueMaskFront);
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_VALUE_MASK, mStencilValueMaskBack);
|
|
|
|
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_WRITEMASK, mStencilWriteMaskFront);
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_STENCIL_BACK_WRITEMASK, mStencilWriteMaskBack);
|
|
|
|
|
|
|
|
// Viewport
|
|
|
|
GLint int4[4] = {0, 0, 0, 0};
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_VIEWPORT, int4);
|
|
|
|
MOZ_ASSERT(int4[0] == mViewportX &&
|
|
|
|
int4[1] == mViewportY &&
|
|
|
|
int4[2] == mViewportWidth &&
|
|
|
|
int4[3] == mViewportHeight);
|
|
|
|
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_PACK_ALIGNMENT, mPixelStorePackAlignment);
|
|
|
|
AssertUintParamCorrect(gl, LOCAL_GL_UNPACK_ALIGNMENT, mPixelStoreUnpackAlignment);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!GetAndFlushUnderlyingGLErrors());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|