Mercurial > fife-parpg
diff engine/core/view/renderers/instancerenderer.cpp @ 661:e3140f01749d
* Merged the light branch back into trunk.
* Modified the demos so they work with the new loaders and setting.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 05 Nov 2010 15:21:10 +0000 |
parents | 378b588216d6 |
children | 61a5f86a0db3 |
line wrap: on
line diff
--- a/engine/core/view/renderers/instancerenderer.cpp Wed Nov 03 13:44:12 2010 +0000 +++ b/engine/core/view/renderers/instancerenderer.cpp Fri Nov 05 15:21:10 2010 +0000 @@ -40,11 +40,13 @@ #include "model/structures/instance.h" #include "model/structures/layer.h" #include "model/structures/location.h" +#include "video/opengl/fife_opengl.h" #include "view/camera.h" #include "view/visual.h" #include "instancerenderer.h" + namespace { unsigned int scale(unsigned int val, double factor) { return static_cast<unsigned int>(ceil(static_cast<double>(val) * factor)); @@ -129,6 +131,8 @@ } const bool any_effects = !(m_instance_outlines.empty() && m_instance_colorings.empty()); + const bool unlit = !m_unlit_groups.empty(); + unsigned int lm = m_renderbackend->getLightingModel(); m_area_layer = false; if(!m_instance_areas.empty()) { @@ -185,17 +189,56 @@ if (any_effects) { InstanceToOutlines_t::iterator outline_it = m_instance_outlines.find(instance); if (outline_it != m_instance_outlines.end()) { + if (lm != 0) { + m_renderbackend->disableLighting(); + m_renderbackend->setStencilTest(255, 2, 7); + m_renderbackend->setAlphaTest(0.0); + bindOutline(outline_it->second, vc, cam)->render(vc.dimensions, vc.transparency); + m_renderbackend->enableLighting(); + m_renderbackend->setStencilTest(0, 2, 7); + vc.image->render(vc.dimensions, vc.transparency); + m_renderbackend->disableAlphaTest(); + m_renderbackend->disableStencilTest(); + continue; + } bindOutline(outline_it->second, vc, cam)->render(vc.dimensions, vc.transparency); } InstanceToColoring_t::iterator coloring_it = m_instance_colorings.find(instance); if (coloring_it != m_instance_colorings.end()) { + m_renderbackend->disableLighting(); bindColoring(coloring_it->second, vc, cam)->render(vc.dimensions, vc.transparency); + m_renderbackend->enableLighting(); continue; // Skip normal rendering after drawing overlay } } + if(lm != 0) { + if(unlit) { + bool found = false; + std::string lit_name = instance->getObject()->getNamespace(); + std::list<std::string>::iterator unlit_it = m_unlit_groups.begin(); + for(;unlit_it != m_unlit_groups.end(); ++unlit_it) { + if(lit_name.find(*unlit_it) != -1) { + m_renderbackend->setStencilTest(255, 2, 7); + found = true; + break; + } + } + // This is very expensiv, we have to change it + if(!found) + m_renderbackend->setStencilTest(0, 1, 7); + m_renderbackend->setAlphaTest(0.0); + vc.image->render(vc.dimensions, vc.transparency); + continue; + } + } vc.image->render(vc.dimensions, vc.transparency); + + } + if(lm != 0) { + m_renderbackend->disableAlphaTest(); + m_renderbackend->disableStencilTest(); } } @@ -422,10 +465,37 @@ m_instance_areas.clear(); } + void InstanceRenderer::addIgnoreLight(const std::list<std::string> &groups) { + std::list<std::string>::const_iterator group_it = groups.begin(); + for(;group_it != groups.end(); ++group_it) { + m_unlit_groups.push_back(*group_it); + } + m_unlit_groups.sort(); + m_unlit_groups.unique(); + } + + void InstanceRenderer::removeIgnoreLight(const std::list<std::string> &groups) { + std::list<std::string>::const_iterator group_it = groups.begin(); + for(;group_it != groups.end(); ++group_it) { + std::list<std::string>::iterator unlit_it = m_unlit_groups.begin(); + for(;unlit_it != m_unlit_groups.end(); ++unlit_it) { + if((*group_it).find(*unlit_it) != -1) { + m_unlit_groups.remove(*unlit_it); + break; + } + } + } + } + + void InstanceRenderer::removeAllIgnoreLight() { + m_unlit_groups.clear(); + } + void InstanceRenderer::reset() { removeAllOutlines(); removeAllColored(); removeAllTransparentAreas(); + removeAllIgnoreLight(); } }