Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/draw.cc175
1 files changed, 98 insertions, 77 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 17dbdda..54a56a0 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -8,6 +8,8 @@
#include <iomanip>
#include "core/core.h"
+#include "model/fragment.h"
+#include "model/material.h"
#include "model/model.h"
#include "render/render.h"
#include "render/textures.h"
@@ -245,50 +247,91 @@ void draw_entity_axis(core::Entity *entity)
gl::end();
}
-/* ----- Entity models --------------------------------------------- */
+/* ----- model fragments ------------------------------------------- */
-void draw_model_vertex(core::Entity *entity)
+void draw_fragment(model::Fragment *fragment, bool draw_details)
{
- size_t count = entity->model()->vertex_structural();
- if (entity->state()->detailvisible())
- count += entity->model()->vertex_detail();
-
- // draw model vertices
- if (count) {
- size_t index = entity->model()->first_vertex();
- glDrawArrays(gl::Triangles, index, count);
- Stats::tris += count/3;
+ size_t index = fragment->index();
+
+ size_t vertex_count = fragment->structural_size();
+ if (draw_details)
+ vertex_count += fragment->detail_size();
+
+ switch (fragment->type()) {
+ case model::Fragment::Triangles:
+ glDrawArrays(gl::Triangles, index, vertex_count);
+ Stats::tris += vertex_count / 3;
+ break;
+
+ case model::Fragment::Quads:
+ glDrawArrays(gl::Quads, index, vertex_count);
+ Stats::quads += vertex_count / 4;
+ break;
}
}
-void draw_model_lvertex(core::Entity *entity)
+void draw_model_fragments(core::Entity *entity)
{
- size_t count = entity->model()->lvertex_structural();
- if (entity->state()->detailvisible())
- count += entity->model()->lvertex_detail();
-
- // draw model lvertices
- if (count) {
- gl::disable(GL_LIGHTING);
- size_t index = entity->model()->first_lvertex();
- glDrawArrays(gl::Triangles, index, count);
- Stats::tris += count/3;
+ using namespace model;
+
+ Model *model = entity->model();
+ if (!model)
+ return;
+
+ // default material, lighted and geometry color
+ unsigned int material = Material::None;
+
+ bool use_color_array = true; // glEnableClientState(GL_COLOR_ARRAY) is set
+ bool use_light = true; // gl::disable(GL_LIGHTING) is set
+
+ for (Model::Fragments::iterator fit = model->fragments().begin(); fit != model->fragments().end(); fit++) {
+
+ Fragment *fragment = (*fit);
+
+ if (fragment->material() != material) {
+ material = fragment->material();
+
+ if (material & Material::Tertiary) {
+ if (use_color_array) {
+ use_color_array = false;
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+ // FIXME Primary, Secondary Tertiary color
+ math::Color color(entity->color());
+
+ if (material & Material::Dark)
+ color *= 0.5f;
+ gl::color(color);
+
+ } else {
+ if (!use_color_array) {
+ glEnableClientState(GL_COLOR_ARRAY);
+ use_color_array = true;
+ }
+ }
+
+ if (material & Material::Light) {
+ if (use_light) {
+ gl::disable(GL_LIGHTING);
+ use_light = false;
+ }
+ } else {
+ if (!use_light) {
+ gl::enable(GL_LIGHTING);
+ use_light = true;
+ }
+ }
+ }
+
+ draw_fragment(fragment, entity->state()->detailvisible());
+ }
+
+ if (!use_light) {
gl::enable(GL_LIGHTING);
}
-}
-void draw_model_evertex(core::Entity *entity)
-{
- size_t count = entity->model()->evertex_structural();
- if (entity->state()->detailvisible())
- count += entity->model()->evertex_detail();
-
- // draw model evertices
- if (count) {
- size_t index = entity->model()->first_evertex();
- render::gl::color(entity->color());
- glDrawArrays(gl::Triangles, index, count);
- Stats::tris += count/3;
+ if (!use_color_array) {
+ glEnableClientState(GL_COLOR_ARRAY);
}
}
@@ -298,6 +341,8 @@ void draw_model_evertex(core::Entity *entity)
/* calculate entity visibility */
void pass_prepare(float seconds)
{
+ using namespace model;
+
// reset light state
gl::disable(GL_LIGHT1);
@@ -317,7 +362,7 @@ void pass_prepare(float seconds)
// load entity models and light flare textures
if (!entity->model() && entity->modelname().size()) {
- entity->entity_model = model::Model::load(entity->modelname());
+ entity->entity_model = Model::load(entity->modelname());
if (!entity->model()) {
entity->entity_modelname.clear();
@@ -326,8 +371,8 @@ void pass_prepare(float seconds)
// set entity radius to model radius
entity->entity_radius = entity->entity_model->radius();
- for (std::list<model::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
- model::Light *light = (*lit);
+ for (Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) {
+ Light *light = (*lit);
// load light texture
// FIXME optimize
@@ -336,8 +381,8 @@ void pass_prepare(float seconds)
light->render_texture = Textures::load(flarename.str());
}
- for(std::list<model::Engine*>::iterator eit = entity->model()->model_engine.begin(); eit != entity->model()->model_engine.end(); eit++) {
- model::Engine *engine = (*eit);
+ for(Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) {
+ Engine *engine = (*eit);
if (!engine->flare()) engine->engine_flare = 1;
@@ -348,8 +393,8 @@ void pass_prepare(float seconds)
engine->render_texture = Textures::load(flarename.str());
}
- for (std::list<model::Flare *>::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) {
- model::Flare *flare = (*flit);
+ for (Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) {
+ Flare *flare = (*flit);
// load flare texture
// FIXME optimize
@@ -530,40 +575,19 @@ void draw_pass_default()
}
}
-/* Draw model vertices*/
-void draw_pass_model_vertex()
-{
- std::map<unsigned int, core::Entity *>::iterator it;
- for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
-
- core::Entity *entity = (*it).second;
- if (entity->model() && entity->state()->visible()) {
- gl::push();
- gl::translate(entity->state()->location());
- gl::multmatrix(entity->state()->axis());
-
- draw_model_vertex(entity);
- draw_model_lvertex(entity);
-
- gl::pop();
- }
- }
-}
-
-/* Draw entites with model evertices */
-void draw_pass_model_evertex()
+/* draw model geometry fragments */
+void draw_pass_model_fragments()
{
std::map<unsigned int, core::Entity *>::iterator it;
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
core::Entity *entity = (*it).second;
-
if (entity->model() && entity->state()->visible()) {
gl::push();
gl::translate(entity->state()->location());
gl::multmatrix(entity->state()->axis());
- draw_model_evertex(entity);
+ draw_model_fragments(entity);
gl::pop();
}
@@ -587,7 +611,7 @@ void draw_pass_model_fx()
if (entity->model() && entity->state()->detailvisible()) {
// draw model lights
- for (std::list<model::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) {
+ for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) {
// strobe frequency
t = 1.0f;
@@ -630,7 +654,7 @@ void draw_pass_model_fx()
}
// draw flares
- for (std::list<model::Flare *>::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) {
+ for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) {
model::Flare *flare = (*flit);
@@ -681,11 +705,11 @@ void draw_pass_model_fx()
}
// draw model engines for Controlable entities
- if (entity->type() == core::Entity::Controlable && entity->model()->model_engine.size()) {
+ if (entity->type() == core::Entity::Controlable && entity->model()->engines().size()) {
float u = static_cast<core::EntityControlable *>(entity)->thrust();
- for(std::list<model::Engine*>::iterator eit = entity->model()->model_engine.begin(); eit != entity->model()->model_engine.end(); eit++) {
+ for(model::Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) {
model::Engine *engine = (*eit);
@@ -857,17 +881,14 @@ void draw(float seconds)
glEnableClientState(GL_COLOR_ARRAY);
- draw_pass_model_vertex(); // draw entities with model
+ draw_pass_model_fragments();
glDisableClientState(GL_COLOR_ARRAY);
-
- draw_pass_model_evertex(); // draw entities with model, vertices with entity color
-
- gl::enable(GL_BLEND);
gl::disable(GL_LIGHTING);
-
+
+ gl::enable(GL_BLEND);
+
draw_pass_spacegrid(); // draw the blue spacegrid
-
Dust::draw(); // draw spacedust
draw_pass_model_fx(); // draw entity lights and engines