20 #define DEBUG_INDEX_BUFFER false
22 TypeHandle DXIndexBufferContext9::_type_handle;
27 DXIndexBufferContext9::
37 DXIndexBufferContext9::
38 ~DXIndexBufferContext9() {
65 if (_ibuffer !=
nullptr) {
66 if (DEBUG_INDEX_BUFFER && dxgsg9_cat.is_debug()) {
68 <<
"deleting index buffer " << _ibuffer <<
"\n";
71 if (DEBUG_INDEX_BUFFER) {
72 RELEASE(_ibuffer, dxgsg9,
"index buffer", RELEASE_ONCE);
88 D3DFORMAT index_type =
97 if (reader->get_index_type() == GeomEnums::NT_uint8) {
102 _managed = scrn._managed_index_buffers;
105 usage = D3DUSAGE_WRITEONLY;
106 pool = D3DPOOL_MANAGED;
110 usage = D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC;
111 pool = D3DPOOL_DEFAULT;
120 hr = scrn._d3d_device->CreateIndexBuffer
121 (data_size, usage, index_type, pool, &_ibuffer,
nullptr);
124 while (scrn._dxgsg9 -> check_dx_allocation (hr, data_size, attempts));
128 <<
"CreateIndexBuffer failed" << D3DERRORSTRING(hr);
131 if (DEBUG_INDEX_BUFFER && dxgsg9_cat.is_debug()) {
133 <<
"creating index buffer " << _ibuffer <<
": "
134 << reader->get_num_vertices() <<
" indices ("
135 << reader->get_index_type() <<
")\n";
146 nassertv(reader->get_object() ==
get_data());
147 Thread *current_thread = reader->get_current_thread();
151 PStatTimer timer(GraphicsStateGuardian::_create_index_buffer_pcollector,
162 nassertr(reader->get_object() ==
get_data(),
false);
163 Thread *current_thread = reader->get_current_thread();
165 nassertr(_ibuffer !=
nullptr,
false);
167 const unsigned char *data_pointer = reader->get_read_pointer(force);
168 if (data_pointer ==
nullptr) {
173 if (reader->get_index_type() == GeomEnums::NT_uint8) {
178 if (dxgsg9_cat.is_spam()) {
180 <<
"copying " << data_size
181 <<
" bytes into index buffer " << _ibuffer <<
"\n";
183 PStatTimer timer(GraphicsStateGuardian::_load_index_buffer_pcollector,
190 hr = _ibuffer->Lock(0, data_size, (
void **) &local_pointer, 0);
192 hr = _ibuffer->Lock(0, data_size, (
void **) &local_pointer, D3DLOCK_DISCARD);
196 <<
"IndexBuffer::Lock failed" << D3DERRORSTRING(hr);
200 GraphicsStateGuardian::_data_transferred_pcollector.add_level(data_size);
202 if (reader->get_index_type() == GeomEnums::NT_uint8) {
204 uint16_t *ptr = (uint16_t *)local_pointer;
205 for (
size_t i = 0; i < data_size; i += 2) {
206 *ptr++ = (uint16_t)*data_pointer++;
209 memcpy(local_pointer, data_pointer, data_size);
void dequeue_lru()
Removes the page from its AdaptiveLru.
static D3DFORMAT get_index_type(Geom::NumericType numeric_type)
Maps from the Geom's internal numeric type symbols to DirectX's.
bool upload_data(const GeomPrimitivePipelineReader *reader, bool force)
Copies the latest data from the client store to DirectX.
void free_ibuffer()
Free index buffer.
void allocate_ibuffer(DXScreenData &scrn, const GeomPrimitivePipelineReader *reader)
Allocates index buffer memory.
virtual void evict_lru()
Evicts the page from the LRU.
void create_ibuffer(DXScreenData &scrn, const GeomPrimitivePipelineReader *reader)
Creates a new index buffer (but does not upload data to it).
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This is a special class object that holds all the information returned by a particular GSG to indicat...
void mark_unloaded()
Should be called after the buffer has been forced out of graphics memory.
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.
GeomPrimitive * get_data() const
Returns the pointer to the client-side array data object.
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.
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.
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.