mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 11:54:00 +02:00
- cleanup of texture compression. We output stats for textures that we attempt to compress and what percent they were compressed (before and after byte sizes)
This commit is contained in:
@@ -89,9 +89,11 @@ void CoreData::load(){
|
|||||||
waterSplashTexture->getPixmap()->load(dir+"/misc_textures/water_splash.tga");
|
waterSplashTexture->getPixmap()->load(dir+"/misc_textures/water_splash.tga");
|
||||||
|
|
||||||
buttonSmallTexture= renderer.newTexture2D(rsGlobal);
|
buttonSmallTexture= renderer.newTexture2D(rsGlobal);
|
||||||
|
buttonSmallTexture->setForceCompressionDisabled(true);
|
||||||
buttonSmallTexture->getPixmap()->load(dir+"/menu/textures/button_small.tga");
|
buttonSmallTexture->getPixmap()->load(dir+"/menu/textures/button_small.tga");
|
||||||
|
|
||||||
buttonBigTexture= renderer.newTexture2D(rsGlobal);
|
buttonBigTexture= renderer.newTexture2D(rsGlobal);
|
||||||
|
buttonBigTexture->setForceCompressionDisabled(true);
|
||||||
buttonBigTexture->getPixmap()->load(dir+"/menu/textures/button_big.tga");
|
buttonBigTexture->getPixmap()->load(dir+"/menu/textures/button_big.tga");
|
||||||
|
|
||||||
//display font
|
//display font
|
||||||
|
@@ -24,20 +24,24 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
|||||||
|
|
||||||
class TextureGl {
|
class TextureGl {
|
||||||
protected:
|
protected:
|
||||||
GLuint handle;
|
GLuint handle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
TextureGl();
|
||||||
GLuint getHandle() const {return handle;}
|
GLuint getHandle() const {return handle;}
|
||||||
|
|
||||||
void OutputTextureDebugInfo(Texture::Format format, int components, const string path);
|
void OutputTextureDebugInfo(Texture::Format format, int components, const string path,uint64 rawSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Texture1DGl
|
// class Texture1DGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Texture1DGl: public Texture1D, public TextureGl{
|
class Texture1DGl: public Texture1D, public TextureGl {
|
||||||
public:
|
public:
|
||||||
|
Texture1DGl();
|
||||||
|
virtual ~Texture1DGl();
|
||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end();
|
virtual void end();
|
||||||
};
|
};
|
||||||
@@ -48,6 +52,9 @@ public:
|
|||||||
|
|
||||||
class Texture2DGl: public Texture2D, public TextureGl{
|
class Texture2DGl: public Texture2D, public TextureGl{
|
||||||
public:
|
public:
|
||||||
|
Texture2DGl();
|
||||||
|
virtual ~Texture2DGl();
|
||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end();
|
virtual void end();
|
||||||
};
|
};
|
||||||
@@ -58,6 +65,10 @@ public:
|
|||||||
|
|
||||||
class Texture3DGl: public Texture3D, public TextureGl{
|
class Texture3DGl: public Texture3D, public TextureGl{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Texture3DGl();
|
||||||
|
virtual ~Texture3DGl();
|
||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end();
|
virtual void end();
|
||||||
};
|
};
|
||||||
@@ -68,6 +79,10 @@ public:
|
|||||||
|
|
||||||
class TextureCubeGl: public TextureCube, public TextureGl{
|
class TextureCubeGl: public TextureCube, public TextureGl{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
TextureCubeGl();
|
||||||
|
virtual ~TextureCubeGl();
|
||||||
|
|
||||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||||
virtual void end();
|
virtual void end();
|
||||||
};
|
};
|
||||||
|
@@ -24,6 +24,7 @@ using Shared::Platform::int16;
|
|||||||
using Shared::Platform::uint16;
|
using Shared::Platform::uint16;
|
||||||
using Shared::Platform::int32;
|
using Shared::Platform::int32;
|
||||||
using Shared::Platform::uint32;
|
using Shared::Platform::uint32;
|
||||||
|
using Shared::Platform::uint64;
|
||||||
using Shared::Platform::float32;
|
using Shared::Platform::float32;
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{
|
namespace Shared{ namespace Graphics{
|
||||||
@@ -97,7 +98,7 @@ public:
|
|||||||
// class Pixmap1D
|
// class Pixmap1D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Pixmap1D{
|
class Pixmap1D {
|
||||||
protected:
|
protected:
|
||||||
int w;
|
int w;
|
||||||
int components;
|
int components;
|
||||||
@@ -124,13 +125,14 @@ public:
|
|||||||
uint8 *getPixels() const {return pixels;}
|
uint8 *getPixels() const {return pixels;}
|
||||||
void deletePixels();
|
void deletePixels();
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
|
uint64 getPixelByteCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Pixmap2D
|
// class Pixmap2D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Pixmap2D{
|
class Pixmap2D {
|
||||||
protected:
|
protected:
|
||||||
int h;
|
int h;
|
||||||
int w;
|
int w;
|
||||||
@@ -199,6 +201,7 @@ public:
|
|||||||
void copy(const Pixmap2D *sourcePixmap);
|
void copy(const Pixmap2D *sourcePixmap);
|
||||||
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
|
uint64 getPixelByteCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool doDimensionsAgree(const Pixmap2D *pixmap);
|
bool doDimensionsAgree(const Pixmap2D *pixmap);
|
||||||
@@ -208,7 +211,7 @@ private:
|
|||||||
// class Pixmap3D
|
// class Pixmap3D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Pixmap3D{
|
class Pixmap3D {
|
||||||
protected:
|
protected:
|
||||||
int h;
|
int h;
|
||||||
int w;
|
int w;
|
||||||
@@ -240,13 +243,14 @@ public:
|
|||||||
uint8 *getPixels() const {return pixels;}
|
uint8 *getPixels() const {return pixels;}
|
||||||
void deletePixels();
|
void deletePixels();
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
|
uint64 getPixelByteCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class PixmapCube
|
// class PixmapCube
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class PixmapCube{
|
class PixmapCube {
|
||||||
public:
|
public:
|
||||||
enum Face{
|
enum Face{
|
||||||
fPositiveX,
|
fPositiveX,
|
||||||
@@ -276,6 +280,7 @@ public:
|
|||||||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||||
void deletePixels();
|
void deletePixels();
|
||||||
string getPath(int face) const { return path[face];}
|
string getPath(int face) const { return path[face];}
|
||||||
|
uint64 getPixelByteCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -61,6 +61,7 @@ protected:
|
|||||||
Format format;
|
Format format;
|
||||||
|
|
||||||
bool inited;
|
bool inited;
|
||||||
|
bool forceCompressionDisabled;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Texture();
|
Texture();
|
||||||
@@ -82,6 +83,10 @@ public:
|
|||||||
virtual void deletePixels() = 0;
|
virtual void deletePixels() = 0;
|
||||||
|
|
||||||
virtual void reseInitState() { inited = false; }
|
virtual void reseInitState() { inited = false; }
|
||||||
|
|
||||||
|
virtual void setForceCompressionDisabled(bool value) { forceCompressionDisabled = value;}
|
||||||
|
virtual bool getForceCompressionDisabled() const {return forceCompressionDisabled;}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -105,7 +110,7 @@ public:
|
|||||||
// class Texture2D
|
// class Texture2D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Texture2D: public Texture{
|
class Texture2D: public Texture {
|
||||||
protected:
|
protected:
|
||||||
Pixmap2D pixmap;
|
Pixmap2D pixmap;
|
||||||
|
|
||||||
|
@@ -23,6 +23,8 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
|||||||
|
|
||||||
using namespace Platform;
|
using namespace Platform;
|
||||||
|
|
||||||
|
const uint64 MIN_BYTES_TO_COMPRESS = 12;
|
||||||
|
|
||||||
GLint toCompressionFormatGl(GLint format) {
|
GLint toCompressionFormatGl(GLint format) {
|
||||||
if(Texture::useTextureCompression == false) {
|
if(Texture::useTextureCompression == false) {
|
||||||
return format;
|
return format;
|
||||||
@@ -134,20 +136,31 @@ GLint toInternalFormatGl(Texture::Format format, int components){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureGl::TextureGl() {
|
||||||
|
handle=0;
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Texture1DGl
|
// class Texture1DGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
Texture1DGl::Texture1DGl() {}
|
||||||
|
|
||||||
void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
Texture1DGl::~Texture1DGl() {
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture1DGl::init(Filter filter, int maxAnisotropy) {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
if(!inited) {
|
if(inited == false) {
|
||||||
|
|
||||||
//params
|
//params
|
||||||
GLint wrap= toWrapModeGl(wrapMode);
|
GLint wrap= toWrapModeGl(wrapMode);
|
||||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||||
|
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||||
|
glCompressionFormat = glInternalFormat;
|
||||||
|
}
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||||
@@ -164,7 +177,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mipmap){
|
if(mipmap) {
|
||||||
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
||||||
|
|
||||||
//build mipmaps
|
//build mipmaps
|
||||||
@@ -175,14 +188,14 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
GL_TEXTURE_1D, glCompressionFormat, pixmap.getW(),
|
GL_TEXTURE_1D, glCompressionFormat, pixmap.getW(),
|
||||||
glFormat, GL_UNSIGNED_BYTE, pixels);
|
glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
if(error!=0){
|
if(error != 0) {
|
||||||
//throw runtime_error("Error building texture 1D mipmaps");
|
//throw runtime_error("Error building texture 1D mipmaps");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error building texture 1D mipmaps, returned: %d [%s] w = %d",error,pixmap.getPath().c_str(),pixmap.getW());
|
sprintf(szBuf,"Error building texture 1D mipmaps, returned: %d [%s] w = %d",error,pixmap.getPath().c_str(),pixmap.getW());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
//build single texture
|
//build single texture
|
||||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
@@ -200,17 +213,20 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture1DGl::end(){
|
void Texture1DGl::end() {
|
||||||
if(inited){
|
if(inited == true) {
|
||||||
assertGl();
|
assertGl();
|
||||||
glDeleteTextures(1, &handle);
|
glDeleteTextures(1, &handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
|
handle=0;
|
||||||
|
inited=false;
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,16 +234,24 @@ void Texture1DGl::end(){
|
|||||||
// class Texture2DGl
|
// class Texture2DGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
Texture2DGl::Texture2DGl() {}
|
||||||
|
|
||||||
|
Texture2DGl::~Texture2DGl() {
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture2DGl::init(Filter filter, int maxAnisotropy) {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
if(!inited) {
|
if(inited == false) {
|
||||||
|
|
||||||
//params
|
//params
|
||||||
GLint wrap= toWrapModeGl(wrapMode);
|
GLint wrap= toWrapModeGl(wrapMode);
|
||||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||||
|
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||||
|
glCompressionFormat = glInternalFormat;
|
||||||
|
}
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||||
@@ -241,11 +265,11 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
||||||
|
|
||||||
//maxAnisotropy
|
//maxAnisotropy
|
||||||
if(isGlExtensionSupported("GL_EXT_texture_filter_anisotropic")){
|
if(isGlExtensionSupported("GL_EXT_texture_filter_anisotropic")) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mipmap){
|
if(mipmap) {
|
||||||
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
||||||
|
|
||||||
//build mipmaps
|
//build mipmaps
|
||||||
@@ -257,14 +281,14 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
pixmap.getW(), pixmap.getH(),
|
pixmap.getW(), pixmap.getH(),
|
||||||
glFormat, GL_UNSIGNED_BYTE, pixels);
|
glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
if(error!=0){
|
if(error != 0) {
|
||||||
//throw runtime_error("Error building texture 2D mipmaps");
|
//throw runtime_error("Error building texture 2D mipmaps");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH());
|
sprintf(szBuf,"Error building texture 2D mipmaps, returned: %d [%s] w = %d, h = %d",error,(pixmap.getPath() != "" ? pixmap.getPath().c_str() : this->path.c_str()),pixmap.getW(),pixmap.getH());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
//build single texture
|
//build single texture
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
@@ -277,25 +301,28 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
|
|
||||||
//throw runtime_error("TEST!");
|
//throw runtime_error("TEST!");
|
||||||
|
|
||||||
if(error!=GL_NO_ERROR){
|
if(error != GL_NO_ERROR) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture 2D, returned: %d [%s] w = %d, h = %d, glInternalFormat = %d, glFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),glInternalFormat,glFormat);
|
sprintf(szBuf,"Error creating texture 2D, returned: %d [%s] w = %d, h = %d, glInternalFormat = %d, glFormat = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),glInternalFormat,glFormat);
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2DGl::end(){
|
void Texture2DGl::end() {
|
||||||
if(inited) {
|
if(inited == true) {
|
||||||
//printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle);
|
//printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
glDeleteTextures(1, &handle);
|
glDeleteTextures(1, &handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
|
handle=0;
|
||||||
|
inited=false;
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,16 +330,24 @@ void Texture2DGl::end(){
|
|||||||
// class Texture3DGl
|
// class Texture3DGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
Texture3DGl::Texture3DGl() {}
|
||||||
|
|
||||||
|
Texture3DGl::~Texture3DGl() {
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture3DGl::init(Filter filter, int maxAnisotropy) {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
if(!inited){
|
if(inited == false) {
|
||||||
|
|
||||||
//params
|
//params
|
||||||
GLint wrap= toWrapModeGl(wrapMode);
|
GLint wrap= toWrapModeGl(wrapMode);
|
||||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||||
|
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||||
|
glCompressionFormat = glInternalFormat;
|
||||||
|
}
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||||
@@ -336,7 +371,7 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
GLint error= glGetError();
|
GLint error= glGetError();
|
||||||
if(error!=GL_NO_ERROR){
|
if(error != GL_NO_ERROR) {
|
||||||
//throw runtime_error("Error creating texture 3D");
|
//throw runtime_error("Error creating texture 3D");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture 3D, returned: %d [%s] w = %d, h = %d, d = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),pixmap.getD());
|
sprintf(szBuf,"Error creating texture 3D, returned: %d [%s] w = %d, h = %d, d = %d",error,pixmap.getPath().c_str(),pixmap.getW(),pixmap.getH(),pixmap.getD());
|
||||||
@@ -344,17 +379,21 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
|
||||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture3DGl::end(){
|
void Texture3DGl::end() {
|
||||||
if(inited){
|
if(inited == true) {
|
||||||
assertGl();
|
assertGl();
|
||||||
glDeleteTextures(1, &handle);
|
glDeleteTextures(1, &handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
|
handle=0;
|
||||||
|
inited=false;
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,11 +401,16 @@ void Texture3DGl::end(){
|
|||||||
// class TextureCubeGl
|
// class TextureCubeGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
TextureCubeGl::TextureCubeGl() {}
|
||||||
|
|
||||||
|
TextureCubeGl::~TextureCubeGl() {
|
||||||
|
end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
if(!inited){
|
if(inited == false) {
|
||||||
|
|
||||||
//gen texture
|
//gen texture
|
||||||
glGenTextures(1, &handle);
|
glGenTextures(1, &handle);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, handle);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, handle);
|
||||||
@@ -377,42 +421,45 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrap);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrap);
|
||||||
|
|
||||||
//filter
|
//filter
|
||||||
if(mipmap){
|
if(mipmap) {
|
||||||
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST;
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, glFilter);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, glFilter);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<6; ++i){
|
for(int i = 0; i < 6; ++i) {
|
||||||
//params
|
//params
|
||||||
const Pixmap2D *currentPixmap= pixmap.getFace(i);
|
const Pixmap2D *currentPixmap= pixmap.getFace(i);
|
||||||
|
|
||||||
GLint glFormat= toFormatGl(format, currentPixmap->getComponents());
|
GLint glFormat= toFormatGl(format, currentPixmap->getComponents());
|
||||||
GLint glInternalFormat= toInternalFormatGl(format, currentPixmap->getComponents());
|
GLint glInternalFormat= toInternalFormatGl(format, currentPixmap->getComponents());
|
||||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||||
|
if(forceCompressionDisabled == true || (currentPixmap->getPixelByteCount() > 0 && currentPixmap->getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||||
|
glCompressionFormat = glInternalFormat;
|
||||||
|
}
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? currentPixmap->getPixels(): NULL;
|
const uint8* pixels= pixmapInit? currentPixmap->getPixels(): NULL;
|
||||||
GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
|
GLenum target= GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
|
||||||
|
|
||||||
if(mipmap){
|
if(mipmap) {
|
||||||
int error= gluBuild2DMipmaps(
|
int error= gluBuild2DMipmaps(
|
||||||
target, glCompressionFormat,
|
target, glCompressionFormat,
|
||||||
currentPixmap->getW(), currentPixmap->getH(),
|
currentPixmap->getW(), currentPixmap->getH(),
|
||||||
glFormat, GL_UNSIGNED_BYTE, pixels);
|
glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
if(error!=0){
|
if(error != 0) {
|
||||||
//throw runtime_error("Error building texture cube mipmaps");
|
//throw runtime_error("Error building texture cube mipmaps");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH());
|
sprintf(szBuf,"Error building texture cube mipmaps, returned: %d [%s] w = %d, h = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
target, 0, glCompressionFormat,
|
target, 0, glCompressionFormat,
|
||||||
currentPixmap->getW(), currentPixmap->getH(),
|
currentPixmap->getW(), currentPixmap->getH(),
|
||||||
@@ -420,14 +467,14 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int error = glGetError();
|
int error = glGetError();
|
||||||
if(error!=GL_NO_ERROR){
|
if(error != GL_NO_ERROR) {
|
||||||
//throw runtime_error("Error creating texture cube");
|
//throw runtime_error("Error creating texture cube");
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"Error creating texture cube, returned: %d [%s] w = %d, h = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH());
|
sprintf(szBuf,"Error creating texture cube, returned: %d [%s] w = %d, h = %d",error,currentPixmap->getPath().c_str(),currentPixmap->getW(),currentPixmap->getH());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath());
|
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath(),currentPixmap->getPixelByteCount());
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
|
||||||
@@ -436,19 +483,23 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCubeGl::end(){
|
void TextureCubeGl::end() {
|
||||||
if(inited){
|
if(inited == true) {
|
||||||
assertGl();
|
assertGl();
|
||||||
glDeleteTextures(1, &handle);
|
glDeleteTextures(1, &handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
|
handle=0;
|
||||||
|
inited=false;
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,const string path) {
|
void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,const string path,uint64 rawSize) {
|
||||||
if(Texture::useTextureCompression == true) {
|
if(Texture::useTextureCompression == true) {
|
||||||
GLint glFormat= toFormatGl(format, components);
|
GLint glFormat= toFormatGl(format, components);
|
||||||
|
|
||||||
printf("**** Texture filename: [%s] format = %d components = %d, glFormat = %d\n",path.c_str(),format,components,glFormat);
|
printf("**** Texture filename: [%s] format = %d components = %d, glFormat = %d, rawSize = %llu\n",path.c_str(),format,components,glFormat,(long long unsigned int)rawSize);
|
||||||
|
|
||||||
GLint compressed=0;
|
GLint compressed=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
||||||
@@ -456,10 +507,17 @@ void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,co
|
|||||||
|
|
||||||
printf("**** Texture compressed status: %d, error [%d]\n",compressed,error);
|
printf("**** Texture compressed status: %d, error [%d]\n",compressed,error);
|
||||||
|
|
||||||
|
bool isCompressed = (compressed == 1);
|
||||||
compressed=0;
|
compressed=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
printf("**** Texture image size in video RAM: %d, error [%d]\n",compressed,error);
|
|
||||||
|
double percent = 0;
|
||||||
|
if(isCompressed == true) {
|
||||||
|
percent = ((double)compressed / (double)rawSize) * (double)100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("**** Texture image size in video RAM: %d [%.2f%%], error [%d]\n",compressed,percent,error);
|
||||||
|
|
||||||
compressed=0;
|
compressed=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
||||||
|
@@ -84,19 +84,20 @@ const int tgaUncompressedBw= 3;
|
|||||||
// class PixmapIoTga
|
// class PixmapIoTga
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
PixmapIoTga::PixmapIoTga(){
|
PixmapIoTga::PixmapIoTga() {
|
||||||
file= NULL;
|
file= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PixmapIoTga::~PixmapIoTga(){
|
PixmapIoTga::~PixmapIoTga() {
|
||||||
if(file!=NULL){
|
if(file != NULL) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
file=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::openRead(const string &path){
|
void PixmapIoTga::openRead(const string &path) {
|
||||||
file= fopen(path.c_str(),"rb");
|
file= fopen(path.c_str(),"rb");
|
||||||
if (file==NULL){
|
if (file == NULL) {
|
||||||
throw runtime_error("Can't open TGA file: "+ path);
|
throw runtime_error("Can't open TGA file: "+ path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,53 +106,53 @@ void PixmapIoTga::openRead(const string &path){
|
|||||||
size_t readBytes = fread(&fileHeader, sizeof(TargaFileHeader), 1, file);
|
size_t readBytes = fread(&fileHeader, sizeof(TargaFileHeader), 1, file);
|
||||||
|
|
||||||
//check that we can load this tga file
|
//check that we can load this tga file
|
||||||
if(fileHeader.idLength!=0){
|
if(fileHeader.idLength != 0) {
|
||||||
throw runtime_error(path + ": id field is not 0");
|
throw runtime_error(path + ": id field is not 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileHeader.dataTypeCode!=tgaUncompressedRgb && fileHeader.dataTypeCode!=tgaUncompressedBw){
|
if(fileHeader.dataTypeCode != tgaUncompressedRgb && fileHeader.dataTypeCode != tgaUncompressedBw) {
|
||||||
throw runtime_error(path + ": only uncompressed BW and RGB targa images are supported");
|
throw runtime_error(path + ": only uncompressed BW and RGB targa images are supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
//check bits per pixel
|
//check bits per pixel
|
||||||
if(fileHeader.bitsPerPixel!=8 && fileHeader.bitsPerPixel!=24 && fileHeader.bitsPerPixel!=32){
|
if(fileHeader.bitsPerPixel != 8 && fileHeader.bitsPerPixel != 24 && fileHeader.bitsPerPixel !=32) {
|
||||||
throw runtime_error(path + ": only 8, 24 and 32 bit targa images are supported");
|
throw runtime_error(path + ": only 8, 24 and 32 bit targa images are supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
h= fileHeader.height;
|
h= fileHeader.height;
|
||||||
w= fileHeader.width;
|
w= fileHeader.width;
|
||||||
components= fileHeader.bitsPerPixel/8;
|
components= fileHeader.bitsPerPixel / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::read(uint8 *pixels){
|
void PixmapIoTga::read(uint8 *pixels) {
|
||||||
read(pixels, components);
|
read(pixels, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::read(uint8 *pixels, int components){
|
void PixmapIoTga::read(uint8 *pixels, int components) {
|
||||||
for(int i=0; i<h*w*components; i+=components){
|
for(int i=0; i<h*w*components; i+=components) {
|
||||||
uint8 r, g, b, a, l;
|
uint8 r=0, g=0, b=0, a=0, l=0;
|
||||||
|
|
||||||
if(this->components==1){
|
if(this->components == 1) {
|
||||||
size_t readBytes = fread(&l, 1, 1, file);
|
size_t readBytes = fread(&l, 1, 1, file);
|
||||||
r= l;
|
r= l;
|
||||||
g= l;
|
g= l;
|
||||||
b= l;
|
b= l;
|
||||||
a= 255;
|
a= 255;
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
size_t readBytes = fread(&b, 1, 1, file);
|
size_t readBytes = fread(&b, 1, 1, file);
|
||||||
readBytes = fread(&g, 1, 1, file);
|
readBytes = fread(&g, 1, 1, file);
|
||||||
readBytes = fread(&r, 1, 1, file);
|
readBytes = fread(&r, 1, 1, file);
|
||||||
if(this->components==4){
|
if(this->components == 4) {
|
||||||
readBytes = fread(&a, 1, 1, file);
|
readBytes = fread(&a, 1, 1, file);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
a= 255;
|
a= 255;
|
||||||
}
|
}
|
||||||
l= (r+g+b)/3;
|
l= (r+g+b)/3;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(components){
|
switch(components) {
|
||||||
case 1:
|
case 1:
|
||||||
pixels[i]= l;
|
pixels[i]= l;
|
||||||
break;
|
break;
|
||||||
@@ -170,13 +171,13 @@ void PixmapIoTga::read(uint8 *pixels, int components){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::openWrite(const string &path, int w, int h, int components){
|
void PixmapIoTga::openWrite(const string &path, int w, int h, int components) {
|
||||||
this->w= w;
|
this->w= w;
|
||||||
this->h= h;
|
this->h= h;
|
||||||
this->components= components;
|
this->components= components;
|
||||||
|
|
||||||
file= fopen(path.c_str(),"wb");
|
file= fopen(path.c_str(),"wb");
|
||||||
if (file==NULL){
|
if (file == NULL) {
|
||||||
throw runtime_error("Can't open TGA file: "+ path);
|
throw runtime_error("Can't open TGA file: "+ path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,12 +192,12 @@ void PixmapIoTga::openWrite(const string &path, int w, int h, int components){
|
|||||||
fwrite(&fileHeader, sizeof(TargaFileHeader), 1, file);
|
fwrite(&fileHeader, sizeof(TargaFileHeader), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::write(uint8 *pixels){
|
void PixmapIoTga::write(uint8 *pixels) {
|
||||||
if(components==1){
|
if(components == 1) {
|
||||||
fwrite(pixels, h*w, 1, file);
|
fwrite(pixels, h*w, 1, file);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
for(int i=0; i<h*w*components; i+=components){
|
for(int i=0; i<h*w*components; i+=components) {
|
||||||
fwrite(&pixels[i+2], 1, 1, file);
|
fwrite(&pixels[i+2], 1, 1, file);
|
||||||
fwrite(&pixels[i+1], 1, 1, file);
|
fwrite(&pixels[i+1], 1, 1, file);
|
||||||
fwrite(&pixels[i], 1, 1, file);
|
fwrite(&pixels[i], 1, 1, file);
|
||||||
@@ -211,13 +212,14 @@ void PixmapIoTga::write(uint8 *pixels){
|
|||||||
// class PixmapIoBmp
|
// class PixmapIoBmp
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
PixmapIoBmp::PixmapIoBmp(){
|
PixmapIoBmp::PixmapIoBmp() {
|
||||||
file= NULL;
|
file= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PixmapIoBmp::~PixmapIoBmp(){
|
PixmapIoBmp::~PixmapIoBmp() {
|
||||||
if(file!=NULL){
|
if(file!=NULL){
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
file=NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,12 +248,12 @@ void PixmapIoBmp::openRead(const string &path){
|
|||||||
components= 3;
|
components= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoBmp::read(uint8 *pixels){
|
void PixmapIoBmp::read(uint8 *pixels) {
|
||||||
read(pixels, 3);
|
read(pixels, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoBmp::read(uint8 *pixels, int components){
|
void PixmapIoBmp::read(uint8 *pixels, int components) {
|
||||||
for(int i=0; i<h*w*components; i+=components){
|
for(int i=0; i<h*w*components; i+=components) {
|
||||||
uint8 r, g, b;
|
uint8 r, g, b;
|
||||||
size_t readBytes = fread(&b, 1, 1, file);
|
size_t readBytes = fread(&b, 1, 1, file);
|
||||||
readBytes = fread(&g, 1, 1, file);
|
readBytes = fread(&g, 1, 1, file);
|
||||||
@@ -276,13 +278,13 @@ void PixmapIoBmp::read(uint8 *pixels, int components){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoBmp::openWrite(const string &path, int w, int h, int components){
|
void PixmapIoBmp::openWrite(const string &path, int w, int h, int components) {
|
||||||
this->w= w;
|
this->w= w;
|
||||||
this->h= h;
|
this->h= h;
|
||||||
this->components= components;
|
this->components= components;
|
||||||
|
|
||||||
file= fopen(path.c_str(),"wb");
|
file= fopen(path.c_str(),"wb");
|
||||||
if (file==NULL){
|
if (file == NULL) {
|
||||||
throw runtime_error("Can't open BMP file for writting: "+ path);
|
throw runtime_error("Can't open BMP file for writting: "+ path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +313,7 @@ void PixmapIoBmp::openWrite(const string &path, int w, int h, int components){
|
|||||||
fwrite(&infoHeader, sizeof(BitmapInfoHeader), 1, file);
|
fwrite(&infoHeader, sizeof(BitmapInfoHeader), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoBmp::write(uint8 *pixels){
|
void PixmapIoBmp::write(uint8 *pixels) {
|
||||||
for (int i=0; i<h*w*components; i+=components){
|
for (int i=0; i<h*w*components; i+=components){
|
||||||
fwrite(&pixels[i+2], 1, 1, file);
|
fwrite(&pixels[i+2], 1, 1, file);
|
||||||
fwrite(&pixels[i+1], 1, 1, file);
|
fwrite(&pixels[i+1], 1, 1, file);
|
||||||
@@ -349,7 +351,11 @@ void Pixmap1D::init(int components){
|
|||||||
void Pixmap1D::init(int w, int components){
|
void Pixmap1D::init(int w, int components){
|
||||||
this->w= w;
|
this->w= w;
|
||||||
this->components= components;
|
this->components= components;
|
||||||
pixels= new uint8[w*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 Pixmap1D::getPixelByteCount() const {
|
||||||
|
return (w * components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap1D::deletePixels() {
|
void Pixmap1D::deletePixels() {
|
||||||
@@ -361,72 +367,72 @@ Pixmap1D::~Pixmap1D(){
|
|||||||
deletePixels();
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap1D::load(const string &path){
|
void Pixmap1D::load(const string &path) {
|
||||||
string extension= path.substr(path.find_last_of('.')+1);
|
string extension= path.substr(path.find_last_of('.')+1);
|
||||||
if(extension=="bmp"){
|
if(extension=="bmp") {
|
||||||
loadBmp(path);
|
loadBmp(path);
|
||||||
}
|
}
|
||||||
else if(extension=="tga"){
|
else if(extension=="tga") {
|
||||||
loadTga(path);
|
loadTga(path);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Unknown pixmap extension: "+extension);
|
throw runtime_error("Unknown pixmap extension: " + extension);
|
||||||
}
|
}
|
||||||
this->path = path;
|
this->path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap1D::loadBmp(const string &path){
|
void Pixmap1D::loadBmp(const string &path) {
|
||||||
this->path = path;
|
this->path = path;
|
||||||
|
|
||||||
PixmapIoBmp plb;
|
PixmapIoBmp plb;
|
||||||
plb.openRead(path);
|
plb.openRead(path);
|
||||||
|
|
||||||
//init
|
//init
|
||||||
if(plb.getH()==1){
|
if(plb.getH()==1) {
|
||||||
w= plb.getW();
|
w= plb.getW();
|
||||||
}
|
}
|
||||||
else if(plb.getW()==1){
|
else if(plb.getW()==1) {
|
||||||
w= plb.getH();
|
w= plb.getH();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("One of the texture dimensions must be 1");
|
throw runtime_error("One of the texture dimensions must be 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(components==-1){
|
if(components == -1) {
|
||||||
components= 3;
|
components= 3;
|
||||||
}
|
}
|
||||||
if(pixels==NULL){
|
if(pixels == NULL) {
|
||||||
pixels= new uint8[w*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
}
|
}
|
||||||
|
|
||||||
//data
|
//data
|
||||||
plb.read(pixels, components);
|
plb.read(pixels, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap1D::loadTga(const string &path){
|
void Pixmap1D::loadTga(const string &path) {
|
||||||
this->path = path;
|
this->path = path;
|
||||||
|
|
||||||
PixmapIoTga plt;
|
PixmapIoTga plt;
|
||||||
plt.openRead(path);
|
plt.openRead(path);
|
||||||
|
|
||||||
//init
|
//init
|
||||||
if(plt.getH()==1){
|
if(plt.getH()==1) {
|
||||||
w= plt.getW();
|
w= plt.getW();
|
||||||
}
|
}
|
||||||
else if(plt.getW()==1){
|
else if(plt.getW()==1) {
|
||||||
w= plt.getH();
|
w= plt.getH();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("One of the texture dimensions must be 1");
|
throw runtime_error("One of the texture dimensions must be 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileComponents= plt.getComponents();
|
int fileComponents= plt.getComponents();
|
||||||
|
|
||||||
if(components==-1){
|
if(components == -1) {
|
||||||
components= fileComponents;
|
components= fileComponents;
|
||||||
}
|
}
|
||||||
if(pixels==NULL){
|
if(pixels == NULL) {
|
||||||
pixels= new uint8[w*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
}
|
}
|
||||||
|
|
||||||
//read data
|
//read data
|
||||||
@@ -465,7 +471,11 @@ void Pixmap2D::init(int w, int h, int components) {
|
|||||||
this->w= w;
|
this->w= w;
|
||||||
this->h= h;
|
this->h= h;
|
||||||
this->components= components;
|
this->components= components;
|
||||||
pixels= new uint8[h*w*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 Pixmap2D::getPixelByteCount() const {
|
||||||
|
return (h * w * components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::deletePixels() {
|
void Pixmap2D::deletePixels() {
|
||||||
@@ -473,7 +483,7 @@ void Pixmap2D::deletePixels() {
|
|||||||
pixels = NULL;
|
pixels = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap2D::~Pixmap2D(){
|
Pixmap2D::~Pixmap2D() {
|
||||||
deletePixels();
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,14 +506,14 @@ void Pixmap2D::load(const string &path) {
|
|||||||
|
|
||||||
void Pixmap2D::save(const string &path) {
|
void Pixmap2D::save(const string &path) {
|
||||||
string extension= path.substr(path.find_last_of('.')+1);
|
string extension= path.substr(path.find_last_of('.')+1);
|
||||||
if(extension=="bmp"){
|
if(extension == "bmp") {
|
||||||
saveBmp(path);
|
saveBmp(path);
|
||||||
}
|
}
|
||||||
else if(extension=="tga"){
|
else if(extension == "tga") {
|
||||||
saveTga(path);
|
saveTga(path);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Unknown pixmap extension: "+extension);
|
throw runtime_error("Unknown pixmap extension: " + extension);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,28 +529,28 @@ void Pixmap2D::saveTga(const string &path) {
|
|||||||
pst.write(pixels);
|
pst.write(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::getPixel(int x, int y, uint8 *value) const{
|
void Pixmap2D::getPixel(int x, int y, uint8 *value) const {
|
||||||
for(int i=0; i<components; ++i){
|
for(int i=0; i<components; ++i){
|
||||||
value[i]= pixels[(w*y+x)*components+i];
|
value[i]= pixels[(w*y+x)*components+i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::getPixel(int x, int y, float32 *value) const{
|
void Pixmap2D::getPixel(int x, int y, float32 *value) const {
|
||||||
for(int i=0; i<components; ++i){
|
for(int i=0; i<components; ++i) {
|
||||||
value[i]= pixels[(w*y+x)*components+i]/255.f;
|
value[i]= pixels[(w*y+x)*components+i]/255.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::getComponent(int x, int y, int component, uint8 &value) const{
|
void Pixmap2D::getComponent(int x, int y, int component, uint8 &value) const {
|
||||||
value= pixels[(w*y+x)*components+component];
|
value= pixels[(w*y+x)*components+component];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::getComponent(int x, int y, int component, float32 &value) const{
|
void Pixmap2D::getComponent(int x, int y, int component, float32 &value) const {
|
||||||
value= pixels[(w*y+x)*components+component]/255.f;
|
value= pixels[(w*y+x)*components+component]/255.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//vector get
|
//vector get
|
||||||
Vec4f Pixmap2D::getPixel4f(int x, int y) const{
|
Vec4f Pixmap2D::getPixel4f(int x, int y) const {
|
||||||
Vec4f v(0.f);
|
Vec4f v(0.f);
|
||||||
for(int i=0; i<components && i<4; ++i){
|
for(int i=0; i<components && i<4; ++i){
|
||||||
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
|
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
|
||||||
@@ -548,7 +558,7 @@ Vec4f Pixmap2D::getPixel4f(int x, int y) const{
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3f Pixmap2D::getPixel3f(int x, int y) const{
|
Vec3f Pixmap2D::getPixel3f(int x, int y) const {
|
||||||
Vec3f v(0.f);
|
Vec3f v(0.f);
|
||||||
for(int i=0; i<components && i<3; ++i){
|
for(int i=0; i<components && i<3; ++i){
|
||||||
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
|
v.ptr()[i]= pixels[(w*y+x)*components+i]/255.f;
|
||||||
@@ -556,29 +566,29 @@ Vec3f Pixmap2D::getPixel3f(int x, int y) const{
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pixmap2D::getPixelf(int x, int y) const{
|
float Pixmap2D::getPixelf(int x, int y) const {
|
||||||
return pixels[(w*y+x)*components]/255.f;
|
return pixels[(w*y+x)*components]/255.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Pixmap2D::getComponentf(int x, int y, int component) const{
|
float Pixmap2D::getComponentf(int x, int y, int component) const {
|
||||||
float c;
|
float c;
|
||||||
getComponent(x, y, component, c);
|
getComponent(x, y, component, c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::setPixel(int x, int y, const uint8 *value){
|
void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
|
||||||
for(int i=0; i<components; ++i){
|
for(int i=0; i<components; ++i) {
|
||||||
pixels[(w*y+x)*components+i]= value[i];
|
pixels[(w*y+x)*components+i]= value[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::setPixel(int x, int y, const float32 *value){
|
void Pixmap2D::setPixel(int x, int y, const float32 *value) {
|
||||||
for(int i=0; i<components; ++i){
|
for(int i=0; i<components; ++i) {
|
||||||
pixels[(w*y+x)*components+i]= static_cast<uint8>(value[i]*255.f);
|
pixels[(w*y+x)*components+i]= static_cast<uint8>(value[i]*255.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap2D::setComponent(int x, int y, int component, uint8 value){
|
void Pixmap2D::setComponent(int x, int y, int component, uint8 value) {
|
||||||
pixels[(w*y+x)*components+component]= value;
|
pixels[(w*y+x)*components+component]= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +779,11 @@ void Pixmap3D::init(int w, int h, int d, int components){
|
|||||||
this->h= h;
|
this->h= h;
|
||||||
this->d= d;
|
this->d= d;
|
||||||
this->components= components;
|
this->components= components;
|
||||||
pixels= new uint8[h*w*d*components];;
|
pixels= new uint8[getPixelByteCount()];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 Pixmap3D::getPixelByteCount() const {
|
||||||
|
return (h * w * d * components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap3D::init(int d, int components){
|
void Pixmap3D::init(int d, int components){
|
||||||
@@ -780,7 +794,7 @@ void Pixmap3D::init(int d, int components){
|
|||||||
pixels= NULL;
|
pixels= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap3D::init(int components){
|
void Pixmap3D::init(int components) {
|
||||||
this->w= -1;
|
this->w= -1;
|
||||||
this->h= -1;
|
this->h= -1;
|
||||||
this->d= -1;
|
this->d= -1;
|
||||||
@@ -793,19 +807,19 @@ void Pixmap3D::deletePixels() {
|
|||||||
pixels = NULL;
|
pixels = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap3D::~Pixmap3D(){
|
Pixmap3D::~Pixmap3D() {
|
||||||
deletePixels();
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap3D::loadSlice(const string &path, int slice){
|
void Pixmap3D::loadSlice(const string &path, int slice) {
|
||||||
string extension= path.substr(path.find_last_of('.')+1);
|
string extension= path.substr(path.find_last_of('.') + 1);
|
||||||
if(extension=="bmp"){
|
if(extension == "bmp") {
|
||||||
loadSliceBmp(path, slice);
|
loadSliceBmp(path, slice);
|
||||||
}
|
}
|
||||||
else if(extension=="tga"){
|
else if(extension == "tga") {
|
||||||
loadSliceTga(path, slice);
|
loadSliceTga(path, slice);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw runtime_error("Unknown pixmap extension: "+extension);
|
throw runtime_error("Unknown pixmap extension: "+extension);
|
||||||
}
|
}
|
||||||
this->path = path;
|
this->path = path;
|
||||||
@@ -824,7 +838,7 @@ void Pixmap3D::loadSliceBmp(const string &path, int slice){
|
|||||||
components= 3;
|
components= 3;
|
||||||
}
|
}
|
||||||
if(pixels==NULL){
|
if(pixels==NULL){
|
||||||
pixels= new uint8[w*h*d*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
}
|
}
|
||||||
|
|
||||||
//data
|
//data
|
||||||
@@ -847,7 +861,7 @@ void Pixmap3D::loadSliceTga(const string &path, int slice){
|
|||||||
components= fileComponents;
|
components= fileComponents;
|
||||||
}
|
}
|
||||||
if(pixels==NULL){
|
if(pixels==NULL){
|
||||||
pixels= new uint8[w*h*d*components];
|
pixels= new uint8[getPixelByteCount()];
|
||||||
}
|
}
|
||||||
|
|
||||||
//read data
|
//read data
|
||||||
@@ -858,20 +872,29 @@ void Pixmap3D::loadSliceTga(const string &path, int slice){
|
|||||||
// class PixmapCube
|
// class PixmapCube
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void PixmapCube::init(int w, int h, int components){
|
void PixmapCube::init(int w, int h, int components) {
|
||||||
for(int i=0; i<6; ++i){
|
for(int i=0; i<6; ++i) {
|
||||||
faces[i].init(w, h, components);
|
faces[i].init(w, h, components);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapCube::init(int components){
|
void PixmapCube::init(int components) {
|
||||||
for(int i=0; i<6; ++i){
|
for(int i=0; i<6; ++i) {
|
||||||
faces[i].init(components);
|
faces[i].init(components);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//load & save
|
uint64 PixmapCube::getPixelByteCount() const {
|
||||||
void PixmapCube::loadFace(const string &path, int face){
|
uint64 result = 0;
|
||||||
|
for(int i=0; i<6; ++i) {
|
||||||
|
result += faces[i].getPixelByteCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//load & save
|
||||||
|
void PixmapCube::loadFace(const string &path, int face) {
|
||||||
this->path[face] = path;
|
this->path[face] = path;
|
||||||
|
|
||||||
faces[face].load(path);
|
faces[face].load(path);
|
||||||
|
@@ -22,17 +22,18 @@ namespace Shared{ namespace Graphics{
|
|||||||
// class Texture
|
// class Texture
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
const int Texture::defaultSize= 256;
|
const int Texture::defaultSize = 256;
|
||||||
const int Texture::defaultComponents = 4;
|
const int Texture::defaultComponents = 4;
|
||||||
bool Texture::useTextureCompression = false;
|
bool Texture::useTextureCompression = false;
|
||||||
|
|
||||||
Texture::Texture(){
|
Texture::Texture() {
|
||||||
mipmap= true;
|
mipmap= true;
|
||||||
pixmapInit= true;
|
pixmapInit= true;
|
||||||
wrapMode= wmRepeat;
|
wrapMode= wmRepeat;
|
||||||
format= fAuto;
|
format= fAuto;
|
||||||
|
|
||||||
inited= false;
|
inited= false;
|
||||||
|
forceCompressionDisabled=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -55,7 +56,7 @@ string Texture1D::getPath() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Texture1D::deletePixels() {
|
void Texture1D::deletePixels() {
|
||||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
//printf("+++> Texture1D pixmap deletion for [%s]\n",getPath().c_str());
|
||||||
pixmap.deletePixels();
|
pixmap.deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ string Texture2D::getPath() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Texture2D::deletePixels() {
|
void Texture2D::deletePixels() {
|
||||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
//printf("+++> Texture2D pixmap deletion for [%s]\n",getPath().c_str());
|
||||||
pixmap.deletePixels();
|
pixmap.deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ string Texture3D::getPath() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Texture3D::deletePixels() {
|
void Texture3D::deletePixels() {
|
||||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
//printf("+++> Texture3D pixmap deletion for [%s]\n",getPath().c_str());
|
||||||
pixmap.deletePixels();
|
pixmap.deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ string TextureCube::getPath() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureCube::deletePixels() {
|
void TextureCube::deletePixels() {
|
||||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
//printf("+++> TextureCube pixmap deletion for [%s]\n",getPath().c_str());
|
||||||
pixmap.deletePixels();
|
pixmap.deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user