Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglLightProcessor.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglLightProcessor.hpp
00021  *   Author: Tom Stimson
00022  *  Created: 20 April 2002
00023  *  Summary: Classes to sort and apply lights during cull and draw
00024  *****************************************************************************/
00025 
00026 #ifndef __SGL_LIGHT_PROCESSOR_HPP
00027 #define __SGL_LIGHT_PROCESSOR_HPP
00028 
00029 #include <sgl.h>
00030 #include <sglObject.hpp>
00031 #include <sglMatrix.hpp>
00032 
00033 #include <map>
00034 
00035 class sglLight;
00036 
00044 class SGL_DLL_API sglLightProcessor : public sglObject
00045 {
00046 public:
00048    sglLightProcessor() {}
00049 
00051    virtual ~sglLightProcessor() {}
00052 
00054    virtual void reset() = 0;
00055 
00060    virtual void addLight(const sglMat4f& matrix, const sglLight* light) = 0;
00061 
00065    virtual unsigned int getNumLights() const = 0;
00066 
00070    virtual void apply() = 0;
00071 };
00072 
00073 
00081 class SGL_DLL_API sglDefaultLightProcessor : public sglLightProcessor
00082 {
00083 public:
00085    sglDefaultLightProcessor() {}
00086 
00088    virtual ~sglDefaultLightProcessor() {}
00089 
00090    // See sglLightProcessor::reset() for details.
00091    virtual void reset() { m_light_list.clear(); }
00092 
00093    // See sglLightProcessor::addLight() for details.
00094    virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00095 
00096    // See sglLightProcessor::getNumLights() for details.
00097    virtual unsigned int getNumLights() const { return m_light_list.size(); }
00098 
00099    // See sglLightProcessor::apply() for details.
00100    virtual void apply();
00101 
00102 private:
00103    typedef pair<sglMat4f, const sglLight*> LightStruct;
00104    vector<LightStruct>  m_light_list;
00105 };
00106 
00107 
00119 class SGL_DLL_API sglSortedLightProcessor : public sglLightProcessor
00120 {
00121 public:
00123    sglSortedLightProcessor() {}
00124 
00126    virtual ~sglSortedLightProcessor() {}
00127 
00128    // See sglLightProcessor::reset() for details.
00129    virtual void reset()
00130       {
00131          m_inf_lights.clear();
00132          m_positional_lights.clear();
00133       }
00134 
00135    // See sglLightProcessor::addLight() for details.
00136    virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00137 
00138    // See sglLightProcessor::getNumLights() for details.
00139    virtual unsigned int getNumLights() const
00140       { return m_inf_lights.size() + m_positional_lights.size(); }
00141 
00142    // See sglLightProcessor::apply() for details.
00143    virtual void apply();
00144 
00145 private:
00146    typedef pair<sglMat4f, const sglLight*> LightStruct;
00147    typedef multimap<float, LightStruct, greater<float> > MapType;
00148    MapType m_inf_lights;
00149    MapType m_positional_lights;
00150 };
00151 
00152 
00158 class SGL_DLL_API sglCountSortedLightProcessor : public sglLightProcessor
00159 {
00160 public:
00165    sglCountSortedLightProcessor(unsigned int num_bins = 10);
00166 
00168    virtual ~sglCountSortedLightProcessor();
00169 
00170    // See sglLightProcessor::reset() for details.
00171    virtual void reset()
00172       {
00173          m_inf_lights.clear();
00174          m_positional_lights.clear();
00175       }
00176 
00177    // See sglLightProcessor::addLight() for details.
00178    virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00179 
00180    // See sglLightProcessor::getNumLights() for details.
00181    virtual unsigned int getNumLights() const
00182       { return m_inf_lights.size() + m_positional_lights.size(); }
00183 
00184    // See sglLightProcessor::apply() for details.
00185    virtual void apply();
00186 
00187 private:
00188    typedef float (*ValFunc)(const sglMat4f&, const sglLight*);
00189 
00190    struct LightStruct
00191    {
00192       LightStruct(const sglMat4f &matrix, const sglLight* light)
00193          : m_matrix(matrix), m_light(light) {}
00194 
00195       sglMat4f         m_matrix;
00196       const sglLight  *m_light;
00197       float            m_val;
00198       unsigned int     m_bin;
00199    };
00200 
00201    void sortLights(
00202       vector<LightStruct> &lights,
00203       ValFunc val_func,
00204       GLenum first_light,
00205       GLint max_lights,
00206       float &last_min_val,
00207       float &last_max_val);
00208 
00209 private:
00210    vector<LightStruct>   m_inf_lights;
00211    vector<LightStruct>   m_positional_lights;
00212    unsigned int         *m_count;
00213    unsigned int          m_num_bins;
00214    float                 m_last_min_brightness;
00215    float                 m_last_max_brightness;
00216    float                 m_last_min_effect;
00217    float                 m_last_max_effect;
00218 };
00219 
00220 #endif

Generated at Mon Jul 1 18:00:05 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001