mirror of
https://github.com/glfw/glfw.git
synced 2026-02-17 21:12:34 +01:00
Replace glad and the Vulkan SDK with glad2
This removes all dependencies from the GLFW test programs on the Vulkan SDK. It also removes support for linking the GLFW shared library (dynamic library, DLL) against the Vulkan loader static library.
This commit is contained in:
@@ -11,33 +11,36 @@ if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h"
|
||||
"${GLFW_SOURCE_DIR}/deps/glad.c")
|
||||
set(GLAD_GL "${GLFW_SOURCE_DIR}/deps/glad/gl.h"
|
||||
"${GLFW_SOURCE_DIR}/deps/glad_gl.c")
|
||||
set(GLAD_VULKAN "${GLFW_SOURCE_DIR}/deps/glad/vulkan.h"
|
||||
"${GLFW_SOURCE_DIR}/deps/glad_vulkan.c")
|
||||
set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h"
|
||||
"${GLFW_SOURCE_DIR}/deps/getopt.c")
|
||||
set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h"
|
||||
"${GLFW_SOURCE_DIR}/deps/tinycthread.c")
|
||||
|
||||
add_executable(clipboard clipboard.c ${GETOPT} ${GLAD})
|
||||
add_executable(events events.c ${GETOPT} ${GLAD})
|
||||
add_executable(msaa msaa.c ${GETOPT} ${GLAD})
|
||||
add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD})
|
||||
add_executable(iconify iconify.c ${GETOPT} ${GLAD})
|
||||
add_executable(monitors monitors.c ${GETOPT} ${GLAD})
|
||||
add_executable(reopen reopen.c ${GLAD})
|
||||
add_executable(cursor cursor.c ${GLAD})
|
||||
add_executable(clipboard clipboard.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(events events.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(msaa msaa.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(glfwinfo glfwinfo.c ${GETOPT} ${GLAD_GL} ${GLAD_VULKAN})
|
||||
add_executable(iconify iconify.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(monitors monitors.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(reopen reopen.c ${GLAD_GL})
|
||||
add_executable(cursor cursor.c ${GLAD_GL})
|
||||
|
||||
add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD})
|
||||
add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD})
|
||||
add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD})
|
||||
add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD})
|
||||
add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD})
|
||||
add_executable(opacity WIN32 MACOSX_BUNDLE opacity.c ${GLAD})
|
||||
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT} ${GLAD})
|
||||
add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD})
|
||||
add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD})
|
||||
add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD})
|
||||
add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD})
|
||||
add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD_GL})
|
||||
add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD_GL})
|
||||
add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD_GL})
|
||||
add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD_GL})
|
||||
add_executable(opacity WIN32 MACOSX_BUNDLE opacity.c ${GLAD_GL})
|
||||
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD_GL})
|
||||
add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD_GL})
|
||||
add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD_GL})
|
||||
add_executable(vulkan WIN32 vulkan.c ${ICON} ${GLAD_VULKAN})
|
||||
add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD_GL})
|
||||
|
||||
target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}")
|
||||
target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}")
|
||||
@@ -47,21 +50,10 @@ if (RT_LIBRARY)
|
||||
endif()
|
||||
|
||||
set(WINDOWS_BINARIES empty gamma icon inputlag joysticks opacity tearing
|
||||
threads timeout title windows)
|
||||
threads timeout title vulkan windows)
|
||||
set(CONSOLE_BINARIES clipboard events msaa glfwinfo iconify monitors reopen
|
||||
cursor)
|
||||
|
||||
if (VULKAN_FOUND)
|
||||
add_executable(vulkan WIN32 vulkan.c ${ICON})
|
||||
target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}")
|
||||
if (GLFW_VULKAN_STATIC)
|
||||
target_link_libraries(vulkan "${VULKAN_STATIC_LIBRARY}")
|
||||
else()
|
||||
target_link_libraries(vulkan "${VULKAN_LIBRARY}")
|
||||
endif()
|
||||
list(APPEND WINDOWS_BINARIES vulkan)
|
||||
endif()
|
||||
|
||||
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
||||
FOLDER "GLFW3/Tests")
|
||||
|
||||
@@ -81,6 +73,7 @@ if (APPLE)
|
||||
set_target_properties(threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Threads")
|
||||
set_target_properties(timeout PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Timeout")
|
||||
set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title")
|
||||
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Vulkan")
|
||||
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
|
||||
|
||||
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -123,7 +123,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
@@ -278,7 +278,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
glGenBuffers(1, &vertex_buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "tinycthread.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <math.h>
|
||||
@@ -91,7 +91,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
if (thrd_create(&thread, thread_main, NULL) != thrd_success)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -604,7 +604,7 @@ int main(int argc, char** argv)
|
||||
glfwSetDropCallback(slots[i].window, drop_callback);
|
||||
|
||||
glfwMakeContextCurrent(slots[i].window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define NK_IMPLEMENTATION
|
||||
@@ -121,7 +121,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#define VK_NO_PROTOTYPES
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <glad/vulkan.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -214,9 +213,6 @@ static void list_vulkan_instance_extensions(void)
|
||||
{
|
||||
uint32_t i, ep_count = 0;
|
||||
VkExtensionProperties* ep;
|
||||
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties =
|
||||
(PFN_vkEnumerateInstanceExtensionProperties)
|
||||
glfwGetInstanceProcAddress(NULL, "vkEnumerateInstanceExtensionProperties");
|
||||
|
||||
printf("Vulkan instance extensions:\n");
|
||||
|
||||
@@ -241,9 +237,6 @@ static void list_vulkan_instance_layers(void)
|
||||
{
|
||||
uint32_t i, lp_count = 0;
|
||||
VkLayerProperties* lp;
|
||||
PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties =
|
||||
(PFN_vkEnumerateInstanceLayerProperties)
|
||||
glfwGetInstanceProcAddress(NULL, "vkEnumerateInstanceLayerProperties");
|
||||
|
||||
printf("Vulkan instance layers:\n");
|
||||
|
||||
@@ -273,9 +266,6 @@ static void list_vulkan_device_extensions(VkInstance instance, VkPhysicalDevice
|
||||
{
|
||||
uint32_t i, ep_count;
|
||||
VkExtensionProperties* ep;
|
||||
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties =
|
||||
(PFN_vkEnumerateDeviceExtensionProperties)
|
||||
glfwGetInstanceProcAddress(instance, "vkEnumerateDeviceExtensionProperties");
|
||||
|
||||
printf("Vulkan device extensions:\n");
|
||||
|
||||
@@ -300,9 +290,6 @@ static void list_vulkan_device_layers(VkInstance instance, VkPhysicalDevice devi
|
||||
{
|
||||
uint32_t i, lp_count;
|
||||
VkLayerProperties* lp;
|
||||
PFN_vkEnumerateDeviceLayerProperties vkEnumerateDeviceLayerProperties =
|
||||
(PFN_vkEnumerateDeviceLayerProperties)
|
||||
glfwGetInstanceProcAddress(instance, "vkEnumerateDeviceLayerProperties");
|
||||
|
||||
printf("Vulkan device layers:\n");
|
||||
|
||||
@@ -358,6 +345,11 @@ static void print_version(void)
|
||||
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
||||
}
|
||||
|
||||
static GLADapiproc glad_vulkan_callback(const char* name, void* user)
|
||||
{
|
||||
return glfwGetInstanceProcAddress((VkInstance) user, name);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ch, client, major, minor, revision, profile;
|
||||
@@ -639,7 +631,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
@@ -823,11 +815,8 @@ int main(int argc, char** argv)
|
||||
VkInstanceCreateInfo ici = {0};
|
||||
VkInstance instance;
|
||||
VkPhysicalDevice* pd;
|
||||
PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance)
|
||||
glfwGetInstanceProcAddress(NULL, "vkCreateInstance");
|
||||
PFN_vkDestroyInstance vkDestroyInstance;
|
||||
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
|
||||
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
|
||||
|
||||
gladLoadVulkanUserPtr(NULL, glad_vulkan_callback, NULL);
|
||||
|
||||
re = glfwGetRequiredInstanceExtensions(&re_count);
|
||||
|
||||
@@ -865,12 +854,7 @@ int main(int argc, char** argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
vkDestroyInstance = (PFN_vkDestroyInstance)
|
||||
glfwGetInstanceProcAddress(instance, "vkDestroyInstance");
|
||||
vkEnumeratePhysicalDevices = (PFN_vkEnumeratePhysicalDevices)
|
||||
glfwGetInstanceProcAddress(instance, "vkEnumeratePhysicalDevices");
|
||||
vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)
|
||||
glfwGetInstanceProcAddress(instance, "vkGetPhysicalDeviceProperties");
|
||||
gladLoadVulkanUserPtr(NULL, glad_vulkan_callback, instance);
|
||||
|
||||
if (vkEnumeratePhysicalDevices(instance, &pd_count, NULL) != VK_SUCCESS)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -129,7 +129,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
set_icon(window, cur_icon_color);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -191,7 +191,7 @@ static GLFWwindow* create_window(GLFWmonitor* monitor)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define NK_IMPLEMENTATION
|
||||
@@ -210,7 +210,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
update_vsync();
|
||||
|
||||
last_time = glfwGetTime();
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define NK_IMPLEMENTATION
|
||||
@@ -190,7 +190,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -166,7 +166,7 @@ static void test_modes(GLFWmonitor* monitor)
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetTime(0.0);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
@@ -141,7 +141,7 @@ int main(int argc, char** argv)
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glGetIntegerv(GL_SAMPLES, &samples);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define NK_IMPLEMENTATION
|
||||
@@ -67,7 +67,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <time.h>
|
||||
@@ -164,7 +164,7 @@ int main(int argc, char** argv)
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -222,7 +222,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
set_swap_interval(window, 0);
|
||||
|
||||
last_time = glfwGetTime();
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "tinycthread.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -114,7 +114,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(threads[0].window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwMakeContextCurrent(NULL);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <time.h>
|
||||
@@ -70,7 +70,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -55,7 +55,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
|
||||
133
tests/vulkan.c
133
tests/vulkan.c
@@ -41,8 +41,8 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <glad/vulkan.h>
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define DEMO_TEXTURE_COUNT 1
|
||||
@@ -65,25 +65,10 @@
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
#define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \
|
||||
{ \
|
||||
demo->fp##entrypoint = \
|
||||
(PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \
|
||||
if (demo->fp##entrypoint == NULL) { \
|
||||
ERR_EXIT("vkGetInstanceProcAddr failed to find vk" #entrypoint, \
|
||||
"vkGetInstanceProcAddr Failure"); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GET_DEVICE_PROC_ADDR(dev, entrypoint) \
|
||||
{ \
|
||||
demo->fp##entrypoint = \
|
||||
(PFN_vk##entrypoint)vkGetDeviceProcAddr(dev, "vk" #entrypoint); \
|
||||
if (demo->fp##entrypoint == NULL) { \
|
||||
ERR_EXIT("vkGetDeviceProcAddr failed to find vk" #entrypoint, \
|
||||
"vkGetDeviceProcAddr Failure"); \
|
||||
} \
|
||||
}
|
||||
static GLADapiproc glad_vulkan_callback(const char* name, void* user)
|
||||
{
|
||||
return glfwGetInstanceProcAddress((VkInstance) user, name);
|
||||
}
|
||||
|
||||
static const char fragShaderCode[] = {
|
||||
0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00,
|
||||
@@ -287,19 +272,6 @@ struct demo {
|
||||
VkFormat format;
|
||||
VkColorSpaceKHR color_space;
|
||||
|
||||
PFN_vkGetPhysicalDeviceSurfaceSupportKHR
|
||||
fpGetPhysicalDeviceSurfaceSupportKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR
|
||||
fpGetPhysicalDeviceSurfaceCapabilitiesKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR
|
||||
fpGetPhysicalDeviceSurfaceFormatsKHR;
|
||||
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR
|
||||
fpGetPhysicalDeviceSurfacePresentModesKHR;
|
||||
PFN_vkCreateSwapchainKHR fpCreateSwapchainKHR;
|
||||
PFN_vkDestroySwapchainKHR fpDestroySwapchainKHR;
|
||||
PFN_vkGetSwapchainImagesKHR fpGetSwapchainImagesKHR;
|
||||
PFN_vkAcquireNextImageKHR fpAcquireNextImageKHR;
|
||||
PFN_vkQueuePresentKHR fpQueuePresentKHR;
|
||||
uint32_t swapchainImageCount;
|
||||
VkSwapchainKHR swapchain;
|
||||
SwapchainBuffers *buffers;
|
||||
@@ -347,10 +319,7 @@ struct demo {
|
||||
int32_t frameCount;
|
||||
bool validate;
|
||||
bool use_break;
|
||||
PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback;
|
||||
PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback;
|
||||
VkDebugReportCallbackEXT msg_callback;
|
||||
PFN_vkDebugReportMessageEXT DebugReportMessage;
|
||||
|
||||
float depthStencil;
|
||||
float depthIncrement;
|
||||
@@ -631,10 +600,10 @@ static void demo_draw(struct demo *demo) {
|
||||
assert(!err);
|
||||
|
||||
// Get the index of the next available swapchain image:
|
||||
err = demo->fpAcquireNextImageKHR(demo->device, demo->swapchain, UINT64_MAX,
|
||||
imageAcquiredSemaphore,
|
||||
(VkFence)0, // TODO: Show use of fence
|
||||
&demo->current_buffer);
|
||||
err = vkAcquireNextImageKHR(demo->device, demo->swapchain, UINT64_MAX,
|
||||
imageAcquiredSemaphore,
|
||||
(VkFence)0, // TODO: Show use of fence
|
||||
&demo->current_buffer);
|
||||
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
// demo->swapchain is out of date (e.g. the window was resized) and
|
||||
// must be recreated:
|
||||
@@ -684,7 +653,7 @@ static void demo_draw(struct demo *demo) {
|
||||
.pImageIndices = &demo->current_buffer,
|
||||
};
|
||||
|
||||
err = demo->fpQueuePresentKHR(demo->queue, &present);
|
||||
err = vkQueuePresentKHR(demo->queue, &present);
|
||||
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
|
||||
// demo->swapchain is out of date (e.g. the window was resized) and
|
||||
// must be recreated:
|
||||
@@ -709,18 +678,18 @@ static void demo_prepare_buffers(struct demo *demo) {
|
||||
|
||||
// Check the surface capabilities and formats
|
||||
VkSurfaceCapabilitiesKHR surfCapabilities;
|
||||
err = demo->fpGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||
demo->gpu, demo->surface, &surfCapabilities);
|
||||
assert(!err);
|
||||
|
||||
uint32_t presentModeCount;
|
||||
err = demo->fpGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
err = vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
demo->gpu, demo->surface, &presentModeCount, NULL);
|
||||
assert(!err);
|
||||
VkPresentModeKHR *presentModes =
|
||||
(VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR));
|
||||
assert(presentModes);
|
||||
err = demo->fpGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
err = vkGetPhysicalDeviceSurfacePresentModesKHR(
|
||||
demo->gpu, demo->surface, &presentModeCount, presentModes);
|
||||
assert(!err);
|
||||
|
||||
@@ -797,8 +766,7 @@ static void demo_prepare_buffers(struct demo *demo) {
|
||||
};
|
||||
uint32_t i;
|
||||
|
||||
err = demo->fpCreateSwapchainKHR(demo->device, &swapchain, NULL,
|
||||
&demo->swapchain);
|
||||
err = vkCreateSwapchainKHR(demo->device, &swapchain, NULL, &demo->swapchain);
|
||||
assert(!err);
|
||||
|
||||
// If we just re-created an existing swapchain, we should destroy the old
|
||||
@@ -806,19 +774,19 @@ static void demo_prepare_buffers(struct demo *demo) {
|
||||
// Note: destroying the swapchain also cleans up all its associated
|
||||
// presentable images once the platform is done with them.
|
||||
if (oldSwapchain != VK_NULL_HANDLE) {
|
||||
demo->fpDestroySwapchainKHR(demo->device, oldSwapchain, NULL);
|
||||
vkDestroySwapchainKHR(demo->device, oldSwapchain, NULL);
|
||||
}
|
||||
|
||||
err = demo->fpGetSwapchainImagesKHR(demo->device, demo->swapchain,
|
||||
err = vkGetSwapchainImagesKHR(demo->device, demo->swapchain,
|
||||
&demo->swapchainImageCount, NULL);
|
||||
assert(!err);
|
||||
|
||||
VkImage *swapchainImages =
|
||||
(VkImage *)malloc(demo->swapchainImageCount * sizeof(VkImage));
|
||||
assert(swapchainImages);
|
||||
err = demo->fpGetSwapchainImagesKHR(demo->device, demo->swapchain,
|
||||
&demo->swapchainImageCount,
|
||||
swapchainImages);
|
||||
err = vkGetSwapchainImagesKHR(demo->device, demo->swapchain,
|
||||
&demo->swapchainImageCount,
|
||||
swapchainImages);
|
||||
assert(!err);
|
||||
|
||||
demo->buffers = (SwapchainBuffers *)malloc(sizeof(SwapchainBuffers) *
|
||||
@@ -1843,6 +1811,8 @@ static void demo_init_vk(struct demo *demo) {
|
||||
"vkCreateInstance Failure");
|
||||
}
|
||||
|
||||
gladLoadVulkanUserPtr(NULL, glad_vulkan_callback, demo->inst);
|
||||
|
||||
/* Make initial call to query gpu_count, then second call for gpu info*/
|
||||
err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, NULL);
|
||||
assert(!err && gpu_count > 0);
|
||||
@@ -1864,6 +1834,8 @@ static void demo_init_vk(struct demo *demo) {
|
||||
"vkEnumeratePhysicalDevices Failure");
|
||||
}
|
||||
|
||||
gladLoadVulkanUserPtr(demo->gpu, glad_vulkan_callback, demo->inst);
|
||||
|
||||
/* Look for device extensions */
|
||||
uint32_t device_extension_count = 0;
|
||||
VkBool32 swapchainExtFound = 0;
|
||||
@@ -1904,30 +1876,6 @@ static void demo_init_vk(struct demo *demo) {
|
||||
}
|
||||
|
||||
if (demo->validate) {
|
||||
demo->CreateDebugReportCallback =
|
||||
(PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(
|
||||
demo->inst, "vkCreateDebugReportCallbackEXT");
|
||||
demo->DestroyDebugReportCallback =
|
||||
(PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(
|
||||
demo->inst, "vkDestroyDebugReportCallbackEXT");
|
||||
if (!demo->CreateDebugReportCallback) {
|
||||
ERR_EXIT(
|
||||
"GetProcAddr: Unable to find vkCreateDebugReportCallbackEXT\n",
|
||||
"vkGetProcAddr Failure");
|
||||
}
|
||||
if (!demo->DestroyDebugReportCallback) {
|
||||
ERR_EXIT(
|
||||
"GetProcAddr: Unable to find vkDestroyDebugReportCallbackEXT\n",
|
||||
"vkGetProcAddr Failure");
|
||||
}
|
||||
demo->DebugReportMessage =
|
||||
(PFN_vkDebugReportMessageEXT)vkGetInstanceProcAddr(
|
||||
demo->inst, "vkDebugReportMessageEXT");
|
||||
if (!demo->DebugReportMessage) {
|
||||
ERR_EXIT("GetProcAddr: Unable to find vkDebugReportMessageEXT\n",
|
||||
"vkGetProcAddr Failure");
|
||||
}
|
||||
|
||||
VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
|
||||
dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
|
||||
dbgCreateInfo.flags =
|
||||
@@ -1935,8 +1883,8 @@ static void demo_init_vk(struct demo *demo) {
|
||||
dbgCreateInfo.pfnCallback = demo->use_break ? BreakCallback : dbgFunc;
|
||||
dbgCreateInfo.pUserData = demo;
|
||||
dbgCreateInfo.pNext = NULL;
|
||||
err = demo->CreateDebugReportCallback(demo->inst, &dbgCreateInfo, NULL,
|
||||
&demo->msg_callback);
|
||||
err = vkCreateDebugReportCallbackEXT(demo->inst, &dbgCreateInfo, NULL,
|
||||
&demo->msg_callback);
|
||||
switch (err) {
|
||||
case VK_SUCCESS:
|
||||
break;
|
||||
@@ -1951,13 +1899,6 @@ static void demo_init_vk(struct demo *demo) {
|
||||
}
|
||||
}
|
||||
|
||||
// Having these GIPA queries of device extension entry points both
|
||||
// BEFORE and AFTER vkCreateDevice is a good test for the loader
|
||||
GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceFormatsKHR);
|
||||
GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfacePresentModesKHR);
|
||||
GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceSupportKHR);
|
||||
|
||||
vkGetPhysicalDeviceProperties(demo->gpu, &demo->gpu_props);
|
||||
|
||||
// Query with NULL data to get count
|
||||
@@ -2009,12 +1950,6 @@ static void demo_init_device(struct demo *demo) {
|
||||
|
||||
err = vkCreateDevice(demo->gpu, &device, NULL, &demo->device);
|
||||
assert(!err);
|
||||
|
||||
GET_DEVICE_PROC_ADDR(demo->device, CreateSwapchainKHR);
|
||||
GET_DEVICE_PROC_ADDR(demo->device, DestroySwapchainKHR);
|
||||
GET_DEVICE_PROC_ADDR(demo->device, GetSwapchainImagesKHR);
|
||||
GET_DEVICE_PROC_ADDR(demo->device, AcquireNextImageKHR);
|
||||
GET_DEVICE_PROC_ADDR(demo->device, QueuePresentKHR);
|
||||
}
|
||||
|
||||
static void demo_init_vk_swapchain(struct demo *demo) {
|
||||
@@ -2028,8 +1963,8 @@ static void demo_init_vk_swapchain(struct demo *demo) {
|
||||
VkBool32 *supportsPresent =
|
||||
(VkBool32 *)malloc(demo->queue_count * sizeof(VkBool32));
|
||||
for (i = 0; i < demo->queue_count; i++) {
|
||||
demo->fpGetPhysicalDeviceSurfaceSupportKHR(demo->gpu, i, demo->surface,
|
||||
&supportsPresent[i]);
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(demo->gpu, i, demo->surface,
|
||||
&supportsPresent[i]);
|
||||
}
|
||||
|
||||
// Search for a graphics and a present queue in the array of queue
|
||||
@@ -2087,13 +2022,13 @@ static void demo_init_vk_swapchain(struct demo *demo) {
|
||||
|
||||
// Get the list of VkFormat's that are supported:
|
||||
uint32_t formatCount;
|
||||
err = demo->fpGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface,
|
||||
&formatCount, NULL);
|
||||
err = vkGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface,
|
||||
&formatCount, NULL);
|
||||
assert(!err);
|
||||
VkSurfaceFormatKHR *surfFormats =
|
||||
(VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR));
|
||||
err = demo->fpGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface,
|
||||
&formatCount, surfFormats);
|
||||
err = vkGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface,
|
||||
&formatCount, surfFormats);
|
||||
assert(!err);
|
||||
// If the format list includes just one entry of VK_FORMAT_UNDEFINED,
|
||||
// the surface has no preferred format. Otherwise, at least one
|
||||
@@ -2126,6 +2061,8 @@ static void demo_init_connection(struct demo *demo) {
|
||||
fflush(stdout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gladLoadVulkanUserPtr(NULL, glad_vulkan_callback, NULL);
|
||||
}
|
||||
|
||||
static void demo_init(struct demo *demo, const int argc, const char *argv[])
|
||||
@@ -2208,12 +2145,12 @@ static void demo_cleanup(struct demo *demo) {
|
||||
vkDestroyImage(demo->device, demo->depth.image, NULL);
|
||||
vkFreeMemory(demo->device, demo->depth.mem, NULL);
|
||||
|
||||
demo->fpDestroySwapchainKHR(demo->device, demo->swapchain, NULL);
|
||||
vkDestroySwapchainKHR(demo->device, demo->swapchain, NULL);
|
||||
free(demo->buffers);
|
||||
|
||||
vkDestroyDevice(demo->device, NULL);
|
||||
if (demo->validate) {
|
||||
demo->DestroyDebugReportCallback(demo->inst, demo->msg_callback, NULL);
|
||||
vkDestroyDebugReportCallbackEXT(demo->inst, demo->msg_callback, NULL);
|
||||
}
|
||||
vkDestroySurfaceKHR(demo->inst, demo->surface, NULL);
|
||||
vkDestroyInstance(demo->inst, NULL);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -140,7 +140,7 @@ int main(int argc, char** argv)
|
||||
glfwSetKeyCallback(windows[i], key_callback);
|
||||
|
||||
glfwMakeContextCurrent(windows[i]);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
|
||||
|
||||
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom);
|
||||
|
||||
Reference in New Issue
Block a user