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 WEBGLPROGRAM_H_ |
michael@0 | 7 | #define WEBGLPROGRAM_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "WebGLObjectModel.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsWrapperCache.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "mozilla/LinkedList.h" |
michael@0 | 14 | #include "mozilla/CheckedInt.h" |
michael@0 | 15 | #include <map> |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | class WebGLShader; |
michael@0 | 20 | class WebGLUniformInfo; |
michael@0 | 21 | |
michael@0 | 22 | typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap; |
michael@0 | 23 | typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap; |
michael@0 | 24 | |
michael@0 | 25 | class WebGLProgram MOZ_FINAL |
michael@0 | 26 | : public nsWrapperCache |
michael@0 | 27 | , public WebGLRefCountedObject<WebGLProgram> |
michael@0 | 28 | , public LinkedListElement<WebGLProgram> |
michael@0 | 29 | , public WebGLContextBoundObject |
michael@0 | 30 | { |
michael@0 | 31 | public: |
michael@0 | 32 | WebGLProgram(WebGLContext *context); |
michael@0 | 33 | |
michael@0 | 34 | ~WebGLProgram() { |
michael@0 | 35 | DeleteOnce(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | void Delete(); |
michael@0 | 39 | |
michael@0 | 40 | void DetachShaders() { |
michael@0 | 41 | mAttachedShaders.Clear(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | GLuint GLName() { return mGLName; } |
michael@0 | 45 | const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; } |
michael@0 | 46 | bool LinkStatus() { return mLinkStatus; } |
michael@0 | 47 | uint32_t Generation() const { return mGeneration.value(); } |
michael@0 | 48 | void SetLinkStatus(bool val) { mLinkStatus = val; } |
michael@0 | 49 | |
michael@0 | 50 | bool ContainsShader(WebGLShader *shader) { |
michael@0 | 51 | return mAttachedShaders.Contains(shader); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | // return true if the shader wasn't already attached |
michael@0 | 55 | bool AttachShader(WebGLShader *shader); |
michael@0 | 56 | |
michael@0 | 57 | // return true if the shader was found and removed |
michael@0 | 58 | bool DetachShader(WebGLShader *shader); |
michael@0 | 59 | |
michael@0 | 60 | bool HasAttachedShaderOfType(GLenum shaderType); |
michael@0 | 61 | |
michael@0 | 62 | bool HasBothShaderTypesAttached() { |
michael@0 | 63 | return |
michael@0 | 64 | HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) && |
michael@0 | 65 | HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | bool HasBadShaderAttached(); |
michael@0 | 69 | |
michael@0 | 70 | size_t UpperBoundNumSamplerUniforms(); |
michael@0 | 71 | |
michael@0 | 72 | bool NextGeneration() |
michael@0 | 73 | { |
michael@0 | 74 | if (!(mGeneration + 1).isValid()) |
michael@0 | 75 | return false; // must exit without changing mGeneration |
michael@0 | 76 | ++mGeneration; |
michael@0 | 77 | return true; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /* Called only after LinkProgram */ |
michael@0 | 81 | bool UpdateInfo(); |
michael@0 | 82 | |
michael@0 | 83 | /* Getters for cached program info */ |
michael@0 | 84 | bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; } |
michael@0 | 85 | |
michael@0 | 86 | /* Maps identifier |name| to the mapped identifier |*mappedName| |
michael@0 | 87 | * Both are ASCII strings. |
michael@0 | 88 | */ |
michael@0 | 89 | void MapIdentifier(const nsACString& name, nsCString *mappedName); |
michael@0 | 90 | |
michael@0 | 91 | /* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName| |
michael@0 | 92 | * Both are ASCII strings. |
michael@0 | 93 | */ |
michael@0 | 94 | void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName); |
michael@0 | 95 | |
michael@0 | 96 | /* Returns the uniform array size (or 1 if the uniform is not an array) of |
michael@0 | 97 | * the uniform with given mapped identifier. |
michael@0 | 98 | * |
michael@0 | 99 | * Note: the input string |name| is the mapped identifier, not the original identifier. |
michael@0 | 100 | */ |
michael@0 | 101 | WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name); |
michael@0 | 102 | |
michael@0 | 103 | WebGLContext *GetParentObject() const { |
michael@0 | 104 | return Context(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; |
michael@0 | 108 | |
michael@0 | 109 | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram) |
michael@0 | 110 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram) |
michael@0 | 111 | |
michael@0 | 112 | // public post-link data |
michael@0 | 113 | std::map<GLint, nsCString> mActiveAttribMap; |
michael@0 | 114 | |
michael@0 | 115 | protected: |
michael@0 | 116 | |
michael@0 | 117 | GLuint mGLName; |
michael@0 | 118 | bool mLinkStatus; |
michael@0 | 119 | // attached shaders of the program object |
michael@0 | 120 | nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders; |
michael@0 | 121 | CheckedUint32 mGeneration; |
michael@0 | 122 | |
michael@0 | 123 | // post-link data |
michael@0 | 124 | FallibleTArray<bool> mAttribsInUse; |
michael@0 | 125 | nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap; |
michael@0 | 126 | nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap; |
michael@0 | 127 | int mAttribMaxNameLength; |
michael@0 | 128 | }; |
michael@0 | 129 | |
michael@0 | 130 | } // namespace mozilla |
michael@0 | 131 | |
michael@0 | 132 | #endif |