Commit 65c0c640 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added TextureData Files to TextureControl



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5603 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7769c9fc
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5183 $
// $Author: wilden $
// $Date: 2009-03-03 12:51:24 +0100 (Tue, 03 Mar 2009) $
//
//=============================================================================
#include "TextureData.hh"
//-----------------------------------------------------------------------------------
TextureData::TextureData(){
nextInternalID_ = 0;
}
//-----------------------------------------------------------------------------------
TextureData::~TextureData() {
}
//-----------------------------------------------------------------------------------
/** \brief Check if a texture exists
*
* @param _textureName name of the texture
* @return returns wether the texture exists
*/
bool TextureData::textureExists(QString _textureName)
{
return ( getTextureIndex(_textureName) != -1);
}
//-----------------------------------------------------------------------------------
/** \brief Check if a texture is enabled
*
* @param _textureName name of the texture
* @return returns wether the texture is enabled
*/
bool TextureData::isEnabled(QString _textureName)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
return textures_[id].enabled;
else
return false;
}
//-----------------------------------------------------------------------------------
/** \brief Enable a given texture
*
* @param _textureName name of the texture
* @param _exclusive disable other textures?
*/
void TextureData::enableTexture(QString _textureName, bool _exclusive)
{
int id = getTextureIndex(_textureName);
if ( id != -1){
textures_[id].enabled = true;
//disable other textures
if (_exclusive)
for ( int i = 0 ; i < (int)textures_.size() ; ++i )
if (i != id)
textures_[i].enabled = false;
}
}
//-----------------------------------------------------------------------------------
/** \brief Disable a given texture
*
* @param _textureName name of the texture
*/
void TextureData::disableTexture(QString _textureName)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
textures_[id].enabled = false;
}
//-----------------------------------------------------------------------------------
/** \brief Add a Texture
*
* @param _textureName name of the texture
* @param _filename filename of the texture
* @param _dimension dimension of the texture
* @param _glName glName for the texture
* @return persistent id of the texture
*/
int TextureData::addTexture(QString _textureName, QString _filename, uint _dimension, GLuint _glName)
{
//generate texture object
Texture tex;
tex.id = nextInternalID_++;
tex.name = _textureName;
tex.glName = _glName;
tex.filename = _filename;
tex.dimension = _dimension;
tex.enabled = true;
tex.dirty = false;
tex.type = VERTEXBASED;
tex.parameters = TexParameters();
textures_.push_back( tex );
textureMap_[ tex.id ] = tex.glName;
propertyMap_[ tex.id ] = tex.name.toStdString();
return tex.id;
}
//-----------------------------------------------------------------------------------
/** \brief Delete a given texture
*
* @param _textureName name of the texture
*/
void TextureData::deleteTexture(QString _textureName)
{
int index = getTextureIndex(_textureName);
if ( index != -1){
textureMap_.erase( texture(_textureName).id );
propertyMap_.erase( texture(_textureName).id );
textures_.erase(textures_.begin()+index);
}
}
//-----------------------------------------------------------------------------------
/** \brief get parameters of a given texture
*
* @param _textureName name of the texture
* @return corresponding textureParameters or invalid TexParameters
*/
TexParameters TextureData::textureParameters(QString _textureName)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
return textures_[id].parameters;
else
return TexParameters();
}
//-----------------------------------------------------------------------------------
/** \brief Set Parameters for a given texture
*
* @param _textureName name of the texture
* @param _params new parameters for the texture
*/
void TextureData::setTextureParameters(QString _textureName, TexParameters _params)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
textures_[id].parameters = _params;
}
//-----------------------------------------------------------------------------------
/** \brief get texture object of a given texture
*
* @param _textureName name of the texture
* @return corresponding texture object
*/
Texture TextureData::texture(QString _textureName)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
return textures_[id];
else
return Texture();
}
//-----------------------------------------------------------------------------------
/** \brief Get the index of a given texture
*
* @param _textureName name of the texture
* @return index in texture vector or -1 if not found
*/
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 ) {
textureid = i;
break;
}
}
return textureid;
}
//-----------------------------------------------------------------------------------
/** \brief Get reference to the texture vector
*
* @return texture vector
*/
std::vector< Texture >& TextureData::textures(){
return textures_;
}
//-----------------------------------------------------------------------------------
/** \brief Get pointer to the textureMap
*
* @return textureMap
*/
std::map< int, GLuint>* TextureData::textureMap(){
return &textureMap_;
}
//-----------------------------------------------------------------------------------
/** \brief Get pointer to the propertyMap
*
* @return propertyMap
*/
std::map< int, std::string>* TextureData::propertyMap(){
return &propertyMap_;
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5183 $
// $Author: wilden $
// $Date: 2009-03-03 12:51:24 +0100 (Tue, 03 Mar 2009) $
//
//=============================================================================
#include <OpenFlipper/common/perObjectData.hh>
#include <QString>
#include <GL/gl.h>
#include <vector>
#include <map>
struct TexParameters {
double clamp_min;
double clamp_max;
bool clamp;
bool repeat;
double max_val;
bool center;
bool abs;
bool scale;
};
struct Texture {
// Texture id
int id;
// glName
GLuint glName;
// Texture Name
QString name;
// Filename of the texture
QString filename;
// dimension
uint dimension;
// Status
bool enabled;
// does this texture need an update?
bool dirty;
// Texture Type
uint type;
// Parameters
TexParameters parameters;
};
class TextureData : public PerObjectData
{
public:
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
public :
/// Konstruktor
TextureData();
/// Destruktor
~TextureData();
/// Check if a texture exists
bool textureExists(QString _textureName);
/// Check if a texture is enabled
bool isEnabled(QString _textureName);
/// Enable a given texture
void enableTexture(QString _textureName, bool _exclusive=false);
/// Disable a given texture
void disableTexture(QString _textureName);
/// Add a Texture
int addTexture(QString _textureName , QString _filename , uint _dimension, GLuint _glName);
/// Delete a given texture
void deleteTexture(QString _textureName);
/// get parameters of a given texture
TexParameters textureParameters(QString _textureName);
/// Set Parameters for a given texture
void setTextureParameters(QString _textureName, TexParameters _params);
/// Get the texture object
Texture texture(QString _textureName);
/// Get reference to the texture vector
std::vector< Texture >& textures();
/// Get reference to the textureMap
std::map< int, GLuint >* textureMap();
/// Get reference to the propertyMap
std::map< int, std::string >* propertyMap();
private :
std::map< int, GLuint> textureMap_;
std::map< int, std::string> propertyMap_;
int nextInternalID_;
//vector containing all textures of an object
std::vector< Texture > textures_;
// Get the index of a given texture
int getTextureIndex(QString _textureName);
};
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