mirror of
https://github.com/glfw/glfw.git
synced 2024-11-13 14:03:52 +00:00
Removed hard-coded EGL config limit.
This commit is contained in:
parent
af925681dd
commit
ddb497c5d5
@ -33,9 +33,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// Max number of EGL configuration we handle
|
|
||||||
#define _GLFW_EGL_CONFIG_IN 15
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Returns the specified attribute of the specified EGLConfig
|
// Returns the specified attribute of the specified EGLConfig
|
||||||
@ -57,16 +54,26 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
|
|||||||
const _GLFWwndconfig* wndconfig,
|
const _GLFWwndconfig* wndconfig,
|
||||||
unsigned int* found)
|
unsigned int* found)
|
||||||
{
|
{
|
||||||
EGLConfig fbconfigs[_GLFW_EGL_CONFIG_IN];
|
EGLConfig* fbconfigs;
|
||||||
_GLFWfbconfig* result;
|
_GLFWfbconfig* result;
|
||||||
int i, count = 0;
|
int i, count = 0;
|
||||||
|
|
||||||
*found = 0;
|
*found = 0;
|
||||||
|
|
||||||
eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs,
|
eglGetConfigs(_glfwLibrary.EGL.display, NULL, 0, &count);
|
||||||
_GLFW_EGL_CONFIG_IN, &count);
|
|
||||||
|
fbconfigs = (EGLConfig*) malloc(sizeof(EGLConfig) * count);
|
||||||
|
if (!fbconfigs)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, count, &count);
|
||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
|
free(fbconfigs);
|
||||||
|
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
|
||||||
"X11/EGL: No EGLConfigs returned");
|
"X11/EGL: No EGLConfigs returned");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -75,8 +82,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
|
|||||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY,
|
free(fbconfigs);
|
||||||
"X11/EGL: Failed to allocate _GLFWfbconfig array");
|
|
||||||
|
_glfwSetError(GLFW_OUT_OF_MEMORY, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +138,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
|
|||||||
(*found)++;
|
(*found)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fbconfigs);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,18 +149,13 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
|
|||||||
|
|
||||||
static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID)
|
static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID)
|
||||||
{
|
{
|
||||||
EGLint dummy;
|
EGLint count;
|
||||||
EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN];
|
EGLConfig fbconfig;
|
||||||
|
|
||||||
int attribs[] = { EGL_CONFIG_ID, fbconfigID, None };
|
int attribs[] = { EGL_CONFIG_ID, fbconfigID, None };
|
||||||
|
|
||||||
eglChooseConfig(_glfwLibrary.EGL.display,
|
eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count);
|
||||||
attribs,
|
if (!count)
|
||||||
fbconfig,
|
|
||||||
_GLFW_EGL_CONFIG_IN,
|
|
||||||
&dummy);
|
|
||||||
|
|
||||||
if (!dummy)
|
|
||||||
{
|
{
|
||||||
// This should never ever happen
|
// This should never ever happen
|
||||||
// TODO: Flag this as an error and propagate up
|
// TODO: Flag this as an error and propagate up
|
||||||
@ -165,15 +169,15 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID)
|
|||||||
// true sounds better than false, so we hardcode true here
|
// true sounds better than false, so we hardcode true here
|
||||||
window->accelerated = GL_TRUE;
|
window->accelerated = GL_TRUE;
|
||||||
|
|
||||||
window->redBits = getFBConfigAttrib(*fbconfig, EGL_RED_SIZE);
|
window->redBits = getFBConfigAttrib(fbconfig, EGL_RED_SIZE);
|
||||||
window->greenBits = getFBConfigAttrib(*fbconfig, EGL_GREEN_SIZE);
|
window->greenBits = getFBConfigAttrib(fbconfig, EGL_GREEN_SIZE);
|
||||||
window->blueBits = getFBConfigAttrib(*fbconfig, EGL_BLUE_SIZE);
|
window->blueBits = getFBConfigAttrib(fbconfig, EGL_BLUE_SIZE);
|
||||||
|
|
||||||
window->alphaBits = getFBConfigAttrib(*fbconfig, EGL_ALPHA_SIZE);
|
window->alphaBits = getFBConfigAttrib(fbconfig, EGL_ALPHA_SIZE);
|
||||||
window->depthBits = getFBConfigAttrib(*fbconfig, EGL_DEPTH_SIZE);
|
window->depthBits = getFBConfigAttrib(fbconfig, EGL_DEPTH_SIZE);
|
||||||
window->stencilBits = getFBConfigAttrib(*fbconfig, EGL_STENCIL_SIZE);
|
window->stencilBits = getFBConfigAttrib(fbconfig, EGL_STENCIL_SIZE);
|
||||||
|
|
||||||
window->samples = getFBConfigAttrib(*fbconfig, EGL_SAMPLES);
|
window->samples = getFBConfigAttrib(fbconfig, EGL_SAMPLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,9 +194,9 @@ static int createContext(_GLFWwindow* window,
|
|||||||
EGLint fbconfigID)
|
EGLint fbconfigID)
|
||||||
{
|
{
|
||||||
int attribs[40], visMask;
|
int attribs[40], visMask;
|
||||||
EGLint dummy, index, visualID = 0;
|
EGLint count, index, visualID = 0;
|
||||||
EGLint red_size, green_size, blue_size, alpha_size;
|
EGLint red_size, green_size, blue_size, alpha_size;
|
||||||
EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN];
|
EGLConfig fbconfig;
|
||||||
EGLContext share = NULL;
|
EGLContext share = NULL;
|
||||||
XVisualInfo visTemplate;
|
XVisualInfo visTemplate;
|
||||||
|
|
||||||
@ -206,13 +210,8 @@ static int createContext(_GLFWwindow* window,
|
|||||||
setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID);
|
setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID);
|
||||||
setEGLattrib(attribs, index, EGL_NONE, EGL_NONE);
|
setEGLattrib(attribs, index, EGL_NONE, EGL_NONE);
|
||||||
|
|
||||||
eglChooseConfig(_glfwLibrary.EGL.display,
|
eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count);
|
||||||
attribs,
|
if (!count)
|
||||||
fbconfig,
|
|
||||||
_GLFW_EGL_CONFIG_IN,
|
|
||||||
&dummy);
|
|
||||||
|
|
||||||
if (!dummy)
|
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR,
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
"X11/EGL: Failed to retrieve the selected EGLConfig");
|
"X11/EGL: Failed to retrieve the selected EGLConfig");
|
||||||
@ -223,7 +222,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
// Retrieve the corresponding visual
|
// Retrieve the corresponding visual
|
||||||
// NOTE: This is the only non-portable code in this file.
|
// NOTE: This is the only non-portable code in this file.
|
||||||
// Maybe it would not hurt too much to add #ifdefs for different platforms?
|
// Maybe it would not hurt too much to add #ifdefs for different platforms?
|
||||||
eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, EGL_NATIVE_VISUAL_ID, &visualID);
|
eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_NATIVE_VISUAL_ID, &visualID);
|
||||||
|
|
||||||
// Init visual template
|
// Init visual template
|
||||||
visTemplate.screen = _glfwLibrary.X11.screen;
|
visTemplate.screen = _glfwLibrary.X11.screen;
|
||||||
@ -240,13 +239,13 @@ static int createContext(_GLFWwindow* window,
|
|||||||
// some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
|
// some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
|
||||||
// attribute, so attempt to find the closest match.
|
// attribute, so attempt to find the closest match.
|
||||||
|
|
||||||
eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig,
|
eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig,
|
||||||
EGL_RED_SIZE, &red_size);
|
EGL_RED_SIZE, &red_size);
|
||||||
eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig,
|
eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig,
|
||||||
EGL_GREEN_SIZE, &green_size);
|
EGL_GREEN_SIZE, &green_size);
|
||||||
eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig,
|
eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig,
|
||||||
EGL_BLUE_SIZE, &blue_size);
|
EGL_BLUE_SIZE, &blue_size);
|
||||||
eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig,
|
eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig,
|
||||||
EGL_ALPHA_SIZE, &alpha_size);
|
EGL_ALPHA_SIZE, &alpha_size);
|
||||||
|
|
||||||
visTemplate.depth = red_size + green_size + blue_size + alpha_size;
|
visTemplate.depth = red_size + green_size + blue_size + alpha_size;
|
||||||
@ -254,7 +253,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display,
|
window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display,
|
||||||
visMask, &visTemplate, &dummy);
|
visMask, &visTemplate, &count);
|
||||||
|
|
||||||
if (window->EGL.visual == NULL)
|
if (window->EGL.visual == NULL)
|
||||||
{
|
{
|
||||||
@ -278,7 +277,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
eglBindAPI(EGL_OPENGL_ES_API);
|
eglBindAPI(EGL_OPENGL_ES_API);
|
||||||
|
|
||||||
window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display,
|
window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display,
|
||||||
*fbconfig, share, attribs);
|
fbconfig, share, attribs);
|
||||||
|
|
||||||
if (window->EGL.context == EGL_NO_CONTEXT)
|
if (window->EGL.context == EGL_NO_CONTEXT)
|
||||||
{
|
{
|
||||||
@ -289,7 +288,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->EGL.config = *fbconfig;
|
window->EGL.config = fbconfig;
|
||||||
|
|
||||||
refreshContextParams(window, fbconfigID);
|
refreshContextParams(window, fbconfigID);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user