diff --git a/__init__.py b/__init__.py index 0e2f8d0..f14bb8f 100644 --- a/__init__.py +++ b/__init__.py @@ -21,6 +21,12 @@ _engine = ctypes.cdll.LoadLibrary(Path(__file__).parent / "engine.so") # types.hpp +_handle = ctypes.c_void_p + +def _check_handle(result, func, arguments): + assert result + return result + def _flag(x): return 1 << x @@ -138,6 +144,7 @@ mat4_identity = mat4( vec4_origin) vec3_rotate = _engine.rk_vec3_rotate +vec3_rotate.restype = None vec3_rotate.argtypes = ( _vec3_p, # ret _vec3_p, # vec3 @@ -145,30 +152,35 @@ vec3_rotate.argtypes = ( ctypes.c_float) # angle vec3_mul_vec3 = _engine.rk_vec3_mul_vec3 +vec3_mul_vec3.restype = None vec3_mul_vec3.argtypes = ( _vec3_p, # ret _vec3_p, # a _vec3_p) # b mat3_rotation = _engine.rk_mat3_rotation +mat3_rotation.restype = None mat3_rotation.argtypes = ( _mat3_p, # ret _vec3_p, # axis ctypes.c_float) # angle mat3_mul_vec3 = _engine.rk_mat3_mul_vec3 +mat3_mul_vec3.restype = None mat3_mul_vec3.argtypes = ( _vec3_p, # ret _mat3_p, # a _vec3_p) # b mat3_mul_mat3 = _engine.rk_mat3_mul_mat3 +mat3_mul_mat3.restype = None mat3_mul_mat3.argtypes = ( _mat3_p, # ret _mat3_p, # a _mat3_p) # b mat4_projection = _engine.rk_mat4_projection +mat4_projection.restype = None mat4_projection.argtypes = ( _mat4_p, # ret ctypes.c_float, # hfov @@ -177,12 +189,14 @@ mat4_projection.argtypes = ( ctypes.c_float) # far mat4_lookat = _engine.rk_mat4_lookat +mat4_lookat.restype = None mat4_lookat.argtypes = ( _mat4_p, # ret _vec3_p, # position _vec3_p) # lookat mat4_orbit = _engine.rk_mat4_orbit +mat4_orbit.restype = None mat4_orbit.argtypes = ( _mat4_p, # ret _vec3_p, # origin @@ -191,6 +205,7 @@ mat4_orbit.argtypes = ( ctypes.c_float) # distance mat4_mul_vec3 = _engine.rk_mat4_mul_vec3 +mat4_mul_vec3.restype = None mat4_mul_vec3.argtypes = ( _vec3_p, # ret _mat4_p, # a @@ -198,12 +213,14 @@ mat4_mul_vec3.argtypes = ( ctypes.c_float) # w mat4_mul_vec4 = _engine.rk_mat4_mul_vec4 +mat4_mul_vec4.restype = None mat4_mul_vec4.argtypes = ( _vec4_p, # ret _mat4_p, # a _vec4_p) # b mat4_mul_mat4 = _engine.rk_mat4_mul_mat4 +mat4_mul_mat4.restype = None mat4_mul_mat4.argtypes = ( _mat4_p, # ret _mat4_p, # a @@ -212,17 +229,20 @@ mat4_mul_mat4.argtypes = ( # display.hpp create_display = _engine.rk_create_display -create_display.restype = ctypes.c_void_p +create_display.restype = _handle +create_display.errcheck = _check_handle create_display.argtypes = ( ctypes.c_char_p, # name ctypes.c_uint, # width ctypes.c_uint) # height destroy_display = _engine.rk_destroy_display +destroy_display.restype = None destroy_display.argtypes = ( ctypes.c_void_p,) # display swap_buffers = _engine.rk_swap_buffers +swap_buffers.restype = None swap_buffers.argtypes = ( ctypes.c_void_p,) # display @@ -279,13 +299,16 @@ INSTANCE_FLAG_VISIBLE = _flag(1) BATCH_MAX_SIZE = 65536 render_initialize = _engine.rk_render_initialize +render_initialize.restype = None render_initialize.argtypes = ( ctypes.c_bool,) # debug render_terminate = _engine.rk_render_terminate +render_terminate.restype = None _load_shader = _engine.rk_load_shader -_load_shader.restype = ctypes.c_void_p +_load_shader.restype = _handle +_load_shader.errcheck = _check_handle _load_shader.argtypes = ( ctypes.c_uint, # vert_nlines ctypes.POINTER(ctypes.c_char_p), # vert_lines @@ -302,19 +325,20 @@ def load_shader(vert_lines, 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 +resolve_input.restype = _handle resolve_input.argtypes = ( ctypes.c_void_p, # shader ctypes.c_char_p) # name resolve_param = _engine.rk_resolve_param -resolve_param.restype = ctypes.c_void_p +resolve_param.restype = _handle resolve_param.argtypes = ( ctypes.c_void_p, # shader ctypes.c_char_p) # name _create_texture = _engine.rk_create_texture -_create_texture.restype = ctypes.c_void_p +_create_texture.restype = _handle +_create_texture.errcheck = _check_handle _create_texture.argtypes = ( ctypes.c_uint, # format ctypes.c_uint, # width @@ -329,7 +353,8 @@ def create_texture(format, width, height, nlevels, flags, 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 +_create_triangles.restype = _handle +_create_triangles.errcheck = _check_handle _create_triangles.argtypes = ( ctypes.c_uint, # nvertices ctypes.c_void_p) # vertices @@ -339,7 +364,8 @@ def create_triangles(vertices): return _create_triangles(len(vertices) // 3, _float_addr(vertices)) _create_vertices = _engine.rk_create_vertices -_create_vertices.restype = ctypes.c_void_p +_create_vertices.restype = _handle +_create_vertices.errcheck = _check_handle _create_vertices.argtypes = ( ctypes.c_char_p, # format ctypes.c_uint, # nvertices @@ -351,7 +377,8 @@ def create_vertices(format, nvertices, vertices, 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 +create_batch.restype = _handle +create_batch.errcheck = _check_handle create_batch.argtypes = ( ctypes.c_void_p, # vertices ctypes.c_uint, # max_size @@ -359,52 +386,63 @@ create_batch.argtypes = ( ctypes.c_char_p) # params_format begin_frame = _engine.rk_begin_frame +begin_frame.restype = None select_shader = _engine.rk_select_shader +select_shader.restype = None select_shader.argtypes = ( ctypes.c_void_p,) # shader set_input_float = _engine.rk_set_input_float +set_input_float.restype = None set_input_float.argtypes = ( ctypes.c_void_p, # input ctypes.c_float) # value set_input_vec3 = _engine.rk_set_input_vec3 +set_input_vec3.restype = None set_input_vec3.argtypes = ( ctypes.c_void_p, # input _vec3_p) # value set_input_mat3 = _engine.rk_set_input_mat3 +set_input_mat3.restype = None set_input_mat3.argtypes = ( ctypes.c_void_p, # input _mat3_p) # value set_input_mat4 = _engine.rk_set_input_mat4 +set_input_mat4.restype = None set_input_mat4.argtypes = ( ctypes.c_void_p, # input _mat4_p) # value set_param_vec3 = _engine.rk_set_param_vec3 +set_param_vec3.restype = None set_param_vec3.argtypes = ( ctypes.c_uint, # layout _vec3_p) # value set_param_mat3 = _engine.rk_set_param_mat3 +set_param_mat3.restype = None set_param_mat3.argtypes = ( ctypes.c_uint, # layout _mat3_p) # value select_texture = _engine.rk_select_texture +select_texture.restype = None select_texture.argtypes = ( ctypes.c_uint, # slot ctypes.c_void_p, # texture ctypes.c_void_p) # sampler draw_triangles = _engine.rk_draw_triangles +draw_triangles.restype = None draw_triangles.argtypes = ( ctypes.c_void_p,) # triangles draw_batch = _engine.rk_draw_batch +draw_batch.restype = None draw_batch.argtypes = ( ctypes.c_void_p, # batch ctypes.c_uint, # count @@ -413,33 +451,41 @@ draw_batch.argtypes = ( ctypes.POINTER(ctypes.c_void_p)) # params unselect_texture = _engine.rk_unselect_texture +unselect_texture.restype = None unselect_texture.argtypes = ( ctypes.c_uint, # slot ctypes.c_void_p) # texture unselect_shader = _engine.rk_unselect_shader +unselect_shader.restype = None unselect_shader.argtypes = ( ctypes.c_void_p,) # shader end_frame = _engine.rk_end_frame +end_frame.restype = None destroy_batch = _engine.rk_destroy_batch +destroy_batch.restype = None destroy_batch.argtypes = ( ctypes.c_void_p,) # batch destroy_triangles = _engine.rk_destroy_triangles +destroy_triangles.restype = None destroy_triangles.argtypes = ( ctypes.c_void_p,) # triangles destroy_vertices = _engine.rk_destroy_vertices +destroy_vertices.restype = None destroy_vertices.argtypes = ( ctypes.c_void_p,) # vertices destroy_texture = _engine.rk_destroy_texture +destroy_texture.restype = None destroy_texture.argtypes = ( ctypes.c_void_p,) # texture destroy_shader = _engine.rk_destroy_shader +destroy_shader.restype = None destroy_shader.argtypes = ( ctypes.c_void_p,) # shader @@ -483,21 +529,25 @@ class Event(ctypes.Structure): _fields_ = ('type', ctypes.c_uint), ('data', _Events) create_events = _engine.rk_create_events -create_events.restype = ctypes.c_void_p +create_events.restype = _handle +create_events.errcheck = _check_handle create_events.argtypes = ( ctypes.c_void_p,) # display destroy_events = _engine.rk_destroy_events +destroy_events.restype = None destroy_events.argtypes = ( ctypes.c_void_p, # display ctypes.c_void_p) # events set_key_autorepeat = _engine.rk_set_key_autorepeat +set_key_autorepeat.restype = None set_key_autorepeat.argtypes = ( ctypes.c_void_p, # events ctypes.c_bool) # autorepeat set_motion_acceleration = _engine.rk_set_motion_acceleration +set_motion_acceleration.restype = None set_motion_acceleration.argtypes = ( ctypes.c_void_p, # events ctypes.c_uint, # numerator diff --git a/cpp/render/render_opengles.cpp b/cpp/render/render_opengles.cpp index ed03189..2163677 100644 --- a/cpp/render/render_opengles.cpp +++ b/cpp/render/render_opengles.cpp @@ -179,6 +179,9 @@ rk_input_t rk_resolve_input( return RK_INVALID_HANDLE; } GLint const uniform = glGetUniformLocation(shader->program, name); + if (uniform < 0) { + printf("[RK] rk_resolve_input(): uniform %s not found.\n", name); + } return reinterpret_cast(uniform + 1); } @@ -191,6 +194,9 @@ rk_param_t rk_resolve_param( return RK_INVALID_HANDLE; } GLint const location = glGetAttribLocation(shader->program, name); + if (location < 0) { + printf("[RK] rk_resolve_param(): attrib %s not found.\n", name); + } return reinterpret_cast(location + 1); }