194d5bbb62614425bb6af067878f97271af8216f
[mesa.git] / src / glut / directfb / state.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 <sys/time.h>
23
24 #include "GL/glu.h"
25
26 #include "internal.h"
27
28
29 int GLUTAPIENTRY
30 glutGet( GLenum type )
31 {
32 switch (type) {
33 case GLUT_WINDOW_X:
34 if (g_current && g_current->window) {
35 int x;
36 g_current->window->GetPosition( g_current->window, &x, 0 );
37 return x;
38 }
39 break;
40 case GLUT_WINDOW_Y:
41 if (g_current && g_current->window) {
42 int y;
43 g_current->window->GetPosition( g_current->window, 0, &y );
44 return y;
45 }
46 break;
47
48 case GLUT_WINDOW_WIDTH:
49 if (g_current) {
50 int w;
51 g_current->surface->GetSize( g_current->surface, &w, 0 );
52 return w;
53 }
54 break;
55 case GLUT_WINDOW_HEIGHT:
56 if (g_current) {
57 int h;
58 g_current->surface->GetSize( g_current->surface, 0, &h );
59 return h;
60 }
61 break;
62
63 case GLUT_WINDOW_BUFFER_SIZE:
64 if (g_current) {
65 DFBGLAttributes a;
66 g_current->gl->GetAttributes( g_current->gl, &a );
67 return a.buffer_size;
68 }
69 break;
70 case GLUT_WINDOW_STENCIL_SIZE:
71 if (g_current) {
72 DFBGLAttributes a;
73 g_current->gl->GetAttributes( g_current->gl, &a );
74 return a.stencil_size;
75 }
76 break;
77 case GLUT_WINDOW_DEPTH_SIZE:
78 if (g_current) {
79 DFBGLAttributes a;
80 g_current->gl->GetAttributes( g_current->gl, &a );
81 return a.depth_size;
82 }
83 break;
84 case GLUT_WINDOW_RED_SIZE:
85 if (g_current) {
86 DFBGLAttributes a;
87 g_current->gl->GetAttributes( g_current->gl, &a );
88 return a.red_size;
89 }
90 break;
91 case GLUT_WINDOW_GREEN_SIZE:
92 if (g_current) {
93 DFBGLAttributes a;
94 g_current->gl->GetAttributes( g_current->gl, &a );
95 return a.green_size;
96 }
97 break;
98 case GLUT_WINDOW_BLUE_SIZE:
99 if (g_current) {
100 DFBGLAttributes a;
101 g_current->gl->GetAttributes( g_current->gl, &a );
102 return a.blue_size;
103 }
104 break;
105 case GLUT_WINDOW_ALPHA_SIZE:
106 if (g_current) {
107 DFBGLAttributes a;
108 g_current->gl->GetAttributes( g_current->gl, &a );
109 return a.alpha_size;
110 }
111 break;
112 case GLUT_WINDOW_ACCUM_RED_SIZE:
113 if (g_current) {
114 DFBGLAttributes a;
115 g_current->gl->GetAttributes( g_current->gl, &a );
116 return a.accum_red_size;
117 }
118 break;
119 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
120 if (g_current) {
121 DFBGLAttributes a;
122 g_current->gl->GetAttributes( g_current->gl, &a );
123 return a.accum_green_size;
124 }
125 break;
126 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
127 if (g_current) {
128 DFBGLAttributes a;
129 g_current->gl->GetAttributes( g_current->gl, &a );
130 return a.accum_blue_size;
131 }
132 break;
133 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
134 if (g_current) {
135 DFBGLAttributes a;
136 g_current->gl->GetAttributes( g_current->gl, &a );
137 return a.accum_alpha_size;
138 }
139 break;
140 case GLUT_WINDOW_DOUBLEBUFFER:
141 if (g_current) {
142 DFBGLAttributes a;
143 g_current->gl->GetAttributes( g_current->gl, &a );
144 return a.double_buffer;
145 }
146 break;
147
148 case GLUT_WINDOW_RGBA:
149 return 1;
150
151 case GLUT_WINDOW_CURSOR:
152 if (g_current)
153 return g_current->cursor;
154 break;
155
156 case GLUT_SCREEN_WIDTH:
157 if (primary) {
158 DFBDisplayLayerConfig c;
159 primary->GetConfiguration( primary, &c );
160 return c.width;
161 }
162 break;
163 case GLUT_SCREEN_HEIGHT:
164 if (primary) {
165 DFBDisplayLayerConfig c;
166 primary->GetConfiguration( primary, &c );
167 return c.height;
168 }
169 break;
170
171 case GLUT_INIT_DISPLAY_MODE:
172 return g_display_mode;
173 case GLUT_INIT_WINDOW_X:
174 return g_xpos;
175 case GLUT_INIT_WINDOW_Y:
176 return g_ypos;
177 case GLUT_INIT_WINDOW_WIDTH:
178 return g_width;
179 case GLUT_INIT_WINDOW_HEIGHT:
180 return g_height;
181
182 case GLUT_ELAPSED_TIME:
183 {
184 static long long start = -1;
185 struct timeval t;
186
187 gettimeofday( &t, NULL );
188 if (start == -1) {
189 start = t.tv_sec * 1000ll + t.tv_usec / 1000ll;
190 return 0;
191 }
192 return (t.tv_sec * 1000ll + t.tv_usec / 1000ll - start);
193 }
194 break;
195
196 default:
197 break;
198 }
199
200 return 0;
201 }
202
203
204 int GLUTAPIENTRY
205 glutLayerGet( GLenum type )
206 {
207 return 0;
208 }
209
210 void GLUTAPIENTRY
211 glutReportErrors( void )
212 {
213 GLenum error;
214
215 while ((error = glGetError()) != GL_NO_ERROR)
216 __glutWarning( "**OpenGL Error** %s", gluErrorString( error ) );
217 }
218
219