Skip to content

Commit ea9038d

Browse files
committed
Fix build of interop tests.
1 parent c1eaa5e commit ea9038d

4 files changed

+62
-48
lines changed

tests/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ if (GRANITE_TEST_INTEROP)
188188
glad/src/glad.c
189189
glad/include/glad/glad.h
190190
glad/include/KHR/khrplatform.h)
191-
target_link_libraries(granite-gl-interop PRIVATE glfw granite-vulkan)
191+
target_link_libraries(granite-gl-interop PRIVATE SDL3-static granite-vulkan)
192192
target_include_directories(granite-gl-interop PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)
193193

194194
if (WIN32)
195195
add_granite_offline_tool(granite-d3d11-interop d3d11_interop_test.cpp)
196-
target_link_libraries(granite-d3d11-interop PRIVATE glfw granite-vulkan d3d11 dxgi)
196+
target_link_libraries(granite-d3d11-interop PRIVATE SDL3-static granite-vulkan d3d11 dxgi)
197197
add_granite_offline_tool(granite-d3d12-interop d3d12_interop_test.cpp)
198-
target_link_libraries(granite-d3d12-interop PRIVATE glfw granite-vulkan d3d12 dxgi)
198+
target_link_libraries(granite-d3d12-interop PRIVATE SDL3-static granite-vulkan d3d12 dxgi)
199199
endif()
200200
endif()
201201

tests/d3d11_interop_test.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#define GLFW_EXPOSE_NATIVE_WIN32
2-
#include "GLFW/glfw3.h"
3-
#include "GLFW/glfw3native.h"
41
#include "device.hpp"
52
#include "context.hpp"
63
#include "global_managers_init.hpp"
@@ -9,6 +6,8 @@
96
#include "dxgi1_6.h"
107
#include "d3d11_4.h"
118

9+
#include <SDL3/SDL.h>
10+
1211
using namespace Vulkan;
1312

1413
struct DXGIContext
@@ -110,9 +109,13 @@ static D3DContext create_d3d11_device()
110109
return ctx;
111110
}
112111

113-
static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
112+
static bool init_swapchain(SDL_Window *window, D3DContext &ctx)
114113
{
115-
HWND hwnd = glfwGetWin32Window(window);
114+
SDL_PropertiesID props = SDL_GetWindowProperties(window);
115+
SDL_LockProperties(props);
116+
HWND hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
117+
SDL_UnlockProperties(props);
118+
116119
DXGI_SWAP_CHAIN_DESC desc = {};
117120
desc.BufferCount = 1;
118121
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
@@ -140,7 +143,7 @@ static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
140143

141144
int main()
142145
{
143-
if (!glfwInit())
146+
if (SDL_Init(SDL_INIT_VIDEO) < 0)
144147
return EXIT_FAILURE;
145148

146149
Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
@@ -149,8 +152,7 @@ int main()
149152
if (!ctx.dev)
150153
return EXIT_FAILURE;
151154

152-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
153-
GLFWwindow *window = glfwCreateWindow(1280, 720, "D3D11 interop", nullptr, nullptr);
155+
SDL_Window *window = SDL_CreateWindow("D3D11 interop", 1280, 720, 0);
154156
if (!window)
155157
{
156158
LOGE("Failed to create window.\n");
@@ -182,7 +184,7 @@ int main()
182184
return EXIT_FAILURE;
183185
}
184186

185-
if (memcmp(device.get_device_features().id_properties.deviceLUID,
187+
if (memcmp(device.get_device_features().vk11_props.deviceLUID,
186188
&ctx.luid, VK_LUID_SIZE) != 0)
187189
{
188190
LOGE("LUID mismatch.\n");
@@ -261,9 +263,13 @@ int main()
261263
uint64_t timeline_value = 0;
262264
unsigned frame_count = 0;
263265

264-
while (!glfwWindowShouldClose(window))
266+
bool alive = true;
267+
SDL_Event e;
268+
while (alive)
265269
{
266-
glfwPollEvents();
270+
while (SDL_PollEvent(&e))
271+
if (e.type == SDL_EVENT_QUIT)
272+
alive = false;
267273

268274
// Render frame in Vulkan
269275
{
@@ -352,6 +358,6 @@ int main()
352358
if (ref != 0)
353359
LOGE("Missed a release on device.\n");
354360

355-
glfwDestroyWindow(window);
356-
glfwTerminate();
361+
SDL_DestroyWindow(window);
362+
SDL_Quit();
357363
}

tests/d3d12_interop_test.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#define GLFW_EXPOSE_NATIVE_WIN32
2-
#include "GLFW/glfw3.h"
3-
#include "GLFW/glfw3native.h"
41
#include "device.hpp"
52
#include "context.hpp"
63
#include "global_managers_init.hpp"
@@ -9,6 +6,8 @@
96
#include "dxgi1_6.h"
107
#include "d3d12.h"
118

9+
#include <SDL3/SDL.h>
10+
1211
using namespace Vulkan;
1312

1413
struct DXGIContext
@@ -117,9 +116,13 @@ static D3DContext create_d3d12_device()
117116
return ctx;
118117
}
119118

120-
static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
119+
static bool init_swapchain(SDL_Window *window, D3DContext &ctx)
121120
{
122-
HWND hwnd = glfwGetWin32Window(window);
121+
SDL_PropertiesID props = SDL_GetWindowProperties(window);
122+
SDL_LockProperties(props);
123+
HWND hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
124+
SDL_UnlockProperties(props);
125+
123126
DXGI_SWAP_CHAIN_DESC desc = {};
124127
desc.BufferCount = 2;
125128
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
@@ -156,7 +159,7 @@ static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
156159

157160
int main()
158161
{
159-
if (!glfwInit())
162+
if (SDL_Init(SDL_INIT_VIDEO) < 0)
160163
return EXIT_FAILURE;
161164

162165
Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
@@ -165,8 +168,7 @@ int main()
165168
if (!ctx.dev)
166169
return EXIT_FAILURE;
167170

168-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
169-
GLFWwindow *window = glfwCreateWindow(1280, 720, "D3D12 interop", nullptr, nullptr);
171+
SDL_Window *window = SDL_CreateWindow("D3D12 interop", 1280, 720, 0);
170172
if (!window)
171173
{
172174
LOGE("Failed to create window.\n");
@@ -198,7 +200,7 @@ int main()
198200
return EXIT_FAILURE;
199201
}
200202

201-
if (memcmp(device.get_device_features().id_properties.deviceLUID,
203+
if (memcmp(device.get_device_features().vk11_props.deviceLUID,
202204
&ctx.luid, VK_LUID_SIZE) != 0)
203205
{
204206
LOGE("LUID mismatch.\n");
@@ -279,9 +281,13 @@ int main()
279281
unsigned frame_count = 0;
280282
unsigned wait_context;
281283

282-
while (!glfwWindowShouldClose(window))
284+
bool alive = true;
285+
SDL_Event e;
286+
while (alive)
283287
{
284-
glfwPollEvents();
288+
while (SDL_PollEvent(&e))
289+
if (e.type == SDL_EVENT_QUIT)
290+
alive = false;
285291

286292
wait_context = frame_count % 2;
287293

@@ -400,6 +406,6 @@ int main()
400406
if (ref != 0)
401407
LOGE("Missed a release on device.\n");
402408

403-
glfwDestroyWindow(window);
404-
glfwTerminate();
409+
SDL_DestroyWindow(window);
410+
SDL_Quit();
405411
}

tests/gl_interop_test.cpp

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "glad/glad.h"
2-
#include "GLFW/glfw3.h"
32
#include "device.hpp"
43
#include "context.hpp"
54
#include "global_managers_init.hpp"
65
#include <stdlib.h>
76
#include <cmath>
87

8+
#include <SDL3/SDL.h>
9+
910
#ifndef _WIN32
1011
#include <unistd.h>
1112
#endif
@@ -38,24 +39,20 @@ static void import_semaphore(GLuint &glsem, const ExternalHandle &handle)
3839
int main()
3940
{
4041
Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
41-
if (!glfwInit())
42+
if (SDL_Init(SDL_INIT_VIDEO) < 0)
4243
return EXIT_FAILURE;
4344

44-
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
45-
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
46-
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
47-
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
48-
49-
GLFWwindow *window = glfwCreateWindow(1280, 720, "GL interop", nullptr, nullptr);
45+
SDL_Window *window = SDL_CreateWindow("GL interop", 1280, 720, SDL_WINDOW_OPENGL);
5046
if (!window)
5147
{
5248
LOGE("Failed to create window.\n");
5349
return EXIT_FAILURE;
5450
}
5551

56-
glfwMakeContextCurrent(window);
52+
SDL_GLContext glctx = SDL_GL_CreateContext(window);
53+
SDL_GL_MakeCurrent(window, glctx);
5754

58-
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
55+
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
5956
{
6057
LOGE("Failed to load GL context functions.\n");
6158
return EXIT_FAILURE;
@@ -81,7 +78,7 @@ int main()
8178
}
8279
#endif
8380

84-
glfwSwapInterval(1);
81+
SDL_GL_SetSwapInterval(1);
8582
unsigned frame_count = 0;
8683

8784
Context ctx;
@@ -134,12 +131,12 @@ int main()
134131
LOGI("GL vendor: %s\n", vendor);
135132

136133
auto &features = device.get_device_features();
137-
if (features.id_properties.deviceLUIDValid)
134+
if (features.vk11_props.deviceLUIDValid)
138135
{
139136
GLubyte luid[GL_LUID_SIZE_EXT] = {};
140137
glGetUnsignedBytevEXT(GL_DEVICE_LUID_EXT, luid);
141138

142-
if (memcmp(features.id_properties.deviceLUID, luid, GL_LUID_SIZE_EXT) != 0)
139+
if (memcmp(features.vk11_props.deviceLUID, luid, GL_LUID_SIZE_EXT) != 0)
143140
{
144141
LOGE("LUID mismatch.\n");
145142
return EXIT_FAILURE;
@@ -178,9 +175,13 @@ int main()
178175
return EXIT_FAILURE;
179176
}
180177

181-
while (!glfwWindowShouldClose(window))
178+
bool alive = true;
179+
SDL_Event e;
180+
while (alive)
182181
{
183-
glfwPollEvents();
182+
while (SDL_PollEvent(&e))
183+
if (e.type == SDL_EVENT_QUIT)
184+
alive = false;
184185

185186
// Render frame in Vulkan
186187
{
@@ -243,7 +244,7 @@ int main()
243244
}
244245

245246
int fb_width, fb_height;
246-
glfwGetFramebufferSize(window, &fb_width, &fb_height);
247+
SDL_GetWindowSize(window, &fb_width, &fb_height);
247248

248249
glBlitNamedFramebuffer(glfbo, 0,
249250
0, 0, GLint(image->get_width()), GLint(image->get_height()),
@@ -273,7 +274,7 @@ int main()
273274
glDeleteSemaphoresEXT(1, &glsem);
274275
}
275276

276-
glfwSwapBuffers(window);
277+
SDL_GL_SwapWindow(window);
277278
device.next_frame_context();
278279
frame_count++;
279280
}
@@ -284,6 +285,7 @@ int main()
284285

285286
check_gl_error();
286287

287-
glfwDestroyWindow(window);
288-
glfwTerminate();
288+
SDL_GL_DeleteContext(glctx);
289+
SDL_DestroyWindow(window);
290+
SDL_Quit();
289291
}

0 commit comments

Comments
 (0)