Commit ad503c41 authored by Jeremy Huddleston Sequoia's avatar Jeremy Huddleston Sequoia
Browse files

apple: Initial import of libGL for OSX from AppleSGLX svn repository.


Signed-off-by: Jeremy Huddleston Sequoia's avatarJeremy Huddleston <jeremyhu@apple.com>
parent f1381880
apple_xgl_api.[hc]
exports.list
stage.[1234]
#GL_EXT_texture_object
alias AreTexturesResidentEXT AreTexturesResident
alias BindTextureEXT BindTexture
alias DeleteTexturesEXT DeleteTextures
alias GenTexturesEXT GenTextures
alias IsTextureEXT IsTexture
alias PrioritizeTexturesEXT PrioritizeTextures
alias TexImage3DEXT TexImage3D
extension ARB_transpose_matrix
extension ARB_vertex_program
extension ARB_vertex_blend
extension ARB_window_pos
extension ARB_shader_objects
extension ARB_vertex_shader
extension ARB_shading_language_100
extension ARB_imaging
extension ARB_point_parameters
extension ARB_texture_env_crossbar
extension ARB_texture_border_clamp
extension ARB_multitexture
extension ARB_texture_env_add
extension ARB_texture_cube_map
extension ARB_texture_env_dot3
extension ARB_multisample
extension ARB_texture_env_combine
extension ARB_texture_compression
extension ARB_texture_mirrored_repeat
extension ARB_shadow
extension ARB_depth_texture
extension ARB_shadow_ambient
extension ARB_fragment_program
extension ARB_fragment_program_shadow
extension ARB_fragment_shader
extension ARB_occlusion_query
extension ARB_point_sprite
extension ARB_texture_non_power_of_two
extension ARB_vertex_buffer_object
extension ARB_pixel_buffer_object
extension ARB_draw_buffers
extension ARB_shader_texture_lod
extension ARB_texture_rectangle
extension ARB_texture_float
extension ARB_half_float_pixel
extension EXT_multi_draw_arrays
extension EXT_clip_volume_hint
extension EXT_rescale_normal
extension EXT_draw_range_elements
extension EXT_fog_coord
extension EXT_gpu_program_parameters
extension EXT_geometry_shader4
#The gl.spec has the wrong arguments for GetTransformFeedbackVaryingEXT
#extension EXT_transform_feedback
extension EXT_compiled_vertex_array
extension EXT_framebuffer_object
extension EXT_framebuffer_blit
extension EXT_framebuffer_multisample
extension EXT_texture_rectangle
extension EXT_texture_env_add
extension EXT_blend_color
extension EXT_blend_minmax
extension EXT_blend_subtract
extension EXT_texture_lod_bias
extension EXT_abgr
extension EXT_bgra
extension EXT_stencil_wrap
extension EXT_texture_filter_anisotropic
extension EXT_separate_specular_color
extension EXT_secondary_color
extension EXT_blend_func_separate
extension EXT_shadow_funcs
extension EXT_stencil_two_side
extension EXT_texture_compression_s3tc
extension EXT_texture_compression_dxt1
extension EXT_texture_sRGB
extension EXT_blend_equation_separate
extension EXT_texture_mirror_clamp
extension EXT_packed_depth_stencil
extension APPLE_client_storage
extension APPLE_specular_vector
extension APPLE_transform_hint
extension APPLE_packed_pixels
#The gl.spec has different argument types for this:
#extension APPLE_fence
extension APPLE_vertex_array_object
extension APPLE_vertex_program_evaluators
extension APPLE_element_array
extension APPLE_flush_render
extension APPLE_aux_depth_stencil
extension APPLE_flush_buffer_range
extension APPLE_ycbcr_422
#The gl.spec has different argument types for this:
#extension APPLE_vertex_array_range
extension APPLE_texture_range
extension APPLE_float_pixels
extension APPLE_pixel_buffer
extension APPLE_object_purgeable
#The OpenGL framework has moved this to the core OpenGL, and eliminated EXT_convolution listing.
#extension EXT_convolution
#Leopard supports these according to nm.
#Applications should use the GL_EXTENSIONS list to determine capabilities.
extension EXT_paletted_texture
extension APPLE_fence
extension NV_vertex_program4
extension EXT_draw_buffers2
extension EXT_gpu_shader4
extension ATI_pn_triangles
extension NV_register_combiners
extension EXT_depth_bounds_test
#These are for compatibility with the old libGL.
noop SGI_color_table
noop EXT_convolution
noop EXT_cull_vertex
noop NV_fence
noop SGIS_detail_texture
noop SGIX_fragment_lighting
noop SGIX_flush_raster
noop EXT_vertex_array
noop SGIX_instruments
noop EXT_histogram
noop NV_vertex_program
noop PGI_misc_hints
noop SGIS_multisample
noop EXT_multisample
promoted MESA_window_pos
promoted ARB_window_pos
promoted EXT_copy_texture
promoted ARB_vertex_program
INSTALL_DIR = /usr/X11
X11_DIR = $(INSTALL_DIR)
CC=gcc
GL_CFLAGS=-Wall -ggdb3 -Os -DPTHREADS -D_REENTRANT -DGLX_USE_APPLEGL -DGLX_ALIAS_UNSUPPORTED $(RC_CFLAGS) $(CFLAGS)
GL_LDFLAGS=-L$(INSTALL_DIR)/lib -L$(X11_DIR)/lib $(LDFLAGS) -Wl,-single_module
TCLSH=tclsh8.5
MKDIR=mkdir
INSTALL=install
LN=ln
RM=rm
INCLUDE=-I. -Iinclude -Iinclude/internal -I.. -I../../../include -I$(INSTALL_DIR)/include -I$(X11_DIR)/include
COMPILE=$(CC) $(INCLUDE) $(GL_CFLAGS) -c
#The directory with the final binaries.
BUILD_DIR=builds
all: $(BUILD_DIR)/libGL.1.2.dylib
OBJECTS=glxext.o glxcmds.o glx_pbuffer.o glx_query.o glxcurrent.o glxextensions.o \
appledri.o apple_glx_context.o apple_glx.o pixel.o \
compsize.o apple_visual.o apple_cgl.o glxreply.o glcontextmodes.o \
apple_xgl_api.o apple_glx_drawable.o xfont.o apple_glx_pbuffer.o \
apple_glx_pixmap.o apple_xgl_api_read.o glx_empty.o glx_error.o \
apple_xgl_api_viewport.o apple_glx_surface.o apple_xgl_api_stereo.o
$(BUILD_DIR)/libGL.1.2.dylib: $(OBJECTS)
-if ! test -d $(BUILD_DIR); then $(MKDIR) $(BUILD_DIR); fi
$(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)
.c.o:
$(COMPILE) $<
apple_glx_drawable.o: apple_glx_drawable.h apple_glx_drawable.c include/GL/gl.h
apple_xgl_api.o: apple_xgl_api.h apple_xgl_api.c apple_xgl_api_stereo.c include/GL/gl.h
apple_xgl_api_read.o: apple_xgl_api_read.h apple_xgl_api_read.c apple_xgl_api.h include/GL/gl.h
apple_xgl_api_viewport.o: apple_xgl_api_viewport.h apple_xgl_api_viewport.c apple_xgl_api.h include/GL/gl.h
apple_xgl_api_stereo.o: apple_xgl_api_stereo.h apple_xgl_api_stereo.c apple_xgl_api.h include/GL/gl.h
glcontextmodes.o: glcontextmodes.c include/GL/gl.h
glxext.o: glxext.c include/GL/gl.h
glxreply.o: glxreply.c include/GL/gl.h
glxcmds.o: glxcmds.c apple_glx_context.h include/GL/gl.h
glx_pbuffer.o: glx_pbuffer.c include/GL/gl.h
glx_error.o: glx_error.c include/GL/gl.h
glx_query.o: glx_query.c include/GL/gl.h
glxcurrent.o: glxcurrent.c include/GL/gl.h
glxextensions.o: glxextensions.c include/GL/gl.h
glxhash.o: glxhash.h glxhash.c include/GL/gl.h
appledri.o: appledri.h appledristr.h appledri.c include/GL/gl.h
apple_glx_context.o: apple_glx_context.c apple_glx_context.h apple_glx_context.h include/GL/gl.h
apple_glx.o: apple_glx.h apple_glx.c apple_xgl_api.h include/GL/gl.h
apple_visual.o: apple_visual.h apple_visual.c include/GL/gl.h
apple_cgl.o: apple_cgl.h apple_cgl.c include/GL/gl.h
apple_glx_pbuffer.o: apple_glx_drawable.h apple_glx_pbuffer.c include/GL/gl.h
apple_glx_pixmap.o: apple_glx_drawable.h apple_glx_pixmap.c appledri.h include/GL/gl.h
apple_glx_surface.o: apple_glx_drawable.h apple_glx_surface.c appledri.h include/GL/gl.h
xfont.o: xfont.c include/GL/gl.h
compsize.o: compsize.c include/GL/gl.h
renderpix.o: renderpix.c include/GL/gl.h
singlepix.o: singlepix.c include/GL/gl.h
pixel.o: pixel.c include/GL/gl.h
glx_empty.o: glx_empty.c include/GL/gl.h
apple_xgl_api.c: apple_xgl_api.h
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
$(TCLSH) gen_code.tcl
include/GL/gl.h: include/GL/gl.h.template gen_gl_h.sh
./gen_gl_h.sh include/GL/gl.h.template $@
install_headers: include/GL/gl.h
$(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/include/GL
$(INSTALL) -m 644 include/GL/gl.h include/GL/glext.h include/GL/glx.h include/GL/glxext.h $(DESTDIR)$(INSTALL_DIR)/include/GL
install_libraries: $(BUILD_DIR)/libGL.1.2.dylib
$(INSTALL) -d $(DESTDIR)$(INSTALL_DIR)/lib
$(INSTALL) -m 755 $(BUILD_DIR)/libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib
$(RM) -f $(DESTDIR)$(INSTALL_DIR)/lib/libGL.dylib
$(LN) -s libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib/libGL.dylib
$(RM) -f $(DESTDIR)$(INSTALL_DIR)/lib/libGL.1.dylib
$(LN) -s libGL.1.2.dylib $(DESTDIR)$(INSTALL_DIR)/lib/libGL.1.dylib
install: install_headers install_libraries
clean:
rm -rf $(BUILD_DIR)
rm -f *.o *.a
rm -f *.c~ *.h~
rm -f apple_xgl_api.h apple_xgl_api.c
rm -f *.dylib
rm -f include/GL/gl.h
%.c : ../%.c
ln -s $<
A lot of the code is automatically generated.
The following are generated based on specs/gl.spec and specs/enum.spec (from OpenGL.org):
apple_xgl_api.h
apple_xgl_api.c
exports.list
include/GL/gl.h
include/GL/glext.h (includes the OpenGL framework glext.h)
The gen_code.tcl script is what executes the various gen_*.tcl scripts to produce those.
You will need Tcl 8.5 for the gen_code.tcl script.
The tests/ directory contains some tests that are built in testbuilds.
The tests built in testbuilds don't require installation of the library.
The design of most of this code is such that we extend the GLX structures
with a void * named apple.
The GLX functions that need to do Apple-specific things are passed
&s->apple in order to initialize the private structures.
Thus when updating, just run a diff against glxext.c or glxcmds.c, and
manually merge from there as needed.
AppleSGLX Release Notes
o OpenGL Support
AppleSGLX supports the same version of OpenGL as Leopard (OpenGL 2.1).
Many extensions from the OpenGL framework are now builtin.
This adds support for GLSL, and a variety of other features.
o Thread Support
Thread support has been improved since the libGL in XQuartz 2.3.2.1.
o GLX 1.4 Support
The GLX 1.3 and 1.4 functions should all work with a few exceptions
as outlined in this document.
o glXMakeContextCurrent (a GLX 1.3 feature)
glXMakeContextCurrent should work with the readable drawable. The
OpenGL functions: glReadPixels, glCopyPixels, and glCopyColorTable,
should use the readable drawable if it's different than the rendering
drawable.
o glXGetProcAddress (a GLX 1.4 feature and ARB extension)
glXGetProcAddress should work and allow getting the address of any
extension functions you may need from the X11 libGL, or OpenGL framework
libGL. Previous versions of the X11 libGL didn't allow getting the newer
OpenGL framework addresses.
o GLXPixmaps
New support for GLXPixmaps works well with mixed X11 and OpenGL drawing
operations. You can create them using glXCreateGLXPixmap or
glXCreatePixmap.
o GLXPbuffers
Support for GLXPbuffers has been added. These are drawables that are
not possible to render to with X11, which is allowed by the spec.
A GLXPbuffer will never generate a clobber event, however
glXSelectEvent and glXGetSelectedEvent should operate normally.
Clobber events are not generated due to low-level architectural
differences. The contents of your pbuffers will not be clobbered.
o Shared Contexts
Due to basic low-level architectural differences the usage of shared
contexts requires a similar visual or GLXFBConfig be used in the
creation of a shared context. It's best if you specify the same
visual. This is due to a CGL design difference, and not something
that is easily worked around. UPDATE: some changes made seem to
help resolve this issue in many cases, so you may be able to use a
shared context without this restriction.
o Indirect
The X server supports indirect fairly well, so OpenGL applications
can be run remotely and displayed by XQuartz. This means you can run
applications from a remote host on an XQuartz X server.
AppleSGLX does not support indirect rendering. Any indirect context
created will appear to glXIsDirect as an indirect context, but it
does not actually support indirect rendering to a remote X server.
AppleSGLX supports GLXPixmaps and GLXPbuffers with direct and indirect
contexts, though they are all direct contexts by definition (see above).
Test shared contexts!
Go over every glxcmd in glxcmds.c and make sure we have them working.
Verify the XError behavior of GLXPixmap support functions.
Test GLXPixmap support with various pixmap depths.
Test GLXPixmap support with invalid pixmaps (to stress the protocol code).
-- Feb 10, 2009
Test glXCopyContext.
-- Dec 12 2008
TEST glXCopyContext needs some work and additional code in apple_glx.c.
----
Make sure we report the proper list of GLX extensions available. Apple direct may not support some
that Mesa does, and vice-versa.
Modify create_destroy_context and create a new test called create_destroy_context_thread_race.
Where 2 threads are doing the same sort of path of create and destroy. The locking should protect
us there, but we need to verify nothing goes wrong.
/*
Copyright (c) 2008 Apple Inc.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name(s) of the above
copyright holders shall not be used in advertising or otherwise to
promote the sale, use or other dealings in this Software without
prior written authorization.
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "apple_cgl.h"
#include "apple_glx.h"
#ifndef OPENGL_FRAMEWORK_PATH
#define OPENGL_FRAMEWORK_PATH "/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL"
#endif
static void *dl_handle = NULL;
struct apple_cgl_api apple_cgl;
static bool initialized = false;
static void *
sym(void *h, const char *name)
{
void *s;
s = dlsym(h, name);
if (NULL == s) {
fprintf(stderr, "error: %s\n", dlerror());
abort();
}
return s;
}
void
apple_cgl_init(void)
{
void *h;
GLint major = 0, minor = 0;
const char *opengl_framework_path;
if (initialized)
return;
opengl_framework_path = getenv("OPENGL_FRAMEWORK_PATH");
if (!opengl_framework_path) {
opengl_framework_path = OPENGL_FRAMEWORK_PATH;
}
(void) dlerror(); /*drain dlerror */
h = dlopen(opengl_framework_path, RTLD_NOW);
if (NULL == h) {
fprintf(stderr, "error: unable to dlopen %s : %s\n",
opengl_framework_path, dlerror());
abort();
}
dl_handle = h;
apple_cgl.get_version = sym(h, "CGLGetVersion");
apple_cgl.get_version(&major, &minor);
apple_glx_diagnostic("CGL major %d minor %d\n", major, minor);
if (1 != major) {
fprintf(stderr, "WARNING: the CGL major version has changed!\n"
"libGL may be incompatible!\n");
}
apple_cgl.choose_pixel_format = sym(h, "CGLChoosePixelFormat");
apple_cgl.destroy_pixel_format = sym(h, "CGLDestroyPixelFormat");
apple_cgl.clear_drawable = sym(h, "CGLClearDrawable");
apple_cgl.flush_drawable = sym(h, "CGLFlushDrawable");
apple_cgl.create_context = sym(h, "CGLCreateContext");
apple_cgl.destroy_context = sym(h, "CGLDestroyContext");
apple_cgl.set_current_context = sym(h, "CGLSetCurrentContext");
apple_cgl.get_current_context = sym(h, "CGLGetCurrentContext");
apple_cgl.error_string = sym(h, "CGLErrorString");
apple_cgl.set_off_screen = sym(h, "CGLSetOffScreen");
apple_cgl.copy_context = sym(h, "CGLCopyContext");
apple_cgl.create_pbuffer = sym(h, "CGLCreatePBuffer");
apple_cgl.destroy_pbuffer = sym(h, "CGLDestroyPBuffer");
apple_cgl.set_pbuffer = sym(h, "CGLSetPBuffer");
initialized = true;
}
void *
apple_cgl_get_dl_handle(void)
{
return dl_handle;
}
/*
Copyright (c) 2008, 2009 Apple Inc.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name(s) of the above
copyright holders shall not be used in advertising or otherwise to
promote the sale, use or other dealings in this Software without
prior written authorization.
*/
#ifndef APPLE_CGL_H
#define APPLE_CGL_H
#include <stdio.h>
#include <OpenGL/CGLCurrent.h>
#include <OpenGL/CGLTypes.h>
#include <OpenGL/OpenGL.h>
/* For GLint and GLsizei on Tiger */
#include <OpenGL/gl.h>
struct apple_cgl_api
{
void (*get_version) (GLint * majorvers, GLint * minorvers);
CGLError(*choose_pixel_format) (const CGLPixelFormatAttribute * attribs,
CGLPixelFormatObj * pix, GLint * npix);
CGLError(*destroy_pixel_format) (CGLPixelFormatObj pix);
CGLError(*clear_drawable) (CGLContextObj ctx);
CGLError(*flush_drawable) (CGLContextObj ctx);
CGLError(*create_context) (CGLPixelFormatObj pix, CGLContextObj share,
CGLContextObj * ctx);
CGLError(*destroy_context) (CGLContextObj pix);
CGLError(*set_current_context) (CGLContextObj ctx);
CGLContextObj(*get_current_context) (void);
const char *(*error_string) (CGLError error);
CGLError(*set_off_screen) (CGLContextObj ctx,
GLsizei width, GLsizei height, GLint rowbytes,
void *baseaddr);
CGLError(*copy_context) (CGLContextObj src, CGLContextObj dst,
GLbitfield mask);
CGLError(*create_pbuffer) (GLsizei width,
GLsizei height,
GLenum target,
GLenum internalFormat,
GLint max_level, CGLPBufferObj * pbuffer);
CGLError(*destroy_pbuffer) (CGLPBufferObj pbuffer);
CGLError(*set_pbuffer) (CGLContextObj ctx,
CGLPBufferObj pbuffer,
GLenum face, GLint level, GLint screen);
};
extern struct apple_cgl_api apple_cgl;
extern void apple_cgl_init(void);
extern void *apple_cgl_get_dl_handle(void);
#endif
_glAccum
_glAlphaFunc
_glAreTexturesResident
_glArrayElement
_glBegin
_glBindTexture
_glBitmap
_glBlendColor
_glBlendEquation
_glBlendEquationSeparate
_glBlendFunc
_glCallList
_glCallLists
_glClear
_glClearAccum
_glClearColor
_glClearDepth
_glClearIndex
_glClearStencil
_glClipPlane
_glColor3b
_glColor3bv
_glColor3d
_glColor3dv
_glColor3f
_glColor3fv
_glColor3i
_glColor3iv
_glColor3s
_glColor3sv
_glColor3ub
_glColor3ubv
_glColor3ui
_glColor3uiv
_glColor3us
_glColor3usv
_glColor4b
_glColor4bv
_glColor4d
_glColor4dv
_glColor4f
_glColor4fv
_glColor4i