diff --git a/src/modules/graphics/Buffer.cpp b/src/modules/graphics/Buffer.cpp index 8a4d61c38..0cad4de76 100644 --- a/src/modules/graphics/Buffer.cpp +++ b/src/modules/graphics/Buffer.cpp @@ -36,6 +36,7 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vectorimmutable = 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 diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 397e31531..1dac23eee 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -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."); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 37cba9344..9d0114c0b 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -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. **/ diff --git a/src/modules/graphics/opengl/Buffer.cpp b/src/modules/graphics/opengl/Buffer.cpp index 1c7b577d0..4addac731 100644 --- a/src/modules/graphics/opengl/Buffer.cpp +++ b/src/modules/graphics/opengl/Buffer.cpp @@ -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(); diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index c18be9940..5b3f65ab5 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -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 },