14#ifndef PREPAREDGRAPHICSOBJECTS_H
15#define PREPAREDGRAPHICSOBJECTS_H
58class EXPCL_PANDA_GOBJ PreparedGraphicsObjects :
public ReferenceCount {
60 PreparedGraphicsObjects();
61 ~PreparedGraphicsObjects();
64 INLINE
const std::string &
get_name()
const;
176 virtual bool cancel()
final;
179 MAKE_PROPERTY(
object, get_object);
182 PreparedGraphicsObjects *_pgo;
189 static void init_type() {
190 AsyncFuture::init_type();
192 AsyncFuture::get_class_type());
195 return get_class_type();
197 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
218 static std::string init_name();
221 typedef phash_set<TextureContext *, pointer_hash> Textures;
223 typedef phash_set<GeomContext *, pointer_hash> Geoms;
224 typedef phash_set< PT(
Geom) > EnqueuedGeoms;
225 typedef phash_set<ShaderContext *, pointer_hash> Shaders;
227 typedef phash_set<BufferContext *, pointer_hash> Buffers;
230 typedef phash_set< PT(
ShaderBuffer) > EnqueuedShaderBuffers;
234 typedef pmap<SamplerState, SamplerContext *> PreparedSamplers;
235 typedef pset<SamplerContext *, pointer_hash> ReleasedSamplers;
236 typedef pset<SamplerState> EnqueuedSamplers;
238 class BufferCacheKey {
240 INLINE
bool operator < (
const BufferCacheKey &other)
const;
241 INLINE
bool operator == (
const BufferCacheKey &other)
const;
242 INLINE
bool operator != (
const BufferCacheKey &other)
const;
243 size_t _data_size_bytes;
244 GeomEnums::UsageHint _usage_hint;
246 typedef pvector<BufferContext *> BufferList;
247 typedef pmap<BufferCacheKey, BufferList> BufferCache;
250 void cache_unprepared_buffer(
BufferContext *buffer,
size_t data_size_bytes,
251 GeomEnums::UsageHint usage_hint,
252 BufferCache &buffer_cache,
253 BufferCacheLRU &buffer_cache_lru,
254 size_t &buffer_cache_size,
255 int released_buffer_cache_size,
256 Buffers &released_buffers);
258 GeomEnums::UsageHint usage_hint,
259 BufferCache &buffer_cache,
260 BufferCacheLRU &buffer_cache_lru,
261 size_t &buffer_cache_size);
265 Textures _prepared_textures, _released_textures;
266 EnqueuedTextures _enqueued_textures;
267 PreparedSamplers _prepared_samplers;
268 ReleasedSamplers _released_samplers;
269 EnqueuedSamplers _enqueued_samplers;
270 Geoms _prepared_geoms, _released_geoms;
271 EnqueuedGeoms _enqueued_geoms;
272 Shaders _prepared_shaders, _released_shaders;
273 EnqueuedShaders _enqueued_shaders;
274 Buffers _prepared_vertex_buffers, _released_vertex_buffers;
275 EnqueuedVertexBuffers _enqueued_vertex_buffers;
276 Buffers _prepared_index_buffers, _released_index_buffers;
277 EnqueuedIndexBuffers _enqueued_index_buffers;
278 Buffers _prepared_shader_buffers, _released_shader_buffers;
279 EnqueuedShaderBuffers _enqueued_shader_buffers;
281 BufferCache _vertex_buffer_cache;
282 BufferCacheLRU _vertex_buffer_cache_lru;
283 size_t _vertex_buffer_cache_size;
285 BufferCache _index_buffer_cache;
286 BufferCacheLRU _index_buffer_cache_lru;
287 size_t _index_buffer_cache_size;
301 bool _support_released_buffer_cache;
304 static int _name_index;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic LRU-type algorithm, except that it is adaptive and attempts to avoid evicting pages that have...
AsyncFuture()
Initializes the future in the pending state.
TypedObject * get_result() const
Returns this future's result.
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
This class is used to keep track of the current state of all the BufferContexts for a particular grap...
This is a special class object that holds all the information returned by a particular GSG to indicat...
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This is the data for one array of a GeomVertexData structure.
A container for geometry primitives.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encapsulates all the communication with a particular instance of a given rendering backend.
This is a special class object that holds all the information returned by a particular GSG to indicat...
This is a handle to an enqueued object, from which the result can be obtained upon completion.
void set_result(SavedContext *result)
Indicates that the preparation request is done.
virtual bool cancel() final
Cancels the pending preparation request.
EnqueuedObject(PreparedGraphicsObjects *pgo, TypedWritableReferenceCount *object)
Creates a new future for the given object.
void notify_removed()
Called by PreparedGraphicsObjects to indicate that the preparation request has been cancelled.
void enqueue_vertex_buffer(GeomVertexArrayData *data)
Indicates that a buffer would like to be put on the list to be prepared when the GSG is next ready to...
int get_num_queued_geoms() const
Returns the number of geoms that have been enqueued to be prepared on this GSG.
int release_all_geoms()
Releases all geoms at once.
void release_sampler(SamplerContext *sc)
Indicates that a sampler context, created by a previous call to prepare_sampler(),...
bool dequeue_vertex_buffer(GeomVertexArrayData *data)
Removes a buffer from the queued list of data arrays to be prepared.
bool is_texture_queued(const Texture *tex) const
Returns true if the texture has been queued on this GSG, false otherwise.
int release_all_textures()
Releases all textures at once.
int get_num_prepared_shaders() const
Returns the number of shaders that have already been prepared on this GSG.
int get_num_queued_index_buffers() const
Returns the number of index buffers that have been enqueued to be prepared on this GSG.
int get_num_prepared_shader_buffers() const
Returns the number of index buffers that have already been prepared on this GSG.
TextureContext * prepare_texture_now(Texture *tex, int view, GraphicsStateGuardianBase *gsg)
Immediately creates a new TextureContext for the indicated texture and returns it.
int get_num_prepared_vertex_buffers() const
Returns the number of vertex buffers that have already been prepared on this GSG.
void release_geom(GeomContext *gc)
Indicates that a geom context, created by a previous call to prepare_geom(), is no longer needed.
bool is_index_buffer_prepared(const GeomPrimitive *data) const
Returns true if the index buffer has been prepared on this GSG, false otherwise.
int get_num_prepared_textures() const
Returns the number of textures that have already been prepared on this GSG.
void enqueue_sampler(const SamplerState &sampler)
Indicates that a sampler would like to be put on the list to be prepared when the GSG is next ready t...
void enqueue_texture(Texture *tex)
Indicates that a texture would like to be put on the list to be prepared when the GSG is next ready t...
int get_num_queued_vertex_buffers() const
Returns the number of vertex buffers that have been enqueued to be prepared on this GSG.
void show_residency_trackers(std::ostream &out) const
Writes to the indicated ostream a report of how the various textures and vertex buffers are allocated...
bool is_shader_queued(const Shader *shader) const
Returns true if the shader has been queued on this GSG, false otherwise.
SamplerContext * prepare_sampler_now(const SamplerState &sampler, GraphicsStateGuardianBase *gsg)
Immediately creates a new SamplerContext for the indicated sampler and returns it.
bool is_geom_prepared(const Geom *geom) const
Returns true if the vertex buffer has been prepared on this GSG, false otherwise.
int get_num_queued_samplers() const
Returns the number of samplers that have been enqueued to be prepared on this GSG.
bool is_shader_buffer_queued(const ShaderBuffer *data) const
Returns true if the index buffer has been queued on this GSG, false otherwise.
int get_num_queued_shaders() const
Returns the number of shaders that have been enqueued to be prepared on this GSG.
bool dequeue_shader(Shader *shader)
Removes a shader from the queued list of shaders to be prepared.
bool is_texture_prepared(const Texture *tex) const
Returns true if the texture has been prepared on this GSG, false otherwise.
void release_shader_buffer(BufferContext *bc)
Indicates that a data context, created by a previous call to prepare_shader_buffer(),...
int get_num_prepared() const
Returns the number of objects of any kind that have already been prepared on this GSG.
const std::string & get_name() const
Returns the name of the PreparedGraphicsObjects structure.
int release_all_shaders()
Releases all shaders at once.
bool is_sampler_prepared(const SamplerState &sampler) const
Returns true if the sampler has been prepared on this GSG, false otherwise.
int get_num_queued_textures() const
Returns the number of textures that have been enqueued to be prepared on this GSG.
bool is_sampler_queued(const SamplerState &sampler) const
Returns true if the sampler has been queued on this GSG, false otherwise.
bool dequeue_sampler(const SamplerState &sampler)
Removes a sampler from the queued list of samplers to be prepared.
int release_all_index_buffers()
Releases all datas at once.
void release_all()
Releases all prepared objects of all kinds at once.
bool is_geom_queued(const Geom *geom) const
Returns true if the geom has been queued on this GSG, false otherwise.
int get_num_prepared_geoms() const
Returns the number of geoms that have already been prepared on this GSG.
void release_shader(ShaderContext *sc)
Indicates that a shader context, created by a previous call to prepare_shader(), is no longer needed.
int release_all_shader_buffers()
Releases all datas at once.
bool is_index_buffer_queued(const GeomPrimitive *data) const
Returns true if the index buffer has been queued on this GSG, false otherwise.
PointerTo< EnqueuedObject > enqueue_texture_future(Texture *tex)
Like enqueue_texture, but returns an AsyncFuture that can be used to query the status of the texture'...
bool is_shader_buffer_prepared(const ShaderBuffer *data) const
Returns true if the index buffer has been prepared on this GSG, false otherwise.
void set_graphics_memory_limit(size_t limit)
Sets an artificial cap on graphics memory that will be imposed on this GSG.
bool dequeue_texture(Texture *tex)
Removes a texture from the queued list of textures to be prepared.
GeomContext * prepare_geom_now(Geom *geom, GraphicsStateGuardianBase *gsg)
Immediately creates a new GeomContext for the indicated geom and returns it.
void end_frame(Thread *current_thread)
This is called by the GraphicsStateGuardian to indicate that it has finished processing of the frame.
int release_all_samplers()
Releases all samplers at once.
void show_graphics_memory_lru(std::ostream &out) const
Writes to the indicated ostream a report of how the various textures and vertex buffers are allocated...
int get_num_queued() const
Returns the number of objects of any kind that have been enqueued to be prepared on this GSG.
size_t get_graphics_memory_limit() const
Returns the artificial cap on graphics memory that will be imposed on this GSG.
bool dequeue_shader_buffer(ShaderBuffer *data)
Removes a buffer from the queued list of data arrays to be prepared.
bool dequeue_geom(Geom *geom)
Removes a geom from the queued list of geoms to be prepared.
void release_index_buffer(IndexBufferContext *ibc)
Indicates that a data context, created by a previous call to prepare_index_buffer(),...
int get_num_prepared_samplers() const
Returns the number of samplers that have already been prepared on this GSG.
bool is_shader_prepared(const Shader *shader) const
Returns true if the shader has been prepared on this GSG, false otherwise.
bool is_vertex_buffer_prepared(const GeomVertexArrayData *data) const
Returns true if the vertex buffer has been prepared on this GSG, false otherwise.
void begin_frame(GraphicsStateGuardianBase *gsg, Thread *current_thread)
This is called by the GraphicsStateGuardian to indicate that it is about to begin processing of the f...
void enqueue_index_buffer(GeomPrimitive *data)
Indicates that a buffer would like to be put on the list to be prepared when the GSG is next ready to...
BufferContext * prepare_shader_buffer_now(ShaderBuffer *data, GraphicsStateGuardianBase *gsg)
Immediately creates a new BufferContext for the indicated data and returns it.
void release_vertex_buffer(VertexBufferContext *vbc)
Indicates that a data context, created by a previous call to prepare_vertex_buffer(),...
void enqueue_shader(Shader *shader)
Indicates that a shader would like to be put on the list to be prepared when the GSG is next ready to...
void enqueue_geom(Geom *geom)
Indicates that a geom would like to be put on the list to be prepared when the GSG is next ready to d...
bool is_vertex_buffer_queued(const GeomVertexArrayData *data) const
Returns true if the vertex buffer has been queued on this GSG, false otherwise.
void release_texture(TextureContext *tc)
Indicates that a texture context, created by a previous call to prepare_texture(),...
int get_num_queued_shader_buffers() const
Returns the number of index buffers that have been enqueued to be prepared on this GSG.
PointerTo< EnqueuedObject > enqueue_shader_future(Shader *shader)
Like enqueue_shader, but returns an AsyncFuture that can be used to query the status of the shader's ...
int release_all_vertex_buffers()
Releases all datas at once.
int get_num_prepared_index_buffers() const
Returns the number of index buffers that have already been prepared on this GSG.
IndexBufferContext * prepare_index_buffer_now(GeomPrimitive *data, GraphicsStateGuardianBase *gsg)
Immediately creates a new IndexBufferContext for the indicated data and returns it.
ShaderContext * prepare_shader_now(Shader *shader, GraphicsStateGuardianBase *gsg)
Immediately creates a new ShaderContext for the indicated shader and returns it.
void enqueue_shader_buffer(ShaderBuffer *data)
Indicates that a buffer would like to be put on the list to be prepared when the GSG is next ready to...
VertexBufferContext * prepare_vertex_buffer_now(GeomVertexArrayData *data, GraphicsStateGuardianBase *gsg)
Immediately creates a new VertexBufferContext for the indicated data and returns it.
bool dequeue_index_buffer(GeomPrimitive *data)
Removes a buffer from the queued list of data arrays to be prepared.
This is a special class object that holds a handle to the sampler state object given by the graphics ...
Represents a set of settings that indicate how a texture is sampled.
This is the base class for all GSG-specific context objects, such as TextureContext and GeomContext.
This is a generic buffer object that lives in graphics memory.
The ShaderContext is meant to contain the compiled version of a shader string.
An implementation of a very simple LRU algorithm.
This is a special class object that holds all the information returned by a particular GSG to indicat...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
This is a special class object that holds all the information returned by a particular GSG to indicat...
This is our own Panda specialization on the default STL list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.