- 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:
parent
de3a92081d
commit
df3f56a451
|
@ -89,9 +89,11 @@ void CoreData::load(){
|
|||
waterSplashTexture->getPixmap()->load(dir+"/misc_textures/water_splash.tga");
|
||||
|
||||
buttonSmallTexture= renderer.newTexture2D(rsGlobal);
|
||||
buttonSmallTexture->setForceCompressionDisabled(true);
|
||||
buttonSmallTexture->getPixmap()->load(dir+"/menu/textures/button_small.tga");
|
||||
|
||||
buttonBigTexture= renderer.newTexture2D(rsGlobal);
|
||||
buttonBigTexture->setForceCompressionDisabled(true);
|
||||
buttonBigTexture->getPixmap()->load(dir+"/menu/textures/button_big.tga");
|
||||
|
||||
//display font
|
||||
|
|
|
@ -27,9 +27,10 @@ protected:
|
|||
GLuint handle;
|
||||
|
||||
public:
|
||||
TextureGl();
|
||||
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);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -38,6 +39,9 @@ public:
|
|||
|
||||
class Texture1DGl: public Texture1D, public TextureGl {
|
||||
public:
|
||||
Texture1DGl();
|
||||
virtual ~Texture1DGl();
|
||||
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
@ -48,6 +52,9 @@ public:
|
|||
|
||||
class Texture2DGl: public Texture2D, public TextureGl{
|
||||
public:
|
||||
Texture2DGl();
|
||||
virtual ~Texture2DGl();
|
||||
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
@ -58,6 +65,10 @@ public:
|
|||
|
||||
class Texture3DGl: public Texture3D, public TextureGl{
|
||||
public:
|
||||
|
||||
Texture3DGl();
|
||||
virtual ~Texture3DGl();
|
||||
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
@ -68,6 +79,10 @@ public:
|
|||
|
||||
class TextureCubeGl: public TextureCube, public TextureGl{
|
||||
public:
|
||||
|
||||
TextureCubeGl();
|
||||
virtual ~TextureCubeGl();
|
||||
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@ using Shared::Platform::int16;
|
|||
using Shared::Platform::uint16;
|
||||
using Shared::Platform::int32;
|
||||
using Shared::Platform::uint32;
|
||||
using Shared::Platform::uint64;
|
||||
using Shared::Platform::float32;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
@ -124,6 +125,7 @@ public:
|
|||
uint8 *getPixels() const {return pixels;}
|
||||
void deletePixels();
|
||||
string getPath() const { return path;}
|
||||
uint64 getPixelByteCount() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -199,6 +201,7 @@ public:
|
|||
void copy(const Pixmap2D *sourcePixmap);
|
||||
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
||||
string getPath() const { return path;}
|
||||
uint64 getPixelByteCount() const;
|
||||
|
||||
private:
|
||||
bool doDimensionsAgree(const Pixmap2D *pixmap);
|
||||
|
@ -240,6 +243,7 @@ public:
|
|||
uint8 *getPixels() const {return pixels;}
|
||||
void deletePixels();
|
||||
string getPath() const { return path;}
|
||||
uint64 getPixelByteCount() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -276,6 +280,7 @@ public:
|
|||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||
void deletePixels();
|
||||
string getPath(int face) const { return path[face];}
|
||||
uint64 getPixelByteCount() const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -61,6 +61,7 @@ protected:
|
|||
Format format;
|
||||
|
||||
bool inited;
|
||||
bool forceCompressionDisabled;
|
||||
|
||||
public:
|
||||
Texture();
|
||||
|
@ -82,6 +83,10 @@ public:
|
|||
virtual void deletePixels() = 0;
|
||||
|
||||
virtual void reseInitState() { inited = false; }
|
||||
|
||||
virtual void setForceCompressionDisabled(bool value) { forceCompressionDisabled = value;}
|
||||
virtual bool getForceCompressionDisabled() const {return forceCompressionDisabled;}
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
|||
|
||||
using namespace Platform;
|
||||
|
||||
const uint64 MIN_BYTES_TO_COMPRESS = 12;
|
||||
|
||||
GLint toCompressionFormatGl(GLint format) {
|
||||
if(Texture::useTextureCompression == false) {
|
||||
return format;
|
||||
|
@ -134,20 +136,31 @@ GLint toInternalFormatGl(Texture::Format format, int components){
|
|||
}
|
||||
}
|
||||
|
||||
TextureGl::TextureGl() {
|
||||
handle=0;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class Texture1DGl
|
||||
// =====================================================
|
||||
Texture1DGl::Texture1DGl() {}
|
||||
|
||||
Texture1DGl::~Texture1DGl() {
|
||||
end();
|
||||
}
|
||||
|
||||
void Texture1DGl::init(Filter filter, int maxAnisotropy) {
|
||||
assertGl();
|
||||
|
||||
if(!inited) {
|
||||
|
||||
if(inited == false) {
|
||||
//params
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||
glCompressionFormat = glInternalFormat;
|
||||
}
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||
|
@ -200,17 +213,20 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||
}
|
||||
}
|
||||
inited= true;
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
}
|
||||
|
||||
void Texture1DGl::end() {
|
||||
if(inited){
|
||||
if(inited == true) {
|
||||
assertGl();
|
||||
glDeleteTextures(1, &handle);
|
||||
assertGl();
|
||||
handle=0;
|
||||
inited=false;
|
||||
deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,16 +234,24 @@ void Texture1DGl::end(){
|
|||
// class Texture2DGl
|
||||
// =====================================================
|
||||
|
||||
Texture2DGl::Texture2DGl() {}
|
||||
|
||||
Texture2DGl::~Texture2DGl() {
|
||||
end();
|
||||
}
|
||||
|
||||
void Texture2DGl::init(Filter filter, int maxAnisotropy) {
|
||||
assertGl();
|
||||
|
||||
if(!inited) {
|
||||
|
||||
if(inited == false) {
|
||||
//params
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||
glCompressionFormat = glInternalFormat;
|
||||
}
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||
|
@ -284,18 +308,21 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
|||
}
|
||||
}
|
||||
inited= true;
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
}
|
||||
|
||||
void Texture2DGl::end() {
|
||||
if(inited) {
|
||||
if(inited == true) {
|
||||
//printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle);
|
||||
assertGl();
|
||||
glDeleteTextures(1, &handle);
|
||||
assertGl();
|
||||
handle=0;
|
||||
inited=false;
|
||||
deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,16 +330,24 @@ void Texture2DGl::end(){
|
|||
// class Texture3DGl
|
||||
// =====================================================
|
||||
|
||||
Texture3DGl::Texture3DGl() {}
|
||||
|
||||
Texture3DGl::~Texture3DGl() {
|
||||
end();
|
||||
}
|
||||
|
||||
void Texture3DGl::init(Filter filter, int maxAnisotropy) {
|
||||
assertGl();
|
||||
|
||||
if(!inited){
|
||||
|
||||
if(inited == false) {
|
||||
//params
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
if(forceCompressionDisabled == true || (pixmap.getPixelByteCount() > 0 && pixmap.getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||
glCompressionFormat = glInternalFormat;
|
||||
}
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||
|
@ -344,17 +379,21 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
|||
}
|
||||
inited= true;
|
||||
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath(),pixmap.getPixelByteCount());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
}
|
||||
|
||||
void Texture3DGl::end() {
|
||||
if(inited){
|
||||
if(inited == true) {
|
||||
assertGl();
|
||||
glDeleteTextures(1, &handle);
|
||||
assertGl();
|
||||
|
||||
handle=0;
|
||||
inited=false;
|
||||
deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,11 +401,16 @@ void Texture3DGl::end(){
|
|||
// class TextureCubeGl
|
||||
// =====================================================
|
||||
|
||||
TextureCubeGl::TextureCubeGl() {}
|
||||
|
||||
TextureCubeGl::~TextureCubeGl() {
|
||||
end();
|
||||
}
|
||||
|
||||
void TextureCubeGl::init(Filter filter, int maxAnisotropy) {
|
||||
assertGl();
|
||||
|
||||
if(!inited){
|
||||
|
||||
if(inited == false) {
|
||||
//gen texture
|
||||
glGenTextures(1, &handle);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, handle);
|
||||
|
@ -394,6 +438,9 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||
GLint glFormat= toFormatGl(format, currentPixmap->getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, currentPixmap->getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
if(forceCompressionDisabled == true || (currentPixmap->getPixelByteCount() > 0 && currentPixmap->getPixelByteCount() <= MIN_BYTES_TO_COMPRESS)) {
|
||||
glCompressionFormat = glInternalFormat;
|
||||
}
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? currentPixmap->getPixels(): NULL;
|
||||
|
@ -427,7 +474,7 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath());
|
||||
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath(),currentPixmap->getPixelByteCount());
|
||||
}
|
||||
inited= true;
|
||||
|
||||
|
@ -437,18 +484,22 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||
}
|
||||
|
||||
void TextureCubeGl::end() {
|
||||
if(inited){
|
||||
if(inited == true) {
|
||||
assertGl();
|
||||
glDeleteTextures(1, &handle);
|
||||
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) {
|
||||
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;
|
||||
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);
|
||||
|
||||
bool isCompressed = (compressed == 1);
|
||||
compressed=0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
|
||||
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;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
||||
|
|
|
@ -91,6 +91,7 @@ PixmapIoTga::PixmapIoTga(){
|
|||
PixmapIoTga::~PixmapIoTga() {
|
||||
if(file != NULL) {
|
||||
fclose(file);
|
||||
file=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,7 @@ void PixmapIoTga::read(uint8 *pixels){
|
|||
|
||||
void PixmapIoTga::read(uint8 *pixels, int 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) {
|
||||
size_t readBytes = fread(&l, 1, 1, file);
|
||||
|
@ -218,6 +219,7 @@ PixmapIoBmp::PixmapIoBmp(){
|
|||
PixmapIoBmp::~PixmapIoBmp() {
|
||||
if(file!=NULL){
|
||||
fclose(file);
|
||||
file=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,7 +351,11 @@ void Pixmap1D::init(int components){
|
|||
void Pixmap1D::init(int w, int components){
|
||||
this->w= w;
|
||||
this->components= components;
|
||||
pixels= new uint8[w*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
uint64 Pixmap1D::getPixelByteCount() const {
|
||||
return (w * components);
|
||||
}
|
||||
|
||||
void Pixmap1D::deletePixels() {
|
||||
|
@ -396,7 +402,7 @@ void Pixmap1D::loadBmp(const string &path){
|
|||
components= 3;
|
||||
}
|
||||
if(pixels == NULL) {
|
||||
pixels= new uint8[w*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
//data
|
||||
|
@ -426,7 +432,7 @@ void Pixmap1D::loadTga(const string &path){
|
|||
components= fileComponents;
|
||||
}
|
||||
if(pixels == NULL) {
|
||||
pixels= new uint8[w*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
//read data
|
||||
|
@ -465,7 +471,11 @@ void Pixmap2D::init(int w, int h, int components) {
|
|||
this->w= w;
|
||||
this->h= h;
|
||||
this->components= components;
|
||||
pixels= new uint8[h*w*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
uint64 Pixmap2D::getPixelByteCount() const {
|
||||
return (h * w * components);
|
||||
}
|
||||
|
||||
void Pixmap2D::deletePixels() {
|
||||
|
@ -769,7 +779,11 @@ void Pixmap3D::init(int w, int h, int d, int components){
|
|||
this->h= h;
|
||||
this->d= d;
|
||||
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){
|
||||
|
@ -824,7 +838,7 @@ void Pixmap3D::loadSliceBmp(const string &path, int slice){
|
|||
components= 3;
|
||||
}
|
||||
if(pixels==NULL){
|
||||
pixels= new uint8[w*h*d*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
//data
|
||||
|
@ -847,7 +861,7 @@ void Pixmap3D::loadSliceTga(const string &path, int slice){
|
|||
components= fileComponents;
|
||||
}
|
||||
if(pixels==NULL){
|
||||
pixels= new uint8[w*h*d*components];
|
||||
pixels= new uint8[getPixelByteCount()];
|
||||
}
|
||||
|
||||
//read data
|
||||
|
@ -870,6 +884,15 @@ void PixmapCube::init(int components){
|
|||
}
|
||||
}
|
||||
|
||||
uint64 PixmapCube::getPixelByteCount() const {
|
||||
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;
|
||||
|
|
|
@ -33,6 +33,7 @@ Texture::Texture(){
|
|||
format= fAuto;
|
||||
|
||||
inited= false;
|
||||
forceCompressionDisabled=false;
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
|
@ -55,7 +56,7 @@ string Texture1D::getPath() const {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -79,7 +80,7 @@ string Texture2D::getPath() const {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -103,7 +104,7 @@ string Texture3D::getPath() const {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ string TextureCube::getPath() const {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue