3 * Mesa context/visual/framebuffer management functions.
8 * Mesa 3-D graphics library
11 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included
21 * in all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
27 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 * \mainpage Mesa Main Module
35 * \section MainIntroduction Introduction
37 * The Mesa Main module consists of all the files in the main/ directory.
38 * Among the features of this module are:
40 * <LI> Structures to represent most GL state </LI>
41 * <LI> State set/get functions </LI>
42 * <LI> Display lists </LI>
43 * <LI> Texture unit, object and image handling </LI>
44 * <LI> Matrix and attribute stacks </LI>
47 * Other modules are responsible for API dispatch, vertex transformation,
48 * point/line/triangle setup, rasterization, vertex array caching,
49 * vertex/fragment programs/shaders, etc.
52 * \section AboutDoxygen About Doxygen
54 * If you're viewing this information as Doxygen-generated HTML you'll
55 * see the documentation index at the top of this page.
57 * The first line lists the Mesa source code modules.
58 * The second line lists the indexes available for viewing the documentation
61 * Selecting the <b>Main page</b> link will display a summary of the module
64 * Selecting <b>Data Structures</b> will list all C structures.
66 * Selecting the <b>File List</b> link will list all the source files in
68 * Selecting a filename will show a list of all functions defined in that file.
70 * Selecting the <b>Data Fields</b> link will display a list of all
71 * documented structure members.
73 * Selecting the <b>Globals</b> link will display a list
74 * of all functions, structures, global variables and macros in the module.
85 #include "bufferobj.h"
93 #include "extensions.h"
98 #include "glapioffsets.h"
99 #include "histogram.h"
110 #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
114 #include "simple_list.h"
117 #include "texcompress.h"
118 #include "teximage.h"
120 #include "texstate.h"
125 #include "math/m_translate.h"
126 #include "math/m_matrix.h"
127 #include "math/m_xform.h"
128 #include "math/mathmod.h"
132 #include "sparc/sparc.h"
136 int MESA_VERBOSE
= 0;
139 #ifndef MESA_DEBUG_FLAGS
140 int MESA_DEBUG_FLAGS
= 0;
144 /* ubyte -> float conversion */
145 GLfloat _mesa_ubyte_to_float_color_tab
[256];
148 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
);
151 /**********************************************************************/
152 /** \name OpenGL SI-style interface (new in Mesa 3.5)
155 * \note Most of these functions are never called in the Mesa subset.
161 * Destroy context callback.
164 * \return GL_TRUE on success, or GL_FALSE on failure.
167 * Called by window system/device driver (via __GLexports::destroyCurrent) when
168 * the rendering context is to be destroyed.
171 * Frees the context data and the context structure.
174 _mesa_destroyContext(__GLcontext
*gc
)
177 _mesa_free_context_data(gc
);
184 * Unbind context callback.
187 * \return GL_TRUE on success, or GL_FALSE on failure.
190 * Called by window system/device driver (via __GLexports::loseCurrent)
191 * when the rendering context is made non-current.
197 _mesa_loseCurrent(__GLcontext
*gc
)
199 /* XXX unbind context from thread */
205 * Bind context callback.
208 * \return GL_TRUE on success, or GL_FALSE on failure.
211 * Called by window system/device driver (via __GLexports::makeCurrent)
212 * when the rendering context is made current.
218 _mesa_makeCurrent(__GLcontext
*gc
)
220 /* XXX bind context to thread */
226 * Share context callback.
229 * \param gcShare shared context.
230 * \return GL_TRUE on success, or GL_FALSE on failure.
233 * Called by window system/device driver (via __GLexports::shareContext)
236 * Update the shared context reference count, gl_shared_state::RefCount.
239 _mesa_shareContext(__GLcontext
*gc
, __GLcontext
*gcShare
)
241 if (gc
&& gcShare
&& gc
->Shared
&& gcShare
->Shared
) {
242 gc
->Shared
->RefCount
--;
243 if (gc
->Shared
->RefCount
== 0) {
244 free_shared_state(gc
, gc
->Shared
);
246 gc
->Shared
= gcShare
->Shared
;
247 gc
->Shared
->RefCount
++;
258 * Copy context callback.
261 _mesa_copyContext(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
)
264 _mesa_copy_context( src
, dst
, mask
);
275 _mesa_forceCurrent(__GLcontext
*gc
)
282 * Windows/buffer resizing notification callback.
284 * \param gc GL context.
285 * \return GL_TRUE on success, or GL_FALSE on failure.
288 _mesa_notifyResize(__GLcontext
*gc
)
291 GLuint width
, height
;
292 __GLdrawablePrivate
*d
= gc
->imports
.getDrawablePrivate(gc
);
293 if (!d
|| !d
->getDrawableSize
)
295 d
->getDrawableSize( d
, &x
, &y
, &width
, &height
);
296 /* update viewport, resize software buffers, etc. */
301 * Window/buffer destruction notification callback.
303 * \param gc GL context.
305 * Called when the context's window/buffer is going to be destroyed.
310 _mesa_notifyDestroy(__GLcontext
*gc
)
312 /* Unbind from it. */
317 * Swap buffers notification callback.
319 * \param gc GL context.
321 * Called by window system just before swapping buffers.
322 * We have to finish any pending rendering.
325 _mesa_notifySwapBuffers(__GLcontext
*gc
)
327 FLUSH_VERTICES( gc
, 0 );
331 struct __GLdispatchStateRec
*
332 _mesa_dispatchExec(__GLcontext
*gc
)
340 _mesa_beginDispatchOverride(__GLcontext
*gc
)
347 _mesa_endDispatchOverride(__GLcontext
*gc
)
356 * The window system will call these functions when it needs Mesa to do
359 * \note Device drivers should override these functions! For example,
360 * the Xlib driver should plug in the XMesa*-style functions into this
361 * structure. The XMesa-style functions should then call the _mesa_*
362 * version of these functions. This is an approximation to OO design
363 * (inheritance and virtual functions).
372 _mesa_init_default_exports(__GLexports
*exports
)
375 exports
->destroyContext
= _mesa_destroyContext
;
376 exports
->loseCurrent
= _mesa_loseCurrent
;
377 exports
->makeCurrent
= _mesa_makeCurrent
;
378 exports
->shareContext
= _mesa_shareContext
;
379 exports
->copyContext
= _mesa_copyContext
;
380 exports
->forceCurrent
= _mesa_forceCurrent
;
381 exports
->notifyResize
= _mesa_notifyResize
;
382 exports
->notifyDestroy
= _mesa_notifyDestroy
;
383 exports
->notifySwapBuffers
= _mesa_notifySwapBuffers
;
384 exports
->dispatchExec
= _mesa_dispatchExec
;
385 exports
->beginDispatchOverride
= _mesa_beginDispatchOverride
;
386 exports
->endDispatchOverride
= _mesa_endDispatchOverride
;
393 * Exported OpenGL SI interface.
396 __glCoreCreateContext(__GLimports
*imports
, __GLcontextModes
*modes
)
400 ctx
= (GLcontext
*) (*imports
->calloc
)(NULL
, 1, sizeof(GLcontext
));
405 /* XXX doesn't work at this time */
406 _mesa_initialize_context(ctx
, modes
, NULL
, NULL
, NULL
);
407 ctx
->imports
= *imports
;
413 * Exported OpenGL SI interface.
416 __glCoreNopDispatch(void)
420 __gl_dispatch
= __glNopDispatchState
;
423 _glapi_set_dispatch(NULL
);
430 /**********************************************************************/
431 /** \name GL Visual allocation/destruction */
432 /**********************************************************************/
436 * Allocates a GLvisual structure and initializes it via
437 * _mesa_initialize_visual().
439 * \param rgbFlag GL_TRUE for RGB(A) mode, GL_FALSE for Color Index mode.
440 * \param dbFlag double buffering
441 * \param stereoFlag stereo buffer
442 * \param depthBits requested bits per depth buffer value. Any value in [0, 32]
443 * is acceptable but the actual depth type will be GLushort or GLuint as
445 * \param stencilBits requested minimum bits per stencil buffer value
446 * \param accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits number of bits per color component in accum buffer.
447 * \param indexBits number of bits per pixel if \p rgbFlag is GL_FALSE
448 * \param redBits number of bits per color component in frame buffer for RGB(A)
449 * mode. We always use 8 in core Mesa though.
450 * \param greenBits same as above.
451 * \param blueBits same as above.
452 * \param alphaBits same as above.
453 * \param numSamples not really used.
455 * \return pointer to new GLvisual or NULL if requested parameters can't be
458 * \note Need to add params for level and numAuxBuffers (at least)
461 _mesa_create_visual( GLboolean rgbFlag
,
463 GLboolean stereoFlag
,
472 GLint accumGreenBits
,
474 GLint accumAlphaBits
,
477 GLvisual
*vis
= (GLvisual
*) CALLOC( sizeof(GLvisual
) );
479 if (!_mesa_initialize_visual(vis
, rgbFlag
, dbFlag
, stereoFlag
,
480 redBits
, greenBits
, blueBits
, alphaBits
,
481 indexBits
, depthBits
, stencilBits
,
482 accumRedBits
, accumGreenBits
,
483 accumBlueBits
, accumAlphaBits
,
493 * Makes some sanity checks and fills in the fields of the
494 * GLvisual structure with the given parameters.
496 * \return GL_TRUE on success, or GL_FALSE on failure.
498 * \sa _mesa_create_visual() above for the parameter description.
500 * \note Need to add params for level and numAuxBuffers (at least)
503 _mesa_initialize_visual( GLvisual
*vis
,
506 GLboolean stereoFlag
,
515 GLint accumGreenBits
,
517 GLint accumAlphaBits
,
522 /* This is to catch bad values from device drivers not updated for
523 * Mesa 3.3. Some device drivers just passed 1. That's a REALLY
524 * bad value now (a 1-bit depth buffer!?!).
526 assert(depthBits
== 0 || depthBits
> 1);
528 if (depthBits
< 0 || depthBits
> 32) {
531 if (stencilBits
< 0 || stencilBits
> (GLint
) (8 * sizeof(GLstencil
))) {
534 if (accumRedBits
< 0 || accumRedBits
> (GLint
) (8 * sizeof(GLaccum
))) {
537 if (accumGreenBits
< 0 || accumGreenBits
> (GLint
) (8 * sizeof(GLaccum
))) {
540 if (accumBlueBits
< 0 || accumBlueBits
> (GLint
) (8 * sizeof(GLaccum
))) {
543 if (accumAlphaBits
< 0 || accumAlphaBits
> (GLint
) (8 * sizeof(GLaccum
))) {
547 vis
->rgbMode
= rgbFlag
;
548 vis
->doubleBufferMode
= dbFlag
;
549 vis
->stereoMode
= stereoFlag
;
551 vis
->redBits
= redBits
;
552 vis
->greenBits
= greenBits
;
553 vis
->blueBits
= blueBits
;
554 vis
->alphaBits
= alphaBits
;
556 vis
->indexBits
= indexBits
;
557 vis
->depthBits
= depthBits
;
558 vis
->accumRedBits
= (accumRedBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
559 vis
->accumGreenBits
= (accumGreenBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
560 vis
->accumBlueBits
= (accumBlueBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
561 vis
->accumAlphaBits
= (accumAlphaBits
> 0) ? (8 * sizeof(GLaccum
)) : 0;
562 vis
->stencilBits
= (stencilBits
> 0) ? (8 * sizeof(GLstencil
)) : 0;
564 vis
->haveAccumBuffer
= accumRedBits
> 0;
565 vis
->haveDepthBuffer
= depthBits
> 0;
566 vis
->haveStencilBuffer
= stencilBits
> 0;
568 vis
->numAuxBuffers
= 0;
571 vis
->samples
= numSamples
;
578 * Destroy a visual and free its memory.
582 * Frees the visual structure.
585 _mesa_destroy_visual( GLvisual
*vis
)
593 /**********************************************************************/
594 /** \name GL Framebuffer allocation/destruction */
595 /**********************************************************************/
599 * Allocate a GLframebuffer structure and initializes it via
600 * _mesa_initialize_framebuffer().
602 * A GLframebuffer is a structure which encapsulates the depth, stencil and
603 * accum buffers and related parameters.
605 * Note that the actual depth/stencil/accum/etc buffers are not allocated
606 * at this time. It's up to the device driver and/or swrast module to
607 * allocate them as needed.
609 * \param visual a GLvisual pointer (we copy the struct contents)
610 * \param softwareDepth create/use a software depth buffer?
611 * \param softwareStencil create/use a software stencil buffer?
612 * \param softwareAccum create/use a software accum buffer?
613 * \param softwareAlpha create/use a software alpha buffer?
615 * \return pointer to new GLframebuffer struct or NULL if error.
617 * \note Need to add softwareAuxBuffers parameter.
620 _mesa_create_framebuffer( const GLvisual
*visual
,
621 GLboolean softwareDepth
,
622 GLboolean softwareStencil
,
623 GLboolean softwareAccum
,
624 GLboolean softwareAlpha
)
626 GLframebuffer
*buffer
= CALLOC_STRUCT(gl_frame_buffer
);
629 _mesa_initialize_framebuffer(buffer
, visual
,
630 softwareDepth
, softwareStencil
,
631 softwareAccum
, softwareAlpha
);
638 * Makes some sanity checks and fills in the fields of the
639 * GLframebuffer structure with the given parameters.
641 * \sa _mesa_create_framebuffer() above for the parameter description.
644 _mesa_initialize_framebuffer( GLframebuffer
*buffer
,
645 const GLvisual
*visual
,
646 GLboolean softwareDepth
,
647 GLboolean softwareStencil
,
648 GLboolean softwareAccum
,
649 GLboolean softwareAlpha
)
651 GLboolean softwareAux
= GL_FALSE
;
655 _mesa_bzero(buffer
, sizeof(GLframebuffer
));
658 if (softwareDepth
) {
659 assert(visual
->depthBits
> 0);
661 if (softwareStencil
) {
662 assert(visual
->stencilBits
> 0);
665 assert(visual
->rgbMode
);
666 assert(visual
->accumRedBits
> 0);
667 assert(visual
->accumGreenBits
> 0);
668 assert(visual
->accumBlueBits
> 0);
671 assert(visual
->rgbMode
);
672 assert(visual
->alphaBits
> 0);
675 buffer
->Visual
= *visual
;
676 buffer
->UseSoftwareDepthBuffer
= softwareDepth
;
677 buffer
->UseSoftwareStencilBuffer
= softwareStencil
;
678 buffer
->UseSoftwareAccumBuffer
= softwareAccum
;
679 buffer
->UseSoftwareAlphaBuffers
= softwareAlpha
;
680 buffer
->UseSoftwareAuxBuffers
= softwareAux
;
685 * Free a framebuffer struct and its buffers.
687 * Calls _mesa_free_framebuffer_data() and frees the structure.
690 _mesa_destroy_framebuffer( GLframebuffer
*buffer
)
693 _mesa_free_framebuffer_data(buffer
);
700 * Free the data hanging off of \p buffer, but not \p buffer itself.
702 * \param buffer framebuffer.
704 * Frees all the buffers associated with the structure.
707 _mesa_free_framebuffer_data( GLframebuffer
*buffer
)
712 if (buffer
->UseSoftwareDepthBuffer
&& buffer
->DepthBuffer
) {
713 MESA_PBUFFER_FREE( buffer
->DepthBuffer
);
714 buffer
->DepthBuffer
= NULL
;
716 if (buffer
->UseSoftwareAccumBuffer
&& buffer
->Accum
) {
717 MESA_PBUFFER_FREE( buffer
->Accum
);
718 buffer
->Accum
= NULL
;
720 if (buffer
->UseSoftwareStencilBuffer
&& buffer
->Stencil
) {
721 MESA_PBUFFER_FREE( buffer
->Stencil
);
722 buffer
->Stencil
= NULL
;
724 if (buffer
->UseSoftwareAlphaBuffers
){
725 if (buffer
->FrontLeftAlpha
) {
726 MESA_PBUFFER_FREE( buffer
->FrontLeftAlpha
);
727 buffer
->FrontLeftAlpha
= NULL
;
729 if (buffer
->BackLeftAlpha
) {
730 MESA_PBUFFER_FREE( buffer
->BackLeftAlpha
);
731 buffer
->BackLeftAlpha
= NULL
;
733 if (buffer
->FrontRightAlpha
) {
734 MESA_PBUFFER_FREE( buffer
->FrontRightAlpha
);
735 buffer
->FrontRightAlpha
= NULL
;
737 if (buffer
->BackRightAlpha
) {
738 MESA_PBUFFER_FREE( buffer
->BackRightAlpha
);
739 buffer
->BackRightAlpha
= NULL
;
747 /**********************************************************************/
748 /** \name Context allocation, initialization, destroying
750 * The purpose of the most initialization functions here is to provide the
751 * default state values according to the OpenGL specification.
753 /**********************************************************************/
757 * One-time initialization mutex lock.
759 * \sa Used by one_time_init().
761 _glthread_DECLARE_STATIC_MUTEX(OneTimeLock
);
764 * Calls all the various one-time-init functions in Mesa.
766 * While holding a global mutex lock, calls several initialization functions,
767 * and sets the glapi callbacks if the \c MESA_DEBUG environment variable is
770 * \sa _mesa_init_lists(), _math_init().
773 one_time_init( GLcontext
*ctx
)
775 static GLboolean alreadyCalled
= GL_FALSE
;
777 _glthread_LOCK_MUTEX(OneTimeLock
);
778 if (!alreadyCalled
) {
781 /* do some implementation tests */
782 assert( sizeof(GLbyte
) == 1 );
783 assert( sizeof(GLubyte
) == 1 );
784 assert( sizeof(GLshort
) == 2 );
785 assert( sizeof(GLushort
) == 2 );
786 assert( sizeof(GLint
) == 4 );
787 assert( sizeof(GLuint
) == 4 );
794 for (i
= 0; i
< 256; i
++) {
795 _mesa_ubyte_to_float_color_tab
[i
] = (float) i
/ 255.0F
;
800 _mesa_init_sparc_glapi_relocs();
802 if (_mesa_getenv("MESA_DEBUG")) {
803 _glapi_noop_enable_warnings(GL_TRUE
);
804 #ifndef GLX_DIRECT_RENDERING
805 /* libGL from before 2002/06/28 don't have this function. Someday,
806 * when newer libGL libs are common, remove the #ifdef test. This
807 * only serves to print warnings when calling undefined GL functions.
809 _glapi_set_warning_func( (_glapi_warning_func
) _mesa_warning
);
813 _glapi_noop_enable_warnings(GL_FALSE
);
816 #if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
817 _mesa_debug(ctx
, "Mesa DEBUG build %s %s\n", __DATE__
, __TIME__
);
820 alreadyCalled
= GL_TRUE
;
822 _glthread_UNLOCK_MUTEX(OneTimeLock
);
827 * Allocate and initialize a shared context state structure.
828 * Initializes the display list, texture objects and vertex programs hash
829 * tables, allocates the texture objects. If it runs out of memory, frees
830 * everything already allocated before returning NULL.
832 * \return pointer to a gl_shared_state structure on success, or NULL on
836 alloc_shared_state( GLcontext
*ctx
)
838 struct gl_shared_state
*ss
= CALLOC_STRUCT(gl_shared_state
);
844 _glthread_INIT_MUTEX(ss
->Mutex
);
846 ss
->DisplayList
= _mesa_NewHashTable();
847 ss
->TexObjects
= _mesa_NewHashTable();
848 #if FEATURE_NV_vertex_program || FEATURE_NV_fragment_program
849 ss
->Programs
= _mesa_NewHashTable();
852 #if FEATURE_ARB_vertex_program
853 ss
->DefaultVertexProgram
= ctx
->Driver
.NewProgram(ctx
, GL_VERTEX_PROGRAM_ARB
, 0);
854 if (!ss
->DefaultVertexProgram
)
857 #if FEATURE_ARB_fragment_program
858 ss
->DefaultFragmentProgram
= ctx
->Driver
.NewProgram(ctx
, GL_FRAGMENT_PROGRAM_ARB
, 0);
859 if (!ss
->DefaultFragmentProgram
)
863 ss
->BufferObjects
= _mesa_NewHashTable();
865 ss
->Default1D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_1D
);
869 ss
->Default2D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_2D
);
873 ss
->Default3D
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_3D
);
877 ss
->DefaultCubeMap
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_CUBE_MAP_ARB
);
878 if (!ss
->DefaultCubeMap
)
881 ss
->DefaultRect
= (*ctx
->Driver
.NewTextureObject
)(ctx
, 0, GL_TEXTURE_RECTANGLE_NV
);
882 if (!ss
->DefaultRect
)
885 /* Effectively bind the default textures to all texture units */
886 ss
->Default1D
->RefCount
+= MAX_TEXTURE_IMAGE_UNITS
;
887 ss
->Default2D
->RefCount
+= MAX_TEXTURE_IMAGE_UNITS
;
888 ss
->Default3D
->RefCount
+= MAX_TEXTURE_IMAGE_UNITS
;
889 ss
->DefaultCubeMap
->RefCount
+= MAX_TEXTURE_IMAGE_UNITS
;
890 ss
->DefaultRect
->RefCount
+= MAX_TEXTURE_IMAGE_UNITS
;
895 /* Ran out of memory at some point. Free everything and return NULL */
897 _mesa_DeleteHashTable(ss
->DisplayList
);
899 _mesa_DeleteHashTable(ss
->TexObjects
);
900 #if FEATURE_NV_vertex_program
902 _mesa_DeleteHashTable(ss
->Programs
);
904 #if FEATURE_ARB_vertex_program
905 if (ss
->DefaultVertexProgram
)
906 ctx
->Driver
.DeleteProgram(ctx
, ss
->DefaultVertexProgram
);
908 #if FEATURE_ARB_fragment_program
909 if (ss
->DefaultFragmentProgram
)
910 ctx
->Driver
.DeleteProgram(ctx
, ss
->DefaultFragmentProgram
);
912 #if FEATURE_ARB_vertex_buffer_object
913 if (ss
->BufferObjects
)
914 _mesa_DeleteHashTable(ss
->BufferObjects
);
918 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default1D
);
920 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default2D
);
922 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default3D
);
923 if (ss
->DefaultCubeMap
)
924 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->DefaultCubeMap
);
926 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->DefaultRect
);
933 * Deallocate a shared state context and all children structures.
935 * \param ctx GL context.
936 * \param ss shared state pointer.
938 * Frees the display lists, the texture objects (calling the driver texture
939 * deletion callback to free its private data) and the vertex programs, as well
940 * as their hash tables.
942 * \sa alloc_shared_state().
945 free_shared_state( GLcontext
*ctx
, struct gl_shared_state
*ss
)
947 /* Free display lists */
949 GLuint list
= _mesa_HashFirstEntry(ss
->DisplayList
);
951 _mesa_destroy_list(ctx
, list
);
957 _mesa_DeleteHashTable(ss
->DisplayList
);
959 /* Free texture objects */
960 ASSERT(ctx
->Driver
.DeleteTexture
);
961 /* the default textures */
962 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default1D
);
963 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default2D
);
964 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->Default3D
);
965 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->DefaultCubeMap
);
966 (*ctx
->Driver
.DeleteTexture
)(ctx
, ss
->DefaultRect
);
967 /* all other textures */
969 GLuint texName
= _mesa_HashFirstEntry(ss
->TexObjects
);
971 struct gl_texture_object
*texObj
= (struct gl_texture_object
*)
972 _mesa_HashLookup(ss
->TexObjects
, texName
);
974 (*ctx
->Driver
.DeleteTexture
)(ctx
, texObj
);
975 _mesa_HashRemove(ss
->TexObjects
, texName
);
981 _mesa_DeleteHashTable(ss
->TexObjects
);
983 #if FEATURE_NV_vertex_program
984 /* Free vertex programs */
986 GLuint prog
= _mesa_HashFirstEntry(ss
->Programs
);
988 struct program
*p
= (struct program
*) _mesa_HashLookup(ss
->Programs
,
991 ctx
->Driver
.DeleteProgram(ctx
, p
);
992 _mesa_HashRemove(ss
->Programs
, prog
);
998 _mesa_DeleteHashTable(ss
->Programs
);
1000 #if FEATURE_ARB_vertex_program
1001 _mesa_delete_program(ctx
, ss
->DefaultVertexProgram
);
1003 #if FEATURE_ARB_fragment_program
1004 _mesa_delete_program(ctx
, ss
->DefaultFragmentProgram
);
1007 #if FEATURE_ARB_vertex_buffer_object
1008 _mesa_DeleteHashTable(ss
->BufferObjects
);
1010 _glthread_DESTROY_MUTEX(ss
->Mutex
);
1017 * Initialize fields of gl_current_attrib (aka ctx->Current.*)
1020 _mesa_init_current( GLcontext
*ctx
)
1025 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
1026 ASSIGN_4V( ctx
->Current
.Attrib
[i
], 0.0, 0.0, 0.0, 1.0 );
1028 /* special cases: */
1029 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_WEIGHT
], 1.0, 0.0, 0.0, 1.0 );
1030 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
], 0.0, 0.0, 1.0, 1.0 );
1031 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
], 1.0, 1.0, 1.0, 1.0 );
1032 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
], 0.0, 0.0, 0.0, 1.0 );
1033 ASSIGN_4V( ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
], 0.0, 0.0, 0.0, 0.0 );
1035 ctx
->Current
.Index
= 1;
1036 ctx
->Current
.EdgeFlag
= GL_TRUE
;
1041 * Initialize fields of gl_constants (aka ctx->Const.*).
1042 * Use defaults from config.h. The device drivers will often override
1043 * some of these values (such as number of texture units).
1046 _mesa_init_constants( GLcontext
*ctx
)
1050 assert(MAX_TEXTURE_LEVELS
>= MAX_3D_TEXTURE_LEVELS
);
1051 assert(MAX_TEXTURE_LEVELS
>= MAX_CUBE_TEXTURE_LEVELS
);
1053 /* Constants, may be overriden (usually only reduced) by device drivers */
1054 ctx
->Const
.MaxTextureLevels
= MAX_TEXTURE_LEVELS
;
1055 ctx
->Const
.Max3DTextureLevels
= MAX_3D_TEXTURE_LEVELS
;
1056 ctx
->Const
.MaxCubeTextureLevels
= MAX_CUBE_TEXTURE_LEVELS
;
1057 ctx
->Const
.MaxTextureRectSize
= MAX_TEXTURE_RECT_SIZE
;
1058 ctx
->Const
.MaxTextureUnits
= MAX_TEXTURE_UNITS
;
1059 ctx
->Const
.MaxTextureCoordUnits
= MAX_TEXTURE_COORD_UNITS
;
1060 ctx
->Const
.MaxTextureImageUnits
= MAX_TEXTURE_IMAGE_UNITS
;
1061 ctx
->Const
.MaxTextureMaxAnisotropy
= MAX_TEXTURE_MAX_ANISOTROPY
;
1062 ctx
->Const
.MaxTextureLodBias
= MAX_TEXTURE_LOD_BIAS
;
1063 ctx
->Const
.MaxArrayLockSize
= MAX_ARRAY_LOCK_SIZE
;
1064 ctx
->Const
.SubPixelBits
= SUB_PIXEL_BITS
;
1065 ctx
->Const
.MinPointSize
= MIN_POINT_SIZE
;
1066 ctx
->Const
.MaxPointSize
= MAX_POINT_SIZE
;
1067 ctx
->Const
.MinPointSizeAA
= MIN_POINT_SIZE
;
1068 ctx
->Const
.MaxPointSizeAA
= MAX_POINT_SIZE
;
1069 ctx
->Const
.PointSizeGranularity
= (GLfloat
) POINT_SIZE_GRANULARITY
;
1070 ctx
->Const
.MinLineWidth
= MIN_LINE_WIDTH
;
1071 ctx
->Const
.MaxLineWidth
= MAX_LINE_WIDTH
;
1072 ctx
->Const
.MinLineWidthAA
= MIN_LINE_WIDTH
;
1073 ctx
->Const
.MaxLineWidthAA
= MAX_LINE_WIDTH
;
1074 ctx
->Const
.LineWidthGranularity
= (GLfloat
) LINE_WIDTH_GRANULARITY
;
1075 ctx
->Const
.MaxColorTableSize
= MAX_COLOR_TABLE_SIZE
;
1076 ctx
->Const
.MaxConvolutionWidth
= MAX_CONVOLUTION_WIDTH
;
1077 ctx
->Const
.MaxConvolutionHeight
= MAX_CONVOLUTION_HEIGHT
;
1078 ctx
->Const
.MaxClipPlanes
= MAX_CLIP_PLANES
;
1079 ctx
->Const
.MaxLights
= MAX_LIGHTS
;
1080 ctx
->Const
.MaxShininess
= 128.0;
1081 ctx
->Const
.MaxSpotExponent
= 128.0;
1082 ctx
->Const
.MaxViewportWidth
= MAX_WIDTH
;
1083 ctx
->Const
.MaxViewportHeight
= MAX_HEIGHT
;
1084 #if FEATURE_ARB_vertex_program
1085 ctx
->Const
.MaxVertexProgramInstructions
= MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS
;
1086 ctx
->Const
.MaxVertexProgramAttribs
= MAX_NV_VERTEX_PROGRAM_INPUTS
;
1087 ctx
->Const
.MaxVertexProgramTemps
= MAX_NV_VERTEX_PROGRAM_TEMPS
;
1088 ctx
->Const
.MaxVertexProgramLocalParams
= MAX_NV_VERTEX_PROGRAM_PARAMS
;
1089 ctx
->Const
.MaxVertexProgramEnvParams
= MAX_NV_VERTEX_PROGRAM_PARAMS
;/*XXX*/
1090 ctx
->Const
.MaxVertexProgramAddressRegs
= MAX_VERTEX_PROGRAM_ADDRESS_REGS
;
1092 #if FEATURE_ARB_fragment_program
1093 ctx
->Const
.MaxFragmentProgramInstructions
= MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS
;
1094 ctx
->Const
.MaxFragmentProgramAttribs
= MAX_NV_FRAGMENT_PROGRAM_INPUTS
;
1095 ctx
->Const
.MaxFragmentProgramTemps
= MAX_NV_FRAGMENT_PROGRAM_TEMPS
;
1096 ctx
->Const
.MaxFragmentProgramLocalParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
1097 ctx
->Const
.MaxFragmentProgramEnvParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;/*XXX*/
1098 ctx
->Const
.MaxFragmentProgramAddressRegs
= MAX_FRAGMENT_PROGRAM_ADDRESS_REGS
;
1099 ctx
->Const
.MaxFragmentProgramAluInstructions
= MAX_FRAGMENT_PROGRAM_ALU_INSTRUCTIONS
;
1100 ctx
->Const
.MaxFragmentProgramTexInstructions
= MAX_FRAGMENT_PROGRAM_TEX_INSTRUCTIONS
;
1101 ctx
->Const
.MaxFragmentProgramTexIndirections
= MAX_FRAGMENT_PROGRAM_TEX_INDIRECTIONS
;
1103 ctx
->Const
.MaxProgramMatrices
= MAX_PROGRAM_MATRICES
;
1104 ctx
->Const
.MaxProgramMatrixStackDepth
= MAX_PROGRAM_MATRIX_STACK_DEPTH
;
1106 /* If we're running in the X server, do bounds checking to prevent
1107 * segfaults and server crashes!
1109 #if defined(XFree86LOADER) && defined(IN_MODULE)
1110 ctx
->Const
.CheckArrayBounds
= GL_TRUE
;
1112 ctx
->Const
.CheckArrayBounds
= GL_FALSE
;
1115 ctx
->Const
.MaxDrawBuffers
= MAX_DRAW_BUFFERS
;
1117 ctx
->Const
.ColorReadFormat
= GL_RGBA
;
1118 ctx
->Const
.ColorReadType
= GL_UNSIGNED_BYTE
;
1121 ASSERT(ctx
->Const
.MaxTextureUnits
== MAX2(ctx
->Const
.MaxTextureImageUnits
, ctx
->Const
.MaxTextureCoordUnits
));
1126 * Initialize the attribute groups in a GL context.
1128 * \param ctx GL context.
1130 * Initializes all the attributes, calling the respective <tt>init*</tt>
1131 * functions for the more complex data structures.
1134 init_attrib_groups( GLcontext
*ctx
)
1139 _mesa_init_constants( ctx
);
1142 _mesa_init_extensions( ctx
);
1144 /* Attribute Groups */
1145 _mesa_init_accum( ctx
);
1146 _mesa_init_attrib( ctx
);
1147 _mesa_init_buffers( ctx
);
1148 _mesa_init_buffer_objects( ctx
);
1149 _mesa_init_color( ctx
);
1150 _mesa_init_colortables( ctx
);
1151 _mesa_init_current( ctx
);
1152 _mesa_init_depth( ctx
);
1153 _mesa_init_debug( ctx
);
1154 _mesa_init_display_list( ctx
);
1155 _mesa_init_eval( ctx
);
1156 _mesa_init_feedback( ctx
);
1157 _mesa_init_fog( ctx
);
1158 _mesa_init_histogram( ctx
);
1159 _mesa_init_hint( ctx
);
1160 _mesa_init_line( ctx
);
1161 _mesa_init_lighting( ctx
);
1162 _mesa_init_matrix( ctx
);
1163 _mesa_init_occlude( ctx
);
1164 _mesa_init_pixel( ctx
);
1165 _mesa_init_point( ctx
);
1166 _mesa_init_polygon( ctx
);
1167 _mesa_init_program( ctx
);
1168 _mesa_init_rastpos( ctx
);
1169 _mesa_init_stencil( ctx
);
1170 _mesa_init_transform( ctx
);
1171 _mesa_init_varray( ctx
);
1172 _mesa_init_viewport( ctx
);
1174 if (!_mesa_init_texture( ctx
))
1177 _mesa_init_texture_s3tc( ctx
);
1178 _mesa_init_texture_fxt1( ctx
);
1181 ctx
->NewState
= _NEW_ALL
;
1182 ctx
->ErrorValue
= (GLenum
) GL_NO_ERROR
;
1184 #if CHAN_TYPE == GL_FLOAT
1185 ctx
->ClampFragmentColors
= GL_FALSE
; /* XXX temporary */
1187 ctx
->ClampFragmentColors
= GL_TRUE
;
1189 ctx
->ClampVertexColors
= GL_TRUE
;
1196 * If the DRI libGL.so library is old, it may not have the entrypoints for
1197 * some recent OpenGL extensions. Dynamically add them now.
1198 * If we're building stand-alone Mesa where libGL.so has both the dispatcher
1199 * and driver code, this won't be an issue (and calling this function won't
1203 add_newer_entrypoints(void)
1206 static const struct {
1207 const char * const name
;
1210 newer_entrypoints
[] = {
1211 /* GL_ARB_window_pos aliases with GL_MESA_window_pos */
1212 { "glWindowPos2dARB", 513 },
1213 { "glWindowPos2dvARB", 514 },
1214 { "glWindowPos2fARB", 515 },
1215 { "glWindowPos2fvARB", 516 },
1216 { "glWindowPos2iARB", 517 },
1217 { "glWindowPos2ivARB", 518 },
1218 { "glWindowPos2sARB", 519 },
1219 { "glWindowPos2svARB", 520 },
1220 { "glWindowPos3dARB", 521 },
1221 { "glWindowPos3dvARB", 522 },
1222 { "glWindowPos3fARB", 523 },
1223 { "glWindowPos3fvARB", 524 },
1224 { "glWindowPos3iARB", 525 },
1225 { "glWindowPos3ivARB", 526 },
1226 { "glWindowPos3sARB", 527 },
1227 { "glWindowPos3svARB", 528 },
1228 #if FEATURE_NV_vertex_program
1229 { "glAreProgramsResidentNV", 578 },
1230 { "glBindProgramNV", 579 },
1231 { "glDeleteProgramsNV", 580 },
1232 { "glExecuteProgramNV", 581 },
1233 { "glGenProgramsNV", 582 },
1234 { "glGetProgramParameterdvNV", 583 },
1235 { "glGetProgramParameterfvNV", 584 },
1236 { "glGetProgramivNV", 585 },
1237 { "glGetProgramStringNV", 586 },
1238 { "glGetTrackMatrixivNV", 587 },
1239 { "glGetVertexAttribdvNV", 588 },
1240 { "glGetVertexAttribfvNV", 589 },
1241 { "glGetVertexAttribivNV", 590 },
1242 { "glGetVertexAttribPointervNV", 591 },
1243 { "glIsProgramNV", 592 },
1244 { "glLoadProgramNV", 593 },
1245 { "glProgramParameter4dNV", 594 },
1246 { "glProgramParameter4dvNV", 595 },
1247 { "glProgramParameter4fNV", 596 },
1248 { "glProgramParameter4fvNV", 597 },
1249 { "glProgramParameters4dvNV", 598 },
1250 { "glProgramParameters4fvNV", 599 },
1251 { "glRequestResidentProgramsNV", 600 },
1252 { "glTrackMatrixNV", 601 },
1253 { "glVertexAttribPointerNV", 602 },
1254 { "glVertexAttrib1dNV", 603 },
1255 { "glVertexAttrib1dvNV", 604 },
1256 { "glVertexAttrib1fNV", 605 },
1257 { "glVertexAttrib1fvNV", 606 },
1258 { "glVertexAttrib1sNV", 607 },
1259 { "glVertexAttrib1svNV", 608 },
1260 { "glVertexAttrib2dNV", 609 },
1261 { "glVertexAttrib2dvNV", 610 },
1262 { "glVertexAttrib2fNV", 611 },
1263 { "glVertexAttrib2fvNV", 612 },
1264 { "glVertexAttrib2sNV", 613 },
1265 { "glVertexAttrib2svNV", 614 },
1266 { "glVertexAttrib3dNV", 615 },
1267 { "glVertexAttrib3dvNV", 616 },
1268 { "glVertexAttrib3fNV", 617 },
1269 { "glVertexAttrib3fvNV", 618 },
1270 { "glVertexAttrib3sNV", 619 },
1271 { "glVertexAttrib3svNV", 620 },
1272 { "glVertexAttrib4dNV", 621 },
1273 { "glVertexAttrib4dvNV", 622 },
1274 { "glVertexAttrib4fNV", 623 },
1275 { "glVertexAttrib4fvNV", 624 },
1276 { "glVertexAttrib4sNV", 625 },
1277 { "glVertexAttrib4svNV", 626 },
1278 { "glVertexAttrib4ubNV", 627 },
1279 { "glVertexAttrib4ubvNV", 628 },
1280 { "glVertexAttribs1dvNV", 629 },
1281 { "glVertexAttribs1fvNV", 630 },
1282 { "glVertexAttribs1svNV", 631 },
1283 { "glVertexAttribs2dvNV", 632 },
1284 { "glVertexAttribs2fvNV", 633 },
1285 { "glVertexAttribs2svNV", 634 },
1286 { "glVertexAttribs3dvNV", 635 },
1287 { "glVertexAttribs3fvNV", 636 },
1288 { "glVertexAttribs3svNV", 637 },
1289 { "glVertexAttribs4dvNV", 638 },
1290 { "glVertexAttribs4fvNV", 639 },
1291 { "glVertexAttribs4svNV", 640 },
1292 { "glVertexAttribs4ubvNV", 641 },
1294 { "glPointParameteriNV", 642 },
1295 { "glPointParameterivNV", 643 },
1296 { "glMultiDrawArraysEXT", 644 },
1297 { "glMultiDrawElementsEXT", 645 },
1298 { "glMultiDrawArraysSUN", _gloffset_MultiDrawArraysEXT
},
1299 { "glMultiDrawElementsSUN", _gloffset_MultiDrawElementsEXT
},
1300 { "glActiveStencilFaceEXT", 646 },
1301 #if FEATURE_NV_fence
1302 { "glDeleteFencesNV", 647 },
1303 { "glGenFencesNV", 648 },
1304 { "glIsFenceNV", 649 },
1305 { "glTestFenceNV", 650 },
1306 { "glGetFenceivNV", 651 },
1307 { "glFinishFenceNV", 652 },
1308 { "glSetFenceNV", 653 },
1310 #if FEATURE_NV_fragment_program
1311 { "glProgramNamedParameter4fNV", 682 },
1312 { "glProgramNamedParameter4dNV", 683 },
1313 { "glProgramNamedParameter4fvNV", 683 },
1314 { "glProgramNamedParameter4dvNV", 684 },
1315 { "glGetProgramNamedParameterfvNV", 685 },
1316 { "glGetProgramNamedParameterdvNV", 686 },
1318 #if FEATURE_ARB_vertex_program
1319 { "glVertexAttrib1sARB", _gloffset_VertexAttrib1sNV
},
1320 { "glVertexAttrib1fARB", _gloffset_VertexAttrib1fNV
},
1321 { "glVertexAttrib1dARB", _gloffset_VertexAttrib1dNV
},
1322 { "glVertexAttrib2sARB", _gloffset_VertexAttrib2sNV
},
1323 { "glVertexAttrib2fARB", _gloffset_VertexAttrib2fNV
},
1324 { "glVertexAttrib2dARB", _gloffset_VertexAttrib2dNV
},
1325 { "glVertexAttrib3sARB", _gloffset_VertexAttrib3sNV
},
1326 { "glVertexAttrib3fARB", _gloffset_VertexAttrib3fNV
},
1327 { "glVertexAttrib3dARB", _gloffset_VertexAttrib3dNV
},
1328 { "glVertexAttrib4sARB", _gloffset_VertexAttrib4sNV
},
1329 { "glVertexAttrib4fARB", _gloffset_VertexAttrib4fNV
},
1330 { "glVertexAttrib4dARB", _gloffset_VertexAttrib4dNV
},
1331 { "glVertexAttrib4NubARB", _gloffset_VertexAttrib4ubNV
},
1332 { "glVertexAttrib1svARB", _gloffset_VertexAttrib1svNV
},
1333 { "glVertexAttrib1fvARB", _gloffset_VertexAttrib1fvNV
},
1334 { "glVertexAttrib1dvARB", _gloffset_VertexAttrib1dvNV
},
1335 { "glVertexAttrib2svARB", _gloffset_VertexAttrib2svNV
},
1336 { "glVertexAttrib2fvARB", _gloffset_VertexAttrib2fvNV
},
1337 { "glVertexAttrib2dvARB", _gloffset_VertexAttrib2dvNV
},
1338 { "glVertexAttrib3svARB", _gloffset_VertexAttrib3svNV
},
1339 { "glVertexAttrib3fvARB", _gloffset_VertexAttrib3fvNV
},
1340 { "glVertexAttrib3dvARB", _gloffset_VertexAttrib3dvNV
},
1341 { "glVertexAttrib4bvARB", _gloffset_VertexAttrib4bvARB
},
1342 { "glVertexAttrib4svARB", _gloffset_VertexAttrib4svNV
},
1343 { "glVertexAttrib4ivARB", _gloffset_VertexAttrib4ivARB
},
1344 { "glVertexAttrib4ubvARB", _gloffset_VertexAttrib4ubvARB
},
1345 { "glVertexAttrib4usvARB", _gloffset_VertexAttrib4usvARB
},
1346 { "glVertexAttrib4uivARB", _gloffset_VertexAttrib4uivARB
},
1347 { "glVertexAttrib4fvARB", _gloffset_VertexAttrib4fvNV
},
1348 { "glVertexAttrib4dvARB", _gloffset_VertexAttrib4dvNV
},
1349 { "glVertexAttrib4NbvARB", _gloffset_VertexAttrib4NbvARB
},
1350 { "glVertexAttrib4NsvARB", _gloffset_VertexAttrib4NsvARB
},
1351 { "glVertexAttrib4NivARB", _gloffset_VertexAttrib4NivARB
},
1352 { "glVertexAttrib4NubvARB", _gloffset_VertexAttrib4ubvNV
},
1353 { "glVertexAttrib4NusvARB", _gloffset_VertexAttrib4NusvARB
},
1354 { "glVertexAttrib4NuivARB", _gloffset_VertexAttrib4NuivARB
},
1355 { "glVertexAttribPointerARB", _gloffset_VertexAttribPointerARB
},
1356 { "glEnableVertexAttribArrayARB", _gloffset_EnableVertexAttribArrayARB
},
1357 { "glDisableVertexAttribArrayARB", _gloffset_DisableVertexAttribArrayARB
},
1358 { "glProgramStringARB", _gloffset_ProgramStringARB
},
1359 { "glBindProgramARB", _gloffset_BindProgramNV
},
1360 { "glDeleteProgramsARB", _gloffset_DeleteProgramsNV
},
1361 { "glGenProgramsARB", _gloffset_GenProgramsNV
},
1362 { "glIsProgramARB", _gloffset_IsProgramNV
},
1363 { "glProgramEnvParameter4dARB", _gloffset_ProgramEnvParameter4dARB
},
1364 { "glProgramEnvParameter4dvARB", _gloffset_ProgramEnvParameter4dvARB
},
1365 { "glProgramEnvParameter4fARB", _gloffset_ProgramEnvParameter4fARB
},
1366 { "glProgramEnvParameter4fvARB", _gloffset_ProgramEnvParameter4fvARB
},
1367 { "glProgramLocalParameter4dARB", _gloffset_ProgramLocalParameter4dARB
},
1368 { "glProgramLocalParameter4dvARB", _gloffset_ProgramLocalParameter4dvARB
},
1369 { "glProgramLocalParameter4fARB", _gloffset_ProgramLocalParameter4fARB
},
1370 { "glProgramLocalParameter4fvARB", _gloffset_ProgramLocalParameter4fvARB
},
1371 { "glGetProgramEnvParameterdvARB", _gloffset_GetProgramEnvParameterdvARB
},
1372 { "glGetProgramEnvParameterfvARB", _gloffset_GetProgramEnvParameterfvARB
},
1373 { "glGetProgramLocalParameterdvARB", _gloffset_GetProgramLocalParameterdvARB
},
1374 { "glGetProgramLocalParameterfvARB", _gloffset_GetProgramLocalParameterfvARB
},
1375 { "glGetProgramivARB", _gloffset_GetProgramivARB
},
1376 { "glGetProgramStringARB", _gloffset_GetProgramStringARB
},
1377 { "glGetVertexAttribdvARB", _gloffset_GetVertexAttribdvNV
},
1378 { "glGetVertexAttribfvARB", _gloffset_GetVertexAttribfvNV
},
1379 { "glGetVertexAttribivARB", _gloffset_GetVertexAttribivNV
},
1380 { "glGetVertexAttribPointervARB", _gloffset_GetVertexAttribPointervNV
},
1382 { "glMultiModeDrawArraysIBM", _gloffset_MultiModeDrawArraysIBM
},
1383 { "glMultiModeDrawElementsIBM", _gloffset_MultiModeDrawElementsIBM
},
1386 for ( i
= 0 ; i
< Elements(newer_entrypoints
) ; i
++ ) {
1387 _glapi_add_entrypoint( newer_entrypoints
[i
].name
,
1388 newer_entrypoints
[i
].offset
);
1394 * Initialize a GLcontext struct (rendering context).
1396 * This includes allocating all the other structs and arrays which hang off of
1397 * the context by pointers.
1398 * Note that the driver needs to pass in its dd_function_table here since
1399 * we need to at least call driverFunctions->NewTextureObject to create the
1400 * default texture objects.
1402 * Called by _mesa_create_context().
1404 * Performs the imports and exports callback tables initialization, and
1405 * miscellaneous one-time initializations. If no shared context is supplied one
1406 * is allocated, and increase its reference count. Setups the GL API dispatch
1407 * tables. Initialize the TNL module. Sets the maximum Z buffer depth.
1408 * Finally queries the \c MESA_DEBUG and \c MESA_VERBOSE environment variables
1411 * \param ctx the context to initialize
1412 * \param visual describes the visual attributes for this context
1413 * \param share_list points to context to share textures, display lists,
1415 * \param driverFunctions table of device driver functions for this context
1417 * \param driverContext pointer to driver-specific context data
1420 _mesa_initialize_context( GLcontext
*ctx
,
1421 const GLvisual
*visual
,
1422 GLcontext
*share_list
,
1423 const struct dd_function_table
*driverFunctions
,
1424 void *driverContext
)
1426 GLuint dispatchSize
;
1428 ASSERT(driverContext
);
1429 assert(driverFunctions
->NewTextureObject
);
1431 /* If the driver wants core Mesa to use special imports, it'll have to
1432 * override these defaults.
1434 _mesa_init_default_imports( &(ctx
->imports
), driverContext
);
1436 /* initialize the exports (Mesa functions called by the window system) */
1437 _mesa_init_default_exports( &(ctx
->exports
) );
1439 /* misc one-time initializations */
1442 ctx
->Visual
= *visual
;
1443 ctx
->DrawBuffer
= NULL
;
1444 ctx
->ReadBuffer
= NULL
;
1446 /* Plug in driver functions and context pointer here.
1447 * This is important because when we call alloc_shared_state() below
1448 * we'll call ctx->Driver.NewTextureObject() to create the default
1451 ctx
->Driver
= *driverFunctions
;
1452 ctx
->DriverCtx
= driverContext
;
1455 /* share state with another context */
1456 ctx
->Shared
= share_list
->Shared
;
1459 /* allocate new, unshared state */
1460 if (!alloc_shared_state( ctx
)) {
1464 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1465 ctx
->Shared
->RefCount
++;
1466 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1468 if (!init_attrib_groups( ctx
)) {
1469 free_shared_state(ctx
, ctx
->Shared
);
1473 /* libGL ABI coordination */
1474 add_newer_entrypoints();
1476 /* Find the larger of Mesa's dispatch table and libGL's dispatch table.
1477 * In practice, this'll be the same for stand-alone Mesa. But for DRI
1478 * Mesa we do this to accomodate different versions of libGL and various
1481 dispatchSize
= MAX2(_glapi_get_dispatch_table_size(),
1482 sizeof(struct _glapi_table
) / sizeof(void *));
1484 /* setup API dispatch tables */
1485 ctx
->Exec
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1486 ctx
->Save
= (struct _glapi_table
*) CALLOC(dispatchSize
* sizeof(void*));
1487 if (!ctx
->Exec
|| !ctx
->Save
) {
1488 free_shared_state(ctx
, ctx
->Shared
);
1492 _mesa_init_exec_table(ctx
->Exec
, dispatchSize
);
1493 ctx
->CurrentDispatch
= ctx
->Exec
;
1496 _mesa_init_dlist_table(ctx
->Save
, dispatchSize
);
1497 _mesa_install_save_vtxfmt( ctx
, &ctx
->ListState
.ListVtxfmt
);
1500 /* Neutral tnl module stuff */
1501 _mesa_init_exec_vtxfmt( ctx
);
1502 ctx
->TnlModule
.Current
= NULL
;
1503 ctx
->TnlModule
.SwapCount
= 0;
1511 * Allocate and initialize a GLcontext structure.
1512 * Note that the driver needs to pass in its dd_function_table here since
1513 * we need to at least call driverFunctions->NewTextureObject to initialize
1514 * the rendering context.
1516 * \param visual a GLvisual pointer (we copy the struct contents)
1517 * \param share_list another context to share display lists with or NULL
1518 * \param driverFunctions points to the dd_function_table into which the
1519 * driver has plugged in all its special functions.
1520 * \param driverCtx points to the device driver's private context state
1522 * \return pointer to a new __GLcontextRec or NULL if error.
1525 _mesa_create_context( const GLvisual
*visual
,
1526 GLcontext
*share_list
,
1527 const struct dd_function_table
*driverFunctions
,
1528 void *driverContext
)
1534 ASSERT(driverContext
);
1536 ctx
= (GLcontext
*) _mesa_calloc(sizeof(GLcontext
));
1540 if (_mesa_initialize_context(ctx
, visual
, share_list
,
1541 driverFunctions
, driverContext
)) {
1552 * Free the data associated with the given context.
1554 * But doesn't free the GLcontext struct itself.
1556 * \sa _mesa_initialize_context() and init_attrib_groups().
1559 _mesa_free_context_data( GLcontext
*ctx
)
1561 /* if we're destroying the current context, unbind it first */
1562 if (ctx
== _mesa_get_current_context()) {
1563 _mesa_make_current(NULL
, NULL
);
1566 _mesa_free_lighting_data( ctx
);
1567 _mesa_free_eval_data( ctx
);
1568 _mesa_free_texture_data( ctx
);
1569 _mesa_free_matrix_data( ctx
);
1570 _mesa_free_viewport_data( ctx
);
1571 _mesa_free_colortables_data( ctx
);
1572 _mesa_free_program_data(ctx
);
1573 _mesa_free_occlude_data(ctx
);
1575 #if FEATURE_ARB_vertex_buffer_object
1576 _mesa_delete_buffer_object(ctx
, ctx
->Array
.NullBufferObj
);
1579 /* Shared context state (display lists, textures, etc) */
1580 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1581 ctx
->Shared
->RefCount
--;
1582 assert(ctx
->Shared
->RefCount
>= 0);
1583 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1584 if (ctx
->Shared
->RefCount
== 0) {
1585 /* free shared state */
1586 free_shared_state( ctx
, ctx
->Shared
);
1589 if (ctx
->Extensions
.String
)
1590 FREE((void *) ctx
->Extensions
.String
);
1598 * Destroy a GLcontext structure.
1600 * \param ctx GL context.
1602 * Calls _mesa_free_context_data() and frees the GLcontext structure itself.
1605 _mesa_destroy_context( GLcontext
*ctx
)
1608 _mesa_free_context_data(ctx
);
1609 FREE( (void *) ctx
);
1616 * Copy attribute groups from one context to another.
1618 * \param src source context
1619 * \param dst destination context
1620 * \param mask bitwise OR of GL_*_BIT flags
1622 * According to the bits specified in \p mask, copies the corresponding
1623 * attributes from \p src into \p dst. For many of the attributes a simple \c
1624 * memcpy is not enough due to the existence of internal pointers in their data
1628 _mesa_copy_context( const GLcontext
*src
, GLcontext
*dst
, GLuint mask
)
1630 if (mask
& GL_ACCUM_BUFFER_BIT
) {
1632 dst
->Accum
= src
->Accum
;
1634 if (mask
& GL_COLOR_BUFFER_BIT
) {
1636 dst
->Color
= src
->Color
;
1638 if (mask
& GL_CURRENT_BIT
) {
1640 dst
->Current
= src
->Current
;
1642 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1644 dst
->Depth
= src
->Depth
;
1646 if (mask
& GL_ENABLE_BIT
) {
1649 if (mask
& GL_EVAL_BIT
) {
1651 dst
->Eval
= src
->Eval
;
1653 if (mask
& GL_FOG_BIT
) {
1655 dst
->Fog
= src
->Fog
;
1657 if (mask
& GL_HINT_BIT
) {
1659 dst
->Hint
= src
->Hint
;
1661 if (mask
& GL_LIGHTING_BIT
) {
1663 /* begin with memcpy */
1664 MEMCPY( &dst
->Light
, &src
->Light
, sizeof(struct gl_light
) );
1665 /* fixup linked lists to prevent pointer insanity */
1666 make_empty_list( &(dst
->Light
.EnabledList
) );
1667 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
1668 if (dst
->Light
.Light
[i
].Enabled
) {
1669 insert_at_tail(&(dst
->Light
.EnabledList
), &(dst
->Light
.Light
[i
]));
1673 if (mask
& GL_LINE_BIT
) {
1675 dst
->Line
= src
->Line
;
1677 if (mask
& GL_LIST_BIT
) {
1679 dst
->List
= src
->List
;
1681 if (mask
& GL_PIXEL_MODE_BIT
) {
1683 dst
->Pixel
= src
->Pixel
;
1685 if (mask
& GL_POINT_BIT
) {
1687 dst
->Point
= src
->Point
;
1689 if (mask
& GL_POLYGON_BIT
) {
1691 dst
->Polygon
= src
->Polygon
;
1693 if (mask
& GL_POLYGON_STIPPLE_BIT
) {
1694 /* Use loop instead of MEMCPY due to problem with Portland Group's
1695 * C compiler. Reported by John Stone.
1698 for (i
= 0; i
< 32; i
++) {
1699 dst
->PolygonStipple
[i
] = src
->PolygonStipple
[i
];
1702 if (mask
& GL_SCISSOR_BIT
) {
1704 dst
->Scissor
= src
->Scissor
;
1706 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1708 dst
->Stencil
= src
->Stencil
;
1710 if (mask
& GL_TEXTURE_BIT
) {
1711 /* Cannot memcpy because of pointers */
1712 _mesa_copy_texture_state(src
, dst
);
1714 if (mask
& GL_TRANSFORM_BIT
) {
1716 dst
->Transform
= src
->Transform
;
1718 if (mask
& GL_VIEWPORT_BIT
) {
1719 /* Cannot use memcpy, because of pointers in GLmatrix _WindowMap */
1720 dst
->Viewport
.X
= src
->Viewport
.X
;
1721 dst
->Viewport
.Y
= src
->Viewport
.Y
;
1722 dst
->Viewport
.Width
= src
->Viewport
.Width
;
1723 dst
->Viewport
.Height
= src
->Viewport
.Height
;
1724 dst
->Viewport
.Near
= src
->Viewport
.Near
;
1725 dst
->Viewport
.Far
= src
->Viewport
.Far
;
1726 _math_matrix_copy(&dst
->Viewport
._WindowMap
, &src
->Viewport
._WindowMap
);
1729 /* XXX FIXME: Call callbacks?
1731 dst
->NewState
= _NEW_ALL
;
1737 * Check if the given context can render into the given framebuffer
1738 * by checking visual attributes.
1739 * \return GL_TRUE if compatible, GL_FALSE otherwise.
1742 check_compatible(const GLcontext
*ctx
, const GLframebuffer
*buffer
)
1744 const GLvisual
*ctxvis
= &ctx
->Visual
;
1745 const GLvisual
*bufvis
= &buffer
->Visual
;
1747 if (ctxvis
== bufvis
)
1750 if (ctxvis
->rgbMode
!= bufvis
->rgbMode
)
1752 if (ctxvis
->doubleBufferMode
&& !bufvis
->doubleBufferMode
)
1754 if (ctxvis
->stereoMode
&& !bufvis
->stereoMode
)
1756 if (ctxvis
->haveAccumBuffer
&& !bufvis
->haveAccumBuffer
)
1758 if (ctxvis
->haveDepthBuffer
&& !bufvis
->haveDepthBuffer
)
1760 if (ctxvis
->haveStencilBuffer
&& !bufvis
->haveStencilBuffer
)
1762 if (ctxvis
->redMask
&& ctxvis
->redMask
!= bufvis
->redMask
)
1764 if (ctxvis
->greenMask
&& ctxvis
->greenMask
!= bufvis
->greenMask
)
1766 if (ctxvis
->blueMask
&& ctxvis
->blueMask
!= bufvis
->blueMask
)
1768 if (ctxvis
->depthBits
&& ctxvis
->depthBits
!= bufvis
->depthBits
)
1770 if (ctxvis
->stencilBits
&& ctxvis
->stencilBits
!= bufvis
->stencilBits
)
1778 * Set the current context, binding the given frame buffer to the context.
1780 * \param newCtx new GL context.
1781 * \param buffer framebuffer.
1783 * Calls _mesa_make_current2() with \p buffer as read and write framebuffer.
1786 _mesa_make_current( GLcontext
*newCtx
, GLframebuffer
*buffer
)
1788 _mesa_make_current2( newCtx
, buffer
, buffer
);
1792 * Bind the given context to the given draw-buffer and read-buffer and
1793 * make it the current context for this thread.
1795 * \param newCtx new GL context. If NULL then there will be no current GL
1797 * \param drawBuffer draw framebuffer.
1798 * \param readBuffer read framebuffer.
1800 * Check that the context's and framebuffer's visuals are compatible, returning
1801 * immediately otherwise. Sets the glapi current context via
1802 * _glapi_set_context(). If \p newCtx is not NULL, associates \p drawBuffer and
1803 * \p readBuffer with it and calls dd_function_table::ResizeBuffers if the buffers size has changed.
1804 * Calls dd_function_table::MakeCurrent callback if defined.
1806 * When a context is bound by the first time and the \c MESA_INFO environment
1807 * variable is set it calls print_info() as an aid for remote user
1811 _mesa_make_current2( GLcontext
*newCtx
, GLframebuffer
*drawBuffer
,
1812 GLframebuffer
*readBuffer
)
1815 _mesa_debug(newCtx
, "_mesa_make_current2()\n");
1817 /* Check that the context's and framebuffer's visuals are compatible.
1819 if (newCtx
&& drawBuffer
&& newCtx
->DrawBuffer
!= drawBuffer
) {
1820 if (!check_compatible(newCtx
, drawBuffer
))
1823 if (newCtx
&& readBuffer
&& newCtx
->ReadBuffer
!= readBuffer
) {
1824 if (!check_compatible(newCtx
, readBuffer
))
1828 /* We call this function periodically (just here for now) in
1829 * order to detect when multithreading has begun.
1831 _glapi_check_multithread();
1833 _glapi_set_context((void *) newCtx
);
1834 ASSERT(_mesa_get_current_context() == newCtx
);
1838 _glapi_set_dispatch(NULL
); /* none current */
1841 _glapi_set_dispatch(newCtx
->CurrentDispatch
);
1843 if (drawBuffer
&& readBuffer
) {
1844 /* TODO: check if newCtx and buffer's visual match??? */
1845 newCtx
->DrawBuffer
= drawBuffer
;
1846 newCtx
->ReadBuffer
= readBuffer
;
1847 newCtx
->NewState
|= _NEW_BUFFERS
;
1850 if (drawBuffer
->Width
== 0 && drawBuffer
->Height
== 0) {
1851 /* get initial window size */
1852 GLuint bufWidth
, bufHeight
;
1854 /* ask device driver for size of output buffer */
1855 (*newCtx
->Driver
.GetBufferSize
)( drawBuffer
, &bufWidth
, &bufHeight
);
1857 if (drawBuffer
->Width
!= bufWidth
||
1858 drawBuffer
->Height
!= bufHeight
) {
1860 drawBuffer
->Width
= bufWidth
;
1861 drawBuffer
->Height
= bufHeight
;
1863 newCtx
->Driver
.ResizeBuffers( drawBuffer
);
1867 if (readBuffer
!= drawBuffer
&&
1868 readBuffer
->Width
== 0 && readBuffer
->Height
== 0) {
1869 /* get initial window size */
1870 GLuint bufWidth
, bufHeight
;
1872 /* ask device driver for size of output buffer */
1873 (*newCtx
->Driver
.GetBufferSize
)( readBuffer
, &bufWidth
, &bufHeight
);
1875 if (readBuffer
->Width
!= bufWidth
||
1876 readBuffer
->Height
!= bufHeight
) {
1878 readBuffer
->Width
= bufWidth
;
1879 readBuffer
->Height
= bufHeight
;
1881 newCtx
->Driver
.ResizeBuffers( readBuffer
);
1887 /* Alert the driver - usually passed on to the sw t&l module,
1888 * but also used to detect threaded cases in the radeon codegen
1891 if (newCtx
->Driver
.MakeCurrent
)
1892 newCtx
->Driver
.MakeCurrent( newCtx
, drawBuffer
, readBuffer
);
1894 /* We can use this to help debug user's problems. Tell them to set
1895 * the MESA_INFO env variable before running their app. Then the
1896 * first time each context is made current we'll print some useful
1899 if (newCtx
->FirstTimeCurrent
) {
1900 if (_mesa_getenv("MESA_INFO")) {
1903 newCtx
->FirstTimeCurrent
= GL_FALSE
;
1909 * Get current context for the calling thread.
1911 * \return pointer to the current GL context.
1913 * Calls _glapi_get_context(). This isn't the fastest way to get the current
1914 * context. If you need speed, see the #GET_CURRENT_CONTEXT macro in context.h.
1917 _mesa_get_current_context( void )
1919 return (GLcontext
*) _glapi_get_context();
1923 * Get context's current API dispatch table.
1925 * It'll either be the immediate-mode execute dispatcher or the display list
1926 * compile dispatcher.
1928 * \param ctx GL context.
1930 * \return pointer to dispatch_table.
1932 * Simply returns __GLcontextRec::CurrentDispatch.
1934 struct _glapi_table
*
1935 _mesa_get_dispatch(GLcontext
*ctx
)
1937 return ctx
->CurrentDispatch
;
1943 /**********************************************************************/
1944 /** \name Miscellaneous functions */
1945 /**********************************************************************/
1951 * \param ctx GL context.
1952 * \param error error code.
1954 * Records the given error code and call the driver's dd_function_table::Error
1955 * function if defined.
1958 * This is called via _mesa_error().
1961 _mesa_record_error( GLcontext
*ctx
, GLenum error
)
1966 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
1967 ctx
->ErrorValue
= error
;
1970 /* Call device driver's error handler, if any. This is used on the Mac. */
1971 if (ctx
->Driver
.Error
) {
1972 (*ctx
->Driver
.Error
)( ctx
);
1977 * Execute glFinish().
1979 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1980 * dd_function_table::Finish driver callback, if not NULL.
1983 _mesa_Finish( void )
1985 GET_CURRENT_CONTEXT(ctx
);
1986 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1987 if (ctx
->Driver
.Finish
) {
1988 (*ctx
->Driver
.Finish
)( ctx
);
1993 * Execute glFlush().
1995 * Calls the #ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH macro and the
1996 * dd_function_table::Flush driver callback, if not NULL.
2001 GET_CURRENT_CONTEXT(ctx
);
2002 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2003 if (ctx
->Driver
.Flush
) {
2004 (*ctx
->Driver
.Flush
)( ctx
);