GLdc/glu-texture.c

116 lines
3.3 KiB
C
Raw Normal View History

2014-09-07 22:41:26 +00:00
/* KallistiGL for KallistiOS ##version##
libgl/glu-texture.c
2014-09-29 02:40:41 +00:00
Copyright (C) 2013-2014 Josh Pearson
2014-09-07 22:41:26 +00:00
2014-09-29 02:40:41 +00:00
A set of functions for working with ARGB pixel data.
2014-09-07 22:41:26 +00:00
*/
#include "gl.h"
#include "gl-api.h"
#include "gl-rgb.h"
#include "glu.h"
2014-09-29 02:40:41 +00:00
GLAPI GLuint APIENTRY glKosMipMapTexSize(GLuint width, GLuint height) {
2014-09-07 22:41:26 +00:00
GLuint b = 0;
while(width >= 1 && height >= 1) {
b += width * height * 2;
if(width >= 1)
width /= 2;
if(height >= 1)
height /= 2;
}
return b;
}
static GLint gluBuild2DBiMipmaps(GLenum target, GLint internalFormat, GLsizei width,
2014-09-29 02:40:41 +00:00
GLsizei height, GLenum format, GLenum type, const void *data) {
2014-09-07 22:41:26 +00:00
if(target != GL_TEXTURE_2D)
return -1;
if(width < 1 || height < 1)
return 0;
uint32 i = 0;
uint16 x , y;
uint16 *src = (uint16 *)data;
uint16 *dst = (uint16 *)data + (width * height);
for(y = 0; y < height; y += 2) {
for(x = 0; x < width; x += 2) {
switch(type) {
case GL_UNSIGNED_SHORT_5_6_5:
dst[i++] = __glKosAverageBiPixelRGB565(*src, *(src + 1));
break;
case GL_UNSIGNED_SHORT_4_4_4_4:
dst[i++] = __glKosAverageBiPixelARGB4444(*src, *(src + 1));
break;
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2014-09-07 22:41:26 +00:00
dst[i++] = __glKosAverageBiPixelARGB1555(*src, *(src + 1));
break;
}
src += 2;
}
src += width;
}
return gluBuild2DBiMipmaps(target, internalFormat, width / 2, height / 2,
format, type, (uint16 *)data + (width * height));
}
GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width,
2014-09-29 02:40:41 +00:00
GLsizei height, GLenum format, GLenum type, const void *data) {
2014-09-07 22:41:26 +00:00
if(target != GL_TEXTURE_2D)
return -1;
2014-09-29 02:40:41 +00:00
if(type != GL_UNSIGNED_SHORT_5_6_5 && type != GL_UNSIGNED_SHORT_4_4_4_4
&& type != GL_UNSIGNED_SHORT_1_5_5_5_REV)
2014-09-29 02:40:41 +00:00
return -1;
if(width < 1 || height < 1)
2014-09-07 22:41:26 +00:00
return 0;
if(width == 1 || height == 1)
return gluBuild2DBiMipmaps(target, internalFormat, width, height, format, type, data);
uint32 i = 0;
uint16 x, y;
uint16 *src = (uint16 *)data;
uint16 *dst = (uint16 *)data + (width * height);
for(y = 0; y < height; y += 2) {
for(x = 0; x < width; x += 2) {
switch(type) {
case GL_UNSIGNED_SHORT_5_6_5:
dst[i++] = __glKosAverageQuadPixelRGB565(*src, *(src + 1), *(src + width), *(src + width + 1));
break;
case GL_UNSIGNED_SHORT_4_4_4_4:
dst[i++] = __glKosAverageQuadPixelARGB4444(*src, *(src + 1), *(src + width), *(src + width + 1));
break;
case GL_UNSIGNED_SHORT_1_5_5_5_REV:
2014-09-07 22:41:26 +00:00
dst[i++] = __glKosAverageQuadPixelARGB1555(*src, *(src + 1), *(src + width), *(src + width + 1));
break;
}
src += 2;
}
src += width;
}
return gluBuild2DMipmaps(target, internalFormat, width / 2, height / 2,
format, type, (uint16 *)data + (width * height));
}