mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
automatic build
This commit is contained in:
parent
13cdb21fb1
commit
ac3211ffc8
@ -1270,11 +1270,16 @@ release_texture(TextureContext *tc) {
|
|||||||
_texturing_state = 0; // just in case
|
_texturing_state = 0; // just in case
|
||||||
|
|
||||||
GLTexture *gltex = >c->_gltex;
|
GLTexture *gltex = >c->_gltex;
|
||||||
for (int i = 0; i < gltex->num_levels; ++i) {
|
if (gltex->allocated_buffer != NULL) {
|
||||||
gl_free(gltex->levels[i].pixmap);
|
nassertv(gltex->num_levels != 0);
|
||||||
gltex->levels[i].pixmap = NULL;
|
TinyTextureContext::get_class_type().dec_memory_usage(TypeHandle::MC_array, gltex->total_bytecount);
|
||||||
}
|
gl_free(gltex->allocated_buffer);
|
||||||
|
gltex->allocated_buffer = NULL;
|
||||||
|
gltex->total_bytecount = 0;
|
||||||
gltex->num_levels = 0;
|
gltex->num_levels = 0;
|
||||||
|
} else {
|
||||||
|
nassertv(gltex->num_levels == 0);
|
||||||
|
}
|
||||||
|
|
||||||
gtc->dequeue_lru();
|
gtc->dequeue_lru();
|
||||||
|
|
||||||
@ -1857,31 +1862,44 @@ setup_gltex(GLTexture *gltex, int x_size, int y_size, int num_levels) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
num_levels = min(num_levels, MAX_MIPMAP_LEVELS);
|
||||||
|
|
||||||
gltex->xsize = x_size;
|
gltex->xsize = x_size;
|
||||||
gltex->ysize = y_size;
|
gltex->ysize = y_size;
|
||||||
|
|
||||||
gltex->s_max = 1 << (s_bits + ZB_POINT_ST_FRAC_BITS);
|
gltex->s_max = 1 << (s_bits + ZB_POINT_ST_FRAC_BITS);
|
||||||
gltex->t_max = 1 << (t_bits + ZB_POINT_ST_FRAC_BITS);
|
gltex->t_max = 1 << (t_bits + ZB_POINT_ST_FRAC_BITS);
|
||||||
|
|
||||||
for (int i = 0; i < gltex->num_levels; ++i) {
|
|
||||||
gl_free(gltex->levels[i].pixmap);
|
|
||||||
gltex->levels[i].pixmap = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
gltex->num_levels = num_levels;
|
gltex->num_levels = num_levels;
|
||||||
|
|
||||||
// We allocate one big buffer, large enough to include all the
|
// We allocate one big buffer, large enough to include all the
|
||||||
// mipmap levels, and index into that buffer for each level. This
|
// mipmap levels, and index into that buffer for each level. This
|
||||||
// cuts down on the number of individual alloc calls we have to make
|
// cuts down on the number of individual alloc calls we have to make
|
||||||
// for each texture.
|
// for each texture.
|
||||||
gltex->total_bytecount = (x_size * y_size * 4);
|
int total_bytecount = 0;
|
||||||
if (num_levels > 1) {
|
|
||||||
gltex->total_bytecount = (gltex->total_bytecount * 4 + 3) / 3;
|
// Count up the total bytes required for all mipmap levels.
|
||||||
|
{
|
||||||
|
int x = x_size;
|
||||||
|
int y = y_size;
|
||||||
|
for (int level = 0; level < num_levels; ++level) {
|
||||||
|
int bytecount = x * y * 4;
|
||||||
|
total_bytecount += bytecount;
|
||||||
|
x = max((x >> 1), 1);
|
||||||
|
y = max((y >> 1), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gltex->total_bytecount != total_bytecount) {
|
||||||
|
gl_free(gltex->allocated_buffer);
|
||||||
|
TinyTextureContext::get_class_type().dec_memory_usage(TypeHandle::MC_array, gltex->total_bytecount);
|
||||||
|
gltex->allocated_buffer = (void *)gl_malloc(total_bytecount);
|
||||||
|
gltex->total_bytecount = total_bytecount;
|
||||||
|
TinyTextureContext::get_class_type().inc_memory_usage(TypeHandle::MC_array, total_bytecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
gltex->allocated_buffer = (void *)gl_malloc(gltex->total_bytecount);
|
|
||||||
char *next_buffer = (char *)gltex->allocated_buffer;
|
char *next_buffer = (char *)gltex->allocated_buffer;
|
||||||
char *end_of_buffer = next_buffer + gltex->total_bytecount;
|
char *end_of_buffer = next_buffer + total_bytecount;
|
||||||
|
|
||||||
int level = 0;
|
int level = 0;
|
||||||
ZTextureLevel *dest = NULL;
|
ZTextureLevel *dest = NULL;
|
||||||
|
@ -23,6 +23,8 @@ TinyTextureContext(PreparedGraphicsObjects *pgo, Texture *tex) :
|
|||||||
TextureContext(pgo, tex), SimpleLruPage(0)
|
TextureContext(pgo, tex), SimpleLruPage(0)
|
||||||
{
|
{
|
||||||
_gltex.num_levels = 0;
|
_gltex.num_levels = 0;
|
||||||
|
_gltex.allocated_buffer = NULL;
|
||||||
|
_gltex.total_bytecount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -32,7 +34,7 @@ TinyTextureContext(PreparedGraphicsObjects *pgo, Texture *tex) :
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE TinyTextureContext::
|
INLINE TinyTextureContext::
|
||||||
~TinyTextureContext() {
|
~TinyTextureContext() {
|
||||||
nassertv(_gltex.num_levels == 0);
|
nassertv(_gltex.num_levels == 0 && _gltex.allocated_buffer == NULL && _gltex.total_bytecount == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -36,11 +36,17 @@ void TinyTextureContext::
|
|||||||
evict_lru() {
|
evict_lru() {
|
||||||
dequeue_lru();
|
dequeue_lru();
|
||||||
|
|
||||||
for (int i = 0; i < _gltex.num_levels; ++i) {
|
GLTexture *gltex = &_gltex;
|
||||||
gl_free(_gltex.levels[i].pixmap);
|
if (gltex->allocated_buffer != NULL) {
|
||||||
_gltex.levels[i].pixmap = NULL;
|
nassertv(gltex->num_levels != 0);
|
||||||
|
TinyTextureContext::get_class_type().dec_memory_usage(TypeHandle::MC_array, gltex->total_bytecount);
|
||||||
|
gl_free(gltex->allocated_buffer);
|
||||||
|
gltex->allocated_buffer = NULL;
|
||||||
|
gltex->total_bytecount = 0;
|
||||||
|
gltex->num_levels = 0;
|
||||||
|
} else {
|
||||||
|
nassertv(gltex->num_levels == 0);
|
||||||
}
|
}
|
||||||
_gltex.num_levels = 0;
|
|
||||||
|
|
||||||
set_resident(false);
|
set_resident(false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user