Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLProgram.h
blobddd2cb0f00d81bffa9182fdff7dbaca3a7087677
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 WEBGLPROGRAM_H_
7 #define WEBGLPROGRAM_H_
9 #include "WebGLObjectModel.h"
11 #include <map>
13 #include "mozilla/CheckedInt.h"
14 #include "mozilla/LinkedList.h"
15 #include "nsWrapperCache.h"
16 #include "WebGLShader.h"
17 #include "WebGLUniformInfo.h"
19 namespace mozilla {
21 class WebGLShader;
22 struct WebGLUniformInfo;
24 typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
25 typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;
27 class WebGLProgram MOZ_FINAL
28 : public nsWrapperCache
29 , public WebGLRefCountedObject<WebGLProgram>
30 , public LinkedListElement<WebGLProgram>
31 , public WebGLContextBoundObject
33 public:
34 WebGLProgram(WebGLContext *context);
36 void Delete();
38 void DetachShaders() {
39 mAttachedShaders.Clear();
42 GLuint GLName() { return mGLName; }
43 const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; }
44 bool LinkStatus() { return mLinkStatus; }
45 uint32_t Generation() const { return mGeneration.value(); }
46 void SetLinkStatus(bool val) { mLinkStatus = val; }
48 bool ContainsShader(WebGLShader *shader) {
49 return mAttachedShaders.Contains(shader);
52 // return true if the shader wasn't already attached
53 bool AttachShader(WebGLShader *shader);
55 // return true if the shader was found and removed
56 bool DetachShader(WebGLShader *shader);
58 bool HasAttachedShaderOfType(GLenum shaderType);
60 bool HasBothShaderTypesAttached() {
61 return
62 HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) &&
63 HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER);
66 bool HasBadShaderAttached();
68 size_t UpperBoundNumSamplerUniforms();
70 bool NextGeneration()
72 if (!(mGeneration + 1).isValid())
73 return false; // must exit without changing mGeneration
74 ++mGeneration;
75 return true;
78 /* Called only after LinkProgram */
79 bool UpdateInfo();
81 /* Getters for cached program info */
82 bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; }
84 /* Maps identifier |name| to the mapped identifier |*mappedName|
85 * Both are ASCII strings.
87 void MapIdentifier(const nsACString& name, nsCString *mappedName);
89 /* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName|
90 * Both are ASCII strings.
92 void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName);
94 /* Returns the uniform array size (or 1 if the uniform is not an array) of
95 * the uniform with given mapped identifier.
97 * Note: the input string |name| is the mapped identifier, not the original identifier.
99 WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name);
101 WebGLContext *GetParentObject() const {
102 return Context();
105 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
107 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
108 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram)
110 // public post-link data
111 std::map<GLint, nsCString> mActiveAttribMap;
113 static uint64_t IdentifierHashFunction(const char *ident, size_t size);
114 static void HashMapIdentifier(const nsACString& name, nsCString *hashedName);
116 protected:
117 ~WebGLProgram() {
118 DeleteOnce();
121 GLuint mGLName;
122 bool mLinkStatus;
123 // attached shaders of the program object
124 nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders;
125 CheckedUint32 mGeneration;
127 // post-link data
128 FallibleTArray<bool> mAttribsInUse;
129 nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap;
130 nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap;
131 int mAttribMaxNameLength;
134 } // namespace mozilla
136 #endif