X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fmaterial.cpp;h=72467acc7f39572b50a8c3f53ccc0404b1fd8578;hb=41a6ad96e81a8d8153c54877c4c12f61100677a9;hp=b4122563eed5a6db7e0fb25eb192c8ec7ea9c76a;hpb=f3e2debaa586874bc403a1dfb01709433627f9cd;p=guile-irrlicht.git diff --git a/src/material.cpp b/src/material.cpp index b412256..72467ac 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -21,38 +21,332 @@ #include #include + +#include "color.h" +#include "gsubr.h" #include "material.h" -#include "wrapped.h" - -extern "C" { - - void - init_material (void) - { - init_material_type (); - scm_c_define_gsubr ("make-material", 0, 0, 1, (scm_t_subr)make_material); - scm_c_export ("make-material", NULL); - } - - DEFINE_WRAPPED_TYPE (irr::video::SMaterial*, "material", - init_material_type, material_p, - wrap_material, unwrap_material); - - SCM - make_material (SCM rest) - { - SCM wireframe = scm_from_bool (0); - SCM lighting = scm_from_bool (1); - - scm_c_bind_keyword_arguments ("make-material", rest, (scm_t_keyword_arguments_flags)0, - scm_from_utf8_keyword ("wireframe"), &wireframe, - scm_from_utf8_keyword ("lighting"), &lighting, - SCM_UNDEFINED); - - irr::video::SMaterial* material = new irr::video::SMaterial (); - material->Wireframe = wireframe; - material->Lighting = lighting; - return wrap_material (material); - } +#include "material-types.h" + +using namespace irr; + +SCM +video_SMaterial_make (SCM rest) +{ + SCM material_type; + SCM ambient_color; + SCM diffuse_color; + SCM emissive_color; + SCM specular_color; + SCM shininess; + SCM material_type_param; + SCM material_type_param_2; + SCM thickness; + SCM z_buffer; + SCM anti_aliasing; + SCM color_mask; + SCM color_material; + SCM blend_operation; + SCM polygon_offset_factor; + SCM polygon_offset_direction; + SCM wireframe; + SCM point_cloud; + SCM gouraud_shading; + SCM lighting; + SCM z_write_enable; + SCM backface_culling; + SCM frontface_culling; + SCM fog_enable; + SCM normalize_normals; + SCM use_mip_maps; + + scm_c_bind_keyword_arguments + ("video_SMaterial_make", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("material-type"), &material_type, + scm_from_utf8_keyword ("ambient-color"), &ambient_color, + scm_from_utf8_keyword ("diffuse-color"), &diffuse_color, + scm_from_utf8_keyword ("emissive-color"), &emissive_color, + scm_from_utf8_keyword ("specular-color"), &specular_color, + scm_from_utf8_keyword ("shininess"), &shininess, + scm_from_utf8_keyword ("material-type-param"), &material_type_param, + scm_from_utf8_keyword ("material-type-param-2"), &material_type_param_2, + scm_from_utf8_keyword ("thickness"), &thickness, + scm_from_utf8_keyword ("z-buffer"), &z_buffer, + scm_from_utf8_keyword ("anti-aliasing"), &anti_aliasing, + scm_from_utf8_keyword ("color-mask"), &color_mask, + scm_from_utf8_keyword ("color-material"), &color_material, + scm_from_utf8_keyword ("blend-operation"), &blend_operation, + scm_from_utf8_keyword ("polygon-offset-factor"), &polygon_offset_factor, + scm_from_utf8_keyword ("polygon-offset-direction"), &polygon_offset_direction, + scm_from_utf8_keyword ("wireframe"), &wireframe, + scm_from_utf8_keyword ("point-cloud"), &point_cloud, + scm_from_utf8_keyword ("gouraud-shading"), &gouraud_shading, + scm_from_utf8_keyword ("lighting"), &lighting, + scm_from_utf8_keyword ("z-write-enable"), &z_write_enable, + scm_from_utf8_keyword ("backface-culling"), &backface_culling, + scm_from_utf8_keyword ("frontface-culling"), &frontface_culling, + scm_from_utf8_keyword ("fog-enable"), &fog_enable, + scm_from_utf8_keyword ("normalize-normals"), &normalize_normals, + scm_from_utf8_keyword ("use-mip-maps"), &use_mip_maps, + SCM_UNDEFINED); + + video::SMaterial* material = new video::SMaterial (); + material->MaterialType = scm_to_material_type(material_type); + material->AmbientColor = scm_to_color (ambient_color); + material->DiffuseColor = scm_to_color (diffuse_color); + material->EmissiveColor = scm_to_color (emissive_color); + material->SpecularColor = scm_to_color (specular_color); + material->Shininess = scm_to_double (shininess); + material->MaterialTypeParam = scm_to_double (material_type_param); + material->MaterialTypeParam2 = scm_to_double (material_type_param_2); + material->Thickness = scm_to_double (thickness); + material->ZBuffer = scm_to_comparison_func (z_buffer); + material->AntiAliasing = scm_to_anti_aliasing_mode (anti_aliasing); + material->ColorMask = scm_to_color_plane (color_mask); + material->ColorMaterial = scm_to_color_material (color_material); + material->BlendOperation = scm_to_blend_operation (blend_operation); + material->PolygonOffsetFactor = scm_to_uint8 (polygon_offset_factor); + material->PolygonOffsetDirection = scm_to_polygon_offset (polygon_offset_direction); + material->Wireframe = scm_to_bool (wireframe); + material->PointCloud = scm_to_bool (point_cloud); + material->GouraudShading = scm_to_bool (gouraud_shading); + material->Lighting = scm_to_bool (lighting); + material->ZWriteEnable = scm_to_bool (z_write_enable); + material->BackfaceCulling = scm_to_bool (backface_culling); + material->FrontfaceCulling = scm_to_bool (frontface_culling); + material->FogEnable = scm_to_bool (fog_enable); + material->NormalizeNormals = scm_to_bool (normalize_normals); + material->UseMipMaps = scm_to_bool (use_mip_maps); + return scm_from_pointer ((void*) material, NULL); +} + +void +init_material (void) +{ + DEFINE_GSUBR ("video_SMaterial_make", 0, 0, 1, video_SMaterial_make); +} + +video::E_ANTI_ALIASING_MODE +scm_to_anti_aliasing_mode (SCM anti_aliasing_mode) +{ + char* mode = scm_to_utf8_stringn (scm_symbol_to_string (anti_aliasing_mode), NULL); + if (!strcmp (mode, "off")) + { + return video::EAAM_OFF; + } + else if (!strcmp (mode, "simple")) + { + return video::EAAM_SIMPLE; + } + else if (!strcmp (mode, "quality")) + { + return video::EAAM_QUALITY; + } + else if (!strcmp (mode, "line-smooth")) + { + return video::EAAM_LINE_SMOOTH; + } + else if (!strcmp (mode, "point-smooth")) + { + return video::EAAM_POINT_SMOOTH; + } + else if (!strcmp (mode, "full-basic")) + { + return video::EAAM_FULL_BASIC; + } + else if (!strcmp (mode, "alpha-to-coverage")) + { + return video::EAAM_ALPHA_TO_COVERAGE; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong anti aliasing mode: ~S", + scm_list_1 (anti_aliasing_mode), scm_list_1 (anti_aliasing_mode)); + } +} + +video::E_BLEND_OPERATION +scm_to_blend_operation (SCM blend_operation) +{ + char* operation = scm_to_utf8_stringn (scm_symbol_to_string (blend_operation), NULL); + if (!strcmp (operation, "none")) + { + return video::EBO_NONE; + } + else if (!strcmp (operation, "add")) + { + return video::EBO_ADD; + } + else if (!strcmp (operation, "subtract")) + { + return video::EBO_SUBTRACT; + } + else if (!strcmp (operation, "rev-subtract")) + { + return video::EBO_REVSUBTRACT; + } + else if (!strcmp (operation, "min")) + { + return video::EBO_MIN; + } + else if (!strcmp (operation, "max")) + { + return video::EBO_MAX; + } + else if (!strcmp (operation, "min-factor")) + { + return video::EBO_MIN_FACTOR; + } + else if (!strcmp (operation, "max-factor")) + { + return video::EBO_MAX_FACTOR; + } + else if (!strcmp (operation, "min-alpha")) + { + return video::EBO_MIN_ALPHA; + } + else if (!strcmp (operation, "max-alpha")) + { + return video::EBO_MAX_ALPHA; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong blend operation: ~S", + scm_list_1 (blend_operation), scm_list_1 (blend_operation)); + } +} + +video::E_COLOR_MATERIAL +scm_to_color_material (SCM color_material) +{ + char* material = scm_to_utf8_stringn (scm_symbol_to_string (color_material), NULL); + if (!strcmp (material, "none")) + { + return video::ECM_NONE; + } + else if (!strcmp (material, "diffuse")) + { + return video::ECM_DIFFUSE; + } + else if (!strcmp (material, "ambient")) + { + return video::ECM_AMBIENT; + } + else if (!strcmp (material, "emissive")) + { + return video::ECM_EMISSIVE; + } + else if (!strcmp (material, "specular")) + { + return video::ECM_SPECULAR; + } + else if (!strcmp (material, "diffuse-and-ambient")) + { + return video::ECM_DIFFUSE_AND_AMBIENT; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong color material: ~S", + scm_list_1 (color_material), scm_list_1 (color_material)); + } +} + +video::E_COLOR_PLANE +scm_to_color_plane (SCM color_plane) +{ + char* plane = scm_to_utf8_stringn (scm_symbol_to_string (color_plane), NULL); + if (!strcmp (plane, "none")) + { + return video::ECP_NONE; + } + else if (!strcmp (plane, "alpha")) + { + return video::ECP_ALPHA; + } + else if (!strcmp (plane, "red")) + { + return video::ECP_RED; + } + else if (!strcmp (plane, "green")) + { + return video::ECP_GREEN; + } + else if (!strcmp (plane, "blue")) + { + return video::ECP_BLUE; + } + else if (!strcmp (plane, "rgb")) + { + return video::ECP_RGB; + } + else if (!strcmp (plane, "all")) + { + return video::ECP_ALL; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong color plane: ~S", + scm_list_1 (color_plane), scm_list_1 (color_plane)); + } +} + +video::E_COMPARISON_FUNC +scm_to_comparison_func (SCM comparison_func) +{ + char* func = scm_to_utf8_stringn (scm_symbol_to_string (comparison_func), NULL); + if (!strcmp (func, "never")) + { + return video::ECFN_NEVER; + } + else if (!strcmp (func, "less-equal")) + { + return video::ECFN_LESSEQUAL; + } + else if (!strcmp (func, "equal")) + { + return video::ECFN_EQUAL; + } + else if (!strcmp (func, "less")) + { + return video::ECFN_LESS; + } + else if (!strcmp (func, "not-equal")) + { + return video::ECFN_NOTEQUAL; + } + else if (!strcmp (func, "greater-equal")) + { + return video::ECFN_GREATEREQUAL; + } + else if (!strcmp (func, "greater")) + { + return video::ECFN_GREATER; + } + else if (!strcmp (func, "always")) + { + return video::ECFN_ALWAYS; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong comparison func: ~S", + scm_list_1 (comparison_func), scm_list_1 (comparison_func)); + } +} +video::E_POLYGON_OFFSET +scm_to_polygon_offset (SCM polygon_offset) +{ + char* offset = scm_to_utf8_stringn (scm_symbol_to_string (polygon_offset), NULL); + if (!strcmp (offset, "back")) + { + return video::EPO_BACK; + } + else if (!strcmp (offset, "front")) + { + return video::EPO_FRONT; + } + else + { + scm_error (scm_arg_type_key, NULL, "Wrong polygon offset: ~S", + scm_list_1 (polygon_offset), scm_list_1 (polygon_offset)); + } }