Browse Source

shader: Vectors have components, not elements

rdb 5 years ago
parent
commit
124aac5d90

+ 5 - 5
panda/src/gobj/shader.cxx

@@ -98,7 +98,7 @@ expect_float_vector(const InternalName *name, const ::ShaderType *type, int lo,
     scalar_type = scalar->get_scalar_type();
   }
   else if (const ::ShaderType::Vector *vector = type->as_vector()) {
-    nfloat = vector->get_num_elements();
+    nfloat = vector->get_num_components();
     scalar_type = vector->get_scalar_type();
   }
   else {
@@ -2225,7 +2225,7 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
         bind._part[1] = SMO_identity;
         bind._arg[1] = nullptr;
 
-        if (member.type->as_vector()->get_num_elements() == 3) {
+        if (member.type->as_vector()->get_num_components() == 3) {
           bind._piece = SMP_row3x3;
         } else {
           bind._piece = SMP_row3;
@@ -2280,13 +2280,13 @@ bind_parameter(CPT_InternalName name, const ::ShaderType *type, int location) {
               return false;
             }
             const ::ShaderType::Vector *vector = member.type->as_vector();
-            if (vector == nullptr || vector->get_num_elements() == 1) {
+            if (vector == nullptr || vector->get_num_components() == 1) {
               bind._piece = SMP_row3x1;
             }
-            else if (vector->get_num_elements() == 2) {
+            else if (vector->get_num_components() == 2) {
               bind._piece = SMP_row3x2;
             }
-            else if (vector->get_num_elements() == 3) {
+            else if (vector->get_num_components() == 3) {
               bind._piece = SMP_row3x3;
             }
             else {

+ 5 - 5
panda/src/gobj/shaderType.I

@@ -63,9 +63,9 @@ get_scalar_type() const {
  * Constructs a vector from a scalar type and number of elements.
  */
 INLINE ShaderType::Vector::
-Vector(ScalarType scalar_type, uint32_t num_elements) :
+Vector(ScalarType scalar_type, uint32_t num_components) :
   _scalar_type(scalar_type),
-  _num_elements(num_elements) {
+  _num_components(num_components) {
 }
 
 /**
@@ -77,11 +77,11 @@ get_scalar_type() const {
 }
 
 /**
- * Returns the number of elements in this vector.
+ * Returns the number of components in this vector.
  */
 INLINE uint32_t ShaderType::Vector::
-get_num_elements() const {
-  return _num_elements;
+get_num_components() const {
+  return _num_components;
 }
 
 /**

+ 4 - 4
panda/src/gobj/shaderType.cxx

@@ -124,7 +124,7 @@ as_scalar_type(ScalarType &type, uint32_t &num_elements,
   type = _scalar_type;
   num_elements = 1;
   num_rows = 1;
-  num_columns = _num_elements;
+  num_columns = _num_components;
   return true;
 }
 
@@ -133,7 +133,7 @@ as_scalar_type(ScalarType &type, uint32_t &num_elements,
  */
 void ShaderType::Vector::
 output(std::ostream &out) const {
-  out << _scalar_type << _num_elements;
+  out << _scalar_type << _num_components;
 }
 
 /**
@@ -146,8 +146,8 @@ compare_to_impl(const ShaderType &other) const {
   if (_scalar_type != other_vector._scalar_type) {
     return _scalar_type < other_vector._scalar_type ? -1 : 1;
   }
-  return (_num_elements > other_vector._num_elements)
-       - (_num_elements < other_vector._num_elements);
+  return (_num_components > other_vector._num_components)
+       - (_num_components < other_vector._num_components);
 }
 
 /**

+ 3 - 3
panda/src/gobj/shaderType.h

@@ -145,11 +145,11 @@ private:
  */
 class EXPCL_PANDA_GOBJ ShaderType::Vector final : public ShaderType {
 public:
-  INLINE Vector(ScalarType scalar_type, uint32_t num_elements);
+  INLINE Vector(ScalarType scalar_type, uint32_t num_components);
   Vector(const Vector &copy) = default;
 
   INLINE ScalarType get_scalar_type() const;
-  INLINE uint32_t get_num_elements() const;
+  INLINE uint32_t get_num_components() const;
 
   virtual bool as_scalar_type(ScalarType &type, uint32_t &num_elements,
                               uint32_t &num_rows, uint32_t &num_columns) const override;
@@ -162,7 +162,7 @@ private:
   virtual int compare_to_impl(const ShaderType &other) const override;
 
   const ScalarType _scalar_type;
-  const uint32_t _num_elements;
+  const uint32_t _num_components;
 
 public:
   static TypeHandle get_class_type() {

+ 1 - 1
panda/src/shaderpipeline/shaderModuleSpirV.cxx

@@ -285,7 +285,7 @@ parse_instruction(Definitions &defs, SpvOp opcode, const uint32_t *args, size_t
       DCAST_INTO_R(column_type, defs[args[1]]._type, false);
       uint32_t num_rows = args[2];
       defs[args[0]].set_type(ShaderType::register_type(
-        ShaderType::Matrix(column_type->get_scalar_type(), column_type->get_num_elements(), num_rows)));
+        ShaderType::Matrix(column_type->get_scalar_type(), num_rows, column_type->get_num_components())));
     }
     break;