port pfnUpdateTexture

This commit is contained in:
Jaime Passos 2020-01-28 00:16:38 -03:00
parent 6f60fd2a64
commit 85f016e4d8
5 changed files with 212 additions and 173 deletions

View file

@ -40,6 +40,7 @@ EXPORT void HWRAPI(RenderSkyDome) (INT32 tex, INT32 texture_width, INT32 texture
EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags);
EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor); EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFloat *ClearColor);
EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo); EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo);
EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *TexInfo);
EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data); EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data);
EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip); EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip);
EXPORT void HWRAPI(ClearMipMapCache) (void); EXPORT void HWRAPI(ClearMipMapCache) (void);
@ -92,6 +93,7 @@ struct hwdriver_s
SetBlend pfnSetBlend; SetBlend pfnSetBlend;
ClearBuffer pfnClearBuffer; ClearBuffer pfnClearBuffer;
SetTexture pfnSetTexture; SetTexture pfnSetTexture;
UpdateTexture pfnUpdateTexture;
ReadRect pfnReadRect; ReadRect pfnReadRect;
GClipRect pfnGClipRect; GClipRect pfnGClipRect;
ClearMipMapCache pfnClearMipMapCache; ClearMipMapCache pfnClearMipMapCache;

View file

@ -267,6 +267,7 @@ static void GL_MSG_Error(const char *format, ...)
#define pglTexEnvi glTexEnvi #define pglTexEnvi glTexEnvi
#define pglTexParameteri glTexParameteri #define pglTexParameteri glTexParameteri
#define pglTexImage2D glTexImage2D #define pglTexImage2D glTexImage2D
#define pglTexSubImage2D glTexSubImage2D
/* Fog */ /* Fog */
#define pglFogf glFogf #define pglFogf glFogf
@ -381,6 +382,8 @@ typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint
static PFNglTexParameteri pglTexParameteri; static PFNglTexParameteri pglTexParameteri;
typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexImage2D pglTexImage2D; static PFNglTexImage2D pglTexImage2D;
typedef void (APIENTRY * PFNglTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
static PFNglTexSubImage2D pglTexSubImage2D;
/* Fog */ /* Fog */
typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param); typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param);
@ -518,6 +521,7 @@ boolean SetupGLfunc(void)
GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexEnvi, glTexEnvi)
GETOPENGLFUNC(pglTexParameteri, glTexParameteri) GETOPENGLFUNC(pglTexParameteri, glTexParameteri)
GETOPENGLFUNC(pglTexImage2D, glTexImage2D) GETOPENGLFUNC(pglTexImage2D, glTexImage2D)
GETOPENGLFUNC(pglTexSubImage2D , glTexSubImage2D)
GETOPENGLFUNC(pglFogf, glFogf) GETOPENGLFUNC(pglFogf, glFogf)
GETOPENGLFUNC(pglFogfv, glFogfv) GETOPENGLFUNC(pglFogfv, glFogfv)
@ -1633,34 +1637,27 @@ EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags)
CurrentPolyFlags = PolyFlags; CurrentPolyFlags = PolyFlags;
} }
// -----------------+ // -----------------+
// SetTexture : The mipmap becomes the current texture source // UpdateTexture : Updates the texture data.
// -----------------+ // -----------------+
EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo)
{
if (!pTexInfo)
{
SetNoTexture();
return;
}
else if (pTexInfo->downloaded)
{
if (pTexInfo->downloaded != tex_downloaded)
{
pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded);
tex_downloaded = pTexInfo->downloaded;
}
}
else
{ {
// Download a mipmap // Download a mipmap
boolean updatemipmap = true;
static RGBA_t tex[2048*2048]; static RGBA_t tex[2048*2048];
const GLvoid *ptex = tex; const GLvoid *ptex = tex;
INT32 w, h; INT32 w, h;
GLuint texnum = 0; GLuint texnum = 0;
if (!pTexInfo->downloaded)
{
pglGenTextures(1, &texnum); pglGenTextures(1, &texnum);
pTexInfo->downloaded = texnum;
updatemipmap = false;
}
else
texnum = pTexInfo->downloaded;
//GL_DBG_Printf ("DownloadMipmap %d %x\n",(INT32)texnum,pTexInfo->grInfo.data); //GL_DBG_Printf ("DownloadMipmap %d %x\n",(INT32)texnum,pTexInfo->grInfo.data);
w = pTexInfo->width; w = pTexInfo->width;
@ -1751,7 +1748,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
// the texture number was already generated by pglGenTextures // the texture number was already generated by pglGenTextures
pglBindTexture(GL_TEXTURE_2D, texnum); pglBindTexture(GL_TEXTURE_2D, texnum);
pTexInfo->downloaded = texnum;
tex_downloaded = texnum; tex_downloaded = texnum;
// disable texture filtering on any texture that has holes so there's no dumb borders or blending issues // disable texture filtering on any texture that has holes so there's no dumb borders or blending issues
@ -1779,9 +1775,14 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4);
//pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR);
} }
else
{
if (updatemipmap)
pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
else else
pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
} }
}
else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_8) else if (pTexInfo->grInfo.format == GR_TEXFMT_ALPHA_8)
{ {
//pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
@ -1795,9 +1796,14 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4);
//pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR);
} }
else
{
if (updatemipmap)
pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
else else
pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
} }
}
else else
{ {
if (MipMap) if (MipMap)
@ -1810,9 +1816,14 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
else else
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5);
} }
else
{
if (updatemipmap)
pglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
else else
pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex);
} }
}
if (pTexInfo->flags & TF_WRAPX) if (pTexInfo->flags & TF_WRAPX)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -1826,7 +1837,29 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
if (maximumAnisotropy) if (maximumAnisotropy)
pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic_filter);
}
// -----------------+
// SetTexture : The mipmap becomes the current texture source
// -----------------+
EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
{
if (!pTexInfo)
{
SetNoTexture();
return;
}
else if (pTexInfo->downloaded)
{
if (pTexInfo->downloaded != tex_downloaded)
{
pglBindTexture(GL_TEXTURE_2D, pTexInfo->downloaded);
tex_downloaded = pTexInfo->downloaded;
}
}
else
{
UpdateTexture(pTexInfo);
pTexInfo->nextmipmap = NULL; pTexInfo->nextmipmap = NULL;
if (gr_cachetail) if (gr_cachetail)
{ // insertion at the tail { // insertion at the tail

View file

@ -84,6 +84,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetBlend); GETFUNC(SetBlend);
GETFUNC(ClearBuffer); GETFUNC(ClearBuffer);
GETFUNC(SetTexture); GETFUNC(SetTexture);
GETFUNC(UpdateTexture);
GETFUNC(ReadRect); GETFUNC(ReadRect);
GETFUNC(GClipRect); GETFUNC(GClipRect);
GETFUNC(ClearMipMapCache); GETFUNC(ClearMipMapCache);

View file

@ -1769,6 +1769,7 @@ void I_StartupHardwareGraphics(void)
HWD.pfnSetBlend = hwSym("SetBlend",NULL); HWD.pfnSetBlend = hwSym("SetBlend",NULL);
HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL); HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL);
HWD.pfnSetTexture = hwSym("SetTexture",NULL); HWD.pfnSetTexture = hwSym("SetTexture",NULL);
HWD.pfnUpdateTexture = hwSym("UpdateTexture",NULL);
HWD.pfnReadRect = hwSym("ReadRect",NULL); HWD.pfnReadRect = hwSym("ReadRect",NULL);
HWD.pfnGClipRect = hwSym("GClipRect",NULL); HWD.pfnGClipRect = hwSym("GClipRect",NULL);
HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL);

View file

@ -106,6 +106,7 @@ static loadfunc_t hwdFuncTable[] = {
{"SetBlend@4", &hwdriver.pfnSetBlend}, {"SetBlend@4", &hwdriver.pfnSetBlend},
{"ClearBuffer@12", &hwdriver.pfnClearBuffer}, {"ClearBuffer@12", &hwdriver.pfnClearBuffer},
{"SetTexture@4", &hwdriver.pfnSetTexture}, {"SetTexture@4", &hwdriver.pfnSetTexture},
{"UpdateTexture@4", &hwdriver.pfnUpdateTexture},
{"ReadRect@24", &hwdriver.pfnReadRect}, {"ReadRect@24", &hwdriver.pfnReadRect},
{"GClipRect@20", &hwdriver.pfnGClipRect}, {"GClipRect@20", &hwdriver.pfnGClipRect},
{"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache}, {"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache},
@ -137,6 +138,7 @@ static loadfunc_t hwdFuncTable[] = {
{"SetBlend", &hwdriver.pfnSetBlend}, {"SetBlend", &hwdriver.pfnSetBlend},
{"ClearBuffer", &hwdriver.pfnClearBuffer}, {"ClearBuffer", &hwdriver.pfnClearBuffer},
{"SetTexture", &hwdriver.pfnSetTexture}, {"SetTexture", &hwdriver.pfnSetTexture},
{"UpdateTexture", &hwdriver.pfnUpdateTexture},
{"ReadRect", &hwdriver.pfnReadRect}, {"ReadRect", &hwdriver.pfnReadRect},
{"GClipRect", &hwdriver.pfnGClipRect}, {"GClipRect", &hwdriver.pfnGClipRect},
{"ClearMipMapCache", &hwdriver.pfnClearMipMapCache}, {"ClearMipMapCache", &hwdriver.pfnClearMipMapCache},