Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-09-28 12:13:29 +0000
committerStijn Buys <ingar@osirion.org>2013-09-28 12:13:29 +0000
commit18dc1f6d0e044e5e4b1f3a40fcc65e532ec2e765 (patch)
tree0d6fe9eba4663bdfaa2901b158c5eca554cf1368 /src/render
parentb13e375c130066e2c9d0f34bc79b6b1ad0f0b449 (diff)
Cleanup of the material API: split flags into flags and colortype.
Diffstat (limited to 'src/render')
-rw-r--r--src/render/state.cc68
-rw-r--r--src/render/textures.cc2
2 files changed, 38 insertions, 32 deletions
diff --git a/src/render/state.cc b/src/render/state.cc
index 7720722..df9a001 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -237,7 +237,7 @@ void State::use_material(const model::Material * material) {
}
// material has the decal flag set
- if (material->flags() & model::Material::Decal) {
+ if (material->flag_is_set(model::Material::FlagDecal)) {
gl::enable(GL_POLYGON_OFFSET_FILL);
gl::enable(GL_ALPHA_TEST);
gl::polygonoffset(-1,-1);
@@ -245,48 +245,54 @@ void State::use_material(const model::Material * material) {
}
// assign the opengl drawing color according to material flags
- if (material->flags() & model::Material::Engine) {
-
- // use current engine color
- color.assign(state_color_engine);
- specular.assign(0.0f);
-
- } else if (material->flags() & model::Material::Tertiary) {
-
- // use entity colors
- if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) {
+ switch (material->colortype()) {
+ case model::Material::ColorMaterial:
+ color.assign(material->color());
+ specular.assign(material->specular());
+ break;
+
+ case model::Material::ColorEngine:
+ // assign current engine color
+ color.assign(state_color_engine);
+ specular.assign(0.0f);
+ break;
+
+ case model::Material::ColorPrimary:
+ // assign current primary entity color
+ color.assign(state_color_primary);
+ specular.assign(state_color_primary);
+ break;
+
+ case model::Material::ColorSecondary:
+ // assign current secondry entity color
+ color.assign(state_color_secondary);
+ specular.assign(state_color_secondary);
+ break;
+
+ case model::Material::ColorTertiary:
+ // assign current tertiary entity color
for (size_t i = 0; i < 3; i++) {
color[i] = (state_color_primary[i] + state_color_secondary[i]) / 2;
specular[i] = (state_color_primary[i] + state_color_secondary[i]) / 2;
}
-
- } else if ((material->flags() & model::Material::Secondary) == model::Material::Secondary) {
- color.assign(state_color_secondary);
- specular.assign(state_color_secondary);
-
- } else if ((material->flags() & model::Material::Primary) == model::Material::Primary) {
- color.assign(state_color_primary);
- specular.assign(state_color_primary);
- }
-
+ break;
+ }
+
+ // blend color type with material color
+ if (material->colortype() != model::Material::ColorMaterial) {
color.r *= material->color().r;
color.g *= material->color().g;
color.b *= material->color().b;
specular.r *= material->specular().r;
specular.g *= material->specular().g;
specular.b *= material->specular().b;
-
- } else {
- // use material color
- color.assign(material->color());
- specular.assign(material->specular());
}
// lighted or fullbright
- if (state_power && (material->flags() & model::Material::Bright)) {
+ if (state_power && (material->flag_is_set(model::Material::FlagBright))) {
gl::disable(GL_LIGHTING);
- } else if (state_power && (material->flags() & model::Material::Engine)) {
+ } else if (state_power && (material->colortype() == model::Material::ColorEngine)) {
gl::disable(GL_LIGHTING);
} else {
@@ -294,12 +300,12 @@ void State::use_material(const model::Material * material) {
}
// texture
- if (material->flags() & model::Material::Texture) {
+ if (material->flag_is_set(model::Material::FlagTexture)) {
Textures::bind(material->texture_id());
gl::enable(GL_TEXTURE_2D);
- if (material->flags() & model::Material::Environment) {
+ if (material->flag_is_set(model::Material::FlagEnvironment)) {
gl::texgen(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
gl::texgen(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
@@ -309,7 +315,7 @@ void State::use_material(const model::Material * material) {
} else {
// envmapped without texture: use the skybox as envmap
- if (material->flags() & model::Material::Environment) {
+ if (material->flag_is_set(model::Material::FlagEnvironment)) {
if (core::localplayer()->zone()->sky().size()) {
gl::enable(GL_TEXTURE_CUBE_MAP);
diff --git a/src/render/textures.cc b/src/render/textures.cc
index e4bfe7f..05c73da 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -418,7 +418,7 @@ size_t Textures::bind(const size_t texture, const bool filter)
void Textures::material_loader(model::Material *material)
{
- if ((material->flags() & model::Material::Texture) && (material->texture().size())) {
+ if (material->flag_is_set(model::Material::FlagTexture) && (material->texture().size() > 0)) {
size_t id = load(material->texture());
material->set_texture_id(id);
material->set_size(texture_size[id]);