- Revert changes accidentally committed.

This is WIP code using hash tables for texture lookups. Not yet stable.
This commit is contained in:
Couriersud 2010-02-12 22:45:29 +00:00
parent 377fc28f9b
commit a7dea2f6eb

View File

@ -117,12 +117,6 @@ typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuin
#define GL_DEPTH_COMPONENT32 0x81A7 #define GL_DEPTH_COMPONENT32 0x81A7
#endif #endif
//#define OLD_CODE 1
#ifndef OLD_CODE
#define HASH_SIZE ((1<<10)+1)
#define OVERFLOW_SIZE (1<<10)
#endif
// OSD headers // OSD headers
#include "osdsdl.h" #include "osdsdl.h"
@ -169,9 +163,7 @@ typedef void (*texture_copy_func)(texture_info *texture, const render_texinfo *t
/* texture_info holds information about a texture */ /* texture_info holds information about a texture */
struct _texture_info struct _texture_info
{ {
#ifdef OLD_CODE
texture_info * next; // next texture in the list texture_info * next; // next texture in the list
#endif
HashT hash; // hash value for the texture (must be >= pointer size) HashT hash; // hash value for the texture (must be >= pointer size)
UINT32 flags; // rendering flags UINT32 flags; // rendering flags
render_texinfo texinfo; // copy of the texture info render_texinfo texinfo; // copy of the texture info
@ -228,11 +220,7 @@ struct _sdl_info
int initialized; // is everything well initialized, i.e. all GL stuff etc. int initialized; // is everything well initialized, i.e. all GL stuff etc.
// 3D info (GL mode only) // 3D info (GL mode only)
#ifdef OLD_CODE
texture_info * texlist; // list of active textures texture_info * texlist; // list of active textures
#else
texture_info * texhash[HASH_SIZE + OVERFLOW_SIZE];
#endif
int last_blendmode; // previous blendmode int last_blendmode; // previous blendmode
INT32 texture_max_width; // texture maximum width INT32 texture_max_width; // texture maximum width
INT32 texture_max_height; // texture maximum height INT32 texture_max_height; // texture maximum height
@ -295,19 +283,10 @@ static const line_aa_step line_aa_4step[] =
// INLINES // INLINES
//============================================================ //============================================================
#ifdef OLD_CODE
INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags) INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags)
{ {
return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)); return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
} }
#else
INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags)
{
HashT h = (HashT)texture ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
//printf("hash %d\n", (int) h % HASH_SIZE);
return (h >> 8) % HASH_SIZE;
}
#endif
INLINE void set_blendmode(sdl_info *sdl, int blendmode) INLINE void set_blendmode(sdl_info *sdl, int blendmode)
{ {
@ -2560,24 +2539,9 @@ static texture_info *texture_create(sdl_window_info *window, const render_texinf
} }
// add us to the texture list // add us to the texture list
#ifdef OLD_CODE
texture->next = sdl->texlist; texture->next = sdl->texlist;
sdl->texlist = texture; sdl->texlist = texture;
#else
if (sdl->texhash[texture->hash] == NULL)
sdl->texhash[texture->hash] = texture;
else
{
int i;
for (i = HASH_SIZE; i < HASH_SIZE + OVERFLOW_SIZE; i++)
if (sdl->texhash[i] == NULL)
{
sdl->texhash[i] = texture;
break;
}
assert(i < HASH_SIZE + OVERFLOW_SIZE);
}
#endif
if(sdl->usevbo) if(sdl->usevbo)
{ {
// Generate And Bind The Texture Coordinate Buffer // Generate And Bind The Texture Coordinate Buffer
@ -2704,7 +2668,6 @@ static void texture_set_data(texture_info *texture, const render_texinfo *texsou
// texture_find // texture_find
//============================================================ //============================================================
#ifdef OLD_CODE
static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim) static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim)
{ {
HashT texhash = texture_compute_hash(&prim->texture, prim->flags); HashT texhash = texture_compute_hash(&prim->texture, prim->flags);
@ -2723,55 +2686,6 @@ static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim)
// nothing found // nothing found
return NULL; return NULL;
} }
#else
#if 0
static int compare_texinfo(render_texinfo *t1, render_texinfo *t2)
{
if (t1->base == t2->base &&
t1->width == t2->width &&
t1->height == t2->height &&
t1->rowpixels == t2->rowpixels)
return 1;
else
return 0;
}
#endif
static int compare_texture_primitive(const texture_info *texture, const render_primitive *prim)
{
if (texture->texinfo.base == prim->texture.base &&
texture->texinfo.width == prim->texture.width &&
texture->texinfo.height == prim->texture.height &&
texture->texinfo.rowpixels == prim->texture.rowpixels &&
((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
return 1;
else
return 0;
}
static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim)
{
HashT texhash = texture_compute_hash(&prim->texture, prim->flags);
texture_info *texture;
texture = sdl->texhash[texhash];
if (texture != NULL)
{
int i;
if (compare_texture_primitive(texture, prim))
return texture;
for (i=HASH_SIZE; i<HASH_SIZE + OVERFLOW_SIZE; i++)
{
texture = sdl->texhash[i];
if (texture != NULL && compare_texture_primitive(texture, prim))
return texture;
}
}
return NULL;
}
#endif
//============================================================ //============================================================
// texture_update // texture_update
@ -3113,13 +3027,8 @@ static void texture_all_disable(sdl_info *sdl)
static void drawogl_destroy_all_textures(sdl_window_info *window) static void drawogl_destroy_all_textures(sdl_window_info *window)
{ {
sdl_info *sdl = (sdl_info *) window->dxdata; sdl_info *sdl = (sdl_info *) window->dxdata;
texture_info *texture = NULL; texture_info *next_texture=NULL, *texture = NULL;
int lock=FALSE; int lock=FALSE;
#ifdef OLD_CODE
texture_info *next_texture=NULL;
#else
int i;
#endif
if (sdl == NULL) if (sdl == NULL)
return; return;
@ -3137,26 +3046,16 @@ static void drawogl_destroy_all_textures(sdl_window_info *window)
osd_lock_acquire(window->primlist->lock); osd_lock_acquire(window->primlist->lock);
} }
texture = sdl->texlist;
glFinish(); glFinish();
texture_all_disable(sdl); texture_all_disable(sdl);
glFinish(); glFinish();
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
#ifdef OLD_CODE
texture = sdl->texlist;
while (texture) while (texture)
{ {
next_texture = texture->next; next_texture = texture->next;
#else
i=0;
while (i<HASH_SIZE+OVERFLOW_SIZE)
{
texture = sdl->texhash[i];
sdl->texhash[i] = NULL;
if (texture != NULL)
{
#endif
if(sdl->usevbo) if(sdl->usevbo)
{ {
@ -3195,15 +3094,10 @@ static void drawogl_destroy_all_textures(sdl_window_info *window)
texture->data_own=FALSE; texture->data_own=FALSE;
} }
free(texture); free(texture);
#ifdef OLD_CODE
texture = next_texture; texture = next_texture;
} }
sdl->texlist = NULL; sdl->texlist = NULL;
#else
}
i++;
}
#endif
if ( sdl->useglsl ) if ( sdl->useglsl )
{ {
glsl_shader_free(sdl->glsl); glsl_shader_free(sdl->glsl);