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_VIEW_HPP
00027 #define __SGL_VIEW_HPP
00028
00029 #include <sgl.h>
00030 #include <sglTimespec.hpp>
00031 #include <sglVector.hpp>
00032 #include <sglCallback.hpp>
00033
00034 #if defined(vxw)
00035 #include <iterator>
00036 #endif
00037
00038 #include <deque>
00039
00040 class sglScene;
00041 class sglViewPlatform;
00042 class sglStatelet;
00043 class sglGeode;
00044 class sglGeoSet;
00045 class sglLightProcessor;
00046 template <class T> class sglCull;
00047 template <class T> class sglStatsCull;
00048
00049
00050
00055 class SGL_DLL_API sglView
00056 {
00057 public:
00059 sglView();
00061 virtual ~sglView();
00062
00063
00064
00068 void setClearColor(const sglVec4f &color);
00070 void setClearColor(float r, float g, float b, float a);
00072 const sglVec4f &getClearColor() const { return m_clear_color; }
00073
00077 void setClearDepth(double depth);
00079 double getClearDepth() const { return m_clear_depth; }
00080
00084 void setViewport(int origin_x, int origin_y,
00085 unsigned int width, unsigned int height);
00087 void getViewport(int &origin_x, int &origin_y,
00088 unsigned int &width, unsigned int &height);
00089
00092 void setScene(sglScene *root);
00094 sglScene *getScene() const { return m_root; }
00095
00099 void setViewPlatform(sglViewPlatform *view_platform);
00101 sglViewPlatform *getViewPlatform() const { return m_view_platform; }
00102
00107 void setScene(sglScene *root, sglViewPlatform *view_platform);
00108
00113 void setTraversalType(bool dp_flag, bool stats_flag);
00115 bool getDPTraversalFlag() const { return m_dptrav_flag; }
00117 bool getStatsFlag() const { return m_stats_flag; }
00118
00122 void enableFrameRateOutput(bool on) { m_frame_rate_flag = on; }
00124 bool getFrameRateOutputFlag() const { return m_frame_rate_flag; }
00125
00129 void setStatsInterval(double seconds) { m_stats_interval = seconds; }
00131 double getStatsInterval() const { return m_stats_interval; }
00132
00134 void setOverrideStatelets(const deque<const sglStatelet*> &statelets)
00135 {
00136 m_override_statelets = statelets;
00137 }
00138
00142 void setDiscriminatorMask(unsigned int mask) { m_discriminator_mask = mask;}
00144 unsigned int getDiscriminatorMask() const { return m_discriminator_mask;}
00145
00149 void setStateMask(unsigned int mask) { m_state_mask = mask; }
00151 unsigned int getStateMask() const { return m_state_mask; }
00152
00159 void setDrawCallback(sglCallbackFunc callback, void *data)
00160 {
00161 m_draw_callback = callback;
00162 m_draw_callback_data = data;
00163 }
00165 sglCallbackFunc getDrawCallback() const { return m_draw_callback; }
00167 void *getDrawCallbackData() const { return m_draw_callback_data; }
00168
00170 void cullAndDraw() { preDraw(); cull(); draw(); }
00171
00173 void cullAndDraw(const sglTimespec &frame_time, unsigned int frame_count)
00174 {
00175 preDraw(frame_time, frame_count);
00176 cull();
00177 draw();
00178 }
00179
00187 void setLightProcessor(sglLightProcessor *light_processor);
00188
00192 sglLightProcessor *getLightProcessor() const;
00193
00194 protected:
00195 void outputFramerate();
00196
00197
00198 void preDraw(const sglTimespec &frame_time, unsigned int frame_count);
00199 void preDraw();
00200
00201
00202 void cull();
00203
00204
00205 void draw();
00206
00207 private:
00208 sglVec4f m_clear_color;
00209 double m_clear_depth;
00210
00211
00212 int m_origin_x;
00213 int m_origin_y;
00214 unsigned int m_width;
00215 unsigned int m_height;
00216
00217
00218 sglScene *m_root;
00219 sglViewPlatform *m_view_platform;
00220
00221
00222 sglMat4f m_view_matrix_f;
00223 sglMat4d m_view_matrix_d;
00224
00225
00226 bool m_dptrav_flag;
00227 bool m_stats_flag;
00228
00229 sglCull<float> *m_trav_state;
00230 sglCull<double> *m_trav_state_dp;
00231
00232 sglStatsCull<float> *m_stats_trav_state;
00233 sglStatsCull<double> *m_stats_trav_state_dp;
00234
00235 deque<const sglStatelet *> m_override_statelets;
00236
00237 unsigned int m_discriminator_mask;
00238 unsigned int m_state_mask;
00239
00240 sglCallbackFunc m_draw_callback;
00241 void * m_draw_callback_data;
00242
00243
00244 sglTimespec m_last_ts;
00245 sglTimespec m_ts1, m_ts2, m_ts3;
00246 double m_cull_time;
00247 double m_draw_time;
00248 unsigned int m_frame_count;
00249 double m_stats_interval;
00250
00251 bool m_frame_rate_flag;
00252 double m_frame_rate;
00253 };
00254
00255 #endif