2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-09-17 23:01:12 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
|
|
|
* Mark Steele <mwsteele@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
|
2010-08-09 23:51:56 -07:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
#include "CheckedInt.h"
|
|
|
|
|
2010-08-09 23:51:56 -07:00
|
|
|
#if defined(USE_ANGLE)
|
2010-07-14 20:52:34 -07:00
|
|
|
#include "angle/ShaderLang.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
/*
|
|
|
|
* Pull all the data out of the program that will be used by validate later on
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
WebGLProgram::UpdateInfo(gl::GLContext *gl)
|
|
|
|
{
|
|
|
|
gl->fGetProgramiv(mName, LOCAL_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &mAttribMaxNameLength);
|
|
|
|
gl->fGetProgramiv(mName, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, &mUniformMaxNameLength);
|
|
|
|
gl->fGetProgramiv(mName, LOCAL_GL_ACTIVE_UNIFORMS, &mUniformCount);
|
|
|
|
gl->fGetProgramiv(mName, LOCAL_GL_ACTIVE_ATTRIBUTES, &mAttribCount);
|
|
|
|
|
|
|
|
GLint numVertexAttribs;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, &numVertexAttribs);
|
|
|
|
mAttribsInUse.clear();
|
|
|
|
mAttribsInUse.resize(numVertexAttribs);
|
|
|
|
|
|
|
|
nsAutoArrayPtr<char> nameBuf(new char[mAttribMaxNameLength]);
|
|
|
|
|
|
|
|
for (int i = 0; i < mAttribCount; ++i) {
|
|
|
|
GLint attrnamelen;
|
|
|
|
GLint attrsize;
|
|
|
|
GLenum attrtype;
|
|
|
|
gl->fGetActiveAttrib(mName, i, mAttribMaxNameLength, &attrnamelen, &attrsize, &attrtype, nameBuf);
|
|
|
|
if (attrnamelen > 0) {
|
|
|
|
GLint loc = gl->fGetAttribLocation(mName, nameBuf);
|
|
|
|
mAttribsInUse[loc] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
/*
|
|
|
|
* Verify that we can read count consecutive elements from each bound VBO.
|
|
|
|
*/
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
WebGLContext::ValidateBuffers(PRUint32 count)
|
|
|
|
{
|
2010-06-08 15:14:43 -07:00
|
|
|
NS_ENSURE_TRUE(count > 0, PR_TRUE);
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
GLuint currentProgram = 0;
|
2009-09-02 17:47:49 -07:00
|
|
|
MakeContextCurrent();
|
2010-06-10 10:45:00 -07:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_CURRENT_PROGRAM, (GLint*) ¤tProgram);
|
|
|
|
NS_ASSERTION(currentProgram == mCurrentProgram->GLName(),
|
|
|
|
"WebGL: current program doesn't agree with GL state");
|
|
|
|
if (currentProgram != mCurrentProgram->GLName())
|
2009-09-02 17:47:49 -07:00
|
|
|
return PR_FALSE;
|
2010-06-10 10:45:00 -07:00
|
|
|
#endif
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
PRUint32 attribs = mAttribBuffers.Length();
|
|
|
|
for (PRUint32 i = 0; i < attribs; ++i) {
|
|
|
|
const WebGLVertexAttribData& vd = mAttribBuffers[i];
|
2010-06-04 12:03:33 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
// If the attrib array isn't enabled, there's nothing to check;
|
|
|
|
// it's a static value.
|
|
|
|
if (!vd.enabled)
|
|
|
|
continue;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
if (vd.buf == nsnull) {
|
2010-09-13 08:40:01 -07:00
|
|
|
LogMessage(mVerbose, "No VBO bound to enabled attrib index %d!", i);
|
2010-06-10 10:45:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
// If the attrib is not in use, then we don't have to validate
|
|
|
|
// it, just need to make sure that the binding is non-null.
|
|
|
|
if (!mCurrentProgram->IsAttribInUse(i))
|
|
|
|
continue;
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
// compute the number of bytes we actually need
|
2010-07-03 15:32:19 -07:00
|
|
|
CheckedUint32 checked_needed = CheckedUint32(vd.byteOffset) + // the base offset
|
|
|
|
CheckedUint32(vd.actualStride()) * (count-1) + // to stride to the start of the last element group
|
|
|
|
CheckedUint32(vd.componentSize()) * vd.size; // and the number of bytes needed for these components
|
|
|
|
|
|
|
|
if (!checked_needed.valid()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
LogMessage(mVerbose, "Integer overflow computing the size of bound vertex attrib buffer at index %d", i);
|
2010-07-03 15:32:19 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-06-08 15:14:43 -07:00
|
|
|
|
2010-07-03 15:32:19 -07:00
|
|
|
if (vd.buf->ByteLength() < checked_needed.value()) {
|
2010-09-13 08:40:01 -07:00
|
|
|
LogMessage(mVerbose, "VBO too small for bound attrib index %d: need at least %d bytes, but have only %d",
|
2010-07-03 15:32:19 -07:00
|
|
|
i, checked_needed.value(), vd.buf->ByteLength());
|
2010-06-10 10:45:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2010-06-01 23:09:18 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateCapabilityEnum(WebGLenum cap, const char *info)
|
2010-06-08 11:45:23 -07:00
|
|
|
{
|
|
|
|
switch (cap) {
|
|
|
|
case LOCAL_GL_BLEND:
|
|
|
|
case LOCAL_GL_CULL_FACE:
|
|
|
|
case LOCAL_GL_DEPTH_TEST:
|
|
|
|
case LOCAL_GL_DITHER:
|
|
|
|
case LOCAL_GL_POLYGON_OFFSET_FILL:
|
|
|
|
case LOCAL_GL_SAMPLE_ALPHA_TO_COVERAGE:
|
|
|
|
case LOCAL_GL_SAMPLE_COVERAGE:
|
|
|
|
case LOCAL_GL_SCISSOR_TEST:
|
|
|
|
case LOCAL_GL_STENCIL_TEST:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, cap);
|
2010-06-08 11:45:23 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateBlendEquationEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, mode);
|
2010-06-19 07:48:44 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateBlendFuncDstEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, factor);
|
2010-06-19 07:48:44 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateBlendFuncSrcEnum(WebGLenum 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)
|
2010-06-19 07:48:44 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
else
|
2010-06-30 08:49:59 -07:00
|
|
|
return ValidateBlendFuncDstEnum(factor, info);
|
2010-06-19 07:48:44 -07:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateTextureTargetEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, target);
|
2010-06-30 08:48:30 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateComparisonEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, target);
|
2010-06-30 08:48:30 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateStencilOpEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, action);
|
2010-06-30 08:48:30 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-16 07:31:48 -07:00
|
|
|
PRBool WebGLContext::ValidateFaceEnum(WebGLenum 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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, face);
|
2010-06-30 08:48:30 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 15:34:07 -07:00
|
|
|
PRBool WebGLContext::ValidateBufferUsageEnum(WebGLenum target, const char *info)
|
|
|
|
{
|
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_STREAM_DRAW:
|
|
|
|
case LOCAL_GL_STATIC_DRAW:
|
|
|
|
case LOCAL_GL_DYNAMIC_DRAW:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnumInfo(info, target);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool WebGLContext::ValidateDrawModeEnum(WebGLenum mode, const char *info)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
|
|
|
ErrorInvalidEnumInfo(info, mode);
|
2010-07-03 15:34:07 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:49:59 -07:00
|
|
|
PRBool WebGLContext::ValidateTexFormatAndType(WebGLenum format, WebGLenum type,
|
|
|
|
PRUint32 *texelSize, const char *info)
|
|
|
|
{
|
|
|
|
if (type == LOCAL_GL_UNSIGNED_BYTE)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case LOCAL_GL_RED:
|
|
|
|
case LOCAL_GL_GREEN:
|
|
|
|
case LOCAL_GL_BLUE:
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
*texelSize = 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
|
|
|
*texelSize = 2;
|
|
|
|
return PR_TRUE;
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
*texelSize = 3;
|
|
|
|
return PR_TRUE;
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
*texelSize = 4;
|
|
|
|
return PR_TRUE;
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnum("%s: invalid format 0x%x", info, format);
|
2010-06-30 08:49:59 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (type) {
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
|
|
|
|
if (format == LOCAL_GL_RGBA) {
|
|
|
|
*texelSize = 2;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
ErrorInvalidOperation("%s: mutually incompatible format and type", info);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
|
|
|
|
if (format == LOCAL_GL_RGB) {
|
|
|
|
*texelSize = 2;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
ErrorInvalidOperation("%s: mutually incompatible format and type", info);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
default:
|
2010-07-16 07:31:48 -07:00
|
|
|
ErrorInvalidEnum("%s: invalid type 0x%x", info, type);
|
2010-06-30 08:49:59 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
PRBool
|
2010-06-14 11:44:12 -07:00
|
|
|
WebGLContext::InitAndValidateGL()
|
2010-06-10 10:45:00 -07:00
|
|
|
{
|
2010-06-14 11:44:12 -07:00
|
|
|
if (!gl) return PR_FALSE;
|
|
|
|
|
|
|
|
mActiveTexture = 0;
|
|
|
|
mSynthesizedGLError = LOCAL_GL_NO_ERROR;
|
|
|
|
|
|
|
|
mAttribBuffers.Clear();
|
|
|
|
|
|
|
|
mUniformTextures.Clear();
|
|
|
|
mBound2DTextures.Clear();
|
|
|
|
mBoundCubeMapTextures.Clear();
|
|
|
|
|
|
|
|
mBoundArrayBuffer = nsnull;
|
|
|
|
mBoundElementArrayBuffer = nsnull;
|
|
|
|
mCurrentProgram = nsnull;
|
|
|
|
|
|
|
|
mFramebufferColorAttachments.Clear();
|
|
|
|
mFramebufferDepthAttachment = nsnull;
|
|
|
|
mFramebufferStencilAttachment = nsnull;
|
|
|
|
|
|
|
|
mBoundFramebuffer = nsnull;
|
|
|
|
mBoundRenderbuffer = nsnull;
|
|
|
|
|
|
|
|
mMapTextures.Clear();
|
|
|
|
mMapBuffers.Clear();
|
|
|
|
mMapPrograms.Clear();
|
|
|
|
mMapShaders.Clear();
|
|
|
|
mMapFramebuffers.Clear();
|
|
|
|
mMapRenderbuffers.Clear();
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
// make sure that the opengl stuff that we need is supported
|
|
|
|
GLint val = 0;
|
|
|
|
|
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
|
|
|
|
if (!gl->IsGLES2()) {
|
|
|
|
gl->fEnableVertexAttribArray(0);
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_ATTRIBS, (GLint*) &mGLMaxVertexAttribs);
|
|
|
|
if (mGLMaxVertexAttribs < 8) {
|
2010-07-18 22:01:14 -07:00
|
|
|
LogMessage("GL_MAX_VERTEX_ATTRIBS: %d is < 8!", mGLMaxVertexAttribs);
|
2010-06-10 10:45:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
mAttribBuffers.SetLength(mGLMaxVertexAttribs);
|
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.
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, (GLint*) &mGLMaxTextureUnits);
|
|
|
|
if (mGLMaxTextureUnits < 8) {
|
2010-07-18 22:01:14 -07:00
|
|
|
LogMessage("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!", mGLMaxTextureUnits);
|
2010-06-10 10:45:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
mBound2DTextures.SetLength(mGLMaxTextureUnits);
|
|
|
|
mBoundCubeMapTextures.SetLength(mGLMaxTextureUnits);
|
|
|
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, (GLint*) &mGLMaxTextureSize);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*) &mGLMaxCubeMapTextureSize);
|
|
|
|
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, (GLint*) &mGLMaxTextureImageUnits);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, (GLint*) &mGLMaxVertexTextureImageUnits);
|
|
|
|
|
2010-07-28 14:24:09 -07:00
|
|
|
if (gl->IsGLES2()) {
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS, (GLint*) &mGLMaxFragmentUniformVectors);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS, (GLint*) &mGLMaxVertexUniformVectors);
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VARYING_VECTORS, (GLint*) &mGLMaxVaryingVectors);
|
|
|
|
} else {
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, (GLint*) &mGLMaxFragmentUniformVectors);
|
|
|
|
mGLMaxFragmentUniformVectors /= 4;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS, (GLint*) &mGLMaxVertexUniformVectors);
|
|
|
|
mGLMaxVertexUniformVectors /= 4;
|
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_VARYING_FLOATS, (GLint*) &mGLMaxVaryingVectors);
|
|
|
|
mGLMaxVaryingVectors /= 4;
|
|
|
|
}
|
2010-06-10 10:45:00 -07:00
|
|
|
|
2010-07-28 14:24:09 -07:00
|
|
|
#if 0
|
|
|
|
// Leaving this code in here, even though it's ifdef'd out, for
|
|
|
|
// when we support more than 1 color attachment.
|
2010-07-14 20:52:34 -07:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, (GLint*) &val);
|
2010-07-28 14:24:09 -07:00
|
|
|
#else
|
|
|
|
// Always 1 for GLES2
|
|
|
|
val = 1;
|
|
|
|
#endif
|
2010-06-10 10:45:00 -07:00
|
|
|
mFramebufferColorAttachments.SetLength(val);
|
|
|
|
|
|
|
|
#if defined(DEBUG_vladimir) && defined(USE_GLES2)
|
2010-07-14 20:52:34 -07:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_IMPLEMENTATION_COLOR_READ_FORMAT, (GLint*) &val);
|
2010-06-10 10:45:00 -07:00
|
|
|
fprintf(stderr, "GL_IMPLEMENTATION_COLOR_READ_FORMAT: 0x%04x\n", val);
|
|
|
|
|
2010-07-14 20:52:34 -07:00
|
|
|
gl->fGetIntegerv(LOCAL_GL_IMPLEMENTATION_COLOR_READ_TYPE, (GLint*) &val);
|
2010-06-10 10:45:00 -07:00
|
|
|
fprintf(stderr, "GL_IMPLEMENTATION_COLOR_READ_TYPE: 0x%04x\n", val);
|
|
|
|
#endif
|
|
|
|
|
2010-07-28 14:24:09 -07:00
|
|
|
if (!gl->IsGLES2()) {
|
|
|
|
// 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
|
|
|
|
2010-10-06 13:43:21 -07:00
|
|
|
// we don't do the following glEnable(GL_POINT_SPRITE) on ATI cards on Windows, because bug 602183 shows that it causes
|
|
|
|
// crashes in the ATI/Windows driver; and point sprites on ATI seem like a lost cause anyway, see
|
|
|
|
// http://www.gamedev.net/community/forums/topic.asp?topic_id=525643
|
|
|
|
// Also, if the ATI/Windows driver implements a recent GL spec version, this shouldn't be needed anyway.
|
|
|
|
#ifdef XP_WIN
|
2010-10-06 14:07:16 -07:00
|
|
|
if (gl->Vendor() != gl::GLContext::VendorATI)
|
2010-10-06 13:43:21 -07:00
|
|
|
#else
|
|
|
|
if (true)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
gl->fEnable(LOCAL_GL_POINT_SPRITE);
|
|
|
|
}
|
2010-07-28 14:24:09 -07:00
|
|
|
}
|
2010-07-14 20:52:34 -07:00
|
|
|
|
2010-08-19 19:50:38 -07:00
|
|
|
// Check the shader validator pref
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(prefService != nsnull, NS_ERROR_FAILURE);
|
2010-08-09 23:51:56 -07:00
|
|
|
|
2010-08-19 19:50:38 -07:00
|
|
|
prefService->GetBoolPref("webgl.shader_validator", &mShaderValidation);
|
2010-08-09 23:51:56 -07:00
|
|
|
|
|
|
|
#if defined(USE_ANGLE)
|
2010-08-19 19:50:38 -07:00
|
|
|
// initialize shader translator
|
|
|
|
if (mShaderValidation) {
|
|
|
|
if (!ShInitialize()) {
|
|
|
|
LogMessage("GLSL translator initialization failed!");
|
|
|
|
return PR_FALSE;
|
2010-07-14 20:52:34 -07:00
|
|
|
}
|
2010-08-09 23:51:56 -07:00
|
|
|
}
|
2010-08-19 19:50:38 -07:00
|
|
|
#endif
|
2010-08-09 23:51:56 -07:00
|
|
|
|
2010-09-16 09:45:01 -07:00
|
|
|
// notice that the point of calling GetError here is not only to check for error,
|
|
|
|
// it is also to reset the error flag so that a subsequent WebGL getError call will give the correct result.
|
|
|
|
GLenum error = gl->fGetError();
|
|
|
|
if (error != LOCAL_GL_NO_ERROR) {
|
|
|
|
LogMessage("GL error 0x%x occurred during WebGL context initialization!", error);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-10 10:45:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|