From 5c1b0a8f107e5158bc42584735089e7b420bccc3 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 17 Jul 2025 22:15:31 +0800 Subject: [PATCH] [Test] (BufferTest): add `Binding` test, and fix compile errors --- MobileGL/Config.h | 2 +- MobileGL/Includes.h | 18 +++++++++- .../GLState/BufferState/BufferState.cpp | 2 +- MobileGL/MG_Test/Buffer/BufferTest.cpp | 34 +++++++++++++++++++ MobileGL/MG_Test/Buffer/CMakeLists.txt | 22 ++++++++++++ MobileGL/MG_Test/CMakeLists.txt | 9 +++-- 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 MobileGL/MG_Test/Buffer/BufferTest.cpp create mode 100644 MobileGL/MG_Test/Buffer/CMakeLists.txt diff --git a/MobileGL/Config.h b/MobileGL/Config.h index 65075379..2ae1da0e 100644 --- a/MobileGL/Config.h +++ b/MobileGL/Config.h @@ -8,7 +8,7 @@ #ifdef __ANDROID__ #define MOBILEGL_LOG_FILE_PATH "/sdcard/MG/latest.log" -#elif +#else #define MOBILEGL_LOG_FILE_PATH "" #endif diff --git a/MobileGL/Includes.h b/MobileGL/Includes.h index bc47fdb3..30e74788 100644 --- a/MobileGL/Includes.h +++ b/MobileGL/Includes.h @@ -68,6 +68,23 @@ #include #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; + +int __android_log_print(int prio, const char *tag, const char *fmt, ...); +#endif + #include #include #include @@ -90,7 +107,6 @@ #include "MG_Util/Pipelines/PipelineExecutor.hpp" -#include "MG_Util/Pipelines/Shader/GLSLtoSPIRVPipeline.h" #include "MG_Util/Pipelines/ShaderCompilationPipeline.h" #include "MG_State/GLState/BufferState/BufferObject.h" diff --git a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp index 59914b06..4b874f6b 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp +++ b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp @@ -11,7 +11,7 @@ namespace MobileGL { m_dirtyRange->Extend(0, m_size); } - void* BufferObject::AquireMemory(Bool markMapped = true, Bool read, Bool write) { + void* BufferObject::AquireMemory(Bool markMapped, Bool read, Bool write) { if (markMapped) { m_isMapped = true; m_mappingAccess = (read ? BufferMappingAccessBit::Read : BufferMappingAccessBit::Null) | diff --git a/MobileGL/MG_Test/Buffer/BufferTest.cpp b/MobileGL/MG_Test/Buffer/BufferTest.cpp new file mode 100644 index 00000000..3e82e078 --- /dev/null +++ b/MobileGL/MG_Test/Buffer/BufferTest.cpp @@ -0,0 +1,34 @@ +// +// Created by Swung 0x48 on 2025/7/17. +// +#include + +#include "Includes.h" + +using namespace MobileGL; + +class BufferTest : public ::testing::Test { +protected: + MG_State::GLState::GLContext glContext; +}; + +TEST_F(BufferTest, Binding) { + auto bufferNames = glContext.GenBufferNames(3); + auto& arraySlot = glContext.GetBufferBindingSlot(BufferTarget::Vertex); + auto& indexSlot = glContext.GetBufferBindingSlot(BufferTarget::Index); + + auto obj0 = glContext.CreateBufferObject(bufferNames[0]); + auto obj1 = glContext.CreateBufferObject(bufferNames[1]); + auto obj2 = glContext.CreateBufferObject(bufferNames[2]); + + arraySlot.Bind(obj0); + indexSlot.Bind(obj1); + + ASSERT_TRUE(arraySlot.GetBoundObject() == obj0); + ASSERT_TRUE(indexSlot.GetBoundObject() == obj1); + + arraySlot.Bind(obj2); + indexSlot.Bind(obj2); + ASSERT_TRUE(arraySlot.GetBoundObject() == obj2); + ASSERT_TRUE(indexSlot.GetBoundObject() == obj2); +} \ No newline at end of file diff --git a/MobileGL/MG_Test/Buffer/CMakeLists.txt b/MobileGL/MG_Test/Buffer/CMakeLists.txt new file mode 100644 index 00000000..b631e06f --- /dev/null +++ b/MobileGL/MG_Test/Buffer/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.14) + +add_executable( + BufferTest + BufferTest.cpp + + ${MGL_ROOT}/MobileGL/MG_State/GLState/Core.cpp + ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferState.cpp +) + +target_include_directories(BufferTest PRIVATE + ${MGL_ROOT}/include + ${MGL_ROOT}/MobileGL +) + +target_link_libraries( + BufferTest + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(BufferTest) \ No newline at end of file diff --git a/MobileGL/MG_Test/CMakeLists.txt b/MobileGL/MG_Test/CMakeLists.txt index 012699ac..0f9831ae 100644 --- a/MobileGL/MG_Test/CMakeLists.txt +++ b/MobileGL/MG_Test/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14) project(MobileGLTest) # GoogleTest requires at least C++17 -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) @@ -15,6 +15,9 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) enable_testing() + +set(MGL_ROOT ${CMAKE_CURRENT_LIST_DIR}/../..) + add_executable( SanityTest SanityTest.cpp @@ -25,4 +28,6 @@ target_link_libraries( ) include(GoogleTest) -gtest_discover_tests(SanityTest) \ No newline at end of file +gtest_discover_tests(SanityTest) + +add_subdirectory(Buffer)