fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / i915 / intel_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "glheader.h"
30 #include "context.h"
31 #include "matrix.h"
32 #include "simple_list.h"
33 #include "extensions.h"
34 #include "framebuffer.h"
35 #include "imports.h"
36
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
39 #include "tnl/tnl.h"
40 #include "array_cache/acache.h"
41
42 #include "tnl/t_pipeline.h"
43 #include "tnl/t_vertex.h"
44
45 #include "drivers/common/driverfuncs.h"
46
47 #include "intel_screen.h"
48
49 #include "i830_dri.h"
50 #include "i830_common.h"
51
52 #include "intel_tex.h"
53 #include "intel_span.h"
54 #include "intel_tris.h"
55 #include "intel_ioctl.h"
56 #include "intel_batchbuffer.h"
57
58 #include "utils.h"
59 #ifndef INTEL_DEBUG
60 int INTEL_DEBUG = (0);
61 #endif
62
63 #define need_GL_ARB_multisample
64 #define need_GL_ARB_point_parameters
65 #define need_GL_ARB_texture_compression
66 #define need_GL_ARB_vertex_buffer_object
67 #define need_GL_ARB_vertex_program
68 #define need_GL_ARB_window_pos
69 #define need_GL_EXT_blend_color
70 #define need_GL_EXT_blend_equation_separate
71 #define need_GL_EXT_blend_func_separate
72 #define need_GL_EXT_blend_minmax
73 #define need_GL_EXT_cull_vertex
74 #define need_GL_EXT_fog_coord
75 #define need_GL_EXT_multi_draw_arrays
76 #define need_GL_EXT_secondary_color
77 #define need_GL_NV_vertex_program
78 #include "extension_helper.h"
79
80 #ifndef VERBOSE
81 int VERBOSE = 0;
82 #endif
83
84 #if DEBUG_LOCKING
85 char *prevLockFile;
86 int prevLockLine;
87 #endif
88
89 /***************************************
90 * Mesa's Driver Functions
91 ***************************************/
92
93 #define DRIVER_DATE "20050225"
94
95 const GLubyte *intelGetString( GLcontext *ctx, GLenum name )
96 {
97 const char * chipset;
98 static char buffer[128];
99
100 switch (name) {
101 case GL_VENDOR:
102 return (GLubyte *)"Tungsten Graphics, Inc";
103 break;
104
105 case GL_RENDERER:
106 switch (INTEL_CONTEXT(ctx)->intelScreen->deviceID) {
107 case PCI_CHIP_845_G:
108 chipset = "Intel(R) 845G"; break;
109 case PCI_CHIP_I830_M:
110 chipset = "Intel(R) 830M"; break;
111 case PCI_CHIP_I855_GM:
112 chipset = "Intel(R) 852GM/855GM"; break;
113 case PCI_CHIP_I865_G:
114 chipset = "Intel(R) 865G"; break;
115 case PCI_CHIP_I915_G:
116 chipset = "Intel(R) 915G"; break;
117 case PCI_CHIP_I915_GM:
118 chipset = "Intel(R) 915GM"; break;
119 case PCI_CHIP_I945_G:
120 chipset = "Intel(R) 945G"; break;
121 default:
122 chipset = "Unknown Intel Chipset"; break;
123 }
124
125 (void) driGetRendererString( buffer, chipset, DRIVER_DATE, 0 );
126 return (GLubyte *) buffer;
127
128 default:
129 return NULL;
130 }
131 }
132
133 static void intelBufferSize(GLframebuffer *buffer,
134 GLuint *width, GLuint *height)
135 {
136 GET_CURRENT_CONTEXT(ctx);
137 intelContextPtr intel = INTEL_CONTEXT(ctx);
138 /* Need to lock to make sure the driDrawable is uptodate. This
139 * information is used to resize Mesa's software buffers, so it has
140 * to be correct.
141 */
142 LOCK_HARDWARE(intel);
143 *width = intel->driDrawable->w;
144 *height = intel->driDrawable->h;
145 UNLOCK_HARDWARE(intel);
146 }
147
148
149 /**
150 * Extension strings exported by the intel driver.
151 *
152 * \note
153 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
154 * old i830-specific driver.
155 */
156 const struct dri_extension card_extensions[] =
157 {
158 { "GL_ARB_multisample", GL_ARB_multisample_functions },
159 { "GL_ARB_multitexture", NULL },
160 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
161 { "GL_ARB_texture_border_clamp", NULL },
162 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
163 { "GL_ARB_texture_cube_map", NULL },
164 { "GL_ARB_texture_env_add", NULL },
165 { "GL_ARB_texture_env_combine", NULL },
166 { "GL_ARB_texture_env_dot3", NULL },
167 { "GL_ARB_texture_mirrored_repeat", NULL },
168 { "GL_ARB_texture_rectangle", NULL },
169 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
170 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
171 { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
172 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
173 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
174 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
175 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
176 { "GL_EXT_blend_subtract", NULL },
177 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions },
178 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
179 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
180 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
181 { "GL_EXT_stencil_wrap", NULL },
182 { "GL_EXT_texture_edge_clamp", NULL },
183 { "GL_EXT_texture_env_combine", NULL },
184 { "GL_EXT_texture_env_dot3", NULL },
185 { "GL_EXT_texture_filter_anisotropic", NULL },
186 { "GL_EXT_texture_lod_bias", NULL },
187 { "GL_3DFX_texture_compression_FXT1", NULL },
188 { "GL_APPLE_client_storage", NULL },
189 { "GL_MESA_pack_invert", NULL },
190 { "GL_MESA_ycbcr_texture", NULL },
191 { "GL_NV_blend_square", NULL },
192 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
193 { "GL_NV_vertex_program1_1", NULL },
194 { "GL_SGIS_generate_mipmap", NULL },
195 { NULL, NULL }
196 };
197
198 extern const struct tnl_pipeline_stage _intel_render_stage;
199
200 static const struct tnl_pipeline_stage *intel_pipeline[] = {
201 &_tnl_vertex_transform_stage,
202 &_tnl_vertex_cull_stage,
203 &_tnl_normal_transform_stage,
204 &_tnl_lighting_stage,
205 &_tnl_fog_coordinate_stage,
206 &_tnl_texgen_stage,
207 &_tnl_texture_transform_stage,
208 &_tnl_point_attenuation_stage,
209 &_tnl_arb_vertex_program_stage,
210 &_tnl_vertex_program_stage,
211 #if 1
212 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
213 #endif
214 &_tnl_render_stage,
215 0,
216 };
217
218
219 static const struct dri_debug_control debug_control[] =
220 {
221 { "fall", DEBUG_FALLBACKS },
222 { "tex", DEBUG_TEXTURE },
223 { "ioctl", DEBUG_IOCTL },
224 { "prim", DEBUG_PRIMS },
225 { "vert", DEBUG_VERTS },
226 { "state", DEBUG_STATE },
227 { "verb", DEBUG_VERBOSE },
228 { "dri", DEBUG_DRI },
229 { "dma", DEBUG_DMA },
230 { "san", DEBUG_SANITY },
231 { "sync", DEBUG_SYNC },
232 { "sleep", DEBUG_SLEEP },
233 { "pix", DEBUG_PIXEL },
234 { NULL, 0 }
235 };
236
237
238 static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
239 {
240 _swrast_InvalidateState( ctx, new_state );
241 _swsetup_InvalidateState( ctx, new_state );
242 _ac_InvalidateState( ctx, new_state );
243 _tnl_InvalidateState( ctx, new_state );
244 _tnl_invalidate_vertex_state( ctx, new_state );
245 INTEL_CONTEXT(ctx)->NewGLState |= new_state;
246 }
247
248
249 void intelInitDriverFunctions( struct dd_function_table *functions )
250 {
251 _mesa_init_driver_functions( functions );
252
253 functions->Flush = intelFlush;
254 functions->Clear = intelClear;
255 functions->Finish = intelFinish;
256 functions->GetBufferSize = intelBufferSize;
257 functions->ResizeBuffers = _mesa_resize_framebuffer;
258 functions->GetString = intelGetString;
259 functions->UpdateState = intelInvalidateState;
260 functions->CopyColorTable = _swrast_CopyColorTable;
261 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
262 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
263 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
264
265 intelInitTextureFuncs( functions );
266 intelInitPixelFuncs( functions );
267 intelInitStateFuncs( functions );
268 }
269
270
271
272 GLboolean intelInitContext( intelContextPtr intel,
273 const __GLcontextModes *mesaVis,
274 __DRIcontextPrivate *driContextPriv,
275 void *sharedContextPrivate,
276 struct dd_function_table *functions )
277 {
278 GLcontext *ctx = &intel->ctx;
279 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
280 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
281 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
282 drmI830Sarea *saPriv = (drmI830Sarea *)
283 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
284
285 if (!_mesa_initialize_context(&intel->ctx,
286 mesaVis, shareCtx,
287 functions,
288 (void*) intel))
289 return GL_FALSE;
290
291 driContextPriv->driverPrivate = intel;
292 intel->intelScreen = intelScreen;
293 intel->driScreen = sPriv;
294 intel->sarea = saPriv;
295
296
297 (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) );
298 make_empty_list( & intel->swapped );
299
300 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
301
302 ctx->Const.MinLineWidth = 1.0;
303 ctx->Const.MinLineWidthAA = 1.0;
304 ctx->Const.MaxLineWidth = 3.0;
305 ctx->Const.MaxLineWidthAA = 3.0;
306 ctx->Const.LineWidthGranularity = 1.0;
307
308 ctx->Const.MinPointSize = 1.0;
309 ctx->Const.MinPointSizeAA = 1.0;
310 ctx->Const.MaxPointSize = 255.0;
311 ctx->Const.MaxPointSizeAA = 3.0;
312 ctx->Const.PointSizeGranularity = 1.0;
313
314 /* Initialize the software rasterizer and helper modules. */
315 _swrast_CreateContext( ctx );
316 _ac_CreateContext( ctx );
317 _tnl_CreateContext( ctx );
318 _swsetup_CreateContext( ctx );
319
320 /* Install the customized pipeline: */
321 _tnl_destroy_pipeline( ctx );
322 _tnl_install_pipeline( ctx, intel_pipeline );
323
324 /* Configure swrast to match hardware characteristics: */
325 _swrast_allow_pixel_fog( ctx, GL_FALSE );
326 _swrast_allow_vertex_fog( ctx, GL_TRUE );
327
328 /* Dri stuff */
329 intel->hHWContext = driContextPriv->hHWContext;
330 intel->driFd = sPriv->fd;
331 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
332
333 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
334 intel->hw_stipple = 1;
335
336 switch(mesaVis->depthBits) {
337 case 0: /* what to do in this case? */
338 case 16:
339 intel->depth_scale = 1.0/0xffff;
340 intel->polygon_offset_scale = 1.0/0xffff;
341 intel->depth_clear_mask = ~0;
342 intel->ClearDepth = 0xffff;
343 break;
344 case 24:
345 intel->depth_scale = 1.0/0xffffff;
346 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
347 intel->depth_clear_mask = 0x00ffffff;
348 intel->stencil_clear_mask = 0xff000000;
349 intel->ClearDepth = 0x00ffffff;
350 break;
351 default:
352 assert(0);
353 break;
354 }
355
356 /* Initialize swrast, tnl driver tables: */
357 intelInitSpanFuncs( ctx );
358 intelInitTriFuncs( ctx );
359
360
361 intel->RenderIndex = ~0;
362
363 intel->do_irqs = (intel->intelScreen->irq_active &&
364 !getenv("INTEL_NO_IRQS"));
365
366 _math_matrix_ctr (&intel->ViewportMatrix);
367
368 driInitExtensions( ctx, card_extensions, GL_TRUE );
369
370 if (intel->ctx.Mesa_DXTn) {
371 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
372 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
373 }
374 else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) {
375 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
376 }
377
378 /* driInitTextureObjects( ctx, & intel->swapped, */
379 /* DRI_TEXMGR_DO_TEXTURE_1D | */
380 /* DRI_TEXMGR_DO_TEXTURE_2D | */
381 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
382
383
384 intel->prim.flush = intelInitBatchBuffer;
385 intel->prim.primitive = ~0;
386
387
388 #if DO_DEBUG
389 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
390 debug_control );
391 INTEL_DEBUG |= driParseDebugString( getenv( "INTEL_DEBUG" ),
392 debug_control );
393 #endif
394
395 #ifndef VERBOSE
396 if (getenv("INTEL_VERBOSE"))
397 VERBOSE=1;
398 #endif
399
400 if (getenv("INTEL_NO_RAST") ||
401 getenv("INTEL_NO_RAST")) {
402 fprintf(stderr, "disabling 3D rasterization\n");
403 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
404 }
405
406 return GL_TRUE;
407 }
408
409 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
410 {
411 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
412
413 assert(intel); /* should never be null */
414 if (intel) {
415 GLboolean release_texture_heaps;
416
417
418 intel->vtbl.destroy( intel );
419
420 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
421 _swsetup_DestroyContext (&intel->ctx);
422 _tnl_DestroyContext (&intel->ctx);
423 _ac_DestroyContext (&intel->ctx);
424
425 _swrast_DestroyContext (&intel->ctx);
426 intel->Fallback = 0; /* don't call _swrast_Flush later */
427
428 intelDestroyBatchBuffer(&intel->ctx);
429
430
431 if ( release_texture_heaps ) {
432 /* This share group is about to go away, free our private
433 * texture object data.
434 */
435 int i;
436
437 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
438 driDestroyTextureHeap( intel->texture_heaps[ i ] );
439 intel->texture_heaps[ i ] = NULL;
440 }
441
442 assert( is_empty_list( & intel->swapped ) );
443 }
444
445 /* free the Mesa context */
446 _mesa_destroy_context(&intel->ctx);
447 }
448 }
449
450 void intelSetFrontClipRects( intelContextPtr intel )
451 {
452 __DRIdrawablePrivate *dPriv = intel->driDrawable;
453
454 if (!dPriv) return;
455
456 intel->numClipRects = dPriv->numClipRects;
457 intel->pClipRects = dPriv->pClipRects;
458 intel->drawX = dPriv->x;
459 intel->drawY = dPriv->y;
460 }
461
462
463 void intelSetBackClipRects( intelContextPtr intel )
464 {
465 __DRIdrawablePrivate *dPriv = intel->driDrawable;
466
467 if (!dPriv) return;
468
469 if (intel->sarea->pf_enabled == 0 && dPriv->numBackClipRects == 0) {
470 intel->numClipRects = dPriv->numClipRects;
471 intel->pClipRects = dPriv->pClipRects;
472 intel->drawX = dPriv->x;
473 intel->drawY = dPriv->y;
474 } else {
475 intel->numClipRects = dPriv->numBackClipRects;
476 intel->pClipRects = dPriv->pBackClipRects;
477 intel->drawX = dPriv->backX;
478 intel->drawY = dPriv->backY;
479
480 if (dPriv->numBackClipRects == 1 &&
481 dPriv->x == dPriv->backX &&
482 dPriv->y == dPriv->backY) {
483
484 /* Repeat the calculation of the back cliprect dimensions here
485 * as early versions of dri.a in the Xserver are incorrect. Try
486 * very hard not to restrict future versions of dri.a which
487 * might eg. allocate truly private back buffers.
488 */
489 int x1, y1;
490 int x2, y2;
491
492 x1 = dPriv->x;
493 y1 = dPriv->y;
494 x2 = dPriv->x + dPriv->w;
495 y2 = dPriv->y + dPriv->h;
496
497 if (x1 < 0) x1 = 0;
498 if (y1 < 0) y1 = 0;
499 if (x2 > intel->intelScreen->width) x2 = intel->intelScreen->width;
500 if (y2 > intel->intelScreen->height) y2 = intel->intelScreen->height;
501
502 if (x1 == dPriv->pBackClipRects[0].x1 &&
503 y1 == dPriv->pBackClipRects[0].y1) {
504
505 dPriv->pBackClipRects[0].x2 = x2;
506 dPriv->pBackClipRects[0].y2 = y2;
507 }
508 }
509 }
510 }
511
512
513 void intelWindowMoved( intelContextPtr intel )
514 {
515 if (!intel->ctx.DrawBuffer) {
516 intelSetFrontClipRects( intel );
517 }
518 else {
519 switch (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0]) {
520 case BUFFER_BIT_FRONT_LEFT:
521 intelSetFrontClipRects( intel );
522 break;
523 case BUFFER_BIT_BACK_LEFT:
524 intelSetBackClipRects( intel );
525 break;
526 default:
527 /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
528 intelSetFrontClipRects( intel );
529 }
530 }
531 }
532
533 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
534 {
535 return GL_TRUE;
536 }
537
538 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
539 __DRIdrawablePrivate *driDrawPriv,
540 __DRIdrawablePrivate *driReadPriv)
541 {
542
543 if (driContextPriv) {
544 intelContextPtr intel = (intelContextPtr) driContextPriv->driverPrivate;
545
546 if ( intel->driDrawable != driDrawPriv ) {
547 /* Shouldn't the readbuffer be stored also? */
548 intel->driDrawable = driDrawPriv;
549 intelWindowMoved( intel );
550 }
551
552 _mesa_make_current(&intel->ctx,
553 (GLframebuffer *) driDrawPriv->driverPrivate,
554 (GLframebuffer *) driReadPriv->driverPrivate);
555
556 intel->ctx.Driver.DrawBuffer( &intel->ctx, intel->ctx.Color.DrawBuffer[0] );
557 } else {
558 _mesa_make_current(NULL, NULL, NULL);
559 }
560
561 return GL_TRUE;
562 }
563
564 void intelGetLock( intelContextPtr intel, GLuint flags )
565 {
566 __DRIdrawablePrivate *dPriv = intel->driDrawable;
567 __DRIscreenPrivate *sPriv = intel->driScreen;
568 drmI830Sarea * sarea = intel->sarea;
569 int me = intel->hHWContext;
570 unsigned i;
571
572 drmGetLock(intel->driFd, intel->hHWContext, flags);
573
574 /* If the window moved, may need to set a new cliprect now.
575 *
576 * NOTE: This releases and regains the hw lock, so all state
577 * checking must be done *after* this call:
578 */
579 if (dPriv)
580 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
581
582 /* If we lost context, need to dump all registers to hardware.
583 * Note that we don't care about 2d contexts, even if they perform
584 * accelerated commands, so the DRI locking in the X server is even
585 * more broken than usual.
586 */
587
588 if (sarea->ctxOwner != me) {
589 intel->perf_boxes |= I830_BOX_LOST_CONTEXT;
590 sarea->ctxOwner = me;
591 }
592
593 /* Shared texture managment - if another client has played with
594 * texture space, figure out which if any of our textures have been
595 * ejected, and update our global LRU.
596 */
597
598 for ( i = 0 ; i < intel->nr_heaps ; i++ ) {
599 DRI_AGE_TEXTURES( intel->texture_heaps[ i ] );
600 }
601
602 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
603 intelWindowMoved( intel );
604 intel->lastStamp = dPriv->lastStamp;
605 }
606 }
607
608 void intelSwapBuffers( __DRIdrawablePrivate *dPriv )
609 {
610 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
611 intelContextPtr intel;
612 GLcontext *ctx;
613 intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate;
614 ctx = &intel->ctx;
615 if (ctx->Visual.doubleBufferMode) {
616 _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */
617 if ( 0 /*intel->doPageFlip*/ ) { /* doPageFlip is never set !!! */
618 intelPageFlip( dPriv );
619 } else {
620 intelCopyBuffer( dPriv );
621 }
622 }
623 } else {
624 /* XXX this shouldn't be an error but we can't handle it for now */
625 fprintf(stderr, "%s: drawable has no context!\n", __FUNCTION__);
626 }
627 }
628
629
630 void intelInitState( GLcontext *ctx )
631 {
632 /* Mesa should do this for us:
633 */
634 ctx->Driver.AlphaFunc( ctx,
635 ctx->Color.AlphaFunc,
636 ctx->Color.AlphaRef);
637
638 ctx->Driver.BlendColor( ctx,
639 ctx->Color.BlendColor );
640
641 ctx->Driver.BlendEquationSeparate( ctx,
642 ctx->Color.BlendEquationRGB,
643 ctx->Color.BlendEquationA);
644
645 ctx->Driver.BlendFuncSeparate( ctx,
646 ctx->Color.BlendSrcRGB,
647 ctx->Color.BlendDstRGB,
648 ctx->Color.BlendSrcA,
649 ctx->Color.BlendDstA);
650
651 ctx->Driver.ColorMask( ctx,
652 ctx->Color.ColorMask[RCOMP],
653 ctx->Color.ColorMask[GCOMP],
654 ctx->Color.ColorMask[BCOMP],
655 ctx->Color.ColorMask[ACOMP]);
656
657 ctx->Driver.CullFace( ctx, ctx->Polygon.CullFaceMode );
658 ctx->Driver.DepthFunc( ctx, ctx->Depth.Func );
659 ctx->Driver.DepthMask( ctx, ctx->Depth.Mask );
660
661 ctx->Driver.Enable( ctx, GL_ALPHA_TEST, ctx->Color.AlphaEnabled );
662 ctx->Driver.Enable( ctx, GL_BLEND, ctx->Color.BlendEnabled );
663 ctx->Driver.Enable( ctx, GL_COLOR_LOGIC_OP, ctx->Color.ColorLogicOpEnabled );
664 ctx->Driver.Enable( ctx, GL_COLOR_SUM, ctx->Fog.ColorSumEnabled );
665 ctx->Driver.Enable( ctx, GL_CULL_FACE, ctx->Polygon.CullFlag );
666 ctx->Driver.Enable( ctx, GL_DEPTH_TEST, ctx->Depth.Test );
667 ctx->Driver.Enable( ctx, GL_DITHER, ctx->Color.DitherFlag );
668 ctx->Driver.Enable( ctx, GL_FOG, ctx->Fog.Enabled );
669 ctx->Driver.Enable( ctx, GL_LIGHTING, ctx->Light.Enabled );
670 ctx->Driver.Enable( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
671 ctx->Driver.Enable( ctx, GL_POLYGON_STIPPLE, ctx->Polygon.StippleFlag );
672 ctx->Driver.Enable( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
673 ctx->Driver.Enable( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
674 ctx->Driver.Enable( ctx, GL_TEXTURE_1D, GL_FALSE );
675 ctx->Driver.Enable( ctx, GL_TEXTURE_2D, GL_FALSE );
676 ctx->Driver.Enable( ctx, GL_TEXTURE_RECTANGLE_NV, GL_FALSE );
677 ctx->Driver.Enable( ctx, GL_TEXTURE_3D, GL_FALSE );
678 ctx->Driver.Enable( ctx, GL_TEXTURE_CUBE_MAP, GL_FALSE );
679
680 ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color );
681 ctx->Driver.Fogfv( ctx, GL_FOG_MODE, 0 );
682 ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density );
683 ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start );
684 ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End );
685
686 ctx->Driver.FrontFace( ctx, ctx->Polygon.FrontFace );
687
688 {
689 GLfloat f = (GLfloat)ctx->Light.Model.ColorControl;
690 ctx->Driver.LightModelfv( ctx, GL_LIGHT_MODEL_COLOR_CONTROL, &f );
691 }
692
693 ctx->Driver.LineWidth( ctx, ctx->Line.Width );
694 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
695 ctx->Driver.PointSize( ctx, ctx->Point.Size );
696 ctx->Driver.PolygonStipple( ctx, (const GLubyte *)ctx->PolygonStipple );
697 ctx->Driver.Scissor( ctx, ctx->Scissor.X, ctx->Scissor.Y,
698 ctx->Scissor.Width, ctx->Scissor.Height );
699 ctx->Driver.ShadeModel( ctx, ctx->Light.ShadeModel );
700 ctx->Driver.StencilFuncSeparate( ctx, GL_FRONT,
701 ctx->Stencil.Function[0],
702 ctx->Stencil.Ref[0],
703 ctx->Stencil.ValueMask[0] );
704 ctx->Driver.StencilFuncSeparate( ctx, GL_BACK,
705 ctx->Stencil.Function[1],
706 ctx->Stencil.Ref[1],
707 ctx->Stencil.ValueMask[1] );
708 ctx->Driver.StencilMaskSeparate( ctx, GL_FRONT, ctx->Stencil.WriteMask[0] );
709 ctx->Driver.StencilMaskSeparate( ctx, GL_BACK, ctx->Stencil.WriteMask[1] );
710 ctx->Driver.StencilOpSeparate( ctx, GL_FRONT,
711 ctx->Stencil.FailFunc[0],
712 ctx->Stencil.ZFailFunc[0],
713 ctx->Stencil.ZPassFunc[0]);
714 ctx->Driver.StencilOpSeparate( ctx, GL_BACK,
715 ctx->Stencil.FailFunc[1],
716 ctx->Stencil.ZFailFunc[1],
717 ctx->Stencil.ZPassFunc[1]);
718
719
720 ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] );
721 }