зеркало из https://github.com/mozilla/pjs.git
Bug 678940 - remove caching of uniform values. r=joe
This commit is contained in:
Родитель
b10d9db26b
Коммит
7d7af68671
|
@ -59,55 +59,6 @@ namespace layers {
|
|||
#define ASSERT_THIS_PROGRAM
|
||||
#endif
|
||||
|
||||
struct UniformValue {
|
||||
UniformValue() {
|
||||
memset(this, 0, sizeof(UniformValue));
|
||||
}
|
||||
|
||||
void setInt(const int i) {
|
||||
value.i[0] = i;
|
||||
}
|
||||
|
||||
void setFloat(const float f) {
|
||||
value.f[0] = f;
|
||||
}
|
||||
|
||||
void setFloatN(const float *f, const int n) {
|
||||
memcpy(value.f, f, sizeof(float)*n);
|
||||
}
|
||||
|
||||
void setColor(const gfxRGBA& c) {
|
||||
value.f[0] = float(c.r);
|
||||
value.f[1] = float(c.g);
|
||||
value.f[2] = float(c.b);
|
||||
value.f[3] = float(c.a);
|
||||
}
|
||||
|
||||
bool equalsInt(const int i) {
|
||||
return i == value.i[0];
|
||||
}
|
||||
|
||||
bool equalsFloat(const float f) {
|
||||
return f == value.f[0];
|
||||
}
|
||||
|
||||
bool equalsFloatN(const float *f, const int n) {
|
||||
return memcmp(f, value.f, sizeof(float)*n) == 0;
|
||||
}
|
||||
|
||||
bool equalsColor(const gfxRGBA& c) {
|
||||
return value.f[0] == float(c.r) &&
|
||||
value.f[1] == float(c.g) &&
|
||||
value.f[2] == float(c.b) &&
|
||||
value.f[3] == float(c.a);
|
||||
}
|
||||
|
||||
union {
|
||||
int i[1];
|
||||
float f[16];
|
||||
} value;
|
||||
};
|
||||
|
||||
class LayerManagerOGLProgram {
|
||||
protected:
|
||||
#ifdef CHECK_CURRENT_PROGRAM
|
||||
|
@ -146,26 +97,16 @@ public:
|
|||
|
||||
void SetUniform(GLuint aUniform, float aFloatValue) {
|
||||
ASSERT_THIS_PROGRAM;
|
||||
|
||||
if (aUniform == GLuint(-1))
|
||||
return;
|
||||
|
||||
if (!mUniformValues[aUniform].equalsFloat(aFloatValue)) {
|
||||
mGL->fUniform1f(aUniform, aFloatValue);
|
||||
mUniformValues[aUniform].setFloat(aFloatValue);
|
||||
}
|
||||
mGL->fUniform1f(aUniform, aFloatValue);
|
||||
}
|
||||
|
||||
void SetUniform(GLuint aUniform, const gfxRGBA& aColor) {
|
||||
ASSERT_THIS_PROGRAM;
|
||||
|
||||
if (aUniform == GLuint(-1))
|
||||
return;
|
||||
|
||||
if (!mUniformValues[aUniform].equalsColor(aColor)) {
|
||||
mGL->fUniform4f(aUniform, float(aColor.r), float(aColor.g), float(aColor.b), float(aColor.a));
|
||||
mUniformValues[aUniform].setColor(aColor);
|
||||
}
|
||||
mGL->fUniform4f(aUniform, float(aColor.r), float(aColor.g), float(aColor.b), float(aColor.a));
|
||||
}
|
||||
|
||||
void SetUniform(GLuint aUniform, int aLength, float *aFloatValues) {
|
||||
|
@ -174,44 +115,31 @@ public:
|
|||
if (aUniform == GLuint(-1))
|
||||
return;
|
||||
|
||||
if (!mUniformValues[aUniform].equalsFloatN(aFloatValues, aLength)) {
|
||||
if (aLength == 1) {
|
||||
mGL->fUniform1fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 2) {
|
||||
mGL->fUniform2fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 3) {
|
||||
mGL->fUniform3fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 4) {
|
||||
mGL->fUniform4fv(aUniform, 1, aFloatValues);
|
||||
} else {
|
||||
NS_NOTREACHED("Bogus aLength param");
|
||||
}
|
||||
mUniformValues[aUniform].setFloatN(aFloatValues, aLength);
|
||||
if (aLength == 1) {
|
||||
mGL->fUniform1fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 2) {
|
||||
mGL->fUniform2fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 3) {
|
||||
mGL->fUniform3fv(aUniform, 1, aFloatValues);
|
||||
} else if (aLength == 4) {
|
||||
mGL->fUniform4fv(aUniform, 1, aFloatValues);
|
||||
} else {
|
||||
NS_NOTREACHED("Bogus aLength param");
|
||||
}
|
||||
}
|
||||
|
||||
void SetUniform(GLuint aUniform, GLint aIntValue) {
|
||||
ASSERT_THIS_PROGRAM;
|
||||
|
||||
if (aUniform == GLuint(-1))
|
||||
return;
|
||||
|
||||
if (!mUniformValues[aUniform].equalsInt(aIntValue)) {
|
||||
mGL->fUniform1i(aUniform, aIntValue);
|
||||
mUniformValues[aUniform].setInt(aIntValue);
|
||||
}
|
||||
mGL->fUniform1i(aUniform, aIntValue);
|
||||
}
|
||||
|
||||
void SetMatrixUniform(GLuint aUniform, const float *aFloatValues) {
|
||||
ASSERT_THIS_PROGRAM;
|
||||
|
||||
if (aUniform == GLuint(-1))
|
||||
return;
|
||||
|
||||
if (!mUniformValues[aUniform].equalsFloatN(aFloatValues, 16)) {
|
||||
mGL->fUniformMatrix4fv(aUniform, 1, false, aFloatValues);
|
||||
mUniformValues[aUniform].setFloatN(aFloatValues, 16);
|
||||
}
|
||||
mGL->fUniformMatrix4fv(aUniform, 1, false, aFloatValues);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -219,8 +147,6 @@ protected:
|
|||
|
||||
GLuint mProgram;
|
||||
|
||||
nsTArray<UniformValue> mUniformValues;
|
||||
|
||||
GLint CreateShader(GLenum aShaderType,
|
||||
const char *aShaderSource)
|
||||
{
|
||||
|
@ -322,34 +248,6 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
// Now query uniforms, so that we can initialize mUniformValues
|
||||
// note that for simplicity, mUniformLocations is indexed by the
|
||||
// uniform -location-, and not the uniform -index-. This means
|
||||
// that it might have a bunch of unused space as locations dense
|
||||
// like indices are; however, there are unlikely to be enough for
|
||||
// our shaders for this to become a significant memory issue.
|
||||
GLint count, maxnamelen;
|
||||
nsCAutoString uname;
|
||||
GLint maxloc = 0;
|
||||
mGL->fGetProgramiv(mProgram, LOCAL_GL_ACTIVE_UNIFORMS, &count);
|
||||
mGL->fGetProgramiv(mProgram, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxnamelen);
|
||||
uname.SetCapacity(maxnamelen);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
GLsizei namelen;
|
||||
GLint usize;
|
||||
GLenum utype;
|
||||
|
||||
mGL->fGetActiveUniform(mProgram, i, maxnamelen, &namelen, &usize, &utype, uname.BeginWriting());
|
||||
uname.SetLength(namelen);
|
||||
GLint uloc = mGL->fGetUniformLocation(mProgram, uname.BeginReading());
|
||||
if (maxloc < uloc)
|
||||
maxloc = uloc;
|
||||
}
|
||||
|
||||
// Note +1: the last valid index needs to be 'maxloc', so we need
|
||||
// to set the array length to 1 more than that.
|
||||
mUniformValues.SetLength(maxloc+1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -383,11 +281,11 @@ protected:
|
|||
* aVertexCoord - vertex coordinate
|
||||
*
|
||||
* Uniforms:
|
||||
* uTransformMatrix - a transform matrix
|
||||
* uQuadTransform
|
||||
* uProjMatrix - projection matrix
|
||||
* uOffset - a vec4 offset to apply to the transformed coordinates
|
||||
* uLayerOpacity - a float, the layer opacity (final colors will be multiplied by this)
|
||||
* uLayerTransform - a transform matrix
|
||||
* uLayerQuadTransform
|
||||
* uMatrixProj - projection matrix
|
||||
* uRenderTargetOffset - a vec4 offset to apply to the transformed coordinates
|
||||
* uLayerOpacity - a float, the layer opacity (final colors will be multiplied by this)
|
||||
*/
|
||||
|
||||
class LayerProgram :
|
||||
|
@ -763,7 +661,7 @@ public:
|
|||
* vertices. It has the following attributes and uniforms:
|
||||
*
|
||||
* Attribute inputs:
|
||||
* aVertex - vertex coordinate
|
||||
* aVertexCoord - vertex coordinate
|
||||
* aTexCoord - texture coordinate
|
||||
*
|
||||
* Uniforms:
|
||||
|
|
Загрузка…
Ссылка в новой задаче