2012-12-08 20:41:02 +00: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/. */
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
#ifndef WEBGL_PROGRAM_H_
|
|
|
|
#define WEBGL_PROGRAM_H_
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2014-05-22 02:03:09 +00:00
|
|
|
#include <map>
|
2015-07-15 00:37:28 +00:00
|
|
|
#include <set>
|
2016-01-08 02:12:22 +00:00
|
|
|
#include <string>
|
2015-07-15 00:37:28 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-05-22 02:03:09 +00:00
|
|
|
#include "mozilla/LinkedList.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-07-15 00:37:28 +00:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2015-01-15 23:40:39 +00:00
|
|
|
#include "nsString.h"
|
2014-05-22 02:03:09 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2015-07-15 00:37:28 +00:00
|
|
|
|
2017-10-20 22:40:12 +00:00
|
|
|
#include "CacheMap.h"
|
2016-07-22 06:25:41 +00:00
|
|
|
#include "WebGLContext.h"
|
2014-11-14 04:03:50 +00:00
|
|
|
#include "WebGLObjectModel.h"
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2015-07-15 00:37:28 +00:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2015-01-15 23:40:39 +00:00
|
|
|
class WebGLActiveInfo;
|
|
|
|
class WebGLProgram;
|
2015-07-15 00:37:28 +00:00
|
|
|
class WebGLShader;
|
2015-01-15 23:40:39 +00:00
|
|
|
class WebGLUniformLocation;
|
2013-06-10 20:00:35 +00:00
|
|
|
|
2015-07-15 00:37:28 +00:00
|
|
|
namespace dom {
|
|
|
|
template<typename> struct Nullable;
|
|
|
|
class OwningUnsignedLongOrUint32ArrayOrBoolean;
|
|
|
|
template<typename> class Sequence;
|
|
|
|
} // namespace dom
|
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
namespace webgl {
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-07-14 19:04:31 +00:00
|
|
|
struct AttribInfo final
|
2015-03-18 03:30:52 +00:00
|
|
|
{
|
2016-07-14 19:04:31 +00:00
|
|
|
const RefPtr<WebGLActiveInfo> mActiveInfo;
|
2016-12-23 21:29:07 +00:00
|
|
|
const GLint mLoc; // -1 for active built-ins
|
2016-12-22 03:42:07 +00:00
|
|
|
const GLenum mBaseType;
|
2016-07-14 19:04:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UniformInfo final
|
|
|
|
{
|
|
|
|
typedef decltype(WebGLContext::mBound2DTextures) TexListT;
|
|
|
|
|
|
|
|
const RefPtr<WebGLActiveInfo> mActiveInfo;
|
|
|
|
const TexListT* const mSamplerTexList;
|
|
|
|
std::vector<uint32_t> mSamplerValues;
|
2015-03-18 03:30:52 +00:00
|
|
|
|
2016-07-14 19:04:31 +00:00
|
|
|
protected:
|
|
|
|
static const TexListT*
|
|
|
|
GetTexList(WebGLActiveInfo* activeInfo);
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit UniformInfo(WebGLActiveInfo* activeInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UniformBlockInfo final
|
|
|
|
{
|
2016-12-23 21:29:07 +00:00
|
|
|
const nsCString mUserName;
|
|
|
|
const nsCString mMappedName;
|
2016-09-10 04:02:54 +00:00
|
|
|
const uint32_t mDataSize;
|
2015-03-18 03:30:52 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
const IndexedBufferBinding* mBinding;
|
|
|
|
|
2016-12-23 21:29:07 +00:00
|
|
|
UniformBlockInfo(WebGLContext* webgl, const nsACString& userName,
|
|
|
|
const nsACString& mappedName, uint32_t dataSize)
|
|
|
|
: mUserName(userName)
|
|
|
|
, mMappedName(mappedName)
|
2016-09-10 04:02:54 +00:00
|
|
|
, mDataSize(dataSize)
|
|
|
|
, mBinding(&webgl->mIndexedUniformBufferBindings[0])
|
|
|
|
{ }
|
2015-03-18 03:30:52 +00:00
|
|
|
};
|
|
|
|
|
2017-10-20 22:40:12 +00:00
|
|
|
struct CachedDrawFetchLimits final {
|
|
|
|
uint64_t maxVerts;
|
|
|
|
uint64_t maxInstances;
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
struct LinkedProgramInfo final
|
2015-01-15 23:40:39 +00:00
|
|
|
: public RefCounted<LinkedProgramInfo>
|
|
|
|
, public SupportsWeakPtr<LinkedProgramInfo>
|
2012-12-08 20:41:02 +00:00
|
|
|
{
|
2016-09-10 04:02:54 +00:00
|
|
|
friend class WebGLProgram;
|
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(LinkedProgramInfo)
|
2015-04-24 16:43:01 +00:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LinkedProgramInfo)
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-07-14 19:04:31 +00:00
|
|
|
//////
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-07-14 19:04:31 +00:00
|
|
|
WebGLProgram* const prog;
|
2016-12-29 08:08:39 +00:00
|
|
|
const GLenum transformFeedbackBufferMode;
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-07-14 19:04:31 +00:00
|
|
|
std::vector<AttribInfo> attribs;
|
|
|
|
std::vector<UniformInfo*> uniforms; // Owns its contents.
|
2016-09-10 04:02:54 +00:00
|
|
|
std::vector<UniformBlockInfo*> uniformBlocks; // Owns its contents.
|
2016-07-14 19:04:31 +00:00
|
|
|
std::vector<RefPtr<WebGLActiveInfo>> transformFeedbackVaryings;
|
2015-03-18 03:30:52 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
// Needed for draw call validation.
|
2016-07-14 19:04:31 +00:00
|
|
|
std::vector<UniformInfo*> uniformSamplers;
|
2016-07-07 16:12:10 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
mutable std::vector<size_t> componentsPerTFVert;
|
|
|
|
|
2017-10-20 22:40:12 +00:00
|
|
|
bool attrib0Active;
|
|
|
|
|
2016-07-07 16:12:10 +00:00
|
|
|
//////
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-07-18 12:19:04 +00:00
|
|
|
// The maps for the frag data names to the translated names.
|
|
|
|
std::map<nsCString, const nsCString> fragDataMap;
|
|
|
|
|
2017-10-20 22:40:12 +00:00
|
|
|
//////
|
|
|
|
|
|
|
|
mutable CacheMap<const WebGLVertexArray*,
|
|
|
|
CachedDrawFetchLimits> mDrawFetchCache;
|
|
|
|
|
|
|
|
const CachedDrawFetchLimits* GetDrawFetchLimits(const char* funcName) const;
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2015-07-15 00:37:28 +00:00
|
|
|
explicit LinkedProgramInfo(WebGLProgram* prog);
|
2016-07-14 19:04:31 +00:00
|
|
|
~LinkedProgramInfo();
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-12-22 00:40:42 +00:00
|
|
|
bool FindAttrib(const nsCString& userName, const AttribInfo** const out_info) const;
|
|
|
|
bool FindUniform(const nsCString& userName, nsCString* const out_mappedName,
|
|
|
|
size_t* const out_arrayIndex, UniformInfo** const out_info) const;
|
|
|
|
bool MapFragDataName(const nsCString& userName,
|
|
|
|
nsCString* const out_mappedName) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
};
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
} // namespace webgl
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class WebGLProgram final
|
2015-01-15 23:40:39 +00:00
|
|
|
: public nsWrapperCache
|
|
|
|
, public WebGLRefCountedObject<WebGLProgram>
|
|
|
|
, public LinkedListElement<WebGLProgram>
|
|
|
|
{
|
2016-09-10 04:02:54 +00:00
|
|
|
friend class WebGLTransformFeedback;
|
2016-12-22 03:42:07 +00:00
|
|
|
friend struct webgl::LinkedProgramInfo;
|
2016-09-10 04:02:54 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLProgram)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLProgram)
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
explicit WebGLProgram(WebGLContext* webgl);
|
2015-01-10 05:03:54 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
void Delete();
|
2015-01-13 08:07:26 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
// GL funcs
|
|
|
|
void AttachShader(WebGLShader* shader);
|
|
|
|
void BindAttribLocation(GLuint index, const nsAString& name);
|
2016-11-01 21:58:07 +00:00
|
|
|
void DetachShader(const WebGLShader* shader);
|
2015-01-15 23:40:39 +00:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveAttrib(GLuint index) const;
|
|
|
|
already_AddRefed<WebGLActiveInfo> GetActiveUniform(GLuint index) const;
|
2015-10-18 05:24:48 +00:00
|
|
|
void GetAttachedShaders(nsTArray<RefPtr<WebGLShader>>* const out) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
GLint GetAttribLocation(const nsAString& name) const;
|
2015-01-27 01:10:25 +00:00
|
|
|
GLint GetFragDataLocation(const nsAString& name) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
void GetProgramInfoLog(nsAString* const out) const;
|
|
|
|
JS::Value GetProgramParameter(GLenum pname) const;
|
2015-03-18 03:30:52 +00:00
|
|
|
GLuint GetUniformBlockIndex(const nsAString& name) const;
|
|
|
|
void GetActiveUniformBlockName(GLuint uniformBlockIndex, nsAString& name) const;
|
2016-10-14 22:59:27 +00:00
|
|
|
JS::Value GetActiveUniformBlockParam(GLuint uniformBlockIndex, GLenum pname) const;
|
|
|
|
JS::Value GetActiveUniformBlockActiveUniforms(JSContext* cx, GLuint uniformBlockIndex,
|
|
|
|
ErrorResult* const out_error) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
already_AddRefed<WebGLUniformLocation> GetUniformLocation(const nsAString& name) const;
|
2015-11-03 16:02:30 +00:00
|
|
|
void GetUniformIndices(const dom::Sequence<nsString>& uniformNames,
|
|
|
|
dom::Nullable< nsTArray<GLuint> >& retval) const;
|
2015-03-18 03:30:52 +00:00
|
|
|
void UniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) const;
|
|
|
|
|
2016-04-20 19:02:07 +00:00
|
|
|
void LinkProgram();
|
2015-01-15 23:40:39 +00:00
|
|
|
bool UseProgram() const;
|
|
|
|
void ValidateProgram() const;
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
bool FindAttribUserNameByMappedName(const nsACString& mappedName,
|
2016-12-23 21:29:07 +00:00
|
|
|
nsCString* const out_userName) const;
|
2015-11-14 03:27:17 +00:00
|
|
|
bool FindVaryingByMappedName(const nsACString& mappedName,
|
|
|
|
nsCString* const out_userName,
|
|
|
|
bool* const out_isArray) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
bool FindUniformByMappedName(const nsACString& mappedName,
|
|
|
|
nsCString* const out_userName,
|
|
|
|
bool* const out_isArray) const;
|
2016-12-23 21:29:07 +00:00
|
|
|
bool UnmapUniformBlockName(const nsCString& mappedName,
|
|
|
|
nsCString* const out_userName) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
|
2015-04-21 01:02:34 +00:00
|
|
|
void TransformFeedbackVaryings(const dom::Sequence<nsString>& varyings,
|
|
|
|
GLenum bufferMode);
|
2016-09-10 04:02:54 +00:00
|
|
|
already_AddRefed<WebGLActiveInfo> GetTransformFeedbackVarying(GLuint index) const;
|
2015-04-21 01:02:34 +00:00
|
|
|
|
2016-07-18 12:19:04 +00:00
|
|
|
void EnumerateFragOutputs(std::map<nsCString, const nsCString> &out_FragOutputs) const;
|
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
bool IsLinked() const { return mMostRecentLinkInfo; }
|
|
|
|
|
|
|
|
const webgl::LinkedProgramInfo* LinkInfo() const {
|
|
|
|
return mMostRecentLinkInfo.get();
|
|
|
|
}
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLContext* GetParentObject() const {
|
2015-11-25 04:15:29 +00:00
|
|
|
return mContext;
|
2012-12-08 20:41:02 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 00:37:28 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* js, JS::Handle<JSObject*> givenProto) override;
|
2014-05-14 00:15:19 +00:00
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
private:
|
2015-07-15 00:37:28 +00:00
|
|
|
~WebGLProgram();
|
2012-12-08 20:41:02 +00:00
|
|
|
|
2016-04-20 19:02:07 +00:00
|
|
|
void LinkAndUpdate();
|
2016-09-10 04:02:54 +00:00
|
|
|
bool ValidateForLink();
|
2016-07-07 16:12:10 +00:00
|
|
|
bool ValidateAfterTentativeLink(nsCString* const out_linkLog) const;
|
2015-01-15 23:40:39 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
const GLuint mGLName;
|
|
|
|
|
|
|
|
private:
|
|
|
|
WebGLRefPtr<WebGLShader> mVertShader;
|
|
|
|
WebGLRefPtr<WebGLShader> mFragShader;
|
2016-09-10 04:02:54 +00:00
|
|
|
size_t mNumActiveTFOs;
|
|
|
|
|
|
|
|
std::map<nsCString, GLuint> mNextLink_BoundAttribLocs;
|
|
|
|
|
|
|
|
std::vector<nsString> mNextLink_TransformFeedbackVaryings;
|
|
|
|
GLenum mNextLink_TransformFeedbackBufferMode;
|
|
|
|
|
2015-01-15 23:40:39 +00:00
|
|
|
nsCString mLinkLog;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<const webgl::LinkedProgramInfo> mMostRecentLinkInfo;
|
2012-12-08 20:41:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
#endif // WEBGL_PROGRAM_H_
|