Merge commit 'origin/gallium-0.1'
[mesa.git] / src / mesa / drivers / dri / swrast / swrast.c
1 /*
2 * Copyright (C) 2008 George Sapountzis <gsap7@yahoo.gr>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * DRI software rasterizer
24 *
25 * This is the mesa swrast module packaged into a DRI driver structure.
26 *
27 * The front-buffer is allocated by the loader. The loader provides read/write
28 * callbacks for access to the front-buffer. The driver uses a scratch row for
29 * front-buffer rendering to avoid repeated calls to the loader.
30 *
31 * The back-buffer is allocated by the driver and is private.
32 */
33
34 #include "main/context.h"
35 #include "main/extensions.h"
36 #include "main/framebuffer.h"
37 #include "main/imports.h"
38 #include "main/renderbuffer.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "tnl/tnl.h"
42 #include "tnl/t_context.h"
43 #include "tnl/t_pipeline.h"
44 #include "vbo/vbo.h"
45 #include "drivers/common/driverfuncs.h"
46 #include "utils.h"
47
48 #include "swrast_priv.h"
49
50
51 #define need_GL_VERSION_1_3
52 #define need_GL_VERSION_1_4
53 #define need_GL_VERSION_1_5
54 #define need_GL_VERSION_2_0
55 #define need_GL_VERSION_2_1
56
57 /* sw extensions for imaging */
58 #define need_GL_EXT_blend_color
59 #define need_GL_EXT_blend_minmax
60 #define need_GL_EXT_convolution
61 #define need_GL_EXT_histogram
62 #define need_GL_SGI_color_table
63
64 /* sw extensions not associated with some GL version */
65 #define need_GL_ARB_shader_objects
66 #define need_GL_ARB_vertex_program
67 #define need_GL_APPLE_vertex_array_object
68 #define need_GL_ATI_fragment_shader
69 #define need_GL_ATI_separate_stencil
70 #define need_GL_EXT_depth_bounds_test
71 #define need_GL_EXT_framebuffer_object
72 #define need_GL_EXT_framebuffer_blit
73 #define need_GL_EXT_gpu_program_parameters
74 #define need_GL_EXT_paletted_texture
75 #define need_GL_EXT_stencil_two_side
76 #define need_GL_MESA_resize_buffers
77 #define need_GL_NV_vertex_program
78 #define need_GL_NV_fragment_program
79
80 #include "extension_helper.h"
81
82 const struct dri_extension card_extensions[] =
83 {
84 { "GL_VERSION_1_3", GL_VERSION_1_3_functions },
85 { "GL_VERSION_1_4", GL_VERSION_1_4_functions },
86 { "GL_VERSION_1_5", GL_VERSION_1_5_functions },
87 { "GL_VERSION_2_0", GL_VERSION_2_0_functions },
88 { "GL_VERSION_2_1", GL_VERSION_2_1_functions },
89
90 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
91 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
92 { "GL_EXT_convolution", GL_EXT_convolution_functions },
93 { "GL_EXT_histogram", GL_EXT_histogram_functions },
94 { "GL_SGI_color_table", GL_SGI_color_table_functions },
95
96 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions },
97 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
98 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions },
99 { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions },
100 { "GL_ATI_separate_stencil", GL_ATI_separate_stencil_functions },
101 { "GL_EXT_depth_bounds_test", GL_EXT_depth_bounds_test_functions },
102 { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions },
103 { "GL_EXT_framebuffer_blit", GL_EXT_framebuffer_blit_functions },
104 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions },
105 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions },
106 { "GL_EXT_stencil_two_side", GL_EXT_stencil_two_side_functions },
107 { "GL_MESA_resize_buffers", GL_MESA_resize_buffers_functions },
108 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
109 { "GL_NV_fragment_program", GL_NV_fragment_program_functions },
110 { NULL, NULL }
111 };
112
113
114 /**
115 * Screen and config-related functions
116 */
117
118 static void
119 setupLoaderExtensions(__DRIscreen *psp,
120 const __DRIextension **extensions)
121 {
122 int i;
123
124 for (i = 0; extensions[i]; i++) {
125 if (strcmp(extensions[i]->name, __DRI_SWRAST_LOADER) == 0)
126 psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i];
127 }
128 }
129
130 static __DRIconfig **
131 swrastFillInModes(__DRIscreen *psp,
132 unsigned pixel_bits, unsigned depth_bits,
133 unsigned stencil_bits, GLboolean have_back_buffer)
134 {
135 __DRIconfig **configs;
136 unsigned depth_buffer_factor;
137 unsigned back_buffer_factor;
138 GLenum fb_format;
139 GLenum fb_type;
140
141 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
142 * support pageflipping at all.
143 */
144 static const GLenum back_buffer_modes[] = {
145 GLX_NONE, GLX_SWAP_UNDEFINED_OML
146 };
147
148 uint8_t depth_bits_array[4];
149 uint8_t stencil_bits_array[4];
150 uint8_t msaa_samples_array[1];
151
152 depth_bits_array[0] = 0;
153 depth_bits_array[1] = 0;
154 depth_bits_array[2] = depth_bits;
155 depth_bits_array[3] = depth_bits;
156
157 /* Just like with the accumulation buffer, always provide some modes
158 * with a stencil buffer.
159 */
160 stencil_bits_array[0] = 0;
161 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
162 stencil_bits_array[2] = 0;
163 stencil_bits_array[3] = (stencil_bits == 0) ? 8 : stencil_bits;
164
165 msaa_samples_array[0] = 0;
166
167 depth_buffer_factor = 4;
168 back_buffer_factor = 2;
169
170 switch (pixel_bits) {
171 case 8:
172 fb_format = GL_RGB;
173 fb_type = GL_UNSIGNED_BYTE_2_3_3_REV;
174 break;
175 case 16:
176 fb_format = GL_RGB;
177 fb_type = GL_UNSIGNED_SHORT_5_6_5;
178 break;
179 case 24:
180 fb_format = GL_BGR;
181 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
182 break;
183 case 32:
184 fb_format = GL_BGRA;
185 fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
186 break;
187 default:
188 fprintf(stderr, "[%s:%u] bad depth %d\n", __func__, __LINE__,
189 pixel_bits);
190 return NULL;
191 }
192
193 configs = driCreateConfigs(fb_format, fb_type,
194 depth_bits_array, stencil_bits_array,
195 depth_buffer_factor, back_buffer_modes,
196 back_buffer_factor, msaa_samples_array, 1);
197 if (configs == NULL) {
198 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
199 __LINE__);
200 return NULL;
201 }
202
203 return configs;
204 }
205
206 static __DRIscreen *
207 driCreateNewScreen(int scrn, const __DRIextension **extensions,
208 const __DRIconfig ***driver_configs, void *data)
209 {
210 static const __DRIextension *emptyExtensionList[] = { NULL };
211 __DRIscreen *psp;
212 __DRIconfig **configs8, **configs16, **configs24, **configs32;
213
214 (void) data;
215
216 TRACE;
217
218 psp = _mesa_calloc(sizeof(*psp));
219 if (!psp)
220 return NULL;
221
222 setupLoaderExtensions(psp, extensions);
223
224 psp->num = scrn;
225 psp->extensions = emptyExtensionList;
226
227 configs8 = swrastFillInModes(psp, 8, 8, 0, 1);
228 configs16 = swrastFillInModes(psp, 16, 16, 0, 1);
229 configs24 = swrastFillInModes(psp, 24, 24, 8, 1);
230 configs32 = swrastFillInModes(psp, 32, 24, 8, 1);
231
232 configs16 = driConcatConfigs(configs8, configs16);
233 configs24 = driConcatConfigs(configs16, configs24);
234 *driver_configs = (const __DRIconfig **)
235 driConcatConfigs(configs24, configs32);
236
237 driInitExtensions( NULL, card_extensions, GL_FALSE );
238
239 return psp;
240 }
241
242 static void driDestroyScreen(__DRIscreen *psp)
243 {
244 TRACE;
245
246 if (psp) {
247 _mesa_free(psp);
248 }
249 }
250
251 static const __DRIextension **driGetExtensions(__DRIscreen *psp)
252 {
253 TRACE;
254
255 return psp->extensions;
256 }
257
258
259 /**
260 * Framebuffer and renderbuffer-related functions.
261 */
262
263 static GLuint
264 choose_pixel_format(const GLvisual *v)
265 {
266 if (v->rgbMode) {
267 int depth = v->rgbBits;
268
269 if (depth == 32
270 && v->redMask == 0xff0000
271 && v->greenMask == 0x00ff00
272 && v->blueMask == 0x0000ff)
273 return PF_A8R8G8B8;
274 else if (depth == 24
275 && v->redMask == 0xff0000
276 && v->greenMask == 0x00ff00
277 && v->blueMask == 0x0000ff)
278 return PF_X8R8G8B8;
279 else if (depth == 16
280 && v->redMask == 0xf800
281 && v->greenMask == 0x07e0
282 && v->blueMask == 0x001f)
283 return PF_R5G6B5;
284 else if (depth == 8
285 && v->redMask == 0x07
286 && v->greenMask == 0x38
287 && v->blueMask == 0xc0)
288 return PF_R3G3B2;
289 }
290 else {
291 if (v->indexBits == 8)
292 return PF_CI8;
293 }
294
295 _mesa_problem( NULL, "unexpected format in %s", __FUNCTION__ );
296 return 0;
297 }
298
299 static void
300 swrast_delete_renderbuffer(struct gl_renderbuffer *rb)
301 {
302 TRACE;
303
304 _mesa_free(rb->Data);
305 _mesa_free(rb);
306 }
307
308 static GLboolean
309 swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
310 GLenum internalFormat, GLuint width, GLuint height)
311 {
312 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
313 unsigned mask = PITCH_ALIGN_BITS - 1;
314
315 TRACE;
316
317 rb->Data = NULL;
318 rb->Width = width;
319 rb->Height = height;
320
321 /* always pad to PITCH_ALIGN_BITS */
322 xrb->pitch = ((width * xrb->bpp + mask) & ~mask) / 8;
323
324 return GL_TRUE;
325 }
326
327 static GLboolean
328 swrast_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
329 GLenum internalFormat, GLuint width, GLuint height)
330 {
331 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
332
333 TRACE;
334
335 _mesa_free(rb->Data);
336
337 swrast_alloc_front_storage(ctx, rb, internalFormat, width, height);
338
339 rb->Data = _mesa_malloc(height * xrb->pitch);
340
341 return GL_TRUE;
342 }
343
344 static struct swrast_renderbuffer *
345 swrast_new_renderbuffer(const GLvisual *visual, GLboolean front)
346 {
347 struct swrast_renderbuffer *xrb = _mesa_calloc(sizeof *xrb);
348 GLuint pixel_format;
349
350 TRACE;
351
352 if (!xrb)
353 return NULL;
354
355 _mesa_init_renderbuffer(&xrb->Base, 0);
356
357 pixel_format = choose_pixel_format(visual);
358
359 xrb->Base.Delete = swrast_delete_renderbuffer;
360 if (front) {
361 xrb->Base.AllocStorage = swrast_alloc_front_storage;
362 swrast_set_span_funcs_front(xrb, pixel_format);
363 }
364 else {
365 xrb->Base.AllocStorage = swrast_alloc_back_storage;
366 swrast_set_span_funcs_back(xrb, pixel_format);
367 }
368
369 switch (pixel_format) {
370 case PF_A8R8G8B8:
371 xrb->Base.InternalFormat = GL_RGBA;
372 xrb->Base._BaseFormat = GL_RGBA;
373 xrb->Base.DataType = GL_UNSIGNED_BYTE;
374 xrb->Base.RedBits = 8 * sizeof(GLubyte);
375 xrb->Base.GreenBits = 8 * sizeof(GLubyte);
376 xrb->Base.BlueBits = 8 * sizeof(GLubyte);
377 xrb->Base.AlphaBits = 8 * sizeof(GLubyte);
378 xrb->bpp = 32;
379 break;
380 case PF_X8R8G8B8:
381 xrb->Base.InternalFormat = GL_RGB;
382 xrb->Base._BaseFormat = GL_RGB;
383 xrb->Base.DataType = GL_UNSIGNED_BYTE;
384 xrb->Base.RedBits = 8 * sizeof(GLubyte);
385 xrb->Base.GreenBits = 8 * sizeof(GLubyte);
386 xrb->Base.BlueBits = 8 * sizeof(GLubyte);
387 xrb->Base.AlphaBits = 0;
388 xrb->bpp = 32;
389 break;
390 case PF_R5G6B5:
391 xrb->Base.InternalFormat = GL_RGB;
392 xrb->Base._BaseFormat = GL_RGB;
393 xrb->Base.DataType = GL_UNSIGNED_BYTE;
394 xrb->Base.RedBits = 5 * sizeof(GLubyte);
395 xrb->Base.GreenBits = 6 * sizeof(GLubyte);
396 xrb->Base.BlueBits = 5 * sizeof(GLubyte);
397 xrb->Base.AlphaBits = 0;
398 xrb->bpp = 16;
399 break;
400 case PF_R3G3B2:
401 xrb->Base.InternalFormat = GL_RGB;
402 xrb->Base._BaseFormat = GL_RGB;
403 xrb->Base.DataType = GL_UNSIGNED_BYTE;
404 xrb->Base.RedBits = 3 * sizeof(GLubyte);
405 xrb->Base.GreenBits = 3 * sizeof(GLubyte);
406 xrb->Base.BlueBits = 2 * sizeof(GLubyte);
407 xrb->Base.AlphaBits = 0;
408 xrb->bpp = 8;
409 break;
410 case PF_CI8:
411 xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT;
412 xrb->Base._BaseFormat = GL_COLOR_INDEX;
413 xrb->Base.DataType = GL_UNSIGNED_BYTE;
414 xrb->Base.IndexBits = 8 * sizeof(GLubyte);
415 xrb->bpp = 8;
416 break;
417 default:
418 return NULL;
419 }
420
421 return xrb;
422 }
423
424 static __DRIdrawable *
425 driCreateNewDrawable(__DRIscreen *screen,
426 const __DRIconfig *config, void *data)
427 {
428 __DRIdrawable *buf;
429 struct swrast_renderbuffer *frontrb, *backrb;
430
431 TRACE;
432
433 buf = _mesa_calloc(sizeof *buf);
434 if (!buf)
435 return NULL;
436
437 buf->loaderPrivate = data;
438
439 buf->driScreenPriv = screen;
440
441 buf->row = _mesa_malloc(MAX_WIDTH * 4);
442
443 /* basic framebuffer setup */
444 _mesa_initialize_framebuffer(&buf->Base, &config->modes);
445
446 /* add front renderbuffer */
447 frontrb = swrast_new_renderbuffer(&config->modes, GL_TRUE);
448 _mesa_add_renderbuffer(&buf->Base, BUFFER_FRONT_LEFT, &frontrb->Base);
449
450 /* add back renderbuffer */
451 if (config->modes.doubleBufferMode) {
452 backrb = swrast_new_renderbuffer(&config->modes, GL_FALSE);
453 _mesa_add_renderbuffer(&buf->Base, BUFFER_BACK_LEFT, &backrb->Base);
454 }
455
456 /* add software renderbuffers */
457 _mesa_add_soft_renderbuffers(&buf->Base,
458 GL_FALSE, /* color */
459 config->modes.haveDepthBuffer,
460 config->modes.haveStencilBuffer,
461 config->modes.haveAccumBuffer,
462 GL_FALSE, /* alpha */
463 GL_FALSE /* aux bufs */);
464
465 return buf;
466 }
467
468 static void
469 driDestroyDrawable(__DRIdrawable *buf)
470 {
471 TRACE;
472
473 if (buf) {
474 struct gl_framebuffer *fb = &buf->Base;
475
476 _mesa_free(buf->row);
477
478 fb->DeletePending = GL_TRUE;
479 _mesa_unreference_framebuffer(&fb);
480 }
481 }
482
483 static void driSwapBuffers(__DRIdrawable *buf)
484 {
485 GET_CURRENT_CONTEXT(ctx);
486
487 struct swrast_renderbuffer *frontrb =
488 swrast_renderbuffer(buf->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
489 struct swrast_renderbuffer *backrb =
490 swrast_renderbuffer(buf->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer);
491
492 __DRIscreen *screen = buf->driScreenPriv;
493
494 TRACE;
495
496 /* check for signle-buffered */
497 if (backrb == NULL)
498 return;
499
500 /* check if swapping currently bound buffer */
501 if (ctx && ctx->DrawBuffer == &(buf->Base)) {
502 /* flush pending rendering */
503 _mesa_notifySwapBuffers(ctx);
504 }
505
506 screen->swrast_loader->putImage(buf, __DRI_SWRAST_IMAGE_OP_SWAP,
507 0, 0,
508 frontrb->Base.Width,
509 frontrb->Base.Height,
510 backrb->Base.Data,
511 buf->loaderPrivate);
512 }
513
514
515 /**
516 * General device driver functions.
517 */
518
519 static void
520 get_window_size( GLframebuffer *fb, GLsizei *w, GLsizei *h )
521 {
522 __DRIdrawable *buf = swrast_drawable(fb);
523 __DRIscreen *screen = buf->driScreenPriv;
524 int x, y;
525
526 screen->swrast_loader->getDrawableInfo(buf,
527 &x, &y, w, h,
528 buf->loaderPrivate);
529 }
530
531 static void
532 swrast_check_and_update_window_size( GLcontext *ctx, GLframebuffer *fb )
533 {
534 GLsizei width, height;
535
536 get_window_size(fb, &width, &height);
537 if (fb->Width != width || fb->Height != height) {
538 _mesa_resize_framebuffer(ctx, fb, width, height);
539 }
540 }
541
542 static const GLubyte *
543 get_string(GLcontext *ctx, GLenum pname)
544 {
545 (void) ctx;
546 switch (pname) {
547 case GL_VENDOR:
548 return (const GLubyte *) "Mesa Project";
549 case GL_RENDERER:
550 return (const GLubyte *) "Software Rasterizer";
551 default:
552 return NULL;
553 }
554 }
555
556 static void
557 update_state( GLcontext *ctx, GLuint new_state )
558 {
559 /* not much to do here - pass it on */
560 _swrast_InvalidateState( ctx, new_state );
561 _swsetup_InvalidateState( ctx, new_state );
562 _vbo_InvalidateState( ctx, new_state );
563 _tnl_InvalidateState( ctx, new_state );
564 }
565
566 static void
567 viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
568 {
569 GLframebuffer *draw = ctx->WinSysDrawBuffer;
570 GLframebuffer *read = ctx->WinSysReadBuffer;
571
572 swrast_check_and_update_window_size(ctx, draw);
573 swrast_check_and_update_window_size(ctx, read);
574 }
575
576 static void
577 swrast_init_driver_functions(struct dd_function_table *driver)
578 {
579 driver->GetString = get_string;
580 driver->UpdateState = update_state;
581 driver->GetBufferSize = NULL;
582 driver->Viewport = viewport;
583 }
584
585
586 /**
587 * Context-related functions.
588 */
589
590 static __DRIcontext *
591 driCreateNewContext(__DRIscreen *screen, const __DRIconfig *config,
592 __DRIcontext *shared, void *data)
593 {
594 __DRIcontext *ctx;
595 GLcontext *mesaCtx;
596 struct dd_function_table functions;
597
598 TRACE;
599
600 ctx = _mesa_calloc(sizeof *ctx);
601 if (!ctx)
602 return NULL;
603
604 ctx->loaderPrivate = data;
605
606 ctx->driScreenPriv = screen;
607
608 /* build table of device driver functions */
609 _mesa_init_driver_functions(&functions);
610 swrast_init_driver_functions(&functions);
611
612 if (!_mesa_initialize_context(&ctx->Base, &config->modes,
613 shared ? &shared->Base : NULL,
614 &functions, (void *) ctx)) {
615 _mesa_free(ctx);
616 return NULL;
617 }
618
619 mesaCtx = &ctx->Base;
620
621 /* do bounds checking to prevent segfaults and server crashes! */
622 mesaCtx->Const.CheckArrayBounds = GL_TRUE;
623
624 /* create module contexts */
625 _swrast_CreateContext( mesaCtx );
626 _vbo_CreateContext( mesaCtx );
627 _tnl_CreateContext( mesaCtx );
628 _swsetup_CreateContext( mesaCtx );
629 _swsetup_Wakeup( mesaCtx );
630
631 /* use default TCL pipeline */
632 {
633 TNLcontext *tnl = TNL_CONTEXT(mesaCtx);
634 tnl->Driver.RunPipeline = _tnl_run_pipeline;
635 }
636
637 _mesa_enable_sw_extensions(mesaCtx);
638 _mesa_enable_1_3_extensions(mesaCtx);
639 _mesa_enable_1_4_extensions(mesaCtx);
640 _mesa_enable_1_5_extensions(mesaCtx);
641 _mesa_enable_2_0_extensions(mesaCtx);
642 _mesa_enable_2_1_extensions(mesaCtx);
643
644 return ctx;
645 }
646
647 static void
648 driDestroyContext(__DRIcontext *ctx)
649 {
650 GLcontext *mesaCtx;
651 TRACE;
652
653 if (ctx) {
654 mesaCtx = &ctx->Base;
655 _swsetup_DestroyContext( mesaCtx );
656 _swrast_DestroyContext( mesaCtx );
657 _tnl_DestroyContext( mesaCtx );
658 _vbo_DestroyContext( mesaCtx );
659 _mesa_destroy_context( mesaCtx );
660 }
661 }
662
663 static int
664 driCopyContext(__DRIcontext *dst, __DRIcontext *src, unsigned long mask)
665 {
666 TRACE;
667
668 _mesa_copy_context(&src->Base, &dst->Base, mask);
669 return GL_TRUE;
670 }
671
672 static int driBindContext(__DRIcontext *ctx,
673 __DRIdrawable *draw,
674 __DRIdrawable *read)
675 {
676 GLcontext *mesaCtx;
677 GLframebuffer *mesaDraw;
678 GLframebuffer *mesaRead;
679 TRACE;
680
681 if (ctx) {
682 if (!draw || !read)
683 return GL_FALSE;
684
685 mesaCtx = &ctx->Base;
686 mesaDraw = &draw->Base;
687 mesaRead = &read->Base;
688
689 /* check for same context and buffer */
690 if (mesaCtx == _mesa_get_current_context()
691 && mesaCtx->DrawBuffer == mesaDraw
692 && mesaCtx->ReadBuffer == mesaRead) {
693 return GL_TRUE;
694 }
695
696 _glapi_check_multithread();
697
698 swrast_check_and_update_window_size(mesaCtx, mesaDraw);
699 if (read != draw)
700 swrast_check_and_update_window_size(mesaCtx, mesaRead);
701
702 _mesa_make_current( mesaCtx,
703 mesaDraw,
704 mesaRead );
705 }
706 else {
707 /* unbind */
708 _mesa_make_current( NULL, NULL, NULL );
709 }
710
711 return GL_TRUE;
712 }
713
714 static int driUnbindContext(__DRIcontext *ctx)
715 {
716 TRACE;
717 (void) ctx;
718 return GL_TRUE;
719 }
720
721
722 static const __DRIcoreExtension driCoreExtension = {
723 { __DRI_CORE, __DRI_CORE_VERSION },
724 NULL, /* driCreateNewScreen */
725 driDestroyScreen,
726 driGetExtensions,
727 driGetConfigAttrib,
728 driIndexConfigAttrib,
729 NULL, /* driCreateNewDrawable */
730 driDestroyDrawable,
731 driSwapBuffers,
732 driCreateNewContext,
733 driCopyContext,
734 driDestroyContext,
735 driBindContext,
736 driUnbindContext
737 };
738
739 static const __DRIswrastExtension driSWRastExtension = {
740 { __DRI_SWRAST, __DRI_SWRAST_VERSION },
741 driCreateNewScreen,
742 driCreateNewDrawable
743 };
744
745 /* This is the table of extensions that the loader will dlsym() for. */
746 PUBLIC const __DRIextension *__driDriverExtensions[] = {
747 &driCoreExtension.base,
748 &driSWRastExtension.base,
749 NULL
750 };