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