bool GrGpuGLShaders::flushGraphicsState(GrPrimitiveType type) { if (!flushGLStateCommon(type)) { return false; } if (fDirtyFlags.fRenderTargetChanged) { // our coords are in pixel space and the GL matrices map to NDC // so if the viewport changed, our matrix is now wrong. #if ATTRIBUTE_MATRIX fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix(); #else // we assume all shader matrices may be wrong after viewport changes fProgramCache->invalidateViewMatrices(); #endif } if (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit) { // invalidate the immediate mode color fHWDrawState.fColor = GrColor_ILLEGAL; } else { if (fHWDrawState.fColor != fCurrDrawState.fColor) { // OpenGL ES only supports the float varities of glVertexAttrib float c[] = { GrColorUnpackR(fCurrDrawState.fColor) / 255.f, GrColorUnpackG(fCurrDrawState.fColor) / 255.f, GrColorUnpackB(fCurrDrawState.fColor) / 255.f, GrColorUnpackA(fCurrDrawState.fColor) / 255.f }; GR_GL(VertexAttrib4fv(COL_ATTR_LOCATION, c)); fHWDrawState.fColor = fCurrDrawState.fColor; } } buildProgram(type); fProgramData = fProgramCache->getProgramData(fCurrentProgram, this); if (fHWProgramID != fProgramData->fProgramID) { GR_GL(UseProgram(fProgramData->fProgramID)); fHWProgramID = fProgramData->fProgramID; } if (!fCurrentProgram.doGLSetup(type, fProgramData)) { return false; } #if ATTRIBUTE_MATRIX GrMatrix& currViewMatrix = fHWDrawState.fViewMatrix; #else GrMatrix& currViewMatrix = fProgramData->fViewMatrix; #endif if (currViewMatrix != fCurrDrawState.fViewMatrix) { flushViewMatrix(); currViewMatrix = fCurrDrawState.fViewMatrix; } for (int s = 0; s < kNumStages; ++s) { GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; if (NULL != texture) { if (-1 != fProgramData->fUniLocations.fStages[s].fTextureMatrixUni && (((1 << s) & fDirtyFlags.fTextureChangedMask) || getHWSamplerMatrix(s) != getSamplerMatrix(s))) { flushTextureMatrix(s); recordHWSamplerMatrix(s, getSamplerMatrix(s)); } } const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s]; if (-1 != fProgramData->fUniLocations.fStages[s].fRadial2Uni && (fProgramData->fRadial2CenterX1[s] != sampler.getRadial2CenterX1() || fProgramData->fRadial2Radius0[s] != sampler.getRadial2Radius0() || fProgramData->fRadial2PosRoot[s] != sampler.isRadial2PosRoot())) { flushRadial2(s); fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1(); fProgramData->fRadial2Radius0[s] = sampler.getRadial2Radius0(); fProgramData->fRadial2PosRoot[s] = sampler.isRadial2PosRoot(); } } resetDirtyFlags(); return true; }
bool GrGpuGLShaders::flushGraphicsState(GrPrimitiveType type) { if (!flushGLStateCommon(type)) { return false; } if (fDirtyFlags.fRenderTargetChanged) { // our coords are in pixel space and the GL matrices map to NDC // so if the viewport changed, our matrix is now wrong. fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix(); // we assume all shader matrices may be wrong after viewport changes fProgramCache->invalidateViewMatrices(); } GrBlendCoeff srcCoeff; GrBlendCoeff dstCoeff; BlendOptFlags blendOpts = this->getBlendOpts(false, &srcCoeff, &dstCoeff); if (kSkipDraw_BlendOptFlag & blendOpts) { return false; } this->buildProgram(type, blendOpts, dstCoeff); fProgramData = fProgramCache->getProgramData(fCurrentProgram); if (NULL == fProgramData) { GrAssert(!"Failed to create program!"); return false; } if (fHWProgramID != fProgramData->fProgramID) { GL_CALL(UseProgram(fProgramData->fProgramID)); fHWProgramID = fProgramData->fProgramID; } fCurrentProgram.overrideBlend(&srcCoeff, &dstCoeff); this->flushBlend(type, srcCoeff, dstCoeff); GrColor color; if (blendOpts & kEmitTransBlack_BlendOptFlag) { color = 0; } else if (blendOpts & kEmitCoverage_BlendOptFlag) { color = 0xffffffff; } else { color = fCurrDrawState.fColor; } this->flushColor(color); GrMatrix* currViewMatrix; if (GrGLProgram::kSetAsAttribute == fProgramData->fUniLocations.fViewMatrixUni) { currViewMatrix = &fHWDrawState.fViewMatrix; } else { currViewMatrix = &fProgramData->fViewMatrix; } if (*currViewMatrix != fCurrDrawState.fViewMatrix) { flushViewMatrix(); *currViewMatrix = fCurrDrawState.fViewMatrix; } for (int s = 0; s < GrDrawState::kNumStages; ++s) { this->flushTextureMatrix(s); this->flushRadial2(s); this->flushConvolution(s); this->flushTexelSize(s); this->flushTextureDomain(s); } this->flushEdgeAAData(); resetDirtyFlags(); return true; }