00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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