blob: cb19d5e21464fc26177bec324c6de331236917b3 [file] [log] [blame]
Camilla Berglund3249f812010-09-07 17:34:51 +02001//========================================================================
2// GLFW - An OpenGL framework
3// Platform: Any
Camilla Berglund38b0ccb2010-09-07 17:41:26 +02004// API version: 3.0
Camilla Berglund3249f812010-09-07 17:34:51 +02005// 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 Berglundd46b2222010-09-08 17:30:21 +020039#if defined(_init_c_)
Camilla Berglund3249f812010-09-07 17:34:51 +020040#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 Berglund3249f812010-09-07 17:34:51 +020054//------------------------------------------------------------------------
Camilla Berglund135194a2010-09-09 18:15:32 +020055// Platform specific definitions goes in platform.h (which also includes
56// glfw.h)
57//------------------------------------------------------------------------
58
59#include "platform.h"
60
61
62//------------------------------------------------------------------------
Camilla Berglund12d17b92010-09-09 20:18:10 +020063// Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow
64// A bucket of semi-random stuff lumped together for historical reasons
Camilla Berglund3249f812010-09-07 17:34:51 +020065// This is used only by the platform independent code and only to store
66// parameters passed to us by glfwOpenWindowHint
67//------------------------------------------------------------------------
Camilla Berglund12d17b92010-09-09 20:18:10 +020068typedef struct _GLFWhints
69{
Camilla Berglund950a3be2010-09-09 19:58:51 +020070 int redBits;
71 int greenBits;
72 int blueBits;
73 int alphaBits;
74 int depthBits;
75 int stencilBits;
Camilla Berglund3249f812010-09-07 17:34:51 +020076 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 Berglund3249f812010-09-07 17:34:51 +020094// 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 Berglund12d17b92010-09-09 20:18:10 +020099typedef struct _GLFWwndconfig
100{
Camilla Berglund3249f812010-09-07 17:34:51 +0200101 int mode;
Camilla Berglund0f80e062010-09-14 03:10:45 +0200102 const char* title;
Camilla Berglund3249f812010-09-07 17:34:51 +0200103 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 Berglund12d17b92010-09-09 20:18:10 +0200120typedef struct _GLFWfbconfig
121{
Camilla Berglund3249f812010-09-07 17:34:51 +0200122 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 Berglund135194a2010-09-09 18:15:32 +0200139//------------------------------------------------------------------------
140// Window structure
141//------------------------------------------------------------------------
Camilla Berglund12d17b92010-09-09 20:18:10 +0200142typedef struct _GLFWwindow
143{
Camilla Berglund326d9972010-09-10 00:06:23 +0200144 struct _GLFWwindow* next;
145
Camilla Berglund135194a2010-09-09 18:15:32 +0200146 // 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 Berglund12d17b92010-09-09 20:18:10 +0200156 // Window settings and state
Camilla Berglund12d17b92010-09-09 20:18:10 +0200157 GLboolean iconified; // GL_TRUE if this window is iconified
Camilla Berglund326d9972010-09-10 00:06:23 +0200158 GLboolean closed; // GL_TRUE if this window should be closed
Camilla Berglund12d17b92010-09-09 20:18:10 +0200159 int width, height;
Camilla Berglund318f7312010-09-14 03:53:22 +0200160 int positionX, positionY;
Camilla Berglund12d17b92010-09-09 20:18:10 +0200161 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 Berglund48f5a7e2010-09-09 22:44:38 +0200165 void* userPointer;
Camilla Berglund135194a2010-09-09 18:15:32 +0200166
Camilla Berglund12d17b92010-09-09 20:18:10 +0200167 // Window input state
Camilla Berglund135194a2010-09-09 18:15:32 +0200168 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 Berglund135194a2010-09-09 18:15:32 +0200177 // 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 Berglund12d17b92010-09-09 20:18:10 +0200193 GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated"
Camilla Berglund135194a2010-09-09 18:15:32 +0200194 int glMajor, glMinor, glRevision;
195 int glForward, glDebug, glProfile;
Camilla Berglund135194a2010-09-09 18:15:32 +0200196 PFNGLGETSTRINGIPROC GetStringi;
197
198 _GLFW_PLATFORM_WINDOW_STATE;
Camilla Berglund32287552010-09-09 20:36:23 +0200199 _GLFW_PLATFORM_CONTEXT_STATE;
Camilla Berglund135194a2010-09-09 18:15:32 +0200200} _GLFWwindow;
201
202
203//------------------------------------------------------------------------
204// Library global data
205//------------------------------------------------------------------------
Camilla Berglund12d17b92010-09-09 20:18:10 +0200206typedef struct _GLFWlibrary
207{
Camilla Berglund135194a2010-09-09 18:15:32 +0200208 _GLFWhints hints;
Camilla Berglund326d9972010-09-10 00:06:23 +0200209
210 _GLFWwindow* windowListHead;
Camilla Berglund135194a2010-09-09 18:15:32 +0200211 _GLFWwindow* currentWindow;
Camilla Berglundae57d132010-09-11 15:14:57 +0200212 _GLFWwindow* activeWindow;
Camilla Berglund135194a2010-09-09 18:15:32 +0200213 _GLFWwindow* cursorLockWindow;
214
215 _GLFW_PLATFORM_LIBRARY_STATE;
216} _GLFWlibrary;
217
218
Camilla Berglund3249f812010-09-07 17:34:51 +0200219//========================================================================
220// System independent global variables (GLFW internals)
221//========================================================================
222
223// Flag indicating if GLFW has been initialized
Camilla Berglundd46b2222010-09-08 17:30:21 +0200224#if defined(_init_c_)
Camilla Berglund12d17b92010-09-09 20:18:10 +0200225GLboolean _glfwInitialized = GL_FALSE;
Camilla Berglund3249f812010-09-07 17:34:51 +0200226#else
Camilla Berglund12d17b92010-09-09 20:18:10 +0200227GLFWGLOBAL GLboolean _glfwInitialized;
Camilla Berglund3249f812010-09-07 17:34:51 +0200228#endif
229
Camilla Berglund135194a2010-09-09 18:15:32 +0200230GLFWGLOBAL _GLFWlibrary _glfwLibrary;
231
Camilla Berglund3249f812010-09-07 17:34:51 +0200232
233//========================================================================
234// Prototypes for platform specific implementation functions
235//========================================================================
236
237// Init/terminate
Camilla Berglundd46b2222010-09-08 17:30:21 +0200238int _glfwPlatformInit(void);
239int _glfwPlatformTerminate(void);
Camilla Berglundd6fe4472010-09-13 18:05:59 +0200240const char* _glfwPlatformGetVersionString(void);
Camilla Berglundf5d74c42010-09-09 21:06:59 +0200241
Camilla Berglund3249f812010-09-07 17:34:51 +0200242// Enable/Disable
Camilla Berglund135194a2010-09-09 18:15:32 +0200243void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
244void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
Camilla Berglund3249f812010-09-07 17:34:51 +0200245
246// Fullscreen
Camilla Berglundd46b2222010-09-08 17:30:21 +0200247int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount);
248void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
Camilla Berglund3249f812010-09-07 17:34:51 +0200249
Camilla Berglund3249f812010-09-07 17:34:51 +0200250// Joystick
Camilla Berglundd46b2222010-09-08 17:30:21 +0200251int _glfwPlatformGetJoystickParam(int joy, int param);
252int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes);
253int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
Camilla Berglund3249f812010-09-07 17:34:51 +0200254
255// Time
Camilla Berglundd46b2222010-09-08 17:30:21 +0200256double _glfwPlatformGetTime(void);
257void _glfwPlatformSetTime(double time);
Camilla Berglund3249f812010-09-07 17:34:51 +0200258
259// Window management
Camilla Berglund819d0442010-09-13 23:42:51 +0200260int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
Camilla Berglund1bac9962010-09-13 23:47:43 +0200261void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window);
Camilla Berglund135194a2010-09-09 18:15:32 +0200262void _glfwPlatformCloseWindow(_GLFWwindow* window);
263void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
264void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
265void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
266void _glfwPlatformIconifyWindow(_GLFWwindow* window);
267void _glfwPlatformRestoreWindow(_GLFWwindow* window);
268void _glfwPlatformHideMouseCursor(_GLFWwindow* window);
269void _glfwPlatformShowMouseCursor(_GLFWwindow* window);
270void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y);
271
272// Event management
273void _glfwPlatformPollEvents(void);
274void _glfwPlatformWaitEvents(void);
275
276// OpenGL context management
Camilla Berglundd46b2222010-09-08 17:30:21 +0200277void _glfwPlatformSwapBuffers(void);
278void _glfwPlatformSwapInterval(int interval);
279void _glfwPlatformRefreshWindowParams(void);
Camilla Berglund135194a2010-09-09 18:15:32 +0200280int _glfwPlatformExtensionSupported(const char* extension);
281void* _glfwPlatformGetProcAddress(const char* procname);
Camilla Berglund3249f812010-09-07 17:34:51 +0200282
283
284//========================================================================
285// Prototypes for platform independent internal functions
286//========================================================================
287
Camilla Berglundd6fe4472010-09-13 18:05:59 +0200288// Error handling
289void _glfwSetError(int error);
290
Camilla Berglund3249f812010-09-07 17:34:51 +0200291// Window management (window.c)
Camilla Berglundd46b2222010-09-08 17:30:21 +0200292void _glfwClearWindowHints(void);
Camilla Berglund3249f812010-09-07 17:34:51 +0200293
294// Input handling (window.c)
Camilla Berglund135194a2010-09-09 18:15:32 +0200295void _glfwClearInput(_GLFWwindow* window);
296void _glfwInputDeactivation(_GLFWwindow* window);
297void _glfwInputKey(_GLFWwindow* window, int key, int action);
Camilla Berglund93ea3412010-09-09 19:33:37 +0200298void _glfwInputChar(_GLFWwindow* window, int character);
Camilla Berglund135194a2010-09-09 18:15:32 +0200299void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
Camilla Berglund3249f812010-09-07 17:34:51 +0200300
301// OpenGL extensions (glext.c)
Camilla Berglundd46b2222010-09-08 17:30:21 +0200302void _glfwParseGLVersion(int* major, int* minor, int* rev);
303int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
Camilla Berglund3249f812010-09-07 17:34:51 +0200304
305// Framebuffer configs
Camilla Berglundd46b2222010-09-08 17:30:21 +0200306const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
307 const _GLFWfbconfig* alternatives,
308 unsigned int count);
Camilla Berglund3249f812010-09-07 17:34:51 +0200309
310
311#endif // _internal_h_