]> git.jsancho.org Git - guile-irrlicht.git/blob - src/material-flags.cpp
set-material-flag!
[guile-irrlicht.git] / src / material-flags.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-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    guile-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 <libguile.h>
24 #include "animated-mesh-scene-node.h"
25 #include "material-flags.h"
26 #include "scene-node.h"
27
28 extern "C" {
29
30   void
31   init_material_flag (void)
32   {
33     scm_c_define_gsubr ("set-material-flag!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialFlag);
34   }
35
36   SCM
37   irr_scene_setMaterialFlag (SCM wrapped_obj,
38                              SCM flag,
39                              SCM newvalue)
40   {
41     if (animated_mesh_scene_node_p (wrapped_obj))
42       {
43         unwrap_animated_mesh_scene_node (wrapped_obj)->setMaterialFlag (scm_to_material_flag (flag),
44                                                                         scm_to_bool (newvalue));
45       }
46     else if (scene_node_p (wrapped_obj))
47       {
48         unwrap_scene_node (wrapped_obj)->setMaterialFlag (scm_to_material_flag (flag),
49                                                           scm_to_bool (newvalue));
50       }
51     else
52       {
53         scm_error (scm_arg_type_key, NULL, "Cannot set material flag for object: ~S",
54                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
55       }
56     return SCM_UNSPECIFIED;
57   }
58
59   irr::video::E_MATERIAL_FLAG
60   scm_to_material_flag (SCM material_flag)
61   {
62     char* flag = scm_to_utf8_stringn (scm_symbol_to_string (material_flag), NULL);
63     if (!strcmp (flag, "wireframe"))
64       {
65         return irr::video::EMF_WIREFRAME;
66       }
67     else if (!strcmp (flag, "pointcloud"))
68       {
69         return irr::video::EMF_POINTCLOUD;
70       }
71     else if (!strcmp (flag, "gouraud-shading"))
72       {
73         return irr::video::EMF_GOURAUD_SHADING;
74       }
75     else if (!strcmp (flag, "lighting"))
76       {
77         return irr::video::EMF_LIGHTING;
78       }
79     else if (!strcmp (flag, "zbuffer"))
80       {
81         return irr::video::EMF_ZBUFFER;
82       }
83     else if (!strcmp (flag, "zwrite-enable"))
84       {
85         return irr::video::EMF_ZWRITE_ENABLE;
86       }
87     else if (!strcmp (flag, "back-face-culling"))
88       {
89         return irr::video::EMF_BACK_FACE_CULLING;
90       }
91     else if (!strcmp (flag, "front-face-culling"))
92       {
93         return irr::video::EMF_FRONT_FACE_CULLING;
94       }
95     else if (!strcmp (flag, "bilinear-filter"))
96       {
97         return irr::video::EMF_BILINEAR_FILTER;
98       }
99     else if (!strcmp (flag, "trilinear-filter"))
100       {
101         return irr::video::EMF_TRILINEAR_FILTER;
102       }
103     else if (!strcmp (flag, "anisotropic-filter"))
104       {
105         return irr::video::EMF_ANISOTROPIC_FILTER;
106       }
107     else if (!strcmp (flag, "fog-enable"))
108       {
109         return irr::video::EMF_FOG_ENABLE;
110       }
111     else if (!strcmp (flag, "normalize-normals"))
112       {
113         return irr::video::EMF_NORMALIZE_NORMALS;
114       }
115     else if (!strcmp (flag, "texture-wrap"))
116       {
117         return irr::video::EMF_TEXTURE_WRAP;
118       }
119     else if (!strcmp (flag, "anti-aliasing"))
120       {
121         return irr::video::EMF_ANTI_ALIASING;
122       }
123     else if (!strcmp (flag, "color-mask"))
124       {
125         return irr::video::EMF_COLOR_MASK;
126       }
127     else if (!strcmp (flag, "color-material"))
128       {
129         return irr::video::EMF_COLOR_MATERIAL;
130       }
131     else if (!strcmp (flag, "use-mip-maps"))
132       {
133         return irr::video::EMF_USE_MIP_MAPS;
134       }
135     else if (!strcmp (flag, "blend-operation"))
136       {
137         return irr::video::EMF_BLEND_OPERATION;
138       }
139     else if (!strcmp (flag, "polygon-offset"))
140       {
141         return irr::video::EMF_POLYGON_OFFSET;
142       }
143     else
144       {
145         scm_error (scm_arg_type_key, NULL, "Wrong material flag: ~S",
146                    scm_list_1 (material_flag), scm_list_1 (material_flag));
147       }
148   }
149
150 }