Introduced support for compressed textures.

pull/3/head
Chris Laurel 2001-03-06 21:57:53 +00:00
parent e19df3cb7f
commit 2dfb8f333b
8 changed files with 78 additions and 12 deletions

View File

@ -856,7 +856,10 @@ void Renderer::renderPlanet(const Body& body,
if (surface.baseTexture != "")
{
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

View File

@ -167,6 +167,7 @@ class Renderer
int nSimultaneousTextures;
bool useRegisterCombiners;
bool useCubeMaps;
bool useCompressedTextures;
public:
friend bool operator<(const Renderer::RenderListEntry&,

View File

@ -174,12 +174,16 @@ static Body* CreatePlanet(PlanetarySystem* system,
bool applyBumpMap = planetData->getString("BumpMap", surface.bumpTexture);
bool blendTexture = false;
planetData->getBoolean("BlendTexture", blendTexture);
bool compressTexture = false;
planetData->getBoolean("CompressTexture", compressTexture);
if (blendTexture)
surface.appearanceFlags |= Surface::BlendTexture;
if (applyBaseTexture)
surface.appearanceFlags |= Surface::ApplyBaseTexture;
if (applyBumpMap)
surface.appearanceFlags |= Surface::ApplyBumpMap;
if (compressTexture)
surface.appearanceFlags |= Surface::CompressBaseTexture;
body->setSurface(surface);
string mesh("");

View File

@ -23,9 +23,10 @@ class Surface
// Appearance flags
enum {
BlendTexture = 0x1,
ApplyBaseTexture = 0x2,
ApplyBumpMap = 0x4,
BlendTexture = 0x1,
ApplyBaseTexture = 0x2,
ApplyBumpMap = 0x4,
CompressBaseTexture = 0x8,
};
Color color;

View File

@ -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());
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
if (tex != NULL)
tex->bindName(true);
{
uint32 texFlags = CTexture::WrapTexture;
if (compress)
texFlags |= CTexture::CompressTexture;
tex->bindName(texFlags);
}
addResource(name, (void*) tex);
return tex;
@ -43,8 +49,8 @@ CTexture* TextureManager::loadBumpMap(const string& name)
CTexture* tex = LoadTextureFromFile(baseDir + "\\" + name);
if (tex != NULL)
{
tex->normalMap(5.0f, true);
tex->bindName();
tex->normalMap(2.5f, true);
tex->bindName(CTexture::WrapTexture);
}
addResource(name, static_cast<void*>(tex));

View File

@ -25,7 +25,7 @@ class TextureManager : public ResourceManager
~TextureManager();
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);
};

View File

@ -48,6 +48,15 @@ typedef struct
unsigned int colorsImportant;
} 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) :
@ -58,6 +67,10 @@ CTexture::CTexture(int w, int h, int fmt) :
cmap = NULL;
cmapEntries = 0;
// Yuck . . .
if (!initialized)
initTextureLoader();
switch (format)
{
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)
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_MAG_FILTER, GL_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,
components,
internalFormat,
width, height,
format,
GL_UNSIGNED_BYTE,

View File

@ -11,6 +11,7 @@
#define _TEXTURE_H_
#include <string>
#include "basictypes.h"
typedef void (*ProceduralTexEval)(float, float, float, unsigned char*);
@ -21,7 +22,12 @@ class CTexture
CTexture(int w, int h, int fmt);
~CTexture();
void bindName(bool wrap = false);
enum {
WrapTexture = 0x1,
CompressTexture = 0x2,
};
void bindName(uint32 flags = 0);
unsigned int getName();
void normalMap(float scale, bool wrap);