Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/savegamemenu.cc4
-rw-r--r--src/model/asefile.cc2
-rw-r--r--src/model/mapfile.cc16
-rw-r--r--src/model/material.cc85
-rw-r--r--src/model/material.h22
-rw-r--r--src/render/state.cc68
-rw-r--r--src/render/textures.cc2
-rw-r--r--src/ui/paint.cc6
8 files changed, 119 insertions, 86 deletions
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index cb2cdeb..8efd746 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -324,8 +324,8 @@ void SaveGameMenu::show_file_info()
if (!screenshotmaterial) {
screenshotmaterial = new model::Material("ui/screenshot");
model::Material::add(screenshotmaterial);
- screenshotmaterial ->set_flags(model::Material::Texture);
- screenshotmaterial ->set_flags(model::Material::Bright);
+ screenshotmaterial ->set_flags(model::Material::FlagTexture);
+ screenshotmaterial ->set_flags(model::Material::FlagBright);
} else if (screenshotmaterial->texture().size()) {
render::Textures::unload(screenshotmaterial->texture());
}
diff --git a/src/model/asefile.cc b/src/model/asefile.cc
index 320d4b7..608dac3 100644
--- a/src/model/asefile.cc
+++ b/src/model/asefile.cc
@@ -583,7 +583,7 @@ bool ASEFile::read_geom(std::istream &is)
size_t submaterial_index = (*smit).first;
Material *material = (*smit).second;
- if ((material->flags() & Material::Ignore) != Material::Ignore ) {
+ if (!material->ignore_is_set()) {
// load GEOMOBJECT triangles with matching material into the fragment
Fragment *fragment = new Fragment(Fragment::Triangles, material);
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 359efe7..d4632e2 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -397,7 +397,7 @@ bool MapFile::read_patchdef()
}
// ignore materials with the 'Ignore' flag set
- if ((material->flags() & Material::Ignore) == Material::Ignore) {
+ if (material->ignore_is_set()) {
return true;
}
@@ -527,7 +527,7 @@ bool MapFile::read_patchdef()
for (size_t i = 0; i < subdivide_u; i++) {
for (size_t j = 0; j < subdivide_v; j++) {
- if ((material->flags() & Material::Clip) == Material::Clip) {
+ if (material->flag_is_set(Material::FlagClip)) {
// if the current material is clip, the patch needs to be converted to triangles
if (map_load_clip) {
@@ -754,7 +754,7 @@ void MapFile::make_brushface(Face *face)
using math::Vector3f;
// ignore materials with the 'Ignore' flag set
- if ((face->material()->flags() & Material::Ignore) == Material::Ignore) {
+ if (face->material()->ignore_is_set()) {
return;
}
@@ -954,7 +954,7 @@ void MapFile::make_brushface(Face *face)
primitives = (*mit).second;
}
- if ((face->material()->flags() & Material::Origin)) {
+ if (face->material()->origin_is_set()) {
// add vertices to the origin list
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); ++it) {
class_origin_vertices.push_back(new math::Vector3f((*(*it) * SCALE)));
@@ -972,7 +972,7 @@ void MapFile::make_brushface(Face *face)
face_normal.normalize();
// clip faces have to be triangulated and can not be split into quads
- if (!(face->material()->flags() & Material::Clip)) {
+ if (!face->material()->flag_is_set(Material::FlagClip)) {
// split polygon into quads
while (vl.size() > 3) {
@@ -987,7 +987,7 @@ void MapFile::make_brushface(Face *face)
Quad *quad = new Quad(*(*vn2) * SCALE, *(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
primitives->add_quad(quad);
- if (face->material()->flags() & Material::Texture) {
+ if (face->material()->flag_is_set(Material::FlagTexture)) {
quad->t0().assign(map_texture_coords(face, *(*vn2)));
quad->t1().assign(map_texture_coords(face, *(*vn1)));
quad->t2().assign(map_texture_coords(face, *(*vn)));
@@ -1011,7 +1011,7 @@ void MapFile::make_brushface(Face *face)
Triangle * triangle = new Triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
primitives->add_triangle(triangle);
- if (face->material()->flags() & Material::Texture) {
+ if (face->material()->flag_is_set(Material::FlagTexture)) {
triangle->t0().assign(map_texture_coords(face, *(*vn1)));
triangle->t1().assign(map_texture_coords(face, *(*vn)));
triangle->t2().assign(map_texture_coords(face, *(*v0)));
@@ -1245,7 +1245,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
// store triangles
if (primitives->triangles().size()) {
- if ((primitives->material()->flags() & Material::Clip) == Material::Clip) {
+ if (primitives->material()->flag_is_set(Material::FlagClip)) {
if (map_load_clip) {
// clip materials are loaded into the CollisionMesh
diff --git a/src/model/material.cc b/src/model/material.cc
index ff9a257..5a99489 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -26,6 +26,7 @@ Material::Material(const std::string &name) :
{
aux::to_lowercase(material_name);
material_flags = 0;
+ material_colortype = ColorMaterial;
material_texture_id = 0;
}
@@ -37,43 +38,47 @@ Material::~Material()
void Material::print()
{
con_print << name() << std::endl;
- con_print << " color: " << material_color.r << " " << material_color.g << " " << material_color.b << " " << material_color.a << std::endl;
- con_print << " flags: " << flags() << " ";
- if (flags() == None) {
+
+ con_print << " material color: " << material_color.r << " " << material_color.g << " " << material_color.b << " " << material_color.a << std::endl;
+ switch (colortype()) {
+ case ColorMaterial:
+ break;
+ case ColorPrimary:
+ con_print << " color type " << "entity primary" << std::endl;
+ break;
+ case ColorSecondary:
+ con_print << " color type " << "entity secondary" << std::endl;
+ break;
+ case ColorTertiary:
+ con_print << " color type " << "entity tertiary" << std::endl;
+ break;
+ case ColorEngine:
+ con_print << " color type " << "entity engine" << std::endl;
+ break;
+ }
+ con_print << " flags: " << flags() << " ";
+ if (flags() == FlagNone) {
con_print << "none";
} else {
- if ((flags() & Tertiary) == Tertiary) {
- con_print << "entitythird ";
-
- } else if (flags() & Secondary) {
- con_print << "entitysecond ";
-
- } else if (flags() & Primary) {
- con_print << "entity ";
- }
-
- if (flags() & Bright) {
+ if (flags() & FlagBright) {
con_print << "bright ";
}
- if (flags() & Engine) {
- con_print << "engine ";
- }
- if (flags() & Environment) {
+ if (flags() & FlagEnvironment) {
con_print << "environment ";
}
- if (flags() & Texture) {
+ if (flags() & FlagTexture) {
con_print << "texture ";
}
- if (flags() & Ignore) {
+ if (flags() & FlagIgnore) {
con_print << "ignore ";
}
- if (flags() & Clip) {
+ if (flags() & FlagClip) {
con_print << "clip ";
}
- if (flags() & Origin) {
+ if (flags() & FlagOrigin) {
con_print << "origin ";
}
- if (flags() & Decal) {
+ if (flags() & FlagDecal) {
con_print << "decal ";
}
}
@@ -99,13 +104,13 @@ void Material::set_specular(const math::Color &color)
void Material::set_texture(const std::string &texture)
{
if (texture.size()) {
- set_flags(Texture);
+ set_flags(FlagTexture);
material_texture.assign(texture);
if (material_loaderfunc) {
material_loaderfunc(this);
}
} else {
- unset_flags(Texture);
+ unset_flags(FlagTexture);
material_texture.clear();
material_texture_id = 0;
}
@@ -126,6 +131,11 @@ void Material::set_size(const math::Vector2f &size)
material_size.assign(size);
}
+void Material::set_colortype(ColorType colortype)
+{
+ material_colortype = colortype;
+}
+
void Material::init()
{
con_print << "^BInitializing materials..." << std::endl;
@@ -249,25 +259,26 @@ void Material::load_shader(const std::string &shadername)
material->set_specular(math::Color(r, g, b, a));
}
} else if (firstword.compare("engine") == 0) {
- material->set_flags(Engine);
- } else if (firstword.compare("bright") == 0) {
- material->set_flags(Bright);
- } else if (firstword.compare("environment") == 0) {
- material->set_flags(Environment);
+ material->set_colortype(ColorEngine);
} else if (firstword.compare("entity") == 0) {
- material->set_flags(Primary);
+ material->set_colortype(ColorPrimary);
} else if (firstword.compare("entitysecond") == 0) {
- material->set_flags(Secondary);
+ material->set_colortype(ColorSecondary);
} else if (firstword.compare("entitythird") == 0) {
- material->set_flags(Tertiary);
+ material->set_colortype(ColorTertiary);
+
+ } else if (firstword.compare("bright") == 0) {
+ material->set_flags(FlagBright);
+ } else if (firstword.compare("environment") == 0) {
+ material->set_flags(FlagEnvironment);
} else if (firstword.compare("ignore") == 0) {
- material->set_flags(Ignore);
+ material->set_flags(FlagIgnore);
} else if (firstword.compare("clip") == 0) {
- material->set_flags(Clip);
+ material->set_flags(FlagClip);
} else if (firstword.compare("origin") == 0) {
- material->set_flags(Origin);
+ material->set_flags(FlagOrigin);
} else if (firstword.compare("decal") == 0) {
- material->set_flags(Decal);
+ material->set_flags(FlagDecal);
} else if (firstword.compare("qer_editorimage") == 0) {
// keyword qer_editorimage is ignored
continue;
diff --git a/src/model/material.h b/src/model/material.h
index 2c66aae..6c332e2 100644
--- a/src/model/material.h
+++ b/src/model/material.h
@@ -23,8 +23,11 @@ public:
/// function pointer type for local functions
typedef void(* LoaderFuncPtr)(Material *);
+ /// color types
+ enum ColorType {ColorMaterial = 0, ColorPrimary = 1, ColorSecondary = 2, ColorTertiary = 3, ColorEngine = 4 };
+
/// surface flags
- enum SurfaceFlags { None = 0, Primary = 1, Secondary = 2, Tertiary = 3, Bright = 4, Engine = 8, Environment = 16, Texture = 32, Ignore = 64, Clip = 128, Origin = 256, Decal = 512 };
+ enum SurfaceFlags { FlagNone = 0, FlagBright = 1,FlagEnvironment = 2, FlagTexture = 4, FlagIgnore = 8, FlagClip = 16, FlagOrigin = 32, FlagDecal = 64 };
/// type definition for the material registry
typedef std::map<std::string, Material *> Registry;
@@ -52,6 +55,10 @@ public:
inline const unsigned int flags() const {
return material_flags;
}
+
+ inline const ColorType colortype() const {
+ return material_colortype;
+ }
inline const std::string &texture() const {
return material_texture;
@@ -80,7 +87,7 @@ public:
* @see flags()
* */
inline bool ignore_is_set() const {
- return (flag_is_set(Ignore));
+ return (flag_is_set(FlagIgnore));
}
/**
@@ -88,13 +95,15 @@ public:
* @see flags()
* */
inline bool origin_is_set() const {
- return (flag_is_set(Origin));
+ return (flag_is_set(FlagOrigin));
}
/* ---- mutators ------------------------------------------- */
void set_color(const math::Color &color);
+
void set_specular(const math::Color &specular);
+
/**
* @brief set the material texture name
*/
@@ -114,6 +123,12 @@ public:
* @brief set the material texture size
*/
void set_size(const math::Vector2f &size);
+
+ /**
+ * @brief set the color type
+ * */
+ void set_colortype(ColorType colortype);
+
inline void set_flags(SurfaceFlags flags) {
material_flags |= flags;
@@ -164,6 +179,7 @@ private:
math::Color material_color;
math::Color material_specular;
unsigned int material_flags;
+ ColorType material_colortype;
std::string material_texture;
size_t material_texture_id;
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]);
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index d400baa..7b8e43f 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -68,7 +68,7 @@ void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vecto
model::Material::add(material);
material->set_texture(material->name());
// ui btimaps are fullbright
- material->set_flags(model::Material::Bright);
+ material->set_flags(model::Material::FlagBright);
}
render::State::set_color(math::Color());
@@ -104,7 +104,7 @@ void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vecto
model::Material::add(material);
material->set_texture(material->name());
// ui btimaps are fullbright
- material->set_flags(model::Material::Bright);
+ material->set_flags(model::Material::FlagBright);
}
render::State::set_power(true);
@@ -141,7 +141,7 @@ void Paint::draw_material(const math::Vector2f &global_location, const math::Vec
model::Material::add(material);
material->set_texture(material->name());
// ui btimaps are fullbright
- material->set_flags(model::Material::Bright);
+ material->set_flags(model::Material::FlagBright);
}
// use global coordinates