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_DRAWABLE_HPP
00027 #define __SGL_DRAWABLE_HPP
00028
00029 #include <sgl.h>
00030 #include <sglObject.hpp>
00031
00032 #include <sglBoxBound.hpp>
00033 #include <sglFrustum.hpp>
00034
00035 #include <sglIntersect.hpp>
00036 #include <sglTexCoords.hpp>
00037 #include <sglStatelet.hpp>
00038 #include <sglStats.hpp>
00039 #include <sglOStream.hpp>
00040
00041 #include <vector>
00042
00043
00044 class sglGeode;
00045 template <class T> class sglIntersect;
00046
00047
00048
00169 class SGL_DLL_API sglDrawable : public sglObject
00170 {
00171 public:
00172 class SGL_DLL_API StateElement
00173 {
00174 public:
00175 StateElement(unsigned int mask);
00176 StateElement(unsigned int mask,
00177 const vector<sglStatelet*> &statelets,
00178 const vector<sglTexCoords> &tex_coords);
00179 StateElement(unsigned int mask,
00180 const vector<sglStatelet*> &statelets,
00181 const sglTexCoords &tex_coords);
00182 ~StateElement();
00183
00184 unsigned int getMask() const { return m_mask; }
00185
00186 const vector<sglStatelet*>& getStatelets() const { return m_statelets; }
00187
00188 const sglTexCoords *getTexCoords() const
00189 { return (m_tex_coords.empty() ? NULL : &m_tex_coords[0]); }
00190
00191 const vector<sglTexCoords>& getTexCoordList() const
00192 { return m_tex_coords; }
00193 const vector<sglTexCoords>* getTexCoordListPtr() const
00194 { return &m_tex_coords; }
00195
00196 GLuint getDisplayList() const { return m_dlist; }
00197
00198 bool getDirty() const { return m_dirty; }
00199
00200 void printInfo(ostream &ostrm, const char *indent_string) const;
00201
00202 private:
00203
00204 StateElement();
00205 StateElement(const StateElement &);
00206 StateElement &operator=(const StateElement &);
00207
00208 friend class sglDrawable;
00209
00210 void setStatelets(const vector<sglStatelet*> &statelets);
00211 void clearStatelets();
00212 void setTexCoordList(const vector<sglTexCoords> &tex_coords);
00213 void setTexCoordList(const sglTexCoords &tex_coords);
00214 void clearTexCoordList();
00215 void setDisplayList(GLuint dlist);
00216 void setDirty(bool dirty) { m_dirty = dirty; }
00217
00218 private:
00219 unsigned int m_mask;
00220 vector<sglStatelet*> m_statelets;
00221 vector<sglTexCoords> m_tex_coords;
00222 GLuint m_dlist;
00223 bool m_dirty;
00224
00225
00226 };
00227
00228 public:
00230 sglDrawable();
00232 virtual ~sglDrawable();
00233
00235 void enableDisplayList(bool on);
00237 bool getDisplayListFlag() const { return m_use_dlist; }
00238
00240 unsigned int getNumParents() const { return m_parent_list.size(); }
00242 sglGeode* getParent(unsigned int i);
00243
00245 unsigned int getNumStates() { return m_state_list.size(); }
00247 StateElement *getState(unsigned int index = 0);
00249 StateElement *getStateByMask(unsigned int mask = 0) const;
00250
00252 StateElement *findState(unsigned int mask) const;
00253
00255 void setState(unsigned int mask,
00256 const vector<sglStatelet*> &statelets);
00258 void setState(unsigned int mask,
00259 const vector<sglStatelet*> &statelets,
00260 sglVec2f *tex_coords);
00262 void setState(unsigned int mask,
00263 const vector<sglStatelet*> &statelets,
00264 const sglTexCoords &tex_coords);
00266 void setState(unsigned int mask,
00267 const vector<sglStatelet*> &statelets,
00268 const vector<sglTexCoords> &tex_coords);
00269
00271 void setTexCoordList(sglVec2f* tex_coords);
00272
00274 void setTexCoordList(const sglTexCoords &tex_coords);
00275
00277 void setTexCoordList(const vector<sglTexCoords> &tex_coords_list);
00278
00285 bool removeState(unsigned int mask);
00286
00293 void setBound(const sglBoxBound *bbox, sglBound::ModeEnum mode);
00294
00296 virtual const sglBoxBound &getBound();
00298 sglBound::ModeEnum getBoundMode() {return m_bound_mode;}
00299
00301 const sglBoxBound &getPrevBound() const { return m_bbox; }
00302
00306 virtual void addStats(sglStats &stats) const = 0;
00307
00309 void preDraw();
00310
00312 sglBound::IntersectResultEnum intersectBBox(sglIntersectf &segset);
00314 sglBound::IntersectResultEnum intersectBBox(sglIntersectd &segset);
00315
00317 virtual sglBound::IntersectResultEnum intersectPrim(sglIntersectf &)
00318 { return sglBound::eOUTSIDE; }
00320 virtual sglBound::IntersectResultEnum intersectPrim(sglIntersectd &)
00321 { return sglBound::eOUTSIDE; }
00322
00324 virtual bool isValid() const { return true; }
00325
00327 enum AAEnum {ePOINT_AA, eLINE_AA, ePOLYGON_AA, eNO_AA};
00329 virtual AAEnum getAAType() const { return eNO_AA; }
00330
00332 virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00333
00335 void drawImmediate(const vector<sglTexCoords> &tex_coords) const;
00336
00337 typedef void (sglDrawable::*DrawFunc)(
00338 const vector<sglTexCoords> &tex_coords) const;
00339
00340 protected:
00341 friend class sglGeode;
00342
00348 virtual bool computeBounds() = 0;
00349
00350 virtual void computeNoBounds();
00351 virtual void computeBoundsRecursiveDown();
00352
00353 void dirty(unsigned char mask, bool all);
00354
00355 void addParent(sglGeode *parent);
00356 void removeParent(sglGeode *parent);
00357
00358 bool cull(const sglFrustum<float> &frustum, unsigned int cull_flags) const;
00359 bool cull(const sglFrustum<double> &frustum, unsigned int cull_flags) const;
00360
00361 private:
00362 sglDrawable(const sglDrawable &);
00363 sglDrawable &operator=(const sglDrawable &);
00364
00365 protected:
00366 sglBoxBound m_bbox;
00367
00368
00369
00370 vector<StateElement *> m_state_list;
00371 bool m_use_dlist;
00372
00373 DrawFunc m_draw_func;
00374
00375 sglBound::ModeEnum m_bound_mode;
00376
00377 enum DirtyEnum { eBOUND = 0x01, eDLIST = 0x02 };
00378 unsigned char m_dirty;
00379
00380 vector<sglGeode*> m_parent_list;
00381 };
00382
00383 #endif