Sfoglia il codice sorgente

shader: Restore default array stride calculation

Don't return 0 from get_array_stride(), various things rely on being
able to always get a valid stride from this.
rdb 1 mese fa
parent
commit
6a63659ac8
3 ha cambiato i file con 18 aggiunte e 17 eliminazioni
  1. 0 8
      panda/src/gobj/shaderType.I
  2. 17 8
      panda/src/gobj/shaderType.cxx
  3. 1 1
      panda/src/gobj/shaderType.h

+ 0 - 8
panda/src/gobj/shaderType.I

@@ -193,14 +193,6 @@ get_num_elements() const {
   return _num_elements;
 }
 
-/**
- * Returns the array stride in bytes, or 0 if this was not specified.
- */
-INLINE uint32_t ShaderType::Array::
-get_stride_bytes() const {
-  return _stride_bytes;
-}
-
 /**
  * Constructs an image type.
  */

+ 17 - 8
panda/src/gobj/shaderType.cxx

@@ -957,6 +957,22 @@ make_from_bam(const FactoryParams &params) {
   return struct_type;
 }
 
+/**
+ * Returns the array stride in bytes.
+ */
+uint32_t ShaderType::Array::
+get_stride_bytes() const {
+  if (_stride_bytes != 0) {
+    return _stride_bytes;
+  } else {
+    // By default we assume std140 / DX9 conventions, where array stride is
+    // always (at least) 16 bytes, even though this is (indeed) incredibly
+    // wasteful for arrays of scalars.
+    uint32_t size = _element_type->get_size_bytes();
+    return (size + 15) & ~15;
+  }
+}
+
 /**
  * If this type is an array, puts the element type in the first argument and the
  * number of elements in the second argument, and returns true.  If not, puts
@@ -1115,14 +1131,7 @@ get_size_bytes() const {
   // Arrays have padding at the end so that the next member is aligned to a
   // 16-byte boundary.  This implies that a float may directly follow a vec3,
   // but not a vec3[1]!  I didn't make up these rules.
-  uint32_t stride_bytes = _stride_bytes;
-  if (stride_bytes == 0) {
-    // Array stride is always (at least) 16 bytes in std140 / DX9, even though
-    // this is (indeed) incredibly wasteful for arrays of scalars.
-    uint32_t size = _element_type->get_size_bytes();
-    stride_bytes = (size + 15) & ~15;
-  }
-  return stride_bytes * _num_elements;
+  return get_stride_bytes() * _num_elements;
 }
 
 /**

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

@@ -401,7 +401,7 @@ public:
 
   INLINE const ShaderType *get_element_type() const;
   INLINE uint32_t get_num_elements() const;
-  INLINE uint32_t get_stride_bytes() const;
+  uint32_t get_stride_bytes() const;
 
   virtual bool unwrap_array(const ShaderType *&element_type, uint32_t &num_elements) const override;