mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-21 20:11:12 +00:00
Generate the TF_CHROMAKEYED texture in hw_cache.c
This commit is contained in:
parent
dd5f030b16
commit
b89aaf709e
2 changed files with 21 additions and 71 deletions
|
@ -450,15 +450,10 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, GLMipmap_t
|
||||||
|
|
||||||
texture = textures[texnum];
|
texture = textures[texnum];
|
||||||
|
|
||||||
mipmap->flags = TF_WRAPXY;
|
|
||||||
mipmap->width = (UINT16)texture->width;
|
|
||||||
mipmap->height = (UINT16)texture->height;
|
|
||||||
mipmap->format = textureformat;
|
|
||||||
|
|
||||||
blockwidth = texture->width;
|
blockwidth = texture->width;
|
||||||
blockheight = texture->height;
|
blockheight = texture->height;
|
||||||
blocksize = (blockwidth * blockheight);
|
blocksize = blockwidth * blockheight;
|
||||||
block = MakeBlock(&grtex->mipmap);
|
block = MakeBlock(mipmap);
|
||||||
|
|
||||||
// Composite the columns together.
|
// Composite the columns together.
|
||||||
for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++)
|
for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++)
|
||||||
|
@ -488,7 +483,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, GLMipmap_t
|
||||||
realpatch = W_CachePatchNumPwad(wadnum, lumpnum, PU_PATCH);
|
realpatch = W_CachePatchNumPwad(wadnum, lumpnum, PU_PATCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
HWR_DrawTexturePatchInCache(&grtex->mipmap, blockwidth, blockheight, texture, patch, realpatch);
|
HWR_DrawTexturePatchInCache(mipmap, blockwidth, blockheight, texture, patch, realpatch);
|
||||||
|
|
||||||
if (free_patch)
|
if (free_patch)
|
||||||
Patch_Free(realpatch);
|
Patch_Free(realpatch);
|
||||||
|
@ -741,21 +736,6 @@ void HWR_LoadMapTextures(size_t pnumtextures)
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Make sure texture is downloaded and set it as the source
|
// Make sure texture is downloaded and set it as the source
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
static void GetMapTexture(INT32 tex, GLMapTexture_t *grtex, GLMipmap_t *mipmap)
|
|
||||||
{
|
|
||||||
// Generate texture if missing from the cache
|
|
||||||
if (!mipmap->data && !mipmap->downloaded)
|
|
||||||
HWR_GenerateTexture(tex, grtex, mipmap);
|
|
||||||
|
|
||||||
// If hardware does not have the texture, then call pfnSetTexture to upload it
|
|
||||||
if (!mipmap->downloaded)
|
|
||||||
HWD.pfnSetTexture(mipmap);
|
|
||||||
HWR_SetCurrentTexture(mipmap);
|
|
||||||
|
|
||||||
// The system-memory data can be purged now.
|
|
||||||
Z_ChangeTag(mipmap->data, PU_HWRCACHE_UNLOCKED);
|
|
||||||
}
|
|
||||||
|
|
||||||
GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean chromakeyed)
|
GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean chromakeyed)
|
||||||
{
|
{
|
||||||
if (tex < 0 || tex >= (signed)gl_numtextures)
|
if (tex < 0 || tex >= (signed)gl_numtextures)
|
||||||
|
@ -772,35 +752,38 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean chromakeyed)
|
||||||
GLMipmap_t *grMipmap = &grtex->mipmap;
|
GLMipmap_t *grMipmap = &grtex->mipmap;
|
||||||
GLMipmap_t *originalMipmap = grMipmap;
|
GLMipmap_t *originalMipmap = grMipmap;
|
||||||
|
|
||||||
if (!originalMipmap->data && !originalMipmap->downloaded)
|
if (!originalMipmap->downloaded)
|
||||||
HWR_GenerateTexture(tex, grtex, originalMipmap);
|
{
|
||||||
|
originalMipmap->flags = TF_WRAPXY;
|
||||||
|
originalMipmap->width = (UINT16)textures[tex]->width;
|
||||||
|
originalMipmap->height = (UINT16)textures[tex]->height;
|
||||||
|
originalMipmap->format = textureformat;
|
||||||
|
}
|
||||||
|
|
||||||
// If chroma-keyed, create or use a different mipmap for the variant
|
// If chroma-keyed, create or use a different mipmap for the variant
|
||||||
if (chromakeyed && !textures[tex]->transparency && originalMipmap->data)
|
if (chromakeyed && !textures[tex]->transparency)
|
||||||
{
|
{
|
||||||
// Allocate it if it wasn't already
|
// Allocate it if it wasn't already
|
||||||
if (!originalMipmap->nextcolormap)
|
if (!originalMipmap->nextcolormap)
|
||||||
{
|
{
|
||||||
GLMipmap_t *newMipmap = calloc(1, sizeof (*grMipmap));
|
GLMipmap_t *newMipmap = calloc(1, sizeof (*grMipmap));
|
||||||
if (newMipmap == NULL)
|
if (newMipmap == NULL)
|
||||||
I_Error("%s: Out of memory", "HWR_GetLevelFlat");
|
I_Error("%s: Out of memory", "HWR_GetTexture");
|
||||||
|
|
||||||
newMipmap->flags = TF_WRAPXY | TF_CHROMAKEYED;
|
newMipmap->flags = originalMipmap->flags | TF_CHROMAKEYED;
|
||||||
newMipmap->width = (UINT16)textures[tex]->width;
|
newMipmap->width = originalMipmap->width;
|
||||||
newMipmap->height = (UINT16)textures[tex]->height;
|
newMipmap->height = originalMipmap->height;
|
||||||
newMipmap->format = textureformat;
|
newMipmap->format = originalMipmap->format;
|
||||||
originalMipmap->nextcolormap = newMipmap;
|
originalMipmap->nextcolormap = newMipmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload and bind the variant texture instead of the original one
|
// Upload and bind the variant texture instead of the original one
|
||||||
grMipmap = originalMipmap->nextcolormap;
|
grMipmap = originalMipmap->nextcolormap;
|
||||||
|
|
||||||
// Use the original texture's pixel data
|
|
||||||
// It can just be a pointer to it, since the r_opengl backend deals with the pixels
|
|
||||||
// that are supposed to be transparent.
|
|
||||||
grMipmap->data = originalMipmap->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!grMipmap->data)
|
||||||
|
HWR_GenerateTexture(tex, grtex, grMipmap);
|
||||||
|
|
||||||
if (!grMipmap->downloaded)
|
if (!grMipmap->downloaded)
|
||||||
HWD.pfnSetTexture(grMipmap);
|
HWD.pfnSetTexture(grMipmap);
|
||||||
HWR_SetCurrentTexture(grMipmap);
|
HWR_SetCurrentTexture(grMipmap);
|
||||||
|
|
|
@ -1556,41 +1556,8 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
|
||||||
}
|
}
|
||||||
else if (pTexInfo->format == GL_TEXFMT_RGBA)
|
else if (pTexInfo->format == GL_TEXFMT_RGBA)
|
||||||
{
|
{
|
||||||
if (pTexInfo->flags & TF_CHROMAKEYED)
|
// Directly upload the texture data without any kind of conversion.
|
||||||
{
|
ptex = pImgData;
|
||||||
RGBA_t *color = (RGBA_t *)pTexInfo->data;
|
|
||||||
|
|
||||||
AllocTextureBuffer(pTexInfo);
|
|
||||||
ptex = tex = textureBuffer;
|
|
||||||
|
|
||||||
for (j = 0; j < h; j++)
|
|
||||||
{
|
|
||||||
for (i = 0; i < w; i++)
|
|
||||||
{
|
|
||||||
if (color->rgba == myPaletteData[HWR_PATCHES_CHROMAKEY_COLORINDEX].rgba)
|
|
||||||
{
|
|
||||||
tex[w*j+i].s.red = 0;
|
|
||||||
tex[w*j+i].s.green = 0;
|
|
||||||
tex[w*j+i].s.blue = 0;
|
|
||||||
tex[w*j+i].s.alpha = 0;
|
|
||||||
pTexInfo->flags |= TF_TRANSPARENT; // there is a hole in it
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tex[w*j+i].s.red = color->s.red;
|
|
||||||
tex[w*j+i].s.green = color->s.green;
|
|
||||||
tex[w*j+i].s.blue = color->s.blue;
|
|
||||||
tex[w*j+i].s.alpha = color->s.alpha;
|
|
||||||
}
|
|
||||||
color++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Directly upload the texture data without any kind of conversion.
|
|
||||||
ptex = pImgData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88)
|
else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue