class Tilemap::TilemapImpl : public Mippleton<TilemapImpl>
{
+ static GLint filterFromString(const std::string& filter)
+ {
+ if (filter == "linear")
+ {
+ return GL_LINEAR;
+ }
+ else if (filter == "nearest_mipmap_nearest")
+ {
+ return GL_NEAREST_MIPMAP_NEAREST;
+ }
+ else if (filter == "nearest_mipmap_linear")
+ {
+ return GL_NEAREST_MIPMAP_LINEAR;
+ }
+ else if (filter == "linear_mipmap_nearest")
+ {
+ return GL_LINEAR_MIPMAP_NEAREST;
+ }
+ else if (filter == "linear_mipmap_linear")
+ {
+ return GL_LINEAR_MIPMAP_LINEAR;
+ }
+
+ return GL_NEAREST;
+ }
+
+ static GLint wrapFromString(const std::string& wrap)
+ {
+ if (wrap == "repeat")
+ {
+ return GL_REPEAT;
+ }
+
+ return GL_CLAMP;
+ }
+
public:
TilemapImpl(const std::string& name) :
Mippleton<TilemapImpl>(name),
- tilesU_(1),
- tilesV_(1),
+ magFilter_(GL_NEAREST),
minFilter_(GL_NEAREST),
- maxFilter_(GL_NEAREST),
- wrapU_(GL_CLAMP),
- wrapV_(GL_CLAMP)
+ nTilesS_(1),
+ nTilesT_(1),
+ wrapS_(GL_CLAMP),
+ wrapT_(GL_CLAMP)
{
loadFromFile();
}
{
std::map<std::string,SerializablePtr>::iterator it;
- if ((it = rootObj.find("TilesU")) != rootObj.end())
+ if ((it = rootObj.find("tiles_s")) != rootObj.end())
{
long value;
if ((*it).second->get(value))
{
- tilesU_ = unsigned(value);
+ nTilesS_ = unsigned(value);
}
}
- if ((it = rootObj.find("TilesV")) != rootObj.end())
+ if ((it = rootObj.find("tiles_t")) != rootObj.end())
{
long value;
if ((*it).second->get(value))
{
- tilesV_ = unsigned(value);
+ nTilesT_ = unsigned(value);
}
}
- if ((it = rootObj.find("MinFilter")) != rootObj.end())
+ if ((it = rootObj.find("min_filter")) != rootObj.end())
{
std::string value;
if ((*it).second->get(value))
{
- if (value == "Linear")
- {
- minFilter_ = GL_LINEAR;
- }
+ minFilter_ = filterFromString(value);
}
}
- if ((it = rootObj.find("MaxFilter")) != rootObj.end())
+ if ((it = rootObj.find("mag_filter")) != rootObj.end())
{
std::string value;
if ((*it).second->get(value))
{
- if (value == "Linear")
- {
- maxFilter_ = GL_LINEAR;
- }
+ magFilter_ = filterFromString(value);
}
}
- if ((it = rootObj.find("WrapU")) != rootObj.end())
+ if ((it = rootObj.find("wrap_s")) != rootObj.end())
{
std::string value;
if ((*it).second->get(value))
{
- if (value == "Repeat")
- {
- wrapU_ = GL_REPEAT;
- }
+ wrapS_ = wrapFromString(value);
}
}
- if ((it = rootObj.find("WrapV")) != rootObj.end())
+ if ((it = rootObj.find("wrap_t")) != rootObj.end())
{
std::string value;
if ((*it).second->get(value))
{
- if (value == "Repeat")
- {
- wrapV_ = GL_REPEAT;
- }
+ wrapT_ = wrapFromString(value);
}
}
}
}
}
- unsigned tilesU_;
- unsigned tilesV_;
+ GLuint magFilter_;
GLuint minFilter_;
- GLuint maxFilter_;
- GLuint wrapU_;
- GLuint wrapV_;
+ unsigned nTilesS_;
+ unsigned nTilesT_;
+ GLuint wrapS_;
+ GLuint wrapT_;
};
Texture(name),
impl_(Tilemap::TilemapImpl::retain(name), &Tilemap::TilemapImpl::release)
{
+ bind();
+
setMinFilter(impl_->minFilter_);
- setMaxFilter(impl_->maxFilter_);
- setWrapU(impl_->wrapU_);
- setWrapV(impl_->wrapV_);
- applyChanges();
+ setMagFilter(impl_->magFilter_);
+ setWrapS(impl_->wrapS_);
+ setWrapT(impl_->wrapT_);
}
-bool Tilemap::getTileCoords(unsigned index, Scalar coords[8])
+bool Tilemap::getTileCoords(unsigned index, Scalar coords[8]) const
{
// make sure the index represents a real tile
- if (index >= impl_->tilesU_ * impl_->tilesV_) return false;
+ if (index >= impl_->nTilesS_ * impl_->nTilesT_) return false;
- Scalar w = 1.0 / Scalar(impl_->tilesU_);
- Scalar h = 1.0 / Scalar(impl_->tilesV_);
+ Scalar w = 1.0 / Scalar(impl_->nTilesS_);
+ Scalar h = 1.0 / Scalar(impl_->nTilesT_);
- coords[0] = Scalar(index % impl_->tilesU_) * w;
- coords[1] = (Scalar(impl_->tilesV_ - 1) -
- Scalar(index / impl_->tilesU_)) * h;
+ coords[0] = Scalar(index % impl_->nTilesS_) * w;
+ coords[1] = (Scalar(impl_->nTilesT_ - 1) -
+ Scalar(index / impl_->nTilesS_)) * h;
coords[2] = coords[0] + w;
coords[3] = coords[1];
coords[4] = coords[2];
}
bool Tilemap::getTileCoords(unsigned index, Scalar coords[8],
- Orientation orientation)
+ Orientation orientation) const
{
if (getTileCoords(index, coords))
{