Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrShaderCaps.h" |
| 10 | #include "src/gpu/GrShaderVar.h" |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 11 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 12 | static const char* type_modifier_string(GrShaderVar::TypeModifier t) { |
| 13 | switch (t) { |
Ben Wagner | dabd98c | 2020-03-25 15:17:18 -0400 | [diff] [blame] | 14 | case GrShaderVar::TypeModifier::None: return ""; |
| 15 | case GrShaderVar::TypeModifier::In: return "in"; |
| 16 | case GrShaderVar::TypeModifier::InOut: return "inout"; |
| 17 | case GrShaderVar::TypeModifier::Out: return "out"; |
| 18 | case GrShaderVar::TypeModifier::Uniform: return "uniform"; |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 19 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 20 | SK_ABORT("Unknown shader variable type modifier."); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 21 | } |
| 22 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 23 | void GrShaderVar::appendDecl(const GrShaderCaps* shaderCaps, SkString* out) const { |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 24 | if (!fLayoutQualifier.isEmpty()) { |
| 25 | out->appendf("layout(%s) ", fLayoutQualifier.c_str()); |
| 26 | } |
Ben Wagner | dabd98c | 2020-03-25 15:17:18 -0400 | [diff] [blame] | 27 | if (!fExtraModifiers.isEmpty()) { |
| 28 | out->appendf("%s ", fExtraModifiers.c_str()); |
| 29 | } |
| 30 | if (this->getTypeModifier() != TypeModifier::None) { |
| 31 | out->appendf("%s ", type_modifier_string(this->getTypeModifier())); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 32 | } |
| 33 | GrSLType effectiveType = this->getType(); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 34 | if (this->isArray()) { |
| 35 | if (this->isUnsizedArray()) { |
Chris Dalton | 4f5cbcd | 2019-02-13 14:04:34 -0700 | [diff] [blame] | 36 | out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str()); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 37 | } else { |
| 38 | SkASSERT(this->getArrayCount() > 0); |
| 39 | out->appendf("%s %s[%d]", |
Chris Dalton | 4f5cbcd | 2019-02-13 14:04:34 -0700 | [diff] [blame] | 40 | GrGLSLTypeString(effectiveType), |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 41 | this->getName().c_str(), |
| 42 | this->getArrayCount()); |
| 43 | } |
| 44 | } else { |
Chris Dalton | 4f5cbcd | 2019-02-13 14:04:34 -0700 | [diff] [blame] | 45 | out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str()); |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 46 | } |
| 47 | } |