00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SGE_RENDERER_STATES_HPP_INCLUDED
00022 #define SGE_RENDERER_STATES_HPP_INCLUDED
00023
00024 #include "../export.hpp"
00025 #include "color.hpp"
00026 #include <boost/variant.hpp>
00027 #include <set>
00028
00029 namespace sge
00030 {
00031 namespace renderer
00032 {
00033
00034 template<typename T>
00035 struct state_var_traits;
00036
00037 template<> struct state_var_traits<int> { enum available_states {
00038 stencil_clear_val
00039 }; };
00040
00041 template<> struct state_var_traits<float> { enum available_states {
00042 zbuffer_clear_val,
00043 fog_start,
00044 fog_end,
00045 fog_density
00046 }; };
00047
00048 template<> struct state_var_traits<bool> { enum available_states {
00049 clear_zbuffer,
00050 clear_backbuffer,
00051 clear_stencil,
00052 enable_alpha_blending,
00053 enable_lighting
00054 }; };
00055
00056 template<> struct state_var_traits<color> { enum available_states {
00057 clear_color,
00058 ambient_light_color,
00059 fog_color
00060 }; };
00061
00062 namespace state_cull_mode_type {
00063 enum type {
00064 off,
00065 back,
00066 front
00067 };
00068 }
00069
00070 template<>
00071 struct state_var_traits<state_cull_mode_type::type> {
00072 enum available_states {
00073 singular
00074 };
00075 };
00076
00077 namespace state_depth_func_type
00078 {
00079 enum type {
00080 off,
00081 never,
00082 less,
00083 equal,
00084 less_equal,
00085 greater,
00086 not_equal,
00087 greater_equal,
00088 always
00089 };
00090 }
00091
00092 template<>
00093 struct state_var_traits<state_depth_func_type::type> {
00094 enum available_states {
00095 singular
00096 };
00097 };
00098
00099 namespace state_stencil_func_type
00100 {
00101 enum type {
00102 off,
00103 never,
00104 less,
00105 equal,
00106 less_equal,
00107 greater,
00108 not_equal,
00109 greater_equal,
00110 always
00111 };
00112 }
00113
00114 template<>
00115 struct state_var_traits<state_stencil_func_type::type> {
00116 enum available_states {
00117 singular
00118 };
00119 };
00120
00121 namespace state_fog_mode_type {
00122 enum type {
00123 off,
00124 linear,
00125 exp,
00126 exp2
00127 };
00128 }
00129
00130 template<>
00131 struct state_var_traits<state_fog_mode_type::type> {
00132 enum available_states {
00133 singular
00134 };
00135 };
00136
00137 namespace state_draw_mode_type
00138 {
00139 enum type {
00140 point,
00141 line,
00142 fill
00143 };
00144 }
00145
00146 template<>
00147 struct state_var_traits<state_draw_mode_type::type> {
00148 enum available_states {
00149 singular
00150 };
00151 };
00152
00153 namespace state_source_blend_func_type
00154 {
00155 enum type {
00156 zero,
00157 one,
00158 dest_color,
00159 inv_dest_color,
00160 src_alpha,
00161 inv_src_alpha,
00162 dest_alpha,
00163 inv_dest_alpha,
00164 src_alpha_sat
00165 };
00166 }
00167
00168 template<>
00169 struct state_var_traits<state_source_blend_func_type::type> {
00170 enum available_states {
00171 singular
00172 };
00173 };
00174
00175 namespace state_dest_blend_func_type
00176 {
00177 enum type {
00178 zero,
00179 one,
00180 src_color,
00181 inv_src_color,
00182 src_alpha,
00183 inv_src_alpha,
00184 dest_alpha,
00185 inv_dest_alpha
00186 };
00187 }
00188
00189 template<>
00190 struct state_var_traits<state_dest_blend_func_type::type> {
00191 enum available_states {
00192 singular
00193 };
00194 };
00195
00196 template<typename T>
00197 struct state_var {
00198 typedef T value_type;
00199
00200 SGE_SYMBOL state_var<T> operator=(T newval);
00201
00202 SGE_SYMBOL T value() const;
00203
00204 const typename state_var_traits<T>::available_states state_id;
00205
00206 SGE_SYMBOL explicit state_var(
00207 const typename state_var_traits<T>::available_states state_id,
00208 const T defval = T());
00209
00210 SGE_SYMBOL bool operator<(state_var const&) const;
00211 private:
00212 T val;
00213 };
00214
00215 namespace int_state {
00216 typedef state_var<int> type;
00217 SGE_SYMBOL extern type
00218 stencil_clear_val;
00219 }
00220
00221 namespace float_state {
00222 typedef state_var<float> type;
00223 SGE_SYMBOL extern type
00224 zbuffer_clear_val,
00225 fog_start,
00226 fog_end,
00227 fog_density;
00228 }
00229
00230 namespace bool_state {
00231 typedef state_var<bool> type;
00232 SGE_SYMBOL extern type
00233 clear_zbuffer,
00234 clear_backbuffer,
00235 clear_stencil,
00236 enable_alpha_blending,
00237 enable_lighting;
00238 }
00239
00240 namespace color_state {
00241 typedef state_var<color> type;
00242 SGE_SYMBOL extern type
00243 clear_color,
00244 ambient_light_color,
00245 fog_color;
00246 }
00247
00248 namespace cull_mode {
00249 typedef state_var<state_cull_mode_type::type> type;
00250 SGE_SYMBOL extern const type
00251 off,
00252 back,
00253 front;
00254 }
00255
00256 namespace depth_func {
00257 typedef state_var<state_depth_func_type::type> type;
00258 SGE_SYMBOL extern const type
00259 off,
00260 never,
00261 less,
00262 equal,
00263 less_equal,
00264 greater,
00265 not_equal,
00266 greater_equal,
00267 always;
00268 }
00269
00270 namespace stencil_func {
00271 typedef state_var<state_stencil_func_type::type> type;
00272 SGE_SYMBOL extern const type
00273 off,
00274 never,
00275 less,
00276 equal,
00277 less_equal,
00278 greater,
00279 not_equal,
00280 greater_equal,
00281 always;
00282 }
00283
00284 namespace fog_mode {
00285 typedef state_var<state_fog_mode_type::type> type;
00286 SGE_SYMBOL extern const type
00287 off,
00288 linear,
00289 exp,
00290 exp2;
00291 }
00292
00293 namespace draw_mode {
00294 typedef state_var<state_draw_mode_type::type> type;
00295 SGE_SYMBOL extern const type
00296 point,
00297 line,
00298 fill;
00299 }
00300
00301 namespace source_blend_func {
00302 typedef state_var<state_source_blend_func_type::type> type;
00303 SGE_SYMBOL extern const type
00304 zero,
00305 one,
00306 dest_color,
00307 inv_dest_color,
00308 src_alpha,
00309 inv_src_alpha,
00310 dest_alpha,
00311 inv_dest_alpha,
00312 src_alpha_sat;
00313 }
00314
00315 namespace dest_blend_func {
00316 typedef state_var<state_dest_blend_func_type::type> type;
00317 SGE_SYMBOL extern const type
00318 zero,
00319 one,
00320 src_color,
00321 inv_src_color,
00322 src_alpha,
00323 inv_src_alpha,
00324 dest_alpha,
00325 inv_dest_alpha;
00326 }
00327
00328 typedef boost::variant<
00329 int_state::type,
00330 float_state::type,
00331 bool_state::type,
00332 color_state::type,
00333 cull_mode::type,
00334 depth_func::type,
00335 stencil_func::type,
00336 fog_mode::type,
00337 draw_mode::type,
00338 source_blend_func::type,
00339 dest_blend_func::type
00340 > any_state;
00341
00342
00343 class state_list {
00344 public:
00345 SGE_SYMBOL state_list();
00346 SGE_SYMBOL explicit state_list(
00347 any_state const &);
00348 SGE_SYMBOL const state_list operator()(
00349 any_state const&) const;
00350
00351 SGE_SYMBOL void overwrite(
00352 any_state const&);
00353
00354 typedef std::set<any_state> set_type;
00355 SGE_SYMBOL set_type const& get() const;
00356 private:
00357 set_type set_;
00358 };
00359
00360 }
00361 }
00362
00363 #endif // SGE_RENDERER_STATES_HPP_INCLUDED