try to fix textures too

This commit is contained in:
UnknownShadow200 2025-10-17 19:35:33 +11:00
parent 6a734b0d6d
commit 5ca6ba9380
2 changed files with 32 additions and 11 deletions

View File

@ -99,7 +99,7 @@ void Gfx_Create(void) {
/*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------*
*------------------------------------------------Buffer generation/deletion-----------------------------------------------*
*#########################################################################################################################*/
/* Necessary to implement this way, so works on both little endian and big endian systems */
typedef GfxResourceID (*GenGLBuffer)(void);
@ -544,14 +544,14 @@ static void APIENTRY gl10_bindTexture(GLenum target, GLuint texture) {
}
}
static void APIENTRY gl10_deleteTexture(GLsizei n, const GLuint* textures) {
struct GL10Texture* tex = (struct GL10Texture*)textures[0];
static void gl10_deleteTexture(GfxResourceID id) {
struct GL10Texture* tex = (struct GL10Texture*)id;
if (tex->pixels) Mem_Free(tex->pixels);
if (tex) Mem_Free(tex);
}
static void APIENTRY gl10_genTexture(GLsizei n, GLuint* textures) {
textures[0] = (GLuint)Mem_AllocCleared(1, sizeof(struct GL10Texture), "GL 1.0 texture");
static GfxResourceID gl10_genTexture(void) {
return Mem_AllocCleared(1, sizeof(struct GL10Texture), "GL 1.0 texture");
}
static void APIENTRY gl10_texImage(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels) {
@ -647,8 +647,8 @@ static void FallbackOpenGL(void) {
_glTexCoordPointer = gl10_texCoordPointer; _glVertexPointer = gl10_vertexPointer;
_glBindTexture = gl10_bindTexture;
_glGenTextures = gl10_genTexture;
_glDeleteTextures = gl10_deleteTexture;
genTexture = gl10_genTexture;
delTexture = gl10_deleteTexture;
_glTexImage2D = gl10_texImage;
_glTexSubImage2D = gl10_texSubImage;

View File

@ -64,6 +64,28 @@ static void* FastAllocTempMem(int size) {
}
/*########################################################################################################################*
*------------------------------------------------Buffer generation/deletion-----------------------------------------------*
*#########################################################################################################################*/
/* Necessary to implement this way, so works on both little endian and big endian systems */
typedef GfxResourceID (*GenGLTexture)(void);
typedef void (*DelGLTexture)(GfxResourceID id);
static GfxResourceID defaultGenTexture(void) {
GLuint buf = 0;
_glGenTextures(1, &buf);
return uint_to_ptr(buf);
}
static void defaultDelTexture(GfxResourceID id) {
GLuint buf = ptr_to_uint(id);
_glDeleteTextures(1, &buf);
}
static GenGLTexture genTexture = defaultGenTexture;
static DelGLTexture delTexture = defaultDelTexture;
/*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/
@ -172,8 +194,7 @@ static CC_NOINLINE void UpdateTextureSlow(int x, int y, struct Bitmap* part, int
}
GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) {
GfxResourceID texId = NULL;
_glGenTextures(1, (GLuint*)&texId);
GfxResourceID texId = genTexture();
_glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId));
_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (flags & TEXTURE_FLAG_BILINEAR) ? GL_LINEAR : GL_NEAREST);
@ -210,8 +231,8 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i
}
void Gfx_DeleteTexture(GfxResourceID* texId) {
GLuint id = ptr_to_uint(*texId);
if (id) _glDeleteTextures(1, &id);
GfxResourceID id = *texId;
if (id) delTexture(id);
*texId = 0;
}