15 #include "dxIndexBufferContext9.h"
16 #include "geomPrimitive.h"
17 #include "config_dxgsg9.h"
18 #include "graphicsStateGuardian.h"
19 #include "pStatTimer.h"
21 #define DEBUG_INDEX_BUFFER false
23 TypeHandle DXIndexBufferContext9::_type_handle;
30 DXIndexBufferContext9::
43 DXIndexBufferContext9::
44 ~DXIndexBufferContext9() {
79 if (_ibuffer != NULL) {
80 if (DEBUG_INDEX_BUFFER && dxgsg9_cat.is_debug()) {
82 <<
"deleting index buffer " << _ibuffer <<
"\n";
85 if (DEBUG_INDEX_BUFFER)
87 RELEASE(_ibuffer, dxgsg9,
"index buffer", RELEASE_ONCE);
91 _ibuffer -> Release ( );
107 D3DFORMAT index_type =
116 _managed = scrn._managed_index_buffers;
119 usage = D3DUSAGE_WRITEONLY;
120 pool = D3DPOOL_MANAGED;
124 usage = D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC;
125 pool = D3DPOOL_DEFAULT;
134 hr = scrn._d3d_device->CreateIndexBuffer
135 (data_size, usage, index_type, pool, &_ibuffer, NULL);
138 while (scrn._dxgsg9 -> check_dx_allocation (hr, data_size, attempts));
142 <<
"CreateIndexBuffer failed" << D3DERRORSTRING(hr);
145 if (DEBUG_INDEX_BUFFER && dxgsg9_cat.is_debug()) {
147 <<
"creating index buffer " << _ibuffer <<
": "
148 << reader->get_num_vertices() <<
" indices ("
149 << reader->get_vertices_reader()->get_array_format()->get_column(0)->get_numeric_type()
164 nassertv(reader->get_object() ==
get_data());
165 Thread *current_thread = reader->get_current_thread();
169 PStatTimer timer(GraphicsStateGuardian::_create_index_buffer_pcollector,
187 nassertr(reader->get_object() ==
get_data(),
false);
188 Thread *current_thread = reader->get_current_thread();
190 nassertr(_ibuffer != NULL,
false);
192 const unsigned char *data_pointer = reader->get_read_pointer(force);
193 if (data_pointer == NULL) {
198 if (dxgsg9_cat.is_spam()) {
200 <<
"copying " << data_size
201 <<
" bytes into index buffer " << _ibuffer <<
"\n";
203 PStatTimer timer(GraphicsStateGuardian::_load_index_buffer_pcollector,
211 hr = _ibuffer->Lock(0, data_size, (
void **) &local_pointer, 0);
215 hr = _ibuffer->Lock(0, data_size, (
void **) &local_pointer, D3DLOCK_DISCARD);
219 <<
"IndexBuffer::Lock failed" << D3DERRORSTRING(hr);
223 GraphicsStateGuardian::_data_transferred_pcollector.add_level(data_size);
224 memcpy(local_pointer, data_pointer, data_size);
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...
static D3DFORMAT get_index_type(Geom::NumericType numeric_type)
Maps from the Geom's internal numeric type symbols to DirectX's.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
A table of objects that are saved within the graphics context for reference by handle later...
void dequeue_lru()
Removes the page from its AdaptiveLru.
void allocate_ibuffer(DXScreenData &scrn, const GeomPrimitivePipelineReader *reader)
Allocates index buffer memory.
GeomPrimitive * get_data() const
Returns the pointer to the client-side array data object.
void mark_unloaded()
Should be called after the buffer has been forced out of graphics memory.
bool upload_data(const GeomPrimitivePipelineReader *reader, bool force)
Copies the latest data from the client store to DirectX.
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
A thread; that is, a lightweight process.
virtual void evict_lru()
Evicts the page from the LRU.
void free_ibuffer()
Free index buffer.
void create_ibuffer(DXScreenData &scrn, const GeomPrimitivePipelineReader *reader)
Creates a new index buffer (but does not upload data to it).
TypeHandle is the identifier used to differentiate C++ class types.
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
void update_data_size_bytes(size_t new_data_size_bytes)
Should be called (usually by a derived class) when the on-card size of this object has changed...