michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef WEBGLVERTEXATTRIBDATA_H_ michael@0: #define WEBGLVERTEXATTRIBDATA_H_ michael@0: michael@0: namespace mozilla { michael@0: michael@0: class WebGLBuffer; michael@0: michael@0: struct WebGLVertexAttribData { michael@0: // note that these initial values are what GL initializes vertex attribs to michael@0: WebGLVertexAttribData() michael@0: : buf(0) michael@0: , stride(0) michael@0: , size(4) michael@0: , divisor(0) // OpenGL ES 3.0 specs paragraphe 6.2 p240 michael@0: , byteOffset(0) michael@0: , type(LOCAL_GL_FLOAT) michael@0: , enabled(false) michael@0: , normalized(false) michael@0: { } michael@0: michael@0: WebGLRefPtr buf; michael@0: GLuint stride; michael@0: GLuint size; michael@0: GLuint divisor; michael@0: GLuint byteOffset; michael@0: GLenum type; michael@0: bool enabled; michael@0: bool normalized; michael@0: michael@0: GLuint componentSize() const { michael@0: switch(type) { michael@0: case LOCAL_GL_BYTE: michael@0: return sizeof(GLbyte); michael@0: break; michael@0: case LOCAL_GL_UNSIGNED_BYTE: michael@0: return sizeof(GLubyte); michael@0: break; michael@0: case LOCAL_GL_SHORT: michael@0: return sizeof(GLshort); michael@0: break; michael@0: case LOCAL_GL_UNSIGNED_SHORT: michael@0: return sizeof(GLushort); michael@0: break; michael@0: // XXX case LOCAL_GL_FIXED: michael@0: case LOCAL_GL_FLOAT: michael@0: return sizeof(GLfloat); michael@0: break; michael@0: default: michael@0: NS_ERROR("Should never get here!"); michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: GLuint actualStride() const { michael@0: if (stride) return stride; michael@0: return size * componentSize(); michael@0: } michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: inline void ImplCycleCollectionUnlink(mozilla::WebGLVertexAttribData& aField) michael@0: { michael@0: aField.buf = nullptr; michael@0: } michael@0: michael@0: inline void michael@0: ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, michael@0: mozilla::WebGLVertexAttribData& aField, michael@0: const char* aName, michael@0: uint32_t aFlags = 0) michael@0: { michael@0: CycleCollectionNoteChild(aCallback, aField.buf.get(), aName, aFlags); michael@0: } michael@0: michael@0: #endif