Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef WEBGLVERTEXATTRIBDATA_H_ |
michael@0 | 7 | #define WEBGLVERTEXATTRIBDATA_H_ |
michael@0 | 8 | |
michael@0 | 9 | namespace mozilla { |
michael@0 | 10 | |
michael@0 | 11 | class WebGLBuffer; |
michael@0 | 12 | |
michael@0 | 13 | struct WebGLVertexAttribData { |
michael@0 | 14 | // note that these initial values are what GL initializes vertex attribs to |
michael@0 | 15 | WebGLVertexAttribData() |
michael@0 | 16 | : buf(0) |
michael@0 | 17 | , stride(0) |
michael@0 | 18 | , size(4) |
michael@0 | 19 | , divisor(0) // OpenGL ES 3.0 specs paragraphe 6.2 p240 |
michael@0 | 20 | , byteOffset(0) |
michael@0 | 21 | , type(LOCAL_GL_FLOAT) |
michael@0 | 22 | , enabled(false) |
michael@0 | 23 | , normalized(false) |
michael@0 | 24 | { } |
michael@0 | 25 | |
michael@0 | 26 | WebGLRefPtr<WebGLBuffer> buf; |
michael@0 | 27 | GLuint stride; |
michael@0 | 28 | GLuint size; |
michael@0 | 29 | GLuint divisor; |
michael@0 | 30 | GLuint byteOffset; |
michael@0 | 31 | GLenum type; |
michael@0 | 32 | bool enabled; |
michael@0 | 33 | bool normalized; |
michael@0 | 34 | |
michael@0 | 35 | GLuint componentSize() const { |
michael@0 | 36 | switch(type) { |
michael@0 | 37 | case LOCAL_GL_BYTE: |
michael@0 | 38 | return sizeof(GLbyte); |
michael@0 | 39 | break; |
michael@0 | 40 | case LOCAL_GL_UNSIGNED_BYTE: |
michael@0 | 41 | return sizeof(GLubyte); |
michael@0 | 42 | break; |
michael@0 | 43 | case LOCAL_GL_SHORT: |
michael@0 | 44 | return sizeof(GLshort); |
michael@0 | 45 | break; |
michael@0 | 46 | case LOCAL_GL_UNSIGNED_SHORT: |
michael@0 | 47 | return sizeof(GLushort); |
michael@0 | 48 | break; |
michael@0 | 49 | // XXX case LOCAL_GL_FIXED: |
michael@0 | 50 | case LOCAL_GL_FLOAT: |
michael@0 | 51 | return sizeof(GLfloat); |
michael@0 | 52 | break; |
michael@0 | 53 | default: |
michael@0 | 54 | NS_ERROR("Should never get here!"); |
michael@0 | 55 | return 0; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | GLuint actualStride() const { |
michael@0 | 60 | if (stride) return stride; |
michael@0 | 61 | return size * componentSize(); |
michael@0 | 62 | } |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | } // namespace mozilla |
michael@0 | 66 | |
michael@0 | 67 | inline void ImplCycleCollectionUnlink(mozilla::WebGLVertexAttribData& aField) |
michael@0 | 68 | { |
michael@0 | 69 | aField.buf = nullptr; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | inline void |
michael@0 | 73 | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, |
michael@0 | 74 | mozilla::WebGLVertexAttribData& aField, |
michael@0 | 75 | const char* aName, |
michael@0 | 76 | uint32_t aFlags = 0) |
michael@0 | 77 | { |
michael@0 | 78 | CycleCollectionNoteChild(aCallback, aField.buf.get(), aName, aFlags); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | #endif |