blob: 07c75bb4a37d15ba6189399281c4d583fb299472 [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
Camilla Berglund3ca63a02010-09-17 00:54:11 +020059#include "config.h"
Camilla Berglund3be0c052010-11-17 14:52:47 +010060
61#include "../../include/GL/glfw3.h"
62#include "../../include/GL/glext.h"
63
Camilla Berglund135194a2010-09-09 18:15:32 +020064#include "platform.h"
65
66
Camilla Berglund99ddce32010-10-04 18:17:53 +020067typedef struct _GLFWhints _GLFWhints;
68typedef struct _GLFWwndconfig _GLFWwndconfig;
69typedef struct _GLFWfbconfig _GLFWfbconfig;
70typedef struct _GLFWwindow _GLFWwindow;
71typedef struct _GLFWlibrary _GLFWlibrary;
72
73
Camilla Berglund135194a2010-09-09 18:15:32 +020074//------------------------------------------------------------------------
Camilla Berglund12d17b92010-09-09 20:18:10 +020075// Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow
76// A bucket of semi-random stuff lumped together for historical reasons
Camilla Berglund3249f812010-09-07 17:34:51 +020077// This is used only by the platform independent code and only to store
78// parameters passed to us by glfwOpenWindowHint
79//------------------------------------------------------------------------
Camilla Berglund99ddce32010-10-04 18:17:53 +020080struct _GLFWhints
Camilla Berglund12d17b92010-09-09 20:18:10 +020081{
Camilla Berglund950a3be2010-09-09 19:58:51 +020082 int redBits;
83 int greenBits;
84 int blueBits;
85 int alphaBits;
86 int depthBits;
87 int stencilBits;
Camilla Berglund3249f812010-09-07 17:34:51 +020088 int refreshRate;
89 int accumRedBits;
90 int accumGreenBits;
91 int accumBlueBits;
92 int accumAlphaBits;
93 int auxBuffers;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +020094 GLboolean stereo;
95 GLboolean windowNoResize;
Camilla Berglund3249f812010-09-07 17:34:51 +020096 int samples;
97 int glMajor;
98 int glMinor;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +020099 GLboolean glForward;
100 GLboolean glDebug;
Camilla Berglund3249f812010-09-07 17:34:51 +0200101 int glProfile;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200102};
Camilla Berglund3249f812010-09-07 17:34:51 +0200103
104
105//------------------------------------------------------------------------
Camilla Berglund3249f812010-09-07 17:34:51 +0200106// Parameters relating to the creation of the context and window but not
107// directly related to the properties of the framebuffer
108// This is used to pass window and context creation parameters from the
109// platform independent code to the platform specific code
110//------------------------------------------------------------------------
Camilla Berglund99ddce32010-10-04 18:17:53 +0200111struct _GLFWwndconfig
Camilla Berglund12d17b92010-09-09 20:18:10 +0200112{
Camilla Berglund99ddce32010-10-04 18:17:53 +0200113 int mode;
114 const char* title;
115 int refreshRate;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +0200116 GLboolean windowNoResize;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200117 int glMajor;
118 int glMinor;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +0200119 GLboolean glForward;
120 GLboolean glDebug;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200121 int glProfile;
122 _GLFWwindow* share;
123};
Camilla Berglund3249f812010-09-07 17:34:51 +0200124
125
126//------------------------------------------------------------------------
127// Framebuffer configuration descriptor, i.e. buffers and their sizes
128// Also a platform specific ID used to map back to the actual backend APIs
129// This is used to pass framebuffer parameters from the platform independent
130// code to the platform specific code, and also to enumerate and select
131// available framebuffer configurations
132//------------------------------------------------------------------------
Camilla Berglund99ddce32010-10-04 18:17:53 +0200133struct _GLFWfbconfig
Camilla Berglund12d17b92010-09-09 20:18:10 +0200134{
Camilla Berglund3249f812010-09-07 17:34:51 +0200135 int redBits;
136 int greenBits;
137 int blueBits;
138 int alphaBits;
139 int depthBits;
140 int stencilBits;
141 int accumRedBits;
142 int accumGreenBits;
143 int accumBlueBits;
144 int accumAlphaBits;
145 int auxBuffers;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +0200146 GLboolean stereo;
Camilla Berglund3249f812010-09-07 17:34:51 +0200147 int samples;
148 GLFWintptr platformID;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200149};
Camilla Berglund3249f812010-09-07 17:34:51 +0200150
151
Camilla Berglund135194a2010-09-09 18:15:32 +0200152//------------------------------------------------------------------------
153// Window structure
154//------------------------------------------------------------------------
Camilla Berglund99ddce32010-10-04 18:17:53 +0200155struct _GLFWwindow
Camilla Berglund12d17b92010-09-09 20:18:10 +0200156{
Camilla Berglund326d9972010-09-10 00:06:23 +0200157 struct _GLFWwindow* next;
158
Camilla Berglund12d17b92010-09-09 20:18:10 +0200159 // Window settings and state
Camilla Berglund12d17b92010-09-09 20:18:10 +0200160 GLboolean iconified; // GL_TRUE if this window is iconified
Camilla Berglund867e7472010-09-16 06:02:44 +0200161 GLboolean closeRequested; // GL_TRUE if this window should be closed
Camilla Berglund12d17b92010-09-09 20:18:10 +0200162 int width, height;
Camilla Berglund318f7312010-09-14 03:53:22 +0200163 int positionX, positionY;
Camilla Berglund12d17b92010-09-09 20:18:10 +0200164 int mode; // GLFW_WINDOW or GLFW_FULLSCREEN
165 GLboolean sysKeysDisabled; // system keys disabled flag
166 GLboolean windowNoResize; // resize- and maximize gadgets disabled flag
167 int refreshRate; // monitor refresh rate
Camilla Berglund48f5a7e2010-09-09 22:44:38 +0200168 void* userPointer;
Camilla Berglund135194a2010-09-09 18:15:32 +0200169
Camilla Berglund12d17b92010-09-09 20:18:10 +0200170 // Window input state
Camilla Berglund135194a2010-09-09 18:15:32 +0200171 GLboolean stickyKeys;
172 GLboolean stickyMouseButtons;
173 GLboolean keyRepeat;
174 int mousePosX, mousePosY;
Camilla Berglund007766b2010-09-27 02:09:54 +0200175 int scrollX, scrollY;
Camilla Berglund135194a2010-09-09 18:15:32 +0200176 char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
177 char key[GLFW_KEY_LAST + 1];
Camilla Berglund135194a2010-09-09 18:15:32 +0200178
Camilla Berglund135194a2010-09-09 18:15:32 +0200179 // Framebuffer attributes
180 int redBits;
181 int greenBits;
182 int blueBits;
183 int alphaBits;
184 int depthBits;
185 int stencilBits;
186 int accumRedBits;
187 int accumGreenBits;
188 int accumBlueBits;
189 int accumAlphaBits;
190 int auxBuffers;
191 GLboolean stereo;
192 int samples;
193
194 // OpenGL extensions and context attributes
Camilla Berglund12d17b92010-09-09 20:18:10 +0200195 GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated"
Camilla Berglund135194a2010-09-09 18:15:32 +0200196 int glMajor, glMinor, glRevision;
Camilla Berglund70b9a1f2010-10-25 12:36:14 +0200197 GLboolean glForward, glDebug;
198 int glProfile;
Camilla Berglund135194a2010-09-09 18:15:32 +0200199 PFNGLGETSTRINGIPROC GetStringi;
200
Camilla Berglunde9eb8412010-10-14 16:40:10 +0200201 // These are defined in the current port's platform.h
Camilla Berglund135194a2010-09-09 18:15:32 +0200202 _GLFW_PLATFORM_WINDOW_STATE;
Camilla Berglund32287552010-09-09 20:36:23 +0200203 _GLFW_PLATFORM_CONTEXT_STATE;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200204};
Camilla Berglund135194a2010-09-09 18:15:32 +0200205
206
207//------------------------------------------------------------------------
208// Library global data
209//------------------------------------------------------------------------
Camilla Berglund99ddce32010-10-04 18:17:53 +0200210struct _GLFWlibrary
Camilla Berglund12d17b92010-09-09 20:18:10 +0200211{
Camilla Berglund2630d492010-10-13 04:04:43 +0200212 _GLFWhints hints;
Camilla Berglund326d9972010-09-10 00:06:23 +0200213
Camilla Berglund2630d492010-10-13 04:04:43 +0200214 _GLFWwindow* windowListHead;
215 _GLFWwindow* currentWindow;
216 _GLFWwindow* activeWindow;
217 _GLFWwindow* cursorLockWindow;
218
Camilla Berglundf1e7d7c2010-11-23 17:45:23 +0100219 GLFWerrorfun errorCallback;
Camilla Berglund4044c2d2010-10-24 18:28:55 +0200220 GLFWwindowsizefun windowSizeCallback;
221 GLFWwindowclosefun windowCloseCallback;
222 GLFWwindowrefreshfun windowRefreshCallback;
223 GLFWwindowfocusfun windowFocusCallback;
224 GLFWwindowiconifyfun windowIconifyCallback;
225 GLFWmousebuttonfun mouseButtonCallback;
226 GLFWmouseposfun mousePosCallback;
227 GLFWscrollfun scrollCallback;
228 GLFWkeyfun keyCallback;
229 GLFWcharfun charCallback;
230
Camilla Berglund2630d492010-10-13 04:04:43 +0200231 GLFWgammaramp currentRamp;
232 GLFWgammaramp originalRamp;
233 int originalRampSize;
Camilla Berglund135194a2010-09-09 18:15:32 +0200234
Camilla Berglunde9eb8412010-10-14 16:40:10 +0200235 // This is defined in the current port's platform.h
Camilla Berglund135194a2010-09-09 18:15:32 +0200236 _GLFW_PLATFORM_LIBRARY_STATE;
Camilla Berglund99ddce32010-10-04 18:17:53 +0200237};
Camilla Berglund135194a2010-09-09 18:15:32 +0200238
239
Camilla Berglund3249f812010-09-07 17:34:51 +0200240//========================================================================
241// System independent global variables (GLFW internals)
242//========================================================================
243
244// Flag indicating if GLFW has been initialized
Camilla Berglundd46b2222010-09-08 17:30:21 +0200245#if defined(_init_c_)
Camilla Berglund12d17b92010-09-09 20:18:10 +0200246GLboolean _glfwInitialized = GL_FALSE;
Camilla Berglund3249f812010-09-07 17:34:51 +0200247#else
Camilla Berglund12d17b92010-09-09 20:18:10 +0200248GLFWGLOBAL GLboolean _glfwInitialized;
Camilla Berglund3249f812010-09-07 17:34:51 +0200249#endif
250
Camilla Berglund135194a2010-09-09 18:15:32 +0200251GLFWGLOBAL _GLFWlibrary _glfwLibrary;
252
Camilla Berglund3249f812010-09-07 17:34:51 +0200253
254//========================================================================
255// Prototypes for platform specific implementation functions
256//========================================================================
257
258// Init/terminate
Camilla Berglundd46b2222010-09-08 17:30:21 +0200259int _glfwPlatformInit(void);
260int _glfwPlatformTerminate(void);
Camilla Berglundd6fe4472010-09-13 18:05:59 +0200261const char* _glfwPlatformGetVersionString(void);
Camilla Berglundf5d74c42010-09-09 21:06:59 +0200262
Camilla Berglund3249f812010-09-07 17:34:51 +0200263// Enable/Disable
Camilla Berglund135194a2010-09-09 18:15:32 +0200264void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
265void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
Camilla Berglund3249f812010-09-07 17:34:51 +0200266
267// Fullscreen
Camilla Berglundd46b2222010-09-08 17:30:21 +0200268int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount);
269void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
Camilla Berglund3249f812010-09-07 17:34:51 +0200270
Camilla Berglund2630d492010-10-13 04:04:43 +0200271// Gamma ramp
Camilla Berglund85bcd1f2010-10-13 22:42:31 +0200272void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);
Camilla Berglund2630d492010-10-13 04:04:43 +0200273void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp);
274
Camilla Berglund3249f812010-09-07 17:34:51 +0200275// Joystick
Camilla Berglundd46b2222010-09-08 17:30:21 +0200276int _glfwPlatformGetJoystickParam(int joy, int param);
277int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes);
278int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
Camilla Berglund3249f812010-09-07 17:34:51 +0200279
280// Time
Camilla Berglundd46b2222010-09-08 17:30:21 +0200281double _glfwPlatformGetTime(void);
282void _glfwPlatformSetTime(double time);
Camilla Berglund3249f812010-09-07 17:34:51 +0200283
284// Window management
Camilla Berglund819d0442010-09-13 23:42:51 +0200285int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
Camilla Berglund1bac9962010-09-13 23:47:43 +0200286void _glfwPlatformMakeWindowCurrent(_GLFWwindow* window);
Camilla Berglund135194a2010-09-09 18:15:32 +0200287void _glfwPlatformCloseWindow(_GLFWwindow* window);
288void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
289void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
290void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
291void _glfwPlatformIconifyWindow(_GLFWwindow* window);
292void _glfwPlatformRestoreWindow(_GLFWwindow* window);
293void _glfwPlatformHideMouseCursor(_GLFWwindow* window);
294void _glfwPlatformShowMouseCursor(_GLFWwindow* window);
295void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y);
296
297// Event management
298void _glfwPlatformPollEvents(void);
299void _glfwPlatformWaitEvents(void);
300
301// OpenGL context management
Camilla Berglundd46b2222010-09-08 17:30:21 +0200302void _glfwPlatformSwapBuffers(void);
303void _glfwPlatformSwapInterval(int interval);
304void _glfwPlatformRefreshWindowParams(void);
Camilla Berglund135194a2010-09-09 18:15:32 +0200305int _glfwPlatformExtensionSupported(const char* extension);
306void* _glfwPlatformGetProcAddress(const char* procname);
Camilla Berglund3249f812010-09-07 17:34:51 +0200307
308
309//========================================================================
310// Prototypes for platform independent internal functions
311//========================================================================
312
Camilla Berglund3089e602010-09-16 03:48:19 +0200313// Fullscren management (fullscreen.c)
314void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
315
Camilla Berglundd6fe4472010-09-13 18:05:59 +0200316// Error handling
Camilla Berglundf1e7d7c2010-11-23 17:45:23 +0100317void _glfwSetError(int error, const char* description);
Camilla Berglundd6fe4472010-09-13 18:05:59 +0200318
Camilla Berglund3249f812010-09-07 17:34:51 +0200319// Window management (window.c)
Camilla Berglundd46b2222010-09-08 17:30:21 +0200320void _glfwClearWindowHints(void);
Camilla Berglund3249f812010-09-07 17:34:51 +0200321
322// Input handling (window.c)
Camilla Berglund135194a2010-09-09 18:15:32 +0200323void _glfwInputKey(_GLFWwindow* window, int key, int action);
Camilla Berglund93ea3412010-09-09 19:33:37 +0200324void _glfwInputChar(_GLFWwindow* window, int character);
Camilla Berglundf93801c2010-09-27 02:16:17 +0200325void _glfwInputScroll(_GLFWwindow* window, int x, int y);
Camilla Berglund135194a2010-09-09 18:15:32 +0200326void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
Camilla Berglundbc7a8d42010-09-19 02:49:42 +0200327void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
Camilla Berglund3249f812010-09-07 17:34:51 +0200328
329// OpenGL extensions (glext.c)
Camilla Berglundd46b2222010-09-08 17:30:21 +0200330void _glfwParseGLVersion(int* major, int* minor, int* rev);
331int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
Camilla Berglund3249f812010-09-07 17:34:51 +0200332
333// Framebuffer configs
Camilla Berglundd46b2222010-09-08 17:30:21 +0200334const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
335 const _GLFWfbconfig* alternatives,
336 unsigned int count);
Camilla Berglund3249f812010-09-07 17:34:51 +0200337
338
339#endif // _internal_h_