blob: d8dc98096fa776778db6ca59bcead192054156a5 [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)
fmalitad214d6a2016-09-30 08:05:24 -070025 , fOriginUpperLeft(layout.fOriginUpperLeft) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070026
fmalitad214d6a2016-09-30 08:05:24 -070027 Layout(int location, int binding, int index, int set, int builtin, bool originUpperLeft)
ethannicholasb3058bd2016-07-01 08:22:01 -070028 : fLocation(location)
29 , fBinding(binding)
30 , fIndex(index)
31 , fSet(set)
ethannicholasf789b382016-08-03 12:43:36 -070032 , fBuiltin(builtin)
fmalitad214d6a2016-09-30 08:05:24 -070033 , fOriginUpperLeft(originUpperLeft) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070034
35 std::string description() const {
36 std::string result;
37 std::string separator;
38 if (fLocation >= 0) {
39 result += separator + "location = " + to_string(fLocation);
40 separator = ", ";
41 }
42 if (fBinding >= 0) {
43 result += separator + "binding = " + to_string(fBinding);
44 separator = ", ";
45 }
46 if (fIndex >= 0) {
47 result += separator + "index = " + to_string(fIndex);
48 separator = ", ";
49 }
50 if (fSet >= 0) {
51 result += separator + "set = " + to_string(fSet);
52 separator = ", ";
53 }
54 if (fBuiltin >= 0) {
55 result += separator + "builtin = " + to_string(fBuiltin);
56 separator = ", ";
57 }
ethannicholasf789b382016-08-03 12:43:36 -070058 if (fOriginUpperLeft) {
59 result += separator + "origin_upper_left";
60 separator = ", ";
61 }
ethannicholasb3058bd2016-07-01 08:22:01 -070062 if (result.length() > 0) {
63 result = "layout (" + result + ")";
64 }
65 return result;
66 }
67
68 bool operator==(const Layout& other) const {
fmalitad214d6a2016-09-30 08:05:24 -070069 return fLocation == other.fLocation &&
70 fBinding == other.fBinding &&
71 fIndex == other.fIndex &&
72 fSet == other.fSet &&
73 fBuiltin == other.fBuiltin;
ethannicholasb3058bd2016-07-01 08:22:01 -070074 }
75
76 bool operator!=(const Layout& other) const {
77 return !(*this == other);
78 }
79
ethannicholasf789b382016-08-03 12:43:36 -070080 // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and identifies which
81 // particular builtin value this object represents.
82 int fLocation;
83 int fBinding;
84 int fIndex;
85 int fSet;
86 int fBuiltin;
87 bool fOriginUpperLeft;
ethannicholasb3058bd2016-07-01 08:22:01 -070088};
89
90} // namespace
91
92#endif