separate view matrix from rt adjustment
R=robertphillips@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/299943002 git-svn-id: http://skia.googlecode.com/svn/trunk@14944 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
537326089e
commit
47c66ddaeb
@ -52,6 +52,7 @@ GrGLProgram::GrGLProgram(GrGpuGL* gpu,
|
||||
GrGLFullShaderBuilder fullBuilder(fGpu, fUniformManager, fDesc);
|
||||
if (this->genProgram(&fullBuilder, colorStages, coverageStages)) {
|
||||
fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUniform();
|
||||
fUniformHandles.fRTAdjustmentUni = fullBuilder.getRTAdjustmentVecUniform();
|
||||
fHasVertexShader = true;
|
||||
}
|
||||
} else {
|
||||
@ -329,6 +330,7 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) {
|
||||
|
||||
if (!fHasVertexShader) {
|
||||
SkASSERT(!fUniformHandles.fViewMatrixUni.isValid());
|
||||
SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
|
||||
fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin());
|
||||
} else if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
|
||||
fMatrixState.fRenderTargetSize != size ||
|
||||
@ -342,5 +344,9 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) {
|
||||
GrGLfloat viewMatrix[3 * 3];
|
||||
fMatrixState.getGLMatrix<3>(viewMatrix);
|
||||
fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix);
|
||||
|
||||
GrGLfloat rtAdjustmentVec[4];
|
||||
fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
|
||||
fUniformManager.set4fv(fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
|
||||
}
|
||||
}
|
||||
|
@ -103,20 +103,50 @@ public:
|
||||
fRenderTargetSize.fHeight = -1;
|
||||
fRenderTargetOrigin = (GrSurfaceOrigin) -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a matrix that goes from local coords to Skia's device coordinates.
|
||||
*/
|
||||
template<int Size> void getGLMatrix(GrGLfloat* destMatrix) {
|
||||
GrGLGetMatrix<Size>(destMatrix, fViewMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a matrix that goes from local coordinates to GL normalized device coords.
|
||||
*/
|
||||
template<int Size> void getRTAdjustedGLMatrix(GrGLfloat* destMatrix) {
|
||||
SkMatrix combined;
|
||||
if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
|
||||
combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
|
||||
0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1,
|
||||
0, 0, SkMatrix::I()[8]);
|
||||
0, 0, 1);
|
||||
} else {
|
||||
combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
|
||||
0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
|
||||
0, 0, SkMatrix::I()[8]);
|
||||
0, 0, 1);
|
||||
}
|
||||
combined.preConcat(fViewMatrix);
|
||||
GrGLGetMatrix<Size>(destMatrix, combined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a vec4 that adjusts the position from Skia device coords to GL's normalized device
|
||||
* coords. Assuming the transformed position, pos, is a homogeneous vec3, the vec, v, is
|
||||
* applied as such:
|
||||
* pos.x = dot(v.xy, pos.xz)
|
||||
* pos.y = dot(v.zq, pos.yz)
|
||||
*/
|
||||
void getRTAdjustmentVec(GrGLfloat* destVec) {
|
||||
destVec[0] = 2.f / fRenderTargetSize.fWidth;
|
||||
destVec[1] = -1.f;
|
||||
if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
|
||||
destVec[2] = -2.f / fRenderTargetSize.fHeight;
|
||||
destVec[3] = 1.f;
|
||||
} else {
|
||||
destVec[2] = 2.f / fRenderTargetSize.fHeight;
|
||||
destVec[3] = -1.f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -137,6 +167,7 @@ private:
|
||||
// handles for uniforms (aside from per-effect samplers)
|
||||
struct UniformHandles {
|
||||
UniformHandle fViewMatrixUni;
|
||||
UniformHandle fRTAdjustmentUni;
|
||||
UniformHandle fColorUni;
|
||||
UniformHandle fCoverageUni;
|
||||
|
||||
|
@ -757,11 +757,19 @@ GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu,
|
||||
const char* viewMName;
|
||||
fViewMatrixUniform = this->addUniform(GrGLShaderBuilder::kVertex_Visibility,
|
||||
kMat33f_GrSLType, "ViewM", &viewMName);
|
||||
const char* rtAdjustName;
|
||||
fRTAdustmentVecUniform = this->addUniform(GrGLShaderBuilder::kVertex_Visibility,
|
||||
kVec4f_GrSLType, "rtAdjustment", &rtAdjustName);
|
||||
|
||||
this->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n"
|
||||
"\tgl_Position = vec4(pos3.xy, 0, pos3.z);\n",
|
||||
// Transform the position into Skia's device coords.
|
||||
this->vsCodeAppendf("\tvec3 pos3 = %s * vec3(%s, 1);\n",
|
||||
viewMName, fPositionVar->c_str());
|
||||
|
||||
// Transform from Skia's device coords to GL's normalized device coords.
|
||||
this->vsCodeAppendf(
|
||||
"\tgl_Position = vec4(dot(pos3.xz, %s.xy), dot(pos3.yz, %s.zw), 0, pos3.z);\n",
|
||||
rtAdjustName, rtAdjustName);
|
||||
|
||||
// we output point size in the GS if present
|
||||
if (header.fEmitsPointSize
|
||||
#if GR_GL_EXPERIMENTAL_GS
|
||||
|
@ -417,10 +417,17 @@ public:
|
||||
int effectCnt,
|
||||
GrGLSLExpr4* inOutFSColor) SK_OVERRIDE;
|
||||
|
||||
/**
|
||||
* The view matrix uniform is only valid in the VS. It is always mat33.
|
||||
*/
|
||||
GrGLUniformManager::UniformHandle getViewMatrixUniform() const {
|
||||
return fViewMatrixUniform;
|
||||
}
|
||||
|
||||
GrGLUniformManager::UniformHandle getRTAdjustmentVecUniform() const {
|
||||
return fRTAdustmentVecUniform;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const SK_OVERRIDE;
|
||||
virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE;
|
||||
@ -444,7 +451,7 @@ private:
|
||||
SkSTArray<10, AttributePair, true> fEffectAttributes;
|
||||
|
||||
GrGLUniformManager::UniformHandle fViewMatrixUniform;
|
||||
|
||||
GrGLUniformManager::UniformHandle fRTAdustmentVecUniform;
|
||||
GrGLShaderVar* fPositionVar;
|
||||
GrGLShaderVar* fLocalCoordsVar;
|
||||
|
||||
|
@ -2233,7 +2233,7 @@ void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix,
|
||||
fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin;
|
||||
|
||||
GrGLfloat glMatrix[4 * 4];
|
||||
fHWProjectionMatrixState.getGLMatrix<4>(glMatrix);
|
||||
fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix);
|
||||
GL_CALL(MatrixLoadf(GR_GL_PROJECTION, glMatrix));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user