Skip to content
Permalink
Browse files

close #479

  • Loading branch information...
rtri
rtri committed Oct 13, 2019
1 parent f3ba37a commit 724535d2b5a5a246f9cb70a8f81c83adf63037eb
Showing with 41 additions and 3 deletions.
  1. +38 −3 rts/Lua/LuaOpenGL.cpp
  2. +3 −0 rts/Lua/LuaOpenGL.h
@@ -276,6 +276,7 @@ bool LuaOpenGL::PushEntries(lua_State* L)

REGISTER_LUA_CFUNC(BeginEnd);
REGISTER_LUA_CFUNC(Vertex);
REGISTER_LUA_CFUNC(VertexIndices);
REGISTER_LUA_CFUNC(Normal);
REGISTER_LUA_CFUNC(TexCoord);
REGISTER_LUA_CFUNC(Color);
@@ -331,6 +332,8 @@ bool LuaOpenGL::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(Billboard);
REGISTER_LUA_CFUNC(GetMatrixData);

REGISTER_LUA_CFUNC(GetDrawMode);

REGISTER_LUA_CFUNC(PushAttrib);
REGISTER_LUA_CFUNC(PopAttrib);
REGISTER_LUA_CFUNC(UnsafeState);
@@ -1657,7 +1660,11 @@ int LuaOpenGL::BeginEnd(lua_State* L)
if (callError != 0)
luaL_error(L, "[gl.%s(type, func, ...)] error %d (%s)", __func__, callError, lua_tostring(L, -1));

luaRenderBuffer->Submit(primType);
if (luaRenderBuffer->NumIndcs() > 0)
luaRenderBuffer->SubmitIndexed(primType);
else
luaRenderBuffer->Submit(primType);

luaRenderBuffer = nullptr;
}

@@ -1684,6 +1691,26 @@ int LuaOpenGL::Vertex(lua_State* L)
return 0;
}


int LuaOpenGL::VertexIndices(lua_State* L)
{
CheckDrawingEnabled(L, __func__);

if (luaRenderBuffer == nullptr)
return 0;

if (lua_type(L, 1) != LUA_TTABLE) {
luaL_error(L, "[gl.%s] argument not a table", __func__);
return 0;
}

std::array<int, 4096> indcs;

// luaRenderBuffer->SafeUpdate(reinterpret_cast<uint32_t*>(indcs.data()), LuaUtils::ParseIntArray(L, -1, indcs.data(), indcs.size()), 0);
luaRenderBuffer->SafeAppend(reinterpret_cast<uint32_t*>(indcs.data()), LuaUtils::ParseIntArray(L, -1, indcs.data(), indcs.size()));
return 0;
}

int LuaOpenGL::Normal(lua_State* L)
{
CheckDrawingEnabled(L, __func__);
@@ -2809,15 +2836,15 @@ int LuaOpenGL::UpdateVertexArray(lua_State* L)
} break;

case LUA_TFUNCTION: {
// make gl.Vertex write to the chosen buffer
// make gl.Vertex{Indices} write to the chosen buffer
luaRenderBuffer = &wb;
// rewind; length of sub-region update is determined
// by the number of gl.Vertex calls made in function
luaRenderBuffer->Reset(elemsPos, indcsPos);

{
inBeginEnd = true;
// fill the buffer (TODO: gl.VertexIndex?)
// fill the buffer
const int nFuncArgs = lua_gettop(L) - 4;
const int callError = lua_pcall(L, nFuncArgs, 0, 0);
inBeginEnd = false;
@@ -3203,6 +3230,14 @@ int LuaOpenGL::GetMatrixData(lua_State* L)
return 0;
}


int LuaOpenGL::GetDrawMode(lua_State* L)
{
lua_pushnumber(L, currDrawMode);
lua_pushnumber(L, prevDrawMode);
return 2;
}

/******************************************************************************/

int LuaOpenGL::PushAttrib(lua_State* L)
@@ -203,6 +203,7 @@ class LuaOpenGL {

static int BeginEnd(lua_State* L);
static int Vertex(lua_State* L);
static int VertexIndices(lua_State* L);
static int Normal(lua_State* L);
static int TexCoord(lua_State* L);

@@ -264,6 +265,8 @@ class LuaOpenGL {
static int PushPopMatrix(lua_State* L);
static int GetMatrixData(lua_State* L);

static int GetDrawMode(lua_State* L);

static int PushAttrib(lua_State* L);
static int PopAttrib(lua_State* L);
static int UnsafeState(lua_State* L);

0 comments on commit 724535d

Please sign in to comment.
You can’t perform that action at this time.