/src/mozilla-central/dom/canvas/WebGLVertexAttribData.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "WebGLVertexAttribData.h" |
7 | | |
8 | | #include "GLContext.h" |
9 | | #include "WebGLBuffer.h" |
10 | | |
11 | | namespace mozilla { |
12 | | |
13 | | static uint8_t |
14 | | CalcBytesPerVertex(GLenum type, uint8_t size) |
15 | 0 | { |
16 | 0 | uint8_t bytesPerType; |
17 | 0 | switch (type) { |
18 | 0 | case LOCAL_GL_INT_2_10_10_10_REV: |
19 | 0 | case LOCAL_GL_UNSIGNED_INT_2_10_10_10_REV: |
20 | 0 | return 4; |
21 | 0 |
|
22 | 0 | case LOCAL_GL_BYTE: |
23 | 0 | case LOCAL_GL_UNSIGNED_BYTE: |
24 | 0 | bytesPerType = 1; |
25 | 0 | break; |
26 | 0 |
|
27 | 0 | case LOCAL_GL_HALF_FLOAT: |
28 | 0 | case LOCAL_GL_SHORT: |
29 | 0 | case LOCAL_GL_UNSIGNED_SHORT: |
30 | 0 | bytesPerType = 2; |
31 | 0 | break; |
32 | 0 |
|
33 | 0 | case LOCAL_GL_FIXED: // GLES 3.0.4 p9: 32-bit signed, with 16 fractional bits. |
34 | 0 | case LOCAL_GL_FLOAT: |
35 | 0 | case LOCAL_GL_INT: |
36 | 0 | case LOCAL_GL_UNSIGNED_INT: |
37 | 0 | bytesPerType = 4; |
38 | 0 | break; |
39 | 0 |
|
40 | 0 | default: |
41 | 0 | MOZ_CRASH("Bad `type`."); |
42 | 0 | } |
43 | 0 |
|
44 | 0 | return bytesPerType * size; |
45 | 0 | } |
46 | | |
47 | | static GLenum |
48 | | AttribPointerBaseType(bool integerFunc, GLenum type) |
49 | 0 | { |
50 | 0 | if (!integerFunc) |
51 | 0 | return LOCAL_GL_FLOAT; |
52 | 0 | |
53 | 0 | switch (type) { |
54 | 0 | case LOCAL_GL_BYTE: |
55 | 0 | case LOCAL_GL_SHORT: |
56 | 0 | case LOCAL_GL_INT: |
57 | 0 | return LOCAL_GL_INT; |
58 | 0 |
|
59 | 0 | case LOCAL_GL_UNSIGNED_BYTE: |
60 | 0 | case LOCAL_GL_UNSIGNED_SHORT: |
61 | 0 | case LOCAL_GL_UNSIGNED_INT: |
62 | 0 | return LOCAL_GL_UNSIGNED_INT; |
63 | 0 |
|
64 | 0 | default: |
65 | 0 | MOZ_CRASH(); |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | | void |
70 | | WebGLVertexAttribData::VertexAttribPointer(bool integerFunc, WebGLBuffer* buf, |
71 | | uint8_t size, GLenum type, bool normalized, |
72 | | uint32_t stride, uint64_t byteOffset) |
73 | 0 | { |
74 | 0 | mIntegerFunc = integerFunc; |
75 | 0 | WebGLBuffer::SetSlot(0, buf, &mBuf); |
76 | 0 | mType = type; |
77 | 0 | mBaseType = AttribPointerBaseType(integerFunc, type); |
78 | 0 | mSize = size; |
79 | 0 | mBytesPerVertex = CalcBytesPerVertex(mType, mSize); |
80 | 0 | mNormalized = normalized; |
81 | 0 | mStride = stride; |
82 | 0 | mExplicitStride = (mStride ? mStride : mBytesPerVertex); |
83 | 0 | mByteOffset = byteOffset; |
84 | 0 | } |
85 | | |
86 | | void |
87 | | WebGLVertexAttribData::DoVertexAttribPointer(gl::GLContext* gl, GLuint index) const |
88 | 0 | { |
89 | 0 | if (mIntegerFunc) { |
90 | 0 | gl->fVertexAttribIPointer(index, mSize, mType, mStride, |
91 | 0 | (const void*)mByteOffset); |
92 | 0 | } else { |
93 | 0 | gl->fVertexAttribPointer(index, mSize, mType, mNormalized, mStride, |
94 | 0 | (const void*)mByteOffset); |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | | } // namespace mozilla |