Track the buffer's mapped section

This commit is contained in:
Chris Robinson 2018-01-23 10:51:23 -08:00
parent 4f9a0460c4
commit 9ee58fd454
2 changed files with 10 additions and 3 deletions

View File

@ -90,6 +90,8 @@ typedef struct ALbuffer {
ATOMIC(ALsizei) PackAlign;
ALbitfieldSOFT MappedAccess;
ALsizei MappedOffset;
ALsizei MappedSize;
/* Number of times buffer was attached to a source (deletion can only occur when 0) */
RefCount ref;

View File

@ -244,6 +244,8 @@ AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei
retval = (ALbyte*)albuf->data + offset;
albuf->MappedAccess = access;
albuf->MappedOffset = offset;
albuf->MappedSize = length;
unlock_done:
WriteUnlock(&albuf->lock);
@ -273,7 +275,11 @@ AL_API void AL_APIENTRY alUnmapBufferSOFT(ALuint buffer)
if(albuf->MappedAccess == 0)
alSetError(context, AL_INVALID_OPERATION);
else
{
albuf->MappedAccess = 0;
albuf->MappedOffset = 0;
albuf->MappedSize = 0;
}
WriteUnlock(&albuf->lock);
done:
@ -298,9 +304,8 @@ AL_API void AL_APIENTRY alFlushMappedBufferSOFT(ALuint buffer, ALsizei offset, A
WriteLock(&albuf->lock);
if(albuf->MappedAccess == 0 || !(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT))
alSetError(context, AL_INVALID_OPERATION);
/* TODO: Should check mapped range. */
else if(offset < 0 || offset >= albuf->OriginalSize ||
length <= 0 || length > albuf->OriginalSize - offset)
else if(offset < albuf->MappedOffset || offset >= albuf->MappedOffset+albuf->MappedSize ||
length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset)
alSetError(context, AL_INVALID_VALUE);
else
{