}
- static void bindScriptConstants(Mf::Script& script)
+ static void bindScriptConstants(Script& script)
{
- script.push(GL_CLAMP); script.set("CLAMP");
- script.push(GL_REPEAT); script.set("REPEAT");
- script.push(GL_LINEAR); script.set("LINEAR");
- script.push(GL_NEAREST); script.set("NEAREST");
- script.push(GL_LINEAR_MIPMAP_LINEAR);
- script.set("LINEAR_MIPMAP_LINEAR");
- script.push(GL_LINEAR_MIPMAP_NEAREST);
- script.set("LINEAR_MIPMAP_NEAREST");
- script.push(GL_NEAREST_MIPMAP_LINEAR);
- script.set("NEAREST_MIPMAP_LINEAR");
- script.push(GL_NEAREST_MIPMAP_NEAREST);
- script.set("NEAREST_MIPMAP_NEAREST");
+ Script::Slot g = script.globals();
+
+ g.setField("CLAMP", GL_CLAMP);
+ g.setField("REPEAT", GL_REPEAT);
+ g.setField("LINEAR", GL_LINEAR);
+ g.setField("NEAREST", GL_NEAREST);
+ g.setField("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);
+ g.setField("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
+ g.setField("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
+ g.setField("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
}
public:
mObject(0)
{
// make sure we have a video context
- ASSERT(video &&
- "cannot load textures without a current video context");
+ Video* video = Video::current();
+ ASSERT(video && "should have a video context set");
// we want to know when the GL context is recreated
- mDispatchHandler = core.addHandler("video.newcontext",
- boost::bind(&Impl::contextRecreated, this));
+ Dispatch& dispatch = Dispatch::global();
+ mNewContextDispatch = dispatch.addTarget("video.newcontext",
+ boost::bind(&Impl::contextRecreated, this));
}
~Impl()
void init(const std::string& name)
{
- std::string path = Texture::getPath(name);
+ std::string path(name);
+
+ Texture::getPath(path);
mImage = Image::alloc(path);
if (!mImage->isValid())
mImage->flip();
- Mf::Script script;
+ Script script;
importLogFunctions(script);
bindScriptConstants(script);
- if (script.doString(mImage->getComment()) != Mf::Script::SUCCESS)
+ if (script.doString(mImage->getComment()) != Script::SUCCESS)
{
std::string str;
script[-1].get(str);
- Mf::logWarning(str);
+ logWarning(str);
}
else
{
- Mf::logInfo << "loading tiles from texture " << path
- << std::endl;
-
- Mf::Script::Slot globals = script.getGlobalTable();
- Mf::Script::Slot top = script[-1];
-
- globals.pushField("tiles_s");
- top.get(mTilesS);
-
- globals.pushField("tiles_t");
- top.get(mTilesT);
-
- globals.pushField("min_filter");
- top.get(mMinFilter);
-
- globals.pushField("mag_filter");
- top.get(mMagFilter);
-
- globals.pushField("wrap_s");
- top.get(mWrapS);
-
- globals.pushField("wrap_t");
- top.get(mWrapT);
+ logInfo << "loading tiles from texture " << path
+ << std::endl;
+
+ Script::Slot globals = script.globals();
+ globals.get(mTilesS, "tiles_s");
+ globals.get(mTilesT, "tiles_t");
+ globals.get(mMinFilter, "min_filter");
+ globals.get(mMagFilter, "mag_filter");
+ globals.get(mWrapS, "wrap_s");
+ globals.get(mWrapT, "wrap_t");
}
}
GLuint mObject; ///< GL texture handle.
static GLuint gObject; ///< Global GL texture handle.
- Dispatch::Handler mDispatchHandler;
+ Dispatch::Handle mNewContextDispatch;
};
GLuint Texture::Impl::gObject = 0;
-Texture::Texture(const std::string& name) :
- Image(Texture::getPath(name)),
+Texture::Texture(const std::string& name) : // TODO hmm..
+ Image(name),
// pass through
mImpl(Texture::Impl::getInstance(name)) {}
}
-std::string Texture::getPath(const std::string& name)
+bool Texture::getPath(std::string& name)
{
- if (boost::find_last(name, ".png"))
- {
- return Resource::getPath(name);
- }
- else
- {
- std::string path("textures/");
- path += name;
- path += ".png";
- return Resource::getPath(path);
- }
+ return Resource::getPath(name, "textures/", "png");
}