Bug 1217290 - Refine WebGLContext members r=daoshengmu,jgilbert
authorChung-Sheng Fu <cfu@mozilla.com>
Thu, 27 Jul 2017 15:49:21 +0800
changeset 428613 3fc40b0c5e0ae244af61b1335c363f3c085e2e0f
parent 428612 715cea82455ce243f6a0f50a84034a97e9f6640f
child 428614 61d074cfdeafd13395c089dcd4b2c47fb5d80204
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaoshengmu, jgilbert
bugs1217290
milestone57.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 1217290 - Refine WebGLContext members r=daoshengmu,jgilbert MozReview-Commit-ID: BjZCM1ygZ4k
dom/canvas/WebGL2ContextSamplers.cpp
dom/canvas/WebGLContext.h
dom/canvas/WebGLContextGL.cpp
dom/canvas/WebGLContextValidate.cpp
dom/canvas/WebGLShaderValidator.cpp
--- a/dom/canvas/WebGL2ContextSamplers.cpp
+++ b/dom/canvas/WebGL2ContextSamplers.cpp
@@ -24,17 +24,17 @@ WebGL2Context::CreateSampler()
 }
 
 void
 WebGL2Context::DeleteSampler(WebGLSampler* sampler)
 {
     if (!ValidateDeleteObject("deleteSampler", sampler))
         return;
 
-    for (int n = 0; n < mGLMaxTextureUnits; n++) {
+    for (uint32_t n = 0; n < mGLMaxTextureUnits; n++) {
         if (mBoundSamplers[n] == sampler) {
             mBoundSamplers[n] = nullptr;
 
             InvalidateResolveCacheForTextureWithTexUnit(n);
         }
     }
 
     sampler->RequestDelete();
@@ -54,18 +54,18 @@ void
 WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler)
 {
     if (IsContextLost())
         return;
 
     if (sampler && !ValidateObject("bindSampler", *sampler))
         return;
 
-    if (GLint(unit) >= mGLMaxTextureUnits)
-        return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits);
+    if (unit >= mGLMaxTextureUnits)
+        return ErrorInvalidValue("bindSampler: unit must be < %u", mGLMaxTextureUnits);
 
     ////
 
     gl->MakeCurrent();
     gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
 
     InvalidateResolveCacheForTextureWithTexUnit(unit);
     mBoundSamplers[unit] = sampler;
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -1461,25 +1461,29 @@ protected:
     GLenum mUnderlyingGLError;
     GLenum GetAndFlushUnderlyingGLErrors();
 
     bool mBypassShaderValidation;
 
     webgl::ShaderValidator* CreateShaderValidator(GLenum shaderType) const;
 
     // some GL constants
+    uint32_t mGLMaxTextureUnits;
+
     uint32_t mGLMaxVertexAttribs;
-    int32_t mGLMaxTextureUnits;
-    int32_t mGLMaxTextureImageUnits;
-    int32_t mGLMaxVertexTextureImageUnits;
-    int32_t mGLMaxVaryingVectors;
-    int32_t mGLMaxFragmentUniformVectors;
-    int32_t mGLMaxVertexUniformVectors;
-    uint32_t  mGLMaxTransformFeedbackSeparateAttribs;
-    GLuint  mGLMaxUniformBufferBindings;
+    uint32_t mGLMaxFragmentUniformVectors;
+    uint32_t mGLMaxVertexUniformVectors;
+    uint32_t mGLMaxVaryingVectors;
+
+    uint32_t mGLMaxTransformFeedbackSeparateAttribs;
+    uint32_t mGLMaxUniformBufferBindings;
+
+    uint32_t mGLMaxVertexTextureImageUnits;
+    uint32_t mGLMaxFragmentTextureImageUnits;
+    uint32_t mGLMaxCombinedTextureImageUnits;
 
     uint32_t mGLMaxColorAttachments;
     uint32_t mGLMaxDrawBuffers;
 
     uint32_t mGLMaxViewportDims[2];
 
 public:
     GLenum LastColorAttachmentEnum() const {
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -79,17 +79,17 @@ using namespace mozilla::gl;
 
 void
 WebGLContext::ActiveTexture(GLenum texture)
 {
     if (IsContextLost())
         return;
 
     if (texture < LOCAL_GL_TEXTURE0 ||
-        texture >= LOCAL_GL_TEXTURE0 + uint32_t(mGLMaxTextureUnits))
+        texture >= LOCAL_GL_TEXTURE0 + mGLMaxTextureUnits)
     {
         return ErrorInvalidEnum(
             "ActiveTexture: texture unit %d out of range. "
             "Accepted values range from TEXTURE0 to TEXTURE0 + %d. "
             "Notice that TEXTURE0 != 0.",
             texture, mGLMaxTextureUnits);
     }
 
@@ -425,17 +425,17 @@ WebGLContext::DeleteTexture(WebGLTexture
 
     if (mBoundDrawFramebuffer)
         mBoundDrawFramebuffer->DetachTexture(funcName, tex);
 
     if (mBoundReadFramebuffer)
         mBoundReadFramebuffer->DetachTexture(funcName, tex);
 
     GLuint activeTexture = mActiveTexture;
-    for (int32_t i = 0; i < mGLMaxTextureUnits; i++) {
+    for (uint32_t i = 0; i < mGLMaxTextureUnits; i++) {
         if (mBound2DTextures[i] == tex ||
             mBoundCubeMapTextures[i] == tex ||
             mBound3DTextures[i] == tex ||
             mBound2DArrayTextures[i] == tex)
         {
             ActiveTexture(LOCAL_GL_TEXTURE0 + i);
             BindTexture(tex->Target().get(), nullptr);
         }
--- a/dom/canvas/WebGLContextValidate.cpp
+++ b/dom/canvas/WebGLContextValidate.cpp
@@ -448,20 +448,20 @@ WebGLContext::InitAndValidateGL(FailureR
                                      mGLMaxVertexAttribs);
         *out_failReason = { "FEATURE_FAILURE_WEBGL_V_ATRB", reason };
         return false;
     }
 
     // Note: GL_MAX_TEXTURE_UNITS is fixed at 4 for most desktop hardware,
     // even though the hardware supports much more.  The
     // GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS value is the accurate value.
-    gl->fGetIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGLMaxTextureUnits);
+    gl->GetUIntegerv(LOCAL_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGLMaxTextureUnits);
 
     if (mGLMaxTextureUnits < 8) {
-        const nsPrintfCString reason("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d is < 8!",
+        const nsPrintfCString reason("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %u is < 8!",
                                      mGLMaxTextureUnits);
         *out_failReason = { "FEATURE_FAILURE_WEBGL_T_UNIT", reason };
         return false;
     }
 
     mBound2DTextures.SetLength(mGLMaxTextureUnits);
     mBoundCubeMapTextures.SetLength(mGLMaxTextureUnits);
     mBound3DTextures.SetLength(mGLMaxTextureUnits);
@@ -476,58 +476,57 @@ WebGLContext::InitAndValidateGL(FailureR
     gl->fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint*)&mGLMaxCubeMapTextureSize);
     gl->fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, (GLint*)&mGLMaxRenderbufferSize);
 
     if (!gl->GetPotentialInteger(LOCAL_GL_MAX_3D_TEXTURE_SIZE, (GLint*)&mGLMax3DTextureSize))
         mGLMax3DTextureSize = 0;
     if (!gl->GetPotentialInteger(LOCAL_GL_MAX_ARRAY_TEXTURE_LAYERS, (GLint*)&mGLMaxArrayTextureLayers))
         mGLMaxArrayTextureLayers = 0;
 
-    gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, &mGLMaxTextureImageUnits);
-    gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGLMaxVertexTextureImageUnits);
+    gl->GetUIntegerv(LOCAL_GL_MAX_TEXTURE_IMAGE_UNITS, &mGLMaxFragmentTextureImageUnits);
+    gl->GetUIntegerv(LOCAL_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGLMaxVertexTextureImageUnits);
 
     ////////////////
 
     mGLMaxColorAttachments = 1;
     mGLMaxDrawBuffers = 1;
 
     if (IsWebGL2()) {
         UpdateMaxDrawBuffers();
     }
 
     ////////////////
 
     if (gl->IsSupported(gl::GLFeature::ES2_compatibility)) {
-        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);
+        gl->GetUIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGLMaxFragmentUniformVectors);
+        gl->GetUIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_VECTORS, &mGLMaxVertexUniformVectors);
+        gl->GetUIntegerv(LOCAL_GL_MAX_VARYING_VECTORS, &mGLMaxVaryingVectors);
     } else {
-        gl->fGetIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &mGLMaxFragmentUniformVectors);
+        gl->GetUIntegerv(LOCAL_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &mGLMaxFragmentUniformVectors);
         mGLMaxFragmentUniformVectors /= 4;
-        gl->fGetIntegerv(LOCAL_GL_MAX_VERTEX_UNIFORM_COMPONENTS, &mGLMaxVertexUniformVectors);
+        gl->GetUIntegerv(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.
-            *
-            * On the public_webgl list, "problematic GetParameter pnames"
-            * thread, the following formula was given:
-            *   maxVaryingVectors = min(GL_MAX_VERTEX_OUTPUT_COMPONENTS,
-            *                           GL_MAX_FRAGMENT_INPUT_COMPONENTS) / 4
-            */
-        GLint maxVertexOutputComponents = 0;
-        GLint maxFragmentInputComponents = 0;
-
-        const bool ok = (gl->GetPotentialInteger(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS,
-                                                    &maxVertexOutputComponents) &&
-                            gl->GetPotentialInteger(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS,
-                                                    &maxFragmentInputComponents));
-
+         * 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.
+         *
+         * On the public_webgl list, "problematic GetParameter pnames"
+         * thread, the following formula was given:
+         *   maxVaryingVectors = min(GL_MAX_VERTEX_OUTPUT_COMPONENTS,
+         *                           GL_MAX_FRAGMENT_INPUT_COMPONENTS) / 4
+         */
+        uint32_t maxVertexOutputComponents = 0;
+        uint32_t maxFragmentInputComponents = 0;
+        bool ok = true;
+        ok &= gl->GetPotentialInteger(LOCAL_GL_MAX_VERTEX_OUTPUT_COMPONENTS,
+                                      (GLint*)&maxVertexOutputComponents);
+        ok &= gl->GetPotentialInteger(LOCAL_GL_MAX_FRAGMENT_INPUT_COMPONENTS,
+                                      (GLint*)&maxFragmentInputComponents);
         if (ok) {
             mGLMaxVaryingVectors = std::min(maxVertexOutputComponents,
                                             maxFragmentInputComponents) / 4;
         } else {
             mGLMaxVaryingVectors = 16;
             // 16 = 64/4, and 64 is the min value for
             // maxVertexOutputComponents in the OpenGL 3.2 spec.
         }
--- a/dom/canvas/WebGLShaderValidator.cpp
+++ b/dom/canvas/WebGLShaderValidator.cpp
@@ -140,18 +140,18 @@ WebGLContext::CreateShaderValidator(GLen
     ShInitBuiltInResources(&resources);
 
     resources.HashFunction = webgl::IdentifierHashFunc;
 
     resources.MaxVertexAttribs = mGLMaxVertexAttribs;
     resources.MaxVertexUniformVectors = mGLMaxVertexUniformVectors;
     resources.MaxVaryingVectors = mGLMaxVaryingVectors;
     resources.MaxVertexTextureImageUnits = mGLMaxVertexTextureImageUnits;
-    resources.MaxCombinedTextureImageUnits = mGLMaxTextureUnits;
-    resources.MaxTextureImageUnits = mGLMaxTextureImageUnits;
+    resources.MaxCombinedTextureImageUnits = mGLMaxCombinedTextureImageUnits;
+    resources.MaxTextureImageUnits = mGLMaxFragmentTextureImageUnits;
     resources.MaxFragmentUniformVectors = mGLMaxFragmentUniformVectors;
 
     const bool hasMRTs = (IsWebGL2() ||
                           IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers));
     resources.MaxDrawBuffers = (hasMRTs ? mGLMaxDrawBuffers : 1);
 
     if (IsExtensionEnabled(WebGLExtensionID::EXT_frag_depth))
         resources.EXT_frag_depth = 1;