mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Refactor] (All): Restructure include system.
This commit is contained in:
@@ -1,159 +1,155 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "BufferObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
BufferObject::BufferObject()
|
||||
: m_id(0), m_size(0), m_usage(BufferUsage::StaticDraw),
|
||||
m_isMapped(false), m_mappingAccess(BufferMappingAccessBit::Null),
|
||||
m_dirtyRange({ 0, 0 }), m_mappedRange({ 0, 0 }) {
|
||||
}
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
BufferObject::BufferObject()
|
||||
: m_id(0), m_size(0), m_usage(BufferUsage::StaticDraw), m_isMapped(false),
|
||||
m_mappingAccess(BufferMappingAccessBit::Null), m_dirtyRange({0, 0}), m_mappedRange({0, 0}) {}
|
||||
|
||||
void BufferObject::Resize(SizeT size) {
|
||||
m_size = size;
|
||||
m_data.reserve(std::bit_ceil(size)); // power-of-2 reserve
|
||||
m_data.resize(size);
|
||||
m_dirtyRange = { 0, 0 };
|
||||
}
|
||||
void BufferObject::Resize(SizeT size) {
|
||||
m_size = size;
|
||||
m_data.reserve(std::bit_ceil(size)); // power-of-2 reserve
|
||||
m_data.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);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
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);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
void BufferObject::SetUsage(BufferUsage usage) {
|
||||
m_usage = usage;
|
||||
}
|
||||
void BufferObject::SetUsage(BufferUsage usage) {
|
||||
m_usage = usage;
|
||||
}
|
||||
|
||||
void BufferObject::ReleaseMemory() {
|
||||
if (!m_isMapped) return;
|
||||
void BufferObject::ReleaseMemory() {
|
||||
if (!m_isMapped) return;
|
||||
|
||||
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(),
|
||||
m_mappedRange.end - m_mappedRange.start);
|
||||
m_dirtyRange.UnionUpdate(m_mappedRange.start, m_mappedRange.end);
|
||||
}
|
||||
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(),
|
||||
m_mappedRange.end - m_mappedRange.start);
|
||||
m_dirtyRange.UnionUpdate(m_mappedRange.start, m_mappedRange.end);
|
||||
}
|
||||
|
||||
m_stagingData.clear();
|
||||
}
|
||||
m_stagingData.clear();
|
||||
}
|
||||
|
||||
m_isMapped = false;
|
||||
m_mappingAccess = BufferMappingAccessBit::Null;
|
||||
m_mappedRange = { 0, 0 };
|
||||
m_ownsStagingData = false;
|
||||
}
|
||||
m_isMapped = false;
|
||||
m_mappingAccess = BufferMappingAccessBit::Null;
|
||||
m_mappedRange = {0, 0};
|
||||
m_ownsStagingData = false;
|
||||
}
|
||||
|
||||
void BufferObject::FlushMemoryRange(SizeT offset, SizeT length) {
|
||||
assert(m_isMapped);
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::FlushExplicit));
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::Write));
|
||||
void BufferObject::FlushMemoryRange(SizeT offset, SizeT length) {
|
||||
assert(m_isMapped);
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::FlushExplicit));
|
||||
assert((m_mappingAccess & BufferMappingAccessBit::Write));
|
||||
|
||||
SizeT start = m_mappedRange.start + offset;
|
||||
SizeT end = start + length;
|
||||
assert(end <= m_mappedRange.end);
|
||||
SizeT start = m_mappedRange.start + offset;
|
||||
SizeT end = start + length;
|
||||
assert(end <= m_mappedRange.end);
|
||||
|
||||
memcpy(m_data.data() + start, m_stagingData.data() + offset, length);
|
||||
m_dirtyRange.UnionUpdate(start, end);
|
||||
}
|
||||
memcpy(m_data.data() + start, m_stagingData.data() + offset, length);
|
||||
m_dirtyRange.UnionUpdate(start, end);
|
||||
}
|
||||
|
||||
void BufferObject::UploadSubData(DataPtr data, SizeT atOffset) {
|
||||
assert(!m_isMapped);
|
||||
assert(atOffset + data.size <= m_size);
|
||||
void BufferObject::UploadSubData(DataPtr data, SizeT atOffset) {
|
||||
assert(!m_isMapped);
|
||||
assert(atOffset + data.size <= m_size);
|
||||
|
||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
|
||||
}
|
||||
|
||||
void BufferObject::CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset, SizeT size) {
|
||||
assert(!m_isMapped);
|
||||
assert(!src->IsMapped());
|
||||
assert(srcOffset + size <= src->GetSize());
|
||||
assert(dstOffset + size <= m_size);
|
||||
void BufferObject::CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset,
|
||||
SizeT size) {
|
||||
assert(!m_isMapped);
|
||||
assert(!src->IsMapped());
|
||||
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);
|
||||
m_dirtyRange.UnionUpdate(dstOffset, dstOffset + size);
|
||||
}
|
||||
const Uint8* srcData = src->m_data.data() + srcOffset;
|
||||
memcpy(m_data.data() + dstOffset, srcData, size);
|
||||
m_dirtyRange.UnionUpdate(dstOffset, dstOffset + size);
|
||||
}
|
||||
|
||||
void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) {
|
||||
if (markMapped) {
|
||||
m_isMapped = true;
|
||||
auto a = BufferMappingAccessBit::Coherent | BufferMappingAccessBit::Read;
|
||||
m_mappingAccess =
|
||||
(read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
|
||||
(write ? BufferMappingAccessBit::Write : BufferMappingAccessBit::Null);
|
||||
m_mappedRange = { 0, m_size };
|
||||
void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) {
|
||||
if (markMapped) {
|
||||
m_isMapped = true;
|
||||
auto a = BufferMappingAccessBit::Coherent | BufferMappingAccessBit::Read;
|
||||
m_mappingAccess = (read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
|
||||
(write ? BufferMappingAccessBit::Write : BufferMappingAccessBit::Null);
|
||||
m_mappedRange = {0, m_size};
|
||||
|
||||
if (m_mappingAccess & BufferMappingAccessBit::Write) {
|
||||
m_stagingData.resize(m_size);
|
||||
m_ownsStagingData = true;
|
||||
if (m_mappingAccess & BufferMappingAccessBit::Write) {
|
||||
m_stagingData.resize(m_size);
|
||||
m_ownsStagingData = true;
|
||||
|
||||
if (!(m_mappingAccess & (BufferMappingAccessBit::InvalidateRange |
|
||||
BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data(), m_size);
|
||||
}
|
||||
if (!(m_mappingAccess &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data(), m_size);
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
}
|
||||
}
|
||||
return m_stagingData.data();
|
||||
}
|
||||
}
|
||||
|
||||
return m_data.data();
|
||||
}
|
||||
return m_data.data();
|
||||
}
|
||||
|
||||
void* BufferObject::AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access) {
|
||||
assert(range.end <= m_size && range.start <= range.end);
|
||||
m_isMapped = true;
|
||||
m_mappingAccess = access;
|
||||
m_mappedRange = range;
|
||||
void* BufferObject::AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access) {
|
||||
assert(range.end <= m_size && range.start <= range.end);
|
||||
m_isMapped = true;
|
||||
m_mappingAccess = access;
|
||||
m_mappedRange = range;
|
||||
|
||||
if (access & BufferMappingAccessBit::Write) {
|
||||
m_stagingData.resize(range.end - range.start);
|
||||
m_ownsStagingData = true;
|
||||
if (access & BufferMappingAccessBit::Write) {
|
||||
m_stagingData.resize(range.end - range.start);
|
||||
m_ownsStagingData = true;
|
||||
|
||||
if (!(access & (BufferMappingAccessBit::InvalidateRange |
|
||||
BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
|
||||
}
|
||||
if (!(access &
|
||||
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
|
||||
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
|
||||
}
|
||||
|
||||
return m_stagingData.data();
|
||||
}
|
||||
else {
|
||||
m_ownsStagingData = false;
|
||||
return m_data.data() + range.start;
|
||||
}
|
||||
}
|
||||
return m_stagingData.data();
|
||||
} else {
|
||||
m_ownsStagingData = false;
|
||||
return m_data.data() + range.start;
|
||||
}
|
||||
}
|
||||
|
||||
void BufferObject::ClearDirty() {
|
||||
m_dirtyRange = { 0, 0 };
|
||||
}
|
||||
void BufferObject::ClearDirty() {
|
||||
m_dirtyRange = {0, 0};
|
||||
}
|
||||
|
||||
SizeT BufferObject::GetSize() const {
|
||||
return m_size;
|
||||
}
|
||||
SizeT BufferObject::GetSize() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
BufferUsage BufferObject::GetUsage() const {
|
||||
return m_usage;
|
||||
}
|
||||
BufferUsage BufferObject::GetUsage() const {
|
||||
return m_usage;
|
||||
}
|
||||
|
||||
Range1D BufferObject::GetDirtyRange() const {
|
||||
return m_dirtyRange;
|
||||
}
|
||||
Range1D BufferObject::GetDirtyRange() const {
|
||||
return m_dirtyRange;
|
||||
}
|
||||
|
||||
Bool BufferObject::IsMapped() const {
|
||||
return m_isMapped;
|
||||
}
|
||||
Bool BufferObject::IsMapped() const {
|
||||
return m_isMapped;
|
||||
}
|
||||
|
||||
Range1D BufferObject::GetMappedRange() const {
|
||||
return m_isMapped ? m_mappedRange : Range1D{ 0, 0 };
|
||||
}
|
||||
Range1D BufferObject::GetMappedRange() const {
|
||||
return m_isMapped ? m_mappedRange : Range1D{0, 0};
|
||||
}
|
||||
|
||||
Flags<BufferMappingAccessBit> BufferObject::GetMappingAccess() const {
|
||||
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Flags<BufferMappingAccessBit> BufferObject::GetMappingAccess() const {
|
||||
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,106 +1,89 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
enum class BufferTarget {
|
||||
Vertex,
|
||||
Index,
|
||||
Uniform,
|
||||
CopyRead,
|
||||
CopyWrite,
|
||||
PixelPack,
|
||||
PixelUnpack,
|
||||
Query,
|
||||
Texture,
|
||||
TransformFeedback,
|
||||
AtomicCounter,
|
||||
DispatchIndirect,
|
||||
DrawIndirect,
|
||||
ShaderStorage,
|
||||
enum class BufferTarget {
|
||||
Vertex,
|
||||
Index,
|
||||
Uniform,
|
||||
CopyRead,
|
||||
CopyWrite,
|
||||
PixelPack,
|
||||
PixelUnpack,
|
||||
Query,
|
||||
Texture,
|
||||
TransformFeedback,
|
||||
AtomicCounter,
|
||||
DispatchIndirect,
|
||||
DrawIndirect,
|
||||
ShaderStorage,
|
||||
BufferTargetCount,
|
||||
Unknown = -1
|
||||
};
|
||||
Unknown = -1
|
||||
};
|
||||
|
||||
enum class BufferUsage {
|
||||
StreamDraw,
|
||||
StreamRead,
|
||||
StreamCopy,
|
||||
StaticDraw,
|
||||
StaticRead,
|
||||
StaticCopy,
|
||||
DynamicDraw,
|
||||
DynamicRead,
|
||||
DynamicCopy,
|
||||
Unknown = -1
|
||||
};
|
||||
enum class BufferUsage {
|
||||
StreamDraw,
|
||||
StreamRead,
|
||||
StreamCopy,
|
||||
StaticDraw,
|
||||
StaticRead,
|
||||
StaticCopy,
|
||||
DynamicDraw,
|
||||
DynamicRead,
|
||||
DynamicCopy,
|
||||
Unknown = -1
|
||||
};
|
||||
|
||||
enum class BufferMappingAccessBit : Uint {
|
||||
Null = 0x00,
|
||||
Read = 0x01,
|
||||
Write = 0x02,
|
||||
InvalidateRange = 0x04,
|
||||
InvalidateBuffer = 0x08,
|
||||
FlushExplicit = 0x10,
|
||||
Unsynchronized = 0x20,
|
||||
Persistent = 0x40,
|
||||
Coherent = 0x80
|
||||
};
|
||||
enum class BufferMappingAccessBit : Uint {
|
||||
Null = 0x00,
|
||||
Read = 0x01,
|
||||
Write = 0x02,
|
||||
InvalidateRange = 0x04,
|
||||
InvalidateBuffer = 0x08,
|
||||
FlushExplicit = 0x10,
|
||||
Unsynchronized = 0x20,
|
||||
Persistent = 0x40,
|
||||
Coherent = 0x80
|
||||
};
|
||||
|
||||
// inline Flags<BufferMappingAccessBit> operator|(BufferMappingAccessBit a, const BufferMappingAccessBit b) {
|
||||
// return Flags(a) | b;
|
||||
// }
|
||||
//
|
||||
// inline BufferMappingAccessBit& operator|=(BufferMappingAccessBit& a, BufferMappingAccessBit b) {
|
||||
// a = a | b;
|
||||
// return a;
|
||||
// }
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class BufferObject {
|
||||
public:
|
||||
using TargetEnum = BufferTarget;
|
||||
|
||||
// inline Flags<BufferMappingAccessBit> operator&(const BufferMappingAccessBit a, const BufferMappingAccessBit b) {
|
||||
// return Flags(a) & b;
|
||||
// }
|
||||
BufferObject();
|
||||
|
||||
// inline bool Any(BufferMappingAccessBit a) {
|
||||
// using T = std::underlying_type_t<BufferMappingAccessBit>;
|
||||
// return static_cast<T>(a) != 0;
|
||||
// }
|
||||
void Resize(SizeT size);
|
||||
void UploadData(DataPtr data, SizeT atOffset);
|
||||
void SetUsage(BufferUsage usage);
|
||||
void* AcquireMemory(Bool markMapped, Bool read, Bool write);
|
||||
void* AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access);
|
||||
void ReleaseMemory();
|
||||
void FlushMemoryRange(SizeT offset, SizeT length);
|
||||
void UploadSubData(DataPtr data, SizeT atOffset);
|
||||
void CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset, SizeT size);
|
||||
void ClearDirty();
|
||||
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class BufferObject {
|
||||
public:
|
||||
using TargetEnum = BufferTarget;
|
||||
|
||||
BufferObject();
|
||||
Bool IsMapped() const;
|
||||
SizeT GetSize() const;
|
||||
BufferUsage GetUsage() const;
|
||||
Range1D GetDirtyRange() const;
|
||||
Range1D GetMappedRange() const;
|
||||
Flags<BufferMappingAccessBit> GetMappingAccess() const;
|
||||
|
||||
void Resize(SizeT size);
|
||||
void UploadData(DataPtr data, SizeT atOffset);
|
||||
void SetUsage(BufferUsage usage);
|
||||
void* AcquireMemory(Bool markMapped, Bool read, Bool write);
|
||||
void* AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access);
|
||||
void ReleaseMemory();
|
||||
void FlushMemoryRange(SizeT offset, SizeT length);
|
||||
void UploadSubData(DataPtr data, SizeT atOffset);
|
||||
void CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset, SizeT size);
|
||||
void ClearDirty();
|
||||
|
||||
Bool IsMapped() const;
|
||||
SizeT GetSize() const;
|
||||
BufferUsage GetUsage() const;
|
||||
Range1D GetDirtyRange() const;
|
||||
Range1D GetMappedRange() const;
|
||||
Flags<BufferMappingAccessBit> GetMappingAccess() const;
|
||||
private:
|
||||
Int m_id = 0;
|
||||
SizeT m_size = 0;
|
||||
BufferUsage m_usage = BufferUsage::StaticDraw;
|
||||
Data m_data;
|
||||
Bool m_isMapped;
|
||||
Flags<BufferMappingAccessBit> m_mappingAccess;
|
||||
Range1D m_dirtyRange;
|
||||
Range1D m_mappedRange;
|
||||
std::vector<Uint8> m_stagingData;
|
||||
bool m_ownsStagingData;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
Int m_id = 0;
|
||||
SizeT m_size = 0;
|
||||
BufferUsage m_usage = BufferUsage::StaticDraw;
|
||||
Data m_data;
|
||||
Bool m_isMapped;
|
||||
Flags<BufferMappingAccessBit> m_mappingAccess;
|
||||
Range1D m_dirtyRange;
|
||||
Range1D m_mappedRange;
|
||||
std::vector<Uint8> m_stagingData;
|
||||
bool m_ownsStagingData;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,66 +1,65 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "BufferState.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
BufferState::BufferState()
|
||||
: m_indexGenerator(1024, 1) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
m_bindingSlots[i] = BindingSlot<BufferObject>(GlobalBufferTargets[i]);
|
||||
}
|
||||
}
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
BufferState::BufferState() : m_indexGenerator(1024, 1) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
m_bindingSlots[i] = BindingSlot<BufferObject>(GlobalBufferTargets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SharedPtr<BufferObject> BufferState::GetBufferObject(Uint index) {
|
||||
auto it = m_bufferObjects.find(index);
|
||||
if (it != m_bufferObjects.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
SharedPtr<BufferObject> BufferState::GetBufferObject(Uint index) {
|
||||
auto it = m_bufferObjects.find(index);
|
||||
if (it != m_bufferObjects.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Vector<Uint> BufferState::GenerateNames(Uint number) {
|
||||
Vector<Uint> buffers(number);
|
||||
m_indexGenerator.Generate(number, buffers.data());
|
||||
return buffers;
|
||||
}
|
||||
Vector<Uint> BufferState::GenerateNames(Uint number) {
|
||||
Vector<Uint> buffers(number);
|
||||
m_indexGenerator.Generate(number, buffers.data());
|
||||
return buffers;
|
||||
}
|
||||
|
||||
SharedPtr<BufferObject> BufferState::CreateBufferObject(Uint index) {
|
||||
auto bufferObject = MakeShared<BufferObject>();
|
||||
m_bufferObjects[index] = bufferObject;
|
||||
return bufferObject;
|
||||
}
|
||||
SharedPtr<BufferObject> BufferState::CreateBufferObject(Uint index) {
|
||||
auto bufferObject = MakeShared<BufferObject>();
|
||||
m_bufferObjects[index] = bufferObject;
|
||||
return bufferObject;
|
||||
}
|
||||
|
||||
BindingSlot<BufferObject>& BufferState::GetBindingSlot(BufferTarget target) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
if (m_bindingSlots[i].GetTarget() == target) {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
BindingSlot<BufferObject>& BufferState::GetBindingSlot(BufferTarget target) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
if (m_bindingSlots[i].GetTarget() == target) {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void BufferState::MarkBufferObjectForDeletion(Uint index) {
|
||||
if (m_indexGenerator.IsValid(index)) {
|
||||
auto it = m_bufferObjects.find(index);
|
||||
if (it != m_bufferObjects.end()) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
if (m_bindingSlots[i].GetBoundObject() == it->second) {
|
||||
m_bindingSlots[i].Bind(nullptr);
|
||||
}
|
||||
}
|
||||
m_bufferObjects.erase(it);
|
||||
}
|
||||
m_indexGenerator.Delete(index);
|
||||
}
|
||||
}
|
||||
void BufferState::MarkBufferObjectForDeletion(Uint index) {
|
||||
if (m_indexGenerator.IsValid(index)) {
|
||||
auto it = m_bufferObjects.find(index);
|
||||
if (it != m_bufferObjects.end()) {
|
||||
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
|
||||
if (m_bindingSlots[i].GetBoundObject() == it->second) {
|
||||
m_bindingSlots[i].Bind(nullptr);
|
||||
}
|
||||
}
|
||||
m_bufferObjects.erase(it);
|
||||
}
|
||||
m_indexGenerator.Delete(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool BufferState::ValidateName(Uint index) const {
|
||||
return m_indexGenerator.IsValid(index);
|
||||
}
|
||||
bool BufferState::ValidateName(Uint index) const {
|
||||
return m_indexGenerator.IsValid(index);
|
||||
}
|
||||
|
||||
bool BufferState::ValidateBufferObject(Uint index) const {
|
||||
return m_bufferObjects.find(index) != m_bufferObjects.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool BufferState::ValidateBufferObject(Uint index) const {
|
||||
return m_bufferObjects.find(index) != m_bufferObjects.end();
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,40 +1,34 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "BufferObject.h"
|
||||
#include <MG_Util/Miscellany/IndexGenerator.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
constexpr const auto GlobalBufferTargets = ToArray(
|
||||
BufferTarget::Vertex,
|
||||
BufferTarget::Uniform,
|
||||
BufferTarget::CopyRead,
|
||||
BufferTarget::CopyWrite,
|
||||
BufferTarget::PixelPack,
|
||||
BufferTarget::PixelUnpack,
|
||||
BufferTarget::Query,
|
||||
BufferTarget::Texture,
|
||||
BufferTarget::TransformFeedback,
|
||||
BufferTarget::AtomicCounter,
|
||||
BufferTarget::DispatchIndirect,
|
||||
BufferTarget::DrawIndirect,
|
||||
BufferTarget::ShaderStorage);
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
constexpr const auto GlobalBufferTargets =
|
||||
ToArray(BufferTarget::Vertex, BufferTarget::Uniform, BufferTarget::CopyRead, BufferTarget::CopyWrite,
|
||||
BufferTarget::PixelPack, BufferTarget::PixelUnpack, BufferTarget::Query, BufferTarget::Texture,
|
||||
BufferTarget::TransformFeedback, BufferTarget::AtomicCounter, BufferTarget::DispatchIndirect,
|
||||
BufferTarget::DrawIndirect, BufferTarget::ShaderStorage);
|
||||
|
||||
class BufferState {
|
||||
public:
|
||||
BufferState();
|
||||
class BufferState {
|
||||
public:
|
||||
BufferState();
|
||||
|
||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||
Vector<Uint> GenerateNames(Uint number);
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
BindingSlot<BufferObject>& GetBindingSlot(BufferTarget target);
|
||||
void MarkBufferObjectForDeletion(Uint index);
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateBufferObject(Uint index) const;
|
||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||
Vector<Uint> GenerateNames(Uint number);
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
BindingSlot<BufferObject>& GetBindingSlot(BufferTarget target);
|
||||
void MarkBufferObjectForDeletion(Uint index);
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateBufferObject(Uint index) const;
|
||||
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
Array<BindingSlot<BufferObject>, GlobalBufferTargets.size()> m_bindingSlots;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
Array<BindingSlot<BufferObject>, GlobalBufferTargets.size()> m_bindingSlots;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../../Includes.h"
|
||||
#include "Core.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -36,7 +36,7 @@ namespace MobileGL {
|
||||
m_errorState.Clear();
|
||||
}
|
||||
|
||||
// Buffer
|
||||
// Buffer
|
||||
Vector<Uint> GLContext::GenBufferNames(Uint number) {
|
||||
return m_bufferState.GenerateNames(number);
|
||||
}
|
||||
@@ -47,9 +47,9 @@ namespace MobileGL {
|
||||
|
||||
BindingSlot<BufferObject>& GLContext::GetBufferBindingSlot(BufferTarget target) {
|
||||
if (target == BufferTarget::Index) {
|
||||
return m_vertexArrayState.GetBoundVertexArray()->GetIndexBufferBindingSlot();
|
||||
return m_vertexArrayState.GetBoundVertexArray()->GetIndexBufferBindingSlot();
|
||||
}
|
||||
|
||||
|
||||
return m_bufferState.GetBindingSlot(target);
|
||||
}
|
||||
|
||||
@@ -59,12 +59,11 @@ namespace MobileGL {
|
||||
|
||||
void GLContext::MarkBufferObjectForDeletion(Uint index) {
|
||||
if (ValidateBufferObject(index)) {
|
||||
auto bufferObject = m_bufferState.GetBufferObject(index);
|
||||
auto bufferObject = m_bufferState.GetBufferObject(index);
|
||||
auto& vaos = m_vertexArrayState.GetAllVertexArrays();
|
||||
for (SizeT i = 0; i < vaos.size(); ++i) {
|
||||
auto vao = vaos[i];
|
||||
if (vao == nullptr)
|
||||
continue;
|
||||
if (vao == nullptr) continue;
|
||||
|
||||
if (vao->GetIndexBufferBindingSlot().GetBoundObject() == bufferObject) {
|
||||
vao->GetIndexBufferBindingSlot().Bind(nullptr);
|
||||
@@ -81,11 +80,11 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
bool GLContext::ValidateBufferName(Uint index) const {
|
||||
return m_bufferState.ValidateName(index);
|
||||
return m_bufferState.ValidateName(index);
|
||||
}
|
||||
|
||||
bool GLContext::ValidateBufferObject(Uint index) const {
|
||||
return m_bufferState.ValidateBufferObject(index);
|
||||
return m_bufferState.ValidateBufferObject(index);
|
||||
}
|
||||
|
||||
// VertexArray
|
||||
@@ -120,8 +119,8 @@ namespace MobileGL {
|
||||
SharedPtr<VertexArrayObject> GLContext::GetBoundVertexArray() {
|
||||
return m_vertexArrayState.GetBoundVertexArray();
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
|
||||
GLState::GLContext* pGLContext;
|
||||
}
|
||||
}
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,53 +1,58 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "BufferState/BufferState.h"
|
||||
#include "VertexArrayState/VertexArrayState.h"
|
||||
#include "ErrorState/Error.h"
|
||||
#include "ProgramState/ProgramState.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class GLContext {
|
||||
public:
|
||||
GLContext() = default;
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class GLContext {
|
||||
public:
|
||||
GLContext() = default;
|
||||
|
||||
// Error
|
||||
void RecordError(ErrorCode code, SharedPtr<ErrorInfo> info = nullptr);
|
||||
bool HasGLError() const;
|
||||
Optional<const Error> PeekGLError() const;
|
||||
Optional<Error> PopGLError();
|
||||
bool HasNonGLError() const;
|
||||
Optional<const Error> PeekNonGLError() const;
|
||||
Optional<Error> PopNonGLError();
|
||||
void ClearErrors();
|
||||
// Error
|
||||
void RecordError(ErrorCode code, SharedPtr<ErrorInfo> info = nullptr);
|
||||
bool HasGLError() const;
|
||||
Optional<const Error> PeekGLError() const;
|
||||
Optional<Error> PopGLError();
|
||||
bool HasNonGLError() const;
|
||||
Optional<const Error> PeekNonGLError() const;
|
||||
Optional<Error> PopNonGLError();
|
||||
void ClearErrors();
|
||||
|
||||
// Buffer
|
||||
Vector<Uint> GenBufferNames(Uint number);
|
||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||
BindingSlot<BufferObject>& GetBufferBindingSlot(BufferTarget target);
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
void MarkBufferObjectForDeletion(Uint index);
|
||||
bool ValidateBufferName(Uint index) const;
|
||||
bool ValidateBufferObject(Uint index) const;
|
||||
// Buffer
|
||||
Vector<Uint> GenBufferNames(Uint number);
|
||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||
BindingSlot<BufferObject>& GetBufferBindingSlot(BufferTarget target);
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
void MarkBufferObjectForDeletion(Uint index);
|
||||
bool ValidateBufferName(Uint index) const;
|
||||
bool ValidateBufferObject(Uint index) const;
|
||||
|
||||
// VertexArray
|
||||
Vector<Uint> GenVertexArrayNames(Uint number);
|
||||
SharedPtr<VertexArrayObject> GetVertexArrayObject(Uint index);
|
||||
void BindVertexArray(Uint index);
|
||||
SharedPtr<VertexArrayObject> CreateVertexArrayObject(Uint index);
|
||||
void MarkVertexArrayForDeletion(Uint index);
|
||||
bool ValidateVertexArrayName(Uint index) const;
|
||||
bool ValidateVertexArrayObject(Uint index) const;
|
||||
SharedPtr<VertexArrayObject> GetBoundVertexArray();
|
||||
// VertexArray
|
||||
Vector<Uint> GenVertexArrayNames(Uint number);
|
||||
SharedPtr<VertexArrayObject> GetVertexArrayObject(Uint index);
|
||||
void BindVertexArray(Uint index);
|
||||
SharedPtr<VertexArrayObject> CreateVertexArrayObject(Uint index);
|
||||
void MarkVertexArrayForDeletion(Uint index);
|
||||
bool ValidateVertexArrayName(Uint index) const;
|
||||
bool ValidateVertexArrayObject(Uint index) const;
|
||||
SharedPtr<VertexArrayObject> GetBoundVertexArray();
|
||||
|
||||
private:
|
||||
// Error
|
||||
ErrorState m_errorState;
|
||||
private:
|
||||
// Error
|
||||
ErrorState m_errorState;
|
||||
|
||||
// Buffer
|
||||
BufferState m_bufferState;
|
||||
// Buffer
|
||||
BufferState m_bufferState;
|
||||
|
||||
// VertexArray
|
||||
VertexArrayState m_vertexArrayState;
|
||||
};
|
||||
}
|
||||
// VertexArray
|
||||
VertexArrayState m_vertexArrayState;
|
||||
};
|
||||
} // namespace GLState
|
||||
|
||||
extern GLState::GLContext* pGLContext;
|
||||
}
|
||||
}
|
||||
extern GLState::GLContext* pGLContext;
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,19 +1,19 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "Error.h"
|
||||
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
|
||||
#include <MG_Util/Converters/MGToGL/ErrorCodeConverter.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
void ErrorState::RecordError(ErrorCode code, SharedPtr<ErrorInfo> info) {
|
||||
if (code == ErrorCode::NoError) {
|
||||
MGLOG_E("Recording Non-OpenGL error:\n%s",
|
||||
info->ToString().c_str());
|
||||
m_nonGLErrors.push_back(Error{ code, info });
|
||||
}
|
||||
else {
|
||||
MGLOG_E("Recording OpenGL error (%s):\n%s",
|
||||
MG_Util::ConvertGLEnumToString(MG_Util::ConvertErrorCodeToGLEnum(code)).c_str(),
|
||||
info->ToString().c_str());
|
||||
m_errors.push_back(Error{ code, info });
|
||||
MGLOG_E("Recording Non-OpenGL error:\n%s", info->ToString().c_str());
|
||||
m_nonGLErrors.push_back(Error{code, info});
|
||||
} else {
|
||||
MGLOG_E("Recording OpenGL error (%s):\n%s",
|
||||
MG_Util::ConvertGLEnumToString(MG_Util::ConvertErrorCodeToGLEnum(code)).c_str(),
|
||||
info->ToString().c_str());
|
||||
m_errors.push_back(Error{code, info});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
Optional<const Error> ErrorState::PeekNonGLError() const {
|
||||
if (m_nonGLErrors.empty()) return Optional<const Error>{ };
|
||||
if (m_nonGLErrors.empty()) return Optional<const Error>{};
|
||||
return Optional<const Error>{m_nonGLErrors.front()};
|
||||
}
|
||||
|
||||
Optional<Error> ErrorState::PopNonGLError() {
|
||||
if (m_nonGLErrors.empty()) return Optional<const Error>{ };
|
||||
if (m_nonGLErrors.empty()) return Optional<const Error>{};
|
||||
auto error = Move(m_nonGLErrors.front());
|
||||
m_nonGLErrors.erase(m_nonGLErrors.begin());
|
||||
return Optional<const Error>{ error };
|
||||
return Optional<const Error>{error};
|
||||
}
|
||||
|
||||
bool ErrorState::HasGLError() const {
|
||||
@@ -38,21 +38,21 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
Optional<const Error> ErrorState::PeekGLError() const {
|
||||
if (m_errors.empty()) return Optional<const Error>{ };
|
||||
if (m_errors.empty()) return Optional<const Error>{};
|
||||
return Optional<const Error>{m_errors.front()};
|
||||
}
|
||||
|
||||
Optional<Error> ErrorState::PopGLError() {
|
||||
if (m_errors.empty()) return Optional<const Error>{ };
|
||||
if (m_errors.empty()) return Optional<const Error>{};
|
||||
auto error = Move(m_errors.front());
|
||||
m_errors.erase(m_errors.begin());
|
||||
return Optional<const Error>{ error };
|
||||
return Optional<const Error>{error};
|
||||
}
|
||||
|
||||
void ErrorState::Clear() {
|
||||
m_errors.clear();
|
||||
m_nonGLErrors.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "ErrorCode.h"
|
||||
#include "ErrorInfo.h"
|
||||
|
||||
namespace MobileGL {
|
||||
struct Error {
|
||||
@@ -23,6 +26,6 @@ namespace MobileGL {
|
||||
Vector<Error> m_errors;
|
||||
Vector<Error> m_nonGLErrors;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
class ErrorInfo {
|
||||
@@ -10,9 +11,11 @@ namespace MobileGL {
|
||||
class GenericErrorInfo : public ErrorInfo {
|
||||
public:
|
||||
explicit GenericErrorInfo(String message) : m_message(Move(message)) {}
|
||||
explicit GenericErrorInfo(String m_prefix, String message) : m_message(Move(message)), m_prefix(Move(m_prefix)) {}
|
||||
explicit GenericErrorInfo(String m_prefix, String m_prefix_2, String message) : m_message(Move(message)), m_prefix(Move(m_prefix)), m_prefix_2(Move(m_prefix_2)) {}
|
||||
|
||||
explicit GenericErrorInfo(String m_prefix, String message)
|
||||
: m_message(Move(message)), m_prefix(Move(m_prefix)) {}
|
||||
explicit GenericErrorInfo(String m_prefix, String m_prefix_2, String message)
|
||||
: m_message(Move(message)), m_prefix(Move(m_prefix)), m_prefix_2(Move(m_prefix_2)) {}
|
||||
|
||||
String ToString() const override {
|
||||
StringStream ss;
|
||||
if (m_prefix.has_value()) {
|
||||
@@ -22,11 +25,12 @@ namespace MobileGL {
|
||||
ss << "[" << m_prefix_2.value() << "] ";
|
||||
}
|
||||
ss << m_message;
|
||||
return ss.str();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
String m_message;
|
||||
Optional<String> m_prefix;
|
||||
Optional<String> m_prefix_2;
|
||||
Optional<String> m_prefix;
|
||||
Optional<String> m_prefix_2;
|
||||
};
|
||||
}
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ProgramObject.h"
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -8,10 +9,8 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void ProgramObject::DetachShader(SharedPtr<ShaderObject> shader) {
|
||||
auto count = std::erase_if(m_shaders,
|
||||
[shader](const SharedPtr<ShaderObject>& s) {
|
||||
return s.get() == shader.get();
|
||||
});
|
||||
auto count = std::erase_if(
|
||||
m_shaders, [shader](const SharedPtr<ShaderObject>& s) { return s.get() == shader.get(); });
|
||||
|
||||
if (count == 0) {
|
||||
// FIXME: handle error here
|
||||
@@ -27,7 +26,7 @@ namespace MobileGL {
|
||||
shaders[i] = m_shaders[i]->m_shader;
|
||||
}
|
||||
|
||||
MG_Util::ShaderTranspiler::ProgramAttrib attrib {
|
||||
MG_Util::ShaderTranspiler::ProgramAttrib attrib{
|
||||
.shaderTypes = Move(shaderTypes),
|
||||
.shaders = Move(shaders),
|
||||
};
|
||||
@@ -40,12 +39,11 @@ namespace MobileGL {
|
||||
m_linkStatus = false;
|
||||
m_infoLog = result.error().log;
|
||||
|
||||
const std::string e =
|
||||
std::format("Shader link failed: \nerrc: {}\nmsg: {}\n",
|
||||
result.error().errc, result.error().log);
|
||||
const std::string e = std::format("Shader link failed: \nerrc: {}\nmsg: {}\n", result.error().errc,
|
||||
result.error().log);
|
||||
THROW_EXCEPTION(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,23 +1,25 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
#include "ShaderObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class ProgramObject {
|
||||
public:
|
||||
void AttachShader(SharedPtr<ShaderObject> shader);
|
||||
void DetachShader(SharedPtr<ShaderObject> shader);
|
||||
void Link();
|
||||
private:
|
||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||
// basically this contains SPIR-V in binary format
|
||||
Vector<Vector<Uint>> m_programBinary;
|
||||
String m_infoLog;
|
||||
bool m_deleteStatus = false;
|
||||
bool m_linkStatus = true;
|
||||
bool m_validateStatus = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class ProgramObject {
|
||||
public:
|
||||
void AttachShader(SharedPtr<ShaderObject> shader);
|
||||
void DetachShader(SharedPtr<ShaderObject> shader);
|
||||
void Link();
|
||||
|
||||
private:
|
||||
Vector<SharedPtr<ShaderObject>> m_shaders;
|
||||
// basically this contains SPIR-V in binary format
|
||||
Vector<Vector<Uint>> m_programBinary;
|
||||
String m_infoLog;
|
||||
bool m_deleteStatus = false;
|
||||
bool m_linkStatus = true;
|
||||
bool m_validateStatus = true;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ProgramState.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -12,16 +12,14 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
SharedPtr<ProgramObject> ProgramState::GetProgramObject(Uint id) {
|
||||
if (!CheckIndexAvail(id))
|
||||
return nullptr; // FIXME: add error reporting here
|
||||
if (!CheckIndexAvail(id)) return nullptr; // FIXME: add error reporting here
|
||||
return m_programObjects[id];
|
||||
}
|
||||
|
||||
void ProgramState::DeleteProgram(Uint id) {
|
||||
if (!CheckIndexAvail(id))
|
||||
return; // FIXME: add error reporting here
|
||||
if (!CheckIndexAvail(id)) return; // FIXME: add error reporting here
|
||||
m_programObjects[id].reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include <MG_Util/Miscellany/IndexGenerator.h>
|
||||
#include "ProgramObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -10,10 +13,9 @@ namespace MobileGL {
|
||||
Uint CreateProgram();
|
||||
SharedPtr<ProgramObject> GetProgramObject(Uint id);
|
||||
void DeleteProgram(Uint program);
|
||||
|
||||
private:
|
||||
bool CheckIndexAvail(SizeT idx) {
|
||||
return idx < m_programObjects.size();
|
||||
}
|
||||
bool CheckIndexAvail(SizeT idx) { return idx < m_programObjects.size(); }
|
||||
|
||||
void EnsureIndexAvail(SizeT idx) {
|
||||
if (CheckIndexAvail(idx)) return;
|
||||
@@ -25,6 +27,6 @@ namespace MobileGL {
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
Vector<SharedPtr<ProgramObject>> m_programObjects;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "ShaderObject.h"
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -9,11 +10,8 @@ namespace MobileGL {
|
||||
|
||||
void ShaderObject::Compile() {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
ShaderAttrib attrib {
|
||||
.sourceStr = m_source,
|
||||
.shaderType = GetGLShaderTypeByMGLShaderStage(m_stage),
|
||||
.flags = 0
|
||||
};
|
||||
ShaderAttrib attrib{
|
||||
.sourceStr = m_source, .shaderType = GetGLShaderTypeByMGLShaderStage(m_stage), .flags = 0};
|
||||
|
||||
auto result = ShaderCompiler::CompileShader(attrib);
|
||||
if (result) {
|
||||
@@ -23,12 +21,11 @@ namespace MobileGL {
|
||||
m_compileStatus = false;
|
||||
m_infoLog = result.error().log;
|
||||
|
||||
const std::string e =
|
||||
std::format("Shader compilation failed: \nerrc: {}\nmsg: {}\n",
|
||||
result.error().errc, result.error().log);
|
||||
const std::string e = std::format("Shader compilation failed: \nerrc: {}\nmsg: {}\n",
|
||||
result.error().errc, result.error().log);
|
||||
THROW_EXCEPTION(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -15,27 +15,27 @@ namespace MobileGL {
|
||||
|
||||
inline static GLenum GetGLShaderTypeByMGLShaderStage(ShaderStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderStage::Vertex:
|
||||
return GL_VERTEX_SHADER;
|
||||
case ShaderStage::TessControl:
|
||||
return GL_TESS_CONTROL_SHADER;
|
||||
case ShaderStage::TessEval:
|
||||
return GL_TESS_EVALUATION_SHADER;
|
||||
case ShaderStage::Geometry:
|
||||
return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::Fragment:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
case ShaderStage::Compute:
|
||||
return GL_COMPUTE_SHADER;
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
case ShaderStage::Vertex:
|
||||
return GL_VERTEX_SHADER;
|
||||
case ShaderStage::TessControl:
|
||||
return GL_TESS_CONTROL_SHADER;
|
||||
case ShaderStage::TessEval:
|
||||
return GL_TESS_EVALUATION_SHADER;
|
||||
case ShaderStage::Geometry:
|
||||
return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::Fragment:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
case ShaderStage::Compute:
|
||||
return GL_COMPUTE_SHADER;
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class ShaderObject {
|
||||
public:
|
||||
ShaderObject(const ShaderStage stage): m_stage(stage) {}
|
||||
ShaderObject(const ShaderStage stage) : m_stage(stage) {}
|
||||
void SetShaderSource(const std::string& source);
|
||||
void Compile();
|
||||
|
||||
@@ -47,6 +47,6 @@ namespace MobileGL {
|
||||
bool m_deleteStatus = false;
|
||||
bool m_compileStatus = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "VertexArrayObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -30,8 +30,8 @@ namespace MobileGL {
|
||||
return m_attributes[index].Enabled;
|
||||
}
|
||||
|
||||
void VertexArrayObject::SetAttributeFormat(Uint index, int size, DataType type,
|
||||
bool normalized, int stride, SizeT offset, bool isInteger) {
|
||||
void VertexArrayObject::SetAttributeFormat(Uint index, int size, DataType type, bool normalized, int stride,
|
||||
SizeT offset, bool isInteger) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
|
||||
if (size < 1 || size > 4) {
|
||||
@@ -44,17 +44,16 @@ namespace MobileGL {
|
||||
attr.Normalized = normalized;
|
||||
attr.Stride = stride;
|
||||
attr.Offset = offset;
|
||||
attr.IsInteger = isInteger;
|
||||
attr.IsInteger = isInteger;
|
||||
}
|
||||
|
||||
void VertexArrayObject::BindAttributeBuffer(Uint index,
|
||||
const SharedPtr<BufferObject>& buffer) {
|
||||
void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr<BufferObject>& buffer) {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||
m_attributes[index].Buffer = buffer;
|
||||
}
|
||||
|
||||
BindingSlot<BufferObject>& VertexArrayObject::GetIndexBufferBindingSlot() {
|
||||
return m_indexBufferBindingSlot;
|
||||
return m_indexBufferBindingSlot;
|
||||
}
|
||||
|
||||
const VertexAttribute& VertexArrayObject::GetAttribute(Uint index) const {
|
||||
@@ -62,6 +61,6 @@ namespace MobileGL {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return emptyAttr;
|
||||
return m_attributes[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "../BufferState/BufferObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -24,7 +26,8 @@ namespace MobileGL {
|
||||
void DisableAttribute(Uint index);
|
||||
bool IsAttributeEnabled(Uint index) const;
|
||||
|
||||
void SetAttributeFormat(Uint index, int size, DataType type, bool normalized, int stride, SizeT offset, bool isInteger);
|
||||
void SetAttributeFormat(Uint index, int size, DataType type, bool normalized, int stride, SizeT offset,
|
||||
bool isInteger);
|
||||
|
||||
void BindAttributeBuffer(Uint index, const SharedPtr<BufferObject>& buffer);
|
||||
|
||||
@@ -36,6 +39,6 @@ namespace MobileGL {
|
||||
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
|
||||
BindingSlot<BufferObject> m_indexBufferBindingSlot;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "../../../Includes.h"
|
||||
#include "VertexArrayState.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
VertexArrayState::VertexArrayState()
|
||||
: m_indexGenerator(1024, 1) {
|
||||
}
|
||||
VertexArrayState::VertexArrayState() : m_indexGenerator(1024, 1) {}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::GetVertexArrayObject(Uint index) {
|
||||
if (index >= m_vertexArrays.size())
|
||||
@@ -71,6 +69,6 @@ namespace MobileGL {
|
||||
Vector<SharedPtr<VertexArrayObject>>& VertexArrayState::GetAllVertexArrays() {
|
||||
return m_vertexArrays;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "VertexArrayObject.h"
|
||||
#include <MG_Util/Miscellany/IndexGenerator.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -22,6 +25,6 @@ namespace MobileGL {
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
SharedPtr<VertexArrayObject> m_boundVertexArray;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
Reference in New Issue
Block a user