fix: minor texture changes for GluBuildMipmaps

This commit is contained in:
Hayden Kowalchuk 2019-08-13 18:17:11 -04:00
parent 0ab6a7f039
commit 2965df485b
2 changed files with 116 additions and 4 deletions

112
GL/glu.c
View File

@ -1,5 +1,6 @@
#include <math.h> #include <math.h>
#include "private.h" #include "private.h"
#include "glext.h"
/* Set the Perspective */ /* Set the Perspective */
void APIENTRY gluPerspective(GLfloat angle, GLfloat aspect, 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) { void APIENTRY gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) {
glOrtho(left, right, bottom, top, -1.0f, 1.0f); 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;
}

View File

@ -21,7 +21,7 @@ GLubyte ACTIVE_TEXTURE = 0;
static TexturePalette* SHARED_PALETTES[4] = {NULL, NULL, NULL, NULL}; 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) ) #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; return ACTIVE_TEXTURE;
} }
static GLint _determineStride(GLenum format, GLenum type) { GLint _determineStride(GLenum format, GLenum type) {
switch(type) { switch(type) {
case GL_BYTE: case GL_BYTE:
case GL_UNSIGNED_BYTE: case GL_UNSIGNED_BYTE:
@ -563,7 +563,7 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
sq_cpy(active->data, data, imageSize); sq_cpy(active->data, data, imageSize);
} }
static GLint _cleanInternalFormat(GLint internalFormat) { GLint _cleanInternalFormat(GLint internalFormat) {
switch (internalFormat) { switch (internalFormat) {
case GL_COLOR_INDEX4_EXT: case GL_COLOR_INDEX4_EXT:
return 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 /* Given a cleaned internalFormat, return the Dreamcast format
* that can hold it * that can hold it
*/ */