From 2965df485bb87c6b525cc406c7d8d4a355fd067f Mon Sep 17 00:00:00 2001 From: Hayden Kowalchuk Date: Tue, 13 Aug 2019 18:17:11 -0400 Subject: [PATCH] fix: minor texture changes for GluBuildMipmaps --- GL/glu.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ GL/texture.c | 8 ++-- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/GL/glu.c b/GL/glu.c index ae9a590..59834ea 100644 --- a/GL/glu.c +++ b/GL/glu.c @@ -1,5 +1,6 @@ #include #include "private.h" +#include "glext.h" /* Set the Perspective */ void APIENTRY gluPerspective(GLfloat angle, GLfloat aspect, @@ -17,3 +18,114 @@ void APIENTRY gluPerspective(GLfloat angle, GLfloat aspect, void APIENTRY gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) { glOrtho(left, right, bottom, top, -1.0f, 1.0f); } + +extern GLuint _determinePVRFormat(GLint internalFormat, GLenum type); +extern GLint _determineStride(GLenum format, GLenum type); +extern GLint _cleanInternalFormat(GLint internalFormat); + + +GLint APIENTRY gluScaleImage(GLenum format, + GLsizei src_width, GLsizei src_height, + GLenum src_type, const GLvoid *src, + GLsizei dst_width, GLsizei dst_height, + GLenum dst_type, GLvoid *dst) +{ + + /* Calculate the format that we need to convert the data to */ + GLuint dst_format = _determinePVRFormat(format, src_type); + GLuint pvr_format = _determinePVRFormat(format, dst_type); + + int i; + + if (src_width == dst_width && + src_height == dst_height && + src_type == dst_type) { + memcpy(dst, src, dst_width * dst_height * 2 /* shorts? */); + return 0; + } else { + return 0; + } +#if 0 + image = malloc(src_width * src_height * sizeof(pix_t)); + if (image == NULL) + return GLU_OUT_OF_MEMORY; + for(i = 0; i < src_height; i++) + (*srcfmt->unpack)(srcfmt, + src + i * src_width * srcfmt->size, + &image[i * src_width], + src_width); + + if (src_width != dst_width) + image = rescale_horiz(image, src_width, dst_width, src_height); + + if (src_height != dst_height) + image = rescale_vert(image, dst_width, src_height, dst_height); + + if (image == NULL) + return GL_OUT_OF_MEMORY; + + for(i = 0; i < dst_height; i++) + (*dstfmt->pack)(dstfmt, + &image[i * dst_width], + dst + i * dst_width * dstfmt->size, + dst_width); + free(image); + #endif + return 0; +} + +GLint APIENTRY gluBuild2DMipmaps( GLenum target,GLint internalFormat, GLsizei width, GLsizei height, + GLenum format, GLenum type, const void *data ) +{ + #if 0 + GLsizei tw, th; + const void *src; + void *dst; + int level, levels; + GLint maxtex; + + tw = width; + th = height; + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtex); + + while(tw > maxtex) + tw /= 2; + while(th > maxtex) + th /= 2; + + levels = 1 + floor(log2(tw)); + level = 1 + floor(log2(th)); + if (level > levels) + levels = level; + + src = data; + dst = NULL; + + for(level = 0; level <= levels; level++) { + dst = malloc(tw * th * 2 /*shorts so 2 bytes*/); + + gluScaleImage(format, + width, height, type, src, + tw, th, type, dst); + + glTexImage2D(target, level, internalFormat, + tw, th, 0, format, type, dst); + + if (src != data) + free((void *)src); + src = dst; + width = tw; + height = th; + + if (tw > 1) + tw /= 2; + if (th > 1) + th /= 2; + } + free(dst); + #endif + glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data); + glGenerateMipmapEXT(target); + return 0; +} \ No newline at end of file diff --git a/GL/texture.c b/GL/texture.c index cf8971e..6733f8e 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -21,7 +21,7 @@ GLubyte ACTIVE_TEXTURE = 0; static TexturePalette* SHARED_PALETTES[4] = {NULL, NULL, NULL, NULL}; -static GLuint _determinePVRFormat(GLint internalFormat, GLenum type); +GLuint _determinePVRFormat(GLint internalFormat, GLenum type); #define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) ) @@ -139,7 +139,7 @@ GLubyte _glGetActiveTexture() { return ACTIVE_TEXTURE; } -static GLint _determineStride(GLenum format, GLenum type) { + GLint _determineStride(GLenum format, GLenum type) { switch(type) { case GL_BYTE: case GL_UNSIGNED_BYTE: @@ -563,7 +563,7 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target, sq_cpy(active->data, data, imageSize); } -static GLint _cleanInternalFormat(GLint internalFormat) { +GLint _cleanInternalFormat(GLint internalFormat) { switch (internalFormat) { case GL_COLOR_INDEX4_EXT: return GL_COLOR_INDEX4_EXT; @@ -637,7 +637,7 @@ static GLint _cleanInternalFormat(GLint internalFormat) { } } -static GLuint _determinePVRFormat(GLint internalFormat, GLenum type) { + GLuint _determinePVRFormat(GLint internalFormat, GLenum type) { /* Given a cleaned internalFormat, return the Dreamcast format * that can hold it */