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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef ACG_GLSTATE_HH
00052 #define ACG_GLSTATE_HH
00053
00054
00055
00056
00057
00058 #include "gl.hh"
00059 #include "../Math/GLMatrixT.hh"
00060 #include "../Math/VectorT.hh"
00061 #include "../Config/ACGDefines.hh"
00062 #include "ColorStack.hh"
00063 #include <stack>
00064 #include <vector>
00065
00066 #ifdef WIN32
00067 #pragma warning(push)
00068 #pragma warning(disable:4251)
00069 #endif
00070
00071
00072
00073
00074 namespace ACG {
00075
00076
00077
00078
00079
00090 class ACGDLLEXPORT GLState
00091 {
00092 public:
00093
00095 GLState(bool _updateGL = true);
00096
00098 ~GLState() {}
00099
00100
00101 void makeCurrent() { }
00102
00104 void initialize();
00105
00107 bool updateGL() const { return updateGL_; }
00109 void set_updateGL(bool _b) { updateGL_ = _b; }
00110
00112 unsigned int msSinceLastRedraw () const { return msSinceLastRedraw_; }
00113
00115 void set_msSinceLastRedraw (unsigned int _ms) { msSinceLastRedraw_ = _ms; }
00116
00118 void setState ();
00119
00121 void clearBuffers ();
00122
00123
00124
00125
00127 void reset_projection();
00128
00130 void set_projection(const GLMatrixd& _m) {
00131 GLMatrixd inv_m(_m); inv_m.invert(); set_projection(_m, inv_m);
00132 }
00134 void set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m);
00135
00137 void ortho( double _left, double _right,
00138 double _bottom, double _top,
00139 double _near_plane, double _far_plane );
00140
00142 void frustum( double _left, double _right,
00143 double _bottom, double _top,
00144 double _near_plane, double _far_plane );
00145
00147 void perspective( double _fovY, double _aspect,
00148 double _near_plane, double _far_plane );
00149
00151 void viewport( int _left, int _bottom, int _width, int _height,
00152 int _glwidth = 0, int _glheight = 0);
00153
00154
00155
00156
00157
00158
00159
00160
00162 void reset_modelview();
00163
00165 void set_modelview(const GLMatrixd& _m) {
00166 GLMatrixd inv_m(_m); inv_m.invert(); set_modelview(_m, inv_m);
00167 }
00169 void set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m);
00170
00172 void lookAt( const Vec3d& _eye, const Vec3d& _center, const Vec3d& _up );
00173
00175 void translate( double _x, double _y, double _z,
00176 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00177
00179 void rotate( double _angle, double _x, double _y, double _z,
00180 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00181
00183 void scale( double _s )
00184 { scale(_s, _s, _s); }
00185
00187 void scale( double _s,
00188 MultiplyFrom )
00189 { scale(_s, _s, _s); }
00190
00192 void scale( double _sx, double _sy, double _sz,
00193 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00194
00196 void mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
00197 MultiplyFrom _mult_from = MULT_FROM_RIGHT );
00198
00199
00201 void push_projection_matrix();
00203 void pop_projection_matrix();
00204
00206 void push_modelview_matrix();
00208 void pop_modelview_matrix();
00209
00210
00211
00212
00213
00215 const GLMatrixd& projection() const {
00216 return projection_;
00217 }
00218
00220 const GLMatrixd& modelview() const {
00221 return modelview_;
00222 }
00223
00225 const GLMatrixd& viewport() const {
00226 return window2viewport_;
00227 }
00228
00230 const GLMatrixd& forward_projection() const {
00231 return forward_projection_;
00232 }
00233
00235 const GLMatrixd& inverse_projection() const {
00236 return inverse_projection_;
00237 }
00238
00240 const GLMatrixd& inverse_modelview() const {
00241 return inverse_modelview_;
00242 }
00243
00245 void get_viewport( int& _left, int& _bottom,
00246 int& _width, int& _height ) const {
00247 _left = left_; _bottom = bottom_; _width = width_; _height = height_;
00248 }
00249
00251 int viewport_width() const { return width_; }
00253 int viewport_height() const { return height_; }
00254
00256 int context_width() const { return glwidth_; }
00257
00259 int context_height() const { return glheight_; }
00260
00262 double near_plane() const { return near_plane_; }
00263
00265 double far_plane() const { return far_plane_; }
00266
00268 double fovy() const;
00269
00271 double aspect() const;
00272
00274 Vec3d eye() const;
00275
00277 Vec3d viewing_direction() const {
00278 return viewing_direction(width_>>1, height_>>1);
00279 }
00280
00282 Vec3d viewing_direction(int _x, int _y) const;
00283
00285 Vec3d up() const;
00286
00288 Vec3d right() const;
00289
00293 void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
00294
00295
00296
00297
00299 Vec3d project(const Vec3d& _point) const;
00300
00302 Vec3d unproject(const Vec3d& _winPoint) const;
00303
00304
00305
00306
00307
00308
00310 static const Vec4f default_clear_color;
00312 static const Vec4f default_base_color;
00314 static const Vec4f default_ambient_color;
00316 static const Vec4f default_diffuse_color;
00318 static const Vec4f default_specular_color;
00320 static const float default_shininess;
00321
00322
00324 void set_clear_color(const Vec4f& _col);
00326 const Vec4f& clear_color() const { return clear_color_; }
00327
00329 void set_base_color(const Vec4f& _col);
00331 const Vec4f& base_color() const { return base_color_; }
00332
00334 void set_ambient_color(const Vec4f& _col);
00336 const Vec4f& ambient_color() const { return ambient_color_; }
00337
00339 void set_diffuse_color(const Vec4f& _col);
00341 const Vec4f& diffuse_color() const { return diffuse_color_; }
00342
00344 void set_specular_color(const Vec4f& _col);
00346 const Vec4f& specular_color() const { return specular_color_; }
00347
00349 void set_shininess(float _shininess);
00351 float shininess() const { return shininess_; }
00352
00353
00354
00355
00356
00357
00359 void set_point_size(float _f);
00361 float point_size() const { return point_size_; }
00362
00364 void set_line_width(float _f);
00366 float line_width() const { return line_width_; }
00367
00368
00371
00372
00373 public:
00375 unsigned int render_pass() const { return render_pass_; }
00376
00378 void reset_render_pass() { render_pass_ = 1; }
00379
00381 void next_render_pass() { ++render_pass_; }
00382
00384 unsigned int max_render_passes() const { return max_render_passes_; }
00385
00387 void set_max_render_passes(const unsigned int _max) { max_render_passes_ = _max; }
00388
00389 private:
00392 unsigned int render_pass_;
00393
00396 unsigned int max_render_passes_;
00397
00400
00401
00402 public:
00404 void set_blending(bool _b) { blending_ = _b; }
00406 bool blending() { return blending_; }
00407
00409 void set_twosided_lighting(bool _b);
00411 bool twosided_lighting() { return twosided_lighting_; }
00412
00413
00414
00416 void set_multisampling( bool _b );
00417
00419 bool multisampling(){ return multisampling_; };
00420
00422 void allow_multisampling( bool _b ) { allow_multisampling_ = _b; };
00423
00425 bool multisampling_allowed(){ return allow_multisampling_; };
00426
00428 int max_texture_units() const { return num_texture_units_; }
00429
00430
00431
00440
00441 void pick_init (bool _color);
00442
00446 bool pick_set_maximum (unsigned int _idx);
00447
00449 void pick_set_name (unsigned int _idx);
00450
00454 Vec4uc pick_get_name_color (unsigned int _idx);
00455
00457 void pick_push_name (unsigned int _idx);
00458
00460 void pick_pop_name ();
00461
00464 std::vector<unsigned int> pick_color_to_stack (Vec4uc _rgba) const;
00465
00467 unsigned int pick_free_indicies () const;
00468
00471 bool pick_error () const;
00472
00476 unsigned int pick_current_index () const;
00477
00479 bool color_picking () const;
00480
00481
00482 private:
00483
00484
00485 void update_matrices();
00486
00487
00488
00489 std::stack<GLMatrixd> stack_projection_,
00490 stack_modelview_,
00491 stack_inverse_projection_,
00492 stack_inverse_modelview_;
00493
00494
00495 GLMatrixd projection_,
00496 inverse_projection_,
00497 modelview_,
00498 inverse_modelview_,
00499 window2viewport_,
00500 inverse_window2viewport_,
00501 forward_projection_,
00502 backward_projection_;
00503
00504
00505 int left_, bottom_, width_, height_;
00506
00507
00508 int glwidth_, glheight_;
00509
00510
00511 double near_plane_, far_plane_;
00512
00513
00514 Vec4f clear_color_,
00515 base_color_,
00516 ambient_color_,
00517 diffuse_color_,
00518 specular_color_;
00519
00520 float shininess_;
00521
00522
00523 float point_size_, line_width_;
00524
00525
00526 bool twosided_lighting_;
00527
00528
00529 bool multisampling_;
00530 bool allow_multisampling_;
00531
00532 int num_texture_units_;
00533
00534
00535 bool updateGL_;
00536
00537
00538 bool blending_;
00539
00540
00541 unsigned int msSinceLastRedraw_;
00542
00543
00544 ColorStack colorStack_;
00545
00546
00547 bool colorPicking_;
00548
00549 };
00550
00551 #ifdef WIN32
00552 #pragma warning(push)
00553 #endif
00554
00555
00556 }
00557
00558 #endif // ACG_GLSTATE_HH defined
00559