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_Uniform_DEFINED 9 #define skgpu_Uniform_DEFINED 10 11 #include "experimental/graphite/src/DrawTypes.h" 12 13 namespace skgpu { 14 15 /** 16 * Describes a uniform. Uniforms consist of: 17 * type: The type of the uniform 18 * count: Number of elements of 'type' in the array or kNonArray if not an array. 19 */ 20 class Uniform { 21 public: 22 static constexpr int kNonArray = 0; 23 Uniform(const char * name,SLType type)24 constexpr Uniform(const char* name, SLType type) : Uniform(name, type, kNonArray) {} 25 Uniform(const char * name,SLType type,int count)26 constexpr Uniform(const char* name, SLType type, int count) 27 : fType (static_cast<unsigned>(type)) 28 , fCount (static_cast<unsigned>(count)) 29 , fName (name) { 30 } 31 32 constexpr Uniform(const Uniform&) = default; 33 Uniform& operator=(const Uniform&) = default; 34 isInitialized()35 constexpr bool isInitialized() const { return this->type() != SLType::kVoid; } 36 name()37 constexpr const char* name() const { return fName; } type()38 constexpr SLType type() const { return static_cast<SLType>(fType); } count()39 constexpr uint32_t count() const { return static_cast<uint32_t>(fCount); } 40 41 private: 42 uint32_t fType : 6; 43 uint32_t fCount : 26; 44 const char* fName; 45 46 static_assert(kSLTypeCount <= (1 << 6)); 47 }; 48 49 } // namespace skgpu 50 51 #endif // skgpu_Uniform_DEFINED 52