2012-12-09 00:41:02 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WEBGLPROGRAM_H_
|
|
|
|
#define WEBGLPROGRAM_H_
|
|
|
|
|
|
|
|
#include "WebGLObjectModel.h"
|
|
|
|
|
2014-05-22 06:03:09 +04:00
|
|
|
#include <map>
|
2012-12-09 00:41:02 +04:00
|
|
|
|
2014-05-13 06:11:40 +04:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2014-05-22 06:03:09 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "WebGLShader.h"
|
|
|
|
#include "WebGLUniformInfo.h"
|
2012-12-09 00:41:02 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
class WebGLShader;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct WebGLUniformInfo;
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2012-12-09 00:41:02 +04:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> CStringMap;
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, WebGLUniformInfo> CStringToUniformInfoMap;
|
|
|
|
|
|
|
|
class WebGLProgram MOZ_FINAL
|
2013-08-29 19:39:17 +04:00
|
|
|
: public nsWrapperCache
|
2012-12-09 00:41:02 +04:00
|
|
|
, public WebGLRefCountedObject<WebGLProgram>
|
|
|
|
, public LinkedListElement<WebGLProgram>
|
|
|
|
, public WebGLContextBoundObject
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit WebGLProgram(WebGLContext* aContext);
|
2012-12-09 00:41:02 +04:00
|
|
|
|
|
|
|
void Delete();
|
|
|
|
|
|
|
|
void DetachShaders() {
|
|
|
|
mAttachedShaders.Clear();
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint GLName() { return mGLName; }
|
2012-12-09 00:41:02 +04:00
|
|
|
const nsTArray<WebGLRefPtr<WebGLShader> >& AttachedShaders() const { return mAttachedShaders; }
|
|
|
|
bool LinkStatus() { return mLinkStatus; }
|
|
|
|
uint32_t Generation() const { return mGeneration.value(); }
|
|
|
|
void SetLinkStatus(bool val) { mLinkStatus = val; }
|
|
|
|
|
|
|
|
bool ContainsShader(WebGLShader *shader) {
|
|
|
|
return mAttachedShaders.Contains(shader);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return true if the shader wasn't already attached
|
|
|
|
bool AttachShader(WebGLShader *shader);
|
|
|
|
|
|
|
|
// return true if the shader was found and removed
|
|
|
|
bool DetachShader(WebGLShader *shader);
|
|
|
|
|
|
|
|
bool HasAttachedShaderOfType(GLenum shaderType);
|
|
|
|
|
|
|
|
bool HasBothShaderTypesAttached() {
|
|
|
|
return
|
|
|
|
HasAttachedShaderOfType(LOCAL_GL_VERTEX_SHADER) &&
|
|
|
|
HasAttachedShaderOfType(LOCAL_GL_FRAGMENT_SHADER);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasBadShaderAttached();
|
|
|
|
|
|
|
|
size_t UpperBoundNumSamplerUniforms();
|
|
|
|
|
|
|
|
bool NextGeneration()
|
|
|
|
{
|
|
|
|
if (!(mGeneration + 1).isValid())
|
|
|
|
return false; // must exit without changing mGeneration
|
|
|
|
++mGeneration;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called only after LinkProgram */
|
|
|
|
bool UpdateInfo();
|
|
|
|
|
|
|
|
/* Getters for cached program info */
|
|
|
|
bool IsAttribInUse(unsigned i) const { return mAttribsInUse[i]; }
|
|
|
|
|
|
|
|
/* Maps identifier |name| to the mapped identifier |*mappedName|
|
|
|
|
* Both are ASCII strings.
|
|
|
|
*/
|
|
|
|
void MapIdentifier(const nsACString& name, nsCString *mappedName);
|
|
|
|
|
|
|
|
/* Un-maps mapped identifier |name| to the original identifier |*reverseMappedName|
|
|
|
|
* Both are ASCII strings.
|
|
|
|
*/
|
|
|
|
void ReverseMapIdentifier(const nsACString& name, nsCString *reverseMappedName);
|
|
|
|
|
|
|
|
/* Returns the uniform array size (or 1 if the uniform is not an array) of
|
|
|
|
* the uniform with given mapped identifier.
|
|
|
|
*
|
|
|
|
* Note: the input string |name| is the mapped identifier, not the original identifier.
|
|
|
|
*/
|
|
|
|
WebGLUniformInfo GetUniformInfoForMappedIdentifier(const nsACString& name);
|
|
|
|
|
|
|
|
WebGLContext *GetParentObject() const {
|
|
|
|
return Context();
|
|
|
|
}
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
|
2012-12-09 00:41:02 +04:00
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram)
|
2012-12-09 00:41:02 +04:00
|
|
|
|
2013-08-27 17:01:44 +04:00
|
|
|
// public post-link data
|
|
|
|
std::map<GLint, nsCString> mActiveAttribMap;
|
|
|
|
|
2014-05-14 04:15:19 +04:00
|
|
|
static uint64_t IdentifierHashFunction(const char *ident, size_t size);
|
|
|
|
static void HashMapIdentifier(const nsACString& name, nsCString *hashedName);
|
|
|
|
|
2012-12-09 00:41:02 +04:00
|
|
|
protected:
|
2014-06-26 17:30:49 +04:00
|
|
|
~WebGLProgram() {
|
|
|
|
DeleteOnce();
|
|
|
|
}
|
2012-12-09 00:41:02 +04:00
|
|
|
|
2013-09-04 16:14:43 +04:00
|
|
|
GLuint mGLName;
|
2012-12-09 00:41:02 +04:00
|
|
|
bool mLinkStatus;
|
|
|
|
// attached shaders of the program object
|
|
|
|
nsTArray<WebGLRefPtr<WebGLShader> > mAttachedShaders;
|
|
|
|
CheckedUint32 mGeneration;
|
|
|
|
|
|
|
|
// post-link data
|
2014-02-10 03:16:38 +04:00
|
|
|
FallibleTArray<bool> mAttribsInUse;
|
2012-12-09 00:41:02 +04:00
|
|
|
nsAutoPtr<CStringMap> mIdentifierMap, mIdentifierReverseMap;
|
|
|
|
nsAutoPtr<CStringToUniformInfoMap> mUniformInfoMap;
|
|
|
|
int mAttribMaxNameLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|