crc = CRC_Block((unsigned char *)path, strlen(path));
hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
for (pic = cachepichash[hashkey];pic;pic = pic->chain)
+ {
if (!strcmp (path, pic->name))
- if(!((pic->texflags ^ texflags) & ~(TEXF_COMPRESS))) // ignore TEXF_COMPRESS when comparing, because fallback pics remove the flag
+ {
+ // if it was created (or replaced) by Draw_NewPic, just return it
+ if(pic->flags & CACHEPICFLAG_NEWPIC)
+ return pic;
+ if (!((pic->texflags ^ texflags) & ~(TEXF_COMPRESS))) // ignore TEXF_COMPRESS when comparing, because fallback pics remove the flag
{
if(!(cachepicflags & CACHEPICFLAG_NOTPERSISTENT))
{
}
return pic;
}
+ }
+ }
if (numcachepics == MAX_CACHED_PICS)
{
return cachepics; // return the first one
}
pic = cachepics + (numcachepics++);
+ memset(pic, 0, sizeof(*pic));
strlcpy (pic->name, path, sizeof(pic->name));
// link into list
pic->chain = cachepichash[hashkey];
cachepichash[hashkey] = pic;
reload:
+ // TODO why does this crash?
+ if(pic->allow_free_tex && pic->tex)
+ R_PurgeTexture(pic->tex);
+
// check whether it is an dynamic texture (if so, we can directly use its texture handler)
+ pic->flags = cachepicflags;
pic->tex = CL_GetDynTexture( path );
// if so, set the width/height, too
if( pic->tex ) {
+ pic->allow_free_tex = false;
pic->width = R_TextureWidth(pic->tex);
pic->height = R_TextureHeight(pic->tex);
// we're done now (early-out)
return pic;
}
+ pic->allow_free_tex = true;
+
pic->hasalpha = true; // assume alpha unless we know it has none
pic->texflags = texflags;
pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
if (!pic->autoload)
{
pic->tex = R_LoadTexture2D(drawtexturepool, pic->name, image_width, image_height, pixels, vid.sRGB2D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, pic->texflags & (pic->hasalpha ? ~0 : ~TEXF_ALPHA), -1, NULL);
+#ifndef USE_GLES2
if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
}
}
if (!loaded)
pic->tex = draw_generatepic(pic->name, (cachepicflags & CACHEPICFLAG_QUIET) != 0);
pic->width = R_TextureWidth(pic->tex);
pic->height = R_TextureHeight(pic->tex);
+ pic->allow_free_tex = (pic->tex != r_texture_notexture);
}
return pic;
if (pic->tex == NULL)
{
pic->tex = loadtextureimage(drawtexturepool, pic->name, false, pic->texflags, true, vid.sRGB2D);
+#ifndef USE_GLES2
if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
}
if (pic->tex == NULL && !strncmp(pic->name, "gfx/", 4))
{
pic->tex = loadtextureimage(drawtexturepool, pic->name+4, false, pic->texflags, true, vid.sRGB2D);
+#ifndef USE_GLES2
if (r_texture_dds_save.integer && qglGetCompressedTexImageARB && pic->tex)
R_SaveTextureDDSFile(pic->tex, va("dds/%s.dds", pic->name), r_texture_dds_save.integer < 2, pic->hasalpha);
+#endif
}
if (pic->tex == NULL)
pic->tex = draw_generatepic(pic->name, true);
if (pic)
{
- if (pic->tex && pic->width == width && pic->height == height)
+ if (pic->flags == CACHEPICFLAG_NEWPIC && pic->tex && pic->width == width && pic->height == height)
{
R_UpdateTexture(pic->tex, pixels_bgra, 0, 0, 0, width, height, 1);
return pic;
}
else
{
- if (pic == NULL)
+ if (numcachepics == MAX_CACHED_PICS)
{
- if (numcachepics == MAX_CACHED_PICS)
- {
- Con_Printf ("Draw_NewPic: numcachepics == MAX_CACHED_PICS\n");
- // FIXME: support NULL in callers?
- return cachepics; // return the first one
- }
- pic = cachepics + (numcachepics++);
- strlcpy (pic->name, picname, sizeof(pic->name));
- // link into list
- pic->chain = cachepichash[hashkey];
- cachepichash[hashkey] = pic;
+ Con_Printf ("Draw_NewPic: numcachepics == MAX_CACHED_PICS\n");
+ // FIXME: support NULL in callers?
+ return cachepics; // return the first one
}
+ pic = cachepics + (numcachepics++);
+ memset(pic, 0, sizeof(*pic));
+ strlcpy (pic->name, picname, sizeof(pic->name));
+ // link into list
+ pic->chain = cachepichash[hashkey];
+ cachepichash[hashkey] = pic;
}
+ pic->flags = CACHEPICFLAG_NEWPIC; // disable texflags checks in Draw_CachePic
pic->width = width;
pic->height = height;
- if (pic->tex)
+ if (pic->allow_free_tex && pic->tex)
R_FreeTexture(pic->tex);
pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0), -1, NULL);
return pic;
width = pic->width;
if (height == 0)
height = pic->height;
- R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
#if 0
// AK07: lets be texel correct on the corners
#endif
}
else
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
floats[2] = floats[5] = floats[8] = floats[11] = 0;
floats[0] = floats[9] = x;
width = pic->width;
if (height == 0)
height = pic->height;
- R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
}
else
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
floats[2] = floats[5] = floats[8] = floats[11] = 0;
return;
// R_Mesh_ResetTextureState();
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
floats[2] = floats[5] = floats[8] = floats[11] = 0;
floats[0] = floats[9] = x;
// R_Mesh_ResetTextureState();
if (!fontmap)
R_Mesh_TexBind(0, fnt->tex);
- R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
ac = color4f;
at = texcoord2f;
at = texcoord2f;
av = vertex3f;
}
- R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(fnt->tex, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
map = ft2_oldstyle_map;
}
}
break;
}
}
- R_SetupShader_Generic(map->pic->tex, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(map->pic->tex, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
}
mapch = ch - map->start;
width = pic->width;
if (height == 0)
height = pic->height;
- R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(Draw_GetPicTexture(pic), NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
}
else
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
floats[2] = floats[5] = floats[8] = floats[11] = 0;
floats[0] = floats[9] = x;
DrawQ_ProcessDrawFlag(flags, hasalpha);
// R_Mesh_ResetTextureState();
- R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(mesh->texture, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
R_Mesh_PrepareVertices_Generic_Arrays(mesh->num_vertices, mesh->data_vertex3f, mesh->data_color4f, mesh->data_texcoord2f);
R_Mesh_Draw(0, mesh->num_vertices, 0, mesh->num_triangles, mesh->data_element3i, NULL, 0, mesh->data_element3s, NULL, 0);
case RENDERPATH_GL11:
case RENDERPATH_GL13:
case RENDERPATH_GL20:
+#ifndef USE_GLES2
CHECKGLERROR
qglBegin(GL_LINE_LOOP);
for (num = 0;num < mesh->num_vertices;num++)
}
qglEnd();
CHECKGLERROR
+#endif
break;
case RENDERPATH_D3D9:
//Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
if(!r_draw2d.integer && !r_draw2d_force)
return;
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
switch(vid.renderpath)
{
case RENDERPATH_GL11:
case RENDERPATH_GL13:
case RENDERPATH_GL20:
+#ifndef USE_GLES2
CHECKGLERROR
//qglLineWidth(width);CHECKGLERROR
qglVertex2f(x2, y2);
qglEnd();
CHECKGLERROR
+#endif
break;
case RENDERPATH_D3D9:
//Con_DPrintf("FIXME D3D9 %s:%i %s\n", __FILE__, __LINE__, __FUNCTION__);
case RENDERPATH_GL20:
CHECKGLERROR
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, (flags & DRAWFLAGS_BLEND) ? false : true, true);
//qglLineWidth(width);CHECKGLERROR
}
// all the blends ignore depth
// R_Mesh_ResetTextureState();
- R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true);
+ R_SetupShader_Generic(NULL, NULL, GL_MODULATE, 1, true, true);
GL_DepthMask(true);
GL_DepthRange(0, 1);
GL_PolygonOffset(0, 0);