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"
341
344
dummy_enum_func(void)
344
gl_colortable_index ci;
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;
396
403
_mesa_get_cpu_features();
398
_mesa_init_remap_table();
408
_mesa_init_remap_table();
413
_mesa_init_remap_table_es1();
418
_mesa_init_remap_table_es2();
400
425
_mesa_init_sqrt_table();
426
_mesa_init_get_hash(ctx);
402
428
for (i = 0; i < 256; i++) {
403
429
_mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
455
486
prog->MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
456
487
prog->MaxUniformComponents = 4 * MAX_UNIFORMS;
458
if (type == GL_VERTEX_PROGRAM_ARB) {
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;
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;
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;
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;
513
assert(0 && "Bad program type in init_program_limits()");
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);
579
#if FEATURE_ARB_geometry_shader4
580
init_program_limits(MESA_GEOMETRY_PROGRAM, &ctx->Const.GeometryProgram);
532
582
ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
533
583
ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
561
611
/* GL_EXT_provoking_vertex */
562
612
ctx->Const.QuadsFollowProvokingVertexConvention = GL_TRUE;
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;
619
/* GL 3.2: hard-coded for now: */
620
ctx->Const.ProfileMask = GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
628
686
assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
688
/* if this fails, add more enum values to gl_buffer_index */
689
assert(BUFFER_COLOR0 + MAX_DRAW_BUFFERS <= BUFFER_COUNT);
630
691
/* XXX probably add more tests */
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 );
740
802
* Allocate and initialize a new dispatch table.
742
static struct _glapi_table *
743
alloc_dispatch_table(void)
804
struct _glapi_table *
805
_mesa_alloc_dispatch_table(int size)
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
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));
781
843
* for debug flags.
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
792
_mesa_initialize_context(GLcontext *ctx,
793
const GLvisual *visual,
794
GLcontext *share_list,
795
const struct dd_function_table *driverFunctions,
855
_mesa_initialize_context_for_api(GLcontext *ctx,
857
const GLvisual *visual,
858
GLcontext *share_list,
859
const struct dd_function_table *driverFunctions,
798
862
struct gl_shared_state *shared;
800
865
/*ASSERT(driverContext);*/
801
866
assert(driverFunctions->NewTextureObject);
802
867
assert(driverFunctions->FreeTexImageData);
804
/* misc one-time initializations */
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;
876
/* misc one-time initializations */
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
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) {
913
ctx->Exec = _mesa_create_exec_table();
918
ctx->Exec = _mesa_create_exec_table_es1();
923
ctx->Exec = _mesa_create_exec_table_es2();
927
_mesa_problem(ctx, "unknown or unsupported API");
846
932
_mesa_release_shared_state(ctx, ctx->Shared);
852
_mesa_init_exec_table(ctx->Exec);
854
936
ctx->CurrentDispatch = ctx->Exec;
857
_mesa_init_save_table(ctx->Save);
858
_mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
861
/* Neutral tnl module stuff */
862
_mesa_init_exec_vtxfmt( ctx );
863
ctx->TnlModule.Current = NULL;
864
ctx->TnlModule.SwapCount = 0;
866
938
ctx->FragmentProgram._MaintainTexEnvProgram
867
939
= (_mesa_getenv("MESA_TEX_PROG") != NULL);
873
945
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
876
#ifdef FEATURE_extra_context_init
877
_mesa_initialize_context_extra(ctx);
950
/* Neutral tnl module stuff */
951
_mesa_init_exec_vtxfmt( ctx );
952
ctx->TnlModule.Current = NULL;
953
ctx->TnlModule.SwapCount = 0;
956
ctx->Save = _mesa_create_save_table();
958
_mesa_release_shared_state(ctx, ctx->Shared);
963
_mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
968
* GL_OES_texture_cube_map says
969
* "Initially all texture generation modes are set to REFLECTION_MAP_OES"
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;
982
ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
983
ctx->VertexProgram._MaintainTnlProgram = GL_TRUE;
984
ctx->Point.PointSprite = GL_TRUE; /* always on for ES 2.x */
880
988
ctx->FirstTimeCurrent = GL_TRUE;
994
_mesa_initialize_context(GLcontext *ctx,
995
const GLvisual *visual,
996
GLcontext *share_list,
997
const struct dd_function_table *driverFunctions,
1000
return _mesa_initialize_context_for_api(ctx,
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.
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.
901
_mesa_create_context(const GLvisual *visual,
902
GLcontext *share_list,
903
const struct dd_function_table *driverFunctions,
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)
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)) {
1050
_mesa_create_context(const GLvisual *visual,
1051
GLcontext *share_list,
1052
const struct dd_function_table *driverFunctions,
1053
void *driverContext)
1055
return _mesa_create_context_for_api(API_OPENGL, visual,
927
1062
* Free the data associated with the given context.
969
1104
_mesa_free_sync_data(ctx);
971
1106
_mesa_free_varray_data(ctx);
1107
_mesa_free_transform_feedback(ctx);
973
1109
_mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
1358
1494
if (newCtx->FirstTimeCurrent) {
1359
1495
_mesa_compute_version(newCtx);
1497
newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
1361
1499
check_context_limits(newCtx);
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;
1572
1710
#if 0 /* not normally enabled */