├── tests ├── shared_mapping │ ├── clean.sh │ ├── bld.sh │ ├── NOTES │ ├── client.c │ └── server.c ├── engine │ ├── reflect.rgb │ ├── engine.mk │ ├── readtex.h │ └── trackball.h ├── triangle │ ├── triangle.mk │ └── triangle.m ├── glxinfo │ └── glxinfo.mk ├── glxgears │ └── glxgears.mk ├── shared │ └── shared.mk ├── fbconfigs │ ├── fbconfigs.mk │ └── fbconfigs.c ├── texenv │ └── texenv.mk ├── triangle_glx_single │ ├── triangle_glx.mk │ └── triangle_glx.c ├── pbuffer │ ├── pbuffer.mk │ ├── pbuffer_destroy.c │ └── pbuffer.c ├── glxpixmap │ ├── glxpixmap.mk │ ├── glxpixmap_destroy_invalid.c │ └── glxpixmap.c ├── simple │ ├── simple.c │ ├── simple.mk │ ├── query_drawable.c │ ├── render_types.c │ ├── drawable_types.c │ └── multisample_glx.c ├── triangle_glx │ ├── triangle_glx.mk │ ├── triangle_glx.c │ ├── triangle_glx_surface.c │ ├── triangle_glx_withdraw_remap.c │ ├── triangle_glx_surface-2.c │ └── triangle_glx_destroy_relation.c ├── create_destroy_context │ ├── create_destroy_context.mk │ ├── create_destroy_context_alone.c │ ├── create_destroy_context_with_drawable.c │ ├── create_destroy_context_with_drawable_2.c │ └── create_destroy_context.c ├── tests.mk └── cgl_growth.c ├── specs └── README.txt ├── BASED_ON ├── GL_promoted ├── GL_aliases ├── README_UPDATING ├── GL_noop ├── OVERALL_DESIGN ├── attic ├── api_generator.tcl ├── apple_GL_pbuffer_max.c ├── api_delta_generator.tcl ├── apple_GL_extensions_gen.c ├── gliDispatch_to_list.tcl ├── api_to_code.tcl └── api_list_completion.tcl ├── gen_types.tcl ├── glxhash.h ├── TODO ├── gen_gl_h.sh ├── glx_error.h ├── apple_xgl_api_viewport.h ├── apple_xgl_api_stereo.h ├── apple_visual.h ├── apple_xgl_api_viewport.c ├── gen_defs.tcl ├── apple_glx.h ├── gen_code.tcl ├── apple_xgl_api_read.h ├── glx_error.c ├── glcontextmodes.h ├── gen_api_header.tcl ├── RELEASE_NOTES ├── apple_cgl.h ├── apple_glx_context.h ├── apple_xgl_api_stereo.c ├── GL_extensions ├── apple_cgl.c ├── include ├── GL │ └── gl.h.template └── simple_list.h ├── glxreply.c ├── apple_xgl_api_read.c ├── apple_visual.c ├── appledri.h ├── gen_exports.tcl ├── Makefile ├── apple_glx.c ├── glx_query.c ├── compsize.c ├── gen_api_library.tcl └── apple_glx_pixmap.c /tests/shared_mapping/clean.sh: -------------------------------------------------------------------------------- 1 | rm -f client server *~ 2 | -------------------------------------------------------------------------------- /specs/README.txt: -------------------------------------------------------------------------------- 1 | spec files from http://www.opengl.org/registry 2 | 3 | -------------------------------------------------------------------------------- /tests/shared_mapping/bld.sh: -------------------------------------------------------------------------------- 1 | gcc client.c -o client 2 | gcc server.c -o server 3 | -------------------------------------------------------------------------------- /BASED_ON: -------------------------------------------------------------------------------- 1 | master as of 2009.12.21 (c020a83fae23f088990b1d5ae2fc4a1ed92f03d9) 2 | 3 | -------------------------------------------------------------------------------- /tests/engine/reflect.rgb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XQuartz/AppleSGLX/HEAD/tests/engine/reflect.rgb -------------------------------------------------------------------------------- /GL_promoted: -------------------------------------------------------------------------------- 1 | promoted MESA_window_pos 2 | promoted ARB_window_pos 3 | promoted EXT_copy_texture 4 | promoted ARB_vertex_program 5 | -------------------------------------------------------------------------------- /tests/triangle/triangle.mk: -------------------------------------------------------------------------------- 1 | triangle: tests/triangle/triangle.m libgl.a libglx.a 2 | $(CC) tests/triangle/triangle.m -framework GLUT -framework OpenGL -o triangle 3 | -------------------------------------------------------------------------------- /tests/glxinfo/glxinfo.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/glxinfo: tests/glxinfo/glxinfo.c $(LIBGL) 2 | $(CC) tests/glxinfo/glxinfo.c $(INCLUDE) -o $(TEST_BUILD_DIR)/glxinfo $(LINK_TEST) 3 | -------------------------------------------------------------------------------- /tests/glxgears/glxgears.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/glxgears: tests/glxgears/glxgears.c $(LIBGL) 2 | $(CC) tests/glxgears/glxgears.c -Iinclude -o $(TEST_BUILD_DIR)/glxgears $(LINK_TEST) 3 | -------------------------------------------------------------------------------- /tests/shared/shared.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/sharedtex: tests/shared/sharedtex.c $(LIBGL) 2 | $(CC) tests/shared/sharedtex.c $(INCLUDE) -o $(TEST_BUILD_DIR)/sharedtex $(LINK_TEST) 3 | 4 | -------------------------------------------------------------------------------- /tests/fbconfigs/fbconfigs.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/fbconfigs: tests/fbconfigs/fbconfigs.c $(LIBGL) 2 | $(CC) tests/fbconfigs/fbconfigs.c $(INCLUDE) -o $(TEST_BUILD_DIR)/fbconfigs $(LINK_TEST) 3 | -------------------------------------------------------------------------------- /tests/texenv/texenv.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/texenv: tests/texenv/texenv.c $(LIBGL) 2 | $(CC) tests/texenv/texenv.c $(INCLUDE) -o $(TEST_BUILD_DIR)/texenv -L$(INSTALL_DIR)/lib -L$(X11_DIR)/lib -lXmu -lglu libglut.a $(LINK_TEST) 3 | -------------------------------------------------------------------------------- /tests/triangle_glx_single/triangle_glx.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/triangle_glx_single: tests/triangle_glx_single/triangle_glx.c $(LIBGL) 2 | $(CC) tests/triangle_glx_single/triangle_glx.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_single $(LINK_TEST) 3 | -------------------------------------------------------------------------------- /tests/engine/engine.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/engine: tests/engine/engine.c $(LIBGL) libglut.a 2 | $(CC) tests/engine/engine.c tests/engine/readtex.c tests/engine/trackball.c $(INCLUDE) -o $(TEST_BUILD_DIR)/engine $(LINK_TEST) libglut.a -L$(INSTALL_DIR)/lib -L$(X11_DIR)/lib -lXmu -lGLU 3 | -------------------------------------------------------------------------------- /GL_aliases: -------------------------------------------------------------------------------- 1 | #GL_EXT_texture_object 2 | alias AreTexturesResidentEXT AreTexturesResident 3 | alias BindTextureEXT BindTexture 4 | alias DeleteTexturesEXT DeleteTextures 5 | alias GenTexturesEXT GenTextures 6 | alias IsTextureEXT IsTexture 7 | alias PrioritizeTexturesEXT PrioritizeTextures 8 | alias TexImage3DEXT TexImage3D 9 | -------------------------------------------------------------------------------- /tests/pbuffer/pbuffer.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/pbuffer: tests/pbuffer/pbuffer.c $(LIBGL) 2 | $(CC) tests/pbuffer/pbuffer.c -Iinclude -o $(TEST_BUILD_DIR)/pbuffer $(LINK_TEST) 3 | 4 | $(TEST_BUILD_DIR)/pbuffer_destroy: tests/pbuffer/pbuffer_destroy.c $(LIBGL) 5 | $(CC) tests/pbuffer/pbuffer_destroy.c -Iinclude -o $(TEST_BUILD_DIR)/pbuffer_destroy $(LINK_TEST) 6 | -------------------------------------------------------------------------------- /README_UPDATING: -------------------------------------------------------------------------------- 1 | The design of most of this code is such that we extend the GLX structures 2 | with a void * named apple. 3 | 4 | The GLX functions that need to do Apple-specific things are passed 5 | &s->apple in order to initialize the private structures. 6 | 7 | Thus when updating, just run a diff against glxext.c or glxcmds.c, and 8 | manually merge from there as needed. 9 | -------------------------------------------------------------------------------- /GL_noop: -------------------------------------------------------------------------------- 1 | #These are for compatibility with the old libGL. 2 | noop SGI_color_table 3 | noop EXT_convolution 4 | noop EXT_cull_vertex 5 | noop NV_fence 6 | noop SGIS_detail_texture 7 | noop SGIX_fragment_lighting 8 | noop SGIX_flush_raster 9 | noop EXT_vertex_array 10 | noop SGIX_instruments 11 | noop EXT_histogram 12 | noop NV_vertex_program 13 | noop PGI_misc_hints 14 | noop SGIS_multisample 15 | noop EXT_multisample 16 | -------------------------------------------------------------------------------- /tests/shared_mapping/NOTES: -------------------------------------------------------------------------------- 1 | The client and server programs are protypes to test the behavior 2 | of GLXPixmap shared memory in a controlled environment 3 | 4 | The client faults after munmapping and truncating its fd, but the 5 | server keeps going. This is a good thing from a security perspective. 6 | 7 | The client sees the servers changes, and the server can see the 8 | client changes, but the server won't fault if the file is truncated. 9 | -------------------------------------------------------------------------------- /OVERALL_DESIGN: -------------------------------------------------------------------------------- 1 | A lot of the code is automatically generated. 2 | 3 | The following are generated based on specs/gl.spec and specs/enum.spec (from OpenGL.org): 4 | 5 | apple_xgl_api.h 6 | apple_xgl_api.c 7 | exports.list 8 | include/GL/gl.h 9 | include/GL/glext.h (includes the OpenGL framework glext.h) 10 | 11 | The gen_code.tcl script is what executes the various gen_*.tcl scripts to produce those. 12 | 13 | You will need Tcl 8.5 for the gen_code.tcl script. 14 | 15 | The tests/ directory contains some tests that are built in testbuilds. 16 | 17 | The tests built in testbuilds don't require installation of the library. 18 | 19 | -------------------------------------------------------------------------------- /tests/engine/readtex.h: -------------------------------------------------------------------------------- 1 | /* readtex.h */ 2 | 3 | #ifndef READTEX_H 4 | #define READTEX_H 5 | 6 | 7 | #include 8 | 9 | 10 | extern GLboolean 11 | LoadRGBMipmaps( const char *imageFile, GLint intFormat ); 12 | 13 | 14 | extern GLboolean 15 | LoadRGBMipmaps2( const char *imageFile, GLenum target, 16 | GLint intFormat, GLint *width, GLint *height ); 17 | 18 | 19 | extern GLubyte * 20 | LoadRGBImage( const char *imageFile, 21 | GLint *width, GLint *height, GLenum *format ); 22 | 23 | extern GLushort * 24 | LoadYUVImage( const char *imageFile, GLint *width, GLint *height ); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /tests/glxpixmap/glxpixmap.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/glxpixmap: tests/glxpixmap/glxpixmap.c $(LIBGL) 2 | $(CC) tests/glxpixmap/glxpixmap.c $(INCLUDE) -o $(TEST_BUILD_DIR)/glxpixmap $(LINK_TEST) 3 | 4 | $(TEST_BUILD_DIR)/glxpixmap_create_destroy: tests/glxpixmap/glxpixmap_create_destroy.c $(LIBGL) 5 | $(CC) tests/glxpixmap/glxpixmap_create_destroy.c $(INCLUDE) -o $(TEST_BUILD_DIR)/glxpixmap_create_destroy $(LINK_TEST) 6 | 7 | $(TEST_BUILD_DIR)/glxpixmap_destroy_invalid: tests/glxpixmap/glxpixmap_destroy_invalid.c $(LIBGL) 8 | $(CC) tests/glxpixmap/glxpixmap_destroy_invalid.c $(INCLUDE) -o $(TEST_BUILD_DIR)/glxpixmap_destroy_invalid $(LINK_TEST) 9 | -------------------------------------------------------------------------------- /attic/api_generator.tcl: -------------------------------------------------------------------------------- 1 | 2 | proc main {} { 3 | set fd [open dri_dispatch.defs r] 4 | set data [read $fd] 5 | close $fd 6 | 7 | set api [list] 8 | 9 | foreach {match exact} [regexp -all -inline {\((.*?)\)[^\n]*\n} $data] { 10 | #puts EXACT:$exact 11 | if {[llength $exact] != 4} { 12 | continue 13 | } 14 | 15 | set rettype [lindex $exact 0] 16 | set fnsuffix [lindex $exact 1] 17 | #skip offset 18 | set argpat [split [lindex $exact 3] ,] 19 | set argpatfinal [list] 20 | 21 | foreach i $argpat { 22 | lappend argpatfinal [string trim $i] 23 | } 24 | 25 | lappend api [list $rettype $fnsuffix $argpatfinal] 26 | } 27 | 28 | foreach i $api { 29 | puts $i 30 | } 31 | 32 | } 33 | main 34 | -------------------------------------------------------------------------------- /gen_types.tcl: -------------------------------------------------------------------------------- 1 | 2 | proc main {argc argv} { 3 | if {1 != $argc} { 4 | puts stderr "syntax is: [info script] output.h" 5 | exit 1 6 | } 7 | 8 | set fd [open [lindex $argv 0] w] 9 | puts $fd " 10 | /*OpenGL primitive typedefs*/ 11 | typedef unsigned int GLenum; 12 | typedef unsigned char GLboolean; 13 | typedef unsigned int GLbitfield; 14 | typedef signed char GLbyte; 15 | typedef short GLshort; 16 | typedef int GLint; 17 | typedef int GLsizei; 18 | typedef unsigned char GLubyte; 19 | typedef unsigned short GLushort; 20 | typedef unsigned int GLuint; 21 | typedef float GLfloat; 22 | typedef float GLclampf; 23 | typedef double GLdouble; 24 | typedef double GLclampd; 25 | typedef void GLvoid; 26 | 27 | typedef long GLintptr; 28 | typedef long GLsizeiptr; 29 | " 30 | 31 | } 32 | main $::argc $::argv 33 | -------------------------------------------------------------------------------- /glxhash.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLX_HASH_H_ 2 | #define _GLX_HASH_H_ 3 | 4 | 5 | typedef struct __glxHashTable __glxHashTable; 6 | 7 | /* Hash table routines */ 8 | extern __glxHashTable *__glxHashCreate(void); 9 | extern int __glxHashDestroy(__glxHashTable * t); 10 | extern int __glxHashLookup(__glxHashTable * t, unsigned long key, 11 | void **value); 12 | extern int __glxHashInsert(__glxHashTable * t, unsigned long key, 13 | void *value); 14 | extern int __glxHashDelete(__glxHashTable * t, unsigned long key); 15 | extern int __glxHashFirst(__glxHashTable * t, unsigned long *key, 16 | void **value); 17 | extern int __glxHashNext(__glxHashTable * t, unsigned long *key, 18 | void **value); 19 | 20 | #endif /* _GLX_HASH_H_ */ 21 | -------------------------------------------------------------------------------- /tests/simple/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | Display *dpy; 8 | int eventbase, errorbase; 9 | int major, minor; 10 | 11 | dpy = XOpenDisplay(NULL); 12 | 13 | if(NULL == dpy) { 14 | fprintf(stderr, "error: unable to open display!\n"); 15 | return EXIT_FAILURE; 16 | } 17 | 18 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 19 | fprintf(stderr, "GLX is not available!\n"); 20 | return EXIT_FAILURE; 21 | } 22 | 23 | printf("GLX eventbase %d errorbase %d\n", eventbase, errorbase); 24 | 25 | if(!glXQueryVersion(dpy, &major, &minor)) { 26 | fprintf(stderr, "GLX version query error!\n"); 27 | return EXIT_FAILURE; 28 | } 29 | 30 | printf("GLX version: %d.%d\n", major, minor); 31 | 32 | return EXIT_SUCCESS; 33 | } 34 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Test shared contexts! 2 | 3 | Go over every glxcmd in glxcmds.c and make sure we have them working. 4 | Verify the XError behavior of GLXPixmap support functions. 5 | 6 | Test GLXPixmap support with various pixmap depths. 7 | 8 | Test GLXPixmap support with invalid pixmaps (to stress the protocol code). 9 | 10 | -- Feb 10, 2009 11 | 12 | Test glXCopyContext. 13 | 14 | -- Dec 12 2008 15 | 16 | TEST glXCopyContext needs some work and additional code in apple_glx.c. 17 | 18 | ---- 19 | 20 | Make sure we report the proper list of GLX extensions available. Apple direct may not support some 21 | that Mesa does, and vice-versa. 22 | 23 | Modify create_destroy_context and create a new test called create_destroy_context_thread_race. 24 | Where 2 threads are doing the same sort of path of create and destroy. The locking should protect 25 | us there, but we need to verify nothing goes wrong. 26 | 27 | -------------------------------------------------------------------------------- /tests/simple/simple.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/simple: tests/simple/simple.c $(LIBGL) 2 | $(CC) tests/simple/simple.c $(INCLUDE) -o $(TEST_BUILD_DIR)/simple $(LINK_TEST) 3 | 4 | $(TEST_BUILD_DIR)/render_types: tests/simple/render_types.c $(LIBGL) 5 | $(CC) tests/simple/render_types.c $(INCLUDE) -o $(TEST_BUILD_DIR)/render_types $(LINK_TEST) 6 | 7 | $(TEST_BUILD_DIR)/drawable_types: tests/simple/drawable_types.c $(LIBGL) 8 | $(CC) tests/simple/drawable_types.c $(INCLUDE) -o $(TEST_BUILD_DIR)/drawable_types $(LINK_TEST) 9 | 10 | $(TEST_BUILD_DIR)/multisample_glx: tests/simple/multisample_glx.c $(LIBGL) 11 | $(CC) tests/simple/multisample_glx.c $(INCLUDE) -o $(TEST_BUILD_DIR)/multisample_glx $(LINK_TEST) 12 | 13 | $(TEST_BUILD_DIR)/glthreads: tests/simple/glthreads.c $(LIBGL) 14 | $(CC) -DPTHREADS -pthread tests/simple/glthreads.c $(INCLUDE) -o $(TEST_BUILD_DIR)/glthreads $(LINK_TEST) 15 | 16 | $(TEST_BUILD_DIR)/query_drawable: tests/simple/query_drawable.c $(LIBGL) 17 | $(CC) tests/simple/query_drawable.c $(INCLUDE) -o $@ $(LINK_TEST) 18 | -------------------------------------------------------------------------------- /attic/apple_GL_pbuffer_max.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | CGLPixelFormatAttribute attribs[] = { 7 | kCGLPFAAccelerated, 8 | kCGLPFADoubleBuffer, 9 | kCGLPFAColorSize, 24, 10 | 0 11 | }; 12 | 13 | CGLPixelFormatObj pixobj; 14 | GLint npix; 15 | CGLError err; 16 | CGLContextObj context; 17 | GLint maxview[2]; 18 | 19 | err = CGLChoosePixelFormat(attribs, &pixobj, &npix); 20 | 21 | if(err != kCGLNoError) { 22 | fprintf(stderr, "choose pixel format error!\n"); 23 | return EXIT_FAILURE; 24 | } 25 | 26 | err = CGLCreateContext(pixobj, NULL, &context); 27 | 28 | if(err != kCGLNoError) { 29 | fprintf(stderr, "create context error!\n"); 30 | return EXIT_FAILURE; 31 | } 32 | 33 | CGLSetCurrentContext(context); 34 | 35 | maxview[0] = 0; 36 | maxview[1] = 0; 37 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, maxview); 38 | 39 | printf("max pbuffer width %d heigth %d\n", maxview[0], maxview[1]); 40 | 41 | return EXIT_SUCCESS; 42 | } 43 | -------------------------------------------------------------------------------- /gen_gl_h.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INFILE=$1 4 | OUTFILE=$2 5 | 6 | generate_macros() { 7 | grep gl.*ProcPtr /System/Library/Frameworks/OpenGL.framework/Headers/gl{,ext}.h | sed 's:^.*\(gl.*Ptr\).*$:\1:' | sort -u | perl -ne 'chomp($_); $s = "PFN".uc($_); $s =~ s/PROCPTR/PROC/; print "#define ".$_." ".$s."\n"' 8 | } 9 | 10 | generate_function_pointers() { 11 | { 12 | echo "#define GL_GLEXT_FUNCTION_POINTERS 1" 13 | echo "#define GL_GLEXT_LEGACY 1" 14 | generate_macros 15 | echo '#include "/System/Library/Frameworks/OpenGL.framework/Headers/gl.h"' 16 | } | ${CC:-gcc} -E - | grep typedef.*PFN 17 | } 18 | 19 | cat ${INFILE} | while IFS= read LINE ; do 20 | case $LINE in 21 | "@CGL_MESA_COMPAT_MACROS@") 22 | generate_macros 23 | ;; 24 | "@CGL_MESA_FUNCTION_POINTERS@") 25 | if ! grep -q GL_GLEXT_PROTOTYPES /System/Library/Frameworks/OpenGL.framework/Headers/gl.h ; then 26 | generate_function_pointers 27 | fi 28 | ;; 29 | *) 30 | printf "${LINE}\n" 31 | ;; 32 | esac 33 | done > ${OUTFILE} 34 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/triangle_glx: tests/triangle_glx/triangle_glx.c $(LIBGL) 2 | $(CC) tests/triangle_glx/triangle_glx.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx $(LINK_TEST) 3 | 4 | $(TEST_BUILD_DIR)/triangle_glx_surface: tests/triangle_glx/triangle_glx_surface.c $(LIBGL) 5 | $(CC) tests/triangle_glx/triangle_glx_surface.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_surface $(LINK_TEST) 6 | 7 | $(TEST_BUILD_DIR)/triangle_glx_surface-2: tests/triangle_glx/triangle_glx_surface-2.c $(LIBGL) 8 | $(CC) tests/triangle_glx/triangle_glx_surface-2.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_surface-2 $(LINK_TEST) 9 | 10 | $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap: tests/triangle_glx/triangle_glx_withdraw_remap.c $(LIBGL) 11 | $(CC) tests/triangle_glx/triangle_glx_withdraw_remap.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap $(LINK_TEST) 12 | 13 | $(TEST_BUILD_DIR)/triangle_glx_destroy_relation: tests/triangle_glx/triangle_glx_destroy_relation.c $(LIBGL) 14 | $(CC) tests/triangle_glx/triangle_glx_destroy_relation.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_destroy_relation $(LINK_TEST) 15 | -------------------------------------------------------------------------------- /attic/api_delta_generator.tcl: -------------------------------------------------------------------------------- 1 | 2 | proc main {argc argv} { 3 | if {2 != $argc} { 4 | puts stderr "syntax is: [info nameofexecutable] $::argv0 api.list gliDispatch.list" 5 | exit 1 6 | } 7 | 8 | set fd [open [lindex $argv 0] r] 9 | set data [read $fd] 10 | close $fd 11 | 12 | foreach line [split $data \n] { 13 | set gliname [lindex $line 3] 14 | if {"" eq $gliname} continue 15 | set a($gliname) 1 16 | } 17 | 18 | set fd [open [lindex $argv 1] r] 19 | set data [read $fd] 20 | close $fd 21 | 22 | set blist [split $data \n] 23 | 24 | foreach name $blist { 25 | if {"" eq $name} continue 26 | set b($name) 1 27 | } 28 | 29 | #Now find the differences between the 2 arrays. 30 | array set deltas {} 31 | 32 | foreach name [array names a] { 33 | if {[info exists b($name)]} { 34 | set deltas($name) BOTH 35 | } else { 36 | set deltas($name) [lindex $argv 0] 37 | } 38 | } 39 | 40 | foreach name [array names b] { 41 | if {![info exists a($name)]} { 42 | set deltas($name) [lindex $argv 1] 43 | } 44 | } 45 | 46 | parray deltas 47 | 48 | } 49 | main $::argc $::argv 50 | -------------------------------------------------------------------------------- /tests/shared_mapping/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) { 10 | int fd; 11 | size_t length; 12 | void *buffer; 13 | 14 | fd = shm_open("FOOBAR", O_RDWR, 0); 15 | 16 | if(-1 == fd) { 17 | perror("shm_open"); 18 | return EXIT_FAILURE; 19 | } 20 | 21 | 22 | length = sysconf(_SC_PAGESIZE) * 2; 23 | 24 | buffer = mmap(NULL, length, 25 | PROT_READ | PROT_WRITE, 26 | MAP_FILE | MAP_SHARED, fd, 0); 27 | 28 | if(MAP_FAILED == buffer) { 29 | perror("mmap"); 30 | shm_unlink("FOOBAR"); 31 | close(fd); 32 | return EXIT_FAILURE; 33 | } 34 | 35 | while(1) { 36 | unsigned char *cp, *cplimit; 37 | 38 | cp = buffer; 39 | cplimit = cp + length; 40 | 41 | while(cp < cplimit) { 42 | printf("cp %x\n", *cp); 43 | ++cp; 44 | } 45 | 46 | if(-1 == munmap(buffer, length)) 47 | perror("munmap"); 48 | 49 | if(-1 == ftruncate(fd, 10)) 50 | perror("ftruncate"); 51 | } 52 | 53 | 54 | return EXIT_SUCCESS; 55 | } 56 | -------------------------------------------------------------------------------- /tests/create_destroy_context/create_destroy_context.mk: -------------------------------------------------------------------------------- 1 | $(TEST_BUILD_DIR)/create_destroy_context: tests/create_destroy_context/create_destroy_context.c $(LIBGL) 2 | $(CC) tests/create_destroy_context/create_destroy_context.c -Iinclude \ 3 | -o $(TEST_BUILD_DIR)/create_destroy_context $(LINK_TEST) 4 | 5 | $(TEST_BUILD_DIR)/create_destroy_context_alone: tests/create_destroy_context/create_destroy_context_alone.c $(LIBGL) 6 | $(CC) tests/create_destroy_context/create_destroy_context_alone.c -Iinclude \ 7 | -o $(TEST_BUILD_DIR)/create_destroy_context_alone $(LINK_TEST) 8 | 9 | $(TEST_BUILD_DIR)/create_destroy_context_with_drawable: tests/create_destroy_context/create_destroy_context_with_drawable.c $(LIBGL) 10 | $(CC) tests/create_destroy_context/create_destroy_context_with_drawable.c -Iinclude \ 11 | -o $(TEST_BUILD_DIR)/create_destroy_context_with_drawable $(LINK_TEST) 12 | 13 | $(TEST_BUILD_DIR)/create_destroy_context_with_drawable_2: tests/create_destroy_context/create_destroy_context_with_drawable_2.c $(LIBGL) 14 | $(CC) tests/create_destroy_context/create_destroy_context_with_drawable_2.c -Iinclude \ 15 | -o $(TEST_BUILD_DIR)/create_destroy_context_with_drawable_2 $(LINK_TEST) 16 | 17 | -------------------------------------------------------------------------------- /tests/simple/query_drawable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | Display *dpy; 8 | int eventbase, errorbase; 9 | int major, minor; 10 | Window root; 11 | unsigned int width, height; 12 | 13 | dpy = XOpenDisplay(NULL); 14 | 15 | if(NULL == dpy) { 16 | fprintf(stderr, "error: unable to open display!\n"); 17 | return EXIT_FAILURE; 18 | } 19 | 20 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 21 | fprintf(stderr, "GLX is not available!\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | printf("GLX eventbase %d errorbase %d\n", eventbase, errorbase); 26 | 27 | if(!glXQueryVersion(dpy, &major, &minor)) { 28 | fprintf(stderr, "GLX version query error!\n"); 29 | return EXIT_FAILURE; 30 | } 31 | 32 | printf("GLX version: %d.%d\n", major, minor); 33 | 34 | root = DefaultRootWindow(dpy); 35 | 36 | glXQueryDrawable(dpy, root, GLX_WIDTH, &width); 37 | 38 | printf("query 1: width %d\n", width); 39 | 40 | glXQueryDrawable(dpy, root, GLX_HEIGHT, &height); 41 | 42 | printf("query 2: height %d\n", height); 43 | 44 | return EXIT_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /attic/apple_GL_extensions_gen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static void print_extensions(const GLubyte *strings) { 6 | int n = 1; 7 | 8 | printf("extension "); 9 | 10 | for(; *strings; ++strings) { 11 | if(isspace(*strings)) 12 | printf("\nextension"); 13 | 14 | putchar(*strings); 15 | } 16 | 17 | putchar('\n'); 18 | fflush(stdout); 19 | } 20 | 21 | int main() { 22 | CGLPixelFormatAttribute attribs[] = { 23 | kCGLPFAAccelerated, 24 | kCGLPFADoubleBuffer, 25 | kCGLPFAColorSize, 24, 26 | 0 27 | }; 28 | 29 | CGLPixelFormatObj pixobj; 30 | GLint npix; 31 | CGLError err; 32 | CGLContextObj context; 33 | 34 | err = CGLChoosePixelFormat(attribs, &pixobj, &npix); 35 | 36 | if(err != kCGLNoError) { 37 | fprintf(stderr, "choose pixel format error!\n"); 38 | return EXIT_FAILURE; 39 | } 40 | 41 | err = CGLCreateContext(pixobj, NULL, &context); 42 | 43 | if(err != kCGLNoError) { 44 | fprintf(stderr, "create context error!\n"); 45 | return EXIT_FAILURE; 46 | } 47 | 48 | CGLSetCurrentContext(context); 49 | 50 | //printf("%s\n", glGetString(GL_EXTENSIONS)); 51 | 52 | print_extensions(glGetString(GL_EXTENSIONS)); 53 | 54 | return EXIT_SUCCESS; 55 | } 56 | -------------------------------------------------------------------------------- /tests/shared_mapping/server.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) { 10 | int fd; 11 | size_t length; 12 | void *buffer; 13 | int b; 14 | 15 | shm_unlink("FOOBAR"); 16 | 17 | fd = shm_open("FOOBAR", O_RDWR | O_EXCL | O_CREAT, 18 | S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH); 19 | 20 | if(-1 == fd) { 21 | perror("shm_open"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | 26 | length = sysconf(_SC_PAGESIZE) * 2; 27 | 28 | if(-1 == ftruncate(fd, length)) { 29 | perror("ftruncate"); 30 | shm_unlink("FOOBAR"); 31 | close(fd); 32 | return EXIT_FAILURE; 33 | } 34 | 35 | printf("length %zu\n", length); 36 | 37 | buffer = mmap(NULL, length, 38 | PROT_READ | PROT_WRITE, 39 | MAP_FILE | MAP_SHARED, fd, 0); 40 | 41 | if(MAP_FAILED == buffer) { 42 | perror("mmap"); 43 | shm_unlink("FOOBAR"); 44 | close(fd); 45 | return EXIT_FAILURE; 46 | } 47 | 48 | b = 0; 49 | while(1) { 50 | printf("b %d\n", b); 51 | 52 | memset(buffer, b, length); 53 | ++b; 54 | 55 | if(b > 255) 56 | b = 0; 57 | 58 | sleep(1); 59 | } 60 | 61 | 62 | return EXIT_SUCCESS; 63 | } 64 | -------------------------------------------------------------------------------- /tests/triangle/triangle.m: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void initialize(void) { 7 | glEnable(GL_DEPTH_TEST); 8 | } 9 | 10 | void reshape(int width, int height) { 11 | glViewport(0, 0, width, height); 12 | glutPostRedisplay(); 13 | } 14 | 15 | void display(void) { 16 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 17 | glLoadIdentity(); 18 | glBegin(GL_TRIANGLES); 19 | glVertex3f( 0.0f, 1.0f, 0.0f); 20 | glVertex3f(-1.0f,-1.0f, 0.0f); 21 | glVertex3f( 1.0f,-1.0f, 0.0f); 22 | glEnd(); 23 | glFlush(); 24 | } 25 | 26 | int main(int argc, char *argv[]) { 27 | int win; 28 | glutInit(&argc, (char **)argv); 29 | glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH); 30 | glutInitWindowSize(800, 600); 31 | win = glutCreateWindow("Test"); 32 | 33 | initialize(); 34 | 35 | glutReshapeFunc(reshape); 36 | glutDisplayFunc(display); 37 | 38 | printf( "GL_RENDERER = %s\n", (char *) glGetString( GL_RENDERER ) ); 39 | printf( "GL_VERSION = %s\n", (char *) glGetString( GL_VERSION ) ); 40 | printf( "GL_VENDOR = %s\n", (char *) glGetString( GL_VENDOR ) ) ; 41 | printf( "GL_EXTENSIONS = %s\n", (char *) glGetString( GL_EXTENSIONS ) ); 42 | 43 | glutMainLoop(); 44 | 45 | return EXIT_FAILURE; 46 | } 47 | -------------------------------------------------------------------------------- /tests/fbconfigs/fbconfigs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | Display *dpy; 8 | int eventbase, errorbase; 9 | int major, minor; 10 | GLXFBConfig *configs; 11 | int numconfigs, i; 12 | 13 | dpy = XOpenDisplay(NULL); 14 | 15 | if(NULL == dpy) { 16 | fprintf(stderr, "error: unable to open display!\n"); 17 | return EXIT_FAILURE; 18 | } 19 | 20 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 21 | fprintf(stderr, "GLX is not available!\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | printf("GLX eventbase %d errorbase %d\n", eventbase, errorbase); 26 | 27 | if(!glXQueryVersion(dpy, &major, &minor)) { 28 | fprintf(stderr, "GLX version query error!\n"); 29 | return EXIT_FAILURE; 30 | } 31 | 32 | printf("GLX version: %d.%d\n", major, minor); 33 | 34 | configs = glXGetFBConfigs(dpy, DefaultScreen(dpy), &numconfigs); 35 | if(NULL == configs) { 36 | fprintf(stderr, "error: retrieving GLXFBConfigs!\n"); 37 | return EXIT_FAILURE; 38 | } 39 | 40 | for(i = 0; i < numconfigs; ++i) { 41 | int value; 42 | if(Success != glXGetFBConfigAttrib(dpy, configs[i], GLX_STEREO, &value)) { 43 | fprintf(stderr, "unable to query GLX_STEREO!\n"); 44 | return EXIT_FAILURE; 45 | } 46 | 47 | printf("GLXFBConfig[%d] has stereo %d\n", i, value); 48 | } 49 | 50 | 51 | return EXIT_SUCCESS; 52 | } 53 | -------------------------------------------------------------------------------- /tests/simple/render_types.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | Display *dpy; 8 | int eventbase, errorbase; 9 | int major, minor; 10 | GLXFBConfig *fbconfigs; 11 | int i, numfbconfigs; 12 | 13 | dpy = XOpenDisplay(NULL); 14 | 15 | if(NULL == dpy) { 16 | fprintf(stderr, "error: unable to open display!\n"); 17 | return EXIT_FAILURE; 18 | } 19 | 20 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 21 | fprintf(stderr, "GLX is not available!\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | printf("GLX eventbase %d errorbase %d\n", eventbase, errorbase); 26 | 27 | if(!glXQueryVersion(dpy, &major, &minor)) { 28 | fprintf(stderr, "GLX version query error!\n"); 29 | return EXIT_FAILURE; 30 | } 31 | 32 | printf("GLX version: %d.%d\n", major, minor); 33 | 34 | fbconfigs = glXGetFBConfigs(dpy, DefaultScreen(dpy), &numfbconfigs); 35 | 36 | if(NULL == fbconfigs) { 37 | fprintf(stderr, "%s: failed to get GLXFBConfigs!\n", __func__); 38 | return EXIT_FAILURE; 39 | } 40 | 41 | for(i = 0; i < numfbconfigs; ++i) { 42 | int r, value; 43 | 44 | r = glXGetFBConfigAttrib(dpy, fbconfigs[i], GLX_RENDER_TYPE, &value); 45 | 46 | printf("fbconfigs[%d] GLX_RENDER_TYPE is %x supporting %s\n", 47 | i, value, (value == GLX_RGBA_BIT) ? "GLX_RGBA" : "GLX_COLOR_INDEX_BIT"); 48 | } 49 | 50 | return EXIT_SUCCESS; 51 | } 52 | -------------------------------------------------------------------------------- /glx_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | #include 30 | #include 31 | 32 | void __glXSendError(Display * dpy, int errorCode, unsigned long resourceID, 33 | unsigned long minorCode, bool coreX11error); 34 | -------------------------------------------------------------------------------- /apple_xgl_api_viewport.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | #ifndef APPLE_XGL_API_VIEWPORT_H 30 | #define APPLE_XGL_API_VIEWPORT_H 31 | 32 | #include "glxclient.h" 33 | 34 | void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tests/simple/drawable_types.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | Display *dpy; 8 | int eventbase, errorbase; 9 | int major, minor; 10 | GLXFBConfig *fbconfigs; 11 | int i, numfbconfigs; 12 | 13 | dpy = XOpenDisplay(NULL); 14 | 15 | if(NULL == dpy) { 16 | fprintf(stderr, "error: unable to open display!\n"); 17 | return EXIT_FAILURE; 18 | } 19 | 20 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 21 | fprintf(stderr, "GLX is not available!\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | printf("GLX eventbase %d errorbase %d\n", eventbase, errorbase); 26 | 27 | if(!glXQueryVersion(dpy, &major, &minor)) { 28 | fprintf(stderr, "GLX version query error!\n"); 29 | return EXIT_FAILURE; 30 | } 31 | 32 | printf("GLX version: %d.%d\n", major, minor); 33 | 34 | fbconfigs = glXGetFBConfigs(dpy, DefaultScreen(dpy), &numfbconfigs); 35 | 36 | if(NULL == fbconfigs) { 37 | fprintf(stderr, "%s: failed to get GLXFBConfigs!\n", __func__); 38 | return EXIT_FAILURE; 39 | } 40 | 41 | for(i = 0; i < numfbconfigs; ++i) { 42 | int r, value; 43 | 44 | r = glXGetFBConfigAttrib(dpy, fbconfigs[i], GLX_DRAWABLE_TYPE, &value); 45 | 46 | printf("fbconfigs[%d] GLX_DRAWABLE_TYPE is %x supporting: %s %s %s\n", 47 | i, value, 48 | (value & GLX_WINDOW_BIT) ? "GLX_WINDOW_BIT" : "", 49 | (value & GLX_PIXMAP_BIT) ? "GLX_PIXMAP_BIT" : "", 50 | (value & GLX_PBUFFER_BIT) ? "GLX_PBUFFER_BIT" : ""); 51 | } 52 | 53 | return EXIT_SUCCESS; 54 | } 55 | -------------------------------------------------------------------------------- /apple_xgl_api_stereo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include "glxclient.h" 31 | 32 | #ifndef APPLE_XGL_API_STEREO_H 33 | #define APPLE_XGL_API_STEREO_H 34 | 35 | extern void glDrawBuffer(GLenum mode); 36 | extern void glDrawBuffers(GLsizei n, const GLenum * bufs); 37 | extern void glDrawBuffersARB(GLsizei n, const GLenum * bufs); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tests/tests.mk: -------------------------------------------------------------------------------- 1 | .PHONY : tests 2 | 3 | LIBGL=$(TEST_BUILD_DIR)/libGL.dylib 4 | LINK_TEST=-L$(INSTALL_DIR)/lib -L$(X11_DIR)/lib $(LIBGL) -lX11 -lXext -lXplugin -lpthread 5 | 6 | include tests/triangle/triangle.mk 7 | include tests/simple/simple.mk 8 | include tests/fbconfigs/fbconfigs.mk 9 | include tests/triangle_glx/triangle_glx.mk 10 | include tests/create_destroy_context/create_destroy_context.mk 11 | include tests/glxgears/glxgears.mk 12 | include tests/glxinfo/glxinfo.mk 13 | include tests/pbuffer/pbuffer.mk 14 | include tests/texenv/texenv.mk 15 | include tests/engine/engine.mk 16 | include tests/glxpixmap/glxpixmap.mk 17 | include tests/triangle_glx_single/triangle_glx.mk 18 | include tests/shared/shared.mk 19 | 20 | tests: $(TEST_BUILD_DIR)/simple $(TEST_BUILD_DIR)/fbconfigs $(TEST_BUILD_DIR)/triangle_glx \ 21 | $(TEST_BUILD_DIR)/create_destroy_context $(TEST_BUILD_DIR)/glxgears $(TEST_BUILD_DIR)/glxinfo \ 22 | $(TEST_BUILD_DIR)/pbuffer $(TEST_BUILD_DIR)/pbuffer_destroy \ 23 | $(TEST_BUILD_DIR)/glxpixmap \ 24 | $(TEST_BUILD_DIR)/triangle_glx_single \ 25 | $(TEST_BUILD_DIR)/create_destroy_context_alone \ 26 | $(TEST_BUILD_DIR)/create_destroy_context_with_drawable \ 27 | $(TEST_BUILD_DIR)/create_destroy_context_with_drawable_2 \ 28 | $(TEST_BUILD_DIR)/render_types \ 29 | $(TEST_BUILD_DIR)/glxpixmap_create_destroy \ 30 | $(TEST_BUILD_DIR)/sharedtex \ 31 | $(TEST_BUILD_DIR)/drawable_types \ 32 | $(TEST_BUILD_DIR)/glxpixmap_destroy_invalid \ 33 | $(TEST_BUILD_DIR)/multisample_glx \ 34 | $(TEST_BUILD_DIR)/glthreads \ 35 | $(TEST_BUILD_DIR)/triangle_glx_surface \ 36 | $(TEST_BUILD_DIR)/triangle_glx_surface-2 \ 37 | $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap \ 38 | $(TEST_BUILD_DIR)/triangle_glx_destroy_relation \ 39 | $(TEST_BUILD_DIR)/query_drawable 40 | 41 | -------------------------------------------------------------------------------- /apple_visual.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #ifndef APPLE_VISUAL_H 31 | #define APPLE_VISUAL_H 32 | 33 | #include 34 | #include 35 | 36 | /* mode is expected to be of type __GLcontextModes. */ 37 | void apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const void *mode, 38 | bool * double_buffered, bool * uses_stereo, 39 | bool offscreen); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /apple_xgl_api_viewport.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | #include "apple_glx_context.h" 30 | #include "apple_xgl_api.h" 31 | #include "apple_xgl_api_viewport.h" 32 | 33 | extern struct apple_xgl_api __gl_api; 34 | 35 | void 36 | glViewport(GLint x, GLint y, GLsizei width, GLsizei height) 37 | { 38 | GLXContext gc = __glXGetCurrentContext(); 39 | Display *dpy = glXGetCurrentDisplay(); 40 | 41 | if (gc && gc->apple) 42 | apple_glx_context_update(dpy, gc->apple); 43 | 44 | __gl_api.Viewport(x, y, width, height); 45 | } 46 | -------------------------------------------------------------------------------- /gen_defs.tcl: -------------------------------------------------------------------------------- 1 | #This parses and generates #defines from an enum.spec type of file. 2 | 3 | proc main {argc argv} { 4 | if {2 != $argc} { 5 | puts stderr "syntax is: [info script] input.spec output.h" 6 | exit 1 7 | } 8 | 9 | set fd [open [lindex $argv 0] r] 10 | set data [read $fd] 11 | close $fd 12 | 13 | set fd [open [lindex $argv 1] w] 14 | 15 | set state "" 16 | 17 | puts $fd "#define GL_VERSION_1_1 1" 18 | puts $fd "#define GL_VERSION_1_2 1" 19 | puts $fd "#define GL_VERSION_1_3 1" 20 | puts $fd "#define GL_VERSION_1_4 1" 21 | puts $fd "#define GL_VERSION_1_5 1" 22 | puts $fd "#define GL_VERSION_2_0 1" 23 | #puts $fd "#define GL_VERSION_3_0 1" 24 | 25 | set mask "" 26 | array set ar {} 27 | 28 | foreach line [split $data \n] { 29 | if {[regexp {^\S*#.*} $line] > 0} { 30 | #puts COMMENT:$line 31 | set state "" 32 | } elseif {"enum" eq $state} { 33 | if {[string match "\t*" $line]} { 34 | if {[regexp {^\tuse.*} $line] > 0} { 35 | lassign [split [string trim $line]] use usemask def 36 | set usemask [string trim $usemask] 37 | set def [string trim $def] 38 | puts $fd "/* GL_$def */" 39 | } else { 40 | lassign [split [string trim $line] =] def value 41 | set def [string trim $def] 42 | set value [string trim $value] 43 | 44 | #Trim out the data like: 0x0B00 # 4 F 45 | set value [lindex [split $value] 0] 46 | 47 | puts $fd "#define GL_$def $value" 48 | 49 | #Save this association with the value. 50 | set d $ar($mask) 51 | dict set d $def $value 52 | set ar($mask) $d 53 | } 54 | } else { 55 | set state "" 56 | } 57 | } elseif {[string match "* enum:*" $line]} { 58 | lassign [split $line] mask _ 59 | puts $fd "\n/*[string trim $mask]*/" 60 | set ar($mask) [dict create] 61 | set state enum 62 | } 63 | } 64 | 65 | close $fd 66 | } 67 | main $::argc $::argv 68 | -------------------------------------------------------------------------------- /apple_glx.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #ifndef APPLE_GLX_H 31 | #define APPLE_GLX_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #define XP_NO_X_HEADERS 39 | #include 40 | 41 | void apple_glx_diagnostic(const char *fmt, ...); 42 | xp_client_id apple_glx_get_client_id(void); 43 | bool apple_init_glx(Display * dpy); 44 | void apple_glx_swap_buffers(void *ptr); 45 | void *apple_glx_get_proc_address(const GLubyte * procname); 46 | void apple_glx_waitx(Display * dpy, void *ptr); 47 | int apple_get_dri_event_base(void); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /gen_code.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | Copyright (c) 2008 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | } 29 | 30 | package require Tcl 8.5 31 | 32 | proc main {} { 33 | set tclsh [info nameofexecutable] 34 | 35 | puts TYPES 36 | exec $tclsh ./gen_types.tcl stage.1 37 | puts DEFS 38 | exec $tclsh ./gen_defs.tcl specs/enum.spec stage.2 39 | puts FUNCS 40 | exec $tclsh ./gen_funcs.tcl specs/gl.spec stage.3 stage.4 41 | puts HEADER 42 | exec $tclsh ./gen_api_header.tcl stage.4 apple_xgl_api.h 43 | puts "C API" 44 | exec $tclsh ./gen_api_library.tcl stage.4 apple_xgl_api.c 45 | puts "EXPORTS" 46 | exec $tclsh ./gen_exports.tcl stage.4 exports.list 47 | 48 | return 0 49 | } 50 | exit [main] 51 | -------------------------------------------------------------------------------- /apple_xgl_api_read.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | /* 31 | * This file works with the glXMakeContextCurrent readable drawable. 32 | */ 33 | #ifndef APPLE_XGL_API_READ_H 34 | #define APPLE_XGL_API_READ_H 35 | 36 | #include "glxclient.h" 37 | 38 | extern void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, 39 | GLenum format, GLenum type, void *pixels); 40 | 41 | extern void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, 42 | GLenum type); 43 | 44 | extern void glCopyColorTable(GLenum target, GLenum internalformat, GLint x, 45 | GLint y, GLsizei width); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /attic/gliDispatch_to_list.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | gliDispatch_to_list.tcl -- This generates a list of Apple OpenGL 3 | functions based on the gliDispatch.h header file. This tool is 4 | used to decide which OpenGL functions to make direct. 5 | 6 | Copyright (c) 2008 Apple Inc. 7 | 8 | Permission is hereby granted, free of charge, to any person 9 | obtaining a copy of this software and associated documentation files 10 | (the "Software"), to deal in the Software without restriction, 11 | including without limitation the rights to use, copy, modify, merge, 12 | publish, distribute, sublicense, and/or sell copies of the Software, 13 | and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 23 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | 28 | Except as contained in this notice, the name(s) of the above 29 | copyright holders shall not be used in advertising or otherwise to 30 | promote the sale, use or other dealings in this Software without 31 | prior written authorization. 32 | } 33 | 34 | 35 | proc main {argv} { 36 | set fd [open [lindex $argv 0] r] 37 | set data [read $fd] 38 | close $fd 39 | 40 | set glifuncs [list] 41 | 42 | foreach line [split $data \n] { 43 | #puts LINE:$line 44 | foreach {allmatch exact} [regexp -inline -all {.*?\s\(\*([^\)]+)\).*?} $line] { 45 | lappend glifuncs $exact 46 | } 47 | } 48 | 49 | foreach i $glifuncs { 50 | puts $i 51 | } 52 | 53 | exit 0 54 | } 55 | main $::argv -------------------------------------------------------------------------------- /tests/create_destroy_context/create_destroy_context_alone.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | Display *dpy; 11 | int attrib[] = { GLX_RGBA, 12 | GLX_RED_SIZE, 8, 13 | GLX_GREEN_SIZE, 8, 14 | GLX_BLUE_SIZE, 8, 15 | GLX_DEPTH_SIZE, 24, 16 | GLX_DOUBLEBUFFER, 17 | None }; 18 | int eventbase, errorbase; 19 | int screen; 20 | Window root, win; 21 | XVisualInfo *visinfo; 22 | XSetWindowAttributes attr; 23 | GLXContext ctx; 24 | int iter; 25 | unsigned int p; 26 | 27 | dpy = XOpenDisplay(NULL); 28 | 29 | if(NULL == dpy) { 30 | fprintf(stderr, "error: unable to open display!\n"); 31 | return EXIT_FAILURE; 32 | } 33 | 34 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 35 | fprintf(stderr, "GLX is not available!\n"); 36 | return EXIT_FAILURE; 37 | } 38 | 39 | screen = DefaultScreen(dpy); 40 | root = RootWindow(dpy, screen); 41 | 42 | visinfo = glXChooseVisual(dpy, screen, attrib); 43 | 44 | if(!visinfo) { 45 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 46 | return EXIT_FAILURE; 47 | } 48 | 49 | attr.background_pixel = 0; 50 | attr.border_pixel = 0; 51 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 52 | attr.event_mask = StructureNotifyMask | ExposureMask; 53 | 54 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 55 | /*width*/ 400, /*height*/ 400, 56 | 0, visinfo->depth, InputOutput, 57 | visinfo->visual, 58 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 59 | &attr); 60 | 61 | p = (unsigned int)getpid(); 62 | 63 | printf("pid %u\n", p); 64 | 65 | while(1) { 66 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 67 | if(!ctx) { 68 | fprintf(stderr, "error: glXCreateContext failed!\n"); 69 | return EXIT_FAILURE; 70 | } 71 | 72 | glXDestroyContext(dpy, ctx); 73 | } 74 | 75 | return EXIT_SUCCESS; 76 | } 77 | -------------------------------------------------------------------------------- /tests/create_destroy_context/create_destroy_context_with_drawable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | Display *dpy; 11 | int attrib[] = { GLX_RGBA, 12 | GLX_RED_SIZE, 8, 13 | GLX_GREEN_SIZE, 8, 14 | GLX_BLUE_SIZE, 8, 15 | GLX_DEPTH_SIZE, 24, 16 | GLX_DOUBLEBUFFER, 17 | None }; 18 | int eventbase, errorbase; 19 | int screen; 20 | Window root, win; 21 | XVisualInfo *visinfo; 22 | XSetWindowAttributes attr; 23 | GLXContext ctx; 24 | int iter; 25 | unsigned int p; 26 | 27 | dpy = XOpenDisplay(NULL); 28 | 29 | if(NULL == dpy) { 30 | fprintf(stderr, "error: unable to open display!\n"); 31 | return EXIT_FAILURE; 32 | } 33 | 34 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 35 | fprintf(stderr, "GLX is not available!\n"); 36 | return EXIT_FAILURE; 37 | } 38 | 39 | screen = DefaultScreen(dpy); 40 | root = RootWindow(dpy, screen); 41 | 42 | visinfo = glXChooseVisual(dpy, screen, attrib); 43 | 44 | if(!visinfo) { 45 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 46 | return EXIT_FAILURE; 47 | } 48 | 49 | attr.background_pixel = 0; 50 | attr.border_pixel = 0; 51 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 52 | attr.event_mask = StructureNotifyMask | ExposureMask; 53 | 54 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 55 | /*width*/ 400, /*height*/ 400, 56 | 0, visinfo->depth, InputOutput, 57 | visinfo->visual, 58 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 59 | &attr); 60 | 61 | p = (unsigned int)getpid(); 62 | printf("pid %u\n", p); 63 | 64 | while(1) { 65 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 66 | if(!ctx) { 67 | fprintf(stderr, "error: glXCreateContext failed!\n"); 68 | return EXIT_FAILURE; 69 | } 70 | 71 | glXMakeCurrent(dpy, win, ctx); 72 | 73 | /* We can't destroy a context if it's still current according to the 74 | * documentation. 75 | */ 76 | glXMakeCurrent(dpy, None, NULL); 77 | 78 | glXDestroyContext(dpy, ctx); 79 | 80 | sleep(1); 81 | } 82 | 83 | return EXIT_SUCCESS; 84 | } 85 | -------------------------------------------------------------------------------- /glx_error.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "glxclient.h" 34 | #include "glx_error.h" 35 | 36 | extern XExtDisplayInfo *__glXFindDisplay(Display * dpy); 37 | 38 | void 39 | __glXSendError(Display * dpy, int errorCode, unsigned long resourceID, 40 | unsigned long minorCode, bool coreX11error) 41 | { 42 | XExtDisplayInfo *info = __glXFindDisplay(dpy); 43 | GLXContext gc = __glXGetCurrentContext(); 44 | xError error; 45 | 46 | LockDisplay(dpy); 47 | 48 | error.type = X_Error; 49 | 50 | if (coreX11error) { 51 | error.errorCode = errorCode; 52 | } 53 | else { 54 | error.errorCode = info->codes->first_error + errorCode; 55 | } 56 | 57 | error.sequenceNumber = dpy->request; 58 | error.resourceID = resourceID; 59 | error.minorCode = minorCode; 60 | error.majorCode = gc ? gc->majorOpcode : 0; 61 | 62 | _XError(dpy, &error); 63 | 64 | UnlockDisplay(dpy); 65 | } 66 | -------------------------------------------------------------------------------- /tests/create_destroy_context/create_destroy_context_with_drawable_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | Display *dpy; 11 | int attrib[] = { GLX_RGBA, 12 | GLX_RED_SIZE, 8, 13 | GLX_GREEN_SIZE, 8, 14 | GLX_BLUE_SIZE, 8, 15 | GLX_DEPTH_SIZE, 24, 16 | GLX_DOUBLEBUFFER, 17 | None }; 18 | int eventbase, errorbase; 19 | int screen; 20 | Window root, win; 21 | XVisualInfo *visinfo; 22 | XSetWindowAttributes attr; 23 | GLXContext ctx; 24 | int iter; 25 | unsigned int p; 26 | 27 | dpy = XOpenDisplay(NULL); 28 | 29 | if(NULL == dpy) { 30 | fprintf(stderr, "error: unable to open display!\n"); 31 | return EXIT_FAILURE; 32 | } 33 | 34 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 35 | fprintf(stderr, "GLX is not available!\n"); 36 | return EXIT_FAILURE; 37 | } 38 | 39 | screen = DefaultScreen(dpy); 40 | root = RootWindow(dpy, screen); 41 | 42 | visinfo = glXChooseVisual(dpy, screen, attrib); 43 | 44 | if(!visinfo) { 45 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 46 | return EXIT_FAILURE; 47 | } 48 | 49 | attr.background_pixel = 0; 50 | attr.border_pixel = 0; 51 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 52 | attr.event_mask = StructureNotifyMask | ExposureMask; 53 | 54 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 55 | /*width*/ 400, /*height*/ 400, 56 | 0, visinfo->depth, InputOutput, 57 | visinfo->visual, 58 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 59 | &attr); 60 | 61 | p = (unsigned int)getpid(); 62 | printf("pid %u\n", p); 63 | 64 | while(1) { 65 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 66 | if(!ctx) { 67 | fprintf(stderr, "error: glXCreateContext failed!\n"); 68 | return EXIT_FAILURE; 69 | } 70 | 71 | glXMakeCurrent(dpy, win, ctx); 72 | glXDestroyContext(dpy, ctx); 73 | /* 74 | * This should free the memory associated with the context, 75 | * because a current context can't be freed. Thus, the 76 | * glXDestroyContext sets a flag to indicate it should be destroyed, 77 | * and the next time the current context changes, we destroy it. 78 | */ 79 | glXMakeCurrent(dpy, None, NULL); 80 | 81 | sleep(1); 82 | } 83 | 84 | return EXIT_SUCCESS; 85 | } 86 | -------------------------------------------------------------------------------- /glcontextmodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright IBM Corporation 2003 3 | * All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * on the rights to use, copy, modify, merge, publish, distribute, sub 9 | * license, and/or sell copies of the Software, and to permit persons to whom 10 | * the Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including the next 13 | * paragraph) shall be included in all copies or substantial portions of the 14 | * Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19 | * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 | * USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * \file glcontextmodes.h 27 | * \author Ian Romanick 28 | */ 29 | 30 | #ifndef GLCONTEXTMODES_H 31 | #define GLCONTEXTMODES_H 32 | 33 | #include "GL/internal/glcore.h" 34 | 35 | #if !defined(IN_MINI_GLX) 36 | extern GLint _gl_convert_from_x_visual_type(int visualType); 37 | extern GLint _gl_convert_to_x_visual_type(int visualType); 38 | extern void _gl_copy_visual_to_context_mode(__GLcontextModes * mode, 39 | const __GLXvisualConfig * config); 40 | extern int _gl_get_context_mode_data(const __GLcontextModes * mode, 41 | int attribute, int *value_return); 42 | #endif /* !defined(IN_MINI_GLX) */ 43 | 44 | extern __GLcontextModes *_gl_context_modes_create(unsigned count, 45 | size_t minimum_size); 46 | extern void _gl_context_modes_destroy(__GLcontextModes * modes); 47 | extern __GLcontextModes *_gl_context_modes_find_visual(__GLcontextModes * 48 | modes, int vid); 49 | extern __GLcontextModes *_gl_context_modes_find_fbconfig(__GLcontextModes * 50 | modes, int fbid); 51 | extern GLboolean _gl_context_modes_are_same(const __GLcontextModes * a, 52 | const __GLcontextModes * b); 53 | 54 | #endif /* GLCONTEXTMODES_H */ 55 | -------------------------------------------------------------------------------- /gen_api_header.tcl: -------------------------------------------------------------------------------- 1 | 2 | package require Tcl 8.5 3 | 4 | set license { 5 | /* 6 | Copyright (c) 2008, 2009 Apple Inc. 7 | 8 | Permission is hereby granted, free of charge, to any person 9 | obtaining a copy of this software and associated documentation files 10 | (the "Software"), to deal in the Software without restriction, 11 | including without limitation the rights to use, copy, modify, merge, 12 | publish, distribute, sublicense, and/or sell copies of the Software, 13 | and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 23 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | 28 | Except as contained in this notice, the name(s) of the above 29 | copyright holders shall not be used in advertising or otherwise to 30 | promote the sale, use or other dealings in this Software without 31 | prior written authorization. 32 | */ 33 | } 34 | 35 | set this_script [info script] 36 | 37 | proc main {argc argv} { 38 | if {2 != $argc} { 39 | puts stderr "syntax is: [set ::this_script] serialized-array-file output.h" 40 | return 1 41 | } 42 | 43 | set fd [open [lindex $argv 0] r] 44 | array set api [read $fd] 45 | close $fd 46 | 47 | set fd [open [lindex $argv 1] w] 48 | 49 | puts $fd "/* This file was automatically generated by [set ::this_script]. */" 50 | puts $fd $::license 51 | 52 | puts $fd " 53 | #ifndef APPLE_XGL_API_H 54 | #define APPLE_XGL_API_H 55 | " 56 | 57 | puts $fd "struct apple_xgl_api \{" 58 | 59 | set sorted [lsort -dictionary [array names api]] 60 | 61 | foreach f $sorted { 62 | set attr $api($f) 63 | set pstr "" 64 | 65 | if {[dict exists $attr alias_for] || [dict exists $attr noop]} { 66 | #Skip this function. 67 | continue 68 | } 69 | 70 | foreach p [dict get $attr parameters] { 71 | append pstr "[lindex $p 0] [lindex $p 1], " 72 | } 73 | 74 | set pstr [string trimright $pstr ", "] 75 | puts $fd "\t[dict get $attr return] (*[set f])([set pstr]);" 76 | } 77 | 78 | puts $fd "\};" 79 | puts $fd "void apple_xgl_init_direct(void); 80 | 81 | #endif /*APPLE_XGL_API_H*/ 82 | " 83 | 84 | return 0 85 | } 86 | exit [main $::argc $::argv] -------------------------------------------------------------------------------- /RELEASE_NOTES: -------------------------------------------------------------------------------- 1 | AppleSGLX Release Notes 2 | 3 | o OpenGL Support 4 | 5 | AppleSGLX supports the same version of OpenGL as Leopard (OpenGL 2.1). 6 | Many extensions from the OpenGL framework are now builtin. 7 | 8 | This adds support for GLSL, and a variety of other features. 9 | 10 | o Thread Support 11 | 12 | Thread support has been improved since the libGL in XQuartz 2.3.2.1. 13 | 14 | o GLX 1.4 Support 15 | 16 | The GLX 1.3 and 1.4 functions should all work with a few exceptions 17 | as outlined in this document. 18 | 19 | o glXMakeContextCurrent (a GLX 1.3 feature) 20 | 21 | glXMakeContextCurrent should work with the readable drawable. The 22 | OpenGL functions: glReadPixels, glCopyPixels, and glCopyColorTable, 23 | should use the readable drawable if it's different than the rendering 24 | drawable. 25 | 26 | o glXGetProcAddress (a GLX 1.4 feature and ARB extension) 27 | 28 | glXGetProcAddress should work and allow getting the address of any 29 | extension functions you may need from the X11 libGL, or OpenGL framework 30 | libGL. Previous versions of the X11 libGL didn't allow getting the newer 31 | OpenGL framework addresses. 32 | 33 | o GLXPixmaps 34 | 35 | New support for GLXPixmaps works well with mixed X11 and OpenGL drawing 36 | operations. You can create them using glXCreateGLXPixmap or 37 | glXCreatePixmap. 38 | 39 | o GLXPbuffers 40 | 41 | Support for GLXPbuffers has been added. These are drawables that are 42 | not possible to render to with X11, which is allowed by the spec. 43 | A GLXPbuffer will never generate a clobber event, however 44 | glXSelectEvent and glXGetSelectedEvent should operate normally. 45 | 46 | Clobber events are not generated due to low-level architectural 47 | differences. The contents of your pbuffers will not be clobbered. 48 | 49 | o Shared Contexts 50 | 51 | Due to basic low-level architectural differences the usage of shared 52 | contexts requires a similar visual or GLXFBConfig be used in the 53 | creation of a shared context. It's best if you specify the same 54 | visual. This is due to a CGL design difference, and not something 55 | that is easily worked around. UPDATE: some changes made seem to 56 | help resolve this issue in many cases, so you may be able to use a 57 | shared context without this restriction. 58 | 59 | 60 | o Indirect 61 | 62 | The X server supports indirect fairly well, so OpenGL applications 63 | can be run remotely and displayed by XQuartz. This means you can run 64 | applications from a remote host on an XQuartz X server. 65 | 66 | AppleSGLX does not support indirect rendering. Any indirect context 67 | created will appear to glXIsDirect as an indirect context, but it 68 | does not actually support indirect rendering to a remote X server. 69 | 70 | AppleSGLX supports GLXPixmaps and GLXPbuffers with direct and indirect 71 | contexts, though they are all direct contexts by definition (see above). 72 | -------------------------------------------------------------------------------- /tests/triangle_glx_single/triangle_glx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void draw(Display *dpy, Window w) { 7 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 8 | glLoadIdentity(); 9 | glColor3f(0.5f, 0.5f, 1.0f); 10 | glBegin(GL_TRIANGLES); 11 | glVertex3f( 0.0f, 1.0f, 0.0f); 12 | glVertex3f(-1.0f,-1.0f, 0.0f); 13 | glVertex3f( 1.0f,-1.0f, 0.0f); 14 | glEnd(); 15 | glXSwapBuffers(dpy, w); 16 | } 17 | 18 | void resize(Display *dpy, Window w, int width, int height) { 19 | glViewport(0, 0, width, height); 20 | draw(dpy, w); 21 | } 22 | 23 | void event_loop(Display *dpy) { 24 | XEvent event; 25 | 26 | while(1) { 27 | XNextEvent(dpy, &event); 28 | 29 | switch(event.type) { 30 | case Expose: 31 | draw(dpy, event.xexpose.window); 32 | break; 33 | 34 | case ConfigureNotify: 35 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 36 | event.xconfigure.height); 37 | break; 38 | } 39 | } 40 | } 41 | 42 | int main() { 43 | Display *dpy; 44 | int attrib[] = { GLX_RGBA, 45 | GLX_RED_SIZE, 8, 46 | GLX_GREEN_SIZE, 8, 47 | GLX_BLUE_SIZE, 8, 48 | GLX_DEPTH_SIZE, 24, 49 | None }; 50 | int eventbase, errorbase; 51 | int screen; 52 | Window root, win; 53 | XVisualInfo *visinfo; 54 | XSetWindowAttributes attr; 55 | GLXContext ctx; 56 | 57 | dpy = XOpenDisplay(NULL); 58 | 59 | if(NULL == dpy) { 60 | fprintf(stderr, "error: unable to open display!\n"); 61 | return EXIT_FAILURE; 62 | } 63 | 64 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 65 | fprintf(stderr, "GLX is not available!\n"); 66 | return EXIT_FAILURE; 67 | } 68 | 69 | screen = DefaultScreen(dpy); 70 | root = RootWindow(dpy, screen); 71 | 72 | visinfo = glXChooseVisual(dpy, screen, attrib); 73 | 74 | if(!visinfo) { 75 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 76 | return EXIT_FAILURE; 77 | } 78 | 79 | attr.background_pixel = 0; 80 | attr.border_pixel = 0; 81 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 82 | attr.event_mask = StructureNotifyMask | ExposureMask; 83 | 84 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 85 | /*width*/ 400, /*height*/ 400, 86 | 0, visinfo->depth, InputOutput, 87 | visinfo->visual, 88 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 89 | &attr); 90 | 91 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 92 | if(!ctx) { 93 | fprintf(stderr, "error: glXCreateContext failed!\n"); 94 | return EXIT_FAILURE; 95 | } 96 | 97 | XMapWindow(dpy, win); 98 | 99 | glXMakeCurrent(dpy, win, ctx); 100 | 101 | event_loop(dpy); 102 | 103 | return EXIT_SUCCESS; 104 | } 105 | -------------------------------------------------------------------------------- /attic/api_to_code.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | api_to_code.tcl -- This generates the API frontend functions for libGL. 3 | 4 | Copyright (c) 2008 Apple Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation files 8 | (the "Software"), to deal in the Software without restriction, 9 | including without limitation the rights to use, copy, modify, merge, 10 | publish, distribute, sublicense, and/or sell copies of the Software, 11 | and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 21 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | 26 | Except as contained in this notice, the name(s) of the above 27 | copyright holders shall not be used in advertising or otherwise to 28 | promote the sale, use or other dealings in this Software without 29 | prior written authorization. 30 | } 31 | 32 | set ::template { 33 | _GLXcontext *gc; 34 | 35 | gc = __glXGetCurrentContext(); 36 | 37 | if(gc->isDirect) { 38 | OPTIONAL_RETURN gc->apple.contextobj->disp.MEMBER(gc->apple.contextobj, ARGUMENTS); 39 | } else { 40 | struct _glapi_table *disp = _glapi_dispatch; 41 | if(__builtin_expect (disp == NULL, 0)) { 42 | /* TODO verify that _glapi_get_dispatch aborts if it fails. 43 | * otherwise we get a segfault here after this. 44 | */ 45 | disp = _glapi_get_dispatch (); 46 | } 47 | 48 | OPTIONAL_RETURN disp.INDIRECT_MEMBER(ARGUMENTS); 49 | } 50 | } 51 | 52 | proc main {argc argv} { 53 | global template 54 | 55 | set fd [open [lindex $argv 0] r] 56 | set data [read $fd] 57 | close $fd 58 | 59 | set outfd [open [lindex $argv 1] w] 60 | 61 | foreach flist [split $data \n] { 62 | foreach {rettype name argpat member indirect_member} $flist { 63 | puts $outfd "$rettype gl[set name]([join $argpat ", "]) \{" 64 | 65 | set optreturn "" 66 | if {$rettype ne "void"} { 67 | set optreturn return 68 | } 69 | 70 | set arguments "" 71 | foreach typevar $argpat { 72 | set var [lindex $typevar 1] 73 | append arguments "$var, " 74 | } 75 | set arguments [string trimright $arguments ", "] 76 | 77 | puts $outfd [string map \ 78 | [list OPTIONAL_RETURN $optreturn INDIRECT_MEMBER $indirect_member \ 79 | MEMBER $member ARGUMENTS $arguments] $template] 80 | 81 | puts $outfd "\}" 82 | } 83 | } 84 | close $outfd 85 | exit 0 86 | } 87 | main $::argc $::argv 88 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void draw(Display *dpy, Window w) { 7 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 8 | glLoadIdentity(); 9 | glColor3f(0.5f, 0.5f, 1.0f); 10 | glBegin(GL_TRIANGLES); 11 | glVertex3f( 0.0f, 1.0f, 0.0f); 12 | glVertex3f(-1.0f,-1.0f, 0.0f); 13 | glVertex3f( 1.0f,-1.0f, 0.0f); 14 | glEnd(); 15 | glXSwapBuffers(dpy, w); 16 | } 17 | 18 | void resize(Display *dpy, Window w, int width, int height) { 19 | glViewport(0, 0, width, height); 20 | draw(dpy, w); 21 | } 22 | 23 | void event_loop(Display *dpy) { 24 | XEvent event; 25 | 26 | while(1) { 27 | XNextEvent(dpy, &event); 28 | 29 | switch(event.type) { 30 | case Expose: 31 | draw(dpy, event.xexpose.window); 32 | break; 33 | 34 | case ConfigureNotify: 35 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 36 | event.xconfigure.height); 37 | break; 38 | } 39 | } 40 | } 41 | 42 | int main() { 43 | Display *dpy; 44 | int attrib[] = { GLX_RGBA, 45 | GLX_RED_SIZE, 8, 46 | GLX_GREEN_SIZE, 8, 47 | GLX_BLUE_SIZE, 8, 48 | GLX_DEPTH_SIZE, 24, 49 | GLX_DOUBLEBUFFER, 50 | None }; 51 | int eventbase, errorbase; 52 | int screen; 53 | Window root, win; 54 | XVisualInfo *visinfo; 55 | XSetWindowAttributes attr; 56 | GLXContext ctx; 57 | 58 | dpy = XOpenDisplay(NULL); 59 | 60 | if(NULL == dpy) { 61 | fprintf(stderr, "error: unable to open display!\n"); 62 | return EXIT_FAILURE; 63 | } 64 | 65 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 66 | fprintf(stderr, "GLX is not available!\n"); 67 | return EXIT_FAILURE; 68 | } 69 | 70 | screen = DefaultScreen(dpy); 71 | root = RootWindow(dpy, screen); 72 | 73 | visinfo = glXChooseVisual(dpy, screen, attrib); 74 | 75 | if(!visinfo) { 76 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 77 | return EXIT_FAILURE; 78 | } 79 | 80 | attr.background_pixel = 0; 81 | attr.border_pixel = 0; 82 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 83 | attr.event_mask = StructureNotifyMask | ExposureMask; 84 | 85 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 86 | /*width*/ 400, /*height*/ 400, 87 | 0, visinfo->depth, InputOutput, 88 | visinfo->visual, 89 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 90 | &attr); 91 | 92 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 93 | if(!ctx) { 94 | fprintf(stderr, "error: glXCreateContext failed!\n"); 95 | return EXIT_FAILURE; 96 | } 97 | 98 | XMapWindow(dpy, win); 99 | 100 | glXMakeCurrent(dpy, win, ctx); 101 | printf("passed dpy %p current dpy %p\n", (void *)dpy, 102 | (void *)glXGetCurrentDisplay()); 103 | 104 | event_loop(dpy); 105 | 106 | return EXIT_SUCCESS; 107 | } 108 | -------------------------------------------------------------------------------- /tests/glxpixmap/glxpixmap_destroy_invalid.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * A demonstration of using the GLXPixmap functions. This program is in 5 | * the public domain. 6 | * 7 | * Brian Paul 8 | */ 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | static GLXContext ctx; 19 | static XVisualInfo *visinfo; 20 | static GC gc; 21 | 22 | 23 | 24 | static Window make_rgb_window( Display *dpy, 25 | unsigned int width, unsigned int height ) 26 | { 27 | const int sbAttrib[] = { GLX_RGBA, 28 | GLX_RED_SIZE, 1, 29 | GLX_GREEN_SIZE, 1, 30 | GLX_BLUE_SIZE, 1, 31 | None }; 32 | const int dbAttrib[] = { GLX_RGBA, 33 | GLX_RED_SIZE, 1, 34 | GLX_GREEN_SIZE, 1, 35 | GLX_BLUE_SIZE, 1, 36 | GLX_DOUBLEBUFFER, 37 | None }; 38 | int scrnum; 39 | XSetWindowAttributes attr; 40 | unsigned long mask; 41 | Window root; 42 | Window win; 43 | 44 | scrnum = DefaultScreen( dpy ); 45 | root = RootWindow( dpy, scrnum ); 46 | 47 | visinfo = glXChooseVisual( dpy, scrnum, (int *) sbAttrib ); 48 | if (!visinfo) { 49 | visinfo = glXChooseVisual( dpy, scrnum, (int *) dbAttrib ); 50 | if (!visinfo) { 51 | printf("Error: couldn't get an RGB visual\n"); 52 | exit(1); 53 | } 54 | } 55 | 56 | /* window attributes */ 57 | attr.background_pixel = 0; 58 | attr.border_pixel = 0; 59 | /* TODO: share root colormap if possible */ 60 | attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); 61 | attr.event_mask = StructureNotifyMask | ExposureMask; 62 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; 63 | 64 | win = XCreateWindow( dpy, root, 0, 0, width, height, 65 | 0, visinfo->depth, InputOutput, 66 | visinfo->visual, mask, &attr ); 67 | 68 | /* make an X GC so we can do XCopyArea later */ 69 | gc = XCreateGC( dpy, win, 0, NULL ); 70 | 71 | /* need indirect context */ 72 | ctx = glXCreateContext( dpy, visinfo, NULL, False ); 73 | if (!ctx) { 74 | printf("Error: glXCreateContext failed\n"); 75 | exit(-1); 76 | } 77 | 78 | printf("Direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); 79 | 80 | return win; 81 | } 82 | 83 | int main( int argc, char *argv[] ) 84 | { 85 | Display *dpy; 86 | Window win; 87 | Pixmap pm; 88 | GLXPixmap glxpm; 89 | int eventbase, errorbase; 90 | 91 | dpy = XOpenDisplay(NULL); 92 | 93 | if(NULL == dpy) { 94 | fprintf(stderr, "error: opening display\n"); 95 | return EXIT_FAILURE; 96 | } 97 | 98 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 99 | fprintf(stderr, "GLX is not available!\n"); 100 | return EXIT_FAILURE; 101 | } 102 | 103 | 104 | win = make_rgb_window( dpy, 300, 300 ); 105 | 106 | fprintf(stderr, "This test should produce a GLXBadPixmap error.\n"); 107 | 108 | glXDestroyPixmap(dpy, /*intentional*/ win); 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx_surface.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | Window mainwin; 7 | GLXContext ctx; 8 | 9 | void draw(Display *dpy, Window w) { 10 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 11 | glLoadIdentity(); 12 | glColor3f(0.5f, 0.5f, 1.0f); 13 | glBegin(GL_TRIANGLES); 14 | glVertex3f( 0.0f, 1.0f, 0.0f); 15 | glVertex3f(-1.0f,-1.0f, 0.0f); 16 | glVertex3f( 1.0f,-1.0f, 0.0f); 17 | glEnd(); 18 | glXSwapBuffers(dpy, w); 19 | } 20 | 21 | void resize(Display *dpy, Window w, int width, int height) { 22 | glViewport(0, 0, width, height); 23 | draw(dpy, w); 24 | } 25 | 26 | void event_loop(Display *dpy) { 27 | XEvent event; 28 | 29 | while(1) { 30 | if(XPending(dpy) > 0) { 31 | XNextEvent(dpy, &event); 32 | 33 | switch(event.type) { 34 | case Expose: 35 | draw(dpy, event.xexpose.window); 36 | break; 37 | 38 | case ConfigureNotify: 39 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 40 | event.xconfigure.height); 41 | break; 42 | } 43 | } 44 | 45 | draw(dpy, mainwin); 46 | /* This should destroy the surface. */ 47 | glXMakeCurrent(dpy, None, ctx); 48 | /* This should recreate the surface. */ 49 | glXMakeCurrent(dpy, mainwin, ctx); 50 | } 51 | } 52 | 53 | int main() { 54 | Display *dpy; 55 | int attrib[] = { GLX_RGBA, 56 | GLX_RED_SIZE, 8, 57 | GLX_GREEN_SIZE, 8, 58 | GLX_BLUE_SIZE, 8, 59 | GLX_DEPTH_SIZE, 24, 60 | GLX_DOUBLEBUFFER, 61 | None }; 62 | int eventbase, errorbase; 63 | int screen; 64 | Window root, win; 65 | XVisualInfo *visinfo; 66 | XSetWindowAttributes attr; 67 | 68 | dpy = XOpenDisplay(NULL); 69 | 70 | if(NULL == dpy) { 71 | fprintf(stderr, "error: unable to open display!\n"); 72 | return EXIT_FAILURE; 73 | } 74 | 75 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 76 | fprintf(stderr, "GLX is not available!\n"); 77 | return EXIT_FAILURE; 78 | } 79 | 80 | screen = DefaultScreen(dpy); 81 | root = RootWindow(dpy, screen); 82 | 83 | visinfo = glXChooseVisual(dpy, screen, attrib); 84 | 85 | if(!visinfo) { 86 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 87 | return EXIT_FAILURE; 88 | } 89 | 90 | attr.background_pixel = 0; 91 | attr.border_pixel = 0; 92 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 93 | attr.event_mask = StructureNotifyMask | ExposureMask; 94 | 95 | mainwin = win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 96 | /*width*/ 400, /*height*/ 400, 97 | 0, visinfo->depth, InputOutput, 98 | visinfo->visual, 99 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 100 | &attr); 101 | 102 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 103 | if(!ctx) { 104 | fprintf(stderr, "error: glXCreateContext failed!\n"); 105 | return EXIT_FAILURE; 106 | } 107 | 108 | XMapWindow(dpy, win); 109 | 110 | glXMakeCurrent(dpy, win, ctx); 111 | 112 | event_loop(dpy); 113 | 114 | return EXIT_SUCCESS; 115 | } 116 | -------------------------------------------------------------------------------- /tests/cgl_growth.c: -------------------------------------------------------------------------------- 1 | /* Test case for a CGL leak that seems to involve glRectf and only occurs 2 | * with CGLSetOffScreen (from what I've seen so far). 3 | * Author: George Staplin. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main(int argc, char *argv[]) { 13 | CGLPixelFormatAttribute attr[60]; 14 | CGLPixelFormatObj pfobj; 15 | CGLContextObj ctxobj; 16 | int numattr = 0; 17 | GLint vsref = 0; 18 | CGLError error; 19 | int width, height, pitch; 20 | void *ptr; 21 | double rcolor, gcolor, bcolor; 22 | 23 | attr[numattr++] = kCGLPFAOffScreen; 24 | attr[numattr++] = kCGLPFAColorSize; 25 | attr[numattr++] = 32; 26 | 27 | #if 0 28 | attr[numattr++] = kCGLPFAColorSize; 29 | attr[numattr++] = 24; 30 | #endif 31 | attr[numattr++] = kCGLPFAAlphaSize; 32 | attr[numattr++] = 8; 33 | attr[numattr++] = kCGLPFAAccumSize; 34 | attr[numattr++] = 32; 35 | attr[numattr++] = 0; 36 | 37 | width = 300; 38 | height = 300; 39 | pitch = width * 4; 40 | 41 | ptr = malloc(pitch * height); 42 | if(NULL == ptr) 43 | abort(); 44 | 45 | rcolor = 0.0; 46 | gcolor = 0.0; 47 | bcolor = 0.0; 48 | 49 | #if 0 50 | while(1) { 51 | error = CGLChoosePixelFormat(attr, &pfobj, &vsref); 52 | 53 | if(kCGLNoError != error) 54 | abort(); 55 | 56 | error = CGLCreateContext(pfobj, NULL, &ctxobj); 57 | 58 | if(kCGLNoError != error) 59 | abort(); 60 | 61 | error = CGLSetCurrentContext(ctxobj); 62 | 63 | if(kCGLNoError != error) 64 | abort(); 65 | 66 | CGLSetCurrentContext(NULL); 67 | CGLDestroyPixelFormat(pfobj); 68 | CGLDestroyContext(ctxobj); 69 | } 70 | 71 | #else 72 | /* This is the leak path with glRectf. */ 73 | while(1) { 74 | error = CGLChoosePixelFormat(attr, &pfobj, &vsref); 75 | 76 | if(kCGLNoError != error) 77 | abort(); 78 | 79 | error = CGLCreateContext(pfobj, NULL, &ctxobj); 80 | 81 | if(kCGLNoError != error) 82 | abort(); 83 | 84 | error = CGLSetCurrentContext(ctxobj); 85 | 86 | if(kCGLNoError != error) 87 | abort(); 88 | 89 | error = CGLSetOffScreen(ctxobj, width, height, pitch, ptr); 90 | 91 | if(kCGLNoError != error) 92 | abort(); 93 | 94 | glShadeModel( GL_FLAT ); 95 | glClearColor( 0.5, 0.5, 0.5, 1.0 ); 96 | glClear( GL_COLOR_BUFFER_BIT ); 97 | glViewport( 0, 0, 300, 300 ); 98 | glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); 99 | glColor3f( rcolor, gcolor, bcolor); 100 | /* The glRectf makes the whole process grow RPRVT in Leopard. */ 101 | /* Try to comment this out and watch how the bug goes away: */ 102 | glRectf( -0.75, -0.75, 0.75, 0.75 ); 103 | 104 | rcolor += 0.01; 105 | gcolor += 0.02; 106 | bcolor += 0.03; 107 | 108 | if(rcolor >= 1.0) 109 | rcolor = 0.0; 110 | 111 | if(gcolor >= 1.0) 112 | gcolor = 0.0; 113 | 114 | if(bcolor >= 1.0) 115 | bcolor = 0.0; 116 | 117 | CGLClearDrawable(ctxobj); 118 | 119 | CGLSetCurrentContext(NULL); 120 | CGLDestroyPixelFormat(pfobj); 121 | CGLDestroyContext(ctxobj); 122 | 123 | printf("r %g b %g b %g\n", rcolor, gcolor, bcolor); 124 | } 125 | #endif 126 | 127 | return EXIT_FAILURE; 128 | } 129 | -------------------------------------------------------------------------------- /apple_cgl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #ifndef APPLE_CGL_H 31 | #define APPLE_CGL_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | /* For GLint and GLsizei on Tiger */ 39 | #include 40 | 41 | struct apple_cgl_api 42 | { 43 | void (*get_version) (GLint * majorvers, GLint * minorvers); 44 | 45 | CGLError(*choose_pixel_format) (const CGLPixelFormatAttribute * attribs, 46 | CGLPixelFormatObj * pix, GLint * npix); 47 | CGLError(*destroy_pixel_format) (CGLPixelFormatObj pix); 48 | 49 | CGLError(*clear_drawable) (CGLContextObj ctx); 50 | CGLError(*flush_drawable) (CGLContextObj ctx); 51 | 52 | CGLError(*create_context) (CGLPixelFormatObj pix, CGLContextObj share, 53 | CGLContextObj * ctx); 54 | CGLError(*destroy_context) (CGLContextObj pix); 55 | 56 | CGLError(*set_current_context) (CGLContextObj ctx); 57 | CGLContextObj(*get_current_context) (void); 58 | const char *(*error_string) (CGLError error); 59 | 60 | CGLError(*set_off_screen) (CGLContextObj ctx, 61 | GLsizei width, GLsizei height, GLint rowbytes, 62 | void *baseaddr); 63 | 64 | CGLError(*copy_context) (CGLContextObj src, CGLContextObj dst, 65 | GLbitfield mask); 66 | 67 | CGLError(*create_pbuffer) (GLsizei width, 68 | GLsizei height, 69 | GLenum target, 70 | GLenum internalFormat, 71 | GLint max_level, CGLPBufferObj * pbuffer); 72 | 73 | CGLError(*destroy_pbuffer) (CGLPBufferObj pbuffer); 74 | 75 | CGLError(*set_pbuffer) (CGLContextObj ctx, 76 | CGLPBufferObj pbuffer, 77 | GLenum face, GLint level, GLint screen); 78 | }; 79 | 80 | extern struct apple_cgl_api apple_cgl; 81 | 82 | extern void apple_cgl_init(void); 83 | 84 | extern void *apple_cgl_get_dl_handle(void); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /apple_glx_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | #ifndef APPLE_GLX_CONTEXT_H 30 | #define APPLE_GLX_CONTEXT_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #define XP_NO_X_HEADERS 38 | #include 39 | #undef XP_NO_X_HEADERS 40 | 41 | #include "apple_glx_drawable.h" 42 | 43 | struct apple_glx_context 44 | { 45 | CGLContextObj context_obj; 46 | CGLPixelFormatObj pixel_format_obj; 47 | struct apple_glx_drawable *drawable; 48 | pthread_t thread_id; 49 | int screen; 50 | bool double_buffered; 51 | bool uses_stereo; 52 | bool need_update; 53 | bool is_current; /* True if the context is current in some thread. */ 54 | bool made_current; /* True if the context has ever been made current. */ 55 | 56 | /* 57 | * last_surface is set by the pending_destroy code handler for a drawable. 58 | * Due to a CG difference, we have to recreate a surface if the window 59 | * is unmapped and mapped again. 60 | */ 61 | Window last_surface_window; 62 | struct apple_glx_context *previous, *next; 63 | }; 64 | 65 | bool apple_glx_create_context(void **ptr, Display * dpy, int screen, 66 | const void *mode, void *sharedContext, 67 | int *errorptr, bool * x11errorptr); 68 | void apple_glx_destroy_context(void **ptr, Display * dpy); 69 | 70 | bool apple_glx_make_current_context(Display * dpy, void *oldptr, void *ptr, 71 | GLXDrawable drawable); 72 | bool apple_glx_is_current_drawable(Display * dpy, void *ptr, 73 | GLXDrawable drawable); 74 | 75 | bool apple_glx_copy_context(void *currentptr, void *srcptr, void *destptr, 76 | unsigned long mask, int *errorptr, 77 | bool * x11errorptr); 78 | 79 | int apple_glx_context_surface_changed(unsigned int uid, pthread_t caller); 80 | 81 | void apple_glx_context_update(Display * dpy, void *ptr); 82 | 83 | bool apple_glx_context_uses_stereo(void *ptr); 84 | 85 | #endif /*APPLE_GLX_CONTEXT_H */ 86 | -------------------------------------------------------------------------------- /tests/create_destroy_context/create_destroy_context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void draw(Display *dpy, Window w) { 9 | static bool toggle; 10 | 11 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 12 | glLoadIdentity(); 13 | 14 | if(toggle) { 15 | glColor3f(0.5f, 0.5f, 1.0f); 16 | toggle = false; 17 | } else { 18 | glColor3f(1.0f, 0.5, 0.5f); 19 | toggle = true; 20 | } 21 | 22 | glBegin(GL_TRIANGLES); 23 | glVertex3f( 0.0f, 1.0f, 0.0f); 24 | glVertex3f(-1.0f,-1.0f, 0.0f); 25 | glVertex3f( 1.0f,-1.0f, 0.0f); 26 | glEnd(); 27 | glXSwapBuffers(dpy, w); 28 | } 29 | 30 | void resize(Display *dpy, Window w, int width, int height) { 31 | glViewport(0, 0, width, height); 32 | draw(dpy, w); 33 | } 34 | 35 | void event_loop(Display *dpy) { 36 | XEvent event; 37 | 38 | while(1) { 39 | XNextEvent(dpy, &event); 40 | 41 | switch(event.type) { 42 | case Expose: 43 | draw(dpy, event.xexpose.window); 44 | break; 45 | 46 | case ConfigureNotify: 47 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 48 | event.xconfigure.height); 49 | break; 50 | } 51 | } 52 | } 53 | 54 | int main() { 55 | Display *dpy; 56 | int attrib[] = { GLX_RGBA, 57 | GLX_RED_SIZE, 8, 58 | GLX_GREEN_SIZE, 8, 59 | GLX_BLUE_SIZE, 8, 60 | GLX_DEPTH_SIZE, 24, 61 | GLX_DOUBLEBUFFER, 62 | None }; 63 | int eventbase, errorbase; 64 | int screen; 65 | Window root, win; 66 | XVisualInfo *visinfo; 67 | XSetWindowAttributes attr; 68 | GLXContext ctx; 69 | int iter; 70 | 71 | dpy = XOpenDisplay(NULL); 72 | 73 | if(NULL == dpy) { 74 | fprintf(stderr, "error: unable to open display!\n"); 75 | return EXIT_FAILURE; 76 | } 77 | 78 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 79 | fprintf(stderr, "GLX is not available!\n"); 80 | return EXIT_FAILURE; 81 | } 82 | 83 | screen = DefaultScreen(dpy); 84 | root = RootWindow(dpy, screen); 85 | 86 | visinfo = glXChooseVisual(dpy, screen, attrib); 87 | 88 | if(!visinfo) { 89 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 90 | return EXIT_FAILURE; 91 | } 92 | 93 | attr.background_pixel = 0; 94 | attr.border_pixel = 0; 95 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 96 | attr.event_mask = StructureNotifyMask | ExposureMask; 97 | 98 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 99 | /*width*/ 400, /*height*/ 400, 100 | 0, visinfo->depth, InputOutput, 101 | visinfo->visual, 102 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 103 | &attr); 104 | 105 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 106 | if(!ctx) { 107 | fprintf(stderr, "error: glXCreateContext failed!\n"); 108 | return EXIT_FAILURE; 109 | } 110 | 111 | XMapWindow(dpy, win); 112 | 113 | glXMakeCurrent(dpy, win, ctx); 114 | glXMakeCurrent(dpy, None, ctx); 115 | 116 | iter = 0; 117 | while(1) { 118 | ++iter; 119 | printf("iterations %d\n", iter); 120 | glXDestroyContext(dpy, ctx); 121 | ctx = glXCreateContext(dpy, visinfo, NULL, True); 122 | assert(NULL != ctx); 123 | glXMakeCurrent(dpy, win, ctx); 124 | draw(dpy, win); 125 | } 126 | 127 | return EXIT_SUCCESS; 128 | } 129 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx_withdraw_remap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void draw(Display *dpy, Window w) { 7 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 8 | glLoadIdentity(); 9 | glColor3f(0.5f, 0.5f, 1.0f); 10 | glBegin(GL_TRIANGLES); 11 | glVertex3f( 0.0f, 1.0f, 0.0f); 12 | glVertex3f(-1.0f,-1.0f, 0.0f); 13 | glVertex3f( 1.0f,-1.0f, 0.0f); 14 | glEnd(); 15 | glXSwapBuffers(dpy, w); 16 | } 17 | 18 | void resize(Display *dpy, Window w, int width, int height) { 19 | glViewport(0, 0, width, height); 20 | draw(dpy, w); 21 | } 22 | 23 | void event_loop(Display *dpy) { 24 | XEvent event; 25 | 26 | while(1) { 27 | XNextEvent(dpy, &event); 28 | 29 | switch(event.type) { 30 | case Expose: 31 | draw(dpy, event.xexpose.window); 32 | break; 33 | 34 | case KeyPress: 35 | printf("withdrawing window...\n"); 36 | XWithdrawWindow(dpy, event.xkey.window, DefaultScreen(dpy)); 37 | XFlush(dpy); 38 | printf("sleeping...\n"); 39 | sleep(1); 40 | printf("mapping window again...\n"); 41 | XMapWindow(dpy, event.xkey.window); 42 | printf("drawing...\n"); 43 | draw(dpy, event.xkey.window); 44 | XFlush(dpy); 45 | break; 46 | 47 | case ConfigureNotify: 48 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 49 | event.xconfigure.height); 50 | break; 51 | } 52 | } 53 | } 54 | 55 | int main() { 56 | Display *dpy; 57 | int attrib[] = { GLX_RGBA, 58 | GLX_RED_SIZE, 8, 59 | GLX_GREEN_SIZE, 8, 60 | GLX_BLUE_SIZE, 8, 61 | GLX_DEPTH_SIZE, 24, 62 | GLX_DOUBLEBUFFER, 63 | None }; 64 | int eventbase, errorbase; 65 | int screen; 66 | Window root, win; 67 | XVisualInfo *visinfo; 68 | XSetWindowAttributes attr; 69 | GLXContext ctx; 70 | 71 | dpy = XOpenDisplay(NULL); 72 | 73 | if(NULL == dpy) { 74 | fprintf(stderr, "error: unable to open display!\n"); 75 | return EXIT_FAILURE; 76 | } 77 | 78 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 79 | fprintf(stderr, "GLX is not available!\n"); 80 | return EXIT_FAILURE; 81 | } 82 | 83 | screen = DefaultScreen(dpy); 84 | root = RootWindow(dpy, screen); 85 | 86 | visinfo = glXChooseVisual(dpy, screen, attrib); 87 | 88 | if(!visinfo) { 89 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 90 | return EXIT_FAILURE; 91 | } 92 | 93 | attr.background_pixel = 0; 94 | attr.border_pixel = 0; 95 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 96 | attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; 97 | 98 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 99 | /*width*/ 400, /*height*/ 400, 100 | 0, visinfo->depth, InputOutput, 101 | visinfo->visual, 102 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 103 | &attr); 104 | 105 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 106 | if(!ctx) { 107 | fprintf(stderr, "error: glXCreateContext failed!\n"); 108 | return EXIT_FAILURE; 109 | } 110 | 111 | XMapWindow(dpy, win); 112 | 113 | glXMakeCurrent(dpy, win, ctx); 114 | printf("passed dpy %p current dpy %p\n", (void *)dpy, 115 | (void *)glXGetCurrentDisplay()); 116 | 117 | printf("Press any key to withdraw, sleep, and remap.\n"); 118 | 119 | event_loop(dpy); 120 | 121 | return EXIT_SUCCESS; 122 | } 123 | -------------------------------------------------------------------------------- /tests/engine/trackball.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1993, 1994, Silicon Graphics, Inc. 3 | * ALL RIGHTS RESERVED 4 | * Permission to use, copy, modify, and distribute this software for 5 | * any purpose and without fee is hereby granted, provided that the above 6 | * copyright notice appear in all copies and that both the copyright notice 7 | * and this permission notice appear in supporting documentation, and that 8 | * the name of Silicon Graphics, Inc. not be used in advertising 9 | * or publicity pertaining to distribution of the software without specific, 10 | * written prior permission. 11 | * 12 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 13 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 14 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 15 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 16 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 17 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 18 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 19 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 20 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 21 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 22 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 23 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 24 | * 25 | * US Government Users Restricted Rights 26 | * Use, duplication, or disclosure by the Government is subject to 27 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 28 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software 29 | * clause at DFARS 252.227-7013 and/or in similar or successor 30 | * clauses in the FAR or the DOD or NASA FAR Supplement. 31 | * Unpublished-- rights reserved under the copyright laws of the 32 | * United States. Contractor/manufacturer is Silicon Graphics, 33 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 34 | * 35 | * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 36 | */ 37 | /* 38 | * trackball.h 39 | * A virtual trackball implementation 40 | * Written by Gavin Bell for Silicon Graphics, November 1988. 41 | */ 42 | 43 | #ifndef TRACKBALL_H 44 | #define TRACKBALL_H 45 | 46 | 47 | /* 48 | * Pass the x and y coordinates of the last and current positions of 49 | * the mouse, scaled so they are from (-1.0 ... 1.0). 50 | * 51 | * The resulting rotation is returned as a quaternion rotation in the 52 | * first paramater. 53 | */ 54 | void 55 | trackball(float q[4], float p1x, float p1y, float p2x, float p2y); 56 | 57 | /* 58 | * Given two quaternions, add them together to get a third quaternion. 59 | * Adding quaternions to get a compound rotation is analagous to adding 60 | * translations to get a compound translation. When incrementally 61 | * adding rotations, the first argument here should be the new 62 | * rotation, the second and third the total rotation (which will be 63 | * over-written with the resulting new total rotation). 64 | */ 65 | void 66 | add_quats(const float q1[4], const float q2[4], float dest[4]); 67 | 68 | /* 69 | * A useful function, builds a rotation matrix in Matrix based on 70 | * given quaternion. 71 | */ 72 | void 73 | build_rotmatrix(float m[4][4], const float q[4]); 74 | 75 | /* 76 | * This function computes a quaternion based on an axis (defined by 77 | * the given vector) and an angle about which to rotate. The angle is 78 | * expressed in radians. The result is put into the third argument. 79 | */ 80 | void 81 | axis_to_quat(const float a[3], float phi, float q[4]); 82 | 83 | 84 | #endif /* TRACKBALL_H */ 85 | -------------------------------------------------------------------------------- /attic/api_list_completion.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | api_list_completion.tcl -- This automatically completes an API list from 3 | api_generator.tcl. 4 | 5 | Copyright (c) 2008 Apple Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person 8 | obtaining a copy of this software and associated documentation files 9 | (the "Software"), to deal in the Software without restriction, 10 | including without limitation the rights to use, copy, modify, merge, 11 | publish, distribute, sublicense, and/or sell copies of the Software, 12 | and to permit persons to whom the Software is furnished to do so, 13 | subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 22 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | 27 | Except as contained in this notice, the name(s) of the above 28 | copyright holders shall not be used in advertising or otherwise to 29 | promote the sale, use or other dealings in this Software without 30 | prior written authorization. 31 | } 32 | 33 | 34 | proc gliDispatch-name name { 35 | set r "" 36 | set ext [string match *EXT $name] 37 | 38 | if {$ext} { 39 | #Trim off the EXT suffix for appending it later. 40 | set name [string range $name 0 end-3] 41 | } 42 | 43 | set nv [string match *NV $name] 44 | 45 | if {$nv} { 46 | #Trim off the NV suffix for appending it later. 47 | set name [string range $name 0 end-2] 48 | } 49 | 50 | set mesa [string match *MESA $name] 51 | 52 | if {$mesa} { 53 | set name [string range $name 0 end-4] 54 | } 55 | 56 | set arb [string match *ARB $name] 57 | 58 | if {$arb} { 59 | set name [string range $name 0 end-3] 60 | } 61 | 62 | set sgix [string match *SGIX $name] 63 | 64 | if {$sgix} { 65 | set name [string range $name 0 end-4] 66 | } 67 | 68 | foreach c [split $name ""] { 69 | if {[string is upper $c]} { 70 | if {"" eq $r} { 71 | append r [string tolower $c] 72 | } else { 73 | append r _[string tolower $c] 74 | } 75 | } else { 76 | append r $c 77 | } 78 | } 79 | 80 | if {$ext} { 81 | append r _EXT 82 | } 83 | 84 | if {$nv} { 85 | append r _NV 86 | } 87 | 88 | if {$mesa} { 89 | append r _MESA 90 | } 91 | 92 | if {$arb} { 93 | append r _ARB 94 | } 95 | 96 | if {$sgix} { 97 | append r _SGIX 98 | } 99 | 100 | return $r 101 | } 102 | 103 | proc main {argv} { 104 | set fd [open [lindex $argv 0] r] 105 | set data [read $fd] 106 | close $fd 107 | 108 | set completed [list] 109 | 110 | foreach line [split $data \n] { 111 | if {[llength $line] == 5} { 112 | lappend completed $line 113 | continue 114 | } 115 | 116 | set type [lindex $line 0] 117 | set name [lindex $line 1] 118 | set arguments [lindex $line 2] 119 | 120 | set gli [gliDispatch-name $name] 121 | set mesa $name 122 | 123 | lappend completed [list $type $name $arguments $gli $mesa] 124 | } 125 | 126 | foreach i $completed { 127 | puts $i 128 | } 129 | } 130 | main $::argv 131 | -------------------------------------------------------------------------------- /apple_xgl_api_stereo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include 31 | #include "apple_xgl_api_stereo.h" 32 | #include "apple_xgl_api.h" 33 | #include "apple_glx_context.h" 34 | 35 | extern struct apple_xgl_api __gl_api; 36 | /* 37 | * These are special functions for stereoscopic support 38 | * differences in MacOS X. 39 | */ 40 | void 41 | glDrawBuffer(GLenum mode) 42 | { 43 | GLXContext gc = glXGetCurrentContext(); 44 | 45 | if (gc && apple_glx_context_uses_stereo(gc->apple)) { 46 | GLenum buf[2]; 47 | GLsizei n = 0; 48 | 49 | switch (mode) { 50 | case GL_BACK: 51 | buf[0] = GL_BACK_LEFT; 52 | buf[1] = GL_BACK_RIGHT; 53 | n = 2; 54 | break; 55 | case GL_FRONT: 56 | buf[0] = GL_FRONT_LEFT; 57 | buf[1] = GL_FRONT_RIGHT; 58 | n = 2; 59 | break; 60 | 61 | default: 62 | buf[0] = mode; 63 | n = 1; 64 | break; 65 | } 66 | 67 | __gl_api.DrawBuffers(n, buf); 68 | } 69 | else { 70 | __gl_api.DrawBuffer(mode); 71 | } 72 | } 73 | 74 | 75 | void 76 | glDrawBuffers(GLsizei n, const GLenum * bufs) 77 | { 78 | GLXContext gc = glXGetCurrentContext(); 79 | 80 | if (gc && apple_glx_context_uses_stereo(gc->apple)) { 81 | GLenum newbuf[n + 2]; 82 | GLsizei i, outi = 0; 83 | bool have_back = false; 84 | bool have_front = false; 85 | 86 | for (i = 0; i < n; ++i) { 87 | if (GL_BACK == bufs[i]) { 88 | have_back = true; 89 | } 90 | else if (GL_FRONT == bufs[i]) { 91 | have_back = true; 92 | } 93 | else { 94 | newbuf[outi++] = bufs[i]; 95 | } 96 | } 97 | 98 | if (have_back) { 99 | newbuf[outi++] = GL_BACK_LEFT; 100 | newbuf[outi++] = GL_BACK_RIGHT; 101 | } 102 | 103 | if (have_front) { 104 | newbuf[outi++] = GL_FRONT_LEFT; 105 | newbuf[outi++] = GL_FRONT_RIGHT; 106 | } 107 | 108 | __gl_api.DrawBuffers(outi, newbuf); 109 | } 110 | else { 111 | __gl_api.DrawBuffers(n, bufs); 112 | } 113 | } 114 | 115 | void 116 | glDrawBuffersARB(GLsizei n, const GLenum * bufs) 117 | { 118 | glDrawBuffers(n, bufs); 119 | } 120 | -------------------------------------------------------------------------------- /GL_extensions: -------------------------------------------------------------------------------- 1 | extension ARB_transpose_matrix 2 | extension ARB_vertex_program 3 | extension ARB_vertex_blend 4 | extension ARB_window_pos 5 | extension ARB_shader_objects 6 | extension ARB_vertex_shader 7 | extension ARB_shading_language_100 8 | extension ARB_imaging 9 | extension ARB_point_parameters 10 | extension ARB_texture_env_crossbar 11 | extension ARB_texture_border_clamp 12 | extension ARB_multitexture 13 | extension ARB_texture_env_add 14 | extension ARB_texture_cube_map 15 | extension ARB_texture_env_dot3 16 | extension ARB_multisample 17 | extension ARB_texture_env_combine 18 | extension ARB_texture_compression 19 | extension ARB_texture_mirrored_repeat 20 | extension ARB_shadow 21 | extension ARB_depth_texture 22 | extension ARB_shadow_ambient 23 | extension ARB_fragment_program 24 | extension ARB_fragment_program_shadow 25 | extension ARB_fragment_shader 26 | extension ARB_occlusion_query 27 | extension ARB_point_sprite 28 | extension ARB_texture_non_power_of_two 29 | extension ARB_vertex_buffer_object 30 | extension ARB_pixel_buffer_object 31 | extension ARB_draw_buffers 32 | extension ARB_shader_texture_lod 33 | extension ARB_texture_rectangle 34 | extension ARB_texture_float 35 | extension ARB_half_float_pixel 36 | 37 | extension EXT_multi_draw_arrays 38 | extension EXT_clip_volume_hint 39 | extension EXT_rescale_normal 40 | extension EXT_draw_range_elements 41 | extension EXT_fog_coord 42 | extension EXT_gpu_program_parameters 43 | extension EXT_geometry_shader4 44 | 45 | #The gl.spec has the wrong arguments for GetTransformFeedbackVaryingEXT 46 | #extension EXT_transform_feedback 47 | extension EXT_compiled_vertex_array 48 | extension EXT_framebuffer_object 49 | extension EXT_framebuffer_blit 50 | extension EXT_framebuffer_multisample 51 | extension EXT_texture_rectangle 52 | extension EXT_texture_env_add 53 | extension EXT_blend_color 54 | extension EXT_blend_minmax 55 | extension EXT_blend_subtract 56 | extension EXT_texture_lod_bias 57 | extension EXT_abgr 58 | extension EXT_bgra 59 | extension EXT_stencil_wrap 60 | extension EXT_texture_filter_anisotropic 61 | extension EXT_separate_specular_color 62 | extension EXT_secondary_color 63 | extension EXT_blend_func_separate 64 | extension EXT_shadow_funcs 65 | extension EXT_stencil_two_side 66 | extension EXT_texture_compression_s3tc 67 | extension EXT_texture_compression_dxt1 68 | extension EXT_texture_sRGB 69 | extension EXT_blend_equation_separate 70 | extension EXT_texture_mirror_clamp 71 | extension EXT_packed_depth_stencil 72 | 73 | extension APPLE_client_storage 74 | extension APPLE_specular_vector 75 | extension APPLE_transform_hint 76 | extension APPLE_packed_pixels 77 | #The gl.spec has different argument types for this: 78 | #extension APPLE_fence 79 | extension APPLE_vertex_array_object 80 | extension APPLE_vertex_program_evaluators 81 | extension APPLE_element_array 82 | extension APPLE_flush_render 83 | extension APPLE_aux_depth_stencil 84 | extension APPLE_flush_buffer_range 85 | extension APPLE_ycbcr_422 86 | #The gl.spec has different argument types for this: 87 | #extension APPLE_vertex_array_range 88 | extension APPLE_texture_range 89 | extension APPLE_float_pixels 90 | extension APPLE_pixel_buffer 91 | extension APPLE_object_purgeable 92 | 93 | #The OpenGL framework has moved this to the core OpenGL, and eliminated EXT_convolution listing. 94 | #extension EXT_convolution 95 | 96 | #Leopard supports these according to nm. 97 | #Applications should use the GL_EXTENSIONS list to determine capabilities. 98 | extension EXT_paletted_texture 99 | extension APPLE_fence 100 | extension NV_vertex_program4 101 | extension EXT_draw_buffers2 102 | extension EXT_gpu_shader4 103 | extension ATI_pn_triangles 104 | extension NV_register_combiners 105 | extension EXT_depth_bounds_test 106 | 107 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx_surface-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | Window mainwin; 7 | GLXContext ctx; 8 | Window root, win; 9 | XVisualInfo *visinfo; 10 | XSetWindowAttributes attr; 11 | 12 | void draw(Display *dpy, Window w) { 13 | printf("draw window 0x%lx\n", w); 14 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 15 | glLoadIdentity(); 16 | glColor3f(0.5f, 0.5f, 1.0f); 17 | glBegin(GL_TRIANGLES); 18 | glVertex3f( 0.0f, 1.0f, 0.0f); 19 | glVertex3f(-1.0f,-1.0f, 0.0f); 20 | glVertex3f( 1.0f,-1.0f, 0.0f); 21 | glEnd(); 22 | glXSwapBuffers(dpy, w); 23 | } 24 | 25 | void resize(Display *dpy, Window w, int width, int height) { 26 | glViewport(0, 0, width, height); 27 | draw(dpy, w); 28 | } 29 | 30 | void event_loop(Display *dpy) { 31 | XEvent event; 32 | 33 | while(1) { 34 | if(XPending(dpy) > 0) { 35 | XNextEvent(dpy, &event); 36 | 37 | switch(event.type) { 38 | case Expose: 39 | draw(dpy, mainwin); 40 | break; 41 | 42 | case ConfigureNotify: 43 | resize(dpy, mainwin, event.xconfigure.width, 44 | event.xconfigure.height); 45 | break; 46 | } 47 | } 48 | 49 | draw(dpy, mainwin); 50 | /* This should destroy the surface. */ 51 | if(!glXMakeCurrent(dpy, None, ctx)) { 52 | fprintf(stderr, "%s: make current None failed!\n", __func__); 53 | exit(EXIT_FAILURE); 54 | } 55 | 56 | printf("destroying mainwin 0x%lx\n", mainwin); 57 | XDestroyWindow(dpy, mainwin); 58 | 59 | mainwin = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 60 | /*width*/ 400, /*height*/ 400, 61 | 0, visinfo->depth, InputOutput, 62 | visinfo->visual, 63 | CWBackPixel | CWBorderPixel 64 | | CWColormap | CWEventMask, 65 | &attr); 66 | 67 | printf("created mainwin 0x%lx\n", mainwin); 68 | 69 | /* This should recreate the surface. */ 70 | if(!glXMakeCurrent(dpy, mainwin, ctx)) { 71 | fprintf(stderr, "%s: make mainwin current failed!\n", __func__); 72 | exit(EXIT_FAILURE); 73 | } 74 | } 75 | } 76 | 77 | int main() { 78 | Display *dpy; 79 | int attrib[] = { GLX_RGBA, 80 | GLX_RED_SIZE, 8, 81 | GLX_GREEN_SIZE, 8, 82 | GLX_BLUE_SIZE, 8, 83 | GLX_DEPTH_SIZE, 24, 84 | GLX_DOUBLEBUFFER, 85 | None }; 86 | int eventbase, errorbase; 87 | int screen; 88 | 89 | dpy = XOpenDisplay(NULL); 90 | 91 | if(NULL == dpy) { 92 | fprintf(stderr, "error: unable to open display!\n"); 93 | return EXIT_FAILURE; 94 | } 95 | 96 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 97 | fprintf(stderr, "GLX is not available!\n"); 98 | return EXIT_FAILURE; 99 | } 100 | 101 | screen = DefaultScreen(dpy); 102 | root = RootWindow(dpy, screen); 103 | 104 | visinfo = glXChooseVisual(dpy, screen, attrib); 105 | 106 | if(!visinfo) { 107 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 108 | return EXIT_FAILURE; 109 | } 110 | 111 | attr.background_pixel = 0; 112 | attr.border_pixel = 0; 113 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 114 | attr.event_mask = StructureNotifyMask | ExposureMask; 115 | 116 | mainwin = win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 117 | /*width*/ 400, /*height*/ 400, 118 | 0, visinfo->depth, InputOutput, 119 | visinfo->visual, 120 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 121 | &attr); 122 | 123 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 124 | if(!ctx) { 125 | fprintf(stderr, "error: glXCreateContext failed!\n"); 126 | return EXIT_FAILURE; 127 | } 128 | 129 | XMapWindow(dpy, win); 130 | 131 | glXMakeCurrent(dpy, win, ctx); 132 | 133 | event_loop(dpy); 134 | 135 | return EXIT_SUCCESS; 136 | } 137 | -------------------------------------------------------------------------------- /tests/triangle_glx/triangle_glx_destroy_relation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | Window root, win, win2; 7 | GLXContext ctx; 8 | 9 | void draw(Display *dpy, Window w) { 10 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 11 | glLoadIdentity(); 12 | glColor3f(0.5f, 0.5f, 1.0f); 13 | glBegin(GL_TRIANGLES); 14 | glVertex3f( 0.0f, 1.0f, 0.0f); 15 | glVertex3f(-1.0f,-1.0f, 0.0f); 16 | glVertex3f( 1.0f,-1.0f, 0.0f); 17 | glEnd(); 18 | glXSwapBuffers(dpy, w); 19 | } 20 | 21 | void resize(Display *dpy, Window w, int width, int height) { 22 | glViewport(0, 0, width, height); 23 | draw(dpy, w); 24 | } 25 | 26 | void event_loop(Display *dpy) { 27 | XEvent event; 28 | XWindowAttributes wattr; 29 | 30 | while(1) { 31 | XNextEvent(dpy, &event); 32 | 33 | switch(event.type) { 34 | case ButtonPress: 35 | printf("event.xbutton.window 0x%lx\n", 36 | event.xbutton.window); 37 | XDestroyWindow(dpy, event.xbutton.window); 38 | break; 39 | 40 | case Expose: 41 | glXMakeCurrent(dpy, event.xexpose.window, ctx); 42 | XGetWindowAttributes(dpy, event.xexpose.window, &wattr); 43 | resize(dpy, event.xexpose.window, wattr.width, wattr.height); 44 | draw(dpy, event.xexpose.window); 45 | break; 46 | 47 | case KeyPress: { 48 | glXMakeCurrent(dpy, win2, ctx); 49 | XGetWindowAttributes(dpy, win2, &wattr); 50 | resize(dpy, win2, wattr.width, wattr.height); 51 | draw(dpy, win2); 52 | XFlush(dpy); 53 | } 54 | break; 55 | 56 | case ConfigureNotify: 57 | glXMakeCurrent(dpy, event.xconfigure.window, ctx); 58 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 59 | event.xconfigure.height); 60 | break; 61 | } 62 | } 63 | } 64 | 65 | int main() { 66 | Display *dpy; 67 | int attrib[] = { GLX_RGBA, 68 | GLX_RED_SIZE, 8, 69 | GLX_GREEN_SIZE, 8, 70 | GLX_BLUE_SIZE, 8, 71 | GLX_DEPTH_SIZE, 24, 72 | GLX_DOUBLEBUFFER, 73 | None }; 74 | int eventbase, errorbase; 75 | int screen; 76 | XVisualInfo *visinfo; 77 | XSetWindowAttributes attr; 78 | 79 | 80 | dpy = XOpenDisplay(NULL); 81 | 82 | if(NULL == dpy) { 83 | fprintf(stderr, "error: unable to open display!\n"); 84 | return EXIT_FAILURE; 85 | } 86 | 87 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 88 | fprintf(stderr, "GLX is not available!\n"); 89 | return EXIT_FAILURE; 90 | } 91 | 92 | screen = DefaultScreen(dpy); 93 | root = RootWindow(dpy, screen); 94 | 95 | visinfo = glXChooseVisual(dpy, screen, attrib); 96 | 97 | if(!visinfo) { 98 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 99 | return EXIT_FAILURE; 100 | } 101 | 102 | attr.background_pixel = 0; 103 | attr.border_pixel = 0; 104 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 105 | attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask 106 | | ButtonPressMask; 107 | 108 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 109 | /*width*/ 400, /*height*/ 400, 110 | 0, visinfo->depth, InputOutput, 111 | visinfo->visual, 112 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 113 | &attr); 114 | 115 | win2 = XCreateWindow(dpy, win, 0, 0, 116 | 100, 100, 117 | 0, visinfo->depth, InputOutput, 118 | visinfo->visual, 119 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 120 | &attr); 121 | 122 | printf("win 0x%lx win2 0x%lx\n", win, win2); 123 | 124 | ctx = glXCreateContext(dpy, visinfo, NULL, True); 125 | if(!ctx) { 126 | fprintf(stderr, "error: glXCreateContext failed!\n"); 127 | return EXIT_FAILURE; 128 | } 129 | 130 | XMapWindow(dpy, win); 131 | XMapWindow(dpy, win2); 132 | 133 | glXMakeCurrent(dpy, win, ctx); 134 | 135 | event_loop(dpy); 136 | 137 | return EXIT_SUCCESS; 138 | } 139 | -------------------------------------------------------------------------------- /tests/pbuffer/pbuffer_destroy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | GLXPbuffer pbuf; 8 | 9 | void dump_pbuffer(Display *dpy) { 10 | unsigned int width = 0, height = 0, fbid = 0; 11 | 12 | glXQueryDrawable(dpy, pbuf, GLX_WIDTH, &width); 13 | glXQueryDrawable(dpy, pbuf, GLX_HEIGHT, &height); 14 | glXQueryDrawable(dpy, pbuf, GLX_FBCONFIG_ID, &fbid); 15 | 16 | printf("queried drawable width %u height %u fbconfigID %x\n", 17 | width, height, fbid); 18 | } 19 | 20 | void draw(Display *dpy) { 21 | GLenum err; 22 | 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | glLoadIdentity(); 25 | glColor3f(0.5f, 0.5f, 1.0f); 26 | glBegin(GL_TRIANGLES); 27 | glVertex3f( 0.0f, 1.0f, 0.0f); 28 | glVertex3f(-1.0f,-1.0f, 0.0f); 29 | glVertex3f( 1.0f,-1.0f, 0.0f); 30 | glEnd(); 31 | glFinish(); 32 | 33 | puts("RENDER"); 34 | 35 | err = glGetError(); 36 | if(GL_NO_ERROR != err) { 37 | fprintf(stderr, "an unexpect error occurred: %d\n", err); 38 | abort(); 39 | } 40 | 41 | dump_pbuffer(dpy); 42 | } 43 | 44 | int main() { 45 | Display *dpy; 46 | int attrib[] = { 47 | GLX_RED_SIZE, 8, 48 | GLX_GREEN_SIZE, 8, 49 | GLX_BLUE_SIZE, 8, 50 | GLX_DEPTH_SIZE, 24, 51 | GLX_RENDER_TYPE, GLX_RGBA_BIT, 52 | GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT, 53 | GLX_X_RENDERABLE, True, 54 | None, 55 | }; 56 | int eventbase, errorbase; 57 | int screen; 58 | Window root, win; 59 | XVisualInfo *visinfo; 60 | XSetWindowAttributes attr; 61 | GLXContext ctx; 62 | GLXFBConfig *fbconfig; 63 | int numfbconfig; 64 | int pbattrib[] = { 65 | GLX_PBUFFER_WIDTH, 400, 66 | GLX_PBUFFER_HEIGHT, 400, 67 | None 68 | }; 69 | 70 | dpy = XOpenDisplay(NULL); 71 | 72 | if(NULL == dpy) { 73 | fprintf(stderr, "error: unable to open display!\n"); 74 | return EXIT_FAILURE; 75 | } 76 | 77 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 78 | fprintf(stderr, "GLX is not available!\n"); 79 | return EXIT_FAILURE; 80 | } 81 | 82 | screen = DefaultScreen(dpy); 83 | root = RootWindow(dpy, screen); 84 | 85 | fbconfig = glXChooseFBConfig(dpy, screen, attrib, &numfbconfig); 86 | 87 | if(NULL == fbconfig) { 88 | fprintf(stderr, "error: couldn't choose a GLXFBConfig!\n"); 89 | return EXIT_FAILURE; 90 | } 91 | 92 | visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[0]); 93 | 94 | attr.background_pixel = 0; 95 | attr.border_pixel = 0; 96 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 97 | attr.event_mask = StructureNotifyMask | ExposureMask; 98 | 99 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 100 | /*width*/ 400, /*height*/ 400, 101 | 0, visinfo->depth, InputOutput, 102 | visinfo->visual, 103 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 104 | &attr); 105 | 106 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 107 | 108 | if(!ctx) { 109 | fprintf(stderr, "error: glXCreateContext failed!\n"); 110 | return EXIT_FAILURE; 111 | } 112 | 113 | XMapWindow(dpy, win); 114 | 115 | /*THIS ISN'T RIGHT YET. We need to check the fbconfig for the Pbuffer bit. */ 116 | pbuf = glXCreatePbuffer(dpy, fbconfig[0], pbattrib); 117 | 118 | printf("numfbconfig %d\n", numfbconfig); 119 | 120 | if(None == pbuf) { 121 | fprintf(stderr, "unable to create a GLXPbuffer!\n"); 122 | return EXIT_FAILURE; 123 | } 124 | 125 | printf("pbuf %lx\n", pbuf); 126 | 127 | if(!glXMakeCurrent(dpy, pbuf, ctx)) { 128 | fprintf(stderr, "glXMakeCurrent failed!\n"); 129 | return EXIT_FAILURE; 130 | } 131 | 132 | draw(dpy); 133 | glXDestroyPbuffer(dpy, pbuf); 134 | draw(dpy); 135 | /* This should release the final reference to the pbuffer. */ 136 | glXMakeCurrent(dpy, None, ctx); 137 | printf("Expect a GLXBadDrawable error.\n"); 138 | draw(dpy); 139 | 140 | return EXIT_SUCCESS; 141 | } 142 | -------------------------------------------------------------------------------- /apple_cgl.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "apple_cgl.h" 36 | #include "apple_glx.h" 37 | 38 | #ifndef OPENGL_FRAMEWORK_PATH 39 | #define OPENGL_FRAMEWORK_PATH "/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL" 40 | #endif 41 | 42 | static void *dl_handle = NULL; 43 | 44 | struct apple_cgl_api apple_cgl; 45 | 46 | static bool initialized = false; 47 | 48 | static void * 49 | sym(void *h, const char *name) 50 | { 51 | void *s; 52 | 53 | s = dlsym(h, name); 54 | 55 | if (NULL == s) { 56 | fprintf(stderr, "error: %s\n", dlerror()); 57 | abort(); 58 | } 59 | 60 | return s; 61 | } 62 | 63 | void 64 | apple_cgl_init(void) 65 | { 66 | void *h; 67 | GLint major = 0, minor = 0; 68 | const char *opengl_framework_path; 69 | 70 | if (initialized) 71 | return; 72 | 73 | opengl_framework_path = getenv("OPENGL_FRAMEWORK_PATH"); 74 | if (!opengl_framework_path) { 75 | opengl_framework_path = OPENGL_FRAMEWORK_PATH; 76 | } 77 | 78 | (void) dlerror(); /*drain dlerror */ 79 | h = dlopen(opengl_framework_path, RTLD_NOW); 80 | 81 | if (NULL == h) { 82 | fprintf(stderr, "error: unable to dlopen %s : %s\n", 83 | opengl_framework_path, dlerror()); 84 | abort(); 85 | } 86 | 87 | dl_handle = h; 88 | 89 | apple_cgl.get_version = sym(h, "CGLGetVersion"); 90 | 91 | apple_cgl.get_version(&major, &minor); 92 | 93 | apple_glx_diagnostic("CGL major %d minor %d\n", major, minor); 94 | 95 | if (1 != major) { 96 | fprintf(stderr, "WARNING: the CGL major version has changed!\n" 97 | "libGL may be incompatible!\n"); 98 | } 99 | 100 | apple_cgl.choose_pixel_format = sym(h, "CGLChoosePixelFormat"); 101 | apple_cgl.destroy_pixel_format = sym(h, "CGLDestroyPixelFormat"); 102 | 103 | apple_cgl.clear_drawable = sym(h, "CGLClearDrawable"); 104 | apple_cgl.flush_drawable = sym(h, "CGLFlushDrawable"); 105 | 106 | apple_cgl.create_context = sym(h, "CGLCreateContext"); 107 | apple_cgl.destroy_context = sym(h, "CGLDestroyContext"); 108 | 109 | apple_cgl.set_current_context = sym(h, "CGLSetCurrentContext"); 110 | apple_cgl.get_current_context = sym(h, "CGLGetCurrentContext"); 111 | apple_cgl.error_string = sym(h, "CGLErrorString"); 112 | 113 | apple_cgl.set_off_screen = sym(h, "CGLSetOffScreen"); 114 | 115 | apple_cgl.copy_context = sym(h, "CGLCopyContext"); 116 | 117 | apple_cgl.create_pbuffer = sym(h, "CGLCreatePBuffer"); 118 | apple_cgl.destroy_pbuffer = sym(h, "CGLDestroyPBuffer"); 119 | apple_cgl.set_pbuffer = sym(h, "CGLSetPBuffer"); 120 | 121 | initialized = true; 122 | } 123 | 124 | void * 125 | apple_cgl_get_dl_handle(void) 126 | { 127 | return dl_handle; 128 | } 129 | -------------------------------------------------------------------------------- /include/GL/gl.h.template: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 3 | * Copyright (C) 2009 Apple Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef __X_GL_H 24 | #define __X_GL_H 25 | 26 | /* The following macros exist to address conflicts between the names given to 27 | * function pointers by the MESA API and OpenGL.framework's API. 28 | */ 29 | @CGL_MESA_COMPAT_MACROS@ 30 | 31 | /* On SL, we want to use OpelGL.framework's headers to get both prototypes and 32 | * function pointers (like Mesa's API), but on Leo and before, OpenGL.framework 33 | * can't give us both. 34 | */ 35 | 36 | #ifdef GL_GLEXT_FUNCTION_POINTERS 37 | #define _GL_GLEXT_FUNCTION_POINTERS GL_GLEXT_FUNCTION_POINTERS 38 | #undef GL_GLEXT_FUNCTION_POINTERS 39 | #endif 40 | 41 | #ifdef GL_GLEXT_PROTOTYPES 42 | #define _GL_GLEXT_PROTOTYPES GL_GLEXT_PROTOTYPES 43 | #else 44 | #define GL_GLEXT_PROTOTYPES 1 45 | #endif 46 | 47 | /* Our glext.h is based on a version from the registry that is newer. */ 48 | #ifdef GL_GLEXT_LEGACY 49 | #define _GL_GLEXT_LEGACY GL_GLEXT_LEGACY 50 | #else 51 | #define GL_GLEXT_LEGACY 1 52 | #endif 53 | 54 | #include "/System/Library/Frameworks/OpenGL.framework/Headers/gl.h" 55 | 56 | /* These are not set by the system gl.h */ 57 | #define GL_VERSION_1_2_DEPRECATED 1 58 | #define GL_VERSION_1_3_DEPRECATED 1 59 | #define GL_VERSION_1_4_DEPRECATED 1 60 | 61 | /* Restore our GLEXT-fu */ 62 | #ifdef _GL_GLEXT_FUNCTION_POINTERS 63 | #define GL_GLEXT_FUNCTION_POINTERS _GL_GLEXT_FUNCTION_POINTERS 64 | #undef _GL_GLEXT_FUNCTION_POINTERS 65 | #endif 66 | 67 | #ifdef _GL_GLEXT_PROTOTYPES 68 | #undef _GL_GLEXT_PROTOTYPES 69 | #else 70 | #undef GL_GLEXT_PROTOTYPES 71 | #endif 72 | 73 | #ifdef _GL_GLEXT_LEGACY 74 | #undef _GL_GLEXT_LEGACY 75 | #else 76 | #undef GL_GLEXT_LEGACY 77 | #endif 78 | 79 | @CGL_MESA_FUNCTION_POINTERS@ 80 | 81 | #ifndef GL_GLEXT_LEGACY 82 | #include 83 | #endif 84 | 85 | /* 86 | * This is needed for building apple_glx_pbuffer.c, the latest 87 | * glext.h from the registry lacks it, so it's from the Leopard glext.h: 88 | */ 89 | #ifndef GL_TEXTURE_RECTANGLE_EXT 90 | #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 91 | #endif 92 | 93 | /* This is needed for building the X server: */ 94 | /* 95 | * GL_MESA_packed_depth_stencil 96 | */ 97 | #ifndef GL_MESA_packed_depth_stencil 98 | #define GL_MESA_packed_depth_stencil 1 99 | 100 | #define GL_DEPTH_STENCIL_MESA 0x8750 101 | #define GL_UNSIGNED_INT_24_8_MESA 0x8751 102 | #define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752 103 | #define GL_UNSIGNED_SHORT_15_1_MESA 0x8753 104 | #define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754 105 | 106 | #endif /* GL_MESA_packed_depth_stencil */ 107 | 108 | /* Various other OS projects expect to get these macros from Mesa's gl.h */ 109 | #ifndef GLAPI 110 | #define GLAPI extern 111 | #endif 112 | 113 | #ifndef GLAPIENTRY 114 | #define GLAPIENTRY 115 | #endif 116 | 117 | #ifndef APIENTRY 118 | #define APIENTRY GLAPIENTRY 119 | #endif 120 | 121 | /* "P" suffix to be used for a pointer to a function */ 122 | #ifndef APIENTRYP 123 | #define APIENTRYP APIENTRY * 124 | #endif 125 | 126 | #ifndef GLAPIENTRYP 127 | #define GLAPIENTRYP GLAPIENTRY * 128 | #endif 129 | 130 | #endif /*__X_GL_H*/ 131 | -------------------------------------------------------------------------------- /glxreply.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright Apple Inc. 2008 3 | * (C) Copyright IBM Corporation 2004, 2005 4 | * All Rights Reserved. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sub license, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the next 14 | * paragraph) shall be included in all copies or substantial portions of the 15 | * Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20 | * IBM, 21 | * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 23 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include "glxclient.h" 29 | #include 30 | 31 | CARD32 32 | __glXReadReply(Display * dpy, size_t size, void *dest, 33 | GLboolean reply_is_always_array) 34 | { 35 | xGLXSingleReply reply; 36 | 37 | (void) _XReply(dpy, (xReply *) & reply, 0, False); 38 | if (size != 0) { 39 | if ((reply.length > 0) || reply_is_always_array) { 40 | const GLint bytes = (reply_is_always_array) 41 | ? (4 * reply.length) : (reply.size * size); 42 | const GLint extra = 4 - (bytes & 3); 43 | 44 | _XRead(dpy, dest, bytes); 45 | if (extra < 4) { 46 | _XEatData(dpy, extra); 47 | } 48 | } 49 | else { 50 | (void) memcpy(dest, &(reply.pad3), size); 51 | } 52 | } 53 | 54 | return reply.retval; 55 | } 56 | 57 | void 58 | __glXReadPixelReply(Display * dpy, __GLXcontext * gc, unsigned max_dim, 59 | GLint width, GLint height, GLint depth, GLenum format, 60 | GLenum type, void *dest, GLboolean dimensions_in_reply) 61 | { 62 | xGLXSingleReply reply; 63 | GLint size; 64 | 65 | (void) _XReply(dpy, (xReply *) & reply, 0, False); 66 | 67 | if (dimensions_in_reply) { 68 | width = reply.pad3; 69 | height = reply.pad4; 70 | depth = reply.pad5; 71 | 72 | if ((height == 0) || (max_dim < 2)) { 73 | height = 1; 74 | } 75 | if ((depth == 0) || (max_dim < 3)) { 76 | depth = 1; 77 | } 78 | } 79 | 80 | size = reply.length * 4; 81 | if (size != 0) { 82 | void *buf = Xmalloc(size); 83 | 84 | if (buf == NULL) { 85 | _XEatData(dpy, size); 86 | __glXSetError(gc, GL_OUT_OF_MEMORY); 87 | } 88 | else { 89 | const GLint extra = 4 - (size & 3); 90 | 91 | _XRead(dpy, buf, size); 92 | if (extra < 4) { 93 | _XEatData(dpy, extra); 94 | } 95 | 96 | __glEmptyImage(gc, 3, width, height, depth, format, type, buf, dest); 97 | Xfree(buf); 98 | } 99 | } 100 | } 101 | 102 | #if 0 103 | GLubyte * 104 | __glXSetupSingleRequest(__GLXcontext * gc, GLint sop, GLint cmdlen) 105 | { 106 | xGLXSingleReq *req; 107 | Display *const dpy = gc->currentDpy; 108 | 109 | (void) __glXFlushRenderBuffer(gc, gc->pc); 110 | LockDisplay(dpy); 111 | GetReqExtra(GLXSingle, cmdlen, req); 112 | req->reqType = gc->majorOpcode; 113 | req->contextTag = gc->currentContextTag; 114 | req->glxCode = sop; 115 | return (GLubyte *) (req) + sz_xGLXSingleReq; 116 | } 117 | #endif 118 | 119 | GLubyte * 120 | __glXSetupVendorRequest(__GLXcontext * gc, GLint code, GLint vop, 121 | GLint cmdlen) 122 | { 123 | xGLXVendorPrivateReq *req; 124 | Display *const dpy = gc->currentDpy; 125 | 126 | (void) __glXFlushRenderBuffer(gc, gc->pc); 127 | LockDisplay(dpy); 128 | GetReqExtra(GLXVendorPrivate, cmdlen, req); 129 | req->reqType = gc->majorOpcode; 130 | req->glxCode = code; 131 | req->vendorCode = vop; 132 | req->contextTag = gc->currentContextTag; 133 | return (GLubyte *) (req) + sz_xGLXVendorPrivateReq; 134 | } 135 | -------------------------------------------------------------------------------- /apple_xgl_api_read.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | /* 31 | * This file works with the glXMakeContextCurrent readable drawable. 32 | * 33 | * The way it works is by swapping the currentDrawable for the currentReadable 34 | * drawable if they are different. 35 | */ 36 | #include 37 | #include "apple_xgl_api_read.h" 38 | #include "apple_xgl_api.h" 39 | #include "apple_cgl.h" 40 | #include "apple_glx_context.h" 41 | 42 | extern struct apple_xgl_api __gl_api; 43 | 44 | struct apple_xgl_saved_state 45 | { 46 | bool swapped; 47 | }; 48 | 49 | static void 50 | SetRead(struct apple_xgl_saved_state *saved) 51 | { 52 | GLXContext gc = __glXGetCurrentContext(); 53 | 54 | /* 55 | * By default indicate that the state was not swapped, so that UnsetRead 56 | * functions correctly. 57 | */ 58 | saved->swapped = false; 59 | 60 | /* 61 | * If the readable drawable isn't the same as the drawable then 62 | * the user has requested a readable drawable with glXMakeContextCurrent(). 63 | * We emulate this behavior by switching the current drawable. 64 | */ 65 | if (None != gc->currentReadable 66 | && gc->currentReadable != gc->currentDrawable) { 67 | Display *dpy = glXGetCurrentDisplay(); 68 | 69 | saved->swapped = true; 70 | 71 | if (apple_glx_make_current_context(dpy, gc->apple, gc->apple, 72 | gc->currentReadable)) { 73 | /* An error occurred, so try to restore the old context state. */ 74 | (void) apple_glx_make_current_context(dpy, gc->apple, gc->apple, 75 | gc->currentDrawable); 76 | saved->swapped = false; 77 | } 78 | } 79 | } 80 | 81 | static void 82 | UnsetRead(struct apple_xgl_saved_state *saved) 83 | { 84 | if (saved->swapped) { 85 | GLXContext gc = __glXGetCurrentContext(); 86 | Display *dpy = glXGetCurrentDisplay(); 87 | 88 | if (apple_glx_make_current_context(dpy, gc->apple, gc->apple, 89 | gc->currentDrawable)) { 90 | /* 91 | * An error occurred restoring the drawable. 92 | * It's unclear what to do about that. 93 | */ 94 | } 95 | } 96 | } 97 | 98 | void 99 | glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, 100 | GLenum format, GLenum type, void *pixels) 101 | { 102 | struct apple_xgl_saved_state saved; 103 | 104 | SetRead(&saved); 105 | 106 | __gl_api.ReadPixels(x, y, width, height, format, type, pixels); 107 | 108 | UnsetRead(&saved); 109 | } 110 | 111 | void 112 | glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) 113 | { 114 | struct apple_xgl_saved_state saved; 115 | 116 | SetRead(&saved); 117 | 118 | __gl_api.CopyPixels(x, y, width, height, type); 119 | 120 | UnsetRead(&saved); 121 | } 122 | 123 | void 124 | glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, 125 | GLsizei width) 126 | { 127 | struct apple_xgl_saved_state saved; 128 | 129 | SetRead(&saved); 130 | 131 | __gl_api.CopyColorTable(target, internalformat, x, y, width); 132 | 133 | UnsetRead(&saved); 134 | } 135 | -------------------------------------------------------------------------------- /apple_visual.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "apple_cgl.h" 39 | #include "apple_visual.h" 40 | #include "apple_glx.h" 41 | #include "glcontextmodes.h" 42 | 43 | enum 44 | { 45 | MAX_ATTR = 60 46 | }; 47 | 48 | /*mode is a __GlcontextModes*/ 49 | void 50 | apple_visual_create_pfobj(CGLPixelFormatObj * pfobj, const void *mode, 51 | bool * double_buffered, bool * uses_stereo, 52 | bool offscreen) 53 | { 54 | CGLPixelFormatAttribute attr[MAX_ATTR]; 55 | const __GLcontextModes *c = mode; 56 | int numattr = 0; 57 | GLint vsref = 0; 58 | CGLError error = 0; 59 | 60 | if (offscreen) { 61 | apple_glx_diagnostic 62 | ("offscreen rendering enabled. Using kCGLPFAOffScreen\n"); 63 | 64 | attr[numattr++] = kCGLPFAOffScreen; 65 | attr[numattr++] = kCGLPFAColorSize; 66 | attr[numattr++] = 32; 67 | } 68 | else if (getenv("LIBGL_ALWAYS_SOFTWARE") != NULL) { 69 | apple_glx_diagnostic 70 | ("Software rendering requested. Using kCGLRendererGenericFloatID.\n"); 71 | attr[numattr++] = kCGLPFARendererID; 72 | attr[numattr++] = kCGLRendererGenericFloatID; 73 | } 74 | else if (getenv("LIBGL_ALLOW_SOFTWARE") != NULL) { 75 | apple_glx_diagnostic 76 | ("Software rendering is not being excluded. Not using kCGLPFAAccelerated.\n"); 77 | } 78 | else { 79 | attr[numattr++] = kCGLPFAAccelerated; 80 | } 81 | 82 | /* 83 | * The program chose a config based on the fbconfigs or visuals. 84 | * Those are based on the attributes from CGL, so we probably 85 | * do want the closest match for the color, depth, and accum. 86 | */ 87 | attr[numattr++] = kCGLPFAClosestPolicy; 88 | 89 | if (c->stereoMode) { 90 | attr[numattr++] = kCGLPFAStereo; 91 | *uses_stereo = true; 92 | } 93 | else { 94 | *uses_stereo = false; 95 | } 96 | 97 | if (c->doubleBufferMode) { 98 | attr[numattr++] = kCGLPFADoubleBuffer; 99 | *double_buffered = true; 100 | } 101 | else { 102 | *double_buffered = false; 103 | } 104 | 105 | attr[numattr++] = kCGLPFAColorSize; 106 | attr[numattr++] = c->redBits + c->greenBits + c->blueBits; 107 | attr[numattr++] = kCGLPFAAlphaSize; 108 | attr[numattr++] = c->alphaBits; 109 | 110 | if ((c->accumRedBits + c->accumGreenBits + c->accumBlueBits) > 0) { 111 | attr[numattr++] = kCGLPFAAccumSize; 112 | attr[numattr++] = c->accumRedBits + c->accumGreenBits + 113 | c->accumBlueBits + c->accumAlphaBits; 114 | } 115 | 116 | if (c->depthBits > 0) { 117 | attr[numattr++] = kCGLPFADepthSize; 118 | attr[numattr++] = c->depthBits; 119 | } 120 | 121 | if (c->stencilBits > 0) { 122 | attr[numattr++] = kCGLPFAStencilSize; 123 | attr[numattr++] = c->stencilBits; 124 | } 125 | 126 | if (c->sampleBuffers > 0) { 127 | attr[numattr++] = kCGLPFAMultisample; 128 | attr[numattr++] = kCGLPFASampleBuffers; 129 | attr[numattr++] = c->sampleBuffers; 130 | attr[numattr++] = kCGLPFASamples; 131 | attr[numattr++] = c->samples; 132 | } 133 | 134 | attr[numattr++] = 0; 135 | 136 | assert(numattr < MAX_ATTR); 137 | 138 | error = apple_cgl.choose_pixel_format(attr, pfobj, &vsref); 139 | 140 | if (error) { 141 | fprintf(stderr, "error: %s\n", apple_cgl.error_string(error)); 142 | abort(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /tests/pbuffer/pbuffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | GLXPbuffer pbuf; 8 | 9 | void dump_pbuffer(Display *dpy) { 10 | size_t length = 400 * 400 * /*RGBA*/ 4; 11 | void *p = malloc(length); 12 | unsigned char *cp; 13 | int x, y; 14 | 15 | if(NULL == p) { 16 | perror("malloc"); 17 | abort(); 18 | } 19 | 20 | memset(p, 0, length); 21 | 22 | glReadPixels(0, 0, 400, 400, GL_RGBA, GL_UNSIGNED_BYTE, p); 23 | 24 | cp = p; 25 | for(y = 0; y < 400; ++y) { 26 | for(x = 0; x < 400; ++x) { 27 | printf("%d %d %d %d, ", cp[0], cp[1], cp[2], cp[3]); 28 | cp += 4; 29 | } 30 | putchar('\n'); 31 | } 32 | 33 | free(p); 34 | 35 | { 36 | unsigned int width = 0, height = 0, fbid = 0; 37 | 38 | glXQueryDrawable(dpy, pbuf, GLX_WIDTH, &width); 39 | glXQueryDrawable(dpy, pbuf, GLX_HEIGHT, &height); 40 | glXQueryDrawable(dpy, pbuf, GLX_FBCONFIG_ID, &fbid); 41 | 42 | printf("queried drawable width %u height %u fbconfigID %x\n", 43 | width, height, fbid); 44 | 45 | } 46 | } 47 | 48 | void draw(Display *dpy, Window w) { 49 | GLenum err; 50 | 51 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 52 | glLoadIdentity(); 53 | glColor3f(0.5f, 0.5f, 1.0f); 54 | glBegin(GL_TRIANGLES); 55 | glVertex3f( 0.0f, 1.0f, 0.0f); 56 | glVertex3f(-1.0f,-1.0f, 0.0f); 57 | glVertex3f( 1.0f,-1.0f, 0.0f); 58 | glEnd(); 59 | glFinish(); 60 | 61 | puts("RENDER"); 62 | 63 | err = glGetError(); 64 | if(GL_NO_ERROR != err) { 65 | fprintf(stderr, "an unexpect error occurred: %d\n", err); 66 | abort(); 67 | } 68 | 69 | dump_pbuffer(dpy); 70 | } 71 | 72 | void resize(Display *dpy, Window w, int width, int height) { 73 | glViewport(0, 0, width, height); 74 | draw(dpy, w); 75 | } 76 | 77 | void event_loop(Display *dpy) { 78 | XEvent event; 79 | 80 | while(1) { 81 | XNextEvent(dpy, &event); 82 | 83 | switch(event.type) { 84 | case Expose: 85 | draw(dpy, event.xexpose.window); 86 | break; 87 | 88 | case ConfigureNotify: 89 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 90 | event.xconfigure.height); 91 | break; 92 | } 93 | } 94 | } 95 | 96 | int main() { 97 | Display *dpy; 98 | int attrib[] = { 99 | GLX_RED_SIZE, 8, 100 | GLX_GREEN_SIZE, 8, 101 | GLX_BLUE_SIZE, 8, 102 | GLX_DEPTH_SIZE, 24, 103 | GLX_RENDER_TYPE, GLX_RGBA_BIT, 104 | GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT, 105 | GLX_X_RENDERABLE, True, 106 | None, 107 | }; 108 | int eventbase, errorbase; 109 | int screen; 110 | Window root, win; 111 | XVisualInfo *visinfo; 112 | XSetWindowAttributes attr; 113 | GLXContext ctx; 114 | GLXFBConfig *fbconfig; 115 | int numfbconfig; 116 | int pbattrib[] = { 117 | GLX_PBUFFER_WIDTH, 400, 118 | GLX_PBUFFER_HEIGHT, 400, 119 | None 120 | }; 121 | 122 | dpy = XOpenDisplay(NULL); 123 | 124 | if(NULL == dpy) { 125 | fprintf(stderr, "error: unable to open display!\n"); 126 | return EXIT_FAILURE; 127 | } 128 | 129 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 130 | fprintf(stderr, "GLX is not available!\n"); 131 | return EXIT_FAILURE; 132 | } 133 | 134 | screen = DefaultScreen(dpy); 135 | root = RootWindow(dpy, screen); 136 | 137 | fbconfig = glXChooseFBConfig(dpy, screen, attrib, &numfbconfig); 138 | 139 | if(NULL == fbconfig) { 140 | fprintf(stderr, "error: couldn't choose a GLXFBConfig!\n"); 141 | return EXIT_FAILURE; 142 | } 143 | 144 | visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[0]); 145 | 146 | attr.background_pixel = 0; 147 | attr.border_pixel = 0; 148 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 149 | attr.event_mask = StructureNotifyMask | ExposureMask; 150 | 151 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 152 | /*width*/ 400, /*height*/ 400, 153 | 0, visinfo->depth, InputOutput, 154 | visinfo->visual, 155 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 156 | &attr); 157 | 158 | ctx = glXCreateContext(dpy, visinfo, NULL, True ); 159 | 160 | if(!ctx) { 161 | fprintf(stderr, "error: glXCreateContext failed!\n"); 162 | return EXIT_FAILURE; 163 | } 164 | 165 | XMapWindow(dpy, win); 166 | 167 | /*THIS ISN'T RIGHT YET. We need to check the fbconfig for the Pbuffer bit. */ 168 | pbuf = glXCreatePbuffer(dpy, fbconfig[0], pbattrib); 169 | 170 | printf("numfbconfig %d\n", numfbconfig); 171 | 172 | if(None == pbuf) { 173 | fprintf(stderr, "unable to create a GLXPbuffer!\n"); 174 | return EXIT_FAILURE; 175 | } 176 | 177 | printf("pbuf %lx\n", pbuf); 178 | 179 | if(!glXMakeCurrent(dpy, pbuf, ctx)) { 180 | fprintf(stderr, "glXMakeCurrent failed!\n"); 181 | return EXIT_FAILURE; 182 | } 183 | 184 | event_loop(dpy); 185 | 186 | return EXIT_SUCCESS; 187 | } 188 | -------------------------------------------------------------------------------- /appledri.h: -------------------------------------------------------------------------------- 1 | /* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.7 2000/12/07 20:26:02 dawes Exp $ */ 2 | /************************************************************************** 3 | 4 | Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. 5 | Copyright 2000 VA Linux Systems, Inc. 6 | Copyright (c) 2002, 2008, 2009 Apple Computer, Inc. 7 | All Rights Reserved. 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a 10 | copy of this software and associated documentation files (the 11 | "Software"), to deal in the Software without restriction, including 12 | without limitation the rights to use, copy, modify, merge, publish, 13 | distribute, sub license, and/or sell copies of the Software, and to 14 | permit persons to whom the Software is furnished to do so, subject to 15 | the following conditions: 16 | 17 | The above copyright notice and this permission notice (including the 18 | next paragraph) shall be included in all copies or substantial portions 19 | of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 24 | IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 25 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | 29 | **************************************************************************/ 30 | 31 | /* 32 | * Authors: 33 | * Kevin E. Martin 34 | * Jens Owen 35 | * Rickard E. (Rik) Faith 36 | * 37 | */ 38 | 39 | #ifndef _APPLEDRI_H_ 40 | #define _APPLEDRI_H_ 41 | 42 | #include 43 | #include 44 | 45 | #define X_AppleDRIQueryVersion 0 46 | #define X_AppleDRIQueryDirectRenderingCapable 1 47 | #define X_AppleDRICreateSurface 2 48 | #define X_AppleDRIDestroySurface 3 49 | #define X_AppleDRIAuthConnection 4 50 | #define X_AppleDRICreateSharedBuffer 5 51 | #define X_AppleDRISwapBuffers 6 52 | #define X_AppleDRICreatePixmap 7 53 | #define X_AppleDRIDestroyPixmap 8 54 | 55 | /* Requests up to and including 18 were used in a previous version */ 56 | 57 | /* Events */ 58 | #define AppleDRIObsoleteEvent1 0 59 | #define AppleDRIObsoleteEvent2 1 60 | #define AppleDRIObsoleteEvent3 2 61 | #define AppleDRISurfaceNotify 3 62 | #define AppleDRINumberEvents 4 63 | 64 | /* Errors */ 65 | #define AppleDRIClientNotLocal 0 66 | #define AppleDRIOperationNotSupported 1 67 | #define AppleDRINumberErrors (AppleDRIOperationNotSupported + 1) 68 | 69 | /* Kinds of SurfaceNotify events: */ 70 | #define AppleDRISurfaceNotifyChanged 0 71 | #define AppleDRISurfaceNotifyDestroyed 1 72 | 73 | #ifndef _APPLEDRI_SERVER_ 74 | 75 | typedef struct 76 | { 77 | int type; /* of event */ 78 | unsigned long serial; /* # of last request processed by server */ 79 | Bool send_event; /* true if this came frome a SendEvent request */ 80 | Display *display; /* Display the event was read from */ 81 | Window window; /* window of event */ 82 | Time time; /* server timestamp when event happened */ 83 | int kind; /* subtype of event */ 84 | int arg; 85 | } XAppleDRINotifyEvent; 86 | 87 | _XFUNCPROTOBEGIN 88 | Bool XAppleDRIQueryExtension(Display * dpy, int *event_base, 89 | int *error_base); 90 | 91 | Bool XAppleDRIQueryVersion(Display * dpy, int *majorVersion, 92 | int *minorVersion, int *patchVersion); 93 | 94 | Bool XAppleDRIQueryDirectRenderingCapable(Display * dpy, int screen, 95 | Bool * isCapable); 96 | 97 | void *XAppleDRISetSurfaceNotifyHandler(void (*fun) (Display * dpy, 98 | unsigned uid, int kind)); 99 | 100 | Bool XAppleDRIAuthConnection(Display * dpy, int screen, unsigned int magic); 101 | 102 | Bool XAppleDRICreateSurface(Display * dpy, int screen, Drawable drawable, 103 | unsigned int client_id, unsigned int key[2], 104 | unsigned int *uid); 105 | 106 | Bool XAppleDRIDestroySurface(Display * dpy, int screen, Drawable drawable); 107 | 108 | Bool XAppleDRISynchronizeSurfaces(Display * dpy); 109 | 110 | Bool XAppleDRICreateSharedBuffer(Display * dpy, int screen, Drawable drawable, 111 | Bool doubleSwap, char *path, size_t pathlen, 112 | int *width, int *height); 113 | 114 | Bool XAppleDRISwapBuffers(Display * dpy, int screen, Drawable drawable); 115 | 116 | Bool XAppleDRICreatePixmap(Display * dpy, int screen, Drawable drawable, 117 | int *width, int *height, int *pitch, int *bpp, 118 | size_t * size, char *bufname, size_t bufnamesize); 119 | 120 | Bool XAppleDRIDestroyPixmap(Display * dpy, Pixmap pixmap); 121 | 122 | _XFUNCPROTOEND 123 | #endif /* _APPLEDRI_SERVER_ */ 124 | #endif /* _APPLEDRI_H_ */ 125 | -------------------------------------------------------------------------------- /gen_exports.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | } 29 | 30 | package require Tcl 8.5 31 | 32 | proc main {argc argv} { 33 | if {2 != $argc} { 34 | puts stderr "syntax is: [info script] serialized-array-file export.list" 35 | return 1 36 | } 37 | 38 | set fd [open [lindex $argv 0] r] 39 | array set api [read $fd] 40 | close $fd 41 | 42 | #Start with 1.0 43 | set glxlist [list \ 44 | glXChooseVisual glXCreateContext glXDestroyContext \ 45 | glXMakeCurrent glXCopyContext glXSwapBuffers \ 46 | glXCreateGLXPixmap glXDestroyGLXPixmap \ 47 | glXQueryExtension glXQueryVersion \ 48 | glXIsDirect glXGetConfig \ 49 | glXGetCurrentContext glXGetCurrentDrawable \ 50 | glXWaitGL glXWaitX glXUseXFont] 51 | 52 | #GLX 1.1 and later 53 | lappend glxlist glXQueryExtensionsString glXQueryServerString \ 54 | glXGetClientString 55 | 56 | #GLX 1.2 and later 57 | lappend glxlist glXGetCurrentDisplay 58 | 59 | #GLX 1.3 and later 60 | lappend glxlist glXChooseFBConfig glXGetFBConfigAttrib \ 61 | glXGetFBConfigs glXGetVisualFromFBConfig \ 62 | glXCreateWindow glXDestroyWindow \ 63 | glXCreatePixmap glXDestroyPixmap \ 64 | glXCreatePbuffer glXDestroyPbuffer \ 65 | glXQueryDrawable glXCreateNewContext \ 66 | glXMakeContextCurrent glXGetCurrentReadDrawable \ 67 | glXQueryContext glXSelectEvent glXGetSelectedEvent 68 | 69 | #GLX 1.4 and later 70 | lappend glxlist glXGetProcAddress 71 | 72 | #Extensions 73 | lappend glxlist glXGetProcAddressARB 74 | 75 | #Old extensions we don't support and never really have, but need for 76 | #symbol compatibility. See also: glx_empty.c 77 | lappend glxlist glXSwapIntervalSGI glXSwapIntervalMESA \ 78 | glXGetSwapIntervalMESA glXBeginFrameTrackingMESA \ 79 | glXEndFrameTrackingMESA glXGetFrameUsageMESA \ 80 | glXQueryFrameTrackingMESA glXGetVideoSyncSGI \ 81 | glXWaitVideoSyncSGI glXJoinSwapGroupSGIX \ 82 | glXBindSwapBarrierSGIX glXQueryMaxSwapBarriersSGIX \ 83 | glXGetSyncValuesOML glXSwapBuffersMscOML \ 84 | glXWaitForMscOML glXWaitForSbcOML \ 85 | glXAllocateMemoryMESA glXFreeMemoryMESA \ 86 | glXGetMemoryOffsetMESA glXReleaseBuffersMESA \ 87 | glXCreateGLXPixmapMESA glXCopySubBufferMESA \ 88 | glXQueryGLXPbufferSGIX glXCreateGLXPbufferSGIX \ 89 | glXDestroyGLXPbufferSGIX glXSelectEventSGIX \ 90 | glXGetSelectedEventSGIX 91 | 92 | #These are for GLX_SGIX_fbconfig, which isn't implemented, because 93 | #we have the GLX 1.3 GLXFBConfig functions which are in the standard spec. 94 | #It should be possible to support these to some extent. 95 | #The old libGL somewhat supported the GLXFBConfigSGIX code, but lacked 96 | #pbuffer, and pixmap support. 97 | #We mainly just need these stubs for linking with apps, because for 98 | #some reason the OpenGL site suggests using the latest glxext.h, 99 | #and glxext.h defines all GLX extensions, which doesn't seem right for 100 | #compile-time capability detection. 101 | #See also: http://www.mesa3d.org/brianp/sig97/exten.htm#Compile 102 | #which conflicts with: the ABI registry from what I saw on opengl.org. 103 | #By disabling some of the #defines in glxext.h we break some software, 104 | #and by enabling them without the symbols we break others (in Mesa). 105 | #I think a lot of OpenGL-based programs have issues one way or another. 106 | #It seems that even Mesa developers are confused on this issue, because 107 | #Mesa-7.3/progs/xdemos/glxgears_fbconfig.c has comments about breakage 108 | #in some comments. 109 | lappend glxlist glXGetFBConfigAttribSGIX \ 110 | glXChooseFBConfigSGIX \ 111 | glXGetVisualFromFBConfigSGIX \ 112 | glXCreateGLXPixmapWithConfigSGIX \ 113 | glXCreateContextWithConfigSGIX \ 114 | glXGetFBConfigFromVisualSGIX 115 | 116 | 117 | set fd [open [lindex $argv 1] w] 118 | 119 | foreach f [lsort -dictionary [array names api]] { 120 | puts $fd _gl$f 121 | } 122 | 123 | foreach f [lsort -dictionary $glxlist] { 124 | puts $fd _$f 125 | } 126 | 127 | close $fd 128 | 129 | return 0 130 | } 131 | 132 | exit [main $::argc $::argv] -------------------------------------------------------------------------------- /include/simple_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file simple_list.h 3 | * Simple macros for type-safe, intrusive lists. 4 | * 5 | * Intended to work with a list sentinal which is created as an empty 6 | * list. Insert & delete are O(1). 7 | * 8 | * \author 9 | * (C) 1997, Keith Whitwell 10 | */ 11 | 12 | /* 13 | * Mesa 3-D graphics library 14 | * Version: 3.5 15 | * 16 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 17 | * 18 | * Permission is hereby granted, free of charge, to any person obtaining a 19 | * copy of this software and associated documentation files (the "Software"), 20 | * to deal in the Software without restriction, including without limitation 21 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 | * and/or sell copies of the Software, and to permit persons to whom the 23 | * Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included 26 | * in all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 29 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 31 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 32 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 33 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | */ 35 | 36 | 37 | #ifndef _SIMPLE_LIST_H 38 | #define _SIMPLE_LIST_H 39 | 40 | /** 41 | * Remove an element from list. 42 | * 43 | * \param elem element to remove. 44 | */ 45 | #define remove_from_list(elem) \ 46 | do { \ 47 | (elem)->next->prev = (elem)->prev; \ 48 | (elem)->prev->next = (elem)->next; \ 49 | } while (0) 50 | 51 | /** 52 | * Insert an element to the list head. 53 | * 54 | * \param list list. 55 | * \param elem element to insert. 56 | */ 57 | #define insert_at_head(list, elem) \ 58 | do { \ 59 | (elem)->prev = list; \ 60 | (elem)->next = (list)->next; \ 61 | (list)->next->prev = elem; \ 62 | (list)->next = elem; \ 63 | } while(0) 64 | 65 | /** 66 | * Insert an element to the list tail. 67 | * 68 | * \param list list. 69 | * \param elem element to insert. 70 | */ 71 | #define insert_at_tail(list, elem) \ 72 | do { \ 73 | (elem)->next = list; \ 74 | (elem)->prev = (list)->prev; \ 75 | (list)->prev->next = elem; \ 76 | (list)->prev = elem; \ 77 | } while(0) 78 | 79 | /** 80 | * Move an element to the list head. 81 | * 82 | * \param list list. 83 | * \param elem element to move. 84 | */ 85 | #define move_to_head(list, elem) \ 86 | do { \ 87 | remove_from_list(elem); \ 88 | insert_at_head(list, elem); \ 89 | } while (0) 90 | 91 | /** 92 | * Move an element to the list tail. 93 | * 94 | * \param list list. 95 | * \param elem element to move. 96 | */ 97 | #define move_to_tail(list, elem) \ 98 | do { \ 99 | remove_from_list(elem); \ 100 | insert_at_tail(list, elem); \ 101 | } while (0) 102 | 103 | /** 104 | * Make a empty list empty. 105 | * 106 | * \param sentinal list (sentinal element). 107 | */ 108 | #define make_empty_list(sentinal) \ 109 | do { \ 110 | (sentinal)->next = sentinal; \ 111 | (sentinal)->prev = sentinal; \ 112 | } while (0) 113 | 114 | /** 115 | * Get list first element. 116 | * 117 | * \param list list. 118 | * 119 | * \return pointer to first element. 120 | */ 121 | #define first_elem(list) ((list)->next) 122 | 123 | /** 124 | * Get list last element. 125 | * 126 | * \param list list. 127 | * 128 | * \return pointer to last element. 129 | */ 130 | #define last_elem(list) ((list)->prev) 131 | 132 | /** 133 | * Get next element. 134 | * 135 | * \param elem element. 136 | * 137 | * \return pointer to next element. 138 | */ 139 | #define next_elem(elem) ((elem)->next) 140 | 141 | /** 142 | * Get previous element. 143 | * 144 | * \param elem element. 145 | * 146 | * \return pointer to previous element. 147 | */ 148 | #define prev_elem(elem) ((elem)->prev) 149 | 150 | /** 151 | * Test whether element is at end of the list. 152 | * 153 | * \param list list. 154 | * \param elem element. 155 | * 156 | * \return non-zero if element is at end of list, or zero otherwise. 157 | */ 158 | #define at_end(list, elem) ((elem) == (list)) 159 | 160 | /** 161 | * Test if a list is empty. 162 | * 163 | * \param list list. 164 | * 165 | * \return non-zero if list empty, or zero otherwise. 166 | */ 167 | #define is_empty_list(list) ((list)->next == (list)) 168 | 169 | /** 170 | * Walk through the elements of a list. 171 | * 172 | * \param ptr pointer to the current element. 173 | * \param list list. 174 | * 175 | * \note It should be followed by a { } block or a single statement, as in a \c 176 | * for loop. 177 | */ 178 | #define foreach(ptr, list) \ 179 | for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next ) 180 | 181 | /** 182 | * Walk through the elements of a list. 183 | * 184 | * Same as #foreach but lets you unlink the current value during a list 185 | * traversal. Useful for freeing a list, element by element. 186 | * 187 | * \param ptr pointer to the current element. 188 | * \param t temporary pointer. 189 | * \param list list. 190 | * 191 | * \note It should be followed by a { } block or a single statement, as in a \c 192 | * for loop. 193 | */ 194 | #define foreach_s(ptr, t, list) \ 195 | for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next) 196 | 197 | #endif 198 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INSTALL_DIR = /usr/X11 2 | X11_DIR = $(INSTALL_DIR) 3 | 4 | CC=gcc 5 | GL_CFLAGS=-Wall -ggdb3 -Os -DPTHREADS -D_REENTRANT -DGLX_USE_APPLEGL -DGLX_ALIAS_UNSUPPORTED $(RC_CFLAGS) $(CFLAGS) 6 | GL_LDFLAGS=-L$(INSTALL_DIR)/lib -L$(X11_DIR)/lib $(LDFLAGS) -Wl,-single_module 7 | 8 | TCLSH=tclsh8.5 9 | 10 | MKDIR=mkdir 11 | INSTALL=install 12 | LN=ln 13 | RM=rm 14 | 15 | INCLUDE=-I. -Iinclude -Iinclude/internal -I$(INSTALL_DIR)/include -I$(X11_DIR)/include 16 | COMPILE=$(CC) $(INCLUDE) $(GL_CFLAGS) -c 17 | 18 | #The directory with the final binaries. 19 | BUILD_DIR=builds 20 | 21 | #The directory with binaries that can tested without an install. 22 | TEST_BUILD_DIR=testbuilds 23 | 24 | PROGRAMS=$(BUILD_DIR)/glxinfo $(BUILD_DIR)/glxgears 25 | 26 | all: programs tests 27 | programs: $(PROGRAMS) 28 | 29 | include tests/tests.mk 30 | 31 | OBJECTS=glxext.o glxcmds.o glx_pbuffer.o glx_query.o glxcurrent.o glxextensions.o \ 32 | appledri.o apple_glx_context.o apple_glx.o pixel.o \ 33 | compsize.o apple_visual.o apple_cgl.o glxreply.o glcontextmodes.o \ 34 | apple_xgl_api.o apple_glx_drawable.o xfont.o apple_glx_pbuffer.o \ 35 | apple_glx_pixmap.o apple_xgl_api_read.o glx_empty.o glx_error.o \ 36 | apple_xgl_api_viewport.o apple_glx_surface.o apple_xgl_api_stereo.o 37 | 38 | #This is used for building the tests. 39 | #The tests don't require installation. 40 | $(TEST_BUILD_DIR)/libGL.dylib: $(OBJECTS) 41 | -if ! test -d $(TEST_BUILD_DIR); then $(MKDIR) $(TEST_BUILD_DIR); fi 42 | $(CC) -O0 -ggdb3 -o $@ -dynamiclib -lXplugin -framework ApplicationServices -framework CoreFoundation -L$(X11_DIR)/lib -lX11 -lXext -Wl,-exported_symbols_list,exports.list -Wl,-single_module $(OBJECTS) 43 | 44 | $(BUILD_DIR)/libGL.1.2.dylib: $(OBJECTS) 45 | -if ! test -d $(BUILD_DIR); then $(MKDIR) $(BUILD_DIR); fi 46 | $(CC) $(GL_CFLAGS) -o $@ -dynamiclib -install_name $(INSTALL_DIR)/lib/libGL.1.dylib -compatibility_version 1.2 -current_version 1.2 -lXplugin -framework ApplicationServices -framework CoreFoundation $(GL_LDFLAGS) -lXext -lX11 -Wl,-exported_symbols_list,exports.list $(OBJECTS) 47 | 48 | .c.o: 49 | $(COMPILE) $< 50 | 51 | apple_glx_drawable.o: apple_glx_drawable.h apple_glx_drawable.c include/GL/gl.h 52 | apple_xgl_api.o: apple_xgl_api.h apple_xgl_api.c apple_xgl_api_stereo.c include/GL/gl.h 53 | apple_xgl_api_read.o: apple_xgl_api_read.h apple_xgl_api_read.c apple_xgl_api.h include/GL/gl.h 54 | apple_xgl_api_viewport.o: apple_xgl_api_viewport.h apple_xgl_api_viewport.c apple_xgl_api.h include/GL/gl.h 55 | apple_xgl_api_stereo.o: apple_xgl_api_stereo.h apple_xgl_api_stereo.c apple_xgl_api.h include/GL/gl.h 56 | glcontextmodes.o: glcontextmodes.c glcontextmodes.h include/GL/gl.h 57 | glxext.o: glxext.c include/GL/gl.h 58 | glxreply.o: glxreply.c include/GL/gl.h 59 | glxcmds.o: glxcmds.c apple_glx_context.h include/GL/gl.h 60 | glx_pbuffer.o: glx_pbuffer.c include/GL/gl.h 61 | glx_error.o: glx_error.c include/GL/gl.h 62 | glx_query.o: glx_query.c include/GL/gl.h 63 | glxcurrent.o: glxcurrent.c include/GL/gl.h 64 | glxextensions.o: glxextensions.h glxextensions.c include/GL/gl.h 65 | glxhash.o: glxhash.h glxhash.c include/GL/gl.h 66 | appledri.o: appledri.h appledristr.h appledri.c include/GL/gl.h 67 | apple_glx_context.o: apple_glx_context.c apple_glx_context.h apple_glx_context.h include/GL/gl.h 68 | apple_glx.o: apple_glx.h apple_glx.c apple_xgl_api.h include/GL/gl.h 69 | apple_visual.o: apple_visual.h apple_visual.c include/GL/gl.h 70 | apple_cgl.o: apple_cgl.h apple_cgl.c include/GL/gl.h 71 | apple_glx_pbuffer.o: apple_glx_drawable.h apple_glx_pbuffer.c include/GL/gl.h 72 | apple_glx_pixmap.o: apple_glx_drawable.h apple_glx_pixmap.c appledri.h include/GL/gl.h 73 | apple_glx_surface.o: apple_glx_drawable.h apple_glx_surface.c appledri.h include/GL/gl.h 74 | xfont.o: xfont.c glxclient.h include/GL/gl.h 75 | compsize.o: compsize.c include/GL/gl.h 76 | renderpix.o: renderpix.c include/GL/gl.h 77 | singlepix.o: singlepix.c include/GL/gl.h 78 | pixel.o: pixel.c include/GL/gl.h 79 | glx_empty.o: glx_empty.c include/GL/gl.h 80 | 81 | apple_xgl_api.c: apple_xgl_api.h 82 | apple_xgl_api.h: gen_api_header.tcl gen_api_library.tcl gen_code.tcl gen_defs.tcl gen_exports.tcl gen_funcs.tcl gen_types.tcl 83 | $(TCLSH) gen_code.tcl 84 | 85 | include/GL/gl.h: include/GL/gl.h.template gen_gl_h.sh 86 | ./gen_gl_h.sh include/GL/gl.h.template $@ 87 | 88 | $(BUILD_DIR)/glxinfo: tests/glxinfo/glxinfo.c $(BUILD_DIR)/libGL.1.2.dylib 89 | $(CC) tests/glxinfo/glxinfo.c $(INCLUDE) -L$(X11_DIR)/lib -lX11 $(BUILD_DIR)/libGL.1.2.dylib -o $@ 90 | 91 | $(BUILD_DIR)/glxgears: tests/glxgears/glxgears.c $(BUILD_DIR)/libGL.1.2.dylib 92 | $(CC) tests/glxgears/glxgears.c $(INCLUDE) -L$(X11_DIR)/lib -lX11 $(BUILD_DIR)/libGL.1.2.dylib -o $@ 93 | 94 | install_headers: 95 | $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GL 96 | $(INSTALL) -m 644 include/GL/gl.h include/GL/glext.h include/GL/glx.h include/GL/glxext.h $(DESTDIR)$(INSTALL_DIR)/include/GL 97 | 98 | install_programs: programs 99 | $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/bin 100 | $(INSTALL) -m 755 $(PROGRAMS) $(DESTDIR)$(INSTALL_DIR)/bin 101 | 102 | install_libraries: $(BUILD_DIR)/libGL.1.2.dylib 103 | $(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/lib 104 | $(INSTALL) -m 755 $(BUILD_DIR)/libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib 105 | $(RM) -f $(DESTDIR)$(INSTALL_DIR)/lib/libGL.dylib 106 | $(LN) -s libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib/libGL.dylib 107 | $(RM) -f $(DESTDIR)$(INSTALL_DIR)/lib/libGL.1.dylib 108 | $(LN) -s libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib/libGL.1.dylib 109 | 110 | install: install_headers install_libraries 111 | 112 | clean: 113 | rm -rf $(BUILD_DIR) 114 | rm -rf $(TEST_BUILD_DIR) 115 | rm -f *.o *.a 116 | rm -f *.c~ *.h~ 117 | rm -f apple_xgl_api.h apple_xgl_api.c 118 | rm -f *.dylib 119 | rm -f include/GL/gl.h 120 | -------------------------------------------------------------------------------- /tests/simple/multisample_glx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | GLuint tlist, checkerlist; 7 | 8 | void draw(Display *dpy, Window w) { 9 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 10 | glLoadIdentity(); 11 | glEnable(GL_MULTISAMPLE); 12 | 13 | glCallList(tlist); 14 | glXSwapBuffers(dpy, w); 15 | } 16 | 17 | void resize(Display *dpy, Window w, int width, int height) { 18 | glViewport(0, 0, width, height); 19 | draw(dpy, w); 20 | } 21 | 22 | void create_lists(void) { 23 | GLint sbufs, samples; 24 | int i; 25 | 26 | tlist = glGenLists(1); 27 | checkerlist = glGenLists(1); 28 | 29 | if(0 == tlist || 0 == checkerlist) { 30 | fprintf(stderr, "unable to generate lists!\n"); 31 | abort(); 32 | } 33 | 34 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 35 | glGetIntegerv(GL_SAMPLE_BUFFERS, &sbufs); 36 | glGetIntegerv(GL_SAMPLES, &samples); 37 | 38 | printf("sample buffers %d samples %d\n", sbufs, samples); 39 | 40 | glNewList(tlist, GL_COMPILE); 41 | 42 | for(i = 0; i < 20; ++i) { 43 | glPushMatrix(); 44 | glRotatef(360.0f * (float) i / 20, 0.0f, 0.0f, 1.0f); 45 | glColor3f(1.0f, 0.5f, 0.5f); 46 | glLineWidth(0.1); 47 | glBegin(GL_LINES); 48 | glVertex2f(0.1, 0.5); 49 | glVertex2f(0.8, 0.4); 50 | glEnd(); 51 | 52 | glColor3f(0.5f, 0.5f, 0.5f); 53 | glBegin(GL_TRIANGLES); 54 | glVertex2f(0.5, 0.0f); 55 | glVertex2f(0.9, 0.9f); 56 | glVertex2f(0.1, 0.9f); 57 | glEnd(); 58 | 59 | glPopMatrix(); 60 | } 61 | 62 | glEndList(); 63 | } 64 | 65 | void event_loop(Display *dpy) { 66 | XEvent event; 67 | 68 | while(1) { 69 | XNextEvent(dpy, &event); 70 | 71 | switch(event.type) { 72 | case Expose: 73 | draw(dpy, event.xexpose.window); 74 | break; 75 | 76 | case ConfigureNotify: 77 | resize(dpy, event.xconfigure.window, event.xconfigure.width, 78 | event.xconfigure.height); 79 | break; 80 | } 81 | } 82 | } 83 | 84 | int main() { 85 | Display *dpy; 86 | int fbattrib[] = { 87 | GLX_DOUBLEBUFFER, True, 88 | GLX_RED_SIZE, 8, 89 | GLX_GREEN_SIZE, 8, 90 | GLX_BLUE_SIZE, 8, 91 | GLX_ALPHA_SIZE, 8, 92 | GLX_SAMPLE_BUFFERS, 1, 93 | GLX_SAMPLES, 1, 94 | None 95 | }; 96 | 97 | int eventbase, errorbase; 98 | int screen; 99 | Window root, win; 100 | XVisualInfo *visinfo; 101 | XSetWindowAttributes attr; 102 | GLXContext ctx; 103 | GLXFBConfig *fbconfig; 104 | int i, numfbconfig, maxsample = 0; 105 | int bestfbi = 0, value; 106 | 107 | dpy = XOpenDisplay(NULL); 108 | 109 | if(NULL == dpy) { 110 | fprintf(stderr, "error: unable to open display!\n"); 111 | return EXIT_FAILURE; 112 | } 113 | 114 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 115 | fprintf(stderr, "GLX is not available!\n"); 116 | return EXIT_FAILURE; 117 | } 118 | 119 | screen = DefaultScreen(dpy); 120 | root = RootWindow(dpy, screen); 121 | 122 | fbconfig = glXChooseFBConfig(dpy, screen, fbattrib, &numfbconfig); 123 | 124 | if(NULL == fbconfig) { 125 | fprintf(stderr, "error: choosing GLXFBConfig!\n"); 126 | return EXIT_FAILURE; 127 | } 128 | 129 | for(i = 0; i < numfbconfig; ++i) { 130 | glXGetFBConfigAttrib(dpy, fbconfig[i], GLX_SAMPLES, &value); 131 | 132 | if(value > maxsample) { 133 | bestfbi = i; 134 | maxsample = value; 135 | } 136 | } 137 | 138 | glXGetFBConfigAttrib(dpy, fbconfig[bestfbi], GLX_SAMPLES, &value); 139 | printf("peak GLX_SAMPLES %d\n", value); 140 | 141 | visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[bestfbi]); 142 | 143 | if (!visinfo) { 144 | fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); 145 | return EXIT_FAILURE; 146 | } 147 | 148 | printf("visinfo->visualid %lx\n", visinfo->visualid); 149 | 150 | glXGetFBConfigAttrib(dpy, fbconfig[bestfbi], GLX_FBCONFIG_ID, &value); 151 | 152 | printf("fbconfig id 0x%x\n", value); 153 | 154 | 155 | attr.background_pixel = 0; 156 | attr.border_pixel = 0; 157 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); 158 | attr.event_mask = StructureNotifyMask | ExposureMask; 159 | 160 | win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, 161 | /*width*/ 400, /*height*/ 400, 162 | 0, visinfo->depth, InputOutput, 163 | visinfo->visual, 164 | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, 165 | &attr); 166 | 167 | ctx = glXCreateNewContext(dpy, fbconfig[bestfbi], GLX_WINDOW_BIT, 168 | NULL, True); 169 | 170 | if (!ctx) { 171 | fprintf(stderr, "error: glXCreateNewContext failed!\n"); 172 | return EXIT_FAILURE; 173 | } 174 | 175 | XMapWindow(dpy, win); 176 | 177 | if(!glXMakeCurrent(dpy, win, ctx)) { 178 | fprintf(stderr, "error: making context current!\n"); 179 | return EXIT_FAILURE; 180 | } 181 | 182 | printf("GL_RENDERER %s\n", (char *) glGetString(GL_RENDERER)); 183 | 184 | glEnable(GL_MULTISAMPLE); 185 | 186 | create_lists(); 187 | 188 | { 189 | GLint alpha, red, green; 190 | GLboolean dbuf; 191 | 192 | glGetIntegerv(GL_RED_BITS, &red); 193 | printf("glGetIntegerv(GL_RED_BITS) %d\n", red); 194 | 195 | glGetIntegerv(GL_GREEN_BITS, &green); 196 | printf("glGetIntegerv(GL_GREEN_BITS) %d\n", green); 197 | 198 | glGetIntegerv(GL_ALPHA_BITS, &alpha); 199 | printf("glGetIntegerv(GL_ALPHA_BITS) %d\n", alpha); 200 | 201 | glGetBooleanv(GL_DOUBLEBUFFER, &dbuf); 202 | printf("glGetBooleanv(GL_DOUBLEBUFFER) %d\n", dbuf); 203 | 204 | GLint aux; 205 | glGetIntegerv(GL_AUX_BUFFERS, &aux); 206 | printf("aux buffers %d\n", aux); 207 | 208 | GLint ared; 209 | glGetIntegerv(GL_ACCUM_RED_BITS, &ared); 210 | printf("accum red bits %d\n", ared); 211 | } 212 | 213 | event_loop(dpy); 214 | 215 | return EXIT_SUCCESS; 216 | } 217 | -------------------------------------------------------------------------------- /tests/glxpixmap/glxpixmap.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * A demonstration of using the GLXPixmap functions. This program is in 5 | * the public domain. 6 | * 7 | * Brian Paul 8 | */ 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | static GLXContext ctx; 19 | static XVisualInfo *visinfo; 20 | static GC gc; 21 | 22 | 23 | 24 | static Window make_rgb_window( Display *dpy, 25 | unsigned int width, unsigned int height ) 26 | { 27 | const int sbAttrib[] = { GLX_RGBA, 28 | GLX_RED_SIZE, 1, 29 | GLX_GREEN_SIZE, 1, 30 | GLX_BLUE_SIZE, 1, 31 | None }; 32 | const int dbAttrib[] = { GLX_RGBA, 33 | GLX_RED_SIZE, 1, 34 | GLX_GREEN_SIZE, 1, 35 | GLX_BLUE_SIZE, 1, 36 | GLX_DOUBLEBUFFER, 37 | None }; 38 | int scrnum; 39 | XSetWindowAttributes attr; 40 | unsigned long mask; 41 | Window root; 42 | Window win; 43 | 44 | scrnum = DefaultScreen( dpy ); 45 | root = RootWindow( dpy, scrnum ); 46 | 47 | visinfo = glXChooseVisual( dpy, scrnum, (int *) sbAttrib ); 48 | if (!visinfo) { 49 | visinfo = glXChooseVisual( dpy, scrnum, (int *) dbAttrib ); 50 | if (!visinfo) { 51 | printf("Error: couldn't get an RGB visual\n"); 52 | exit(1); 53 | } 54 | } 55 | 56 | /* window attributes */ 57 | attr.background_pixel = 0; 58 | attr.border_pixel = 0; 59 | /* TODO: share root colormap if possible */ 60 | attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); 61 | attr.event_mask = StructureNotifyMask | ExposureMask; 62 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; 63 | 64 | win = XCreateWindow( dpy, root, 0, 0, width, height, 65 | 0, visinfo->depth, InputOutput, 66 | visinfo->visual, mask, &attr ); 67 | 68 | /* make an X GC so we can do XCopyArea later */ 69 | gc = XCreateGC( dpy, win, 0, NULL ); 70 | 71 | /* need indirect context */ 72 | ctx = glXCreateContext( dpy, visinfo, NULL, False ); 73 | if (!ctx) { 74 | printf("Error: glXCreateContext failed\n"); 75 | exit(-1); 76 | } 77 | 78 | printf("Direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); 79 | 80 | return win; 81 | } 82 | 83 | 84 | static GLXPixmap make_pixmap( Display *dpy, Window win, 85 | unsigned int width, unsigned int height, 86 | Pixmap *pixmap) 87 | { 88 | Pixmap pm; 89 | GLXPixmap glxpm; 90 | XWindowAttributes attr; 91 | 92 | pm = XCreatePixmap( dpy, win, width, height, visinfo->depth ); 93 | if (!pm) { 94 | printf("Error: XCreatePixmap failed\n"); 95 | exit(-1); 96 | } 97 | 98 | XGetWindowAttributes( dpy, win, &attr ); 99 | 100 | printf("pm %lx\n", pm); 101 | /* 102 | * IMPORTANT: 103 | * Use the glXCreateGLXPixmapMESA funtion when using Mesa because 104 | * Mesa needs to know the colormap associated with a pixmap in order 105 | * to render correctly. This is because Mesa allows RGB rendering 106 | * into any kind of visual, not just TrueColor or DirectColor. 107 | */ 108 | #ifdef GLX_MESA_pixmap_colormap 109 | if (strstr(glXQueryExtensionsString(dpy, 0), "GLX_MESA_pixmap_colormap")) { 110 | /* stand-alone Mesa, specify the colormap */ 111 | glxpm = glXCreateGLXPixmapMESA( dpy, visinfo, pm, attr.colormap ); 112 | } 113 | else { 114 | glxpm = glXCreateGLXPixmap( dpy, visinfo, pm ); 115 | } 116 | #else 117 | /* This will work with Mesa too if the visual is TrueColor or DirectColor */ 118 | glxpm = glXCreateGLXPixmap( dpy, visinfo, pm ); 119 | #endif 120 | 121 | if (!glxpm) { 122 | printf("Error: GLXCreateGLXPixmap failed\n"); 123 | exit(-1); 124 | } 125 | 126 | *pixmap = pm; 127 | 128 | return glxpm; 129 | } 130 | 131 | 132 | 133 | static void event_loop( Display *dpy, GLXPixmap pm ) 134 | { 135 | XEvent event; 136 | 137 | while (1) { 138 | XNextEvent( dpy, &event ); 139 | 140 | switch (event.type) { 141 | case Expose: 142 | printf("Redraw\n"); 143 | /* copy the image from GLXPixmap to window */ 144 | XCopyArea( dpy, pm, event.xany.window, /* src, dest */ 145 | gc, 0, 0, 300, 300, /* gc, src pos, size */ 146 | 0, 0 ); /* dest pos */ 147 | break; 148 | case ConfigureNotify: 149 | /* nothing */ 150 | break; 151 | } 152 | } 153 | } 154 | 155 | 156 | 157 | int main( int argc, char *argv[] ) 158 | { 159 | Display *dpy; 160 | Window win; 161 | Pixmap pm; 162 | GLXPixmap glxpm; 163 | int eventbase, errorbase; 164 | 165 | dpy = XOpenDisplay(NULL); 166 | 167 | if(NULL == dpy) { 168 | fprintf(stderr, "error: opening display\n"); 169 | return EXIT_FAILURE; 170 | } 171 | 172 | if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { 173 | fprintf(stderr, "GLX is not available!\n"); 174 | return EXIT_FAILURE; 175 | } 176 | 177 | 178 | win = make_rgb_window( dpy, 300, 300 ); 179 | glxpm = make_pixmap( dpy, win, 300, 300, &pm ); 180 | 181 | printf("glxpm 0x%lx\n", glxpm); 182 | 183 | if(!glXMakeCurrent(dpy, glxpm, ctx)) { 184 | fprintf(stderr, "glXMakeCurrent failed!\n"); 185 | return EXIT_FAILURE; 186 | } 187 | 188 | printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); 189 | 190 | /* Render an image into the pixmap */ 191 | glShadeModel( GL_FLAT ); 192 | glClearColor( 0.5, 0.5, 0.5, 1.0 ); 193 | glClear( GL_COLOR_BUFFER_BIT ); 194 | glViewport( 0, 0, 300, 300 ); 195 | glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); 196 | glColor3f( 0.0, 0.0, 1.0 ); 197 | glRectf( -0.75, -0.75, 0.75, 0.75 ); 198 | glFlush(); 199 | 200 | XMapWindow( dpy, win ); 201 | 202 | event_loop( dpy, pm ); 203 | 204 | return 0; 205 | } 206 | -------------------------------------------------------------------------------- /apple_glx.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008, 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "appledri.h" 37 | #include "apple_glx.h" 38 | #include "apple_glx_context.h" 39 | #include "apple_cgl.h" 40 | #include "apple_xgl_api.h" 41 | 42 | static bool initialized = false; 43 | static int dri_event_base = 0; 44 | 45 | const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 }; 46 | 47 | #ifndef OPENGL_LIB_PATH 48 | #define OPENGL_LIB_PATH "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" 49 | #endif 50 | 51 | static void *libgl_handle = NULL; 52 | 53 | static bool diagnostic = false; 54 | 55 | void 56 | apple_glx_diagnostic(const char *fmt, ...) 57 | { 58 | va_list vl; 59 | 60 | if (diagnostic) { 61 | fprintf(stderr, "DIAG: "); 62 | 63 | va_start(vl, fmt); 64 | vfprintf(stderr, fmt, vl); 65 | va_end(vl); 66 | } 67 | } 68 | 69 | int 70 | apple_get_dri_event_base(void) 71 | { 72 | if (!initialized) { 73 | fprintf(stderr, 74 | "error: dri_event_base called before apple_init_glx!\n"); 75 | abort(); 76 | } 77 | return dri_event_base; 78 | } 79 | 80 | static void 81 | surface_notify_handler(Display * dpy, unsigned int uid, int kind) 82 | { 83 | 84 | switch (kind) { 85 | case AppleDRISurfaceNotifyDestroyed: 86 | apple_glx_diagnostic("%s: surface destroyed %u\n", __func__, uid); 87 | apple_glx_surface_destroy(uid); 88 | break; 89 | 90 | case AppleDRISurfaceNotifyChanged:{ 91 | int updated; 92 | 93 | updated = apple_glx_context_surface_changed(uid, pthread_self()); 94 | 95 | apple_glx_diagnostic("surface notify updated %d\n", updated); 96 | } 97 | break; 98 | 99 | default: 100 | fprintf(stderr, "unhandled kind of event: %d in %s\n", kind, __func__); 101 | } 102 | } 103 | 104 | xp_client_id 105 | apple_glx_get_client_id(void) 106 | { 107 | static xp_client_id id; 108 | 109 | if (0 == id) { 110 | if ((XP_Success != xp_init(XP_IN_BACKGROUND)) || 111 | (Success != xp_get_client_id(&id))) { 112 | return 0; 113 | } 114 | } 115 | 116 | return id; 117 | } 118 | 119 | /* Return true if an error occured. */ 120 | bool 121 | apple_init_glx(Display * dpy) 122 | { 123 | int eventBase, errorBase; 124 | int major, minor, patch; 125 | 126 | if (!XAppleDRIQueryExtension(dpy, &eventBase, &errorBase)) 127 | return true; 128 | 129 | if (!XAppleDRIQueryVersion(dpy, &major, &minor, &patch)) 130 | return true; 131 | 132 | if (initialized) 133 | return false; 134 | 135 | if (getenv("LIBGL_DIAGNOSTIC")) { 136 | printf("initializing libGL in %s\n", __func__); 137 | diagnostic = true; 138 | } 139 | 140 | apple_cgl_init(); 141 | apple_xgl_init_direct(); 142 | libgl_handle = dlopen(OPENGL_LIB_PATH, RTLD_LAZY); 143 | (void) apple_glx_get_client_id(); 144 | 145 | XAppleDRISetSurfaceNotifyHandler(surface_notify_handler); 146 | 147 | /* This should really be per display. */ 148 | dri_event_base = eventBase; 149 | initialized = true; 150 | 151 | return false; 152 | } 153 | 154 | void 155 | apple_glx_swap_buffers(void *ptr) 156 | { 157 | struct apple_glx_context *ac = ptr; 158 | 159 | /* This may not be needed with CGLFlushDrawable: */ 160 | glFlush(); 161 | apple_cgl.flush_drawable(ac->context_obj); 162 | } 163 | 164 | void * 165 | apple_glx_get_proc_address(const GLubyte * procname) 166 | { 167 | size_t len; 168 | void *h, *s; 169 | char *pname = (char *) procname; 170 | 171 | assert(NULL != procname); 172 | len = strlen(pname); 173 | 174 | if (len < 3) { 175 | return NULL; 176 | } 177 | 178 | if ((pname != strstr(pname, "glX")) && (pname != strstr(pname, "gl"))) { 179 | fprintf(stderr, 180 | "warning: get proc address request is not for a gl or glX function"); 181 | return NULL; 182 | } 183 | 184 | /* Search using the default symbols first. */ 185 | (void) dlerror(); /*drain dlerror */ 186 | h = dlopen(NULL, RTLD_NOW); 187 | if (NULL == h) { 188 | fprintf(stderr, "warning: get proc address: %s\n", dlerror()); 189 | return NULL; 190 | } 191 | 192 | s = dlsym(h, pname); 193 | 194 | if (NULL == s) { 195 | /* Try the libGL.dylib from the OpenGL.framework. */ 196 | s = dlsym(libgl_handle, pname); 197 | } 198 | 199 | dlclose(h); 200 | 201 | return s; 202 | } 203 | 204 | void 205 | apple_glx_waitx(Display * dpy, void *ptr) 206 | { 207 | struct apple_private_context *ac = ptr; 208 | 209 | (void) ac; 210 | 211 | glFlush(); 212 | glFinish(); 213 | XSync(dpy, False); 214 | } 215 | -------------------------------------------------------------------------------- /glx_query.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright IBM Corporation 2004 3 | * All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * on the rights to use, copy, modify, merge, publish, distribute, sub 9 | * license, and/or sell copies of the Software, and to permit persons to whom 10 | * the Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including the next 13 | * paragraph) shall be included in all copies or substantial portions of the 14 | * Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19 | * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * \file glx_query.c 27 | * Generic utility functions to query internal data from the server. 28 | * 29 | * \author Ian Romanick 30 | */ 31 | 32 | #include "glxclient.h" 33 | 34 | #if defined(USE_XCB) 35 | # include 36 | # include 37 | # include 38 | #endif 39 | 40 | #ifdef USE_XCB 41 | 42 | /** 43 | * Exchange a protocol request for glXQueryServerString. 44 | */ 45 | char * 46 | __glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) 47 | { 48 | xcb_connection_t *c = XGetXCBConnection(dpy); 49 | xcb_glx_query_server_string_reply_t *reply = 50 | xcb_glx_query_server_string_reply(c, 51 | xcb_glx_query_server_string(c, 52 | screen, 53 | name), 54 | NULL); 55 | 56 | /* The spec doesn't mention this, but the Xorg server replies with 57 | * a string already terminated with '\0'. */ 58 | uint32_t len = xcb_glx_query_server_string_string_length(reply); 59 | char *buf = Xmalloc(len); 60 | memcpy(buf, xcb_glx_query_server_string_string(reply), len); 61 | free(reply); 62 | 63 | return buf; 64 | } 65 | 66 | /** 67 | * Exchange a protocol request for glGetString. 68 | */ 69 | char * 70 | __glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) 71 | { 72 | xcb_connection_t *c = XGetXCBConnection(dpy); 73 | xcb_glx_get_string_reply_t *reply = xcb_glx_get_string_reply(c, 74 | xcb_glx_get_string 75 | (c, 76 | contextTag, 77 | name), 78 | NULL); 79 | 80 | /* The spec doesn't mention this, but the Xorg server replies with 81 | * a string already terminated with '\0'. */ 82 | uint32_t len = xcb_glx_get_string_string_length(reply); 83 | char *buf = Xmalloc(len); 84 | memcpy(buf, xcb_glx_get_string_string(reply), len); 85 | free(reply); 86 | 87 | return buf; 88 | } 89 | 90 | #else 91 | 92 | /** 93 | * GLX protocol structure for the ficticious "GXLGenericGetString" request. 94 | * 95 | * This is a non-existant protocol packet. It just so happens that all of 96 | * the real protocol packets used to request a string from the server have 97 | * an identical binary layout. The only difference between them is the 98 | * meaning of the \c for_whom field and the value of the \c glxCode. 99 | */ 100 | typedef struct GLXGenericGetString 101 | { 102 | CARD8 reqType; 103 | CARD8 glxCode; 104 | CARD16 length B16; 105 | CARD32 for_whom B32; 106 | CARD32 name B32; 107 | } xGLXGenericGetStringReq; 108 | 109 | /* These defines are only needed to make the GetReq macro happy. 110 | */ 111 | #define sz_xGLXGenericGetStringReq 12 112 | #define X_GLXGenericGetString 0 113 | 114 | /** 115 | * Query the Server GLX string. 116 | * This routine will allocate the necessay space for the string. 117 | */ 118 | static char * 119 | __glXGetStringFromServer(Display * dpy, int opcode, CARD32 glxCode, 120 | CARD32 for_whom, CARD32 name) 121 | { 122 | xGLXGenericGetStringReq *req; 123 | xGLXSingleReply reply; 124 | int length; 125 | int numbytes; 126 | char *buf; 127 | 128 | 129 | LockDisplay(dpy); 130 | 131 | 132 | /* All of the GLX protocol requests for getting a string from the server 133 | * look the same. The exact meaning of the for_whom field is usually 134 | * either the screen number (for glXQueryServerString) or the context tag 135 | * (for GLXSingle). 136 | */ 137 | 138 | GetReq(GLXGenericGetString, req); 139 | req->reqType = opcode; 140 | req->glxCode = glxCode; 141 | req->for_whom = for_whom; 142 | req->name = name; 143 | 144 | _XReply(dpy, (xReply *) & reply, 0, False); 145 | 146 | length = reply.length * 4; 147 | numbytes = reply.size; 148 | 149 | buf = (char *) Xmalloc(numbytes); 150 | if (buf != NULL) { 151 | _XRead(dpy, buf, numbytes); 152 | length -= numbytes; 153 | } 154 | 155 | _XEatData(dpy, length); 156 | 157 | UnlockDisplay(dpy); 158 | SyncHandle(); 159 | 160 | return buf; 161 | } 162 | 163 | char * 164 | __glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name) 165 | { 166 | return __glXGetStringFromServer(dpy, opcode, 167 | X_GLXQueryServerString, screen, name); 168 | } 169 | 170 | char * 171 | __glXGetString(Display * dpy, int opcode, CARD32 contextTag, CARD32 name) 172 | { 173 | return __glXGetStringFromServer(dpy, opcode, X_GLsop_GetString, 174 | contextTag, name); 175 | } 176 | 177 | #endif /* USE_XCB */ 178 | -------------------------------------------------------------------------------- /compsize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice including the dates of first publication and 13 | * either this permission notice or a reference to 14 | * http://oss.sgi.com/projects/FreeB/ 15 | * shall be included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | * 25 | * Except as contained in this notice, the name of Silicon Graphics, Inc. 26 | * shall not be used in advertising or otherwise to promote the sale, use or 27 | * other dealings in this Software without prior written authorization from 28 | * Silicon Graphics, Inc. 29 | */ 30 | 31 | #include 32 | #ifndef GLX_USE_APPLEGL 33 | #include "indirect_size.h" 34 | #endif 35 | #include "glxclient.h" 36 | 37 | /* 38 | ** Return the number of elements per group of a specified format 39 | */ 40 | GLint 41 | __glElementsPerGroup(GLenum format, GLenum type) 42 | { 43 | /* 44 | ** To make row length computation valid for image extraction, 45 | ** packed pixel types assume elements per group equals one. 46 | */ 47 | switch (type) { 48 | case GL_UNSIGNED_BYTE_3_3_2: 49 | case GL_UNSIGNED_BYTE_2_3_3_REV: 50 | case GL_UNSIGNED_SHORT_5_6_5: 51 | case GL_UNSIGNED_SHORT_5_6_5_REV: 52 | case GL_UNSIGNED_SHORT_4_4_4_4: 53 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: 54 | case GL_UNSIGNED_SHORT_5_5_5_1: 55 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: 56 | case GL_UNSIGNED_SHORT_8_8_APPLE: 57 | case GL_UNSIGNED_SHORT_8_8_REV_APPLE: 58 | case GL_UNSIGNED_SHORT_15_1_MESA: 59 | case GL_UNSIGNED_SHORT_1_15_REV_MESA: 60 | case GL_UNSIGNED_INT_8_8_8_8: 61 | case GL_UNSIGNED_INT_8_8_8_8_REV: 62 | case GL_UNSIGNED_INT_10_10_10_2: 63 | case GL_UNSIGNED_INT_2_10_10_10_REV: 64 | case GL_UNSIGNED_INT_24_8_NV: 65 | case GL_UNSIGNED_INT_24_8_MESA: 66 | case GL_UNSIGNED_INT_8_24_REV_MESA: 67 | return 1; 68 | default: 69 | break; 70 | } 71 | 72 | switch (format) { 73 | case GL_RGB: 74 | case GL_BGR: 75 | return 3; 76 | case GL_422_EXT: 77 | case GL_422_REV_EXT: 78 | case GL_422_AVERAGE_EXT: 79 | case GL_422_REV_AVERAGE_EXT: 80 | case GL_YCBCR_422_APPLE: 81 | case GL_LUMINANCE_ALPHA: 82 | return 2; 83 | case GL_RGBA: 84 | case GL_BGRA: 85 | case GL_ABGR_EXT: 86 | return 4; 87 | case GL_COLOR_INDEX: 88 | case GL_STENCIL_INDEX: 89 | case GL_DEPTH_COMPONENT: 90 | case GL_RED: 91 | case GL_GREEN: 92 | case GL_BLUE: 93 | case GL_ALPHA: 94 | case GL_LUMINANCE: 95 | case GL_INTENSITY: 96 | return 1; 97 | default: 98 | return 0; 99 | } 100 | } 101 | 102 | /* 103 | ** Return the number of bytes per element, based on the element type (other 104 | ** than GL_BITMAP). 105 | */ 106 | GLint 107 | __glBytesPerElement(GLenum type) 108 | { 109 | switch (type) { 110 | case GL_UNSIGNED_SHORT: 111 | case GL_SHORT: 112 | case GL_UNSIGNED_SHORT_5_6_5: 113 | case GL_UNSIGNED_SHORT_5_6_5_REV: 114 | case GL_UNSIGNED_SHORT_4_4_4_4: 115 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: 116 | case GL_UNSIGNED_SHORT_5_5_5_1: 117 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: 118 | case GL_UNSIGNED_SHORT_8_8_APPLE: 119 | case GL_UNSIGNED_SHORT_8_8_REV_APPLE: 120 | case GL_UNSIGNED_SHORT_15_1_MESA: 121 | case GL_UNSIGNED_SHORT_1_15_REV_MESA: 122 | return 2; 123 | case GL_UNSIGNED_BYTE: 124 | case GL_BYTE: 125 | case GL_UNSIGNED_BYTE_3_3_2: 126 | case GL_UNSIGNED_BYTE_2_3_3_REV: 127 | return 1; 128 | case GL_INT: 129 | case GL_UNSIGNED_INT: 130 | case GL_FLOAT: 131 | case GL_UNSIGNED_INT_8_8_8_8: 132 | case GL_UNSIGNED_INT_8_8_8_8_REV: 133 | case GL_UNSIGNED_INT_10_10_10_2: 134 | case GL_UNSIGNED_INT_2_10_10_10_REV: 135 | case GL_UNSIGNED_INT_24_8_NV: 136 | case GL_UNSIGNED_INT_24_8_MESA: 137 | case GL_UNSIGNED_INT_8_24_REV_MESA: 138 | return 4; 139 | default: 140 | return 0; 141 | } 142 | } 143 | 144 | /* 145 | ** Compute memory required for internal packed array of data of given type 146 | ** and format. 147 | */ 148 | GLint 149 | __glImageSize(GLsizei width, GLsizei height, GLsizei depth, 150 | GLenum format, GLenum type, GLenum target) 151 | { 152 | int bytes_per_row; 153 | int components; 154 | 155 | switch (target) { 156 | case GL_PROXY_TEXTURE_1D: 157 | case GL_PROXY_TEXTURE_2D: 158 | case GL_PROXY_TEXTURE_3D: 159 | case GL_PROXY_TEXTURE_4D_SGIS: 160 | case GL_PROXY_TEXTURE_CUBE_MAP: 161 | case GL_PROXY_TEXTURE_RECTANGLE_ARB: 162 | case GL_PROXY_HISTOGRAM: 163 | case GL_PROXY_COLOR_TABLE: 164 | case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 165 | case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 166 | case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 167 | case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP: 168 | return 0; 169 | } 170 | 171 | if (width < 0 || height < 0 || depth < 0) { 172 | return 0; 173 | } 174 | 175 | /* 176 | ** Zero is returned if either format or type are invalid. 177 | */ 178 | components = __glElementsPerGroup(format, type); 179 | if (type == GL_BITMAP) { 180 | if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) { 181 | bytes_per_row = (width + 7) >> 3; 182 | } 183 | else { 184 | return 0; 185 | } 186 | } 187 | else { 188 | bytes_per_row = __glBytesPerElement(type) * width; 189 | } 190 | 191 | return bytes_per_row * height * depth * components; 192 | } 193 | -------------------------------------------------------------------------------- /gen_api_library.tcl: -------------------------------------------------------------------------------- 1 | package require Tcl 8.5 2 | 3 | set license { 4 | /* 5 | Copyright (c) 2008, 2009 Apple Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person 8 | obtaining a copy of this software and associated documentation files 9 | (the "Software"), to deal in the Software without restriction, 10 | including without limitation the rights to use, copy, modify, merge, 11 | publish, distribute, sublicense, and/or sell copies of the Software, 12 | and to permit persons to whom the Software is furnished to do so, 13 | subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 22 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | 27 | Except as contained in this notice, the name(s) of the above 28 | copyright holders shall not be used in advertising or otherwise to 29 | promote the sale, use or other dealings in this Software without 30 | prior written authorization. 31 | */ 32 | } 33 | 34 | set gl_license { 35 | /* 36 | ** License Applicability. Except to the extent portions of this file are 37 | ** made subject to an alternative license as permitted in the SGI Free 38 | ** Software License B, Version 1.1 (the "License"), the contents of this 39 | ** file are subject only to the provisions of the License. You may not use 40 | ** this file except in compliance with the License. You may obtain a copy 41 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 42 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 43 | ** 44 | ** http://oss.sgi.com/projects/FreeB 45 | ** 46 | ** Note that, as provided in the License, the Software is distributed on an 47 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 48 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 49 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 50 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 51 | ** 52 | ** Original Code. The Original Code is: OpenGL Sample Implementation, 53 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 54 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 55 | ** Copyright in any portions created by third parties is as indicated 56 | ** elsewhere herein. All Rights Reserved. 57 | ** 58 | ** Additional Notice Provisions: This software was created using the 59 | ** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has 60 | ** not been independently verified as being compliant with the OpenGL(R) 61 | ** version 1.2.1 Specification. 62 | */ 63 | } 64 | 65 | set init_code { 66 | static void *glsym(void *handle, const char *name) { 67 | void *sym = dlsym(handle, name); 68 | 69 | if(NULL == sym) { 70 | fprintf(stderr, "Error: symbol not found: '%s'. " 71 | "Error information: %s\n", 72 | name, dlerror()); 73 | abort(); 74 | } 75 | 76 | return sym; 77 | } 78 | 79 | } 80 | 81 | set dlopen_code { 82 | #ifndef LIBGLNAME 83 | #define LIBGLNAME "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" 84 | #endif LIBGLNAME 85 | 86 | (void)dlerror(); /*drain dlerror()*/ 87 | 88 | handle = dlopen(LIBGLNAME, RTLD_LAZY); 89 | 90 | if(NULL == handle) { 91 | fprintf(stderr, "error: unable to dlopen " 92 | LIBGLNAME " :" "%s\n", dlerror()); 93 | abort(); 94 | } 95 | } 96 | 97 | set this_script [info script] 98 | 99 | proc main {argc argv} { 100 | if {2 != $argc} { 101 | puts stderr "syntax is: [set ::this_script] serialized-array-file output.c" 102 | return 1 103 | } 104 | 105 | 106 | set fd [open [lindex $argv 0] r] 107 | array set api [read $fd] 108 | close $fd 109 | 110 | set fd [open [lindex $argv 1] w] 111 | 112 | puts $fd "/* This file was automatically generated by [set ::this_script]. */" 113 | puts $fd $::license 114 | 115 | puts $fd { 116 | #define GL_GLEXT_PROTOTYPES 117 | #include 118 | #include 119 | #include "glxclient.h" 120 | #include "apple_xgl_api.h" 121 | #include "apple_glx_context.h" 122 | } 123 | 124 | puts $fd "struct apple_xgl_api __gl_api;" 125 | 126 | set sorted [lsort -dictionary [array names api]] 127 | 128 | set exclude [list DrawBuffer DrawBuffers DrawBuffersARB] 129 | 130 | #These are special to glXMakeContextCurrent. 131 | #See also: apple_xgl_api_read.c. 132 | lappend exclude ReadPixels CopyPixels CopyColorTable 133 | 134 | #This is excluded to work with surface updates. 135 | lappend exclude Viewport 136 | 137 | foreach f $sorted { 138 | if {$f in $exclude} { 139 | continue 140 | } 141 | 142 | set attr $api($f) 143 | 144 | set pstr "" 145 | 146 | foreach p [dict get $attr parameters] { 147 | append pstr "[lindex $p 0] [lindex $p 1], " 148 | } 149 | 150 | set pstr [string trimright $pstr ", "] 151 | 152 | if {![string length $pstr]} { 153 | set pstr void 154 | } 155 | 156 | set callvars "" 157 | 158 | foreach p [dict get $attr parameters] { 159 | append callvars "[lindex $p end], " 160 | } 161 | 162 | set callvars [string trimright $callvars ", "] 163 | 164 | set return "" 165 | if {"void" ne [dict get $attr return]} { 166 | set return "return " 167 | } 168 | 169 | if {[dict exists $attr noop]} { 170 | if {"void" eq [dict get $attr return]} { 171 | set body "/*noop*/" 172 | } else { 173 | set body "return 0; /*noop*/" 174 | } 175 | } elseif {[dict exists $attr alias_for]} { 176 | set alias [dict get $attr alias_for] 177 | set body "[set return] gl[set alias]([set callvars]);" 178 | } else { 179 | set body "[set return]__gl_api.[set f]([set callvars]);" 180 | } 181 | 182 | puts $fd "GLAPI [dict get $attr return] APIENTRY gl[set f]([set pstr]) \{\n\t$body\n\}" 183 | } 184 | 185 | puts $fd $::init_code 186 | 187 | puts $fd "void apple_xgl_init_direct(void) \{" 188 | puts $fd "\tvoid *handle;" 189 | 190 | puts $fd $::dlopen_code 191 | 192 | foreach f $sorted { 193 | set attr $api($f) 194 | 195 | puts $attr 196 | puts $f 197 | 198 | if {[dict exists $attr alias_for] || [dict exists $attr noop]} { 199 | #Function f is an alias_for another, so we shouldn't try 200 | #to load it. 201 | continue 202 | } 203 | 204 | puts $fd "\t__gl_api.$f = glsym(handle, \"gl$f\");" 205 | } 206 | 207 | puts $fd "\}\n" 208 | close $fd 209 | 210 | return 0 211 | } 212 | exit [main $::argc $::argv] 213 | -------------------------------------------------------------------------------- /apple_glx_pixmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Apple Inc. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation files 6 | (the "Software"), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of the Software, 9 | and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT 19 | HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | Except as contained in this notice, the name(s) of the above 25 | copyright holders shall not be used in advertising or otherwise to 26 | promote the sale, use or other dealings in this Software without 27 | prior written authorization. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "apple_glx.h" 39 | #include "apple_cgl.h" 40 | #include "apple_visual.h" 41 | #include "apple_glx_drawable.h" 42 | #include "appledri.h" 43 | #include "glcontextmodes.h" 44 | 45 | static bool pixmap_make_current(struct apple_glx_context *ac, 46 | struct apple_glx_drawable *d); 47 | 48 | static void pixmap_destroy(Display * dpy, struct apple_glx_drawable *d); 49 | 50 | static struct apple_glx_drawable_callbacks callbacks = { 51 | .type = APPLE_GLX_DRAWABLE_PIXMAP, 52 | .make_current = pixmap_make_current, 53 | .destroy = pixmap_destroy 54 | }; 55 | 56 | static bool 57 | pixmap_make_current(struct apple_glx_context *ac, 58 | struct apple_glx_drawable *d) 59 | { 60 | CGLError cglerr; 61 | struct apple_glx_pixmap *p = &d->types.pixmap; 62 | 63 | assert(APPLE_GLX_DRAWABLE_PIXMAP == d->type); 64 | 65 | cglerr = apple_cgl.set_current_context(p->context_obj); 66 | 67 | if (kCGLNoError != cglerr) { 68 | fprintf(stderr, "set current context: %s\n", 69 | apple_cgl.error_string(cglerr)); 70 | return true; 71 | } 72 | 73 | cglerr = apple_cgl.set_off_screen(p->context_obj, p->width, p->height, 74 | p->pitch, p->buffer); 75 | 76 | if (kCGLNoError != cglerr) { 77 | fprintf(stderr, "set off screen: %s\n", apple_cgl.error_string(cglerr)); 78 | 79 | return true; 80 | } 81 | 82 | if (!ac->made_current) { 83 | glViewport(0, 0, p->width, p->height); 84 | glScissor(0, 0, p->width, p->height); 85 | ac->made_current = true; 86 | } 87 | 88 | return false; 89 | } 90 | 91 | static void 92 | pixmap_destroy(Display * dpy, struct apple_glx_drawable *d) 93 | { 94 | struct apple_glx_pixmap *p = &d->types.pixmap; 95 | 96 | if (p->pixel_format_obj) 97 | (void) apple_cgl.destroy_pixel_format(p->pixel_format_obj); 98 | 99 | if (p->context_obj) 100 | (void) apple_cgl.destroy_context(p->context_obj); 101 | 102 | XAppleDRIDestroyPixmap(dpy, p->xpixmap); 103 | 104 | if (p->buffer) { 105 | if (munmap(p->buffer, p->size)) 106 | perror("munmap"); 107 | 108 | if (-1 == close(p->fd)) 109 | perror("close"); 110 | 111 | if (shm_unlink(p->path)) 112 | perror("shm_unlink"); 113 | } 114 | 115 | apple_glx_diagnostic("destroyed pixmap buffer for: 0x%lx\n", d->drawable); 116 | } 117 | 118 | /* Return true if an error occurred. */ 119 | bool 120 | apple_glx_pixmap_create(Display * dpy, int screen, Pixmap pixmap, 121 | const void *mode) 122 | { 123 | struct apple_glx_drawable *d; 124 | struct apple_glx_pixmap *p; 125 | bool double_buffered; 126 | bool uses_stereo; 127 | CGLError error; 128 | const __GLcontextModes *cmodes = mode; 129 | 130 | if (apple_glx_drawable_create(dpy, screen, pixmap, &d, &callbacks)) 131 | return true; 132 | 133 | /* d is locked and referenced at this point. */ 134 | 135 | p = &d->types.pixmap; 136 | 137 | p->xpixmap = pixmap; 138 | p->buffer = NULL; 139 | 140 | if (!XAppleDRICreatePixmap(dpy, screen, pixmap, 141 | &p->width, &p->height, &p->pitch, &p->bpp, 142 | &p->size, p->path, PATH_MAX)) { 143 | d->unlock(d); 144 | d->destroy(d); 145 | return true; 146 | } 147 | 148 | p->fd = shm_open(p->path, O_RDWR, 0); 149 | 150 | if (p->fd < 0) { 151 | perror("shm_open"); 152 | d->unlock(d); 153 | d->destroy(d); 154 | return true; 155 | } 156 | 157 | p->buffer = mmap(NULL, p->size, PROT_READ | PROT_WRITE, 158 | MAP_FILE | MAP_SHARED, p->fd, 0); 159 | 160 | if (MAP_FAILED == p->buffer) { 161 | perror("mmap"); 162 | d->unlock(d); 163 | d->destroy(d); 164 | return true; 165 | } 166 | 167 | apple_visual_create_pfobj(&p->pixel_format_obj, mode, &double_buffered, 168 | &uses_stereo, /*offscreen */ true); 169 | 170 | error = apple_cgl.create_context(p->pixel_format_obj, NULL, 171 | &p->context_obj); 172 | 173 | if (kCGLNoError != error) { 174 | d->unlock(d); 175 | d->destroy(d); 176 | return true; 177 | } 178 | 179 | p->fbconfigID = cmodes->fbconfigID; 180 | 181 | d->unlock(d); 182 | 183 | apple_glx_diagnostic("created: pixmap buffer for 0x%lx\n", d->drawable); 184 | 185 | return false; 186 | } 187 | 188 | bool 189 | apple_glx_pixmap_query(GLXPixmap pixmap, int attr, unsigned int *value) 190 | { 191 | struct apple_glx_drawable *d; 192 | struct apple_glx_pixmap *p; 193 | bool result = false; 194 | 195 | d = apple_glx_drawable_find_by_type(pixmap, APPLE_GLX_DRAWABLE_PIXMAP, 196 | APPLE_GLX_DRAWABLE_LOCK); 197 | 198 | if (d) { 199 | p = &d->types.pixmap; 200 | 201 | switch (attr) { 202 | case GLX_WIDTH: 203 | *value = p->width; 204 | result = true; 205 | break; 206 | 207 | case GLX_HEIGHT: 208 | *value = p->height; 209 | result = true; 210 | break; 211 | 212 | case GLX_FBCONFIG_ID: 213 | *value = p->fbconfigID; 214 | result = true; 215 | break; 216 | } 217 | 218 | d->unlock(d); 219 | } 220 | 221 | return result; 222 | } 223 | 224 | /* Return true if the type is valid for pixmap. */ 225 | bool 226 | apple_glx_pixmap_destroy(Display * dpy, GLXPixmap pixmap) 227 | { 228 | return !apple_glx_drawable_destroy_by_type(dpy, pixmap, 229 | APPLE_GLX_DRAWABLE_PIXMAP); 230 | } 231 | --------------------------------------------------------------------------------