void GrGpuGLShaders::flushViewMatrix() { GrAssert(NULL != fCurrDrawState.fRenderTarget); GrMatrix m ( GrIntToScalar(2) / fCurrDrawState.fRenderTarget->width(), 0, -GR_Scalar1, 0,-GrIntToScalar(2) / fCurrDrawState.fRenderTarget->height(), GR_Scalar1, 0, 0, GrMatrix::I()[8]); m.setConcat(m, fCurrDrawState.fViewMatrix); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrScalar mt[] = { m[GrMatrix::kScaleX], m[GrMatrix::kSkewY], m[GrMatrix::kPersp0], m[GrMatrix::kSkewX], m[GrMatrix::kScaleY], m[GrMatrix::kPersp1], m[GrMatrix::kTransX], m[GrMatrix::kTransY], m[GrMatrix::kPersp2] }; #if ATTRIBUTE_MATRIX GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+0, mt+0)); GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+1, mt+3)); GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+2, mt+6)); #else GR_GL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,1,false,mt)); #endif }
void GrGpuGLShaders::flushTextureMatrix(int stage) { GrAssert(NULL != fCurrDrawState.fTextures[stage]); GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[stage]; GrMatrix m = getSamplerMatrix(stage); GrSamplerState::SampleMode mode = fCurrDrawState.fSamplerStates[0].getSampleMode(); AdjustTextureMatrix(texture, mode, &m); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrScalar mt[] = { m[GrMatrix::kScaleX], m[GrMatrix::kSkewY], m[GrMatrix::kPersp0], m[GrMatrix::kSkewX], m[GrMatrix::kScaleY], m[GrMatrix::kPersp1], m[GrMatrix::kTransX], m[GrMatrix::kTransY], m[GrMatrix::kPersp2] }; #if ATTRIBUTE_MATRIX GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+0, mt+0)); GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+1, mt+3)); GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+2, mt+6)); #else GR_GL(UniformMatrix3fv(fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni, 1, false, mt)); #endif }
void GrGpuGLShaders::flushViewMatrix() { const GrMatrix& vm = this->getDrawState().getViewMatrix(); if (!fProgramData->fViewMatrix.cheapEqualTo(vm)) { const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); GrAssert(NULL != rt); GrMatrix m; m.setAll( GrIntToScalar(2) / rt->width(), 0, -GR_Scalar1, 0,-GrIntToScalar(2) / rt->height(), GR_Scalar1, 0, 0, GrMatrix::I()[8]); m.setConcat(m, vm); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrGLfloat mt[] = { GrScalarToFloat(m[GrMatrix::kMScaleX]), GrScalarToFloat(m[GrMatrix::kMSkewY]), GrScalarToFloat(m[GrMatrix::kMPersp0]), GrScalarToFloat(m[GrMatrix::kMSkewX]), GrScalarToFloat(m[GrMatrix::kMScaleY]), GrScalarToFloat(m[GrMatrix::kMPersp1]), GrScalarToFloat(m[GrMatrix::kMTransX]), GrScalarToFloat(m[GrMatrix::kMTransY]), GrScalarToFloat(m[GrMatrix::kMPersp2]) }; GrAssert(GrGLProgram::kUnusedUniform != fProgramData->fUniLocations.fViewMatrixUni); GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni, 1, false, mt)); fProgramData->fViewMatrix = vm; } }
void GrGpuGLShaders::flushTextureMatrix(int s) { const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni; GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; if (NULL != texture) { if (GrGLProgram::kUnusedUniform != uni && (((1 << s) & fDirtyFlags.fTextureChangedMask) || getHWSamplerMatrix(s) != getSamplerMatrix(s))) { GrAssert(NULL != fCurrDrawState.fTextures[s]); GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; GrMatrix m = getSamplerMatrix(s); GrSamplerState::SampleMode mode = fCurrDrawState.fSamplerStates[s].getSampleMode(); AdjustTextureMatrix(texture, mode, &m); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrGLfloat mt[] = { GrScalarToFloat(m[GrMatrix::kMScaleX]), GrScalarToFloat(m[GrMatrix::kMSkewY]), GrScalarToFloat(m[GrMatrix::kMPersp0]), GrScalarToFloat(m[GrMatrix::kMSkewX]), GrScalarToFloat(m[GrMatrix::kMScaleY]), GrScalarToFloat(m[GrMatrix::kMPersp1]), GrScalarToFloat(m[GrMatrix::kMTransX]), GrScalarToFloat(m[GrMatrix::kMTransY]), GrScalarToFloat(m[GrMatrix::kMPersp2]) }; if (GrGLProgram::kSetAsAttribute == fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) { int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s); GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); } else { GL_CALL(UniformMatrix3fv(uni, 1, false, mt)); } recordHWSamplerMatrix(s, getSamplerMatrix(s)); } } }
void GrGpuGLShaders::flushViewMatrix() { const GrMatrix& vm = this->getDrawState().getViewMatrix(); if (GrGpuGLShaders::getHWViewMatrix() != vm) { const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); GrAssert(NULL != rt); GrMatrix m; m.setAll( GrIntToScalar(2) / rt->width(), 0, -GR_Scalar1, 0,-GrIntToScalar(2) / rt->height(), GR_Scalar1, 0, 0, GrMatrix::I()[8]); m.setConcat(m, vm); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrGLfloat mt[] = { GrScalarToFloat(m[GrMatrix::kMScaleX]), GrScalarToFloat(m[GrMatrix::kMSkewY]), GrScalarToFloat(m[GrMatrix::kMPersp0]), GrScalarToFloat(m[GrMatrix::kMSkewX]), GrScalarToFloat(m[GrMatrix::kMScaleY]), GrScalarToFloat(m[GrMatrix::kMPersp1]), GrScalarToFloat(m[GrMatrix::kMTransX]), GrScalarToFloat(m[GrMatrix::kMTransY]), GrScalarToFloat(m[GrMatrix::kMPersp2]) }; if (GrGLProgram::kSetAsAttribute == fProgramData->fUniLocations.fViewMatrixUni) { int baseIdx = GrGLProgram::ViewMatrixAttributeIdx(); GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); } else { GrAssert(GrGLProgram::kUnusedUniform != fProgramData->fUniLocations.fViewMatrixUni); GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni, 1, false, mt)); } this->recordHWViewMatrix(vm); } }
void GrGpuGLShaders::flushTextureMatrix(int s) { const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni; const GrDrawState& drawState = this->getDrawState(); const GrGLTexture* texture = static_cast<const GrGLTexture*>(drawState.getTexture(s)); if (NULL != texture) { const GrMatrix& hwMatrix = fProgramData->fTextureMatrices[s]; const GrMatrix& samplerMatrix = drawState.getSampler(s).getMatrix(); if (GrGLProgram::kUnusedUniform != uni && (((1 << s) & fDirtyFlags.fTextureChangedMask) || !hwMatrix.cheapEqualTo(samplerMatrix))) { GrMatrix m = samplerMatrix; GrSamplerState::SampleMode mode = drawState.getSampler(s).getSampleMode(); AdjustTextureMatrix(texture, mode, &m); // ES doesn't allow you to pass true to the transpose param, // so do our own transpose GrGLfloat mt[] = { GrScalarToFloat(m[GrMatrix::kMScaleX]), GrScalarToFloat(m[GrMatrix::kMSkewY]), GrScalarToFloat(m[GrMatrix::kMPersp0]), GrScalarToFloat(m[GrMatrix::kMSkewX]), GrScalarToFloat(m[GrMatrix::kMScaleY]), GrScalarToFloat(m[GrMatrix::kMPersp1]), GrScalarToFloat(m[GrMatrix::kMTransX]), GrScalarToFloat(m[GrMatrix::kMTransY]), GrScalarToFloat(m[GrMatrix::kMPersp2]) }; GL_CALL(UniformMatrix3fv(uni, 1, false, mt)); fProgramData->fTextureMatrices[s] = samplerMatrix; } } }
GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) { CONTEXT_EXEC(UniformMatrix3fv(location, count, transpose, value)); }