Discarded work on mipmaps.

This commit is contained in:
Joel de Vahl 2007-07-22 11:46:25 +00:00
parent 14745012f3
commit 2165a728c2
5 changed files with 111 additions and 4 deletions

View file

@ -222,7 +222,35 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data)
return tex; return tex;
} }
/*
int gfx_load_mip_texture_raw(int w, int h, int format, const void *data)
{
// grab texture
int tex = first_free_texture;
first_free_texture = textures[tex].next;
textures[tex].next = -1;
// set data and return
// TODO: should be RGBA, not BGRA
dbg_msg("gfx", "%d = %dx%d", tex, w, h);
dbg_assert(format == IMG_RGBA, "not an RGBA image");
unsigned mip_w = w;
unsigned mip_h = h;
unsigned level = 0;
const unsigned char *ptr = (const unsigned char*)data;
while(mip_w > 0 && mip_h > 0)
{
dbg_msg("gfx mip", "%d = %dx%d", level, mip_w, mip_h);
textures[tex].tex.data2d_mip(mip_w, mip_h, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, level, ptr);
level++;
ptr = ptr + mip_w*mip_h*4;
mip_w = mip_w>>1;
mip_h = mip_h>>1;
}
return tex;
}
*/
// simple uncompressed RGBA loaders // simple uncompressed RGBA loaders
int gfx_load_texture(const char *filename) int gfx_load_texture(const char *filename)
{ {

View file

@ -99,6 +99,7 @@ int gfx_load_texture(const char *filename);
<gfx_unload_texture> <gfx_unload_texture>
*/ */
int gfx_load_texture_raw(int w, int h, int format, const void *data); int gfx_load_texture_raw(int w, int h, int format, const void *data);
//int gfx_load_mip_texture_raw(int w, int h, int format, const void *data);
/* /*
Function: gfx_texture_set Function: gfx_texture_set

View file

@ -5,7 +5,84 @@
static int map_textures[64] = {0}; static int map_textures[64] = {0};
static int count = 0; static int count = 0;
/*
static void calc_mipmaps(void *data_in, unsigned width, unsigned height, void *data_out)
{
unsigned char *src = (unsigned char*)data_in;
unsigned char *dst = (unsigned char*)data_out;
unsigned mip_w = width;
unsigned mip_h = height;
unsigned prev_w;
unsigned prev_h;
// Highest level - no mod
for(unsigned x = 0; x < mip_w; x++)
{
for(unsigned y = 0; y < mip_h; y++)
{
unsigned i = (y * mip_w + x)<<2;
for(unsigned j = 0; j < 4; j++)
dst[i+j] = src[i+j];
}
}
src = dst;
dst += mip_w * mip_h * 4;
prev_w = mip_w;
prev_h = mip_h;
mip_w = mip_w>>1;
mip_h = mip_h>>1;
while(mip_w > 0 && mip_h > 0)
{
for(unsigned x = 0; x < mip_w; x++)
{
for(unsigned y = 0; y < mip_h; y++)
{
unsigned i = (y * mip_w + x)<<2;
unsigned r = 0;
unsigned g = 0;
unsigned b = 0;
unsigned a = 0;
r += src[(((y<<1) * prev_w + (x<<1))<<2)];
g += src[(((y<<1) * prev_w + (x<<1))<<2)+1];
b += src[(((y<<1) * prev_w + (x<<1))<<2)+2];
a += src[(((y<<1) * prev_w + (x<<1))<<2)+3];
r += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)];
g += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+1];
b += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+2];
a += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+3];
r += src[((((y+1)<<1) * prev_w + (x<<1))<<2)];
g += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+1];
b += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+2];
a += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+3];
r += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)];
g += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+1];
b += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+2];
a += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+3];
dst[i] = r>>2;
dst[i+1] = g>>2;
dst[i+2] = b>>2;
dst[i+3] = a>>2;
}
}
src = dst;
dst = dst + mip_w*mip_h*4;
prev_w = mip_w;
prev_h = mip_h;
mip_w = mip_w>>1;
mip_h = mip_h>>1;
}
}
*/
extern int DEBUGTEST_MAPIMAGE; extern int DEBUGTEST_MAPIMAGE;
int img_init() int img_init()
@ -22,13 +99,16 @@ int img_init()
} }
} }
//void *data_res = (void*)mem_alloc(1024*1024*4*2, 16);
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
mapres_image *img = (mapres_image *)map_get_item(start+i, 0, 0); mapres_image *img = (mapres_image *)map_get_item(start+i, 0, 0);
void *data = map_get_data(img->image_data); void *data = map_get_data(img->image_data);
//calc_mipmaps(data, img->width, img->height, data_res);
map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data); map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data);
} }
//mem_free(data_res);
return count; return count;
} }

View file

@ -44,7 +44,6 @@ void tilemap_render(float scale, int fg)
float frac = (1.0f/1024.0f);//2.0f; //2.0f; float frac = (1.0f/1024.0f);//2.0f; //2.0f;
float texsize = 1024.0f; float texsize = 1024.0f;
float nudge = 0.5f/texsize; float nudge = 0.5f/texsize;
const float s = 1.0f;
for(int y = 0; y < tmap->height; y++) for(int y = 0; y < tmap->height; y++)
for(int x = 0; x < tmap->width; x++, c++) for(int x = 0; x < tmap->width; x++, c++)
{ {

View file

@ -935,7 +935,6 @@ int player::handle_weapons()
// check if we hit anything along the way // check if we hit anything along the way
int type = OBJTYPE_PLAYER; int type = OBJTYPE_PLAYER;
entity *ents[64]; entity *ents[64];
float reach = 20.0f;
vec2 lookdir(direction.x > 0.0f ? 1.0f : -1.0f, 0.0f); vec2 lookdir(direction.x > 0.0f ? 1.0f : -1.0f, 0.0f);
vec2 dir = lookdir * data->weapons[active_weapon].meleereach; vec2 dir = lookdir * data->weapons[active_weapon].meleereach;
float radius = length(dir * 0.5f); float radius = length(dir * 0.5f);