mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat] (MG_Backend/DirectGLES): Implement basic stuff for DirectGLES backend.
This commit is contained in:
@@ -9,15 +9,15 @@ namespace MobileGL {
|
||||
|
||||
void BufferObject::Resize(SizeT size) {
|
||||
m_size = size;
|
||||
m_data.reserve(std::bit_ceil(size)); // power-of-2 reserve
|
||||
m_data.resize(size);
|
||||
m_dataPtr->reserve(std::bit_ceil(size)); // power-of-2 reserve
|
||||
m_dataPtr->resize(size);
|
||||
m_dirtyRange = {0, 0};
|
||||
}
|
||||
|
||||
void BufferObject::UploadData(DataPtr data, SizeT atOffset) {
|
||||
assert(atOffset + data.size <= m_size);
|
||||
assert(!m_isMapped);
|
||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||
memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace MobileGL {
|
||||
|
||||
if (m_mappingAccess & BufferMappingAccessBit::Write) { // if we wrote to the buffer
|
||||
if (!(m_mappingAccess & BufferMappingAccessBit::FlushExplicit)) { // if we didn't flush explicitly
|
||||
memcpy(m_data.data() + m_mappedRange.start, m_stagingData.data(),
|
||||
memcpy(m_dataPtr->data() + m_mappedRange.start, m_stagingData.data(),
|
||||
m_mappedRange.end - m_mappedRange.start);
|
||||
m_dirtyRange.UnionUpdate(m_mappedRange.start, m_mappedRange.end);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ namespace MobileGL {
|
||||
SizeT end = start + length;
|
||||
assert(end <= m_mappedRange.end);
|
||||
|
||||
memcpy(m_data.data() + start, m_stagingData.data() + offset, length);
|
||||
memcpy(m_dataPtr->data() + start, m_stagingData.data() + offset, length);
|
||||
m_dirtyRange.UnionUpdate(start, end);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace MobileGL {
|
||||
assert(!m_isMapped);
|
||||
assert(atOffset + data.size <= m_size);
|
||||
|
||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||
memcpy(m_dataPtr->data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ namespace MobileGL {
|
||||
assert(srcOffset + size <= src->GetSize());
|
||||
assert(dstOffset + size <= m_size);
|
||||
|
||||
const Uint8* srcData = src->m_data.data() + srcOffset;
|
||||
memcpy(m_data.data() + dstOffset, srcData, size);
|
||||
const Uint8* srcData = src->m_dataPtr->data() + srcOffset;
|
||||
memcpy(m_dataPtr->data() + dstOffset, srcData, size);
|
||||
m_dirtyRange.UnionUpdate(dstOffset, dstOffset + size);
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ namespace MobileGL {
|
||||
|
||||
if (!(m_mappingAccess &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data(), m_size);
|
||||
memcpy(m_stagingData.data(), m_dataPtr->data(), m_size);
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
}
|
||||
}
|
||||
|
||||
return m_data.data();
|
||||
return m_dataPtr->data();
|
||||
}
|
||||
|
||||
void* BufferObject::AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access) {
|
||||
@@ -113,16 +113,20 @@ namespace MobileGL {
|
||||
|
||||
if (!(access &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
|
||||
memcpy(m_stagingData.data(), m_dataPtr->data() + range.start, m_stagingData.size());
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
} else {
|
||||
m_ownsStagingData = false;
|
||||
return m_data.data() + range.start;
|
||||
return m_dataPtr->data() + range.start;
|
||||
}
|
||||
}
|
||||
|
||||
SharedPtr<Data> BufferObject::GetDataReadOnly() const {
|
||||
return m_dataPtr;
|
||||
}
|
||||
|
||||
void BufferObject::ClearDirty() {
|
||||
m_dirtyRange = {0, 0};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
@@ -70,18 +71,19 @@ namespace MobileGL {
|
||||
BufferUsage GetUsage() const;
|
||||
Range1D GetDirtyRange() const;
|
||||
Range1D GetMappedRange() const;
|
||||
SharedPtr<Data> GetDataReadOnly() const;
|
||||
Flags<BufferMappingAccessBit> GetMappingAccess() const;
|
||||
|
||||
private:
|
||||
Int m_id = 0;
|
||||
SizeT m_size = 0;
|
||||
BufferUsage m_usage = BufferUsage::StaticDraw;
|
||||
Data m_data;
|
||||
SharedPtr<Data> m_dataPtr;
|
||||
Bool m_isMapped;
|
||||
Flags<BufferMappingAccessBit> m_mappingAccess;
|
||||
Range1D m_dirtyRange;
|
||||
Range1D m_mappedRange;
|
||||
std::vector<Uint8> m_stagingData;
|
||||
Vector<Uint8> m_stagingData;
|
||||
Bool m_ownsStagingData;
|
||||
};
|
||||
} // namespace GLState
|
||||
|
||||
@@ -88,6 +88,12 @@ namespace MobileGL {
|
||||
return m_attachments[static_cast<SizeT>(type)];
|
||||
}
|
||||
|
||||
const Array<FramebufferAttachment,
|
||||
static_cast<SizeT>(FramebufferAttachmentType::FramebufferAttachmentTypeCount)>&
|
||||
FramebufferObject::GetAllAttachments() const {
|
||||
return m_attachments;
|
||||
}
|
||||
|
||||
Bool FramebufferObject::CheckCompleteness() const {
|
||||
if (m_attachments.empty()) {
|
||||
return false;
|
||||
|
||||
@@ -89,6 +89,9 @@ namespace MobileGL {
|
||||
std::shared_ptr<RenderbufferObjectStub> renderbuffer);
|
||||
void Detach(FramebufferAttachmentType type);
|
||||
const FramebufferAttachment& GetAttachment(FramebufferAttachmentType type) const;
|
||||
const Array<FramebufferAttachment,
|
||||
static_cast<SizeT>(FramebufferAttachmentType::FramebufferAttachmentTypeCount)>&
|
||||
GetAllAttachments() const;
|
||||
Bool CheckCompleteness() const;
|
||||
void SetDrawBuffers(const std::vector<FramebufferAttachmentType>& buffers);
|
||||
const Vector<FramebufferAttachmentType>& GetDrawBuffers() const;
|
||||
|
||||
@@ -68,6 +68,12 @@ namespace MobileGL {
|
||||
m_internalFormat = format;
|
||||
}
|
||||
|
||||
void TextureObjectBase::UnmarkMipmapDirty(Int index) {
|
||||
if (index >= 0 && index < static_cast<Int>(m_mipmaps.size())) {
|
||||
m_mipmaps[index].dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
// TextureObject1D
|
||||
TextureObject1D::TextureObject1D() : TextureObjectBase(TextureTarget::Texture1D) {}
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@ namespace MobileGL {
|
||||
virtual MipmapLevelInternal& GetMipmap(Int index) = 0;
|
||||
virtual void SetInternalFormat(TextureInternalFormat format) = 0;
|
||||
virtual Bool IsComplete() const = 0;
|
||||
virtual void UnmarkMipmapDirty(Int index) = 0;
|
||||
};
|
||||
|
||||
class TextureObjectBase : public ITextureObject {
|
||||
@@ -227,6 +228,7 @@ namespace MobileGL {
|
||||
MipmapLevelInternal& GetMipmap(Int index) override;
|
||||
void SetInternalFormat(TextureInternalFormat format) override;
|
||||
Bool IsComplete() const override;
|
||||
void UnmarkMipmapDirty(Int index) override;
|
||||
|
||||
protected:
|
||||
virtual void SetMipmapImpl(const MipmapLevelInput& level) = 0;
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
VertexArrayObject::VertexArrayObject() {
|
||||
for (auto& attr : m_attributes) {
|
||||
for (int index = 0; index < MAX_VERTEX_ATTRIBS; ++index) {
|
||||
auto& attr = m_attributes[index];
|
||||
attr.Enabled = false;
|
||||
attr.Size = 4;
|
||||
attr.Type = DataType::Float32;
|
||||
@@ -12,17 +13,21 @@ namespace MobileGL {
|
||||
attr.Stride = 0;
|
||||
attr.Offset = 0;
|
||||
attr.Buffer = nullptr;
|
||||
|
||||
MarkAttributeDirty(index);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArrayObject::EnableAttribute(Uint index) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
m_attributes[index].Enabled = true;
|
||||
MarkAttributeDirty(index);
|
||||
}
|
||||
|
||||
void VertexArrayObject::DisableAttribute(Uint index) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
m_attributes[index].Enabled = false;
|
||||
MarkAttributeDirty(index);
|
||||
}
|
||||
|
||||
Bool VertexArrayObject::IsAttributeEnabled(Uint index) const {
|
||||
@@ -45,11 +50,14 @@ namespace MobileGL {
|
||||
attr.Stride = stride;
|
||||
attr.Offset = offset;
|
||||
attr.IsInteger = isInteger;
|
||||
|
||||
MarkAttributeDirty(index);
|
||||
}
|
||||
|
||||
void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr<BufferObject>& buffer) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
m_attributes[index].Buffer = buffer;
|
||||
MarkAttributeDirty(index);
|
||||
}
|
||||
|
||||
BindingSlot<BufferObject>& VertexArrayObject::GetIndexBufferBindingSlot() {
|
||||
@@ -61,6 +69,27 @@ namespace MobileGL {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return emptyAttr;
|
||||
return m_attributes[index];
|
||||
}
|
||||
|
||||
const Array<VertexAttribute, VertexArrayObject::MAX_VERTEX_ATTRIBS>& VertexArrayObject::GetAllAttributes()
|
||||
const {
|
||||
return m_attributes;
|
||||
}
|
||||
|
||||
void VertexArrayObject::MarkAttributeDirty(Uint index) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
if (std::find(m_dirtyAttributes.begin(), m_dirtyAttributes.end(), index) != m_dirtyAttributes.end()) {
|
||||
return;
|
||||
}
|
||||
m_dirtyAttributes.push_back(index);
|
||||
}
|
||||
|
||||
const Vector<Uint>& VertexArrayObject::GetDirtyAttributeIndices() const {
|
||||
return m_dirtyAttributes;
|
||||
}
|
||||
|
||||
void VertexArrayObject::ClearDirtyAttributes() {
|
||||
m_dirtyAttributes.clear();
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -34,9 +34,16 @@ namespace MobileGL {
|
||||
BindingSlot<BufferObject>& GetIndexBufferBindingSlot();
|
||||
|
||||
const VertexAttribute& GetAttribute(Uint index) const;
|
||||
const Array<VertexAttribute, MAX_VERTEX_ATTRIBS>& GetAllAttributes() const;
|
||||
|
||||
const Vector<Uint>& GetDirtyAttributeIndices() const;
|
||||
void ClearDirtyAttributes();
|
||||
|
||||
private:
|
||||
void MarkAttributeDirty(Uint index);
|
||||
|
||||
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
|
||||
Vector<Uint> m_dirtyAttributes;
|
||||
BindingSlot<BufferObject> m_indexBufferBindingSlot;
|
||||
};
|
||||
} // namespace GLState
|
||||
|
||||
Reference in New Issue
Block a user