Added initial multisampling support to glfbdev driver.
[mesa.git] / src / glut / fbdev / state.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 * Copyright (C) 1995-2006 Brian Paul
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * Library for glut using mesa fbdev driver
23 *
24 * Written by Sean D'Epagnier (c) 2006
25 */
26
27 #include <sys/time.h>
28
29 #include <linux/fb.h>
30
31 #include <GL/glut.h>
32
33 #include "../../mesa/main/config.h"
34
35 #include "internal.h"
36
37 int AccumSize = 16; /* per channel size of accumulation buffer */
38 int DepthSize = DEFAULT_SOFTWARE_DEPTH_BITS;
39 int StencilSize = STENCIL_BITS;
40 int NumSamples = 4;
41
42 int glutGet(GLenum state)
43 {
44 switch(state) {
45 case GLUT_WINDOW_X:
46 return 0;
47 case GLUT_WINDOW_Y:
48 return 0;
49 case GLUT_INIT_WINDOW_WIDTH:
50 case GLUT_WINDOW_WIDTH:
51 case GLUT_SCREEN_WIDTH:
52 return VarInfo.xres;
53 case GLUT_INIT_WINDOW_HEIGHT:
54 case GLUT_WINDOW_HEIGHT:
55 case GLUT_SCREEN_HEIGHT:
56 return VarInfo.yres;
57 case GLUT_WINDOW_BUFFER_SIZE:
58 return VarInfo.bits_per_pixel;
59 case GLUT_WINDOW_STENCIL_SIZE:
60 return StencilSize;
61 case GLUT_WINDOW_DEPTH_SIZE:
62 return DepthSize;
63 case GLUT_WINDOW_RED_SIZE:
64 return VarInfo.red.length;
65 case GLUT_WINDOW_GREEN_SIZE:
66 return VarInfo.green.length;
67 case GLUT_WINDOW_BLUE_SIZE:
68 return VarInfo.green.length;
69 case GLUT_WINDOW_ALPHA_SIZE:
70 return VarInfo.transp.length;
71 case GLUT_WINDOW_ACCUM_RED_SIZE:
72 case GLUT_WINDOW_ACCUM_GREEN_SIZE:
73 case GLUT_WINDOW_ACCUM_BLUE_SIZE:
74 case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
75 return AccumSize;
76 case GLUT_WINDOW_DOUBLEBUFFER:
77 if(DisplayMode & GLUT_DOUBLE)
78 return 1;
79 return 0;
80 case GLUT_WINDOW_RGBA:
81 if(DisplayMode & GLUT_INDEX)
82 return 0;
83 return 1;
84 case GLUT_WINDOW_PARENT:
85 return 0;
86 case GLUT_WINDOW_NUM_CHILDREN:
87 return 0;
88 case GLUT_WINDOW_COLORMAP_SIZE:
89 if(DisplayMode & GLUT_INDEX)
90 return 256;
91 return 0;
92 case GLUT_WINDOW_NUM_SAMPLES:
93 return NumSamples;
94 case GLUT_WINDOW_STEREO:
95 return 0;
96 case GLUT_WINDOW_CURSOR:
97 return CurrentCursor;
98 case GLUT_SCREEN_WIDTH_MM:
99 return VarInfo.width;
100 case GLUT_SCREEN_HEIGHT_MM:
101 return VarInfo.height;
102 case GLUT_MENU_NUM_ITEMS:
103 if(CurrentMenu)
104 return Menus[CurrentMenu].NumItems;
105 return 0;
106 case GLUT_DISPLAY_MODE_POSSIBLE:
107 if((DisplayMode & GLUT_MULTISAMPLE)
108 || (DisplayMode & GLUT_STEREO)
109 || (DisplayMode & GLUT_LUMINANCE)
110 || (DisplayMode & GLUT_ALPHA) && (DisplayMode & GLUT_INDEX))
111 return 0;
112 return 1;
113 case GLUT_INIT_DISPLAY_MODE:
114 return DisplayMode;
115 case GLUT_INIT_WINDOW_X:
116 case GLUT_INIT_WINDOW_Y:
117 return 0;
118 case GLUT_ELAPSED_TIME:
119 {
120 static struct timeval tv;
121 gettimeofday(&tv, 0);
122 return 1000 * (tv.tv_sec - StartTime.tv_sec)
123 + (tv.tv_usec - StartTime.tv_usec) / 1000;
124 }
125 }
126 return -1;
127 }
128
129 int glutLayerGet(GLenum info)
130 {
131 switch(info) {
132 case GLUT_OVERLAY_POSSIBLE:
133 return 0;
134 case GLUT_LAYER_IN_USE:
135 return GLUT_NORMAL;
136 case GLUT_HAS_OVERLAY:
137 return 0;
138 case GLUT_TRANSPARENT_INDEX:
139 return -1;
140 case GLUT_NORMAL_DAMAGED:
141 return Redisplay;
142 case GLUT_OVERLAY_DAMAGED:
143 return -1;
144 }
145 return -1;
146 }
147
148 int glutDeviceGet(GLenum info)
149 {
150 switch(info) {
151 case GLUT_HAS_KEYBOARD:
152 return ConsoleFD != -1 ? 1 : 0;
153 case GLUT_HAS_MOUSE:
154 case GLUT_NUM_MOUSE_BUTTONS:
155 return NumMouseButtons;
156 case GLUT_HAS_SPACEBALL:
157 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
158 case GLUT_HAS_TABLET:
159 return 0;
160 case GLUT_NUM_SPACEBALL_BUTTONS:
161 case GLUT_NUM_BUTTON_BOX_BUTTONS:
162 case GLUT_NUM_DIALS:
163 case GLUT_NUM_TABLET_BUTTONS:
164 return 0;
165 case GLUT_DEVICE_IGNORE_KEY_REPEAT:
166 return KeyRepeatMode == GLUT_KEY_REPEAT_OFF;
167 case GLUT_DEVICE_KEY_REPEAT:
168 return KeyRepeatMode;
169 case GLUT_JOYSTICK_POLL_RATE:
170 case GLUT_HAS_JOYSTICK:
171 case GLUT_JOYSTICK_BUTTONS:
172 case GLUT_JOYSTICK_AXES:
173 return 0;
174 }
175 return -1;
176 }
177
178 int glutGetModifiers(void){
179 return KeyboardModifiers;
180 }
181
182 int glutExtensionSupported(const char *extension)
183 {
184 const char *exts = (const char *) glGetString(GL_EXTENSIONS);
185 const char *start = exts;
186 int len = strlen(extension);
187 for(;;) {
188 const char *p = strstr(exts, extension);
189 if(!p)
190 break;
191 if((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0))
192 return 1;
193 exts = p + len;
194 }
195 return 0;
196 }