Chromium Code Reviews| Index: src/gpu/gl/GrGpuGL.cpp |
| diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp |
| index 6f9a8ab152f04f43e192bbf2229a92c88b168f29..4f4bb0f93f51c40af99e37a361f822e2267892cf 100644 |
| --- a/src/gpu/gl/GrGpuGL.cpp |
| +++ b/src/gpu/gl/GrGpuGL.cpp |
| @@ -124,6 +124,7 @@ GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) |
| fCaps.reset(SkRef(ctx.info().caps())); |
| fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); |
| + fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords()); |
| fillInConfigRenderableTable(); |
| @@ -377,7 +378,10 @@ void GrGpuGL::onResetContext(uint32_t resetBits) { |
| GL_CALL(Disable(GR_GL_TEXTURE_GEN_T)); |
| GL_CALL(Disable(GR_GL_TEXTURE_GEN_Q)); |
| GL_CALL(Disable(GR_GL_TEXTURE_GEN_R)); |
| + fHWTexGenSettings[i].fMode = GR_GL_NONE; |
| + fHWTexGenSettings[i].fNumComponents = 0; |
| } |
| + fHWActiveTexGenUnits = 0; |
| } |
| // we assume these values |
| @@ -2112,6 +2116,121 @@ void GrGpuGL::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur |
| texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
| } |
| +void GrGpuGL::setProjectionMatrix(const SkMatrix& matrix, |
| + const SkISize& renderTargetSize, |
| + GrSurfaceOrigin renderTargetOrigin) { |
| + |
| + SkASSERT(this->glCaps().fixedFunctionSupport()); |
| + |
| + if (renderTargetOrigin == fHWProjectionMatrixState.fRenderTargetOrigin && |
| + renderTargetSize == fHWProjectionMatrixState.fRenderTargetSize && |
| + matrix.cheapEqualTo(fHWProjectionMatrixState.fViewMatrix)) { |
| + return; |
| + } |
| + |
| + fHWProjectionMatrixState.fViewMatrix = matrix; |
| + fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; |
| + fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; |
| + |
| + GrGLfloat glMatrix[4 * 4]; |
| + fHWProjectionMatrixState.getGLMatrix<4>(glMatrix); |
|
Mark Kilgard
2013/09/10 02:13:48
glMatrixLoadfEXT opportunity
|
| + GL_CALL(MatrixMode(GR_GL_PROJECTION)); |
| + GL_CALL(LoadMatrixf(glMatrix)); |
| +} |
| + |
| +void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const GrGLfloat* coefficients) { |
| + |
| + SkASSERT(this->glCaps().fixedFunctionSupport()); |
| + SkASSERT(numComponents <= 3 && numComponents > 0); |
| + |
| + if (GR_GL_OBJECT_LINEAR == fHWTexGenSettings[unitIdx].fMode && |
| + numComponents == fHWTexGenSettings[unitIdx].fNumComponents && |
| + !memcmp(coefficients, fHWTexGenSettings[unitIdx].fCoefficients, |
| + 3 * numComponents * sizeof(GrGLfloat))) { |
| + return; |
| + } |
| + |
|
Mark Kilgard
2013/09/10 02:13:48
It would be nice if we did *either* the fixed-func
bsalomon
2013/09/10 13:51:06
seems reasonable
|
| + setTextureUnit(unitIdx); |
|
bsalomon
2013/09/10 13:51:06
style nit: this->setTextureUnit(unitIdx);
(we use
|
| + |
|
Mark Kilgard
2013/09/10 02:13:48
Instead of glActiveTexture/glTexGeni/glEnable/glDi
|
| + if (GR_GL_OBJECT_LINEAR != fHWTexGenSettings[unitIdx].fMode) { |
| + for (int i = 0; i < 4; i++) { |
| + GL_CALL(TexGeni(GR_GL_S + i, GR_GL_TEXTURE_GEN_MODE, GR_GL_OBJECT_LINEAR)); |
| + } |
| + fHWTexGenSettings[unitIdx].fMode = GR_GL_OBJECT_LINEAR; |
| + } |
| + |
| + for (int i = fHWTexGenSettings[unitIdx].fNumComponents; i < numComponents; i++) { |
| + GL_CALL(Enable(GR_GL_TEXTURE_GEN_S + i)); |
| + } |
| + for (int i = numComponents; i < fHWTexGenSettings[unitIdx].fNumComponents; i++) { |
| + GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + i)); |
| + } |
| + fHWTexGenSettings[unitIdx].fNumComponents = numComponents; |
| + |
| + for (int i = 0; i < numComponents; i++) { |
| + GrGLfloat plane[] = {coefficients[0 + 3 * i], |
| + coefficients[1 + 3 * i], |
| + 0, |
| + coefficients[2 + 3 * i]}; |
| + GL_CALL(TexGenfv(GR_GL_S + i, GR_GL_OBJECT_PLANE, plane)); |
| + } |
| + |
| + GL_CALL(PathTexGen(GR_GL_TEXTURE0 + unitIdx, |
| + GR_GL_OBJECT_LINEAR, |
| + numComponents, |
| + coefficients)); |
| + |
| + memcpy(fHWTexGenSettings[unitIdx].fCoefficients, coefficients, |
| + 3 * numComponents * sizeof(GrGLfloat)); |
| + |
| + fHWActiveTexGenUnits = SkTMax(fHWActiveTexGenUnits, unitIdx); |
| +} |
| + |
| +void GrGpuGL::enableTexGen(int unitIdx, int numComponents, const SkMatrix& matrix) { |
| + |
| + GrGLfloat coefficients[9]; |
| + SkASSERT(this->glCaps().fixedFunctionSupport()); |
| + SkASSERT(numComponents <= 3 && numComponents > 0); |
| + |
| + coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); |
| + coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]); |
| + coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]); |
| + |
| + if (numComponents >= 2) { |
| + coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]); |
| + coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]); |
| + coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]); |
| + } |
| + |
| + if (numComponents >= 3) { |
| + coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]); |
| + coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]); |
| + coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]); |
| + } |
| + |
| + enableTexGen(unitIdx, numComponents, coefficients); |
| +} |
| + |
| +void GrGpuGL::disableUnusedTexGenUnits(int numUsedUnits) { |
| + |
| + SkASSERT(this->glCaps().fixedFunctionSupport()); |
| + |
| + for (int i = numUsedUnits; i < fHWActiveTexGenUnits; i++) { |
| + if (!fHWTexGenSettings[i].fNumComponents) { |
| + continue; |
| + } |
| + |
|
Mark Kilgard
2013/09/10 02:13:48
Again, a lot of glDisable calls or glPathTexGen.
|
| + setTextureUnit(i); |
| + for (int j = 0; j < fHWTexGenSettings[i].fNumComponents; j++) { |
| + GL_CALL(Disable(GR_GL_TEXTURE_GEN_S + j)); |
| + } |
| + GL_CALL(PathTexGen(GR_GL_TEXTURE0 + i, GR_GL_NONE, 0, NULL)); |
| + fHWTexGenSettings[i].fNumComponents = 0; |
| + } |
| + |
| + fHWActiveTexGenUnits = SkTMin(fHWActiveTexGenUnits, numUsedUnits); |
| +} |
| + |
| void GrGpuGL::flushMiscFixedFunctionState() { |
| const GrDrawState& drawState = this->getDrawState(); |