Add love.graphics.getQuadIndexBuffer.

love's pre-generated quad index buffer is useful when combined with drawShaderVertices. Note that it uses 16 bit indices so it can only draw up to 16k quads in a single call.
This commit is contained in:
Alex Szpakowski
2022-01-03 16:22:08 -04:00
parent 42e8df1489
commit ecbc5ca7f6
6 changed files with 25 additions and 2 deletions
+1
View File
@@ -36,6 +36,7 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
, usageFlags(settings.usageFlags)
, dataUsage(settings.dataUsage)
, mapped(false)
, immutable(false)
{
if (size == 0 && arraylength == 0)
throw love::Exception("Size or array length must be specified.");
+5
View File
@@ -111,6 +111,9 @@ public:
size_t getMemberOffset(int index) const { return dataMembers[index].offset; }
int getDataMemberIndex(const std::string &name) const;
void setImmutable(bool immutable) { this->immutable = immutable; };
bool isImmutable() const { return immutable; }
/**
* Map a portion of the Buffer to client memory.
*/
@@ -176,6 +179,8 @@ protected:
BufferDataUsage dataUsage;
bool mapped;
bool immutable;
}; // Buffer
+8
View File
@@ -182,6 +182,8 @@ void Graphics::createQuadIndexBuffer()
Buffer::Mapper map(*quadIndexBuffer);
fillIndices(TRIANGLEINDEX_QUADS, 0, LOVE_UINT16_MAX, (uint16 *) map.data);
quadIndexBuffer->setImmutable(true);
}
Quad *Graphics::newQuad(Quad::Viewport v, double sw, double sh)
@@ -1073,6 +1075,9 @@ void Graphics::copyBuffer(Buffer *source, Buffer *dest, size_t sourceoffset, siz
if (source == dest && sourcerange.intersects(destrange))
throw love::Exception("Copying a portion of a buffer to the same buffer requires non-overlapping source and destination offsets.");
if (dest->isImmutable())
throw love::Exception("Cannot copy to an immutable buffer.");
source->copyTo(dest, sourceoffset, destoffset, size);
}
@@ -1098,6 +1103,9 @@ void Graphics::copyTextureToBuffer(Texture *source, Buffer *dest, int slice, int
if (dest->getDataUsage() == BUFFERDATAUSAGE_STREAM)
throw love::Exception("Buffers created with 'stream' data usage cannot be used as a copy destination.");
if (dest->isImmutable())
throw love::Exception("Cannot copy to an immutable buffer.");
if (isRenderTargetActive(source))
throw love::Exception("copyTextureToBuffer cannot be called while the Texture is an active render target.");
+2
View File
@@ -519,6 +519,8 @@ public:
virtual int getRequestedBackbufferMSAA() const = 0;
virtual int getBackbufferMSAA() const = 0;
Buffer *getQuadIndexBuffer() const { return quadIndexBuffer; }
/**
* Sets the current constant color.
**/
+2 -2
View File
@@ -166,7 +166,7 @@ bool Buffer::supportsOrphan() const
void *Buffer::map(MapType /*map*/, size_t offset, size_t size)
{
if (size == 0)
if (size == 0 || isImmutable())
return nullptr;
Range r(offset, size);
@@ -229,7 +229,7 @@ void Buffer::unmap(size_t usedoffset, size_t usedsize)
void Buffer::fill(size_t offset, size_t size, const void *data)
{
if (size == 0)
if (size == 0 || isImmutable())
return;
size_t buffersize = getSize();
+7
View File
@@ -242,6 +242,12 @@ int w_getDPIScale(lua_State *L)
return 1;
}
int w_getQuadIndexBuffer(lua_State *L)
{
luax_pushtype(L, instance()->getQuadIndexBuffer());
return 1;
}
static Graphics::RenderTarget checkRenderTarget(lua_State *L, int idx)
{
lua_rawgeti(L, idx, 1);
@@ -3671,6 +3677,7 @@ static const luaL_Reg functions[] =
{ "getPixelHeight", w_getPixelHeight },
{ "getPixelDimensions", w_getPixelDimensions },
{ "getDPIScale", w_getDPIScale },
{ "getQuadIndexBuffer", w_getQuadIndexBuffer },
{ "setScissor", w_setScissor },
{ "intersectScissor", w_intersectScissor },