]> git.jsancho.org Git - c-irrlicht.git/blob - src/IVideoDriver.cpp
Use structs with casting, without classes replication
[c-irrlicht.git] / src / IVideoDriver.cpp
1 /* c-irrlicht --- C bindings for Irrlicht Engine
2
3    Copyright (C) 2019 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of c-irrlicht.
6
7    c-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    c-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht.  If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <wchar.h>
24 #include "IVideoDriver.h"
25
26 extern "C" {
27   int
28   irr_video_beginScene(irr_video_IVideoDriver* driver,
29                        bool backBuffer,
30                        bool zBuffer,
31                        const irr_video_SColor* color,
32                        irr_video_SExposedVideoData* videoData,
33                        const irr_core_rect_s32* sourceRect)
34   {
35     // Video data
36     // TODO
37     irr::video::SExposedVideoData vdata = irr::video::SExposedVideoData();
38
39     // Begin scene
40     return ((irr::video::IVideoDriver*)driver)
41       ->beginScene(backBuffer,
42                    zBuffer,
43                    *(irr::video::SColor*)color,
44                    vdata,
45                    (irr::core::rect<irr::s32>*)sourceRect);
46   }
47
48   void
49   irr_video_drawVertexPrimitiveList(irr_video_IVideoDriver* driver,
50                                     const void* vertices,
51                                     uint32_t vertexCount,
52                                     const void* indexList,
53                                     uint32_t primCount,
54                                     irr_video_E_VERTEX_TYPE vType,
55                                     irr_scene_E_PRIMITIVE_TYPE pType,
56                                     irr_video_E_INDEX_TYPE iType)
57   {
58     ((irr::video::IVideoDriver*)driver)
59       ->drawVertexPrimitiveList(vertices, vertexCount,
60                                 indexList, primCount,
61                                 (irr::video::E_VERTEX_TYPE)vType,
62                                 (irr::scene::E_PRIMITIVE_TYPE)pType,
63                                 (irr::video::E_INDEX_TYPE)iType);
64   }
65
66   int
67   irr_video_endScene(irr_video_IVideoDriver* driver)
68   {
69     return ((irr::video::IVideoDriver*)driver)->endScene();
70   }
71
72   int
73   irr_video_getFPS(irr_video_IVideoDriver* driver)
74   {
75     return ((irr::video::IVideoDriver*)driver)->getFPS();
76   }
77
78   const char*
79   irr_video_getName(irr_video_IVideoDriver* driver)
80   {
81     const wchar_t *wname = ((irr::video::IVideoDriver*)driver)->getName();
82     size_t nbytes = wcslen(wname) + 1;
83     char *name = (char*)malloc(nbytes);
84     wcstombs(name, wname, nbytes);
85     return name;
86   }
87
88   irr_video_ITexture*
89   irr_video_getTexture(irr_video_IVideoDriver* driver,
90                        const char* filename)
91   {
92     return (irr_video_ITexture*)
93       ((irr::video::IVideoDriver*)driver)->getTexture(filename);
94   }
95
96   void
97   irr_video_setMaterial(irr_video_IVideoDriver* driver,
98                         irr_video_SMaterial* material)
99   {
100     ((irr::video::IVideoDriver*)driver)->setMaterial(*(irr::video::SMaterial*)material);
101   }
102
103   void
104   irr_video_setTransform(irr_video_IVideoDriver* driver,
105                          irr_video_E_TRANSFORMATION_STATE state,
106                          irr_core_matrix4* mat)
107   {
108     ((irr::video::IVideoDriver*)driver)
109       ->setTransform((irr::video::E_TRANSFORMATION_STATE)state,
110                      *(irr::core::matrix4*)mat);
111   }
112 }