aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2014-12-30 09:04:15 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-30 09:04:16 -0800
commitee2af95db72152dfa61c841875df0594ca93437d (patch)
tree21f811f95923d1c916e57d1742c2dc4751d067fd /src/gpu/gl
parent78aea9f75248dbfeac8d653fbd0bc37d568ec2f2 (diff)
ViewMatrix uniform upload moved to GeometryProcessor
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLGeometryProcessor.h18
-rw-r--r--src/gpu/gl/GrGLPathRendering.cpp4
-rw-r--r--src/gpu/gl/GrGLPathRendering.h34
-rw-r--r--src/gpu/gl/GrGLProgram.cpp33
-rw-r--r--src/gpu/gl/GrGLProgram.h46
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp2
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h1
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp7
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.h6
9 files changed, 74 insertions, 77 deletions
diff --git a/src/gpu/gl/GrGLGeometryProcessor.h b/src/gpu/gl/GrGLGeometryProcessor.h
index a9f5ead4ac..0b24144d84 100644
--- a/src/gpu/gl/GrGLGeometryProcessor.h
+++ b/src/gpu/gl/GrGLGeometryProcessor.h
@@ -20,7 +20,7 @@ class GrGLGPBuilder;
*/
class GrGLGeometryProcessor {
public:
- GrGLGeometryProcessor() {}
+ GrGLGeometryProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::InvalidMatrix(); }
virtual ~GrGLGeometryProcessor() {}
typedef GrGLProgramDataManager::UniformHandle UniformHandle;
@@ -74,7 +74,23 @@ protected:
const GrGeometryProcessor::GrAttribute* colorAttr,
UniformHandle* colorUniform);
+ const char* uViewM() const { return fViewMatrixName; }
+
+ /** a helper function to setup the uniform handle for the uniform view matrix */
+ void addUniformViewMatrix(GrGLGPBuilder*);
+
+
+ /** a helper function to upload a uniform viewmatrix.
+ * TODO we can remove this function when we have deferred geometry in place
+ */
+ void setUniformViewMatrix(const GrGLProgramDataManager&,
+ const SkMatrix& viewMatrix);
+
private:
+ UniformHandle fViewMatrixUniform;
+ SkMatrix fViewMatrix;
+ const char* fViewMatrixName;
+
typedef GrGLProcessor INHERITED;
};
diff --git a/src/gpu/gl/GrGLPathRendering.cpp b/src/gpu/gl/GrGLPathRendering.cpp
index 7bf6ce6f8e..35c4b82c82 100644
--- a/src/gpu/gl/GrGLPathRendering.cpp
+++ b/src/gpu/gl/GrGLPathRendering.cpp
@@ -339,8 +339,8 @@ void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, G
}
void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix,
- const SkISize& renderTargetSize,
- GrSurfaceOrigin renderTargetOrigin) {
+ const SkISize& renderTargetSize,
+ GrSurfaceOrigin renderTargetOrigin) {
SkASSERT(fGpu->glCaps().pathRenderingSupport());
diff --git a/src/gpu/gl/GrGLPathRendering.h b/src/gpu/gl/GrGLPathRendering.h
index ee4011d3ac..0ebf470ada 100644
--- a/src/gpu/gl/GrGLPathRendering.h
+++ b/src/gpu/gl/GrGLPathRendering.h
@@ -126,10 +126,42 @@ private:
GrGLuint pathBase, GrGLint reference, GrGLuint mask, GrGLenum coverMode,
GrGLenum transformType, const GrGLfloat *transformValues);
+ struct MatrixState {
+ SkMatrix fViewMatrix;
+ SkISize fRenderTargetSize;
+ GrSurfaceOrigin fRenderTargetOrigin;
+
+ MatrixState() { this->invalidate(); }
+ void invalidate() {
+ fViewMatrix = SkMatrix::InvalidMatrix();
+ fRenderTargetSize.fWidth = -1;
+ fRenderTargetSize.fHeight = -1;
+ fRenderTargetOrigin = (GrSurfaceOrigin) -1;
+ }
+
+ /**
+ * 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, 1);
+ } else {
+ combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
+ 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
+ 0, 0, 1);
+ }
+ combined.preConcat(fViewMatrix);
+ GrGLGetMatrix<Size>(destMatrix, combined);
+ }
+ };
+
GrGLGpu* fGpu;
SkAutoTDelete<GrGLNameAllocator> fPathNameAllocator;
Caps fCaps;
- GrGLProgram::MatrixState fHWProjectionMatrixState;
+ MatrixState fHWProjectionMatrixState;
GrStencilSettings fHWPathStencilSettings;
struct PathTexGenData {
GrGLenum fMode;
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 60d97a2969..9400e54b12 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -132,7 +132,7 @@ void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& p
///////////////////////////////////////////////////////////////////////////////
void GrGLProgram::setData(const GrOptDrawState& optState) {
- this->setMatrixAndRenderTargetHeight(optState);
+ this->setRenderTargetState(optState);
const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
if (dstCopy) {
@@ -205,37 +205,29 @@ void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
}
-void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
+void GrGLProgram::setRenderTargetState(const GrOptDrawState& optState) {
// Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
- fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
+ fRenderTargetState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
SkIntToScalar(optState.getRenderTarget()->height()));
}
// call subclasses to set the actual view matrix
- this->onSetMatrixAndRenderTargetHeight(optState);
+ this->onSetRenderTargetState(optState);
}
-void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
+void GrGLProgram::onSetRenderTargetState(const GrOptDrawState& optState) {
const GrRenderTarget* rt = optState.getRenderTarget();
SkISize size;
size.set(rt->width(), rt->height());
- if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
- fMatrixState.fRenderTargetSize != size ||
- !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
- SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
-
- fMatrixState.fViewMatrix = optState.getViewMatrix();
- fMatrixState.fRenderTargetSize = size;
- fMatrixState.fRenderTargetOrigin = rt->origin();
-
- GrGLfloat viewMatrix[3 * 3];
- fMatrixState.getGLMatrix<3>(viewMatrix);
- fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
+ if (fRenderTargetState.fRenderTargetOrigin != rt->origin() ||
+ fRenderTargetState.fRenderTargetSize != size) {
+ fRenderTargetState.fRenderTargetSize = size;
+ fRenderTargetState.fRenderTargetOrigin = rt->origin();
GrGLfloat rtAdjustmentVec[4];
- fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
+ fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
}
}
@@ -254,12 +246,13 @@ GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu,
xferProcessor, fragmentProcessors) {
}
-void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
+void GrGLNvprProgramBase::onSetRenderTargetState(const GrOptDrawState& optState) {
SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
const GrRenderTarget* rt = optState.getRenderTarget();
SkISize size;
size.set(rt->width(), rt->height());
- fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
+ fGpu->glPathRendering()->setProjectionMatrix(optState.getPrimitiveProcessor()->viewMatrix(),
+ size, rt->origin());
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 3ee71b85b1..6e7e22bcad 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -60,50 +60,22 @@ public:
virtual bool hasVertexShader() const { return true; }
/**
- * The GrDrawState's view matrix along with the aspects of the render target determine the
- * matrix sent to GL. The size of the render target affects the GL matrix because we must
- * convert from Skia device coords to GL's normalized coords. Also the origin of the render
- * target may require us to perform a mirror-flip.
+ * We use the RT's size and origin to adjust from Skia device space to OpenGL normalized device
+ * space and to make device space positions have the correct origin for processors that require
+ * them.
*/
- struct MatrixState {
- SkMatrix fViewMatrix;
+ struct RenderTargetState {
SkISize fRenderTargetSize;
GrSurfaceOrigin fRenderTargetOrigin;
- MatrixState() { this->invalidate(); }
+ RenderTargetState() { this->invalidate(); }
void invalidate() {
- fViewMatrix = SkMatrix::InvalidMatrix();
fRenderTargetSize.fWidth = -1;
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, 1);
- } else {
- combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
- 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
- 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:
@@ -162,11 +134,11 @@ protected:
virtual void didSetData(GrGpu::DrawType);
// Helper for setData() that sets the view matrix and loads the render target height uniform
- void setMatrixAndRenderTargetHeight(const GrOptDrawState&);
- virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&);
+ void setRenderTargetState(const GrOptDrawState&);
+ virtual void onSetRenderTargetState(const GrOptDrawState&);
// these reflect the current values of uniforms (GL uniform values travel with program)
- MatrixState fMatrixState;
+ RenderTargetState fRenderTargetState;
GrColor fColor;
uint8_t fCoverage;
int fDstCopyTexUnit;
@@ -204,7 +176,7 @@ protected:
GrGLInstalledGeoProc*,
GrGLInstalledXferProc* xferProcessor,
GrGLInstalledFragProcs* fragmentProcessors);
- virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&);
+ virtual void onSetRenderTargetState(const GrOptDrawState&);
typedef GrGLProgram INHERITED;
};
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index c414aba9ff..0c41781979 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -178,8 +178,6 @@ const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const {
void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage) {
if (fOptState.hasGeometryProcessor()) {
- fVS.setupUniformViewMatrix();
-
fVS.codeAppend("gl_PointSize = 1.0;");
// Setup position
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 032fa57fa2..fd1d6c8041 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -240,7 +240,6 @@ public:
// Handles for program uniforms (other than per-effect uniforms)
struct BuiltinUniformHandles {
- UniformHandle fViewMatrixUni;
UniformHandle fRTAdjustmentUni;
// We use the render target height to provide a y-down frag coord when specifying
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
index 2ff97823cd..fd79abbeb5 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
@@ -26,13 +26,6 @@ void GrGLVertexBuilder::addVarying(const char* name, GrGLVarying* v) {
v->fVsOut = fOutputs.back().getName().c_str();
}
-void GrGLVertexBuilder::setupUniformViewMatrix() {
- fProgramBuilder->fUniformHandles.fViewMatrixUni =
- fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
- kMat33f_GrSLType, kDefault_GrSLPrecision,
- this->uViewM());
-}
-
void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
const GrGeometryProcessor::VertexAttribArray& v = gp.getAttribs();
int vaCount = v.count();
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
index dbff24fe83..ba978a8beb 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
@@ -21,10 +21,6 @@ public:
const char* positionCoords() const { return "position"; }
const char* localCoords() const { return "localCoords"; }
- /** returns the expected uviewM matrix */
- // TODO all of this fixed function stuff can live on the GP/PP
- const char* uViewM() const { return "uViewM"; }
-
void addAttribute(const GrGeometryProcessor::GrAttribute* attr) {
this->addAttribute(GrShaderVar(attr->fName,
GrVertexAttribTypeToSLType(attr->fType),
@@ -41,8 +37,6 @@ private:
* private helpers for compilation by GrGLProgramBuilder
*/
void transformToNormalizedDeviceSpace();
- //TODO GP itself should setup the uniform view matrix
- void setupUniformViewMatrix();
void emitAttributes(const GrGeometryProcessor& gp);
void bindVertexAttributes(GrGLuint programID);
bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const;