1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-08-09 15:49:52 +00:00

Use glGenerateMipmapEXT if available

Don't want to do mipmaps on CPU if not necessary.
This commit is contained in:
fgenesis 2016-09-25 22:55:59 +02:00
parent 84da02e4aa
commit cd24278bf8

View file

@ -28,13 +28,14 @@
#include <windows.h> #include <windows.h>
#endif #endif
#define GL_GLEXT_PROTOTYPES //#define GL_GLEXT_PROTOTYPES
//#include <GL/glpng.h> //#include <GL/glpng.h>
//#include <GL/gl.h> //#include <GL/gl.h>
//#include <GL/glext.h> //#include <GL/glext.h>
#include "../glpng.h" #include "../glpng.h"
#include "gl.h" #include "gl.h"
#include "glext.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -47,10 +48,15 @@ typedef uint64_t uint64;
#include <png.h> #include <png.h>
#include "SDL.h"
static PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT = NULL;
static int s_got_glGenerateMipmapEXT = 0;
/* Used to decide if GL/gl.h supports the paletted extension */ /* Used to decide if GL/gl.h supports the paletted extension */
#ifdef GL_COLOR_INDEX1_EXT /*#ifdef GL_COLOR_INDEX1_EXT
#define SUPPORTS_PALETTE_EXT #define SUPPORTS_PALETTE_EXT
#endif #endif*/
static unsigned char DefaultAlphaCallback(unsigned char red, unsigned char green, unsigned char blue) { static unsigned char DefaultAlphaCallback(unsigned char red, unsigned char green, unsigned char blue) {
return 255; return 255;
@ -235,12 +241,29 @@ static int HalfSize(GLint components, GLint width, GLint height, const unsigned
/* Replacement for gluBuild2DMipmaps so GLU isn't needed */ /* Replacement for gluBuild2DMipmaps so GLU isn't needed */
static void Build2DMipmaps(GLint components, GLint width, GLint height, GLenum format, const unsigned char *data, int filter) { static void Build2DMipmaps(GLint components, GLint width, GLint height, GLenum format, const unsigned char *data, int filter) {
int level = 0; int level = 0;
unsigned char *d = (unsigned char *) malloc((width/2)*(height/2)*components+4); unsigned char *d;
const unsigned char *last = data; const unsigned char *last = data;
glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, level, components, width, height, 0, format, GL_UNSIGNED_BYTE, data);
genmip:
if(glGenerateMipmapEXT)
{
glHint(GL_GENERATE_MIPMAP_HINT, filter ? GL_NICEST : GL_FASTEST);
glGenerateMipmapEXT(GL_TEXTURE_2D);
return;
}
else if(!s_got_glGenerateMipmapEXT)
{
s_got_glGenerateMipmapEXT = 1;
glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC)SDL_GL_GetProcAddress("glGenerateMipmapEXT");
goto genmip;
}
level++; level++;
d = (unsigned char *) malloc((width/2)*(height/2)*components+4);
while (HalfSize(components, width, height, last, d, filter)) { while (HalfSize(components, width, height, last, d, filter)) {
if (width > 1) width /= 2; if (width > 1) width /= 2;