2010-03-26 17:55:17 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest Shared Library (www.glest.org)
|
|
|
|
//
|
2010-09-07 07:25:40 +02:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-26 17:55:17 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _SHARED_GRAPHICS_TEXTURE_H_
|
|
|
|
#define _SHARED_GRAPHICS_TEXTURE_H_
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "pixmap.h"
|
|
|
|
#include <string>
|
2010-09-07 07:25:40 +02:00
|
|
|
#include "leak_dumper.h"
|
2010-03-26 17:55:17 +01:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using Shared::Platform::uint8;
|
2010-10-28 23:06:20 +02:00
|
|
|
using Shared::Platform::uint64;
|
2010-03-26 17:55:17 +01:00
|
|
|
|
|
|
|
namespace Shared{ namespace Graphics{
|
|
|
|
|
|
|
|
class TextureParams;
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Texture
|
|
|
|
// =====================================================
|
|
|
|
|
2010-10-28 02:51:25 +02:00
|
|
|
class Texture {
|
2010-03-26 17:55:17 +01:00
|
|
|
public:
|
|
|
|
static const int defaultSize;
|
|
|
|
static const int defaultComponents;
|
2010-10-28 02:51:25 +02:00
|
|
|
static bool useTextureCompression;
|
2010-03-26 17:55:17 +01:00
|
|
|
|
|
|
|
enum WrapMode{
|
|
|
|
wmRepeat,
|
|
|
|
wmClamp,
|
|
|
|
wmClampToEdge
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Filter{
|
|
|
|
fBilinear,
|
|
|
|
fTrilinear
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Format{
|
|
|
|
fAuto,
|
|
|
|
fAlpha,
|
|
|
|
fLuminance,
|
|
|
|
fRgb,
|
|
|
|
fRgba
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
string path;
|
|
|
|
bool mipmap;
|
|
|
|
WrapMode wrapMode;
|
|
|
|
bool pixmapInit;
|
|
|
|
Format format;
|
|
|
|
|
|
|
|
bool inited;
|
2010-10-28 08:59:43 +02:00
|
|
|
bool forceCompressionDisabled;
|
2010-03-26 17:55:17 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Texture();
|
|
|
|
virtual ~Texture(){};
|
|
|
|
|
|
|
|
bool getMipmap() const {return mipmap;}
|
|
|
|
WrapMode getWrapMode() const {return wrapMode;}
|
|
|
|
bool getPixmapInit() const {return pixmapInit;}
|
|
|
|
Format getFormat() const {return format;}
|
|
|
|
|
|
|
|
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
|
|
|
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
|
|
|
void setPixmapInit(bool pixmapInit) {this->pixmapInit= pixmapInit;}
|
|
|
|
void setFormat(Format format) {this->format= format;}
|
|
|
|
|
|
|
|
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
2010-10-29 18:27:22 +02:00
|
|
|
virtual void end(bool deletePixelBuffer=true)=0;
|
2010-10-28 02:51:25 +02:00
|
|
|
virtual string getPath() const = 0;
|
|
|
|
virtual void deletePixels() = 0;
|
2010-10-28 23:06:20 +02:00
|
|
|
virtual uint64 getPixelByteCount() const = 0;
|
2010-04-05 22:42:05 +02:00
|
|
|
|
|
|
|
virtual void reseInitState() { inited = false; }
|
2010-10-28 08:59:43 +02:00
|
|
|
|
|
|
|
virtual void setForceCompressionDisabled(bool value) { forceCompressionDisabled = value;}
|
|
|
|
virtual bool getForceCompressionDisabled() const {return forceCompressionDisabled;}
|
|
|
|
|
2010-03-26 17:55:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Texture1D
|
|
|
|
// =====================================================
|
|
|
|
|
2010-11-01 17:44:05 +01:00
|
|
|
class Texture1D: public Texture {
|
2010-03-26 17:55:17 +01:00
|
|
|
protected:
|
|
|
|
Pixmap1D pixmap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void load(const string &path);
|
|
|
|
|
|
|
|
Pixmap1D *getPixmap() {return &pixmap;}
|
|
|
|
const Pixmap1D *getPixmap() const {return &pixmap;}
|
2010-10-28 02:51:25 +02:00
|
|
|
virtual string getPath() const;
|
|
|
|
virtual void deletePixels();
|
2010-10-28 23:06:20 +02:00
|
|
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
2010-11-01 17:44:05 +01:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
|
|
|
virtual int getTextureHeight() const {return -1;}
|
|
|
|
|
2010-03-26 17:55:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Texture2D
|
|
|
|
// =====================================================
|
|
|
|
|
2010-10-28 08:59:43 +02:00
|
|
|
class Texture2D: public Texture {
|
2010-03-26 17:55:17 +01:00
|
|
|
protected:
|
|
|
|
Pixmap2D pixmap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void load(const string &path);
|
|
|
|
|
2010-11-09 10:06:52 +01:00
|
|
|
Pixmap2D *getPixmap() {return &pixmap;}
|
|
|
|
const Pixmap2D *getPixmapConst() const {return &pixmap;}
|
2010-10-28 02:51:25 +02:00
|
|
|
virtual string getPath() const;
|
|
|
|
virtual void deletePixels();
|
2010-10-28 23:06:20 +02:00
|
|
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
2010-11-01 17:44:05 +01:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
|
|
|
virtual int getTextureHeight() const {return pixmap.getH();}
|
2010-03-26 17:55:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Texture3D
|
|
|
|
// =====================================================
|
|
|
|
|
2010-11-01 17:44:05 +01:00
|
|
|
class Texture3D: public Texture {
|
2010-03-26 17:55:17 +01:00
|
|
|
protected:
|
|
|
|
Pixmap3D pixmap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void loadSlice(const string &path, int slice);
|
|
|
|
|
|
|
|
Pixmap3D *getPixmap() {return &pixmap;}
|
|
|
|
const Pixmap3D *getPixmap() const {return &pixmap;}
|
2010-10-28 02:51:25 +02:00
|
|
|
virtual string getPath() const;
|
|
|
|
virtual void deletePixels();
|
2010-10-28 23:06:20 +02:00
|
|
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
2010-11-01 17:44:05 +01:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const {return pixmap.getW();}
|
|
|
|
virtual int getTextureHeight() const {return pixmap.getH();}
|
2010-03-26 17:55:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class TextureCube
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
class TextureCube: public Texture{
|
|
|
|
protected:
|
|
|
|
PixmapCube pixmap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void loadFace(const string &path, int face);
|
|
|
|
|
|
|
|
PixmapCube *getPixmap() {return &pixmap;}
|
|
|
|
const PixmapCube *getPixmap() const {return &pixmap;}
|
2010-10-28 02:51:25 +02:00
|
|
|
virtual string getPath() const;
|
|
|
|
virtual void deletePixels();
|
2010-10-28 23:06:20 +02:00
|
|
|
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
2010-11-01 17:44:05 +01:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const {return -1;}
|
|
|
|
virtual int getTextureHeight() const {return -1;}
|
2010-03-26 17:55:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|