From fbd4c01e73a330fbf78599f8b55495aa13e14056 Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Thu, 10 Jul 2025 15:15:24 -0400 Subject: [PATCH] surface details function --- projects/apis/opengl/CMakeLists.txt | 2 +- .../opengl/loader/opengl_instance_loader.c | 3 +- .../apis/opengl/src/surface/opengl_surface.c | 32 +++++++++++++++++++ .../apis/opengl/src/surface/opengl_surface.h | 5 +++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/projects/apis/opengl/CMakeLists.txt b/projects/apis/opengl/CMakeLists.txt index 93d5cd2..e5df6b9 100644 --- a/projects/apis/opengl/CMakeLists.txt +++ b/projects/apis/opengl/CMakeLists.txt @@ -20,4 +20,4 @@ target_include_directories(GryphnOpenGLImpl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/ ) add_compile_definitions(GN_REVEAL_IMPL) -target_link_libraries(GryphnOpenGLImpl GL) +target_link_libraries(GryphnOpenGLImpl GL "X11") diff --git a/projects/apis/opengl/loader/opengl_instance_loader.c b/projects/apis/opengl/loader/opengl_instance_loader.c index 05b664d..b14f7a2 100644 --- a/projects/apis/opengl/loader/opengl_instance_loader.c +++ b/projects/apis/opengl/loader/opengl_instance_loader.c @@ -16,8 +16,7 @@ gnInstanceFunctions loadOpenGLInstanceFunctions() { ._gnCreateX11WindowSurface = createGLXContext, #endif #endif - // ._gnCreateMacOSWindowSurface = createMetalSurface, // ._gnDestroyWindowSurface = destroyMetalWindowSurface, - // ._gnGetSurfaceDetails = getMetalSurfaceDetails + ._gnGetSurfaceDetails = genOpenGLSurfaceDetails }; } diff --git a/projects/apis/opengl/src/surface/opengl_surface.c b/projects/apis/opengl/src/surface/opengl_surface.c index ac3ff61..85a7343 100644 --- a/projects/apis/opengl/src/surface/opengl_surface.c +++ b/projects/apis/opengl/src/surface/opengl_surface.c @@ -16,8 +16,17 @@ gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHan windowSurface->windowSurface->context = glXCreateContext(createInfo.display, vi, NULL, GL_TRUE); if (glXMakeCurrent(createInfo.display, createInfo.window, windowSurface->windowSurface->context) == GL_FALSE) return GN_FAILED_TO_ATTACH_WINDOW; + windowSurface->windowSurface->window = createInfo.window; + windowSurface->windowSurface->display = createInfo.display; return GN_SUCCESS; } + +gnUInt2 getWindowSize(gnPlatformWindowSurface* surface) { + XWindowAttributes attr; + XGetWindowAttributes(surface->display, surface->window, &attr); + return (gnUInt2){ attr.width, attr.height }; +} + #endif #ifdef GN_WINFDOW_WAYLAND @@ -26,3 +35,26 @@ gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle windowSurface, g } #endif #endif + +gnSurfaceDetails genOpenGLSurfaceDetails( + gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device +) { + gnSurfaceDetails surfaceDetails; + surfaceDetails.formatCount = 1; + surfaceDetails.formats = (gnSurfaceFormat[]){ + (gnSurfaceFormat){ + .format = GN_FORMAT_RGBA8_SRGB, + .colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR + } + }; + + surfaceDetails.minImageCount = 2; + surfaceDetails.maxImageCount = 3; + + gnUInt2 windowSize = getWindowSize(windowSurface->windowSurface); + surfaceDetails.minImageSize = windowSize; + surfaceDetails.maxImageSize = windowSize; + surfaceDetails.currentSize = windowSize; + + return surfaceDetails; +} diff --git a/projects/apis/opengl/src/surface/opengl_surface.h b/projects/apis/opengl/src/surface/opengl_surface.h index baa66b0..c9df2ac 100644 --- a/projects/apis/opengl/src/surface/opengl_surface.h +++ b/projects/apis/opengl/src/surface/opengl_surface.h @@ -6,8 +6,13 @@ #ifdef GN_WINDOW_X11 #include typedef struct gnPlatformWindowSurface_t { + Window window; + Display* display; GLXContext context; } gnPlatformWindowSurface; gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo); #endif #endif + +gnUInt2 getWindowSize(gnPlatformWindowSurface* surface); +gnSurfaceDetails genOpenGLSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device);