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