diff options
author | Stijn Buys <ingar@osirion.org> | 2011-07-29 23:38:07 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2011-07-29 23:38:07 +0000 |
commit | 044d0183e254d89dd12d0799be6aa8f8f0f979f2 (patch) | |
tree | 285ec77a8cf5ac57fb17f4168272e1a600e13917 /src/render/draw.cc | |
parent | 8924c07280cdd96b01c501b3b820711f89039edd (diff) |
Moved material context functions into the State class.
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r-- | src/render/draw.cc | 216 |
1 files changed, 12 insertions, 204 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index 84015e3..64ac4c1 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -644,23 +644,10 @@ void draw_model_fragments(model::Model *model, const math::Color & color_primary, const math::Color & color_secondary, const float enginetime, const bool detail, const bool power, const float thrust) { - // default material, lighted and geometry color - const model::Material *material = 0; - math::Color color(1.0f, 1.0f, 1.0f); // current drawing color - bool use_light = true; // gl::disable(GL_LIGHTING) is set - bool use_texture = false; // texturing - bool use_env = false; // environment mapping - - // TODO this should probably be initialized somewhere else - gl::texgeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - gl::texgeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - - /* - gl::texgeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - gl::texgeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - gl::texgeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - */ - + State::set_color(color_primary); + State::set_color_second(color_secondary); + State::set_color_engine(model->enginecolor() * thrust); + for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { const model::FragmentGroup *group = (*git); @@ -684,201 +671,24 @@ void draw_model_fragments(model::Model *model, gl::translate(translation); } - for (model::FragmentGroup::Fragments::const_iterator fit = group->fragments().begin(); fit != group->fragments().end(); fit++) { const model::Fragment *fragment = (*fit); - - if (fragment->material() != material) { - material = fragment->material(); - - if (material) { - if (material->flags() & model::Material::Engine) { - - color.assign(model->enginecolor() * thrust); - - } else if (material->flags() & model::Material::Tertiary) { - - if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) { - for (size_t i = 0; i < 3; i++) - color[i] = (color_primary[i] + color_secondary[i]) / 2; - - } else if ((material->flags() & model::Material::Secondary) == model::Material::Secondary) { - color.assign(color_secondary); - - } - if ((material->flags() & model::Material::Primary) == model::Material::Primary) { - color.assign(color_primary); - } - - color.r *= material->color().r; - color.g *= material->color().g; - color.b *= material->color().b; - } else { - - color.assign(material->color()); - } - - if (power && (material->flags() & model::Material::Bright)) { - if (use_light) { - gl::disable(GL_LIGHTING); - use_light = false; - } - } else if (power && (material->flags() & model::Material::Engine)) { - if (use_light) { - gl::disable(GL_LIGHTING); - use_light = false; - } - } else { - if (!use_light) { - gl::enable(GL_LIGHTING); - use_light = true; - } - } - - if (material->flags() & model::Material::Texture) { - - Textures::bind(material->texture_id()); - - if (!use_texture) { - gl::enable(GL_TEXTURE_2D); - use_texture = true; - } - - } - - if (material->flags() & model::Material::Environment) { - - if (!(material->flags() & model::Material::Texture)) { - - if (use_texture) { - gl::disable(GL_TEXTURE_2D); - use_texture = false; - } - - // use sky as envmap if the material doesn't define a texture - if (core::localplayer()->zone()->sky().size()) { - gl::enable(GL_TEXTURE_CUBE_MAP); - - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); - - gl::enable(GL_TEXTURE_GEN_S); - gl::enable(GL_TEXTURE_GEN_T); - gl::enable(GL_TEXTURE_GEN_R); - use_env = true; - } - - } else { - gl::disable(GL_TEXTURE_CUBE_MAP); - - gl::texgeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - gl::texgeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - - gl::enable(GL_TEXTURE_GEN_S); - gl::enable(GL_TEXTURE_GEN_T); - use_env = true; - - if (!use_texture) { - gl::enable(GL_TEXTURE_2D); - use_texture = true; - } - } - } else { - if (use_env) { - // disable env mapping - gl::disable(GL_TEXTURE_GEN_S); - gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_GEN_R); - gl::disable(GL_TEXTURE_CUBE_MAP); - use_env = false; - } - } - - if (!(material->flags() & (model::Material::Texture + model::Material::Environment))) { - if (use_texture) { - gl::disable(GL_TEXTURE_2D); - use_texture = false; - } - } - - } else { - // material not found - if (use_light) { - // disable lighting - gl::disable(GL_LIGHTING); - use_light = false; - } - - if (use_env) { - // disable env mapping - gl::disable(GL_TEXTURE_GEN_S); - gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_GEN_R); - gl::disable(GL_TEXTURE_CUBE_MAP); - use_env = false; - } - - if (use_texture) { - gl::disable(GL_TEXTURE_2D); - use_texture = false; - } - - color.assign(1.0f, 0.0f, 1.0f); - } - } - - gl::color(color); + State::use_material(fragment->material()); draw_fragment(fragment, detail); if (r_normals->value()) { // force reset of material settings for the next fragment - material = 0; - if (use_light) { - // disable lighting - gl::disable(GL_LIGHTING); - use_light = false; - } - - if (use_env) { - // disable env mapping - gl::disable(GL_TEXTURE_GEN_S); - gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_GEN_R); - gl::disable(GL_TEXTURE_CUBE_MAP); - use_env = false; - } - - if (use_texture) { - gl::disable(GL_TEXTURE_2D); - use_texture = false; - } - - color.assign(0.75f, 0.0f, 0.0f); + State::reset(); + gl::color(0.75f, 0.0f, 0.0f); draw_fragment_normals(fragment, detail); } } gl::pop(); } - - if (!use_light) { - gl::enable(GL_LIGHTING); - } - - if (use_env) { - // disable env mapping - gl::disable(GL_TEXTURE_GEN_S); - gl::disable(GL_TEXTURE_GEN_T); - gl::disable(GL_TEXTURE_GEN_R); - gl::disable(GL_TEXTURE_CUBE_MAP); - } - - if (use_texture) { - gl::disable(GL_TEXTURE_2D); - } - + + State::reset(); } // draw bounding box @@ -1433,13 +1243,11 @@ void draw(float seconds) } gl::depthmask(GL_TRUE); // enable depth buffer writing - gl::disable(GL_DEPTH_TEST); // disable depth buffer testing - - gl::disable(GL_COLOR_MATERIAL); // disable color tracking + gl::disable(GL_DEPTH_TEST); // disable depth buffer testing gl::disable(GL_CULL_FACE); // disable culling - - // GL_BLEND must be enabled for the GUI + // GL_BLEND and GL_COLOR_MATERIAL must be enabled for the GUI + //gl::disable(GL_COLOR_MATERIAL); // disable color tracking } // draw HUD target world space geometry, like dock indicators |