Fixed bug with the video alpha channel being unitialized memory

Added dynamic texture reloading (experimental)
This commit is contained in:
cholleme 2003-11-02 19:11:27 +00:00
parent 174d711f9d
commit d869a71437
2 changed files with 136 additions and 48 deletions

View file

@ -1270,49 +1270,27 @@ int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolea
return texture_extension_number-2;
}
*/
/*
================
GL_CacheTexture
GL_LoadTextureFromFile
Loads a texture
Load a cache texture from its file
================
*/
gltexture_t *GL_CacheTexture (char *filename, qboolean mipmap, int type)
static void GL_LoadTextureFromFile(gltexture_t *glt)
{
int i, width, height, gwidth, gheight, dwidth, dheight;
gltexture_t *glt;
char *glossname;
char *detailname;
char *basename;
char *filename = glt->identifier;
// see if the texture is allready present
if (filename[0])
{
for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
{
if (!strcmp (filename, glt->identifier) && (glt->mipmap == mipmap))
{
//found one, return it...
return &gltextures[i];
}
}
}
// load a new one
glt = &gltextures[numgltextures];
numgltextures++;
//Con_Printf("Load texture: %s %i %i\n",identifier,width,height);
strncpy (glt->identifier, filename, sizeof(glt->identifier));
glt->texnum = texture_extension_number;
texture_extension_number++;
glt->mipmap = mipmap;
glt->dynamic = NULL;
if (type == TEXTURE_CUBEMAP) {
Con_Printf("Loading texture %s\n", glt->identifier);
if (glt->loadtype == TEXTURE_CUBEMAP) {
GL_LoadCubemapTexture(glt);
return glt;
return;
}
if (!strcmp(filename,"$white")) {
@ -1326,14 +1304,14 @@ gltexture_t *GL_CacheTexture (char *filename, qboolean mipmap, int type)
} else if (!strcmp(COM_FileExtension(filename),"roq")) {
Con_Printf("Loading video texture from %s\n",filename);
Roq_SetupTexture(glt, filename) ;
return glt;
return;
} else {
int rez;
char b[MAX_QPATH*3+2], *pb, *b2;
qboolean hasgloss = false;
qboolean hasdetailbump = false;
if (type == TEXTURE_NORMAL) {
if (glt->loadtype == TEXTURE_NORMAL) {
strcpy(b,filename);
pb = b;
@ -1398,20 +1376,68 @@ gltexture_t *GL_CacheTexture (char *filename, qboolean mipmap, int type)
GL_Bind(glt->texnum);
glt->width = width;
glt->height = height;
glt->gltype = GL_TEXTURE_2D;
if (type == TEXTURE_RGB) {
GL_Upload32 (&trans[0], width, height, mipmap, true);
glt->type = GL_TEXTURE_2D;
} else if (type == TEXTURE_NORMAL) {
GL_UploadNormal(&trans[0], width, height, mipmap);
glt->type = GL_TEXTURE_2D;
if (glt->loadtype == TEXTURE_RGB) {
GL_Upload32 (&trans[0], width, height, glt->mipmap, true);
} else if (glt->loadtype == TEXTURE_NORMAL) {
GL_UploadNormal(&trans[0], width, height, glt->mipmap);
};
//texture_extension_number++;
return;
}
/*
================
GL_CacheTexture
Add a texture to the cache
================
*/
gltexture_t *GL_CacheTexture (char *filename, qboolean mipmap, int type)
{
gltexture_t *glt;
int i;
// see if the texture is allready present
if (filename[0])
{
for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
{
if (!strcmp (filename, glt->identifier) && (glt->mipmap == mipmap))
{
//found one, return it...
return &gltextures[i];
}
}
}
// load a new one
glt = &gltextures[numgltextures];
numgltextures++;
//Con_Printf("Load texture: %s %i %i\n",identifier,width,height);
strncpy (glt->identifier, filename, sizeof(glt->identifier));
glt->texnum = texture_extension_number;
texture_extension_number++;
glt->mipmap = mipmap;
glt->dynamic = NULL;
glt->loadtype = type;
GL_LoadTextureFromFile(glt);
return glt;
}
/*
================
GL_ShutdownTextures
Free some memory allocated for textures
================
*/
void GL_ShutdownTextures(void) {
int i;
gltexture_t *glt;
@ -1425,6 +1451,27 @@ void GL_ShutdownTextures(void) {
}
}
void ReloadTextures_f(void) {
int i;
gltexture_t *glt;
Con_Printf("=================================\n");
//Free old memory
Con_Printf("GL_ShutdownTextures...\n");
Con_Printf("Reloading textures...\n");
scr_disabled_for_loading = true;
GL_ShutdownTextures();
//Reload
for (i=0, glt=gltextures ; i<numgltextures ; i++, glt++)
{
//found one, return it...
GL_LoadTextureFromFile(glt);
}
scr_disabled_for_loading = false;
Con_Printf("=================================\n");
}
void Print_Tex_Cache_f(void) {
int i;
gltexture_t *glt;
@ -1433,7 +1480,7 @@ void Print_Tex_Cache_f(void) {
{
//found one, return it...
Con_Printf("%s: texnum(%i) type(%i) dynamic(%i) width(%i) heigt(%i)\n",
glt->identifier, glt->texnum, glt->type, (glt->dynamic == NULL ? 0 : 1), glt->width, glt->height);
glt->identifier, glt->texnum, glt->loadtype, (glt->dynamic == NULL ? 0 : 1), glt->width, glt->height);
}
}
@ -1499,7 +1546,7 @@ int GL_LoadCubemapTexture (gltexture_t *glt)
texturemode = GL_RGBA;
}
glt->type = GL_TEXTURE_CUBE_MAP_ARB;
glt->gltype = GL_TEXTURE_CUBE_MAP_ARB;
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, glt->texnum);
@ -1525,7 +1572,7 @@ int GL_LoadCubemapTexture (gltexture_t *glt)
glt->width = width;
glt->height = height;
glt->mipmap = false;
glt->type = GL_TEXTURE_CUBE_MAP_ARB;
glt->gltype = GL_TEXTURE_CUBE_MAP_ARB;
texture_extension_number++;
@ -1592,7 +1639,7 @@ int GL_Load2DAttenTexture(void)
if (DistSq < radiussq) {
byte value;
float FallOff = (radiussq - DistSq) / radiussq;
FallOff *= FallOff;
//FallOff *= FallOff;
value = FallOff*255.0;
data[t * ATTEN_VOLUME_SIZE + s] = value;
} else {
@ -1623,6 +1670,35 @@ int GL_Load2DAttenTexture(void)
return texture_extension_number-1;
}
int GL_LoadBlackTexture(void)
{
char data[4];
int err;
data[0] = data[1] = data[2] = data[3] = 0;
GL_Bind(texture_extension_number);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_extension_number++;
err = glGetError();
if (err != GL_NO_ERROR) {
Con_Printf("%s",gluErrorString(err));
}
return texture_extension_number-1;
}
/*
===============
PENTA:

View file

@ -25,6 +25,11 @@ to fit in the disc cache)
#include "quakedef.h"
#include "roq/roq.h"
extern unsigned trans[1024*1024]; //just a static scratch buffer (declared in textures.c)
void Roq_UpdateTexture(gltexture_t *tex);
void Roq_ConvertColors(roq_info *ri);
/**
* Console command that prints some information about a video
*/
@ -54,6 +59,7 @@ void Roq_Info_f(void) {
*/
void Roq_SetupTexture(gltexture_t *tex,char *filename) {
roq_info *ri;
int i;
if((ri = roq_open(filename)) == NULL) {
Con_Printf("Error loading video %s\n",filename);
@ -63,6 +69,14 @@ void Roq_SetupTexture(gltexture_t *tex,char *filename) {
tex->dynamic = ri;
tex->width = ri->width;
tex->height = ri->height;
//Load one frame as start frame
/* roq_read_frame(ri);
Roq_ConvertColors(ri);
GL_Bind(tex->texnum);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, ri->width, ri->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/
}
/**
@ -79,8 +93,6 @@ void Roq_FreeTexture(gltexture_t *tex) {
roq_close(ri);
}
extern unsigned trans[1024*1024]; //just a static scratch buffer (declared in textures.c)
/**
* Converts the yuv to usable rgb data.
*/
@ -110,11 +122,11 @@ void Roq_ConvertColors(roq_info *ri) {
(*c++) = limit(r + y1);
(*c++) = limit(g + y1);
(*c++) = limit(b + y1);
c++; //alpha
(*c++) = 255; //alpha
(*c++) = limit(r + y2);
(*c++) = limit(g + y2);
(*c++) = limit(b + y2);
c++; //alpha
(*c++) = 255; //alpha
}
if(j & 0x01) { pb += ri->width/2; pc += ri->width/2; }
}
@ -146,7 +158,7 @@ void Roq_UpdateTexture(gltexture_t *tex) {
} else if (ri->frame_num >= ri->num_frames) {
roq_reset_stream (ri);
//read frames untill we have catched up with the curent time
} else {
} else {
while ((host_time - ri->lastframe_time) > (1.0/30.0)) {
ri->lastframe_time = host_time;
roq_read_frame(ri);
@ -163,4 +175,4 @@ void Roq_UpdateTexture(gltexture_t *tex) {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
}
}