mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 11:58:55 +00:00
Bug 1080266 - Move UpdateInfo into WebGLProgram.cpp. - r=kamidphish
This commit is contained in:
parent
c460713e4d
commit
8d30cdc7be
@ -162,93 +162,6 @@ IsTexImageCubemapTarget(GLenum texImageTarget)
|
||||
texImageTarget <= LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pull data out of the program, post-linking
|
||||
*/
|
||||
bool
|
||||
WebGLProgram::UpdateInfo()
|
||||
{
|
||||
mAttribMaxNameLength = 0;
|
||||
for (size_t i = 0; i < mAttachedShaders.Length(); i++)
|
||||
mAttribMaxNameLength = std::max(mAttribMaxNameLength, mAttachedShaders[i]->mAttribMaxNameLength);
|
||||
|
||||
GLint attribCount;
|
||||
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &attribCount);
|
||||
|
||||
if (!mAttribsInUse.SetLength(mContext->mGLMaxVertexAttribs)) {
|
||||
mContext->ErrorOutOfMemory("updateInfo: out of memory to allocate %d attribs", mContext->mGLMaxVertexAttribs);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mAttribsInUse.Length(); i++)
|
||||
mAttribsInUse[i] = false;
|
||||
|
||||
nsAutoArrayPtr<char> nameBuf(new char[mAttribMaxNameLength]);
|
||||
|
||||
for (int i = 0; i < attribCount; ++i) {
|
||||
GLint attrnamelen;
|
||||
GLint attrsize;
|
||||
GLenum attrtype;
|
||||
mContext->gl->fGetActiveAttrib(mGLName, i, mAttribMaxNameLength, &attrnamelen, &attrsize, &attrtype, nameBuf);
|
||||
if (attrnamelen > 0) {
|
||||
GLint loc = mContext->gl->fGetAttribLocation(mGLName, nameBuf);
|
||||
MOZ_ASSERT(loc >= 0, "major oops in managing the attributes of a WebGL program");
|
||||
if (loc < mContext->mGLMaxVertexAttribs) {
|
||||
mAttribsInUse[loc] = true;
|
||||
} else {
|
||||
mContext->GenerateWarning("program exceeds MAX_VERTEX_ATTRIBS");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nsAutoPtr will delete old version first
|
||||
mIdentifierMap = new CStringMap;
|
||||
mIdentifierReverseMap = new CStringMap;
|
||||
mUniformInfoMap = new CStringToUniformInfoMap;
|
||||
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
||||
// Loop through ATTRIBUTES
|
||||
for (size_t j = 0; j < mAttachedShaders[i]->mAttributes.Length(); j++) {
|
||||
const WebGLMappedIdentifier& attrib = mAttachedShaders[i]->mAttributes[j];
|
||||
mIdentifierMap->Put(attrib.original, attrib.mapped); // FORWARD MAPPING
|
||||
mIdentifierReverseMap->Put(attrib.mapped, attrib.original); // REVERSE MAPPING
|
||||
}
|
||||
|
||||
// Loop through UNIFORMS
|
||||
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
||||
// Add the uniforms name mapping to mIdentifier[Reverse]Map
|
||||
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
||||
mIdentifierMap->Put(uniform.original, uniform.mapped); // FOWARD MAPPING
|
||||
mIdentifierReverseMap->Put(uniform.mapped, uniform.original); // REVERSE MAPPING
|
||||
|
||||
// Add uniform info to mUniformInfoMap
|
||||
const WebGLUniformInfo& info = mAttachedShaders[i]->mUniformInfos[j];
|
||||
mUniformInfoMap->Put(uniform.mapped, info);
|
||||
}
|
||||
}
|
||||
|
||||
mActiveAttribMap.clear();
|
||||
|
||||
GLint numActiveAttrs = 0;
|
||||
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &numActiveAttrs);
|
||||
|
||||
// Spec says the maximum attrib name length is 256 chars, so this is
|
||||
// sufficient to hold any attrib name.
|
||||
char attrName[257];
|
||||
|
||||
GLint dummySize;
|
||||
GLenum dummyType;
|
||||
for (GLint i = 0; i < numActiveAttrs; i++) {
|
||||
mContext->gl->fGetActiveAttrib(mGLName, i, 257, nullptr, &dummySize,
|
||||
&dummyType, attrName);
|
||||
GLint attrLoc = mContext->gl->fGetAttribLocation(mGLName, attrName);
|
||||
MOZ_ASSERT(attrLoc >= 0);
|
||||
mActiveAttribMap.insert(std::make_pair(attrLoc, nsCString(attrName)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WebGLContext::ValidateBlendEquationEnum(GLenum mode, const char *info)
|
||||
{
|
||||
switch (mode) {
|
||||
|
@ -14,10 +14,10 @@
|
||||
using namespace mozilla;
|
||||
|
||||
/** Takes an ASCII string like "foo[i]", turns it into "foo" and returns "[i]" in bracketPart
|
||||
*
|
||||
*
|
||||
* \param string input/output: the string to split, becomes the string without the bracket part
|
||||
* \param bracketPart output: gets the bracket part.
|
||||
*
|
||||
*
|
||||
* Notice that if there are multiple brackets like "foo[i].bar[j]", only the last bracket is split.
|
||||
*/
|
||||
static bool SplitLastSquareBracket(nsACString& string, nsCString& bracketPart)
|
||||
@ -217,6 +217,90 @@ WebGLProgram::GetUniformInfoForMappedIdentifier(const nsACString& name) {
|
||||
return info;
|
||||
}
|
||||
|
||||
bool
|
||||
WebGLProgram::UpdateInfo()
|
||||
{
|
||||
mAttribMaxNameLength = 0;
|
||||
for (size_t i = 0; i < mAttachedShaders.Length(); i++)
|
||||
mAttribMaxNameLength = std::max(mAttribMaxNameLength, mAttachedShaders[i]->mAttribMaxNameLength);
|
||||
|
||||
GLint attribCount;
|
||||
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &attribCount);
|
||||
|
||||
if (!mAttribsInUse.SetLength(mContext->mGLMaxVertexAttribs)) {
|
||||
mContext->ErrorOutOfMemory("updateInfo: out of memory to allocate %d attribs", mContext->mGLMaxVertexAttribs);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < mAttribsInUse.Length(); i++)
|
||||
mAttribsInUse[i] = false;
|
||||
|
||||
nsAutoArrayPtr<char> nameBuf(new char[mAttribMaxNameLength]);
|
||||
|
||||
for (int i = 0; i < attribCount; ++i) {
|
||||
GLint attrnamelen;
|
||||
GLint attrsize;
|
||||
GLenum attrtype;
|
||||
mContext->gl->fGetActiveAttrib(mGLName, i, mAttribMaxNameLength, &attrnamelen, &attrsize, &attrtype, nameBuf);
|
||||
if (attrnamelen > 0) {
|
||||
GLint loc = mContext->gl->fGetAttribLocation(mGLName, nameBuf);
|
||||
MOZ_ASSERT(loc >= 0, "major oops in managing the attributes of a WebGL program");
|
||||
if (loc < mContext->mGLMaxVertexAttribs) {
|
||||
mAttribsInUse[loc] = true;
|
||||
} else {
|
||||
mContext->GenerateWarning("program exceeds MAX_VERTEX_ATTRIBS");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nsAutoPtr will delete old version first
|
||||
mIdentifierMap = new CStringMap;
|
||||
mIdentifierReverseMap = new CStringMap;
|
||||
mUniformInfoMap = new CStringToUniformInfoMap;
|
||||
for (size_t i = 0; i < mAttachedShaders.Length(); i++) {
|
||||
// Loop through ATTRIBUTES
|
||||
for (size_t j = 0; j < mAttachedShaders[i]->mAttributes.Length(); j++) {
|
||||
const WebGLMappedIdentifier& attrib = mAttachedShaders[i]->mAttributes[j];
|
||||
mIdentifierMap->Put(attrib.original, attrib.mapped); // FORWARD MAPPING
|
||||
mIdentifierReverseMap->Put(attrib.mapped, attrib.original); // REVERSE MAPPING
|
||||
}
|
||||
|
||||
// Loop through UNIFORMS
|
||||
for (size_t j = 0; j < mAttachedShaders[i]->mUniforms.Length(); j++) {
|
||||
// Add the uniforms name mapping to mIdentifier[Reverse]Map
|
||||
const WebGLMappedIdentifier& uniform = mAttachedShaders[i]->mUniforms[j];
|
||||
mIdentifierMap->Put(uniform.original, uniform.mapped); // FOWARD MAPPING
|
||||
mIdentifierReverseMap->Put(uniform.mapped, uniform.original); // REVERSE MAPPING
|
||||
|
||||
// Add uniform info to mUniformInfoMap
|
||||
const WebGLUniformInfo& info = mAttachedShaders[i]->mUniformInfos[j];
|
||||
mUniformInfoMap->Put(uniform.mapped, info);
|
||||
}
|
||||
}
|
||||
|
||||
mActiveAttribMap.clear();
|
||||
|
||||
GLint numActiveAttrs = 0;
|
||||
mContext->gl->fGetProgramiv(mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, &numActiveAttrs);
|
||||
|
||||
// Spec says the maximum attrib name length is 256 chars, so this is
|
||||
// sufficient to hold any attrib name.
|
||||
char attrName[257];
|
||||
|
||||
GLint dummySize;
|
||||
GLenum dummyType;
|
||||
for (GLint i = 0; i < numActiveAttrs; i++) {
|
||||
mContext->gl->fGetActiveAttrib(mGLName, i, 257, nullptr, &dummySize,
|
||||
&dummyType, attrName);
|
||||
GLint attrLoc = mContext->gl->fGetAttribLocation(mGLName, attrName);
|
||||
MOZ_ASSERT(attrLoc >= 0);
|
||||
mActiveAttribMap.insert(std::make_pair(attrLoc, nsCString(attrName)));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ uint64_t
|
||||
WebGLProgram::IdentifierHashFunction(const char *ident, size_t size)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user