Introduced support for compressed textures.
parent
e19df3cb7f
commit
2dfb8f333b
|
@ -856,7 +856,10 @@ void Renderer::renderPlanet(const Body& body,
|
||||||
if (surface.baseTexture != "")
|
if (surface.baseTexture != "")
|
||||||
{
|
{
|
||||||
if (!textureManager->find(surface.baseTexture, &tex))
|
if (!textureManager->find(surface.baseTexture, &tex))
|
||||||
tex = textureManager->load(surface.baseTexture);
|
{
|
||||||
|
bool compress = ((surface.appearanceFlags & Surface::CompressBaseTexture) != 0);
|
||||||
|
tex = textureManager->load(surface.baseTexture, compress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this renderer can support bump mapping then get the bump texture
|
// If this renderer can support bump mapping then get the bump texture
|
||||||
|
|
|
@ -167,6 +167,7 @@ class Renderer
|
||||||
int nSimultaneousTextures;
|
int nSimultaneousTextures;
|
||||||
bool useRegisterCombiners;
|
bool useRegisterCombiners;
|
||||||
bool useCubeMaps;
|
bool useCubeMaps;
|
||||||
|
bool useCompressedTextures;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend bool operator<(const Renderer::RenderListEntry&,
|
friend bool operator<(const Renderer::RenderListEntry&,
|
||||||
|
|
|
@ -174,12 +174,16 @@ static Body* CreatePlanet(PlanetarySystem* system,
|
||||||
bool applyBumpMap = planetData->getString("BumpMap", surface.bumpTexture);
|
bool applyBumpMap = planetData->getString("BumpMap", surface.bumpTexture);
|
||||||
bool blendTexture = false;
|
bool blendTexture = false;
|
||||||
planetData->getBoolean("BlendTexture", blendTexture);
|
planetData->getBoolean("BlendTexture", blendTexture);
|
||||||
|
bool compressTexture = false;
|
||||||
|
planetData->getBoolean("CompressTexture", compressTexture);
|
||||||
if (blendTexture)
|
if (blendTexture)
|
||||||
surface.appearanceFlags |= Surface::BlendTexture;
|
surface.appearanceFlags |= Surface::BlendTexture;
|
||||||
if (applyBaseTexture)
|
if (applyBaseTexture)
|
||||||
surface.appearanceFlags |= Surface::ApplyBaseTexture;
|
surface.appearanceFlags |= Surface::ApplyBaseTexture;
|
||||||
if (applyBumpMap)
|
if (applyBumpMap)
|
||||||
surface.appearanceFlags |= Surface::ApplyBumpMap;
|
surface.appearanceFlags |= Surface::ApplyBumpMap;
|
||||||
|
if (compressTexture)
|
||||||
|
surface.appearanceFlags |= Surface::CompressBaseTexture;
|
||||||
body->setSurface(surface);
|
body->setSurface(surface);
|
||||||
|
|
||||||
string mesh("");
|
string mesh("");
|
||||||
|
|
|
@ -23,9 +23,10 @@ class Surface
|
||||||
|
|
||||||
// Appearance flags
|
// Appearance flags
|
||||||
enum {
|
enum {
|
||||||
BlendTexture = 0x1,
|
BlendTexture = 0x1,
|
||||||
ApplyBaseTexture = 0x2,
|
ApplyBaseTexture = 0x2,
|
||||||
ApplyBumpMap = 0x4,
|
ApplyBumpMap = 0x4,
|
||||||
|
CompressBaseTexture = 0x8,
|
||||||
};
|
};
|
||||||
|
|
||||||
Color color;
|
Color color;
|
||||||
|
|
|
@ -25,12 +25,18 @@ bool TextureManager::find(const string& name, CTexture** tex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CTexture* TextureManager::load(const string& name)
|
CTexture* TextureManager::load(const string& name, bool compress)
|
||||||
{
|
{
|
||||||
DPRINTF("Loading texture: %s\n", name.c_str());
|
DPRINTF("Loading texture: %s\n", name.c_str());
|
||||||
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
|
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
|
||||||
|
|
||||||
if (tex != NULL)
|
if (tex != NULL)
|
||||||
tex->bindName(true);
|
{
|
||||||
|
uint32 texFlags = CTexture::WrapTexture;
|
||||||
|
if (compress)
|
||||||
|
texFlags |= CTexture::CompressTexture;
|
||||||
|
tex->bindName(texFlags);
|
||||||
|
}
|
||||||
addResource(name, (void*) tex);
|
addResource(name, (void*) tex);
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
|
@ -43,8 +49,8 @@ CTexture* TextureManager::loadBumpMap(const string& name)
|
||||||
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
|
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
|
||||||
if (tex != NULL)
|
if (tex != NULL)
|
||||||
{
|
{
|
||||||
tex->normalMap(5.0f, true);
|
tex->normalMap(2.5f, true);
|
||||||
tex->bindName();
|
tex->bindName(CTexture::WrapTexture);
|
||||||
}
|
}
|
||||||
addResource(name, static_cast<void*>(tex));
|
addResource(name, static_cast<void*>(tex));
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TextureManager : public ResourceManager
|
||||||
~TextureManager();
|
~TextureManager();
|
||||||
|
|
||||||
bool find(const std::string& name, CTexture**);
|
bool find(const std::string& name, CTexture**);
|
||||||
CTexture* load(const std::string& name);
|
CTexture* load(const std::string& name, bool compress = false);
|
||||||
CTexture* loadBumpMap(const std::string& name);
|
CTexture* loadBumpMap(const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,15 @@ typedef struct
|
||||||
unsigned int colorsImportant;
|
unsigned int colorsImportant;
|
||||||
} BMPImageHeader;
|
} BMPImageHeader;
|
||||||
|
|
||||||
|
static bool initialized = false;
|
||||||
|
static bool compressionSupported = false;
|
||||||
|
|
||||||
|
|
||||||
|
static void initTextureLoader()
|
||||||
|
{
|
||||||
|
compressionSupported = ExtensionSupported("GL_ARB_texture_compression");
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CTexture::CTexture(int w, int h, int fmt) :
|
CTexture::CTexture(int w, int h, int fmt) :
|
||||||
|
@ -58,6 +67,10 @@ CTexture::CTexture(int w, int h, int fmt) :
|
||||||
cmap = NULL;
|
cmap = NULL;
|
||||||
cmapEntries = 0;
|
cmapEntries = 0;
|
||||||
|
|
||||||
|
// Yuck . . .
|
||||||
|
if (!initialized)
|
||||||
|
initTextureLoader();
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case GL_RGB:
|
case GL_RGB:
|
||||||
|
@ -97,8 +110,11 @@ CTexture::~CTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CTexture::bindName(bool wrap)
|
void CTexture::bindName(uint32 flags)
|
||||||
{
|
{
|
||||||
|
bool wrap = ((flags & WrapTexture) != 0);
|
||||||
|
bool compress = ((flags & CompressTexture) != 0) && compressionSupported;
|
||||||
|
|
||||||
if (pixels == NULL)
|
if (pixels == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -110,8 +126,37 @@ void CTexture::bindName(bool wrap)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
|
||||||
|
int internalFormat = components;
|
||||||
|
if (compress)
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case GL_RGB:
|
||||||
|
case GL_BGR_EXT:
|
||||||
|
internalFormat = GL_COMPRESSED_RGB_ARB;
|
||||||
|
break;
|
||||||
|
case GL_RGBA:
|
||||||
|
internalFormat = GL_COMPRESSED_RGBA_ARB;
|
||||||
|
break;
|
||||||
|
case GL_ALPHA:
|
||||||
|
internalFormat = GL_COMPRESSED_ALPHA_ARB;
|
||||||
|
break;
|
||||||
|
case GL_LUMINANCE:
|
||||||
|
internalFormat = GL_COMPRESSED_LUMINANCE_ARB;
|
||||||
|
break;
|
||||||
|
case GL_LUMINANCE_ALPHA:
|
||||||
|
internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB;
|
||||||
|
break;
|
||||||
|
case GL_INTENSITY:
|
||||||
|
internalFormat = GL_COMPRESSED_INTENSITY_ARB;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
glHint((GLenum) GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST);
|
||||||
|
}
|
||||||
|
|
||||||
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
gluBuild2DMipmaps(GL_TEXTURE_2D,
|
||||||
components,
|
internalFormat,
|
||||||
width, height,
|
width, height,
|
||||||
format,
|
format,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define _TEXTURE_H_
|
#define _TEXTURE_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "basictypes.h"
|
||||||
|
|
||||||
|
|
||||||
typedef void (*ProceduralTexEval)(float, float, float, unsigned char*);
|
typedef void (*ProceduralTexEval)(float, float, float, unsigned char*);
|
||||||
|
@ -21,7 +22,12 @@ class CTexture
|
||||||
CTexture(int w, int h, int fmt);
|
CTexture(int w, int h, int fmt);
|
||||||
~CTexture();
|
~CTexture();
|
||||||
|
|
||||||
void bindName(bool wrap = false);
|
enum {
|
||||||
|
WrapTexture = 0x1,
|
||||||
|
CompressTexture = 0x2,
|
||||||
|
};
|
||||||
|
|
||||||
|
void bindName(uint32 flags = 0);
|
||||||
unsigned int getName();
|
unsigned int getName();
|
||||||
void normalMap(float scale, bool wrap);
|
void normalMap(float scale, bool wrap);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue