瀏覽代碼

gobj: fix Python 3 support for GVADHandle::get_(sub)data/set_(sub)data

That said, you should really be using the buffer protocol; you can create a memoryview() directly around the GeomVertexArrayData.
rdb 7 年之前
父節點
當前提交
9231694f8f
共有 3 個文件被更改,包括 12 次插入10 次删除
  1. 6 4
      panda/src/gobj/geomVertexArrayData.I
  2. 2 2
      panda/src/gobj/geomVertexArrayData.cxx
  3. 4 4
      panda/src/gobj/geomVertexArrayData.h

+ 6 - 4
panda/src/gobj/geomVertexArrayData.I

@@ -518,10 +518,11 @@ prepare_now(PreparedGraphicsObjects *prepared_objects,
  * a string.  This is primarily for the benefit of high-level languages such
  * a string.  This is primarily for the benefit of high-level languages such
  * as Python.
  * as Python.
  */
  */
-INLINE std::string GeomVertexArrayDataHandle::
+INLINE vector_uchar GeomVertexArrayDataHandle::
 get_data() const {
 get_data() const {
   mark_used();
   mark_used();
-  return std::string((const char *)_cdata->_buffer.get_read_pointer(true), _cdata->_buffer.get_size());
+  const unsigned char *ptr = _cdata->_buffer.get_read_pointer(true);
+  return vector_uchar(ptr, ptr + _cdata->_buffer.get_size());
 }
 }
 
 
 /**
 /**
@@ -529,12 +530,13 @@ get_data() const {
  * formatted as a string.  This is primarily for the benefit of high-level
  * formatted as a string.  This is primarily for the benefit of high-level
  * languages such as Python.
  * languages such as Python.
  */
  */
-INLINE std::string GeomVertexArrayDataHandle::
+INLINE vector_uchar GeomVertexArrayDataHandle::
 get_subdata(size_t start, size_t size) const {
 get_subdata(size_t start, size_t size) const {
   mark_used();
   mark_used();
   start = std::min(start, _cdata->_buffer.get_size());
   start = std::min(start, _cdata->_buffer.get_size());
   size = std::min(size, _cdata->_buffer.get_size() - start);
   size = std::min(size, _cdata->_buffer.get_size() - start);
-  return std::string((const char *)_cdata->_buffer.get_read_pointer(true) + start, size);
+  const unsigned char *ptr = _cdata->_buffer.get_read_pointer(true) + start;
+  return vector_uchar(ptr, ptr + size);
 }
 }
 
 
 /**
 /**

+ 2 - 2
panda/src/gobj/geomVertexArrayData.cxx

@@ -842,7 +842,7 @@ copy_subdata_from(size_t to_start, size_t to_size,
  * Python.
  * Python.
  */
  */
 void GeomVertexArrayDataHandle::
 void GeomVertexArrayDataHandle::
-set_data(const string &data) {
+set_data(const vector_uchar &data) {
   nassertv(_writable);
   nassertv(_writable);
   mark_used();
   mark_used();
 
 
@@ -864,7 +864,7 @@ set_data(const string &data) {
  * This is primarily for the benefit of high-level languages like Python.
  * This is primarily for the benefit of high-level languages like Python.
  */
  */
 void GeomVertexArrayDataHandle::
 void GeomVertexArrayDataHandle::
-set_subdata(size_t start, size_t size, const string &data) {
+set_subdata(size_t start, size_t size, const vector_uchar &data) {
   nassertv(_writable);
   nassertv(_writable);
   mark_used();
   mark_used();
 
 

+ 4 - 4
panda/src/gobj/geomVertexArrayData.h

@@ -316,10 +316,10 @@ PUBLISHED:
                                    PyObject *buffer,
                                    PyObject *buffer,
                                    size_t from_start, size_t from_size));
                                    size_t from_start, size_t from_size));
 
 
-  INLINE std::string get_data() const;
-  void set_data(const std::string &data);
-  INLINE std::string get_subdata(size_t start, size_t size) const;
-  void set_subdata(size_t start, size_t size, const std::string &data);
+  INLINE vector_uchar get_data() const;
+  void set_data(const vector_uchar &data);
+  INLINE vector_uchar get_subdata(size_t start, size_t size) const;
+  void set_subdata(size_t start, size_t size, const vector_uchar &data);
 
 
   INLINE void mark_used() const;
   INLINE void mark_used() const;