Monitor: use current ramp size in glfwSetGamma

On X11, number of gamma ramp entries must match currently active ramp,
so hardcoded size of 256 is not going to work if the hardware ramp has
more entries. Solve this by querying current ramp size and allocating
the needed amount dynamically.
This commit is contained in:
Alexander Monakov 2018-11-25 00:05:59 +03:00
parent 776d431ded
commit 7ebe8d56fb

View File

@ -427,8 +427,8 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle)
GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
{
int i;
unsigned short values[256];
int i, size;
unsigned short *values;
GLFWgammaramp ramp;
assert(handle != NULL);
@ -440,12 +440,19 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
return;
}
for (i = 0; i < 256; i++)
size = _glfwPlatformGetGammaRampSize((_GLFWmonitor*) handle);
if (size < 2)
return;
values = malloc(size * sizeof(unsigned short));
for (i = 0; i < size; i++)
{
float value;
// Calculate intensity
value = i / 255.f;
value = 1.f / (size - 1) * i;
// Apply gamma curve
value = powf(value, 1.f / gamma) * 65535.f + 0.5f;
@ -459,9 +466,10 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
ramp.red = values;
ramp.green = values;
ramp.blue = values;
ramp.size = 256;
ramp.size = size;
glfwSetGammaRamp(handle, &ramp);
free(values);
}
GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle)