Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 1 | //======================================================================== |
| 2 | // GLFW - An OpenGL framework |
| 3 | // Platform: Any |
Camilla Berglund | 38b0ccb | 2010-09-07 17:41:26 +0200 | [diff] [blame] | 4 | // API version: 3.0 |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 5 | // WWW: http://www.glfw.org/ |
| 6 | //------------------------------------------------------------------------ |
| 7 | // Copyright (c) 2002-2006 Marcus Geelnard |
| 8 | // Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org> |
| 9 | // |
| 10 | // This software is provided 'as-is', without any express or implied |
| 11 | // warranty. In no event will the authors be held liable for any damages |
| 12 | // arising from the use of this software. |
| 13 | // |
| 14 | // Permission is granted to anyone to use this software for any purpose, |
| 15 | // including commercial applications, and to alter it and redistribute it |
| 16 | // freely, subject to the following restrictions: |
| 17 | // |
| 18 | // 1. The origin of this software must not be misrepresented; you must not |
| 19 | // claim that you wrote the original software. If you use this software |
| 20 | // in a product, an acknowledgment in the product documentation would |
| 21 | // be appreciated but is not required. |
| 22 | // |
| 23 | // 2. Altered source versions must be plainly marked as such, and must not |
| 24 | // be misrepresented as being the original software. |
| 25 | // |
| 26 | // 3. This notice may not be removed or altered from any source |
| 27 | // distribution. |
| 28 | // |
| 29 | //======================================================================== |
| 30 | |
| 31 | #ifndef _internal_h_ |
| 32 | #define _internal_h_ |
| 33 | |
| 34 | //======================================================================== |
| 35 | // GLFWGLOBAL is a macro that places all global variables in the init.c |
| 36 | // module (all other modules reference global variables as 'extern') |
| 37 | //======================================================================== |
| 38 | |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 39 | #if defined(_init_c_) |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 40 | #define GLFWGLOBAL |
| 41 | #else |
| 42 | #define GLFWGLOBAL extern |
| 43 | #endif |
| 44 | |
| 45 | |
| 46 | //======================================================================== |
| 47 | // Input handling definitions |
| 48 | //======================================================================== |
| 49 | |
| 50 | // Internal key and button state/action definitions |
| 51 | #define GLFW_STICK 2 |
| 52 | |
| 53 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 54 | //------------------------------------------------------------------------ |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 55 | // Platform specific definitions goes in platform.h (which also includes |
| 56 | // glfw.h) |
| 57 | //------------------------------------------------------------------------ |
| 58 | |
| 59 | #include "platform.h" |
| 60 | |
| 61 | |
| 62 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 63 | // Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow |
| 64 | // A bucket of semi-random stuff lumped together for historical reasons |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 65 | // This is used only by the platform independent code and only to store |
| 66 | // parameters passed to us by glfwOpenWindowHint |
| 67 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 68 | typedef struct _GLFWhints |
| 69 | { |
Camilla Berglund | 950a3be | 2010-09-09 19:58:51 +0200 | [diff] [blame] | 70 | int redBits; |
| 71 | int greenBits; |
| 72 | int blueBits; |
| 73 | int alphaBits; |
| 74 | int depthBits; |
| 75 | int stencilBits; |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 76 | int refreshRate; |
| 77 | int accumRedBits; |
| 78 | int accumGreenBits; |
| 79 | int accumBlueBits; |
| 80 | int accumAlphaBits; |
| 81 | int auxBuffers; |
| 82 | int stereo; |
| 83 | int windowNoResize; |
| 84 | int samples; |
| 85 | int glMajor; |
| 86 | int glMinor; |
| 87 | int glForward; |
| 88 | int glDebug; |
| 89 | int glProfile; |
| 90 | } _GLFWhints; |
| 91 | |
| 92 | |
| 93 | //------------------------------------------------------------------------ |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 94 | // Parameters relating to the creation of the context and window but not |
| 95 | // directly related to the properties of the framebuffer |
| 96 | // This is used to pass window and context creation parameters from the |
| 97 | // platform independent code to the platform specific code |
| 98 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 99 | typedef struct _GLFWwndconfig |
| 100 | { |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 101 | int mode; |
Camilla Berglund | 0f80e06 | 2010-09-14 03:10:45 +0200 | [diff] [blame] | 102 | const char* title; |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 103 | int refreshRate; |
| 104 | int windowNoResize; |
| 105 | int glMajor; |
| 106 | int glMinor; |
| 107 | int glForward; |
| 108 | int glDebug; |
| 109 | int glProfile; |
| 110 | } _GLFWwndconfig; |
| 111 | |
| 112 | |
| 113 | //------------------------------------------------------------------------ |
| 114 | // Framebuffer configuration descriptor, i.e. buffers and their sizes |
| 115 | // Also a platform specific ID used to map back to the actual backend APIs |
| 116 | // This is used to pass framebuffer parameters from the platform independent |
| 117 | // code to the platform specific code, and also to enumerate and select |
| 118 | // available framebuffer configurations |
| 119 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 120 | typedef struct _GLFWfbconfig |
| 121 | { |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 122 | int redBits; |
| 123 | int greenBits; |
| 124 | int blueBits; |
| 125 | int alphaBits; |
| 126 | int depthBits; |
| 127 | int stencilBits; |
| 128 | int accumRedBits; |
| 129 | int accumGreenBits; |
| 130 | int accumBlueBits; |
| 131 | int accumAlphaBits; |
| 132 | int auxBuffers; |
| 133 | int stereo; |
| 134 | int samples; |
| 135 | GLFWintptr platformID; |
| 136 | } _GLFWfbconfig; |
| 137 | |
| 138 | |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 139 | //------------------------------------------------------------------------ |
| 140 | // Window structure |
| 141 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 142 | typedef struct _GLFWwindow |
| 143 | { |
Camilla Berglund | 326d997 | 2010-09-10 00:06:23 +0200 | [diff] [blame] | 144 | struct _GLFWwindow* next; |
| 145 | |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 146 | // User callback functions |
| 147 | GLFWwindowsizefun windowSizeCallback; |
| 148 | GLFWwindowclosefun windowCloseCallback; |
| 149 | GLFWwindowrefreshfun windowRefreshCallback; |
| 150 | GLFWmousebuttonfun mouseButtonCallback; |
| 151 | GLFWmouseposfun mousePosCallback; |
| 152 | GLFWmousewheelfun mouseWheelCallback; |
| 153 | GLFWkeyfun keyCallback; |
| 154 | GLFWcharfun charCallback; |
| 155 | |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 156 | // Window settings and state |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 157 | GLboolean iconified; // GL_TRUE if this window is iconified |
Camilla Berglund | 326d997 | 2010-09-10 00:06:23 +0200 | [diff] [blame] | 158 | GLboolean closed; // GL_TRUE if this window should be closed |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 159 | int width, height; |
Camilla Berglund | 318f731 | 2010-09-14 03:53:22 +0200 | [diff] [blame^] | 160 | int positionX, positionY; |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 161 | int mode; // GLFW_WINDOW or GLFW_FULLSCREEN |
| 162 | GLboolean sysKeysDisabled; // system keys disabled flag |
| 163 | GLboolean windowNoResize; // resize- and maximize gadgets disabled flag |
| 164 | int refreshRate; // monitor refresh rate |
Camilla Berglund | 48f5a7e | 2010-09-09 22:44:38 +0200 | [diff] [blame] | 165 | void* userPointer; |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 166 | |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 167 | // Window input state |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 168 | GLboolean stickyKeys; |
| 169 | GLboolean stickyMouseButtons; |
| 170 | GLboolean keyRepeat; |
| 171 | int mousePosX, mousePosY; |
| 172 | int wheelPos; |
| 173 | char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1]; |
| 174 | char key[GLFW_KEY_LAST + 1]; |
| 175 | int lastChar; |
| 176 | |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 177 | // Framebuffer attributes |
| 178 | int redBits; |
| 179 | int greenBits; |
| 180 | int blueBits; |
| 181 | int alphaBits; |
| 182 | int depthBits; |
| 183 | int stencilBits; |
| 184 | int accumRedBits; |
| 185 | int accumGreenBits; |
| 186 | int accumBlueBits; |
| 187 | int accumAlphaBits; |
| 188 | int auxBuffers; |
| 189 | GLboolean stereo; |
| 190 | int samples; |
| 191 | |
| 192 | // OpenGL extensions and context attributes |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 193 | GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated" |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 194 | int glMajor, glMinor, glRevision; |
| 195 | int glForward, glDebug, glProfile; |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 196 | PFNGLGETSTRINGIPROC GetStringi; |
| 197 | |
| 198 | _GLFW_PLATFORM_WINDOW_STATE; |
Camilla Berglund | 3228755 | 2010-09-09 20:36:23 +0200 | [diff] [blame] | 199 | _GLFW_PLATFORM_CONTEXT_STATE; |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 200 | } _GLFWwindow; |
| 201 | |
| 202 | |
| 203 | //------------------------------------------------------------------------ |
| 204 | // Library global data |
| 205 | //------------------------------------------------------------------------ |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 206 | typedef struct _GLFWlibrary |
| 207 | { |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 208 | _GLFWhints hints; |
Camilla Berglund | 326d997 | 2010-09-10 00:06:23 +0200 | [diff] [blame] | 209 | |
| 210 | _GLFWwindow* windowListHead; |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 211 | _GLFWwindow* currentWindow; |
Camilla Berglund | ae57d13 | 2010-09-11 15:14:57 +0200 | [diff] [blame] | 212 | _GLFWwindow* activeWindow; |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 213 | _GLFWwindow* cursorLockWindow; |
| 214 | |
| 215 | _GLFW_PLATFORM_LIBRARY_STATE; |
| 216 | } _GLFWlibrary; |
| 217 | |
| 218 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 219 | //======================================================================== |
| 220 | // System independent global variables (GLFW internals) |
| 221 | //======================================================================== |
| 222 | |
| 223 | // Flag indicating if GLFW has been initialized |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 224 | #if defined(_init_c_) |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 225 | GLboolean _glfwInitialized = GL_FALSE; |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 226 | #else |
Camilla Berglund | 12d17b9 | 2010-09-09 20:18:10 +0200 | [diff] [blame] | 227 | GLFWGLOBAL GLboolean _glfwInitialized; |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 228 | #endif |
| 229 | |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 230 | GLFWGLOBAL _GLFWlibrary _glfwLibrary; |
| 231 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 232 | |
| 233 | //======================================================================== |
| 234 | // Prototypes for platform specific implementation functions |
| 235 | //======================================================================== |
| 236 | |
| 237 | // Init/terminate |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 238 | int _glfwPlatformInit(void); |
| 239 | int _glfwPlatformTerminate(void); |
Camilla Berglund | d6fe447 | 2010-09-13 18:05:59 +0200 | [diff] [blame] | 240 | const char* _glfwPlatformGetVersionString(void); |
Camilla Berglund | f5d74c4 | 2010-09-09 21:06:59 +0200 | [diff] [blame] | 241 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 242 | // Enable/Disable |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 243 | void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); |
| 244 | void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 245 | |
| 246 | // Fullscreen |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 247 | int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount); |
| 248 | void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 249 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 250 | // Joystick |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 251 | int _glfwPlatformGetJoystickParam(int joy, int param); |
| 252 | int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes); |
| 253 | int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 254 | |
| 255 | // Time |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 256 | double _glfwPlatformGetTime(void); |
| 257 | void _glfwPlatformSetTime(double time); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 258 | |
| 259 | // Window management |
Camilla Berglund | 819d044 | 2010-09-13 23:42:51 +0200 | [diff] [blame] | 260 | int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); |
Camilla Berglund | 1bac996 | 2010-09-13 23:47:43 +0200 | [diff] [blame] | 261 | void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window); |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 262 | void _glfwPlatformCloseWindow(_GLFWwindow* window); |
| 263 | void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); |
| 264 | void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); |
| 265 | void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y); |
| 266 | void _glfwPlatformIconifyWindow(_GLFWwindow* window); |
| 267 | void _glfwPlatformRestoreWindow(_GLFWwindow* window); |
| 268 | void _glfwPlatformHideMouseCursor(_GLFWwindow* window); |
| 269 | void _glfwPlatformShowMouseCursor(_GLFWwindow* window); |
| 270 | void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y); |
| 271 | |
| 272 | // Event management |
| 273 | void _glfwPlatformPollEvents(void); |
| 274 | void _glfwPlatformWaitEvents(void); |
| 275 | |
| 276 | // OpenGL context management |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 277 | void _glfwPlatformSwapBuffers(void); |
| 278 | void _glfwPlatformSwapInterval(int interval); |
| 279 | void _glfwPlatformRefreshWindowParams(void); |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 280 | int _glfwPlatformExtensionSupported(const char* extension); |
| 281 | void* _glfwPlatformGetProcAddress(const char* procname); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 282 | |
| 283 | |
| 284 | //======================================================================== |
| 285 | // Prototypes for platform independent internal functions |
| 286 | //======================================================================== |
| 287 | |
Camilla Berglund | d6fe447 | 2010-09-13 18:05:59 +0200 | [diff] [blame] | 288 | // Error handling |
| 289 | void _glfwSetError(int error); |
| 290 | |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 291 | // Window management (window.c) |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 292 | void _glfwClearWindowHints(void); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 293 | |
| 294 | // Input handling (window.c) |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 295 | void _glfwClearInput(_GLFWwindow* window); |
| 296 | void _glfwInputDeactivation(_GLFWwindow* window); |
| 297 | void _glfwInputKey(_GLFWwindow* window, int key, int action); |
Camilla Berglund | 93ea341 | 2010-09-09 19:33:37 +0200 | [diff] [blame] | 298 | void _glfwInputChar(_GLFWwindow* window, int character); |
Camilla Berglund | 135194a | 2010-09-09 18:15:32 +0200 | [diff] [blame] | 299 | void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 300 | |
| 301 | // OpenGL extensions (glext.c) |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 302 | void _glfwParseGLVersion(int* major, int* minor, int* rev); |
| 303 | int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 304 | |
| 305 | // Framebuffer configs |
Camilla Berglund | d46b222 | 2010-09-08 17:30:21 +0200 | [diff] [blame] | 306 | const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, |
| 307 | const _GLFWfbconfig* alternatives, |
| 308 | unsigned int count); |
Camilla Berglund | 3249f81 | 2010-09-07 17:34:51 +0200 | [diff] [blame] | 309 | |
| 310 | |
| 311 | #endif // _internal_h_ |