b=580345; fix up some GLESv2 vs. desktop GL differences; r=joe

This commit is contained in:
Vladimir Vukicevic 2010-07-28 14:24:09 -07:00
parent cebf5f2628
commit 78b092c544
6 changed files with 97 additions and 110 deletions

View File

@ -319,11 +319,7 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
gl->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, gl->GetOffscreenFBO());
gl->fViewport(0, 0, mWidth, mHeight);
gl->fClearColor(0.0f, 0.0f, 0.0f, 0.0f);
#ifdef USE_GLES2
gl->fClearDepthf(1.0f);
#else
gl->fClearDepth(1.0f);
#endif
gl->fClearStencil(0);
gl->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);

View File

@ -526,11 +526,7 @@ WebGLContext::Clear(PRUint32 mask)
GL_SAME_METHOD_4(ClearColor, ClearColor, WebGLfloat, WebGLfloat, WebGLfloat, WebGLfloat)
#ifdef USE_GLES2
GL_SAME_METHOD_1(ClearDepthf, ClearDepth, WebGLfloat)
#else
GL_SAME_METHOD_1(ClearDepth, ClearDepth, WebGLfloat)
#endif
GL_SAME_METHOD_1(ClearStencil, ClearStencil, WebGLint)
@ -834,11 +830,7 @@ WebGLContext::DepthFunc(WebGLenum func)
GL_SAME_METHOD_1(DepthMask, DepthMask, WebGLboolean)
#ifdef USE_GLES2
GL_SAME_METHOD_2(DepthRangef, DepthRange, WebGLfloat, WebGLfloat)
#else
GL_SAME_METHOD_2(DepthRange, DepthRange, WebGLfloat, WebGLfloat)
#endif
NS_IMETHODIMP
WebGLContext::DisableVertexAttribArray(WebGLuint index)
@ -1342,18 +1334,18 @@ WebGLContext::GetParameter(PRUint32 pname, nsIVariant **retval)
case LOCAL_GL_MAX_VARYING_VECTORS:
{
#ifdef USE_GLES2
if (gl->IsGLES2()) {
GLint i = 0;
gl->fGetIntegerv(pname, &i);
wrval->SetAsInt32(i);
#else
} else {
// since this pname is absent from desktop OpenGL, we have to implement it by hand.
// The formula below comes from the public_webgl list, "problematic GetParameter pnames" thread
GLint i = 0, j = 0;
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS, &i);
gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS, &j);
wrval->SetAsInt32(PR_MIN(i,j)/4);
#endif
}
}
break;

View File

@ -407,20 +407,27 @@ WebGLContext::InitAndValidateGL()
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, (GLint*) &mGLMaxTextureImageUnits);
gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, (GLint*) &mGLMaxVertexTextureImageUnits);
#ifdef USE_GLES2
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
} 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;
#endif
}
#if 0
// Leaving this code in here, even though it's ifdef'd out, for
// when we support more than 1 color attachment.
gl->fGetIntegerv(LOCAL_GL_MAX_COLOR_ATTACHMENTS, (GLint*) &val);
#else
// Always 1 for GLES2
val = 1;
#endif
mFramebufferColorAttachments.SetLength(val);
#if defined(DEBUG_vladimir) && defined(USE_GLES2)
@ -431,11 +438,11 @@ WebGLContext::InitAndValidateGL()
fprintf(stderr, "GL_IMPLEMENTATION_COLOR_READ_TYPE: 0x%04x\n", val);
#endif
#ifndef USE_GLES2
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);
#endif
}
#if !defined(USE_GLES2) && defined(USE_ANGLE)
// initialize shader translator

View File

@ -701,15 +701,15 @@ BasicCanvasLayer::Updated(const nsIntRect& aRect)
// For simplicity, we read the entire framebuffer for now -- in
// the future we should use mUpdatedRect, though with WebGL we don't
// have an easy way to generate one.
#ifndef USE_GLES2
mGLContext->fReadPixels(0, 0, mBounds.width, mBounds.height,
LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV,
isurf->Data());
#else
if (mGLContext->IsGLES2()) {
mGLContext->fReadPixels(0, 0, mBounds.width, mBounds.height,
LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE,
isurf->Data());
#endif
} else {
mGLContext->fReadPixels(0, 0, mBounds.width, mBounds.height,
LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV,
isurf->Data());
}
// Put back the previous framebuffer binding.
if (currentFramebuffer != mCanvasFramebuffer)

View File

@ -173,33 +173,17 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &fBufferSubData, { "BufferSubData", NULL } },
{ (PRFuncPtr*) &fClear, { "Clear", NULL } },
{ (PRFuncPtr*) &fClearColor, { "ClearColor", NULL } },
#ifdef USE_GLES2
{ (PRFuncPtr*) &fClearDepthf, { "ClearDepthf", NULL } },
#else
{ (PRFuncPtr*) &fClearDepth, { "ClearDepth", NULL } },
#endif
{ (PRFuncPtr*) &fClearStencil, { "ClearStencil", NULL } },
{ (PRFuncPtr*) &fColorMask, { "ColorMask", NULL } },
{ (PRFuncPtr*) &fCullFace, { "CullFace", NULL } },
{ (PRFuncPtr*) &fDetachShader, { "DetachShader", "DetachShaderARB", NULL } },
{ (PRFuncPtr*) &fDepthFunc, { "DepthFunc", NULL } },
{ (PRFuncPtr*) &fDepthMask, { "DepthMask", NULL } },
#ifdef USE_GLES2
{ (PRFuncPtr*) &fDepthRangef, { "DepthRangef", NULL } },
#else
{ (PRFuncPtr*) &fDepthRange, { "DepthRange", NULL } },
#endif
{ (PRFuncPtr*) &fDisable, { "Disable", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fDisableClientState, { "DisableClientState", NULL } },
#endif
{ (PRFuncPtr*) &fDisableVertexAttribArray, { "DisableVertexAttribArray", "DisableVertexAttribArrayARB", NULL } },
{ (PRFuncPtr*) &fDrawArrays, { "DrawArrays", NULL } },
{ (PRFuncPtr*) &fDrawElements, { "DrawElements", NULL } },
{ (PRFuncPtr*) &fEnable, { "Enable", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fEnableClientState, { "EnableClientState", NULL } },
#endif
{ (PRFuncPtr*) &fEnableVertexAttribArray, { "EnableVertexAttribArray", "EnableVertexAttribArrayARB", NULL } },
{ (PRFuncPtr*) &fFinish, { "Finish", NULL } },
{ (PRFuncPtr*) &fFlush, { "Flush", NULL } },
@ -215,9 +199,6 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &fGetError, { "GetError", NULL } },
{ (PRFuncPtr*) &fGetProgramiv, { "GetProgramiv", "GetProgramivARB", NULL } },
{ (PRFuncPtr*) &fGetProgramInfoLog, { "GetProgramInfoLog", "GetProgramInfoLogARB", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fTexCoordPointer, { "TexCoordPointer", NULL } },
#endif
{ (PRFuncPtr*) &fTexParameteri, { "TexParameteri", NULL } },
{ (PRFuncPtr*) &fTexParameterf, { "TexParameterf", NULL } },
{ (PRFuncPtr*) &fGetString, { "GetString", NULL } },
@ -238,9 +219,6 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &fLinkProgram, { "LinkProgram", "LinkProgramARB", NULL } },
{ (PRFuncPtr*) &fPixelStorei, { "PixelStorei", NULL } },
{ (PRFuncPtr*) &fPolygonOffset, { "PolygonOffset", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fReadBuffer, { "ReadBuffer", NULL } },
#endif
{ (PRFuncPtr*) &fReadPixels, { "ReadPixels", NULL } },
{ (PRFuncPtr*) &fSampleCoverage, { "SampleCoverage", NULL } },
{ (PRFuncPtr*) &fScissor, { "Scissor", NULL } },
@ -250,9 +228,6 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &fStencilMaskSeparate, { "StencilMaskSeparate", "StencilMaskSeparateEXT", NULL } },
{ (PRFuncPtr*) &fStencilOp, { "StencilOp", NULL } },
{ (PRFuncPtr*) &fStencilOpSeparate, { "StencilOpSeparate", "StencilOpSeparateEXT", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fTexEnvf, { "TexEnvf", NULL } },
#endif
{ (PRFuncPtr*) &fTexImage2D, { "TexImage2D", NULL } },
{ (PRFuncPtr*) &fTexSubImage2D, { "TexSubImage2D", NULL } },
{ (PRFuncPtr*) &fUniform1f, { "Uniform1f", NULL } },
@ -285,9 +260,6 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &fVertexAttrib2fv, { "VertexAttrib2fv", NULL } },
{ (PRFuncPtr*) &fVertexAttrib3fv, { "VertexAttrib3fv", NULL } },
{ (PRFuncPtr*) &fVertexAttrib4fv, { "VertexAttrib4fv", NULL } },
#ifndef USE_GLES2
{ (PRFuncPtr*) &fVertexPointer, { "VertexPointer", NULL } },
#endif
{ (PRFuncPtr*) &fViewport, { "Viewport", NULL } },
{ (PRFuncPtr*) &fCompileShader, { "CompileShader", NULL } },
{ (PRFuncPtr*) &fCopyTexImage2D, { "CopyTexImage2D", NULL } },
@ -323,6 +295,15 @@ GLContext::InitWithPrefix(const char *prefix, PRBool trygl)
{ (PRFuncPtr*) &priv_fDeleteFramebuffers, { "DeleteFramebuffers", "DeleteFramebuffersEXT", NULL } },
{ (PRFuncPtr*) &priv_fDeleteRenderbuffers, { "DeleteRenderbuffers", "DeleteRenderbuffersEXT", NULL } },
{ mIsGLES2 ? (PRFuncPtr*) &priv_fClearDepthf : (PRFuncPtr*) &priv_fClearDepth,
{ mIsGLES2 ? "ClearDepthf" : "ClearDepth", NULL } },
{ mIsGLES2 ? (PRFuncPtr*) &priv_fDepthRangef : (PRFuncPtr*) &priv_fDepthRange,
{ mIsGLES2 ? "DepthRangef" : "DepthRange", NULL } },
// XXX FIXME -- we shouldn't be using glReadBuffer!
{ mIsGLES2 ? (PRFuncPtr*) NULL : (PRFuncPtr*) &fReadBuffer,
{ mIsGLES2 ? NULL : "ReadBuffer", NULL } },
{ NULL, { NULL } },
};
@ -655,21 +636,13 @@ GLContext::ClearSafely()
fClearColor(0.0f, 0.0f, 0.0f, 0.0f);
fClearStencil(0);
#ifdef USE_GLES2
fClearDepthf(1.0f);
#else
fClearDepth(1.0);
#endif
fClearDepth(1.0f);
fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);
fClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
fClearStencil(clearStencil);
#ifdef USE_GLES2
fClearDepthf(clearDepth);
#else
fClearDepth(clearDepth);
#endif
}
void

View File

@ -332,8 +332,13 @@ public:
PRBool aIsOffscreen = PR_FALSE,
GLContext *aSharedContext = nsnull)
: mInitialized(PR_FALSE),
mCreationFormat(aFormat),
mIsOffscreen(aIsOffscreen),
#ifdef USE_GLES2
mIsGLES2(PR_TRUE),
#else
mIsGLES2(PR_FALSE),
#endif
mCreationFormat(aFormat),
mSharedContext(aSharedContext),
mOffscreenTexture(0),
mOffscreenFBO(0),
@ -398,6 +403,15 @@ public:
*/
virtual PRBool IsDoubleBuffered() { return PR_FALSE; }
/**
* If this context is the GLES2 API, returns TRUE.
* This means that various GLES2 restrictions might be in effect (modulo
* extensions).
*/
PRBool IsGLES2() {
return mIsGLES2;
}
/**
* If this context wraps a double-buffered target, swap the back
* and front buffers. It should be assumed that after a swap, the
@ -542,8 +556,9 @@ public:
protected:
PRPackedBool mInitialized;
ContextFormat mCreationFormat;
PRPackedBool mIsOffscreen;
PRPackedBool mIsGLES2;
ContextFormat mCreationFormat;
nsRefPtr<GLContext> mSharedContext;
void UpdateActualFormat();
@ -568,6 +583,11 @@ protected:
nsDataHashtable<nsVoidPtrHashKey, void*> mUserData;
void SetIsGLES2(PRBool aIsGLES2) {
NS_ASSERTION(!mInitialized, "SetIsGLES2 can only be called before initialization!");
mIsGLES2 = aIsGLES2;
}
PRBool InitWithPrefix(const char *prefix, PRBool trygl);
PRBool IsExtensionSupported(const char *extension);
@ -615,13 +635,6 @@ public:
PFNGLCLEARPROC fClear;
typedef void (GLAPIENTRY * PFNGLCLEARCOLORPROC) (GLclampf, GLclampf, GLclampf, GLclampf);
PFNGLCLEARCOLORPROC fClearColor;
#ifdef USE_GLES2
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHFPROC) (GLclampf);
PFNGLCLEARDEPTHFPROC fClearDepthf;
#else
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHPROC) (GLclampd);
PFNGLCLEARDEPTHPROC fClearDepth;
#endif
typedef void (GLAPIENTRY * PFNGLCLEARSTENCILPROC) (GLint);
PFNGLCLEARSTENCILPROC fClearStencil;
typedef void (GLAPIENTRY * PFNGLCOLORMASKPROC) (realGLboolean red, realGLboolean green, realGLboolean blue, realGLboolean alpha);
@ -634,17 +647,8 @@ public:
PFNGLDEPTHFUNCPROC fDepthFunc;
typedef void (GLAPIENTRY * PFNGLDEPTHMASKPROC) (realGLboolean);
PFNGLDEPTHMASKPROC fDepthMask;
#ifdef USE_GLES2
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEFPROC) (GLclampf, GLclampf);
PFNGLDEPTHRANGEFPROC fDepthRangef;
#else
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEPROC) (GLclampd, GLclampd);
PFNGLDEPTHRANGEPROC fDepthRange;
#endif
typedef void (GLAPIENTRY * PFNGLDISABLEPROC) (GLenum);
PFNGLDISABLEPROC fDisable;
typedef void (GLAPIENTRY * PFNGLDISABLECLIENTSTATEPROC) (GLenum);
PFNGLDISABLECLIENTSTATEPROC fDisableClientState;
typedef void (GLAPIENTRY * PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint);
PFNGLDISABLEVERTEXATTRIBARRAYPROC fDisableVertexAttribArray;
typedef void (GLAPIENTRY * PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
@ -653,8 +657,6 @@ public:
PFNGLDRAWELEMENTSPROC fDrawElements;
typedef void (GLAPIENTRY * PFNGLENABLEPROC) (GLenum);
PFNGLENABLEPROC fEnable;
typedef void (GLAPIENTRY * PFNGLENABLECLIENTSTATEPROC) (GLenum);
PFNGLENABLECLIENTSTATEPROC fEnableClientState;
typedef void (GLAPIENTRY * PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint);
PFNGLENABLEVERTEXATTRIBARRAYPROC fEnableVertexAttribArray;
typedef void (GLAPIENTRY * PFNGLFINISHPROC) (void);
@ -687,8 +689,6 @@ public:
PFNGLGETPROGRAMIVPROC fGetProgramiv;
typedef void (GLAPIENTRY * PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
PFNGLGETPROGRAMINFOLOGPROC fGetProgramInfoLog;
typedef void (GLAPIENTRY * PFNGLTEXENVFPROC) (GLenum, GLenum, GLfloat);
PFNGLTEXENVFPROC fTexEnvf;
typedef void (GLAPIENTRY * PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
PFNGLTEXPARAMETERIPROC fTexParameteri;
typedef void (GLAPIENTRY * PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
@ -749,11 +749,6 @@ public:
PFNGLSTENCILOPPROC fStencilOp;
typedef void (GLAPIENTRY * PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
PFNGLSTENCILOPSEPARATEPROC fStencilOpSeparate;
typedef void (GLAPIENTRY * PFNGLTEXCOORDPOINTERPROC) (GLint,
GLenum,
GLsizei,
const GLvoid *);
PFNGLTEXCOORDPOINTERPROC fTexCoordPointer;
typedef void (GLAPIENTRY * PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
PFNGLTEXIMAGE2DPROC fTexImage2D;
typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels);
@ -818,11 +813,6 @@ public:
PFNGLVERTEXATTRIB3FVPROC fVertexAttrib3fv;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat* v);
PFNGLVERTEXATTRIB4FVPROC fVertexAttrib4fv;
typedef void (GLAPIENTRY * PFNGLVERTEXPOINTERPROC) (GLint,
GLenum,
GLsizei,
const GLvoid *);
PFNGLVERTEXPOINTERPROC fVertexPointer;
typedef void (GLAPIENTRY * PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
PFNGLVIEWPORTPROC fViewport;
typedef void (GLAPIENTRY * PFNGLCOMPILESHADERPROC) (GLuint shader);
@ -861,7 +851,36 @@ public:
typedef void (GLAPIENTRY * PFNGLRENDERBUFFERSTORAGE) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height);
PFNGLRENDERBUFFERSTORAGE fRenderbufferStorage;
void fDepthRange(GLclampf a, GLclampf b) {
if (mIsGLES2) {
priv_fDepthRangef(a, b);
} else {
priv_fDepthRange(a, b);
}
}
void fClearDepth(GLclampf v) {
if (mIsGLES2) {
priv_fClearDepthf(v);
} else {
priv_fClearDepth(v);
}
}
protected:
/* These are different between GLES2 and desktop GL; we hide those differences, use the GL
* names, but the most limited data type.
*/
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEFPROC) (GLclampf, GLclampf);
PFNGLDEPTHRANGEFPROC priv_fDepthRangef;
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHFPROC) (GLclampf);
PFNGLCLEARDEPTHFPROC priv_fClearDepthf;
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEPROC) (GLclampd, GLclampd);
PFNGLDEPTHRANGEPROC priv_fDepthRange;
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHPROC) (GLclampd);
PFNGLCLEARDEPTHPROC priv_fClearDepth;
/* These are special -- they create or delete GL resources that can live
* in a shared namespace. In DEBUG, we wrap these calls so that we can
* check when we have something that failed to do cleanup at the time the