lugre_viewport_L.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_luabind.h"
00003 #include "lugre_ogrewrapper.h"
00004 #include "lugre_rendertexture.h"
00005 #include "lugre_camera.h"
00006 #include "lugre_viewport.h"
00007 #include <Ogre.h>
00008 
00009 extern "C" {
00010     #include "lua.h"
00011     #include "lauxlib.h"
00012     #include "lualib.h"
00013 }
00014 
00015 using namespace Ogre;
00016 
00017 namespace Lugre {
00018     
00019 cViewport::cViewport    (Ogre::Viewport* pViewport) : mpViewport(pViewport) {}
00020 
00021 cViewport::~cViewport() {
00022     // TODO !
00023     if (mpViewport) mpViewport = 0;
00024 }
00025 /*
00026     Viewport *pViewport = mWindow->addViewport(mCamera);
00027     Viewport *pViewPort = rttTex->addViewport( mCamera );
00028 
00029     // viewport   bound to rttTex and mCamera
00030 
00031     pViewPort->setBackgroundColour(ColourValue(0,0,0));
00032     pViewPort->setClearEveryFrame( true );
00033 
00034     TODO : maybe general RenderTarget (window OR rtt) instead of specific RenderTexture
00035 TODO : replace obsolete l_Client_SetBackCol(r,g,b,a) by GetMainViewport():SetBackCol(r,g,b,a)
00036 */
00037 
00038 
00039 class cViewport_L : public cLuaBind<cViewport> { public:
00041         virtual void RegisterMethods    (lua_State *L) { PROFILE
00042             #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cViewport_L::methodname));
00043             REGISTER_METHOD(Destroy);
00044             REGISTER_METHOD(SetOverlaysEnabled);
00045             REGISTER_METHOD(GetActualWidth);
00046             REGISTER_METHOD(GetActualHeight);
00047             REGISTER_METHOD(SetBackCol);
00048             
00049             lua_register(L,"CreateRTTViewport",     &cViewport_L::CreateRTTViewport);
00050             lua_register(L,"GetMainViewport",       &cViewport_L::GetMainViewport);
00051         }
00052 
00053     // object methods exported to lua
00054             
00056         static int      Destroy             (lua_State *L) { PROFILE delete checkudata_alive(L); return 0; }
00057         
00059         static int      SetOverlaysEnabled  (lua_State *L) { PROFILE 
00060             checkudata_alive(L)->mpViewport->setOverlaysEnabled(luaL_checkbool(L,2)); 
00061             return 0; 
00062         }
00063         
00064         static int      GetActualWidth (lua_State *L) { PROFILE
00065             Ogre::Viewport* pViewport = checkudata_alive(L)->mpViewport;
00066             if (!pViewport) return 0;
00067             lua_pushnumber(L,pViewport->getActualWidth());
00068             return 1;
00069         }
00070         
00071         static int      GetActualHeight (lua_State *L) { PROFILE
00072             Ogre::Viewport* pViewport = checkudata_alive(L)->mpViewport;
00073             if (!pViewport) return 0;
00074             lua_pushnumber(L,pViewport->getActualHeight());
00075             return 1;
00076         }
00077                 
00078         
00080         static int      SetBackCol      (lua_State *L) { PROFILE
00081             Ogre::Viewport* pViewport = checkudata_alive(L)->mpViewport;
00082             if (!pViewport) return 0;
00083             int numargs=lua_gettop(L);
00084             Ogre::Real r            = (numargs >= 2 && !lua_isnil(L,2)) ? luaL_checknumber(L,2) : 0;
00085             Ogre::Real g            = (numargs >= 3 && !lua_isnil(L,3)) ? luaL_checknumber(L,3) : 0;
00086             Ogre::Real b            = (numargs >= 4 && !lua_isnil(L,4)) ? luaL_checknumber(L,4) : 0;
00087             Ogre::Real a            = (numargs >= 5 && !lua_isnil(L,5)) ? luaL_checknumber(L,5) : 0;
00088             pViewport->setBackgroundColour(Ogre::ColourValue(r,g,b,a));
00089             return 0;
00090         }
00091         
00092         // todo : setClearEveryFrame setOverlaysEnabled
00093         
00094     // static methods exported to lua
00095 
00096         
00098         static int      GetMainViewport (lua_State *L) { PROFILE
00099             static cViewport* pMainViewport = 0;
00100             if (!pMainViewport) pMainViewport = new cViewport(cOgreWrapper::GetSingleton().mViewport);
00101             return CreateUData(L,pMainViewport);
00102         }
00103         
00105         static int      CreateRTTViewport   (lua_State *L) { PROFILE
00106             Ogre::RenderTarget* pRenderTarget   = cLuaBind<cRenderTexture>::checkudata_alive(L,1)->mpRenderTarget;
00107             Ogre::Camera*           pCamera         = cLuaBind<cCamera>::checkudata_alive(L,2)->mpCam;
00108             assert(pRenderTarget);
00109             assert(pCamera);
00110             Ogre::Viewport*         pViewPort = pRenderTarget->addViewport(pCamera);
00111             cViewport* target = pViewPort ? new cViewport(pViewPort) : 0;
00112             return CreateUData(L,target);
00113         }
00114         
00115         virtual const char* GetLuaTypeName () { return "lugre.Viewport"; }
00116 };
00117 
00119 void    cViewport::LuaRegister  (lua_State *L) { PROFILE
00120     cLuaBind<cViewport>::GetSingletonPtr(new cViewport_L())->LuaRegister(L);
00121 }
00122 
00123 };

Generated on Wed May 23 06:00:15 2012 for cpp by  doxygen 1.5.6