ff0c08f182c8d7ab21d7b48c068dd2ca54729f87
[freeglut] / src / blackberry / fg_window_blackberry.c
1 /*
2  * fg_window_blackberry.c
3  *
4  * Window management methods for BlackBerry
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Copied for Platform code by Evan Felix <karcaw at gmail.com>
9  * Copyright (C) 2012  Sylvain Beucler
10  * Copyright (C) 2013  Vincent Simonetti
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29
30 #define FREEGLUT_BUILDING_LIB
31 #include <GL/freeglut.h>
32 #include "fg_internal.h"
33 #include "egl/fg_window_egl.h"
34 #include <screen/screen.h>
35 #include <bps/screen.h>
36
37 /*
38  * Opens a window. Requires a SFG_Window object created and attached
39  * to the freeglut structure. OpenGL context is created here.
40  */
41 void fgPlatformOpenWindow( SFG_Window* window, const char* title,
42                            GLboolean positionUse, int x, int y,
43                            GLboolean sizeUse, int w, int h,
44                            GLboolean gameMode, GLboolean isSubWindow )
45 {
46   /* TODO: only one full-screen window possible? */
47   if (fgDisplay.pDisplay.single_native_window != NULL) {
48     fgWarning("You can't have more than one window on BlackBerry");
49     return;
50   }
51   window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment
52
53   /* Create window */
54   if (screen_create_context(&window->Window.pContext.screenContext, 0)) {
55     fgError("Could not create screen context");
56         return;
57   }
58   screen_window_t sWindow;
59   if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) {
60         screen_destroy_context(window->Window.pContext.screenContext);
61         fgError("Could not create window");
62         return;
63   }
64   fgDisplay.pDisplay.single_native_window = sWindow;
65
66   /* Set window properties */
67   int screenFormat = SCREEN_FORMAT_RGBA8888;
68 #ifdef GL_ES_VERSION_2_0
69   int screenUsage = SCREEN_USAGE_OPENGL_ES2;
70 #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1
71   int screenUsage = SCREEN_USAGE_OPENGL_ES1;
72 #endif
73 #ifndef __X86__
74   screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display
75 #endif
76   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) {
77         screen_destroy_window(sWindow);
78         screen_destroy_context(window->Window.pContext.screenContext);
79         fgError("Could not set window format");
80         return;
81   }
82   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) {
83         screen_destroy_window(sWindow);
84         screen_destroy_context(window->Window.pContext.screenContext);
85         fgError("Could not set window usage");
86         return;
87   }
88
89   /* Could set size based on what is specified for window. Work on another time
90   int size[2];
91   size[0] = w;
92   size[1] = h;
93   if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) {
94         screen_destroy_window(sWindow);
95         screen_destroy_context(window->Window.pContext.screenContext);
96         fgError("Could not set window buffer size");
97         return;
98   }*/
99
100   /* Create window buffers */
101   if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) {
102         screen_destroy_window(sWindow);
103         screen_destroy_context(window->Window.pContext.screenContext);
104         fgError("Could not create window buffers");
105         return;
106   }
107
108   /* Request window events */
109   screen_request_events(window->Window.pContext.screenContext);
110
111   /* Save window and set state */
112   window->Window.Handle = fgDisplay.pDisplay.single_native_window;
113   window->State.WorkMask |= GLUT_INIT_WORK;
114   window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now
115
116   /* Create context */
117   fghChooseConfig(&window->Window.pContext.egl.Config);
118   window->Window.Context = fghCreateNewContextEGL(window);
119
120   /* Create EGL window */
121   fghPlatformOpenWindowEGL(window);
122
123   window->State.Visible = GL_TRUE;
124 }
125
126 /*
127  * Request a window resize
128  */
129 void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
130 {
131   fprintf(stderr, "fgPlatformReshapeWindow: STUB\n");
132 }
133
134 /*
135  * Closes a window, destroying the frame and OpenGL context
136  */
137 void fgPlatformCloseWindow( SFG_Window* window )
138 {
139   fghPlatformCloseWindowEGL(window);
140
141   screen_stop_events(window->Window.pContext.screenContext);
142
143   screen_destroy_window((screen_window_t)window->Window.Handle);
144
145   screen_destroy_context(window->Window.pContext.screenContext);
146 }
147
148 /*
149  * This function makes the specified window visible
150  */
151 void fgPlatformShowWindow( void )
152 {
153   fprintf(stderr, "fgPlatformShowWindow: STUB\n");
154 }
155
156 /*
157  * This function hides the specified window
158  */
159 void fgPlatformHideWindow( SFG_Window *window )
160 {
161   fprintf(stderr, "fgPlatformHideWindow: STUB\n");
162 }
163
164 /*
165  * Iconify the specified window (top-level windows only)
166  */
167 void fgPlatformIconifyWindow( SFG_Window *window )
168 {
169   fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n");
170 }
171
172 /*
173  * Set the current window's title
174  */
175 void fgPlatformGlutSetWindowTitle( const char* title )
176 {
177   fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n");
178 }
179
180 /*
181  * Set the current window's iconified title
182  */
183 void fgPlatformGlutSetIconTitle( const char* title )
184 {
185   fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");}
186
187 /*
188  * Change the specified window's position
189  */
190 void fgPlatformPositionWindow( SFG_Window *window, int x, int y )
191 {
192   fprintf(stderr, "fgPlatformPositionWindow: STUB\n");
193 }
194
195 /*
196  * Lowers the specified window (by Z order change)
197  */
198 void fgPlatformPushWindow( SFG_Window *window )
199 {
200   fprintf(stderr, "fgPlatformPushWindow: STUB\n");
201 }
202
203 /*
204  * Raises the specified window (by Z order change)
205  */
206 void fgPlatformPopWindow( SFG_Window *window )
207 {
208   fprintf(stderr, "fgPlatformPopWindow: STUB\n");
209 }
210
211 /*
212  * Toggle the window's full screen state.
213  */
214 void fgPlatformFullScreenToggle( SFG_Window *win )
215 {
216   fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n");
217 }