]> git.jsancho.org Git - guile-irrlicht.git/blobdiff - src/video-driver.cpp
Use SWIG for wrapping C++
[guile-irrlicht.git] / src / video-driver.cpp
diff --git a/src/video-driver.cpp b/src/video-driver.cpp
deleted file mode 100644 (file)
index 60fc867..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
-
-   Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
-
-   This file is part of guile-irrlicht.
-
-   guile-irrlicht is free software; you can redistribute it and/or modify
-   it under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 3 of the
-   License, or (at your option) any later version.
-
-   guile-irrlicht is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with guile-irrlicht. If not, see
-   <http://www.gnu.org/licenses/>.
-*/
-
-#include <irrlicht/irrlicht.h>
-#include <libguile.h>
-#include "color.h"
-#include "gsubr.h"
-#include "matrix4.h"
-#include "primitive-types.h"
-#include "rect.h"
-#include "vertex3d.h"
-#include "video-driver.h"
-#include "wrapped.h"
-
-using namespace irr;
-
-SCM
-IVideoDriver_beginScene (SCM video_driver,
-                         SCM back_buffer,
-                         SCM z_buffer,
-                         SCM color,
-                         SCM video_data,
-                         SCM source_rect)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-
-  // Source rect
-  core::rect<s32>* sourceRectAddress = 0;
-  if (!scm_is_false (source_rect))
-    {
-      core::rect<s32> sourceRect = scm_to_rect_s32 (source_rect);
-      sourceRectAddress = &sourceRect;
-    }
-
-  return scm_from_bool (driver->beginScene (scm_to_bool (back_buffer),
-                                            scm_to_bool (z_buffer),
-                                            scm_to_color (color),
-                                            video::SExposedVideoData (),
-                                            sourceRectAddress));
-}
-
-SCM
-IVideoDriver_drawVertexPrimitiveList (SCM video_driver,
-                                      SCM vertices,
-                                      SCM indices,
-                                      SCM v_type,
-                                      SCM p_type)
-{
-  // Build vertex array
-  u32 vertex_count = scm_to_uint32 (scm_length (vertices));
-  video::S3DVertex s3d_vertices [vertex_count];
-  for (int i = 0; i < vertex_count; i++)
-    {
-      video::S3DVertex* vertex =
-        (video::S3DVertex*) scm_to_irr_pointer (scm_list_ref (vertices, scm_from_int (i)));
-      s3d_vertices[i] = video::S3DVertex (vertex->Pos,
-                                          vertex->Normal,
-                                          vertex->Color,
-                                          vertex->TCoords);
-    }
-
-  // Build index array
-  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));
-  u32 c_indices [flat_length];
-  for (int i = 0; i < flat_length; i++)
-    {
-      c_indices[i] = scm_to_uint32 (scm_list_ref (flat_indices, scm_from_int (i)));
-    }
-
-  // Draw vertices
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (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),
-                                   video::EIT_32BIT);
-  return SCM_UNSPECIFIED;
-}
-
-SCM
-IVideoDriver_endScene (SCM video_driver)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  return scm_from_bool (driver->endScene ());
-}
-
-SCM
-IVideoDriver_getFPS (SCM video_driver)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  return scm_from_int32 (driver->getFPS ());
-}
-
-SCM
-IVideoDriver_getName (SCM video_driver)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  return scm_from_utf32_string ((scm_t_wchar*) driver->getName ());
-}
-
-SCM
-IVideoDriver_getTexture (SCM video_driver,
-                         SCM filename)
-{
-  char* cfilename = scm_to_utf8_string (filename);
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  video::ITexture* texture = driver->getTexture (cfilename);
-  free (cfilename);
-  return scm_from_irr_pointer ("<texture>", (void*) texture);
-}
-
-SCM
-IVideoDriver_setMaterial (SCM video_driver,
-                          SCM material)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  driver->setMaterial (*((video::SMaterial*) scm_to_irr_pointer (material)));
-  return SCM_UNSPECIFIED;
-}
-
-SCM
-IVideoDriver_setTransform (SCM video_driver,
-                           SCM state,
-                           SCM mat)
-{
-  video::IVideoDriver* driver = (video::IVideoDriver*) scm_to_irr_pointer (video_driver);
-  driver->setTransform (scm_to_transformation_state (state),
-                        scm_to_matrix4 (mat));
-  return SCM_UNSPECIFIED;
-}
-
-
-void
-init_video_driver (void)
-{
-  DEFINE_GSUBR ("IVideoDriver_beginScene", 6, 0, 0, IVideoDriver_beginScene);
-  DEFINE_GSUBR ("IVideoDriver_drawVertexPrimitiveList", 5, 0, 1,
-                IVideoDriver_drawVertexPrimitiveList);
-  DEFINE_GSUBR ("IVideoDriver_endScene", 1, 0, 0, IVideoDriver_endScene);
-  DEFINE_GSUBR ("IVideoDriver_getFPS", 1, 0, 0, IVideoDriver_getFPS);
-  DEFINE_GSUBR ("IVideoDriver_getName", 1, 0, 0, IVideoDriver_getName);
-  DEFINE_GSUBR ("IVideoDriver_getTexture", 2, 0, 0, IVideoDriver_getTexture);
-  DEFINE_GSUBR ("IVideoDriver_setMaterial", 2, 0, 0, IVideoDriver_setMaterial);
-  DEFINE_GSUBR ("IVideoDriver_setTransform", 3, 0, 0, IVideoDriver_setTransform);
-}
-
-video::E_TRANSFORMATION_STATE
-scm_to_transformation_state (SCM transformation_state)
-{
-  char* state_name = scm_to_utf8_string (scm_symbol_to_string (transformation_state));
-  video::E_TRANSFORMATION_STATE state;
-
-  if (!strcmp (state_name, "view"))
-    {
-      state = video::ETS_VIEW;
-    }
-  else if (!strcmp (state_name, "world"))
-    {
-      state = video::ETS_WORLD;
-    }
-  else if (!strcmp (state_name, "projection"))
-    {
-      state = video::ETS_PROJECTION;
-    }
-  else if (!strcmp (state_name, "texture0"))
-    {
-      state = video::ETS_TEXTURE_0;
-    }
-  else if (!strcmp (state_name, "texture1"))
-    {
-      state = video::ETS_TEXTURE_1;
-    }
-  else if (!strcmp (state_name, "texture2"))
-    {
-      state = video::ETS_TEXTURE_2;
-    }
-  else if (!strcmp (state_name, "texture3"))
-    {
-      state = video::ETS_TEXTURE_3;
-    }
-  else
-    {
-      scm_error (scm_arg_type_key, NULL, "Wrong transformation state: ~S",
-                 scm_list_1 (transformation_state), scm_list_1 (transformation_state));
-    }
-
-  free (state_name);
-  return state;
-}