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