Bug 664066 - Initialize GL values - r=karlt
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 27 Jun 2011 13:27:04 -0400
changeset 71834 a5c8bd58f92630b332756036b7df242548945e7f
parent 71833 51e18435b793dc3ee54965fcf2c7688409b1e52f
child 71835 baa619406bea35bcca40592b1220381aeda4c12e
push id20617
push userbjacob@mozilla.com
push dateMon, 27 Jun 2011 17:28:28 +0000
treeherdermozilla-central@baa619406bea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs664066
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 664066 - Initialize GL values - r=karlt This patch initializes by zero the GL max values before we query them, just in case a buggy OpenGL implementation's glGetIntegerv function would fail to set them. This patch also manually sets the initial values of mPixelStorePackAlignment and mPixelStoreUnpackAlignment as per the spec, rather than querying them from the GL.
content/canvas/src/WebGLContext.cpp
content/canvas/src/WebGLContextValidate.cpp
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -143,16 +143,32 @@ WebGLContext::WebGLContext()
     mStencilValueMaskFront = 0xffffffff;
     mStencilValueMaskBack  = 0xffffffff;
     mStencilWriteMaskFront = 0xffffffff;
     mStencilWriteMaskBack  = 0xffffffff;
 
     mScissorTestEnabled = 0;
     mDitherEnabled = 1;
     mBackbufferClearingStatus = BackbufferClearingStatus::NotClearedSinceLastPresented;
+    
+    // initialize some GL values: we're going to get them from the GL and use them as the sizes of arrays,
+    // so in case glGetIntegerv leaves them uninitialized because of a GL bug, we would have very weird crashes.
+    mGLMaxVertexAttribs = 0;
+    mGLMaxTextureUnits = 0;
+    mGLMaxTextureSize = 0;
+    mGLMaxCubeMapTextureSize = 0;
+    mGLMaxTextureImageUnits = 0;
+    mGLMaxVertexTextureImageUnits = 0;
+    mGLMaxVaryingVectors = 0;
+    mGLMaxFragmentUniformVectors = 0;
+    mGLMaxVertexUniformVectors = 0;
+    
+    // See OpenGL ES 2.0.25 spec, 6.2 State Tables, table 6.13
+    mPixelStorePackAlignment = 4;
+    mPixelStoreUnpackAlignment = 4;
 }
 
 WebGLContext::~WebGLContext()
 {
     DestroyResourcesAndContext();
 }
 
 static PLDHashOperator
--- a/content/canvas/src/WebGLContextValidate.cpp
+++ b/content/canvas/src/WebGLContextValidate.cpp
@@ -566,22 +566,16 @@ WebGLContext::InitAndValidateGL()
         {
             // 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);
         }
     }
 
-    GLint i;
-    gl->fGetIntegerv(LOCAL_GL_PACK_ALIGNMENT,   &i);
-    mPixelStorePackAlignment = i;
-    gl->fGetIntegerv(LOCAL_GL_UNPACK_ALIGNMENT, &i);
-    mPixelStoreUnpackAlignment = i;
-
     // Check the shader validator pref
     nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
     NS_ENSURE_TRUE(prefService != nsnull, NS_ERROR_FAILURE);
 
     prefService->GetBoolPref("webgl.shader_validator", &mShaderValidation);
 
 #if defined(USE_ANGLE)
     // initialize shader translator