mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 13:18:31 +09:00
[Feat] (MG_Impl, MG_Backend, MG_State): implement glMultiDrawArrays and glGetBufferSubData
Two previously-stubbed GL 3.3 Core entry points. glMultiDrawArrays: mirrors the existing glMultiDrawElements(BaseVertex) architecture end to end -- a new MultiDrawArrays backend function-table slot dispatched from the frontend after program/primitive-mode validation (plus a drawcount < 0 -> GL_INVALID_VALUE guard). - DirectGLES: PrepareForDraw once, then loop native glDrawArrays with the same per-range client-side array upload the single DrawArrays does. - DirectVulkan: build a MultiDrawCmd payload and hand it to a new VulkanRenderer::MultiDrawArrays, which does one SetupDraw over the union of the sub-draw vertex ranges and then a vkCmdDraw per range (mirrors VulkanRenderer::MultiDrawElements). glGetBufferSubData: reads a range of the bound buffer's CPU shadow into client memory via a new BufferObject::DownloadSubData, with the same validation shape as BufferSubData (INVALID_VALUE for negative/overflowing range, INVALID_OPERATION for no bound buffer or a non-persistent mapped buffer). The shadow reflects CPU writes and backend write-backs but not arbitrary GPU-side writes, which is documented on the method. Tests: 2 BufferTest cases for glGetBufferSubData (round-trip read of a middle range and the whole buffer, plus out-of-range/negative/no-buffer errors). BufferTest 32/32, SanityTest 30/30, VertexArrayTest 42/42; library builds clean. (The glMultiDrawArrays draw paths are not runtime-testable on this host and are compile-verified against the tested MultiDrawElements pattern.)
This commit is contained in:
@@ -799,6 +799,55 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
bufferObject->UploadSubData({(void*)data, (SizeT)size}, offset);
|
||||
}
|
||||
|
||||
void GetBufferSubData_State(GLenum target, GLintptr offset, GLsizeiptr size, void* data) {
|
||||
MGLOG_D("%s: target = %s, offset = %d, size = %d, data = %p", __func__,
|
||||
MG_Util::ConvertGLEnumToString(target).c_str(), offset, size, data);
|
||||
if (!data) {
|
||||
// Match BufferSubData_State: a null pointer is a caller bug, not a GL-specified error.
|
||||
return;
|
||||
}
|
||||
|
||||
if (size < 0 || offset < 0) {
|
||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetBufferSubData_State",
|
||||
"Offset and size must be non-negative."));
|
||||
return;
|
||||
}
|
||||
|
||||
BufferTarget bufferTarget = MG_Util::ConvertGLEnumToBufferTarget(target);
|
||||
if (!BufferImpl::ValidateBufferTarget(bufferTarget)) return;
|
||||
auto& bindingSlot = GetBufferBindingSlot(bufferTarget);
|
||||
|
||||
auto& bufferObject = bindingSlot.GetBoundObject();
|
||||
if (!bufferObject) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetBufferSubData_State",
|
||||
"Buffer target is bound to no buffer object."));
|
||||
return;
|
||||
}
|
||||
|
||||
SizeT bufferSize = bufferObject->GetSize();
|
||||
if (static_cast<SizeT>(offset) + static_cast<SizeT>(size) > bufferSize) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetBufferSubData_State",
|
||||
"Offset and size exceed buffer size."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bufferObject->IsMapped() &&
|
||||
!(bufferObject->GetMappingAccess() & BufferMappingAccessBit::Persistent)) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", "GetBufferSubData_State",
|
||||
"Cannot read from a buffer object mapped without GL_MAP_PERSISTENT_BIT."));
|
||||
return;
|
||||
}
|
||||
|
||||
bufferObject->DownloadSubData(data, static_cast<SizeT>(offset), static_cast<SizeT>(size));
|
||||
}
|
||||
|
||||
void BufferData_State(GLenum target, GLsizeiptr size, const void* data, GLenum usage) {
|
||||
MGLOG_D("%s: %s, size = %d, data = %p, usage = %s", __func__, MG_Util::ConvertGLEnumToString(target).c_str(),
|
||||
size, data, MG_Util::ConvertGLEnumToString(usage).c_str());
|
||||
@@ -1425,6 +1474,10 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
BufferSubData_State(target, offset, size, data);
|
||||
}
|
||||
|
||||
void GetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, void* data) {
|
||||
GetBufferSubData_State(target, offset, size, data);
|
||||
}
|
||||
|
||||
void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage) {
|
||||
BufferData_State(target, size, data, usage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user