mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 21:14:35 +00:00
Added back refresh rate window hint.
This commit is contained in:
parent
f5dc6e4007
commit
2cd34386bc
@ -309,6 +309,7 @@ GLFW.
|
|||||||
* Added `GLFW_VISIBLE` window hint and parameter for controlling and polling
|
* Added `GLFW_VISIBLE` window hint and parameter for controlling and polling
|
||||||
window visibility
|
window visibility
|
||||||
* Added `GLFW_REPEAT` key action for repeated keys
|
* Added `GLFW_REPEAT` key action for repeated keys
|
||||||
|
* Added `refreshRate` member to `GLFWvidmode` struct
|
||||||
* Added key modifier parameter to key and mouse button callbacks
|
* Added key modifier parameter to key and mouse button callbacks
|
||||||
* Added `windows` simple multi-window test program
|
* Added `windows` simple multi-window test program
|
||||||
* Added `sharing` simple OpenGL object sharing test program
|
* Added `sharing` simple OpenGL object sharing test program
|
||||||
|
@ -86,6 +86,10 @@ multisampling. Zero disables multisampling.
|
|||||||
The `GLFW_SRGB_CAPABLE` hint specifies whether the framebuffer should be
|
The `GLFW_SRGB_CAPABLE` hint specifies whether the framebuffer should be
|
||||||
sRGB capable.
|
sRGB capable.
|
||||||
|
|
||||||
|
The `GLFW_REFRESH_RATE` hint specifies the desired refresh rate for full screen
|
||||||
|
windows. If set to zero, the highest available refresh rate will be used. This
|
||||||
|
hint is ignored for windowed mode windows.
|
||||||
|
|
||||||
|
|
||||||
@subsection window_hints_ctx Context related hints
|
@subsection window_hints_ctx Context related hints
|
||||||
|
|
||||||
@ -151,6 +155,7 @@ a robustness strategy.
|
|||||||
| `GLFW_ACCUM_ALPHA_BITS` | 0 | 0 to `INT_MAX` |
|
| `GLFW_ACCUM_ALPHA_BITS` | 0 | 0 to `INT_MAX` |
|
||||||
| `GLFW_AUX_BUFFERS` | 0 | 0 to `INT_MAX` |
|
| `GLFW_AUX_BUFFERS` | 0 | 0 to `INT_MAX` |
|
||||||
| `GLFW_SAMPLES` | 0 | 0 to `INT_MAX` |
|
| `GLFW_SAMPLES` | 0 | 0 to `INT_MAX` |
|
||||||
|
| `GLFW_REFRESH_RATE` | 0 | 0 to `INT_MAX` |
|
||||||
| `GLFW_STEREO` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` |
|
| `GLFW_STEREO` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` |
|
||||||
| `GLFW_SRGB_CAPABLE` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` |
|
| `GLFW_SRGB_CAPABLE` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` |
|
||||||
| `GLFW_CLIENT_API` | `GLFW_OPENGL_API` | `GLFW_OPENGL_API` or `GLFW_OPENGL_ES_API` |
|
| `GLFW_CLIENT_API` | `GLFW_OPENGL_API` | `GLFW_OPENGL_API` or `GLFW_OPENGL_ES_API` |
|
||||||
|
@ -520,6 +520,7 @@ extern "C" {
|
|||||||
#define GLFW_STEREO 0x0002100C
|
#define GLFW_STEREO 0x0002100C
|
||||||
#define GLFW_SAMPLES 0x0002100D
|
#define GLFW_SAMPLES 0x0002100D
|
||||||
#define GLFW_SRGB_CAPABLE 0x0002100E
|
#define GLFW_SRGB_CAPABLE 0x0002100E
|
||||||
|
#define GLFW_REFRESH_RATE 0x0002100F
|
||||||
|
|
||||||
#define GLFW_CLIENT_API 0x00022001
|
#define GLFW_CLIENT_API 0x00022001
|
||||||
#define GLFW_CONTEXT_VERSION_MAJOR 0x00022002
|
#define GLFW_CONTEXT_VERSION_MAJOR 0x00022002
|
||||||
|
@ -158,7 +158,8 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
|||||||
CGDisplayModeRef bestMode = NULL;
|
CGDisplayModeRef bestMode = NULL;
|
||||||
CFArrayRef modes;
|
CFArrayRef modes;
|
||||||
CFIndex count, i;
|
CFIndex count, i;
|
||||||
unsigned int leastSizeDiff = UINT_MAX, leastRateDiff = UINT_MAX;
|
unsigned int sizeDiff, leastSizeDiff = UINT_MAX;
|
||||||
|
unsigned int rateDiff, leastRateDiff = UINT_MAX;
|
||||||
const int bpp = desired->redBits - desired->greenBits - desired->blueBits;
|
const int bpp = desired->redBits - desired->greenBits - desired->blueBits;
|
||||||
|
|
||||||
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
|
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
|
||||||
@ -188,11 +189,14 @@ GLboolean _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
|||||||
const int modeHeight = (int) CGDisplayModeGetHeight(mode);
|
const int modeHeight = (int) CGDisplayModeGetHeight(mode);
|
||||||
const int modeRate = (int) CGDisplayModeGetRefreshRate(mode);
|
const int modeRate = (int) CGDisplayModeGetRefreshRate(mode);
|
||||||
|
|
||||||
unsigned int sizeDiff = (abs(modeBPP - bpp) << 25) |
|
sizeDiff = (abs(modeBPP - bpp) << 25) |
|
||||||
((modeWidth - desired->width) * (modeWidth - desired->width) +
|
((modeWidth - desired->width) * (modeWidth - desired->width) +
|
||||||
(modeHeight - desired->height) * (modeHeight - desired->height));
|
(modeHeight - desired->height) * (modeHeight - desired->height));
|
||||||
|
|
||||||
const unsigned int rateDiff = modeRate - desired->refreshRate;
|
if (desired->refreshRate)
|
||||||
|
rateDiff = abs(modeRate - desired->refreshRate);
|
||||||
|
else
|
||||||
|
rateDiff = UINT_MAX - modeRate;
|
||||||
|
|
||||||
if ((sizeDiff < leastSizeDiff) ||
|
if ((sizeDiff < leastSizeDiff) ||
|
||||||
(sizeDiff == leastSizeDiff && rateDiff < leastRateDiff))
|
(sizeDiff == leastSizeDiff && rateDiff < leastRateDiff))
|
||||||
|
@ -280,6 +280,7 @@ struct _GLFWlibrary
|
|||||||
GLboolean decorated;
|
GLboolean decorated;
|
||||||
int samples;
|
int samples;
|
||||||
GLboolean sRGB;
|
GLboolean sRGB;
|
||||||
|
int refreshRate;
|
||||||
int clientAPI;
|
int clientAPI;
|
||||||
int glMajor;
|
int glMajor;
|
||||||
int glMinor;
|
int glMinor;
|
||||||
|
@ -230,7 +230,10 @@ const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
|
|||||||
(current->height - desired->height) *
|
(current->height - desired->height) *
|
||||||
(current->height - desired->height));
|
(current->height - desired->height));
|
||||||
|
|
||||||
rateDiff = abs(current->refreshRate - desired->refreshRate);
|
if (desired->refreshRate)
|
||||||
|
rateDiff = abs(current->refreshRate - desired->refreshRate);
|
||||||
|
else
|
||||||
|
rateDiff = UINT_MAX - current->refreshRate;
|
||||||
|
|
||||||
if ((colorDiff < leastColorDiff) ||
|
if ((colorDiff < leastColorDiff) ||
|
||||||
(colorDiff == leastColorDiff && sizeDiff < leastSizeDiff) ||
|
(colorDiff == leastColorDiff && sizeDiff < leastSizeDiff) ||
|
||||||
|
15
src/window.c
15
src/window.c
@ -201,11 +201,13 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||||||
wndconfig.resizable = GL_TRUE;
|
wndconfig.resizable = GL_TRUE;
|
||||||
wndconfig.visible = GL_TRUE;
|
wndconfig.visible = GL_TRUE;
|
||||||
|
|
||||||
window->videoMode.width = width;
|
// Set up desired video mode
|
||||||
window->videoMode.height = height;
|
window->videoMode.width = width;
|
||||||
window->videoMode.redBits = fbconfig.redBits;
|
window->videoMode.height = height;
|
||||||
window->videoMode.greenBits = fbconfig.greenBits;
|
window->videoMode.redBits = Max(_glfw.hints.redBits, 0);
|
||||||
window->videoMode.blueBits = fbconfig.blueBits;
|
window->videoMode.greenBits = Max(_glfw.hints.greenBits, 0);
|
||||||
|
window->videoMode.blueBits = Max(_glfw.hints.blueBits, 0);
|
||||||
|
window->videoMode.refreshRate = Max(_glfw.hints.refreshRate, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
window->monitor = wndconfig.monitor;
|
window->monitor = wndconfig.monitor;
|
||||||
@ -322,6 +324,9 @@ GLFWAPI void glfwWindowHint(int target, int hint)
|
|||||||
case GLFW_STEREO:
|
case GLFW_STEREO:
|
||||||
_glfw.hints.stereo = hint;
|
_glfw.hints.stereo = hint;
|
||||||
break;
|
break;
|
||||||
|
case GLFW_REFRESH_RATE:
|
||||||
|
_glfw.hints.refreshRate = hint;
|
||||||
|
break;
|
||||||
case GLFW_RESIZABLE:
|
case GLFW_RESIZABLE:
|
||||||
_glfw.hints.resizable = hint;
|
_glfw.hints.resizable = hint;
|
||||||
break;
|
break;
|
||||||
|
@ -67,28 +67,43 @@ void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
|||||||
{
|
{
|
||||||
if (_glfw.x11.randr.available)
|
if (_glfw.x11.randr.available)
|
||||||
{
|
{
|
||||||
int i;
|
int i, j;
|
||||||
XRRScreenResources* sr;
|
XRRScreenResources* sr;
|
||||||
XRRCrtcInfo* ci;
|
XRRCrtcInfo* ci;
|
||||||
|
XRROutputInfo* oi;
|
||||||
RRMode bestMode = 0;
|
RRMode bestMode = 0;
|
||||||
unsigned int leastSizeDiff = UINT_MAX, leastRateDiff = UINT_MAX;
|
unsigned int sizeDiff, leastSizeDiff = UINT_MAX;
|
||||||
|
unsigned int rateDiff, leastRateDiff = UINT_MAX;
|
||||||
|
|
||||||
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root);
|
||||||
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
|
||||||
|
oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
|
||||||
|
|
||||||
for (i = 0; i < sr->nmode; i++)
|
for (i = 0; i < sr->nmode; i++)
|
||||||
{
|
{
|
||||||
XRRModeInfo* mi = sr->modes + i;
|
const XRRModeInfo* mi = sr->modes + i;
|
||||||
|
|
||||||
if (mi->modeFlags & RR_Interlace)
|
if (mi->modeFlags & RR_Interlace)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const unsigned int sizeDiff = (mi->width - desired->width) *
|
for (j = 0; j < oi->nmode; j++)
|
||||||
(mi->width - desired->width) +
|
{
|
||||||
(mi->height - desired->height) *
|
if (oi->modes[j] == mi->id)
|
||||||
(mi->height - desired->height);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned int rateDiff = abs(calculateRefreshRate(mi) - desired->refreshRate);
|
if (j == oi->nmode)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sizeDiff = (mi->width - desired->width) *
|
||||||
|
(mi->width - desired->width) +
|
||||||
|
(mi->height - desired->height) *
|
||||||
|
(mi->height - desired->height);
|
||||||
|
|
||||||
|
if (desired->refreshRate)
|
||||||
|
rateDiff = abs(calculateRefreshRate(mi) - desired->refreshRate);
|
||||||
|
else
|
||||||
|
rateDiff = UINT_MAX - calculateRefreshRate(mi);
|
||||||
|
|
||||||
if ((sizeDiff < leastSizeDiff) ||
|
if ((sizeDiff < leastSizeDiff) ||
|
||||||
(sizeDiff == leastSizeDiff && rateDiff < leastRateDiff))
|
(sizeDiff == leastSizeDiff && rateDiff < leastRateDiff))
|
||||||
@ -110,6 +125,7 @@ void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired)
|
|||||||
ci->outputs,
|
ci->outputs,
|
||||||
ci->noutput);
|
ci->noutput);
|
||||||
|
|
||||||
|
XRRFreeOutputInfo(oi);
|
||||||
XRRFreeCrtcInfo(ci);
|
XRRFreeCrtcInfo(ci);
|
||||||
XRRFreeScreenResources(sr);
|
XRRFreeScreenResources(sr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user