X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fvideo-driver.cpp;h=61683f2436459c24734641160e9588b227ab27e1;hb=f842432ad7cfd7f530188e2a4848aea3da03719e;hp=c811c182a351ce3fd275c0092db3da71d185e37e;hpb=4590365d48d5af4b16f64279bcef89cfe340506f;p=guile-irrlicht.git diff --git a/src/video-driver.cpp b/src/video-driver.cpp index c811c18..61683f2 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -23,11 +23,15 @@ #include #include "color.h" -#include "device.h" +#include "gsubr.h" #include "gui-environment.h" +#include "material.h" +#include "matrix4.h" +#include "primitive-types.h" #include "rect.h" #include "scene-manager.h" #include "texture.h" +#include "vertex3d.h" #include "video-driver.h" #include "wrapped.h" @@ -37,13 +41,12 @@ extern "C" { init_video_driver (void) { init_video_driver_type (); - scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene); - scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_guiscene_drawAll); - scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene); - scm_c_define_gsubr ("get-texture", 2, 0, 0, (scm_t_subr)irr_video_getTexture); - scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); - scm_c_export ("begin-scene", "draw-all", "end-scene", "get-texture", - "get-video-driver", NULL); + DEFINE_GSUBR ("begin-scene", 1, 0, 1, irr_video_beginScene); + DEFINE_GSUBR ("draw-vertex-primitive-list", 3, 0, 1, irr_video_drawVertexPrimitiveList); + DEFINE_GSUBR ("end-scene", 1, 0, 0, irr_video_endScene); + DEFINE_GSUBR ("get-fps", 1, 0, 0, irr_video_getFPS); + DEFINE_GSUBR ("get-texture", 2, 0, 0, irr_video_getTexture); + DEFINE_GSUBR ("set-transform!", 3, 0, 0, irr_video_setTransform); } DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver", @@ -54,14 +57,14 @@ extern "C" { irr_video_beginScene (SCM wrapped_video_driver, SCM rest) { - SCM back_buffer = scm_from_bool(1); - SCM z_buffer = scm_from_bool(1); + SCM back_buffer = SCM_BOOL_T; + SCM z_buffer = SCM_BOOL_T; SCM color = scm_list_4 (scm_from_uint32 (255), scm_from_uint32 (0), scm_from_uint32 (0), scm_from_uint32 (0)); - SCM video_data = scm_from_bool(0); - SCM source_rect = scm_from_bool(0); + SCM video_data = SCM_BOOL_F; + SCM source_rect = SCM_UNDEFINED; scm_c_bind_keyword_arguments ("begin-scene", rest, (scm_t_keyword_arguments_flags)0, scm_from_utf8_keyword ("back-buffer"), &back_buffer, @@ -73,7 +76,7 @@ extern "C" { irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); irr::core::rect* sourceRectAddress = 0; - if (!scm_is_false (source_rect)) + if (source_rect != SCM_UNDEFINED) { irr::core::rect sourceRect = scm_to_rect_s32 (source_rect); sourceRectAddress = &sourceRect; @@ -86,21 +89,51 @@ extern "C" { } SCM - irr_guiscene_drawAll (SCM wrapped_obj) + irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver, + SCM vertices, + SCM indices, + SCM rest) { - if (gui_environment_p (wrapped_obj)) - { - unwrap_gui_environment (wrapped_obj)->drawAll (); - } - else if (scene_manager_p (wrapped_obj)) + SCM v_type = scm_from_utf8_symbol ("standard"); + SCM p_type = scm_from_utf8_symbol ("triangles"); + + scm_c_bind_keyword_arguments ("draw-vertex-primitive-list", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("vertex-type"), &v_type, + scm_from_utf8_keyword ("primitive-type"), &p_type, + SCM_UNDEFINED); + + // Build vertex array + irr::u32 vertex_count = scm_to_uint32 (scm_length (vertices)); + irr::video::S3DVertex s3d_vertices [vertex_count]; + for (int i = 0; i < vertex_count; i++) { - unwrap_scene_manager (wrapped_obj)->drawAll (); + irr::video::S3DVertex* vertex = unwrap_vertex3d (scm_list_ref (vertices, scm_from_int (i))); + s3d_vertices[i] = irr::video::S3DVertex (vertex->Pos, + vertex->Normal, + vertex->Color, + vertex->TCoords); } - else + + // Build index array + irr::u32 index_count = scm_to_uint32 (scm_length (indices)); + SCM flat_indices = scm_apply_0 (scm_eval_string (scm_from_utf8_string ("append")), + indices); + int flat_length = scm_to_int (scm_length (flat_indices)); + irr::u32 c_indices [flat_length]; + for (int i = 0; i < flat_length; i++) { - scm_error (scm_arg_type_key, NULL, "Cannot draw all elements from object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + c_indices[i] = scm_to_uint32 (scm_list_ref (flat_indices, scm_from_int (i))); } + + // Draw vertices + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->drawVertexPrimitiveList (&s3d_vertices[0], + vertex_count, + &c_indices[0], + index_count, + scm_to_vertex_type (v_type), + scm_to_primitive_type (p_type), + irr::video::EIT_32BIT); return SCM_UNSPECIFIED; } @@ -111,6 +144,13 @@ extern "C" { return scm_from_bool (driver->endScene ()); } + SCM + irr_video_getFPS (SCM wrapped_video_driver) + { + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + return scm_from_int32 (driver->getFPS ()); + } + SCM irr_video_getTexture (SCM wrapped_video_driver, SCM filename) @@ -121,19 +161,62 @@ extern "C" { } SCM - irr_getVideoDriver (SCM wrapped_obj) + irr_video_setMaterial (SCM wrapped_video_driver, + SCM material) { - irr::video::IVideoDriver* driver; - if (device_p (wrapped_obj)) + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->setMaterial (*(unwrap_material (material))); + return SCM_UNSPECIFIED; + } + + SCM + irr_video_setTransform (SCM wrapped_video_driver, + SCM state, + SCM mat) + { + irr::video::IVideoDriver* driver = unwrap_video_driver (wrapped_video_driver); + driver->setTransform (scm_to_transformation_state (state), + scm_to_matrix4 (mat)); + return SCM_UNSPECIFIED; + } + + irr::video::E_TRANSFORMATION_STATE + scm_to_transformation_state (SCM transformation_state) + { + char* state = scm_to_utf8_stringn (scm_symbol_to_string (transformation_state), NULL); + if (!strcmp (state, "view")) + { + return irr::video::ETS_VIEW; + } + else if (!strcmp (state, "world")) + { + return irr::video::ETS_WORLD; + } + else if (!strcmp (state, "projection")) + { + return irr::video::ETS_PROJECTION; + } + else if (!strcmp (state, "texture0")) + { + return irr::video::ETS_TEXTURE_0; + } + else if (!strcmp (state, "texture1")) + { + return irr::video::ETS_TEXTURE_1; + } + else if (!strcmp (state, "texture2")) + { + return irr::video::ETS_TEXTURE_2; + } + else if (!strcmp (state, "texture3")) { - driver = unwrap_device (wrapped_obj)->getVideoDriver (); + return irr::video::ETS_TEXTURE_3; } else { - scm_error (scm_arg_type_key, NULL, "Cannot get video driver from object: ~S", - scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + scm_error (scm_arg_type_key, NULL, "Wrong transformation state: ~S", + scm_list_1 (transformation_state), scm_list_1 (transformation_state)); } - return wrap_video_driver (driver); } }