blob: 24087d06121a817c45923235ade277b8649d7c54 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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#ifndef SKSL_LAYOUT
9#define SKSL_LAYOUT
10
11namespace SkSL {
12
13/**
14 * Represents a layout block appearing before a variable declaration, as in:
15 *
16 * layout (location = 0) int x;
17 */
18struct Layout {
19 Layout(const ASTLayout& layout)
20 : fLocation(layout.fLocation)
21 , fBinding(layout.fBinding)
22 , fIndex(layout.fIndex)
23 , fSet(layout.fSet)
ethannicholasf789b382016-08-03 12:43:36 -070024 , fBuiltin(layout.fBuiltin)
ethannicholasdcfe6db2016-10-10 10:09:00 -070025 , fOriginUpperLeft(layout.fOriginUpperLeft)
26 , fOverrideCoverage(layout.fOverrideCoverage)
27 , fBlendSupportAllEquations(layout.fBlendSupportAllEquations) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070028
ethannicholasdcfe6db2016-10-10 10:09:00 -070029 Layout(int location, int binding, int index, int set, int builtin, bool originUpperLeft,
30 bool overrideCoverage, bool blendSupportAllEquations)
ethannicholasb3058bd2016-07-01 08:22:01 -070031 : fLocation(location)
32 , fBinding(binding)
33 , fIndex(index)
34 , fSet(set)
ethannicholasf789b382016-08-03 12:43:36 -070035 , fBuiltin(builtin)
ethannicholasdcfe6db2016-10-10 10:09:00 -070036 , fOriginUpperLeft(originUpperLeft)
37 , fOverrideCoverage(overrideCoverage)
38 , fBlendSupportAllEquations(blendSupportAllEquations) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070039
40 std::string description() const {
41 std::string result;
42 std::string separator;
43 if (fLocation >= 0) {
44 result += separator + "location = " + to_string(fLocation);
45 separator = ", ";
46 }
47 if (fBinding >= 0) {
48 result += separator + "binding = " + to_string(fBinding);
49 separator = ", ";
50 }
51 if (fIndex >= 0) {
52 result += separator + "index = " + to_string(fIndex);
53 separator = ", ";
54 }
55 if (fSet >= 0) {
56 result += separator + "set = " + to_string(fSet);
57 separator = ", ";
58 }
59 if (fBuiltin >= 0) {
60 result += separator + "builtin = " + to_string(fBuiltin);
61 separator = ", ";
62 }
ethannicholasf789b382016-08-03 12:43:36 -070063 if (fOriginUpperLeft) {
64 result += separator + "origin_upper_left";
65 separator = ", ";
66 }
ethannicholasdcfe6db2016-10-10 10:09:00 -070067 if (fOverrideCoverage) {
68 result += separator + "override_coverage";
69 separator = ", ";
70 }
71 if (fBlendSupportAllEquations) {
72 result += separator + "blend_support_all_equations";
73 separator = ", ";
74 }
ethannicholasb3058bd2016-07-01 08:22:01 -070075 if (result.length() > 0) {
76 result = "layout (" + result + ")";
77 }
78 return result;
79 }
80
81 bool operator==(const Layout& other) const {
ethannicholasdcfe6db2016-10-10 10:09:00 -070082 return fLocation == other.fLocation &&
83 fBinding == other.fBinding &&
84 fIndex == other.fIndex &&
85 fSet == other.fSet &&
86 fBuiltin == other.fBuiltin &&
87 fOriginUpperLeft == other.fOriginUpperLeft &&
88 fOverrideCoverage == other.fOverrideCoverage &&
89 fBlendSupportAllEquations == other.fBlendSupportAllEquations;
ethannicholasb3058bd2016-07-01 08:22:01 -070090 }
91
92 bool operator!=(const Layout& other) const {
93 return !(*this == other);
94 }
95
ethannicholasf789b382016-08-03 12:43:36 -070096 // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and identifies which
97 // particular builtin value this object represents.
98 int fLocation;
99 int fBinding;
100 int fIndex;
101 int fSet;
102 int fBuiltin;
103 bool fOriginUpperLeft;
ethannicholasdcfe6db2016-10-10 10:09:00 -0700104 bool fOverrideCoverage;
105 bool fBlendSupportAllEquations;
ethannicholasb3058bd2016-07-01 08:22:01 -0700106};
107
108} // namespace
109
110#endif