Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ TextureData::TextureData(){
TextureData::~TextureData() {
}
/*
//-----------------------------------------------------------------------------------
/** \brief Check if a texture exists
......@@ -79,7 +79,7 @@ bool TextureData::isEnabled(QString _textureName)
* @param _textureName name of the texture
* @param _exclusive disable other textures?
*/
void TextureData::enableTexture(QString _textureName, bool _exclusive)
bool TextureData::enableTexture(QString _textureName, bool _exclusive)
{
int id = getTextureIndex(_textureName);
......@@ -92,6 +92,7 @@ void TextureData::enableTexture(QString _textureName, bool _exclusive)
for ( int i = 0 ; i < (int)textures_.size() ; ++i )
if (i != id)
textures_[i].enabled = false;
return true;
}
}
......@@ -131,7 +132,7 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
tex.enabled = true;
tex.dirty = false;
tex.type = VERTEXBASED;
tex.parameters = TexParameters();
// tex.parameters = TexParameters;
textures_.push_back( tex );
......@@ -141,24 +142,36 @@ int TextureData::addTexture(QString _textureName, QString _filename, uint _dimen
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
*
* @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);
}
}
// 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);
// }
// }
//-----------------------------------------------------------------------------------
......@@ -167,15 +180,15 @@ void TextureData::deleteTexture(QString _textureName)
* @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();
}
// TexParameters TextureData::textureParameters(QString _textureName)
// {
// int id = getTextureIndex(_textureName);
//
// if ( id != -1)
// return textures_[id].parameters;
// else
// return TexParameters();
// }
//-----------------------------------------------------------------------------------
......@@ -184,13 +197,13 @@ TexParameters TextureData::textureParameters(QString _textureName)
* @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;
}
// void TextureData::setTextureParameters(QString _textureName, TexParameters _params)
// {
// int id = getTextureIndex(_textureName);
//
// if ( id != -1)
// textures_[id].parameters = _params;
// }
//-----------------------------------------------------------------------------------
......@@ -199,14 +212,16 @@ void TextureData::setTextureParameters(QString _textureName, TexParameters _para
* @param _textureName name of the texture
* @return corresponding texture object
*/
Texture TextureData::texture(QString _textureName)
Texture& TextureData::texture(QString _textureName)
{
int id = getTextureIndex(_textureName);
if ( id != -1)
return textures_[id];
else
return Texture();
else {
std::cerr << "Invalid Texture" << _textureName.toStdString() << std::endl;
return noTexture;
}
}
//-----------------------------------------------------------------------------------
......
......@@ -35,21 +35,37 @@
#include <GL/gl.h>
#include <vector>
#include <map>
#include <float.h>
#include <iostream>
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
class TexParameters
{
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;
struct TexParameters {
double clamp_min;
double clamp_max;
bool clamp;
bool repeat;
double max_val;
bool center;
bool abs;
bool scale;
double max_val;
};
struct Texture {
......@@ -76,53 +92,76 @@ struct Texture {
class TextureData : public PerObjectData
{
public:
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
public :
/// Konstruktor
/// Constructor
TextureData();
/// Destruktor
/// Destructor
~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);
bool 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 );
/// Add a Texture ( Based on an existing specification )
int addTexture ( Texture _texture, 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);
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_;
// internal id for the next texture
int nextInternalID_;
//vector containing all textures of an object
std::vector< Texture > textures_;
// Get the index of a given texture
int getTextureIndex(QString _textureName);
Texture noTexture;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment