]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
draw-vertex-primitive-list
authorJavier Sancho <jsf@jsancho.org>
Wed, 1 Apr 2020 09:00:11 +0000 (11:00 +0200)
committerJavier Sancho <jsf@jsancho.org>
Wed, 1 Apr 2020 09:00:11 +0000 (11:00 +0200)
Makefile.am
examples/03.CustomSceneNode.scm
src/primitive-types.cpp [new file with mode: 0644]
src/primitive-types.h [new file with mode: 0644]
src/vertex3d.cpp
src/vertex3d.h
src/video-driver.cpp
src/video-driver.h

index 0eb36724f6aaee90d0a14599d09745aac2187c05..f94c285cbe7ed3636700fa6b7c5db897e9e456d4 100644 (file)
@@ -46,6 +46,7 @@ libguile_irrlicht_la_SOURCES = \
   src/mesh.cpp \
   src/mesh-scene-node.cpp \
   src/position2d.cpp \
+  src/primitive-types.cpp \
   src/rect.cpp \
   src/reference-counted.cpp \
   src/scene-manager.cpp \
index ee1c67e05791d87bba1ae33bc0a2c60f62e0f0a6..21e5be80edf07a0f66c55774e57c151de2d2b482 100644 (file)
   (set! frames (+ frames 1))
   (when (= frames 100)
     (let ((fps (get-fps driver))
-          (driver-name (get-video-driver-name driver)))
+          (driver-name (get-name driver)))
       (let ((caption
              (format #f "Irrlicht Engine [~a] FPS:~a" driver-name fps)))
         (set-window-caption! device caption)))
diff --git a/src/primitive-types.cpp b/src/primitive-types.cpp
new file mode 100644 (file)
index 0000000..2593c75
--- /dev/null
@@ -0,0 +1,83 @@
+/* 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 "primitive-types.h"
+
+extern "C" {
+
+  irr::scene::E_PRIMITIVE_TYPE
+  scm_to_primitive_type (SCM primitive_type)
+  {
+    char* type = scm_to_utf8_stringn (scm_symbol_to_string (primitive_type), NULL);
+    if (!strcmp (type, "points"))
+      {
+        return irr::scene::EPT_POINTS;
+      }
+    else if (!strcmp (type, "line-strip"))
+      {
+        return irr::scene::EPT_LINE_STRIP;
+      }
+    else if (!strcmp (type, "line-loop"))
+      {
+        return irr::scene::EPT_LINE_LOOP;
+      }
+    else if (!strcmp (type, "lines"))
+      {
+        return irr::scene::EPT_LINES;
+      }
+    else if (!strcmp (type, "triangle-strip"))
+      {
+        return irr::scene::EPT_TRIANGLE_STRIP;
+      }
+    else if (!strcmp (type, "triangle-fan"))
+      {
+        return irr::scene::EPT_TRIANGLE_FAN;
+      }
+    else if (!strcmp (type, "triangles"))
+      {
+        return irr::scene::EPT_TRIANGLES;
+      }
+    else if (!strcmp (type, "quad-strip"))
+      {
+        return irr::scene::EPT_QUAD_STRIP;
+      }
+    else if (!strcmp (type, "quads"))
+      {
+        return irr::scene::EPT_QUADS;
+      }
+    else if (!strcmp (type, "polygon"))
+      {
+        return irr::scene::EPT_POLYGON;
+      }
+    else if (!strcmp (type, "point-sprites"))
+      {
+        return irr::scene::EPT_POINT_SPRITES;
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Wrong primitive type: ~S",
+                   scm_list_1 (primitive_type), scm_list_1 (primitive_type));
+      }
+  }
+
+}
diff --git a/src/primitive-types.h b/src/primitive-types.h
new file mode 100644 (file)
index 0000000..a3c8bb6
--- /dev/null
@@ -0,0 +1,35 @@
+/* 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/>.
+*/
+
+#ifndef __GUILE_IRRLICHT_PRIMITIVE_TYPES_H_INCLUDED__
+#define __GUILE_IRRLICHT_PRIMITIVE_TYPES_H_INCLUDED__
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+
+extern "C" {
+
+  irr::scene::E_PRIMITIVE_TYPE
+  scm_to_primitive_type (SCM primitive_type);
+
+}
+
+#endif
index 27bf94137077833fa97a6351df6fe9bc17401f81..f6adab086d5371d8352dee98cfb0814c55a64c4a 100644 (file)
@@ -62,4 +62,27 @@ extern "C" {
     return scm_from_vector3df (s3dvertex->Pos);
   }
 
+  irr::video::E_VERTEX_TYPE
+  scm_to_vertex_type (SCM vertex_type)
+  {
+    char* type = scm_to_utf8_stringn (scm_symbol_to_string (vertex_type), NULL);
+    if (!strcmp (type, "standard"))
+      {
+        return irr::video::EVT_STANDARD;
+      }
+    else if (!strcmp (type, "2tcoords"))
+      {
+        return irr::video::EVT_2TCOORDS;
+      }
+    else if (!strcmp (type, "tangents"))
+      {
+        return irr::video::EVT_TANGENTS;
+      }
+    else
+      {
+        scm_error (scm_arg_type_key, NULL, "Wrong vertex_type: ~S",
+                   scm_list_1 (vertex_type), scm_list_1 (vertex_type));
+      }
+  }
+
 }
index 4c033d3e6414e079287c934c5371524ed61c5c14..2fcf4f52431afa1b94ae011d419134597dde8f05 100644 (file)
@@ -43,6 +43,9 @@ extern "C" {
   SCM
   vertex3d_position (SCM vertex);
 
+  irr::video::E_VERTEX_TYPE
+  scm_to_vertex_type (SCM vertex_type);
+
 }
 
 #endif
index aa63e5289e45d298007d83ad5337d09e1bb5d543..9c81120fb97825ad23f422146a0795569705a9bf 100644 (file)
 #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"
 
@@ -40,13 +42,15 @@ extern "C" {
   {
     init_video_driver_type ();
     scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene);
+    scm_c_define_gsubr ("draw-vertex-primitive-list", 3, 0, 1,
+                        (scm_t_subr)irr_video_drawVertexPrimitiveList);
     scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene);
     scm_c_define_gsubr ("get-fps", 1, 0, 0, (scm_t_subr)irr_video_getFPS);
     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_define_gsubr ("set-transform!", 3, 0, 0, (scm_t_subr)irr_video_setTransform);
-    scm_c_export ("begin-scene", "end-scene", "get-fps", "get-texture",
-                  "get-video-driver", "set-transform!", NULL);
+    scm_c_export ("begin-scene", "draw-vertex-primitive-list", "end-scene", "get-fps",
+                  "get-texture", "get-video-driver", "set-transform!", NULL);
   }
 
   DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver",
@@ -88,6 +92,55 @@ extern "C" {
                                               sourceRectAddress));
   }
 
+  SCM
+  irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver,
+                                     SCM vertices,
+                                     SCM indices,
+                                     SCM rest)
+  {
+    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++)
+      {
+        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);
+      }
+
+    // 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++)
+      {
+        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;
+  }
+
   SCM
   irr_video_endScene (SCM wrapped_video_driver)
   {
index d697e5b5febad6a9412e0af53ee2854f3b9c52eb..4512b9689d46182bcff08272258349f6fb40c437 100644 (file)
@@ -38,6 +38,12 @@ extern "C" {
   irr_video_beginScene (SCM wrapped_video_driver,
                         SCM rest);
 
+  SCM
+  irr_video_drawVertexPrimitiveList (SCM wrapped_video_driver,
+                                     SCM vertices,
+                                     SCM indices,
+                                     SCM rest);
+
   SCM
   irr_video_endScene (SCM wrapped_video_driver);