]> git.jsancho.org Git - c-irrlicht.git/commitdiff
Draw vertex primitive list
authorJavier Sancho <jsf@jsancho.org>
Wed, 4 Dec 2019 18:23:00 +0000 (19:23 +0100)
committerJavier Sancho <jsf@jsancho.org>
Wed, 4 Dec 2019 18:23:00 +0000 (19:23 +0100)
Makefile.am
include/EPrimitiveTypes.h [new file with mode: 0644]
include/IVideoDriver.h
include/S3DVertex.h
include/SVertexIndex.h [new file with mode: 0644]
include/cirrlicht.h
src/IVideoDriver.cpp

index 9af851c5b42e625e50a8aef2194a414888e78f3b..f136bcb65d100082c49b2b2edbaf9368b7c8f24c 100644 (file)
@@ -19,6 +19,7 @@ pkginclude_HEADERS = \
   include/dimension2d.h \
   include/EDriverTypes.h \
   include/EMaterialFlags.h \
+  include/EPrimitiveTypes.h \
   include/IAnimatedMesh.h \
   include/IAnimatedMeshMD2.h \
   include/IAnimatedMeshSceneNode.h \
@@ -43,5 +44,6 @@ pkginclude_HEADERS = \
   include/SExposedVideoData.h \
   include/SKeyMap.h \
   include/SMaterial.h \
+  include/SVertexIndex.h \
   include/vector2d.h \
   include/vector3d.h
diff --git a/include/EPrimitiveTypes.h b/include/EPrimitiveTypes.h
new file mode 100644 (file)
index 0000000..2726918
--- /dev/null
@@ -0,0 +1,64 @@
+/* c-irrlicht --- C bindings for Irrlicht Engine
+
+   Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of c-irrlicht.
+
+   c-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.
+
+   c-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 __C_IRR_E_PRIMITIVE_TYPES_H_INCLUDED__
+#define __C_IRR_E_PRIMITIVE_TYPES_H_INCLUDED__
+
+//! Enumeration for all primitive types there are.
+typedef enum
+  {
+   //! All vertices are non-connected points.
+   irr_scene_EPT_POINTS=0,
+
+   //! All vertices form a single connected line.
+   irr_scene_EPT_LINE_STRIP,
+
+   //! Just as LINE_STRIP, but the last and the first vertex is also connected.
+   irr_scene_EPT_LINE_LOOP,
+
+   //! Every two vertices are connected creating n/2 lines.
+   irr_scene_EPT_LINES,
+
+   //! After the first two vertices each vertex defines a new triangle.
+   //! Always the two last and the new one form a new triangle.
+   irr_scene_EPT_TRIANGLE_STRIP,
+
+   //! After the first two vertices each vertex defines a new triangle.
+   //! All around the common first vertex.
+   irr_scene_EPT_TRIANGLE_FAN,
+
+   //! Explicitly set all vertices for each triangle.
+   irr_scene_EPT_TRIANGLES,
+
+   //! After the first two vertices each further tw vetices create a quad with the preceding two.
+   irr_scene_EPT_QUAD_STRIP,
+
+   //! Every four vertices create a quad.
+   irr_scene_EPT_QUADS,
+
+   //! Just as LINE_LOOP, but filled.
+   irr_scene_EPT_POLYGON,
+
+   //! The single vertices are expanded to quad billboards on the GPU.
+   irr_scene_EPT_POINT_SPRITES
+  } irr_scene_E_PRIMITIVE_TYPE;
+
+#endif
index 5c89181d13b89390dc957e8f00cb83e7f075360f..d9c3e6b2eb2f5e6b72219df90682c882fb402ddf 100644 (file)
 #ifndef __C_I_VIDEO_DRIVER_H_INCLUDED__
 #define __C_I_VIDEO_DRIVER_H_INCLUDED__
 
+#include "EPrimitiveTypes.h"
 #include "ITexture.h"
 #include "matrix4.h"
+#include "rect.h"
+#include "S3DVertex.h"
 #include "SColor.h"
 #include "SExposedVideoData.h"
 #include "SMaterial.h"
-#include "rect.h"
+#include "SVertexIndex.h"
 
 //! enumeration for geometry transformation states
 typedef enum
@@ -81,6 +84,16 @@ extern "C" {
                        irr_video_SExposedVideoData* videoData,
                        const irr_core_rect_s32* sourceRect);
 
+  void
+  irr_video_drawVertexPrimitiveList(irr_video_IVideoDriver* driver,
+                                    const void* vertices,
+                                    unsigned int vertexCount,
+                                    const void* indexList,
+                                    unsigned int primCount,
+                                    irr_video_E_VERTEX_TYPE vType,
+                                    irr_scene_E_PRIMITIVE_TYPE pType,
+                                    irr_video_E_INDEX_TYPE iType);
+
   int
   irr_video_endScene(irr_video_IVideoDriver* driver);
 
index 7d28d833940a0a4d271e26d60a91000b71345b63..ca03a084f586720b70a038fae61195a9fffca304 100644 (file)
 #include "vector2d.h"
 #include "vector3d.h"
 
+//! Enumeration for all vertex types there are.
+typedef enum
+  {
+   //! Standard vertex type used by the Irrlicht engine, video::S3DVertex.
+   irr_video_EVT_STANDARD = 0,
+
+   //! Vertex with two texture coordinates, video::S3DVertex2TCoords.
+   /** Usually used for geometry with lightmaps or other special materials. */
+   irr_video_EVT_2TCOORDS,
+
+   //! Vertex with a tangent and binormal vector, video::S3DVertexTangents.
+   /** Usually used for tangent space normal mapping. */
+   irr_video_EVT_TANGENTS
+  } irr_video_E_VERTEX_TYPE;
+
 typedef struct
 {
   irr_core_vector3df pos;
diff --git a/include/SVertexIndex.h b/include/SVertexIndex.h
new file mode 100644 (file)
index 0000000..e6c6b86
--- /dev/null
@@ -0,0 +1,31 @@
+/* c-irrlicht --- C bindings for Irrlicht Engine
+
+   Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
+
+   This file is part of c-irrlicht.
+
+   c-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.
+
+   c-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 __C_IRR_S_VERTEX_INDEX_H_INCLUDED__
+#define __C_IRR_S_VERTEX_INDEX_H_INCLUDED__
+
+typedef enum
+  {
+   irr_video_EIT_16BIT = 0,
+   irr_video_EIT_32BIT
+  } irr_video_E_INDEX_TYPE;
+
+#endif
index 2c30a04e60ff34c61427cddd1a152eb14228bfd6..fc08e12229b6ba868a8c1d0e265b452436277467 100644 (file)
@@ -26,6 +26,7 @@
 #include "dimension2d.h"
 #include "EDriverTypes.h"
 #include "EMaterialFlags.h"
+#include "EPrimitiveTypes.h"
 #include "IAnimatedMeshMD2.h"
 #include "IAnimatedMeshSceneNode.h"
 #include "ICameraSceneNode.h"
@@ -49,6 +50,7 @@
 #include "SExposedVideoData.h"
 #include "SKeyMap.h"
 #include "SMaterial.h"
+#include "SVertexIndex.h"
 #include "vector2d.h"
 #include "vector3d.h"
 
index 50ee3454283db4ec73ea0d2d7c634c489f0ae4ab..14d8fa91c4f27631d8d8487f72046a820910c6b0 100644 (file)
@@ -59,6 +59,60 @@ extern "C" {
                    sourceRect != NULL ? &rect : 0);
   }
 
+  void
+  irr_video_drawVertexPrimitiveList(irr_video_IVideoDriver* driver,
+                                    const void* vertices,
+                                    unsigned int vertexCount,
+                                    const void* indexList,
+                                    unsigned int primCount,
+                                    irr_video_E_VERTEX_TYPE vType,
+                                    irr_scene_E_PRIMITIVE_TYPE pType,
+                                    irr_video_E_INDEX_TYPE iType)
+  {
+    // Convert vertices
+    irr::video::S3DVertex irrVertices[vertexCount];
+    for (int i=0; i<vertexCount; i++)
+      {
+        irr_video_S3DVertex *vertex = (irr_video_S3DVertex*)vertices + i;
+        irrVertices[i] =
+          irr::video::S3DVertex(vertex->pos.x, vertex->pos.y, vertex->pos.z,
+                                vertex->normal.x, vertex->normal.y, vertex->normal.z,
+                                irr::video::SColor(vertex->color.a,
+                                                   vertex->color.r,
+                                                   vertex->color.g,
+                                                   vertex->color.b),
+                                vertex->tCoords.x, vertex->tCoords.y);
+      }
+
+    // Convert indices
+    size_t indexListSize =
+      ((iType == irr_video_EIT_16BIT) ? sizeof(irr::u16) : sizeof(irr::u32)) *
+      primCount * 3;
+    void* irrIndexList = malloc(indexListSize);
+
+    for (int i=0; i<primCount*3; i++)
+      {
+        unsigned int *index = (unsigned int*)indexList + i;
+        if (iType == irr_video_EIT_16BIT)
+          {
+            ((irr::u16*)irrIndexList)[i] = *index;
+          }
+        else
+          {
+            ((irr::u32*)irrIndexList)[i] = *index;
+          }
+      }
+
+    ((irr::video::IVideoDriver*)driver)
+      ->drawVertexPrimitiveList(&irrVertices[0], vertexCount,
+                                irrIndexList, primCount,
+                                (irr::video::E_VERTEX_TYPE)vType,
+                                (irr::scene::E_PRIMITIVE_TYPE)pType,
+                                (irr::video::E_INDEX_TYPE)iType);
+
+    free(irrIndexList);
+  }
+
   int
   irr_video_endScene(irr_video_IVideoDriver* driver)
   {