mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Adding array based call to wglGetPixelFormatAttribivARB to potentially resolve performance issue report.
This commit is contained in:
parent
5afcd0981b
commit
debabe815e
@ -32,6 +32,88 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Pixel format enum
|
||||||
|
typedef enum glfwEnumPixelFormatAttribs
|
||||||
|
{
|
||||||
|
GLFW_PFA_WGL_NUMBER_PIXEL_FORMATS_ARB,
|
||||||
|
GLFW_PFA_WGL_DRAW_TO_WINDOW_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCELERATION_ARB,
|
||||||
|
GLFW_PFA_WGL_SUPPORT_OPENGL_ARB,
|
||||||
|
GLFW_PFA_WGL_DOUBLE_BUFFER_ARB,
|
||||||
|
GLFW_PFA_WGL_STEREO_ARB,
|
||||||
|
GLFW_PFA_WGL_PIXEL_TYPE_ARB,
|
||||||
|
GLFW_PFA_WGL_RED_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_RED_SHIFT_ARB,
|
||||||
|
GLFW_PFA_WGL_GREEN_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_GREEN_SHIFT_ARB,
|
||||||
|
GLFW_PFA_WGL_BLUE_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_BLUE_SHIFT_ARB,
|
||||||
|
GLFW_PFA_WGL_ALPHA_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_ALPHA_SHIFT_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCUM_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCUM_RED_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCUM_GREEN_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCUM_BLUE_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_ACCUM_ALPHA_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_DEPTH_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_STENCIL_BITS_ARB,
|
||||||
|
GLFW_PFA_WGL_AUX_BUFFERS_ARB,
|
||||||
|
GLFW_PFA_WGL_SAMPLES_ARB,
|
||||||
|
GLFW_PFA_WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB,
|
||||||
|
GLFW_PFA_WGL_COLORSPACE_EXT,
|
||||||
|
|
||||||
|
GLFW_PFA_COUNT // Add values above this line.
|
||||||
|
} glfwEnumPixelFormatAttribs;
|
||||||
|
|
||||||
|
static int glfwPixelFormatAttribs[ GLFW_PFA_COUNT ] = {
|
||||||
|
WGL_NUMBER_PIXEL_FORMATS_ARB,
|
||||||
|
WGL_DRAW_TO_WINDOW_ARB,
|
||||||
|
WGL_ACCELERATION_ARB,
|
||||||
|
WGL_SUPPORT_OPENGL_ARB,
|
||||||
|
WGL_DOUBLE_BUFFER_ARB,
|
||||||
|
WGL_STEREO_ARB,
|
||||||
|
WGL_PIXEL_TYPE_ARB,
|
||||||
|
WGL_RED_BITS_ARB,
|
||||||
|
WGL_RED_SHIFT_ARB,
|
||||||
|
WGL_GREEN_BITS_ARB,
|
||||||
|
WGL_GREEN_SHIFT_ARB,
|
||||||
|
WGL_BLUE_BITS_ARB,
|
||||||
|
WGL_BLUE_SHIFT_ARB,
|
||||||
|
WGL_ALPHA_BITS_ARB,
|
||||||
|
WGL_ALPHA_SHIFT_ARB,
|
||||||
|
WGL_ACCUM_BITS_ARB,
|
||||||
|
WGL_ACCUM_RED_BITS_ARB,
|
||||||
|
WGL_ACCUM_GREEN_BITS_ARB,
|
||||||
|
WGL_ACCUM_BLUE_BITS_ARB,
|
||||||
|
WGL_ACCUM_ALPHA_BITS_ARB,
|
||||||
|
WGL_DEPTH_BITS_ARB,
|
||||||
|
WGL_STENCIL_BITS_ARB,
|
||||||
|
WGL_AUX_BUFFERS_ARB,
|
||||||
|
WGL_SAMPLES_ARB,
|
||||||
|
WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB,
|
||||||
|
WGL_COLORSPACE_EXT
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns all formats in glfwPixelFormats attribute of the specified pixel format
|
||||||
|
// values should be of size GLFW_PFA_COUNT and on return will hold integer values
|
||||||
|
// which can be indexed using glfwEnumPixelFormatAttribs
|
||||||
|
// returns 1 on success, 0 on failure
|
||||||
|
static int getPixelFormatAttribs(_GLFWwindow* window, int pixelFormat, int* values )
|
||||||
|
{
|
||||||
|
assert(_glfw.wgl.ARB_pixel_format);
|
||||||
|
|
||||||
|
if (!_glfw.wgl.GetPixelFormatAttribivARB(window->context.wgl.dc,
|
||||||
|
pixelFormat,
|
||||||
|
0, GLFW_PFA_COUNT, glfwPixelFormatAttribs, values))
|
||||||
|
{
|
||||||
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
||||||
|
"WGL: Failed to retrieve pixel format attributes");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the specified attribute of the specified pixel format
|
// Returns the specified attribute of the specified pixel format
|
||||||
//
|
//
|
||||||
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
|
static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib)
|
||||||
@ -87,54 +169,56 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||||||
if (_glfw.wgl.ARB_pixel_format)
|
if (_glfw.wgl.ARB_pixel_format)
|
||||||
{
|
{
|
||||||
// Get pixel format attributes through "modern" extension
|
// Get pixel format attributes through "modern" extension
|
||||||
|
int pixelFormatAttribs[GLFW_PFA_COUNT];
|
||||||
|
getPixelFormatAttribs(window, n, pixelFormatAttribs );
|
||||||
|
|
||||||
if (!getPixelFormatAttrib(window, n, WGL_SUPPORT_OPENGL_ARB) ||
|
if (!pixelFormatAttribs[GLFW_PFA_WGL_SUPPORT_OPENGL_ARB] ||
|
||||||
!getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB))
|
!pixelFormatAttribs[GLFW_PFA_WGL_DRAW_TO_WINDOW_ARB])
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPixelFormatAttrib(window, n, WGL_PIXEL_TYPE_ARB) !=
|
if (pixelFormatAttribs[GLFW_PFA_WGL_PIXEL_TYPE_ARB] !=
|
||||||
WGL_TYPE_RGBA_ARB )
|
WGL_TYPE_RGBA_ARB )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPixelFormatAttrib(window, n, WGL_ACCELERATION_ARB) ==
|
if (pixelFormatAttribs[GLFW_PFA_WGL_ACCELERATION_ARB] ==
|
||||||
WGL_NO_ACCELERATION_ARB )
|
WGL_NO_ACCELERATION_ARB )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
u->redBits = getPixelFormatAttrib(window, n, WGL_RED_BITS_ARB);
|
u->redBits = pixelFormatAttribs[GLFW_PFA_WGL_RED_BITS_ARB];
|
||||||
u->greenBits = getPixelFormatAttrib(window, n, WGL_GREEN_BITS_ARB);
|
u->greenBits = pixelFormatAttribs[GLFW_PFA_WGL_GREEN_BITS_ARB];
|
||||||
u->blueBits = getPixelFormatAttrib(window, n, WGL_BLUE_BITS_ARB);
|
u->blueBits = pixelFormatAttribs[GLFW_PFA_WGL_BLUE_BITS_ARB];
|
||||||
u->alphaBits = getPixelFormatAttrib(window, n, WGL_ALPHA_BITS_ARB);
|
u->alphaBits = pixelFormatAttribs[GLFW_PFA_WGL_ALPHA_BITS_ARB];
|
||||||
|
|
||||||
u->depthBits = getPixelFormatAttrib(window, n, WGL_DEPTH_BITS_ARB);
|
u->depthBits = pixelFormatAttribs[GLFW_PFA_WGL_DEPTH_BITS_ARB];
|
||||||
u->stencilBits = getPixelFormatAttrib(window, n, WGL_STENCIL_BITS_ARB);
|
u->stencilBits = pixelFormatAttribs[GLFW_PFA_WGL_STENCIL_BITS_ARB];
|
||||||
|
|
||||||
u->accumRedBits = getPixelFormatAttrib(window, n, WGL_ACCUM_RED_BITS_ARB);
|
u->accumRedBits = pixelFormatAttribs[GLFW_PFA_WGL_ACCUM_RED_BITS_ARB];
|
||||||
u->accumGreenBits = getPixelFormatAttrib(window, n, WGL_ACCUM_GREEN_BITS_ARB);
|
u->accumGreenBits = pixelFormatAttribs[GLFW_PFA_WGL_ACCUM_GREEN_BITS_ARB];
|
||||||
u->accumBlueBits = getPixelFormatAttrib(window, n, WGL_ACCUM_BLUE_BITS_ARB);
|
u->accumBlueBits = pixelFormatAttribs[GLFW_PFA_WGL_ACCUM_BLUE_BITS_ARB];
|
||||||
u->accumAlphaBits = getPixelFormatAttrib(window, n, WGL_ACCUM_ALPHA_BITS_ARB);
|
u->accumAlphaBits = pixelFormatAttribs[GLFW_PFA_WGL_ACCUM_ALPHA_BITS_ARB];
|
||||||
|
|
||||||
u->auxBuffers = getPixelFormatAttrib(window, n, WGL_AUX_BUFFERS_ARB);
|
u->auxBuffers = pixelFormatAttribs[GLFW_PFA_WGL_AUX_BUFFERS_ARB];
|
||||||
|
|
||||||
if (getPixelFormatAttrib(window, n, WGL_STEREO_ARB))
|
if (pixelFormatAttribs[GLFW_PFA_WGL_STEREO_ARB])
|
||||||
u->stereo = GLFW_TRUE;
|
u->stereo = GLFW_TRUE;
|
||||||
if (getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB))
|
if (pixelFormatAttribs[GLFW_PFA_WGL_DOUBLE_BUFFER_ARB])
|
||||||
u->doublebuffer = GLFW_TRUE;
|
u->doublebuffer = GLFW_TRUE;
|
||||||
|
|
||||||
if (_glfw.wgl.ARB_multisample)
|
if (_glfw.wgl.ARB_multisample)
|
||||||
u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB);
|
u->samples = pixelFormatAttribs[GLFW_PFA_WGL_SAMPLES_ARB];
|
||||||
|
|
||||||
if (ctxconfig->client == GLFW_OPENGL_API)
|
if (ctxconfig->client == GLFW_OPENGL_API)
|
||||||
{
|
{
|
||||||
if (_glfw.wgl.ARB_framebuffer_sRGB ||
|
if (_glfw.wgl.ARB_framebuffer_sRGB ||
|
||||||
_glfw.wgl.EXT_framebuffer_sRGB)
|
_glfw.wgl.EXT_framebuffer_sRGB)
|
||||||
{
|
{
|
||||||
if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB))
|
if (pixelFormatAttribs[GLFW_PFA_WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB])
|
||||||
u->sRGB = GLFW_TRUE;
|
u->sRGB = GLFW_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +226,7 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||||||
{
|
{
|
||||||
if (_glfw.wgl.EXT_colorspace)
|
if (_glfw.wgl.EXT_colorspace)
|
||||||
{
|
{
|
||||||
if (getPixelFormatAttrib(window, n, WGL_COLORSPACE_EXT) ==
|
if (pixelFormatAttribs[GLFW_PFA_WGL_COLORSPACE_EXT ] ==
|
||||||
WGL_COLORSPACE_SRGB_EXT)
|
WGL_COLORSPACE_SRGB_EXT)
|
||||||
{
|
{
|
||||||
u->sRGB = GLFW_TRUE;
|
u->sRGB = GLFW_TRUE;
|
||||||
|
Loading…
Reference in New Issue
Block a user