| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
| 9 | 9 |
| 10 #include "GrAutoLocaleSetter.h" | 10 #include "GrAutoLocaleSetter.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 return pb->finalize(); | 50 return pb->finalize(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 ///////////////////////////////////////////////////////////////////////////// | 53 ///////////////////////////////////////////////////////////////////////////// |
| 54 | 54 |
| 55 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) | 55 GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) |
| 56 : fVS(this) | 56 : fVS(this) |
| 57 , fGS(this) | 57 , fGS(this) |
| 58 , fFS(this, args.fDesc->header().fFragPosKey) | 58 , fFS(this, args.fDesc->header().fFragPosKey) |
| 59 , fOutOfStage(true) | |
| 60 , fStageIndex(-1) | 59 , fStageIndex(-1) |
| 61 , fGeometryProcessor(nullptr) | 60 , fGeometryProcessor(nullptr) |
| 62 , fXferProcessor(nullptr) | 61 , fXferProcessor(nullptr) |
| 63 , fArgs(args) | 62 , fArgs(args) |
| 64 , fGpu(gpu) | 63 , fGpu(gpu) |
| 65 , fUniforms(kVarsPerBlock) | 64 , fUniforms(kVarsPerBlock) |
| 66 , fSamplerUniforms(4) | 65 , fSamplerUniforms(4) |
| 67 , fSeparableVaryingInfos(kVarsPerBlock) { | 66 , fSeparableVaryingInfos(kVarsPerBlock) { |
| 68 } | 67 } |
| 69 | 68 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 100 fArgs.fPrimitiveProcessor->isPathRendering() && | 99 fArgs.fPrimitiveProcessor->isPathRendering() && |
| 101 !fArgs.fPrimitiveProcessor->willUseGeoShader() && | 100 !fArgs.fPrimitiveProcessor->willUseGeoShader() && |
| 102 fArgs.fPrimitiveProcessor->numAttribs() == 0); | 101 fArgs.fPrimitiveProcessor->numAttribs() == 0); |
| 103 this->addVarying(name, v, fsPrecision); | 102 this->addVarying(name, v, fsPrecision); |
| 104 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back(); | 103 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back(); |
| 105 varyingInfo.fVariable = this->getFragmentShaderBuilder()->fInputs.back(); | 104 varyingInfo.fVariable = this->getFragmentShaderBuilder()->fInputs.back(); |
| 106 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; | 105 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; |
| 107 return SeparableVaryingHandle(varyingInfo.fLocation); | 106 return SeparableVaryingHandle(varyingInfo.fLocation); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na
me) { | 109 void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na
me, bool mangle) { |
| 111 if ('\0' == prefix) { | 110 if ('\0' == prefix) { |
| 112 *out = name; | 111 *out = name; |
| 113 } else { | 112 } else { |
| 114 out->printf("%c%s", prefix, name); | 113 out->printf("%c%s", prefix, name); |
| 115 } | 114 } |
| 116 if (!fOutOfStage) { | 115 if (mangle) { |
| 117 if (out->endsWith('_')) { | 116 if (out->endsWith('_')) { |
| 118 // Names containing "__" are reserved. | 117 // Names containing "__" are reserved. |
| 119 out->append("x"); | 118 out->append("x"); |
| 120 } | 119 } |
| 121 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str()); | 120 out->appendf("_Stage%d%s", fStageIndex, fFS.getMangleString().c_str()); |
| 122 } | 121 } |
| 123 } | 122 } |
| 124 | 123 |
| 125 GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray( | 124 GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformAr
ray( |
| 126 uint32_t visibil
ity, | 125 uint32_t visibil
ity, |
| 127 GrSLType type, | 126 GrSLType type, |
| 128 GrSLPrecision pr
ecision, | 127 GrSLPrecision pr
ecision, |
| 129 const char* name
, | 128 const char* name
, |
| 129 bool mangleName, |
| 130 int count, | 130 int count, |
| 131 const char** out
Name) { | 131 const char** out
Name) { |
| 132 SkASSERT(name && strlen(name)); | 132 SkASSERT(name && strlen(name)); |
| 133 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFr
agment_Visibility); | 133 SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFr
agment_Visibility); |
| 134 SkASSERT(0 == (~kVisibilityMask & visibility)); | 134 SkASSERT(0 == (~kVisibilityMask & visibility)); |
| 135 SkASSERT(0 != visibility); | 135 SkASSERT(0 != visibility); |
| 136 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); | 136 SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type)); |
| 137 | 137 |
| 138 UniformInfo& uni = fUniforms.push_back(); | 138 UniformInfo& uni = fUniforms.push_back(); |
| 139 uni.fVariable.setType(type); | 139 uni.fVariable.setType(type); |
| 140 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); | 140 uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier); |
| 141 // TODO this is a bit hacky, lets think of a better way. Basically we need
to be able to use | 141 // TODO this is a bit hacky, lets think of a better way. Basically we need
to be able to use |
| 142 // the uniform view matrix name in the GP, and the GP is immutable so it has
to tell the PB | 142 // the uniform view matrix name in the GP, and the GP is immutable so it has
to tell the PB |
| 143 // exactly what name it wants to use for the uniform view matrix. If we pre
fix anythings, then | 143 // exactly what name it wants to use for the uniform view matrix. If we pre
fix anythings, then |
| 144 // the names will mismatch. I think the correct solution is to have all GPs
which need the | 144 // the names will mismatch. I think the correct solution is to have all GPs
which need the |
| 145 // uniform view matrix, they should upload the view matrix in their setData
along with regular | 145 // uniform view matrix, they should upload the view matrix in their setData
along with regular |
| 146 // uniforms. | 146 // uniforms. |
| 147 char prefix = 'u'; | 147 char prefix = 'u'; |
| 148 if ('u' == name[0]) { | 148 if ('u' == name[0]) { |
| 149 prefix = '\0'; | 149 prefix = '\0'; |
| 150 } | 150 } |
| 151 this->nameVariable(uni.fVariable.accessName(), prefix, name); | 151 this->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName); |
| 152 uni.fVariable.setArrayCount(count); | 152 uni.fVariable.setArrayCount(count); |
| 153 uni.fVisibility = visibility; | 153 uni.fVisibility = visibility; |
| 154 uni.fVariable.setPrecision(precision); | 154 uni.fVariable.setPrecision(precision); |
| 155 | 155 |
| 156 if (outName) { | 156 if (outName) { |
| 157 *outName = uni.fVariable.c_str(); | 157 *outName = uni.fVariable.c_str(); |
| 158 } | 158 } |
| 159 return GrGLSLProgramDataManager::UniformHandle(fUniforms.count() - 1); | 159 return GrGLSLProgramDataManager::UniformHandle(fUniforms.count() - 1); |
| 160 } | 160 } |
| 161 | 161 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 544 } |
| 545 | 545 |
| 546 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 546 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 547 | 547 |
| 548 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 548 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
| 549 int numProcs = fProcs.count(); | 549 int numProcs = fProcs.count(); |
| 550 for (int i = 0; i < numProcs; ++i) { | 550 for (int i = 0; i < numProcs; ++i) { |
| 551 delete fProcs[i]; | 551 delete fProcs[i]; |
| 552 } | 552 } |
| 553 } | 553 } |
| OLD | NEW |