mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat]: Flags<Bit, Underlying> template for manipulating flag sets
This commit is contained in:
@@ -61,8 +61,8 @@ namespace MobileGL {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMappingAccessBit mappingAccess = bufferObject->GetMappingAccess();
|
auto mappingAccess = bufferObject->GetMappingAccess();
|
||||||
if(!Any(mappingAccess & BufferMappingAccessBit::FlushExplicit)) {
|
if(!(mappingAccess & BufferMappingAccessBit::FlushExplicit)) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
|
||||||
"Cannot flush a buffer object that is not mapped with GL_MAP_FLUSH_EXPLICIT_BIT."));
|
"Cannot flush a buffer object that is not mapped with GL_MAP_FLUSH_EXPLICIT_BIT."));
|
||||||
@@ -134,19 +134,19 @@ namespace MobileGL {
|
|||||||
auto accessBits = MG_Util::ConvertGLEnumToBufferMappingAccess(access);
|
auto accessBits = MG_Util::ConvertGLEnumToBufferMappingAccess(access);
|
||||||
if (!BufferImpl::ValidateBufferMappingAccess(accessBits)) return nullptr;
|
if (!BufferImpl::ValidateBufferMappingAccess(accessBits)) return nullptr;
|
||||||
|
|
||||||
if (!Any(accessBits & (BufferMappingAccessBit::Read | BufferMappingAccessBit::Write))) {
|
if (!(accessBits & (BufferMappingAccessBit::Read | BufferMappingAccessBit::Write))) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
||||||
"At least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT must be set."));
|
"At least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT must be set."));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Any(accessBits & BufferMappingAccessBit::Read)) {
|
if (accessBits & BufferMappingAccessBit::Read) {
|
||||||
const auto invalidFlags = BufferMappingAccessBit::InvalidateRange |
|
const auto invalidFlags = BufferMappingAccessBit::InvalidateRange |
|
||||||
BufferMappingAccessBit::InvalidateBuffer |
|
BufferMappingAccessBit::InvalidateBuffer |
|
||||||
BufferMappingAccessBit::Unsynchronized;
|
BufferMappingAccessBit::Unsynchronized;
|
||||||
|
|
||||||
if (Any(accessBits & invalidFlags)) {
|
if (accessBits & invalidFlags) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
||||||
"GL_MAP_READ_BIT cannot be combined with invalidation or unsynchronized flags."));
|
"GL_MAP_READ_BIT cannot be combined with invalidation or unsynchronized flags."));
|
||||||
@@ -154,8 +154,8 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Any(accessBits & BufferMappingAccessBit::FlushExplicit)) {
|
if (accessBits & BufferMappingAccessBit::FlushExplicit) {
|
||||||
if (!(Any(accessBits & BufferMappingAccessBit::Write))) {
|
if (!(accessBits & BufferMappingAccessBit::Write)) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
||||||
"GL_MAP_FLUSH_EXPLICIT_BIT requires GL_MAP_WRITE_BIT."));
|
"GL_MAP_FLUSH_EXPLICIT_BIT requires GL_MAP_WRITE_BIT."));
|
||||||
@@ -163,10 +163,10 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BufferMappingAccessBit storageFlags =
|
const auto storageFlags =
|
||||||
BufferMappingAccessBit::Persistent | BufferMappingAccessBit::Coherent;
|
BufferMappingAccessBit::Persistent | BufferMappingAccessBit::Coherent;
|
||||||
BufferMappingAccessBit requiredFlags = accessBits & storageFlags;
|
auto requiredFlags = accessBits & storageFlags;
|
||||||
if (Any(requiredFlags)) {
|
if (requiredFlags) {
|
||||||
// TODO: check if the buffer data is created by BufferStorage and its flags after its implementation
|
// TODO: check if the buffer data is created by BufferStorage and its flags after its implementation
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
||||||
@@ -178,7 +178,7 @@ namespace MobileGL {
|
|||||||
const auto invalidateFlags = BufferMappingAccessBit::InvalidateRange |
|
const auto invalidateFlags = BufferMappingAccessBit::InvalidateRange |
|
||||||
BufferMappingAccessBit::InvalidateBuffer;
|
BufferMappingAccessBit::InvalidateBuffer;
|
||||||
|
|
||||||
if (!Any(accessBits & invalidateFlags)) {
|
if (!(accessBits & invalidateFlags)) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
|
||||||
"Cannot map a buffer object that is already mapped."));
|
"Cannot map a buffer object that is already mapped."));
|
||||||
@@ -280,7 +280,7 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto isIllegallyMapped = [](const SharedPtr<MG_State::GLState::BufferObject>& buffer) {
|
auto isIllegallyMapped = [](const SharedPtr<MG_State::GLState::BufferObject>& buffer) {
|
||||||
return buffer->IsMapped() && !Any(buffer->GetMappingAccess() & BufferMappingAccessBit::Persistent);
|
return buffer->IsMapped() && !(buffer->GetMappingAccess() & BufferMappingAccessBit::Persistent);
|
||||||
};
|
};
|
||||||
if (isIllegallyMapped(readBufferObject) || isIllegallyMapped(writeBufferObject)) {
|
if (isIllegallyMapped(readBufferObject) || isIllegallyMapped(writeBufferObject)) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
@@ -328,8 +328,8 @@ namespace MobileGL {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMappingAccessBit mappingAccess = bufferObject->GetMappingAccess();
|
auto mappingAccess = bufferObject->GetMappingAccess();
|
||||||
if (bufferObject->IsMapped() && !Any(mappingAccess & BufferMappingAccessBit::Persistent)) {
|
if (bufferObject->IsMapped() && !(mappingAccess & BufferMappingAccessBit::Persistent)) {
|
||||||
Range1D mappedRange = bufferObject->GetMappedRange();
|
Range1D mappedRange = bufferObject->GetMappedRange();
|
||||||
if (offset + size >= mappedRange.start) {
|
if (offset + size >= mappedRange.start) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValidateBufferMappingAccess(BufferMappingAccessBit accessBits) {
|
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits) {
|
||||||
if (accessBits == BufferMappingAccessBit::Null) {
|
if (accessBits == BufferMappingAccessBit::Null) {
|
||||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
|
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
|
||||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferMappingAccess",
|
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferMappingAccess",
|
||||||
@@ -56,7 +56,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BufferMappingAccessBit validBits =
|
const auto validBits =
|
||||||
BufferMappingAccessBit::Read |
|
BufferMappingAccessBit::Read |
|
||||||
BufferMappingAccessBit::Write |
|
BufferMappingAccessBit::Write |
|
||||||
BufferMappingAccessBit::InvalidateRange |
|
BufferMappingAccessBit::InvalidateRange |
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
|||||||
bool ValidateBufferTarget(BufferTarget target);
|
bool ValidateBufferTarget(BufferTarget target);
|
||||||
bool ValidateBufferName(Uint index);
|
bool ValidateBufferName(Uint index);
|
||||||
bool ValidateBufferUsage(BufferUsage usage);
|
bool ValidateBufferUsage(BufferUsage usage);
|
||||||
bool ValidateBufferMappingAccess(BufferMappingAccessBit accessBits);
|
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,8 +30,8 @@ namespace MobileGL {
|
|||||||
void BufferObject::ReleaseMemory() {
|
void BufferObject::ReleaseMemory() {
|
||||||
if (!m_isMapped) return;
|
if (!m_isMapped) return;
|
||||||
|
|
||||||
if (Any(m_mappingAccess & BufferMappingAccessBit::Write)) { // if we wrote to the buffer
|
if (m_mappingAccess & BufferMappingAccessBit::Write) { // if we wrote to the buffer
|
||||||
if (!Any(m_mappingAccess & BufferMappingAccessBit::FlushExplicit)) { // if we didn't flush explicitly
|
if (!(m_mappingAccess & BufferMappingAccessBit::FlushExplicit)) { // if we didn't flush explicitly
|
||||||
memcpy(m_data.data() + m_mappedRange.start,
|
memcpy(m_data.data() + m_mappedRange.start,
|
||||||
m_stagingData.data(),
|
m_stagingData.data(),
|
||||||
m_mappedRange.end - m_mappedRange.start);
|
m_mappedRange.end - m_mappedRange.start);
|
||||||
@@ -49,8 +49,8 @@ namespace MobileGL {
|
|||||||
|
|
||||||
void BufferObject::FlushMemoryRange(SizeT offset, SizeT length) {
|
void BufferObject::FlushMemoryRange(SizeT offset, SizeT length) {
|
||||||
assert(m_isMapped);
|
assert(m_isMapped);
|
||||||
assert(Any(m_mappingAccess & BufferMappingAccessBit::FlushExplicit));
|
assert((m_mappingAccess & BufferMappingAccessBit::FlushExplicit));
|
||||||
assert(Any(m_mappingAccess & BufferMappingAccessBit::Write));
|
assert((m_mappingAccess & BufferMappingAccessBit::Write));
|
||||||
|
|
||||||
SizeT start = m_mappedRange.start + offset;
|
SizeT start = m_mappedRange.start + offset;
|
||||||
SizeT end = start + length;
|
SizeT end = start + length;
|
||||||
@@ -82,16 +82,17 @@ namespace MobileGL {
|
|||||||
void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) {
|
void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) {
|
||||||
if (markMapped) {
|
if (markMapped) {
|
||||||
m_isMapped = true;
|
m_isMapped = true;
|
||||||
|
auto a = BufferMappingAccessBit::Coherent | BufferMappingAccessBit::Read;
|
||||||
m_mappingAccess =
|
m_mappingAccess =
|
||||||
(read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
|
(read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
|
||||||
(write ? BufferMappingAccessBit::Write : BufferMappingAccessBit::Null);
|
(write ? BufferMappingAccessBit::Write : BufferMappingAccessBit::Null);
|
||||||
m_mappedRange = { 0, m_size };
|
m_mappedRange = { 0, m_size };
|
||||||
|
|
||||||
if (Any(m_mappingAccess & BufferMappingAccessBit::Write)) {
|
if (m_mappingAccess & BufferMappingAccessBit::Write) {
|
||||||
m_stagingData.resize(m_size);
|
m_stagingData.resize(m_size);
|
||||||
m_ownsStagingData = true;
|
m_ownsStagingData = true;
|
||||||
|
|
||||||
if (!Any(m_mappingAccess & (BufferMappingAccessBit::InvalidateRange |
|
if (!(m_mappingAccess & (BufferMappingAccessBit::InvalidateRange |
|
||||||
BufferMappingAccessBit::InvalidateBuffer))) {
|
BufferMappingAccessBit::InvalidateBuffer))) {
|
||||||
memcpy(m_stagingData.data(), m_data.data(), m_size);
|
memcpy(m_stagingData.data(), m_data.data(), m_size);
|
||||||
}
|
}
|
||||||
@@ -103,17 +104,17 @@ namespace MobileGL {
|
|||||||
return m_data.data();
|
return m_data.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void* BufferObject::AcquireMemoryRange(Range1D range, BufferMappingAccessBit access) {
|
void* BufferObject::AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access) {
|
||||||
assert(range.end <= m_size && range.start <= range.end);
|
assert(range.end <= m_size && range.start <= range.end);
|
||||||
m_isMapped = true;
|
m_isMapped = true;
|
||||||
m_mappingAccess = access;
|
m_mappingAccess = access;
|
||||||
m_mappedRange = range;
|
m_mappedRange = range;
|
||||||
|
|
||||||
if (Any(access & BufferMappingAccessBit::Write)) {
|
if (access & BufferMappingAccessBit::Write) {
|
||||||
m_stagingData.resize(range.end - range.start);
|
m_stagingData.resize(range.end - range.start);
|
||||||
m_ownsStagingData = true;
|
m_ownsStagingData = true;
|
||||||
|
|
||||||
if (!Any(access & (BufferMappingAccessBit::InvalidateRange |
|
if (!(access & (BufferMappingAccessBit::InvalidateRange |
|
||||||
BufferMappingAccessBit::InvalidateBuffer))) {
|
BufferMappingAccessBit::InvalidateBuffer))) {
|
||||||
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
|
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
|
||||||
}
|
}
|
||||||
@@ -150,7 +151,7 @@ namespace MobileGL {
|
|||||||
return m_isMapped ? m_mappedRange : Range1D{ 0, 0 };
|
return m_isMapped ? m_mappedRange : Range1D{ 0, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMappingAccessBit BufferObject::GetMappingAccess() const {
|
Flags<BufferMappingAccessBit> BufferObject::GetMappingAccess() const {
|
||||||
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
|
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "MG_Util/Types.h"
|
||||||
|
|
||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
enum class BufferTarget {
|
enum class BufferTarget {
|
||||||
@@ -45,25 +46,23 @@ namespace MobileGL {
|
|||||||
Coherent = 0x80
|
Coherent = 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
inline BufferMappingAccessBit operator|(BufferMappingAccessBit a, BufferMappingAccessBit b) {
|
// inline Flags<BufferMappingAccessBit> operator|(BufferMappingAccessBit a, const BufferMappingAccessBit b) {
|
||||||
using T = std::underlying_type_t<BufferMappingAccessBit>;
|
// return Flags(a) | b;
|
||||||
return static_cast<BufferMappingAccessBit>(static_cast<T>(a) | static_cast<T>(b));
|
// }
|
||||||
}
|
//
|
||||||
|
// inline BufferMappingAccessBit& operator|=(BufferMappingAccessBit& a, BufferMappingAccessBit b) {
|
||||||
|
// a = a | b;
|
||||||
|
// return a;
|
||||||
|
// }
|
||||||
|
|
||||||
inline BufferMappingAccessBit& operator|=(BufferMappingAccessBit& a, BufferMappingAccessBit b) {
|
// inline Flags<BufferMappingAccessBit> operator&(const BufferMappingAccessBit a, const BufferMappingAccessBit b) {
|
||||||
a = a | b;
|
// return Flags(a) & b;
|
||||||
return a;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
inline BufferMappingAccessBit operator&(BufferMappingAccessBit a, BufferMappingAccessBit b) {
|
// inline bool Any(BufferMappingAccessBit a) {
|
||||||
using T = std::underlying_type_t<BufferMappingAccessBit>;
|
// using T = std::underlying_type_t<BufferMappingAccessBit>;
|
||||||
return static_cast<BufferMappingAccessBit>(static_cast<T>(a) & static_cast<T>(b));
|
// return static_cast<T>(a) != 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline bool Any(BufferMappingAccessBit a) {
|
|
||||||
using T = std::underlying_type_t<BufferMappingAccessBit>;
|
|
||||||
return static_cast<T>(a) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MG_State {
|
namespace MG_State {
|
||||||
namespace GLState {
|
namespace GLState {
|
||||||
@@ -77,7 +76,7 @@ namespace MobileGL {
|
|||||||
void UploadData(DataPtr data, SizeT atOffset);
|
void UploadData(DataPtr data, SizeT atOffset);
|
||||||
void SetUsage(BufferUsage usage);
|
void SetUsage(BufferUsage usage);
|
||||||
void* AcquireMemory(Bool markMapped, Bool read, Bool write);
|
void* AcquireMemory(Bool markMapped, Bool read, Bool write);
|
||||||
void* AcquireMemoryRange(Range1D range, BufferMappingAccessBit access);
|
void* AcquireMemoryRange(Range1D range, Flags<BufferMappingAccessBit> access);
|
||||||
void ReleaseMemory();
|
void ReleaseMemory();
|
||||||
void FlushMemoryRange(SizeT offset, SizeT length);
|
void FlushMemoryRange(SizeT offset, SizeT length);
|
||||||
void UploadSubData(DataPtr data, SizeT atOffset);
|
void UploadSubData(DataPtr data, SizeT atOffset);
|
||||||
@@ -89,14 +88,14 @@ namespace MobileGL {
|
|||||||
BufferUsage GetUsage() const;
|
BufferUsage GetUsage() const;
|
||||||
Range1D GetDirtyRange() const;
|
Range1D GetDirtyRange() const;
|
||||||
Range1D GetMappedRange() const;
|
Range1D GetMappedRange() const;
|
||||||
BufferMappingAccessBit GetMappingAccess() const;
|
Flags<BufferMappingAccessBit> GetMappingAccess() const;
|
||||||
private:
|
private:
|
||||||
Int m_id = 0;
|
Int m_id = 0;
|
||||||
SizeT m_size = 0;
|
SizeT m_size = 0;
|
||||||
BufferUsage m_usage = BufferUsage::StaticDraw;
|
BufferUsage m_usage = BufferUsage::StaticDraw;
|
||||||
Data m_data;
|
Data m_data;
|
||||||
Bool m_isMapped;
|
Bool m_isMapped;
|
||||||
BufferMappingAccessBit m_mappingAccess;
|
Flags<BufferMappingAccessBit> m_mappingAccess;
|
||||||
Range1D m_dirtyRange;
|
Range1D m_dirtyRange;
|
||||||
Range1D m_mappedRange;
|
Range1D m_mappedRange;
|
||||||
std::vector<Uint8> m_stagingData;
|
std::vector<Uint8> m_stagingData;
|
||||||
@@ -104,4 +103,4 @@ namespace MobileGL {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMappingAccessBit ConvertGLEnumToBufferMappingAccess(GLbitfield access) {
|
Flags<BufferMappingAccessBit> ConvertGLEnumToBufferMappingAccess(GLbitfield access) {
|
||||||
BufferMappingAccessBit result = BufferMappingAccessBit::Null;
|
Flags result = BufferMappingAccessBit::Null;
|
||||||
if (access & GL_MAP_READ_BIT) result |= BufferMappingAccessBit::Read;
|
if (access & GL_MAP_READ_BIT) result |= BufferMappingAccessBit::Read;
|
||||||
if (access & GL_MAP_WRITE_BIT) result |= BufferMappingAccessBit::Write;
|
if (access & GL_MAP_WRITE_BIT) result |= BufferMappingAccessBit::Write;
|
||||||
if (access & GL_MAP_INVALIDATE_RANGE_BIT) result |= BufferMappingAccessBit::InvalidateRange;
|
if (access & GL_MAP_INVALIDATE_RANGE_BIT) result |= BufferMappingAccessBit::InvalidateRange;
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ namespace MobileGL {
|
|||||||
namespace MG_Util {
|
namespace MG_Util {
|
||||||
BufferTarget ConvertGLEnumToBufferTarget(GLenum bufferTarget);
|
BufferTarget ConvertGLEnumToBufferTarget(GLenum bufferTarget);
|
||||||
BufferUsage ConvertGLEnumToBufferUsage(GLenum usage);
|
BufferUsage ConvertGLEnumToBufferUsage(GLenum usage);
|
||||||
BufferMappingAccessBit ConvertGLEnumToBufferMappingAccess(GLbitfield access);
|
Flags<BufferMappingAccessBit> ConvertGLEnumToBufferMappingAccess(GLbitfield access);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,14 +40,14 @@ namespace MobileGL {
|
|||||||
|
|
||||||
GLbitfield ConvertBufferMappingAccessToGLEnum(BufferMappingAccessBit access) {
|
GLbitfield ConvertBufferMappingAccessToGLEnum(BufferMappingAccessBit access) {
|
||||||
GLbitfield result = 0;
|
GLbitfield result = 0;
|
||||||
if (Any(access & BufferMappingAccessBit::Read)) result |= GL_MAP_READ_BIT;
|
if (access & BufferMappingAccessBit::Read) result |= GL_MAP_READ_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::Write)) result |= GL_MAP_WRITE_BIT;
|
if (access & BufferMappingAccessBit::Write) result |= GL_MAP_WRITE_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::InvalidateRange)) result |= GL_MAP_INVALIDATE_RANGE_BIT;
|
if (access & BufferMappingAccessBit::InvalidateRange) result |= GL_MAP_INVALIDATE_RANGE_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::InvalidateBuffer)) result |= GL_MAP_INVALIDATE_BUFFER_BIT;
|
if (access & BufferMappingAccessBit::InvalidateBuffer) result |= GL_MAP_INVALIDATE_BUFFER_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::FlushExplicit)) result |= GL_MAP_FLUSH_EXPLICIT_BIT;
|
if (access & BufferMappingAccessBit::FlushExplicit) result |= GL_MAP_FLUSH_EXPLICIT_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::Unsynchronized)) result |= GL_MAP_UNSYNCHRONIZED_BIT;
|
if (access & BufferMappingAccessBit::Unsynchronized) result |= GL_MAP_UNSYNCHRONIZED_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::Persistent)) result |= GL_MAP_PERSISTENT_BIT;
|
if (access & BufferMappingAccessBit::Persistent) result |= GL_MAP_PERSISTENT_BIT;
|
||||||
if (Any(access & BufferMappingAccessBit::Coherent)) result |= GL_MAP_COHERENT_BIT;
|
if (access & BufferMappingAccessBit::Coherent) result |= GL_MAP_COHERENT_BIT;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,16 +38,16 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ConvertBufferMappingAccessToString(BufferMappingAccessBit access) {
|
String ConvertBufferMappingAccessToString(Flags<BufferMappingAccessBit> access) {
|
||||||
String result = "[";
|
String result = "[";
|
||||||
if (Any(access & BufferMappingAccessBit::Read)) result += "Read, ";
|
if (access & BufferMappingAccessBit::Read) result += "Read, ";
|
||||||
if (Any(access & BufferMappingAccessBit::Write)) result += "Write, ";
|
if (access & BufferMappingAccessBit::Write) result += "Write, ";
|
||||||
if (Any(access & BufferMappingAccessBit::InvalidateRange)) result += "InvalidateRange, ";
|
if (access & BufferMappingAccessBit::InvalidateRange) result += "InvalidateRange, ";
|
||||||
if (Any(access & BufferMappingAccessBit::InvalidateBuffer)) result += "InvalidateBuffer, ";
|
if (access & BufferMappingAccessBit::InvalidateBuffer) result += "InvalidateBuffer, ";
|
||||||
if (Any(access & BufferMappingAccessBit::FlushExplicit)) result += "FlushExplicit, ";
|
if (access & BufferMappingAccessBit::FlushExplicit) result += "FlushExplicit, ";
|
||||||
if (Any(access & BufferMappingAccessBit::Unsynchronized)) result += "Unsynchronized, ";
|
if (access & BufferMappingAccessBit::Unsynchronized) result += "Unsynchronized, ";
|
||||||
if (Any(access & BufferMappingAccessBit::Persistent)) result += "Persistent, ";
|
if (access & BufferMappingAccessBit::Persistent) result += "Persistent, ";
|
||||||
if (Any(access & BufferMappingAccessBit::Coherent)) result += "Coherent, ";
|
if (access & BufferMappingAccessBit::Coherent) result += "Coherent, ";
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
result.pop_back();
|
result.pop_back();
|
||||||
result += "]";
|
result += "]";
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ namespace MobileGL {
|
|||||||
namespace MG_Util {
|
namespace MG_Util {
|
||||||
String ConvertBufferTargetToString(BufferTarget bufferTarget);
|
String ConvertBufferTargetToString(BufferTarget bufferTarget);
|
||||||
String ConvertBufferUsageToString(BufferUsage usage);
|
String ConvertBufferUsageToString(BufferUsage usage);
|
||||||
String ConvertBufferMappingAccessToString(BufferMappingAccessBit access);
|
String ConvertBufferMappingAccessToString(Flags<BufferMappingAccessBit> access);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,15 @@ namespace MobileGL {
|
|||||||
|
|
||||||
struct EmptyType {};
|
struct EmptyType {};
|
||||||
|
|
||||||
|
enum class ShaderCompileBits : Uint {
|
||||||
|
EmitDiscardAsDemote = 1 << 0,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
struct ShaderAttrib {
|
struct ShaderAttrib {
|
||||||
GLenum shaderType;
|
GLenum shaderType;
|
||||||
String sourceStr;
|
String sourceStr;
|
||||||
|
Flags<ShaderCompileBits> flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProgramAttrib {
|
struct ProgramAttrib {
|
||||||
|
|||||||
@@ -172,6 +172,93 @@ namespace MobileGL {
|
|||||||
GLInfo RendererGLInfo;
|
GLInfo RendererGLInfo;
|
||||||
BackendCap BackendCapability;
|
BackendCap BackendCapability;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Bit, typename Underlying =
|
||||||
|
std::enable_if<std::is_scoped_enum_v<Bit>, std::underlying_type_t<Bit>>
|
||||||
|
>
|
||||||
|
class Flags {
|
||||||
|
public:
|
||||||
|
Flags() = default;
|
||||||
|
|
||||||
|
Flags(Bit b): flags(static_cast<typename Underlying::type>(b)) {}
|
||||||
|
|
||||||
|
Flags(typename Underlying::type b): flags(b) {}
|
||||||
|
|
||||||
|
// Flags - Bit
|
||||||
|
Flags operator|(const Bit b) const {
|
||||||
|
return Flags(flags | static_cast<typename Underlying::type>(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags operator&(const Bit b) const {
|
||||||
|
return Flags(flags & static_cast<typename Underlying::type>(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags& operator|=(const Bit b) {
|
||||||
|
flags |= static_cast<typename Underlying::type>(b);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags& operator&=(const Bit b) {
|
||||||
|
flags &= static_cast<typename Underlying::type>(b);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Bit b) const {
|
||||||
|
return flags == static_cast<typename Underlying::type>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Bit b) const {
|
||||||
|
return !(*this == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flags - Flags
|
||||||
|
Flags operator|(const Flags b) const {
|
||||||
|
return Flags(flags | b.flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags operator&(const Flags b) const {
|
||||||
|
return Flags(flags & b.flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags& operator|=(Flags b) {
|
||||||
|
flags |= b.flags;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Flags& operator&=(Flags b) {
|
||||||
|
flags &= b.flags;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Flags b) const {
|
||||||
|
return flags == b.flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Flags b) const {
|
||||||
|
return !(*this == b);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator bool() const {
|
||||||
|
return Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool Any() const {
|
||||||
|
return static_cast<typename Underlying::type>(flags) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
typename Underlying::type flags = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Bit, typename = std::enable_if_t<std::is_scoped_enum_v<Bit>>>
|
||||||
|
Flags<Bit> operator|(const Bit lhs, const Bit rhs) {
|
||||||
|
return Flags<Bit>(lhs) | rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Bit, typename = std::enable_if_t<std::is_scoped_enum_v<Bit>>>
|
||||||
|
Flags<Bit> operator&(const Bit lhs, const Bit rhs) {
|
||||||
|
return Flags<Bit>(lhs) & rhs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "../MG_Util/ShaderTranspiler/Types.h"
|
#include "../MG_Util/ShaderTranspiler/Types.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user