1 /* 2 * Copyright 2016 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. 6 */ 7 8 9 #include "GrShaderVar.h" 10 #include "GrShaderCaps.h" 11 12 static const char* type_modifier_string(GrShaderVar::TypeModifier t) { 13 switch (t) { 14 case GrShaderVar::kNone_TypeModifier: return ""; 15 case GrShaderVar::kIn_TypeModifier: return "in"; 16 case GrShaderVar::kInOut_TypeModifier: return "inout"; 17 case GrShaderVar::kOut_TypeModifier: return "out"; 18 case GrShaderVar::kUniform_TypeModifier: return "uniform"; 19 } 20 SK_ABORT("Unknown shader variable type modifier."); 21 return ""; 22 } 23 24 void GrShaderVar::setIOType(GrIOType ioType) { 25 switch (ioType) { 26 case kRW_GrIOType: 27 return; 28 case kRead_GrIOType: 29 this->addModifier("readonly"); 30 return; 31 case kWrite_GrIOType: 32 this->addModifier("writeonly"); 33 return; 34 } 35 SK_ABORT("Unknown io type."); 36 } 37 38 void GrShaderVar::appendDecl(const GrShaderCaps* shaderCaps, SkString* out) const { 39 SkString layout = fLayoutQualifier; 40 if (!fLayoutQualifier.isEmpty()) { 41 out->appendf("layout(%s) ", fLayoutQualifier.c_str()); 42 } 43 out->append(fExtraModifiers); 44 if (this->getTypeModifier() != kNone_TypeModifier) { 45 out->append(type_modifier_string(this->getTypeModifier())); 46 out->append(" "); 47 } 48 GrSLType effectiveType = this->getType(); 49 if (this->isArray()) { 50 if (this->isUnsizedArray()) { 51 out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str()); 52 } else { 53 SkASSERT(this->getArrayCount() > 0); 54 out->appendf("%s %s[%d]", 55 GrGLSLTypeString(effectiveType), 56 this->getName().c_str(), 57 this->getArrayCount()); 58 } 59 } else { 60 out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str()); 61 } 62 } 63