diff --git a/src/modules/graphics/vertex.cpp b/src/modules/graphics/vertex.cpp index ea135e0f4..ffc3e448c 100644 --- a/src/modules/graphics/vertex.cpp +++ b/src/modules/graphics/vertex.cpp @@ -337,6 +337,13 @@ const char *getConstant(BuiltinVertexAttribute attrib) return name; } +STRINGMAP_BEGIN(BufferType, BUFFERTYPE_MAX_ENUM, bufferTypeName) +{ + { "vertex", BUFFERTYPE_VERTEX }, + { "index", BUFFERTYPE_INDEX }, +} +STRINGMAP_END(BufferType, BUFFERTYPE_MAX_ENUM, bufferTypeName) + STRINGMAP_BEGIN(IndexDataType, INDEX_MAX_ENUM, indexType) { { "uint16", INDEX_UINT16 }, diff --git a/src/modules/graphics/vertex.h b/src/modules/graphics/vertex.h index 003d4eb9f..5dd74ce47 100644 --- a/src/modules/graphics/vertex.h +++ b/src/modules/graphics/vertex.h @@ -377,6 +377,7 @@ void fillIndices(TriangleIndexMode mode, uint16 vertexStart, uint16 vertexCount, void fillIndices(TriangleIndexMode mode, uint32 vertexStart, uint32 vertexCount, uint32 *indices); STRINGMAP_DECLARE(BuiltinVertexAttribute); +STRINGMAP_DECLARE(BufferType); STRINGMAP_DECLARE(IndexDataType); STRINGMAP_DECLARE(BufferUsage); STRINGMAP_DECLARE(PrimitiveType); diff --git a/src/modules/graphics/wrap_Buffer.cpp b/src/modules/graphics/wrap_Buffer.cpp index 219552258..78813170b 100644 --- a/src/modules/graphics/wrap_Buffer.cpp +++ b/src/modules/graphics/wrap_Buffer.cpp @@ -432,6 +432,24 @@ static int w_Buffer_getFormat(lua_State *L) return 1; } +static int w_Buffer_isBufferType(lua_State *L) +{ + Buffer *t = luax_checkbuffer(L, 1); + BufferType buffertype = BUFFERTYPE_MAX_ENUM; + const char *typestr = luaL_checkstring(L, 2); + if (!getConstant(typestr, buffertype)) + return luax_enumerror(L, "buffer type", getConstants(buffertype), typestr); + luax_pushboolean(L, (t->getTypeFlags() & (1 << buffertype)) != 0); + return 1; +} + +static int w_Buffer_isCPUReadable(lua_State *L) +{ + Buffer *t = luax_checkbuffer(L, 1); + luax_pushboolean(L, (t->getMapFlags() & Buffer::MAP_READ) != 0); + return 1; +} + static const luaL_Reg w_Buffer_functions[] = { { "flush", w_Buffer_flush }, @@ -442,6 +460,8 @@ static const luaL_Reg w_Buffer_functions[] = { "getElementStride", w_Buffer_getElementStride }, { "getSize", w_Buffer_getSize }, { "getFormat", w_Buffer_getFormat }, + { "isBufferType", w_Buffer_isBufferType }, + { "isCPUReadable", w_Buffer_isCPUReadable }, { 0, 0 } }; diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index ec897c9ec..a479411b3 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -1669,10 +1669,16 @@ int w_newBuffer(lua_State *L) Buffer::Settings settings(0, Buffer::MAP_EXPLICIT_RANGE_MODIFY, BUFFERUSAGE_DYNAMIC); luaL_checktype(L, 3, LUA_TTABLE); - if (luax_boolflag(L, 3, "vertex", false)) - settings.typeFlags = (Buffer::TypeFlags)(settings.typeFlags | Buffer::TYPEFLAG_VERTEX); - if (luax_boolflag(L, 3, "index", false)) - settings.typeFlags = (Buffer::TypeFlags)(settings.typeFlags | Buffer::TYPEFLAG_INDEX); + + for (int i = 0; i < BUFFERTYPE_MAX_ENUM; i++) + { + BufferType buffertype = (BufferType) i; + const char *tname = nullptr; + if (!getConstant(buffertype, tname)) + continue; + if (luax_boolflag(L, 3, tname, false)) + settings.typeFlags = (Buffer::TypeFlags)(settings.typeFlags | (1u << i)); + } luax_optbuffersettings(L, 3, settings);