4c027a68f65a5de74583697aa83129fc8505692d
[mesa.git] / src / glut / directfb / game.c
1 /*
2 * Copyright (C) 2006 Claudio Ciccani <klan@users.sf.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "internal.h"
25
26
27 /*****************************************************************************/
28
29 static int g_display_changed = 0;
30
31 /*****************************************************************************/
32
33
34 void GLUTAPIENTRY
35 glutGameModeString( const char *string )
36 {
37 int x, y, bpp;
38 char *tmp;
39
40 if (!string)
41 return;
42
43 tmp = strchr( string, 'x' );
44 if (tmp) {
45 x = strtol( string, NULL, 10 );
46 y = strtol( tmp+1, NULL, 10 );
47
48 if (x > 0 && y > 0) {
49 g_width = x;
50 g_height = y;
51 }
52 }
53
54 tmp = strchr( string, ':' );
55 if (tmp) {
56 bpp = strtol( tmp+1, NULL, 10 );
57
58 if (bpp > 0)
59 g_bpp = bpp;
60 }
61 }
62
63
64 int GLUTAPIENTRY
65 glutEnterGameMode( void )
66 {
67 DFBDisplayLayerConfig prev, cur;
68
69 glutInit( NULL, NULL );
70
71 primary->GetConfiguration( primary, &prev );
72 primary->SetCooperativeLevel( primary, DLSCL_EXCLUSIVE );
73
74 if (g_game)
75 __glutDestroyWindow( g_game );
76
77 g_game = __glutCreateWindow( GL_TRUE );
78 if (!g_game)
79 return 0;
80
81 __glutSetWindow( g_game );
82 g_game->cursor = GLUT_CURSOR_NONE;
83
84 primary->GetConfiguration( primary, &cur );
85 g_display_changed = (cur.width != prev.width ||
86 cur.height != prev.height ||
87 cur.pixelformat != prev.pixelformat);
88
89 return g_game->id;
90 }
91
92
93 void GLUTAPIENTRY
94 glutLeaveGameMode( void )
95 {
96 if (g_game)
97 __glutDestroyWindow( g_game );
98
99 primary->SetCooperativeLevel( primary, DLSCL_ADMINISTRATIVE );
100 }
101
102
103 int GLUTAPIENTRY
104 glutGameModeGet( GLenum type )
105 {
106 switch (type) {
107 case GLUT_GAME_MODE_ACTIVE:
108 return (g_game != NULL);
109 case GLUT_GAME_MODE_POSSIBLE:
110 if (primary) {
111 DFBDisplayLayerConfig c;
112 c.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
113 c.width = g_width;
114 c.height = g_height;
115 /* XXX: bpp */
116 if (primary->TestConfiguration( primary, &c, 0 ) == DFB_OK)
117 return 1;
118 }
119 break;
120 case GLUT_GAME_MODE_WIDTH:
121 if (g_game) {
122 int w;
123 g_game->surface->GetSize( g_game->surface, &w, 0 );
124 return w;
125 }
126 break;
127 case GLUT_GAME_MODE_HEIGHT:
128 if (g_game) {
129 int h;
130 g_game->surface->GetSize( g_game->surface, 0, &h );
131 return h;
132 }
133 break;
134 case GLUT_GAME_MODE_PIXEL_DEPTH:
135 if (g_game) {
136 DFBSurfacePixelFormat f;
137 g_game->surface->GetPixelFormat( g_game->surface, &f );
138 return DFB_COLOR_BITS_PER_PIXEL( f );
139 }
140 break;
141 case GLUT_GAME_MODE_REFRESH_RATE:
142 return 60; /* assume 60hz */
143 case GLUT_GAME_MODE_DISPLAY_CHANGED:
144 return g_display_changed;
145 default:
146 break;
147 }
148
149 return 0;
150 }
151
152
153