summaryrefslogtreecommitdiffstats
path: root/dom/canvas/WebGLVertexAttribData.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/canvas/WebGLVertexAttribData.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/canvas/WebGLVertexAttribData.cpp')
-rw-r--r--dom/canvas/WebGLVertexAttribData.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/dom/canvas/WebGLVertexAttribData.cpp b/dom/canvas/WebGLVertexAttribData.cpp
new file mode 100644
index 000000000..b5aee18e5
--- /dev/null
+++ b/dom/canvas/WebGLVertexAttribData.cpp
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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 "WebGLVertexAttribData.h"
+
+#include "GLContext.h"
+#include "WebGLBuffer.h"
+
+namespace mozilla {
+
+static uint8_t
+CalcBytesPerVertex(GLenum type, uint8_t size)
+{
+ uint8_t bytesPerType;
+ switch (type) {
+ case LOCAL_GL_INT_2_10_10_10_REV:
+ case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV:
+ return 4;
+
+ case LOCAL_GL_BYTE:
+ case LOCAL_GL_UNSIGNED_BYTE:
+ bytesPerType = 1;
+ break;
+
+ case LOCAL_GL_HALF_FLOAT:
+ case LOCAL_GL_SHORT:
+ case LOCAL_GL_UNSIGNED_SHORT:
+ bytesPerType = 2;
+ break;
+
+ case LOCAL_GL_FIXED: // GLES 3.0.4 p9: 32-bit signed, with 16 fractional bits.
+ case LOCAL_GL_FLOAT:
+ case LOCAL_GL_INT:
+ case LOCAL_GL_UNSIGNED_INT:
+ bytesPerType = 4;
+ break;
+
+ default:
+ MOZ_CRASH("Bad `type`.");
+ }
+
+ return bytesPerType * size;
+}
+
+static GLenum
+AttribPointerBaseType(bool integerFunc, GLenum type)
+{
+ if (!integerFunc)
+ return LOCAL_GL_FLOAT;
+
+ switch (type) {
+ case LOCAL_GL_BYTE:
+ case LOCAL_GL_SHORT:
+ case LOCAL_GL_INT:
+ return LOCAL_GL_INT;
+
+ case LOCAL_GL_UNSIGNED_BYTE:
+ case LOCAL_GL_UNSIGNED_SHORT:
+ case LOCAL_GL_UNSIGNED_INT:
+ return LOCAL_GL_UNSIGNED_INT;
+
+ default:
+ MOZ_CRASH();
+ }
+}
+
+void
+WebGLVertexAttribData::VertexAttribPointer(bool integerFunc, WebGLBuffer* buf,
+ uint8_t size, GLenum type, bool normalized,
+ uint32_t stride, uint64_t byteOffset)
+{
+ mIntegerFunc = integerFunc;
+ WebGLBuffer::SetSlot(0, buf, &mBuf);
+ mType = type;
+ mBaseType = AttribPointerBaseType(integerFunc, type);
+ mSize = size;
+ mBytesPerVertex = CalcBytesPerVertex(mType, mSize);
+ mNormalized = normalized;
+ mStride = stride;
+ mExplicitStride = (mStride ? mStride : mBytesPerVertex);
+ mByteOffset = byteOffset;
+}
+
+void
+WebGLVertexAttribData::DoVertexAttribPointer(gl::GLContext* gl, GLuint index) const
+{
+ if (mIntegerFunc) {
+ gl->fVertexAttribIPointer(index, mSize, mType, mStride,
+ (const void*)mByteOffset);
+ } else {
+ gl->fVertexAttribPointer(index, mSize, mType, mNormalized, mStride,
+ (const void*)mByteOffset);
+ }
+}
+
+} // namespace mozilla