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 #ifndef SRC_AST_TYPE_TEXTURE_TYPE_H_
16 #define SRC_AST_TYPE_TEXTURE_TYPE_H_
17 
18 #include <ostream>
19 #include <string>
20 
21 #include "src/ast/type/type.h"
22 
23 namespace tint {
24 namespace ast {
25 namespace type {
26 
27 class DepthTextureType;
28 class MultisampledTextureType;
29 class SampledTextureType;
30 class StorageTextureType;
31 
32 /// The dimensionality of the texture
33 enum class TextureDimension {
34   /// Invalid texture
35   kNone = -1,
36   /// 1 dimensional texture
37   k1d,
38   /// 1 dimenstional array texture
39   k1dArray,
40   /// 2 dimensional texture
41   k2d,
42   /// 2 dimensional array texture
43   k2dArray,
44   /// 3 dimensional texture
45   k3d,
46   /// cube texture
47   kCube,
48   /// cube array texture
49   kCubeArray,
50 };
51 std::ostream& operator<<(std::ostream& out, TextureDimension dim);
52 
53 /// A texture type.
54 class TextureType : public Type {
55  public:
56   /// Constructor
57   /// @param dim the dimensionality of the texture
58   explicit TextureType(TextureDimension dim);
59   /// Move constructor
60   TextureType(TextureType&&);
61   ~TextureType() override;
62 
63   /// @returns true if the type is a texture type
64   bool IsTexture() const override;
65 
66   /// @returns the texture dimension
dim()67   TextureDimension dim() const { return dim_; }
68 
69   /// @returns true if this is a depth texture
70   virtual bool IsDepth() const;
71   /// @returns ture if this is a multisampled texture
72   virtual bool IsMultisampled() const;
73   /// @returns true if this is a storage texture
74   virtual bool IsStorage() const;
75   /// @returns true if this is a sampled texture
76   virtual bool IsSampled() const;
77 
78   /// @returns the texture as a depth texture
79   const DepthTextureType* AsDepth() const;
80   /// @returns the texture as a multisampled texture
81   const MultisampledTextureType* AsMultisampled() const;
82   /// @returns the texture as a sampled texture
83   const SampledTextureType* AsSampled() const;
84   /// @returns the texture as a storage texture
85   const StorageTextureType* AsStorage() const;
86 
87   /// @returns the texture as a depth texture
88   DepthTextureType* AsDepth();
89   /// @returns the texture as a multisampled texture
90   MultisampledTextureType* AsMultisampled();
91   /// @returns the texture as a sampled texture
92   SampledTextureType* AsSampled();
93   /// @returns the texture as a storage texture
94   StorageTextureType* AsStorage();
95 
96  private:
97   TextureDimension dim_ = TextureDimension::k1d;
98 };
99 
100 }  // namespace type
101 }  // namespace ast
102 }  // namespace tint
103 
104 #endif  // SRC_AST_TYPE_TEXTURE_TYPE_H_
105