Commit a8ea120c authored by Camilla Berglund's avatar Camilla Berglund
Browse files

Removed internal fbconfig enum and selection.

parent 0517a824
......@@ -92,169 +92,6 @@ static GLboolean parseGLVersion(int* api, int* major, int* minor, int* rev)
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return the available framebuffer config closest to the desired values
// This is based on the manual GLX Visual selection from 2.6
//========================================================================
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
const _GLFWfbconfig* alternatives,
unsigned int count)
{
unsigned int i;
unsigned int missing, leastMissing = UINT_MAX;
unsigned int colorDiff, leastColorDiff = UINT_MAX;
unsigned int extraDiff, leastExtraDiff = UINT_MAX;
const _GLFWfbconfig* current;
const _GLFWfbconfig* closest = NULL;
for (i = 0; i < count; i++)
{
current = alternatives + i;
if (desired->stereo > 0 && current->stereo == 0)
{
// Stereo is a hard constraint
continue;
}
// Count number of missing buffers
{
missing = 0;
if (desired->alphaBits > 0 && current->alphaBits == 0)
missing++;
if (desired->depthBits > 0 && current->depthBits == 0)
missing++;
if (desired->stencilBits > 0 && current->stencilBits == 0)
missing++;
if (desired->auxBuffers > 0 && current->auxBuffers < desired->auxBuffers)
missing += desired->auxBuffers - current->auxBuffers;
if (desired->samples > 0 && current->samples == 0)
{
// Technically, several multisampling buffers could be
// involved, but that's a lower level implementation detail and
// not important to us here, so we count them as one
missing++;
}
}
// These polynomials make many small channel size differences matter
// less than one large channel size difference
// Calculate color channel size difference value
{
colorDiff = 0;
if (desired->redBits > 0)
{
colorDiff += (desired->redBits - current->redBits) *
(desired->redBits - current->redBits);
}
if (desired->greenBits > 0)
{
colorDiff += (desired->greenBits - current->greenBits) *
(desired->greenBits - current->greenBits);
}
if (desired->blueBits > 0)
{
colorDiff += (desired->blueBits - current->blueBits) *
(desired->blueBits - current->blueBits);
}
}
// Calculate non-color channel size difference value
{
extraDiff = 0;
if (desired->alphaBits > 0)
{
extraDiff += (desired->alphaBits - current->alphaBits) *
(desired->alphaBits - current->alphaBits);
}
if (desired->depthBits > 0)
{
extraDiff += (desired->depthBits - current->depthBits) *
(desired->depthBits - current->depthBits);
}
if (desired->stencilBits > 0)
{
extraDiff += (desired->stencilBits - current->stencilBits) *
(desired->stencilBits - current->stencilBits);
}
if (desired->accumRedBits > 0)
{
extraDiff += (desired->accumRedBits - current->accumRedBits) *
(desired->accumRedBits - current->accumRedBits);
}
if (desired->accumGreenBits > 0)
{
extraDiff += (desired->accumGreenBits - current->accumGreenBits) *
(desired->accumGreenBits - current->accumGreenBits);
}
if (desired->accumBlueBits > 0)
{
extraDiff += (desired->accumBlueBits - current->accumBlueBits) *
(desired->accumBlueBits - current->accumBlueBits);
}
if (desired->accumAlphaBits > 0)
{
extraDiff += (desired->accumAlphaBits - current->accumAlphaBits) *
(desired->accumAlphaBits - current->accumAlphaBits);
}
if (desired->samples > 0)
{
extraDiff += (desired->samples - current->samples) *
(desired->samples - current->samples);
}
if (desired->sRGB)
{
if (!current->sRGB)
extraDiff++;
}
}
// Figure out if the current one is better than the best one found so far
// Least number of missing buffers is the most important heuristic,
// then color buffer size match and lastly size match for other buffers
if (missing < leastMissing)
closest = current;
else if (missing == leastMissing)
{
if ((colorDiff < leastColorDiff) ||
(colorDiff == leastColorDiff && extraDiff < leastExtraDiff))
{
closest = current;
}
}
if (current == closest)
{
leastMissing = missing;
leastColorDiff = colorDiff;
leastExtraDiff = extraDiff;
}
}
return closest;
}
//========================================================================
// Checks whether the client API part of the window config is sane
//========================================================================
......
......@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//========================================================================
......@@ -52,139 +53,62 @@
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
//========================================================================
// Returns the specified attribute of the specified EGLConfig
//========================================================================
static int getConfigAttrib(EGLConfig config, int attrib)
{
int value;
eglGetConfigAttrib(_glfw.egl.display, config, attrib, &value);
return value;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Return a list of available and usable framebuffer configs
// Initialize EGL
//========================================================================
static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
unsigned int* found)
int _glfwInitOpenGL(void)
{
EGLConfig* configs;
_GLFWfbconfig* result;
int i, count = 0;
*found = 0;
eglGetConfigs(_glfw.egl.display, NULL, 0, &count);
configs = (EGLConfig*) malloc(sizeof(EGLConfig) * count);
if (!configs)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
eglGetConfigs(_glfw.egl.display, configs, count, &count);
if (!count)
_glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY);
if (_glfw.egl.display == EGL_NO_DISPLAY)
{
free(configs);
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: No EGLConfigs returned");
return NULL;
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to get EGL display");
return GL_FALSE;
}
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
if (!result)
if (!eglInitialize(_glfw.egl.display,
&_glfw.egl.versionMajor,
&_glfw.egl.versionMinor))
{
free(configs);
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to initialize EGL");
return GL_FALSE;
}
for (i = 0; i < count; i++)
{
_GLFWfbconfig* f = result + *found;
#if defined(_GLFW_X11)
if (!getConfigAttrib(configs[i], EGL_NATIVE_VISUAL_ID))
{
// Only consider EGLConfigs with associated visuals
continue;
}
#endif // _GLFW_X11
if (!(getConfigAttrib(configs[i], EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER))
{
// Only consider RGB(A) EGLConfigs
continue;
}
if (!(getConfigAttrib(configs[i], EGL_SURFACE_TYPE) & EGL_WINDOW_BIT))
{
// Only consider window EGLConfigs
continue;
}
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
if (wndconfig->glMajor == 1)
{
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT))
continue;
}
else
{
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
continue;
}
}
else if (wndconfig->clientAPI == GLFW_OPENGL_API)
{
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_BIT))
continue;
}
f->redBits = getConfigAttrib(configs[i], EGL_RED_SIZE);
f->greenBits = getConfigAttrib(configs[i], EGL_GREEN_SIZE);
f->blueBits = getConfigAttrib(configs[i], EGL_BLUE_SIZE);
f->alphaBits = getConfigAttrib(configs[i], EGL_ALPHA_SIZE);
f->depthBits = getConfigAttrib(configs[i], EGL_DEPTH_SIZE);
f->stencilBits = getConfigAttrib(configs[i], EGL_STENCIL_SIZE);
f->samples = getConfigAttrib(configs[i], EGL_SAMPLES);
if (_glfwPlatformExtensionSupported("EGL_KHR_create_context"))
_glfw.egl.KHR_create_context = GL_TRUE;
// NOTE: There does not appear to be any way to request sRGB
// framebuffers for OpenGL or GLES contexts; only for OpenVG ones
f->sRGB = GL_FALSE;
return GL_TRUE;
}
f->platformID = (GLFWintptr) getConfigAttrib(configs[i], EGL_CONFIG_ID);
(*found)++;
}
//========================================================================
// Terminate EGL
//========================================================================
free(configs);
return result;
void _glfwTerminateOpenGL(void)
{
eglTerminate(_glfw.egl.display);
}
//========================================================================
// Create the actual OpenGL(|ES) context
// Prepare for creation of the OpenGL context
//========================================================================
#define setEGLattrib(attribName, attribValue) \
{ \
attribs[index++] = attribName; \
attribs[index++] = attribValue; \
assert(index < sizeof(attribs) / sizeof(attribs[0])); \
}
static int createContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
EGLint fbconfigID)
int _glfwCreateContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
int attribs[40];
EGLint count;
......@@ -198,7 +122,28 @@ static int createContext(_GLFWwindow* window,
{
int index = 0;
setEGLattrib(EGL_CONFIG_ID, fbconfigID);
setEGLattrib(EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER);
if (fbconfig->redBits)
setEGLattrib(EGL_RED_SIZE, fbconfig->redBits);
if (fbconfig->greenBits)
setEGLattrib(EGL_GREEN_SIZE, fbconfig->greenBits);
if (fbconfig->blueBits)
setEGLattrib(EGL_BLUE_SIZE, fbconfig->blueBits);
if (fbconfig->alphaBits)
setEGLattrib(EGL_BLUE_SIZE, fbconfig->alphaBits);
if (fbconfig->depthBits)
setEGLattrib(EGL_DEPTH_SIZE, fbconfig->depthBits);
if (fbconfig->stencilBits)
setEGLattrib(EGL_STENCIL_SIZE, fbconfig->stencilBits);
if (fbconfig->samples)
{
setEGLattrib(EGL_SAMPLE_BUFFERS, 1);
setEGLattrib(EGL_SAMPLES, fbconfig->samples);
}
setEGLattrib(EGL_NONE, EGL_NONE);
eglChooseConfig(_glfw.egl.display, attribs, &config, 1, &count);
......@@ -351,90 +296,6 @@ static int createContext(_GLFWwindow* window,
#undef setEGLattrib
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialize EGL
//========================================================================
int _glfwInitOpenGL(void)
{
_glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY);
if (_glfw.egl.display == EGL_NO_DISPLAY)
{
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to get EGL display");
return GL_FALSE;
}
if (!eglInitialize(_glfw.egl.display,
&_glfw.egl.versionMajor,
&_glfw.egl.versionMinor))
{
_glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to initialize EGL");
return GL_FALSE;
}
if (_glfwPlatformExtensionSupported("EGL_KHR_create_context"))
_glfw.egl.KHR_create_context = GL_TRUE;
return GL_TRUE;
}
//========================================================================
// Terminate EGL
//========================================================================
void _glfwTerminateOpenGL(void)
{
eglTerminate(_glfw.egl.display);
}
//========================================================================
// Prepare for creation of the OpenGL context
//========================================================================
int _glfwCreateContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
_GLFWfbconfig closest;
// Choose the best available fbconfig
{
unsigned int fbcount;
_GLFWfbconfig* fbconfigs;
const _GLFWfbconfig* result;
fbconfigs = getFBConfigs(window, wndconfig, &fbcount);
if (!fbconfigs)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: No usable EGLFBConfigs found");
return GL_FALSE;
}
result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount);
if (!result)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"EGL: No EGLFBConfig matched the criteria");
free(fbconfigs);
return GL_FALSE;
}
closest = *result;
free(fbconfigs);
}
return createContext(window, wndconfig, closest.platformID);
}
//========================================================================
// Destroy the OpenGL context
//========================================================================
......
This diff is collapsed.
......@@ -177,11 +177,8 @@ struct _GLFWwndconfig
/*! @brief Framebuffer configuration.
*
* This describes buffers and their sizes. It also contains
* a platform-specific ID used to map back to the backend API's object.
*
* It is used to pass framebuffer parameters from shared code to the
* platform API and also to enumerate and select available framebuffer configs.
* This describes buffers and their sizes. It is used to pass framebuffer
* parameters from shared code to the platform API.
*/
struct _GLFWfbconfig
{
......@@ -199,7 +196,6 @@ struct _GLFWfbconfig
GLboolean stereo;
int samples;
GLboolean sRGB;
GLFWintptr platformID;
};
......@@ -671,18 +667,6 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
*/
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
/*! @brief Chooses the framebuffer config that best matches the desired one.
* @param[in] desired The desired framebuffer config.
* @param[in] alternatives The framebuffer configs supported by the system.
* @param[in] count The number of entries in the alternatives array.
* @return The framebuffer config most closely matching the desired one, or @c
* NULL if none fulfilled the hard constraints of the desired values.
* @ingroup utility
*/
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
const _GLFWfbconfig* alternatives,
unsigned int count);
/*! @brief Checks and reads back properties from the current context.
* @return @c GL_TRUE if successful, or @c GL_FALSE if the context is unusable.
* @ingroup utility
......
......@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <malloc.h>
#include <assert.h>
//========================================================================
......@@ -64,7 +65,7 @@ static void initWGLExtensions(_GLFWwindow* window)
{
// This needs to include every function pointer loaded below
window->wgl.SwapIntervalEXT = NULL;
window->wgl.GetPixelFormatAttribivARB = NULL;
window->wgl.ChoosePixelFormatARB = NULL;
window->wgl.GetExtensionsStringARB = NULL;
window->wgl.GetExtensionsStringEXT = NULL;
window->wgl.CreateContextAttribsARB = NULL;
......@@ -135,215 +136,146 @@ static void initWGLExtensions(_GLFWwindow* window)
if (_glfwPlatformExtensionSupported("WGL_ARB_pixel_format"))
{
window->wgl.GetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)
wglGetProcAddress("wglGetPixelFormatAttribivARB");
window->wgl.ChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)
wglGetProcAddress("wglChoosePixelFormatARB");
if (window->wgl.GetPixelFormatAttribivARB)
if (window->wgl.ChoosePixelFormatARB)
window->wgl.ARB_pixel_format = GL_TRUE;
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Returns the specified attribute of the specified pixel format
// NOTE: Do not call this unless we have found WGL_ARB_pixel_format
// Prepare for creation of the OpenGL context
//========================================================================
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
{
int value = 0;
if (!window->wgl.GetPixelFormatAttribivARB(window->wgl.dc,
pixelFormat,
0, 1, &attrib, &value))
{
// NOTE: We should probably handle this error somehow
return 0;
}
return value;
#define setWGLattrib(attribName, attribValue) \
{ \
attribs[index++] = attribName; \
attribs[index++] = attribValue; \
assert(index < sizeof(attribs) / sizeof(attribs[0])); \
}
//========================================================================
// Return a list of available and usable framebuffer configs
//========================================================================
static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
int _glfwCreateContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig)
{
_GLFWfbconfig* fbconfigs;
int attribs[40];
int pixelFormat;
PIXELFORMATDESCRIPTOR pfd;
int i, available;
*found = 0;
if (window->wgl.ARB_pixel_format)
{
available = getPixelFormatAttrib(window,
1,
WGL_NUMBER_PIXEL_FORMATS_ARB);
}
else
{
available = DescribePixelFormat(window->wgl.dc,
1,
sizeof(PIXELFORMATDESCRIPTOR),
NULL);
}
HGLRC share = NULL;
if (!available)
{
_glfwInputError(GLFW_API_UNAVAILABLE, "WGL: No pixel formats found");
return NULL;
}
if (wndconfig->share)
share = wndconfig->share->wgl.context;
fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available);
if (!fbconfigs)
window->wgl.dc = GetDC(window->win32.handle);
if (!window->wgl.dc)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve DC for window");
return GL_FALSE;
}
for (i = 1; i <= available; i++)
if (window->wgl.ARB_pixel_format)
{
_GLFWfbconfig* f = fbconfigs + *found;
if (window->wgl.ARB_pixel_format)