MCPcopy Create free account
hub / github.com/crownengine/crown / AL_APIENTRY alMapBufferSOFT

Function AL_APIENTRY alMapBufferSOFT

3rdparty/openal/al/buffer.cpp:766–814  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764 }
765}
766END_API_FUNC
767
768AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access)
769START_API_FUNC
770{
771 ContextRef context{GetContextRef()};
772 if UNLIKELY(!context) return nullptr;
773
774 ALCdevice *device{context->mDevice.get()};
775 std::lock_guard<std::mutex> _{device->BufferLock};
776
777 ALbuffer *albuf = LookupBuffer(device, buffer);
778 if UNLIKELY(!albuf)
779 context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
780 else if UNLIKELY((access&INVALID_MAP_FLAGS) != 0)
781 context->setError(AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS);
782 else if UNLIKELY(!(access&MAP_READ_WRITE_FLAGS))
783 context->setError(AL_INVALID_VALUE, "Mapping buffer %u without read or write access",
784 buffer);
785 else
786 {
787 ALbitfieldSOFT unavailable = (albuf->Access^access) & access;
788 if UNLIKELY(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT))
789 context->setError(AL_INVALID_OPERATION,
790 "Mapping in-use buffer %u without persistent mapping", buffer);
791 else if UNLIKELY(albuf->MappedAccess != 0)
792 context->setError(AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer);
793 else if UNLIKELY((unavailable&AL_MAP_READ_BIT_SOFT))
794 context->setError(AL_INVALID_VALUE,
795 "Mapping buffer %u for reading without read access", buffer);
796 else if UNLIKELY((unavailable&AL_MAP_WRITE_BIT_SOFT))
797 context->setError(AL_INVALID_VALUE,
798 "Mapping buffer %u for writing without write access", buffer);
799 else if UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT))
800 context->setError(AL_INVALID_VALUE,
801 "Mapping buffer %u persistently without persistent access", buffer);
802 else if UNLIKELY(offset < 0 || length <= 0
803 || static_cast<ALuint>(offset) >= albuf->OriginalSize
804 || static_cast<ALuint>(length) > albuf->OriginalSize - static_cast<ALuint>(offset))
805 context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u",
806 offset, length, buffer);
807 else
808 {
809 void *retval = albuf->mData.data() + offset;
810 albuf->MappedAccess = access;
811 albuf->MappedOffset = offset;
812 albuf->MappedSize = length;
813 return retval;
814 }
815 }
816
817 return nullptr;

Callers

nothing calls this directly

Calls 6

GetContextRefFunction · 0.85
ReadRefFunction · 0.85
setErrorMethod · 0.80
LookupBufferFunction · 0.70
getMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected