1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef LUA_OBJECT_RENDERING_H
#define LUA_OBJECT_RENDERING_H
// for LuaObjType
#include "LuaObjectMaterial.h"
struct lua_State;
template<LuaObjType T> class LuaObjectRendering;
class LuaObjectRenderingImpl {
#if __GNUC__ == 11
public:
#else
private:
friend class LuaObjectRendering<LUAOBJ_UNIT>;
friend class LuaObjectRendering<LUAOBJ_FEATURE>;
#endif
static void CreateMatRefMetatable(lua_State* L);
static void PushFunction(lua_State* L, int (*fnPntr)(lua_State*), const char* fnName);
static void PushObjectType(LuaObjType type) { objectTypeStack.push_back(type); }
static void PopObjectType() { objectTypeStack.pop_back(); }
static LuaObjType GetObjectType() {
if (!objectTypeStack.empty())
return (objectTypeStack.back());
return LUAOBJ_LAST;
}
static int GetLODCount(lua_State* L);
static int SetLODCount(lua_State* L);
static int SetLODLength(lua_State* L);
static int SetLODDistance(lua_State* L);
static int SetPieceList(lua_State* L) { return 0; }
static int GetMaterial(lua_State* L);
static int SetMaterial(lua_State* L);
static int SetMaterialLastLOD(lua_State* L);
static int SetMaterialDisplayLists(lua_State* L) { return 0; }
static int SetDeferredMaterialUniform(lua_State* L);
static int SetForwardMaterialUniform(lua_State* L);
static int ClearDeferredMaterialUniform(lua_State* L);
static int ClearForwardMaterialUniform(lua_State* L);
static int SetUnitLuaDraw(lua_State* L);
static int SetFeatureLuaDraw(lua_State* L);
static int SetProjectileLuaDraw(lua_State* L);
static int Debug(lua_State* L);
private:
static std::vector<LuaObjType> objectTypeStack;
};
template<LuaObjType T> class LuaObjectRendering {
public:
static bool PushEntries(lua_State* L) {
LuaObjectRenderingImpl::CreateMatRefMetatable(L);
// register our wrapper functions so the implementations know
// the proper LuaObjType value for their corresponding tables
#define PUSH_FUNCTION(x) LuaObjectRenderingImpl::PushFunction(L, x, #x)
PUSH_FUNCTION(GetLODCount);
PUSH_FUNCTION(SetLODCount);
PUSH_FUNCTION(SetLODLength);
PUSH_FUNCTION(SetLODDistance);
PUSH_FUNCTION(GetMaterial);
PUSH_FUNCTION(SetMaterial);
PUSH_FUNCTION(SetMaterialLastLOD);
PUSH_FUNCTION(SetMaterialDisplayLists);
PUSH_FUNCTION(SetDeferredMaterialUniform);
PUSH_FUNCTION(SetForwardMaterialUniform);
PUSH_FUNCTION(ClearDeferredMaterialUniform);
PUSH_FUNCTION(ClearForwardMaterialUniform);
PUSH_FUNCTION(SetPieceList);
PUSH_FUNCTION(SetUnitLuaDraw);
PUSH_FUNCTION(SetFeatureLuaDraw);
PUSH_FUNCTION(SetProjectileLuaDraw);
PUSH_FUNCTION(Debug);
#undef PUSH_FUNCTION
return true;
}
private:
static int GetLODCount(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::GetLODCount(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetLODCount(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetLODCount(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetLODLength(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetLODLength(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetLODDistance(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetLODDistance(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetPieceList(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetPieceList(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int GetMaterial(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::GetMaterial(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetMaterial(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetMaterial(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetMaterialLastLOD(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetMaterialLastLOD(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetMaterialDisplayLists(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetMaterialDisplayLists(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetDeferredMaterialUniform(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetDeferredMaterialUniform(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetForwardMaterialUniform(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::SetForwardMaterialUniform(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int ClearDeferredMaterialUniform(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::ClearDeferredMaterialUniform(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int ClearForwardMaterialUniform(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::ClearForwardMaterialUniform(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
static int SetUnitLuaDraw(lua_State* L) {
if (T != LUAOBJ_UNIT)
return 0;
return (LuaObjectRenderingImpl::SetUnitLuaDraw(L));
}
static int SetFeatureLuaDraw(lua_State* L) {
if (T != LUAOBJ_FEATURE)
return 0;
return (LuaObjectRenderingImpl::SetFeatureLuaDraw(L));
}
// NB: value of T is not relevant here, slightly foreign callout
static int SetProjectileLuaDraw(lua_State* L) {
return (LuaObjectRenderingImpl::SetProjectileLuaDraw(L));
}
static int Debug(lua_State* L) {
LuaObjectRenderingImpl::PushObjectType(T);
const int ret = LuaObjectRenderingImpl::Debug(L);
LuaObjectRenderingImpl::PopObjectType();
return ret;
}
};
#endif /* LUA_OBJECT_RENDERING_H */
|