mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Improvement] (...): Optimize code.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Impl::EGLImpl {
|
||||
// TODO: Implement complete EGL functionality
|
||||
// TODO: implement complete EGL functionality
|
||||
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
const EGLint* attrib_list) {
|
||||
|
||||
@@ -216,8 +216,8 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
void* MapBuffer_State(GLenum target, GLenum access) {
|
||||
bool readable = access == GL_READ_ONLY || access == GL_READ_WRITE;
|
||||
bool writable = access == GL_WRITE_ONLY || access == GL_READ_WRITE;
|
||||
Bool readable = access == GL_READ_ONLY || access == GL_READ_WRITE;
|
||||
Bool writable = access == GL_WRITE_ONLY || access == GL_READ_WRITE;
|
||||
if (access != GL_READ_ONLY && access != GL_WRITE_ONLY && access != GL_READ_WRITE) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidEnum,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace MobileGL::MG_Impl::GLImpl {
|
||||
namespace BufferImpl {
|
||||
bool ValidateBufferTarget(BufferTarget target) {
|
||||
Bool ValidateBufferTarget(BufferTarget target) {
|
||||
if (target == BufferTarget::Unknown) {
|
||||
using namespace MG_Util;
|
||||
String bufferTargetStr = ConvertBufferTargetToString(target);
|
||||
@@ -31,8 +31,8 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateBufferName(Uint index) {
|
||||
bool isValid = MG_State::pGLContext->ValidateBufferName(index);
|
||||
Bool ValidateBufferName(Uint index) {
|
||||
Bool isValid = MG_State::pGLContext->ValidateBufferName(index);
|
||||
if (isValid) return true;
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
@@ -41,7 +41,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ValidateBufferUsage(BufferUsage usage) {
|
||||
Bool ValidateBufferUsage(BufferUsage usage) {
|
||||
if (usage != BufferUsage::Unknown) {
|
||||
return true;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits) {
|
||||
Bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits) {
|
||||
if (accessBits == BufferMappingAccessBit::Null) {
|
||||
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
|
||||
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl",
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
namespace MobileGL::MG_Impl::GLImpl {
|
||||
namespace BufferImpl {
|
||||
bool ValidateBufferTarget(BufferTarget target);
|
||||
bool ValidateBufferName(Uint index);
|
||||
bool ValidateBufferUsage(BufferUsage usage);
|
||||
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits);
|
||||
Bool ValidateBufferTarget(BufferTarget target);
|
||||
Bool ValidateBufferName(Uint index);
|
||||
Bool ValidateBufferUsage(BufferUsage usage);
|
||||
Bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits);
|
||||
} // namespace BufferImpl
|
||||
} // namespace MobileGL::MG_Impl::GLImpl
|
||||
@@ -78,7 +78,7 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
static Vector<String> extStrings;
|
||||
static bool initialized = false;
|
||||
static Bool initialized = false;
|
||||
if (!initialized) {
|
||||
extStrings.reserve(exts.size());
|
||||
for (const auto& ext : exts) {
|
||||
@@ -93,7 +93,7 @@ namespace MobileGL {
|
||||
void GetIntegerv(GLenum pname, GLint* params) {
|
||||
MGLOG_D("glGetIntegerv, pname: %s", MG_Util::ConvertGLEnumToString(pname).c_str());
|
||||
if (!params) {
|
||||
// TODO: Report GL_INVALID_VALUE.
|
||||
// TODO: report GL_INVALID_VALUE.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace MobileGL {
|
||||
// Others...
|
||||
default:
|
||||
MGLOG_E("glGetIntegerv: Invalid enum %s (0x%X)", MG_Util::ConvertGLEnumToString(pname).c_str(), pname);
|
||||
// TODO: Report GL_INVALID_ENUM.
|
||||
// TODO: report GL_INVALID_ENUM.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace MobileGL {
|
||||
vao->EnableAttribute(index);
|
||||
}
|
||||
|
||||
// TODO: Implement GL_BGRA support
|
||||
// TODO: implement GL_BGRA support
|
||||
void VertexAttribIPointer_State(GLuint index, GLint size, GLenum type, GLsizei stride, const void* pointer) {
|
||||
if (!VertexArrayImpl::ValidateVertexAttributeIndex(index)) return;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace MobileGL {
|
||||
vao->BindAttributeBuffer(index, vbo);
|
||||
}
|
||||
|
||||
// TODO: Implement GL_BGRA support
|
||||
// TODO: implement GL_BGRA support
|
||||
void VertexAttribPointer_State(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
|
||||
const void* pointer) {
|
||||
if (!VertexArrayImpl::ValidateVertexAttributeIndex(index)) return;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace MobileGL::MG_Impl::GLImpl {
|
||||
namespace VertexArrayImpl {
|
||||
|
||||
bool ValidateVertexArrayName(Uint index) {
|
||||
Bool ValidateVertexArrayName(Uint index) {
|
||||
if (index == 0) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexArrayName",
|
||||
@@ -15,7 +15,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isValid = MG_State::pGLContext->ValidateVertexArrayName(index);
|
||||
Bool isValid = MG_State::pGLContext->ValidateVertexArrayName(index);
|
||||
if (!isValid) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
@@ -26,7 +26,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateVertexArrayObject(Uint index) {
|
||||
Bool ValidateVertexArrayObject(Uint index) {
|
||||
if (!MG_State::pGLContext->ValidateVertexArrayObject(index)) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
@@ -37,7 +37,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateVertexAttributeIndex(Uint index) {
|
||||
Bool ValidateVertexAttributeIndex(Uint index) {
|
||||
if (index >= MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
@@ -50,7 +50,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateVertexAttribPointerParams(Uint index, SizeT size, DataType type, Int stride) {
|
||||
Bool ValidateVertexAttribPointerParams(Uint index, SizeT size, DataType type, Int stride) {
|
||||
if (size < 1 || size > 4) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
namespace MobileGL::MG_Impl::GLImpl {
|
||||
namespace VertexArrayImpl {
|
||||
bool ValidateVertexArrayName(Uint index);
|
||||
bool ValidateVertexArrayObject(Uint index);
|
||||
bool ValidateVertexAttributeIndex(Uint index);
|
||||
bool ValidateVertexAttribPointerParams(Uint index, SizeT size, DataType type, Int stride);
|
||||
Bool ValidateVertexArrayName(Uint index);
|
||||
Bool ValidateVertexArrayObject(Uint index);
|
||||
Bool ValidateVertexAttributeIndex(Uint index);
|
||||
Bool ValidateVertexAttribPointerParams(Uint index, SizeT size, DataType type, Int stride);
|
||||
} // namespace VertexArrayImpl
|
||||
} // namespace MobileGL::MG_Impl::GLImpl
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "LookUp.h"
|
||||
|
||||
namespace MG_Impl::GLXImpl {
|
||||
// TODO: Implement complete GLX functionality
|
||||
// TODO: implement complete GLX functionality
|
||||
|
||||
void* GetProcAddress(const char* name) {
|
||||
MGLOG_D("glXGetProcAddress(\"%s\")", name);
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace MobileGL {
|
||||
Range1D m_dirtyRange;
|
||||
Range1D m_mappedRange;
|
||||
std::vector<Uint8> m_stagingData;
|
||||
bool m_ownsStagingData;
|
||||
Bool m_ownsStagingData;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -53,11 +53,11 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
|
||||
bool BufferState::ValidateName(Uint index) const {
|
||||
Bool BufferState::ValidateName(Uint index) const {
|
||||
return m_indexGenerator.IsValid(index);
|
||||
}
|
||||
|
||||
bool BufferState::ValidateBufferObject(Uint index) const {
|
||||
Bool BufferState::ValidateBufferObject(Uint index) const {
|
||||
return m_bufferObjects.find(index) != m_bufferObjects.end();
|
||||
}
|
||||
} // namespace GLState
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "BufferObject.h"
|
||||
#include <MG_Util/Miscellany/IndexGenerator.h>
|
||||
#include "BufferObject.h"
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -21,8 +21,8 @@ namespace MobileGL {
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
BindingSlot<BufferObject>& GetBindingSlot(BufferTarget target);
|
||||
void MarkBufferObjectForDeletion(Uint index);
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateBufferObject(Uint index) const;
|
||||
Bool ValidateName(Uint index) const;
|
||||
Bool ValidateBufferObject(Uint index) const;
|
||||
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
|
||||
bool ErrorState::HasNonGLError() const {
|
||||
Bool ErrorState::HasNonGLError() const {
|
||||
return !m_nonGLErrors.empty();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace MobileGL {
|
||||
return Optional<const Error>{error};
|
||||
}
|
||||
|
||||
bool ErrorState::HasGLError() const {
|
||||
Bool ErrorState::HasGLError() const {
|
||||
return !m_errors.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace MobileGL {
|
||||
class ErrorState {
|
||||
public:
|
||||
void RecordError(ErrorCode code, SharedPtr<ErrorInfo> info = nullptr);
|
||||
bool HasNonGLError() const;
|
||||
Bool HasNonGLError() const;
|
||||
Optional<const Error> PeekNonGLError() const;
|
||||
Optional<Error> PopNonGLError();
|
||||
bool HasGLError() const;
|
||||
Bool HasGLError() const;
|
||||
Optional<const Error> PeekGLError() const;
|
||||
Optional<Error> PopGLError();
|
||||
void Clear();
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace MobileGL {
|
||||
// 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;
|
||||
Bool m_deleteStatus = false;
|
||||
Bool m_linkStatus = true;
|
||||
Bool m_validateStatus = true;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace MobileGL {
|
||||
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;
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace MobileGL {
|
||||
SharedPtr<glslang::TShader> m_shader;
|
||||
std::string m_infoLog;
|
||||
|
||||
bool m_deleteStatus = false;
|
||||
bool m_compileStatus = false;
|
||||
Bool m_deleteStatus = false;
|
||||
Bool m_compileStatus = false;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add other texture types as needed
|
||||
// TODO: add other texture types as needed
|
||||
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace MobileGL {
|
||||
void SetMipmapImpl(const MipmapLevelInput& level) override;
|
||||
};
|
||||
|
||||
// TODO: Add other texture types as needed
|
||||
// TODO: add other texture types as needed
|
||||
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -25,13 +25,13 @@ namespace MobileGL {
|
||||
m_attributes[index].Enabled = false;
|
||||
}
|
||||
|
||||
bool VertexArrayObject::IsAttributeEnabled(Uint index) const {
|
||||
Bool VertexArrayObject::IsAttributeEnabled(Uint index) const {
|
||||
if (index >= MAX_VERTEX_ATTRIBS) return false;
|
||||
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) {
|
||||
|
||||
@@ -6,13 +6,13 @@ namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
struct VertexAttribute {
|
||||
bool Enabled = false;
|
||||
Bool Enabled = false;
|
||||
int Size = 4;
|
||||
DataType Type = DataType::Float32;
|
||||
bool Normalized = false;
|
||||
Bool Normalized = false;
|
||||
int Stride = 0;
|
||||
SizeT Offset = 0;
|
||||
bool IsInteger = false;
|
||||
Bool IsInteger = false;
|
||||
SharedPtr<BufferObject> Buffer;
|
||||
};
|
||||
|
||||
@@ -24,10 +24,10 @@ namespace MobileGL {
|
||||
|
||||
void EnableAttribute(Uint index);
|
||||
void DisableAttribute(Uint index);
|
||||
bool IsAttributeEnabled(Uint index) const;
|
||||
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);
|
||||
|
||||
|
||||
@@ -54,11 +54,11 @@ namespace MobileGL {
|
||||
// FIXME: report GL error here?
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateName(Uint index) const {
|
||||
Bool VertexArrayState::ValidateName(Uint index) const {
|
||||
return m_indexGenerator.IsValid(index);
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateVertexArrayObject(Uint index) const {
|
||||
Bool VertexArrayState::ValidateVertexArrayObject(Uint index) const {
|
||||
return index < m_vertexArrays.size() && m_vertexArrays[index] != nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace MobileGL {
|
||||
void Bind(Uint index);
|
||||
SharedPtr<VertexArrayObject> CreateVertexArrayObject(Uint index);
|
||||
void MarkVertexArrayForDeletion(Uint index);
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateVertexArrayObject(Uint index) const;
|
||||
Bool ValidateName(Uint index) const;
|
||||
Bool ValidateVertexArrayObject(Uint index) const;
|
||||
SharedPtr<VertexArrayObject> GetBoundVertexArray();
|
||||
Vector<SharedPtr<VertexArrayObject>>& GetAllVertexArrays();
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace MobileGL {
|
||||
return data[index];
|
||||
}
|
||||
|
||||
bool operator==(const VecBase& rhs) const { return data == rhs.data; }
|
||||
bool operator!=(const VecBase& rhs) const { return !(*this == rhs); }
|
||||
Bool operator==(const VecBase& rhs) const { return data == rhs.data; }
|
||||
Bool operator!=(const VecBase& rhs) const { return !(*this == rhs); }
|
||||
|
||||
Derived operator+(const VecBase& rhs) const {
|
||||
Derived result;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValid(IndexType index) const {
|
||||
Bool IsValid(IndexType index) const {
|
||||
SizeT word = index >> 6;
|
||||
SizeT bit = index & 0x3F;
|
||||
return word < is_valid_.size() && (is_valid_[word] & (1ull << bit));
|
||||
@@ -56,7 +56,7 @@ namespace MobileGL {
|
||||
SizeT ActiveCount() const { return next_index_ - freed_indices_.size(); }
|
||||
|
||||
private:
|
||||
inline void SetValid(IndexType index, bool valid) {
|
||||
inline void SetValid(IndexType index, Bool valid) {
|
||||
SizeT word = index >> 6;
|
||||
uint64_t mask = 1ull << (index & 0x3F);
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ namespace MobileGL {
|
||||
std::string name;
|
||||
uint32_t location;
|
||||
|
||||
bool operator<(const InterfaceVariable& other) const { return location < other.location; }
|
||||
Bool operator<(const InterfaceVariable& other) const { return location < other.location; }
|
||||
|
||||
bool operator==(const InterfaceVariable& other) const {
|
||||
Bool operator==(const InterfaceVariable& other) const {
|
||||
return location == other.location && name == other.name;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace MobileGL {
|
||||
using Uint = Uint32;
|
||||
using Int64 = int64_t;
|
||||
using Uint64 = uint64_t;
|
||||
using Bool = bool;
|
||||
using Bool = Bool;
|
||||
using Float = float;
|
||||
using Double = double;
|
||||
using StringView = std::string_view;
|
||||
@@ -46,7 +46,7 @@ namespace MobileGL {
|
||||
template <typename T, SizeT N>
|
||||
using Array = std::array<T, N>;
|
||||
template <typename Key, typename Value>
|
||||
using UnorderedMap = std::unordered_map<Key, Value>;
|
||||
using UnorderedMap = ankerl::unordered_dense::map<Key, Value>;
|
||||
template <typename T>
|
||||
inline constexpr std::remove_reference_t<T>&& Move(T&& t) noexcept {
|
||||
return static_cast<std::remove_reference_t<T>&&>(t);
|
||||
@@ -196,9 +196,9 @@ namespace MobileGL {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Bit b) const { return flags == static_cast<typename Underlying::type>(b); }
|
||||
Bool operator==(const Bit b) const { return flags == static_cast<typename Underlying::type>(b); }
|
||||
|
||||
bool operator!=(const Bit b) const { return !(*this == b); }
|
||||
Bool operator!=(const Bit b) const { return !(*this == b); }
|
||||
|
||||
// Flags - Flags
|
||||
Flags operator|(const Flags b) const { return Flags(flags | b.flags); }
|
||||
@@ -215,14 +215,14 @@ namespace MobileGL {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Flags b) const { return flags == b.flags; }
|
||||
Bool operator==(const Flags b) const { return flags == b.flags; }
|
||||
|
||||
bool operator!=(const Flags b) const { return !(*this == b); }
|
||||
Bool operator!=(const Flags b) const { return !(*this == b); }
|
||||
|
||||
operator bool() const { return Any(); }
|
||||
operator Bool() const { return Any(); }
|
||||
|
||||
private:
|
||||
bool Any() const { return static_cast<typename Underlying::type>(flags) != 0; }
|
||||
Bool Any() const { return static_cast<typename Underlying::type>(flags) != 0; }
|
||||
|
||||
typename Underlying::type flags = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user