gxcache.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2002-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Wed Nov 13 14:03:42 2002
00010 // commit: $Id: gxcache.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/gfx/gxcache.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_GFX_GXCACHE_CC_UTC20050626084023_DEFINED
00035 #define GROOVX_GFX_GXCACHE_CC_UTC20050626084023_DEFINED
00036 
00037 #include "gxcache.h"
00038 
00039 #include "gfx/glcanvas.h"
00040 
00041 #include "io/reader.h"
00042 #include "io/writer.h"
00043 
00044 #include "rutz/error.h"
00045 
00046 #include "rutz/debug.h"
00047 #include "rutz/trace.h"
00048 GVX_DBG_REGISTER
00049 
00050 namespace
00051 {
00052   const io::version_id GXCACHE_SVID = 1;
00053 }
00054 
00055 GxCache::GxCache(nub::soft_ref<GxNode> child) :
00056   GxBin(child),
00057   itsMode(DIRECT),
00058   itsDisplayList(0),
00059   itsCanvas()
00060 {
00061 GVX_TRACE("GxCache::GxCache");
00062 }
00063 
00064 GxCache::~GxCache() throw()
00065 {
00066 GVX_TRACE("GxCache::~GxCache");
00067   invalidate();
00068 }
00069 
00070 io::version_id GxCache::class_version_id() const
00071 {
00072 GVX_TRACE("GxCache::class_version_id");
00073   return GXCACHE_SVID;
00074 }
00075 
00076 void GxCache::read_from(io::reader& reader)
00077 {
00078 GVX_TRACE("GxCache::read_from");
00079 
00080   reader.ensure_version_id("GxCache", 1,
00081                            "Try Revision 1.11", SRC_POS);
00082 
00083   reader.read_value("mode", itsMode);
00084 }
00085 
00086 void GxCache::write_to(io::writer& writer) const
00087 {
00088 GVX_TRACE("GxCache::write_to");
00089 
00090   writer.write_value("mode", itsMode);
00091 }
00092 
00093 void GxCache::draw(Gfx::Canvas& canvas) const
00094 {
00095 GVX_TRACE("GxCache::draw");
00096   GLCanvas* const glcanvas = dynamic_cast<GLCanvas*>(&canvas);
00097   if (itsMode != GLCOMPILE || glcanvas == 0)
00098     {
00099       child()->draw(canvas);
00100     }
00101   else
00102     {
00103       if (glcanvas == itsCanvas.get_weak() &&
00104           glcanvas->isList(itsDisplayList))
00105         {
00106           glcanvas->callList(itsDisplayList);
00107           dbg_eval_nl(3, itsDisplayList);
00108         }
00109       else
00110         {
00111           itsDisplayList = glcanvas->genLists(1);
00112           itsCanvas = nub::soft_ref<GLCanvas>(glcanvas);
00113 
00114           glcanvas->newList(itsDisplayList, true);
00115           child()->draw(canvas);
00116           glcanvas->endList();
00117         }
00118     }
00119 }
00120 
00121 void GxCache::getBoundingCube(Gfx::Bbox& bbox) const
00122 {
00123 GVX_TRACE("GxCache::getBoundingCube");
00124   child()->getBoundingCube(bbox);
00125 }
00126 
00127 void GxCache::invalidate() throw()
00128 {
00129 GVX_TRACE("GxCache::invalidate");
00130   if (itsCanvas.is_valid())
00131     itsCanvas->deleteLists(itsDisplayList, 1);
00132 
00133   // Now forget the display list and its owning canvas
00134   itsDisplayList = 0;
00135   itsCanvas = nub::soft_ref<GLCanvas>();
00136 }
00137 
00138 void GxCache::setMode(Mode new_mode) throw()
00139 {
00140 GVX_TRACE("GxCache::setMode");
00141 #ifdef GVX_BROKEN_GL_DISPLAY_LISTS
00142   if (new_mode == GLCOMPILE) new_mode = DIRECT;
00143 #endif
00144 
00145   if (itsMode != new_mode)
00146     invalidate();
00147 
00148   itsMode = new_mode;
00149 }
00150 
00151 static const char __attribute__((used)) vcid_groovx_gfx_gxcache_cc_utc20050626084023[] = "$Id: gxcache.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00152 #endif // !GROOVX_GFX_GXCACHE_CC_UTC20050626084023_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:38 2008 by Doxygen version 1.5.5.