• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/ast/texture.h"
16 
17 TINT_INSTANTIATE_TYPEINFO(tint::ast::Texture);
18 
19 namespace tint {
20 namespace ast {
21 
operator <<(std::ostream & out,TextureDimension dim)22 std::ostream& operator<<(std::ostream& out, TextureDimension dim) {
23   switch (dim) {
24     case TextureDimension::kNone:
25       out << "None";
26       break;
27     case TextureDimension::k1d:
28       out << "1d";
29       break;
30     case TextureDimension::k2d:
31       out << "2d";
32       break;
33     case TextureDimension::k2dArray:
34       out << "2d_array";
35       break;
36     case TextureDimension::k3d:
37       out << "3d";
38       break;
39     case TextureDimension::kCube:
40       out << "cube";
41       break;
42     case TextureDimension::kCubeArray:
43       out << "cube_array";
44       break;
45   }
46   return out;
47 }
48 
IsTextureArray(TextureDimension dim)49 bool IsTextureArray(TextureDimension dim) {
50   switch (dim) {
51     case TextureDimension::k2dArray:
52     case TextureDimension::kCubeArray:
53       return true;
54     case TextureDimension::k2d:
55     case TextureDimension::kNone:
56     case TextureDimension::k1d:
57     case TextureDimension::k3d:
58     case TextureDimension::kCube:
59       return false;
60   }
61   return false;
62 }
63 
NumCoordinateAxes(TextureDimension dim)64 int NumCoordinateAxes(TextureDimension dim) {
65   switch (dim) {
66     case TextureDimension::kNone:
67       return 0;
68     case TextureDimension::k1d:
69       return 1;
70     case TextureDimension::k2d:
71     case TextureDimension::k2dArray:
72       return 2;
73     case TextureDimension::k3d:
74     case TextureDimension::kCube:
75     case TextureDimension::kCubeArray:
76       return 3;
77   }
78   return 0;
79 }
80 
Texture(ProgramID pid,const Source & src,TextureDimension d)81 Texture::Texture(ProgramID pid, const Source& src, TextureDimension d)
82     : Base(pid, src), dim(d) {}
83 
84 Texture::Texture(Texture&&) = default;
85 
86 Texture::~Texture() = default;
87 
88 }  // namespace ast
89 }  // namespace tint
90