]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Tilemap.cc
fixed up video and texture handling
[chaz/yoink] / src / Moof / Tilemap.cc
index 6accbd167d3b3fc638cf0443ee1facd59fb84fdd..1bfbfbcb9796e9b257970070b6243f2299a3b5eb 100644 (file)
@@ -38,15 +38,51 @@ namespace Mf {
 
 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();
        }
@@ -65,76 +101,64 @@ public:
                        {
                                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_;
 };
 
 
@@ -142,25 +166,26 @@ Tilemap::Tilemap(const std::string& name) :
        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])
 {
        // 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];
This page took 0.02443 seconds and 4 git commands to generate.