DeleteColumn should return success even for uOwnerData.
[wine/gsoc_dplay.git] / graphics / x11drv / opengl.c
blob7b837890c2c11a6dda8dd7a1842bff666c8e9ad9
1 /*
2 * X11DRV OpenGL functions
4 * Copyright 2000 Lionel Ulmer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include "ts_xlib.h"
25 #include <stdlib.h>
26 #include <string.h>
28 #include "wine/debug.h"
29 #include "gdi.h"
30 #include "x11drv.h"
31 #include "wine_gl.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(opengl);
35 #ifdef HAVE_OPENGL
37 static void dump_PIXELFORMATDESCRIPTOR(PIXELFORMATDESCRIPTOR *ppfd) {
38 DPRINTF(" - size / version : %d / %d\n", ppfd->nSize, ppfd->nVersion);
39 DPRINTF(" - dwFlags : ");
40 #define TEST_AND_DUMP(t,tv) if ((t) & (tv)) DPRINTF(#tv " ")
41 TEST_AND_DUMP(ppfd->dwFlags, PFD_DEPTH_DONTCARE);
42 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER);
43 TEST_AND_DUMP(ppfd->dwFlags, PFD_DOUBLEBUFFER_DONTCARE);
44 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_WINDOW);
45 TEST_AND_DUMP(ppfd->dwFlags, PFD_DRAW_TO_BITMAP);
46 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_ACCELERATED);
47 TEST_AND_DUMP(ppfd->dwFlags, PFD_GENERIC_FORMAT);
48 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_PALETTE);
49 TEST_AND_DUMP(ppfd->dwFlags, PFD_NEED_SYSTEM_PALETTE);
50 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO);
51 TEST_AND_DUMP(ppfd->dwFlags, PFD_STEREO_DONTCARE);
52 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_GDI);
53 TEST_AND_DUMP(ppfd->dwFlags, PFD_SUPPORT_OPENGL);
54 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_COPY);
55 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_EXCHANGE);
56 TEST_AND_DUMP(ppfd->dwFlags, PFD_SWAP_LAYER_BUFFERS);
57 #undef TEST_AND_DUMP
58 DPRINTF("\n");
60 DPRINTF(" - iPixelType : ");
61 switch (ppfd->iPixelType) {
62 case PFD_TYPE_RGBA: DPRINTF("PFD_TYPE_RGBA"); break;
63 case PFD_TYPE_COLORINDEX: DPRINTF("PFD_TYPE_COLORINDEX"); break;
65 DPRINTF("\n");
67 DPRINTF(" - Color : %d\n", ppfd->cColorBits);
68 DPRINTF(" - Alpha : %d\n", ppfd->cAlphaBits);
69 DPRINTF(" - Accum : %d\n", ppfd->cAccumBits);
70 DPRINTF(" - Depth : %d\n", ppfd->cDepthBits);
71 DPRINTF(" - Stencil : %d\n", ppfd->cStencilBits);
72 DPRINTF(" - Aux : %d\n", ppfd->cAuxBuffers);
74 DPRINTF(" - iLayerType : ");
75 switch (ppfd->iLayerType) {
76 case PFD_MAIN_PLANE: DPRINTF("PFD_MAIN_PLANE"); break;
77 case PFD_OVERLAY_PLANE: DPRINTF("PFD_OVERLAY_PLANE"); break;
78 case PFD_UNDERLAY_PLANE: DPRINTF("PFD_UNDERLAY_PLANE"); break;
80 DPRINTF("\n");
83 /* X11DRV_ChoosePixelFormat
85 Equivalent of glXChooseVisual
87 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
88 const PIXELFORMATDESCRIPTOR *ppfd) {
89 #define TEST_AND_ADD1(t,a) if (t) att_list[att_pos++] = a
90 #define TEST_AND_ADD2(t,a,b) if (t) { att_list[att_pos++] = a; att_list[att_pos++] = b; }
91 #define NULL_TEST_AND_ADD2(tv,a,b) att_list[att_pos++] = a; att_list[att_pos++] = ((tv) == 0 ? 0 : b)
92 #define ADD2(a,b) att_list[att_pos++] = a; att_list[att_pos++] = b
94 int att_list[64];
95 int att_pos = 0;
96 XVisualInfo *vis;
97 int i;
99 if (TRACE_ON(opengl)) {
100 TRACE("(%p,%p)\n", physDev, ppfd);
102 dump_PIXELFORMATDESCRIPTOR((PIXELFORMATDESCRIPTOR *) ppfd);
105 if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) {
106 ERR("Flag not supported !\n");
107 /* Should SetError here... */
108 return 0;
111 /* Now, build the request to GLX */
112 TEST_AND_ADD1(ppfd->dwFlags & PFD_DOUBLEBUFFER, GLX_DOUBLEBUFFER);
113 TEST_AND_ADD1(ppfd->dwFlags & PFD_STEREO, GLX_STEREO);
114 TEST_AND_ADD1(ppfd->iPixelType == PFD_TYPE_RGBA, GLX_RGBA);
115 TEST_AND_ADD2(ppfd->iPixelType == PFD_TYPE_COLORINDEX, GLX_BUFFER_SIZE, ppfd->cColorBits);
117 NULL_TEST_AND_ADD2(ppfd->cDepthBits, GLX_DEPTH_SIZE, 8);
118 /* These flags are not supported yet...
120 NULL_TEST_AND_ADD2(ppfd->cAlphaBits, GLX_ALPHA_SIZE, 8);
121 ADD2(GLX_ACCUM_SIZE, ppfd->cAccumBits); */
122 ADD2(GLX_STENCIL_SIZE, ppfd->cStencilBits); /* now suported */
123 /* ADD2(GLX_AUX_BUFFERS, ppfd->cAuxBuffers); */
124 att_list[att_pos] = None;
126 ENTER_GL(); {
128 This command cannot be used as we need to use the default visual...
129 Let's hope it at least contains some OpenGL functionnalities
131 vis = glXChooseVisual(gdi_display, DefaultScreen(gdi_display), att_list);
133 int num;
134 XVisualInfo template;
136 template.visualid = XVisualIDFromVisual(visual);
137 vis = XGetVisualInfo(gdi_display, VisualIDMask, &template, &num);
139 TRACE("Found visual : %p - returns %d\n", vis, physDev->used_visuals + 1);
141 LEAVE_GL();
143 if (vis == NULL) {
144 ERR("No visual found !\n");
145 /* Should SetError here... */
146 return 0;
148 /* try to find the visualid in the already created visuals */
149 for( i=0; i<physDev->used_visuals; i++ ) {
150 if ( vis->visualid == physDev->visuals[i]->visualid ) {
151 XFree(vis);
152 return i+1;
155 /* now give up, if the maximum is reached */
156 if (physDev->used_visuals == MAX_PIXELFORMATS) {
157 ERR("Maximum number of visuals reached !\n");
158 /* Should SetError here... */
159 return 0;
161 physDev->visuals[physDev->used_visuals++] = vis;
163 return physDev->used_visuals;
166 /* X11DRV_DescribePixelFormat
168 Get the pixel-format descriptor associated to the given id
170 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
171 int iPixelFormat,
172 UINT nBytes,
173 PIXELFORMATDESCRIPTOR *ppfd) {
174 XVisualInfo *vis;
175 int value;
176 int rb,gb,bb,ab;
178 TRACE("(%p,%d,%d,%p)\n", physDev, iPixelFormat, nBytes, ppfd);
180 if (ppfd == NULL) {
181 /* The application is only querying the number of visuals */
182 return MAX_PIXELFORMATS;
185 if (nBytes < sizeof(PIXELFORMATDESCRIPTOR)) {
186 ERR("Wrong structure size !\n");
187 /* Should set error */
188 return 0;
190 if ((iPixelFormat > MAX_PIXELFORMATS) ||
191 (iPixelFormat > physDev->used_visuals + 1) ||
192 (iPixelFormat <= 0)) {
193 ERR("Wrong pixel format !\n");
194 /* Should set error */
195 return 0;
198 if (iPixelFormat == physDev->used_visuals + 1) {
199 int dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
201 /* Create a 'standard' X Visual */
202 ENTER_GL();
203 vis = glXChooseVisual(gdi_display, DefaultScreen(gdi_display), dblBuf);
204 LEAVE_GL();
206 WARN("Uninitialized Visual. Creating standard (%p) !\n", vis);
208 if (vis == NULL) {
209 ERR("Could not create standard visual !\n");
210 /* Should set error */
211 return 0;
214 physDev->visuals[physDev->used_visuals++] = vis;
216 vis = physDev->visuals[iPixelFormat - 1];
218 memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
219 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
220 ppfd->nVersion = 1;
222 /* These flags are always the same... */
223 ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_GENERIC_ACCELERATED;
224 /* Now the flags extraced from the Visual */
225 ENTER_GL();
226 glXGetConfig(gdi_display, vis, GLX_DOUBLEBUFFER, &value); if (value) ppfd->dwFlags |= PFD_DOUBLEBUFFER;
227 glXGetConfig(gdi_display, vis, GLX_STEREO, &value); if (value) ppfd->dwFlags |= PFD_STEREO;
229 /* Pixel type */
230 glXGetConfig(gdi_display, vis, GLX_RGBA, &value);
231 if (value)
232 ppfd->iPixelType = PFD_TYPE_RGBA;
233 else
234 ppfd->iPixelType = PFD_TYPE_COLORINDEX;
236 /* Color bits */
237 glXGetConfig(gdi_display, vis, GLX_BUFFER_SIZE, &value);
238 ppfd->cColorBits = value;
240 /* Red, green, blue and alpha bits / shifts */
241 if (ppfd->iPixelType == PFD_TYPE_RGBA) {
242 glXGetConfig(gdi_display, vis, GLX_RED_SIZE, &rb);
243 glXGetConfig(gdi_display, vis, GLX_GREEN_SIZE, &gb);
244 glXGetConfig(gdi_display, vis, GLX_BLUE_SIZE, &bb);
245 glXGetConfig(gdi_display, vis, GLX_ALPHA_SIZE, &ab);
247 ppfd->cRedBits = rb;
248 ppfd->cRedShift = gb + bb + ab;
249 ppfd->cBlueBits = bb;
250 ppfd->cBlueShift = ab;
251 ppfd->cGreenBits = gb;
252 ppfd->cGreenShift = bb + ab;
253 ppfd->cAlphaBits = ab;
254 ppfd->cAlphaShift = 0;
255 } else {
256 ppfd->cRedBits = 0;
257 ppfd->cRedShift = 0;
258 ppfd->cBlueBits = 0;
259 ppfd->cBlueShift = 0;
260 ppfd->cGreenBits = 0;
261 ppfd->cGreenShift = 0;
262 ppfd->cAlphaBits = 0;
263 ppfd->cAlphaShift = 0;
265 /* Accums : to do ... */
267 /* Depth bits */
268 glXGetConfig(gdi_display, vis, GLX_DEPTH_SIZE, &value);
269 ppfd->cDepthBits = value;
271 /* stencil bits */
272 glXGetConfig( gdi_display, vis, GLX_STENCIL_SIZE, &value );
273 ppfd->cStencilBits = value;
275 LEAVE_GL();
277 /* Aux : to do ... */
279 ppfd->iLayerType = PFD_MAIN_PLANE;
281 if (TRACE_ON(opengl)) {
282 dump_PIXELFORMATDESCRIPTOR(ppfd);
285 return MAX_PIXELFORMATS;
288 /* X11DRV_GetPixelFormat
290 Get the pixel-format id used by this DC
292 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
293 TRACE("(%p): returns %d\n", physDev, physDev->current_pf);
295 return physDev->current_pf;
298 /* X11DRV_SetPixelFormat
300 Set the pixel-format id used by this DC
302 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
303 int iPixelFormat,
304 const PIXELFORMATDESCRIPTOR *ppfd) {
305 TRACE("(%p,%d,%p)\n", physDev, iPixelFormat, ppfd);
307 physDev->current_pf = iPixelFormat;
309 return TRUE;
312 /* X11DRV_SwapBuffers
314 Swap the buffers of this DC
316 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
317 TRACE("(%p)\n", physDev);
319 ENTER_GL();
320 glXSwapBuffers(gdi_display, physDev->drawable);
321 LEAVE_GL();
323 return TRUE;
326 #else /* defined(HAVE_OPENGL) */
328 int X11DRV_ChoosePixelFormat(X11DRV_PDEVICE *physDev,
329 const PIXELFORMATDESCRIPTOR *ppfd) {
330 ERR("No OpenGL support compiled in.\n");
332 return 0;
335 int X11DRV_DescribePixelFormat(X11DRV_PDEVICE *physDev,
336 int iPixelFormat,
337 UINT nBytes,
338 PIXELFORMATDESCRIPTOR *ppfd) {
339 ERR("No OpenGL support compiled in.\n");
341 return 0;
344 int X11DRV_GetPixelFormat(X11DRV_PDEVICE *physDev) {
345 ERR("No OpenGL support compiled in.\n");
347 return 0;
350 BOOL X11DRV_SetPixelFormat(X11DRV_PDEVICE *physDev,
351 int iPixelFormat,
352 const PIXELFORMATDESCRIPTOR *ppfd) {
353 ERR("No OpenGL support compiled in.\n");
355 return FALSE;
358 BOOL X11DRV_SwapBuffers(X11DRV_PDEVICE *physDev) {
359 ERR("No OpenGL support compiled in.\n");
361 return FALSE;
364 #endif /* defined(HAVE_OPENGL) */