diff --git a/__init__.py b/__init__.py index bf9bf10..c37b325 100644 --- a/__init__.py +++ b/__init__.py @@ -27,18 +27,18 @@ def _flag(x): def buffer(type, size): return (type * size)() -def _voidp(x): +def _void_addr(x): return x.buffer_info()[0] -def _ubytep(x): +def _ubyte_addr(x): assert x.typecode == 'B' return x.buffer_info()[0] -def _ushortp(x): +def _ushort_addr(x): assert x.typecode == 'H' return x.buffer_info()[0] -def _floatp(x): +def _float_addr(x): assert x.typecode == 'f' return x.buffer_info()[0] @@ -67,10 +67,10 @@ class mat3(ctypes.Structure): class mat4(ctypes.Structure): _fields_ = ('x', vec4), ('y', vec4), ('z', vec4), ('w', vec4) -_vec3p = ctypes.POINTER(vec3) -_vec4p = ctypes.POINTER(vec4) -_mat3p = ctypes.POINTER(mat3) -_mat4p = ctypes.POINTER(mat4) +_vec3_p = ctypes.POINTER(vec3) +_vec4_p = ctypes.POINTER(vec4) +_mat3_p = ctypes.POINTER(mat3) +_mat4_p = ctypes.POINTER(mat4) vec3_right = vec3(1.0, 0.0, 0.0) vec3_forward = vec3(0.0, 1.0, 0.0) @@ -78,39 +78,38 @@ vec3_up = vec3(0.0, 0.0, 1.0) vec3_rotate = _engine.rk_vec3_rotate vec3_rotate.argtypes = ( - _vec3p, # ret - _vec3p, # vec3 - _vec3p, # axis + _vec3_p, # ret + _vec3_p, # vec3 + _vec3_p, # axis ctypes.c_float) # angle - vec3_mul_vec3 = _engine.rk_vec3_mul_vec3 vec3_mul_vec3.argtypes = ( - _vec3p, # ret - _vec3p, # a - _vec3p) # b + _vec3_p, # ret + _vec3_p, # a + _vec3_p) # b mat3_rotation = _engine.rk_mat3_rotation mat3_rotation.argtypes = ( - _mat3p, # ret - _vec3p, # axis + _mat3_p, # ret + _vec3_p, # axis ctypes.c_float) # angle mat3_mul_vec3 = _engine.rk_mat3_mul_vec3 mat3_mul_vec3.argtypes = ( - _vec3p, # ret - _mat3p, # a - _vec3p) # b + _vec3_p, # ret + _mat3_p, # a + _vec3_p) # b mat3_mul_mat3 = _engine.rk_mat3_mul_mat3 mat3_mul_mat3.argtypes = ( - _mat3p, # ret - _mat3p, # a - _mat3p) # b + _mat3_p, # ret + _mat3_p, # a + _mat3_p) # b mat4_projection = _engine.rk_mat4_projection mat4_projection.argtypes = ( - _mat4p, # ret + _mat4_p, # ret ctypes.c_float, # hfov ctypes.c_float, # ratio ctypes.c_float, # near @@ -118,28 +117,28 @@ mat4_projection.argtypes = ( mat4_lookat = _engine.rk_mat4_lookat mat4_lookat.argtypes = ( - _mat4p, # ret - _vec3p, # position - _vec3p) # lookat + _mat4_p, # ret + _vec3_p, # position + _vec3_p) # lookat mat4_mul_vec3 = _engine.rk_mat4_mul_vec3 mat4_mul_vec3.argtypes = ( - _vec3p, # ret - _mat4p, # a - _vec3p, # b + _vec3_p, # ret + _mat4_p, # a + _vec3_p, # b ctypes.c_float) # w mat4_mul_vec4 = _engine.rk_mat4_mul_vec4 mat4_mul_vec4.argtypes = ( - _vec4p, # ret - _mat4p, # a - _vec4p) # b + _vec4_p, # ret + _mat4_p, # a + _vec4_p) # b mat4_mul_mat4 = _engine.rk_mat4_mul_mat4 mat4_mul_mat4.argtypes = ( - _mat4p, # ret - _mat4p, # a - _mat4p) # b + _mat4_p, # ret + _mat4_p, # a + _mat4_p) # b # display.hpp @@ -203,9 +202,9 @@ _load_shader = _engine.rk_load_shader _load_shader.restype = ctypes.c_void_p _load_shader.argtypes = ( ctypes.c_uint, # vert_nlines - ctypes.c_void_p, # vert_lines + ctypes.POINTER(ctypes.c_char_p), # vert_lines ctypes.c_uint, # frag_nlines - ctypes.c_void_p) # frag_lines + ctypes.POINTER(ctypes.c_char_p)) # frag_lines def load_shader(vert_lines, frag_lines): vert_nlines = len(vert_lines) @@ -214,9 +213,7 @@ def load_shader(vert_lines, frag_lines): frag_nlines = len(frag_lines) frag_type = ctypes.c_char_p * frag_nlines frag_lines = frag_type(*map(ctypes.c_char_p, frag_lines)) - return _load_shader( - vert_nlines, ctypes.addressof(vert_lines), - frag_nlines, ctypes.addressof(frag_lines)) + return _load_shader(vert_nlines, vert_lines, frag_nlines, frag_lines) resolve_input = _engine.rk_resolve_input resolve_input.restype = ctypes.c_void_p @@ -243,7 +240,7 @@ _create_texture.argtypes = ( def create_texture(format, width, height, nlevels, flags, pixels): assert pixels.typecode == TEXTURE_FORMAT_TYPECODE[format] assert len(pixels) == width * height * max(1, nlevels) * TEXTURE_FORMAT_NELEMS[format] - return _create_texture(format, width, height, nlevels, flags, _voidp(pixels)) + return _create_texture(format, width, height, nlevels, flags, _void_addr(pixels)) _create_triangles = _engine.rk_create_triangles _create_triangles.restype = ctypes.c_void_p @@ -253,7 +250,7 @@ _create_triangles.argtypes = ( def create_triangles(vertices): assert len(vertices) % 9 == 0 - return _create_triangles(len(vertices) // 3, _floatp(vertices)) + return _create_triangles(len(vertices) // 3, _float_addr(vertices)) _create_vertices = _engine.rk_create_vertices _create_vertices.restype = ctypes.c_void_p @@ -265,7 +262,7 @@ _create_vertices.argtypes = ( ctypes.c_void_p) # indices def create_vertices(format, nvertices, vertices, indices): - return _create_vertices(format, nvertices, _ubytep(vertices), len(indices), _ushortp(indices)) + return _create_vertices(format, nvertices, _ubyte_addr(vertices), len(indices), _ushort_addr(indices)) create_batch = _engine.rk_create_batch create_batch.restype = ctypes.c_void_p @@ -288,22 +285,22 @@ set_input_float.argtypes = ( set_input_vec3 = _engine.rk_set_input_vec3 set_input_vec3.argtypes = ( ctypes.c_void_p, # input - _vec3p) # value + _vec3_p) # value set_input_mat3 = _engine.rk_set_input_mat3 set_input_mat3.argtypes = ( ctypes.c_void_p, # input - _mat3p) # value + _mat3_p) # value set_input_mat4 = _engine.rk_set_input_mat4 set_input_mat4.argtypes = ( ctypes.c_void_p, # input - _mat4p) # value + _mat4_p) # value set_param_vec3 = _engine.rk_set_param_vec3 set_param_vec3.argtypes = ( ctypes.c_uint, # layout - _vec3p) # value + _vec3_p) # value select_texture = _engine.rk_select_texture select_texture.argtypes = (