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);
|
logger.add("Initializing renderer", true);
|
||||||
renderer.initGame(this);
|
renderer.initGame(this);
|
||||||
|
|
||||||
|
for(int i=0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction= world.getFaction(i);
|
||||||
|
if(faction != NULL) {
|
||||||
|
faction->deletePixels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(initForPreviewOnly == false) {
|
if(initForPreviewOnly == false) {
|
||||||
//good_fpu_control_registers(NULL,__FILE__,__FUNCTION__,__LINE__);
|
//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::debugUnitCommands,"START\n");
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"START\n");
|
SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"START\n");
|
||||||
|
|
||||||
|
Texture::useTextureCompression = config.getBool("EnableTextureCompression","false");
|
||||||
|
|
||||||
// 256 for English
|
// 256 for English
|
||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
||||||
|
@ -53,7 +53,7 @@ Faction::~Faction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Faction::init(
|
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)
|
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources)
|
||||||
{
|
{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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 Faction::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ private:
|
|||||||
ControlType control;
|
ControlType control;
|
||||||
|
|
||||||
Texture2D *texture;
|
Texture2D *texture;
|
||||||
const FactionType *factionType;
|
FactionType *factionType;
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
int teamIndex;
|
int teamIndex;
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
~Faction();
|
~Faction();
|
||||||
|
|
||||||
void init(
|
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);
|
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
@ -169,6 +169,8 @@ public:
|
|||||||
Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type);
|
Vec2i getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceType *type);
|
||||||
void cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr);
|
void cleanupResourceTypeTargetCache(std::vector<Vec2i> *deleteListPtr);
|
||||||
|
|
||||||
|
void deletePixels();
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -535,6 +535,16 @@ int FactionType::getStartingResourceAmount(const ResourceType *resourceType) con
|
|||||||
return 0;
|
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 FactionType::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
@ -72,6 +72,8 @@ public:
|
|||||||
std::vector<std::string> validateFactionType();
|
std::vector<std::string> validateFactionType();
|
||||||
std::vector<std::string> validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes);
|
std::vector<std::string> validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes);
|
||||||
std::vector<std::string> validateFactionTypeUpgradeTypes();
|
std::vector<std::string> validateFactionTypeUpgradeTypes();
|
||||||
|
|
||||||
|
void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//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;}
|
int getClass() const {return objectClass;}
|
||||||
bool getWalkable() const {return walkable;}
|
bool getWalkable() const {return walkable;}
|
||||||
bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
|
bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
|
||||||
|
void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -152,4 +152,10 @@ ResourceClass ResourceType::strToRc(const string &s){
|
|||||||
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceType::deletePixels() {
|
||||||
|
if(model != NULL) {
|
||||||
|
model->deletePixels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -60,6 +60,7 @@ public:
|
|||||||
bool getRecoup_cost() const { return recoup_cost;}
|
bool getRecoup_cost() const { return recoup_cost;}
|
||||||
|
|
||||||
static ResourceClass strToRc(const string &s);
|
static ResourceClass strToRc(const string &s);
|
||||||
|
void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
}} //end namespace
|
}} //end namespace
|
||||||
|
@ -62,6 +62,11 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||||||
resourceTypes[i].load(str, checksum);
|
resourceTypes[i].load(str, checksum);
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup pixmap memory
|
||||||
|
for(int i=0; i<filenames.size(); ++i) {
|
||||||
|
resourceTypes[i].deletePixels();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||||
@ -186,15 +191,26 @@ std::vector<std::string> TechTree::validateResourceTypes() {
|
|||||||
|
|
||||||
// ==================== get ====================
|
// ==================== get ====================
|
||||||
|
|
||||||
const FactionType *TechTree::getType(const string &name) const{
|
FactionType *TechTree::getTypeByName(const string &name) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
for(int i=0; i<factionTypes.size(); ++i){
|
for(int i=0; i < factionTypes.size(); ++i) {
|
||||||
if(factionTypes[i].getName()==name){
|
if(factionTypes[i].getName() == name) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return &factionTypes[i];
|
return &factionTypes[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw runtime_error("Faction not found: "+name);
|
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) {
|
||||||
|
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 ResourceType *TechTree::getTechResourceType(int i) const{
|
const ResourceType *TechTree::getTechResourceType(int i) const{
|
||||||
|
@ -55,6 +55,7 @@ public:
|
|||||||
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
|
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
|
||||||
const string &getDesc() const {return desc;}
|
const string &getDesc() const {return desc;}
|
||||||
const FactionType *getType(const string &name) const;
|
const FactionType *getType(const string &name) const;
|
||||||
|
FactionType *getTypeByName(const string &name);
|
||||||
const ResourceType *getResourceType(const string &name) const;
|
const ResourceType *getResourceType(const string &name) const;
|
||||||
const ResourceType *getTechResourceType(int i) const;
|
const ResourceType *getTechResourceType(int i) const;
|
||||||
const ResourceType *getFirstTechResourceType() const;
|
const ResourceType *getFirstTechResourceType() const;
|
||||||
|
@ -54,6 +54,7 @@ const char *UnitType::propertyNames[]= {"burnable", "rotated_climb"};
|
|||||||
|
|
||||||
UnitType::UnitType(){
|
UnitType::UnitType(){
|
||||||
|
|
||||||
|
meetingPointImage = NULL;
|
||||||
lightColor= Vec3f(0.f);
|
lightColor= Vec3f(0.f);
|
||||||
light= false;
|
light= false;
|
||||||
multiSelect= 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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//ambient sounds
|
//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());
|
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) {
|
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(
|
factions[i].init(
|
||||||
ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
|
ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i),
|
||||||
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
|
gs->getStartLocationIndex(i), i==thisFactionIndex, gs->getDefaultResources());
|
||||||
|
@ -29,7 +29,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
GLuint getHandle() const {return handle;}
|
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:
|
private:
|
||||||
//mesh data
|
//mesh data
|
||||||
Texture2D *textures[meshTextureCount];
|
Texture2D *textures[meshTextureCount];
|
||||||
|
bool texturesOwned[meshTextureCount];
|
||||||
string texturePaths[meshTextureCount];
|
string texturePaths[meshTextureCount];
|
||||||
|
|
||||||
//vertex data counts
|
//vertex data counts
|
||||||
@ -68,6 +69,7 @@ private:
|
|||||||
bool customColor;
|
bool customColor;
|
||||||
|
|
||||||
InterpolationData *interpolationData;
|
InterpolationData *interpolationData;
|
||||||
|
TextureManager *textureManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//init & end
|
//init & end
|
||||||
@ -111,11 +113,13 @@ public:
|
|||||||
void updateInterpolationVertices(float t, bool cycle) const;
|
void updateInterpolationVertices(float t, bool cycle) const;
|
||||||
|
|
||||||
//load
|
//load
|
||||||
void loadV2(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);
|
void loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
|
||||||
void load(const string &dir, FILE *f, TextureManager *textureManager);
|
void load(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad);
|
||||||
void save(const string &dir, FILE *f);
|
void save(const string &dir, FILE *f);
|
||||||
|
|
||||||
|
void deletePixels();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void computeTangents();
|
void computeTangents();
|
||||||
};
|
};
|
||||||
@ -156,12 +160,13 @@ public:
|
|||||||
uint32 getVertexCount() const;
|
uint32 getVertexCount() const;
|
||||||
|
|
||||||
//io
|
//io
|
||||||
void load(const string &path);
|
void load(const string &path,bool deletePixMapAfterLoad=false);
|
||||||
void save(const string &path);
|
void save(const string &path);
|
||||||
void loadG3d(const string &path);
|
void loadG3d(const string &path,bool deletePixMapAfterLoad=false);
|
||||||
void saveS3d(const string &path);
|
void saveS3d(const string &path);
|
||||||
|
|
||||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||||
|
void deletePixels();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterpolationData() const;
|
void buildInterpolationData() const;
|
||||||
|
@ -122,6 +122,7 @@ public:
|
|||||||
int getW() const {return w;}
|
int getW() const {return w;}
|
||||||
int getComponents() const {return components;}
|
int getComponents() const {return components;}
|
||||||
uint8 *getPixels() const {return pixels;}
|
uint8 *getPixels() const {return pixels;}
|
||||||
|
void deletePixels();
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -161,6 +162,7 @@ public:
|
|||||||
int getH() const {return h;}
|
int getH() const {return h;}
|
||||||
int getComponents() const {return components;}
|
int getComponents() const {return components;}
|
||||||
uint8 *getPixels() const {return pixels;}
|
uint8 *getPixels() const {return pixels;}
|
||||||
|
void deletePixels();
|
||||||
|
|
||||||
//get data
|
//get data
|
||||||
void getPixel(int x, int y, uint8 *value) const;
|
void getPixel(int x, int y, uint8 *value) const;
|
||||||
@ -236,6 +238,7 @@ public:
|
|||||||
int getD() const {return d;}
|
int getD() const {return d;}
|
||||||
int getComponents() const {return components;}
|
int getComponents() const {return components;}
|
||||||
uint8 *getPixels() const {return pixels;}
|
uint8 *getPixels() const {return pixels;}
|
||||||
|
void deletePixels();
|
||||||
string getPath() const { return path;}
|
string getPath() const { return path;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -271,6 +274,7 @@ public:
|
|||||||
//get
|
//get
|
||||||
Pixmap2D *getFace(int face) {return &faces[face];}
|
Pixmap2D *getFace(int face) {return &faces[face];}
|
||||||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||||
|
void deletePixels();
|
||||||
string getPath(int face) const { return path[face];}
|
string getPath(int face) const { return path[face];}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,10 +28,11 @@ class TextureParams;
|
|||||||
// class Texture
|
// class Texture
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Texture{
|
class Texture {
|
||||||
public:
|
public:
|
||||||
static const int defaultSize;
|
static const int defaultSize;
|
||||||
static const int defaultComponents;
|
static const int defaultComponents;
|
||||||
|
static bool useTextureCompression;
|
||||||
|
|
||||||
enum WrapMode{
|
enum WrapMode{
|
||||||
wmRepeat,
|
wmRepeat,
|
||||||
@ -69,7 +70,6 @@ public:
|
|||||||
WrapMode getWrapMode() const {return wrapMode;}
|
WrapMode getWrapMode() const {return wrapMode;}
|
||||||
bool getPixmapInit() const {return pixmapInit;}
|
bool getPixmapInit() const {return pixmapInit;}
|
||||||
Format getFormat() const {return format;}
|
Format getFormat() const {return format;}
|
||||||
const string getPath() const {return path;}
|
|
||||||
|
|
||||||
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
||||||
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
||||||
@ -78,6 +78,8 @@ public:
|
|||||||
|
|
||||||
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
||||||
virtual void end()=0;
|
virtual void end()=0;
|
||||||
|
virtual string getPath() const = 0;
|
||||||
|
virtual void deletePixels() = 0;
|
||||||
|
|
||||||
virtual void reseInitState() { inited = false; }
|
virtual void reseInitState() { inited = false; }
|
||||||
};
|
};
|
||||||
@ -95,6 +97,8 @@ public:
|
|||||||
|
|
||||||
Pixmap1D *getPixmap() {return &pixmap;}
|
Pixmap1D *getPixmap() {return &pixmap;}
|
||||||
const Pixmap1D *getPixmap() const {return &pixmap;}
|
const Pixmap1D *getPixmap() const {return &pixmap;}
|
||||||
|
virtual string getPath() const;
|
||||||
|
virtual void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -110,6 +114,8 @@ public:
|
|||||||
|
|
||||||
Pixmap2D *getPixmap() {return &pixmap;}
|
Pixmap2D *getPixmap() {return &pixmap;}
|
||||||
const Pixmap2D *getPixmap() const {return &pixmap;}
|
const Pixmap2D *getPixmap() const {return &pixmap;}
|
||||||
|
virtual string getPath() const;
|
||||||
|
virtual void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -125,6 +131,8 @@ public:
|
|||||||
|
|
||||||
Pixmap3D *getPixmap() {return &pixmap;}
|
Pixmap3D *getPixmap() {return &pixmap;}
|
||||||
const Pixmap3D *getPixmap() const {return &pixmap;}
|
const Pixmap3D *getPixmap() const {return &pixmap;}
|
||||||
|
virtual string getPath() const;
|
||||||
|
virtual void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -140,6 +148,8 @@ public:
|
|||||||
|
|
||||||
PixmapCube *getPixmap() {return &pixmap;}
|
PixmapCube *getPixmap() {return &pixmap;}
|
||||||
const PixmapCube *getPixmap() const {return &pixmap;}
|
const PixmapCube *getPixmap() const {return &pixmap;}
|
||||||
|
virtual string getPath() const;
|
||||||
|
virtual void deletePixels();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -48,6 +48,9 @@ public:
|
|||||||
void endLastTexture(bool mustExistInList=false);
|
void endLastTexture(bool mustExistInList=false);
|
||||||
void reinitTextures();
|
void reinitTextures();
|
||||||
|
|
||||||
|
Texture::Filter getTextureFilter() const {return textureFilter;}
|
||||||
|
int getMaxAnisotropy() const {return maxAnisotropy;}
|
||||||
|
|
||||||
Texture *getTexture(const string &path);
|
Texture *getTexture(const string &path);
|
||||||
Texture1D *newTexture1D();
|
Texture1D *newTexture1D();
|
||||||
Texture2D *newTexture2D();
|
Texture2D *newTexture2D();
|
||||||
|
@ -23,6 +23,44 @@ namespace Shared{ namespace Graphics{ namespace Gl{
|
|||||||
|
|
||||||
using namespace Platform;
|
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){
|
GLint toWrapModeGl(Texture::WrapMode wrapMode){
|
||||||
switch(wrapMode){
|
switch(wrapMode){
|
||||||
case Texture::wmClamp:
|
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
|
// class Texture1DGl
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -147,6 +147,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
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);
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
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);
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
int error= gluBuild1DMipmaps(
|
int error= gluBuild1DMipmaps(
|
||||||
GL_TEXTURE_1D, glInternalFormat, pixmap.getW(),
|
GL_TEXTURE_1D, glCompressionFormat, pixmap.getW(),
|
||||||
glFormat, GL_UNSIGNED_BYTE, pixels);
|
glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
if(error!=0){
|
if(error!=0){
|
||||||
@ -187,7 +188,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexImage1D(
|
glTexImage1D(
|
||||||
GL_TEXTURE_1D, 0, glInternalFormat, pixmap.getW(),
|
GL_TEXTURE_1D, 0, glCompressionFormat, pixmap.getW(),
|
||||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
GLint error= glGetError();
|
GLint error= glGetError();
|
||||||
@ -199,6 +200,7 @@ void Texture1DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
@ -280,17 +282,17 @@ 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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputTextureDebugInfo(&pixmap,format, pixmap.getComponents(),getPath());
|
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2DGl::end(){
|
void Texture2DGl::end(){
|
||||||
if(inited){
|
if(inited) {
|
||||||
|
//printf("==> Deleting GL Texture [%s] handle = %d\n",getPath().c_str(),handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
glDeleteTextures(1, &handle);
|
glDeleteTextures(1, &handle);
|
||||||
assertGl();
|
assertGl();
|
||||||
@ -310,6 +312,7 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
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);
|
||||||
|
|
||||||
//pixel init var
|
//pixel init var
|
||||||
const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL;
|
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);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexImage3D(
|
glTexImage3D(
|
||||||
GL_TEXTURE_3D, 0, glInternalFormat,
|
GL_TEXTURE_3D, 0, glCompressionFormat,
|
||||||
pixmap.getW(), pixmap.getH(), pixmap.getD(),
|
pixmap.getW(), pixmap.getH(), pixmap.getD(),
|
||||||
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
0, glFormat, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
@ -340,6 +343,8 @@ void Texture3DGl::init(Filter filter, int maxAnisotropy){
|
|||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
|
||||||
|
OutputTextureDebugInfo(format, pixmap.getComponents(),getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
@ -422,7 +427,7 @@ void TextureCubeGl::init(Filter filter, int maxAnisotropy){
|
|||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputTextureDebugInfo(currentPixmap,format, currentPixmap->getComponents(),getPath());
|
OutputTextureDebugInfo(format, currentPixmap->getComponents(),getPath());
|
||||||
}
|
}
|
||||||
inited= true;
|
inited= true;
|
||||||
|
|
||||||
@ -439,29 +444,28 @@ 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\n",path.c_str(),format,components,glFormat);
|
||||||
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());
|
GLint compressed=0;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
||||||
|
int error = glGetError();
|
||||||
|
|
||||||
GLint compressed=0;
|
printf("**** Texture compressed status: %d, error [%d]\n",compressed,error);
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &compressed);
|
|
||||||
int error = glGetError();
|
|
||||||
|
|
||||||
printf("**** Texture compressed status: %d, error [%d]\n",compressed,error);
|
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);
|
||||||
|
|
||||||
compressed=0;
|
compressed=0;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &compressed);
|
||||||
error = glGetError();
|
error = glGetError();
|
||||||
printf("**** Texture image size in video RAM: %d, error [%d]\n",compressed,error);
|
printf("**** Texture image compression format used: %d, error [%d]\n",compressed,error);
|
||||||
|
}
|
||||||
compressed=0;
|
|
||||||
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
|
}}}//end namespace
|
||||||
|
@ -34,7 +34,8 @@ using namespace Util;
|
|||||||
|
|
||||||
// ==================== constructor & destructor ====================
|
// ==================== constructor & destructor ====================
|
||||||
|
|
||||||
Mesh::Mesh(){
|
Mesh::Mesh() {
|
||||||
|
textureManager = NULL;
|
||||||
frameCount= 0;
|
frameCount= 0;
|
||||||
vertexCount= 0;
|
vertexCount= 0;
|
||||||
indexCount= 0;
|
indexCount= 0;
|
||||||
@ -48,24 +49,25 @@ Mesh::Mesh(){
|
|||||||
|
|
||||||
for(int i=0; i<meshTextureCount; ++i){
|
for(int i=0; i<meshTextureCount; ++i){
|
||||||
textures[i]= NULL;
|
textures[i]= NULL;
|
||||||
|
texturesOwned[i]=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
twoSided= false;
|
twoSided= false;
|
||||||
customColor= false;
|
customColor= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh::~Mesh(){
|
Mesh::~Mesh() {
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::init(){
|
void Mesh::init() {
|
||||||
vertices= new Vec3f[frameCount*vertexCount];
|
vertices= new Vec3f[frameCount*vertexCount];
|
||||||
normals= new Vec3f[frameCount*vertexCount];
|
normals= new Vec3f[frameCount*vertexCount];
|
||||||
texCoords= new Vec2f[vertexCount];
|
texCoords= new Vec2f[vertexCount];
|
||||||
indices= new uint32[indexCount];
|
indices= new uint32[indexCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::end(){
|
void Mesh::end() {
|
||||||
delete [] vertices;
|
delete [] vertices;
|
||||||
delete [] normals;
|
delete [] normals;
|
||||||
delete [] texCoords;
|
delete [] texCoords;
|
||||||
@ -73,6 +75,16 @@ void Mesh::end(){
|
|||||||
delete [] indices;
|
delete [] indices;
|
||||||
|
|
||||||
delete interpolationData;
|
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 =========================
|
// ========================== shadows & interpolation =========================
|
||||||
@ -91,7 +103,8 @@ void Mesh::updateInterpolationVertices(float t, bool cycle) const{
|
|||||||
|
|
||||||
// ==================== load ====================
|
// ==================== 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
|
//read header
|
||||||
MeshHeaderV2 meshHeader;
|
MeshHeaderV2 meshHeader;
|
||||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f);
|
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){
|
if(textures[mtDiffuse]==NULL){
|
||||||
textures[mtDiffuse]= textureManager->newTexture2D();
|
textures[mtDiffuse]= textureManager->newTexture2D();
|
||||||
textures[mtDiffuse]->load(texPath);
|
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);
|
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
|
//read header
|
||||||
MeshHeaderV3 meshHeader;
|
MeshHeaderV3 meshHeader;
|
||||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f);
|
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){
|
if(textures[mtDiffuse]==NULL){
|
||||||
textures[mtDiffuse]= textureManager->newTexture2D();
|
textures[mtDiffuse]= textureManager->newTexture2D();
|
||||||
textures[mtDiffuse]->load(texPath);
|
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);
|
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
|
//read header
|
||||||
MeshHeader meshHeader;
|
MeshHeader meshHeader;
|
||||||
size_t readBytes = fread(&meshHeader, sizeof(MeshHeader), 1, f);
|
size_t readBytes = fread(&meshHeader, sizeof(MeshHeader), 1, f);
|
||||||
@ -222,10 +251,15 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager){
|
|||||||
textures[i]= static_cast<Texture2D*>(textureManager->getTexture(mapFullPath));
|
textures[i]= static_cast<Texture2D*>(textureManager->getTexture(mapFullPath));
|
||||||
if(textures[i]==NULL){
|
if(textures[i]==NULL){
|
||||||
textures[i]= textureManager->newTexture2D();
|
textures[i]= textureManager->newTexture2D();
|
||||||
if(meshTextureChannelCount[i]!=-1){
|
if(meshTextureChannelCount[i] != -1){
|
||||||
textures[i]->getPixmap()->init(meshTextureChannelCount[i]);
|
textures[i]->getPixmap()->init(meshTextureChannelCount[i]);
|
||||||
}
|
}
|
||||||
textures[i]->load(mapFullPath);
|
textures[i]->load(mapFullPath);
|
||||||
|
texturesOwned[i]=true;
|
||||||
|
textures[i]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
|
||||||
|
if(deletePixMapAfterLoad == true) {
|
||||||
|
textures[i]->deletePixels();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flag*= 2;
|
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
|
// class Model
|
||||||
// ===============================================
|
// ===============================================
|
||||||
@ -359,7 +401,7 @@ uint32 Model::getTriangleCount() const{
|
|||||||
return triangleCount;
|
return triangleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Model::getVertexCount() const{
|
uint32 Model::getVertexCount() const {
|
||||||
uint32 vertexCount= 0;
|
uint32 vertexCount= 0;
|
||||||
for(uint32 i=0; i<meshCount; ++i){
|
for(uint32 i=0; i<meshCount; ++i){
|
||||||
vertexCount+= meshes[i].getVertexCount();
|
vertexCount+= meshes[i].getVertexCount();
|
||||||
@ -369,17 +411,17 @@ uint32 Model::getVertexCount() const{
|
|||||||
|
|
||||||
// ==================== io ====================
|
// ==================== io ====================
|
||||||
|
|
||||||
void Model::load(const string &path){
|
void Model::load(const string &path, bool deletePixMapAfterLoad) {
|
||||||
string extension= path.substr(path.find_last_of('.')+1);
|
string extension= path.substr(path.find_last_of('.')+1);
|
||||||
if(extension=="g3d" || extension=="G3D"){
|
if(extension=="g3d" || extension=="G3D"){
|
||||||
loadG3d(path);
|
loadG3d(path,deletePixMapAfterLoad);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw runtime_error("Unknown model format: " + extension);
|
throw runtime_error("Unknown model format: " + extension);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::save(const string &path){
|
void Model::save(const string &path) {
|
||||||
string extension= path.substr(path.find_last_of('.')+1);
|
string extension= path.substr(path.find_last_of('.')+1);
|
||||||
if(extension=="g3d" ||extension=="G3D" || extension=="s3d" || extension=="S3D"){
|
if(extension=="g3d" ||extension=="G3D" || extension=="s3d" || extension=="S3D"){
|
||||||
saveS3d(path);
|
saveS3d(path);
|
||||||
@ -428,7 +470,7 @@ void Model::save(const string &path){
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
//load a model from a g3d file
|
//load a model from a g3d file
|
||||||
void Model::loadG3d(const string &path){
|
void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
FILE *f=fopen(path.c_str(),"rb");
|
FILE *f=fopen(path.c_str(),"rb");
|
||||||
@ -462,7 +504,7 @@ void Model::loadG3d(const string &path){
|
|||||||
//load meshes
|
//load meshes
|
||||||
meshes= new Mesh[meshCount];
|
meshes= new Mesh[meshCount];
|
||||||
for(uint32 i=0; i<meshCount; ++i){
|
for(uint32 i=0; i<meshCount; ++i){
|
||||||
meshes[i].load(dir, f, textureManager);
|
meshes[i].load(dir, f, textureManager,deletePixMapAfterLoad);
|
||||||
meshes[i].buildInterpolationData();
|
meshes[i].buildInterpolationData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,7 +514,7 @@ void Model::loadG3d(const string &path){
|
|||||||
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
||||||
meshes= new Mesh[meshCount];
|
meshes= new Mesh[meshCount];
|
||||||
for(uint32 i=0; i<meshCount; ++i){
|
for(uint32 i=0; i<meshCount; ++i){
|
||||||
meshes[i].loadV3(dir, f, textureManager);
|
meshes[i].loadV3(dir, f, textureManager,deletePixMapAfterLoad);
|
||||||
meshes[i].buildInterpolationData();
|
meshes[i].buildInterpolationData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,7 +524,7 @@ void Model::loadG3d(const string &path){
|
|||||||
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
|
||||||
meshes= new Mesh[meshCount];
|
meshes= new Mesh[meshCount];
|
||||||
for(uint32 i=0; i<meshCount; ++i){
|
for(uint32 i=0; i<meshCount; ++i){
|
||||||
meshes[i].loadV2(dir, f, textureManager);
|
meshes[i].loadV2(dir, f, textureManager,deletePixMapAfterLoad);
|
||||||
meshes[i].buildInterpolationData();
|
meshes[i].buildInterpolationData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -523,4 +565,10 @@ void Model::saveS3d(const string &path){
|
|||||||
fclose(f);*/
|
fclose(f);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::deletePixels() {
|
||||||
|
for(uint32 i = 0; i < meshCount; ++i) {
|
||||||
|
meshes[i].deletePixels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -352,8 +352,13 @@ void Pixmap1D::init(int w, int components){
|
|||||||
pixels= new uint8[w*components];
|
pixels= new uint8[w*components];
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap1D::~Pixmap1D(){
|
void Pixmap1D::deletePixels() {
|
||||||
delete [] pixels;
|
delete [] pixels;
|
||||||
|
pixels = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pixmap1D::~Pixmap1D(){
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap1D::load(const string &path){
|
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];
|
pixels= new uint8[h*w*components];
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap2D::~Pixmap2D(){
|
void Pixmap2D::deletePixels() {
|
||||||
delete [] pixels;
|
delete [] pixels;
|
||||||
|
pixels = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pixmap2D::~Pixmap2D(){
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap2D* Pixmap2D::loadPath(const string& path) {
|
Pixmap2D* Pixmap2D::loadPath(const string& path) {
|
||||||
@ -778,8 +788,13 @@ void Pixmap3D::init(int components){
|
|||||||
pixels= NULL;
|
pixels= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pixmap3D::~Pixmap3D(){
|
void Pixmap3D::deletePixels() {
|
||||||
delete [] pixels;
|
delete [] pixels;
|
||||||
|
pixels = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pixmap3D::~Pixmap3D(){
|
||||||
|
deletePixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pixmap3D::loadSlice(const string &path, int slice){
|
void Pixmap3D::loadSlice(const string &path, int slice){
|
||||||
@ -862,5 +877,11 @@ void PixmapCube::loadFace(const string &path, int face){
|
|||||||
faces[face].load(path);
|
faces[face].load(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PixmapCube::deletePixels() {
|
||||||
|
for(int i=0; i<6; ++i){
|
||||||
|
faces[i].deletePixels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@ -24,6 +24,7 @@ namespace Shared{ namespace Graphics{
|
|||||||
|
|
||||||
const int Texture::defaultSize= 256;
|
const int Texture::defaultSize= 256;
|
||||||
const int Texture::defaultComponents = 4;
|
const int Texture::defaultComponents = 4;
|
||||||
|
bool Texture::useTextureCompression = false;
|
||||||
|
|
||||||
Texture::Texture(){
|
Texture::Texture(){
|
||||||
mipmap= true;
|
mipmap= true;
|
||||||
@ -49,6 +50,15 @@ void Texture1D::load(const string &path){
|
|||||||
this->path= 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
|
// class Texture2D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -64,6 +74,15 @@ void Texture2D::load(const string &path){
|
|||||||
this->path= 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
|
// class Texture3D
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -79,6 +98,15 @@ void Texture3D::loadSlice(const string &path, int slice){
|
|||||||
this->path= path;
|
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
|
// class TextureCube
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@ -94,4 +122,25 @@ void TextureCube::loadFace(const string &path, int face){
|
|||||||
this->path= path;
|
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
|
}}//end namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user