diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 4c28792a5f..6fe922cc53 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -370,6 +370,18 @@ get_render_buffer(int buffer_type, const FrameBufferProperties &prop) { return RenderBuffer(this, buffer_type & prop.get_buffer_mask() & _stereo_buffer_mask); } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsStateGuardian::get_prepared_objects +// Access: Public, Virtual +// Description: Returns the set of texture and geom objects that have +// been prepared with this GSG (and possibly other GSG's +// that share objects). +//////////////////////////////////////////////////////////////////// +PreparedGraphicsObjects *GraphicsStateGuardian:: +get_prepared_objects() { + return _prepared_objects; +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::set_scene // Access: Public @@ -404,18 +416,6 @@ get_scene() const { return _scene_setup; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_prepared_objects -// Access: Public, Virtual -// Description: Returns the set of texture and geom objects that have -// been prepared with this GSG (and possibly other GSG's -// that share objects). -//////////////////////////////////////////////////////////////////// -PreparedGraphicsObjects *GraphicsStateGuardian:: -get_prepared_objects() { - return _prepared_objects; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::prepare_texture // Access: Public, Virtual diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 1d11830f56..028e93877b 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -152,12 +152,12 @@ PUBLISHED: INLINE void make_global_gsg(); INLINE static GraphicsStateGuardian *get_global_gsg(); + virtual PreparedGraphicsObjects *get_prepared_objects(); + public: bool set_scene(SceneSetup *scene_setup); virtual SceneSetup *get_scene() const; - virtual PreparedGraphicsObjects *get_prepared_objects(); - virtual TextureContext *prepare_texture(Texture *tex); virtual void release_texture(TextureContext *tc); virtual bool extract_texture_data(Texture *tex); diff --git a/panda/src/display/standardMunger.cxx b/panda/src/display/standardMunger.cxx index d5cda2c1ae..42635a2061 100644 --- a/panda/src/display/standardMunger.cxx +++ b/panda/src/display/standardMunger.cxx @@ -224,6 +224,11 @@ munge_geom_impl(CPT(Geom) &geom, CPT(GeomVertexData) &vertex_data, int StandardMunger:: compare_to_impl(const GeomMunger *other) const { const StandardMunger *om = DCAST(StandardMunger, other); + + if (_gsg != om->_gsg) { + return _gsg < om->_gsg ? -1 : 1; + } + if (_render_mode != om->_render_mode) { return _render_mode < om->_render_mode ? -1 : 1; } diff --git a/panda/src/display/standardMunger.h b/panda/src/display/standardMunger.h index 3e94131fb1..69029476ef 100644 --- a/panda/src/display/standardMunger.h +++ b/panda/src/display/standardMunger.h @@ -26,6 +26,7 @@ #include "colorScaleAttrib.h" #include "renderModeAttrib.h" #include "pointerTo.h" +#include "weakPointerTo.h" //////////////////////////////////////////////////////////////////// // Class : StandardMunger @@ -55,7 +56,7 @@ private: int _num_components; NumericType _numeric_type; Contents _contents; - PT(GraphicsStateGuardian) _gsg; + WPT(GraphicsStateGuardian) _gsg; CPT(RenderModeAttrib) _render_mode; bool _munge_color; diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 7b48c0a467..b48bc8ad71 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -2938,10 +2938,7 @@ close_gsg() { // Unlike in OpenGL, in DX8 it is safe to try to explicitly release // any textures here. And it may even be a good idea. if (_prepared_objects->get_ref_count() == 1) { - release_all_textures(); - release_all_geoms(); - release_all_vertex_buffers(); - release_all_index_buffers(); + release_all(); // Now we need to actually delete all of the objects we just // released. diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 29e292dda8..8449fd7d05 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -4048,10 +4048,7 @@ close_gsg() { // Unlike in OpenGL, in DX9 it is safe to try to explicitly release // any textures here. And it may even be a good idea. if (_prepared_objects->get_ref_count() == 1) { - release_all_textures(); - release_all_geoms(); - release_all_vertex_buffers(); - release_all_index_buffers(); + release_all(); // Now we need to actually delete all of the objects we just // released. diff --git a/panda/src/gobj/bufferContext.h b/panda/src/gobj/bufferContext.h index 6d0085bc88..ca020a55a1 100644 --- a/panda/src/gobj/bufferContext.h +++ b/panda/src/gobj/bufferContext.h @@ -47,9 +47,11 @@ public: BufferContext(BufferResidencyTracker *residency); virtual ~BufferContext(); +PUBLISHED: INLINE size_t get_data_size_bytes() const; INLINE UpdateSeq get_modified() const; +public: INLINE void set_active(bool flag); INLINE void set_resident(bool flag); diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 3dfa8033c2..b6956bc535 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -896,6 +896,23 @@ prepare(PreparedGraphicsObjects *prepared_objects) { prepared_objects->enqueue_geom(this); } +//////////////////////////////////////////////////////////////////// +// Function: Geom::is_prepared +// Access: Published +// Description: Returns true if the geom has already been prepared +// or enqueued for preparation on the indicated GSG, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool Geom:: +is_prepared(PreparedGraphicsObjects *prepared_objects) const { + Contexts::const_iterator ci; + ci = _contexts.find(prepared_objects); + if (ci != _contexts.end()) { + return true; + } + return prepared_objects->is_geom_queued(this); +} + //////////////////////////////////////////////////////////////////// // Function: Geom::release // Access: Published diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index de780759b4..405216eaba 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -126,13 +126,14 @@ PUBLISHED: void clear_cache_stage(Thread *current_thread); void prepare(PreparedGraphicsObjects *prepared_objects); + bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; bool release(PreparedGraphicsObjects *prepared_objects); int release_all(); -public: GeomContext *prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg); +public: void draw(GraphicsStateGuardianBase *gsg, const GeomMunger *munger, const GeomVertexData *vertex_data, diff --git a/panda/src/gobj/geomContext.I b/panda/src/gobj/geomContext.I index 3516a34991..84bcc311b3 100644 --- a/panda/src/gobj/geomContext.I +++ b/panda/src/gobj/geomContext.I @@ -27,3 +27,13 @@ GeomContext(Geom *geom) : _geom(geom) { } + +//////////////////////////////////////////////////////////////////// +// Function: GeomContext::get_geom +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE Geom *GeomContext:: +get_geom() const { + return _geom; +} diff --git a/panda/src/gobj/geomContext.h b/panda/src/gobj/geomContext.h index 9d579a3782..fff6d2157b 100644 --- a/panda/src/gobj/geomContext.h +++ b/panda/src/gobj/geomContext.h @@ -44,6 +44,10 @@ class EXPCL_PANDA GeomContext : public SavedContext { public: INLINE GeomContext(Geom *geom); +PUBLISHED: + INLINE Geom *get_geom() const; + +public: // This cannot be a PT(Geom), because the geom and the GSG // both own their GeomContexts! That would create a circular // reference count. diff --git a/panda/src/gobj/geomPrimitive.cxx b/panda/src/gobj/geomPrimitive.cxx index 54cdd2e5f1..43a6af3993 100644 --- a/panda/src/gobj/geomPrimitive.cxx +++ b/panda/src/gobj/geomPrimitive.cxx @@ -1076,6 +1076,23 @@ prepare(PreparedGraphicsObjects *prepared_objects) { prepared_objects->enqueue_index_buffer(this); } +//////////////////////////////////////////////////////////////////// +// Function: GeomPrimitive::is_prepared +// Access: Published +// Description: Returns true if the data has already been prepared +// or enqueued for preparation on the indicated GSG, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool GeomPrimitive:: +is_prepared(PreparedGraphicsObjects *prepared_objects) const { + Contexts::const_iterator ci; + ci = _contexts.find(prepared_objects); + if (ci != _contexts.end()) { + return true; + } + return prepared_objects->is_index_buffer_queued(this); +} + //////////////////////////////////////////////////////////////////// // Function: GeomPrimitive::prepare_now // Access: Public diff --git a/panda/src/gobj/geomPrimitive.h b/panda/src/gobj/geomPrimitive.h index 3cee00bc81..5560b2785a 100644 --- a/panda/src/gobj/geomPrimitive.h +++ b/panda/src/gobj/geomPrimitive.h @@ -176,8 +176,8 @@ public: virtual int get_num_unused_vertices_per_primitive() const; void prepare(PreparedGraphicsObjects *prepared_objects); + bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; -public: IndexBufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg); bool release(PreparedGraphicsObjects *prepared_objects); diff --git a/panda/src/gobj/geomVertexArrayData.cxx b/panda/src/gobj/geomVertexArrayData.cxx index 4b77bf399a..22ffc14b6c 100644 --- a/panda/src/gobj/geomVertexArrayData.cxx +++ b/panda/src/gobj/geomVertexArrayData.cxx @@ -174,6 +174,23 @@ prepare(PreparedGraphicsObjects *prepared_objects) { prepared_objects->enqueue_vertex_buffer(this); } +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexArrayData::is_prepared +// Access: Published +// Description: Returns true if the data has already been prepared +// or enqueued for preparation on the indicated GSG, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool GeomVertexArrayData:: +is_prepared(PreparedGraphicsObjects *prepared_objects) const { + Contexts::const_iterator ci; + ci = _contexts.find(prepared_objects); + if (ci != _contexts.end()) { + return true; + } + return prepared_objects->is_vertex_buffer_queued(this); +} + //////////////////////////////////////////////////////////////////// // Function: GeomVertexArrayData::prepare_now // Access: Public diff --git a/panda/src/gobj/geomVertexArrayData.h b/panda/src/gobj/geomVertexArrayData.h index a5f3db26a5..1c2618e94d 100644 --- a/panda/src/gobj/geomVertexArrayData.h +++ b/panda/src/gobj/geomVertexArrayData.h @@ -95,8 +95,8 @@ PUBLISHED: INLINE PTA_uchar modify_data(); INLINE void set_data(CPTA_uchar data); -public: void prepare(PreparedGraphicsObjects *prepared_objects); + bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; VertexBufferContext *prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg); diff --git a/panda/src/gobj/indexBufferContext.h b/panda/src/gobj/indexBufferContext.h index f375b65857..298e09bc1b 100644 --- a/panda/src/gobj/indexBufferContext.h +++ b/panda/src/gobj/indexBufferContext.h @@ -40,12 +40,14 @@ class EXPCL_PANDA IndexBufferContext : public BufferContext { public: INLINE IndexBufferContext(PreparedGraphicsObjects *pgo, GeomPrimitive *data); +PUBLISHED: INLINE GeomPrimitive *get_data() const; INLINE bool changed_size(const GeomPrimitivePipelineReader *reader) const; INLINE bool changed_usage_hint(const GeomPrimitivePipelineReader *reader) const; INLINE bool was_modified(const GeomPrimitivePipelineReader *reader) const; +public: INLINE void mark_loaded(const GeomPrimitivePipelineReader *reader); private: diff --git a/panda/src/gobj/preparedGraphicsObjects.I b/panda/src/gobj/preparedGraphicsObjects.I index 83dca00140..fbfe779d4a 100644 --- a/panda/src/gobj/preparedGraphicsObjects.I +++ b/panda/src/gobj/preparedGraphicsObjects.I @@ -42,3 +42,33 @@ release_all() { release_all_vertex_buffers(); release_all_index_buffers(); } + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued +// Access: Public +// Description: Returns the number of objects of any kind that have +// been enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +INLINE int PreparedGraphicsObjects:: +get_num_queued() const { + return (get_num_queued_textures() + + get_num_queued_geoms() + + get_num_queued_shaders() + + get_num_queued_vertex_buffers() + + get_num_queued_index_buffers()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared +// Access: Public +// Description: Returns the number of objects of any kind that have +// already been prepared on this GSG. +//////////////////////////////////////////////////////////////////// +INLINE int PreparedGraphicsObjects:: +get_num_prepared() const { + return (get_num_prepared_textures() + + get_num_prepared_geoms() + + get_num_prepared_shaders() + + get_num_prepared_vertex_buffers() + + get_num_prepared_index_buffers()); +} diff --git a/panda/src/gobj/preparedGraphicsObjects.cxx b/panda/src/gobj/preparedGraphicsObjects.cxx index 48c41bbae5..1dd80bbe45 100644 --- a/panda/src/gobj/preparedGraphicsObjects.cxx +++ b/panda/src/gobj/preparedGraphicsObjects.cxx @@ -137,6 +137,20 @@ enqueue_texture(Texture *tex) { _enqueued_textures.insert(tex); } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::is_texture_queued +// Access: Public +// Description: Returns true if the texture has been queued on this +// GSG, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PreparedGraphicsObjects:: +is_texture_queued(const Texture *tex) const { + ReMutexHolder holder(_lock); + + EnqueuedTextures::const_iterator qi = _enqueued_textures.find((Texture *)tex); + return (qi != _enqueued_textures.end()); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::dequeue_texture // Access: Public @@ -205,7 +219,7 @@ int PreparedGraphicsObjects:: release_all_textures() { ReMutexHolder holder(_lock); - int num_textures = (int)_prepared_textures.size(); + int num_textures = (int)_prepared_textures.size() + (int)_enqueued_textures.size(); Textures::iterator tci; for (tci = _prepared_textures.begin(); @@ -219,10 +233,33 @@ release_all_textures() { } _prepared_textures.clear(); + _enqueued_textures.clear(); return num_textures; } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued_textures +// Access: Public +// Description: Returns the number of textures that have been +// enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_queued_textures() const { + return _enqueued_textures.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared_textures +// Access: Public +// Description: Returns the number of textures that have already been +// prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_prepared_textures() const { + return _prepared_textures.size(); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::prepare_texture_now // Access: Public @@ -277,6 +314,20 @@ enqueue_geom(Geom *geom) { _enqueued_geoms.insert(geom); } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::is_geom_queued +// Access: Public +// Description: Returns true if the geom has been queued on this +// GSG, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PreparedGraphicsObjects:: +is_geom_queued(const Geom *geom) const { + ReMutexHolder holder(_lock); + + EnqueuedGeoms::const_iterator qi = _enqueued_geoms.find((Geom *)geom); + return (qi != _enqueued_geoms.end()); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::dequeue_geom // Access: Public @@ -345,7 +396,7 @@ int PreparedGraphicsObjects:: release_all_geoms() { ReMutexHolder holder(_lock); - int num_geoms = (int)_prepared_geoms.size(); + int num_geoms = (int)_prepared_geoms.size() + (int)_enqueued_geoms.size(); Geoms::iterator gci; for (gci = _prepared_geoms.begin(); @@ -359,10 +410,33 @@ release_all_geoms() { } _prepared_geoms.clear(); + _enqueued_geoms.clear(); return num_geoms; } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued_geoms +// Access: Public +// Description: Returns the number of geoms that have been +// enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_queued_geoms() const { + return _enqueued_geoms.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared_geoms +// Access: Public +// Description: Returns the number of geoms that have already been +// prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_prepared_geoms() const { + return _prepared_geoms.size(); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::prepare_geom_now // Access: Public @@ -417,6 +491,20 @@ enqueue_shader(ShaderExpansion *se) { _enqueued_shaders.insert(se); } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::is_shader_queued +// Access: Public +// Description: Returns true if the shader has been queued on this +// GSG, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PreparedGraphicsObjects:: +is_shader_queued(const ShaderExpansion *shader) const { + ReMutexHolder holder(_lock); + + EnqueuedShaders::const_iterator qi = _enqueued_shaders.find((ShaderExpansion *)shader); + return (qi != _enqueued_shaders.end()); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::dequeue_shader // Access: Public @@ -485,7 +573,7 @@ int PreparedGraphicsObjects:: release_all_shaders() { ReMutexHolder holder(_lock); - int num_shaders = (int)_prepared_shaders.size(); + int num_shaders = (int)_prepared_shaders.size() + (int)_enqueued_shaders.size(); Shaders::iterator sci; for (sci = _prepared_shaders.begin(); @@ -499,10 +587,33 @@ release_all_shaders() { } _prepared_shaders.clear(); + _enqueued_shaders.clear(); return num_shaders; } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued_shaders +// Access: Public +// Description: Returns the number of shaders that have been +// enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_queued_shaders() const { + return _enqueued_shaders.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared_shaders +// Access: Public +// Description: Returns the number of shaders that have already been +// prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_prepared_shaders() const { + return _prepared_shaders.size(); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::prepare_shader_now // Access: Public @@ -557,6 +668,20 @@ enqueue_vertex_buffer(GeomVertexArrayData *data) { _enqueued_vertex_buffers.insert(data); } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::is_vertex_buffer_queued +// Access: Public +// Description: Returns true if the vertex buffer has been queued on +// this GSG, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PreparedGraphicsObjects:: +is_vertex_buffer_queued(const GeomVertexArrayData *data) const { + ReMutexHolder holder(_lock); + + EnqueuedVertexBuffers::const_iterator qi = _enqueued_vertex_buffers.find((GeomVertexArrayData *)data); + return (qi != _enqueued_vertex_buffers.end()); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::dequeue_vertex_buffer // Access: Public @@ -625,7 +750,7 @@ int PreparedGraphicsObjects:: release_all_vertex_buffers() { ReMutexHolder holder(_lock); - int num_vertex_buffers = (int)_prepared_vertex_buffers.size(); + int num_vertex_buffers = (int)_prepared_vertex_buffers.size() + (int)_enqueued_vertex_buffers.size(); VertexBuffers::iterator vbci; for (vbci = _prepared_vertex_buffers.begin(); @@ -639,10 +764,33 @@ release_all_vertex_buffers() { } _prepared_vertex_buffers.clear(); + _enqueued_vertex_buffers.clear(); return num_vertex_buffers; } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued_vertex_buffers +// Access: Public +// Description: Returns the number of vertex buffers that have been +// enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_queued_vertex_buffers() const { + return _enqueued_vertex_buffers.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared_vertex_buffers +// Access: Public +// Description: Returns the number of vertex buffers that have +// already been prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_prepared_vertex_buffers() const { + return _prepared_vertex_buffers.size(); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::prepare_vertex_buffer_now // Access: Public @@ -697,6 +845,20 @@ enqueue_index_buffer(GeomPrimitive *data) { _enqueued_index_buffers.insert(data); } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::is_index_buffer_queued +// Access: Public +// Description: Returns true if the index buffer has been queued on +// this GSG, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PreparedGraphicsObjects:: +is_index_buffer_queued(const GeomPrimitive *data) const { + ReMutexHolder holder(_lock); + + EnqueuedIndexBuffers::const_iterator qi = _enqueued_index_buffers.find((GeomPrimitive *)data); + return (qi != _enqueued_index_buffers.end()); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::dequeue_index_buffer // Access: Public @@ -765,7 +927,7 @@ int PreparedGraphicsObjects:: release_all_index_buffers() { ReMutexHolder holder(_lock); - int num_index_buffers = (int)_prepared_index_buffers.size(); + int num_index_buffers = (int)_prepared_index_buffers.size() + (int)_enqueued_index_buffers.size(); IndexBuffers::iterator ibci; for (ibci = _prepared_index_buffers.begin(); @@ -779,10 +941,33 @@ release_all_index_buffers() { } _prepared_index_buffers.clear(); + _enqueued_index_buffers.clear(); return num_index_buffers; } +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_queued_index_buffers +// Access: Public +// Description: Returns the number of index buffers that have been +// enqueued to be prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_queued_index_buffers() const { + return _enqueued_index_buffers.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PreparedGraphicsObjects::get_num_prepared_index_buffers +// Access: Public +// Description: Returns the number of index buffers that have +// already been prepared on this GSG. +//////////////////////////////////////////////////////////////////// +int PreparedGraphicsObjects:: +get_num_prepared_index_buffers() const { + return _prepared_index_buffers.size(); +} + //////////////////////////////////////////////////////////////////// // Function: PreparedGraphicsObjects::prepare_index_buffer_now // Access: Public diff --git a/panda/src/gobj/preparedGraphicsObjects.h b/panda/src/gobj/preparedGraphicsObjects.h index 10f13986d1..6c836e58a9 100644 --- a/panda/src/gobj/preparedGraphicsObjects.h +++ b/panda/src/gobj/preparedGraphicsObjects.h @@ -63,49 +63,68 @@ public: PreparedGraphicsObjects(); ~PreparedGraphicsObjects(); +PUBLISHED: INLINE const string &get_name() const; INLINE void release_all(); + INLINE int get_num_queued() const; + INLINE int get_num_prepared() const; void enqueue_texture(Texture *tex); + bool is_texture_queued(const Texture *tex) const; bool dequeue_texture(Texture *tex); void release_texture(TextureContext *tc); int release_all_textures(); + int get_num_queued_textures() const; + int get_num_prepared_textures() const; TextureContext *prepare_texture_now(Texture *tex, GraphicsStateGuardianBase *gsg); void enqueue_geom(Geom *geom); + bool is_geom_queued(const Geom *geom) const; bool dequeue_geom(Geom *geom); void release_geom(GeomContext *gc); int release_all_geoms(); + int get_num_queued_geoms() const; + int get_num_prepared_geoms() const; GeomContext *prepare_geom_now(Geom *geom, GraphicsStateGuardianBase *gsg); void enqueue_shader(ShaderExpansion *shader); + bool is_shader_queued(const ShaderExpansion *shader) const; bool dequeue_shader(ShaderExpansion *shader); void release_shader(ShaderContext *sc); int release_all_shaders(); + int get_num_queued_shaders() const; + int get_num_prepared_shaders() const; ShaderContext *prepare_shader_now(ShaderExpansion *shader, GraphicsStateGuardianBase *gsg); void enqueue_vertex_buffer(GeomVertexArrayData *data); + bool is_vertex_buffer_queued(const GeomVertexArrayData *data) const; bool dequeue_vertex_buffer(GeomVertexArrayData *data); void release_vertex_buffer(VertexBufferContext *vbc); int release_all_vertex_buffers(); + int get_num_queued_vertex_buffers() const; + int get_num_prepared_vertex_buffers() const; VertexBufferContext * prepare_vertex_buffer_now(GeomVertexArrayData *data, GraphicsStateGuardianBase *gsg); void enqueue_index_buffer(GeomPrimitive *data); + bool is_index_buffer_queued(const GeomPrimitive *data) const; bool dequeue_index_buffer(GeomPrimitive *data); void release_index_buffer(IndexBufferContext *ibc); int release_all_index_buffers(); + int get_num_queued_index_buffers() const; + int get_num_prepared_index_buffers() const; IndexBufferContext * prepare_index_buffer_now(GeomPrimitive *data, GraphicsStateGuardianBase *gsg); +public: void begin_frame(GraphicsStateGuardianBase *gsg, Thread *current_thread); void end_frame(Thread *current_thread); diff --git a/panda/src/gobj/savedContext.h b/panda/src/gobj/savedContext.h index 2de6f7c3f9..a2956bf9e1 100644 --- a/panda/src/gobj/savedContext.h +++ b/panda/src/gobj/savedContext.h @@ -36,10 +36,11 @@ class EXPCL_PANDA SavedContext : public TypedObject { public: INLINE SavedContext(); -public: +PUBLISHED: static TypeHandle get_class_type() { return _type_handle; } +public: static void init_type() { TypedObject::init_type(); register_type(_type_handle, "SavedContext", diff --git a/panda/src/gobj/shaderContext.I b/panda/src/gobj/shaderContext.I index 0cc4a56c0e..d0c1e74771 100755 --- a/panda/src/gobj/shaderContext.I +++ b/panda/src/gobj/shaderContext.I @@ -27,4 +27,12 @@ ShaderContext(ShaderExpansion *se) : { } - +//////////////////////////////////////////////////////////////////// +// Function: ShaderContext::get_expansion +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE ShaderExpansion *ShaderContext:: +get_expansion() const { + return _expansion; +} diff --git a/panda/src/gobj/shaderContext.h b/panda/src/gobj/shaderContext.h index e8c2b0b73e..5b1dae2e59 100755 --- a/panda/src/gobj/shaderContext.h +++ b/panda/src/gobj/shaderContext.h @@ -39,7 +39,11 @@ class EXPCL_PANDA ShaderContext: public SavedContext { public: INLINE ShaderContext(ShaderExpansion *se); - + +PUBLISHED: + INLINE ShaderExpansion *get_expansion() const; + +public: ShaderExpansion *_expansion; public: diff --git a/panda/src/gobj/shaderExpansion.cxx b/panda/src/gobj/shaderExpansion.cxx index a5fb591c48..abe9494580 100644 --- a/panda/src/gobj/shaderExpansion.cxx +++ b/panda/src/gobj/shaderExpansion.cxx @@ -1308,6 +1308,23 @@ prepare(PreparedGraphicsObjects *prepared_objects) { prepared_objects->enqueue_shader(this); } +//////////////////////////////////////////////////////////////////// +// Function: ShaderExpansion::is_prepared +// Access: Published +// Description: Returns true if the shader has already been prepared +// or enqueued for preparation on the indicated GSG, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool ShaderExpansion:: +is_prepared(PreparedGraphicsObjects *prepared_objects) const { + Contexts::const_iterator ci; + ci = _contexts.find(prepared_objects); + if (ci != _contexts.end()) { + return true; + } + return prepared_objects->is_shader_queued(this); +} + //////////////////////////////////////////////////////////////////// // Function: ShaderExpansion::release // Access: Published @@ -1335,7 +1352,7 @@ release(PreparedGraphicsObjects *prepared_objects) { //////////////////////////////////////////////////////////////////// // Function: ShaderExpansion::prepare_now -// Access: Public +// Access: Published // Description: Creates a context for the texture on the particular // GSG, if it does not already exist. Returns the new // (or old) ShaderContext. This assumes that the diff --git a/panda/src/gobj/shaderExpansion.h b/panda/src/gobj/shaderExpansion.h index 3ed4dbd9cd..8f3b4bad9b 100644 --- a/panda/src/gobj/shaderExpansion.h +++ b/panda/src/gobj/shaderExpansion.h @@ -54,8 +54,12 @@ PUBLISHED: INLINE bool get_error_flag() const; void prepare(PreparedGraphicsObjects *prepared_objects); + bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; bool release(PreparedGraphicsObjects *prepared_objects); int release_all(); + + ShaderContext *prepare_now(PreparedGraphicsObjects *prepared_objects, + GraphicsStateGuardianBase *gsg); public: @@ -268,9 +272,6 @@ public: typedef pmap Contexts; Contexts _contexts; - public: - ShaderContext *prepare_now(PreparedGraphicsObjects *prepared_objects, - GraphicsStateGuardianBase *gsg); private: ShaderExpansion(const string &name, const string &text, diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 4e58c838a8..d39d96cb40 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -1244,6 +1244,23 @@ prepare(PreparedGraphicsObjects *prepared_objects) { prepared_objects->enqueue_texture(this); } +//////////////////////////////////////////////////////////////////// +// Function: Texture::is_prepared +// Access: Published +// Description: Returns true if the texture has already been prepared +// or enqueued for preparation on the indicated GSG, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool Texture:: +is_prepared(PreparedGraphicsObjects *prepared_objects) const { + Contexts::const_iterator ci; + ci = _contexts.find(prepared_objects); + if (ci != _contexts.end()) { + return true; + } + return prepared_objects->is_texture_queued(this); +} + //////////////////////////////////////////////////////////////////// // Function: Texture::release // Access: Published @@ -1581,7 +1598,7 @@ is_mipmap(FilterType filter_type) { //////////////////////////////////////////////////////////////////// // Function: Texture::prepare_now -// Access: Public +// Access: Published // Description: Creates a context for the texture on the particular // GSG, if it does not already exist. Returns the new // (or old) TextureContext. This assumes that the diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index c659d81791..dc1173eaa3 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -311,6 +311,7 @@ PUBLISHED: INLINE UpdateSeq get_image_modified() const; void prepare(PreparedGraphicsObjects *prepared_objects); + bool is_prepared(PreparedGraphicsObjects *prepared_objects) const; bool release(PreparedGraphicsObjects *prepared_objects); int release_all(); @@ -352,10 +353,10 @@ PUBLISHED: INLINE bool get_match_framebuffer_format() const; INLINE void set_match_framebuffer_format(bool flag); -public: - TextureContext *prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg); + +public: void texture_uploaded(); virtual bool has_cull_callback() const; diff --git a/panda/src/gobj/textureContext.h b/panda/src/gobj/textureContext.h index 6f387148c7..3bd40dc875 100644 --- a/panda/src/gobj/textureContext.h +++ b/panda/src/gobj/textureContext.h @@ -42,11 +42,14 @@ class EXPCL_PANDA TextureContext : public BufferContext { public: INLINE TextureContext(PreparedGraphicsObjects *pgo, Texture *tex); +PUBLISHED: INLINE Texture *get_texture() const; INLINE bool was_modified() const; INLINE bool was_properties_modified() const; INLINE bool was_image_modified() const; + +public: INLINE void mark_loaded(); private: diff --git a/panda/src/gobj/vertexBufferContext.h b/panda/src/gobj/vertexBufferContext.h index 2c8a04625e..28ed15cdd6 100644 --- a/panda/src/gobj/vertexBufferContext.h +++ b/panda/src/gobj/vertexBufferContext.h @@ -41,12 +41,14 @@ public: INLINE VertexBufferContext(PreparedGraphicsObjects *pgo, GeomVertexArrayData *data); +PUBLISHED: INLINE GeomVertexArrayData *get_data() const; INLINE bool changed_size(const GeomVertexArrayDataPipelineReader *reader) const; INLINE bool changed_usage_hint(const GeomVertexArrayDataPipelineReader *reader) const; INLINE bool was_modified(const GeomVertexArrayDataPipelineReader *reader) const; +public: INLINE void mark_loaded(const GeomVertexArrayDataPipelineReader *reader); private: diff --git a/panda/src/gsgbase/graphicsStateGuardianBase.h b/panda/src/gsgbase/graphicsStateGuardianBase.h index 4f54497c47..91b30f5f04 100644 --- a/panda/src/gsgbase/graphicsStateGuardianBase.h +++ b/panda/src/gsgbase/graphicsStateGuardianBase.h @@ -120,7 +120,12 @@ public: // mainly to make it easy to call these from code in some directory // that display depends on. virtual SceneSetup *get_scene() const=0; + +#ifndef CPPPARSER + // We hide this from interrogate, so that it will be properly + // exported from the GraphicsStateGuardian class, later. virtual PreparedGraphicsObjects *get_prepared_objects()=0; +#endif virtual TextureContext *prepare_texture(Texture *tex)=0; virtual void release_texture(TextureContext *tc)=0; diff --git a/panda/src/pgraph/camera.cxx b/panda/src/pgraph/camera.cxx index fb5b045061..d6f7b0ac17 100644 --- a/panda/src/pgraph/camera.cxx +++ b/panda/src/pgraph/camera.cxx @@ -39,7 +39,7 @@ Camera(const string &name) : //////////////////////////////////////////////////////////////////// // Function: Camera::Copy Constructor -// Access: Protected +// Access: Published // Description: //////////////////////////////////////////////////////////////////// Camera:: diff --git a/panda/src/pgraph/camera.h b/panda/src/pgraph/camera.h index 5343d91745..df6e9bc999 100644 --- a/panda/src/pgraph/camera.h +++ b/panda/src/pgraph/camera.h @@ -41,9 +41,8 @@ class DisplayRegion; class EXPCL_PANDA Camera : public LensNode { PUBLISHED: Camera(const string &name); - -protected: Camera(const Camera ©); + public: virtual ~Camera(); diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 46d29d2833..1d01372e87 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -77,7 +77,7 @@ event_W(CPT_Event, void *) { WindowFramework *old_window = framework.get_window(0); GraphicsWindow *win = old_window->get_graphics_window(); pipe = win->get_pipe(); - gsg = win->get_gsg(); + // gsg = win->get_gsg(); } WindowFramework *window = framework.open_window(pipe, gsg);