diff --git a/SDK/include/NDK/LuaAPI.hpp b/SDK/include/NDK/LuaAPI.hpp index f248e28e8..8965229e2 100644 --- a/SDK/include/NDK/LuaAPI.hpp +++ b/SDK/include/NDK/LuaAPI.hpp @@ -25,6 +25,9 @@ namespace Ndk static void Register_Audio(Nz::LuaInstance& instance); static void Register_Core(Nz::LuaInstance& instance); static void Register_Math(Nz::LuaInstance& instance); + static void Register_Utility(Nz::LuaInstance& instance); + static void Register_Graphics(Nz::LuaInstance& instance); + static void Register_Renderer(Nz::LuaInstance& instance); }; } diff --git a/SDK/src/NDK/LuaAPI_Graphics.cpp b/SDK/src/NDK/LuaAPI_Graphics.cpp new file mode 100644 index 000000000..685e64cb5 --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Graphics.cpp @@ -0,0 +1,15 @@ +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Graphics(Nz::LuaInstance& instance) + { + + } +} \ No newline at end of file diff --git a/SDK/src/NDK/LuaAPI_Renderer.cpp b/SDK/src/NDK/LuaAPI_Renderer.cpp new file mode 100644 index 000000000..e61d10af1 --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Renderer.cpp @@ -0,0 +1,147 @@ +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Renderer(Nz::LuaInstance& instance) + { + /*********************************** Nz::AbstractImage **********************************/ + Nz::LuaClass abstractImage("AbstractImage"); + + abstractImage.SetMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel); + abstractImage.SetMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast(0)); + abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat); + abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast(0)); + abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount); + abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel); + /*abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast(0));*/ // Need to add Nz::Vector3ui to auto binding mecanism, or do it by hand + abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType); + abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast(0)); + abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); + abstractImage.SetMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); + + abstractImage.SetMethod("GetMemoryUsage", + [](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + { + unsigned int memory = 0; + + unsigned int argCount = std::min(lua.GetStackTop(), 2U); + if (argCount == 1 && lua.IsOfType(1, Nz::LuaType_Number)) + memory = abstractImage->GetMemoryUsage(static_cast(lua.CheckInteger(1))); // Maybe do a range check instead of casting like a savage? + else + memory = abstractImage->GetMemoryUsage(); + + lua.PushInteger(memory); + return 1; + }); + + abstractImage.SetMethod("__tostring", + [](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + { + lua.PushString(Nz::StringStream("AbstractImage()")); + return 1; + }); + + abstractImage.SetMethod("Update", + [](Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + { + unsigned int argCount = std::min(lua.GetStackTop(), 2U); + + if (argCount < 1) + { + lua.Error("No matching overload for method AbstractImage::Update"); + return 0; + } + + bool rValue; + const Nz::UInt8* pixels = reinterpret_cast(lua.CheckString(1)); + + if (argCount == 1) + rValue = abstractImage->Update(pixels); + else + { + // Three possible overloads, based on second argument type + if (lua.IsOfType(2, Nz::LuaType_Number)) // Overload #1 + { + /* Prototype is: + virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) + */ + + unsigned int srcWidth = static_cast(lua.CheckInteger(2)); // Range check? + unsigned int srcHeight = 0; + Nz::UInt8 level = 0; + + if (argCount >= 3) + { + srcHeight = static_cast(lua.CheckInteger(3)); // Range check? + if (argCount >= 4) + level = static_cast(lua.CheckInteger(3)); // Range check? + } + + rValue = abstractImage->Update(pixels, srcWidth, srcHeight, level); + } + else if (lua.IsOfType(2, "Box")) // Overload #2 + { + /* Prototype is: + virtual bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) + */ + + Nz::Boxui box (*(static_cast(lua.ToUserdata(2)))); // Placeholder. Ask Lynix about templates & bindings. Nz::Box has to be bound, too. + unsigned int srcWidth = 0; + unsigned int srcHeight = 0; + Nz::UInt8 level = 0; + + if (argCount >= 3) + { + srcWidth = static_cast(lua.CheckInteger(3)); // Range check? + if (argCount >= 4) + { + srcHeight = static_cast(lua.CheckInteger(4)); // Range check? + if (argCount >= 5) + level = static_cast(lua.CheckInteger(5)); // Range check? + } + } + rValue = abstractImage->Update(pixels, box, srcWidth, srcHeight, level); + } + else if (lua.IsOfType(2, "Rect")) // Overload #3 + { + /* Prototype is: + virtual bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) + */ + + Nz::Rectui rect(*(static_cast(lua.ToUserdata(2)))); // Placeholder. See comment at box declaration in overload #2 + unsigned int z = 0; + unsigned int srcWidth = 0; + unsigned int srcHeight = 0; + Nz::UInt8 level = 0; + + if (argCount >= 3) + { + z = static_cast(lua.CheckInteger(3)); // Range check? + if (argCount >= 4) + { + srcWidth = static_cast(lua.CheckInteger(4)); // Range check? + if (argCount >= 5) + { + srcHeight = static_cast(lua.CheckInteger(5)); // Range check? + if (argCount >= 6) + level = static_cast(lua.CheckInteger(6)); // Range check? + } + } + } + rValue = abstractImage->Update(pixels, rect, z, srcWidth, srcHeight, level); + } + } + + lua.PushBoolean(rValue); + return 1; + }); + + abstractImage.Register(instance); + } +} \ No newline at end of file diff --git a/SDK/src/NDK/LuaAPI_Utility.cpp b/SDK/src/NDK/LuaAPI_Utility.cpp new file mode 100644 index 000000000..0f6bfb1cd --- /dev/null +++ b/SDK/src/NDK/LuaAPI_Utility.cpp @@ -0,0 +1,14 @@ +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + + +#include +#include +#include + +namespace Ndk +{ + void LuaAPI::Register_Utility(Nz::LuaInstance& instance) + { + } +} \ No newline at end of file