编辑:一个最小的失败测试用例现在在 github 上: https ://github.com/shadowmint/Panda-setRamImage-problem
--
我有一个 C 库,它将 unsigned char * 指针传递回 python,其中包含 RGB 像素数据。
执行此操作的 python api 是:
# unsigned char *ar_get_rgb(void *handle);
libar.ar_get_rgb.argtypes = [ c_void_p ]
libar.ar_get_rgb.restype = POINTER(c_char)
在 panda3d 中,我试图将这些数据渲染为纹理。这里有一篇关于如何做到这一点的博客文章:http: //www.panda3d.org/blog/?p=96
但是,我发现这样做有一些非常严重的限制,我在这里讨论过:http: //www.panda3d.org/forums/viewtopic.php?t=13183,结果我现在正在尝试使用 setRamImage() api 设置纹理内存。
似乎必须有一种方法可以做到这一点,但我目前能够做到的唯一方法是在纹理上使用逐像素设置调用,如下所示:
def updateTextureTask(self, t):
expectedSize = self.getExpectedRamImageSize()
print("Expected length: " + str(expectedSize))
(rgb, depth) = self.__vision.next()
p = PTAUchar.emptyArray(expectedSize)
for i in range(0, self.__vision.width * self.__vision.height * 3):
p.setElement(i, ord(rgb[i]))
print("PTAU length: " + str(p.size()))
self.setRamImage(CPTAUchar(p))
return Task.cont
这行得通……但它每 2 秒以惊人的 1 帧运行。
如果我调用 p.setData(rgb) 来设置 PTAUchar 的数据(提示: http: //www.panda3d.org/dox/python/html/classpanda3d_1_1core_1_1PTAUchar.html)我得到:
Expected length: 921600
RGB buffer size: 921600 <-- C debugging data
PTAU length: 4
Assertion failed: compression != CM_off || image.size() == do_get_expected_ram_image_size() at line 833 of panda/src/gobj/texture.cxx
Traceback (most recent call last):
我对这个“4”长度的来源感到困惑,因为 RGB 数组中前 20 个奇数值的转储就像:
0: 163, 1: 151, 2: 162, 3: 85, 4: 83, 5: 190, 6: 241, 7: 252, 8: 249, 9: 121, 10: 107, 11: 82, 12: 20, 13: 19, 14: 233, 15: 226, 16: 45, 17: 81, 18: 142, 19: 31
PTAU length: 4
必须有一种方法可以将我的 unsigned char * 数组转换为可以输入 PTAUchar.setData 或 PTAUchar.setSubdata 的东西,但我想不通。
帮助!