1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/src/WebGLVertexAttribData.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef WEBGLVERTEXATTRIBDATA_H_ 1.10 +#define WEBGLVERTEXATTRIBDATA_H_ 1.11 + 1.12 +namespace mozilla { 1.13 + 1.14 +class WebGLBuffer; 1.15 + 1.16 +struct WebGLVertexAttribData { 1.17 + // note that these initial values are what GL initializes vertex attribs to 1.18 + WebGLVertexAttribData() 1.19 + : buf(0) 1.20 + , stride(0) 1.21 + , size(4) 1.22 + , divisor(0) // OpenGL ES 3.0 specs paragraphe 6.2 p240 1.23 + , byteOffset(0) 1.24 + , type(LOCAL_GL_FLOAT) 1.25 + , enabled(false) 1.26 + , normalized(false) 1.27 + { } 1.28 + 1.29 + WebGLRefPtr<WebGLBuffer> buf; 1.30 + GLuint stride; 1.31 + GLuint size; 1.32 + GLuint divisor; 1.33 + GLuint byteOffset; 1.34 + GLenum type; 1.35 + bool enabled; 1.36 + bool normalized; 1.37 + 1.38 + GLuint componentSize() const { 1.39 + switch(type) { 1.40 + case LOCAL_GL_BYTE: 1.41 + return sizeof(GLbyte); 1.42 + break; 1.43 + case LOCAL_GL_UNSIGNED_BYTE: 1.44 + return sizeof(GLubyte); 1.45 + break; 1.46 + case LOCAL_GL_SHORT: 1.47 + return sizeof(GLshort); 1.48 + break; 1.49 + case LOCAL_GL_UNSIGNED_SHORT: 1.50 + return sizeof(GLushort); 1.51 + break; 1.52 + // XXX case LOCAL_GL_FIXED: 1.53 + case LOCAL_GL_FLOAT: 1.54 + return sizeof(GLfloat); 1.55 + break; 1.56 + default: 1.57 + NS_ERROR("Should never get here!"); 1.58 + return 0; 1.59 + } 1.60 + } 1.61 + 1.62 + GLuint actualStride() const { 1.63 + if (stride) return stride; 1.64 + return size * componentSize(); 1.65 + } 1.66 +}; 1.67 + 1.68 +} // namespace mozilla 1.69 + 1.70 +inline void ImplCycleCollectionUnlink(mozilla::WebGLVertexAttribData& aField) 1.71 +{ 1.72 + aField.buf = nullptr; 1.73 +} 1.74 + 1.75 +inline void 1.76 +ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, 1.77 + mozilla::WebGLVertexAttribData& aField, 1.78 + const char* aName, 1.79 + uint32_t aFlags = 0) 1.80 +{ 1.81 + CycleCollectionNoteChild(aCallback, aField.buf.get(), aName, aFlags); 1.82 +} 1.83 + 1.84 +#endif 1.85 \ No newline at end of file