diff options
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r-- | src/render/draw.cc | 318 |
1 files changed, 178 insertions, 140 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index 4fc0b60..ed2c8f7 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -51,6 +51,9 @@ float zone_light[4]; // locaton of the zone light math::Color zone_color; // color of the zone light bool has_zone_light = false; +bool draw_particles = true; +bool draw_lights = true; + typedef std::map<float, core::EntityGlobe *> Globes; Globes globes_list; @@ -59,7 +62,18 @@ Globes globes_list; void pass_prepare(float seconds) { using namespace model; - + + // render settings for this pass_prepare + draw_lights = true; + if (r_lights && (r_lights->value() <= 0.0f)) { + draw_lights = false; + } + + draw_particles = true; + if (r_particles && (r_particles->value() <= 0.0f)) { + draw_particles = false; + } + // lighting settings for the default light GL_LIGHT0 GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat ambient_light[] = { r_ambient->value(), r_ambient->value(), r_ambient->value(), 1.0f }; @@ -506,7 +520,7 @@ void draw_pass_default() /* ---- Model Fragments -------------------------------------------- */ -void draw_fragment(model::Fragment *fragment, bool draw_details) +void draw_fragment(const model::Fragment *fragment, bool draw_details) { size_t index = fragment->index(); @@ -564,9 +578,9 @@ void draw_model_fragments(model::Model *model, gl::texgeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); gl::texgeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - for (model::Model::Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) { + for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { - model::FragmentGroup *group = (*git); + const model::FragmentGroup *group = (*git); if (group->transform()) { gl::push(); @@ -585,9 +599,9 @@ void draw_model_fragments(model::Model *model, gl::scale(s, s, s); } - for (model::FragmentGroup::iterator fit = group->begin(); fit != group->end(); fit++) { + for (model::FragmentGroup::Fragments::const_iterator fit = group->fragments().begin(); fit != group->fragments().end(); fit++) { - model::Fragment *fragment = (*fit); + const model::Fragment *fragment = (*fit); if (fragment->material() != material) { material = fragment->material(); @@ -930,175 +944,178 @@ void draw_pass_model_fx(float elapsed) // default light texture size_t current_texture = Textures::bind("textures/fx/flare00"); gl::enable(GL_TEXTURE_2D); + + if (draw_lights) { - gl::begin(gl::Quads); + gl::begin(gl::Quads); - // draw model lights - for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { - model::Light *light = (*lit); + // draw model lights + for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { + model::Light *light = (*lit); - // engine activated lights - if (light->engine()) { - if (entity->type() == core::Entity::Controlable) { - core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity); - if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { - thrust = 1.0f; - } else { - thrust = ec->thrust(); - if (thrust < 0.001f) { - continue; // next light + // engine activated lights + if (light->engine()) { + if (entity->type() == core::Entity::Controlable) { + core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity); + if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { + thrust = 1.0f; + } else { + thrust = ec->thrust(); + if (thrust < 0.001f) { + continue; // next light + } } + } else { + continue; // next light } - } else { - continue; // next light } - } - // strobe frequency - if (light->strobe()) { - t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * light->frequency(); - if ((t - floorf(t)) > light->time()) { - continue; // next light + // strobe frequency + if (light->strobe()) { + t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * light->frequency(); + if ((t - floorf(t)) > light->time()) { + continue; // next light + } } - } - // default alpha is 0.8 - a = 0.8f; - if (light->entity()) { - color.assign(entity->color()); - } else if (light->engine()) { - color.assign(entity->model()->enginecolor()); - a *= thrust; - } else { - color.assign(light->color()); - } - color.a = a; + // default alpha is 0.8 + a = 0.8f; + if (light->entity()) { + color.assign(entity->color()); + } else if (light->engine()) { + color.assign(entity->model()->enginecolor()); + a *= thrust; + } else { + color.assign(light->color()); + } + color.a = a; - location.assign(entity->location() + (entity->axis() * light->location())); - light_size = 0.0625f * light->radius(); + location.assign(entity->location() + (entity->axis() * light->location())); + light_size = 0.0625f * light->radius(); - // track OpenGL state changes - if (current_texture != light->texture()) { - gl::end(); - current_texture = Textures::bind(light->texture()); - gl::begin(gl::Quads); - } + // track OpenGL state changes + if (current_texture != light->texture()) { + gl::end(); + current_texture = Textures::bind(light->texture()); + gl::begin(gl::Quads); + } - // draw the quad - gl::color(color); + // draw the quad + gl::color(color); - glTexCoord2f(0, 1); - gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * light_size); - glTexCoord2f(0, 0); - gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * light_size); - glTexCoord2f(1, 0); - gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); - glTexCoord2f(1, 1); - gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); - Stats::quads++; + glTexCoord2f(0, 1); + gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * light_size); + glTexCoord2f(0, 0); + gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * light_size); + glTexCoord2f(1, 0); + gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); + glTexCoord2f(1, 1); + gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); + Stats::quads++; - } + } - // draw flares - for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { - model::Flare *flare = (*flit); + // draw flares + for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { + model::Flare *flare = (*flit); - // engine activated flares - if (flare->engine()) { - if (entity->type() == core::Entity::Controlable) { - core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity); - if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { - thrust = 1.0f; - } else { - thrust = ec->thrust(); - if (thrust < 0.001f) { - continue; // next flare + // engine activated flares + if (flare->engine()) { + if (entity->type() == core::Entity::Controlable) { + core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity); + if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { + thrust = 1.0f; + } else { + thrust = ec->thrust(); + if (thrust < 0.001f) { + continue; // next flare + } } + } else { + continue; // next flare } - } else { - continue; // next flare } - } - // strobe frequency - if (flare->strobe()) { - t = (core::application()->time() + ext_render(entity)->fuzz() - flare->offset()) * flare->frequency(); - if ((t - floorf(t)) > flare->time()) { - continue; // next flare + // strobe frequency + if (flare->strobe()) { + t = (core::application()->time() + ext_render(entity)->fuzz() - flare->offset()) * flare->frequency(); + if ((t - floorf(t)) > flare->time()) { + continue; // next flare + } } - } - - // calulcate viewing angle factor - flare_axis.assign(entity->axis() * flare->axis()); - a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward())); - if (a < 0.01f) { - continue; // next flare - } - // alpha decreases with viewing angle - a *= 0.8f; - if (flare->entity()) { - color.assign(entity->color()); - } else if (flare->engine()) { - color.assign(entity->model()->enginecolor()); - a *= thrust; - } else { - color.assign(flare->color()); - } - color.a = a; + // calulcate viewing angle factor + flare_axis.assign(entity->axis() * flare->axis()); + a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward())); + if (a < 0.01f) { + continue; // next flare + } - location.assign(entity->location() + (entity->axis() * flare->location())); - light_size = 0.0625f * flare->radius(); + // alpha decreases with viewing angle + a *= 0.8f; + if (flare->entity()) { + color.assign(entity->color()); + } else if (flare->engine()) { + color.assign(entity->model()->enginecolor()); + a *= thrust; + } else { + color.assign(flare->color()); + } + color.a = a; - // track OpenGL state changes - if ((current_cull != flare->cull()) || (current_texture != flare->texture())) { - gl::end(); + location.assign(entity->location() + (entity->axis() * flare->location())); + light_size = 0.0625f * flare->radius(); - if (current_texture != flare->texture()) { - current_texture = Textures::bind(flare->texture()); - } + // track OpenGL state changes + if ((current_cull != flare->cull()) || (current_texture != flare->texture())) { + gl::end(); - if (current_cull != flare->cull()) { - if (flare->cull() == model::CullNone) { - gl::disable(GL_CULL_FACE); - current_cull = model::CullNone; - } else { - if (current_cull == model::CullNone) { - gl::enable(GL_CULL_FACE); - } + if (current_texture != flare->texture()) { + current_texture = Textures::bind(flare->texture()); + } - if (flare->cull() == model::CullBack) { - gl::cullface(GL_BACK); - current_cull = model::CullBack; + if (current_cull != flare->cull()) { + if (flare->cull() == model::CullNone) { + gl::disable(GL_CULL_FACE); + current_cull = model::CullNone; } else { - gl::cullface(GL_FRONT); - current_cull = model::CullFront; + if (current_cull == model::CullNone) { + gl::enable(GL_CULL_FACE); + } + + if (flare->cull() == model::CullBack) { + gl::cullface(GL_BACK); + current_cull = model::CullBack; + } else { + gl::cullface(GL_FRONT); + current_cull = model::CullFront; + } } } + + gl::begin(gl::Quads); } - gl::begin(gl::Quads); - } + // draw the quad + gl::color(color); - // draw the quad - gl::color(color); + glTexCoord2f(0, 1); + gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); + glTexCoord2f(0, 0); + gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); + glTexCoord2f(1, 0); + gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); + glTexCoord2f(1, 1); + gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); - glTexCoord2f(0, 1); - gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); - glTexCoord2f(0, 0); - gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); - glTexCoord2f(1, 0); - gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); - glTexCoord2f(1, 1); - gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); + Stats::quads++; + } - Stats::quads++; + gl::end(); } - gl::end(); - // draw particle systems - if (r_particles->value() && ext_render(entity)->particles().size()) { + if (draw_particles && ext_render(entity)->particles().size()) { for (RenderExt::ParticleSystems::iterator it = ext_render(entity)->particles().begin(); it != ext_render(entity)->particles().end(); it++) { ParticleSystem *particlesystem = (*it); @@ -1216,9 +1233,29 @@ void draw(float seconds) if (r_wireframe && r_wireframe->value()) { glPolygonMode(GL_FRONT, GL_LINE); } - + + // check if the vertexarray needs re-uploading // set vertex array pointers - glInterleavedArrays(GL_T2F_N3F_V3F, 0, core::game()->vertexarray()->ptr()); + if (State::has_vbo()) { + gl::bindbuffer(GL_ARRAY_BUFFER, State::vbo()); + + if (core::game()->vertexarray()->dirty()) { + gl::bufferdata(GL_ARRAY_BUFFER, sizeof(float) * core::game()->vertexarray()->index(), core::game()->vertexarray()->ptr(), GL_STATIC_DRAW); + core::game()->vertexarray()->set_dirty(false); + + } + // Interleaved format is GL_T2F_N3F_V3F + + // void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) + glTexCoordPointer(2, GL_FLOAT, 8 * sizeof(GLfloat), 0); + // void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr) + glNormalPointer(GL_FLOAT, 8 * sizeof(GLfloat), (void*) (2 * sizeof(GLfloat))); + // void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) + glVertexPointer(3, GL_FLOAT, 8 * sizeof(GLfloat), (void*) (5 * sizeof(GLfloat))); + + } else { + glInterleavedArrays(GL_T2F_N3F_V3F, 0, core::game()->vertexarray()->ptr()); + } // enable vertex arrays glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -1261,7 +1298,8 @@ void draw(float seconds) } // draw entity lights, flares and particles - draw_pass_model_fx(seconds); + if (draw_lights || draw_particles) + draw_pass_model_fx(seconds); // draw entity radius globe if (r_radius && r_radius->value()) { |