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

sglDrawablePool.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: sglDrawablePool.hpp
00021  *   Author: Tom Stimson
00022  *  Created: 9 July 2000
00023  *  Summary: 
00024  *****************************************************************************/
00025 
00026 #ifndef __SGL_DRAWABLE_POOL_HPP
00027 #define __SGL_DRAWABLE_POOL_HPP
00028 
00029 #include <sgl.h>
00030 #include <list>
00031 #include <vector>
00032 #include <map>
00033 
00034 #include <sglCurrState.hpp>
00035 #include <sglObjPool.hpp>
00036 
00037 class sglDrawable;
00038 class sglStats;
00039 struct sglDrawablePoolSources;
00040 
00041 //----------------------------------------------------------------------------
00042 class SGL_DLL_API sglDrawItem
00043 {
00044 public:
00045    sglDrawItem() {}
00046    virtual ~sglDrawItem() {}
00047 
00048    virtual void draw(sglCurrState *curr_state) const = 0;
00049    virtual void statsDraw(sglCurrState *curr_state,
00050                           sglStats& stats) const = 0;
00051    virtual const sglFullState* getFirstState() const = 0;
00052 };
00053 
00054 //----------------------------------------------------------------------------
00055 class SGL_DLL_API sglDrawablePair : public sglDrawItem
00056 {
00057 public:
00058    sglDrawablePair() : m_drawable(NULL), m_fullstate(NULL) {}
00059    virtual ~sglDrawablePair() {}
00060 
00061    virtual void draw(sglCurrState *curr_state) const;
00062    virtual void statsDraw(sglCurrState *curr_state,
00063                           sglStats& stats) const;
00064    virtual const sglFullState* getFirstState() const;
00065 
00066    void set(const sglDrawable *drawable, sglFullState *fullstate)
00067       { m_drawable = drawable; m_fullstate = fullstate; }
00068 
00069 private:
00070    const sglDrawable *m_drawable;
00071    sglFullState      *m_fullstate;
00072 };
00073 
00074 //----------------------------------------------------------------------------
00075 class SGL_DLL_API sglDrawablePool : public sglDrawItem
00076 {
00077 public:
00078    sglDrawablePool() {};
00079    virtual ~sglDrawablePool() {};
00080 
00081    virtual void clear() = 0;
00082    virtual void insert(sglDrawItem *d_item) = 0;
00083 
00084 private:  // not implemented
00085    sglDrawablePool(const sglDrawablePool &);
00086    sglDrawablePool &operator=(const sglDrawablePool &);
00087 };
00088 
00089 //----------------------------------------------------------------------------
00090 class SGL_DLL_API sglUnSortedDrawablePool : public sglDrawablePool
00091 {
00092 public:
00093    sglUnSortedDrawablePool() {}
00094    virtual ~sglUnSortedDrawablePool() {}
00095 
00096    void clear()
00097       { m_list.clear(); }
00098 
00099    void insert(sglDrawItem *d_item)
00100       { m_list.push_back(d_item); }
00101 
00102    void draw(sglCurrState *curr_state) const;
00103 
00104    void statsDraw(sglCurrState *curr_state,
00105                   sglStats& stats) const;
00106 
00107    const sglFullState* getFirstState() const;
00108 
00109 private:  // not implemented
00110    sglUnSortedDrawablePool(const sglUnSortedDrawablePool &);
00111    sglUnSortedDrawablePool &operator=(const sglUnSortedDrawablePool &);
00112 
00113 private:
00114    vector<sglDrawItem*>  m_list;
00115 };
00116 
00117 //----------------------------------------------------------------------------
00118 class SGL_DLL_API sglSortedDrawablePool : public sglDrawablePool
00119 {
00120 public:
00121    sglSortedDrawablePool();
00122    virtual ~sglSortedDrawablePool();
00123 
00124    void setSortKey(vector<unsigned int>::iterator sort_key)
00125       { m_sort_key = sort_key; }
00126 
00127    void setSources(sglDrawablePoolSources *sources)
00128       { m_sources = sources; }
00129 
00130    void clear();
00131 
00132    void insert(sglDrawItem *d_item);
00133 
00134    void draw(sglCurrState *curr_state) const;
00135 
00136    void statsDraw(sglCurrState *curr_state,
00137                   sglStats& stats) const;
00138 
00139    const sglFullState* getFirstState() const;
00140 
00141 private:  // not implemented
00142    sglSortedDrawablePool(const sglSortedDrawablePool &);
00143    sglSortedDrawablePool &operator=(const sglSortedDrawablePool &);
00144 
00145 private:
00146    sglDrawablePoolSources                   *m_sources;
00147    vector<unsigned int>::iterator            m_sort_key;
00148    map<const void*,sglDrawablePool*>         m_map;
00149 };
00150 
00151 //----------------------------------------------------------------------------
00152 class SGL_DLL_API sglIndexedDrawablePool : public sglDrawablePool
00153 {
00154 public:
00155    sglIndexedDrawablePool() {}
00156    virtual ~sglIndexedDrawablePool() {}
00157 
00158    void setSortKey(vector<unsigned int>::iterator sort_key)
00159       { m_sort_key = sort_key; }
00160 
00161    void setSources(sglDrawablePoolSources *sources)
00162       { m_sources = sources; }
00163 
00164    void clear()
00165       { m_list.clear(); }
00166 
00167    void insert(sglDrawItem *d_item);
00168 
00169    void draw(sglCurrState *curr_state) const;
00170 
00171    void statsDraw(sglCurrState *curr_state,
00172                   sglStats& stats) const;
00173 
00174    const sglFullState* getFirstState() const;
00175 
00176 private:  // not implemented
00177    sglIndexedDrawablePool(const sglIndexedDrawablePool &);
00178    sglIndexedDrawablePool &operator=(const sglIndexedDrawablePool &);
00179 
00180 private:
00181    sglDrawablePoolSources                   *m_sources;
00182    vector<unsigned int>::iterator            m_sort_key;
00183    vector<sglDrawablePool*>                  m_list;
00184 };
00185 
00186 //----------------------------------------------------------------------------
00187 struct SGL_DLL_API sglDrawablePoolSources
00188 {
00189 public:
00190    sglDrawablePoolSources()
00191       : m_unsorted_dp_pool(100, 100),
00192         m_sorted_dp_pool(100, 100),
00193         m_indexed_dp_pool(100, 100) {}
00194 
00195    void reset()
00196       {
00197          m_unsorted_dp_pool.reset();
00198          m_sorted_dp_pool.reset();
00199          m_indexed_dp_pool.reset();
00200       }
00201 
00202 public:
00203    sglObjPool< sglUnSortedDrawablePool >  m_unsorted_dp_pool;
00204    sglObjPool< sglSortedDrawablePool >    m_sorted_dp_pool;
00205    sglObjPool< sglIndexedDrawablePool >   m_indexed_dp_pool;
00206 };
00207 
00208 #endif

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