+
#include "quakedef.h"
cvar_t r_max_size = {CVAR_SAVE, "r_max_size", "2048"};
cvar_t r_lerpimages = {CVAR_SAVE, "r_lerpimages", "1"};
cvar_t r_precachetextures = {CVAR_SAVE, "r_precachetextures", "1"};
-int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR; //NEAREST;
+int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
int gl_filter_mag = GL_LINEAR;
#define GLTEXF_DESTROYED 0x00040000
// size of images which hold fragment textures, ignores picmip and max_size
-//#define BLOCK_SIZE 256
static int block_size;
// really this number only governs gltexnuminuse
return glt->image->texnum;
}
-static void R_FreeTexture(gltexture_t *glt)
+void R_FreeTexture(rtexture_t *rt)
{
- gltexture_t **gltpointer;
+ gltexture_t *glt, **gltpointer;
gltextureimage_t *image, **gltimagepointer;
GLuint texnum;
+ glt = (gltexture_t *)rt;
if (glt == NULL)
Host_Error("R_FreeTexture: texture == NULL\n");
{
texnum = image->texnum;
gltexnuminuse[image->texnum] = 0;
- glDeleteTextures(1, &texnum);
+ qglDeleteTextures(1, &texnum);
}
if (image->blockallocation)
Mem_Free(image->blockallocation);
pool = Mem_Alloc(texturemempool, sizeof(gltexturepool_t));
if (pool == NULL)
return NULL;
- //memset(pool, 0, sizeof(gltexturepool_t));
pool->next = gltexturepoolchain;
gltexturepoolchain = pool;
pool->sentinel = TEXTUREPOOL_SENTINEL;
else
Host_Error("R_FreeTexturePool: pool not linked\n");
while (pool->gltchain)
- R_FreeTexture(pool->gltchain);
+ R_FreeTexture((rtexture_t *)pool->gltchain);
if (pool->imagechain)
Sys_Error("R_FreeTexturePool: not all images freed\n");
Mem_Free(pool);
static void r_textures_start(void)
{
// deal with size limits of various drivers (3dfx in particular)
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &realmaxsize);
+ qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &realmaxsize);
CHECKGLERROR
// use the largest scrap texture size we can (not sure if this is really a good idea)
texturedatamempool = Mem_AllocPool("Texture Storage (not yet uploaded)");
textureprocessingmempool = Mem_AllocPool("Texture Processing Buffers");
gltexnuminuse = Mem_Alloc(texturemempool, MAX_GLTEXTURES);
- //memset(gltexnuminuse, 0, MAX_GLTEXTURES);
}
static void r_textures_shutdown(void)
R_FreeTexturePool(&temp);
}
- /*
- if (resizebuffer) Mem_Free(resizebuffer);resizebuffer = NULL;
- if (colorconvertbuffer) Mem_Free(colorconvertbuffer);colorconvertbuffer = NULL;
- if (texturebuffer) Mem_Free(texturebuffer);texturebuffer = NULL;
- if (gltexnuminuse) Mem_Free(gltexnuminuse);gltexnuminuse = NULL;
- */
resizebuffersize = 0;
texturebuffersize = 0;
resizebuffer = NULL;
continue;
if (image->glformat != texinfo->glformat || image->glinternalformat != texinfo->glinternalformat)
continue;
+ if (glt->width > image->width || glt->height > image->height)
+ continue;
// got a fragments texture, find a place in it if we can
- best = block_size;
- for (best = block_size, i = 0;i < block_size - w;i += texinfo->align)
+ for (best = image->width, i = 0;i < image->width - w;i += texinfo->align)
{
for (best2 = 0, j = 0;j < w;j++)
{
}
}
- if (best + h > block_size)
+ if (best + h > image->height)
continue;
for (i = 0;i < w;i++)
image = Mem_Alloc(texturemempool, sizeof(gltextureimage_t));
if (image == NULL)
Sys_Error("R_FindImageForTexture: ran out of memory\n");
- //memset(image, 0, sizeof(*image));
image->type = GLIMAGETYPE_FRAGMENTS;
- image->width = block_size;
- image->height = block_size;
- image->blockallocation = Mem_Alloc(texturemempool, block_size * sizeof(short));
- memset(image->blockallocation, 0, block_size * sizeof(short));
+ // make sure the created image is big enough for the fragment
+ for (image->width = block_size;image->width < glt->width;image->width <<= 1);
+ for (image->height = block_size;image->height < glt->height;image->height <<= 1);
+ image->blockallocation = Mem_Alloc(texturemempool, image->width * sizeof(short));
+ memset(image->blockallocation, 0, image->width * sizeof(short));
x = 0;
y = 0;
image = Mem_Alloc(texturemempool, sizeof(gltextureimage_t));
if (image == NULL)
Sys_Error("R_FindImageForTexture: ran out of memory\n");
- //memset(image, 0, sizeof(*image));
image->type = GLIMAGETYPE_TILE;
image->blockallocation = NULL;
{
gltexture_t *glt;
glt = Mem_Alloc(texturemempool, sizeof(gltexture_t));
- //memset(glt, 0, sizeof(gltexture_t));
if (identifier)
{
glt->identifier = Mem_Alloc(texturemempool, strlen(identifier)+1);
texinfo = R_GetTexTypeInfo(textype, flags);
- // data can be NULL
-// if (data == NULL)
-// Host_Error("R_LoadTexture: \"%s\" has no data\n", identifier);
-
if (flags & TEXF_FRAGMENT)
- {
- if (width > block_size || height > block_size)
- Host_Error("R_LoadTexture: fragment too big, must be no more than %dx%d\n", block_size, block_size);
if ((width * texinfo->internalbytesperpixel) & 3)
Host_Error("R_LoadTexture: incompatible width for fragment");
- }
// clear the alpha flag if the texture has no transparent pixels
switch(textype)
return (rtexture_t *)glt; // exact match, use existing
}
Con_Printf("R_LoadTexture: cache mismatch on %s, replacing old texture\n", identifier);
- R_FreeTexture(glt);
+ R_FreeTexture((rtexture_t *)glt);
}
return (rtexture_t *)R_SetupTexture(pool, identifier, crc, width, height, flags | GLTEXF_UPLOAD, texinfo, data, NULL, NULL, 0);
texinfo = R_GetTexTypeInfo(textype, flags);
- // no function is supported, for odd uses
-// if (generate == NULL)
-// Host_Error("R_ProceduralTexture: \"%s\" has no generate function\n", identifier);
if (flags & TEXF_FRAGMENT)
- {
- if (width > block_size || height > block_size)
- Host_Error("R_ProceduralTexture: fragment too big, must be no more than %dx%d\n", block_size, block_size);
if ((width * texinfo->internalbytesperpixel) & 3)
Host_Error("R_ProceduralTexture: incompatible width for fragment");
- }
// see if the texture is already present
if (identifier && (glt = R_FindTexture(pool, identifier)))
return (rtexture_t *)glt; // exact match, use existing
}
Con_Printf("R_LoadTexture: cache mismatch, replacing old texture\n");
- R_FreeTexture(glt);
+ R_FreeTexture((rtexture_t *)glt);
}
return (rtexture_t *)R_SetupTexture(pool, identifier, 0, width, height, flags | GLTEXF_PROCEDURAL | GLTEXF_UPLOAD, texinfo, NULL, generate, proceduraldata, proceduraldatasize);
if (data == NULL)
Host_Error("R_UpdateTexture: no data supplied\n");
glt = (gltexture_t *)rt;
- /*
- if (!(glt->flags & GLTEXF_PROCEDURAL))
- {
- if (glt->inputtexels == NULL)
- {
- glt->inputtexels = Mem_Alloc(texturedatamempool, glt->width * glt->height * glt->textype->inputbytesperpixel);
- if (glt->inputtexels == NULL)
- Host_Error("R_UpdateTexture: ran out of memory\n");
- }
- memcpy(glt->inputtexels, data, glt->width * glt->height * glt->textype->inputbytesperpixel);
- }
- R_Upload(glt, data);
- */
+
// if it has not been uploaded yet, update the data that will be used when it is
if (glt->inputtexels)
memcpy(glt->inputtexels, data, glt->width * glt->height * glt->textype->inputbytesperpixel);