mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-03-06 03:11:40 +00:00
Update r_opengl.c
This commit is contained in:
parent
5539341ebc
commit
0abc659168
1 changed files with 22 additions and 53 deletions
|
|
@ -62,6 +62,9 @@ static FBITFIELD CurrentPolyFlags;
|
|||
static FTextureInfo *TexCacheTail = NULL;
|
||||
static FTextureInfo *TexCacheHead = NULL;
|
||||
|
||||
static RGBA_t *textureBuffer = NULL;
|
||||
static size_t textureBufferSize = 0;
|
||||
|
||||
RGBA_t myPaletteData[256];
|
||||
GLint screen_width = 0; // used by Draw2DLine()
|
||||
GLint screen_height = 0;
|
||||
|
|
@ -202,32 +205,6 @@ static void GL_MSG_Error(const char *format, ...)
|
|||
#endif
|
||||
}
|
||||
|
||||
// ----------------------+
|
||||
// GetTextureFormatName : Returns the corresponding texture format string from the texture format enumeration.
|
||||
// ----------------------+
|
||||
static const char *GetTextureFormatName(INT32 format)
|
||||
{
|
||||
static char num[12];
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case GL_TEXFMT_P_8: return "GL_TEXFMT_P_8";
|
||||
case GL_TEXFMT_AP_88: return "GL_TEXFMT_AP_88";
|
||||
case GL_TEXFMT_RGBA: return "GL_TEXFMT_RGBA";
|
||||
case GL_TEXFMT_ALPHA_8: return "GL_TEXFMT_ALPHA_8";
|
||||
case GL_TEXFMT_INTENSITY_8: return "GL_TEXFMT_INTENSITY_8";
|
||||
case GL_TEXFMT_ALPHA_INTENSITY_88: return "GL_TEXFMT_ALPHA_INTENSITY_88";
|
||||
default: break;
|
||||
}
|
||||
|
||||
// If the texture format is not known (due to it being invalid),
|
||||
// return a string containing the format index instead.
|
||||
format = INT32_MIN;
|
||||
snprintf(num, sizeof(num), "%d", format);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
#ifdef STATIC_OPENGL
|
||||
/* 1.0 functions */
|
||||
/* Miscellaneous */
|
||||
|
|
@ -1398,6 +1375,10 @@ void Flush(void)
|
|||
|
||||
TexCacheTail = TexCacheHead = NULL; //Hurdler: well, TexCacheHead is already NULL
|
||||
tex_downloaded = 0;
|
||||
|
||||
free(textureBuffer);
|
||||
textureBuffer = NULL;
|
||||
textureBufferSize = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1790,28 +1771,16 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags)
|
|||
CurrentPolyFlags = PolyFlags;
|
||||
}
|
||||
|
||||
// -------------------+
|
||||
// AllocTextureBuffer : Allocates memory for converting a non-RGBA texture into an RGBA texture.
|
||||
// -------------------+
|
||||
static RGBA_t *AllocTextureBuffer(GLMipmap_t *pTexInfo)
|
||||
static void AllocTextureBuffer(GLMipmap_t *pTexInfo)
|
||||
{
|
||||
size_t len = (pTexInfo->width * pTexInfo->height);
|
||||
RGBA_t *tex = calloc(len, sizeof(RGBA_t));
|
||||
|
||||
if (tex == NULL)
|
||||
I_Error("AllocTextureBuffer: out of memory allocating %s bytes for texture %d, format %s",
|
||||
sizeu1(len * sizeof(RGBA_t)), pTexInfo->downloaded, GetTextureFormatName(pTexInfo->format));
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
// ------------------+
|
||||
// FreeTextureBuffer : Frees memory allocated by AllocTextureBuffer.
|
||||
// ------------------+
|
||||
static void FreeTextureBuffer(RGBA_t *tex)
|
||||
{
|
||||
if (tex)
|
||||
free(tex);
|
||||
size_t size = pTexInfo->width * pTexInfo->height;
|
||||
if (size > textureBufferSize)
|
||||
{
|
||||
textureBuffer = realloc(textureBuffer, size * sizeof(RGBA_t));
|
||||
if (textureBuffer == NULL)
|
||||
I_Error("AllocTextureBuffer: out of memory allocating %s bytes", sizeu1(size * sizeof(RGBA_t)));
|
||||
textureBufferSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------+
|
||||
|
|
@ -1842,7 +1811,8 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
|
|||
|
||||
if ((pTexInfo->format == GL_TEXFMT_P_8) || (pTexInfo->format == GL_TEXFMT_AP_88))
|
||||
{
|
||||
ptex = tex = AllocTextureBuffer(pTexInfo);
|
||||
AllocTextureBuffer(pTexInfo);
|
||||
ptex = tex = textureBuffer;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
{
|
||||
|
|
@ -1883,7 +1853,8 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
|
|||
}
|
||||
else if (pTexInfo->format == GL_TEXFMT_ALPHA_INTENSITY_88)
|
||||
{
|
||||
ptex = tex = AllocTextureBuffer(pTexInfo);
|
||||
AllocTextureBuffer(pTexInfo);
|
||||
ptex = tex = textureBuffer;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
{
|
||||
|
|
@ -1900,7 +1871,8 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
|
|||
}
|
||||
else if (pTexInfo->format == GL_TEXFMT_ALPHA_8) // Used for fade masks
|
||||
{
|
||||
ptex = tex = AllocTextureBuffer(pTexInfo);
|
||||
AllocTextureBuffer(pTexInfo);
|
||||
ptex = tex = textureBuffer;
|
||||
|
||||
for (j = 0; j < h; j++)
|
||||
{
|
||||
|
|
@ -1995,9 +1967,6 @@ EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *pTexInfo)
|
|||
}
|
||||
}
|
||||
|
||||
// Free the texture buffer
|
||||
FreeTextureBuffer(tex);
|
||||
|
||||
if (pTexInfo->flags & TF_WRAPX)
|
||||
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue