diff --git a/projects/apis/opengl/loader/opengl_instance_loader.c b/projects/apis/opengl/loader/opengl_instance_loader.c index b66e65f..33bcb00 100644 --- a/projects/apis/opengl/loader/opengl_instance_loader.c +++ b/projects/apis/opengl/loader/opengl_instance_loader.c @@ -1,5 +1,6 @@ #include "opengl_loader.h" #include "instance/opengl_instance.h" +#include "surface/opengl_surface.h" gnInstanceFunctions loadOpenGLInstanceFunctions() { return (gnInstanceFunctions){ @@ -9,6 +10,11 @@ gnInstanceFunctions loadOpenGLInstanceFunctions() { // ._gnQueueCanPresentToSurface = metalCanQueuePresentToSurface, // ._gnCreateOutputDevice = createMetalOutputDevice, // ._gnDestroyOutputDevice = destroyMetalOutputDevice, + #ifdef GN_PLATFORM_LINUX + #ifdef GN_WINDOW_X11 + ._gnCreateX11WindowSurface = createGLXContext, + #endif + #endif // ._gnCreateMacOSWindowSurface = createMetalSurface, // ._gnDestroyWindowSurface = destroyMetalWindowSurface, // ._gnGetSurfaceDetails = getMetalSurfaceDetails diff --git a/projects/apis/opengl/src/surface/opengl_surface.c b/projects/apis/opengl/src/surface/opengl_surface.c new file mode 100644 index 0000000..ac3ff61 --- /dev/null +++ b/projects/apis/opengl/src/surface/opengl_surface.c @@ -0,0 +1,28 @@ +#include "opengl_surface.h" + +#ifdef GN_PLATFORM_LINUX +#ifdef GN_WINDOW_X11 +#include +gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo) { + windowSurface->windowSurface = malloc(sizeof(gnPlatformWindowSurface)); + int attribs[] = { + GLX_RGBA, + GLX_DEPTH_SIZE, 24, + GLX_DOUBLEBUFFER, + None + }; + + XVisualInfo* vi = glXChooseVisual(createInfo.display, 0, attribs); + 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; + return GN_SUCCESS; +} +#endif + +#ifdef GN_WINFDOW_WAYLAND +gnReturnCode gnCreateWaylandWindowSurface(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnWaylandWindowSurfaceInfo createInfo) { + return GN_FAILED_TO_ATTACH_WINDOW; +} +#endif +#endif diff --git a/projects/apis/opengl/src/surface/opengl_surface.h b/projects/apis/opengl/src/surface/opengl_surface.h new file mode 100644 index 0000000..baa66b0 --- /dev/null +++ b/projects/apis/opengl/src/surface/opengl_surface.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include "core/src/window_surface/gryphn_surface_create_functions.h" + +#ifdef GN_PLATFORM_LINUX +#ifdef GN_WINDOW_X11 +#include +typedef struct gnPlatformWindowSurface_t { + GLXContext context; +} gnPlatformWindowSurface; +gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHandle instance, gnX11WindowSurfaceInfo createInfo); +#endif +#endif