Caches the location of generic uniforms

TRAC #12215 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@298 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 15a4d2ef
...@@ -1703,27 +1703,27 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1703,27 +1703,27 @@ bool Context::applyRenderTarget(bool ignoreViewport)
{ {
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
GLint halfPixelSize = programObject->getUniformLocation("dx_HalfPixelSize"); GLint halfPixelSize = programObject->getDxHalfPixelSizeLocation();
GLfloat xy[2] = {1.0f / viewport.Width, 1.0f / viewport.Height}; GLfloat xy[2] = {1.0f / viewport.Width, 1.0f / viewport.Height};
programObject->setUniform2fv(halfPixelSize, 1, (GLfloat*)&xy); programObject->setUniform2fv(halfPixelSize, 1, (GLfloat*)&xy);
GLint window = programObject->getUniformLocation("dx_Window"); GLint window = programObject->getDxWindowLocation();
GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f, GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f,
(float)mState.viewportX + mState.viewportWidth / 2.0f, (float)mState.viewportX + mState.viewportWidth / 2.0f,
(float)mState.viewportY + mState.viewportHeight / 2.0f}; (float)mState.viewportY + mState.viewportHeight / 2.0f};
programObject->setUniform4fv(window, 1, (GLfloat*)&whxy); programObject->setUniform4fv(window, 1, (GLfloat*)&whxy);
GLint depth = programObject->getUniformLocation("dx_Depth"); GLint depth = programObject->getDxDepthLocation();
GLfloat dz[2] = {(mState.zFar - mState.zNear) / 2.0f, (mState.zNear + mState.zFar) / 2.0f}; GLfloat dz[2] = {(mState.zFar - mState.zNear) / 2.0f, (mState.zNear + mState.zFar) / 2.0f};
programObject->setUniform2fv(depth, 1, (GLfloat*)&dz); programObject->setUniform2fv(depth, 1, (GLfloat*)&dz);
GLint near = programObject->getUniformLocation("gl_DepthRange.near"); GLint near = programObject->getDepthRangeNearLocation();
programObject->setUniform1fv(near, 1, &mState.zNear); programObject->setUniform1fv(near, 1, &mState.zNear);
GLint far = programObject->getUniformLocation("gl_DepthRange.far"); GLint far = programObject->getDepthRangeFarLocation();
programObject->setUniform1fv(far, 1, &mState.zFar); programObject->setUniform1fv(far, 1, &mState.zFar);
GLint diff = programObject->getUniformLocation("gl_DepthRange.diff"); GLint diff = programObject->getDepthRangeDiffLocation();
GLfloat zDiff = mState.zFar - mState.zNear; GLfloat zDiff = mState.zFar - mState.zNear;
programObject->setUniform1fv(diff, 1, &zDiff); programObject->setUniform1fv(diff, 1, &zDiff);
} }
...@@ -1737,11 +1737,11 @@ void Context::applyState(GLenum drawMode) ...@@ -1737,11 +1737,11 @@ void Context::applyState(GLenum drawMode)
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
GLint frontCCW = programObject->getUniformLocation("dx_FrontCCW"); GLint frontCCW = programObject->getDxFrontCCWLocation();
GLint ccw = (mState.frontFace == GL_CCW); GLint ccw = (mState.frontFace == GL_CCW);
programObject->setUniform1iv(frontCCW, 1, &ccw); programObject->setUniform1iv(frontCCW, 1, &ccw);
GLint pointsOrLines = programObject->getUniformLocation("dx_PointsOrLines"); GLint pointsOrLines = programObject->getDxPointsOrLinesLocation();
GLint alwaysFront = !isTriangleMode(drawMode); GLint alwaysFront = !isTriangleMode(drawMode);
programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront); programObject->setUniform1iv(pointsOrLines, 1, &alwaysFront);
......
...@@ -1494,6 +1494,15 @@ void Program::link() ...@@ -1494,6 +1494,15 @@ void Program::link()
return; return;
} }
mDepthRangeNearLocation = getUniformLocation("gl_DepthRange.near");
mDepthRangeFarLocation = getUniformLocation("gl_DepthRange.far");
mDepthRangeDiffLocation = getUniformLocation("gl_DepthRange.diff");
mDxDepthLocation = getUniformLocation("dx_Depth");
mDxWindowLocation = getUniformLocation("dx_Window");
mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize");
mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW");
mDxPointsOrLinesLocation = getUniformLocation("dx_PointsOrLines");
mLinked = true; // Success mLinked = true; // Success
} }
} }
...@@ -2394,6 +2403,15 @@ void Program::unlink(bool destroy) ...@@ -2394,6 +2403,15 @@ void Program::unlink(bool destroy)
mUniforms.pop_back(); mUniforms.pop_back();
} }
mDepthRangeDiffLocation = -1;
mDepthRangeNearLocation = -1;
mDepthRangeFarLocation = -1;
mDxDepthLocation = -1;
mDxWindowLocation = -1;
mDxHalfPixelSizeLocation = -1;
mDxFrontCCWLocation = -1;
mDxPointsOrLinesLocation = -1;
mUniformIndex.clear(); mUniformIndex.clear();
mPixelHLSL.clear(); mPixelHLSL.clear();
...@@ -2693,4 +2711,45 @@ void Program::getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS, ...@@ -2693,4 +2711,45 @@ void Program::getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS,
*constantPS = targetUniform->psHandle; *constantPS = targetUniform->psHandle;
*constantVS = targetUniform->vsHandle; *constantVS = targetUniform->vsHandle;
} }
GLint Program::getDepthRangeDiffLocation() const
{
return mDepthRangeDiffLocation;
}
GLint Program::getDepthRangeNearLocation() const
{
return mDepthRangeFarLocation;
}
GLint Program::getDepthRangeFarLocation() const
{
return mDepthRangeFarLocation;
}
GLint Program::getDxDepthLocation() const
{
return mDxDepthLocation;
}
GLint Program::getDxWindowLocation() const
{
return mDxWindowLocation;
}
GLint Program::getDxHalfPixelSizeLocation() const
{
return mDxHalfPixelSizeLocation;
}
GLint Program::getDxFrontCCWLocation() const
{
return mDxFrontCCWLocation;
}
GLint Program::getDxPointsOrLinesLocation() const
{
return mDxPointsOrLinesLocation;
}
} }
...@@ -93,6 +93,15 @@ class Program ...@@ -93,6 +93,15 @@ class Program
bool getUniformfv(GLint location, GLfloat *params); bool getUniformfv(GLint location, GLfloat *params);
bool getUniformiv(GLint location, GLint *params); bool getUniformiv(GLint location, GLint *params);
GLint getDepthRangeDiffLocation() const;
GLint getDepthRangeNearLocation() const;
GLint getDepthRangeFarLocation() const;
GLint getDxDepthLocation() const;
GLint getDxWindowLocation() const;
GLint getDxHalfPixelSizeLocation() const;
GLint getDxFrontCCWLocation() const;
GLint getDxPointsOrLinesLocation() const;
void dirtyAllUniforms(); void dirtyAllUniforms();
void applyUniforms(); void applyUniforms();
...@@ -191,6 +200,15 @@ class Program ...@@ -191,6 +200,15 @@ class Program
typedef std::vector<UniformLocation> UniformIndex; typedef std::vector<UniformLocation> UniformIndex;
UniformIndex mUniformIndex; UniformIndex mUniformIndex;
GLint mDepthRangeDiffLocation;
GLint mDepthRangeNearLocation;
GLint mDepthRangeFarLocation;
GLint mDxDepthLocation;
GLint mDxWindowLocation;
GLint mDxHalfPixelSizeLocation;
GLint mDxFrontCCWLocation;
GLint mDxPointsOrLinesLocation;
bool mLinked; bool mLinked;
bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
char *mInfoLog; char *mInfoLog;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment