Commit 0cf983ae authored by Jan Möbius's avatar Jan Möbius
Browse files

Updated textureData before enabling new texture handling

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5633 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6b8873cc
...@@ -42,7 +42,7 @@ TextureData::TextureData(){ ...@@ -42,7 +42,7 @@ TextureData::TextureData(){
TextureData::~TextureData() { TextureData::~TextureData() {
} }
/*
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Check if a texture exists /** \brief Check if a texture exists
...@@ -79,7 +79,7 @@ bool TextureData::isEnabled(QString _textureName) ...@@ -79,7 +79,7 @@ bool TextureData::isEnabled(QString _textureName)
* @param _textureName name of the texture * @param _textureName name of the texture
* @param _exclusive disable other textures? * @param _exclusive disable other textures?
*/ */
void TextureData::enableTexture(QString _textureName, bool _exclusive) bool TextureData::enableTexture(QString _textureName, bool _exclusive)
{ {
int id = getTextureIndex(_textureName); int id = getTextureIndex(_textureName);
...@@ -92,6 +92,7 @@ void TextureData::enableTexture(QString _textureName, bool _exclusive) ...@@ -92,6 +92,7 @@ void TextureData::enableTexture(QString _textureName, bool _exclusive)
for ( int i = 0 ; i < (int)textures_.size() ; ++i ) for ( int i = 0 ; i < (int)textures_.size() ; ++i )
if (i != id) if (i != id)
textures_[i].enabled = false; textures_[i].enabled = false;
return true;
} }
} }
...@@ -131,7 +132,7 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen ...@@ -131,7 +132,7 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
tex.enabled = true; tex.enabled = true;
tex.dirty = false; tex.dirty = false;
tex.type = VERTEXBASED; tex.type = VERTEXBASED;
tex.parameters = TexParameters(); // tex.parameters = TexParameters;
textures_.push_back( tex ); textures_.push_back( tex );
...@@ -141,24 +142,36 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen ...@@ -141,24 +142,36 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
return tex.id; return tex.id;
} }
int TextureData::addTexture ( Texture _texture, GLuint _glName ) {
_texture.id = nextInternalID_++;
_texture.glName = _glName;
textures_.push_back(_texture);
textureMap_[ _texture.id ] = _texture.glName;
propertyMap_[ _texture.id ] = _texture.name.toStdString();
std::cerr << "Added texture " << _texture.name.toStdString() << std::endl;
return _texture.id;
}
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Delete a given texture /** \brief Delete a given texture
* *
* @param _textureName name of the texture * @param _textureName name of the texture
*/ */
void TextureData::deleteTexture(QString _textureName) // void TextureData::deleteTexture(QString _textureName)
{ // {
int index = getTextureIndex(_textureName); // int index = getTextureIndex(_textureName);
//
if ( index != -1){ // if ( index != -1){
//
//
textureMap_.erase( texture(_textureName).id ); // textureMap_.erase( texture(_textureName).id );
propertyMap_.erase( texture(_textureName).id ); // propertyMap_.erase( texture(_textureName).id );
textures_.erase(textures_.begin()+index); // textures_.erase(textures_.begin()+index);
} // }
} // }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
...@@ -167,15 +180,15 @@ void TextureData::deleteTexture(QString _textureName) ...@@ -167,15 +180,15 @@ void TextureData::deleteTexture(QString _textureName)
* @param _textureName name of the texture * @param _textureName name of the texture
* @return corresponding textureParameters or invalid TexParameters * @return corresponding textureParameters or invalid TexParameters
*/ */
TexParameters TextureData::textureParameters(QString _textureName) // TexParameters TextureData::textureParameters(QString _textureName)
{ // {
int id = getTextureIndex(_textureName); // int id = getTextureIndex(_textureName);
//
if ( id != -1) // if ( id != -1)
return textures_[id].parameters; // return textures_[id].parameters;
else // else
return TexParameters(); // return TexParameters();
} // }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
...@@ -184,13 +197,13 @@ TexParameters TextureData::textureParameters(QString _textureName) ...@@ -184,13 +197,13 @@ TexParameters TextureData::textureParameters(QString _textureName)
* @param _textureName name of the texture * @param _textureName name of the texture
* @param _params new parameters for the texture * @param _params new parameters for the texture
*/ */
void TextureData::setTextureParameters(QString _textureName, TexParameters _params) // void TextureData::setTextureParameters(QString _textureName, TexParameters _params)
{ // {
int id = getTextureIndex(_textureName); // int id = getTextureIndex(_textureName);
//
if ( id != -1) // if ( id != -1)
textures_[id].parameters = _params; // textures_[id].parameters = _params;
} // }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
...@@ -199,14 +212,16 @@ void TextureData::setTextureParameters(QString _textureName, TexParameters _para ...@@ -199,14 +212,16 @@ void TextureData::setTextureParameters(QString _textureName, TexParameters _para
* @param _textureName name of the texture * @param _textureName name of the texture
* @return corresponding texture object * @return corresponding texture object
*/ */
Texture TextureData::texture(QString _textureName) Texture& TextureData::texture(QString _textureName)
{ {
int id = getTextureIndex(_textureName); int id = getTextureIndex(_textureName);
if ( id != -1) if ( id != -1)
return textures_[id]; return textures_[id];
else else {
return Texture(); std::cerr << "Invalid Texture" << _textureName.toStdString() << std::endl;
return noTexture;
}
} }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
...@@ -233,7 +248,7 @@ int TextureData::getTextureIndex(QString _textureName) ...@@ -233,7 +248,7 @@ int TextureData::getTextureIndex(QString _textureName)
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Get reference to the texture vector /** \brief Get reference to the texture vector
* *
* @return texture vector * @return texture vector
*/ */
std::vector< Texture >& TextureData::textures(){ std::vector< Texture >& TextureData::textures(){
...@@ -243,7 +258,7 @@ std::vector< Texture >& TextureData::textures(){ ...@@ -243,7 +258,7 @@ std::vector< Texture >& TextureData::textures(){
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Get pointer to the textureMap /** \brief Get pointer to the textureMap
* *
* @return textureMap * @return textureMap
*/ */
std::map< int, GLuint>* TextureData::textureMap(){ std::map< int, GLuint>* TextureData::textureMap(){
...@@ -253,7 +268,7 @@ std::map< int, GLuint>* TextureData::textureMap(){ ...@@ -253,7 +268,7 @@ std::map< int, GLuint>* TextureData::textureMap(){
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
/** \brief Get pointer to the propertyMap /** \brief Get pointer to the propertyMap
* *
* @return propertyMap * @return propertyMap
*/ */
std::map< int, std::string>* TextureData::propertyMap(){ std::map< int, std::string>* TextureData::propertyMap(){
......
...@@ -35,21 +35,37 @@ ...@@ -35,21 +35,37 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <vector> #include <vector>
#include <map> #include <map>
#include <float.h>
#include <iostream>
struct TexParameters { enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
double clamp_min;
double clamp_max;
bool clamp; class TexParameters
bool repeat; {
public:
TexParameters() :
scale ( true ),
clamp_min ( FLT_MIN ),
clamp_max ( FLT_MAX ),
clamp ( false ),
repeat ( false ),
center ( false ),
abs ( false ),
max_val ( 1.0 ) {std::cerr << "Constructor for parameters" << std::endl;};
bool scale;
double clamp_min;
double clamp_max;
double max_val; bool clamp;
bool repeat;
bool center; bool center;
bool abs; bool abs;
bool scale; double max_val;
}; };
struct Texture { struct Texture {
...@@ -76,53 +92,76 @@ struct Texture { ...@@ -76,53 +92,76 @@ struct Texture {
class TextureData : public PerObjectData class TextureData : public PerObjectData
{ {
public:
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
public : public :
/// Konstruktor /// Constructor
TextureData(); TextureData();
/// Destruktor /// Destructor
~TextureData(); ~TextureData();
/// Check if a texture exists
bool textureExists(QString _textureName); /// Check if a texture exists
/// Check if a texture is enabled bool textureExists(QString _textureName);
bool isEnabled(QString _textureName);
/// Enable a given texture
void enableTexture(QString _textureName, bool _exclusive=false); /// Check if a texture is enabled
/// Disable a given texture bool isEnabled(QString _textureName);
void disableTexture(QString _textureName);
/// Add a Texture
int addTexture(QString _textureName , QString _filename , uint _dimension, GLuint _glName); /// Enable a given texture
/// Delete a given texture bool enableTexture(QString _textureName, bool _exclusive = false);
void deleteTexture(QString _textureName);
/// get parameters of a given texture /// Disable a given texture
TexParameters textureParameters(QString _textureName); void disableTexture(QString _textureName);
/// Set Parameters for a given texture
void setTextureParameters(QString _textureName, TexParameters _params); /// Add a Texture
/// Get the texture object int addTexture ( QString _textureName , QString _filename , uint _dimension, GLuint _glName );
Texture texture(QString _textureName);
/// Get reference to the texture vector /// Add a Texture ( Based on an existing specification )
std::vector< Texture >& textures(); int addTexture ( Texture _texture, GLuint _glName );
/// Get reference to the textureMap
std::map< int, GLuint >* textureMap(); /*
/// Get reference to the propertyMap /// Delete a given texture
std::map< int, std::string >* propertyMap(); 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 : private :
std::map< int, GLuint> textureMap_; std::map< int, GLuint> textureMap_;
std::map< int, std::string> propertyMap_; std::map< int, std::string> propertyMap_;
// internal id for the next texture
int nextInternalID_; int nextInternalID_;
//vector containing all textures of an object //vector containing all textures of an object
std::vector< Texture > textures_; std::vector< Texture > textures_;
// Get the index of a given texture // Get the index of a given texture
int getTextureIndex(QString _textureName); int getTextureIndex(QString _textureName);
Texture noTexture;
}; };
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