surface details function

This commit is contained in:
Gregory Wells
2025-07-10 15:15:24 -04:00
parent 0dc2e035ab
commit fbd4c01e73
4 changed files with 39 additions and 3 deletions

View File

@@ -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")

View File

@@ -16,8 +16,7 @@ gnInstanceFunctions loadOpenGLInstanceFunctions() {
._gnCreateX11WindowSurface = createGLXContext,
#endif
#endif
// ._gnCreateMacOSWindowSurface = createMetalSurface,
// ._gnDestroyWindowSurface = destroyMetalWindowSurface,
// ._gnGetSurfaceDetails = getMetalSurfaceDetails
._gnGetSurfaceDetails = genOpenGLSurfaceDetails
};
}

View File

@@ -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;
}

View File

@@ -6,8 +6,13 @@
#ifdef GN_WINDOW_X11
#include <GL/glx.h>
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);