Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
core_material.h
1 #pragma once
2 
3 #include "../constants.h"
4 
5 namespace smlt {
6 
7 typedef uint32_t MaterialPropertyNameHash;
8 
9 unsigned constexpr material_property_hash(char const *input) {
10  return *input ?
11  static_cast<unsigned int>(*input) + 33 * material_property_hash(input + 1) :
12  5381;
13 }
14 
15 constexpr const MaterialPropertyNameHash DIFFUSE_PROPERTY_HASH = material_property_hash(DIFFUSE_PROPERTY_NAME);
16 constexpr const MaterialPropertyNameHash AMBIENT_PROPERTY_HASH = material_property_hash(AMBIENT_PROPERTY_NAME);
17 constexpr const MaterialPropertyNameHash SPECULAR_PROPERTY_HASH = material_property_hash(SPECULAR_PROPERTY_NAME);
18 constexpr const MaterialPropertyNameHash EMISSION_PROPERTY_HASH = material_property_hash(EMISSION_PROPERTY_NAME);
19 constexpr const MaterialPropertyNameHash SHININESS_PROPERTY_HASH = material_property_hash(SHININESS_PROPERTY_NAME);
20 constexpr const MaterialPropertyNameHash POINT_SIZE_PROPERTY_HASH = material_property_hash(POINT_SIZE_PROPERTY_NAME);
21 
22 constexpr const MaterialPropertyNameHash DEPTH_WRITE_ENABLED_PROPERTY_HASH = material_property_hash(DEPTH_WRITE_ENABLED_PROPERTY_NAME);
23 constexpr const MaterialPropertyNameHash DEPTH_TEST_ENABLED_PROPERTY_HASH = material_property_hash(DEPTH_TEST_ENABLED_PROPERTY_NAME);
24 constexpr const MaterialPropertyNameHash LIGHTING_ENABLED_PROPERTY_HASH = material_property_hash(LIGHTING_ENABLED_PROPERTY_NAME);
25 constexpr const MaterialPropertyNameHash TEXTURES_ENABLED_PROPERTY_HASH = material_property_hash(TEXTURES_ENABLED_PROPERTY_NAME);
26 
27 constexpr const MaterialPropertyNameHash DIFFUSE_MAP_PROPERTY_HASH = material_property_hash(DIFFUSE_MAP_PROPERTY_NAME);
28 constexpr const MaterialPropertyNameHash LIGHT_MAP_PROPERTY_HASH = material_property_hash(LIGHT_MAP_PROPERTY_NAME);
29 constexpr const MaterialPropertyNameHash NORMAL_MAP_PROPERTY_HASH = material_property_hash(NORMAL_MAP_PROPERTY_NAME);
30 constexpr const MaterialPropertyNameHash SPECULAR_MAP_PROPERTY_HASH = material_property_hash(SPECULAR_MAP_PROPERTY_NAME);
31 
32 constexpr const MaterialPropertyNameHash DIFFUSE_MAP_MATRIX_PROPERTY_HASH = material_property_hash(DIFFUSE_MAP_MATRIX_PROPERTY_NAME);
33 constexpr const MaterialPropertyNameHash LIGHT_MAP_MATRIX_PROPERTY_HASH = material_property_hash(LIGHT_MAP_MATRIX_PROPERTY_NAME);
34 constexpr const MaterialPropertyNameHash NORMAL_MAP_MATRIX_PROPERTY_HASH = material_property_hash(NORMAL_MAP_MATRIX_PROPERTY_NAME);
35 constexpr const MaterialPropertyNameHash SPECULAR_MAP_MATRIX_PROPERTY_HASH = material_property_hash(SPECULAR_MAP_MATRIX_PROPERTY_NAME);
36 
37 constexpr const MaterialPropertyNameHash BLEND_FUNC_PROPERTY_HASH = material_property_hash(BLEND_FUNC_PROPERTY_NAME);
38 constexpr const MaterialPropertyNameHash POLYGON_MODE_PROPERTY_HASH = material_property_hash(POLYGON_MODE_PROPERTY_NAME);
39 constexpr const MaterialPropertyNameHash SHADE_MODEL_PROPERTY_HASH = material_property_hash(SHADE_MODEL_PROPERTY_NAME);
40 constexpr const MaterialPropertyNameHash COLOUR_MATERIAL_PROPERTY_HASH = material_property_hash(COLOUR_MATERIAL_PROPERTY_NAME);
41 constexpr const MaterialPropertyNameHash CULL_MODE_PROPERTY_HASH = material_property_hash(CULL_MODE_PROPERTY_NAME);
42 constexpr const MaterialPropertyNameHash DEPTH_FUNC_PROPERTY_HASH = material_property_hash(DEPTH_FUNC_PROPERTY_NAME);
43 
44 constexpr const MaterialPropertyNameHash FOG_MODE_PROPERTY_HASH = material_property_hash(FOG_MODE_PROPERTY_NAME);
45 constexpr const MaterialPropertyNameHash FOG_DENSITY_PROPERTY_HASH = material_property_hash(FOG_DENSITY_PROPERTY_NAME);
46 constexpr const MaterialPropertyNameHash FOG_START_PROPERTY_HASH = material_property_hash(FOG_START_PROPERTY_NAME);
47 constexpr const MaterialPropertyNameHash FOG_END_PROPERTY_HASH = material_property_hash(FOG_END_PROPERTY_NAME);
48 constexpr const MaterialPropertyNameHash FOG_COLOUR_PROPERTY_HASH = material_property_hash(FOG_COLOUR_PROPERTY_NAME);
49 
50 
51 enum MaterialPropertyType {
52  MATERIAL_PROPERTY_TYPE_BOOL,
53  MATERIAL_PROPERTY_TYPE_INT,
54  MATERIAL_PROPERTY_TYPE_FLOAT,
55  MATERIAL_PROPERTY_TYPE_VEC2,
56  MATERIAL_PROPERTY_TYPE_VEC3,
57  MATERIAL_PROPERTY_TYPE_VEC4,
58  MATERIAL_PROPERTY_TYPE_MAT3,
59  MATERIAL_PROPERTY_TYPE_MAT4,
60  MATERIAL_PROPERTY_TYPE_TEXTURE
61 };
62 
63 struct CoreMaterial {
64  const Colour diffuse = Colour(1, 1, 1, 1);
65  const Colour ambient = Colour(1, 1, 1, 1);
66  const Colour emission = Colour(0, 0, 0, 1);
67  const Colour specular = Colour(0, 0, 0, 1);
68 
69  const float shininess = 0.0f;
70  const float point_size = 1.0f;
71 
72  const bool depth_writes_enabled = true;
73  const bool depth_test_enabled = true;
74 
75  const bool lighting_enabled = true;
76  const int32_t textures_enabled = DIFFUSE_MAP_ENABLED | LIGHT_MAP_ENABLED | SPECULAR_MAP_ENABLED | NORMAL_MAP_ENABLED; /* Enable first 4 texture units */
77 
78  TexturePtr diffuse_map;
79  TexturePtr light_map;
80  TexturePtr normal_map;
81  TexturePtr specular_map;
82 
83  const Mat4 diffuse_map_matrix;
84  const Mat4 specular_map_matrix;
85  const Mat4 light_map_matrix;
86  const Mat4 normal_map_matrix;
87 
88  const EnumType blend_func = (EnumType) BLEND_NONE;
89  const EnumType polygon_mode = (EnumType) POLYGON_MODE_FILL;
90  const EnumType shade_model = (EnumType) SHADE_MODEL_SMOOTH;
91  const EnumType colour_material = (EnumType) COLOUR_MATERIAL_NONE;
92  const EnumType cull_mode = (EnumType) CULL_MODE_NONE;
93  const EnumType depth_func = (EnumType) DEPTH_FUNC_LEQUAL;
94 
95  const EnumType fog_mode = (EnumType) FOG_MODE_NONE;
96  const float fog_density = 1.0f;
97  const float fog_start = 100.0f;
98  const float fog_end = 1000.0f;
99  const Colour fog_colour = smlt::Colour::WHITE;
100 };
101 
102 void init_core_material(const CoreMaterial& base);
103 const CoreMaterial& core_material();
104 
105 typedef std::vector<std::pair<std::string, MaterialPropertyType>> PropertyList;
106 
107 const PropertyList &core_properties();
108 
109 bool is_core_property(const char* name);
110 bool is_core_property(const MaterialPropertyNameHash hsh);
111 
112 bool core_property_type(const char* name, MaterialPropertyType* type);
113 bool core_property_type(MaterialPropertyNameHash hsh, MaterialPropertyType* type);
114 
115 bool core_material_property_value(const char* name, const Colour*& out);
116 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Colour*& out);
117 
118 bool core_material_property_value(const char* name, const float *&out);
119 bool core_material_property_value(const MaterialPropertyNameHash hsh, const float*& out);
120 
121 bool core_material_property_value(const char* name, const int32_t*&);
122 bool core_material_property_value(const MaterialPropertyNameHash hsh, const int32_t*& out);
123 
124 bool core_material_property_value(const char* name, const bool*& out);
125 bool core_material_property_value(const MaterialPropertyNameHash hsh, const bool*& out);
126 
127 bool core_material_property_value(const char* name, const Vec2*& out);
128 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Vec2*& out);
129 
130 bool core_material_property_value(const char* name, const Vec3*& out);
131 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Vec3*& out);
132 
133 bool core_material_property_value(const char* name, const Vec4*& out);
134 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Vec4*& out);
135 
136 bool core_material_property_value(const char* name, const Mat3*& out);
137 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Mat3*& out);
138 
139 bool core_material_property_value(const char* name, const Mat4*& out);
140 bool core_material_property_value(const MaterialPropertyNameHash hsh, const Mat4*& out);
141 
142 bool core_material_property_value(const char* name, const TexturePtr*& out);
143 bool core_material_property_value(const MaterialPropertyNameHash hsh, const TexturePtr*& out);
144 
145 }
smlt::CoreMaterial
Definition: core_material.h:63
smlt::Mat4
Definition: mat4.h:25
smlt::Vec3
Definition: vec3.h:23
smlt::Mat3
Definition: mat3.h:13
smlt
Definition: animation.cpp:25
smlt::Colour
Definition: colour.h:29
smlt::Vec4
Definition: vec4.h:11
smlt::Vec2
Definition: vec2.h:13