• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrShaderCaps.h"
10 #include "src/gpu/GrShaderVar.h"
11 
type_modifier_string(GrShaderVar::TypeModifier t)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 }
22 
setIOType(GrIOType ioType)23 void GrShaderVar::setIOType(GrIOType ioType) {
24     switch (ioType) {
25         case kRW_GrIOType:
26             return;
27         case kRead_GrIOType:
28             this->addModifier("readonly");
29             return;
30         case kWrite_GrIOType:
31             this->addModifier("writeonly");
32             return;
33     }
34     SK_ABORT("Unknown io type.");
35 }
36 
appendDecl(const GrShaderCaps * shaderCaps,SkString * out) const37 void GrShaderVar::appendDecl(const GrShaderCaps* shaderCaps, SkString* out) const {
38     SkString layout = fLayoutQualifier;
39     if (!fLayoutQualifier.isEmpty()) {
40         out->appendf("layout(%s) ", fLayoutQualifier.c_str());
41     }
42     out->append(fExtraModifiers);
43     if (this->getTypeModifier() != kNone_TypeModifier) {
44         out->append(type_modifier_string(this->getTypeModifier()));
45         out->append(" ");
46     }
47     GrSLType effectiveType = this->getType();
48     if (this->isArray()) {
49         if (this->isUnsizedArray()) {
50             out->appendf("%s %s[]", GrGLSLTypeString(effectiveType), this->getName().c_str());
51         } else {
52             SkASSERT(this->getArrayCount() > 0);
53             out->appendf("%s %s[%d]",
54                          GrGLSLTypeString(effectiveType),
55                          this->getName().c_str(),
56                          this->getArrayCount());
57         }
58     } else {
59         out->appendf("%s %s", GrGLSLTypeString(effectiveType), this->getName().c_str());
60     }
61 }
62