mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add buffer stats to love.graphics.getStats.
- Add 'buffers' field, to count the total number of graphics buffer objects. - Add 'buffermemory' field, to estimate the total number of bytes of graphics memory used by all buffers.
This commit is contained in:
@@ -29,6 +29,9 @@ namespace graphics
|
||||
|
||||
love::Type Buffer::type("GraphicsBuffer", &Object::type);
|
||||
|
||||
int Buffer::bufferCount = 0;
|
||||
int64 Buffer::totalGraphicsMemory = 0;
|
||||
|
||||
Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &bufferformat, size_t size, size_t arraylength)
|
||||
: arrayLength(0)
|
||||
, arrayStride(0)
|
||||
@@ -240,10 +243,15 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
|
||||
if (texelbuffer && arraylength * dataMembers.size() > caps.limits[Graphics::LIMIT_TEXEL_BUFFER_SIZE])
|
||||
throw love::Exception("Cannot create texel buffer: total number of values in the buffer (%d * %d) is too large for this system (maximum %d).",
|
||||
(int) dataMembers.size(), (int) arraylength, caps.limits[Graphics::LIMIT_TEXEL_BUFFER_SIZE]);
|
||||
|
||||
++bufferCount;
|
||||
totalGraphicsMemory += size;
|
||||
}
|
||||
|
||||
Buffer::~Buffer()
|
||||
{
|
||||
totalGraphicsMemory -= size;
|
||||
--bufferCount;
|
||||
}
|
||||
|
||||
int Buffer::getDataMemberIndex(const std::string &name) const
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
|
||||
static love::Type type;
|
||||
|
||||
static int bufferCount;
|
||||
static int64 totalGraphicsMemory;
|
||||
|
||||
static const size_t SHADER_STORAGE_BUFFER_MAX_STRIDE = 2048;
|
||||
|
||||
enum MapType
|
||||
|
||||
@@ -2422,8 +2422,10 @@ Graphics::Stats Graphics::getStats() const
|
||||
stats.drawCallsBatched = drawCallsBatched;
|
||||
stats.textures = Texture::textureCount;
|
||||
stats.fonts = Font::fontCount;
|
||||
stats.buffers = Buffer::bufferCount;
|
||||
stats.textureMemory = Texture::totalGraphicsMemory;
|
||||
|
||||
stats.bufferMemory = Buffer::totalGraphicsMemory;
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,9 @@ public:
|
||||
int shaderSwitches;
|
||||
int textures;
|
||||
int fonts;
|
||||
int buffers;
|
||||
int64 textureMemory;
|
||||
int64 bufferMemory;
|
||||
};
|
||||
|
||||
struct DrawCommand
|
||||
|
||||
@@ -3005,9 +3005,15 @@ int w_getStats(lua_State *L)
|
||||
lua_pushinteger(L, stats.fonts);
|
||||
lua_setfield(L, -2, "fonts");
|
||||
|
||||
lua_pushinteger(L, stats.textureMemory);
|
||||
lua_pushinteger(L, stats.buffers);
|
||||
lua_setfield(L, -2, "buffers");
|
||||
|
||||
lua_pushnumber(L, (lua_Number) stats.textureMemory);
|
||||
lua_setfield(L, -2, "texturememory");
|
||||
|
||||
lua_pushnumber(L, (lua_Number) stats.bufferMemory);
|
||||
lua_setfield(L, -2, "buffermemory");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user