mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- a bunch of in progress work related to texture compression and more timely texture memory management cleanup. For now to test texture compression use the following ini setting: EnableTextureCompression=true
This commit is contained in:
parent
3c57f16a4a
commit
de3a92081d
@ -578,6 +578,13 @@ void Game::init(bool initForPreviewOnly)
|
||||
logger.add("Initializing renderer", true);
|
||||
renderer.initGame(this);
|
||||
|
||||
for(int i=0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction= world.getFaction(i);
|
||||
if(faction != NULL) {
|
||||
faction->deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
if(initForPreviewOnly == false) {
|
||||
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -656,6 +656,8 @@ int glestMain(int argc, char** argv){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"START\n");
|
||||
SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"START\n");
|
||||
|
||||
Texture::useTextureCompression = config.getBool("EnableTextureCompression","false");
|
||||
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
||||
|
@ -53,7 +53,7 @@ Faction::~Faction() {
|
||||
}
|
||||
|
||||
void Faction::init(
|
||||
const FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
|
||||
FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
|
||||
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources)
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@ -929,6 +929,12 @@ void Faction::addCachedPath(const Vec2i &target, Unit *unit) {
|
||||
}
|
||||
}
|
||||
|
||||
void Faction::deletePixels() {
|
||||
if(factionType != NULL) {
|
||||
factionType->deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
std::string Faction::toString() const {
|
||||
std::string result = "";
|
||||
|
||||
|
@ -75,7 +75,7 @@ private:
|
||||
ControlType control;
|
||||
|
||||
Texture2D *texture;
|
||||
const FactionType *factionType;
|
||||
FactionType *factionType;
|
||||
|
||||
int index;
|
||||
int teamIndex;
|
||||
@ -97,7 +97,7 @@ public:
|
||||
~Faction();
|
||||
|
||||
void init(
|
||||
const FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
|
||||
FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
|
||||
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
||||
void end();
|
||||
|
||||
@ -169,6 +169,8 @@ public:
|
||||
Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type);
|
||||
void cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr);
|
||||
|
||||
void deletePixels();
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
|
@ -535,6 +535,16 @@ int FactionType::getStartingResourceAmount(const ResourceType *resourceType) con
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FactionType::deletePixels() {
|
||||
for(int i = 0; i <unitTypes.size(); ++i) {
|
||||
UnitType &unitType = unitTypes[i];
|
||||
Texture2D *texture = unitType.getMeetingPointImage();
|
||||
if(texture != NULL) {
|
||||
texture->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string FactionType::toString() const {
|
||||
std::string result = "";
|
||||
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
std::vector<std::string> validateFactionType();
|
||||
std::vector<std::string> validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes);
|
||||
std::vector<std::string> validateFactionTypeUpgradeTypes();
|
||||
|
||||
void deletePixels();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
49
source/glest_game/types/object_type.cpp
Normal file
49
source/glest_game/types/object_type.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// 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
|
||||
// ==============================================================
|
||||
|
||||
#include "object_type.h"
|
||||
|
||||
#include "renderer.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
// =====================================================
|
||||
// class ObjectType
|
||||
// =====================================================
|
||||
|
||||
void ObjectType::init(int modelCount, int objectClass, bool walkable){
|
||||
models.reserve(modelCount);
|
||||
this->objectClass= objectClass;
|
||||
this->walkable= walkable;
|
||||
}
|
||||
|
||||
void ObjectType::loadModel(const string &path){
|
||||
Model *model= Renderer::getInstance().newModel(rsGame);
|
||||
model->load(path);
|
||||
color= Vec3f(0.f);
|
||||
if(model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) {
|
||||
const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmap();
|
||||
color= p->getPixel3f(p->getW()/2, p->getH()/2);
|
||||
}
|
||||
models.push_back(model);
|
||||
}
|
||||
|
||||
void ObjectType::deletePixels() {
|
||||
for(int i = 0; i < models.size(); ++i) {
|
||||
Model *model = models[i];
|
||||
if(model != NULL) {
|
||||
model->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}//end namespace
|
@ -56,6 +56,7 @@ public:
|
||||
int getClass() const {return objectClass;}
|
||||
bool getWalkable() const {return walkable;}
|
||||
bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
|
||||
void deletePixels();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@ -152,4 +152,10 @@ ResourceClass ResourceType::strToRc(const string &s){
|
||||
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
||||
}
|
||||
|
||||
void ResourceType::deletePixels() {
|
||||
if(model != NULL) {
|
||||
model->deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
bool getRecoup_cost() const { return recoup_cost;}
|
||||
|
||||
static ResourceClass strToRc(const string &s);
|
||||
void deletePixels();
|
||||
};
|
||||
|
||||
}} //end namespace
|
||||
|
@ -62,6 +62,11 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
||||
resourceTypes[i].load(str, checksum);
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
// Cleanup pixmap memory
|
||||
for(int i=0; i<filenames.size(); ++i) {
|
||||
resourceTypes[i].deletePixels();
|
||||
}
|
||||
}
|
||||
catch(const exception &e){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||
@ -186,6 +191,17 @@ std::vector<std::string> TechTree::validateResourceTypes() {
|
||||
|
||||
// ==================== get ====================
|
||||
|
||||
FactionType *TechTree::getTypeByName(const string &name) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i=0; i < factionTypes.size(); ++i) {
|
||||
if(factionTypes[i].getName() == name) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return &factionTypes[i];
|
||||
}
|
||||
}
|
||||
throw runtime_error("Faction not found: "+name);
|
||||
}
|
||||
|
||||
const FactionType *TechTree::getType(const string &name) const {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i=0; i < factionTypes.size(); ++i) {
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
|
||||
const string &getDesc() const {return desc;}
|
||||
const FactionType *getType(const string &name) const;
|
||||
FactionType *getTypeByName(const string &name);
|
||||
const ResourceType *getResourceType(const string &name) const;
|
||||
const ResourceType *getTechResourceType(int i) const;
|
||||
const ResourceType *getFirstTechResourceType() const;
|
||||
|
@ -54,6 +54,7 @@ const char *UnitType::propertyNames[]= {"burnable", "rotated_climb"};
|
||||
|
||||
UnitType::UnitType(){
|
||||
|
||||
meetingPointImage = NULL;
|
||||
lightColor= Vec3f(0.f);
|
||||
light= false;
|
||||
multiSelect= false;
|
||||
|
@ -160,6 +160,11 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
||||
}
|
||||
}
|
||||
|
||||
// Now free up the pixmap memory
|
||||
for(int i=0; i<objCount; ++i){
|
||||
objectTypes[i].deletePixels();
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//ambient sounds
|
||||
|
@ -864,7 +864,7 @@ void World::initFactionTypes(GameSettings *gs){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factions.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,factions.size());
|
||||
|
||||
for(int i=0; i < factions.size(); ++i) {
|
||||
const FactionType *ft= techTree->getType(gs->getFactionTypeName(i));
|
||||
FactionType *ft= techTree->getTypeByName(gs->getFactionTypeName(i));
|
||||
factions[i].init(
|
||||
ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
|
||||
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
|
||||
|
@ -29,7 +29,7 @@ protected:
|
||||
public:
|
||||
GLuint getHandle() const {return handle;}
|
||||
|
||||
void OutputTextureDebugInfo(const Pixmap2D *pixmap,Texture::Format format, int components, const string path);
|
||||
void OutputTextureDebugInfo(Texture::Format format, int components, const string path);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@ -43,6 +43,7 @@ class Mesh{
|
||||
private:
|
||||
//mesh data
|
||||
Texture2D *textures[meshTextureCount];
|
||||
bool texturesOwned[meshTextureCount];
|
||||
string texturePaths[meshTextureCount];
|
||||
|
||||
//vertex data counts
|
||||
@ -68,6 +69,7 @@ private:
|
||||
bool customColor;
|
||||
|
||||
InterpolationData *interpolationData;
|
||||
TextureManager *textureManager;
|
||||
|
||||
public:
|
||||
//init & end
|
||||
@ -111,11 +113,13 @@ public:
|
||||
void updateInterpolationVertices(float t, bool cycle) const;
|
||||
|
||||
//load
|
||||
void loadV2(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void loadV3(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void load(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
|
||||
void loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
|
||||
void load(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
|
||||
void save(const string &dir, FILE *f);
|
||||
|
||||
void deletePixels();
|
||||
|
||||
private:
|
||||
void computeTangents();
|
||||
};
|
||||
@ -156,12 +160,13 @@ public:
|
||||
uint32 getVertexCount() const;
|
||||
|
||||
//io
|
||||
void load(const string &path);
|
||||
void load(const string &path,bool deletePixMapAfterLoad=false);
|
||||
void save(const string &path);
|
||||
void loadG3d(const string &path);
|
||||
void loadG3d(const string &path,bool deletePixMapAfterLoad=false);
|
||||
void saveS3d(const string &path);
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
void deletePixels();
|
||||
|
||||
private:
|
||||
void buildInterpolationData() const;
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
int getW() const {return w;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
void deletePixels();
|
||||
string getPath() const { return path;}
|
||||
};
|
||||
|
||||
@ -161,6 +162,7 @@ public:
|
||||
int getH() const {return h;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
void deletePixels();
|
||||
|
||||
//get data
|
||||
void getPixel(int x, int y, uint8 *value) const;
|
||||
@ -236,6 +238,7 @@ public:
|
||||
int getD() const {return d;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
void deletePixels();
|
||||
string getPath() const { return path;}
|
||||
};
|
||||
|
||||
@ -271,6 +274,7 @@ public:
|
||||
//get
|
||||
Pixmap2D *getFace(int face) {return &faces[face];}
|
||||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||
void deletePixels();
|
||||
string getPath(int face) const { return path[face];}
|
||||
};
|
||||
|
||||
|
@ -32,6 +32,7 @@ class Texture{
|
||||
public:
|
||||
static const int defaultSize;
|
||||
static const int defaultComponents;
|
||||
static bool useTextureCompression;
|
||||
|
||||
enum WrapMode{
|
||||
wmRepeat,
|
||||
@ -69,7 +70,6 @@ public:
|
||||
WrapMode getWrapMode() const {return wrapMode;}
|
||||
bool getPixmapInit() const {return pixmapInit;}
|
||||
Format getFormat() const {return format;}
|
||||
const string getPath() const {return path;}
|
||||
|
||||
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
||||
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
||||
@ -78,6 +78,8 @@ public:
|
||||
|
||||
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
||||
virtual void end()=0;
|
||||
virtual string getPath() const = 0;
|
||||
virtual void deletePixels() = 0;
|
||||
|
||||
virtual void reseInitState() { inited = false; }
|
||||
};
|
||||
@ -95,6 +97,8 @@ public:
|
||||
|
||||
Pixmap1D *getPixmap() {return &pixmap;}
|
||||
const Pixmap1D *getPixmap() const {return &pixmap;}
|
||||
virtual string getPath() const;
|
||||
virtual void deletePixels();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@ -110,6 +114,8 @@ public:
|
||||
|
||||
Pixmap2D *getPixmap() {return &pixmap;}
|
||||
const Pixmap2D *getPixmap() const {return &pixmap;}
|
||||
virtual string getPath() const;
|
||||
virtual void deletePixels();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@ -125,6 +131,8 @@ public:
|
||||
|
||||
Pixmap3D *getPixmap() {return &pixmap;}
|
||||
const Pixmap3D *getPixmap() const {return &pixmap;}
|
||||
virtual string getPath() const;
|
||||
virtual void deletePixels();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@ -140,6 +148,8 @@ public:
|
||||
|
||||
PixmapCube *getPixmap() {return &pixmap;}
|
||||
const PixmapCube *getPixmap() const {return &pixmap;}
|
||||
virtual string getPath() const;
|
||||
virtual void deletePixels();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@ -48,6 +48,9 @@ public:
|
||||
void endLastTexture(bool mustExistInList=false);
|
||||
void reinitTextures();
|
||||
|
||||
Texture::Filter getTextureFilter() const {return textureFilter;}
|
||||
int getMaxAnisotropy() const {return maxAnisotropy;}
|
||||
|
||||
Texture *getTexture(const string &path);
|
||||
Texture1D *newTexture1D();
|
||||
Texture2D *newTexture2D();
|
||||
|
@ -23,6 +23,44 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
using namespace Platform;
|
||||
|
||||
GLint toCompressionFormatGl(GLint format) {
|
||||
if(Texture::useTextureCompression == false) {
|
||||
return format;
|
||||
}
|
||||
|
||||
//GL_COMPRESSED_ALPHA <- white things but tile ok!
|
||||
//GL_COMPRESSED_LUMINANCE <- black tiles
|
||||
//GL_COMPRESSED_LUMINANCE_ALPHA <- black tiles
|
||||
//GL_COMPRESSED_INTENSITY <- black tiles
|
||||
//GL_COMPRESSED_RGB <- black tiles
|
||||
//GL_COMPRESSED_RGBA <- black tiles
|
||||
|
||||
// With the following extension (GL_EXT_texture_compression_s3tc)
|
||||
//GL_COMPRESSED_RGB_S3TC_DXT1_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
|
||||
|
||||
switch(format) {
|
||||
case GL_LUMINANCE:
|
||||
case GL_LUMINANCE8:
|
||||
return GL_COMPRESSED_LUMINANCE;
|
||||
case GL_RGB:
|
||||
case GL_RGB8:
|
||||
//return GL_COMPRESSED_RGB;
|
||||
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case GL_RGBA:
|
||||
case GL_RGBA8:
|
||||
//return GL_COMPRESSED_RGBA;
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case GL_ALPHA:
|
||||
case GL_ALPHA8:
|
||||
return GL_COMPRESSED_ALPHA;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
GLint toWrapModeGl(Texture::WrapMode wrapMode){
|
||||
switch(wrapMode){
|
||||
case Texture::wmClamp:
|
||||
@ -96,44 +134,6 @@ GLint toInternalFormatGl(Texture::Format format, int components){
|
||||
}
|
||||
}
|
||||
|
||||
GLint toCompressionFormatGl(GLint format) {
|
||||
return format;
|
||||
|
||||
//GL_COMPRESSED_ALPHA <- white things but tile ok!
|
||||
//GL_COMPRESSED_LUMINANCE <- black tiles
|
||||
//GL_COMPRESSED_LUMINANCE_ALPHA <- black tiles
|
||||
//GL_COMPRESSED_INTENSITY <- black tiles
|
||||
//GL_COMPRESSED_RGB <- black tiles
|
||||
//GL_COMPRESSED_RGBA <- black tiles
|
||||
|
||||
// With the following extension (GL_EXT_texture_compression_s3tc)
|
||||
//GL_COMPRESSED_RGB_S3TC_DXT1_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
|
||||
//GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
|
||||
|
||||
/*
|
||||
switch(format) {
|
||||
case GL_LUMINANCE:
|
||||
case GL_LUMINANCE8:
|
||||
return GL_COMPRESSED_LUMINANCE;
|
||||
case GL_RGB:
|
||||
case GL_RGB8:
|
||||
//return GL_COMPRESSED_RGB;
|
||||
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case GL_RGBA:
|
||||
case GL_RGBA8:
|
||||
//return GL_COMPRESSED_RGBA;
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case GL_ALPHA:
|
||||
case GL_ALPHA8:
|
||||
return GL_COMPRESSED_ALPHA;
|
||||
default:
|
||||
return format;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class Texture1DGl
|
||||
// =====================================================
|
||||
@ -147,6 +147,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||
@ -171,7 +172,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
int error= gluBuild1DMipmaps(
|
||||
GL_TEXTURE_1D, glInternalFormat, pixmap.getW(),
|
||||
GL_TEXTURE_1D, glCompressionFormat, pixmap.getW(),
|
||||
glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
if(error!=0){
|
||||
@ -187,7 +188,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexImage1D(
|
||||
GL_TEXTURE_1D, 0, glInternalFormat, pixmap.getW(),
|
||||
GL_TEXTURE_1D, 0, glCompressionFormat, pixmap.getW(),
|
||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
GLint error= glGetError();
|
||||
@ -199,6 +200,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
||||
}
|
||||
}
|
||||
inited= true;
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
@ -280,10 +282,9 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
||||
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);
|
||||
}
|
||||
|
||||
OutputTextureDebugInfo(&pixmap,format, pixmap.getComponents(),getPath());
|
||||
}
|
||||
inited= true;
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
@ -291,6 +292,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy){
|
||||
|
||||
void Texture2DGl::end(){
|
||||
if(inited) {
|
||||
//printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle);
|
||||
assertGl();
|
||||
glDeleteTextures(1, &handle);
|
||||
assertGl();
|
||||
@ -310,6 +312,7 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
||||
GLint wrap= toWrapModeGl(wrapMode);
|
||||
GLint glFormat= toFormatGl(format, pixmap.getComponents());
|
||||
GLint glInternalFormat= toInternalFormatGl(format, pixmap.getComponents());
|
||||
GLint glCompressionFormat = toCompressionFormatGl(glInternalFormat);
|
||||
|
||||
//pixel init var
|
||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
||||
@ -328,7 +331,7 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glTexImage3D(
|
||||
GL_TEXTURE_3D, 0, glInternalFormat,
|
||||
GL_TEXTURE_3D, 0, glCompressionFormat,
|
||||
pixmap.getW(), pixmap.getH(), pixmap.getD(),
|
||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
@ -340,6 +343,8 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
inited= true;
|
||||
|
||||
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||
}
|
||||
|
||||
assertGl();
|
||||
@ -422,7 +427,7 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
OutputTextureDebugInfo(currentPixmap,format, currentPixmap->getComponents(),getPath());
|
||||
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath());
|
||||
}
|
||||
inited= true;
|
||||
|
||||
@ -439,12 +444,11 @@ void TextureCubeGl::end(){
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGl::OutputTextureDebugInfo(const Pixmap2D *pixmap,Texture::Format format, int components,const string path) {
|
||||
|
||||
/*
|
||||
void TextureGl::OutputTextureDebugInfo(Texture::Format format, int components,const string path) {
|
||||
if(Texture::useTextureCompression == true) {
|
||||
GLint glFormat= toFormatGl(format, components);
|
||||
|
||||
printf("**** Texture filename: [%s] format = %d components = %d, glFormat = %d, path [%s]\n",pixmap->getPath().c_str(),format,components,glFormat,path.c_str());
|
||||
printf("**** Texture filename: [%s] format = %d components = %d, glFormat = %d\n",path.c_str(),format,components,glFormat);
|
||||
|
||||
GLint compressed=0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
||||
@ -461,7 +465,7 @@ void TextureGl::OutputTextureDebugInfo(const Pixmap2D *pixmap,Texture::Format fo
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
||||
error = glGetError();
|
||||
printf("**** Texture image compression format used: %d, error [%d]\n",compressed,error);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
||||
|
@ -35,6 +35,7 @@ using namespace Util;
|
||||
// ==================== constructor & destructor ====================
|
||||
|
||||
Mesh::Mesh() {
|
||||
textureManager = NULL;
|
||||
frameCount= 0;
|
||||
vertexCount= 0;
|
||||
indexCount= 0;
|
||||
@ -48,6 +49,7 @@ Mesh::Mesh(){
|
||||
|
||||
for(int i=0; i<meshTextureCount; ++i){
|
||||
textures[i]= NULL;
|
||||
texturesOwned[i]=false;
|
||||
}
|
||||
|
||||
twoSided= false;
|
||||
@ -73,6 +75,16 @@ void Mesh::end(){
|
||||
delete [] indices;
|
||||
|
||||
delete interpolationData;
|
||||
|
||||
if(textureManager != NULL) {
|
||||
for(int i = 0; i < meshTextureCount; ++i) {
|
||||
if(texturesOwned[i] == true && textures[i] != NULL) {
|
||||
//printf("Deleting Texture [%s] i = %d\n",textures[i]->getPath().c_str(),i);
|
||||
textureManager->endTexture(textures[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
textureManager = NULL;
|
||||
}
|
||||
|
||||
// ========================== shadows & interpolation =========================
|
||||
@ -91,7 +103,8 @@ void Mesh::updateInterpolationVertices(float t, bool cycle) const{
|
||||
|
||||
// ==================== load ====================
|
||||
|
||||
void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
|
||||
this->textureManager = textureManager;
|
||||
//read header
|
||||
MeshHeaderV2 meshHeader;
|
||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f);
|
||||
@ -125,6 +138,12 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
if(textures[mtDiffuse]==NULL){
|
||||
textures[mtDiffuse]= textureManager->newTexture2D();
|
||||
textures[mtDiffuse]->load(texPath);
|
||||
texturesOwned[mtDiffuse]=true;
|
||||
// M.V. Test
|
||||
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
|
||||
if(deletePixMapAfterLoad == true) {
|
||||
textures[mtDiffuse]->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +159,9 @@ void Mesh::loadV2(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
|
||||
}
|
||||
|
||||
void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
|
||||
this->textureManager = textureManager;
|
||||
|
||||
//read header
|
||||
MeshHeaderV3 meshHeader;
|
||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f);
|
||||
@ -170,6 +191,12 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
if(textures[mtDiffuse]==NULL){
|
||||
textures[mtDiffuse]= textureManager->newTexture2D();
|
||||
textures[mtDiffuse]->load(texPath);
|
||||
texturesOwned[mtDiffuse]=true;
|
||||
// M.V. Test
|
||||
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
|
||||
if(deletePixMapAfterLoad == true) {
|
||||
textures[mtDiffuse]->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +214,9 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
|
||||
}
|
||||
|
||||
void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
|
||||
this->textureManager = textureManager;
|
||||
|
||||
//read header
|
||||
MeshHeader meshHeader;
|
||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeader), 1, f);
|
||||
@ -226,6 +255,11 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager){
|
||||
textures[i]->getPixmap()->init(meshTextureChannelCount[i]);
|
||||
}
|
||||
textures[i]->load(mapFullPath);
|
||||
texturesOwned[i]=true;
|
||||
textures[i]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
|
||||
if(deletePixMapAfterLoad == true) {
|
||||
textures[i]->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
flag*= 2;
|
||||
@ -313,6 +347,14 @@ void Mesh::computeTangents(){
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh::deletePixels() {
|
||||
for(int i = 0; i < meshTextureCount; ++i) {
|
||||
if(textures[i] != NULL) {
|
||||
textures[i]->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================================
|
||||
// class Model
|
||||
// ===============================================
|
||||
@ -369,10 +411,10 @@ uint32 Model::getVertexCount() const{
|
||||
|
||||
// ==================== io ====================
|
||||
|
||||
void Model::load(const string &path){
|
||||
void Model::load(const string &path, bool deletePixMapAfterLoad) {
|
||||
string extension= path.substr(path.find_last_of('.')+1);
|
||||
if(extension=="g3d" || extension=="G3D"){
|
||||
loadG3d(path);
|
||||
loadG3d(path,deletePixMapAfterLoad);
|
||||
}
|
||||
else{
|
||||
throw runtime_error("Unknown model format: " + extension);
|
||||
@ -428,7 +470,7 @@ void Model::save(const string &path){
|
||||
}*/
|
||||
|
||||
//load a model from a g3d file
|
||||
void Model::loadG3d(const string &path){
|
||||
void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
||||
|
||||
try{
|
||||
FILE *f=fopen(path.c_str(),"rb");
|
||||
@ -462,7 +504,7 @@ void Model::loadG3d(const string &path){
|
||||
//load meshes
|
||||
meshes= new Mesh[meshCount];
|
||||
for(uint32 i=0; i<meshCount; ++i){
|
||||
meshes[i].load(dir, f, textureManager);
|
||||
meshes[i].load(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
}
|
||||
@ -472,7 +514,7 @@ void Model::loadG3d(const string &path){
|
||||
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
||||
meshes= new Mesh[meshCount];
|
||||
for(uint32 i=0; i<meshCount; ++i){
|
||||
meshes[i].loadV3(dir, f, textureManager);
|
||||
meshes[i].loadV3(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
}
|
||||
@ -482,7 +524,7 @@ void Model::loadG3d(const string &path){
|
||||
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
||||
meshes= new Mesh[meshCount];
|
||||
for(uint32 i=0; i<meshCount; ++i){
|
||||
meshes[i].loadV2(dir, f, textureManager);
|
||||
meshes[i].loadV2(dir, f, textureManager,deletePixMapAfterLoad);
|
||||
meshes[i].buildInterpolationData();
|
||||
}
|
||||
}
|
||||
@ -523,4 +565,10 @@ void Model::saveS3d(const string &path){
|
||||
fclose(f);*/
|
||||
}
|
||||
|
||||
void Model::deletePixels() {
|
||||
for(uint32 i = 0; i < meshCount; ++i) {
|
||||
meshes[i].deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
@ -352,8 +352,13 @@ void Pixmap1D::init(int w, int components){
|
||||
pixels= new uint8[w*components];
|
||||
}
|
||||
|
||||
Pixmap1D::~Pixmap1D(){
|
||||
void Pixmap1D::deletePixels() {
|
||||
delete [] pixels;
|
||||
pixels = NULL;
|
||||
}
|
||||
|
||||
Pixmap1D::~Pixmap1D(){
|
||||
deletePixels();
|
||||
}
|
||||
|
||||
void Pixmap1D::load(const string &path){
|
||||
@ -463,8 +468,13 @@ void Pixmap2D::init(int w, int h, int components) {
|
||||
pixels= new uint8[h*w*components];
|
||||
}
|
||||
|
||||
Pixmap2D::~Pixmap2D(){
|
||||
void Pixmap2D::deletePixels() {
|
||||
delete [] pixels;
|
||||
pixels = NULL;
|
||||
}
|
||||
|
||||
Pixmap2D::~Pixmap2D(){
|
||||
deletePixels();
|
||||
}
|
||||
|
||||
Pixmap2D* Pixmap2D::loadPath(const string& path) {
|
||||
@ -778,8 +788,13 @@ void Pixmap3D::init(int components){
|
||||
pixels= NULL;
|
||||
}
|
||||
|
||||
Pixmap3D::~Pixmap3D(){
|
||||
void Pixmap3D::deletePixels() {
|
||||
delete [] pixels;
|
||||
pixels = NULL;
|
||||
}
|
||||
|
||||
Pixmap3D::~Pixmap3D(){
|
||||
deletePixels();
|
||||
}
|
||||
|
||||
void Pixmap3D::loadSlice(const string &path, int slice){
|
||||
@ -862,5 +877,11 @@ void PixmapCube::loadFace(const string &path, int face){
|
||||
faces[face].load(path);
|
||||
}
|
||||
|
||||
void PixmapCube::deletePixels() {
|
||||
for(int i=0; i<6; ++i){
|
||||
faces[i].deletePixels();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
@ -24,6 +24,7 @@ namespace Shared{ namespace Graphics{
|
||||
|
||||
const int Texture::defaultSize= 256;
|
||||
const int Texture::defaultComponents = 4;
|
||||
bool Texture::useTextureCompression = false;
|
||||
|
||||
Texture::Texture(){
|
||||
mipmap= true;
|
||||
@ -49,6 +50,15 @@ void Texture1D::load(const string &path){
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
string Texture1D::getPath() const {
|
||||
return (pixmap.getPath() != "" ? pixmap.getPath() : path);
|
||||
}
|
||||
|
||||
void Texture1D::deletePixels() {
|
||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
||||
pixmap.deletePixels();
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class Texture2D
|
||||
// =====================================================
|
||||
@ -64,6 +74,15 @@ void Texture2D::load(const string &path){
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
string Texture2D::getPath() const {
|
||||
return (pixmap.getPath() != "" ? pixmap.getPath() : path);
|
||||
}
|
||||
|
||||
void Texture2D::deletePixels() {
|
||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
||||
pixmap.deletePixels();
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class Texture3D
|
||||
// =====================================================
|
||||
@ -79,6 +98,15 @@ void Texture3D::loadSlice(const string &path, int slice){
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
string Texture3D::getPath() const {
|
||||
return (pixmap.getPath() != "" ? pixmap.getPath() : path);
|
||||
}
|
||||
|
||||
void Texture3D::deletePixels() {
|
||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
||||
pixmap.deletePixels();
|
||||
}
|
||||
|
||||
// =====================================================
|
||||
// class TextureCube
|
||||
// =====================================================
|
||||
@ -94,4 +122,25 @@ void TextureCube::loadFace(const string &path, int face){
|
||||
this->path= path;
|
||||
}
|
||||
|
||||
string TextureCube::getPath() const {
|
||||
string result = "";
|
||||
for(int i = 0; i < 6; ++i) {
|
||||
if(pixmap.getPath(i) != "") {
|
||||
if(result != "") {
|
||||
result += ",";
|
||||
}
|
||||
result += pixmap.getPath(i);
|
||||
}
|
||||
}
|
||||
if(result == "") {
|
||||
result = path;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void TextureCube::deletePixels() {
|
||||
//printf("+++> Texture pixmap deletion for [%s]\n",getPath().c_str());
|
||||
pixmap.deletePixels();
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user