Use core/FBO function to generate mipmaps instead of glu
parent
b83fc8a037
commit
15bf42104a
|
@ -15,11 +15,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include <jpeglib.h>
|
|
||||||
}
|
|
||||||
#include <png.h>
|
|
||||||
|
|
||||||
#include <Eigen/Core>
|
#include <Eigen/Core>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
@ -44,6 +39,26 @@ struct TextureCaps
|
||||||
|
|
||||||
static TextureCaps texCaps;
|
static TextureCaps texCaps;
|
||||||
|
|
||||||
|
#define NO_GLU
|
||||||
|
#undef DUMP_TEXTURE_MIPMAP_INFO
|
||||||
|
|
||||||
|
#ifdef DUMP_TEXTURE_MIPMAP_INFO
|
||||||
|
static void DumpTextureMipmapInfo(GLenum target)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
GLint w = 0, h = 0;
|
||||||
|
glGetTexLevelParameteriv(target, i, GL_TEXTURE_HEIGHT, &h);
|
||||||
|
if (glGetError() != GL_NO_ERROR) break;
|
||||||
|
glGetTexLevelParameteriv(target, i, GL_TEXTURE_WIDTH, &w);
|
||||||
|
if (glGetError() != GL_NO_ERROR) break;
|
||||||
|
if (w == 0 || h == 0) break;
|
||||||
|
cout << w << 'x' << h << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define DumpTextureMipmapInfo(target) (void)target
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool testMaxLevel()
|
static bool testMaxLevel()
|
||||||
{
|
{
|
||||||
|
@ -382,6 +397,12 @@ ImageTexture::ImageTexture(Image& img,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||||
|
|
||||||
int internalFormat = getInternalFormat(img.getFormat());
|
int internalFormat = getInternalFormat(img.getFormat());
|
||||||
|
bool genMipmaps = mipmap && !precomputedMipMaps;
|
||||||
|
|
||||||
|
#ifdef NO_GLU
|
||||||
|
if (genMipmaps && !GLEW_EXT_framebuffer_object)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mipmap)
|
if (mipmap)
|
||||||
{
|
{
|
||||||
|
@ -391,12 +412,16 @@ ImageTexture::ImageTexture(Image& img,
|
||||||
}
|
}
|
||||||
else if (mipMapMode == DefaultMipMaps)
|
else if (mipMapMode == DefaultMipMaps)
|
||||||
{
|
{
|
||||||
|
#ifdef NO_GLU
|
||||||
|
LoadMiplessTexture(img, GL_TEXTURE_2D);
|
||||||
|
#else
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
getWidth(), getHeight(),
|
getWidth(), getHeight(),
|
||||||
(GLenum) img.getFormat(),
|
(GLenum) img.getFormat(),
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
img.getPixels());
|
img.getPixels());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -408,6 +433,11 @@ ImageTexture::ImageTexture(Image& img,
|
||||||
{
|
{
|
||||||
LoadMiplessTexture(img, GL_TEXTURE_2D);
|
LoadMiplessTexture(img, GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
#ifdef NO_GLU
|
||||||
|
if (genMipmaps && GLEW_EXT_framebuffer_object)
|
||||||
|
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||||
|
#endif
|
||||||
|
DumpTextureMipmapInfo(GL_TEXTURE_2D);
|
||||||
|
|
||||||
alpha = img.hasAlpha();
|
alpha = img.hasAlpha();
|
||||||
compressed = img.isCompressed();
|
compressed = img.isCompressed();
|
||||||
|
@ -588,17 +618,31 @@ TiledTexture::TiledTexture(Image& img,
|
||||||
|
|
||||||
if (mipmap)
|
if (mipmap)
|
||||||
{
|
{
|
||||||
|
#ifdef NO_GLU
|
||||||
|
if (GLEW_EXT_framebuffer_object)
|
||||||
|
{
|
||||||
|
LoadMiplessTexture(*tile, GL_TEXTURE_2D);
|
||||||
|
glGenerateMipmapEXT(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||||
|
LoadMiplessTexture(*tile, GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
#else
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
tileWidth, tileHeight,
|
tileWidth, tileHeight,
|
||||||
(GLenum) tile->getFormat(),
|
(GLenum) tile->getFormat(),
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
tile->getPixels());
|
tile->getPixels());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoadMiplessTexture(*tile, GL_TEXTURE_2D);
|
LoadMiplessTexture(*tile, GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
DumpTextureMipmapInfo(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,6 +746,12 @@ CubeMap::CubeMap(Image* faces[]) :
|
||||||
mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
mipmap ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
||||||
|
|
||||||
int internalFormat = getInternalFormat(format);
|
int internalFormat = getInternalFormat(format);
|
||||||
|
bool genMipmaps = mipmap && !precomputedMipMaps;
|
||||||
|
|
||||||
|
#ifdef NO_GLU
|
||||||
|
if (genMipmaps && !GLEW_EXT_framebuffer_object)
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
|
@ -716,12 +766,16 @@ CubeMap::CubeMap(Image* faces[]) :
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef NO_GLU
|
||||||
|
LoadMiplessTexture(*face, targetFace);
|
||||||
|
#else
|
||||||
gluBuild2DMipmaps(targetFace,
|
gluBuild2DMipmaps(targetFace,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
getWidth(), getHeight(),
|
getWidth(), getHeight(),
|
||||||
(GLenum) face->getFormat(),
|
(GLenum) face->getFormat(),
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
face->getPixels());
|
face->getPixels());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -729,6 +783,11 @@ CubeMap::CubeMap(Image* faces[]) :
|
||||||
LoadMiplessTexture(*face, targetFace);
|
LoadMiplessTexture(*face, targetFace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef NO_GLU
|
||||||
|
if (genMipmaps && GLEW_EXT_framebuffer_object)
|
||||||
|
glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP);
|
||||||
|
#endif
|
||||||
|
DumpTextureMipmapInfo(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue