From: Javier Sancho Date: Wed, 4 Dec 2019 18:23:00 +0000 (+0100) Subject: Draw vertex primitive list X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=7e46627fbadd2bcf8169ae429e6fe0a546d2797a;hp=482d9e598cce378cdb7f5568c9efe5befe579494;p=c-irrlicht.git Draw vertex primitive list --- diff --git a/Makefile.am b/Makefile.am index 9af851c..f136bcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..2726918 --- /dev/null +++ b/include/EPrimitiveTypes.h @@ -0,0 +1,64 @@ +/* c-irrlicht --- C bindings for Irrlicht Engine + + Copyright (C) 2019 Javier Sancho + + 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 + . +*/ + +#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 diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index 5c89181..d9c3e6b 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -22,12 +22,15 @@ #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); diff --git a/include/S3DVertex.h b/include/S3DVertex.h index 7d28d83..ca03a08 100644 --- a/include/S3DVertex.h +++ b/include/S3DVertex.h @@ -26,6 +26,21 @@ #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 index 0000000..e6c6b86 --- /dev/null +++ b/include/SVertexIndex.h @@ -0,0 +1,31 @@ +/* c-irrlicht --- C bindings for Irrlicht Engine + + Copyright (C) 2019 Javier Sancho + + 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 + . +*/ + +#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 diff --git a/include/cirrlicht.h b/include/cirrlicht.h index 2c30a04..fc08e12 100644 --- a/include/cirrlicht.h +++ b/include/cirrlicht.h @@ -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" diff --git a/src/IVideoDriver.cpp b/src/IVideoDriver.cpp index 50ee345..14d8fa9 100644 --- a/src/IVideoDriver.cpp +++ b/src/IVideoDriver.cpp @@ -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; ipos.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; idrawVertexPrimitiveList(&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) {