mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Add Buffer:isBufferType and Buffer:isCPUReadable.
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 }
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user