Skip to content

Commit

Permalink
Fix non-stream buffers uploading redundant data when a sub-range is m…
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Dec 28, 2021
1 parent cee8f8a commit cf0a45f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions src/modules/graphics/opengl/Buffer.cpp
Expand Up @@ -39,8 +39,8 @@ Buffer::Buffer(size_t size, const void *data, BufferType type, vertex::Usage usa
: love::graphics::Buffer(size, type, usage, mapflags)
, vbo(0)
, memory_map(nullptr)
, modified_offset(0)
, modified_size(0)
, modified_start(std::numeric_limits<size_t>::max())
, modified_end(0)
{
target = OpenGL::getGLBufferType(type);

Expand Down Expand Up @@ -78,8 +78,8 @@ void *Buffer::map()

is_mapped = true;

modified_offset = 0;
modified_size = 0;
modified_start = std::numeric_limits<size_t>::max();
modified_end = 0;

return memory_map;
}
Expand Down Expand Up @@ -119,21 +119,25 @@ void Buffer::unmap()

if ((map_flags & MAP_EXPLICIT_RANGE_MODIFY) != 0)
{
modified_offset = std::min(modified_offset, getSize() - 1);
modified_size = std::min(modified_size, getSize() - modified_offset);
if (modified_end >= modified_start)
{
modified_start = std::min(modified_start, getSize() - 1);
modified_end = std::min(modified_end, getSize() - 1);
}
}
else
{
modified_offset = 0;
modified_size = getSize();
modified_start = 0;
modified_end = getSize() - 1;
}

if (modified_size > 0)
if (modified_end >= modified_start)
{
size_t modified_size = (modified_end - modified_start) + 1;
switch (getUsage())
{
case vertex::USAGE_STATIC:
unmapStatic(modified_offset, modified_size);
unmapStatic(modified_start, modified_size);
break;
case vertex::USAGE_STREAM:
unmapStream();
Expand All @@ -145,13 +149,13 @@ void Buffer::unmap()
if (modified_size >= getSize() / 3)
unmapStream();
else
unmapStatic(modified_offset, modified_size);
unmapStatic(modified_start, modified_size);
break;
}
}

modified_offset = 0;
modified_size = 0;
modified_start = std::numeric_limits<size_t>::max();
modified_end = 0;

is_mapped = false;
}
Expand All @@ -164,12 +168,8 @@ void Buffer::setMappedRangeModified(size_t offset, size_t modifiedsize)
// We're being conservative right now by internally marking the whole range
// from the start of section a to the end of section b as modified if both
// a and b are marked as modified.

size_t old_range_end = modified_offset + modified_size;
modified_offset = std::min(modified_offset, offset);

size_t new_range_end = std::max(offset + modifiedsize, old_range_end);
modified_size = new_range_end - modified_offset;
modified_start = std::min(modified_start, offset);
modified_end = std::max(modified_end, offset + modifiedsize - 1);
}

void Buffer::fill(size_t offset, size_t size, const void *data)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/graphics/opengl/Buffer.h
Expand Up @@ -70,8 +70,8 @@ class Buffer final : public love::graphics::Buffer, public Volatile
// A pointer to mapped memory.
char *memory_map;

size_t modified_offset;
size_t modified_size;
size_t modified_start;
size_t modified_end;

}; // Buffer

Expand Down

0 comments on commit cf0a45f

Please sign in to comment.