ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

context.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  7.3
00004  *
00005  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
00006  * Copyright (C) 2008  VMware, Inc.  All Rights Reserved.
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this software and associated documentation files (the "Software"),
00010  * to deal in the Software without restriction, including without limitation
00011  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00012  * and/or sell copies of the Software, and to permit persons to whom the
00013  * Software is furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included
00016  * in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00021  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00022  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00023  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00024  */
00025 
00079 #include "glheader.h"
00080 #include "imports.h"
00081 #if FEATURE_accum
00082 #include "accum.h"
00083 #endif
00084 #include "api_exec.h"
00085 #include "arrayobj.h"
00086 #if FEATURE_attrib_stack
00087 #include "attrib.h"
00088 #endif
00089 #include "blend.h"
00090 #include "buffers.h"
00091 #include "bufferobj.h"
00092 #if FEATURE_colortable
00093 #include "colortab.h"
00094 #endif
00095 #include "context.h"
00096 #include "debug.h"
00097 #include "depth.h"
00098 #if FEATURE_dlist
00099 #include "dlist.h"
00100 #endif
00101 #if FEATURE_evaluators
00102 #include "eval.h"
00103 #endif
00104 #include "enums.h"
00105 #include "extensions.h"
00106 #include "fbobject.h"
00107 #if FEATURE_feedback
00108 #include "feedback.h"
00109 #endif
00110 #include "fog.h"
00111 #include "framebuffer.h"
00112 #include "get.h"
00113 #if FEATURE_histogram
00114 #include "histogram.h"
00115 #endif
00116 #include "hint.h"
00117 #include "hash.h"
00118 #include "light.h"
00119 #include "lines.h"
00120 #include "macros.h"
00121 #include "matrix.h"
00122 #include "multisample.h"
00123 #include "pixel.h"
00124 #include "pixelstore.h"
00125 #include "points.h"
00126 #include "polygon.h"
00127 #if FEATURE_ARB_occlusion_query
00128 #include "queryobj.h"
00129 #endif
00130 #if FEATURE_drawpix
00131 #include "rastpos.h"
00132 #endif
00133 #include "scissor.h"
00134 #include "simple_list.h"
00135 #include "state.h"
00136 #include "stencil.h"
00137 #include "texcompress.h"
00138 #include "teximage.h"
00139 #include "texobj.h"
00140 #include "texstate.h"
00141 #include "mtypes.h"
00142 #include "varray.h"
00143 #include "version.h"
00144 #include "vtxfmt.h"
00145 #include "glapi/glthread.h"
00146 #include "glapi/glapioffsets.h"
00147 #include "glapi/glapitable.h"
00148 #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
00149 #include "shader/program.h"
00150 #endif
00151 #include "shader/shader_api.h"
00152 #if FEATURE_ATI_fragment_shader
00153 #include "shader/atifragshader.h"
00154 #endif
00155 #if _HAVE_FULL_GL
00156 #include "math/m_translate.h"
00157 #include "math/m_matrix.h"
00158 #include "math/m_xform.h"
00159 #include "math/mathmod.h"
00160 #endif
00161 
00162 #ifdef USE_SPARC_ASM
00163 #include "sparc/sparc.h"
00164 #endif
00165 
00166 #ifndef MESA_VERBOSE
00167 int MESA_VERBOSE = 0;
00168 #endif
00169 
00170 #ifndef MESA_DEBUG_FLAGS
00171 int MESA_DEBUG_FLAGS = 0;
00172 #endif
00173 
00174 
00175 /* ubyte -> float conversion */
00176 GLfloat _mesa_ubyte_to_float_color_tab[256];
00177 
00178 
00179 
00188 void
00189 _mesa_notifySwapBuffers(__GLcontext *gc)
00190 {
00191    FLUSH_VERTICES( gc, 0 );
00192 }
00193 
00194 
00195 /**********************************************************************/
00197 /**********************************************************************/
00225 GLvisual *
00226 _mesa_create_visual( GLboolean rgbFlag,
00227                      GLboolean dbFlag,
00228                      GLboolean stereoFlag,
00229                      GLint redBits,
00230                      GLint greenBits,
00231                      GLint blueBits,
00232                      GLint alphaBits,
00233                      GLint indexBits,
00234                      GLint depthBits,
00235                      GLint stencilBits,
00236                      GLint accumRedBits,
00237                      GLint accumGreenBits,
00238                      GLint accumBlueBits,
00239                      GLint accumAlphaBits,
00240                      GLint numSamples )
00241 {
00242    GLvisual *vis = (GLvisual *) _mesa_calloc(sizeof(GLvisual));
00243    if (vis) {
00244       if (!_mesa_initialize_visual(vis, rgbFlag, dbFlag, stereoFlag,
00245                                    redBits, greenBits, blueBits, alphaBits,
00246                                    indexBits, depthBits, stencilBits,
00247                                    accumRedBits, accumGreenBits,
00248                                    accumBlueBits, accumAlphaBits,
00249                                    numSamples)) {
00250          _mesa_free(vis);
00251          return NULL;
00252       }
00253    }
00254    return vis;
00255 }
00256 
00266 GLboolean
00267 _mesa_initialize_visual( GLvisual *vis,
00268                          GLboolean rgbFlag,
00269                          GLboolean dbFlag,
00270                          GLboolean stereoFlag,
00271                          GLint redBits,
00272                          GLint greenBits,
00273                          GLint blueBits,
00274                          GLint alphaBits,
00275                          GLint indexBits,
00276                          GLint depthBits,
00277                          GLint stencilBits,
00278                          GLint accumRedBits,
00279                          GLint accumGreenBits,
00280                          GLint accumBlueBits,
00281                          GLint accumAlphaBits,
00282                          GLint numSamples )
00283 {
00284    assert(vis);
00285 
00286    if (depthBits < 0 || depthBits > 32) {
00287       return GL_FALSE;
00288    }
00289    if (stencilBits < 0 || stencilBits > STENCIL_BITS) {
00290       return GL_FALSE;
00291    }
00292    assert(accumRedBits >= 0);
00293    assert(accumGreenBits >= 0);
00294    assert(accumBlueBits >= 0);
00295    assert(accumAlphaBits >= 0);
00296 
00297    vis->rgbMode          = rgbFlag;
00298    vis->doubleBufferMode = dbFlag;
00299    vis->stereoMode       = stereoFlag;
00300 
00301    vis->redBits          = redBits;
00302    vis->greenBits        = greenBits;
00303    vis->blueBits         = blueBits;
00304    vis->alphaBits        = alphaBits;
00305    vis->rgbBits          = redBits + greenBits + blueBits;
00306 
00307    vis->indexBits      = indexBits;
00308    vis->depthBits      = depthBits;
00309    vis->stencilBits    = stencilBits;
00310 
00311    vis->accumRedBits   = accumRedBits;
00312    vis->accumGreenBits = accumGreenBits;
00313    vis->accumBlueBits  = accumBlueBits;
00314    vis->accumAlphaBits = accumAlphaBits;
00315 
00316    vis->haveAccumBuffer   = accumRedBits > 0;
00317    vis->haveDepthBuffer   = depthBits > 0;
00318    vis->haveStencilBuffer = stencilBits > 0;
00319 
00320    vis->numAuxBuffers = 0;
00321    vis->level = 0;
00322    vis->pixmapMode = 0;
00323    vis->sampleBuffers = numSamples > 0 ? 1 : 0;
00324    vis->samples = numSamples;
00325 
00326    return GL_TRUE;
00327 }
00328 
00329 
00337 void
00338 _mesa_destroy_visual( GLvisual *vis )
00339 {
00340    _mesa_free(vis);
00341 }
00342 
00346 /**********************************************************************/
00352 /**********************************************************************/
00360 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
00361 
00371 static void
00372 one_time_init( GLcontext *ctx )
00373 {
00374    static GLboolean alreadyCalled = GL_FALSE;
00375    (void) ctx;
00376    _glthread_LOCK_MUTEX(OneTimeLock);
00377    if (!alreadyCalled) {
00378       GLuint i;
00379 
00380       /* do some implementation tests */
00381       assert( sizeof(GLbyte) == 1 );
00382       assert( sizeof(GLubyte) == 1 );
00383       assert( sizeof(GLshort) == 2 );
00384       assert( sizeof(GLushort) == 2 );
00385       assert( sizeof(GLint) == 4 );
00386       assert( sizeof(GLuint) == 4 );
00387 
00388       _mesa_init_sqrt_table();
00389 
00390 #if _HAVE_FULL_GL
00391       _math_init();
00392 
00393       for (i = 0; i < 256; i++) {
00394          _mesa_ubyte_to_float_color_tab[i] = (float) i / 255.0F;
00395       }
00396 #endif
00397 
00398 #ifdef USE_SPARC_ASM
00399       _mesa_init_sparc_glapi_relocs();
00400 #endif
00401       if (_mesa_getenv("MESA_DEBUG")) {
00402          _glapi_noop_enable_warnings(GL_TRUE);
00403          _glapi_set_warning_func( (_glapi_warning_func) _mesa_warning );
00404       }
00405       else {
00406          _glapi_noop_enable_warnings(GL_FALSE);
00407       }
00408 
00409 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
00410       _mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
00411                   MESA_VERSION_STRING, __DATE__, __TIME__);
00412 #endif
00413 
00414       alreadyCalled = GL_TRUE;
00415    }
00416    _glthread_UNLOCK_MUTEX(OneTimeLock);
00417 }
00418 
00419 
00429 static GLboolean
00430 alloc_shared_state( GLcontext *ctx )
00431 {
00432    GLuint i;
00433    struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
00434    if (!ss)
00435       return GL_FALSE;
00436 
00437    ctx->Shared = ss;
00438 
00439    _glthread_INIT_MUTEX(ss->Mutex);
00440 
00441    ss->DisplayList = _mesa_NewHashTable();
00442    ss->TexObjects = _mesa_NewHashTable();
00443    ss->Programs = _mesa_NewHashTable();
00444 
00445 #if FEATURE_ARB_vertex_program
00446    ss->DefaultVertexProgram = (struct gl_vertex_program *)
00447       ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
00448    if (!ss->DefaultVertexProgram)
00449       goto cleanup;
00450 #endif
00451 #if FEATURE_ARB_fragment_program
00452    ss->DefaultFragmentProgram = (struct gl_fragment_program *)
00453       ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
00454    if (!ss->DefaultFragmentProgram)
00455       goto cleanup;
00456 #endif
00457 #if FEATURE_ATI_fragment_shader
00458    ss->ATIShaders = _mesa_NewHashTable();
00459    ss->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
00460    if (!ss->DefaultFragmentShader)
00461       goto cleanup;
00462 #endif
00463 
00464 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
00465    ss->BufferObjects = _mesa_NewHashTable();
00466 #endif
00467 
00468    ss->ArrayObjects = _mesa_NewHashTable();
00469 
00470 #if FEATURE_ARB_shader_objects
00471    ss->ShaderObjects = _mesa_NewHashTable();
00472 #endif
00473 
00474    /* Create default texture objects */
00475    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
00476       static const GLenum targets[NUM_TEXTURE_TARGETS] = {
00477          GL_TEXTURE_1D,
00478          GL_TEXTURE_2D,
00479          GL_TEXTURE_3D,
00480          GL_TEXTURE_CUBE_MAP,
00481          GL_TEXTURE_RECTANGLE_NV,
00482          GL_TEXTURE_1D_ARRAY_EXT,
00483          GL_TEXTURE_2D_ARRAY_EXT
00484       };
00485       ss->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
00486       if (!ss->DefaultTex[i])
00487          goto cleanup;
00488    }
00489 
00490    /* sanity check */
00491    assert(ss->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);
00492 
00493    _glthread_INIT_MUTEX(ss->TexMutex);
00494    ss->TextureStateStamp = 0;
00495 
00496 #if FEATURE_EXT_framebuffer_object
00497    ss->FrameBuffers = _mesa_NewHashTable();
00498    if (!ss->FrameBuffers)
00499       goto cleanup;
00500    ss->RenderBuffers = _mesa_NewHashTable();
00501    if (!ss->RenderBuffers)
00502       goto cleanup;
00503 #endif
00504 
00505    return GL_TRUE;
00506 
00507 cleanup:
00508    /* Ran out of memory at some point.  Free everything and return NULL */
00509    if (ss->DisplayList)
00510       _mesa_DeleteHashTable(ss->DisplayList);
00511    if (ss->TexObjects)
00512       _mesa_DeleteHashTable(ss->TexObjects);
00513    if (ss->Programs)
00514       _mesa_DeleteHashTable(ss->Programs);
00515 #if FEATURE_ARB_vertex_program
00516    _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
00517 #endif
00518 #if FEATURE_ARB_fragment_program
00519    _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
00520 #endif
00521 #if FEATURE_ATI_fragment_shader
00522    if (ss->DefaultFragmentShader)
00523       _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
00524 #endif
00525 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
00526    if (ss->BufferObjects)
00527       _mesa_DeleteHashTable(ss->BufferObjects);
00528 #endif
00529 
00530    if (ss->ArrayObjects)
00531       _mesa_DeleteHashTable (ss->ArrayObjects);
00532 
00533 #if FEATURE_ARB_shader_objects
00534    if (ss->ShaderObjects)
00535       _mesa_DeleteHashTable (ss->ShaderObjects);
00536 #endif
00537 
00538 #if FEATURE_EXT_framebuffer_object
00539    if (ss->FrameBuffers)
00540       _mesa_DeleteHashTable(ss->FrameBuffers);
00541    if (ss->RenderBuffers)
00542       _mesa_DeleteHashTable(ss->RenderBuffers);
00543 #endif
00544 
00545    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
00546       if (ss->DefaultTex[i])
00547          ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
00548    }
00549 
00550    _mesa_free(ss);
00551 
00552    return GL_FALSE;
00553 }
00554 
00555 
00559 static void
00560 delete_displaylist_cb(GLuint id, void *data, void *userData)
00561 {
00562 #if FEATURE_dlist
00563    struct mesa_display_list *list = (struct mesa_display_list *) data;
00564    GLcontext *ctx = (GLcontext *) userData;
00565    _mesa_delete_list(ctx, list);
00566 #endif
00567 }
00568 
00572 static void
00573 delete_texture_cb(GLuint id, void *data, void *userData)
00574 {
00575    struct gl_texture_object *texObj = (struct gl_texture_object *) data;
00576    GLcontext *ctx = (GLcontext *) userData;
00577    ctx->Driver.DeleteTexture(ctx, texObj);
00578 }
00579 
00583 static void
00584 delete_program_cb(GLuint id, void *data, void *userData)
00585 {
00586    struct gl_program *prog = (struct gl_program *) data;
00587    GLcontext *ctx = (GLcontext *) userData;
00588    ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */
00589    prog->RefCount = 0;  /* now going away */
00590    ctx->Driver.DeleteProgram(ctx, prog);
00591 }
00592 
00597 static void
00598 delete_fragshader_cb(GLuint id, void *data, void *userData)
00599 {
00600    struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data;
00601    GLcontext *ctx = (GLcontext *) userData;
00602    _mesa_delete_ati_fragment_shader(ctx, shader);
00603 }
00604 
00608 static void
00609 delete_bufferobj_cb(GLuint id, void *data, void *userData)
00610 {
00611    struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data;
00612    GLcontext *ctx = (GLcontext *) userData;
00613    ctx->Driver.DeleteBuffer(ctx, bufObj);
00614 }
00615 
00619 static void
00620 delete_arrayobj_cb(GLuint id, void *data, void *userData)
00621 {
00622    struct gl_array_object *arrayObj = (struct gl_array_object *) data;
00623    GLcontext *ctx = (GLcontext *) userData;
00624    _mesa_delete_array_object(ctx, arrayObj);
00625 }
00626 
00631 static void
00632 free_shader_program_data_cb(GLuint id, void *data, void *userData)
00633 {
00634    GLcontext *ctx = (GLcontext *) userData;
00635    struct gl_shader_program *shProg = (struct gl_shader_program *) data;
00636 
00637    if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
00638        _mesa_free_shader_program_data(ctx, shProg);
00639    }
00640 }
00641 
00646 static void
00647 delete_shader_cb(GLuint id, void *data, void *userData)
00648 {
00649    GLcontext *ctx = (GLcontext *) userData;
00650    struct gl_shader *sh = (struct gl_shader *) data;
00651    if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) {
00652       _mesa_free_shader(ctx, sh);
00653    }
00654    else {
00655       struct gl_shader_program *shProg = (struct gl_shader_program *) data;
00656       ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA);
00657       _mesa_free_shader_program(ctx, shProg);
00658    }
00659 }
00660 
00664 static void
00665 delete_framebuffer_cb(GLuint id, void *data, void *userData)
00666 {
00667    struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
00668    /* The fact that the framebuffer is in the hashtable means its refcount
00669     * is one, but we're removing from the hashtable now.  So clear refcount.
00670     */
00671    /*assert(fb->RefCount == 1);*/
00672    fb->RefCount = 0;
00673 
00674    /* NOTE: Delete should always be defined but there are two reports
00675     * of it being NULL (bugs 13507, 14293).  Work-around for now.
00676     */
00677    if (fb->Delete)
00678       fb->Delete(fb);
00679 }
00680 
00684 static void
00685 delete_renderbuffer_cb(GLuint id, void *data, void *userData)
00686 {
00687    struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data;
00688    rb->RefCount = 0;  /* see comment for FBOs above */
00689    if (rb->Delete)
00690       rb->Delete(rb);
00691 }
00692 
00693 
00694 
00707 static void
00708 free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
00709 {
00710    GLuint i;
00711 
00712    /*
00713     * Free display lists
00714     */
00715    _mesa_HashDeleteAll(ss->DisplayList, delete_displaylist_cb, ctx);
00716    _mesa_DeleteHashTable(ss->DisplayList);
00717 
00718 #if FEATURE_ARB_shader_objects
00719    _mesa_HashWalk(ss->ShaderObjects, free_shader_program_data_cb, ctx);
00720    _mesa_HashDeleteAll(ss->ShaderObjects, delete_shader_cb, ctx);
00721    _mesa_DeleteHashTable(ss->ShaderObjects);
00722 #endif
00723 
00724    _mesa_HashDeleteAll(ss->Programs, delete_program_cb, ctx);
00725    _mesa_DeleteHashTable(ss->Programs);
00726 
00727 #if FEATURE_ARB_vertex_program
00728    _mesa_reference_vertprog(ctx, &ss->DefaultVertexProgram, NULL);
00729 #endif
00730 #if FEATURE_ARB_fragment_program
00731    _mesa_reference_fragprog(ctx, &ss->DefaultFragmentProgram, NULL);
00732 #endif
00733 
00734 #if FEATURE_ATI_fragment_shader
00735    _mesa_HashDeleteAll(ss->ATIShaders, delete_fragshader_cb, ctx);
00736    _mesa_DeleteHashTable(ss->ATIShaders);
00737    _mesa_delete_ati_fragment_shader(ctx, ss->DefaultFragmentShader);
00738 #endif
00739 
00740 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
00741    _mesa_HashDeleteAll(ss->BufferObjects, delete_bufferobj_cb, ctx);
00742    _mesa_DeleteHashTable(ss->BufferObjects);
00743 #endif
00744 
00745    _mesa_HashDeleteAll(ss->ArrayObjects, delete_arrayobj_cb, ctx);
00746    _mesa_DeleteHashTable(ss->ArrayObjects);
00747 
00748 #if FEATURE_EXT_framebuffer_object
00749    _mesa_HashDeleteAll(ss->FrameBuffers, delete_framebuffer_cb, ctx);
00750    _mesa_DeleteHashTable(ss->FrameBuffers);
00751    _mesa_HashDeleteAll(ss->RenderBuffers, delete_renderbuffer_cb, ctx);
00752    _mesa_DeleteHashTable(ss->RenderBuffers);
00753 #endif
00754 
00755    /*
00756     * Free texture objects (after FBOs since some textures might have
00757     * been bound to FBOs).
00758     */
00759    ASSERT(ctx->Driver.DeleteTexture);
00760    /* the default textures */
00761    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
00762       ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
00763    }
00764    /* all other textures */
00765    _mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
00766    _mesa_DeleteHashTable(ss->TexObjects);
00767 
00768    _glthread_DESTROY_MUTEX(ss->Mutex);
00769 
00770    _mesa_free(ss);
00771 }
00772 
00773 
00777 static void
00778 _mesa_init_current(GLcontext *ctx)
00779 {
00780    GLuint i;
00781 
00782    /* Init all to (0,0,0,1) */
00783    for (i = 0; i < VERT_ATTRIB_MAX; i++) {
00784       ASSIGN_4V( ctx->Current.Attrib[i], 0.0, 0.0, 0.0, 1.0 );
00785    }
00786 
00787    /* redo special cases: */
00788    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_WEIGHT], 1.0, 0.0, 0.0, 0.0 );
00789    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_NORMAL], 0.0, 0.0, 1.0, 1.0 );
00790    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR0], 1.0, 1.0, 1.0, 1.0 );
00791    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR1], 0.0, 0.0, 0.0, 1.0 );
00792    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_COLOR_INDEX], 1.0, 0.0, 0.0, 1.0 );
00793    ASSIGN_4V( ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG], 1.0, 0.0, 0.0, 1.0 );
00794 }
00795 
00796 
00800 static void
00801 init_natives(struct gl_program_constants *prog)
00802 {
00803    prog->MaxNativeInstructions = prog->MaxInstructions;
00804    prog->MaxNativeAluInstructions = prog->MaxAluInstructions;
00805    prog->MaxNativeTexInstructions = prog->MaxTexInstructions;
00806    prog->MaxNativeTexIndirections = prog->MaxTexIndirections;
00807    prog->MaxNativeAttribs = prog->MaxAttribs;
00808    prog->MaxNativeTemps = prog->MaxTemps;
00809    prog->MaxNativeAddressRegs = prog->MaxAddressRegs;
00810    prog->MaxNativeParameters = prog->MaxParameters;
00811 }
00812 
00813 
00819 static void 
00820 _mesa_init_constants(GLcontext *ctx)
00821 {
00822    assert(ctx);
00823 
00824    assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
00825    assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
00826 
00827    /* Constants, may be overriden (usually only reduced) by device drivers */
00828    ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
00829    ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
00830    ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
00831    ctx->Const.MaxTextureRectSize = MAX_TEXTURE_RECT_SIZE;
00832    ctx->Const.MaxArrayTextureLayers = MAX_ARRAY_TEXTURE_LAYERS;
00833    ctx->Const.MaxTextureCoordUnits = MAX_TEXTURE_COORD_UNITS;
00834    ctx->Const.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
00835    ctx->Const.MaxTextureUnits = MIN2(ctx->Const.MaxTextureCoordUnits,
00836                                      ctx->Const.MaxTextureImageUnits);
00837    ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
00838    ctx->Const.MaxTextureLodBias = MAX_TEXTURE_LOD_BIAS;
00839    ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
00840    ctx->Const.SubPixelBits = SUB_PIXEL_BITS;
00841    ctx->Const.MinPointSize = MIN_POINT_SIZE;
00842    ctx->Const.MaxPointSize = MAX_POINT_SIZE;
00843    ctx->Const.MinPointSizeAA = MIN_POINT_SIZE;
00844    ctx->Const.MaxPointSizeAA = MAX_POINT_SIZE;
00845    ctx->Const.PointSizeGranularity = (GLfloat) POINT_SIZE_GRANULARITY;
00846    ctx->Const.MinLineWidth = MIN_LINE_WIDTH;
00847    ctx->Const.MaxLineWidth = MAX_LINE_WIDTH;
00848    ctx->Const.MinLineWidthAA = MIN_LINE_WIDTH;
00849    ctx->Const.MaxLineWidthAA = MAX_LINE_WIDTH;
00850    ctx->Const.LineWidthGranularity = (GLfloat) LINE_WIDTH_GRANULARITY;
00851    ctx->Const.MaxColorTableSize = MAX_COLOR_TABLE_SIZE;
00852    ctx->Const.MaxConvolutionWidth = MAX_CONVOLUTION_WIDTH;
00853    ctx->Const.MaxConvolutionHeight = MAX_CONVOLUTION_HEIGHT;
00854    ctx->Const.MaxClipPlanes = MAX_CLIP_PLANES;
00855    ctx->Const.MaxLights = MAX_LIGHTS;
00856    ctx->Const.MaxShininess = 128.0;
00857    ctx->Const.MaxSpotExponent = 128.0;
00858    ctx->Const.MaxViewportWidth = MAX_WIDTH;
00859    ctx->Const.MaxViewportHeight = MAX_HEIGHT;
00860 #if FEATURE_ARB_vertex_program
00861    ctx->Const.VertexProgram.MaxInstructions = MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS;
00862    ctx->Const.VertexProgram.MaxAluInstructions = 0;
00863    ctx->Const.VertexProgram.MaxTexInstructions = 0;
00864    ctx->Const.VertexProgram.MaxTexIndirections = 0;
00865    ctx->Const.VertexProgram.MaxAttribs = MAX_NV_VERTEX_PROGRAM_INPUTS;
00866    ctx->Const.VertexProgram.MaxTemps = MAX_PROGRAM_TEMPS;
00867    ctx->Const.VertexProgram.MaxParameters = MAX_NV_VERTEX_PROGRAM_PARAMS;
00868    ctx->Const.VertexProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
00869    ctx->Const.VertexProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
00870    ctx->Const.VertexProgram.MaxAddressRegs = MAX_VERTEX_PROGRAM_ADDRESS_REGS;
00871    ctx->Const.VertexProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
00872    init_natives(&ctx->Const.VertexProgram);
00873 #endif
00874 
00875 #if FEATURE_ARB_fragment_program
00876    ctx->Const.FragmentProgram.MaxInstructions = MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS;
00877    ctx->Const.FragmentProgram.MaxAluInstructions = MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS;
00878    ctx->Const.FragmentProgram.MaxTexInstructions = MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS;
00879    ctx->Const.FragmentProgram.MaxTexIndirections = MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS;
00880    ctx->Const.FragmentProgram.MaxAttribs = MAX_NV_FRAGMENT_PROGRAM_INPUTS;
00881    ctx->Const.FragmentProgram.MaxTemps = MAX_PROGRAM_TEMPS;
00882    ctx->Const.FragmentProgram.MaxParameters = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
00883    ctx->Const.FragmentProgram.MaxLocalParams = MAX_PROGRAM_LOCAL_PARAMS;
00884    ctx->Const.FragmentProgram.MaxEnvParams = MAX_PROGRAM_ENV_PARAMS;
00885    ctx->Const.FragmentProgram.MaxAddressRegs = MAX_FRAGMENT_PROGRAM_ADDRESS_REGS;
00886    ctx->Const.FragmentProgram.MaxUniformComponents = 4 * MAX_UNIFORMS;
00887    init_natives(&ctx->Const.FragmentProgram);
00888 #endif
00889    ctx->Const.MaxProgramMatrices = MAX_PROGRAM_MATRICES;
00890    ctx->Const.MaxProgramMatrixStackDepth = MAX_PROGRAM_MATRIX_STACK_DEPTH;
00891 
00892    /* CheckArrayBounds is overriden by drivers/x11 for X server */
00893    ctx->Const.CheckArrayBounds = GL_FALSE;
00894 
00895    /* GL_ARB_draw_buffers */
00896    ctx->Const.MaxDrawBuffers = MAX_DRAW_BUFFERS;
00897 
00898    /* GL_OES_read_format */
00899    ctx->Const.ColorReadFormat = GL_RGBA;
00900    ctx->Const.ColorReadType = GL_UNSIGNED_BYTE;
00901 
00902 #if FEATURE_EXT_framebuffer_object
00903    ctx->Const.MaxColorAttachments = MAX_COLOR_ATTACHMENTS;
00904    ctx->Const.MaxRenderbufferSize = MAX_WIDTH;
00905 #endif
00906 
00907 #if FEATURE_ARB_vertex_shader
00908    ctx->Const.MaxVertexTextureImageUnits = MAX_VERTEX_TEXTURE_IMAGE_UNITS;
00909    ctx->Const.MaxVarying = MAX_VARYING;
00910 #endif
00911 
00912    /* sanity checks */
00913    ASSERT(ctx->Const.MaxTextureUnits == MIN2(ctx->Const.MaxTextureImageUnits,
00914                                              ctx->Const.MaxTextureCoordUnits));
00915    ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
00916    ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
00917 
00918    ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
00919    ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
00920    ASSERT(MAX_NV_VERTEX_PROGRAM_INPUTS <= VERT_ATTRIB_MAX);
00921    ASSERT(MAX_NV_VERTEX_PROGRAM_OUTPUTS <= VERT_RESULT_MAX);
00922 }
00923 
00924 
00929 static void
00930 check_context_limits(GLcontext *ctx)
00931 {
00932    /* Many context limits/constants are limited by the size of
00933     * internal arrays.
00934     */
00935    assert(ctx->Const.MaxTextureImageUnits <= MAX_TEXTURE_IMAGE_UNITS);
00936    assert(ctx->Const.MaxTextureCoordUnits <= MAX_TEXTURE_COORD_UNITS);
00937    assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_IMAGE_UNITS);
00938    assert(ctx->Const.MaxTextureUnits <= MAX_TEXTURE_COORD_UNITS);
00939 
00940    /* number of coord units cannot be greater than number of image units */
00941    assert(ctx->Const.MaxTextureCoordUnits <= ctx->Const.MaxTextureImageUnits);
00942 
00943    assert(ctx->Const.MaxViewportWidth <= MAX_WIDTH);
00944    assert(ctx->Const.MaxViewportHeight <= MAX_WIDTH);
00945 
00946    /* make sure largest texture image is <= MAX_WIDTH in size */
00947    assert((1 << (ctx->Const.MaxTextureLevels -1 )) <= MAX_WIDTH);
00948    assert((1 << (ctx->Const.MaxCubeTextureLevels -1 )) <= MAX_WIDTH);
00949    assert((1 << (ctx->Const.Max3DTextureLevels -1 )) <= MAX_WIDTH);
00950 
00951    assert(ctx->Const.MaxDrawBuffers <= MAX_DRAW_BUFFERS);
00952 
00953    /* XXX probably add more tests */
00954 }
00955 
00956 
00965 static GLboolean
00966 init_attrib_groups(GLcontext *ctx)
00967 {
00968    assert(ctx);
00969 
00970    /* Constants */
00971    _mesa_init_constants( ctx );
00972 
00973    /* Extensions */
00974    _mesa_init_extensions( ctx );
00975 
00976    /* Attribute Groups */
00977 #if FEATURE_accum
00978    _mesa_init_accum( ctx );
00979 #endif
00980 #if FEATURE_attrib_stack
00981    _mesa_init_attrib( ctx );
00982 #endif
00983    _mesa_init_buffer_objects( ctx );
00984    _mesa_init_color( ctx );
00985 #if FEATURE_colortable
00986    _mesa_init_colortables( ctx );
00987 #endif
00988    _mesa_init_current( ctx );
00989    _mesa_init_depth( ctx );
00990    _mesa_init_debug( ctx );
00991 #if FEATURE_dlist
00992    _mesa_init_display_list( ctx );
00993 #endif
00994 #if FEATURE_evaluators
00995    _mesa_init_eval( ctx );
00996 #endif
00997    _mesa_init_fbobjects( ctx );
00998 #if FEATURE_feedback
00999    _mesa_init_feedback( ctx );
01000 #else
01001    ctx->RenderMode = GL_RENDER;
01002 #endif
01003    _mesa_init_fog( ctx );
01004 #if FEATURE_histogram
01005    _mesa_init_histogram( ctx );
01006 #endif
01007    _mesa_init_hint( ctx );
01008    _mesa_init_line( ctx );
01009    _mesa_init_lighting( ctx );
01010    _mesa_init_matrix( ctx );
01011    _mesa_init_multisample( ctx );
01012    _mesa_init_pixel( ctx );
01013    _mesa_init_pixelstore( ctx );
01014    _mesa_init_point( ctx );
01015    _mesa_init_polygon( ctx );
01016    _mesa_init_program( ctx );
01017 #if FEATURE_ARB_occlusion_query
01018    _mesa_init_query( ctx );
01019 #endif
01020 #if FEATURE_drawpix
01021    _mesa_init_rastpos( ctx );
01022 #endif
01023    _mesa_init_scissor( ctx );
01024    _mesa_init_shader_state( ctx );
01025    _mesa_init_stencil( ctx );
01026    _mesa_init_transform( ctx );
01027    _mesa_init_varray( ctx );
01028    _mesa_init_viewport( ctx );
01029 
01030    if (!_mesa_init_texture( ctx ))
01031       return GL_FALSE;
01032 
01033 #if FEATURE_texture_s3tc
01034    _mesa_init_texture_s3tc( ctx );
01035 #endif
01036 #if FEATURE_texture_fxt1
01037    _mesa_init_texture_fxt1( ctx );
01038 #endif
01039 
01040    /* Miscellaneous */
01041    ctx->NewState = _NEW_ALL;
01042    ctx->ErrorValue = (GLenum) GL_NO_ERROR;
01043 
01044    return GL_TRUE;
01045 }
01046 
01047 
01057 static GLboolean
01058 update_default_objects(GLcontext *ctx)
01059 {
01060    assert(ctx);
01061 
01062    _mesa_update_default_objects_program(ctx);
01063    _mesa_update_default_objects_texture(ctx);
01064    _mesa_update_default_objects_buffer_objects(ctx);
01065 
01066    return GL_TRUE;
01067 }
01068 
01069 
01075 static int
01076 generic_nop(void)
01077 {
01078    _mesa_warning(NULL, "User called no-op dispatch function (an unsupported extension function?)");
01079    return 0;
01080 }
01081 
01082 
01086 static struct _glapi_table *
01087 alloc_dispatch_table(void)
01088 {
01089    /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
01090     * In practice, this'll be the same for stand-alone Mesa.  But for DRI
01091     * Mesa we do this to accomodate different versions of libGL and various
01092     * DRI drivers.
01093     */
01094    GLint numEntries = MAX2(_glapi_get_dispatch_table_size(),
01095                            sizeof(struct _glapi_table) / sizeof(_glapi_proc));
01096    struct _glapi_table *table =
01097       (struct _glapi_table *) _mesa_malloc(numEntries * sizeof(_glapi_proc));
01098    if (table) {
01099       _glapi_proc *entry = (_glapi_proc *) table;
01100       GLint i;
01101       for (i = 0; i < numEntries; i++) {
01102          entry[i] = (_glapi_proc) generic_nop;
01103       }
01104    }
01105    return table;
01106 }
01107 
01108 
01135 GLboolean
01136 _mesa_initialize_context(GLcontext *ctx,
01137                          const GLvisual *visual,
01138                          GLcontext *share_list,
01139                          const struct dd_function_table *driverFunctions,
01140                          void *driverContext)
01141 {
01142    ASSERT(driverContext);
01143    assert(driverFunctions->NewTextureObject);
01144    assert(driverFunctions->FreeTexImageData);
01145 
01146    /* misc one-time initializations */
01147    one_time_init(ctx);
01148 
01149    ctx->Visual = *visual;
01150    ctx->DrawBuffer = NULL;
01151    ctx->ReadBuffer = NULL;
01152    ctx->WinSysDrawBuffer = NULL;
01153    ctx->WinSysReadBuffer = NULL;
01154 
01155    /* Plug in driver functions and context pointer here.
01156     * This is important because when we call alloc_shared_state() below
01157     * we'll call ctx->Driver.NewTextureObject() to create the default
01158     * textures.
01159     */
01160    ctx->Driver = *driverFunctions;
01161    ctx->DriverCtx = driverContext;
01162 
01163    if (share_list) {
01164       /* share state with another context */
01165       ctx->Shared = share_list->Shared;
01166    }
01167    else {
01168       /* allocate new, unshared state */
01169       if (!alloc_shared_state( ctx )) {
01170          return GL_FALSE;
01171       }
01172    }
01173    _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
01174    ctx->Shared->RefCount++;
01175    _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
01176 
01177    if (!init_attrib_groups( ctx )) {
01178       free_shared_state(ctx, ctx->Shared);
01179       return GL_FALSE;
01180    }
01181 
01182    /* setup the API dispatch tables */
01183    ctx->Exec = alloc_dispatch_table();
01184    ctx->Save = alloc_dispatch_table();
01185    if (!ctx->Exec || !ctx->Save) {
01186       free_shared_state(ctx, ctx->Shared);
01187       if (ctx->Exec)
01188          _mesa_free(ctx->Exec);
01189    }
01190 #if FEATURE_dispatch
01191    _mesa_init_exec_table(ctx->Exec);
01192 #endif
01193    ctx->CurrentDispatch = ctx->Exec;
01194 #if FEATURE_dlist
01195    _mesa_init_dlist_table(ctx->Save);
01196    _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt );
01197 #endif
01198    /* Neutral tnl module stuff */
01199    _mesa_init_exec_vtxfmt( ctx ); 
01200    ctx->TnlModule.Current = NULL;
01201    ctx->TnlModule.SwapCount = 0;
01202 
01203    ctx->FragmentProgram._MaintainTexEnvProgram
01204       = (_mesa_getenv("MESA_TEX_PROG") != NULL);
01205 
01206    ctx->VertexProgram._MaintainTnlProgram
01207       = (_mesa_getenv("MESA_TNL_PROG") != NULL);
01208    if (ctx->VertexProgram._MaintainTnlProgram) {
01209       /* this is required... */
01210       ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE;
01211    }
01212 
01213 #ifdef FEATURE_extra_context_init
01214    _mesa_initialize_context_extra(ctx);
01215 #endif
01216 
01217    ctx->FirstTimeCurrent = GL_TRUE;
01218 
01219    return GL_TRUE;
01220 }
01221 
01222 
01237 GLcontext *
01238 _mesa_create_context(const GLvisual *visual,
01239                      GLcontext *share_list,
01240                      const struct dd_function_table *driverFunctions,
01241                      void *driverContext)
01242 {
01243    GLcontext *ctx;
01244 
01245    ASSERT(visual);
01246    ASSERT(driverContext);
01247 
01248    ctx = (GLcontext *) _mesa_calloc(sizeof(GLcontext));
01249    if (!ctx)
01250       return NULL;
01251 
01252    if (_mesa_initialize_context(ctx, visual, share_list,
01253                                 driverFunctions, driverContext)) {
01254       return ctx;
01255    }
01256    else {
01257       _mesa_free(ctx);
01258       return NULL;
01259    }
01260 }
01261 
01262 
01270 void
01271 _mesa_free_context_data( GLcontext *ctx )
01272 {
01273    GLint RefCount;
01274 
01275    if (!_mesa_get_current_context()){
01276       /* No current context, but we may need one in order to delete
01277        * texture objs, etc.  So temporarily bind the context now.
01278        */
01279       _mesa_make_current(ctx, NULL, NULL);
01280    }
01281 
01282    /* unreference WinSysDraw/Read buffers */
01283    _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer);
01284    _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer);
01285    _mesa_unreference_framebuffer(&ctx->DrawBuffer);
01286    _mesa_unreference_framebuffer(&ctx->ReadBuffer);
01287 
01288    _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL);
01289    _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL);
01290    _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL);
01291 
01292    _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL);
01293    _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL);
01294    _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL);
01295 
01296    _mesa_free_attrib_data(ctx);
01297    _mesa_free_lighting_data( ctx );
01298 #if FEATURE_evaluators
01299    _mesa_free_eval_data( ctx );
01300 #endif
01301    _mesa_free_texture_data( ctx );
01302    _mesa_free_matrix_data( ctx );
01303    _mesa_free_viewport_data( ctx );
01304 #if FEATURE_colortable
01305    _mesa_free_colortables_data( ctx );
01306 #endif
01307    _mesa_free_program_data(ctx);
01308    _mesa_free_shader_state(ctx);
01309 #if FEATURE_ARB_occlusion_query
01310    _mesa_free_query_data(ctx);
01311 #endif
01312 
01313 #if FEATURE_ARB_vertex_buffer_object
01314    _mesa_delete_buffer_object(ctx, ctx->Array.NullBufferObj);
01315 #endif
01316    _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj);
01317 
01318    /* free dispatch tables */
01319    _mesa_free(ctx->Exec);
01320    _mesa_free(ctx->Save);
01321 
01322    /* Shared context state (display lists, textures, etc) */
01323    _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
01324    RefCount = --ctx->Shared->RefCount;
01325    _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
01326    assert(RefCount >= 0);
01327    if (RefCount == 0) {
01328       /* free shared state */
01329       free_shared_state( ctx, ctx->Shared );
01330    }
01331 
01332    if (ctx->Extensions.String)
01333       _mesa_free((void *) ctx->Extensions.String);
01334 
01335    /* unbind the context if it's currently bound */
01336    if (ctx == _mesa_get_current_context()) {
01337       _mesa_make_current(NULL, NULL, NULL);
01338    }
01339 }
01340 
01341 
01349 void
01350 _mesa_destroy_context( GLcontext *ctx )
01351 {
01352    if (ctx) {
01353       _mesa_free_context_data(ctx);
01354       _mesa_free( (void *) ctx );
01355    }
01356 }
01357 
01358 
01359 #if _HAVE_FULL_GL
01360 
01372 void
01373 _mesa_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
01374 {
01375    if (mask & GL_ACCUM_BUFFER_BIT) {
01376       /* OK to memcpy */
01377       dst->Accum = src->Accum;
01378    }
01379    if (mask & GL_COLOR_BUFFER_BIT) {
01380       /* OK to memcpy */
01381       dst->Color = src->Color;
01382    }
01383    if (mask & GL_CURRENT_BIT) {
01384       /* OK to memcpy */
01385       dst->Current = src->Current;
01386    }
01387    if (mask & GL_DEPTH_BUFFER_BIT) {
01388       /* OK to memcpy */
01389       dst->Depth = src->Depth;
01390    }
01391    if (mask & GL_ENABLE_BIT) {
01392       /* no op */
01393    }
01394    if (mask & GL_EVAL_BIT) {
01395       /* OK to memcpy */
01396       dst->Eval = src->Eval;
01397    }
01398    if (mask & GL_FOG_BIT) {
01399       /* OK to memcpy */
01400       dst->Fog = src->Fog;
01401    }
01402    if (mask & GL_HINT_BIT) {
01403       /* OK to memcpy */
01404       dst->Hint = src->Hint;
01405    }
01406    if (mask & GL_LIGHTING_BIT) {
01407       GLuint i;
01408       /* begin with memcpy */
01409       dst->Light = src->Light;
01410       /* fixup linked lists to prevent pointer insanity */
01411       make_empty_list( &(dst->Light.EnabledList) );
01412       for (i = 0; i < MAX_LIGHTS; i++) {
01413          if (dst->Light.Light[i].Enabled) {
01414             insert_at_tail(&(dst->Light.EnabledList), &(dst->Light.Light[i]));
01415          }
01416       }
01417    }
01418    if (mask & GL_LINE_BIT) {
01419       /* OK to memcpy */
01420       dst->Line = src->Line;
01421    }
01422    if (mask & GL_LIST_BIT) {
01423       /* OK to memcpy */
01424       dst->List = src->List;
01425    }
01426    if (mask & GL_PIXEL_MODE_BIT) {
01427       /* OK to memcpy */
01428       dst->Pixel = src->Pixel;
01429    }
01430    if (mask & GL_POINT_BIT) {
01431       /* OK to memcpy */
01432       dst->Point = src->Point;
01433    }
01434    if (mask & GL_POLYGON_BIT) {
01435       /* OK to memcpy */
01436       dst->Polygon = src->Polygon;
01437    }
01438    if (mask & GL_POLYGON_STIPPLE_BIT) {
01439       /* Use loop instead of MEMCPY due to problem with Portland Group's
01440        * C compiler.  Reported by John Stone.
01441        */
01442       GLuint i;
01443       for (i = 0; i < 32; i++) {
01444          dst->PolygonStipple[i] = src->PolygonStipple[i];
01445       }
01446    }
01447    if (mask & GL_SCISSOR_BIT) {
01448       /* OK to memcpy */
01449       dst->Scissor = src->Scissor;
01450    }
01451    if (mask & GL_STENCIL_BUFFER_BIT) {
01452       /* OK to memcpy */
01453       dst->Stencil = src->Stencil;
01454    }
01455    if (mask & GL_TEXTURE_BIT) {
01456       /* Cannot memcpy because of pointers */
01457       _mesa_copy_texture_state(src, dst);
01458    }
01459    if (mask & GL_TRANSFORM_BIT) {
01460       /* OK to memcpy */
01461       dst->Transform = src->Transform;
01462    }
01463    if (mask & GL_VIEWPORT_BIT) {
01464       /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
01465       dst->Viewport.X = src->Viewport.X;
01466       dst->Viewport.Y = src->Viewport.Y;
01467       dst->Viewport.Width = src->Viewport.Width;
01468       dst->Viewport.Height = src->Viewport.Height;
01469       dst->Viewport.Near = src->Viewport.Near;
01470       dst->Viewport.Far = src->Viewport.Far;
01471       _math_matrix_copy(&dst->Viewport._WindowMap, &src->Viewport._WindowMap);
01472    }
01473 
01474    /* XXX FIXME:  Call callbacks?
01475     */
01476    dst->NewState = _NEW_ALL;
01477 }
01478 #endif
01479 
01480 
01491 static GLboolean 
01492 check_compatible(const GLcontext *ctx, const GLframebuffer *buffer)
01493 {
01494    const GLvisual *ctxvis = &ctx->Visual;
01495    const GLvisual *bufvis = &buffer->Visual;
01496 
01497    if (ctxvis == bufvis)
01498       return GL_TRUE;
01499 
01500    if (ctxvis->rgbMode != bufvis->rgbMode)
01501       return GL_FALSE;
01502 #if 0
01503    /* disabling this fixes the fgl_glxgears pbuffer demo */
01504    if (ctxvis->doubleBufferMode && !bufvis->doubleBufferMode)
01505       return GL_FALSE;
01506 #endif
01507    if (ctxvis->stereoMode && !bufvis->stereoMode)
01508       return GL_FALSE;
01509    if (ctxvis->haveAccumBuffer && !bufvis->haveAccumBuffer)
01510       return GL_FALSE;
01511    if (ctxvis->haveDepthBuffer && !bufvis->haveDepthBuffer)
01512       return GL_FALSE;
01513    if (ctxvis->haveStencilBuffer && !bufvis->haveStencilBuffer)
01514       return GL_FALSE;
01515    if (ctxvis->redMask && ctxvis->redMask != bufvis->redMask)
01516       return GL_FALSE;
01517    if (ctxvis->greenMask && ctxvis->greenMask != bufvis->greenMask)
01518       return GL_FALSE;
01519    if (ctxvis->blueMask && ctxvis->blueMask != bufvis->blueMask)
01520       return GL_FALSE;
01521 #if 0
01522    /* disabled (see bug 11161) */
01523    if (ctxvis->depthBits && ctxvis->depthBits != bufvis->depthBits)
01524       return GL_FALSE;
01525 #endif
01526    if (ctxvis->stencilBits && ctxvis->stencilBits != bufvis->stencilBits)
01527       return GL_FALSE;
01528 
01529    return GL_TRUE;
01530 }
01531 
01532 
01539 static void
01540 initialize_framebuffer_size(GLcontext *ctx, GLframebuffer *fb)
01541 {
01542    GLuint width, height;
01543    if (ctx->Driver.GetBufferSize) {
01544       ctx->Driver.GetBufferSize(fb, &width, &height);
01545       if (ctx->Driver.ResizeBuffers)
01546          ctx->Driver.ResizeBuffers(ctx, fb, width, height);
01547       fb->Initialized = GL_TRUE;
01548    }
01549 }
01550 
01551 
01566 void
01567 _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
01568                     GLframebuffer *readBuffer )
01569 {
01570    if (MESA_VERBOSE & VERBOSE_API)
01571       _mesa_debug(newCtx, "_mesa_make_current()\n");
01572 
01573    /* Check that the context's and framebuffer's visuals are compatible.
01574     */
01575    if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) {
01576       if (!check_compatible(newCtx, drawBuffer)) {
01577          _mesa_warning(newCtx,
01578               "MakeCurrent: incompatible visuals for context and drawbuffer");
01579          return;
01580       }
01581    }
01582    if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) {
01583       if (!check_compatible(newCtx, readBuffer)) {
01584          _mesa_warning(newCtx,
01585               "MakeCurrent: incompatible visuals for context and readbuffer");
01586          return;
01587       }
01588    }
01589 
01590    /* We used to call _glapi_check_multithread() here.  Now do it in drivers */
01591    _glapi_set_context((void *) newCtx);
01592    ASSERT(_mesa_get_current_context() == newCtx);
01593 
01594    if (!newCtx) {
01595       _glapi_set_dispatch(NULL);  /* none current */
01596    }
01597    else {
01598       _glapi_set_dispatch(newCtx->CurrentDispatch);
01599 
01600       if (drawBuffer && readBuffer) {
01601      /* TODO: check if newCtx and buffer's visual match??? */
01602 
01603          ASSERT(drawBuffer->Name == 0);
01604          ASSERT(readBuffer->Name == 0);
01605          _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
01606          _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
01607 
01608          /*
01609           * Only set the context's Draw/ReadBuffer fields if they're NULL
01610           * or not bound to a user-created FBO.
01611           */
01612          if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
01613             _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
01614          }
01615          if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
01616             _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
01617          }
01618 
01619          /* XXX only set this flag if we're really changing the draw/read
01620           * framebuffer bindings.
01621           */
01622      newCtx->NewState |= _NEW_BUFFERS;
01623 
01624 #if 1
01625          /* We want to get rid of these lines: */
01626 
01627 #if _HAVE_FULL_GL
01628          if (!drawBuffer->Initialized) {
01629             initialize_framebuffer_size(newCtx, drawBuffer);
01630          }
01631          if (readBuffer != drawBuffer && !readBuffer->Initialized) {
01632             initialize_framebuffer_size(newCtx, readBuffer);
01633          }
01634 
01635      _mesa_resizebuffers(newCtx);
01636 #endif
01637 
01638 #else
01639          /* We want the drawBuffer and readBuffer to be initialized by
01640           * the driver.
01641           * This generally means the Width and Height match the actual
01642           * window size and the renderbuffers (both hardware and software
01643           * based) are allocated to match.  The later can generally be
01644           * done with a call to _mesa_resize_framebuffer().
01645           *
01646           * It's theoretically possible for a buffer to have zero width
01647           * or height, but for now, assert check that the driver did what's
01648           * expected of it.
01649           */
01650          ASSERT(drawBuffer->Width > 0);
01651          ASSERT(drawBuffer->Height > 0);
01652 #endif
01653 
01654          if (newCtx->FirstTimeCurrent) {
01655             /* set initial viewport and scissor size now */
01656             _mesa_set_viewport(newCtx, 0, 0,
01657                                drawBuffer->Width, drawBuffer->Height);
01658         _mesa_set_scissor(newCtx, 0, 0,
01659                   drawBuffer->Width, drawBuffer->Height );
01660             check_context_limits(newCtx);
01661          }
01662       }
01663 
01664       /* We can use this to help debug user's problems.  Tell them to set
01665        * the MESA_INFO env variable before running their app.  Then the
01666        * first time each context is made current we'll print some useful
01667        * information.
01668        */
01669       if (newCtx->FirstTimeCurrent) {
01670      if (_mesa_getenv("MESA_INFO")) {
01671         _mesa_print_info();
01672      }
01673      newCtx->FirstTimeCurrent = GL_FALSE;
01674       }
01675    }
01676 }
01677 
01678 
01685 GLboolean
01686 _mesa_share_state(GLcontext *ctx, GLcontext *ctxToShare)
01687 {
01688    if (ctx && ctxToShare && ctx->Shared && ctxToShare->Shared) {
01689       struct gl_shared_state *oldSharedState = ctx->Shared;
01690 
01691       ctx->Shared = ctxToShare->Shared;
01692       ctx->Shared->RefCount++;
01693 
01694       update_default_objects(ctx);
01695 
01696       oldSharedState->RefCount--;
01697       if (oldSharedState->RefCount == 0) {
01698          free_shared_state(ctx, oldSharedState);
01699       }
01700 
01701       return GL_TRUE;
01702    }
01703    else {
01704       return GL_FALSE;
01705    }
01706 }
01707 
01708 
01709 
01717 GLcontext *
01718 _mesa_get_current_context( void )
01719 {
01720    return (GLcontext *) _glapi_get_context();
01721 }
01722 
01723 
01736 struct _glapi_table *
01737 _mesa_get_dispatch(GLcontext *ctx)
01738 {
01739    return ctx->CurrentDispatch;
01740 }
01741 
01745 /**********************************************************************/
01747 /**********************************************************************/
01762 void
01763 _mesa_record_error(GLcontext *ctx, GLenum error)
01764 {
01765    if (!ctx)
01766       return;
01767 
01768    if (ctx->ErrorValue == GL_NO_ERROR) {
01769       ctx->ErrorValue = error;
01770    }
01771 
01772    /* Call device driver's error handler, if any.  This is used on the Mac. */
01773    if (ctx->Driver.Error) {
01774       ctx->Driver.Error(ctx);
01775    }
01776 }
01777 
01778 
01785 void GLAPIENTRY
01786 _mesa_Finish(void)
01787 {
01788    GET_CURRENT_CONTEXT(ctx);
01789    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
01790    if (ctx->Driver.Finish) {
01791       ctx->Driver.Finish(ctx);
01792    }
01793 }
01794 
01795 
01802 void GLAPIENTRY
01803 _mesa_Flush(void)
01804 {
01805    GET_CURRENT_CONTEXT(ctx);
01806    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
01807    if (ctx->Driver.Flush) {
01808       ctx->Driver.Flush(ctx);
01809    }
01810 }
01811 
01812 

Generated on Mon May 28 2012 04:19:57 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.