updated patch for vertex program
[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 "20040906"
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_secondary_color",
135 "GL_EXT_stencil_wrap",
136 "GL_EXT_texture_edge_clamp",
137 "GL_EXT_texture_env_combine",
138 "GL_EXT_texture_env_dot3",
139 "GL_EXT_texture_filter_anisotropic",
140 "GL_EXT_texture_lod_bias",
141 "GL_EXT_texture_mirror_clamp",
142 "GL_EXT_texture_rectangle",
143 "GL_ATI_texture_env_combine3",
144 "GL_ATI_texture_mirror_once",
145 "GL_MESA_pack_invert",
146 "GL_MESA_ycbcr_texture",
147 "GL_NV_blend_square",
148 "GL_SGIS_generate_mipmap",
149 NULL
150 };
151
152 extern const struct tnl_pipeline_stage _r200_render_stage;
153 extern const struct tnl_pipeline_stage _r200_tcl_stage;
154
155 static const struct tnl_pipeline_stage *r200_pipeline[] = {
156
157 /* Try and go straight to t&l
158 */
159 &_r200_tcl_stage,
160
161 /* Catch any t&l fallbacks
162 */
163 &_tnl_vertex_transform_stage,
164 &_tnl_normal_transform_stage,
165 &_tnl_lighting_stage,
166 &_tnl_fog_coordinate_stage,
167 &_tnl_texgen_stage,
168 &_tnl_texture_transform_stage,
169 &_tnl_vertex_program_stage,
170
171 /* Try again to go to tcl?
172 * - no good for asymmetric-twoside (do with multipass)
173 * - no good for asymmetric-unfilled (do with multipass)
174 * - good for material
175 * - good for texgen
176 * - need to manipulate a bit of state
177 *
178 * - worth it/not worth it?
179 */
180
181 /* Else do them here.
182 */
183 /* &_r200_render_stage, */ /* FIXME: bugs with ut2003 */
184 &_tnl_render_stage, /* FALLBACK: */
185 0,
186 };
187
188
189
190 /* Initialize the driver's misc functions.
191 */
192 static void r200InitDriverFuncs( struct dd_function_table *functions )
193 {
194 functions->GetBufferSize = r200GetBufferSize;
195 functions->ResizeBuffers = _swrast_alloc_buffers;
196 functions->GetString = r200GetString;
197
198 functions->Error = NULL;
199 functions->DrawPixels = NULL;
200 functions->Bitmap = NULL;
201 }
202
203 static const struct dri_debug_control debug_control[] =
204 {
205 { "fall", DEBUG_FALLBACKS },
206 { "tex", DEBUG_TEXTURE },
207 { "ioctl", DEBUG_IOCTL },
208 { "prim", DEBUG_PRIMS },
209 { "vert", DEBUG_VERTS },
210 { "state", DEBUG_STATE },
211 { "code", DEBUG_CODEGEN },
212 { "vfmt", DEBUG_VFMT },
213 { "vtxf", DEBUG_VFMT },
214 { "verb", DEBUG_VERBOSE },
215 { "dri", DEBUG_DRI },
216 { "dma", DEBUG_DMA },
217 { "san", DEBUG_SANITY },
218 { "sync", DEBUG_SYNC },
219 { "pix", DEBUG_PIXEL },
220 { "mem", DEBUG_MEMORY },
221 { NULL, 0 }
222 };
223
224
225 static int
226 get_ust_nop( int64_t * ust )
227 {
228 *ust = 1;
229 return 0;
230 }
231
232
233 /* Create the device specific rendering context.
234 */
235 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
236 __DRIcontextPrivate *driContextPriv,
237 void *sharedContextPrivate)
238 {
239 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
240 r200ScreenPtr screen = (r200ScreenPtr)(sPriv->private);
241 struct dd_function_table functions;
242 r200ContextPtr rmesa;
243 GLcontext *ctx, *shareCtx;
244 int i;
245 int tcl_mode, fthrottle_mode;
246
247 assert(glVisual);
248 assert(driContextPriv);
249 assert(screen);
250
251 /* Allocate the R200 context */
252 rmesa = (r200ContextPtr) CALLOC( sizeof(*rmesa) );
253 if ( !rmesa )
254 return GL_FALSE;
255
256 /* Parse configuration files.
257 * Do this here so that initialMaxAnisotropy is set before we create
258 * the default textures.
259 */
260 driParseConfigFiles (&rmesa->optionCache, &screen->optionCache,
261 screen->driScreen->myNum, "r200");
262 rmesa->initialMaxAnisotropy = driQueryOptionf(&rmesa->optionCache,
263 "def_max_anisotropy");
264
265 /* Init default driver functions then plug in our R200-specific functions
266 * (the texture functions are especially important)
267 */
268 _mesa_init_driver_functions(&functions);
269 r200InitDriverFuncs(&functions);
270 r200InitIoctlFuncs(&functions);
271 r200InitStateFuncs(&functions);
272 r200InitTextureFuncs(&functions);
273
274 /* Allocate and initialize the Mesa context */
275 if (sharedContextPrivate)
276 shareCtx = ((r200ContextPtr) sharedContextPrivate)->glCtx;
277 else
278 shareCtx = NULL;
279 rmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
280 &functions, (void *) rmesa);
281 if (!rmesa->glCtx) {
282 FREE(rmesa);
283 return GL_FALSE;
284 }
285 driContextPriv->driverPrivate = rmesa;
286
287 /* Init r200 context data */
288 rmesa->dri.context = driContextPriv;
289 rmesa->dri.screen = sPriv;
290 rmesa->dri.drawable = NULL; /* Set by XMesaMakeCurrent */
291 rmesa->dri.hwContext = driContextPriv->hHWContext;
292 rmesa->dri.hwLock = &sPriv->pSAREA->lock;
293 rmesa->dri.fd = sPriv->fd;
294 rmesa->dri.drmMinor = sPriv->drmMinor;
295
296 rmesa->r200Screen = screen;
297 rmesa->sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
298 screen->sarea_priv_offset);
299
300
301 rmesa->dma.buf0_address = rmesa->r200Screen->buffers->list[0].address;
302
303 (void) memset( rmesa->texture_heaps, 0, sizeof( rmesa->texture_heaps ) );
304 make_empty_list( & rmesa->swapped );
305
306 rmesa->nr_heaps = 1 /* screen->numTexHeaps */ ;
307 assert(rmesa->nr_heaps < R200_NR_TEX_HEAPS);
308 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
309 rmesa->texture_heaps[i] = driCreateTextureHeap( i, rmesa,
310 screen->texSize[i],
311 12,
312 RADEON_NR_TEX_REGIONS,
313 (drmTextureRegionPtr)rmesa->sarea->tex_list[i],
314 & rmesa->sarea->tex_age[i],
315 & rmesa->swapped,
316 sizeof( r200TexObj ),
317 (destroy_texture_object_t *) r200DestroyTexObj );
318 }
319 rmesa->texture_depth = driQueryOptioni (&rmesa->optionCache,
320 "texture_depth");
321 if (rmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
322 rmesa->texture_depth = ( screen->cpp == 4 ) ?
323 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
324
325 rmesa->swtcl.RenderIndex = ~0;
326 rmesa->lost_context = 1;
327
328 /* Set the maximum texture size small enough that we can guarentee that
329 * all texture units can bind a maximal texture and have them both in
330 * texturable memory at once.
331 */
332
333 ctx = rmesa->glCtx;
334 ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->optionCache,
335 "texture_units");
336 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
337 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
338
339 driCalculateMaxTextureLevels( rmesa->texture_heaps,
340 rmesa->nr_heaps,
341 & ctx->Const,
342 4,
343 11, /* max 2D texture size is 2048x2048 */
344 #if ENABLE_HW_3D_TEXTURE
345 8, /* max 3D texture size is 256^3 */
346 #else
347 0, /* 3D textures unsupported */
348 #endif
349 11, /* max cube texture size is 2048x2048 */
350 11, /* max texture rectangle size is 2048x2048 */
351 12,
352 GL_FALSE );
353
354 ctx->Const.MaxTextureMaxAnisotropy = 16.0;
355
356 /* No wide points.
357 */
358 ctx->Const.MinPointSize = 1.0;
359 ctx->Const.MinPointSizeAA = 1.0;
360 ctx->Const.MaxPointSize = 1.0;
361 ctx->Const.MaxPointSizeAA = 1.0;
362
363 ctx->Const.MinLineWidth = 1.0;
364 ctx->Const.MinLineWidthAA = 1.0;
365 ctx->Const.MaxLineWidth = 10.0;
366 ctx->Const.MaxLineWidthAA = 10.0;
367 ctx->Const.LineWidthGranularity = 0.0625;
368
369 /* Initialize the software rasterizer and helper modules.
370 */
371 _swrast_CreateContext( ctx );
372 _ac_CreateContext( ctx );
373 _tnl_CreateContext( ctx );
374 _swsetup_CreateContext( ctx );
375 _ae_create_context( ctx );
376
377 /* Install the customized pipeline:
378 */
379 _tnl_destroy_pipeline( ctx );
380 _tnl_install_pipeline( ctx, r200_pipeline );
381 ctx->Driver.FlushVertices = r200FlushVertices;
382
383 /* Try and keep materials and vertices separate:
384 */
385 _tnl_isolate_materials( ctx, GL_TRUE );
386
387
388 /* Configure swrast and TNL to match hardware characteristics:
389 */
390 _swrast_allow_pixel_fog( ctx, GL_FALSE );
391 _swrast_allow_vertex_fog( ctx, GL_TRUE );
392 _tnl_allow_pixel_fog( ctx, GL_FALSE );
393 _tnl_allow_vertex_fog( ctx, GL_TRUE );
394
395
396 for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) {
397 _math_matrix_ctr( &rmesa->TexGenMatrix[i] );
398 _math_matrix_set_identity( &rmesa->TexGenMatrix[i] );
399 }
400 _math_matrix_ctr( &rmesa->tmpmat );
401 _math_matrix_set_identity( &rmesa->tmpmat );
402
403 driInitExtensions( ctx, card_extensions, GL_TRUE );
404 if (rmesa->r200Screen->drmSupportsCubeMaps)
405 _mesa_enable_extension( ctx, "GL_ARB_texture_cube_map" );
406 if (rmesa->r200Screen->drmSupportsBlendColor) {
407 _mesa_enable_extension( ctx, "GL_EXT_blend_equation_separate" );
408 _mesa_enable_extension( ctx, "GL_EXT_blend_func_separate" );
409 }
410 if(driQueryOptionb(&rmesa->optionCache, "arb_vertex_program"))
411 _mesa_enable_extension( ctx, "GL_ARB_vertex_program");
412 if(driQueryOptionb(&rmesa->optionCache, "nv_vertex_program"))
413 _mesa_enable_extension( ctx, "GL_NV_vertex_program");
414
415 #if 0
416 r200InitDriverFuncs( ctx );
417 r200InitIoctlFuncs( ctx );
418 r200InitStateFuncs( ctx );
419 r200InitTextureFuncs( ctx );
420 #endif
421 /* plug in a few more device driver functions */
422 /* XXX these should really go right after _mesa_init_driver_functions() */
423 r200InitPixelFuncs( ctx );
424 r200InitSpanFuncs( ctx );
425 r200InitTnlFuncs( ctx );
426 r200InitState( rmesa );
427 r200InitSwtcl( ctx );
428
429 fthrottle_mode = driQueryOptioni(&rmesa->optionCache, "fthrottle_mode");
430 rmesa->iw.irq_seq = -1;
431 rmesa->irqsEmitted = 0;
432 rmesa->do_irqs = (rmesa->dri.drmMinor >= 6 &&
433 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
434 rmesa->r200Screen->irq);
435
436 rmesa->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
437
438 if (!rmesa->do_irqs)
439 fprintf(stderr,
440 "IRQ's not enabled, falling back to %s: %d %d %d\n",
441 rmesa->do_usleeps ? "usleeps" : "busy waits",
442 rmesa->dri.drmMinor,
443 fthrottle_mode,
444 rmesa->r200Screen->irq);
445
446 rmesa->vblank_flags = (rmesa->r200Screen->irq != 0)
447 ? driGetDefaultVBlankFlags(&rmesa->optionCache) : VBLANK_FLAG_NO_IRQ;
448
449 rmesa->prefer_gart_client_texturing =
450 (getenv("R200_GART_CLIENT_TEXTURES") != 0);
451
452 rmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
453 if ( rmesa->get_ust == NULL ) {
454 rmesa->get_ust = get_ust_nop;
455 }
456 (*rmesa->get_ust)( & rmesa->swap_ust );
457
458
459 #if DO_DEBUG
460 R200_DEBUG = driParseDebugString( getenv( "R200_DEBUG" ),
461 debug_control );
462 R200_DEBUG |= driParseDebugString( getenv( "RADEON_DEBUG" ),
463 debug_control );
464 #endif
465
466 tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
467 if (driQueryOptionb(&rmesa->optionCache, "no_rast")) {
468 fprintf(stderr, "disabling 3D acceleration\n");
469 FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1);
470 }
471 else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") ||
472 !(rmesa->r200Screen->chipset & R200_CHIPSET_TCL)) {
473 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
474 rmesa->r200Screen->chipset &= ~R200_CHIPSET_TCL;
475 fprintf(stderr, "Disabling HW TCL support\n");
476 }
477 TCL_FALLBACK(rmesa->glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
478 }
479 if (rmesa->r200Screen->chipset & R200_CHIPSET_TCL) {
480 if (tcl_mode >= DRI_CONF_TCL_VTXFMT && !getenv("R200_NO_VTXFMT")) {
481 r200VtxfmtInit( ctx, tcl_mode >= DRI_CONF_TCL_CODEGEN );
482 }
483 _tnl_need_dlist_norm_lengths( ctx, GL_FALSE );
484 }
485 return GL_TRUE;
486 }
487
488
489 /* Destroy the device specific context.
490 */
491 /* Destroy the Mesa and driver specific context data.
492 */
493 void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
494 {
495 GET_CURRENT_CONTEXT(ctx);
496 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
497 r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;
498
499 /* check if we're deleting the currently bound context */
500 if (rmesa == current) {
501 R200_FIREVERTICES( rmesa );
502 _mesa_make_current2(NULL, NULL, NULL);
503 }
504
505 /* Free r200 context resources */
506 assert(rmesa); /* should never be null */
507 if ( rmesa ) {
508 GLboolean release_texture_heaps;
509
510
511 release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);
512 _swsetup_DestroyContext( rmesa->glCtx );
513 _tnl_DestroyContext( rmesa->glCtx );
514 _ac_DestroyContext( rmesa->glCtx );
515 _swrast_DestroyContext( rmesa->glCtx );
516
517 r200DestroySwtcl( rmesa->glCtx );
518 r200ReleaseArrays( rmesa->glCtx, ~0 );
519
520 if (rmesa->dma.current.buf) {
521 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
522 r200FlushCmdBuf( rmesa, __FUNCTION__ );
523 }
524
525 if (!(rmesa->TclFallback & R200_TCL_FALLBACK_TCL_DISABLE)) {
526 int tcl_mode = driQueryOptioni(&rmesa->optionCache, "tcl_mode");
527 if (tcl_mode >= DRI_CONF_TCL_VTXFMT)
528 r200VtxfmtDestroy( rmesa->glCtx );
529 }
530
531 /* free the Mesa context */
532 rmesa->glCtx->DriverCtx = NULL;
533 _mesa_destroy_context( rmesa->glCtx );
534
535 if (rmesa->state.scissor.pClipRects) {
536 FREE(rmesa->state.scissor.pClipRects);
537 rmesa->state.scissor.pClipRects = 0;
538 }
539
540 if ( release_texture_heaps ) {
541 /* This share group is about to go away, free our private
542 * texture object data.
543 */
544 int i;
545
546 for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
547 driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
548 rmesa->texture_heaps[ i ] = NULL;
549 }
550
551 assert( is_empty_list( & rmesa->swapped ) );
552 }
553
554 /* free the option cache */
555 driDestroyOptionCache (&rmesa->optionCache);
556
557 FREE( rmesa );
558 }
559 }
560
561
562
563
564 void
565 r200SwapBuffers( __DRIdrawablePrivate *dPriv )
566 {
567 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
568 r200ContextPtr rmesa;
569 GLcontext *ctx;
570 rmesa = (r200ContextPtr) dPriv->driContextPriv->driverPrivate;
571 ctx = rmesa->glCtx;
572 if (ctx->Visual.doubleBufferMode) {
573 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
574 if ( rmesa->doPageFlip ) {
575 r200PageFlip( dPriv );
576 }
577 else {
578 r200CopyBuffer( dPriv );
579 }
580 }
581 }
582 else {
583 /* XXX this shouldn't be an error but we can't handle it for now */
584 _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__);
585 }
586 }
587
588
589 /* Force the context `c' to be the current context and associate with it
590 * buffer `b'.
591 */
592 GLboolean
593 r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
594 __DRIdrawablePrivate *driDrawPriv,
595 __DRIdrawablePrivate *driReadPriv )
596 {
597 if ( driContextPriv ) {
598 r200ContextPtr newCtx =
599 (r200ContextPtr) driContextPriv->driverPrivate;
600
601 if (R200_DEBUG & DEBUG_DRI)
602 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->glCtx);
603
604 if ( newCtx->dri.drawable != driDrawPriv ) {
605 driDrawableInitVBlank( driDrawPriv, newCtx->vblank_flags );
606 newCtx->dri.drawable = driDrawPriv;
607 r200UpdateWindow( newCtx->glCtx );
608 r200UpdateViewportOffset( newCtx->glCtx );
609 }
610
611 _mesa_make_current2( newCtx->glCtx,
612 (GLframebuffer *) driDrawPriv->driverPrivate,
613 (GLframebuffer *) driReadPriv->driverPrivate );
614
615 if ( !newCtx->glCtx->Viewport.Width ) {
616 _mesa_set_viewport( newCtx->glCtx, 0, 0,
617 driDrawPriv->w, driDrawPriv->h );
618 }
619
620 if (newCtx->vb.enabled)
621 r200VtxfmtMakeCurrent( newCtx->glCtx );
622
623 _mesa_update_state( newCtx->glCtx );
624 r200ValidateState( newCtx->glCtx );
625
626 } else {
627 if (R200_DEBUG & DEBUG_DRI)
628 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
629 _mesa_make_current( 0, 0 );
630 }
631
632 if (R200_DEBUG & DEBUG_DRI)
633 fprintf(stderr, "End %s\n", __FUNCTION__);
634 return GL_TRUE;
635 }
636
637 /* Force the context `c' to be unbound from its buffer.
638 */
639 GLboolean
640 r200UnbindContext( __DRIcontextPrivate *driContextPriv )
641 {
642 r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
643
644 if (R200_DEBUG & DEBUG_DRI)
645 fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)rmesa->glCtx);
646
647 r200VtxfmtUnbindContext( rmesa->glCtx );
648 return GL_TRUE;
649 }