Commit db1a0b7d authored by Jan Möbius's avatar Jan Möbius

Changed Texture data type to struct

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5722 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b46dd5d1
......@@ -155,7 +155,7 @@ void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QStrin
// Get the id of the new texture
_textureId = -1;
_textureId = texData->texture(_name).id;
_textureId = texData->texture(_name).id();
QImage textureImage;
getImage(_filename,textureImage);
......@@ -170,7 +170,7 @@ void TextureControlPlugin::slotMultiTextureAdded( QString _textureGroup , QStrin
}
void TextureControlPlugin::getImage( QString& _fileName, QImage& _image ) {
void TextureControlPlugin::getImage( QString _fileName, QImage& _image ) {
QString loadFilename;
if ( _fileName.startsWith("/") )
......@@ -219,7 +219,7 @@ void TextureControlPlugin::fileOpened( int _id ) {
// ================================================================================
QImage textureImage;
getImage(globalTextures_.textures()[i].filename,textureImage);
getImage(globalTextures_.textures()[i].filename(),textureImage);
// ================================================================================
// Add the texture to the texture node and get the corresponding id
......@@ -239,7 +239,7 @@ void TextureControlPlugin::fileOpened( int _id ) {
if (glName != 0) {
texData->addTexture(globalTextures_.textures()[i], glName);
texData->setImage(globalTextures_.textures()[i].name,textureImage);
texData->setImage(globalTextures_.textures()[i].name(),textureImage);
}
else {
emit log(LOGERR,"Unable to bind Texture");
......@@ -330,8 +330,8 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
if (_texture.dimension == 1) {
OpenMesh::HPropHandleT< double > texture;
if ( ! _mesh.get_property_handle(texture, _texture.name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name );
if ( ! _mesh.get_property_handle(texture, _texture.name().toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name() );
return;
}
......@@ -340,8 +340,8 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
} else if ( _texture.dimension == 2 ) {
OpenMesh::HPropHandleT< OpenMesh::Vec2d > texture2D;
if ( ! _mesh.get_property_handle( texture2D, _texture.name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name);
if ( ! _mesh.get_property_handle( texture2D, _texture.name().toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name() );
return;
}
......@@ -353,8 +353,8 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
if ( _texture.dimension == 1 ) {
OpenMesh::VPropHandleT< double > texture;
if ( ! _mesh.get_property_handle(texture,_texture.name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name );
if ( ! _mesh.get_property_handle(texture,_texture.name().toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name() );
return;
}
......@@ -363,8 +363,8 @@ void TextureControlPlugin::doUpdateTexture ( Texture& _texture, MeshT& _mesh )
} else if ( _texture.dimension == 2 ) {
OpenMesh::VPropHandleT< OpenMesh::Vec2d > texture2D;
if ( ! _mesh.get_property_handle(texture2D,_texture.name.toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name );
if ( ! _mesh.get_property_handle(texture2D,_texture.name().toStdString() ) ) {
emit log(LOGERR,"Unable to get property " + _texture.name() );
return;
}
......@@ -473,7 +473,7 @@ void TextureControlPlugin::slotObjectUpdated(int _identifier)
}
if ( update && texData->textures()[i].enabled )
emit updateTexture( texData->textures()[i].name , _identifier );
emit updateTexture( texData->textures()[i].name() , _identifier );
}
}
......@@ -870,10 +870,10 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
QStringList textureList = texData->texture(_textureName).multiTextureList;
for ( uint i = 0 ; i < texData->textures().size() ; ++i ) {
if ( textureList.contains( texData->textures()[i].name ) )
texData->enableTexture( texData->textures()[i].name , false );
if ( textureList.contains( texData->textures()[i].name() ) )
texData->enableTexture( texData->textures()[i].name() , false );
else
texData->disableTexture( texData->textures()[i].name );
texData->disableTexture( texData->textures()[i].name() );
}
......@@ -886,7 +886,7 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
// ================================================================================
if ( !multiTextureMode && texData->texture( _textureName).dirty ) {
// TODO: maybe introduce lock to prevent extra redraws if updating all objects
emit updateTexture( texData->texture( _textureName ).name , obj->id() );
emit updateTexture( texData->texture( _textureName ).name() , obj->id() );
return;
}
......@@ -896,7 +896,7 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
if( obj->dataType( DATA_TRIANGLE_MESH ) ){
if (!multiTextureMode) {
doUpdateTexture(texData->texture(_textureName), *PluginFunctions::triMeshObject(obj)->mesh());
PluginFunctions::triMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName );
PluginFunctions::triMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName() );
PluginFunctions::triMeshObject(obj)->meshNode()->set_texture_map( 0 );
PluginFunctions::triMeshObject(obj)->meshNode()->set_property_map( 0 );
} else {
......@@ -909,7 +909,7 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
if ( obj->dataType( DATA_POLY_MESH ) ){
if (!multiTextureMode) {
doUpdateTexture(texData->texture(_textureName), *PluginFunctions::polyMeshObject(obj)->mesh());
PluginFunctions::polyMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName );
PluginFunctions::polyMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName() );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_texture_map( 0 );
PluginFunctions::polyMeshObject(obj)->meshNode()->set_property_map( 0 );
} else {
......@@ -1005,7 +1005,7 @@ void TextureControlPlugin::slotUpdateContextMenu( int _objectId ) {
for ( uint i = 0 ; i < texData->textures().size() ; ++i ) {
action = actionGroup->addAction( texData->textures()[i].name );
action = actionGroup->addAction( texData->textures()[i].name() );
action->setCheckable(true);
......
......@@ -155,13 +155,11 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
bool StringToBool(QString _value);
/// Load an Image from disk ( if filename contains leading "/ " its consedered global otherwise in texturedir)
void getImage( QString& _fileName, QImage& _image );
void getImage( QString _fileName, QImage& _image );
/// Checks for a correct drawmode and changes if necessary
void switchDrawMode( bool _multiTexture );
QAction* AC_Texture_Settings;
TextureData globalTextures_;
texturePropertiesWidget* settingsDialog_;
......
......@@ -33,6 +33,19 @@
//-----------------------------------------------------------------------------------
Texture::Texture() :
id_(-1),
glName_(0),
name_("No Texture"),
filename_("Invalid"),
dimension(0),
enabled(false),
dirty(true),
type(UNSET)
{
}
TextureData::TextureData() :
nextInternalID_(0)
{
......@@ -129,10 +142,10 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
{
//generate texture object
Texture tex;
tex.id = nextInternalID_++;
tex.name = _textureName;
tex.glName = _glName;
tex.filename = _filename;
tex.id( nextInternalID_++ );
tex.name( _textureName );
tex.glName( _glName );
tex.filename( _filename );
tex.dimension = _dimension;
tex.enabled = true;
tex.dirty = false;
......@@ -141,21 +154,21 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
textures_.push_back( tex );
textureMap_[ tex.id ] = tex.glName;
propertyMap_[ tex.id ] = tex.name.toStdString();
textureMap_[ tex.id() ] = tex.glName();
propertyMap_[ tex.id() ] = tex.name().toStdString();
return tex.id;
return tex.id();
}
int TextureData::addTexture ( Texture _texture, GLuint _glName ) {
_texture.id = nextInternalID_++;
_texture.glName = _glName;
_texture.id( nextInternalID_++ );
_texture.glName( _glName );
textures_.push_back(_texture);
textureMap_[ _texture.id ] = _texture.glName;
propertyMap_[ _texture.id ] = _texture.name.toStdString();
textureMap_[ _texture.id() ] = _texture.glName();
propertyMap_[ _texture.id() ] = _texture.name().toStdString();
return _texture.id;
return _texture.id();
}
bool TextureData::addMultiTexture( QString _textureName ) {
......@@ -171,12 +184,9 @@ bool TextureData::addMultiTexture( QString _textureName ) {
//generate texture object
Texture tex;
tex.id = nextInternalID_++;
tex.name = _textureName;
tex.glName = 0;
tex.filename = "MultiTexture";
tex.dimension = 0;
tex.enabled = false;
tex.id( nextInternalID_++ );
tex.name( _textureName );
tex.filename("MultiTexture");
tex.dirty = false;
tex.type = MULTITEXTURE;
......@@ -281,7 +291,7 @@ int TextureData::getTextureIndex(QString _textureName)
// Search the list of textures if we have the texture
int textureid = -1;
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) {
if ( textures_[i].name == _textureName ) {
if ( textures_[i].name() == _textureName ) {
textureid = i;
break;
}
......
......@@ -43,7 +43,10 @@
#include <float.h>
#include <iostream>
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1, MULTITEXTURE = 1 << 2};
enum TextureType { UNSET = 1 << 0,
VERTEXBASED = 1 << 1,
HALFEDGEBASED = 1 << 2,
MULTITEXTURE = 1 << 3 };
class TexParameters
{
......@@ -73,15 +76,22 @@ class TexParameters
double max_val;
};
struct Texture {
// Texture id
int id;
// glName
GLuint glName;
// Texture Name
QString name;
// Filename of the texture
QString filename;
class Texture {
public :
Texture();
void filename( QString _name ) { filename_ = _name; };
QString filename() { return filename_; };
void id( int _id ) { id_ = _id; };
int id() { return id_; };
void glName( GLuint _glName ) { glName_ = _glName; };
GLuint glName() { return glName_; };
void name( QString _name ) { name_ = _name; };
QString name() { return name_; };
// dimension
uint dimension;
// Status
......@@ -98,6 +108,19 @@ struct Texture {
/// If this is a multiTexture, the list will contain all textures for this multi Texture node.
QStringList multiTextureList;
private:
// Filename of the texture
QString filename_;
// Texture id
int id_;
// glName
GLuint glName_;
// Texture Name
QString name_;
};
class TextureData : public PerObjectData
......
......@@ -112,7 +112,7 @@ void texturePropertiesWidget::show(TextureData* _texData, int _id, QString _name
textureList->clear();
for (uint i=0; i < texData_->textures().size(); i++)
textureList->addItem( texData_->textures()[i].name );
textureList->addItem( texData_->textures()[i].name() );
if ( textureList->count() == 0){
QMessageBox msgBox(this);
......@@ -191,10 +191,10 @@ void texturePropertiesWidget::textureChanged(QListWidgetItem* _item){
imageLabel->setPixmap(QPixmap::fromImage(texture.textureImage));
imageLabel->setScaledContents(true);
if ( !texture.filename.startsWith("/") )
fileLabel->setText( "File: " + texture.filename );
if ( !texture.filename().startsWith("/") )
fileLabel->setText( "File: " + texture.filename() );
else
fileLabel->setText( "File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename );
fileLabel->setText( "File: " + OpenFlipper::Options::textureDirStr() + QDir::separator() + texture.filename() );
// update plot only when dimension is 1
if ( texture.dimension == 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment