~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/mesa/main/context.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
#include "remap.h"
119
119
#include "scissor.h"
120
120
#include "shared.h"
 
121
#include "shaderobj.h"
121
122
#include "simple_list.h"
122
123
#include "state.h"
123
124
#include "stencil.h"
124
125
#include "texcompress_s3tc.h"
125
126
#include "texstate.h"
 
127
#include "transformfeedback.h"
126
128
#include "mtypes.h"
127
129
#include "varray.h"
128
130
#include "version.h"
129
131
#include "viewport.h"
130
132
#include "vtxfmt.h"
131
 
#include "glapi/glthread.h"
132
 
#include "glapi/glapitable.h"
133
 
#include "shader/program.h"
134
 
#include "shader/prog_print.h"
135
 
#include "shader/shader_api.h"
 
133
#include "program/program.h"
 
134
#include "program/prog_print.h"
136
135
#if _HAVE_FULL_GL
137
136
#include "math/m_matrix.h"
138
137
#endif
141
140
#include "sparc/sparc.h"
142
141
#endif
143
142
 
 
143
#include "glsl_parser_extras.h"
 
144
 
 
145
 
 
146
 
144
147
#ifndef MESA_VERBOSE
145
148
int MESA_VERBOSE = 0;
146
149
#endif
340
343
static void
341
344
dummy_enum_func(void)
342
345
{
343
 
   gl_buffer_index bi;
344
 
   gl_colortable_index ci;
345
 
   gl_face_index fi;
346
 
   gl_frag_attrib fa;
347
 
   gl_frag_result fr;
348
 
   gl_texture_index ti;
349
 
   gl_vert_attrib va;
350
 
   gl_vert_result vr;
 
346
   gl_buffer_index bi = BUFFER_FRONT_LEFT;
 
347
   gl_colortable_index ci = COLORTABLE_PRECONVOLUTION;
 
348
   gl_face_index fi = FACE_POS_X;
 
349
   gl_frag_attrib fa = FRAG_ATTRIB_WPOS;
 
350
   gl_frag_result fr = FRAG_RESULT_DEPTH;
 
351
   gl_texture_index ti = TEXTURE_2D_ARRAY_INDEX;
 
352
   gl_vert_attrib va = VERT_ATTRIB_POS;
 
353
   gl_vert_result vr = VERT_RESULT_HPOS;
 
354
   gl_geom_attrib ga = GEOM_ATTRIB_POSITION;
 
355
   gl_geom_result gr = GEOM_RESULT_POS;
351
356
 
352
357
   (void) bi;
353
358
   (void) ci;
357
362
   (void) ti;
358
363
   (void) va;
359
364
   (void) vr;
 
365
   (void) ga;
 
366
   (void) gr;
360
367
}
361
368
 
362
369
 
395
402
 
396
403
      _mesa_get_cpu_features();
397
404
 
398
 
      _mesa_init_remap_table();
 
405
      switch (ctx->API) {
 
406
#if FEATURE_GL
 
407
      case API_OPENGL:
 
408
         _mesa_init_remap_table();
 
409
         break;
 
410
#endif
 
411
#if FEATURE_ES1
 
412
      case API_OPENGLES:
 
413
         _mesa_init_remap_table_es1();
 
414
         break;
 
415
#endif
 
416
#if FEATURE_ES2
 
417
      case API_OPENGLES2:
 
418
         _mesa_init_remap_table_es2();
 
419
         break;
 
420
#endif
 
421
      default:
 
422
         break;
 
423
      }
399
424
 
400
425
      _mesa_init_sqrt_table();
 
426
      _mesa_init_get_hash(ctx);
401
427
 
402
428
      for (i = 0; i < 256; i++) {
403
429
         _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
412
438
   }
413
439
   _glthread_UNLOCK_MUTEX(OneTimeLock);
414
440
 
 
441
   /* Hopefully atexit() is widely available.  If not, we may need some
 
442
    * #ifdef tests here.
 
443
    */
 
444
   atexit(_mesa_destroy_shader_compiler);
 
445
 
415
446
   dummy_enum_func();
416
447
}
417
448
 
440
471
 
441
472
 
442
473
/**
443
 
 * Init vertex/fragment program limits.
 
474
 * Init vertex/fragment/geometry program limits.
444
475
 * Important: drivers should override these with actual limits.
445
476
 */
446
477
static void
455
486
   prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
456
487
   prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
457
488
 
458
 
   if (type == GL_VERTEX_PROGRAM_ARB) {
 
489
   switch (type) {
 
490
   case GL_VERTEX_PROGRAM_ARB:
459
491
      prog->MaxParameters = MAX_VERTEX_PROGRAM_PARAMS;
460
492
      prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
461
493
      prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
462
 
   }
463
 
   else {
 
494
      break;
 
495
   case GL_FRAGMENT_PROGRAM_ARB:
464
496
      prog->MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
465
497
      prog->MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
466
498
      prog->MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
 
499
      break;
 
500
   case MESA_GEOMETRY_PROGRAM:
 
501
      prog->MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
 
502
      prog->MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
 
503
      prog->MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
 
504
 
 
505
      prog->MaxGeometryTextureImageUnits = MAX_GEOMETRY_TEXTURE_IMAGE_UNITS;
 
506
      prog->MaxGeometryVaryingComponents = MAX_GEOMETRY_VARYING_COMPONENTS;
 
507
      prog->MaxVertexVaryingComponents = MAX_VERTEX_VARYING_COMPONENTS;
 
508
      prog->MaxGeometryUniformComponents = MAX_GEOMETRY_UNIFORM_COMPONENTS;
 
509
      prog->MaxGeometryOutputVertices = MAX_GEOMETRY_OUTPUT_VERTICES;
 
510
      prog->MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
 
511
      break;
 
512
   default:
 
513
      assert(0 && "Bad program type in init_program_limits()");
467
514
   }
468
515
 
469
516
   /* Set the native limits to zero.  This implies that there is no native
529
576
#if FEATURE_ARB_fragment_program
530
577
   init_program_limits(GL_FRAGMENT_PROGRAM_ARB, &ctx->Const.FragmentProgram);
531
578
#endif
 
579
#if FEATURE_ARB_geometry_shader4
 
580
   init_program_limits(MESA_GEOMETRY_PROGRAM, &ctx->Const.GeometryProgram);
 
581
#endif
532
582
   ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
533
583
   ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
534
584
 
560
610
 
561
611
   /* GL_EXT_provoking_vertex */
562
612
   ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
 
613
 
 
614
   /* GL_EXT_transform_feedback */
 
615
   ctx->Const.MaxTransformFeedbackSeparateAttribs = MAX_FEEDBACK_ATTRIBS;
 
616
   ctx->Const.MaxTransformFeedbackSeparateComponents = 4 * MAX_FEEDBACK_ATTRIBS;
 
617
   ctx->Const.MaxTransformFeedbackInterleavedComponents = 4 * MAX_FEEDBACK_ATTRIBS;
 
618
 
 
619
   /* GL 3.2: hard-coded for now: */
 
620
   ctx->Const.ProfileMask = GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
563
621
}
564
622
 
565
623
 
627
685
 
628
686
   assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
629
687
 
 
688
   /* if this fails, add more enum values to gl_buffer_index */
 
689
   assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
 
690
 
630
691
   /* XXX probably add more tests */
631
692
}
632
693
 
684
745
   _mesa_init_shader_state( ctx );
685
746
   _mesa_init_stencil( ctx );
686
747
   _mesa_init_transform( ctx );
 
748
   _mesa_init_transform_feedback( ctx );
687
749
   _mesa_init_varray( ctx );
688
750
   _mesa_init_viewport( ctx );
689
751
 
739
801
/**
740
802
 * Allocate and initialize a new dispatch table.
741
803
 */
742
 
static struct _glapi_table *
743
 
alloc_dispatch_table(void)
 
804
struct _glapi_table *
 
805
_mesa_alloc_dispatch_table(int size)
744
806
{
745
807
   /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
746
808
    * In practice, this'll be the same for stand-alone Mesa.  But for DRI
748
810
    * DRI drivers.
749
811
    */
750
812
   GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
751
 
                           sizeof(struct _glapi_table) / sizeof(_glapi_proc));
 
813
                           size / sizeof(_glapi_proc));
752
814
   struct _glapi_table *table =
753
815
      (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
754
816
   if (table) {
781
843
 * for debug flags.
782
844
 *
783
845
 * \param ctx the context to initialize
 
846
 * \param api the GL API type to create the context for
784
847
 * \param visual describes the visual attributes for this context
785
848
 * \param share_list points to context to share textures, display lists,
786
849
 *        etc with, or NULL
789
852
 * \param driverContext pointer to driver-specific context data
790
853
 */
791
854
GLboolean
792
 
_mesa_initialize_context(GLcontext *ctx,
793
 
                         const GLvisual *visual,
794
 
                         GLcontext *share_list,
795
 
                         const struct dd_function_table *driverFunctions,
796
 
                         void *driverContext)
 
855
_mesa_initialize_context_for_api(GLcontext *ctx,
 
856
                                 gl_api api,
 
857
                                 const GLvisual *visual,
 
858
                                 GLcontext *share_list,
 
859
                                 const struct dd_function_table *driverFunctions,
 
860
                                 void *driverContext)
797
861
{
798
862
   struct gl_shared_state *shared;
 
863
   int i;
799
864
 
800
865
   /*ASSERT(driverContext);*/
801
866
   assert(driverFunctions->NewTextureObject);
802
867
   assert(driverFunctions->FreeTexImageData);
803
868
 
804
 
   /* misc one-time initializations */
805
 
   one_time_init(ctx);
806
 
 
 
869
   ctx->API = api;
807
870
   ctx->Visual = *visual;
808
871
   ctx->DrawBuffer = NULL;
809
872
   ctx->ReadBuffer = NULL;
810
873
   ctx->WinSysDrawBuffer = NULL;
811
874
   ctx->WinSysReadBuffer = NULL;
812
875
 
 
876
   /* misc one-time initializations */
 
877
   one_time_init(ctx);
 
878
 
813
879
   /* Plug in driver functions and context pointer here.
814
880
    * This is important because when we call alloc_shared_state() below
815
881
    * we'll call ctx->Driver.NewTextureObject() to create the default
839
905
      return GL_FALSE;
840
906
   }
841
907
 
 
908
#if FEATURE_dispatch
842
909
   /* setup the API dispatch tables */
843
 
   ctx->Exec = alloc_dispatch_table();
844
 
   ctx->Save = alloc_dispatch_table();
845
 
   if (!ctx->Exec || !ctx->Save) {
 
910
   switch (ctx->API) {
 
911
#if FEATURE_GL
 
912
   case API_OPENGL:
 
913
      ctx->Exec = _mesa_create_exec_table();
 
914
      break;
 
915
#endif
 
916
#if FEATURE_ES1
 
917
   case API_OPENGLES:
 
918
      ctx->Exec = _mesa_create_exec_table_es1();
 
919
      break;
 
920
#endif
 
921
#if FEATURE_ES2
 
922
   case API_OPENGLES2:
 
923
      ctx->Exec = _mesa_create_exec_table_es2();
 
924
      break;
 
925
#endif
 
926
   default:
 
927
      _mesa_problem(ctx, "unknown or unsupported API");
 
928
      break;
 
929
   }
 
930
 
 
931
   if (!ctx->Exec) {
846
932
      _mesa_release_shared_state(ctx, ctx->Shared);
847
 
      if (ctx->Exec)
848
 
         free(ctx->Exec);
849
933
      return GL_FALSE;
850
934
   }
851
 
#if FEATURE_dispatch
852
 
   _mesa_init_exec_table(ctx->Exec);
853
935
#endif
854
936
   ctx->CurrentDispatch = ctx->Exec;
855
937
 
856
 
#if FEATURE_dlist
857
 
   _mesa_init_save_table(ctx->Save);
858
 
   _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
859
 
#endif
860
 
 
861
 
   /* Neutral tnl module stuff */
862
 
   _mesa_init_exec_vtxfmt( ctx ); 
863
 
   ctx->TnlModule.Current = NULL;
864
 
   ctx->TnlModule.SwapCount = 0;
865
 
 
866
938
   ctx->FragmentProgram._MaintainTexEnvProgram
867
939
      = (_mesa_getenv("MESA_TEX_PROG") != NULL);
868
940
 
873
945
      ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
874
946
   }
875
947
 
876
 
#ifdef FEATURE_extra_context_init
877
 
   _mesa_initialize_context_extra(ctx);
 
948
   switch (ctx->API) {
 
949
   case API_OPENGL:
 
950
      /* Neutral tnl module stuff */
 
951
      _mesa_init_exec_vtxfmt( ctx ); 
 
952
      ctx->TnlModule.Current = NULL;
 
953
      ctx->TnlModule.SwapCount = 0;
 
954
 
 
955
#if FEATURE_dlist
 
956
      ctx->Save = _mesa_create_save_table();
 
957
      if (!ctx->Save) {
 
958
         _mesa_release_shared_state(ctx, ctx->Shared);
 
959
         free(ctx->Exec);
 
960
         return GL_FALSE;
 
961
      }
 
962
 
 
963
      _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
878
964
#endif
 
965
      break;
 
966
   case API_OPENGLES:
 
967
      /**
 
968
       * GL_OES_texture_cube_map says
 
969
       * "Initially all texture generation modes are set to REFLECTION_MAP_OES"
 
970
       */
 
971
      for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
 
972
         struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
 
973
         texUnit->GenS.Mode = GL_REFLECTION_MAP_NV;
 
974
         texUnit->GenT.Mode = GL_REFLECTION_MAP_NV;
 
975
         texUnit->GenR.Mode = GL_REFLECTION_MAP_NV;
 
976
         texUnit->GenS._ModeBit = TEXGEN_REFLECTION_MAP_NV;
 
977
         texUnit->GenT._ModeBit = TEXGEN_REFLECTION_MAP_NV;
 
978
         texUnit->GenR._ModeBit = TEXGEN_REFLECTION_MAP_NV;
 
979
      }
 
980
      break;
 
981
   case API_OPENGLES2:
 
982
      ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
 
983
      ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
 
984
      ctx->Point.PointSprite = GL_TRUE;  /* always on for ES 2.x */
 
985
      break;
 
986
   }
879
987
 
880
988
   ctx->FirstTimeCurrent = GL_TRUE;
881
989
 
882
990
   return GL_TRUE;
883
991
}
884
992
 
 
993
GLboolean
 
994
_mesa_initialize_context(GLcontext *ctx,
 
995
                         const GLvisual *visual,
 
996
                         GLcontext *share_list,
 
997
                         const struct dd_function_table *driverFunctions,
 
998
                         void *driverContext)
 
999
{
 
1000
   return _mesa_initialize_context_for_api(ctx,
 
1001
                                           API_OPENGL,
 
1002
                                           visual,
 
1003
                                           share_list,
 
1004
                                           driverFunctions,
 
1005
                                           driverContext);
 
1006
}
885
1007
 
886
1008
/**
887
1009
 * Allocate and initialize a GLcontext structure.
889
1011
 * we need to at least call driverFunctions->NewTextureObject to initialize
890
1012
 * the rendering context.
891
1013
 *
 
1014
 * \param api the GL API type to create the context for
892
1015
 * \param visual a GLvisual pointer (we copy the struct contents)
893
1016
 * \param share_list another context to share display lists with or NULL
894
1017
 * \param driverFunctions points to the dd_function_table into which the
898
1021
 * \return pointer to a new __GLcontextRec or NULL if error.
899
1022
 */
900
1023
GLcontext *
901
 
_mesa_create_context(const GLvisual *visual,
902
 
                     GLcontext *share_list,
903
 
                     const struct dd_function_table *driverFunctions,
904
 
                     void *driverContext)
 
1024
_mesa_create_context_for_api(gl_api api,
 
1025
                             const GLvisual *visual,
 
1026
                             GLcontext *share_list,
 
1027
                             const struct dd_function_table *driverFunctions,
 
1028
                             void *driverContext)
905
1029
{
906
1030
   GLcontext *ctx;
907
1031
 
912
1036
   if (!ctx)
913
1037
      return NULL;
914
1038
 
915
 
   if (_mesa_initialize_context(ctx, visual, share_list,
916
 
                                driverFunctions, driverContext)) {
 
1039
   if (_mesa_initialize_context_for_api(ctx, api, visual, share_list,
 
1040
                                        driverFunctions, driverContext)) {
917
1041
      return ctx;
918
1042
   }
919
1043
   else {
922
1046
   }
923
1047
}
924
1048
 
 
1049
GLcontext *
 
1050
_mesa_create_context(const GLvisual *visual,
 
1051
                     GLcontext *share_list,
 
1052
                     const struct dd_function_table *driverFunctions,
 
1053
                     void *driverContext)
 
1054
{
 
1055
   return _mesa_create_context_for_api(API_OPENGL, visual,
 
1056
                                       share_list,
 
1057
                                       driverFunctions,
 
1058
                                       driverContext);
 
1059
}
925
1060
 
926
1061
/**
927
1062
 * Free the data associated with the given context.
969
1104
   _mesa_free_sync_data(ctx);
970
1105
#endif
971
1106
   _mesa_free_varray_data(ctx);
 
1107
   _mesa_free_transform_feedback(ctx);
972
1108
 
973
1109
   _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
974
1110
 
1358
1494
      if (newCtx->FirstTimeCurrent) {
1359
1495
         _mesa_compute_version(newCtx);
1360
1496
 
 
1497
         newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
 
1498
 
1361
1499
         check_context_limits(newCtx);
1362
1500
 
1363
1501
         /* We can use this to help debug user's problems.  Tell them to set
1566
1704
      /* using shaders */
1567
1705
      if (!ctx->Shader.CurrentProgram->LinkStatus) {
1568
1706
         _mesa_error(ctx, GL_INVALID_OPERATION,
1569
 
                     "%s(shader not linked), where");
 
1707
                     "%s(shader not linked)", where);
1570
1708
         return GL_FALSE;
1571
1709
      }
1572
1710
#if 0 /* not normally enabled */