mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 00:49:48 +00:00
Null: Add limited EGL context creation on Mesa
This provides very limited support for context creation via EGL on the Null platform. It supports Unix-like systems with a version of Mesa that provides EGL_MESA_platform_surfaceless. Even then, the actual framebuffer provided is not resized along with the 'window'. That will hopefully change once context and framebuffer creation are separated, but this commit should at least allow more applications than before to run on the Null platform.
This commit is contained in:
+33
-8
@@ -92,7 +92,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
||||
EGLConfig* nativeConfigs;
|
||||
_GLFWfbconfig* usableConfigs;
|
||||
const _GLFWfbconfig* closest;
|
||||
int i, nativeCount, usableCount, apiBit;
|
||||
int i, nativeCount, usableCount, apiBit, surfaceTypeBit;
|
||||
GLFWbool wrongApiAvailable = GLFW_FALSE;
|
||||
|
||||
if (ctxconfig->client == GLFW_OPENGL_ES_API)
|
||||
@@ -105,6 +105,11 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
||||
else
|
||||
apiBit = EGL_OPENGL_BIT;
|
||||
|
||||
if (_glfw.egl.platform == EGL_PLATFORM_SURFACELESS_MESA)
|
||||
surfaceTypeBit = EGL_PBUFFER_BIT;
|
||||
else
|
||||
surfaceTypeBit = EGL_WINDOW_BIT;
|
||||
|
||||
if (fbconfig->stereo)
|
||||
{
|
||||
_glfwInputError(GLFW_FORMAT_UNAVAILABLE, "EGL: Stereo rendering not supported");
|
||||
@@ -133,8 +138,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
||||
if (getEGLConfigAttrib(n, EGL_COLOR_BUFFER_TYPE) != EGL_RGB_BUFFER)
|
||||
continue;
|
||||
|
||||
// Only consider window EGLConfigs
|
||||
if (!(getEGLConfigAttrib(n, EGL_SURFACE_TYPE) & EGL_WINDOW_BIT))
|
||||
if (!(getEGLConfigAttrib(n, EGL_SURFACE_TYPE) & surfaceTypeBit))
|
||||
continue;
|
||||
|
||||
#if defined(_GLFW_X11)
|
||||
@@ -420,6 +424,8 @@ GLFWbool _glfwInitEGL(void)
|
||||
_glfwPlatformGetModuleSymbol(_glfw.egl.handle, "eglDestroyContext");
|
||||
_glfw.egl.CreateWindowSurface = (PFN_eglCreateWindowSurface)
|
||||
_glfwPlatformGetModuleSymbol(_glfw.egl.handle, "eglCreateWindowSurface");
|
||||
_glfw.egl.CreatePbufferSurface = (PFN_eglCreatePbufferSurface)
|
||||
_glfwPlatformGetModuleSymbol(_glfw.egl.handle, "eglCreatePbufferSurface");
|
||||
_glfw.egl.MakeCurrent = (PFN_eglMakeCurrent)
|
||||
_glfwPlatformGetModuleSymbol(_glfw.egl.handle, "eglMakeCurrent");
|
||||
_glfw.egl.SwapBuffers = (PFN_eglSwapBuffers)
|
||||
@@ -442,6 +448,7 @@ GLFWbool _glfwInitEGL(void)
|
||||
!_glfw.egl.DestroySurface ||
|
||||
!_glfw.egl.DestroyContext ||
|
||||
!_glfw.egl.CreateWindowSurface ||
|
||||
!_glfw.egl.CreatePbufferSurface ||
|
||||
!_glfw.egl.MakeCurrent ||
|
||||
!_glfw.egl.SwapBuffers ||
|
||||
!_glfw.egl.SwapInterval ||
|
||||
@@ -477,6 +484,8 @@ GLFWbool _glfwInitEGL(void)
|
||||
_glfwStringInExtensionString("EGL_ANGLE_platform_angle_vulkan", extensions);
|
||||
_glfw.egl.ANGLE_platform_angle_metal =
|
||||
_glfwStringInExtensionString("EGL_ANGLE_platform_angle_metal", extensions);
|
||||
_glfw.egl.MESA_platform_surfaceless =
|
||||
_glfwStringInExtensionString("EGL_MESA_platform_surfaceless", extensions);
|
||||
}
|
||||
|
||||
if (_glfw.egl.EXT_platform_base)
|
||||
@@ -708,20 +717,36 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
|
||||
SET_ATTRIB(EGL_PRESENT_OPAQUE_EXT, !fbconfig->transparent);
|
||||
}
|
||||
|
||||
if (_glfw.egl.platform == EGL_PLATFORM_SURFACELESS_MESA)
|
||||
{
|
||||
int width, height;
|
||||
_glfw.platform.getFramebufferSize(window, &width, &height);
|
||||
|
||||
SET_ATTRIB(EGL_WIDTH, width);
|
||||
SET_ATTRIB(EGL_HEIGHT, height);
|
||||
}
|
||||
|
||||
SET_ATTRIB(EGL_NONE, EGL_NONE);
|
||||
|
||||
native = _glfw.platform.getEGLNativeWindow(window);
|
||||
// HACK: ANGLE does not implement eglCreatePlatformWindowSurfaceEXT
|
||||
// despite reporting EGL_EXT_platform_base
|
||||
if (_glfw.egl.platform && _glfw.egl.platform != EGL_PLATFORM_ANGLE_ANGLE)
|
||||
if (!_glfw.egl.platform || _glfw.egl.platform == EGL_PLATFORM_ANGLE_ANGLE)
|
||||
{
|
||||
// HACK: Also use non-platform function for ANGLE, as it does not
|
||||
// implement eglCreatePlatformWindowSurfaceEXT despite reporting
|
||||
// support for EGL_EXT_platform_base
|
||||
window->context.egl.surface =
|
||||
eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, config, native, attribs);
|
||||
eglCreateWindowSurface(_glfw.egl.display, config, native, attribs);
|
||||
}
|
||||
else if (_glfw.egl.platform == EGL_PLATFORM_SURFACELESS_MESA)
|
||||
{
|
||||
// HACK: Use a pbuffer surface as the default framebuffer
|
||||
window->context.egl.surface =
|
||||
eglCreatePbufferSurface(_glfw.egl.display, config, attribs);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->context.egl.surface =
|
||||
eglCreateWindowSurface(_glfw.egl.display, config, native, attribs);
|
||||
eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, config, native, attribs);
|
||||
}
|
||||
|
||||
if (window->context.egl.surface == EGL_NO_SURFACE)
|
||||
|
||||
Reference in New Issue
Block a user