Bug 1170455 - Part 2: Split vertex attribute functions into separate file. r=jgilbert
authorDan Glastonbury <dglastonbury@mozilla.com>
Mon, 20 Jul 2015 13:51:59 +1000
changeset 254049 f03847cf62c27dad282e7b80559c2cd3422bef80
parent 254048 ce1426e69a5cfeec7f61aaadef817b8ffa2eebe2
child 254050 5c815e17ac8ada59568283c8af94068d935d9062
push id29087
push usercbook@mozilla.com
push dateWed, 22 Jul 2015 12:01:23 +0000
treeherdermozilla-central@e7434cafdf2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1170455
milestone42.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 1170455 - Part 2: Split vertex attribute functions into separate file. r=jgilbert
dom/canvas/WebGL2ContextUniforms.cpp
dom/canvas/WebGL2ContextVertices.cpp
dom/canvas/moz.build
--- a/dom/canvas/WebGL2ContextUniforms.cpp
+++ b/dom/canvas/WebGL2ContextUniforms.cpp
@@ -11,119 +11,24 @@
 #include "WebGLBuffer.h"
 #include "WebGLContext.h"
 #include "WebGLProgram.h"
 #include "WebGLVertexArray.h"
 #include "WebGLVertexAttribData.h"
 
 namespace mozilla {
 
-typedef union { GLint i; GLfloat f; GLuint u; } fi_t;
-
-static inline
-GLfloat PuntToFloat(GLint i)
-{
-   fi_t tmp;
-   tmp.i = i;
-   return tmp.f;
-}
-
-static inline
-GLfloat PuntToFloat(GLuint u)
-{
-   fi_t tmp;
-   tmp.u = u;
-   return tmp.f;
-}
-
-bool
-WebGL2Context::ValidateAttribPointerType(bool integerMode, GLenum type,
-                                         GLsizei* out_alignment, const char* info)
-{
-    MOZ_ASSERT(out_alignment);
-
-    switch (type) {
-    case LOCAL_GL_BYTE:
-    case LOCAL_GL_UNSIGNED_BYTE:
-        *out_alignment = 1;
-        return true;
-
-    case LOCAL_GL_SHORT:
-    case LOCAL_GL_UNSIGNED_SHORT:
-        *out_alignment = 2;
-        return true;
-
-    case LOCAL_GL_INT:
-    case LOCAL_GL_UNSIGNED_INT:
-        *out_alignment = 4;
-        return true;
-    }
-
-    if (!integerMode) {
-        switch (type) {
-        case LOCAL_GL_HALF_FLOAT:
-            *out_alignment = 2;
-            return true;
-
-        case LOCAL_GL_FLOAT:
-        case LOCAL_GL_FIXED:
-        case LOCAL_GL_INT_2_10_10_10_REV:
-        case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
-            *out_alignment = 4;
-            return true;
-        }
-    }
-
-    ErrorInvalidEnum("%s: invalid enum value 0x%x", info, type);
-    return false;
-}
-
 bool
 WebGL2Context::ValidateUniformMatrixTranspose(bool /*transpose*/, const char* /*info*/)
 {
     return true;
 }
 
 // -------------------------------------------------------------------------
-// Uniforms and attributes
-
-void
-WebGL2Context::VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride,
-                                    GLintptr offset)
-{
-    if (IsContextLost())
-        return;
-
-    if (!ValidateAttribIndex(index, "vertexAttribIPointer"))
-        return;
-
-    if (!ValidateAttribPointer(true, index, size, type, LOCAL_GL_FALSE, stride, offset,
-                               "vertexAttribIPointer"))
-    {
-        return;
-    }
-
-    MOZ_ASSERT(mBoundVertexArray);
-    mBoundVertexArray->EnsureAttrib(index);
-
-    InvalidateBufferFetching();
-
-    WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
-
-    vd.buf = mBoundArrayBuffer;
-    vd.stride = stride;
-    vd.size = size;
-    vd.byteOffset = offset;
-    vd.type = type;
-    vd.normalized = false;
-    vd.integer = true;
-
-    MakeContextCurrent();
-    gl->fVertexAttribIPointer(index, size, type, stride, reinterpret_cast<void*>(offset));
-}
+// Uniforms
 
 void
 WebGL2Context::Uniform1ui(WebGLUniformLocation* loc, GLuint v0)
 {
     GLuint rawLoc;
     if (!ValidateUniformSetter(loc, 1, LOCAL_GL_UNSIGNED_INT, "uniform1ui", &rawLoc))
         return;
 
@@ -334,95 +239,16 @@ WebGL2Context::UniformMatrix4x3fv_base(W
     {
         return;
     }
 
     MakeContextCurrent();
     gl->fUniformMatrix4x3fv(rawLoc, numElementsToUpload, transpose, data);
 }
 
-void
-WebGL2Context::VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
-{
-    if (IsContextLost())
-        return;
-
-    if (index || gl->IsGLES()) {
-        MakeContextCurrent();
-        gl->fVertexAttribI4i(index, x, y, z, w);
-    } else {
-        mVertexAttrib0Vector[0] = PuntToFloat(x);
-        mVertexAttrib0Vector[1] = PuntToFloat(y);
-        mVertexAttrib0Vector[2] = PuntToFloat(z);
-        mVertexAttrib0Vector[3] = PuntToFloat(w);
-    }
-}
-
-void
-WebGL2Context::VertexAttribI4iv(GLuint index, size_t length, const GLint* v)
-{
-    if (!ValidateAttribArraySetter("vertexAttribI4iv", 4, length))
-        return;
-
-    if (index || gl->IsGLES()) {
-        MakeContextCurrent();
-        gl->fVertexAttribI4iv(index, v);
-    } else {
-        mVertexAttrib0Vector[0] = PuntToFloat(v[0]);
-        mVertexAttrib0Vector[1] = PuntToFloat(v[1]);
-        mVertexAttrib0Vector[2] = PuntToFloat(v[2]);
-        mVertexAttrib0Vector[3] = PuntToFloat(v[3]);
-    }
-}
-
-void
-WebGL2Context::VertexAttribI4iv(GLuint index, const dom::Sequence<GLint>& v)
-{
-    VertexAttribI4iv(index, v.Length(), v.Elements());
-}
-
-void
-WebGL2Context::VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
-{
-    if (IsContextLost())
-        return;
-
-    if (index || gl->IsGLES()) {
-        MakeContextCurrent();
-        gl->fVertexAttribI4ui(index, x, y, z, w);
-    } else {
-        mVertexAttrib0Vector[0] = PuntToFloat(x);
-        mVertexAttrib0Vector[1] = PuntToFloat(y);
-        mVertexAttrib0Vector[2] = PuntToFloat(z);
-        mVertexAttrib0Vector[3] = PuntToFloat(w);
-    }
-}
-
-void
-WebGL2Context::VertexAttribI4uiv(GLuint index, size_t length, const GLuint* v)
-{
-    if (IsContextLost())
-        return;
-
-    if (index || gl->IsGLES()) {
-        MakeContextCurrent();
-        gl->fVertexAttribI4uiv(index, v);
-    } else {
-        mVertexAttrib0Vector[0] = PuntToFloat(v[0]);
-        mVertexAttrib0Vector[1] = PuntToFloat(v[1]);
-        mVertexAttrib0Vector[2] = PuntToFloat(v[2]);
-        mVertexAttrib0Vector[3] = PuntToFloat(v[3]);
-    }
-}
-
-void
-WebGL2Context::VertexAttribI4uiv(GLuint index, const dom::Sequence<GLuint>& v)
-{
-    VertexAttribI4uiv(index, v.Length(), v.Elements());
-}
 
 // -------------------------------------------------------------------------
 // Uniform Buffer Objects and Transform Feedback Buffers
 // TODO(djg): Implemented in WebGLContext
 /*
     void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer);
     void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer,
                          GLintptr offset, GLsizeiptr size);
new file mode 100644
--- /dev/null
+++ b/dom/canvas/WebGL2ContextVertices.cpp
@@ -0,0 +1,193 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#include "WebGL2Context.h"
+
+#include "GLContext.h"
+#include "WebGLVertexArray.h"
+#include "WebGLVertexAttribData.h"
+
+namespace mozilla {
+
+typedef union { GLint i; GLfloat f; GLuint u; } fi_t;
+
+static inline
+GLfloat PuntToFloat(GLint i)
+{
+   fi_t tmp;
+   tmp.i = i;
+   return tmp.f;
+}
+
+static inline
+GLfloat PuntToFloat(GLuint u)
+{
+   fi_t tmp;
+   tmp.u = u;
+   return tmp.f;
+}
+
+bool
+WebGL2Context::ValidateAttribPointerType(bool integerMode, GLenum type,
+                                         GLsizei* out_alignment, const char* info)
+{
+  MOZ_ASSERT(out_alignment);
+
+  switch (type) {
+  case LOCAL_GL_BYTE:
+  case LOCAL_GL_UNSIGNED_BYTE:
+    *out_alignment = 1;
+    return true;
+
+  case LOCAL_GL_SHORT:
+  case LOCAL_GL_UNSIGNED_SHORT:
+    *out_alignment = 2;
+    return true;
+
+  case LOCAL_GL_INT:
+  case LOCAL_GL_UNSIGNED_INT:
+    *out_alignment = 4;
+    return true;
+  }
+
+  if (!integerMode) {
+    switch (type) {
+    case LOCAL_GL_HALF_FLOAT:
+      *out_alignment = 2;
+      return true;
+
+    case LOCAL_GL_FLOAT:
+    case LOCAL_GL_FIXED:
+    case LOCAL_GL_INT_2_10_10_10_REV:
+    case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
+      *out_alignment = 4;
+      return true;
+    }
+  }
+
+  ErrorInvalidEnum("%s: invalid enum value 0x%x", info, type);
+  return false;
+}
+
+// -------------------------------------------------------------------------
+// Vertex Attributes
+
+void
+WebGL2Context::VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride,
+                                    GLintptr offset)
+{
+  if (IsContextLost())
+    return;
+
+  if (!ValidateAttribIndex(index, "vertexAttribIPointer"))
+    return;
+
+  if (!ValidateAttribPointer(true, index, size, type, LOCAL_GL_FALSE, stride, offset,
+                             "vertexAttribIPointer"))
+  {
+    return;
+  }
+
+  MOZ_ASSERT(mBoundVertexArray);
+  mBoundVertexArray->EnsureAttrib(index);
+
+  InvalidateBufferFetching();
+
+  WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
+
+  vd.buf = mBoundArrayBuffer;
+  vd.stride = stride;
+  vd.size = size;
+  vd.byteOffset = offset;
+  vd.type = type;
+  vd.normalized = false;
+  vd.integer = true;
+
+  MakeContextCurrent();
+  gl->fVertexAttribIPointer(index, size, type, stride, reinterpret_cast<void*>(offset));
+}
+
+void
+WebGL2Context::VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
+{
+  if (IsContextLost())
+    return;
+
+  if (index || gl->IsGLES()) {
+    MakeContextCurrent();
+    gl->fVertexAttribI4i(index, x, y, z, w);
+  } else {
+    mVertexAttrib0Vector[0] = PuntToFloat(x);
+    mVertexAttrib0Vector[1] = PuntToFloat(y);
+    mVertexAttrib0Vector[2] = PuntToFloat(z);
+    mVertexAttrib0Vector[3] = PuntToFloat(w);
+  }
+}
+
+void
+WebGL2Context::VertexAttribI4iv(GLuint index, size_t length, const GLint* v)
+{
+  if (!ValidateAttribArraySetter("vertexAttribI4iv", 4, length))
+    return;
+
+  if (index || gl->IsGLES()) {
+    MakeContextCurrent();
+    gl->fVertexAttribI4iv(index, v);
+  } else {
+    mVertexAttrib0Vector[0] = PuntToFloat(v[0]);
+    mVertexAttrib0Vector[1] = PuntToFloat(v[1]);
+    mVertexAttrib0Vector[2] = PuntToFloat(v[2]);
+    mVertexAttrib0Vector[3] = PuntToFloat(v[3]);
+  }
+}
+
+void
+WebGL2Context::VertexAttribI4iv(GLuint index, const dom::Sequence<GLint>& v)
+{
+  VertexAttribI4iv(index, v.Length(), v.Elements());
+}
+
+void
+WebGL2Context::VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
+{
+  if (IsContextLost())
+    return;
+
+  if (index || gl->IsGLES()) {
+    MakeContextCurrent();
+    gl->fVertexAttribI4ui(index, x, y, z, w);
+  } else {
+    mVertexAttrib0Vector[0] = PuntToFloat(x);
+    mVertexAttrib0Vector[1] = PuntToFloat(y);
+    mVertexAttrib0Vector[2] = PuntToFloat(z);
+    mVertexAttrib0Vector[3] = PuntToFloat(w);
+  }
+}
+
+void
+WebGL2Context::VertexAttribI4uiv(GLuint index, size_t length, const GLuint* v)
+{
+  if (IsContextLost())
+    return;
+
+  if (index || gl->IsGLES()) {
+    MakeContextCurrent();
+    gl->fVertexAttribI4uiv(index, v);
+  } else {
+    mVertexAttrib0Vector[0] = PuntToFloat(v[0]);
+    mVertexAttrib0Vector[1] = PuntToFloat(v[1]);
+    mVertexAttrib0Vector[2] = PuntToFloat(v[2]);
+    mVertexAttrib0Vector[3] = PuntToFloat(v[3]);
+  }
+}
+
+void
+WebGL2Context::VertexAttribI4uiv(GLuint index, const dom::Sequence<GLuint>& v)
+{
+  VertexAttribI4uiv(index, v.Length(), v.Elements());
+}
+
+} // namespace mozilla
--- a/dom/canvas/moz.build
+++ b/dom/canvas/moz.build
@@ -62,16 +62,17 @@ UNIFIED_SOURCES += [
     'WebGL2ContextQueries.cpp',
     'WebGL2ContextSamplers.cpp',
     'WebGL2ContextState.cpp',
     'WebGL2ContextSync.cpp',
     'WebGL2ContextTextures.cpp',
     'WebGL2ContextTransformFeedback.cpp',
     'WebGL2ContextUniforms.cpp',
     'WebGL2ContextVAOs.cpp',
+    'WebGL2ContextVertices.cpp',
     'WebGLActiveInfo.cpp',
     'WebGLBuffer.cpp',
     'WebGLContext.cpp',
     'WebGLContextBuffers.cpp',
     'WebGLContextDraw.cpp',
     'WebGLContextExtensions.cpp',
     'WebGLContextFramebufferOperations.cpp',
     'WebGLContextGL.cpp',