[Feat] (MG_Test/Backend/DirectVulkan): add a simple test environment

This commit is contained in:
2026-02-10 23:14:20 +08:00
parent 43e59d8fce
commit 52eb6b3f2a
2 changed files with 92 additions and 0 deletions
@@ -32,6 +32,39 @@ target_link_libraries(
GTest::gtest_main
${LINK_LIBRARIES}
)
target_compile_definitions(DirectVulkanSanityTest PRIVATE -DNOMINMAX)
include(GoogleTest)
gtest_discover_tests(DirectVulkanSanityTest)
add_executable(
DirectVulkanTestExec
TestExec.cpp
)
target_include_directories(DirectVulkanTestExec PRIVATE
${MGL_ROOT}/include
${MGL_ROOT}/MobileGL
)
if (WIN32)
# I know this is horrible, but glfw only provides binary but not CMake config for Windows, so we have to manually link against the library and include directories
#set(GLFW_ROOT path/to/glfw-3.4.bin.WIN64)
target_include_directories(DirectVulkanTestExec PRIVATE ${GLFW_ROOT}/include)
target_link_directories(DirectVulkanTestExec PRIVATE ${GLFW_ROOT}/lib-vc2022)
target_link_libraries(DirectVulkanTestExec PRIVATE glfw3_mt.lib)
else()
find_package(glfw3 REQUIRED)
target_link_libraries(DirectVulkanTestExec PRIVATE glfw)
endif()
find_package(Vulkan REQUIRED)
target_include_directories(DirectVulkanTestExec PUBLIC ${Vulkan_INCLUDE_DIRS})
target_link_libraries(DirectVulkanTestExec PRIVATE Vulkan::Vulkan)
target_link_libraries(
DirectVulkanTestExec PRIVATE
${LINK_LIBRARIES}
)
target_compile_definitions(DirectVulkanTestExec PRIVATE -DNOMINMAX)
@@ -0,0 +1,59 @@
// MobileGL - MobileGL/MG_Test/Backend/DirectVulkan/TestExec.cpp
// Copyright (c) 2025-2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
#include <iostream>
#include <vector>
#include <vulkan/vulkan.h>
#include <GLFW/glfw3.h>
#define EGLAPI
#include <EGL/egl.h>
#ifdef _WIN32
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#include "MG_Backend/DirectVulkan/DirectVulkan.h"
#include "MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h"
#include <GLFW/glfw3native.h>
int main() {
glfwInit();
static EGLint const attribute_list[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_NONE
};
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, nullptr, nullptr);
EGLConfig config;
EGLint num_config;
eglChooseConfig(display, attribute_list, &config, 1, &num_config);
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, nullptr);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "MobileGL ContextCreation", nullptr, nullptr);
#ifdef _WIN32
EGLNativeWindowType nativewindow = glfwGetWin32Window(window);
#endif
EGLSurface surface = eglCreateWindowSurface(display, config, nativewindow, nullptr);
eglMakeCurrent(display, surface, surface, context);
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
// MobileGL::MG_Backend::DirectVulkan::pVulkanRenderer->RenderFrame();
eglSwapBuffers(display, surface);
}
glfwDestroyWindow(window);
glfwTerminate();
}