junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "GrGLProgram.h" |
| 9 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 10 | #include "GrAllocator.h" |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 11 | #include "GrEffect.h" |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 12 | #include "GrCoordTransform.h" |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 13 | #include "GrDrawEffect.h" |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 14 | #include "GrGLEffect.h" |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 15 | #include "GrGpuGL.h" |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 16 | #include "GrGLShaderVar.h" |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 17 | #include "GrGLSL.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 18 | #include "SkXfermode.h" |
| 19 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 20 | SK_DEFINE_INST_COUNT(GrGLProgram) |
| 21 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 22 | #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 23 | #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 25 | GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 26 | const GrGLProgramDesc& desc, |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 27 | const GrEffectStage* colorStages[], |
| 28 | const GrEffectStage* coverageStages[]) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 29 | GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gpu, desc, colorStages, coverageStages)); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 30 | if (!program->succeeded()) { |
| 31 | delete program; |
| 32 | program = NULL; |
| 33 | } |
| 34 | return program; |
| 35 | } |
| 36 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 37 | GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 38 | const GrGLProgramDesc& desc, |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 39 | const GrEffectStage* colorStages[], |
| 40 | const GrEffectStage* coverageStages[]) |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 41 | : fGpu(gpu) |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 42 | , fUniformManager(gpu) |
| 43 | , fHasVertexShader(false) |
| 44 | , fNumTexCoordSets(0) { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 45 | fDesc = desc; |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 46 | fProgramID = 0; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 47 | |
bsalomon@google.com | 804e994 | 2013-06-06 18:04:38 +0000 | [diff] [blame] | 48 | fDstCopyTexUnit = -1; |
| 49 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 50 | fColor = GrColor_ILLEGAL; |
| 51 | fColorFilterColor = GrColor_ILLEGAL; |
| 52 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 53 | if (fDesc.getHeader().fHasVertexCode || |
commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame^] | 54 | !fGpu->shouldUseFixedFunctionTexturing()) { |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 55 | GrGLFullShaderBuilder fullBuilder(fGpu, fUniformManager, fDesc); |
| 56 | if (this->genProgram(&fullBuilder, colorStages, coverageStages)) { |
| 57 | fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUniform(); |
| 58 | fHasVertexShader = true; |
| 59 | } |
| 60 | } else { |
| 61 | GrGLFragmentOnlyShaderBuilder fragmentOnlyBuilder(fGpu, fUniformManager, fDesc); |
| 62 | if (this->genProgram(&fragmentOnlyBuilder, colorStages, coverageStages)) { |
| 63 | fNumTexCoordSets = fragmentOnlyBuilder.getNumTexCoordSets(); |
| 64 | } |
| 65 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | GrGLProgram::~GrGLProgram() { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 69 | if (fProgramID) { |
| 70 | GL_CALL(DeleteProgram(fProgramID)); |
| 71 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 72 | } |
| 73 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 74 | void GrGLProgram::abandon() { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 75 | fProgramID = 0; |
| 76 | } |
| 77 | |
tomhudson@google.com | 0d3f1fb | 2011-06-01 19:27:31 +0000 | [diff] [blame] | 78 | void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 79 | GrBlendCoeff* dstCoeff) const { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 80 | switch (fDesc.getHeader().fCoverageOutput) { |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 81 | case GrGLProgramDesc::kModulate_CoverageOutput: |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 82 | break; |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 83 | // The prog will write a coverage value to the secondary |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 84 | // output and the dst is blended by one minus that value. |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 85 | case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: |
| 86 | case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: |
| 87 | case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: |
| 88 | *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 89 | break; |
| 90 | case GrGLProgramDesc::kCombineWithDst_CoverageOutput: |
| 91 | // We should only have set this if the blend was specified as (1, 0) |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 92 | SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *dstCoeff); |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 93 | break; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 94 | default: |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 95 | GrCrash("Unexpected coverage output"); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 100 | namespace { |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 101 | // given two blend coefficients determine whether the src |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 102 | // and/or dst computation can be omitted. |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 103 | inline void need_blend_inputs(SkXfermode::Coeff srcCoeff, |
| 104 | SkXfermode::Coeff dstCoeff, |
| 105 | bool* needSrcValue, |
| 106 | bool* needDstValue) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 107 | if (SkXfermode::kZero_Coeff == srcCoeff) { |
| 108 | switch (dstCoeff) { |
| 109 | // these all read the src |
| 110 | case SkXfermode::kSC_Coeff: |
| 111 | case SkXfermode::kISC_Coeff: |
| 112 | case SkXfermode::kSA_Coeff: |
| 113 | case SkXfermode::kISA_Coeff: |
| 114 | *needSrcValue = true; |
| 115 | break; |
| 116 | default: |
| 117 | *needSrcValue = false; |
| 118 | break; |
| 119 | } |
| 120 | } else { |
| 121 | *needSrcValue = true; |
| 122 | } |
| 123 | if (SkXfermode::kZero_Coeff == dstCoeff) { |
| 124 | switch (srcCoeff) { |
| 125 | // these all read the dst |
| 126 | case SkXfermode::kDC_Coeff: |
| 127 | case SkXfermode::kIDC_Coeff: |
| 128 | case SkXfermode::kDA_Coeff: |
| 129 | case SkXfermode::kIDA_Coeff: |
| 130 | *needDstValue = true; |
| 131 | break; |
| 132 | default: |
| 133 | *needDstValue = false; |
| 134 | break; |
| 135 | } |
| 136 | } else { |
| 137 | *needDstValue = true; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 142 | * Create a blend_coeff * value string to be used in shader code. Sets empty |
| 143 | * string if result is trivially zero. |
| 144 | */ |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 145 | inline void blend_term_string(SkString* str, SkXfermode::Coeff coeff, |
| 146 | const char* src, const char* dst, |
| 147 | const char* value) { |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 148 | switch (coeff) { |
| 149 | case SkXfermode::kZero_Coeff: /** 0 */ |
| 150 | *str = ""; |
| 151 | break; |
| 152 | case SkXfermode::kOne_Coeff: /** 1 */ |
| 153 | *str = value; |
| 154 | break; |
| 155 | case SkXfermode::kSC_Coeff: |
| 156 | str->printf("(%s * %s)", src, value); |
| 157 | break; |
| 158 | case SkXfermode::kISC_Coeff: |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 159 | str->printf("((vec4(1) - %s) * %s)", src, value); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 160 | break; |
| 161 | case SkXfermode::kDC_Coeff: |
| 162 | str->printf("(%s * %s)", dst, value); |
| 163 | break; |
| 164 | case SkXfermode::kIDC_Coeff: |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 165 | str->printf("((vec4(1) - %s) * %s)", dst, value); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 166 | break; |
| 167 | case SkXfermode::kSA_Coeff: /** src alpha */ |
| 168 | str->printf("(%s.a * %s)", src, value); |
| 169 | break; |
| 170 | case SkXfermode::kISA_Coeff: /** inverse src alpha (i.e. 1 - sa) */ |
| 171 | str->printf("((1.0 - %s.a) * %s)", src, value); |
| 172 | break; |
| 173 | case SkXfermode::kDA_Coeff: /** dst alpha */ |
| 174 | str->printf("(%s.a * %s)", dst, value); |
| 175 | break; |
| 176 | case SkXfermode::kIDA_Coeff: /** inverse dst alpha (i.e. 1 - da) */ |
| 177 | str->printf("((1.0 - %s.a) * %s)", dst, value); |
| 178 | break; |
| 179 | default: |
| 180 | GrCrash("Unexpected xfer coeff."); |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | /** |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 185 | * Adds a line to the fragment shader code which modifies the color by |
| 186 | * the specified color filter. |
| 187 | */ |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 188 | void add_color_filter(GrGLShaderBuilder* builder, |
| 189 | const char * outputVar, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 190 | SkXfermode::Coeff uniformCoeff, |
| 191 | SkXfermode::Coeff colorCoeff, |
| 192 | const char* filterColor, |
| 193 | const char* inColor) { |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 194 | SkString colorStr, constStr; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 195 | blend_term_string(&colorStr, colorCoeff, filterColor, inColor, inColor); |
| 196 | blend_term_string(&constStr, uniformCoeff, filterColor, inColor, filterColor); |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 197 | GrGLSLExpr<4> sum; |
| 198 | if (colorStr.isEmpty() && constStr.isEmpty()) { |
| 199 | sum = GrGLSLExpr<4>(0); |
| 200 | } else if (colorStr.isEmpty()) { |
| 201 | sum = constStr; |
| 202 | } else if (constStr.isEmpty()) { |
| 203 | sum = colorStr; |
| 204 | } else { |
| 205 | sum = GrGLSLExpr<4>(colorStr) + GrGLSLExpr<4>(constStr); |
| 206 | } |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 207 | builder->fsCodeAppendf("\t%s = %s;\n", outputVar, sum.c_str()); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 208 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 209 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 210 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 211 | bool GrGLProgram::genProgram(GrGLShaderBuilder* builder, |
| 212 | const GrEffectStage* colorStages[], |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 213 | const GrEffectStage* coverageStages[]) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 214 | SkASSERT(0 == fProgramID); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 215 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 216 | const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 217 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 218 | // incoming color to current stage being processed. |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 219 | GrGLSLExpr<4> inColor = builder->getInputColor(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 220 | |
commit-bot@chromium.org | a4acf12 | 2013-09-30 15:13:58 +0000 | [diff] [blame] | 221 | // Get the coeffs for the Mode-based color filter, determine if color is needed. |
| 222 | SkXfermode::Coeff colorCoeff; |
| 223 | SkXfermode::Coeff filterColorCoeff; |
| 224 | SkAssertResult( |
commit-bot@chromium.org | 949eef0 | 2013-10-01 18:43:29 +0000 | [diff] [blame] | 225 | SkXfermode::ModeAsCoeff(header.fColorFilterXfermode, |
commit-bot@chromium.org | a4acf12 | 2013-09-30 15:13:58 +0000 | [diff] [blame] | 226 | &filterColorCoeff, |
| 227 | &colorCoeff)); |
| 228 | bool needColor, needFilterColor; |
| 229 | need_blend_inputs(filterColorCoeff, colorCoeff, &needFilterColor, &needColor); |
| 230 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 231 | fColorEffects.reset( |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 232 | builder->createAndEmitEffects(colorStages, |
| 233 | fDesc.effectKeys(), |
| 234 | needColor ? fDesc.numColorEffects() : 0, |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 235 | &inColor)); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 236 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 237 | // Insert the color filter. This will soon be replaced by a color effect. |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 238 | if (SkXfermode::kDst_Mode != header.fColorFilterXfermode) { |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 239 | const char* colorFilterColorUniName = NULL; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 240 | fUniformHandles.fColorFilterUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 241 | kVec4f_GrSLType, "FilterColor", |
| 242 | &colorFilterColorUniName); |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 243 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 244 | builder->fsCodeAppend("\tvec4 filteredColor;\n"); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 245 | add_color_filter(builder, "filteredColor", filterColorCoeff, |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 246 | colorCoeff, colorFilterColorUniName, inColor.c_str()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 247 | inColor = "filteredColor"; |
| 248 | } |
| 249 | |
| 250 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 251 | // compute the partial coverage |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 252 | GrGLSLExpr<4> inCoverage = builder->getInputCoverage(); |
skia.committer@gmail.com | cb6dc75 | 2013-04-19 07:01:00 +0000 | [diff] [blame] | 253 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 254 | fCoverageEffects.reset( |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 255 | builder->createAndEmitEffects(coverageStages, |
| 256 | fDesc.getEffectKeys() + fDesc.numColorEffects(), |
| 257 | fDesc.numCoverageEffects(), |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 258 | &inCoverage)); |
bsalomon@google.com | 504976e | 2013-05-09 13:45:02 +0000 | [diff] [blame] | 259 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 260 | // discard if coverage is zero |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 261 | if (header.fDiscardIfZeroCoverage && !inCoverage.isOnes()) { |
| 262 | if (inCoverage.isZeros()) { |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 263 | // This is unfortunate. |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 264 | builder->fsCodeAppend("\tdiscard;\n"); |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 265 | } else { |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 266 | builder->fsCodeAppendf("\tif (all(lessThanEqual(%s, vec4(0.0)))) {\n\t\tdiscard;\n\t}\n", |
| 267 | inCoverage.c_str()); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 268 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 269 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 270 | |
commit-bot@chromium.org | 949eef0 | 2013-10-01 18:43:29 +0000 | [diff] [blame] | 271 | if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutput)) { |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 272 | const char* secondaryOutputName = builder->enableSecondaryOutput(); |
commit-bot@chromium.org | 410552a | 2013-09-30 15:30:27 +0000 | [diff] [blame] | 273 | |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 274 | // default coeff to ones for kCoverage_DualSrcOutput |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 275 | GrGLSLExpr<4> coeff(1); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 276 | if (GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput == header.fCoverageOutput) { |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 277 | // Get (1-A) into coeff |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 278 | coeff = GrGLSLExprCast4(GrGLSLExpr<1>(1) - GrGLSLExprExtractAlpha(inColor)); |
commit-bot@chromium.org | 949eef0 | 2013-10-01 18:43:29 +0000 | [diff] [blame] | 279 | } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == header.fCoverageOutput) { |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 280 | // Get (1-RGBA) into coeff |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 281 | coeff = GrGLSLExpr<4>(1) - inColor; |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 282 | } |
| 283 | // Get coeff * coverage into modulate and then write that to the dual source output. |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 284 | builder->fsCodeAppendf("\t%s = %s;\n", secondaryOutputName, (coeff * inCoverage).c_str()); |
bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 285 | } |
| 286 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 287 | /////////////////////////////////////////////////////////////////////////// |
| 288 | // combine color and coverage as frag color |
| 289 | |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 290 | // Get "color * coverage" into fragColor |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 291 | GrGLSLExpr<4> fragColor = inColor * inCoverage; |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 292 | // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so. |
commit-bot@chromium.org | 949eef0 | 2013-10-01 18:43:29 +0000 | [diff] [blame] | 293 | if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutput) { |
commit-bot@chromium.org | 824c346 | 2013-10-10 06:30:18 +0000 | [diff] [blame] | 294 | GrGLSLExpr<4> dstCoeff = GrGLSLExpr<4>(1) - inCoverage; |
| 295 | |
| 296 | GrGLSLExpr<4> dstContribution = dstCoeff * GrGLSLExpr<4>(builder->dstColor()); |
| 297 | |
| 298 | fragColor = fragColor + dstContribution; |
bsalomon@google.com | 5920ac2 | 2013-04-19 13:14:45 +0000 | [diff] [blame] | 299 | } |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 300 | builder->fsCodeAppendf("\t%s = %s;\n", builder->getColorOutputName(), fragColor.c_str()); |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 302 | if (!builder->finish(&fProgramID)) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 303 | return false; |
| 304 | } |
| 305 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 306 | fUniformHandles.fRTHeightUni = builder->getRTHeightUniform(); |
| 307 | fUniformHandles.fDstCopyTopLeftUni = builder->getDstCopyTopLeftUniform(); |
| 308 | fUniformHandles.fDstCopyScaleUni = builder->getDstCopyScaleUniform(); |
| 309 | fUniformHandles.fColorUni = builder->getColorUniform(); |
| 310 | fUniformHandles.fCoverageUni = builder->getCoverageUniform(); |
| 311 | fUniformHandles.fDstCopySamplerUni = builder->getDstCopySamplerUniform(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 312 | // This must be called after we set fDstCopySamplerUni above. |
| 313 | this->initSamplerUniforms(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 314 | |
| 315 | return true; |
| 316 | } |
| 317 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 318 | void GrGLProgram::initSamplerUniforms() { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 319 | GL_CALL(UseProgram(fProgramID)); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 320 | GrGLint texUnitIdx = 0; |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 321 | if (fUniformHandles.fDstCopySamplerUni.isValid()) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 322 | fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitIdx); |
bsalomon@google.com | 804e994 | 2013-06-06 18:04:38 +0000 | [diff] [blame] | 323 | fDstCopyTexUnit = texUnitIdx++; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 324 | } |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 325 | fColorEffects->initSamplers(fUniformManager, &texUnitIdx); |
| 326 | fCoverageEffects->initSamplers(fUniformManager, &texUnitIdx); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 327 | } |
| 328 | |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 329 | /////////////////////////////////////////////////////////////////////////////// |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 330 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 331 | void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 332 | const GrEffectStage* colorStages[], |
| 333 | const GrEffectStage* coverageStages[], |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 334 | const GrDeviceCoordTexture* dstCopy, |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 335 | SharedGLState* sharedState) { |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 336 | const GrDrawState& drawState = fGpu->getDrawState(); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 337 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 338 | GrColor color; |
| 339 | GrColor coverage; |
| 340 | if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { |
| 341 | color = 0; |
| 342 | coverage = 0; |
| 343 | } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { |
| 344 | color = 0xffffffff; |
| 345 | coverage = drawState.getCoverage(); |
| 346 | } else { |
| 347 | color = drawState.getColor(); |
| 348 | coverage = drawState.getCoverage(); |
| 349 | } |
| 350 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 351 | this->setColor(drawState, color, sharedState); |
| 352 | this->setCoverage(drawState, coverage, sharedState); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 353 | this->setMatrixAndRenderTargetHeight(drawState); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 354 | |
| 355 | // Setup the SkXfermode::Mode-based colorfilter uniform if necessary |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 356 | if (fUniformHandles.fColorFilterUni.isValid() && |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 357 | fColorFilterColor != drawState.getColorFilterColor()) { |
| 358 | GrGLfloat c[4]; |
| 359 | GrColorToRGBAFloat(drawState.getColorFilterColor(), c); |
| 360 | fUniformManager.set4fv(fUniformHandles.fColorFilterUni, 0, 1, c); |
| 361 | fColorFilterColor = drawState.getColorFilterColor(); |
| 362 | } |
| 363 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 364 | if (NULL != dstCopy) { |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 365 | if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 366 | fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni, |
| 367 | static_cast<GrGLfloat>(dstCopy->offset().fX), |
| 368 | static_cast<GrGLfloat>(dstCopy->offset().fY)); |
| 369 | fUniformManager.set2f(fUniformHandles.fDstCopyScaleUni, |
| 370 | 1.f / dstCopy->texture()->width(), |
| 371 | 1.f / dstCopy->texture()->height()); |
| 372 | GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()); |
| 373 | static GrTextureParams kParams; // the default is clamp, nearest filtering. |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 374 | fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 375 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 376 | SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 377 | SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 378 | } |
| 379 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 380 | SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); |
| 381 | SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); |
| 382 | SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 383 | } |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 384 | |
commit-bot@chromium.org | 3390b9a | 2013-10-03 15:17:58 +0000 | [diff] [blame] | 385 | fColorEffects->setData(fGpu, fUniformManager, colorStages); |
| 386 | fCoverageEffects->setData(fGpu, fUniformManager, coverageStages); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 387 | |
| 388 | if (!fHasVertexShader) { |
| 389 | fGpu->disableUnusedTexGen(fNumTexCoordSets); |
| 390 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 391 | } |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 392 | |
| 393 | void GrGLProgram::setColor(const GrDrawState& drawState, |
| 394 | GrColor color, |
| 395 | SharedGLState* sharedState) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 396 | const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 397 | if (!drawState.hasColorVertexAttribute()) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 398 | switch (header.fColorInput) { |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 399 | case GrGLProgramDesc::kAttribute_ColorInput: |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 400 | SkASSERT(-1 != header.fColorAttributeIndex); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 401 | if (sharedState->fConstAttribColor != color || |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 402 | sharedState->fConstAttribColorIndex != header.fColorAttributeIndex) { |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 403 | // OpenGL ES only supports the float varieties of glVertexAttrib |
| 404 | GrGLfloat c[4]; |
| 405 | GrColorToRGBAFloat(color, c); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 406 | GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 407 | sharedState->fConstAttribColor = color; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 408 | sharedState->fConstAttribColorIndex = header.fColorAttributeIndex; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 409 | } |
| 410 | break; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 411 | case GrGLProgramDesc::kUniform_ColorInput: |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 412 | if (fColor != color) { |
| 413 | // OpenGL ES doesn't support unsigned byte varieties of glUniform |
| 414 | GrGLfloat c[4]; |
| 415 | GrColorToRGBAFloat(color, c); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 416 | fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c); |
| 417 | fColor = color; |
| 418 | } |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 419 | sharedState->fConstAttribColorIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 420 | break; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 421 | case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 422 | case GrGLProgramDesc::kTransBlack_ColorInput: |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 423 | sharedState->fConstAttribColorIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 424 | break; |
| 425 | default: |
| 426 | GrCrash("Unknown color type."); |
| 427 | } |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 428 | } else { |
| 429 | sharedState->fConstAttribColorIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | void GrGLProgram::setCoverage(const GrDrawState& drawState, |
| 434 | GrColor coverage, |
| 435 | SharedGLState* sharedState) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 436 | const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 437 | if (!drawState.hasCoverageVertexAttribute()) { |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 438 | switch (header.fCoverageInput) { |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 439 | case GrGLProgramDesc::kAttribute_ColorInput: |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 440 | if (sharedState->fConstAttribCoverage != coverage || |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 441 | sharedState->fConstAttribCoverageIndex != header.fCoverageAttributeIndex) { |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 442 | // OpenGL ES only supports the float varieties of glVertexAttrib |
| 443 | GrGLfloat c[4]; |
| 444 | GrColorToRGBAFloat(coverage, c); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 445 | GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 446 | sharedState->fConstAttribCoverage = coverage; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 447 | sharedState->fConstAttribCoverageIndex = header.fCoverageAttributeIndex; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 448 | } |
| 449 | break; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 450 | case GrGLProgramDesc::kUniform_ColorInput: |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 451 | if (fCoverage != coverage) { |
| 452 | // OpenGL ES doesn't support unsigned byte varieties of glUniform |
| 453 | GrGLfloat c[4]; |
| 454 | GrColorToRGBAFloat(coverage, c); |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 455 | fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c); |
| 456 | fCoverage = coverage; |
| 457 | } |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 458 | sharedState->fConstAttribCoverageIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 459 | break; |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 460 | case GrGLProgramDesc::kSolidWhite_ColorInput: |
| 461 | case GrGLProgramDesc::kTransBlack_ColorInput: |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 462 | sharedState->fConstAttribCoverageIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 463 | break; |
| 464 | default: |
| 465 | GrCrash("Unknown coverage type."); |
| 466 | } |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 467 | } else { |
| 468 | sharedState->fConstAttribCoverageIndex = -1; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 471 | |
| 472 | void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { |
| 473 | const GrRenderTarget* rt = drawState.getRenderTarget(); |
| 474 | SkISize size; |
| 475 | size.set(rt->width(), rt->height()); |
| 476 | |
| 477 | // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
commit-bot@chromium.org | 7425c12 | 2013-08-14 18:14:19 +0000 | [diff] [blame] | 478 | if (fUniformHandles.fRTHeightUni.isValid() && |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 479 | fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
| 480 | fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.fHeight)); |
| 481 | } |
| 482 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 483 | if (!fHasVertexShader) { |
| 484 | SkASSERT(!fUniformHandles.fViewMatrixUni.isValid()); |
| 485 | fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()); |
| 486 | } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 487 | fMatrixState.fRenderTargetSize != size || |
| 488 | !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())) { |
| 489 | SkASSERT(fUniformHandles.fViewMatrixUni.isValid()); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 490 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 491 | fMatrixState.fViewMatrix = drawState.getViewMatrix(); |
| 492 | fMatrixState.fRenderTargetSize = size; |
| 493 | fMatrixState.fRenderTargetOrigin = rt->origin(); |
commit-bot@chromium.org | 215a682 | 2013-09-05 18:28:42 +0000 | [diff] [blame] | 494 | |
| 495 | GrGLfloat viewMatrix[3 * 3]; |
| 496 | fMatrixState.getGLMatrix<3>(viewMatrix); |
| 497 | fUniformManager.setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix); |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 498 | } |
| 499 | } |