Merge branch 'master' of ssh://glfw.git.sourceforge.net/gitroot/glfw/glfw

This commit is contained in:
Camilla Berglund 2011-04-06 22:00:25 +02:00
commit 7a73105f48
6 changed files with 40 additions and 59 deletions

View File

@ -500,6 +500,7 @@ typedef struct
/* Custom threading model interface */ /* Custom threading model interface */
typedef struct typedef struct
{ {
int dummy;
} GLFWthreadmodel; } GLFWthreadmodel;

View File

@ -57,7 +57,7 @@ GLFWAPI void glfwSetGammaFormula(float gamma, float blacklevel, float gain)
float value = (float) i / ((float) (size - 1)); float value = (float) i / ((float) (size - 1));
// Apply gamma // Apply gamma
value = pow(value, gamma) * 65535.f + 0.5f; value = pow(value, 1.f / gamma) * 65535.f + 0.5f;
// Apply gain // Apply gain
value = gain * (value - 32767.5f) + 32767.5f; value = gain * (value - 32767.5f) + 32767.5f;

View File

@ -41,14 +41,14 @@
GLFWAPI int glfwGetKey(GLFWwindow handle, int key) GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE; return GLFW_RELEASE;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
// Is it a valid key? // Is it a valid key?
if (key < 0 || key > GLFW_KEY_LAST) if (key < 0 || key > GLFW_KEY_LAST)
{ {
@ -74,14 +74,14 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button) GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return GLFW_RELEASE; return GLFW_RELEASE;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
// Is it a valid mouse button? // Is it a valid mouse button?
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
{ {
@ -106,14 +106,14 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos) GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
// Return mouse position // Return mouse position
if (xpos != NULL) if (xpos != NULL)
*xpos = window->mousePosX; *xpos = window->mousePosX;
@ -130,14 +130,14 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
// Don't do anything if the mouse position did not change // Don't do anything if the mouse position did not change
if (xpos == window->mousePosX && ypos == window->mousePosY) if (xpos == window->mousePosX && ypos == window->mousePosY)
return; return;
@ -161,14 +161,14 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset) GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (xoffset) if (xoffset)
*xoffset = window->scrollX; *xoffset = window->scrollX;

View File

@ -43,27 +43,16 @@ void _glfwInitTimer(void)
{ {
__int64 freq; __int64 freq;
// Check if we have a performance counter
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
{ {
// Performance counter is available => use it!
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_TRUE; _glfwLibrary.Win32.timer.hasPerformanceCounter = GL_TRUE;
// Counter resolution is 1 / counter frequency
_glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq; _glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq;
// Set start time for timer
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64); QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
} }
else else
{ {
// No performace counter available => use the tick counter
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_FALSE; _glfwLibrary.Win32.timer.hasPerformanceCounter = GL_FALSE;
_glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms
// Counter resolution is 1 ms
_glfwLibrary.Win32.timer.resolution = 0.001;
// Set start time for timer
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime(); _glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
} }
} }
@ -90,7 +79,6 @@ double _glfwPlatformGetTime(void)
else else
t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32); t = (double)(_glfw_timeGetTime() - _glfwLibrary.Win32.timer.t0_32);
// Calculate the current time in seconds
return t * _glfwLibrary.Win32.timer.resolution; return t * _glfwLibrary.Win32.timer.resolution;
} }

View File

@ -86,8 +86,8 @@ static int setMinMaxAnimations(int enable)
//======================================================================== //========================================================================
// Focus the window and bring it to the top of the stack // Focus the window and bring it to the top of the stack
// Due to some nastiness with how Win98/ME/2k/XP handles SetForegroundWindow, // Due to some nastiness with how XP handles SetForegroundWindow we have
// we have to go through some really bizarre measures to achieve this // to go through some really bizarre measures to achieve this
//======================================================================== //========================================================================
static void setForegroundWindow(HWND hWnd) static void setForegroundWindow(HWND hWnd)
@ -200,8 +200,6 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (window->WGL.has_WGL_ARB_pixel_format) if (window->WGL.has_WGL_ARB_pixel_format)
{ {
// Get pixel format attributes through WGL_ARB_pixel_format // Get pixel format attributes through WGL_ARB_pixel_format
// Only consider doublebuffered OpenGL pixel formats for windows
if (!getPixelFormatAttrib(window, i, WGL_SUPPORT_OPENGL_ARB) || if (!getPixelFormatAttrib(window, i, WGL_SUPPORT_OPENGL_ARB) ||
!getPixelFormatAttrib(window, i, WGL_DRAW_TO_WINDOW_ARB) || !getPixelFormatAttrib(window, i, WGL_DRAW_TO_WINDOW_ARB) ||
!getPixelFormatAttrib(window, i, WGL_DOUBLE_BUFFER_ARB)) !getPixelFormatAttrib(window, i, WGL_DOUBLE_BUFFER_ARB))
@ -209,14 +207,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
continue; continue;
} }
// Only consider RGBA pixel formats
if (getPixelFormatAttrib(window, i, WGL_PIXEL_TYPE_ARB) != if (getPixelFormatAttrib(window, i, WGL_PIXEL_TYPE_ARB) !=
WGL_TYPE_RGBA_ARB) WGL_TYPE_RGBA_ARB)
{ {
continue; continue;
} }
// Only consider "hardware-accelerated" pixel formats
if (getPixelFormatAttrib(window, i, WGL_ACCELERATION_ARB) == if (getPixelFormatAttrib(window, i, WGL_ACCELERATION_ARB) ==
WGL_NO_ACCELERATION_ARB) WGL_NO_ACCELERATION_ARB)
{ {
@ -266,7 +262,6 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
if (!_glfw_DescribePixelFormat(window->WGL.DC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) if (!_glfw_DescribePixelFormat(window->WGL.DC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
continue; continue;
// Only consider doublebuffered OpenGL pixel formats for windows
if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) || if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) ||
!(pfd.dwFlags & PFD_SUPPORT_OPENGL) || !(pfd.dwFlags & PFD_SUPPORT_OPENGL) ||
!(pfd.dwFlags & PFD_DOUBLEBUFFER)) !(pfd.dwFlags & PFD_DOUBLEBUFFER))
@ -274,14 +269,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
continue; continue;
} }
// Only consider "hardware-accelerated" pixel formats
if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) && if (!(pfd.dwFlags & PFD_GENERIC_ACCELERATED) &&
(pfd.dwFlags & PFD_GENERIC_FORMAT)) (pfd.dwFlags & PFD_GENERIC_FORMAT))
{ {
continue; continue;
} }
// Only RGBA pixel formats considered
if (pfd.iPixelType != PFD_TYPE_RGBA) if (pfd.iPixelType != PFD_TYPE_RGBA)
continue; continue;

View File

@ -365,14 +365,14 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow handle) GLFWAPI void glfwMakeWindowCurrent(GLFWwindow handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (_glfwLibrary.currentWindow == window) if (_glfwLibrary.currentWindow == window)
return; return;
@ -388,6 +388,7 @@ GLFWAPI void glfwMakeWindowCurrent(GLFWwindow handle)
GLFWAPI int glfwIsWindow(GLFWwindow handle) GLFWAPI int glfwIsWindow(GLFWwindow handle)
{ {
_GLFWwindow* entry; _GLFWwindow* entry;
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
@ -395,8 +396,6 @@ GLFWAPI int glfwIsWindow(GLFWwindow handle)
return GL_FALSE; return GL_FALSE;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (window == NULL) if (window == NULL)
return GL_FALSE; return GL_FALSE;
@ -515,14 +514,14 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
GLFWAPI void glfwCloseWindow(GLFWwindow handle) GLFWAPI void glfwCloseWindow(GLFWwindow handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
// Allow closing of NULL (to match the behavior of free) // Allow closing of NULL (to match the behavior of free)
if (window == NULL) if (window == NULL)
return; return;
@ -561,14 +560,14 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle)
GLFWAPI void glfwSetWindowTitle(GLFWwindow handle, const char* title) GLFWAPI void glfwSetWindowTitle(GLFWwindow handle, const char* title)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
_glfwPlatformSetWindowTitle(window, title); _glfwPlatformSetWindowTitle(window, title);
} }
@ -579,14 +578,14 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow handle, const char* title)
GLFWAPI void glfwGetWindowSize(GLFWwindow handle, int* width, int* height) GLFWAPI void glfwGetWindowSize(GLFWwindow handle, int* width, int* height)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (width != NULL) if (width != NULL)
*width = window->width; *width = window->width;
@ -601,14 +600,14 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow handle, int* width, int* height)
GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height) GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (window->iconified) if (window->iconified)
{ {
// TODO: Figure out if this is an error // TODO: Figure out if this is an error
@ -636,14 +635,14 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
GLFWAPI void glfwGetWindowPos(GLFWwindow handle, int* xpos, int* ypos) GLFWAPI void glfwGetWindowPos(GLFWwindow handle, int* xpos, int* ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (xpos != NULL) if (xpos != NULL)
*xpos = window->positionX; *xpos = window->positionX;
@ -658,14 +657,14 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow handle, int* xpos, int* ypos)
GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos) GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (window->mode == GLFW_FULLSCREEN || window->iconified) if (window->mode == GLFW_FULLSCREEN || window->iconified)
{ {
// TODO: Figure out if this is an error // TODO: Figure out if this is an error
@ -682,14 +681,14 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos)
GLFWAPI void glfwIconifyWindow(GLFWwindow handle) GLFWAPI void glfwIconifyWindow(GLFWwindow handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (window->iconified) if (window->iconified)
return; return;
@ -703,14 +702,14 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow handle)
GLFWAPI void glfwRestoreWindow(GLFWwindow handle) GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!window->iconified) if (!window->iconified)
return; return;
@ -728,14 +727,14 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0; return 0;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
switch (param) switch (param)
{ {
case GLFW_ACTIVE: case GLFW_ACTIVE:
@ -799,14 +798,14 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow handle, void* pointer) GLFWAPI void glfwSetWindowUserPointer(GLFWwindow handle, void* pointer)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return; return;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
window->userPointer = pointer; window->userPointer = pointer;
} }
@ -817,14 +816,14 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow handle, void* pointer)
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle) GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return NULL; return NULL;
} }
_GLFWwindow* window = (_GLFWwindow*) handle;
return window->userPointer; return window->userPointer;
} }