[Refactor] (All): Restructure include system.

This commit is contained in:
BZLZHH
2025-08-09 23:10:34 +08:00
parent a8914c09ce
commit 93ca669929
75 changed files with 3605 additions and 3339 deletions
+8 -3
View File
@@ -10,11 +10,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fvisibility=hidden -funwind-tables -g -D_THREAD_SAFE -fPIC -stdlib=libc++")
set(PROFILING OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_library(GLSLANG_LIB glslang PATHS ${CMAKE_SOURCE_DIR}/libraries/arm64-v8a/)
add_library(${CMAKE_PROJECT_NAME} SHARED
set(SOURCE_FILES
MobileGL/Init.cpp
MobileGL/MG_Util/Debug/Log.cpp
@@ -56,6 +56,10 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp
)
add_library(${CMAKE_PROJECT_NAME} SHARED
${SOURCE_FILES}
)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/library/arm64-v8a/libglslang.a
${CMAKE_SOURCE_DIR}/library/arm64-v8a/libspirv-cross-c-shared.so
@@ -79,8 +83,9 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
# add_subdirectory(3rdparty/DiligentCore)
target_include_directories(MobileGL PUBLIC
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/MobileGL
)
target_link_libraries(MobileGL
+5 -15
View File
@@ -1,16 +1,6 @@
#pragma once
#define MOBILEGL_LOG_ACTIVE_LEVEL MOBILEGL_LOG_LEVEL_DEBUG
#define MOBILEGL_LOG_ENABLE_CONSOLE 0
#define MOBILEGL_LOG_ENABLE_FILE 1
#define MOBILEGL_LOG_ENABLE_ANDROID 1
#ifdef __ANDROID__
#define MOBILEGL_LOG_FILE_PATH "/sdcard/MG/latest.log"
#else
#define MOBILEGL_LOG_FILE_PATH ""
#endif
#include <Includes.h>
#include <MG_Backend/Backends.h>
namespace MobileGL {
namespace MG_Config {
@@ -27,6 +17,6 @@ namespace MobileGL {
inline const MG_Backend::Diligent::SpecificBackendType SpecificBackend =
MG_Backend::Diligent::SpecificBackendType::Vulkan;
}
}
}
}
} // namespace Backend
} // namespace MG_Config
} // namespace MobileGL
+41
View File
@@ -0,0 +1,41 @@
#pragma once
// ============== Platform-specific definitions and macros ============== //
#ifdef __ANDROID__
#define __ANDROID_API__ 26 // force Android API level to 26 for compatibility
#endif
#ifdef _WIN32
#define NOMINMAX // prevent Windows.h from defining min and max macros
#endif
// ================== MobileGL definitions and macros =================== //
#ifdef _WIN32
#define MOBILEGL_EXPORT extern "C" __declspec(dllexport)
#else
#define MOBILEGL_EXPORT extern "C" __attribute__((visibility("default")))
#endif
#define MOBILEGL_API MOBILEGL_EXPORT
#define MOBILEGL_GLX_API MOBILEGL_API
#define MOBILEGL_GL_API MOBILEGL_API
#define MOBILEGL_EGL_API MOBILEGL_API
#define MOBILEGL_BACKEND_TYPE_UNKNOWN 0
#define MOBILEGL_BACKEND_TYPE_DILIGENT 1
#define MOBILEGL_BACKEND_TYPE_MRHI 2
#define MOBILEGL_BACKEND_TYPE_DIRECT 3
// ====================== MobileGL configurations ======================= //
#define MOBILEGL_LOG_ACTIVE_LEVEL MOBILEGL_LOG_LEVEL_DEBUG
#define MOBILEGL_LOG_ENABLE_CONSOLE 0
#define MOBILEGL_LOG_ENABLE_FILE 1
#define MOBILEGL_LOG_ENABLE_ANDROID 1
#ifdef __ANDROID__
#define MOBILEGL_LOG_FILE_PATH "/sdcard/MG/latest.log"
#else
#define MOBILEGL_LOG_FILE_PATH ""
#endif
+56 -111
View File
@@ -1,137 +1,82 @@
#pragma once
#ifdef __ANDROID__
#define __ANDROID_API__ 26 // force Android API level to 26 for compatibility
#endif
// Include significant project headers
#include "Defines.h"
#include "MG_Util/PlatformStubs.h"
#ifdef _WIN32
#define MOBILEGL_EXPORT extern "C" __declspec(dllexport)
#else
#define MOBILEGL_EXPORT extern "C" __attribute__((visibility("default")))
#endif
#define MOBILEGL_API MOBILEGL_EXPORT
#define MOBILEGL_GLX_API MOBILEGL_API
#define MOBILEGL_GL_API MOBILEGL_API
#define MOBILEGL_EGL_API MOBILEGL_API
#define NOMINMAX // prevent Windows.h from defining min and max macros
#include <cstring>
#include <iostream>
#include <cstdio>
#include <ctime>
#include <chrono>
#include <thread>
#include <string>
#include <string_view>
// Include necessary standard headers
#include <bit>
#include <map>
#include <vector>
#include <cctype>
#include <stdexcept>
#include <atomic>
#include <regex>
#include <algorithm>
#include <array>
#include <random>
#include <optional>
#include <unordered_map>
#include <ctime>
#include <queue>
#include <regex>
#include <atomic>
#include <cctype>
#include <chrono>
#include <cstdio>
#include <format>
#include <memory>
#include <bit>
#include <random>
#include <string>
#include <thread>
#include <vector>
#include <cstdarg>
#include <functional>
#include <cstring>
#include <expected>
#include <iostream>
#include <optional>
#include <algorithm>
#include <stdexcept>
#include <functional>
#include <string_view>
#include <unordered_map>
#include <glslang/Public/ShaderLang.h>
// Include ankerl::unordered_dense
#include <ankerl/unordered_dense.h>
// Include spirv_cross
#include <spirv_cross/spirv_cross_c.h>
// Include glm
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
// Include OpenGL and EGL headers
#include <GL/gl.h>
#include <EGL/egl.h>
#include <GL/glext.h>
#include <GLES3/gl32.h>
// Include glslang headers
#include <glslang/Include/Types.h>
#include <glslang/Public/ShaderLang.h>
#include <spirv_cross/spirv_cross_c.h>
#include <glslang/Public/ShaderLang.h>
#include <glslang/SPIRV/GlslangToSpv.h>
#include <glslang/Include/intermediate.h>
#include <glslang/MachineIndependent/localintermediate.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <ankerl/unordered_dense.h>
#include <GLES3/gl32.h>
#include <EGL/egl.h>
#include <GL/gl.h>
#include <GL/glext.h>
#ifdef __ANDROID__
#include <android/log.h>
#include <pthread.h>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_android.h>
#include <android/native_window.h>
// Include headers for platform-specific functionality
#ifdef __linux__
#include <dlfcn.h>
#include <unistd.h>
#elif defined(_WIN32)
#include <pthread.h>
#endif
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <processthreadsapi.h>
#else
#endif
#ifdef __ANDROID__
#include <unistd.h>
#include <pthread.h>
#include <android/log.h>
#include <vulkan/vulkan.h>
#include <android/native_window.h>
#include <vulkan/vulkan_android.h>
#endif
#ifndef __ANDROID__
// Define a stub for __android_log_print if not on Android
#define ANDROID_LOG_UNKNOWN 0
#define ANDROID_LOG_DEFAULT 1
#define ANDROID_LOG_VERBOSE 2
#define ANDROID_LOG_DEBUG 3
#define ANDROID_LOG_INFO 4
#define ANDROID_LOG_WARN 5
#define ANDROID_LOG_ERROR 6
#define ANDROID_LOG_FATAL 7
#define ANDROID_LOG_SILENT 8
typedef int android_LogPriority;
inline int __android_log_print(int prio, const char* tag, const char* fmt, ...) { return 0; }
#endif
#include "MG_Util/GLExtensions.h"
// Post-includes for significant project headers
#include "MG_Util/Types.h"
#include "MG_Util/Miscellany/IndexGenerator.h"
#include "MG_Util/Debug/Log.h"
#include "MG_State/GLState/ErrorState/ErrorCode.h"
#include "MG_State/GLState/ErrorState/ErrorInfo.h"
#include "MG_State/GLState/ErrorState/Error.h"
#include "MG_Backend/Backends.h"
#include "Config.h"
#include "MG_Impl/GLXImpl/LookUp/LookUp.h"
#include "MG_Impl/EGLImpl/Temporary/TemporaryEGLImpl.h"
#include "MG_State/GLState/BufferState/BufferObject.h"
#include "MG_State/GLState/BufferState/BufferState.h"
#include "MG_State/GLState/VertexArrayState/VertexArrayObject.h"
#include "MG_State/GLState/VertexArrayState/VertexArrayState.h"
/* @INSERTION_POINT:HEADER_FILE_GLIMPL@ */
#include "MG_Impl/GLImpl/VertexArray/Validators.h"
#include "MG_Impl/GLImpl/VertexArray/GL_VertexArray.h"
#include "MG_Impl/GLImpl/Getter/GL_Getter.h"
#include "MG_Impl/GLImpl/Buffer/GL_Buffer.h"
#include "MG_Impl/GLImpl/Buffer/Validators.h"
#include "MG_State/GLState/Core.h"
#include "MG_Util/Converters/MGToGL/BufferEnumConverter.h"
#include "MG_Util/Converters/MGToGL/ErrorCodeConverter.h"
#include "MG_Util/Converters/MGToGL/DataTypeConverter.h"
#include "MG_Util/Converters/MGToStr/DataTypeConverter.h"
#include "MG_Util/Converters/MGToStr/BufferEnumConverter.h"
#include "MG_Util/Converters/MGToStr/GLExtensionConverter.h"
#include "MG_Util/Converters/GLToMG/BufferEnumConverter.h"
#include "MG_Util/Converters/GLToMG/DataTypeConverter.h"
#include "MG_Util/Converters/GLToStr/GLEnumConverter.h"
#include "MG_Util/Converters/GLToGlslang/GLShaderLangConverter.h"
#include "MG_Util/ShaderTranspiler/SpvcSession.h"
#include "MG_Util/ShaderTranspiler/ShaderCompiler.h"
+4 -7
View File
@@ -1,4 +1,5 @@
#include "Includes.h"
#include <MG_Backend/Backends.h>
namespace MobileGL {
void MG_Initialize() {
@@ -25,12 +26,8 @@ namespace MobileGL {
#endif
#ifdef _WIN32
BOOL WINAPI DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
MG_Initialize();
break;
@@ -42,4 +39,4 @@ namespace MobileGL {
return TRUE;
}
#endif
}
} // namespace MobileGL
+12 -23
View File
@@ -1,15 +1,12 @@
#pragma once
#define MOBILEGL_BACKEND_TYPE_UNKNOWN 0
#define MOBILEGL_BACKEND_TYPE_DILIGENT 1
#define MOBILEGL_BACKEND_TYPE_MRHI 2
#define MOBILEGL_BACKEND_TYPE_DIRECT 3 // the previous "ShittilyDraw"
#include <Includes.h>
#include <MG_Util/GLExtensions.h>
namespace MobileGL {
namespace MG_Backend {
namespace Unknown {
const RendererInfo RendererInfoUnknown = {
"<unknown renderer of MobileGL>",
const RendererInfo RendererInfoUnknown = {"<unknown renderer of MobileGL>",
"<unknown backend>",
", <unknown>",
{
@@ -17,9 +14,9 @@ namespace MobileGL {
{0, 0, 0},
{},
},
{ }
};
{}};
}
namespace Diligent {
enum class SpecificBackendType {
Vulkan,
@@ -30,17 +27,10 @@ namespace MobileGL {
"MobileGlued-vk",
"Diligent Engine (Vulkan)",
Nullopt,
{
{ 3, 2, 0 },
{ 4, 5, 0 },
{ V_OpenGL30, V_OpenGL31, V_OpenGL32 },
false
},
{ }
};
{{3, 2, 0}, {4, 5, 0}, {V_OpenGL30, V_OpenGL31, V_OpenGL32}, false},
{}};
const RendererInfo RendererInfoMetal = {
"MobileGlued-mtl",
const RendererInfo RendererInfoMetal = {"MobileGlued-mtl",
"Diligent Engine (Metal)",
Nullopt,
{
@@ -48,10 +38,9 @@ namespace MobileGL {
{4, 5, 0},
{V_OpenGL30, V_OpenGL31, V_OpenGL32},
},
{ }
};
}
{}};
} // namespace Diligent
void Init();
}
}
} // namespace MG_Backend
} // namespace MobileGL
+4 -3
View File
@@ -1,4 +1,5 @@
#include "../Includes.h"
#include "Backends.h"
#include <Config.h>
namespace MobileGL {
namespace MG_Config {
@@ -24,5 +25,5 @@ namespace MobileGL {
MG_Config::RendererInfoPtr = (RendererInfo*)&RendererInfoUnknown;
#endif
}
}
}
} // namespace MG_Backend
} // namespace MobileGL
@@ -1,4 +1,5 @@
#include "../../../Includes.h"
#include <Includes.h>
#include "../Temporary/TemporaryEGLImpl.h"
MOBILEGL_EGL_API EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
const EGLint* attrib_list) {
@@ -82,4 +83,3 @@ MOBILEGL_EGL_API EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig co
MOBILEGL_EGL_API __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char* name) {
return MobileGL::MG_Impl::EGLImpl::GetProcAddress(name);
}
@@ -1,4 +1,4 @@
#include "../../../Includes.h"
#include "TemporaryEGLImpl.h"
namespace MobileGL {
namespace MG_Impl::EGLImpl {
@@ -9,14 +9,13 @@ namespace MobileGL {
return (EGLSurface)1;
}
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs,
EGLint config_size, EGLint* num_config) {
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size,
EGLint* num_config) {
*num_config = 1;
return EGL_TRUE;
}
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx,
const EGLint* attrib_list) {
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list) {
return (EGLContext)1;
}
@@ -59,9 +58,22 @@ namespace MobileGL {
}
EGLBoolean GetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value) {
if (attribute == EGL_NATIVE_VISUAL_ID)
if (attribute == EGL_NATIVE_VISUAL_ID) {
#if defined(ANDROID)
*value = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
return EGL_TRUE;
#elif defined(__linux__)
*value = 0;
return EGL_TRUE;
#elif defined(_WIN32)
*value = 0;
return EGL_TRUE;
#else
*value = 0;
return EGL_FALSE;
#endif
}
return EGL_TRUE;
}
EGLBoolean BindAPI(EGLenum api) {
@@ -97,5 +109,5 @@ namespace MobileGL {
}
return (__eglMustCastToProperFunctionPointerType)proc;
}
}
}
} // namespace MG_Impl::EGLImpl
} // namespace MobileGL
@@ -1,13 +1,13 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Impl::EGLImpl {
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
const EGLint* attrib_list);
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs,
EGLint config_size, EGLint* num_config);
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx,
const EGLint* attrib_list);
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size,
EGLint* num_config);
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list);
EGLBoolean Initialize(EGLDisplay dpy, EGLint* major, EGLint* minor);
EGLDisplay GetDisplay(NativeDisplayType display);
EGLint GetError();
@@ -25,5 +25,5 @@ namespace MobileGL {
EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface draw);
EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list);
__eglMustCastToProperFunctionPointerType GetProcAddress(const char* name);
}
}
} // namespace MG_Impl::EGLImpl
} // namespace MobileGL
+104 -64
View File
@@ -1,12 +1,16 @@
#include "../../../Includes.h"
#include "GL_Buffer.h"
#include "Validators.h"
#include <MG_State/GLState/Core.h>
#include <MG_State/GLState/ErrorState/Error.h>
#include <MG_Util/Converters/GLToMG/BufferEnumConverter.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
void DeleteBuffers_State(GLsizei n, const GLuint* buffers) {
if (n < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "DeleteBuffers_State",
"n must be non-negative."));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "DeleteBuffers_State", "n must be non-negative."));
return;
}
@@ -23,12 +27,12 @@ namespace MobileGL {
if (!BufferImpl::ValidateBufferName(bufferName)) continue;
MG_State::pGLContext->MarkBufferObjectForDeletion(bufferName);
}
}
void FlushMappedBufferRange_State(GLenum target, GLintptr offset, GLsizeiptr length) {
if (length < 0 || offset < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
"Offset and length must be non-negative."));
return;
@@ -41,21 +45,24 @@ namespace MobileGL {
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
"Buffer target is bound to no buffer object."));
return;
}
if (!bufferObject->IsMapped()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
"Cannot flush a buffer object that is not mapped."));
return;
}
if (offset + length > bufferObject->GetSize()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
"Offset and length exceed buffer size."));
return;
@@ -63,8 +70,10 @@ namespace MobileGL {
auto mappingAccess = bufferObject->GetMappingAccess();
if (!(mappingAccess & BufferMappingAccessBit::FlushExplicit)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "FlushMappedBufferRange_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "FlushMappedBufferRange_State",
"Cannot flush a buffer object that is not mapped with GL_MAP_FLUSH_EXPLICIT_BIT."));
return;
}
@@ -80,14 +89,16 @@ namespace MobileGL {
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "UnmapBuffer_State",
"Buffer target is bound to no buffer object."));
return GL_FALSE;
}
if (!bufferObject->IsMapped()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "UnmapBuffer_State",
"Cannot unmap a buffer object that is not mapped."));
return GL_FALSE;
@@ -99,8 +110,8 @@ namespace MobileGL {
void* MapBufferRange_State(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) {
if (length < 0 || offset < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"Offset and length must be non-negative."));
return nullptr;
}
@@ -118,15 +129,16 @@ namespace MobileGL {
auto& bindingSlot = MG_State::pGLContext->GetBufferBindingSlot(bufferTarget);
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"Buffer target is bound to no buffer object."));
return nullptr;
}
if (offset + length > bufferObject->GetSize()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"Offset and length exceed buffer size."));
return nullptr;
}
@@ -135,7 +147,8 @@ namespace MobileGL {
if (!BufferImpl::ValidateBufferMappingAccess(accessBits)) return nullptr;
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",
"At least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT must be set."));
return nullptr;
@@ -147,8 +160,10 @@ namespace MobileGL {
BufferMappingAccessBit::Unsynchronized;
if (accessBits & invalidFlags) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "MapBufferRange_State",
"GL_MAP_READ_BIT cannot be combined with invalidation or unsynchronized flags."));
return nullptr;
}
@@ -156,30 +171,32 @@ namespace MobileGL {
if (accessBits & BufferMappingAccessBit::FlushExplicit) {
if (!(accessBits & BufferMappingAccessBit::Write)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"GL_MAP_FLUSH_EXPLICIT_BIT requires GL_MAP_WRITE_BIT."));
return nullptr;
}
}
const auto storageFlags =
BufferMappingAccessBit::Persistent | BufferMappingAccessBit::Coherent;
const auto storageFlags = BufferMappingAccessBit::Persistent | BufferMappingAccessBit::Coherent;
auto requiredFlags = accessBits & storageFlags;
if (requiredFlags) {
// 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",
"Access flags require matching storage flags in buffer."));
return nullptr;
}
if (bufferObject->IsMapped()) {
const auto invalidateFlags = BufferMappingAccessBit::InvalidateRange |
BufferMappingAccessBit::InvalidateBuffer;
const auto invalidateFlags =
BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer;
if (!(accessBits & invalidateFlags)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"Cannot map a buffer object that is already mapped."));
return nullptr;
@@ -187,11 +204,10 @@ namespace MobileGL {
}
void* result = bufferObject->AcquireMemoryRange(
{ static_cast<SizeT>(offset), static_cast<SizeT>(offset + length) },
accessBits
);
{static_cast<SizeT>(offset), static_cast<SizeT>(offset + length)}, accessBits);
if (!result) {
MG_State::pGLContext->RecordError(ErrorCode::OutOfMemory,
MG_State::pGLContext->RecordError(
ErrorCode::OutOfMemory,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBufferRange_State",
"Failed to map buffer due to insufficient memory."));
return nullptr;
@@ -203,8 +219,10 @@ namespace MobileGL {
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,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBuffer_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "MapBuffer_State",
"Access must be one of GL_READ_ONLY, GL_WRITE_ONLY, or GL_READ_WRITE."));
return nullptr;
}
@@ -215,14 +233,16 @@ namespace MobileGL {
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBuffer_State",
"Buffer target is bound to no buffer object."));
return nullptr;
}
if (bufferObject->IsMapped()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBuffer_State",
"Cannot map a buffer object that is already mapped."));
return nullptr;
@@ -230,7 +250,8 @@ namespace MobileGL {
void* result = bufferObject->AcquireMemory(true, readable, writable);
if (!result) {
MG_State::pGLContext->RecordError(ErrorCode::OutOfMemory,
MG_State::pGLContext->RecordError(
ErrorCode::OutOfMemory,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "MapBuffer_State",
"Failed to map buffer due to insufficient memory."));
return nullptr;
@@ -238,17 +259,20 @@ namespace MobileGL {
return result;
}
void CopyBufferSubData_State(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
void CopyBufferSubData_State(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset,
GLsizeiptr size) {
if (size < 0 || readOffset < 0 || writeOffset < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
"Offset and size must be non-negative."));
return;
}
BufferTarget readBufferTarget = MG_Util::ConvertGLEnumToBufferTarget(readTarget);
BufferTarget writeBufferTarget = MG_Util::ConvertGLEnumToBufferTarget(writeTarget);
if (!BufferImpl::ValidateBufferTarget(readBufferTarget) || !BufferImpl::ValidateBufferTarget(writeBufferTarget)) return;
if (!BufferImpl::ValidateBufferTarget(readBufferTarget) ||
!BufferImpl::ValidateBufferTarget(writeBufferTarget))
return;
auto& readBindingSlot = MG_State::pGLContext->GetBufferBindingSlot(readBufferTarget);
auto& writeBindingSlot = MG_State::pGLContext->GetBufferBindingSlot(writeBufferTarget);
@@ -256,14 +280,16 @@ namespace MobileGL {
auto writeBufferObject = writeBindingSlot.GetBoundObject();
if (!readBufferObject || !writeBufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
"One of the buffer targets is bound to no buffer object."));
return;
}
if (readOffset + size > readBufferObject->GetSize() || writeOffset + size > writeBufferObject->GetSize()) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
"Offset and size must be within the bounds of the buffer objects."));
return;
@@ -272,8 +298,10 @@ namespace MobileGL {
if (readBufferObject == writeBufferObject) {
if ((readOffset <= writeOffset && readOffset + size > writeOffset) ||
(writeOffset <= readOffset && writeOffset + size > readOffset)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "CopyBufferSubData_State",
"Source and destination buffers overlap in the specified ranges."));
return;
}
@@ -283,9 +311,11 @@ namespace MobileGL {
return buffer->IsMapped() && !(buffer->GetMappingAccess() & BufferMappingAccessBit::Persistent);
};
if (isIllegallyMapped(readBufferObject) || isIllegallyMapped(writeBufferObject)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "CopyBufferSubData_State",
"Cannot copy data from/to a mapped buffer object unless it was mapped with GL_MAP_PERSISTENT_BIT."));
"Cannot copy data from/to a mapped buffer object unless it was mapped "
"with GL_MAP_PERSISTENT_BIT."));
return;
}
@@ -294,15 +324,16 @@ namespace MobileGL {
void BufferSubData_State(GLenum target, GLintptr offset, GLsizeiptr size, const void* data) {
if (!data) {
MG_State::pGLContext->RecordError(ErrorCode::NoError, // somehow OpenGL does not generate an error for this
MG_State::pGLContext->RecordError(
ErrorCode::NoError, // somehow OpenGL does not generate an error for this
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
"Data pointer cannot be null."));
return;
}
if (size < 0 || offset < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
"Offset and size must be non-negative."));
return;
}
@@ -313,7 +344,8 @@ namespace MobileGL {
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
"Buffer target is bound to no buffer object."));
return;
@@ -322,8 +354,10 @@ namespace MobileGL {
SizeT bufferSize = bufferObject->GetSize();
Range1D mappedRange = bufferObject->GetMappedRange();
if ((offset < mappedRange.end) && (offset + size > mappedRange.start)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "BufferSubData_State",
"Offset and size must not overlap with the mapped range of the buffer object."));
return;
}
@@ -332,8 +366,10 @@ namespace MobileGL {
if (bufferObject->IsMapped() && !(mappingAccess & BufferMappingAccessBit::Persistent)) {
Range1D mappedRange = bufferObject->GetMappedRange();
if (offset + size >= mappedRange.start) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferSubData_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "BufferSubData_State",
"Cannot modify a mapped buffer object unless it was mapped with GL_MAP_PERSISTENT_BIT."));
return;
}
@@ -344,9 +380,9 @@ namespace MobileGL {
void BufferData_State(GLenum target, GLsizeiptr size, const void* data, GLenum usage) {
if (size < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferData_State",
"Size must be non-negative."));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferData_State", "Size must be non-negative."));
return;
}
@@ -359,7 +395,8 @@ namespace MobileGL {
auto bufferObject = bindingSlot.GetBoundObject();
if (!bufferObject) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "BufferData_State",
"Buffer target is bound to no buffer object."));
return;
@@ -389,7 +426,8 @@ namespace MobileGL {
void GenBuffers_State(GLsizei n, GLuint* buffers) {
if (n < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "GenBuffers_State", "n must be non-negative"));
return;
}
@@ -399,7 +437,8 @@ namespace MobileGL {
GLboolean IsBuffer_State(GLuint buffer) {
if (buffer == 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "IsBuffer_State",
"Buffer name 0 is not a valid buffer object."));
return GL_FALSE;
@@ -434,7 +473,8 @@ namespace MobileGL {
return MapBuffer_State(target, access);
}
void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset,
GLsizeiptr size) {
CopyBufferSubData_State(readTarget, writeTarget, readOffset, writeOffset, size);
}
@@ -453,5 +493,5 @@ namespace MobileGL {
void GenBuffers(GLsizei n, GLuint* buffers) {
GenBuffers_State(n, buffers);
}
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+5 -3
View File
@@ -1,4 +1,5 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -9,10 +10,11 @@ namespace MobileGL {
GLboolean UnmapBuffer(GLenum target);
void* MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
void* MapBuffer(GLenum target, GLenum access);
void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset,
GLsizeiptr size);
void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage);
void BindBuffer(GLenum target, GLuint buffer);
void GenBuffers(GLsizei n, GLuint* buffers);
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+31 -26
View File
@@ -1,4 +1,9 @@
#include "../../../Includes.h"
#include "Validators.h"
#include <MG_State/GLState/Core.h>
#include <MG_State/GLState/ErrorState/Error.h>
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
#include <MG_Util/Converters/MGToGL/BufferEnumConverter.h>
#include <MG_Util/Converters/MGToStr/BufferEnumConverter.h>
namespace MobileGL::MG_Impl::GLImpl {
namespace BufferImpl {
@@ -7,16 +12,18 @@ namespace MobileGL::MG_Impl::GLImpl {
using namespace MG_Util;
String bufferTargetStr = ConvertBufferTargetToString(target);
String glTargetStr = ConvertGLEnumToString(ConvertBufferTargetToGLEnum(target));
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferTarget",
std::format("Target {} ({}) is not valid.",
bufferTargetStr, glTargetStr)));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl/BufferImpl", "ValidateBufferTarget",
std::format("Target {} ({}) is not valid.", bufferTargetStr, glTargetStr)));
return false;
}
if (target == BufferTarget::Index && MG_State::pGLContext->GetBoundVertexArray() == nullptr) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferTarget",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl",
"ValidateBufferTarget",
"No vertex array object is bound."));
return false;
}
@@ -26,9 +33,9 @@ namespace MobileGL::MG_Impl::GLImpl {
bool ValidateBufferName(Uint index) {
bool isValid = MG_State::pGLContext->ValidateBufferName(index);
if (isValid)
return true;
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
if (isValid) return true;
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferName",
std::format("Buffer name {} is not valid.", index)));
return false;
@@ -41,33 +48,31 @@ namespace MobileGL::MG_Impl::GLImpl {
using namespace MG_Util;
String bufferUsageStr = ConvertBufferUsageToString(usage);
String glUsageStr = ConvertGLEnumToString(ConvertBufferUsageToGLEnum(usage));
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferUsage",
std::format("Usage {} ({}) is not one of the allowable values.",
bufferUsageStr, glUsageStr)));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl/BufferImpl", "ValidateBufferUsage",
std::format("Usage {} ({}) is not one of the allowable values.", bufferUsageStr, glUsageStr)));
return false;
}
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits) {
if (accessBits == BufferMappingAccessBit::Null) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferMappingAccess",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl",
"ValidateBufferMappingAccess",
"Access bits cannot be null."));
return false;
}
const auto validBits =
BufferMappingAccessBit::Read |
BufferMappingAccessBit::Write |
BufferMappingAccessBit::InvalidateRange |
BufferMappingAccessBit::InvalidateBuffer |
BufferMappingAccessBit::FlushExplicit |
BufferMappingAccessBit::Unsynchronized |
BufferMappingAccessBit::Persistent |
BufferMappingAccessBit::Coherent;
const auto validBits = BufferMappingAccessBit::Read | BufferMappingAccessBit::Write |
BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer |
BufferMappingAccessBit::FlushExplicit | BufferMappingAccessBit::Unsynchronized |
BufferMappingAccessBit::Persistent | BufferMappingAccessBit::Coherent;
if ((accessBits & validBits) != accessBits) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl/BufferImpl", "ValidateBufferMappingAccess",
"Access bits cannot contain invalid flags."));
return false;
@@ -75,5 +80,5 @@ namespace MobileGL::MG_Impl::GLImpl {
return true;
}
}
}
} // namespace BufferImpl
} // namespace MobileGL::MG_Impl::GLImpl
+4 -2
View File
@@ -1,4 +1,6 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/BufferState/BufferObject.h>
namespace MobileGL::MG_Impl::GLImpl {
namespace BufferImpl {
@@ -6,5 +8,5 @@ namespace MobileGL::MG_Impl::GLImpl {
bool ValidateBufferName(Uint index);
bool ValidateBufferUsage(BufferUsage usage);
bool ValidateBufferMappingAccess(Flags<BufferMappingAccessBit> accessBits);
}
}
} // namespace BufferImpl
} // namespace MobileGL::MG_Impl::GLImpl
@@ -1,4 +1,8 @@
#include "../../../Includes.h"
#include <Includes.h>
#include "../Buffer/GL_Buffer.h"
#include "../VertexArray/GL_VertexArray.h"
#include "../Getter/GL_Getter.h"
#include "../Program/GL_Program.h"
#define DECLARE_GL_FUNCTION_STUB_HEAD(type,name,...) \
MOBILEGL_GL_API type gl##name(__VA_ARGS__) {
+23 -22
View File
@@ -1,4 +1,9 @@
#include "../../../Includes.h"
#include "GL_Getter.h"
#include <Config.h>
#include <MG_State/GLState/Core.h>
#include <MG_Util/Converters/MGToGL/ErrorCodeConverter.h>
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
#include <MG_Util/Converters/MGToStr/GLExtensionConverter.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -14,8 +19,8 @@ namespace MobileGL {
case GL_VENDOR:
if (vendorString.empty()) {
if (MG_Config::RendererInfoPtr->ExtraVendor.has_value()) {
vendorString = std::format("{}{}",
MG_Config::CoreVendor, MG_Config::RendererInfoPtr->ExtraVendor.value());
vendorString =
std::format("{}{}", MG_Config::CoreVendor, MG_Config::RendererInfoPtr->ExtraVendor.value());
} else {
vendorString = MG_Config::CoreVendor;
}
@@ -23,31 +28,28 @@ namespace MobileGL {
return (const GLubyte*)vendorString.c_str();
case GL_VERSION: {
if (versionStr.empty()) {
versionStr = std::format("{} {}, {} Backend, Version {}",
versionStr =
std::format("{} {}, {} Backend, Version {}",
MG_Config::RendererInfoPtr->RendererGLInfo.TargetGLVersion.toString().c_str(),
MG_Config::ProjectName.c_str(),
MG_Config::RendererInfoPtr->BackendName.c_str(),
MG_Config::ProjectName.c_str(), MG_Config::RendererInfoPtr->BackendName.c_str(),
MG_Config::CoreVersion.toString().c_str());
}
return (const GLubyte*)versionStr.c_str();
}
case GL_RENDERER:
{
case GL_RENDERER: {
if (rendererString.empty()) {
String deviceInfo;
rendererString = std::format("{} ({}) ({})",
MG_Config::RendererInfoPtr->RendererName.c_str(),
MG_Config::CoreName.c_str(),
deviceInfo);
rendererString = std::format("{} ({}) ({})", MG_Config::RendererInfoPtr->RendererName.c_str(),
MG_Config::CoreName.c_str(), deviceInfo);
}
return (const GLubyte*)rendererString.c_str();
}
case GL_SHADING_LANGUAGE_VERSION:
if (shadingLanguageVersion.empty()) {
shadingLanguageVersion = std::format("{} MobileGL",
MG_Config::RendererInfoPtr->RendererGLInfo.TargetGLSLVersion.toString(
{ true, false }).c_str());
shadingLanguageVersion = std::format(
"{} MobileGL",
MG_Config::RendererInfoPtr->RendererGLInfo.TargetGLSLVersion.toString({true, false}).c_str());
}
return (const GLubyte*)shadingLanguageVersion.c_str();
case GL_EXTENSIONS:
@@ -88,7 +90,6 @@ namespace MobileGL {
return (const GLubyte*)extStrings[index].c_str();
}
void GetIntegerv(GLenum pname, GLint* params) {
MGLOG_D("glGetIntegerv, pname: %s", MG_Util::ConvertGLEnumToString(pname).c_str());
if (!params) {
@@ -101,8 +102,9 @@ namespace MobileGL {
case GL_CONTEXT_FLAGS:
params[0] = 0;
case GL_CONTEXT_PROFILE_MASK:
params[0] = MG_Config::RendererInfoPtr->RendererGLInfo.IsCompatibilityProfile ?
GL_CONTEXT_COMPATIBILITY_PROFILE_BIT : GL_CONTEXT_CORE_PROFILE_BIT;
params[0] = MG_Config::RendererInfoPtr->RendererGLInfo.IsCompatibilityProfile
? GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
: GL_CONTEXT_CORE_PROFILE_BIT;
break;
case GL_NUM_EXTENSIONS:
params[0] = MG_Config::RendererInfoPtr->RendererGLInfo.Extensions.size();
@@ -119,8 +121,7 @@ namespace MobileGL {
// Others...
default:
MGLOG_E("glGetIntegerv: Invalid enum %s (0x%X)",
MG_Util::ConvertGLEnumToString(pname).c_str(), pname);
MGLOG_E("glGetIntegerv: Invalid enum %s (0x%X)", MG_Util::ConvertGLEnumToString(pname).c_str(), pname);
// TODO: Report GL_INVALID_ENUM.
break;
}
@@ -130,5 +131,5 @@ namespace MobileGL {
ErrorCode errorCode = MG_State::pGLContext->PopGLError().value_or(Error{ErrorCode::NoError, nullptr}).code;
return MG_Util::ConvertErrorCodeToGLEnum(errorCode);
}
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+3 -2
View File
@@ -1,4 +1,5 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -7,5 +8,5 @@ namespace MobileGL {
const GLubyte* GetStringi(GLenum name, GLuint index);
void GetIntegerv(GLenum pname, GLint* params);
GLenum GetError();
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+184 -81
View File
@@ -1,260 +1,363 @@
#include "../../../Includes.h"
#include "GL_Program.h"
namespace MobileGL {
namespace MG_Impl::GLImpl {
void AttachShader_State(GLuint program, GLuint shader) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void BindAttribLocation_State(GLuint program, GLuint index, const GLchar* name) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void CompileShader_State(GLuint shader) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLuint CreateProgram_State(void) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLuint CreateShader_State(GLenum type) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void DeleteProgram_State(GLuint program) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void DeleteShader_State(GLuint shader) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void DetachShader_State(GLuint program, GLuint shader) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetActiveAttrib_State(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {
THROW_UNIMPL_EXCEPTION
void GetActiveAttrib_State(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size,
GLenum* type, GLchar* name) {
THROW_UNIMPL_EXCEPTION;
}
void GetActiveUniform_State(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {
THROW_UNIMPL_EXCEPTION
void GetActiveUniform_State(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size,
GLenum* type, GLchar* name) {
THROW_UNIMPL_EXCEPTION;
}
void GetAttachedShaders_State(GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLint GetAttribLocation_State(GLuint program, const GLchar* name) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetProgramiv_State(GLuint program, GLenum pname, GLint* params) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetProgramInfoLog_State(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetShaderiv_State(GLuint shader, GLenum pname, GLint* params) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetShaderInfoLog_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetShaderSource_State(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLint GetUniformLocation_State(GLuint program, const GLchar* name) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetUniformfv_State(GLuint program, GLint location, GLfloat* params) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void GetUniformiv_State(GLuint program, GLint location, GLint* params) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLboolean IsProgram_State(GLuint program) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
GLboolean IsShader_State(GLuint shader) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void LinkProgram_State(GLuint program) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void ShaderSource_State(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void UseProgram_State(GLuint program) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform1f_State(GLint location, GLfloat v0) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform2f_State(GLint location, GLfloat v0, GLfloat v1) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform3f_State(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform4f_State(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform1i_State(GLint location, GLint v0) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform2i_State(GLint location, GLint v0, GLint v1) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform3i_State(GLint location, GLint v0, GLint v1, GLint v2) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform4i_State(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform1fv_State(GLint location, GLsizei count, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform2fv_State(GLint location, GLsizei count, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform3fv_State(GLint location, GLsizei count, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform4fv_State(GLint location, GLsizei count, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform1iv_State(GLint location, GLsizei count, const GLint* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform2iv_State(GLint location, GLsizei count, const GLint* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform3iv_State(GLint location, GLsizei count, const GLint* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void Uniform4iv_State(GLint location, GLsizei count, const GLint* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void UniformMatrix2fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void UniformMatrix3fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void UniformMatrix4fv_State(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void ValidateProgram_State(GLuint program) {
THROW_UNIMPL_EXCEPTION
THROW_UNIMPL_EXCEPTION;
}
void AttachShader(GLuint program, GLuint shader) {
AttachShader_State(program, shader);
}
void AttachShader(GLuint program, GLuint shader) { AttachShader_State(program, shader); }
void BindAttribLocation(GLuint program, GLuint index, const GLchar* name) {
BindAttribLocation_State(program, index, name);
}
void CompileShader(GLuint shader) { CompileShader_State(shader); }
GLuint CreateProgram(void) { return CreateProgram_State(); }
GLuint CreateShader(GLenum type) { return CreateShader_State(type); }
void DeleteProgram(GLuint program) { DeleteProgram_State(program); }
void DeleteShader(GLuint shader) { DeleteShader_State(shader); }
void DetachShader(GLuint program, GLuint shader) { DetachShader_State(program, shader); }
void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {
void CompileShader(GLuint shader) {
CompileShader_State(shader);
}
GLuint CreateProgram(void) {
return CreateProgram_State();
}
GLuint CreateShader(GLenum type) {
return CreateShader_State(type);
}
void DeleteProgram(GLuint program) {
DeleteProgram_State(program);
}
void DeleteShader(GLuint shader) {
DeleteShader_State(shader);
}
void DetachShader(GLuint program, GLuint shader) {
DetachShader_State(program, shader);
}
void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type,
GLchar* name) {
GetActiveAttrib_State(program, index, bufSize, length, size, type, name);
}
void GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) {
void GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type,
GLchar* name) {
GetActiveUniform_State(program, index, bufSize, length, size, type, name);
}
void GetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders) {
GetAttachedShaders_State(program, maxCount, count, shaders);
}
GLint GetAttribLocation(GLuint program, const GLchar* name) {
GetAttribLocation_State(program, name);
}
void GetProgramiv(GLuint program, GLenum pname, GLint* params) {
GetProgramiv_State(program, pname, params);
}
void GetProgramInfoLog(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
GetProgramInfoLog_State(program, bufSize, length, infoLog);
}
void GetShaderiv(GLuint shader, GLenum pname, GLint* params) {
GetShaderiv_State(shader, pname, params);
}
void GetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) {
GetShaderInfoLog_State(shader, bufSize, length, infoLog);
}
void GetShaderSource(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source) {
GetShaderSource_State(shader, bufSize, length, source);
}
GLint GetUniformLocation(GLuint program, const GLchar* name) {
GetUniformLocation_State(program, name);
}
void GetUniformfv(GLuint program, GLint location, GLfloat* params) {
GetUniformfv_State(program, location, params);
}
void GetUniformiv(GLuint program, GLint location, GLint* params) {
GetUniformiv_State(program, location, params);
}
GLboolean IsProgram(GLuint program) { return IsProgram_State(program); }
GLboolean IsShader(GLuint shader) { return IsShader_State(shader); }
void LinkProgram(GLuint program) { LinkProgram_State(program); }
GLboolean IsProgram(GLuint program) {
return IsProgram_State(program);
}
GLboolean IsShader(GLuint shader) {
return IsShader_State(shader);
}
void LinkProgram(GLuint program) {
LinkProgram_State(program);
}
void ShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length) {
ShaderSource_State(shader, count, string, length);
}
void UseProgram(GLuint program) { UseProgram_State(program); }
void Uniform1f(GLint location, GLfloat v0) { Uniform1f_State(location, v0); }
void Uniform2f(GLint location, GLfloat v0, GLfloat v1) { Uniform2f_State(location, v0, v1); }
void Uniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) { Uniform3f_State(location, v0, v1, v2); }
void Uniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
void Uniform1i(GLint location, GLint v0) { Uniform1i_State(location, v0); }
void Uniform2i(GLint location, GLint v0, GLint v1) { Uniform2i_State(location, v0, v1); }
void Uniform3i(GLint location, GLint v0, GLint v1, GLint v2) { Uniform3i_State(location, v0, v1, v2); }
void Uniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) { Uniform4i_State(location, v0, v1, v2, v3); }
void Uniform1fv(GLint location, GLsizei count, const GLfloat *value) { Uniform1fv_State(location, count, value); }
void Uniform2fv(GLint location, GLsizei count, const GLfloat *value) { Uniform2fv_State(location, count, value); }
void Uniform3fv(GLint location, GLsizei count, const GLfloat *value) { Uniform3fv_State(location, count, value); }
void Uniform4fv(GLint location, GLsizei count, const GLfloat *value) { Uniform4fv_State(location, count, value); }
void Uniform1iv(GLint location, GLsizei count, const GLint *value) { Uniform1iv_State(location, count, value); }
void Uniform2iv(GLint location, GLsizei count, const GLint *value) { Uniform2iv_State(location, count, value); }
void Uniform3iv(GLint location, GLsizei count, const GLint *value) { Uniform3iv_State(location, count, value); }
void Uniform4iv(GLint location, GLsizei count, const GLint *value) { Uniform4iv_State(location, count, value); }
void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { UniformMatrix2fv_State(location, count, transpose, value); }
void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { UniformMatrix3fv_State(location, count, transpose, value); }
void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) { UniformMatrix4fv_State(location, count, transpose, value); }
void ValidateProgram(GLuint program) { ValidateProgram_State(program); }
void UseProgram(GLuint program) {
UseProgram_State(program);
}
void Uniform1f(GLint location, GLfloat v0) {
Uniform1f_State(location, v0);
}
void Uniform2f(GLint location, GLfloat v0, GLfloat v1) {
Uniform2f_State(location, v0, v1);
}
void Uniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {
Uniform3f_State(location, v0, v1, v2);
}
void Uniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
Uniform4f_State(location, v0, v1, v2, v3);
}
void Uniform1i(GLint location, GLint v0) {
Uniform1i_State(location, v0);
}
void Uniform2i(GLint location, GLint v0, GLint v1) {
Uniform2i_State(location, v0, v1);
}
void Uniform3i(GLint location, GLint v0, GLint v1, GLint v2) {
Uniform3i_State(location, v0, v1, v2);
}
void Uniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {
Uniform4i_State(location, v0, v1, v2, v3);
}
void Uniform1fv(GLint location, GLsizei count, const GLfloat* value) {
Uniform1fv_State(location, count, value);
}
void Uniform2fv(GLint location, GLsizei count, const GLfloat* value) {
Uniform2fv_State(location, count, value);
}
void Uniform3fv(GLint location, GLsizei count, const GLfloat* value) {
Uniform3fv_State(location, count, value);
}
void Uniform4fv(GLint location, GLsizei count, const GLfloat* value) {
Uniform4fv_State(location, count, value);
}
void Uniform1iv(GLint location, GLsizei count, const GLint* value) {
Uniform1iv_State(location, count, value);
}
void Uniform2iv(GLint location, GLsizei count, const GLint* value) {
Uniform2iv_State(location, count, value);
}
void Uniform3iv(GLint location, GLsizei count, const GLint* value) {
Uniform3iv_State(location, count, value);
}
void Uniform4iv(GLint location, GLsizei count, const GLint* value) {
Uniform4iv_State(location, count, value);
}
void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
UniformMatrix2fv_State(location, count, transpose, value);
}
void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
UniformMatrix3fv_State(location, count, transpose, value);
}
void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
UniformMatrix4fv_State(location, count, transpose, value);
}
void ValidateProgram(GLuint program) {
ValidateProgram_State(program);
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+7 -4
View File
@@ -1,4 +1,5 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -10,8 +11,10 @@ namespace MobileGL {
void DeleteProgram(GLuint program);
void DeleteShader(GLuint shader);
void DetachShader(GLuint program, GLuint shader);
void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
void GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type,
GLchar* name);
void GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLint* size, GLenum* type,
GLchar* name);
void GetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders);
GLint GetAttribLocation(GLuint program, const GLchar* name);
void GetProgramiv(GLuint program, GLenum pname, GLint* params);
@@ -47,5 +50,5 @@ namespace MobileGL {
void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
void ValidateProgram(GLuint program);
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
@@ -1,4 +1,8 @@
#include "../../../Includes.h"
#include "GL_VertexArray.h"
#include "Validators.h"
#include <MG_State/GLState/Core.h>
#include <MG_State/GLState/ErrorState/Error.h>
#include <MG_Util/Converters/GLToMG/DataTypeConverter.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -8,7 +12,8 @@ namespace MobileGL {
auto vao = MG_State::pGLContext->GetBoundVertexArray();
if (!vao) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "EnableVertexAttribArray_State",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl",
"EnableVertexAttribArray_State",
"No vertex array object is bound."));
return;
}
@@ -22,7 +27,8 @@ namespace MobileGL {
auto vao = MG_State::pGLContext->GetBoundVertexArray();
if (!vao) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "EnableVertexAttribArray_State",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl",
"EnableVertexAttribArray_State",
"No vertex array object is bound."));
return;
}
@@ -40,7 +46,8 @@ namespace MobileGL {
auto vao = MG_State::pGLContext->GetBoundVertexArray();
if (!vao) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "VertexAttribPointer_State",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl",
"VertexAttribPointer_State",
"No vertex array object is bound."));
return;
}
@@ -48,7 +55,8 @@ namespace MobileGL {
auto& vboSlot = MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::Vertex);
auto vbo = vboSlot.GetBoundObject();
if (!vbo) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "VertexAttribPointer_State",
"No buffer is bound to GL_ARRAY_BUFFER."));
return;
@@ -61,7 +69,8 @@ namespace MobileGL {
}
// TODO: Implement GL_BGRA support
void VertexAttribPointer_State(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer) {
void VertexAttribPointer_State(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
const void* pointer) {
if (!VertexArrayImpl::ValidateVertexAttributeIndex(index)) return;
DataType dataType = MG_Util::ConvertGLEnumToDataType(type);
@@ -70,7 +79,8 @@ namespace MobileGL {
auto vao = MG_State::pGLContext->GetBoundVertexArray();
if (!vao) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "VertexAttribPointer_State",
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl",
"VertexAttribPointer_State",
"No vertex array object is bound."));
return;
}
@@ -78,7 +88,8 @@ namespace MobileGL {
auto& vboSlot = MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::Vertex);
auto vbo = vboSlot.GetBoundObject();
if (!vbo) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "VertexAttribPointer_State",
"No buffer is bound to GL_ARRAY_BUFFER."));
return;
@@ -107,8 +118,8 @@ namespace MobileGL {
void DeleteVertexArrays_State(GLsizei n, const GLuint* arrays) {
if (n < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "DeleteVertexArrays_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "DeleteVertexArrays_State",
"n must be non-negative."));
return;
}
@@ -120,8 +131,7 @@ namespace MobileGL {
if (!VertexArrayImpl::ValidateVertexArrayName(vao)) continue;
if (MG_State::pGLContext->GetBoundVertexArray() &&
MG_State::pGLContext->GetBoundVertexArray() ==
MG_State::pGLContext->GetVertexArrayObject(vao)) {
MG_State::pGLContext->GetBoundVertexArray() == MG_State::pGLContext->GetVertexArrayObject(vao)) {
MG_State::pGLContext->BindVertexArray(0);
}
@@ -131,9 +141,9 @@ namespace MobileGL {
void GenVertexArrays_State(GLsizei n, GLuint* arrays) {
if (n < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "GenVertexArrays_State",
"n must be non-negative."));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "GenVertexArrays_State", "n must be non-negative."));
return;
}
@@ -143,14 +153,15 @@ namespace MobileGL {
GLboolean IsVertexArray_State(GLuint array) {
if (array == 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "IsVertexArray_State",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "IsVertexArray_State",
"Vertex array name 0 is not supported."));
return GL_FALSE;
}
if (!VertexArrayImpl::ValidateVertexArrayName(array)) return GL_FALSE;
if (!MG_State::pGLContext->ValidateVertexArrayObject(array)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "IsVertexArray_State",
std::format("Vertex array object {} does not exist.", array)));
return GL_FALSE;
@@ -175,7 +186,8 @@ namespace MobileGL {
VertexAttribIPointer_State(index, size, type, stride, pointer);
}
void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer) {
void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
const void* pointer) {
VertexAttribPointer_State(index, size, type, normalized, stride, pointer);
}
@@ -190,5 +202,5 @@ namespace MobileGL {
void GenVertexArrays(GLsizei n, GLuint* arrays) {
GenVertexArrays_State(n, arrays);
}
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
@@ -1,4 +1,5 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -7,9 +8,10 @@ namespace MobileGL {
void DisableVertexAttribArray(GLuint index);
void EnableVertexAttribArray(GLuint index);
void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const void* pointer);
void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* pointer);
void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride,
const void* pointer);
void BindVertexArray(GLuint array);
void DeleteVertexArrays(GLsizei n, const GLuint* arrays);
void GenVertexArrays(GLsizei n, GLuint* arrays);
}
}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
@@ -1,19 +1,24 @@
#include "../../../Includes.h"
#include "Validators.h"
#include <MG_State/GLState/Core.h>
#include <MG_State/GLState/ErrorState/Error.h>
#include <MG_Util/Converters/MGToGL/DataTypeConverter.h>
#include <MG_Util/Converters/MGToStr/DataTypeConverter.h>
namespace MobileGL::MG_Impl::GLImpl {
namespace VertexArrayImpl {
bool ValidateVertexArrayName(Uint index) {
if (index == 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexArrayName",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue, MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexArrayName",
"Vertex array name 0 is not supported."));
return false;
}
bool isValid = MG_State::pGLContext->ValidateVertexArrayName(index);
if (!isValid) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexArrayName",
std::format("Vertex array name {} is not valid.", index)));
return false;
@@ -23,7 +28,8 @@ namespace MobileGL::MG_Impl::GLImpl {
bool ValidateVertexArrayObject(Uint index) {
if (!MG_State::pGLContext->ValidateVertexArrayObject(index)) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidOperation,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexArrayObject",
std::format("Vertex array object {} does not exist.", index)));
return false;
@@ -33,10 +39,12 @@ namespace MobileGL::MG_Impl::GLImpl {
bool ValidateVertexAttributeIndex(Uint index) {
if (index >= MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexAttributeIndex",
std::format("Attribute index {} exceeds maximum of {}.",
index, MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS - 1)));
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "ValidateVertexAttributeIndex",
std::format("Attribute index {} exceeds maximum of {}.", index,
MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS - 1)));
return false;
}
return true;
@@ -44,27 +52,33 @@ namespace MobileGL::MG_Impl::GLImpl {
bool ValidateVertexAttribPointerParams(Uint index, SizeT size, DataType type, Int stride) {
if (size < 1 || size > 4) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexAttribPointerParams",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "ValidateVertexAttribPointerParams",
std::format("Invalid size {} for attribute {}. Must be 1-4.", size, index)));
return false;
}
if (type == DataType::Unknown) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidEnum,
MG_State::pGLContext->RecordError(
ErrorCode::InvalidEnum,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexAttribPointerParams",
std::format("Invalid type {} for attribute {}.", MG_Util::ConvertDataTypeToString(type).c_str(), index)));
std::format("Invalid type {} for attribute {}.",
MG_Util::ConvertDataTypeToString(type).c_str(), index)));
return false;
}
if (stride < 0) {
MG_State::pGLContext->RecordError(ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateVertexAttribPointerParams",
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
MakeShared<GenericErrorInfo>(
"MG_Impl/GLImpl", "ValidateVertexAttribPointerParams",
std::format("Negative stride {} is not allowed for attribute {}.", stride, index)));
return false;
}
return true;
}
}
}
} // namespace VertexArrayImpl
} // namespace MobileGL::MG_Impl::GLImpl
@@ -1,4 +1,6 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/VertexArrayState/VertexArrayObject.h>
namespace MobileGL::MG_Impl::GLImpl {
namespace VertexArrayImpl {
@@ -6,5 +8,5 @@ namespace MobileGL::MG_Impl::GLImpl {
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,4 +1,5 @@
#include "../../../Includes.h"
#include <Includes.h>
#include "../LookUp/LookUp.h"
MOBILEGL_GLX_API void* glXGetProcAddress(const char* name) {
return MG_Impl::GLXImpl::GetProcAddress(name);
+3 -3
View File
@@ -1,7 +1,7 @@
#include "../../../Includes.h"
#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);
@@ -18,4 +18,4 @@ namespace MG_Impl::GLXImpl {
void* GetProcAddressARB(const char* name) {
return GetProcAddress(name);
}
}
} // namespace MG_Impl::GLXImpl
+3 -2
View File
@@ -1,8 +1,9 @@
#pragma once
#include <Includes.h>
namespace MG_Impl {
namespace GLXImpl {
void* GetProcAddress(const char* name);
void* GetProcAddressARB(const char* name);
}
}
} // namespace GLXImpl
} // namespace MG_Impl
@@ -1,13 +1,11 @@
#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 }) {
}
: 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;
@@ -32,8 +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_data.data() + m_mappedRange.start, m_stagingData.data(),
m_mappedRange.end - m_mappedRange.start);
m_dirtyRange.UnionUpdate(m_mappedRange.start, m_mappedRange.end);
}
@@ -68,7 +65,8 @@ namespace MobileGL {
m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size);
}
void BufferObject::CopyDataFrom(const SharedPtr<BufferObject>& src, SizeT srcOffset, SizeT dstOffset, SizeT 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());
@@ -83,8 +81,7 @@ namespace MobileGL {
if (markMapped) {
m_isMapped = true;
auto a = BufferMappingAccessBit::Coherent | BufferMappingAccessBit::Read;
m_mappingAccess =
(read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
m_mappingAccess = (read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) |
(write ? BufferMappingAccessBit::Write : BufferMappingAccessBit::Null);
m_mappedRange = {0, m_size};
@@ -92,8 +89,8 @@ namespace MobileGL {
m_stagingData.resize(m_size);
m_ownsStagingData = true;
if (!(m_mappingAccess & (BufferMappingAccessBit::InvalidateRange |
BufferMappingAccessBit::InvalidateBuffer))) {
if (!(m_mappingAccess &
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
memcpy(m_stagingData.data(), m_data.data(), m_size);
}
@@ -114,14 +111,13 @@ namespace MobileGL {
m_stagingData.resize(range.end - range.start);
m_ownsStagingData = true;
if (!(access & (BufferMappingAccessBit::InvalidateRange |
BufferMappingAccessBit::InvalidateBuffer))) {
if (!(access &
(BufferMappingAccessBit::InvalidateRange | BufferMappingAccessBit::InvalidateBuffer))) {
memcpy(m_stagingData.data(), m_data.data() + range.start, m_stagingData.size());
}
return m_stagingData.data();
}
else {
} else {
m_ownsStagingData = false;
return m_data.data() + range.start;
}
@@ -154,6 +150,6 @@ namespace MobileGL {
Flags<BufferMappingAccessBit> BufferObject::GetMappingAccess() const {
return m_isMapped ? m_mappingAccess : BufferMappingAccessBit::Null;
}
}
}
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -1,5 +1,5 @@
#pragma once
#include "MG_Util/Types.h"
#include <Includes.h>
namespace MobileGL {
enum class BufferTarget {
@@ -46,24 +46,6 @@ namespace MobileGL {
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;
// }
// inline Flags<BufferMappingAccessBit> operator&(const BufferMappingAccessBit a, const BufferMappingAccessBit b) {
// return Flags(a) & b;
// }
// inline bool Any(BufferMappingAccessBit a) {
// using T = std::underlying_type_t<BufferMappingAccessBit>;
// return static_cast<T>(a) != 0;
// }
namespace MG_State {
namespace GLState {
class BufferObject {
@@ -89,6 +71,7 @@ namespace MobileGL {
Range1D GetDirtyRange() const;
Range1D GetMappedRange() const;
Flags<BufferMappingAccessBit> GetMappingAccess() const;
private:
Int m_id = 0;
SizeT m_size = 0;
@@ -101,6 +84,6 @@ namespace MobileGL {
std::vector<Uint8> m_stagingData;
bool m_ownsStagingData;
};
}
}
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -1,10 +1,9 @@
#include "../../../Includes.h"
#include "BufferState.h"
namespace MobileGL {
namespace MG_State {
namespace GLState {
BufferState::BufferState()
: m_indexGenerator(1024, 1) {
BufferState::BufferState() : m_indexGenerator(1024, 1) {
for (SizeT i = 0; i < m_bindingSlots.size(); ++i) {
m_bindingSlots[i] = BindingSlot<BufferObject>(GlobalBufferTargets[i]);
}
@@ -61,6 +60,6 @@ namespace MobileGL {
bool BufferState::ValidateBufferObject(Uint index) const {
return m_bufferObjects.find(index) != m_bufferObjects.end();
}
}
}
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -1,22 +1,16 @@
#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);
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:
@@ -35,6 +29,6 @@ namespace MobileGL {
IndexGenerator<Uint> m_indexGenerator;
Array<BindingSlot<BufferObject>, GlobalBufferTargets.size()> m_bindingSlots;
};
}
}
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
+5 -6
View File
@@ -1,4 +1,4 @@
#include "../../Includes.h"
#include "Core.h"
namespace MobileGL {
namespace MG_State {
@@ -63,8 +63,7 @@ namespace MobileGL {
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);
@@ -120,8 +119,8 @@ namespace MobileGL {
SharedPtr<VertexArrayObject> GLContext::GetBoundVertexArray() {
return m_vertexArrayState.GetBoundVertexArray();
}
}
} // namespace GLState
GLState::GLContext* pGLContext;
}
}
} // namespace MG_State
} // namespace MobileGL
+8 -3
View File
@@ -1,4 +1,9 @@
#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 {
@@ -46,8 +51,8 @@ namespace MobileGL {
// VertexArray
VertexArrayState m_vertexArrayState;
};
}
} // namespace GLState
extern GLState::GLContext* pGLContext;
}
}
} // namespace MG_State
} // namespace MobileGL
@@ -1,15 +1,15 @@
#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 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());
MGLOG_E("Recording Non-OpenGL error:\n%s", info->ToString().c_str());
m_nonGLErrors.push_back(Error{code, info});
}
else {
} else {
MGLOG_E("Recording OpenGL error (%s):\n%s",
MG_Util::ConvertGLEnumToString(MG_Util::ConvertErrorCodeToGLEnum(code)).c_str(),
info->ToString().c_str());
@@ -53,6 +53,6 @@ namespace MobileGL {
m_errors.clear();
m_nonGLErrors.clear();
}
}
}
}
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
+6 -3
View File
@@ -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,8 +11,10 @@ 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;
@@ -24,9 +27,10 @@ namespace MobileGL {
ss << m_message;
return ss.str();
}
private:
String m_message;
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
@@ -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,5 +1,6 @@
#pragma once
#include "MG_Util/Types.h"
#include <Includes.h>
#include "ShaderObject.h"
namespace MobileGL {
namespace MG_State {
@@ -9,6 +10,7 @@ namespace MobileGL {
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
@@ -18,6 +20,6 @@ namespace MobileGL {
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 {
@@ -10,10 +11,7 @@ namespace MobileGL {
void ShaderObject::Compile() {
using namespace MG_Util::ShaderTranspiler;
ShaderAttrib attrib{
.sourceStr = m_source,
.shaderType = GetGLShaderTypeByMGLShaderStage(m_stage),
.flags = 0
};
.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",
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 {
@@ -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) {
@@ -47,8 +47,7 @@ namespace MobileGL {
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;
}
@@ -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
@@ -1,4 +1,4 @@
#include "../../../Includes.h"
#include "GLShaderLangConverter.h"
namespace MobileGL {
namespace MG_Util {
@@ -20,5 +20,5 @@ namespace MobileGL {
return EShLanguage::EShLangCount;
}
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
EShLanguage ConvertGLEnumToEShLanguage(GLenum shaderType);
}
}
} // namespace MobileGL
@@ -1,40 +1,65 @@
#include "../../../Includes.h"
#include "BufferEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
BufferTarget ConvertGLEnumToBufferTarget(GLenum bufferTarget) {
switch (bufferTarget) {
case GL_ARRAY_BUFFER: return BufferTarget::Vertex;
case GL_ELEMENT_ARRAY_BUFFER: return BufferTarget::Index;
case GL_UNIFORM_BUFFER: return BufferTarget::Uniform;
case GL_COPY_READ_BUFFER: return BufferTarget::CopyRead;
case GL_COPY_WRITE_BUFFER: return BufferTarget::CopyWrite;
case GL_PIXEL_PACK_BUFFER: return BufferTarget::PixelPack;
case GL_PIXEL_UNPACK_BUFFER: return BufferTarget::PixelUnpack;
case GL_QUERY_BUFFER: return BufferTarget::Query;
case GL_TEXTURE_BUFFER: return BufferTarget::Texture;
case GL_TRANSFORM_FEEDBACK_BUFFER: return BufferTarget::TransformFeedback;
case GL_ATOMIC_COUNTER_BUFFER: return BufferTarget::AtomicCounter;
case GL_DISPATCH_INDIRECT_BUFFER: return BufferTarget::DispatchIndirect;
case GL_DRAW_INDIRECT_BUFFER: return BufferTarget::DrawIndirect;
case GL_SHADER_STORAGE_BUFFER: return BufferTarget::ShaderStorage;
case GL_ARRAY_BUFFER:
return BufferTarget::Vertex;
case GL_ELEMENT_ARRAY_BUFFER:
return BufferTarget::Index;
case GL_UNIFORM_BUFFER:
return BufferTarget::Uniform;
case GL_COPY_READ_BUFFER:
return BufferTarget::CopyRead;
case GL_COPY_WRITE_BUFFER:
return BufferTarget::CopyWrite;
case GL_PIXEL_PACK_BUFFER:
return BufferTarget::PixelPack;
case GL_PIXEL_UNPACK_BUFFER:
return BufferTarget::PixelUnpack;
case GL_QUERY_BUFFER:
return BufferTarget::Query;
case GL_TEXTURE_BUFFER:
return BufferTarget::Texture;
case GL_TRANSFORM_FEEDBACK_BUFFER:
return BufferTarget::TransformFeedback;
case GL_ATOMIC_COUNTER_BUFFER:
return BufferTarget::AtomicCounter;
case GL_DISPATCH_INDIRECT_BUFFER:
return BufferTarget::DispatchIndirect;
case GL_DRAW_INDIRECT_BUFFER:
return BufferTarget::DrawIndirect;
case GL_SHADER_STORAGE_BUFFER:
return BufferTarget::ShaderStorage;
case GL_UNKNOWN_MGL:
default: return BufferTarget::Unknown;
default:
return BufferTarget::Unknown;
}
}
BufferUsage ConvertGLEnumToBufferUsage(GLenum usage) {
switch (usage) {
case GL_STREAM_DRAW: return BufferUsage::StreamDraw;
case GL_STREAM_READ: return BufferUsage::StreamRead;
case GL_STREAM_COPY: return BufferUsage::StreamCopy;
case GL_STATIC_DRAW: return BufferUsage::StaticDraw;
case GL_STATIC_READ: return BufferUsage::StaticRead;
case GL_STATIC_COPY: return BufferUsage::StaticCopy;
case GL_DYNAMIC_DRAW: return BufferUsage::DynamicDraw;
case GL_DYNAMIC_READ: return BufferUsage::DynamicRead;
case GL_DYNAMIC_COPY: return BufferUsage::DynamicCopy;
default: return BufferUsage::Unknown;
case GL_STREAM_DRAW:
return BufferUsage::StreamDraw;
case GL_STREAM_READ:
return BufferUsage::StreamRead;
case GL_STREAM_COPY:
return BufferUsage::StreamCopy;
case GL_STATIC_DRAW:
return BufferUsage::StaticDraw;
case GL_STATIC_READ:
return BufferUsage::StaticRead;
case GL_STATIC_COPY:
return BufferUsage::StaticCopy;
case GL_DYNAMIC_DRAW:
return BufferUsage::DynamicDraw;
case GL_DYNAMIC_READ:
return BufferUsage::DynamicRead;
case GL_DYNAMIC_COPY:
return BufferUsage::DynamicCopy;
default:
return BufferUsage::Unknown;
}
}
@@ -50,5 +75,5 @@ namespace MobileGL {
if (access & GL_MAP_COHERENT_BIT) result |= BufferMappingAccessBit::Coherent;
return result;
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,9 +1,11 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/BufferState/BufferObject.h>
namespace MobileGL {
namespace MG_Util {
BufferTarget ConvertGLEnumToBufferTarget(GLenum bufferTarget);
BufferUsage ConvertGLEnumToBufferUsage(GLenum usage);
Flags<BufferMappingAccessBit> ConvertGLEnumToBufferMappingAccess(GLbitfield access);
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,21 +1,30 @@
#include "../../../Includes.h"
#include "DataTypeConverter.h"
namespace MobileGL {
namespace MG_Util {
DataType ConvertGLEnumToDataType(GLenum type) {
switch (type) {
case GL_BYTE: return DataType::Int8;
case GL_UNSIGNED_BYTE: return DataType::Uint8;
case GL_SHORT: return DataType::Int16;
case GL_UNSIGNED_SHORT: return DataType::Uint16;
case GL_INT: return DataType::Int32;
case GL_UNSIGNED_INT: return DataType::Uint32;
case GL_HALF_FLOAT: return DataType::Float16;
case GL_FLOAT: return DataType::Float32;
case GL_DOUBLE: return DataType::Float64;
case GL_BYTE:
return DataType::Int8;
case GL_UNSIGNED_BYTE:
return DataType::Uint8;
case GL_SHORT:
return DataType::Int16;
case GL_UNSIGNED_SHORT:
return DataType::Uint16;
case GL_INT:
return DataType::Int32;
case GL_UNSIGNED_INT:
return DataType::Uint32;
case GL_HALF_FLOAT:
return DataType::Float16;
case GL_FLOAT:
return DataType::Float32;
case GL_DOUBLE:
return DataType::Float64;
default:
return DataType::Unknown;
}
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
DataType ConvertGLEnumToDataType(GLenum type);
}
}
} // namespace MobileGL
@@ -1,11 +1,12 @@
#include "../../../Includes.h"
#include "GLEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
String ConvertGLEnumToString(GLenum value) {
switch (value) {
#define CASE(value) \
case value: return #value;
case value: \
return #value;
// CASE(GL_VERSION_1_0)
// CASE(GL_VERSION_1_1)
CASE(GL_DEPTH_BUFFER_BIT)
@@ -1818,5 +1819,5 @@ namespace MobileGL {
}
#undef CASE
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
String ConvertGLEnumToString(GLenum value);
}
}
} // namespace MobileGL
@@ -1,40 +1,65 @@
#include "../../../Includes.h"
#include "BufferEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
GLenum ConvertBufferTargetToGLEnum(BufferTarget bufferTarget) {
switch (bufferTarget) {
case BufferTarget::Vertex: return GL_ARRAY_BUFFER;
case BufferTarget::Index: return GL_ELEMENT_ARRAY_BUFFER;
case BufferTarget::Uniform: return GL_UNIFORM_BUFFER;
case BufferTarget::CopyRead: return GL_COPY_READ_BUFFER;
case BufferTarget::CopyWrite: return GL_COPY_WRITE_BUFFER;
case BufferTarget::PixelPack: return GL_PIXEL_PACK_BUFFER;
case BufferTarget::PixelUnpack: return GL_PIXEL_UNPACK_BUFFER;
case BufferTarget::Query: return GL_QUERY_BUFFER;
case BufferTarget::Texture: return GL_TEXTURE_BUFFER;
case BufferTarget::TransformFeedback: return GL_TRANSFORM_FEEDBACK_BUFFER;
case BufferTarget::AtomicCounter: return GL_ATOMIC_COUNTER_BUFFER;
case BufferTarget::DispatchIndirect: return GL_DISPATCH_INDIRECT_BUFFER;
case BufferTarget::DrawIndirect: return GL_DRAW_INDIRECT_BUFFER;
case BufferTarget::ShaderStorage: return GL_SHADER_STORAGE_BUFFER;
case BufferTarget::Vertex:
return GL_ARRAY_BUFFER;
case BufferTarget::Index:
return GL_ELEMENT_ARRAY_BUFFER;
case BufferTarget::Uniform:
return GL_UNIFORM_BUFFER;
case BufferTarget::CopyRead:
return GL_COPY_READ_BUFFER;
case BufferTarget::CopyWrite:
return GL_COPY_WRITE_BUFFER;
case BufferTarget::PixelPack:
return GL_PIXEL_PACK_BUFFER;
case BufferTarget::PixelUnpack:
return GL_PIXEL_UNPACK_BUFFER;
case BufferTarget::Query:
return GL_QUERY_BUFFER;
case BufferTarget::Texture:
return GL_TEXTURE_BUFFER;
case BufferTarget::TransformFeedback:
return GL_TRANSFORM_FEEDBACK_BUFFER;
case BufferTarget::AtomicCounter:
return GL_ATOMIC_COUNTER_BUFFER;
case BufferTarget::DispatchIndirect:
return GL_DISPATCH_INDIRECT_BUFFER;
case BufferTarget::DrawIndirect:
return GL_DRAW_INDIRECT_BUFFER;
case BufferTarget::ShaderStorage:
return GL_SHADER_STORAGE_BUFFER;
case BufferTarget::Unknown:
default: return GL_UNKNOWN_MGL;
default:
return GL_UNKNOWN_MGL;
}
}
GLenum ConvertBufferUsageToGLEnum(BufferUsage usage) {
switch (usage) {
case BufferUsage::StreamDraw: return GL_STREAM_DRAW;
case BufferUsage::StreamRead: return GL_STREAM_READ;
case BufferUsage::StreamCopy: return GL_STREAM_COPY;
case BufferUsage::StaticDraw: return GL_STATIC_DRAW;
case BufferUsage::StaticRead: return GL_STATIC_READ;
case BufferUsage::StaticCopy: return GL_STATIC_COPY;
case BufferUsage::DynamicDraw: return GL_DYNAMIC_DRAW;
case BufferUsage::DynamicRead: return GL_DYNAMIC_READ;
case BufferUsage::DynamicCopy: return GL_DYNAMIC_COPY;
default: return GL_UNKNOWN_MGL;
case BufferUsage::StreamDraw:
return GL_STREAM_DRAW;
case BufferUsage::StreamRead:
return GL_STREAM_READ;
case BufferUsage::StreamCopy:
return GL_STREAM_COPY;
case BufferUsage::StaticDraw:
return GL_STATIC_DRAW;
case BufferUsage::StaticRead:
return GL_STATIC_READ;
case BufferUsage::StaticCopy:
return GL_STATIC_COPY;
case BufferUsage::DynamicDraw:
return GL_DYNAMIC_DRAW;
case BufferUsage::DynamicRead:
return GL_DYNAMIC_READ;
case BufferUsage::DynamicCopy:
return GL_DYNAMIC_COPY;
default:
return GL_UNKNOWN_MGL;
}
}
@@ -50,5 +75,5 @@ namespace MobileGL {
if (access & BufferMappingAccessBit::Coherent) result |= GL_MAP_COHERENT_BIT;
return result;
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,9 +1,11 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/BufferState/BufferObject.h>
namespace MobileGL {
namespace MG_Util {
GLenum ConvertBufferTargetToGLEnum(BufferTarget bufferTarget);
GLenum ConvertBufferUsageToGLEnum(BufferUsage usage);
GLbitfield ConvertBufferMappingAccessToGLEnum(BufferMappingAccessBit access);
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,21 +1,30 @@
#include "../../../Includes.h"
#include "DataTypeConverter.h"
namespace MobileGL {
namespace MG_Util {
GLenum ConvertDataTypeToGLEnum(DataType type) {
switch (type) {
case DataType::Int8: return GL_BYTE;
case DataType::Uint8: return GL_UNSIGNED_BYTE;
case DataType::Int16: return GL_SHORT;
case DataType::Uint16: return GL_UNSIGNED_SHORT;
case DataType::Int32: return GL_INT;
case DataType::Uint32: return GL_UNSIGNED_INT;
case DataType::Float16: return GL_HALF_FLOAT;
case DataType::Float32: return GL_FLOAT;
case DataType::Float64: return GL_DOUBLE;
case DataType::Int8:
return GL_BYTE;
case DataType::Uint8:
return GL_UNSIGNED_BYTE;
case DataType::Int16:
return GL_SHORT;
case DataType::Uint16:
return GL_UNSIGNED_SHORT;
case DataType::Int32:
return GL_INT;
case DataType::Uint32:
return GL_UNSIGNED_INT;
case DataType::Float16:
return GL_HALF_FLOAT;
case DataType::Float32:
return GL_FLOAT;
case DataType::Float64:
return GL_DOUBLE;
default:
return GL_UNKNOWN_MGL;
}
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
GLenum ConvertDataTypeToGLEnum(DataType type);
}
}
} // namespace MobileGL
@@ -1,4 +1,4 @@
#include "../../../Includes.h"
#include "ErrorCodeConverter.h"
namespace MobileGL {
namespace MG_Util {
@@ -24,5 +24,5 @@ namespace MobileGL {
return GL_NO_ERROR;
}
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,9 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/ErrorState/ErrorCode.h>
namespace MobileGL {
namespace MG_Util {
GLenum ConvertErrorCodeToGLEnum(ErrorCode code);
}
}
} // namespace MobileGL
@@ -1,40 +1,65 @@
#include "../../../Includes.h"
#include "BufferEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
String ConvertBufferTargetToString(BufferTarget bufferTarget) {
switch (bufferTarget) {
case BufferTarget::Vertex: return "Vertex";
case BufferTarget::Index: return "Index";
case BufferTarget::Uniform: return "Uniform";
case BufferTarget::CopyRead: return "CopyRead";
case BufferTarget::CopyWrite: return "CopyWrite";
case BufferTarget::PixelPack: return "PixelPack";
case BufferTarget::PixelUnpack: return "PixelUnpack";
case BufferTarget::Query: return "Query";
case BufferTarget::Texture: return "Texture";
case BufferTarget::TransformFeedback: return "TransformFeedback";
case BufferTarget::AtomicCounter: return "AtomicCounter";
case BufferTarget::DispatchIndirect: return "DispatchIndirect";
case BufferTarget::DrawIndirect: return "DrawIndirect";
case BufferTarget::ShaderStorage: return "ShaderStorage";
case BufferTarget::Vertex:
return "Vertex";
case BufferTarget::Index:
return "Index";
case BufferTarget::Uniform:
return "Uniform";
case BufferTarget::CopyRead:
return "CopyRead";
case BufferTarget::CopyWrite:
return "CopyWrite";
case BufferTarget::PixelPack:
return "PixelPack";
case BufferTarget::PixelUnpack:
return "PixelUnpack";
case BufferTarget::Query:
return "Query";
case BufferTarget::Texture:
return "Texture";
case BufferTarget::TransformFeedback:
return "TransformFeedback";
case BufferTarget::AtomicCounter:
return "AtomicCounter";
case BufferTarget::DispatchIndirect:
return "DispatchIndirect";
case BufferTarget::DrawIndirect:
return "DrawIndirect";
case BufferTarget::ShaderStorage:
return "ShaderStorage";
case BufferTarget::Unknown:
default: return "Unknown";
default:
return "Unknown";
}
}
String ConvertBufferUsageToString(BufferUsage usage) {
switch (usage) {
case BufferUsage::StreamDraw: return "StreamDraw";
case BufferUsage::StreamRead: return "StreamRead";
case BufferUsage::StreamCopy: return "StreamCopy";
case BufferUsage::StaticDraw: return "StaticDraw";
case BufferUsage::StaticRead: return "StaticRead";
case BufferUsage::StaticCopy: return "StaticCopy";
case BufferUsage::DynamicDraw: return "DynamicDraw";
case BufferUsage::DynamicRead: return "DynamicRead";
case BufferUsage::DynamicCopy: return "DynamicCopy";
default: return "Unknown";
case BufferUsage::StreamDraw:
return "StreamDraw";
case BufferUsage::StreamRead:
return "StreamRead";
case BufferUsage::StreamCopy:
return "StreamCopy";
case BufferUsage::StaticDraw:
return "StaticDraw";
case BufferUsage::StaticRead:
return "StaticRead";
case BufferUsage::StaticCopy:
return "StaticCopy";
case BufferUsage::DynamicDraw:
return "DynamicDraw";
case BufferUsage::DynamicRead:
return "DynamicRead";
case BufferUsage::DynamicCopy:
return "DynamicCopy";
default:
return "Unknown";
}
}
@@ -53,5 +78,5 @@ namespace MobileGL {
result += "]";
return result.empty() ? "[]" : result;
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,9 +1,11 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/BufferState/BufferObject.h>
namespace MobileGL {
namespace MG_Util {
String ConvertBufferTargetToString(BufferTarget bufferTarget);
String ConvertBufferUsageToString(BufferUsage usage);
String ConvertBufferMappingAccessToString(Flags<BufferMappingAccessBit> access);
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,22 +1,33 @@
#include "../../../Includes.h"
#include "DataTypeConverter.h"
namespace MobileGL {
namespace MG_Util {
String ConvertDataTypeToString(DataType type) {
switch (type) {
case DataType::Int8: return "Int8";
case DataType::Uint8: return "Uint8";
case DataType::Int16: return "Int16";
case DataType::Uint16: return "Uint16";
case DataType::Int32: return "Int32";
case DataType::Uint32: return "Uint32";
case DataType::Float16: return "Float16";
case DataType::Float32: return "Float32";
case DataType::Float64: return "Float64";
case DataType::Fixed32: return "Fixed32";
case DataType::Int8:
return "Int8";
case DataType::Uint8:
return "Uint8";
case DataType::Int16:
return "Int16";
case DataType::Uint16:
return "Uint16";
case DataType::Int32:
return "Int32";
case DataType::Uint32:
return "Uint32";
case DataType::Float16:
return "Float16";
case DataType::Float32:
return "Float32";
case DataType::Float64:
return "Float64";
case DataType::Fixed32:
return "Fixed32";
case DataType::Unknown:
default: return "Unknown";
}
}
default:
return "Unknown";
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
String ConvertDataTypeToString(DataType type);
}
}
} // namespace MobileGL
@@ -1,4 +1,4 @@
#include "../../../Includes.h"
#include "GLExtensionConverter.h"
namespace MobileGL {
namespace MG_Util {
@@ -6,7 +6,10 @@ namespace MobileGL {
String str;
switch (extension) {
#define CASE(value) \
case value: { str = #value; break; }
case value: { \
str = #value; \
break; \
}
CASE(V_OpenGL10)
CASE(V_OpenGL11)
CASE(V_OpenGL12)
@@ -771,5 +774,5 @@ namespace MobileGL {
str.erase(0, 2);
return str;
}
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,8 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
String ConvertetGLExtToString(GLExtension extension);
}
}
} // namespace MobileGL
+14 -8
View File
@@ -1,4 +1,5 @@
#pragma once
#include <Includes.h>
#define MOBILEGL_LOG_LEVEL_DEBUG 0
#define MOBILEGL_LOG_LEVEL_WARN 1
@@ -14,31 +15,36 @@
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
#define MGLOG_D(fmt, ...) MOBILEGL_LOG_INTERNAL("DEBUG", ANDROID_LOG_DEBUG, fmt, ##__VA_ARGS__)
#else
# define MGLOG_D(fmt, ...) { }
#define MGLOG_D(fmt, ...) \
{}
#endif
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_INFO
#define MGLOG_I(fmt, ...) MOBILEGL_LOG_INTERNAL("INFO", ANDROID_LOG_INFO, fmt, ##__VA_ARGS__)
#else
# define MGLOG_I(fmt, ...) { }
#define MGLOG_I(fmt, ...) \
{}
#endif
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_WARN
#define MGLOG_W(fmt, ...) MOBILEGL_LOG_INTERNAL("WARN", ANDROID_LOG_WARN, fmt, ##__VA_ARGS__)
#else
# define MGLOG_W(fmt, ...) { }
#define MGLOG_W(fmt, ...) \
{}
#endif
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_ERROR
#define MGLOG_E(fmt, ...) MOBILEGL_LOG_INTERNAL("ERROR", ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__)
#else
# define MGLOG_E(fmt, ...) { }
#define MGLOG_E(fmt, ...) \
{}
#endif
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_FATAL
#define MGLOG_F(fmt, ...) MOBILEGL_LOG_INTERNAL("FATAL", ANDROID_LOG_FATAL, fmt, ##__VA_ARGS__)
#else
# define MGLOG_F(fmt, ...) { }
#define MGLOG_F(fmt, ...) \
{}
#endif
namespace MobileGL {
@@ -51,6 +57,6 @@ namespace MobileGL {
constexpr char* GetOSName();
std::string GetThreadName();
void Close();
}
}
}
} // namespace Debug
} // namespace MG_Util
} // namespace MobileGL
+17 -19
View File
@@ -1,39 +1,38 @@
#pragma once
#include <Includes.h>
namespace MobileGL {
template <typename IndexType>
class IndexGenerator {
public:
explicit IndexGenerator(size_t initial_capacity = 1024, IndexType first_index = 0)
: next_index_(first_index)
{
const size_t words_needed = (initial_capacity + 63) / 64;
explicit IndexGenerator(SizeT initial_capacity = 1024, IndexType first_index = 0) : next_index_(first_index) {
const SizeT words_needed = (initial_capacity + 63) / 64;
is_valid_.resize(words_needed, ~0ull);
freed_indices_.reserve(initial_capacity);
}
void Generate(size_t n, IndexType* indices) {
void Generate(SizeT n, IndexType* indices) {
if (n == 0) return;
size_t from_freed = std::min(n, freed_indices_.size());
SizeT from_freed = std::min(n, freed_indices_.size());
if (from_freed > 0) {
std::copy_n(freed_indices_.end() - from_freed, from_freed, indices);
freed_indices_.resize(freed_indices_.size() - from_freed);
for (size_t i = 0; i < from_freed; ++i) {
for (SizeT i = 0; i < from_freed; ++i) {
SetValid(indices[i], true);
}
}
size_t need_new = n - from_freed;
SizeT need_new = n - from_freed;
if (need_new > 0) {
size_t required_index = next_index_ + need_new;
size_t required_words = (required_index + 63) / 64;
SizeT required_index = next_index_ + need_new;
SizeT required_words = (required_index + 63) / 64;
if (required_words > is_valid_.size()) {
is_valid_.resize(required_words, ~0ull);
}
for (size_t i = 0; i < need_new; ++i) {
for (SizeT i = 0; i < need_new; ++i) {
indices[from_freed + i] = next_index_++;
}
}
@@ -48,25 +47,24 @@ namespace MobileGL {
}
bool IsValid(IndexType index) const {
size_t word = index >> 6;
size_t bit = index & 0x3F;
SizeT word = index >> 6;
SizeT bit = index & 0x3F;
return word < is_valid_.size() && (is_valid_[word] & (1ull << bit));
}
size_t FreeListSize() const { return freed_indices_.size(); }
size_t ActiveCount() const { return next_index_ - freed_indices_.size(); }
SizeT FreeListSize() const { return freed_indices_.size(); }
SizeT ActiveCount() const { return next_index_ - freed_indices_.size(); }
private:
inline void SetValid(IndexType index, bool valid) {
size_t word = index >> 6;
SizeT word = index >> 6;
uint64_t mask = 1ull << (index & 0x3F);
if (word >= is_valid_.size()) return;
if (valid) {
is_valid_[word] |= mask;
}
else {
} else {
is_valid_[word] &= ~mask;
}
}
@@ -82,4 +80,4 @@ namespace MobileGL {
std::vector<IndexType> freed_indices_;
std::vector<Uint64> is_valid_;
};
}
} // namespace MobileGL
+23
View File
@@ -0,0 +1,23 @@
#pragma once
// Stubs for non-Android platforms
#ifndef __ANDROID__
// Stubs for Android logging functions
#define ANDROID_LOG_UNKNOWN 0
#define ANDROID_LOG_DEFAULT 1
#define ANDROID_LOG_VERBOSE 2
#define ANDROID_LOG_DEBUG 3
#define ANDROID_LOG_INFO 4
#define ANDROID_LOG_WARN 5
#define ANDROID_LOG_ERROR 6
#define ANDROID_LOG_FATAL 7
#define ANDROID_LOG_SILENT 8
typedef int android_LogPriority;
inline int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
return 0;
}
#endif
@@ -1,10 +1,11 @@
#include "../../Includes.h"
#include "ShaderCompiler.h"
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
#include <MG_Util/Converters/GLToGlslang/GLShaderLangConverter.h>
namespace MobileGL {
namespace MG_Util {
namespace ShaderTranspiler {
TBuiltInResource& GetTBuiltInResourceInstance()
{
TBuiltInResource& GetTBuiltInResourceInstance() {
static TBuiltInResource Resources{};
Resources.maxLights = 32;
Resources.maxClipPlanes = 6;
@@ -119,8 +120,7 @@ namespace MobileGL {
auto lang = GetEShLanguageByShaderType(shaderType);
if (lang == EShLanguage::EShLangCount) {
ResultInfo r;
r.log += "Error: [Preprocess] Unsupported shader type: " +
ConvertGLEnumToString(shaderType);
r.log += "Error: [Preprocess] Unsupported shader type: " + ConvertGLEnumToString(shaderType);
r.errc = -1;
return std::unexpected(r);
}
@@ -136,14 +136,15 @@ namespace MobileGL {
tshader->setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_5);
tshader->setAutoMapLocations(true);
tshader->setAutoMapBindings(true);
tshader->setEnvInputVulkanRulesRelaxed(); // using EXT_vulkan_glsl_relaxed for gl_VertexID and gl_InstanceID?
tshader->setEnvInputVulkanRulesRelaxed(); // using EXT_vulkan_glsl_relaxed for gl_VertexID and
// gl_InstanceID?
tshader->setGlobalUniformBlockName(GLOBAL_UBO_NAME);
if (!tshader->parse(&GetTBuiltInResourceInstance(), 150, ECoreProfile,
/*forceDefaultVersionAndProfile: */ false,
/*forwardCompatible: */ true, EShMsgDefault)) {
ResultInfo r;
r.log += "Error: [glslang] Cannot compile " + ConvertGLEnumToString(shaderType) + ":\n"
+ std::string(tshader->getInfoLog());
r.log += "Error: [glslang] Cannot compile " + ConvertGLEnumToString(shaderType) + ":\n" +
std::string(tshader->getInfoLog());
r.errc = -2;
return std::unexpected(r);
}
@@ -219,6 +220,6 @@ namespace MobileGL {
return glsl;
}
}
}
}
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
@@ -1,4 +1,6 @@
#pragma once
#include <Includes.h>
#include "SpvcSession.h"
namespace MobileGL {
namespace MG_Util {
@@ -9,6 +11,6 @@ namespace ShaderTranspiler {
static Result<Vector<Vector<unsigned>>> LinkProgram(const ProgramAttrib& attrib);
static Result<String> DecompileShader(SpvcSession& session);
};
}
}
}
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
@@ -1,4 +1,4 @@
#include "../../Includes.h"
#include "SpvcSession.h"
namespace MobileGL {
namespace MG_Util {
@@ -9,7 +9,8 @@ namespace ShaderTranspiler {
spvc_context_create(&context);
spvc_context_parse_spirv(context, p_spirv, word_count, &ir);
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler);
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP,
&compiler);
spvc_compiler_create_shader_resources(compiler, &resources);
}
@@ -74,9 +75,8 @@ namespace ShaderTranspiler {
const spvc_reflected_resource* list = nullptr;
size_t count = 0;
SPVC_CHK_RESULT(
spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER, &list, &count);
)
SPVC_CHK_RESULT(spvc_resources_get_resource_list_for_type(resources, SPVC_RESOURCE_TYPE_UNIFORM_BUFFER,
&list, &count);)
for (size_t i = 0; i < count; ++i) {
if (spvc_compiler_has_decoration(compiler, list[i].id, SpvDecorationBuiltIn)) {
continue;
@@ -105,7 +105,9 @@ namespace ShaderTranspiler {
return spvc_context_get_last_error_string(context);
}
SpvcSession::~SpvcSession() { spvc_context_destroy(context); }
}
}
SpvcSession::~SpvcSession() {
spvc_context_destroy(context);
}
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
@@ -1,14 +1,8 @@
//
// Created by Swung0x48 on 2025/8/7.
//
#ifndef SPVCSESSION_H
#define SPVCSESSION_H
#pragma once
#include <Includes.h>
#include "Types.h"
#define SPVC_CHK_INIT \
auto __r = SPVC_SUCCESS;
#define SPVC_CHK_INIT auto __r = SPVC_SUCCESS;
#define SPVC_CHK_RESULT(res) \
__r = res; \
@@ -16,8 +10,7 @@
return __r; \
}
#define SPVC_CHK_RETURN \
return __r;
#define SPVC_CHK_RETURN return __r;
namespace MobileGL {
namespace MG_Util {
@@ -61,9 +54,6 @@ namespace ShaderTranspiler {
SpvcMetadata metadata;
};
}
}
}
#endif //SPVCSESSION_H
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
+9 -11
View File
@@ -1,5 +1,5 @@
#pragma once
#include "MG_Util/Debug/Log.h"
#include <Includes.h>
namespace MobileGL {
namespace MG_Util {
@@ -10,7 +10,6 @@ namespace MobileGL {
enum class ShaderCompileBits : Uint {
EmitDiscardAsDemote = 1 << 0,
};
struct ShaderAttrib {
@@ -36,9 +35,7 @@ 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 {
return location == other.location && name == other.name;
@@ -55,8 +52,8 @@ namespace MobileGL {
//
// spvc_context_create(&context);
// spvc_context_parse_spirv(context, p_spirv, word_count, &ir);
// spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler);
// spvc_compiler_create_shader_resources(compiler, &resources);
// spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP,
// &compiler); spvc_compiler_create_shader_resources(compiler, &resources);
// }
//
// SpvcSession(SpvcSession&) = delete;
@@ -110,7 +107,8 @@ namespace MobileGL {
// size_t num_members = spvc_type_get_num_member_types(type);
// printf("uniform %s {\n", var.name.c_str());
// for (size_t j = 0; j < num_members; ++j) {
// const char *memberName = spvc_compiler_get_member_name(compiler, list[i].base_type_id, j);
// const char *memberName = spvc_compiler_get_member_name(compiler,
// list[i].base_type_id, j);
// // auto memberTypeId = spvc_type_get_member_type(type, j);
// // auto memberType = spvc_compiler_get_type_handle(compiler, memberTypeId);
//
@@ -160,6 +158,6 @@ namespace MobileGL {
return EShLanguage::EShLangCount;
}
}
}
}
}
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
+25 -57
View File
@@ -1,12 +1,13 @@
#pragma once
#include <Includes.h>
#include "GLExtensions.h"
#define GL_UNKNOWN_MGL 0
#define THROW_EXCEPTION(msg) \
throw std::runtime_error(msg);
#define THROW_EXCEPTION(msg) throw std::runtime_error(msg)
#define THROW_UNIMPL_EXCEPTION \
THROW_EXCEPTION("Unimplemented function called!")
#define THROW_UNIMPL_EXCEPTION THROW_EXCEPTION("Unimplemented function called!")
namespace MobileGL {
using String = std::string;
@@ -126,21 +127,13 @@ namespace MobileGL {
BindingSlot() : m_target((TargetEnum)0), m_boundObject(nullptr) {}
explicit BindingSlot(TargetEnum target)
: m_target(target), m_boundObject(nullptr) {
}
explicit BindingSlot(TargetEnum target) : m_target(target), m_boundObject(nullptr) {}
void Bind(SharedPtr<ObjectType> object) {
m_boundObject = object;
}
void Bind(SharedPtr<ObjectType> object) { m_boundObject = object; }
SharedPtr<ObjectType> GetBoundObject() const {
return m_boundObject;
}
SharedPtr<ObjectType> GetBoundObject() const { return m_boundObject; }
TargetEnum GetTarget() const {
return m_target;
}
TargetEnum GetTarget() const { return m_target; }
private:
TargetEnum m_target;
@@ -155,15 +148,13 @@ namespace MobileGL {
String toString(Pair<Bool, Bool> dots = {true, true}, Bool useSuffix = true) const {
StringStream result;
result << Major << (dots.first ? "." : "") << Minor << (dots.second ? "." : "") << Patch <<
(useSuffix && Suffix.has_value() ? *Suffix : "");
result << Major << (dots.first ? "." : "") << Minor << (dots.second ? "." : "") << Patch
<< (useSuffix && Suffix.has_value() ? *Suffix : "");
return result.str();
}
};
struct BackendCap {
};
struct BackendCap {};
struct GLInfo {
Version TargetGLVersion;
@@ -180,9 +171,8 @@ namespace MobileGL {
BackendCap BackendCapability;
};
template <typename Bit, typename Underlying =
std::enable_if<std::is_scoped_enum_v<Bit>, std::underlying_type_t<Bit>>
>
template <typename Bit,
typename Underlying = std::enable_if<std::is_scoped_enum_v<Bit>, std::underlying_type_t<Bit>>>
class Flags {
public:
Flags() = default;
@@ -192,13 +182,9 @@ namespace MobileGL {
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) 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);
@@ -210,22 +196,14 @@ 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);
}
Flags operator|(const Flags b) const { return Flags(flags | b.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;
@@ -237,22 +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;
};
@@ -266,6 +236,4 @@ namespace MobileGL {
Flags<Bit> operator&(const Bit lhs, const Bit rhs) {
return Flags<Bit>(lhs) & rhs;
}
}
#include "../MG_Util/ShaderTranspiler/Types.h"
} // namespace MobileGL