Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-01-13 19:29:54 +0000
committerStijn Buys <ingar@osirion.org>2009-01-13 19:29:54 +0000
commit5992c46fc62db1bdf038b5b7be0e94dd10183e77 (patch)
tree91b513b038a4e8c2590d02bc7aeea382f998bb43 /src
parent9caf289046ed2639f1935fb1c87133af4f7f6cac (diff)
adds 'cull' option to fx_flare and fx_particles
Diffstat (limited to 'src')
-rw-r--r--src/model/classes.cc2
-rw-r--r--src/model/classes.h24
-rw-r--r--src/model/map.cc30
-rw-r--r--src/render/draw.cc66
-rw-r--r--src/render/particles.cc2
-rw-r--r--src/render/particles.h5
6 files changed, 120 insertions, 9 deletions
diff --git a/src/model/classes.cc b/src/model/classes.cc
index 07a36f3..f90b979 100644
--- a/src/model/classes.cc
+++ b/src/model/classes.cc
@@ -42,6 +42,7 @@ Light::~Light()
Flare::Flare() : Light()
{
flare_engine = false;
+ flare_cull = CullNone;
}
Flare::~Flare()
@@ -55,6 +56,7 @@ Particles::Particles() :
particles_entity = false;
particles_engine = false;
particles_radius = 0.0f;
+ particles_cull = CullNone;
}
Particles::Particles(math::Vector3f const & location) :
diff --git a/src/model/classes.h b/src/model/classes.h
index c6bf3b1..c2b6a20 100644
--- a/src/model/classes.h
+++ b/src/model/classes.h
@@ -14,6 +14,15 @@
namespace model
{
+
+/**
+ * @brief
+ * culling parameter values
+ * Culling is a paremeter used by flares and particles to indicate
+ * with side of the polygons should be culled during rendering
+ */
+enum Cull { CullNone=0, CullBack=1, CullFront=2 };
+
/* ---- class MapClass --------------------------------------------- */
class MapClass
@@ -134,13 +143,19 @@ public:
return flare_axis;
}
- inline bool engine() const
+ inline const bool engine() const
{
return flare_engine;
}
+ inline const Cull cull() const
+ {
+ return flare_cull;
+ }
+
math::Axis flare_axis;
bool flare_engine;
+ Cull flare_cull;
};
/* ---- class Particles -------------------------------------------- */
@@ -185,6 +200,12 @@ public:
{
return particles_radius;
}
+
+ inline const Cull cull() const
+ {
+ return particles_cull;
+ }
+
std::string particles_script;
math::Vector3f particles_location;
math::Axis particles_axis;
@@ -193,6 +214,7 @@ public:
bool particles_engine;
float particles_radius;
+ Cull particles_cull;
};
/* ---- class Dock ------------------------------------------------- */
diff --git a/src/model/map.cc b/src/model/map.cc
index a59d2ff..9a1802f 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -4,6 +4,7 @@
the terms of the GNU General Public License version 2
*/
+#include "auxiliary/functions.h"
#include "filesystem/filesystem.h"
#include "math/mathlib.h"
#include "model/map.h"
@@ -837,6 +838,7 @@ Model * Map::load(std::string const &name)
unsigned int u;
float angle;
float r;
+ std::string str;
while (mapfile.getline()) {
@@ -1027,7 +1029,7 @@ Model * Map::load(std::string const &name)
} else if (mapfile.got_key_float("radius", flare->light_radius)) {
flare->light_radius *= LIGHTSCALE;
-
+
} else if (mapfile.got_key_float("frequency", flare->light_frequency)) {
continue;
@@ -1056,6 +1058,19 @@ Model * Map::load(std::string const &name)
} else if (mapfile.got_key_float("roll", angle)) {
flare->flare_axis.change_roll(angle);
+
+ } else if (mapfile.got_key_string("cull", str)) {
+
+ aux::to_lowercase(str);
+ if (str.compare("none") == 0) {
+ flare->flare_cull = CullNone;
+ } else if (str.compare("back") == 0) {
+ flare->flare_cull = CullBack;
+ } else if (str.compare("front") == 0) {
+ flare->flare_cull = CullFront;
+ } else {
+ mapfile.unknown_value();
+ }
} else if (mapfile.got_key()) {
mapfile.unknown_key();
@@ -1098,6 +1113,19 @@ Model * Map::load(std::string const &name)
} else if (mapfile.got_key_float("radius", r)) {
particles->set_radius(r * LIGHTSCALE);
+
+ } else if (mapfile.got_key_string("cull", str)) {
+
+ aux::to_lowercase(str);
+ if (str.compare("none") == 0) {
+ particles->particles_cull = CullNone;
+ } else if (str.compare("back") == 0) {
+ particles->particles_cull = CullBack;
+ } else if (str.compare("front") == 0) {
+ particles->particles_cull = CullFront;
+ } else {
+ mapfile.unknown_value();
+ }
} else if (mapfile.got_key()) {
mapfile.unknown_key();
diff --git a/src/render/draw.cc b/src/render/draw.cc
index fbf5058..3806672 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -744,9 +744,14 @@ void draw_pass_model_fx(float elapsed)
math::Axis flare_axis;
- size_t current_texture = Textures::bind("textures/fx/flare00");
+ // disable culling by default
+ gl::disable(GL_CULL_FACE);
+ model::Cull current_cull = model::CullNone;
+ // default light texture
+ size_t current_texture = Textures::bind("textures/fx/flare00");
gl::enable(GL_TEXTURE_2D);
+
gl::begin(gl::Quads);
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
@@ -775,6 +780,7 @@ void draw_pass_model_fx(float elapsed)
location.assign(entity->location() + (entity->axis() * light->location()));
light_size = 0.0625 * light->radius();
+ // track stat changes
if (current_texture != light->texture()) {
gl::end();
current_texture = Textures::bind(light->texture());
@@ -826,9 +832,32 @@ void draw_pass_model_fx(float elapsed)
location.assign(entity->location() + (entity->axis() * flare->location()));
light_size = 0.0625 * flare->radius();
- if (current_texture != flare->texture()) {
+ if ((current_cull != flare->cull()) || (current_texture != flare->texture())) {
gl::end();
- current_texture = Textures::bind(flare->texture());
+
+ if (current_texture != flare->texture()) {
+ current_texture = Textures::bind(flare->texture());
+ }
+
+ 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 (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);
}
@@ -870,23 +899,48 @@ void draw_pass_model_fx(float elapsed)
// draw particle systems
if (r_particles->value() && ext_render(entity)->particles().size()) {
gl::end();
- gl::disable(GL_CULL_FACE);
-
+
for (RenderExt::ParticleSystems::iterator it = ext_render(entity)->particles().begin(); it != ext_render(entity)->particles().end(); it++) {
ParticleSystem *particlesystem = (*it);
+
+ if (current_cull != particlesystem->cull()) {
+ if (particlesystem->cull() == model::CullNone) {
+ gl::disable(GL_CULL_FACE);
+ current_cull = model::CullNone;
+ } else {
+ if (current_cull == model::CullNone) {
+ gl::enable(GL_CULL_FACE);
+ }
+
+ if (particlesystem->cull() == model::CullBack) {
+ gl::cullface(GL_BACK);
+ current_cull = model::CullBack;
+ } else {
+ gl::cullface(GL_FRONT);
+ current_cull = model::CullFront;
+ }
+ }
+ }
+
particlesystem->draw(elapsed);
}
- gl::enable(GL_CULL_FACE);
current_texture = Textures::bind("textures/fx/flare00");
gl::begin(gl::Quads);
}
+
+ if (current_cull != model::CullNone) {
+ gl::disable(GL_CULL_FACE);
+ current_cull = model::CullNone;
+ }
}
}
gl::end();
gl::disable(GL_TEXTURE_2D);
+ gl::cullface(GL_BACK);
+ gl::enable(GL_CULL_FACE);
}
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 07a8dc1..ef6886a 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -183,6 +183,7 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, mod
particlesystem_script = script;
particlesystem_texture = 0;
+ particlesystem_cull = model::CullNone;
particlesystem_modelclass = modelclass;
@@ -207,6 +208,7 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, mod
color.assign(entity->model()->enginecolor());
}
particlesystem_axis.assign(modelclass->axis());
+// particlesystem_cull = particlesystem_modelclass->cull();
}
}
diff --git a/src/render/particles.h b/src/render/particles.h
index 096833c..a36b142 100644
--- a/src/render/particles.h
+++ b/src/render/particles.h
@@ -111,7 +111,9 @@ public:
/// axis of the particle system within the entity
inline const math::Axis &axis() const { return particlesystem_axis; }
-
+
+ inline const model::Cull cull() const { return particlesystem_cull; }
+
virtual void draw(float elapsed);
void set_timeout(float timeout);
@@ -146,6 +148,7 @@ protected:
math::Color color;
model::Particles *particlesystem_modelclass;
+ model::Cull particlesystem_cull;
};
/* ---- class Flame ------------------------------------------------ */