Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglDrawable.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglDrawable.hpp
00021  *  Created: 18 August 1999
00022  *  Summary: Base class for all sglObjects that can be collected by the cull
00023  *           traversal (sglCull) for rendering.
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 // foward reference this stuff
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       // Not implemented.
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       // tex coord bounds could go here if I ever want to support clip texture
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:  // not implemented
00362    sglDrawable(const sglDrawable &);
00363    sglDrawable &operator=(const sglDrawable &);
00364 
00365 protected:
00366    sglBoxBound m_bbox;
00367 
00368    // the first element of the following list is set in the ctor, to
00369    // something with mask==0, empty statelet list, and NULL tex coords.
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

Generated at Mon Jul 1 18:00:04 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001