|
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 #ifndef WEBGLVERTEXATTRIBDATA_H_ |
|
7 #define WEBGLVERTEXATTRIBDATA_H_ |
|
8 |
|
9 namespace mozilla { |
|
10 |
|
11 class WebGLBuffer; |
|
12 |
|
13 struct WebGLVertexAttribData { |
|
14 // note that these initial values are what GL initializes vertex attribs to |
|
15 WebGLVertexAttribData() |
|
16 : buf(0) |
|
17 , stride(0) |
|
18 , size(4) |
|
19 , divisor(0) // OpenGL ES 3.0 specs paragraphe 6.2 p240 |
|
20 , byteOffset(0) |
|
21 , type(LOCAL_GL_FLOAT) |
|
22 , enabled(false) |
|
23 , normalized(false) |
|
24 { } |
|
25 |
|
26 WebGLRefPtr<WebGLBuffer> buf; |
|
27 GLuint stride; |
|
28 GLuint size; |
|
29 GLuint divisor; |
|
30 GLuint byteOffset; |
|
31 GLenum type; |
|
32 bool enabled; |
|
33 bool normalized; |
|
34 |
|
35 GLuint componentSize() const { |
|
36 switch(type) { |
|
37 case LOCAL_GL_BYTE: |
|
38 return sizeof(GLbyte); |
|
39 break; |
|
40 case LOCAL_GL_UNSIGNED_BYTE: |
|
41 return sizeof(GLubyte); |
|
42 break; |
|
43 case LOCAL_GL_SHORT: |
|
44 return sizeof(GLshort); |
|
45 break; |
|
46 case LOCAL_GL_UNSIGNED_SHORT: |
|
47 return sizeof(GLushort); |
|
48 break; |
|
49 // XXX case LOCAL_GL_FIXED: |
|
50 case LOCAL_GL_FLOAT: |
|
51 return sizeof(GLfloat); |
|
52 break; |
|
53 default: |
|
54 NS_ERROR("Should never get here!"); |
|
55 return 0; |
|
56 } |
|
57 } |
|
58 |
|
59 GLuint actualStride() const { |
|
60 if (stride) return stride; |
|
61 return size * componentSize(); |
|
62 } |
|
63 }; |
|
64 |
|
65 } // namespace mozilla |
|
66 |
|
67 inline void ImplCycleCollectionUnlink(mozilla::WebGLVertexAttribData& aField) |
|
68 { |
|
69 aField.buf = nullptr; |
|
70 } |
|
71 |
|
72 inline void |
|
73 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, |
|
74 mozilla::WebGLVertexAttribData& aField, |
|
75 const char* aName, |
|
76 uint32_t aFlags = 0) |
|
77 { |
|
78 CycleCollectionNoteChild(aCallback, aField.buf.get(), aName, aFlags); |
|
79 } |
|
80 |
|
81 #endif |