• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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 skgpu_graphite_Attribute_DEFINED
9 #define skgpu_graphite_Attribute_DEFINED
10 
11 #include "include/private/base/SkAlign.h"
12 #include "src/core/SkSLTypeShared.h"
13 #include "src/gpu/graphite/DrawTypes.h"
14 
15 namespace skgpu::graphite {
16 
17  /** Describes a vertex or instance attribute. */
18 class Attribute {
19 public:
20     constexpr Attribute() = default;
Attribute(const char * name,VertexAttribType cpuType,SkSLType gpuType)21     constexpr Attribute(const char* name,
22                         VertexAttribType cpuType,
23                         SkSLType gpuType)
24             : fName(name), fCPUType(cpuType), fGPUType(gpuType) {
25         SkASSERT(name && gpuType != SkSLType::kVoid);
26     }
27     constexpr Attribute(const Attribute&) = default;
28 
29     Attribute& operator=(const Attribute&) = default;
30 
isInitialized()31     constexpr bool isInitialized() const { return fGPUType != SkSLType::kVoid; }
32 
name()33     constexpr const char*      name()    const { return fName; }
cpuType()34     constexpr VertexAttribType cpuType() const { return fCPUType; }
gpuType()35     constexpr SkSLType         gpuType() const { return fGPUType; }
36 
size()37     constexpr size_t size()       const { return VertexAttribTypeSize(fCPUType); }
sizeAlign4()38     constexpr size_t sizeAlign4() const { return SkAlign4(this->size()); }
39 
40 private:
41     const char* fName = nullptr;
42     VertexAttribType fCPUType = VertexAttribType::kFloat;
43     SkSLType fGPUType = SkSLType::kVoid;
44 };
45 
46 } // namespace skgpu::graphite
47 
48 #endif // skgpu_graphite_Attribute_DEFINED
49