|
36 | 36 |
|
37 | 37 | # numpy dtype mapping |
38 | 38 | NP_COMPONENT_DTYPE = { |
39 | | - 5121: numpy.dtype(numpy.uint8), # GL_UNSIGNED_BYTE |
40 | | - 5123: numpy.dtype(numpy.uint16), # GL_UNSIGNED_SHORT |
41 | | - 5125: numpy.dtype(numpy.uint32), # GL_UNSIGNED_INT |
42 | | - 5126: numpy.dtype(numpy.float32), # GL_FLOAT |
| 39 | + 5121: numpy.uint8, # GL_UNSIGNED_BYTE |
| 40 | + 5123: numpy.uint16, # GL_UNSIGNED_SHORT |
| 41 | + 5125: numpy.uint32, # GL_UNSIGNED_INT |
| 42 | + 5126: numpy.float32, # GL_FLOAT |
| 43 | +} |
| 44 | + |
| 45 | +# dtype to moderngl buffer format |
| 46 | +DTYPE_BUFFER_TYPE = { |
| 47 | + numpy.uint8: 'u1', # GL_UNSIGNED_BYTE |
| 48 | + numpy.uint16: 'u2', # GL_UNSIGNED_SHORT |
| 49 | + numpy.uint32: 'u4', # GL_UNSIGNED_INT |
| 50 | + numpy.float32: 'f4', # GL_FLOAT |
43 | 51 | } |
44 | 52 |
|
45 | 53 | ACCESSOR_TYPE = { |
@@ -381,7 +389,7 @@ def load(self, materials): |
381 | 389 | dtype, buffer = vbo_info.create() |
382 | 390 | vao.buffer( |
383 | 391 | buffer, |
384 | | - " ".join(["{}f".format(attr[1]) for attr in vbo_info.attributes]), |
| 392 | + " ".join(["{}{}".format(attr[1], DTYPE_BUFFER_TYPE[dtype]) for attr in vbo_info.attributes]), |
385 | 393 | [name_map[attr[0]] for attr in vbo_info.attributes], |
386 | 394 | ) |
387 | 395 |
|
@@ -444,6 +452,7 @@ def __init__(self, buffer=None, buffer_view=None, target=None, |
444 | 452 | self.component_type = component_type # Datatype of each component |
445 | 453 | self.components = components |
446 | 454 | self.count = count # number of elements of the component type size |
| 455 | + |
447 | 456 | # list of (name, components) tuples |
448 | 457 | self.attributes = [] |
449 | 458 |
|
|
0 commit comments