Просмотр исходного кода

Added MaterialParameter::getSampler() and updated lua bindings.

Darryl Gough 13 лет назад
Родитель
Сommit
ec3b3dfcd8

+ 7 - 0
gameplay/src/MaterialParameter.cpp

@@ -68,6 +68,13 @@ const char* MaterialParameter::getName() const
     return _name.c_str();
 }
 
+Texture::Sampler* MaterialParameter::getSampler() const
+{
+    if (_type == MaterialParameter::SAMPLER)
+        return const_cast<Texture::Sampler*>(_value.samplerValue);
+    return NULL;
+}
+
 void MaterialParameter::setValue(float value)
 {
     clearValue();

+ 7 - 0
gameplay/src/MaterialParameter.h

@@ -44,6 +44,13 @@ public:
      */
     const char* getName() const;
 
+    /**
+     * Returns the texture sampler or NULL if this MaterialParameter is not a sampler type.
+     * 
+     * @return The texture sampler or NULL if this MaterialParameter is not a sampler type.
+     */
+    Texture::Sampler* getSampler() const;
+
     /**
      * Sets the value of this parameter to a float value.
      */

+ 38 - 0
gameplay/src/lua/lua_Game.cpp

@@ -36,6 +36,7 @@ void luaRegister_Game()
         {"getAIController", lua_Game_getAIController},
         {"getAccelerometerValues", lua_Game_getAccelerometerValues},
         {"getAnimationController", lua_Game_getAnimationController},
+        {"getAspectRatio", lua_Game_getAspectRatio},
         {"getAudioController", lua_Game_getAudioController},
         {"getAudioListener", lua_Game_getAudioListener},
         {"getConfig", lua_Game_getConfig},
@@ -728,6 +729,43 @@ int lua_Game_getAnimationController(lua_State* state)
     return 0;
 }
 
+int lua_Game_getAspectRatio(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                Game* instance = getInstance(state);
+                float result = instance->getAspectRatio();
+
+                // Push the return value onto the stack.
+                lua_pushnumber(state, result);
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "lua_Game_getAspectRatio - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Game_getAudioController(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 0
gameplay/src/lua/lua_Game.h

@@ -19,6 +19,7 @@ int lua_Game_gestureTapEvent(lua_State* state);
 int lua_Game_getAIController(lua_State* state);
 int lua_Game_getAccelerometerValues(lua_State* state);
 int lua_Game_getAnimationController(lua_State* state);
+int lua_Game_getAspectRatio(lua_State* state);
 int lua_Game_getAudioController(lua_State* state);
 int lua_Game_getAudioListener(lua_State* state);
 int lua_Game_getConfig(lua_State* state);

+ 47 - 0
gameplay/src/lua/lua_MaterialParameter.cpp

@@ -28,6 +28,7 @@ void luaRegister_MaterialParameter()
         {"getAnimationPropertyValue", lua_MaterialParameter_getAnimationPropertyValue},
         {"getName", lua_MaterialParameter_getName},
         {"getRefCount", lua_MaterialParameter_getRefCount},
+        {"getSampler", lua_MaterialParameter_getSampler},
         {"release", lua_MaterialParameter_release},
         {"setAnimationPropertyValue", lua_MaterialParameter_setAnimationPropertyValue},
         {"setValue", lua_MaterialParameter_setValue},
@@ -788,6 +789,52 @@ int lua_MaterialParameter_getRefCount(lua_State* state)
     return 0;
 }
 
+int lua_MaterialParameter_getSampler(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                MaterialParameter* instance = getInstance(state);
+                void* returnPtr = (void*)instance->getSampler();
+                if (returnPtr)
+                {
+                    ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "TextureSampler");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+            else
+            {
+                lua_pushstring(state, "lua_MaterialParameter_getSampler - Failed to match the given parameters to a valid function signature.");
+                lua_error(state);
+            }
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_MaterialParameter_release(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 0
gameplay/src/lua/lua_MaterialParameter.h

@@ -17,6 +17,7 @@ int lua_MaterialParameter_getAnimationPropertyComponentCount(lua_State* state);
 int lua_MaterialParameter_getAnimationPropertyValue(lua_State* state);
 int lua_MaterialParameter_getName(lua_State* state);
 int lua_MaterialParameter_getRefCount(lua_State* state);
+int lua_MaterialParameter_getSampler(lua_State* state);
 int lua_MaterialParameter_release(lua_State* state);
 int lua_MaterialParameter_setAnimationPropertyValue(lua_State* state);
 int lua_MaterialParameter_setValue(lua_State* state);