d5d2ce150a513b1ec68db8b65a55a5a54be5718b
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_context.c,v 1.3 2003/05/06 23:52:08 daenzer Exp $ */
2 /*
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "api_arrayelt.h"
38 #include "context.h"
39 #include "simple_list.h"
40 #include "imports.h"
41 #include "matrix.h"
42 #include "extensions.h"
43 #include "state.h"
44
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
47 #include "array_cache/acache.h"
48
49 #include "tnl/tnl.h"
50 #include "tnl/t_pipeline.h"
51
52 #include "drivers/common/driverfuncs.h"
53
54 #include "r200_context.h"
55 #include "r200_ioctl.h"
56 #include "r200_state.h"
57 #include "r200_span.h"
58 #include "r200_pixel.h"
59 #include "r200_tex.h"
60 #include "r200_swtcl.h"
61 #include "r200_tcl.h"
62 #include "r200_vtxfmt.h"
63 #include "r200_maos.h"
64
65 #define DRIVER_DATE "20041007"
66
67 #include "vblank.h"
68 #include "utils.h"
69 #include "xmlpool.h" /* for symbolic values of enum-type options */
70 #ifndef R200_DEBUG
71 int R200_DEBUG = (0);
72 #endif
73
74
75 /* Return the width and height of the given buffer.
76 */
77 static void r200GetBufferSize( GLframebuffer *buffer,
78 GLuint *width, GLuint *height )
79 {
80 GET_CURRENT_CONTEXT(ctx);
81 r200ContextPtr rmesa = R200_CONTEXT(ctx);
82
83 LOCK_HARDWARE( rmesa );
84 *width = rmesa->dri.drawable->w;
85 *height = rmesa->dri.drawable->h;
86 UNLOCK_HARDWARE( rmesa );
87 }
88
89 /* Return various strings for glGetString().
90 */
91 static const GLubyte *r200GetString( GLcontext *ctx, GLenum name )
92 {
93 r200ContextPtr rmesa = R200_CONTEXT(ctx);
94 static char buffer[128];
95 unsigned offset;
96 GLuint agp_mode = rmesa->r200Screen->IsPCI ? 0 :
97 rmesa->r200Screen->AGPMode;
98
99 switch ( name ) {
100 case GL_VENDOR:
101 return (GLubyte *)"Tungsten Graphics, Inc.";
102
103 case GL_RENDERER:
104 offset = driGetRendererString( buffer, "R200", DRIVER_DATE,
105 agp_mode );
106
107 sprintf( & buffer[ offset ], " %sTCL",
108 !(rmesa->TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)
109 ? "" : "NO-" );
110
111 return (GLubyte *)buffer;
112
113 default:
114 return NULL;
115 }
116 }
117
118
119 /* Extension strings exported by the R200 driver.
120 */
121 static const char * const card_extensions[] =
122 {
123 "GL_ARB_multisample",
124 "GL_ARB_multitexture",
125 "GL_ARB_texture_border_clamp",
126 "GL_ARB_texture_compression",
127 "GL_ARB_texture_env_add",
128 "GL_ARB_texture_env_combine",
129 "GL_ARB_texture_env_dot3",
130 "GL_ARB_texture_mirrored_repeat",
131 "GL_ARB_vertex_buffer_object",
132 "GL_EXT_blend_minmax",
133 "GL_EXT_blend_subtract",
134 "GL_EXT_fog_coord",
135 "GL_EXT_secondary_color",
136 "GL_EXT_stencil_wrap",
137 "GL_EXT_texture_edge_clamp",
138 "GL_EXT_texture_env_combine",
139 "GL_EXT_texture_env_dot3",
140 "GL_EXT_texture_filter_anisotropic",
141 "GL_EXT_texture_lod_bias",
142 "GL_EXT_texture_mirror_clamp",
143 "GL_EXT_texture_rectangle",
144 "GL_ATI_texture_env_combine3",
145 "GL_ATI_texture_mirror_once",
146 "GL_MESA_pack_invert",
147 "GL_MESA_ycbcr_texture",
148 "GL_NV_blend_square",
149 "GL_SGIS_generate_mipmap",
150 NULL
151 };
152
153 extern const struct tnl_pipeline_stage _r200_render_stage;
154 extern const struct tnl_pipeline_stage _r200_tcl_stage;
155
156 static const struct tnl_pipeline_stage *r200_pipeline[] = {
157
158 /* Try and go straight to t&l
159 */
160 &_r200_tcl_stage,
161
162 /* Catch any t&l fallbacks
163 */
164 &_tnl_vertex_transform_stage,
165 &_tnl_normal_transform_stage,
166 &_tnl_lighting_stage,
167 &_tnl_fog_coordinate_stage,
168 &_tnl_texgen_stage,
169 &_tnl_texture_transform_stage,
170 &_tnl_vertex_program_stage,
171
172 /* Try again to go to tcl?
173 * - no good for asymmetric-twoside (do with multipass)
174 * - no good for asymmetric-unfilled (do with multipass)
175 * - good for material
176 * - good for texgen
177 * - need to manipulate a bit of state
178 *
179 * - worth it/not worth it?
180 */
181
182 /* Else do them here.
183 */
184 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
185 &_tnl_render_stage, /* FALLBACK: */
186 0,
187 };
188
189
190
191 /* Initialize the driver's misc functions.
192 */
193 static void r200InitDriverFuncs( struct dd_function_table *functions )
194 {
195 functions->GetBufferSize = r200GetBufferSize;
196 functions->ResizeBuffers = _swrast_alloc_buffers;
197 functions->GetString = r200GetString;
198
199 functions->Error = NULL;
200 functions->DrawPixels = NULL;
201 functions->Bitmap = NULL;
202 }
203
204 static const struct dri_debug_control debug_control[] =
205 {
206 { "fall", DEBUG_FALLBACKS },
207 { "tex", DEBUG_TEXTURE },
208 { "ioctl", DEBUG_IOCTL },
209 { "prim", DEBUG_PRIMS },
210 { "vert", DEBUG_VERTS },
211 { "state", DEBUG_STATE },
212 { "code", DEBUG_CODEGEN },
213 { "vfmt", DEBUG_VFMT },
214 { "vtxf", DEBUG_VFMT },
215 { "verb", DEBUG_VERBOSE },
216 { "dri", DEBUG_DRI },
217 { "dma", DEBUG_DMA },
218 { "san", DEBUG_SANITY },
219 { "sync", DEBUG_SYNC },
220 { "pix", DEBUG_PIXEL },
221 { "mem", DEBUG_MEMORY },
222 { NULL, 0 }
223 };
224
225
226 static int
227 get_ust_nop( int64_t * ust )
228 {
229 *ust = 1;
230 return 0;
231 }
232
233
234 /* Create the device specific rendering context.
235 */
236 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
237 __DRIcontextPrivate *driContextPriv,
238 void *sharedContextPrivate)
239 {
240 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
241 r200ScreenPtr screen = (r200ScreenPtr)(sPriv->private);
242 struct dd_function_table functions;
243 r200ContextPtr rmesa;
244 GLcontext *ctx, *shareCtx;
245 int i;
246 int tcl_mode, fthrottle_mode;
247
248 assert(glVisual);
249 assert(driContextPriv);
250 assert(screen);
251
252 /* Allocate the R200 context */
253 rmesa = (r200ContextPtr) CALLOC( sizeof(*rmesa) );
254 if ( !rmesa )
255 return GL_FALSE;
256
257 /* init exp fog table data */
258 r200InitStaticFogData();
259
260 /* Parse configuration files.
261 * Do this here so that initialMaxAnisotropy is set before we create
262 * the default textures.
263 */
264 driParseConfigFiles (&rmesa->optionCache, &screen->optionCache,
265 screen->driScreen->myNum, "r200");
266 rmesa->initialMaxAnisotropy = driQueryOptionf(&rmesa->optionCache,
267 "def_max_anisotropy");
268
269 /* Init default driver functions then plug in our R200-specific functions
270 * (the texture functions are especially important)
271 */
272 _mesa_init_driver_functions(&functions);
273 r200InitDriverFuncs(&functions);
274 r200InitIoctlFuncs(&functions);
275 r200InitStateFuncs(&functions);
276 r200InitTextureFuncs(&functions);
277
278 /* Allocate and initialize the Mesa context */
279 if (sharedContextPrivate)
280 shareCtx = ((r200ContextPtr) sharedContextPrivate)->glCtx;
281 else
282 shareCtx = NULL;
283 rmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
284 &functions, (void *) rmesa);
285 if (!rmesa->glCtx) {
286 FREE(rmesa);
287 return GL_FALSE;
288 }
289 driContextPriv->driverPrivate = rmesa;
290
291 /* Init r200 context data */
292 rmesa->dri.context = driContextPriv;
293 rmesa->dri.screen = sPriv;
294 rmesa->dri.drawable = NULL; /* Set by XMesaMakeCurrent */
295 rmesa->dri.hwContext = driContextPriv->hHWContext;
296 rmesa->dri.hwLock = &sPriv->pSAREA->lock;
297 rmesa->dri.fd = sPriv->fd;
298 rmesa->dri.drmMinor = sPriv->drmMinor;
299
300 rmesa->r200Screen = screen;
301 rmesa->sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
302 screen->sarea_priv_offset);
303
304
305 rmesa->dma.buf0_address = rmesa->r200Screen->buffers->list[0].address;
306
307 (void) memset( rmesa->texture_heaps, 0, sizeof( rmesa->texture_heaps ) );
308 make_empty_list( & rmesa->swapped );
309
310 rmesa->nr_heaps = 1 /* screen->numTexHeaps */ ;
311 assert(rmesa->nr_heaps < R200_NR_TEX_HEAPS);
312 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
313 rmesa->texture_heaps[i] = driCreateTextureHeap( i, rmesa,
314 screen->texSize[i],
315 12,
316 RADEON_NR_TEX_REGIONS,
317 (drmTextureRegionPtr)rmesa->sarea->tex_list[i],
318 & rmesa->sarea->tex_age[i],
319 & rmesa->swapped,
320 sizeof( r200TexObj ),
321 (destroy_texture_object_t *) r200DestroyTexObj );
322 }
323 rmesa->texture_depth = driQueryOptioni (&rmesa->optionCache,
324 "texture_depth");
325 if (rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
326 rmesa->texture_depth = ( screen->cpp == 4 ) ?
327 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
328
329 rmesa->swtcl.RenderIndex = ~0;
330 rmesa->hw.all_dirty = 1;
331
332 /* Set the maximum texture size small enough that we can guarentee that
333 * all texture units can bind a maximal texture and have them both in
334 * texturable memory at once.
335 */
336
337 ctx = rmesa->glCtx;
338 ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->optionCache,
339 "texture_units");
340 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
341 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
342
343 driCalculateMaxTextureLevels( rmesa->texture_heaps,
344 rmesa->nr_heaps,
345 & ctx->Const,
346 4,
347 11, /* max 2D texture size is 2048x2048 */
348 #if ENABLE_HW_3D_TEXTURE
349 8, /* max 3D texture size is 256^3 */
350 #else
351 0, /* 3D textures unsupported */
352 #endif
353 11, /* max cube texture size is 2048x2048 */
354 11, /* max texture rectangle size is 2048x2048 */
355 12,
356 GL_FALSE );
357
358 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
359
360 /* No wide points.
361 */
362 ctx->Const.MinPointSize = 1.0;
363 ctx->Const.MinPointSizeAA = 1.0;
364 ctx->Const.MaxPointSize = 1.0;
365 ctx->Const.MaxPointSizeAA = 1.0;
366
367 ctx->Const.MinLineWidth = 1.0;
368 ctx->Const.MinLineWidthAA = 1.0;
369 ctx->Const.MaxLineWidth = 10.0;
370 ctx->Const.MaxLineWidthAA = 10.0;
371 ctx->Const.LineWidthGranularity = 0.0625;
372
373 /* Initialize the software rasterizer and helper modules.
374 */
375 _swrast_CreateContext( ctx );
376 _ac_CreateContext( ctx );
377 _tnl_CreateContext( ctx );
378 _swsetup_CreateContext( ctx );
379 _ae_create_context( ctx );
380
381 /* Install the customized pipeline:
382 */
383 _tnl_destroy_pipeline( ctx );
384 _tnl_install_pipeline( ctx, r200_pipeline );
385 ctx->Driver.FlushVertices = r200FlushVertices;
386
387 /* Try and keep materials and vertices separate:
388 */
389 _tnl_isolate_materials( ctx, GL_TRUE );
390
391
392 /* Configure swrast and TNL to match hardware characteristics:
393 */
394 _swrast_allow_pixel_fog( ctx, GL_FALSE );
395 _swrast_allow_vertex_fog( ctx, GL_TRUE );
396 _tnl_allow_pixel_fog( ctx, GL_FALSE );
397 _tnl_allow_vertex_fog( ctx, GL_TRUE );
398
399
400 for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) {
401 _math_matrix_ctr( &rmesa->TexGenMatrix[i] );
402 _math_matrix_set_identity( &rmesa->TexGenMatrix[i] );
403 }
404 _math_matrix_ctr( &rmesa->tmpmat );
405 _math_matrix_set_identity( &rmesa->tmpmat );
406
407 driInitExtensions( ctx, card_extensions, GL_TRUE );
408 if (rmesa->glCtx->Mesa_DXTn) {
409 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
410 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
411 }
412 else if (driQueryOptionb (&rmesa->optionCache, "force_s3tc_enable")) {
413 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
414 }
415
416 if (rmesa->r200Screen->drmSupportsCubeMaps)
417 _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" );
418 if (rmesa->r200Screen->drmSupportsBlendColor) {
419 _mesa_enable_extension( ctx, "GL_EXT_blend_equation_separate" );
420 _mesa_enable_extension( ctx, "GL_EXT_blend_func_separate" );
421 }
422 if(driQueryOptionb(&rmesa->optionCache, "arb_vertex_program"))
423 _mesa_enable_extension( ctx, "GL_ARB_vertex_program");
424 if(driQueryOptionb(&rmesa->optionCache, "nv_vertex_program"))
425 _mesa_enable_extension( ctx, "GL_NV_vertex_program");
426
427 #if 0
428 r200InitDriverFuncs( ctx );
429 r200InitIoctlFuncs( ctx );
430 r200InitStateFuncs( ctx );
431 r200InitTextureFuncs( ctx );
432 #endif
433 /* plug in a few more device driver functions */
434 /* XXX these should really go right after _mesa_init_driver_functions() */
435 r200InitPixelFuncs( ctx );
436 r200InitSpanFuncs( ctx );
437 r200InitTnlFuncs( ctx );
438 r200InitState( rmesa );
439 r200InitSwtcl( ctx );
440
441 fthrottle_mode = driQueryOptioni(&rmesa->optionCache, "fthrottle_mode");
442 rmesa->iw.irq_seq = -1;
443 rmesa->irqsEmitted = 0;
444 rmesa->do_irqs = (rmesa->dri.drmMinor >= 6 &&
445 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
446 rmesa->r200Screen->irq);
447
448 rmesa->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
449
450 if (!rmesa->do_irqs)
451 fprintf(stderr,
452 "IRQ's not enabled, falling back to %s: %d %d %d\n",
453 rmesa->do_usleeps ? "usleeps" : "busy waits",
454 rmesa->dri.drmMinor,
455 fthrottle_mode,
456 rmesa->r200Screen->irq);
457
458 rmesa->vblank_flags = (rmesa->r200Screen->irq != 0)
459 ? driGetDefaultVBlankFlags(&rmesa->optionCache) : VBLANK_FLAG_NO_IRQ;
460
461 rmesa->prefer_gart_client_texturing =
462 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
463
464 rmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
465 if ( rmesa->get_ust == NULL ) {
466 rmesa->get_ust = get_ust_nop;
467 }
468 (*rmesa->get_ust)( & rmesa->swap_ust );
469
470
471 #if DO_DEBUG
472 R200_DEBUG = driParseDebugString( getenv( "R200_DEBUG" ),
473 debug_control );
474 R200_DEBUG |= driParseDebugString( getenv( "RADEON_DEBUG" ),
475 debug_control );
476 #endif
477
478 tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
479 if (driQueryOptionb(&rmesa->optionCache, "no_rast")) {
480 fprintf(stderr, "disabling 3D acceleration\n");
481 FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1);
482 }
483 else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") ||
484 !(rmesa->r200Screen->chipset & R200_CHIPSET_TCL)) {
485 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
486 rmesa->r200Screen->chipset &= ~R200_CHIPSET_TCL;
487 fprintf(stderr, "Disabling HW TCL support\n");
488 }
489 TCL_FALLBACK(rmesa->glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
490 }
491 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
492 if (tcl_mode >= DRI_CONF_TCL_VTXFMT && !getenv("R200_NO_VTXFMT")) {
493 r200VtxfmtInit( ctx, tcl_mode >= DRI_CONF_TCL_CODEGEN );
494 }
495 _tnl_need_dlist_norm_lengths( ctx, GL_FALSE );
496 }
497 return GL_TRUE;
498 }
499
500
501 /* Destroy the device specific context.
502 */
503 /* Destroy the Mesa and driver specific context data.
504 */
505 void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
506 {
507 GET_CURRENT_CONTEXT(ctx);
508 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
509 r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;
510
511 /* check if we're deleting the currently bound context */
512 if (rmesa == current) {
513 R200_FIREVERTICES( rmesa );
514 _mesa_make_current2(NULL, NULL, NULL);
515 }
516
517 /* Free r200 context resources */
518 assert(rmesa); /* should never be null */
519 if ( rmesa ) {
520 GLboolean release_texture_heaps;
521
522
523 release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);
524 _swsetup_DestroyContext( rmesa->glCtx );
525 _tnl_DestroyContext( rmesa->glCtx );
526 _ac_DestroyContext( rmesa->glCtx );
527 _swrast_DestroyContext( rmesa->glCtx );
528
529 r200DestroySwtcl( rmesa->glCtx );
530 r200ReleaseArrays( rmesa->glCtx, ~0 );
531
532 if (rmesa->dma.current.buf) {
533 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
534 r200FlushCmdBuf( rmesa, __FUNCTION__ );
535 }
536
537 if (!(rmesa->TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)) {
538 int tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
539 if (tcl_mode >= DRI_CONF_TCL_VTXFMT)
540 r200VtxfmtDestroy( rmesa->glCtx );
541 }
542
543 /* free the Mesa context */
544 rmesa->glCtx->DriverCtx = NULL;
545 _mesa_destroy_context( rmesa->glCtx );
546
547 if (rmesa->state.scissor.pClipRects) {
548 FREE(rmesa->state.scissor.pClipRects);
549 rmesa->state.scissor.pClipRects = 0;
550 }
551
552 if ( release_texture_heaps ) {
553 /* This share group is about to go away, free our private
554 * texture object data.
555 */
556 int i;
557
558 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
559 driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
560 rmesa->texture_heaps[ i ] = NULL;
561 }
562
563 assert( is_empty_list( & rmesa->swapped ) );
564 }
565
566 /* free the option cache */
567 driDestroyOptionCache (&rmesa->optionCache);
568
569 FREE( rmesa );
570 }
571 }
572
573
574
575
576 void
577 r200SwapBuffers( __DRIdrawablePrivate *dPriv )
578 {
579 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
580 r200ContextPtr rmesa;
581 GLcontext *ctx;
582 rmesa = (r200ContextPtr) dPriv->driContextPriv->driverPrivate;
583 ctx = rmesa->glCtx;
584 if (ctx->Visual.doubleBufferMode) {
585 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
586 if ( rmesa->doPageFlip ) {
587 r200PageFlip( dPriv );
588 }
589 else {
590 r200CopyBuffer( dPriv );
591 }
592 }
593 }
594 else {
595 /* XXX this shouldn't be an error but we can't handle it for now */
596 _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__);
597 }
598 }
599
600
601 /* Force the context `c' to be the current context and associate with it
602 * buffer `b'.
603 */
604 GLboolean
605 r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
606 __DRIdrawablePrivate *driDrawPriv,
607 __DRIdrawablePrivate *driReadPriv )
608 {
609 if ( driContextPriv ) {
610 r200ContextPtr newCtx =
611 (r200ContextPtr) driContextPriv->driverPrivate;
612
613 if (R200_DEBUG & DEBUG_DRI)
614 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->glCtx);
615
616 if ( newCtx->dri.drawable != driDrawPriv ) {
617 driDrawableInitVBlank( driDrawPriv, newCtx->vblank_flags );
618 newCtx->dri.drawable = driDrawPriv;
619 r200UpdateWindow( newCtx->glCtx );
620 r200UpdateViewportOffset( newCtx->glCtx );
621 }
622
623 _mesa_make_current2( newCtx->glCtx,
624 (GLframebuffer *) driDrawPriv->driverPrivate,
625 (GLframebuffer *) driReadPriv->driverPrivate );
626
627 if ( !newCtx->glCtx->Viewport.Width ) {
628 _mesa_set_viewport( newCtx->glCtx, 0, 0,
629 driDrawPriv->w, driDrawPriv->h );
630 }
631
632 if (newCtx->vb.enabled)
633 r200VtxfmtMakeCurrent( newCtx->glCtx );
634
635 _mesa_update_state( newCtx->glCtx );
636 r200ValidateState( newCtx->glCtx );
637
638 } else {
639 if (R200_DEBUG & DEBUG_DRI)
640 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
641 _mesa_make_current( 0, 0 );
642 }
643
644 if (R200_DEBUG & DEBUG_DRI)
645 fprintf(stderr, "End %s\n", __FUNCTION__);
646 return GL_TRUE;
647 }
648
649 /* Force the context `c' to be unbound from its buffer.
650 */
651 GLboolean
652 r200UnbindContext( __DRIcontextPrivate *driContextPriv )
653 {
654 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
655
656 if (R200_DEBUG & DEBUG_DRI)
657 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)rmesa->glCtx);
658
659 r200VtxfmtUnbindContext( rmesa->glCtx );
660 return GL_TRUE;
661 }