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 WEBGLPROGRAM_H_ michael@0: #define WEBGLPROGRAM_H_ michael@0: michael@0: #include "WebGLObjectModel.h" michael@0: michael@0: #include "nsWrapperCache.h" michael@0: michael@0: #include "mozilla/LinkedList.h" michael@0: #include "mozilla/CheckedInt.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: michael@0: class WebGLShader; michael@0: class WebGLUniformInfo; michael@0: michael@0: typedef nsDataHashtable CStringMap; michael@0: typedef nsDataHashtable CStringToUniformInfoMap; michael@0: michael@0: class WebGLProgram MOZ_FINAL michael@0: : public nsWrapperCache michael@0: , public WebGLRefCountedObject michael@0: , public LinkedListElement michael@0: , public WebGLContextBoundObject michael@0: { michael@0: public: michael@0: WebGLProgram(WebGLContext *context); michael@0: michael@0: ~WebGLProgram() { michael@0: DeleteOnce(); michael@0: } michael@0: michael@0: void Delete(); michael@0: michael@0: void DetachShaders() { michael@0: mAttachedShaders.Clear(); michael@0: } michael@0: michael@0: GLuint GLName() { return mGLName; } michael@0: const nsTArray >& AttachedShaders() const { return mAttachedShaders; } michael@0: bool LinkStatus() { return mLinkStatus; } michael@0: uint32_t Generation() const { return mGeneration.value(); } michael@0: void SetLinkStatus(bool val) { mLinkStatus = val; } michael@0: michael@0: bool ContainsShader(WebGLShader *shader) { michael@0: return mAttachedShaders.Contains(shader); michael@0: } michael@0: michael@0: // return true if the shader wasn't already attached michael@0: bool AttachShader(WebGLShader *shader); michael@0: michael@0: // return true if the shader was found and removed michael@0: bool DetachShader(WebGLShader *shader); michael@0: michael@0: bool HasAttachedShaderOfType(GLenum shaderType); michael@0: michael@0: bool HasBothShaderTypesAttached() { michael@0: return michael@0: HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) && michael@0: HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER); michael@0: } michael@0: michael@0: bool HasBadShaderAttached(); michael@0: michael@0: size_t UpperBoundNumSamplerUniforms(); michael@0: michael@0: bool NextGeneration() michael@0: { michael@0: if (!(mGeneration + 1).isValid()) michael@0: return false; // must exit without changing mGeneration michael@0: ++mGeneration; michael@0: return true; michael@0: } michael@0: michael@0: /* Called only after LinkProgram */ michael@0: bool UpdateInfo(); michael@0: michael@0: /* Getters for cached program info */ michael@0: bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; } michael@0: michael@0: /* Maps identifier |name| to the mapped identifier |*mappedName| michael@0: * Both are ASCII strings. michael@0: */ michael@0: void MapIdentifier(const nsACString& name, nsCString *mappedName); michael@0: michael@0: /* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName| michael@0: * Both are ASCII strings. michael@0: */ michael@0: void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName); michael@0: michael@0: /* Returns the uniform array size (or 1 if the uniform is not an array) of michael@0: * the uniform with given mapped identifier. michael@0: * michael@0: * Note: the input string |name| is the mapped identifier, not the original identifier. michael@0: */ michael@0: WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name); michael@0: michael@0: WebGLContext *GetParentObject() const { michael@0: return Context(); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE; michael@0: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram) michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram) michael@0: michael@0: // public post-link data michael@0: std::map mActiveAttribMap; michael@0: michael@0: protected: michael@0: michael@0: GLuint mGLName; michael@0: bool mLinkStatus; michael@0: // attached shaders of the program object michael@0: nsTArray > mAttachedShaders; michael@0: CheckedUint32 mGeneration; michael@0: michael@0: // post-link data michael@0: FallibleTArray mAttribsInUse; michael@0: nsAutoPtr mIdentifierMap, mIdentifierReverseMap; michael@0: nsAutoPtr mUniformInfoMap; michael@0: int mAttribMaxNameLength; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif