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
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
|
#include "WebGLContext.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
|
#include "WebGLVertexAttribData.h"
|
|
|
|
|
#include "WebGLShader.h"
|
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
|
#include "WebGLUniformLocation.h"
|
|
|
|
|
#include "WebGLFramebuffer.h"
|
|
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
|
#include "WebGLTexture.h"
|
2013-06-27 14:07:21 -07:00
|
|
|
|
#include "WebGLVertexArray.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
|
#include "GLContext.h"
|
2014-02-20 17:20:28 -08:00
|
|
|
|
#include "CanvasUtils.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
2012-05-14 12:50:20 -07:00
|
|
|
|
#include "mozilla/CheckedInt.h"
|
2012-06-06 00:40:02 -07:00
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
#include "mozilla/Services.h"
|
2010-07-03 15:32:19 -07:00
|
|
|
|
|
2012-01-14 09:43:00 -08:00
|
|
|
|
#include "jsfriendapi.h"
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
|
#include "angle/ShaderLang.h"
|
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2012-07-01 16:45:59 -07:00
|
|
|
|
#include "mozilla/Services.h"
|
2012-04-21 13:48:22 -07:00
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return the block size for format.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
BlockSizeFor(GLenum format, GLint* blockWidth, GLint* blockHeight)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(blockWidth && blockHeight);
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
case LOCAL_GL_ATC_RGB:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
|
if (blockWidth)
|
|
|
|
|
*blockWidth = 4;
|
|
|
|
|
if (blockHeight)
|
|
|
|
|
*blockHeight = 4;
|
|
|
|
|
break;
|
2014-03-10 15:42:58 -07:00
|
|
|
|
|
|
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
|
|
|
|
// 4x4 blocks, but no 4-multiple requirement.
|
2014-02-20 17:20:28 -08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the displayable name for the texture function that is the
|
|
|
|
|
* source for validation.
|
|
|
|
|
*/
|
|
|
|
|
static const char*
|
|
|
|
|
InfoFrom(WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Account for dimensions (WebGL 2)
|
|
|
|
|
switch (func) {
|
|
|
|
|
case WebGLTexImageFunc::TexImage: return "texImage2D";
|
|
|
|
|
case WebGLTexImageFunc::TexSubImage: return "texSubImage2D";
|
|
|
|
|
case WebGLTexImageFunc::CopyTexImage: return "copyTexImage2D";
|
|
|
|
|
case WebGLTexImageFunc::CopyTexSubImage: return "copyTexSubImage2D";
|
|
|
|
|
case WebGLTexImageFunc::CompTexImage: return "compressedTexImage2D";
|
|
|
|
|
case WebGLTexImageFunc::CompTexSubImage: return "compressedTexSubImage2D";
|
|
|
|
|
default:
|
|
|
|
|
MOZ_ASSERT(false, "Missing case for WebGLTexImageSource");
|
|
|
|
|
return "(error)";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-02 13:30:00 -07:00
|
|
|
|
* Same as ErrorInvalidEnum but uses WebGLContext::EnumName to print displayable
|
2014-02-20 17:20:28 -08:00
|
|
|
|
* name for \a glenum.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
ErrorInvalidEnumWithName(WebGLContext* ctx, const char* msg, GLenum glenum, WebGLTexImageFunc func)
|
|
|
|
|
{
|
2014-06-02 13:30:00 -07:00
|
|
|
|
const char* name = WebGLContext::EnumName(glenum);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (name)
|
|
|
|
|
ctx->ErrorInvalidEnum("%s: %s %s", InfoFrom(func), msg, name);
|
|
|
|
|
else
|
|
|
|
|
ctx->ErrorInvalidEnum("%s: %s 0x%04X", InfoFrom(func), msg, glenum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the format is valid for source calls.
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
IsAllowedFromSource(GLenum format, WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
switch (format) {
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
|
return (func == WebGLTexImageFunc::CompTexImage ||
|
|
|
|
|
func == WebGLTexImageFunc::CompTexSubImage);
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_ATC_RGB:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
2014-03-10 15:42:58 -07:00
|
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return func == WebGLTexImageFunc::CompTexImage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if func is a CopyTexImage variant.
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
IsCopyFunc(WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
return (func == WebGLTexImageFunc::CopyTexImage ||
|
|
|
|
|
func == WebGLTexImageFunc::CopyTexSubImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if func is a SubImage variant.
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
IsSubFunc(WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
return (func == WebGLTexImageFunc::TexSubImage ||
|
|
|
|
|
func == WebGLTexImageFunc::CopyTexSubImage ||
|
|
|
|
|
func == WebGLTexImageFunc::CompTexSubImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* returns true is target is a texture cube map target.
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
|
|
|
|
IsTexImageCubemapTarget(GLenum target)
|
|
|
|
|
{
|
|
|
|
|
return (target >= LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
|
|
|
|
|
target <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
|
/*
|
2012-03-02 12:42:49 -08:00
|
|
|
|
* Pull data out of the program, post-linking
|
2010-06-10 10:45:00 -07:00
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2012-03-02 12:42:49 -08:00
|
|
|
|
WebGLProgram::UpdateInfo()
|
2010-06-10 10:45:00 -07:00
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
|
mIdentifierMap = nullptr;
|
|
|
|
|
mIdentifierReverseMap = nullptr;
|
|
|
|
|
mUniformInfoMap = nullptr;
|
2012-03-02 12:42:49 -08:00
|
|
|
|
|
|
|
|
|
mAttribMaxNameLength = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mAttachedShaders.Length(); i++)
|
2013-01-15 04:22:03 -08:00
|
|
|
|
mAttribMaxNameLength = std::max(mAttribMaxNameLength, mAttachedShaders[i]->mAttribMaxNameLength);
|
2012-03-02 12:42:49 -08:00
|
|
|
|
|
|
|
|
|
GLint attribCount;
|
|
|
|
|
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &attribCount);
|
|
|
|
|
|
2012-12-08 12:41:02 -08:00
|
|
|
|
if (!mAttribsInUse.SetLength(mContext->mGLMaxVertexAttribs)) {
|
|
|
|
|
mContext->ErrorOutOfMemory("updateInfo: out of memory to allocate %d attribs", mContext->mGLMaxVertexAttribs);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mAttribsInUse.Length(); i++)
|
|
|
|
|
mAttribsInUse[i] = false;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
|
|
|
|
|
nsAutoArrayPtr<char> nameBuf(new char[mAttribMaxNameLength]);
|
|
|
|
|
|
2012-03-02 12:42:49 -08:00
|
|
|
|
for (int i = 0; i < attribCount; ++i) {
|
2010-06-10 10:45:00 -07:00
|
|
|
|
GLint attrnamelen;
|
|
|
|
|
GLint attrsize;
|
|
|
|
|
GLenum attrtype;
|
2012-03-02 12:42:49 -08:00
|
|
|
|
mContext->gl->fGetActiveAttrib(mGLName, i, mAttribMaxNameLength, &attrnamelen, &attrsize, &attrtype, nameBuf);
|
2010-06-10 10:45:00 -07:00
|
|
|
|
if (attrnamelen > 0) {
|
2012-03-02 12:42:49 -08:00
|
|
|
|
GLint loc = mContext->gl->fGetAttribLocation(mGLName, nameBuf);
|
2013-10-11 06:16:43 -07:00
|
|
|
|
MOZ_ASSERT(loc >= 0, "major oops in managing the attributes of a WebGL program");
|
2012-03-02 12:42:49 -08:00
|
|
|
|
if (loc < mContext->mGLMaxVertexAttribs) {
|
|
|
|
|
mAttribsInUse[loc] = true;
|
|
|
|
|
} else {
|
2012-05-29 11:44:31 -07:00
|
|
|
|
mContext->GenerateWarning("program exceeds MAX_VERTEX_ATTRIBS");
|
2012-03-02 12:42:49 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-04 17:51:58 -07:00
|
|
|
|
if (!mUniformInfoMap) {
|
|
|
|
|
mUniformInfoMap = new CStringToUniformInfoMap;
|
|
|
|
|
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
|
|
|
|
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
|
|
|
|
const WebGLUniformInfo& info = mAttachedShaders[i]->mUniformInfos[j];
|
|
|
|
|
mUniformInfoMap->Put(uniform.mapped, info);
|
2013-06-04 17:51:58 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 06:01:44 -07:00
|
|
|
|
mActiveAttribMap.clear();
|
|
|
|
|
|
|
|
|
|
GLint numActiveAttrs = 0;
|
|
|
|
|
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &numActiveAttrs);
|
|
|
|
|
|
|
|
|
|
// Spec says the maximum attrib name length is 256 chars, so this is
|
|
|
|
|
// sufficient to hold any attrib name.
|
|
|
|
|
char attrName[257];
|
|
|
|
|
|
|
|
|
|
GLint dummySize;
|
|
|
|
|
GLenum dummyType;
|
|
|
|
|
for (GLint i = 0; i < numActiveAttrs; i++) {
|
|
|
|
|
mContext->gl->fGetActiveAttrib(mGLName, i, 257, nullptr, &dummySize,
|
|
|
|
|
&dummyType, attrName);
|
|
|
|
|
GLint attrLoc = mContext->gl->fGetAttribLocation(mGLName, attrName);
|
|
|
|
|
MOZ_ASSERT(attrLoc >= 0);
|
|
|
|
|
mActiveAttribMap.insert(std::make_pair(attrLoc, nsCString(attrName)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return the simple base format for a given internal format.
|
|
|
|
|
*
|
|
|
|
|
* \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
|
|
|
|
|
* GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA), or GL_NONE if invalid enum.
|
|
|
|
|
*/
|
|
|
|
|
GLenum
|
|
|
|
|
WebGLContext::BaseTexFormat(GLenum internalFormat) const
|
|
|
|
|
{
|
|
|
|
|
if (internalFormat == LOCAL_GL_ALPHA ||
|
|
|
|
|
internalFormat == LOCAL_GL_LUMINANCE ||
|
|
|
|
|
internalFormat == LOCAL_GL_LUMINANCE_ALPHA ||
|
|
|
|
|
internalFormat == LOCAL_GL_RGB ||
|
|
|
|
|
internalFormat == LOCAL_GL_RGBA)
|
|
|
|
|
{
|
|
|
|
|
return internalFormat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::EXT_sRGB)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (internalFormat == LOCAL_GL_SRGB)
|
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
|
|
|
|
|
|
if (internalFormat == LOCAL_GL_SRGB_ALPHA)
|
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_atc)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (internalFormat == LOCAL_GL_ATC_RGB)
|
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
|
|
|
|
|
|
if (internalFormat == LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA ||
|
|
|
|
|
internalFormat == LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_etc1)) {
|
2014-03-10 15:42:58 -07:00
|
|
|
|
if (internalFormat == LOCAL_GL_ETC1_RGB8_OES)
|
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_pvrtc)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (internalFormat == LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1 ||
|
|
|
|
|
internalFormat == LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (internalFormat == LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1 ||
|
|
|
|
|
internalFormat == LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_s3tc)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (internalFormat == LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT)
|
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
|
|
|
|
|
|
if (internalFormat == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
|
|
|
|
|
internalFormat == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
|
|
|
|
|
internalFormat == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_RGBA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 19:34:07 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (internalFormat == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
|
internalFormat == LOCAL_GL_DEPTH_COMPONENT16 ||
|
|
|
|
|
internalFormat == LOCAL_GL_DEPTH_COMPONENT32)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_DEPTH_COMPONENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (internalFormat == LOCAL_GL_DEPTH_STENCIL ||
|
|
|
|
|
internalFormat == LOCAL_GL_DEPTH24_STENCIL8)
|
|
|
|
|
{
|
|
|
|
|
return LOCAL_GL_DEPTH_STENCIL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(false, "Unhandled internalFormat");
|
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateBlendEquationEnum(GLenum mode, const char *info)
|
2010-06-19 07:48:44 -07:00
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case LOCAL_GL_FUNC_ADD:
|
|
|
|
|
case LOCAL_GL_FUNC_SUBTRACT:
|
|
|
|
|
case LOCAL_GL_FUNC_REVERSE_SUBTRACT:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2013-07-18 08:24:23 -07:00
|
|
|
|
case LOCAL_GL_MIN:
|
|
|
|
|
case LOCAL_GL_MAX:
|
2014-06-14 09:07:53 -07:00
|
|
|
|
if (IsExtensionEnabled(WebGLExtensionID::EXT_blend_minmax)) {
|
2013-07-18 08:24:23 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
default:
|
2013-07-18 08:24:23 -07:00
|
|
|
|
break;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
}
|
2013-07-18 08:24:23 -07:00
|
|
|
|
|
|
|
|
|
ErrorInvalidEnumInfo(info, mode);
|
|
|
|
|
return false;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateBlendFuncDstEnum(GLenum factor, const char *info)
|
2010-06-19 07:48:44 -07:00
|
|
|
|
{
|
|
|
|
|
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:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
|
ErrorInvalidEnumInfo(info, factor);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateBlendFuncSrcEnum(GLenum factor, const char *info)
|
2010-06-19 07:48:44 -07:00
|
|
|
|
{
|
2010-06-30 08:49:59 -07:00
|
|
|
|
if (factor == LOCAL_GL_SRC_ALPHA_SATURATE)
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-19 07:48:44 -07:00
|
|
|
|
else
|
2010-06-30 08:49:59 -07:00
|
|
|
|
return ValidateBlendFuncDstEnum(factor, info);
|
2010-06-19 07:48:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateBlendFuncEnumsCompatibility(GLenum sfactor, GLenum dfactor, const char *info)
|
2010-12-06 03:34:35 -08:00
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool sfactorIsConstantColor = sfactor == LOCAL_GL_CONSTANT_COLOR ||
|
2010-12-06 03:34:35 -08:00
|
|
|
|
sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool sfactorIsConstantAlpha = sfactor == LOCAL_GL_CONSTANT_ALPHA ||
|
2010-12-06 03:34:35 -08:00
|
|
|
|
sfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool dfactorIsConstantColor = dfactor == LOCAL_GL_CONSTANT_COLOR ||
|
2010-12-06 03:34:35 -08:00
|
|
|
|
dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_COLOR;
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool dfactorIsConstantAlpha = dfactor == LOCAL_GL_CONSTANT_ALPHA ||
|
2010-12-06 03:34:35 -08:00
|
|
|
|
dfactor == LOCAL_GL_ONE_MINUS_CONSTANT_ALPHA;
|
|
|
|
|
if ( (sfactorIsConstantColor && dfactorIsConstantAlpha) ||
|
|
|
|
|
(dfactorIsConstantColor && sfactorIsConstantAlpha) ) {
|
|
|
|
|
ErrorInvalidOperation("%s are mutually incompatible, see section 6.8 in the WebGL 1.0 spec", info);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-12-06 03:34:35 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateTextureTargetEnum(GLenum target, const char *info)
|
2010-06-30 08:48:30 -07:00
|
|
|
|
{
|
|
|
|
|
switch (target) {
|
|
|
|
|
case LOCAL_GL_TEXTURE_2D:
|
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
|
ErrorInvalidEnumInfo(info, target);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateComparisonEnum(GLenum target, const char *info)
|
2010-06-30 08:48:30 -07:00
|
|
|
|
{
|
|
|
|
|
switch (target) {
|
|
|
|
|
case LOCAL_GL_NEVER:
|
|
|
|
|
case LOCAL_GL_LESS:
|
|
|
|
|
case LOCAL_GL_LEQUAL:
|
|
|
|
|
case LOCAL_GL_GREATER:
|
|
|
|
|
case LOCAL_GL_GEQUAL:
|
|
|
|
|
case LOCAL_GL_EQUAL:
|
|
|
|
|
case LOCAL_GL_NOTEQUAL:
|
|
|
|
|
case LOCAL_GL_ALWAYS:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
|
ErrorInvalidEnumInfo(info, target);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateStencilOpEnum(GLenum action, const char *info)
|
2010-06-30 08:48:30 -07:00
|
|
|
|
{
|
|
|
|
|
switch (action) {
|
|
|
|
|
case LOCAL_GL_KEEP:
|
|
|
|
|
case LOCAL_GL_ZERO:
|
|
|
|
|
case LOCAL_GL_REPLACE:
|
|
|
|
|
case LOCAL_GL_INCR:
|
|
|
|
|
case LOCAL_GL_INCR_WRAP:
|
|
|
|
|
case LOCAL_GL_DECR:
|
|
|
|
|
case LOCAL_GL_DECR_WRAP:
|
|
|
|
|
case LOCAL_GL_INVERT:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
|
ErrorInvalidEnumInfo(info, action);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateFaceEnum(GLenum face, const char *info)
|
2010-06-30 08:48:30 -07:00
|
|
|
|
{
|
2010-07-16 07:31:48 -07:00
|
|
|
|
switch (face) {
|
2010-06-30 08:48:30 -07:00
|
|
|
|
case LOCAL_GL_FRONT:
|
|
|
|
|
case LOCAL_GL_BACK:
|
|
|
|
|
case LOCAL_GL_FRONT_AND_BACK:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
|
ErrorInvalidEnumInfo(info, face);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-06-30 08:48:30 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateDrawModeEnum(GLenum mode, const char *info)
|
2010-07-16 07:31:48 -07:00
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case LOCAL_GL_TRIANGLES:
|
|
|
|
|
case LOCAL_GL_TRIANGLE_STRIP:
|
|
|
|
|
case LOCAL_GL_TRIANGLE_FAN:
|
|
|
|
|
case LOCAL_GL_POINTS:
|
|
|
|
|
case LOCAL_GL_LINE_STRIP:
|
|
|
|
|
case LOCAL_GL_LINE_LOOP:
|
|
|
|
|
case LOCAL_GL_LINES:
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-07-16 07:31:48 -07:00
|
|
|
|
default:
|
|
|
|
|
ErrorInvalidEnumInfo(info, mode);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-07-03 15:34:07 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
|
bool WebGLContext::ValidateGLSLVariableName(const nsAString& name, const char *info)
|
2011-07-28 14:12:31 -07:00
|
|
|
|
{
|
2012-06-15 14:39:21 -07:00
|
|
|
|
if (name.IsEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
2012-05-23 09:07:01 -07:00
|
|
|
|
const uint32_t maxSize = 256;
|
2011-07-28 14:12:31 -07:00
|
|
|
|
if (name.Length() > maxSize) {
|
|
|
|
|
ErrorInvalidValue("%s: identifier is %d characters long, exceeds the maximum allowed length of %d characters",
|
|
|
|
|
info, name.Length(), maxSize);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-09-07 14:17:44 -07:00
|
|
|
|
|
|
|
|
|
if (!ValidateGLSLString(name, info)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 13:36:06 -08:00
|
|
|
|
nsString prefix1 = NS_LITERAL_STRING("webgl_");
|
|
|
|
|
nsString prefix2 = NS_LITERAL_STRING("_webgl_");
|
|
|
|
|
|
|
|
|
|
if (Substring(name, 0, prefix1.Length()).Equals(prefix1) ||
|
|
|
|
|
Substring(name, 0, prefix2.Length()).Equals(prefix2))
|
|
|
|
|
{
|
|
|
|
|
ErrorInvalidOperation("%s: string contains a reserved GLSL prefix", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 14:17:44 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebGLContext::ValidateGLSLString(const nsAString& string, const char *info)
|
|
|
|
|
{
|
2012-05-23 09:07:01 -07:00
|
|
|
|
for (uint32_t i = 0; i < string.Length(); ++i) {
|
2011-09-07 14:17:44 -07:00
|
|
|
|
if (!ValidateGLSLCharacter(string.CharAt(i))) {
|
|
|
|
|
ErrorInvalidValue("%s: string contains the illegal character '%d'", info, string.CharAt(i));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-28 14:12:31 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return true if format is a valid texture image format for source,
|
|
|
|
|
* taking into account enabled WebGL extensions.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImageFormat(GLenum format, WebGLTexImageFunc func)
|
2013-11-04 13:05:04 -08:00
|
|
|
|
{
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Core WebGL texture formats */
|
|
|
|
|
if (format == LOCAL_GL_ALPHA ||
|
|
|
|
|
format == LOCAL_GL_RGB ||
|
|
|
|
|
format == LOCAL_GL_RGBA ||
|
|
|
|
|
format == LOCAL_GL_LUMINANCE ||
|
|
|
|
|
format == LOCAL_GL_LUMINANCE_ALPHA)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2013-11-04 13:05:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Only core formats are valid for CopyTex(Sub)?Image */
|
|
|
|
|
// TODO: Revisit this once color_buffer_(half_)?float lands
|
|
|
|
|
if (IsCopyFunc(func)) {
|
|
|
|
|
ErrorInvalidEnumWithName(this, "invalid format", format, func);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* WEBGL_depth_texture added formats */
|
|
|
|
|
if (format == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
|
format == LOCAL_GL_DEPTH_STENCIL)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need WEBGL_depth_texture enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* EXT_sRGB added formats */
|
|
|
|
|
if (format == LOCAL_GL_SRGB ||
|
|
|
|
|
format == LOCAL_GL_SRGB_ALPHA)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::EXT_sRGB);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need EXT_sRGB enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* WEBGL_compressed_texture_atc added formats */
|
|
|
|
|
if (format == LOCAL_GL_ATC_RGB ||
|
|
|
|
|
format == LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA ||
|
|
|
|
|
format == LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_atc);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_atc enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-10 15:42:58 -07:00
|
|
|
|
// WEBGL_compressed_texture_etc1
|
|
|
|
|
if (format == LOCAL_GL_ETC1_RGB8_OES) {
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_etc1);
|
2014-03-10 15:42:58 -07:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_etc1 enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-03-10 15:42:58 -07:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
|
|
|
|
|
if (format == LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1 ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1 ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1 ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_pvrtc);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_pvrtc enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (format == LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
|
|
|
|
|
format == LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validFormat = IsExtensionEnabled(WebGLExtensionID::WEBGL_compressed_texture_s3tc);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validFormat)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid format %s: need WEBGL_compressed_texture_s3tc enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validFormat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorInvalidEnumWithName(this, "invalid format", format, func);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the given texture target is valid for TexImage.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImageTarget(GLuint dims, GLenum target, WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
switch (dims) {
|
|
|
|
|
case 2:
|
|
|
|
|
if (target == LOCAL_GL_TEXTURE_2D ||
|
|
|
|
|
IsTexImageCubemapTarget(target))
|
|
|
|
|
{
|
2013-11-04 13:05:04 -08:00
|
|
|
|
return true;
|
2014-02-20 17:20:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorInvalidEnumWithName(this, "invalid target", target, func);
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
MOZ_ASSERT(false, "ValidateTexImageTarget: Invalid dims");
|
2013-11-04 13:05:04 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return true if type is a valid texture image type for source,
|
|
|
|
|
* taking into account enabled WebGL extensions.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImageType(GLenum type, WebGLTexImageFunc func)
|
2012-05-08 10:29:31 -07:00
|
|
|
|
{
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Core WebGL texture types */
|
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_BYTE ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_6_5 ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* OES_texture_float added types */
|
|
|
|
|
if (type == LOCAL_GL_FLOAT) {
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validType = IsExtensionEnabled(WebGLExtensionID::OES_texture_float);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validType)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid type %s: need OES_texture_float enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(type));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* OES_texture_half_float add types */
|
|
|
|
|
if (type == LOCAL_GL_HALF_FLOAT_OES) {
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validType = IsExtensionEnabled(WebGLExtensionID::OES_texture_half_float);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validType)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid type %s: need OES_texture_half_float enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(type));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* WEBGL_depth_texture added types */
|
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_SHORT ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_INT ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_INT_24_8)
|
|
|
|
|
{
|
2014-04-25 19:34:07 -07:00
|
|
|
|
bool validType = IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validType)
|
|
|
|
|
ErrorInvalidEnum("%s: invalid type %s: need WEBGL_depth_texture enabled",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(type));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorInvalidEnumWithName(this, "invalid type", type, func);
|
|
|
|
|
return false;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Validate texture image sizing extra constraints for
|
|
|
|
|
* CompressedTex(Sub)?Image.
|
|
|
|
|
*/
|
|
|
|
|
// TODO: WebGL 2
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateCompTexImageSize(GLenum target, GLint level, GLenum format,
|
|
|
|
|
GLint xoffset, GLint yoffset,
|
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
|
GLsizei levelWidth, GLsizei levelHeight,
|
|
|
|
|
WebGLTexImageFunc func)
|
2012-05-08 10:29:31 -07:00
|
|
|
|
{
|
2014-02-20 17:20:28 -08:00
|
|
|
|
// Negative parameters must already have been handled above
|
|
|
|
|
MOZ_ASSERT(xoffset >= 0 && yoffset >= 0 &&
|
|
|
|
|
width >= 0 && height >= 0);
|
|
|
|
|
|
|
|
|
|
if (xoffset + width > (GLint) levelWidth) {
|
|
|
|
|
ErrorInvalidValue("%s: xoffset + width must be <= levelWidth", InfoFrom(func));
|
2012-09-25 05:49:28 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (yoffset + height > (GLint) levelHeight) {
|
|
|
|
|
ErrorInvalidValue("%s: yoffset + height must be <= levelHeight", InfoFrom(func));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLint blockWidth = 1;
|
|
|
|
|
GLint blockHeight = 1;
|
|
|
|
|
BlockSizeFor(format, &blockWidth, &blockHeight);
|
|
|
|
|
|
|
|
|
|
/* If blockWidth || blockHeight != 1, then the compressed format
|
|
|
|
|
* had block-based constraints to be checked. (For example, PVRTC is compressed but
|
|
|
|
|
* isn't a block-based format)
|
|
|
|
|
*/
|
|
|
|
|
if (blockWidth != 1 || blockHeight != 1) {
|
|
|
|
|
/* offsets must be multiple of block size */
|
|
|
|
|
if (xoffset % blockWidth != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: xoffset must be multiple of %d",
|
|
|
|
|
InfoFrom(func), blockWidth);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (yoffset % blockHeight != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: yoffset must be multiple of %d",
|
|
|
|
|
InfoFrom(func), blockHeight);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The size must be a multiple of blockWidth and blockHeight,
|
|
|
|
|
* or must be using offset+size that exactly hits the edge.
|
2014-02-26 16:32:17 -08:00
|
|
|
|
* Important for small mipmap levels.
|
2014-02-20 17:20:28 -08:00
|
|
|
|
*/
|
2014-02-26 16:32:17 -08:00
|
|
|
|
/* https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
|
|
|
|
|
* "When level equals zero width and height must be a multiple of 4. When
|
|
|
|
|
* level is greater than 0 width and height must be 0, 1, 2 or a multiple of 4.
|
|
|
|
|
* If they are not an INVALID_OPERATION error is generated."
|
|
|
|
|
*/
|
|
|
|
|
if (level == 0) {
|
|
|
|
|
if (width % blockWidth != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: width of level 0 must be multple of %d",
|
|
|
|
|
InfoFrom(func), blockWidth);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (height % blockHeight != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: height of level 0 must be multipel of %d",
|
|
|
|
|
InfoFrom(func), blockHeight);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-25 14:07:17 -08:00
|
|
|
|
}
|
2014-02-26 16:32:17 -08:00
|
|
|
|
else if (level > 0) {
|
|
|
|
|
if (width % blockWidth != 0 && width > 2) {
|
|
|
|
|
ErrorInvalidOperation("%s: width of level %d must be multiple"
|
|
|
|
|
" of %d or 0, 1, 2",
|
|
|
|
|
InfoFrom(func), level, blockWidth);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-25 14:07:17 -08:00
|
|
|
|
|
2014-02-26 16:32:17 -08:00
|
|
|
|
if (height % blockHeight != 0 && height > 2) {
|
|
|
|
|
ErrorInvalidOperation("%s: height of level %d must be multiple"
|
|
|
|
|
" of %d or 0, 1, 2",
|
|
|
|
|
InfoFrom(func), level, blockHeight);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsSubFunc(func)) {
|
|
|
|
|
if ((xoffset % blockWidth) != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: xoffset must be multiple of %d",
|
|
|
|
|
InfoFrom(func), blockWidth);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (yoffset % blockHeight != 0) {
|
|
|
|
|
ErrorInvalidOperation("%s: yoffset must be multiple of %d",
|
|
|
|
|
InfoFrom(func), blockHeight);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-20 17:20:28 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
|
if (!is_pot_assuming_nonnegative(width) ||
|
|
|
|
|
!is_pot_assuming_nonnegative(height))
|
|
|
|
|
{
|
|
|
|
|
ErrorInvalidValue("%s: width and height must be powers of two",
|
|
|
|
|
InfoFrom(func));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the enough data is present to satisfy compressed
|
|
|
|
|
* texture format constraints.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateCompTexImageDataSize(GLint level, GLenum format,
|
|
|
|
|
GLsizei width, GLsizei height,
|
|
|
|
|
uint32_t byteLength, WebGLTexImageFunc func)
|
|
|
|
|
{
|
2012-09-25 05:49:28 -07:00
|
|
|
|
// negative width and height must already have been handled above
|
|
|
|
|
MOZ_ASSERT(width >= 0 && height >= 0);
|
|
|
|
|
|
2012-09-25 05:49:28 -07:00
|
|
|
|
CheckedUint32 required_byteLength = 0;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
2012-09-25 05:49:28 -07:00
|
|
|
|
case LOCAL_GL_ATC_RGB:
|
2014-03-10 15:42:58 -07:00
|
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
2012-05-08 10:29:31 -07:00
|
|
|
|
{
|
2012-09-25 05:49:28 -07:00
|
|
|
|
required_byteLength = ((CheckedUint32(width) + 3) / 4) * ((CheckedUint32(height) + 3) / 4) * 8;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
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_RGBA_EXPLICIT_ALPHA:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
2012-05-08 10:29:31 -07:00
|
|
|
|
{
|
2012-09-25 05:49:28 -07:00
|
|
|
|
required_byteLength = ((CheckedUint32(width) + 3) / 4) * ((CheckedUint32(height) + 3) / 4) * 16;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-09-25 05:49:28 -07:00
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
|
{
|
2013-01-15 04:22:03 -08:00
|
|
|
|
required_byteLength = CheckedUint32(std::max(width, 8)) * CheckedUint32(std::max(height, 8)) / 2;
|
2012-09-25 05:49:28 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
|
{
|
2013-01-15 04:22:03 -08:00
|
|
|
|
required_byteLength = CheckedUint32(std::max(width, 16)) * CheckedUint32(std::max(height, 8)) / 4;
|
2012-09-25 05:49:28 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-25 05:49:28 -07:00
|
|
|
|
if (!required_byteLength.isValid() || required_byteLength.value() != byteLength) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
ErrorInvalidValue("%s: data size does not match dimensions", InfoFrom(func));
|
2012-09-25 05:49:28 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validate the width, height, and depth of a texture image, \return
|
|
|
|
|
* true is valid, false otherwise.
|
|
|
|
|
* Used by all the (Compressed|Copy)?Tex(Sub)?Image functions.
|
|
|
|
|
* Target and level must have been validated before calling.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImageSize(GLenum target, GLint level,
|
|
|
|
|
GLint width, GLint height, GLint depth,
|
|
|
|
|
WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(level >= 0, "level should already be validated");
|
|
|
|
|
|
2014-04-15 18:23:41 -07:00
|
|
|
|
/* Bug 966630: maxTextureSize >> level runs into "undefined"
|
|
|
|
|
* behaviour depending on ISA. For example, on Intel shifts
|
|
|
|
|
* amounts are mod 64 (in 64-bit mode on 64-bit dest) and mod 32
|
|
|
|
|
* otherwise. This means 16384 >> 0x10000001 == 8192 which isn't
|
|
|
|
|
* what would be expected. Make the required behaviour explicit by
|
|
|
|
|
* clamping to a shift of 31 bits if level is greater than that
|
|
|
|
|
* ammount. This will give 0 that if (!maxAllowedSize) is
|
|
|
|
|
* expecting.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (level > 31)
|
|
|
|
|
level = 31;
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
const GLuint maxTexImageSize = MaxTextureSizeForTarget(target) >> level;
|
|
|
|
|
const bool isCubemapTarget = IsTexImageCubemapTarget(target);
|
2014-04-21 21:09:33 -07:00
|
|
|
|
const bool isSub = IsSubFunc(func);
|
2014-02-20 17:20:28 -08:00
|
|
|
|
|
2014-04-21 21:09:33 -07:00
|
|
|
|
if (!isSub && isCubemapTarget && (width != height)) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
|
* "When the target parameter to TexImage2D is one of the
|
|
|
|
|
* six cube map two-dimensional image targets, the error
|
|
|
|
|
* INVALID_VALUE is generated if the width and height
|
|
|
|
|
* parameters are not equal."
|
|
|
|
|
*/
|
|
|
|
|
ErrorInvalidValue("%s: for cube map, width must equal height", InfoFrom(func));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target == LOCAL_GL_TEXTURE_2D || isCubemapTarget)
|
|
|
|
|
{
|
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
|
* "If wt and ht are the specified image width and height,
|
|
|
|
|
* and if either wt or ht are less than zero, then the error
|
|
|
|
|
* INVALID_VALUE is generated."
|
|
|
|
|
*/
|
|
|
|
|
if (width < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: width must be >= 0", InfoFrom(func));
|
2012-09-25 05:49:28 -07:00
|
|
|
|
return false;
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
2014-02-20 17:20:28 -08:00
|
|
|
|
|
|
|
|
|
if (height < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: height must be >= 0", InfoFrom(func));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
|
* "The maximum allowable width and height of a
|
|
|
|
|
* two-dimensional texture image must be at least 2**(k−lod)
|
|
|
|
|
* for image arrays of level zero through k, where k is the
|
|
|
|
|
* log base 2 of MAX_TEXTURE_SIZE. and lod is the
|
|
|
|
|
* level-of-detail of the image array. It may be zero for
|
|
|
|
|
* image arrays of any level-of-detail greater than k. The
|
|
|
|
|
* error INVALID_VALUE is generated if the specified image
|
|
|
|
|
* is too large to be stored under any conditions.
|
|
|
|
|
*/
|
|
|
|
|
if (width > (int) maxTexImageSize) {
|
|
|
|
|
ErrorInvalidValue("%s: the maximum width for level %d is %u",
|
|
|
|
|
InfoFrom(func), level, maxTexImageSize);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (height > (int) maxTexImageSize) {
|
|
|
|
|
ErrorInvalidValue("%s: tex maximum height for level %d is %u",
|
|
|
|
|
InfoFrom(func), level, maxTexImageSize);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
|
* "If level is greater than zero, and either width or
|
|
|
|
|
* height is not a power-of-two, the error INVALID_VALUE is
|
|
|
|
|
* generated."
|
|
|
|
|
*/
|
|
|
|
|
if (level > 0) {
|
|
|
|
|
if (!is_pot_assuming_nonnegative(width)) {
|
|
|
|
|
ErrorInvalidValue("%s: level >= 0, width of %d must be a power of two.",
|
|
|
|
|
InfoFrom(func), width);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_pot_assuming_nonnegative(height)) {
|
|
|
|
|
ErrorInvalidValue("%s: level >= 0, height of %d must be a power of two.",
|
|
|
|
|
InfoFrom(func), height);
|
2012-09-25 05:49:28 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
// TODO: WebGL 2
|
|
|
|
|
if (target == LOCAL_GL_TEXTURE_3D) {
|
|
|
|
|
if (depth < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: depth must be >= 0", InfoFrom(func));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-05-08 10:29:31 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!is_pot_assuming_nonnegative(depth)) {
|
|
|
|
|
ErrorInvalidValue("%s: level >= 0, depth of %d must be a power of two.",
|
|
|
|
|
InfoFrom(func), depth);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-05-08 10:29:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-10-09 11:21:22 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Validate texture image sizing for Tex(Sub)?Image variants.
|
|
|
|
|
*/
|
|
|
|
|
// TODO: WebGL 2. Update this to handle 3D textures.
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexSubImageSize(GLint xoffset, GLint yoffset, GLint /*zoffset*/,
|
|
|
|
|
GLsizei width, GLsizei height, GLsizei /*depth*/,
|
|
|
|
|
GLsizei baseWidth, GLsizei baseHeight, GLsizei /*baseDepth*/,
|
|
|
|
|
WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
/* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
|
|
|
|
|
* "Taking wt and ht to be the specified width and height of the
|
|
|
|
|
* texture array, and taking x, y, w, and h to be the xoffset,
|
|
|
|
|
* yoffset, width, and height argument values, any of the
|
|
|
|
|
* following relationships generates the error INVALID_VALUE:
|
|
|
|
|
* x < 0
|
|
|
|
|
* x + w > wt
|
|
|
|
|
* y < 0
|
|
|
|
|
* y + h > ht"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (xoffset < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: xoffset must be >= 0", InfoFrom(func));
|
2012-05-08 10:29:31 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (yoffset < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: yoffset must be >= 0", InfoFrom(func));
|
2012-05-08 10:29:31 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!CanvasUtils::CheckSaneSubrectSize(xoffset, yoffset, width, height, baseWidth, baseHeight)) {
|
|
|
|
|
ErrorInvalidValue("%s: subtexture rectangle out-of-bounds", InfoFrom(func));
|
2012-05-08 10:29:31 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return the bits per texel for format & type combination.
|
|
|
|
|
* Assumes that format & type are a valid combination as checked with
|
|
|
|
|
* ValidateTexImageFormatAndType().
|
|
|
|
|
*/
|
|
|
|
|
uint32_t
|
|
|
|
|
WebGLContext::GetBitsPerTexel(GLenum format, GLenum type)
|
2011-07-07 17:01:12 -07:00
|
|
|
|
{
|
2012-06-27 16:11:00 -07:00
|
|
|
|
// If there is no defined format or type, we're not taking up any memory
|
|
|
|
|
if (!format || !type) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Known fixed-sized types */
|
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
|
2011-07-07 17:01:12 -07:00
|
|
|
|
{
|
2012-05-08 10:29:31 -07:00
|
|
|
|
return 16;
|
2011-07-07 17:01:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_INT_24_8)
|
|
|
|
|
return 32;
|
|
|
|
|
|
|
|
|
|
int bitsPerComponent = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
|
bitsPerComponent = 8;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT:
|
|
|
|
|
bitsPerComponent = 16;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
|
bitsPerComponent = 32;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
MOZ_ASSERT(false, "Unhandled type.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
// Uncompressed formats
|
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
|
return 1 * bitsPerComponent;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
|
return 2 * bitsPerComponent;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
|
case LOCAL_GL_RGB32F:
|
|
|
|
|
case LOCAL_GL_SRGB_EXT:
|
|
|
|
|
return 3 * bitsPerComponent;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
|
case LOCAL_GL_RGBA32F:
|
|
|
|
|
case LOCAL_GL_SRGB_ALPHA_EXT:
|
|
|
|
|
return 4 * bitsPerComponent;
|
|
|
|
|
|
|
|
|
|
// Compressed formats
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
|
case LOCAL_GL_ATC_RGB:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
2014-03-10 15:42:58 -07:00
|
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 05:08:37 -08:00
|
|
|
|
MOZ_ASSERT(false, "Unhandled format+type combo.");
|
2011-07-07 17:01:12 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Perform validation of format/type combinations for TexImage variants.
|
|
|
|
|
* Returns true if the format/type is a valid combination, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImageFormatAndType(GLenum format, GLenum type, WebGLTexImageFunc func)
|
2010-06-30 08:49:59 -07:00
|
|
|
|
{
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!ValidateTexImageFormat(format, func) ||
|
|
|
|
|
!ValidateTexImageType(type, func))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
bool validCombo = false;
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
switch (format) {
|
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_BYTE ||
|
|
|
|
|
type == LOCAL_GL_HALF_FLOAT ||
|
2014-03-13 01:48:50 -07:00
|
|
|
|
type == LOCAL_GL_HALF_FLOAT_OES ||
|
2014-02-20 17:20:28 -08:00
|
|
|
|
type == LOCAL_GL_FLOAT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
|
case LOCAL_GL_SRGB:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_BYTE ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_6_5 ||
|
|
|
|
|
type == LOCAL_GL_HALF_FLOAT ||
|
2014-03-13 01:48:50 -07:00
|
|
|
|
type == LOCAL_GL_HALF_FLOAT_OES ||
|
2014-02-20 17:20:28 -08:00
|
|
|
|
type == LOCAL_GL_FLOAT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
|
case LOCAL_GL_SRGB_ALPHA:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_BYTE ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 ||
|
|
|
|
|
type == LOCAL_GL_HALF_FLOAT ||
|
2014-03-13 01:48:50 -07:00
|
|
|
|
type == LOCAL_GL_HALF_FLOAT_OES ||
|
2014-02-20 17:20:28 -08:00
|
|
|
|
type == LOCAL_GL_FLOAT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_SHORT ||
|
|
|
|
|
type == LOCAL_GL_UNSIGNED_INT);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_INT_24_8);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-26 16:32:17 -08:00
|
|
|
|
case LOCAL_GL_ATC_RGB:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
|
|
|
|
|
case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
|
2014-03-10 15:42:58 -07:00
|
|
|
|
case LOCAL_GL_ETC1_RGB8_OES:
|
2014-02-26 16:32:17 -08:00
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
|
|
|
|
|
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:
|
|
|
|
|
validCombo = (type == LOCAL_GL_UNSIGNED_BYTE);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
default:
|
|
|
|
|
// Only valid formats should be passed to the switch stmt.
|
2014-02-26 16:32:17 -08:00
|
|
|
|
MOZ_ASSERT(false, "Unexpected format and type combo. How'd this happen?");
|
|
|
|
|
validCombo = false;
|
|
|
|
|
// Fall through to return an InvalidOperations. This will alert us to the
|
|
|
|
|
// unexpected case that needs fixing in builds without asserts.
|
2014-02-20 17:20:28 -08:00
|
|
|
|
}
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validCombo)
|
|
|
|
|
ErrorInvalidOperation("%s: invalid combination of format %s and type %s",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
InfoFrom(func), WebGLContext::EnumName(format), WebGLContext::EnumName(type));
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validCombo;
|
|
|
|
|
}
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Return true if format, type and jsArrayType are a valid combination.
|
|
|
|
|
* Also returns the size for texel of format and type (in bytes) via
|
|
|
|
|
* \a texelSize.
|
|
|
|
|
*
|
|
|
|
|
* It is assumed that type has previously been validated.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexInputData(GLenum type, int jsArrayType, WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
bool validInput = false;
|
2014-01-23 13:47:37 -08:00
|
|
|
|
const char invalidTypedArray[] = "%s: invalid typed array type for given texture data type";
|
2012-08-13 18:17:55 -07:00
|
|
|
|
|
2014-01-23 13:47:37 -08:00
|
|
|
|
// First, we check for packed types
|
2011-05-20 12:53:53 -07:00
|
|
|
|
switch (type) {
|
2014-02-20 17:20:28 -08:00
|
|
|
|
case LOCAL_GL_UNSIGNED_BYTE:
|
|
|
|
|
validInput = (jsArrayType == -1 || jsArrayType == js::ArrayBufferView::TYPE_UINT8);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-03-13 01:48:50 -07:00
|
|
|
|
case LOCAL_GL_HALF_FLOAT:
|
|
|
|
|
case LOCAL_GL_HALF_FLOAT_OES:
|
2014-02-20 17:20:28 -08:00
|
|
|
|
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:
|
|
|
|
|
validInput = (jsArrayType == -1 || jsArrayType == js::ArrayBufferView::TYPE_UINT16);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT_24_8:
|
|
|
|
|
validInput = (jsArrayType == -1 || jsArrayType == js::ArrayBufferView::TYPE_UINT32);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
|
validInput = (jsArrayType == -1 || jsArrayType == js::ArrayBufferView::TYPE_FLOAT32);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
if (!validInput)
|
|
|
|
|
ErrorInvalidOperation(invalidTypedArray, InfoFrom(func));
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return validInput;
|
|
|
|
|
}
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/**
|
|
|
|
|
* Test the gl(Copy|Compressed)?Tex[Sub]?Image[23]() parameters for errors.
|
|
|
|
|
* Verifies each of the parameters against the WebGL standard and enabled extensions.
|
|
|
|
|
*/
|
|
|
|
|
// TODO: Texture dims is here for future expansion in WebGL 2.0
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateTexImage(GLuint dims, GLenum target,
|
|
|
|
|
GLint level, GLint internalFormat,
|
|
|
|
|
GLint xoffset, GLint yoffset, GLint zoffset,
|
|
|
|
|
GLint width, GLint height, GLint depth,
|
|
|
|
|
GLint border, GLenum format, GLenum type,
|
|
|
|
|
WebGLTexImageFunc func)
|
|
|
|
|
{
|
|
|
|
|
const char* info = InfoFrom(func);
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Check target */
|
|
|
|
|
if (!ValidateTexImageTarget(dims, target, func))
|
|
|
|
|
return false;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Check level */
|
|
|
|
|
if (level < 0) {
|
|
|
|
|
ErrorInvalidValue("%s: level must be >= 0", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-23 13:47:37 -08:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Check border */
|
|
|
|
|
if (border != 0) {
|
|
|
|
|
ErrorInvalidValue("%s: border must be 0", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check incoming image format and type */
|
|
|
|
|
if (!ValidateTexImageFormatAndType(format, type, func))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* WebGL and OpenGL ES 2.0 impose additional restrictions on the
|
|
|
|
|
* combinations of format, internalFormat, and type that can be
|
|
|
|
|
* used. Formats and types that require additional extensions
|
|
|
|
|
* (e.g., GL_FLOAT requires GL_OES_texture_float) are filtered
|
|
|
|
|
* elsewhere.
|
|
|
|
|
*/
|
|
|
|
|
if ((GLint) format != internalFormat) {
|
|
|
|
|
ErrorInvalidOperation("%s: format does not match internalformat", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check internalFormat */
|
|
|
|
|
// TODO: Not sure if this is a bit of over kill.
|
|
|
|
|
if (BaseTexFormat(internalFormat) == LOCAL_GL_NONE) {
|
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
|
ErrorInvalidValue("%s:", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-23 13:47:37 -08:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Check texture image size */
|
|
|
|
|
if (!ValidateTexImageSize(target, level, width, height, 0, func))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* 5.14.8 Texture objects - WebGL Spec.
|
|
|
|
|
* "If an attempt is made to call these functions with no
|
|
|
|
|
* WebGLTexture bound (see above), an INVALID_OPERATION error
|
|
|
|
|
* is generated."
|
|
|
|
|
*/
|
|
|
|
|
WebGLTexture* tex = activeBoundTextureForTarget(target);
|
|
|
|
|
if (!tex) {
|
|
|
|
|
ErrorInvalidOperation("%s: no texture is bound to target %s",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
info, WebGLContext::EnumName(target));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsSubFunc(func)) {
|
|
|
|
|
if (!tex->HasImageInfoAt(target, level)) {
|
|
|
|
|
ErrorInvalidOperation("%s: no texture image previously defined for target %s at level %d",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
info, WebGLContext::EnumName(target), level);
|
2014-01-23 13:47:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
const WebGLTexture::ImageInfo& imageInfo = tex->ImageInfoAt(target, level);
|
|
|
|
|
if (!ValidateTexSubImageSize(xoffset, yoffset, zoffset,
|
|
|
|
|
width, height, depth,
|
|
|
|
|
imageInfo.Width(), imageInfo.Height(), 0,
|
|
|
|
|
func))
|
|
|
|
|
{
|
2014-01-23 13:47:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Require the format and type to match that of the existing
|
|
|
|
|
* texture as created
|
|
|
|
|
*/
|
2014-05-01 20:15:58 -07:00
|
|
|
|
if (imageInfo.WebGLFormat() != format ||
|
|
|
|
|
imageInfo.WebGLType() != type)
|
2014-01-23 13:47:37 -08:00
|
|
|
|
{
|
2014-02-20 17:20:28 -08:00
|
|
|
|
ErrorInvalidOperation("%s: format or type doesn't match the existing texture",
|
|
|
|
|
info);
|
2014-01-23 13:47:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-20 17:20:28 -08:00
|
|
|
|
}
|
2014-01-23 13:47:37 -08:00
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Additional checks for depth textures */
|
|
|
|
|
if (target != LOCAL_GL_TEXTURE_2D &&
|
|
|
|
|
(format == LOCAL_GL_DEPTH_COMPONENT ||
|
|
|
|
|
format == LOCAL_GL_DEPTH_STENCIL))
|
|
|
|
|
{
|
|
|
|
|
ErrorInvalidOperation("%s: with format of %s target must be TEXTURE_2D",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
info, WebGLContext::EnumName(format));
|
2014-01-23 13:47:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Additional checks for compressed textures */
|
|
|
|
|
if (!IsAllowedFromSource(format, func)) {
|
|
|
|
|
ErrorInvalidOperation("%s: Invalid format %s for this operation",
|
2014-06-02 13:30:00 -07:00
|
|
|
|
info, WebGLContext::EnumName(format));
|
2014-02-20 17:20:28 -08:00
|
|
|
|
return false;
|
2014-01-23 13:47:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 17:20:28 -08:00
|
|
|
|
/* Parameters are OK */
|
|
|
|
|
return true;
|
2010-06-30 08:49:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateUniformLocation(const char* info, WebGLUniformLocation *location_object)
|
|
|
|
|
{
|
|
|
|
|
if (!ValidateObjectAllowNull(info, location_object))
|
|
|
|
|
return false;
|
|
|
|
|
if (!location_object)
|
|
|
|
|
return false;
|
|
|
|
|
/* the need to check specifically for !mCurrentProgram here is explained in bug 657556 */
|
|
|
|
|
if (!mCurrentProgram) {
|
|
|
|
|
ErrorInvalidOperation("%s: no program is currently bound", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (mCurrentProgram != location_object->Program()) {
|
|
|
|
|
ErrorInvalidOperation("%s: this uniform location doesn't correspond to the current program", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (mCurrentProgram->Generation() != location_object->ProgramGeneration()) {
|
|
|
|
|
ErrorInvalidOperation("%s: This uniform location is obsolete since the program has been relinked", info);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 16:44:31 -08:00
|
|
|
|
bool
|
2013-09-04 05:14:43 -07:00
|
|
|
|
WebGLContext::ValidateSamplerUniformSetter(const char* info, WebGLUniformLocation *location, GLint value)
|
2013-03-04 16:44:31 -08:00
|
|
|
|
{
|
|
|
|
|
if (location->Info().type != SH_SAMPLER_2D &&
|
|
|
|
|
location->Info().type != SH_SAMPLER_CUBE)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value >= 0 && value < mGLMaxTextureUnits)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
ErrorInvalidValue("%s: this uniform location is a sampler, but %d is not a valid texture unit",
|
|
|
|
|
info, value);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 05:17:01 -07:00
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateAttribArraySetter(const char* name, uint32_t cnt, uint32_t arrayLength)
|
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
|
if (IsContextLost()) {
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (arrayLength < cnt) {
|
|
|
|
|
ErrorInvalidOperation("%s: array must be >= %d elements", name, cnt);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateUniformArraySetter(const char* name, uint32_t expectedElemSize, WebGLUniformLocation *location_object,
|
|
|
|
|
GLint& location, uint32_t& numElementsToUpload, uint32_t arrayLength)
|
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
|
if (IsContextLost())
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
2013-01-25 10:40:38 -08:00
|
|
|
|
if (!ValidateUniformLocation(name, location_object))
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
|
|
|
|
location = location_object->Location();
|
|
|
|
|
uint32_t uniformElemSize = location_object->ElementSize();
|
|
|
|
|
if (expectedElemSize != uniformElemSize) {
|
|
|
|
|
ErrorInvalidOperation("%s: this function expected a uniform of element size %d,"
|
|
|
|
|
" got a uniform of element size %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
uniformElemSize);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (arrayLength == 0 ||
|
|
|
|
|
arrayLength % expectedElemSize)
|
|
|
|
|
{
|
|
|
|
|
ErrorInvalidValue("%s: expected an array of length a multiple"
|
|
|
|
|
" of %d, got an array of length %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
arrayLength);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-25 10:40:38 -08:00
|
|
|
|
const WebGLUniformInfo& info = location_object->Info();
|
2012-10-16 05:17:01 -07:00
|
|
|
|
if (!info.isArray &&
|
|
|
|
|
arrayLength != expectedElemSize) {
|
|
|
|
|
ErrorInvalidOperation("%s: expected an array of length exactly"
|
|
|
|
|
" %d (since this uniform is not an array"
|
|
|
|
|
" uniform), got an array of length %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
arrayLength);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
numElementsToUpload =
|
2013-01-15 04:22:03 -08:00
|
|
|
|
std::min(info.arraySize, arrayLength / expectedElemSize);
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateUniformMatrixArraySetter(const char* name, int dim, WebGLUniformLocation *location_object,
|
|
|
|
|
GLint& location, uint32_t& numElementsToUpload, uint32_t arrayLength,
|
|
|
|
|
WebGLboolean aTranspose)
|
|
|
|
|
{
|
|
|
|
|
uint32_t expectedElemSize = (dim)*(dim);
|
2013-09-04 05:14:44 -07:00
|
|
|
|
if (IsContextLost())
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
2013-01-25 10:40:38 -08:00
|
|
|
|
if (!ValidateUniformLocation(name, location_object))
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
|
|
|
|
location = location_object->Location();
|
|
|
|
|
uint32_t uniformElemSize = location_object->ElementSize();
|
|
|
|
|
if (expectedElemSize != uniformElemSize) {
|
|
|
|
|
ErrorInvalidOperation("%s: this function expected a uniform of element size %d,"
|
|
|
|
|
" got a uniform of element size %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
uniformElemSize);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (arrayLength == 0 ||
|
|
|
|
|
arrayLength % expectedElemSize)
|
|
|
|
|
{
|
|
|
|
|
ErrorInvalidValue("%s: expected an array of length a multiple"
|
|
|
|
|
" of %d, got an array of length %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
arrayLength);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-01-25 10:40:38 -08:00
|
|
|
|
const WebGLUniformInfo& info = location_object->Info();
|
2012-10-16 05:17:01 -07:00
|
|
|
|
if (!info.isArray &&
|
|
|
|
|
arrayLength != expectedElemSize) {
|
|
|
|
|
ErrorInvalidOperation("%s: expected an array of length exactly"
|
|
|
|
|
" %d (since this uniform is not an array"
|
|
|
|
|
" uniform), got an array of length %d", name,
|
|
|
|
|
expectedElemSize,
|
|
|
|
|
arrayLength);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (aTranspose) {
|
|
|
|
|
ErrorInvalidValue("%s: transpose must be FALSE as per the "
|
|
|
|
|
"OpenGL ES 2.0 spec", name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
numElementsToUpload =
|
2013-01-15 04:22:03 -08:00
|
|
|
|
std::min(info.arraySize, arrayLength / (expectedElemSize));
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
WebGLContext::ValidateUniformSetter(const char* name, WebGLUniformLocation *location_object, GLint& location)
|
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
|
if (IsContextLost())
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
2013-01-25 10:40:38 -08:00
|
|
|
|
if (!ValidateUniformLocation(name, location_object))
|
2012-10-16 05:17:01 -07:00
|
|
|
|
return false;
|
|
|
|
|
location = location_object->Location();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 05:14:43 -07:00
|
|
|
|
bool WebGLContext::ValidateAttribIndex(GLuint index, const char *info)
|
2011-02-24 14:17:34 -08:00
|
|
|
|
{
|
2013-10-11 06:16:44 -07:00
|
|
|
|
return mBoundVertexArray->EnsureAttrib(index, info);
|
2011-02-24 14:17:34 -08:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool WebGLContext::ValidateStencilParamsForDrawCall()
|
2011-05-20 12:53:53 -07:00
|
|
|
|
{
|
|
|
|
|
const char *msg = "%s set different front and back stencil %s. Drawing in this configuration is not allowed.";
|
|
|
|
|
if (mStencilRefFront != mStencilRefBack) {
|
|
|
|
|
ErrorInvalidOperation(msg, "stencilFuncSeparate", "reference values");
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
}
|
|
|
|
|
if (mStencilValueMaskFront != mStencilValueMaskBack) {
|
|
|
|
|
ErrorInvalidOperation(msg, "stencilFuncSeparate", "value masks");
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
}
|
|
|
|
|
if (mStencilWriteMaskFront != mStencilWriteMaskBack) {
|
|
|
|
|
ErrorInvalidOperation(msg, "stencilMaskSeparate", "write masks");
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2011-05-20 12:53:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 08:07:04 -07:00
|
|
|
|
static inline int32_t floorPOT(int32_t x)
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(x > 0);
|
|
|
|
|
int32_t pot = 1;
|
|
|
|
|
while (pot < 0x40000000) {
|
|
|
|
|
if (x < pot*2)
|
|
|
|
|
break;
|
|
|
|
|
pot *= 2;
|
|
|
|
|
}
|
|
|
|
|
return pot;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool
|
2010-06-14 11:44:12 -07:00
|
|
|
|
WebGLContext::InitAndValidateGL()
|
2010-06-10 10:45:00 -07:00
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
|
if (!gl) return false;
|
2010-06-14 11:44:12 -07:00
|
|
|
|
|
2011-02-11 15:11:30 -08:00
|
|
|
|
GLenum error = gl->fGetError();
|
|
|
|
|
if (error != LOCAL_GL_NO_ERROR) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL error 0x%x occurred during OpenGL context initialization, before WebGL initialization!", error);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2011-02-11 15:11:30 -08:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 05:09:22 -07:00
|
|
|
|
mMinCapability = Preferences::GetBool("webgl.min_capability_mode", false);
|
|
|
|
|
mDisableExtensions = Preferences::GetBool("webgl.disable-extensions", false);
|
2012-12-07 18:00:42 -08:00
|
|
|
|
mLoseContextOnHeapMinimize = Preferences::GetBool("webgl.lose-context-on-heap-minimize", false);
|
2013-01-03 15:39:25 -08:00
|
|
|
|
mCanLoseContextInForeground = Preferences::GetBool("webgl.can-lose-context-in-foreground", true);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
|
2013-05-15 14:50:52 -07:00
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
|
mDisableFragHighP = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-17 13:15:41 -07:00
|
|
|
|
// These are the default values, see 6.2 State tables in the
|
|
|
|
|
// OpenGL ES 2.0.25 spec.
|
|
|
|
|
mColorWriteMask[0] = 1;
|
|
|
|
|
mColorWriteMask[1] = 1;
|
|
|
|
|
mColorWriteMask[2] = 1;
|
|
|
|
|
mColorWriteMask[3] = 1;
|
|
|
|
|
mDepthWriteMask = 1;
|
|
|
|
|
mColorClearValue[0] = 0.f;
|
|
|
|
|
mColorClearValue[1] = 0.f;
|
|
|
|
|
mColorClearValue[2] = 0.f;
|
|
|
|
|
mColorClearValue[3] = 0.f;
|
|
|
|
|
mDepthClearValue = 1.f;
|
|
|
|
|
mStencilClearValue = 0;
|
|
|
|
|
mStencilRefFront = 0;
|
|
|
|
|
mStencilRefBack = 0;
|
2014-05-21 19:03:09 -07:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Technically, we should be setting mStencil[...] values to
|
|
|
|
|
// `allOnes`, but either ANGLE breaks or the SGX540s on Try break.
|
|
|
|
|
GLuint stencilBits = 0;
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_BITS, &stencilBits);
|
|
|
|
|
GLuint allOnes = ~(UINT32_MAX << stencilBits);
|
|
|
|
|
mStencilValueMaskFront = allOnes;
|
|
|
|
|
mStencilValueMaskBack = allOnes;
|
|
|
|
|
mStencilWriteMaskFront = allOnes;
|
|
|
|
|
mStencilWriteMaskBack = allOnes;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_VALUE_MASK, &mStencilValueMaskFront);
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_BACK_VALUE_MASK, &mStencilValueMaskBack);
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_WRITEMASK, &mStencilWriteMaskFront);
|
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_STENCIL_BACK_WRITEMASK, &mStencilWriteMaskBack);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
mDitherEnabled = true;
|
|
|
|
|
mRasterizerDiscardEnabled = false;
|
|
|
|
|
mScissorTestEnabled = false;
|
2014-04-17 13:15:41 -07:00
|
|
|
|
|
|
|
|
|
// Bindings, etc.
|
2010-06-14 11:44:12 -07:00
|
|
|
|
mActiveTexture = 0;
|
2014-03-07 13:16:34 -08:00
|
|
|
|
mEmitContextLostErrorOnce = true;
|
2011-07-07 17:01:16 -07:00
|
|
|
|
mWebGLError = LOCAL_GL_NO_ERROR;
|
2014-03-07 13:16:34 -08:00
|
|
|
|
mUnderlyingGLError = LOCAL_GL_NO_ERROR;
|
2010-06-14 11:44:12 -07:00
|
|
|
|
|
|
|
|
|
mBound2DTextures.Clear();
|
|
|
|
|
mBoundCubeMapTextures.Clear();
|
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
|
mBoundArrayBuffer = nullptr;
|
2013-08-20 08:36:20 -07:00
|
|
|
|
mBoundTransformFeedbackBuffer = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
|
mCurrentProgram = nullptr;
|
2010-06-14 11:44:12 -07:00
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
|
mBoundFramebuffer = nullptr;
|
|
|
|
|
mBoundRenderbuffer = nullptr;
|
2010-06-14 11:44:12 -07:00
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
|
MakeContextCurrent();
|
2010-06-10 10:45:00 -07:00
|
|
|
|
|
2010-09-02 07:34:08 -07:00
|
|
|
|
// on desktop OpenGL, we always keep vertex attrib 0 array enabled
|
2014-03-31 02:10:49 -07:00
|
|
|
|
if (!gl->IsGLES()) {
|
2010-09-02 07:34:08 -07:00
|
|
|
|
gl->fEnableVertexAttribArray(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-13 05:09:22 -07:00
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
|
mGLMaxVertexAttribs = MINVALUE_GL_MAX_VERTEX_ATTRIBS;
|
|
|
|
|
} else {
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &mGLMaxVertexAttribs);
|
|
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
if (mGLMaxVertexAttribs < 8) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL_MAX_VERTEX_ATTRIBS: %d is < 8!", mGLMaxVertexAttribs);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
return false;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note: GL_MAX_TEXTURE_UNITS is fixed at 4 for most desktop hardware,
|
|
|
|
|
// even though the hardware supports much more. The
|
2010-07-14 20:52:34 -07:00
|
|
|
|
// GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value is the accurate value.
|
2011-10-13 05:09:22 -07:00
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
|
mGLMaxTextureUnits = MINVALUE_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS;
|
|
|
|
|
} else {
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGLMaxTextureUnits);
|
|
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
if (mGLMaxTextureUnits < 8) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!", mGLMaxTextureUnits);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
return false;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
|
mBound2DTextures.SetLength(mGLMaxTextureUnits);
|
|
|
|
|
mBoundCubeMapTextures.SetLength(mGLMaxTextureUnits);
|
|
|
|
|
|
2011-10-13 05:09:22 -07:00
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
|
mGLMaxTextureSize = MINVALUE_GL_MAX_TEXTURE_SIZE;
|
|
|
|
|
mGLMaxCubeMapTextureSize = MINVALUE_GL_MAX_CUBE_MAP_TEXTURE_SIZE;
|
2012-12-11 13:57:30 -08:00
|
|
|
|
mGLMaxRenderbufferSize = MINVALUE_GL_MAX_RENDERBUFFER_SIZE;
|
2011-10-13 05:09:22 -07:00
|
|
|
|
mGLMaxTextureImageUnits = MINVALUE_GL_MAX_TEXTURE_IMAGE_UNITS;
|
|
|
|
|
mGLMaxVertexTextureImageUnits = MINVALUE_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS;
|
|
|
|
|
} else {
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mGLMaxTextureSize);
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mGLMaxCubeMapTextureSize);
|
2012-12-11 13:57:30 -08:00
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mGLMaxRenderbufferSize);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, &mGLMaxTextureImageUnits);
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGLMaxVertexTextureImageUnits);
|
|
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
|
2013-07-30 08:07:04 -07:00
|
|
|
|
mGLMaxTextureSize = floorPOT(mGLMaxTextureSize);
|
|
|
|
|
mGLMaxRenderbufferSize = floorPOT(mGLMaxRenderbufferSize);
|
|
|
|
|
|
2011-10-13 05:09:22 -07:00
|
|
|
|
if (MinCapabilityMode()) {
|
|
|
|
|
mGLMaxFragmentUniformVectors = MINVALUE_GL_MAX_FRAGMENT_UNIFORM_VECTORS;
|
|
|
|
|
mGLMaxVertexUniformVectors = MINVALUE_GL_MAX_VERTEX_UNIFORM_VECTORS;
|
|
|
|
|
mGLMaxVaryingVectors = MINVALUE_GL_MAX_VARYING_VECTORS;
|
2010-07-28 14:24:09 -07:00
|
|
|
|
} else {
|
2013-08-22 10:42:05 -07:00
|
|
|
|
if (gl->IsSupported(gl::GLFeature::ES2_compatibility)) {
|
2011-10-13 05:09:22 -07:00
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGLMaxFragmentUniformVectors);
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS, &mGLMaxVertexUniformVectors);
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VARYING_VECTORS, &mGLMaxVaryingVectors);
|
|
|
|
|
} else {
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &mGLMaxFragmentUniformVectors);
|
|
|
|
|
mGLMaxFragmentUniformVectors /= 4;
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS, &mGLMaxVertexUniformVectors);
|
|
|
|
|
mGLMaxVertexUniformVectors /= 4;
|
|
|
|
|
|
|
|
|
|
// we are now going to try to read GL_MAX_VERTEX_OUTPUT_COMPONENTS and GL_MAX_FRAGMENT_INPUT_COMPONENTS,
|
|
|
|
|
// however these constants only entered the OpenGL standard at OpenGL 3.2. So we will try reading,
|
|
|
|
|
// and check OpenGL error for INVALID_ENUM.
|
|
|
|
|
|
|
|
|
|
// before we start, we check that no error already occurred, to prevent hiding it in our subsequent error handling
|
|
|
|
|
error = gl->GetAndClearError();
|
|
|
|
|
if (error != LOCAL_GL_NO_ERROR) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL error 0x%x occurred during WebGL context initialization!", error);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// On the public_webgl list, "problematic GetParameter pnames" thread, the following formula was given:
|
|
|
|
|
// mGLMaxVaryingVectors = min (GL_MAX_VERTEX_OUTPUT_COMPONENTS, GL_MAX_FRAGMENT_INPUT_COMPONENTS) / 4
|
|
|
|
|
GLint maxVertexOutputComponents,
|
|
|
|
|
minFragmentInputComponents;
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS, &maxVertexOutputComponents);
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS, &minFragmentInputComponents);
|
|
|
|
|
|
|
|
|
|
error = gl->GetAndClearError();
|
|
|
|
|
switch (error) {
|
|
|
|
|
case LOCAL_GL_NO_ERROR:
|
2013-01-15 04:22:03 -08:00
|
|
|
|
mGLMaxVaryingVectors = std::min(maxVertexOutputComponents, minFragmentInputComponents) / 4;
|
2011-10-13 05:09:22 -07:00
|
|
|
|
break;
|
|
|
|
|
case LOCAL_GL_INVALID_ENUM:
|
|
|
|
|
mGLMaxVaryingVectors = 16; // = 64/4, 64 is the min value for maxVertexOutputComponents in OpenGL 3.2 spec
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL error 0x%x occurred during WebGL context initialization!", error);
|
2011-10-13 05:09:22 -07:00
|
|
|
|
return false;
|
2013-08-20 08:36:20 -07:00
|
|
|
|
}
|
2011-02-11 15:11:30 -08:00
|
|
|
|
}
|
2010-07-28 14:24:09 -07:00
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
|
|
2010-07-28 14:24:09 -07:00
|
|
|
|
// Always 1 for GLES2
|
2011-06-27 10:27:04 -07:00
|
|
|
|
mMaxFramebufferColorAttachments = 1;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
|
2014-03-31 02:10:49 -07:00
|
|
|
|
if (!gl->IsGLES()) {
|
2010-07-28 14:24:09 -07:00
|
|
|
|
// gl_PointSize is always available in ES2 GLSL, but has to be
|
|
|
|
|
// specifically enabled on desktop GLSL.
|
|
|
|
|
gl->fEnable(LOCAL_GL_VERTEX_PROGRAM_POINT_SIZE);
|
2010-09-27 13:20:15 -07:00
|
|
|
|
|
2013-07-02 13:50:34 -07:00
|
|
|
|
// gl_PointCoord is always available in ES2 GLSL and in newer desktop GLSL versions, but apparently
|
|
|
|
|
// not in OpenGL 2 and apparently not (due to a driver bug) on certain NVIDIA setups. See:
|
|
|
|
|
// http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=261472
|
|
|
|
|
// Note that this used to cause crashes on old ATI drivers... hopefully not a significant
|
|
|
|
|
// problem anymore. See bug 602183.
|
|
|
|
|
gl->fEnable(LOCAL_GL_POINT_SPRITE);
|
2010-07-28 14:24:09 -07:00
|
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
|
2012-07-05 07:13:46 -07:00
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
if (gl->WorkAroundDriverBugs() &&
|
2014-01-10 10:55:23 -08:00
|
|
|
|
gl->Vendor() == gl::GLVendor::ATI) {
|
2012-07-05 07:13:46 -07:00
|
|
|
|
// The Mac ATI driver, in all known OSX version up to and including 10.8,
|
|
|
|
|
// renders points sprites upside-down. Apple bug 11778921
|
|
|
|
|
gl->fPointParameterf(LOCAL_GL_POINT_SPRITE_COORD_ORIGIN, LOCAL_GL_LOWER_LEFT);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-08-19 19:50:38 -07:00
|
|
|
|
// Check the shader validator pref
|
2011-10-17 07:59:28 -07:00
|
|
|
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), false);
|
2010-08-09 23:51:56 -07:00
|
|
|
|
|
2011-07-06 19:00:02 -07:00
|
|
|
|
mShaderValidation =
|
|
|
|
|
Preferences::GetBool("webgl.shader_validator", mShaderValidation);
|
2010-08-09 23:51:56 -07:00
|
|
|
|
|
2010-08-19 19:50:38 -07:00
|
|
|
|
// initialize shader translator
|
|
|
|
|
if (mShaderValidation) {
|
|
|
|
|
if (!ShInitialize()) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GLSL translator initialization failed!");
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-07-14 20:52:34 -07:00
|
|
|
|
}
|
2010-08-09 23:51:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 19:30:17 -07:00
|
|
|
|
// Mesa can only be detected with the GL_VERSION string, of the form "2.1 Mesa 7.11.0"
|
|
|
|
|
mIsMesa = strstr((const char *)(gl->fGetString(LOCAL_GL_VERSION)), "Mesa");
|
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
|
// notice that the point of calling GetAndClearError here is not only to check for error,
|
|
|
|
|
// it is also to reset the error flags so that a subsequent WebGL getError call will give the correct result.
|
|
|
|
|
error = gl->GetAndClearError();
|
2010-09-16 09:45:01 -07:00
|
|
|
|
if (error != LOCAL_GL_NO_ERROR) {
|
2012-05-23 09:07:29 -07:00
|
|
|
|
GenerateWarning("GL error 0x%x occurred during WebGL context initialization!", error);
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return false;
|
2010-09-16 09:45:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-17 09:13:38 -07:00
|
|
|
|
if (IsWebGL2() &&
|
2013-08-26 14:12:54 -07:00
|
|
|
|
!InitWebGL2())
|
2013-07-17 09:13:38 -07:00
|
|
|
|
{
|
2013-08-06 14:23:46 -07:00
|
|
|
|
// Todo: Bug 898404: Only allow WebGL2 on GL>=3.0 on desktop GL.
|
2013-07-17 09:13:38 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-21 13:48:22 -07:00
|
|
|
|
mMemoryPressureObserver
|
|
|
|
|
= new WebGLMemoryPressureObserver(this);
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService
|
|
|
|
|
= mozilla::services::GetObserverService();
|
|
|
|
|
if (observerService) {
|
|
|
|
|
observerService->AddObserver(mMemoryPressureObserver,
|
|
|
|
|
"memory-pressure",
|
|
|
|
|
false);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 16:38:27 -07:00
|
|
|
|
mDefaultVertexArray = WebGLVertexArray::Create(this);
|
2013-10-11 06:16:44 -07:00
|
|
|
|
mDefaultVertexArray->mAttribs.SetLength(mGLMaxVertexAttribs);
|
2013-06-27 14:07:21 -07:00
|
|
|
|
mBoundVertexArray = mDefaultVertexArray;
|
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
|
return true;
|
2010-06-10 10:45:00 -07:00
|
|
|
|
}
|