00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00091 virtual void reset() { m_light_list.clear(); }
00092
00093
00094 virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00095
00096
00097 virtual unsigned int getNumLights() const { return m_light_list.size(); }
00098
00099
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
00129 virtual void reset()
00130 {
00131 m_inf_lights.clear();
00132 m_positional_lights.clear();
00133 }
00134
00135
00136 virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00137
00138
00139 virtual unsigned int getNumLights() const
00140 { return m_inf_lights.size() + m_positional_lights.size(); }
00141
00142
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
00171 virtual void reset()
00172 {
00173 m_inf_lights.clear();
00174 m_positional_lights.clear();
00175 }
00176
00177
00178 virtual void addLight(const sglMat4f& matrix, const sglLight* light);
00179
00180
00181 virtual unsigned int getNumLights() const
00182 { return m_inf_lights.size() + m_positional_lights.size(); }
00183
00184
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