Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / canvas / src / WebGLVertexAttribData.h
blob86f4233b358bd91bc23d87c17dea8815c9c2c384
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/. */
6 #ifndef WEBGLVERTEXATTRIBDATA_H_
7 #define WEBGLVERTEXATTRIBDATA_H_
9 namespace mozilla {
11 class WebGLBuffer;
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 { }
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;
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;
59 GLuint actualStride() const {
60 if (stride) return stride;
61 return size * componentSize();
65 } // namespace mozilla
67 inline void ImplCycleCollectionUnlink(mozilla::WebGLVertexAttribData& aField)
69 aField.buf = nullptr;
72 inline void
73 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
74 mozilla::WebGLVertexAttribData& aField,
75 const char* aName,
76 uint32_t aFlags = 0)
78 CycleCollectionNoteChild(aCallback, aField.buf.get(), aName, aFlags);
81 #endif