diff options
author | David Reveman <davidr@novell.com> | 2005-11-09 12:32:24 +0000 |
---|---|---|
committer | David Reveman <davidr@novell.com> | 2005-11-09 12:32:24 +0000 |
commit | 788dd168a74afab77069b3a2aef0a8abca6843e9 (patch) | |
tree | 68f7bbe3f7fb945cd1176afa8d9561fe56f2a750 | |
parent | 4eb06d14799ec475789756feedb09feefb476adb (diff) |
Add WGL backend. Thanks to Vladimir Vukicevic and Tor Lillqvist.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.in | 51 | ||||
-rw-r--r-- | src/Makefile.am | 15 | ||||
-rw-r--r-- | src/glitz.def | 0 | ||||
-rw-r--r-- | src/glitz.h | 10 | ||||
-rw-r--r-- | src/glitz_gl.h | 184 | ||||
-rw-r--r-- | src/glitzint.h | 37 | ||||
-rw-r--r-- | src/wgl/.cvsignore | 7 | ||||
-rw-r--r-- | src/wgl/Makefile.am | 49 | ||||
-rw-r--r-- | src/wgl/glitz-wgl.def | 0 | ||||
-rw-r--r-- | src/wgl/glitz-wgl.h | 89 | ||||
-rw-r--r-- | src/wgl/glitz-wgl.pc.in | 11 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_context.c | 328 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_drawable.c | 227 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_extension.c | 83 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_format.c | 358 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_info.c | 513 | ||||
-rw-r--r-- | src/wgl/glitz_wgl_pbuffer.c | 71 | ||||
-rw-r--r-- | src/wgl/glitz_wglext.h | 151 | ||||
-rw-r--r-- | src/wgl/glitz_wglint.h | 196 |
21 files changed, 2280 insertions, 104 deletions
@@ -1,5 +1,7 @@ 2005-11-09 David Reveman <davidr@novell.com> + * Add WGL backend. Thanks to Vladimir Vukicevic and Tor Lillqvist. + * src/agl/glitz_aglint.h: AGL backend updates (Vladimir Vukicevic) 2005-09-02 David Reveman <davidr@novell.com> diff --git a/Makefile.am b/Makefile.am index 5c7d167..7af8949 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,3 @@ SUBDIRS = . src -EXTRA_DIST = COPYING
\ No newline at end of file +EXTRA_DIST = COPYING diff --git a/configure.in b/configure.in index fd3f455..1fbf0de 100644 --- a/configure.in +++ b/configure.in @@ -101,6 +101,24 @@ AC_SUBST(GLITZ_INC) dnl =========================================================================== +AC_MSG_CHECKING([for Win32]) +case "$host" in + *-*-mingw*) + native_win32=yes + ;; + *) + native_win32=no + LIBM="-lm" + ;; +esac +AC_MSG_RESULT([$native_win32]) + +AM_CONDITIONAL(OS_WIN32, [test $native_win32 = yes]) + +AC_SUBST(LIBM) + +dnl =========================================================================== + AC_ARG_ENABLE(glx, AC_HELP_STRING([--disable-glx], [Disable glitz's GLX backend]), [use_glx=$enableval], [use_glx=yes]) @@ -235,16 +253,48 @@ AC_SUBST(EGL_LIBS) dnl =========================================================================== +AC_ARG_ENABLE(wgl, + AC_HELP_STRING([--disable-wgl], [Disable glitz's WGL backend]), + [use_wgl=$enableval], [use_wgl=yes]) + +if test "x$use_wgl" = "xyes"; then + AC_MSG_CHECKING([for WGL]) + WGL_LIBS="-lopengl32 -lgdi32" + WGL_CFLAGS="" + + save_libs="$LIBS" + LIBS="$WGL_LIBS" + AC_TRY_LINK([#include <windows.h>], [int main() { wglCreateContext(0); }], + [use_wgl=yes], [use_wgl=no]) + LIBS="$save_libs" + AC_MSG_RESULT([$use_wgl]) +fi + +if test "x$use_wgl" = "xyes"; then + AM_CONDITIONAL(GLITZ_BUILD_WGL_BACKEND, true) +else + AM_CONDITIONAL(GLITZ_BUILD_WGL_BACKEND, false) + WGL_LIBS="" + WGL_CFLAGS="" +fi + +AC_SUBST(WGL_CFLAGS) +AC_SUBST(WGL_LIBS) + +dnl =========================================================================== + AC_OUTPUT([ Makefile src/Makefile src/glx/Makefile src/agl/Makefile src/egl/Makefile +src/wgl/Makefile src/glitz.pc src/glx/glitz-glx.pc src/agl/glitz-agl.pc src/egl/glitz-egl.pc +src/wgl/glitz-wgl.pc ]) dnl =========================================================================== @@ -254,4 +304,5 @@ echo "glitz will be compiled with the following backends:" echo " GLX: $use_glx" echo " AGL: $use_agl" echo " EGL: $use_egl" +echo " WGL: $use_wgl" echo "" diff --git a/src/Makefile.am b/src/Makefile.am index 43e1470..4519bac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,12 @@ -SUBDIRS = . glx agl egl +SUBDIRS = . glx agl egl wgl + +if OS_WIN32 +glitz_def = $(srcdir)/glitz.def +libglitz_export_symbols = -export-symbols $(glitz_def) +else +glitz_def = +libglitz_export_symbols = +endif lib_LTLIBRARIES = libglitz.la include_HEADERS = glitz.h @@ -28,12 +36,13 @@ libglitz_la_SOURCES = \ glitz_gl.h \ glitzint.h -libglitz_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined -libglitz_la_LIBADD = -lm +libglitz_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined $(libglitz_export_symbols) +libglitz_la_LIBADD = $(LIBM) pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = glitz.pc EXTRA_DIST = \ + glitz.def \ glitz.pc.in \ glitz.man diff --git a/src/glitz.def b/src/glitz.def new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/glitz.def diff --git a/src/glitz.h b/src/glitz.h index f07d5d1..c359bdc 100644 --- a/src/glitz.h +++ b/src/glitz.h @@ -26,16 +26,6 @@ #ifndef GLITZ_H_INCLUDED #define GLITZ_H_INCLUDED -#if defined(__SVR4) && defined(__sun) -# include <sys/int_types.h> -#else -# if defined(__OpenBSD__) -# include <inttypes.h> -# else -# include <stdint.h> -# endif -#endif - #define GLITZ_MAJOR 0 #define GLITZ_MINOR 5 #define GLITZ_REVISION 0 diff --git a/src/glitz_gl.h b/src/glitz_gl.h index 98f587b..7b76a31 100644 --- a/src/glitz_gl.h +++ b/src/glitz_gl.h @@ -30,6 +30,12 @@ #include <stddef.h> +#ifdef _WIN32 +#define GLITZ_GL_API_ATTRIBUTE __stdcall +#else +#define GLITZ_GL_API_ATTRIBUTE +#endif + typedef unsigned int glitz_gl_enum_t; typedef unsigned char glitz_gl_boolean_t; typedef void glitz_gl_void_t; @@ -334,228 +340,228 @@ typedef ptrdiff_t glitz_gl_sizeiptr_t; #define GLITZ_GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 #define GLITZ_GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 -typedef glitz_gl_void_t (* glitz_gl_enable_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_enable_t) (glitz_gl_enum_t cap); -typedef glitz_gl_void_t (* glitz_gl_disable_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_disable_t) (glitz_gl_enum_t cap); -typedef glitz_gl_enum_t (* glitz_gl_get_error_t) +typedef glitz_gl_enum_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_error_t) (glitz_gl_void_t); -typedef glitz_gl_ubyte_t *(* glitz_gl_get_string_t) +typedef glitz_gl_ubyte_t *(GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_string_t) (glitz_gl_enum_t); -typedef glitz_gl_void_t (* glitz_gl_enable_client_state_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_enable_client_state_t) (glitz_gl_enum_t cap); -typedef glitz_gl_void_t (* glitz_gl_disable_client_state_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_disable_client_state_t) (glitz_gl_enum_t cap); -typedef glitz_gl_void_t (* glitz_gl_vertex_pointer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_vertex_pointer_t) (glitz_gl_int_t size, glitz_gl_enum_t type, glitz_gl_sizei_t stride, const glitz_gl_void_t *ptr); -typedef glitz_gl_void_t (* glitz_gl_tex_coord_pointer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_coord_pointer_t) (glitz_gl_int_t size, glitz_gl_enum_t type, glitz_gl_sizei_t stride, const glitz_gl_void_t *ptr); -typedef glitz_gl_void_t (* glitz_gl_draw_arrays_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_draw_arrays_t) (glitz_gl_enum_t mode, glitz_gl_int_t first, glitz_gl_sizei_t count); -typedef glitz_gl_void_t (* glitz_gl_multi_draw_arrays_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_multi_draw_arrays_t) (glitz_gl_enum_t mode, glitz_gl_int_t *first, glitz_gl_sizei_t *count, glitz_gl_sizei_t primcount); -typedef glitz_gl_void_t (* glitz_gl_tex_env_f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_env_f_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, glitz_gl_float_t param); -typedef glitz_gl_void_t (* glitz_gl_tex_env_fv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_env_fv_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, const glitz_gl_float_t *params); -typedef glitz_gl_void_t (* glitz_gl_tex_gen_i_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_gen_i_t) (glitz_gl_enum_t coord, glitz_gl_enum_t pname, glitz_gl_int_t param); -typedef glitz_gl_void_t (* glitz_gl_tex_gen_fv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_gen_fv_t) (glitz_gl_enum_t coord, glitz_gl_enum_t pname, const glitz_gl_float_t *params); -typedef glitz_gl_void_t (* glitz_gl_scissor_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_scissor_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height); -typedef glitz_gl_void_t (* glitz_gl_color_4us_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_color_4us_t) (glitz_gl_ushort_t red, glitz_gl_ushort_t green, glitz_gl_ushort_t blue, glitz_gl_ushort_t alpha); -typedef glitz_gl_void_t (* glitz_gl_color_4f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_color_4f_t) (glitz_gl_float_t red, glitz_gl_float_t green, glitz_gl_float_t blue, glitz_gl_float_t alpha); -typedef glitz_gl_void_t (* glitz_gl_blend_func_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_blend_func_t) (glitz_gl_enum_t sfactor, glitz_gl_enum_t dfactor); -typedef glitz_gl_void_t (* glitz_gl_blend_color_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_blend_color_t) (glitz_gl_clampf_t red, glitz_gl_clampf_t green, glitz_gl_clampf_t blue, glitz_gl_clampf_t alpha); -typedef glitz_gl_void_t (* glitz_gl_clear_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_clear_t) (glitz_gl_bitfield_t mask); -typedef glitz_gl_void_t (* glitz_gl_clear_color_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_clear_color_t) (glitz_gl_clampf_t red, glitz_gl_clampf_t green, glitz_gl_clampf_t blue, glitz_gl_clampf_t alpha); -typedef glitz_gl_void_t (* glitz_gl_clear_stencil_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_clear_stencil_t) (glitz_gl_int_t s); -typedef glitz_gl_void_t (* glitz_gl_stencil_func_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_stencil_func_t) (glitz_gl_enum_t func, glitz_gl_int_t ref, glitz_gl_uint_t mask); -typedef glitz_gl_void_t (* glitz_gl_stencil_op_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_stencil_op_t) (glitz_gl_enum_t fail, glitz_gl_enum_t zfail, glitz_gl_enum_t zpass); -typedef glitz_gl_void_t (* glitz_gl_push_attrib_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_push_attrib_t) (glitz_gl_bitfield_t mask); -typedef glitz_gl_void_t (* glitz_gl_pop_attrib_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_pop_attrib_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_matrix_mode_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_matrix_mode_t) (glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_push_matrix_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_push_matrix_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_pop_matrix_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_pop_matrix_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_load_identity_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_load_identity_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_load_matrix_f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_load_matrix_f_t) (const glitz_gl_float_t *m); -typedef glitz_gl_void_t (* glitz_gl_depth_range_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_depth_range_t) (glitz_gl_clampd_t near_val, glitz_gl_clampd_t far_val); -typedef glitz_gl_void_t (* glitz_gl_viewport_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_viewport_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height); -typedef glitz_gl_void_t (* glitz_gl_raster_pos_2f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_raster_pos_2f_t) (glitz_gl_float_t x, glitz_gl_float_t y); -typedef glitz_gl_void_t (* glitz_gl_bitmap_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bitmap_t) (glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_float_t xorig, glitz_gl_float_t yorig, glitz_gl_float_t xmove, glitz_gl_float_t ymove, const glitz_gl_ubyte_t *bitmap); -typedef glitz_gl_void_t (* glitz_gl_read_buffer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_read_buffer_t) (glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_draw_buffer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_draw_buffer_t) (glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_copy_pixels_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_copy_pixels_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_enum_t type); -typedef glitz_gl_void_t (* glitz_gl_flush_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_flush_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_finish_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_finish_t) (glitz_gl_void_t); -typedef glitz_gl_void_t (* glitz_gl_pixel_store_i_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_pixel_store_i_t) (glitz_gl_enum_t pname, glitz_gl_int_t param); -typedef glitz_gl_void_t (* glitz_gl_ortho_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_ortho_t) (glitz_gl_double_t left, glitz_gl_double_t right, glitz_gl_double_t bottom, glitz_gl_double_t top, glitz_gl_double_t near_val, glitz_gl_double_t far_val); -typedef glitz_gl_void_t (* glitz_gl_scale_f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_scale_f_t) (glitz_gl_float_t x, glitz_gl_float_t y, glitz_gl_float_t z); -typedef glitz_gl_void_t (* glitz_gl_translate_f_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_translate_f_t) (glitz_gl_float_t x, glitz_gl_float_t y, glitz_gl_float_t z); -typedef glitz_gl_void_t (* glitz_gl_hint_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_hint_t) (glitz_gl_enum_t target, glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_depth_mask_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_depth_mask_t) (glitz_gl_boolean_t flag); -typedef glitz_gl_void_t (* glitz_gl_polygon_mode_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_polygon_mode_t) (glitz_gl_enum_t face, glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_shade_model_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_shade_model_t) (glitz_gl_enum_t mode); -typedef glitz_gl_void_t (* glitz_gl_color_mask_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_color_mask_t) (glitz_gl_boolean_t red, glitz_gl_boolean_t green, glitz_gl_boolean_t blue, glitz_gl_boolean_t alpha); -typedef glitz_gl_void_t (* glitz_gl_read_pixels_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_read_pixels_t) (glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_enum_t format, glitz_gl_enum_t type, glitz_gl_void_t *pixels); -typedef glitz_gl_void_t (* glitz_gl_get_tex_image_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_tex_image_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_enum_t format, glitz_gl_enum_t type, glitz_gl_void_t *pixels); -typedef glitz_gl_void_t (* glitz_gl_tex_sub_image_2d_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_sub_image_2d_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_int_t xoffset, glitz_gl_int_t yoffset, glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_enum_t format, glitz_gl_enum_t type, const glitz_gl_void_t *pixels); -typedef glitz_gl_void_t (* glitz_gl_gen_textures_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_textures_t) (glitz_gl_sizei_t n, glitz_gl_uint_t *textures); -typedef glitz_gl_void_t (* glitz_gl_delete_textures_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_delete_textures_t) (glitz_gl_sizei_t n, const glitz_gl_uint_t *textures); -typedef glitz_gl_void_t (* glitz_gl_bind_texture_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bind_texture_t) (glitz_gl_enum_t target, glitz_gl_uint_t texture); -typedef glitz_gl_void_t (* glitz_gl_tex_image_2d_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_image_2d_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_int_t internal_format, glitz_gl_sizei_t width, glitz_gl_sizei_t height, glitz_gl_int_t border, glitz_gl_enum_t format, glitz_gl_enum_t type, const glitz_gl_void_t *pixels); -typedef glitz_gl_void_t (* glitz_gl_tex_parameter_i_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_parameter_i_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, glitz_gl_int_t param); -typedef glitz_gl_void_t (* glitz_gl_tex_parameter_fv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_tex_parameter_fv_t) (glitz_gl_enum_t target, glitz_gl_enum_t pname, const glitz_gl_float_t *parama); -typedef glitz_gl_void_t (* glitz_gl_get_tex_level_parameter_iv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_tex_level_parameter_iv_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_enum_t pname, glitz_gl_int_t *param); -typedef glitz_gl_void_t (* glitz_gl_copy_tex_sub_image_2d_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_copy_tex_sub_image_2d_t) (glitz_gl_enum_t target, glitz_gl_int_t level, glitz_gl_int_t xoffset, glitz_gl_int_t yoffset, glitz_gl_int_t x, glitz_gl_int_t y, glitz_gl_sizei_t width, glitz_gl_sizei_t height); -typedef glitz_gl_void_t (* glitz_gl_get_integer_v_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_integer_v_t) (glitz_gl_enum_t pname, glitz_gl_int_t *params); -typedef glitz_gl_void_t (* glitz_gl_get_pointer_v_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_pointer_v_t) (glitz_gl_enum_t pname, glitz_gl_void_t **params); -typedef glitz_gl_void_t (* glitz_gl_active_texture_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_active_texture_t) (glitz_gl_enum_t); -typedef glitz_gl_void_t (* glitz_gl_client_active_texture_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_client_active_texture_t) (glitz_gl_enum_t); -typedef glitz_gl_void_t (* glitz_gl_gen_programs_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_programs_t) (glitz_gl_sizei_t, glitz_gl_uint_t *); -typedef glitz_gl_void_t (* glitz_gl_delete_programs_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_delete_programs_t) (glitz_gl_sizei_t, const glitz_gl_uint_t *); -typedef glitz_gl_void_t (* glitz_gl_program_string_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_program_string_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_sizei_t, const glitz_gl_void_t *); -typedef glitz_gl_void_t (* glitz_gl_bind_program_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bind_program_t) (glitz_gl_enum_t, glitz_gl_uint_t); -typedef glitz_gl_void_t (* glitz_gl_program_local_param_4fv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_program_local_param_4fv_t) (glitz_gl_enum_t, glitz_gl_uint_t, const glitz_gl_float_t *); -typedef glitz_gl_void_t (* glitz_gl_get_program_iv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_program_iv_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_int_t *); -typedef glitz_gl_void_t (* glitz_gl_gen_buffers_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_buffers_t) (glitz_gl_sizei_t, glitz_gl_uint_t *buffers); -typedef glitz_gl_void_t (* glitz_gl_delete_buffers_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_delete_buffers_t) (glitz_gl_sizei_t, const glitz_gl_uint_t *buffers); -typedef glitz_gl_void_t (* glitz_gl_bind_buffer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bind_buffer_t) (glitz_gl_enum_t, glitz_gl_uint_t buffer); -typedef glitz_gl_void_t (* glitz_gl_buffer_data_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_buffer_data_t) (glitz_gl_enum_t, glitz_gl_sizeiptr_t, const glitz_gl_void_t *, glitz_gl_enum_t); -typedef glitz_gl_void_t *(* glitz_gl_buffer_sub_data_t) +typedef glitz_gl_void_t *(GLITZ_GL_API_ATTRIBUTE * glitz_gl_buffer_sub_data_t) (glitz_gl_enum_t, glitz_gl_intptr_t, glitz_gl_sizeiptr_t, const glitz_gl_void_t *); -typedef glitz_gl_void_t *(* glitz_gl_get_buffer_sub_data_t) +typedef glitz_gl_void_t *(GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_buffer_sub_data_t) (glitz_gl_enum_t, glitz_gl_intptr_t, glitz_gl_sizeiptr_t, glitz_gl_void_t *); -typedef glitz_gl_void_t *(* glitz_gl_map_buffer_t) +typedef glitz_gl_void_t *(GLITZ_GL_API_ATTRIBUTE * glitz_gl_map_buffer_t) (glitz_gl_enum_t, glitz_gl_enum_t); -typedef glitz_gl_boolean_t (* glitz_gl_unmap_buffer_t) +typedef glitz_gl_boolean_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_unmap_buffer_t) (glitz_gl_enum_t); -typedef void (* glitz_gl_gen_framebuffers_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_framebuffers_t) (glitz_gl_sizei_t, glitz_gl_uint_t *); -typedef void (* glitz_gl_delete_framebuffers_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_delete_framebuffers_t) (glitz_gl_sizei_t, const glitz_gl_uint_t *); -typedef glitz_gl_void_t (* glitz_gl_bind_framebuffer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bind_framebuffer_t) (glitz_gl_enum_t, glitz_gl_uint_t); -typedef void (* glitz_gl_framebuffer_renderbuffer_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_framebuffer_renderbuffer_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_uint_t); -typedef void (* glitz_gl_framebuffer_texture_2d_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_framebuffer_texture_2d_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_uint_t, glitz_gl_int_t); -typedef glitz_gl_enum_t (* glitz_gl_check_framebuffer_status_t) +typedef glitz_gl_enum_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_check_framebuffer_status_t) (glitz_gl_enum_t); -typedef void (* glitz_gl_gen_renderbuffers_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_renderbuffers_t) (glitz_gl_sizei_t, glitz_gl_uint_t *); -typedef void (* glitz_gl_delete_renderbuffers_t) +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_delete_renderbuffers_t) (glitz_gl_sizei_t, const glitz_gl_uint_t *); -typedef glitz_gl_void_t (* glitz_gl_bind_renderbuffer_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_bind_renderbuffer_t) (glitz_gl_enum_t, glitz_gl_uint_t); -typedef glitz_gl_void_t (* glitz_gl_renderbuffer_storage_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_renderbuffer_storage_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_sizei_t, glitz_gl_sizei_t); -typedef glitz_gl_void_t (* glitz_gl_get_renderbuffer_parameter_iv_t) +typedef glitz_gl_void_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_get_renderbuffer_parameter_iv_t) (glitz_gl_enum_t, glitz_gl_enum_t, glitz_gl_int_t *); #endif /* GLITZ_GL_H_INCLUDED */ diff --git a/src/glitzint.h b/src/glitzint.h index 7a619de..ef149e9 100644 --- a/src/glitzint.h +++ b/src/glitzint.h @@ -26,6 +26,10 @@ #ifndef GLITZINT_H_INCLUDED #define GLITZINT_H_INCLUDED +#ifdef _MSC_VER +#define _USE_MATH_DEFINES +#endif + #include <stdlib.h> #include <string.h> #include <limits.h> @@ -33,6 +37,25 @@ #include "glitz.h" +#if defined(__SVR4) && defined(__sun) +# include <sys/int_types.h> +#elif defined(_MSC_VER) + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +#else +# if defined(__OpenBSD__) +# include <inttypes.h> +# else +# include <stdint.h> +# endif +#endif + #if defined(__APPLE__) || defined(__sun__) # define floorf(a) floor (a) # define ceilf(a) ceil (a) @@ -942,7 +965,7 @@ _glitz_context_fini (glitz_context_t *context); /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */ -#ifdef WIN32 +#ifdef _MSC_VER typedef __int64 glitz_fixed_32_32; #else # if defined(__alpha__) || defined(__alpha) || \ @@ -994,6 +1017,18 @@ typedef glitz_fixed_16_16 glitz_fixed; #define POWER_OF_TWO(v) ((v & (v - 1)) == 0) +/* + * VC's math.h is pretty horrible + */ +#ifdef _MSC_VER +#define ceilf(_X) ((float)ceil((double)(_X))) +#define sqrtf(_X) ((float)sqrt((double)(_X))) +#define floorf(_X) ((float)floor((double)(_X))) +#define sinf(_X) ((float)sin((double)(_X))) +#define cosf(_X) ((float)cos((double)(_X))) +#define atan2f(_X,_Y) ((float)atan2((double)(_X),(double)(_Y))) +#define sqrtf(_X) ((float)sqrt((double)(_X))) +#endif /* Avoid unnecessary PLT entries. */ diff --git a/src/wgl/.cvsignore b/src/wgl/.cvsignore new file mode 100644 index 0000000..6829f0d --- /dev/null +++ b/src/wgl/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +*.la +*.lo +*.loT +.libs +.deps diff --git a/src/wgl/Makefile.am b/src/wgl/Makefile.am new file mode 100644 index 0000000..715d314 --- /dev/null +++ b/src/wgl/Makefile.am @@ -0,0 +1,49 @@ +if GLITZ_BUILD_WGL_BACKEND + +INCLUDES = \ + $(GLITZ_INC) \ + $(WGL_CFLAGS) + +if OS_WIN32 +glitz_wgl_def = $(srcdir)/glitz-wgl.def +libglitz_wgl_export_symbols = -export-symbols $(glitz_wgl_def) +else +glitz_wgl_def = +libglitz_wgl_export_symbols = +endif + +lib_LTLIBRARIES = libglitz-wgl.la +include_HEADERS = glitz-wgl.h + +libglitz_wgl_la_SOURCES = \ + glitz-wgl.h \ + glitz_wgl_drawable.c \ + glitz_wgl_format.c \ + glitz_wgl_info.c \ + glitz_wgl_extension.c \ + glitz_wgl_context.c \ + glitz_wgl_pbuffer.c \ + glitz_wglext.h \ + glitz_wglint.h + +libglitz_wgl_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined $(libglitz_wgl_export_symbols) +libglitz_wgl_la_LIBADD = $(GLITZ_LIB) $(WGL_LIBS) +libglitz_wgl_la_DEPENDENCIES = $(glitz_wgl_def) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = glitz-wgl.pc + +endif + +EXTRA_DIST = \ + glitz-wgl.def \ + glitz-wgl.h \ + glitz_wgl_drawable.c \ + glitz_wgl_format.c \ + glitz_wgl_info.c \ + glitz_wgl_extension.c \ + glitz_wgl_context.c \ + glitz_wgl_pbuffer.c \ + glitz_wglext.h \ + glitz_wglint.h \ + glitz-wgl.pc.in diff --git a/src/wgl/glitz-wgl.def b/src/wgl/glitz-wgl.def new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/wgl/glitz-wgl.def diff --git a/src/wgl/glitz-wgl.h b/src/wgl/glitz-wgl.h new file mode 100644 index 0000000..76ab5e5 --- /dev/null +++ b/src/wgl/glitz-wgl.h @@ -0,0 +1,89 @@ +/* + * Copyright © 2004 David Reveman, Peter Nilsson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman and Peter Nilsson not be used in advertising or + * publicity pertaining to distribution of the software without + * specific, written prior permission. David Reveman and Peter Nilsson + * makes no representations about the suitability of this software for + * any purpose. It is provided "as is" without express or implied warranty. + * + * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND + * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman and Peter Nilsson + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifndef GLITZ_WGL_H_INCLUDED +#define GLITZ_WGL_H_INCLUDED + +#include <glitz.h> + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +#include <windows.h> + +/* glitz_wgl_info.c */ + +typedef struct _glitz_wgl_thread_starter_arg_t { + int (*user_thread_function) (void *); + void *user_thread_function_arg; +} glitz_wgl_thread_starter_arg_t; + +int +glitz_wgl_thread_starter (const glitz_wgl_thread_starter_arg_t *arg); + +void +glitz_wgl_init (const char *gl_library); + +void +glitz_wgl_fini (void); + + +/* glitz_wgl_format.c */ + +glitz_drawable_format_t * +glitz_wgl_find_window_format (unsigned long mask, + const glitz_drawable_format_t *templ, + int count); + +glitz_drawable_format_t * +glitz_wgl_find_pbuffer_format (unsigned long mask, + const glitz_drawable_format_t *templ, + int count); + +/* glitz_wgl_drawable.c */ + +glitz_drawable_t * +glitz_wgl_create_drawable_for_window (glitz_drawable_format_t *format, + HWND window, + unsigned int width, + unsigned int height); + +glitz_drawable_t * +glitz_wgl_create_pbuffer_drawable (glitz_drawable_format_t *format, + unsigned int width, + unsigned int height); + +#if defined(__cplusplus) || defined(c_plusplus) +} +#endif + +#endif /* GLITZ_WGL_H_INCLUDED */ diff --git a/src/wgl/glitz-wgl.pc.in b/src/wgl/glitz-wgl.pc.in new file mode 100644 index 0000000..1059fc8 --- /dev/null +++ b/src/wgl/glitz-wgl.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libglitz-wgl +Description: OpenGL compositing library (WGL backend) +Version: @VERSION@ +Requires: glitz +Libs: -L${libdir} -lglitz-wgl @WGL_LIBS@ +Cflags: -I${includedir} @WGL_CFLAGS@ diff --git a/src/wgl/glitz_wgl_context.c b/src/wgl/glitz_wgl_context.c new file mode 100644 index 0000000..1b6d871 --- /dev/null +++ b/src/wgl/glitz_wgl_context.c @@ -0,0 +1,328 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +#include <stdlib.h> +#include <stdio.h> + +extern glitz_gl_proc_address_list_t _glitz_wgl_gl_proc_address; + +static void +_glitz_wgl_context_create (glitz_wgl_screen_info_t *screen_info, + HDC dc, + int format_id, + glitz_wgl_context_t *context) +{ + PIXELFORMATDESCRIPTOR dummy_pfd; + + dummy_pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR); + dummy_pfd.nVersion = 1; + + SetPixelFormat (dc, format_id, &dummy_pfd); + + context->context = wglCreateContext (dc); + + context->pixel_format = format_id; +} + +static glitz_context_t * +_glitz_wgl_create_context (void *abstract_drawable, + glitz_drawable_format_t *format) +{ + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + glitz_wgl_screen_info_t *screen_info = drawable->screen_info; + int format_id = screen_info->format_ids[format->id]; + glitz_wgl_context_t *context; + + context = malloc (sizeof (glitz_wgl_context_t)); + if (!context) + return NULL; + + _glitz_context_init (&context->base, &drawable->base); + + _glitz_wgl_context_create (screen_info, + drawable->dc, + format_id, + context); + + wglShareLists (screen_info->root_context, context->context); + + return (glitz_context_t *) context; +} + +static void +_glitz_wgl_destroy_context (void *abstract_context) +{ + glitz_wgl_context_t *context = (glitz_wgl_context_t *) abstract_context; + + wglDeleteContext (context->context); + + _glitz_context_fini (&context->base); + + free (context); +} + +static void +_glitz_wgl_copy_context (void *abstract_src, + void *abstract_dst, + unsigned long mask) +{ + glitz_wgl_context_t *src = (glitz_wgl_context_t *) abstract_src; + glitz_wgl_context_t *dst = (glitz_wgl_context_t *) abstract_dst; + + wglCopyContext (src->context, dst->context, mask); +} + +static void +_glitz_wgl_make_current (void *abstract_context, + void *abstract_drawable) +{ + glitz_wgl_context_t *context = (glitz_wgl_context_t *) abstract_context; + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + + if (wglGetCurrentContext() != context->context || + wglGetCurrentDC() != drawable->dc) + { + wglMakeCurrent (drawable->dc, context->context); + } +} + +static void +_glitz_wgl_notify_dummy (void *abstract_drawable, + glitz_surface_t *surface) {} + +static glitz_function_pointer_t +_glitz_wgl_context_get_proc_address (void *abstract_context, + const char *name) +{ + glitz_wgl_context_t *context = (glitz_wgl_context_t *) abstract_context; + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) + context->base.drawable; + + /* _glitz_wgl_make_current (drawable, context, NULL); */ + + return glitz_wgl_get_proc_address (name, drawable->screen_info); +} + +glitz_wgl_context_t * +glitz_wgl_context_get (glitz_wgl_screen_info_t *screen_info, + HDC dc, + glitz_drawable_format_t *format) +{ + glitz_wgl_context_t *context; + glitz_wgl_context_t **contexts = screen_info->contexts; + int index, n_contexts = screen_info->n_contexts; + int format_id; + + for (; n_contexts; n_contexts--, contexts++) + if ((*contexts)->pixel_format == screen_info->format_ids[format->id]) + return *contexts; + + index = screen_info->n_contexts++; + + screen_info->contexts = + realloc (screen_info->contexts, + sizeof (glitz_wgl_context_t *) * screen_info->n_contexts); + + context = malloc (sizeof (glitz_wgl_context_t)); + + screen_info->contexts[index] = context; + + format_id = screen_info->format_ids[format->id]; + + _glitz_wgl_context_create (screen_info, + dc, + format_id, + context); + + wglShareLists (screen_info->root_context, context->context); + +#if 0 + /* Not needed as the root_context is created already when the + * singleton screen_info is set up. + */ + if (!screen_info->root_context) + screen_info->root_context = context->context; +#endif + + context->backend.gl = &_glitz_wgl_gl_proc_address; + + context->backend.create_pbuffer = glitz_wgl_create_pbuffer; + context->backend.destroy = glitz_wgl_destroy; + context->backend.push_current = glitz_wgl_push_current; + context->backend.pop_current = glitz_wgl_pop_current; + context->backend.attach_notify = _glitz_wgl_notify_dummy; + context->backend.detach_notify = _glitz_wgl_notify_dummy; + context->backend.swap_buffers = glitz_wgl_swap_buffers; + + context->backend.create_context = _glitz_wgl_create_context; + context->backend.destroy_context = _glitz_wgl_destroy_context; + context->backend.copy_context = _glitz_wgl_copy_context; + context->backend.make_current = _glitz_wgl_make_current; + context->backend.get_proc_address = _glitz_wgl_context_get_proc_address; + + context->backend.drawable_formats = screen_info->formats; + context->backend.n_drawable_formats = screen_info->n_formats; + + context->backend.texture_formats = NULL; + context->backend.formats = NULL; + context->backend.n_formats = 0; + + context->backend.program_map = &screen_info->program_map; + context->backend.feature_mask = 0; + + context->initialized = 0; + + return context; +} + +void +glitz_wgl_context_destroy (glitz_wgl_screen_info_t *screen_info, + glitz_wgl_context_t *context) +{ + if (context->backend.formats) + free (context->backend.formats); + + if (context->backend.texture_formats) + free (context->backend.texture_formats); + + wglDeleteContext (context->context); + + free (context); +} + +static void +_glitz_wgl_context_initialize (glitz_wgl_screen_info_t *screen_info, + glitz_wgl_context_t *context) +{ + glitz_backend_init (&context->backend, + glitz_wgl_get_proc_address, + (void *) screen_info); + + context->backend.gl->get_integer_v (GLITZ_GL_MAX_VIEWPORT_DIMS, + context->max_viewport_dims); + + glitz_initiate_state (&_glitz_wgl_gl_proc_address); + + context->initialized = 1; +} + +static void +_glitz_wgl_context_make_current (glitz_wgl_drawable_t *drawable, + glitz_bool_t flush) +{ + if (flush) + { + glFlush (); + } + + wglMakeCurrent (drawable->dc, drawable->context->context); + + drawable->base.update_all = 1; + + if (!drawable->context->initialized) + _glitz_wgl_context_initialize (drawable->screen_info, drawable->context); +} + +static void +_glitz_wgl_context_update (glitz_wgl_drawable_t *drawable, + glitz_constraint_t constraint) +{ + HGLRC context; + + switch (constraint) { + case GLITZ_NONE: + break; + case GLITZ_ANY_CONTEXT_CURRENT: + context = wglGetCurrentContext (); + if (context == NULL) + _glitz_wgl_context_make_current (drawable, 0); + break; + case GLITZ_CONTEXT_CURRENT: + context = wglGetCurrentContext (); + if (context != drawable->context->context) + _glitz_wgl_context_make_current (drawable, (context)? 1: 0); + break; + case GLITZ_DRAWABLE_CURRENT: + context = wglGetCurrentContext (); + if ((context != drawable->context->context) || + (wglGetCurrentDC () != drawable->dc)) + _glitz_wgl_context_make_current (drawable, (context)? 1: 0); + break; + } +} + +glitz_bool_t +glitz_wgl_push_current (void *abstract_drawable, + glitz_surface_t *surface, + glitz_constraint_t constraint) +{ + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + glitz_wgl_context_info_t *context_info; + int index; + + index = drawable->screen_info->context_stack_size++; + + context_info = &drawable->screen_info->context_stack[index]; + context_info->drawable = drawable; + context_info->surface = surface; + context_info->constraint = constraint; + + _glitz_wgl_context_update (context_info->drawable, constraint); + + return 1; +} + +glitz_surface_t * +glitz_wgl_pop_current (void *abstract_drawable) +{ + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + glitz_wgl_context_info_t *context_info = NULL; + int index; + + drawable->screen_info->context_stack_size--; + index = drawable->screen_info->context_stack_size - 1; + + context_info = &drawable->screen_info->context_stack[index]; + + if (context_info->drawable) + _glitz_wgl_context_update (context_info->drawable, + context_info->constraint); + + if (context_info->constraint == GLITZ_DRAWABLE_CURRENT) + return context_info->surface; + + return NULL; +} diff --git a/src/wgl/glitz_wgl_drawable.c b/src/wgl/glitz_wgl_drawable.c new file mode 100644 index 0000000..d267072 --- /dev/null +++ b/src/wgl/glitz_wgl_drawable.c @@ -0,0 +1,227 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +#include <stdio.h> + +glitz_status_t +glitz_wgl_make_current_read (void *abstract_surface) +{ + return GLITZ_STATUS_NOT_SUPPORTED; +} + +static glitz_wgl_drawable_t * +_glitz_wgl_create_drawable (glitz_wgl_screen_info_t *screen_info, + glitz_wgl_context_t *context, + glitz_drawable_format_t *format, + HWND window, + HDC dc, + HPBUFFERARB pbuffer, + int width, + int height) +{ + glitz_wgl_drawable_t *drawable; + + if (width <= 0 || height <= 0) + return NULL; + + drawable = (glitz_wgl_drawable_t *) malloc (sizeof (glitz_wgl_drawable_t)); + if (drawable == NULL) + return NULL; + + drawable->base.ref_count = 1; + drawable->screen_info = screen_info; + drawable->context = context; + drawable->window = window; + drawable->dc = dc; + drawable->pbuffer = pbuffer; + + _glitz_drawable_init (&drawable->base, + &screen_info->formats[format->id], + &context->backend, + width, + height); + + if (!context->initialized) { + glitz_wgl_push_current (drawable, NULL, GLITZ_CONTEXT_CURRENT); + glitz_wgl_pop_current (drawable); + } + + if (width > context->max_viewport_dims[0] || + height > context->max_viewport_dims[1]) { + free (drawable); + return NULL; + } + + screen_info->drawables++; + + return drawable; +} + +static glitz_drawable_t * +_glitz_wgl_create_pbuffer_drawable (glitz_wgl_screen_info_t *screen_info, + glitz_drawable_format_t *format, + unsigned int width, + unsigned int height) +{ + glitz_wgl_drawable_t *drawable; + glitz_wgl_context_t *context; + glitz_int_drawable_format_t *iformat = &screen_info->formats[format->id]; + HPBUFFERARB pbuffer; + HDC dc; + + if (!(iformat->types & GLITZ_DRAWABLE_TYPE_PBUFFER_MASK)) + return NULL; + + pbuffer = glitz_wgl_pbuffer_create (screen_info, screen_info->format_ids[format->id], + width, height, + &dc); + if (!pbuffer) + return NULL; + + context = glitz_wgl_context_get (screen_info, dc, format); + if (!context) { + glitz_wgl_pbuffer_destroy (screen_info, pbuffer, dc); + return NULL; + } + + drawable = _glitz_wgl_create_drawable (screen_info, context, format, + NULL, dc, pbuffer, + width, height); + if (!drawable) { + glitz_wgl_pbuffer_destroy (screen_info, pbuffer, dc); + glitz_wgl_context_destroy (screen_info, context); + return NULL; + } + + return &drawable->base; +} + +glitz_drawable_t * +glitz_wgl_create_pbuffer (void *abstract_templ, + glitz_drawable_format_t *format, + unsigned int width, + unsigned int height) +{ + glitz_wgl_drawable_t *templ = (glitz_wgl_drawable_t *) abstract_templ; + + return _glitz_wgl_create_pbuffer_drawable (templ->screen_info, format, + width, height); +} + +glitz_drawable_t * +glitz_wgl_create_drawable_for_window (glitz_drawable_format_t *format, + HWND window, + unsigned int width, + unsigned int height) +{ + glitz_wgl_drawable_t *drawable; + glitz_wgl_screen_info_t *screen_info; + glitz_wgl_context_t *context; + HDC dc; + + screen_info = glitz_wgl_screen_info_get (); + if (!screen_info) + return NULL; + + dc = GetDC (window); + + context = glitz_wgl_context_get (screen_info, dc, format); + if (!context) { + ReleaseDC (window, dc); + return NULL; + } + + drawable = _glitz_wgl_create_drawable (screen_info, context, format, + window, dc, NULL, + width, height); + if (!drawable) + return NULL; + + return &drawable->base; +} + +glitz_drawable_t * +glitz_wgl_create_pbuffer_drawable (glitz_drawable_format_t *format, + unsigned int width, + unsigned int height) +{ + glitz_wgl_screen_info_t *screen_info; + + screen_info = glitz_wgl_screen_info_get (); + if (!screen_info) + return NULL; + + return _glitz_wgl_create_pbuffer_drawable (screen_info, format, + width, height); +} + +void +glitz_wgl_destroy (void *abstract_drawable) +{ + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + + drawable->screen_info->drawables--; + if (drawable->screen_info->drawables == 0) { + /* + * Last drawable? We have to destroy all fragment programs as this may + * be our last chance to have a context current. + */ + glitz_wgl_push_current (abstract_drawable, NULL, GLITZ_CONTEXT_CURRENT); + glitz_program_map_fini (drawable->base.backend->gl, + &drawable->screen_info->program_map); + glitz_wgl_pop_current (abstract_drawable); + } + + if (wglGetCurrentDC () == drawable->dc) + { + wglMakeCurrent (NULL, NULL); + } + + if (drawable->pbuffer) + glitz_wgl_pbuffer_destroy (drawable->screen_info, drawable->pbuffer, drawable->dc); + + free (drawable); +} + +glitz_bool_t +glitz_wgl_swap_buffers (void *abstract_drawable) +{ + glitz_wgl_drawable_t *drawable = (glitz_wgl_drawable_t *) abstract_drawable; + + SwapBuffers (drawable->dc); + + return 1; +} diff --git a/src/wgl/glitz_wgl_extension.c b/src/wgl/glitz_wgl_extension.c new file mode 100644 index 0000000..033d31b --- /dev/null +++ b/src/wgl/glitz_wgl_extension.c @@ -0,0 +1,83 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +#include <stdio.h> +#include <ctype.h> + +static glitz_extension_map wgl_extensions[] = { + { 0.0, "WGL_ARB_pixel_format", GLITZ_WGL_FEATURE_PIXEL_FORMAT_MASK }, + { 0.0, "WGL_ARB_pbuffer", GLITZ_WGL_FEATURE_PBUFFER_MASK }, + { 0.0, "WGL_ARB_make_current_read", + GLITZ_WGL_FEATURE_MAKE_CURRENT_READ_MASK }, + { 0.0, "WGL_ARB_multisample", GLITZ_WGL_FEATURE_MULTISAMPLE_MASK }, + { 0.0, NULL, 0 } +}; + +void +glitz_wgl_query_extensions (glitz_wgl_screen_info_t *screen_info, + glitz_gl_float_t wgl_version) +{ + typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc); + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; + const char *wgl_extensions_string; + + wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) + wglGetProcAddress ("wglGetExtensionsStringARB"); + + if (wglGetExtensionsStringARB == NULL) + return; + + wgl_extensions_string = (*wglGetExtensionsStringARB) (screen_info->root_dc); + + screen_info->wgl_feature_mask = + glitz_extensions_query (wgl_version, + wgl_extensions_string, + wgl_extensions); + + if (screen_info->wgl_feature_mask & GLITZ_WGL_FEATURE_MULTISAMPLE_MASK) { + const char *renderer; + + renderer = glGetString (GL_RENDERER); + if (renderer) { + + /* nVIDIA's driver seem to support multisample with pbuffers (?) */ + if (!strncmp ("GeForce", renderer, 7) || + !strncmp ("Quadro", renderer, 6)) + screen_info->wgl_feature_mask |= + GLITZ_WGL_FEATURE_PBUFFER_MULTISAMPLE_MASK; + } + } +} diff --git a/src/wgl/glitz_wgl_format.c b/src/wgl/glitz_wgl_format.c new file mode 100644 index 0000000..b06da69 --- /dev/null +++ b/src/wgl/glitz_wgl_format.c @@ -0,0 +1,358 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +static int +_glitz_wgl_format_compare (const void *elem1, + const void *elem2) +{ + glitz_int_drawable_format_t *format[2]; + int i, score[2]; + + format[0] = (glitz_int_drawable_format_t *) elem1; + format[1] = (glitz_int_drawable_format_t *) elem2; + i = score[0] = score[1] = 0; + + for (; i < 2; i++) + { + if (format[i]->d.color.red_size) + { + if (format[i]->d.color.red_size >= 8) + score[i] += 5; + + score[i] += 10; + } + + if (format[i]->d.color.alpha_size) + { + if (format[i]->d.color.alpha_size >= 8) + score[i] += 5; + + score[i] += 10; + } + + if (format[i]->d.stencil_size) + score[i] += 5; + + if (format[i]->d.depth_size) + score[i] += 5; + + if (format[i]->d.doublebuffer) + score[i] += 10; + + if (format[i]->d.samples > 1) + score[i] -= (20 - format[i]->d.samples); + + if (format[i]->types & GLITZ_DRAWABLE_TYPE_WINDOW_MASK) + score[i] += 10; + + if (format[i]->types & GLITZ_DRAWABLE_TYPE_PBUFFER_MASK) + score[i] += 10; + + if (format[i]->caveat) + score[i] -= format[i]->caveat * 500; + } + + return score[1] - score[0]; +} + +static void +_glitz_add_format (glitz_wgl_screen_info_t *screen_info, + glitz_int_drawable_format_t *format, + int id) +{ + int n = screen_info->n_formats; + + screen_info->format_ids = + realloc (screen_info->format_ids, + sizeof (int) * (n + 1)); + screen_info->formats = + realloc (screen_info->formats, + sizeof (glitz_int_drawable_format_t) * (n + 1)); + if (screen_info->format_ids && screen_info->formats) + { + screen_info->formats[n] = *format; + screen_info->formats[n].d.id = n; + screen_info->format_ids[n] = id; + screen_info->n_formats++; + } +} + +static glitz_bool_t +_glitz_wgl_query_formats (glitz_wgl_screen_info_t *screen_info) +{ + glitz_int_drawable_format_t format; + int i, num_pixel_formats; + PIXELFORMATDESCRIPTOR pfd; + + pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR); + pfd.nVersion = 1; + + num_pixel_formats = + DescribePixelFormat (screen_info->root_dc, 1, + sizeof (PIXELFORMATDESCRIPTOR), &pfd); + + if (!num_pixel_formats) + return 0; + + for (i = 1; i <= num_pixel_formats; i++) { + format.d.id = 0; + format.caveat = 0; + format.types = 0; + + if (!DescribePixelFormat (screen_info->root_dc, i, + sizeof (PIXELFORMATDESCRIPTOR), &pfd)) + { + continue; + } + +#ifdef DEBUG + printf ("Pixel format %d Flags: 0x%08x\n", i, pfd.dwFlags); +#endif + + if (!((pfd.dwFlags & PFD_DRAW_TO_WINDOW) && + (pfd.dwFlags & PFD_SUPPORT_OPENGL))) + continue; + + if (pfd.iPixelType != PFD_TYPE_RGBA) + continue; + + if (pfd.dwFlags & (PFD_NEED_PALETTE | + PFD_NEED_SYSTEM_PALETTE | + PFD_STEREO)) + continue; + +#ifndef USE_MESA + /* Can't use the Windows software implementation as glitz + * unconditionally requires OpenGL 1.2, and it's only 1.1. + */ + if (pfd.dwFlags & PFD_GENERIC_FORMAT) + continue; +#endif + + format.types = GLITZ_DRAWABLE_TYPE_WINDOW_MASK; + + format.d.color.red_size = pfd.cRedBits; + format.d.color.green_size = pfd.cGreenBits; + format.d.color.blue_size = pfd.cBlueBits; + format.d.color.alpha_size = pfd.cAlphaBits; + + format.d.depth_size = pfd.cDepthBits; + format.d.stencil_size = pfd.cStencilBits; + + format.d.doublebuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER) != 0; + + format.d.samples = 1; + + _glitz_add_format (screen_info, &format, i); + } + + return 0; +} + +static glitz_status_t +_glitz_wgl_query_formats_using_pixel_format (glitz_wgl_screen_info_t *screen_info) +{ + glitz_int_drawable_format_t format; + int i, num_pixel_formats; + int question, answer; + glitz_wgl_static_proc_address_list_t *wgl = &screen_info->wgl; + + question = WGL_NUMBER_PIXEL_FORMATS_ARB; + if (!wgl->get_pixel_format_attrib_iv (screen_info->root_dc, 0, 0, 1, + &question, &num_pixel_formats)) { + /* wglGetPixelFormatAttribivARB didn't work, fall back to + * DescribePixelFormat. + */ + screen_info->wgl_feature_mask &= ~GLITZ_WGL_FEATURE_PIXEL_FORMAT_MASK; + return GLITZ_STATUS_NOT_SUPPORTED; + } + + for (i = 1; i <= num_pixel_formats; i++) { + format.d.id = 0; + format.types = 0; + +#define ASK_QUESTION(q,a) (question=(q),wgl->get_pixel_format_attrib_iv (screen_info->root_dc, i, 0, 1, &question,(a))) + + if (!ASK_QUESTION(WGL_SUPPORT_OPENGL_ARB, &answer) + || !answer) + continue; + + if (!ASK_QUESTION(WGL_PIXEL_TYPE_ARB, &answer) + || answer != WGL_TYPE_RGBA_ARB) + continue; + + if (!ASK_QUESTION(WGL_ACCELERATION_ARB, &answer)) + continue; + if (answer == WGL_NO_ACCELERATION_ARB) + format.caveat = 2; + else if (answer == WGL_GENERIC_ACCELERATION_ARB) + format.caveat = 1; + else + format.caveat = 0; + + /* Stereo is not supported yet */ + if (!ASK_QUESTION(WGL_STEREO_ARB, &answer) + || answer != 0) + continue; + + if (!ASK_QUESTION(WGL_DRAW_TO_WINDOW_ARB, &answer)) + continue; + format.types |= answer ? GLITZ_DRAWABLE_TYPE_WINDOW_MASK : 0; + + if (!ASK_QUESTION(WGL_DRAW_TO_PBUFFER_ARB, &answer)) + continue; + format.types |= answer ? GLITZ_DRAWABLE_TYPE_PBUFFER_MASK : 0; + + if (!(format.types & (GLITZ_DRAWABLE_TYPE_WINDOW_MASK | + GLITZ_DRAWABLE_TYPE_PBUFFER_MASK))) + continue; + + if (!ASK_QUESTION(WGL_RED_BITS_ARB, &answer)) + continue; + format.d.color.red_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_GREEN_BITS_ARB, &answer)) + continue; + format.d.color.green_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_BLUE_BITS_ARB, &answer)) + continue; + format.d.color.blue_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_ALPHA_BITS_ARB, &answer)) + continue; + format.d.color.alpha_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_DEPTH_BITS_ARB, &answer)) + continue; + format.d.depth_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_STENCIL_BITS_ARB, &answer)) + continue; + format.d.stencil_size = (unsigned short) answer; + + if (!ASK_QUESTION(WGL_DOUBLE_BUFFER_ARB, &answer)) + continue; + format.d.doublebuffer = (answer) ? 1: 0; + + format.d.samples = 1; + if (screen_info->wgl_feature_mask & GLITZ_WGL_FEATURE_MULTISAMPLE_MASK) { + if (!ASK_QUESTION(WGL_SAMPLE_BUFFERS_ARB, &answer)) + continue; + + if (answer) { + if (!ASK_QUESTION(WGL_SAMPLES_ARB, &answer)) + continue; + format.d.samples = (unsigned short) answer; + } + } + + _glitz_add_format (screen_info, &format, i); + } + + return GLITZ_STATUS_SUCCESS; +} + +void +glitz_wgl_query_formats (glitz_wgl_screen_info_t *screen_info) +{ + glitz_status_t status = GLITZ_STATUS_NOT_SUPPORTED; + int *new_ids, i; + + if (screen_info->wgl_feature_mask & GLITZ_WGL_FEATURE_PIXEL_FORMAT_MASK) + status = _glitz_wgl_query_formats_using_pixel_format (screen_info); + + if (status) + _glitz_wgl_query_formats (screen_info); + + if (!screen_info->n_formats) + return; + + qsort (screen_info->formats, screen_info->n_formats, + sizeof (glitz_int_drawable_format_t), _glitz_wgl_format_compare); + + new_ids = malloc (sizeof (*new_ids) * screen_info->n_formats); + + for (i = 0; i < screen_info->n_formats; i++) { + new_ids[i] = screen_info->format_ids[screen_info->formats[i].d.id]; + screen_info->formats[i].d.id = i; + } + + free (screen_info->format_ids); + screen_info->format_ids = new_ids; +} + +glitz_drawable_format_t * +glitz_wgl_find_window_format (unsigned long mask, + const glitz_drawable_format_t *templ, + int count) +{ + glitz_int_drawable_format_t itempl; + glitz_wgl_screen_info_t *screen_info = + glitz_wgl_screen_info_get (); + + glitz_drawable_format_copy (templ, &itempl.d, mask); + + itempl.types = GLITZ_DRAWABLE_TYPE_WINDOW_MASK; + mask |= GLITZ_INT_FORMAT_WINDOW_MASK; + + return glitz_drawable_format_find (screen_info->formats, + screen_info->n_formats, + mask, &itempl, count); +} + +glitz_drawable_format_t * +glitz_wgl_find_pbuffer_format (unsigned long mask, + const glitz_drawable_format_t *templ, + int count) +{ + glitz_int_drawable_format_t itempl; + glitz_wgl_screen_info_t *screen_info = + glitz_wgl_screen_info_get (); + + glitz_drawable_format_copy (templ, &itempl.d, mask); + + itempl.types = GLITZ_DRAWABLE_TYPE_PBUFFER_MASK; + mask |= GLITZ_INT_FORMAT_PBUFFER_MASK; + + return glitz_drawable_format_find (screen_info->formats, + screen_info->n_formats, + mask, &itempl, count); +} diff --git a/src/wgl/glitz_wgl_info.c b/src/wgl/glitz_wgl_info.c new file mode 100644 index 0000000..adafff4 --- /dev/null +++ b/src/wgl/glitz_wgl_info.c @@ -0,0 +1,513 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#include <malloc.h> +#include <assert.h> + +void +glitz_wgl_print_win32_error_string (int error_code) +{ + char *msg = NULL; + + FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error_code, 0, + (LPTSTR) &msg, 0, NULL); + + if (msg != NULL) + fprintf (stderr, "%s", msg); + else + fprintf (stderr, "Unknown error code %d", error_code); + + LocalFree (msg); +} + +void +glitz_wgl_win32_api_failed (const char *api) +{ + fprintf (stderr, "%s failed: ", api); + glitz_wgl_print_win32_error_string (GetLastError ()); + fprintf (stderr, "\n"); +} + +glitz_gl_proc_address_list_t _glitz_wgl_gl_proc_address = { + + /* core */ + (glitz_gl_enable_t) glEnable, + (glitz_gl_disable_t) glDisable, + (glitz_gl_get_error_t) glGetError, + (glitz_gl_get_string_t) glGetString, + (glitz_gl_enable_client_state_t) glEnableClientState, + (glitz_gl_disable_client_state_t) glDisableClientState, + (glitz_gl_vertex_pointer_t) glVertexPointer, + (glitz_gl_tex_coord_pointer_t) glTexCoordPointer, + (glitz_gl_draw_arrays_t) glDrawArrays, + (glitz_gl_tex_env_f_t) glTexEnvf, + (glitz_gl_tex_env_fv_t) glTexEnvfv, + (glitz_gl_tex_gen_i_t) glTexGeni, + (glitz_gl_tex_gen_fv_t) glTexGenfv, + (glitz_gl_color_4us_t) glColor4us, + (glitz_gl_color_4f_t) glColor4f, + (glitz_gl_scissor_t) glScissor, + (glitz_gl_blend_func_t) glBlendFunc, + (glitz_gl_clear_t) glClear, + (glitz_gl_clear_color_t) glClearColor, + (glitz_gl_clear_stencil_t) glClearStencil, + (glitz_gl_stencil_func_t) glStencilFunc, + (glitz_gl_stencil_op_t) glStencilOp, + (glitz_gl_push_attrib_t) glPushAttrib, + (glitz_gl_pop_attrib_t) glPopAttrib, + (glitz_gl_matrix_mode_t) glMatrixMode, + (glitz_gl_push_matrix_t) glPushMatrix, + (glitz_gl_pop_matrix_t) glPopMatrix, + (glitz_gl_load_identity_t) glLoadIdentity, + (glitz_gl_load_matrix_f_t) glLoadMatrixf, + (glitz_gl_depth_range_t) glDepthRange, + (glitz_gl_viewport_t) glViewport, + (glitz_gl_raster_pos_2f_t) glRasterPos2f, + (glitz_gl_bitmap_t) glBitmap, + (glitz_gl_read_buffer_t) glReadBuffer, + (glitz_gl_draw_buffer_t) glDrawBuffer, + (glitz_gl_copy_pixels_t) glCopyPixels, + (glitz_gl_flush_t) glFlush, + (glitz_gl_finish_t) glFinish, + (glitz_gl_pixel_store_i_t) glPixelStorei, + (glitz_gl_ortho_t) glOrtho, + (glitz_gl_scale_f_t) glScalef, + (glitz_gl_translate_f_t) glTranslatef, + (glitz_gl_hint_t) glHint, + (glitz_gl_depth_mask_t) glDepthMask, + (glitz_gl_polygon_mode_t) glPolygonMode, + (glitz_gl_shade_model_t) glShadeModel, + (glitz_gl_color_mask_t) glColorMask, + (glitz_gl_read_pixels_t) glReadPixels, + (glitz_gl_get_tex_image_t) glGetTexImage, + (glitz_gl_tex_sub_image_2d_t) glTexSubImage2D, + (glitz_gl_gen_textures_t) glGenTextures, + (glitz_gl_delete_textures_t) glDeleteTextures, + (glitz_gl_bind_texture_t) glBindTexture, + (glitz_gl_tex_image_2d_t) glTexImage2D, + (glitz_gl_tex_parameter_i_t) glTexParameteri, + (glitz_gl_tex_parameter_fv_t) glTexParameterfv, + (glitz_gl_get_tex_level_parameter_iv_t) glGetTexLevelParameteriv, + (glitz_gl_copy_tex_sub_image_2d_t) glCopyTexSubImage2D, + (glitz_gl_get_integer_v_t) glGetIntegerv, + + /* extensions */ + (glitz_gl_blend_color_t) 0, + (glitz_gl_active_texture_t) 0, + (glitz_gl_client_active_texture_t) 0, + (glitz_gl_multi_draw_arrays_t) 0, + (glitz_gl_gen_programs_t) 0, + (glitz_gl_delete_programs_t) 0, + (glitz_gl_program_string_t) 0, + (glitz_gl_bind_program_t) 0, + (glitz_gl_program_local_param_4fv_t) 0, + (glitz_gl_get_program_iv_t) 0, + (glitz_gl_gen_buffers_t) 0, + (glitz_gl_delete_buffers_t) 0, + (glitz_gl_bind_buffer_t) 0, + (glitz_gl_buffer_data_t) 0, + (glitz_gl_buffer_sub_data_t) 0, + (glitz_gl_get_buffer_sub_data_t) 0, + (glitz_gl_map_buffer_t) 0, + (glitz_gl_unmap_buffer_t) 0, + (glitz_gl_gen_framebuffers_t) 0, + (glitz_gl_delete_framebuffers_t) 0, + (glitz_gl_bind_framebuffer_t) 0, + (glitz_gl_framebuffer_renderbuffer_t) 0, + (glitz_gl_framebuffer_texture_2d_t) 0, + (glitz_gl_check_framebuffer_status_t) 0, + (glitz_gl_gen_renderbuffers_t) 0, + (glitz_gl_delete_renderbuffers_t) 0, + (glitz_gl_bind_renderbuffer_t) 0, + (glitz_gl_renderbuffer_storage_t) 0, + (glitz_gl_get_renderbuffer_parameter_iv_t) 0 +}; + +glitz_function_pointer_t +glitz_wgl_get_proc_address (const char *name, + void *closure) +{ + glitz_wgl_screen_info_t *screen_info = (glitz_wgl_screen_info_t *) closure; + glitz_wgl_thread_info_t *info = screen_info->thread_info; + glitz_function_pointer_t address = (glitz_function_pointer_t) + wglGetProcAddress (name); + + if (!address && info->gl_library) { + /* Not sure whether this has any use at all... */ + + if (!info->dlhand) + info->dlhand = LoadLibrary (info->gl_library); + + if (info->dlhand) { + address = (glitz_function_pointer_t) + GetProcAddress (info->dlhand, name); + } + } + + return address; +} + +static void +_glitz_wgl_proc_address_lookup (glitz_wgl_screen_info_t *screen_info) +{ + screen_info->wgl.get_pixel_format_attrib_iv = + (glitz_wgl_get_pixel_format_attrib_iv_t) + glitz_wgl_get_proc_address ("wglGetPixelFormatAttribivARB", screen_info); + screen_info->wgl.choose_pixel_format = (glitz_wgl_choose_pixel_format_t) + glitz_wgl_get_proc_address ("wglChoosePixelFormatARB", screen_info); + + screen_info->wgl.create_pbuffer = (glitz_wgl_create_pbuffer_t) + glitz_wgl_get_proc_address ("wglCreatePbufferARB", screen_info); + screen_info->wgl.get_pbuffer_dc = (glitz_wgl_get_pbuffer_dc_t) + glitz_wgl_get_proc_address ("wglGetPbufferDCARB", screen_info); + screen_info->wgl.release_pbuffer_dc = (glitz_wgl_release_pbuffer_dc_t) + glitz_wgl_get_proc_address ("wglReleasePbufferDCARB", screen_info); + screen_info->wgl.destroy_pbuffer = (glitz_wgl_destroy_pbuffer_t) + glitz_wgl_get_proc_address ("wglDestroyPbufferARB", screen_info); + screen_info->wgl.query_pbuffer = (glitz_wgl_query_pbuffer_t) + glitz_wgl_get_proc_address ("wglQueryPbufferARB", screen_info); + + screen_info->wgl.make_context_current = (glitz_wgl_make_context_current_t) + glitz_wgl_get_proc_address ("wglMakeContextCurrentARB", screen_info); + + if ((!screen_info->wgl.create_pbuffer) || + (!screen_info->wgl.destroy_pbuffer) || + (!screen_info->wgl.query_pbuffer)) + screen_info->wgl_feature_mask &= ~GLITZ_WGL_FEATURE_PBUFFER_MASK; + + +} + +static void +_glitz_wgl_screen_destroy (glitz_wgl_screen_info_t *screen_info); + +static void +_glitz_wgl_thread_info_init (glitz_wgl_thread_info_t *thread_info) +{ + thread_info->screen = NULL; + thread_info->gl_library = NULL; + thread_info->dlhand = NULL; +} + +static void +_glitz_wgl_thread_info_fini (glitz_wgl_thread_info_t *thread_info) +{ + _glitz_wgl_screen_destroy (thread_info->screen); + + thread_info->screen = NULL; + + if (thread_info->gl_library) { + free (thread_info->gl_library); + thread_info->gl_library = NULL; + } + + if (thread_info->dlhand) { + FreeLibrary (thread_info->dlhand); + thread_info->dlhand = NULL; + } +} + +static int tsd_initialized = 0; +static DWORD info_tsd; + +static void +_glitz_wgl_thread_info_destroy (glitz_wgl_thread_info_t *thread_info) +{ + TlsSetValue (info_tsd, NULL); + + if (thread_info) { + _glitz_wgl_thread_info_fini (thread_info); + free (thread_info); + } +} + +static glitz_wgl_thread_info_t * +_glitz_wgl_thread_info_get_inner (void) +{ + glitz_wgl_thread_info_t *thread_info; + void *p; + + if (!tsd_initialized) { + info_tsd = TlsAlloc (); + tsd_initialized = 1; + } + + p = TlsGetValue (info_tsd); + + if (p == NULL) { + thread_info = malloc (sizeof (glitz_wgl_thread_info_t)); + _glitz_wgl_thread_info_init (thread_info); + + TlsSetValue (info_tsd, thread_info); + } else + thread_info = (glitz_wgl_thread_info_t *) p; + + return thread_info; +} + +static glitz_wgl_thread_info_t * +_glitz_wgl_thread_info_get (const char *gl_library) +{ + glitz_wgl_thread_info_t *thread_info = _glitz_wgl_thread_info_get_inner (); + + if (gl_library) { + int len = strlen (gl_library); + + if (thread_info->gl_library) { + free (thread_info->gl_library); + thread_info->gl_library = NULL; + } + + thread_info->gl_library = malloc (len + 1); + if (thread_info->gl_library) { + memcpy (thread_info->gl_library, gl_library, len); + thread_info->gl_library[len] = '\0'; + } + } + + return thread_info; +} + +int +glitz_wgl_thread_starter (const glitz_wgl_thread_starter_arg_t *arg) +{ + glitz_wgl_thread_info_t *thread_info; + int retval; + + retval = (*arg->user_thread_function) (arg->user_thread_function_arg); + + if (tsd_initialized) { + thread_info = (glitz_wgl_thread_info_t *) TlsGetValue (info_tsd); + _glitz_wgl_thread_info_fini (thread_info); + free (thread_info); + } + + return retval; +} + +static void +_glitz_wgl_create_root_context (glitz_wgl_screen_info_t *screen_info) +{ + WNDCLASSEX wcl; + ATOM klass; + + static PIXELFORMATDESCRIPTOR pfd = { + sizeof (PIXELFORMATDESCRIPTOR), + 1, + PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, + PFD_TYPE_RGBA, + 32, + 0, 0, 0, + 0, 0, 0, + 0, 0, + 0, 0, 0, 0, 0, + 0, + 0, + 0, + PFD_MAIN_PLANE, + 0, + 0, + 0, + 0 + }; + + int pixel_format; + + wcl.cbSize = sizeof (wcl); + wcl.style = 0; + wcl.lpfnWndProc = DefWindowProc; + wcl.cbClsExtra = 0; + wcl.cbWndExtra = 0; + wcl.hInstance = GetModuleHandle (NULL); + wcl.hIcon = NULL; + wcl.hCursor = LoadCursor (NULL, IDC_ARROW); + wcl.hbrBackground = NULL; + wcl.lpszMenuName = NULL; + wcl.lpszClassName = "glitz-wgl-root-window-class"; + wcl.hIconSm = NULL; + + klass = RegisterClassEx (&wcl); + + if (!klass) { + exit (1); + } + + screen_info->root_window = + CreateWindowEx (0, (LPCTSTR) (DWORD) klass, "glitz-wgl-root-window", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, + 100, 100, + GetDesktopWindow (), + NULL, GetModuleHandle (NULL), NULL); + + screen_info->root_dc = GetDC (screen_info->root_window); + + pixel_format = ChoosePixelFormat (screen_info->root_dc, &pfd); + + if (pixel_format != 0) { + SetPixelFormat (screen_info->root_dc, pixel_format, &pfd); + + screen_info->root_context = wglCreateContext (screen_info->root_dc); + + wglMakeCurrent (screen_info->root_dc, screen_info->root_context); + } else { + screen_info->root_context = NULL; + } +} + +glitz_wgl_screen_info_t * +glitz_wgl_screen_info_get (void) +{ + static glitz_wgl_screen_info_t *screen_info = NULL; + const char *gl_version; + + if (screen_info != NULL) + return screen_info; + + screen_info = malloc (sizeof (glitz_wgl_screen_info_t)); + + screen_info->drawables = 0; + screen_info->formats = NULL; + screen_info->format_ids = NULL; + screen_info->n_formats = 0; + + screen_info->contexts = NULL; + screen_info->n_contexts = 0; + + memset (&screen_info->wgl, 0, sizeof (glitz_wgl_static_proc_address_list_t)); + + glitz_program_map_init (&screen_info->program_map); + + _glitz_wgl_create_root_context (screen_info); + + gl_version = glGetString (GL_VERSION); + + screen_info->wgl_version = 1; + + /* Can't use atof(), as GL_VERSION might always use a decimal period, + * but atof() looks for the locale-specific decimal separator. + */ + if (gl_version != NULL && gl_version[0]) { + int whole_part; + int n; + if (sscanf (gl_version, "%d%n", &whole_part, &n) == 1 && + (gl_version[n] == '.' || + gl_version[n] == ',')) { + double fraction = 0.1; + + screen_info->wgl_version = whole_part; + while (isdigit (gl_version[n+1])) { + screen_info->wgl_version += (gl_version[n+1] - '0') * fraction; + fraction /= 10; + n++; + } + } + } + + screen_info->wgl_feature_mask = 0; + + screen_info->thread_info = _glitz_wgl_thread_info_get_inner (); + screen_info->thread_info->screen = screen_info; + _glitz_wgl_thread_info_get (NULL); + + glitz_wgl_query_extensions (screen_info, screen_info->wgl_version); + _glitz_wgl_proc_address_lookup (screen_info); + glitz_wgl_query_formats (screen_info); + + screen_info->context_stack_size = 1; + screen_info->context_stack->drawable = NULL; + screen_info->context_stack->surface = NULL; + screen_info->context_stack->constraint = GLITZ_NONE; + + return screen_info; +} + +static void +_glitz_wgl_screen_destroy (glitz_wgl_screen_info_t *screen_info) +{ + int i; + + if (screen_info->root_context) { + wglMakeCurrent (NULL, NULL); + } + + for (i = 0; i < screen_info->n_contexts; i++) + glitz_wgl_context_destroy (screen_info, screen_info->contexts[i]); + + if (screen_info->contexts) + free (screen_info->contexts); + + if (screen_info->formats) + free (screen_info->formats); + + if (screen_info->format_ids) + free (screen_info->format_ids); + + if (screen_info->root_context) { + wglDeleteContext (screen_info->root_context); + } + + if (screen_info->root_dc) { + DeleteDC (screen_info->root_dc); + } + + if (screen_info->root_window) { + DestroyWindow (screen_info->root_window); + } + + free (screen_info); +} + +void +glitz_wgl_init (const char *gl_library) +{ + _glitz_wgl_thread_info_get (gl_library); +} + +void +glitz_wgl_fini (void) +{ + glitz_wgl_thread_info_t *info = _glitz_wgl_thread_info_get (NULL); + + _glitz_wgl_thread_info_destroy (info); +} diff --git a/src/wgl/glitz_wgl_pbuffer.c b/src/wgl/glitz_wgl_pbuffer.c new file mode 100644 index 0000000..18cdb42 --- /dev/null +++ b/src/wgl/glitz_wgl_pbuffer.c @@ -0,0 +1,71 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "glitz_wglint.h" + +HPBUFFERARB +glitz_wgl_pbuffer_create (glitz_wgl_screen_info_t *screen_info, + int pixel_format, + unsigned int width, + unsigned int height, + HDC *dcp) +{ + if (pixel_format) { + HPBUFFERARB retval; + int pbuffer_attr[3], i = 0; + + pbuffer_attr[i++] = WGL_PBUFFER_LARGEST_ARB; + pbuffer_attr[i++] = 0; + pbuffer_attr[i++] = 0; + + retval = + screen_info->wgl.create_pbuffer (screen_info->root_dc, pixel_format, + width, height, pbuffer_attr); + if (retval != NULL) { + *dcp = screen_info->wgl.get_pbuffer_dc (retval); + return retval; + } + } + *dcp = NULL; + return NULL; +} + +void +glitz_wgl_pbuffer_destroy (glitz_wgl_screen_info_t *screen_info, + HPBUFFERARB pbuffer, + HDC dc) +{ + screen_info->wgl.release_pbuffer_dc (pbuffer, dc); + screen_info->wgl.destroy_pbuffer (pbuffer); +} diff --git a/src/wgl/glitz_wglext.h b/src/wgl/glitz_wglext.h new file mode 100644 index 0000000..638f005 --- /dev/null +++ b/src/wgl/glitz_wglext.h @@ -0,0 +1,151 @@ +/* + * Copyright © 2004 David Reveman, Peter Nilsson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman and Peter Nilsson not be used in advertising or + * publicity pertaining to distribution of the software without + * specific, written prior permission. David Reveman and Peter Nilsson + * makes no representations about the suitability of this software for + * any purpose. It is provided "as is" without express or implied warranty. + * + * DAVID REVEMAN AND PETER NILSSON DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DAVID REVEMAN AND + * PETER NILSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman and Peter Nilsson + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifndef GLITZ_WGLEXT_H_INCLUDED +#define GLITZ_WGLEXT_H_INCLUDED + +/* WGL_ARB_pixel_format */ + +#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 +#define WGL_DRAW_TO_WINDOW_ARB 0x2001 +#define WGL_DRAW_TO_BITMAP_ARB 0x2002 +#define WGL_ACCELERATION_ARB 0x2003 +#define WGL_NEED_PALETTE_ARB 0x2004 +#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 +#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 +#define WGL_SWAP_METHOD_ARB 0x2007 +#define WGL_NUMBER_OVERLAYS_ARB 0x2008 +#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 +#define WGL_TRANSPARENT_ARB 0x200A +#define WGL_SHARE_DEPTH_ARB 0x200C +#define WGL_SHARE_STENCIL_ARB 0x200D +#define WGL_SHARE_ACCUM_ARB 0x200E +#define WGL_SUPPORT_GDI_ARB 0x200F +#define WGL_SUPPORT_OPENGL_ARB 0x2010 +#define WGL_DOUBLE_BUFFER_ARB 0x2011 +#define WGL_STEREO_ARB 0x2012 +#define WGL_PIXEL_TYPE_ARB 0x2013 +#define WGL_COLOR_BITS_ARB 0x2014 +#define WGL_RED_BITS_ARB 0x2015 +#define WGL_RED_SHIFT_ARB 0x2016 +#define WGL_GREEN_BITS_ARB 0x2017 +#define WGL_GREEN_SHIFT_ARB 0x2018 +#define WGL_BLUE_BITS_ARB 0x2019 +#define WGL_BLUE_SHIFT_ARB 0x201A +#define WGL_ALPHA_BITS_ARB 0x201B +#define WGL_ALPHA_SHIFT_ARB 0x201C +#define WGL_ACCUM_BITS_ARB 0x201D +#define WGL_ACCUM_RED_BITS_ARB 0x201E +#define WGL_ACCUM_GREEN_BITS_ARB 0x201F +#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 +#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 +#define WGL_DEPTH_BITS_ARB 0x2022 +#define WGL_STENCIL_BITS_ARB 0x2023 +#define WGL_AUX_BUFFERS_ARB 0x2024 +#define WGL_NO_ACCELERATION_ARB 0x2025 +#define WGL_GENERIC_ACCELERATION_ARB 0x2026 +#define WGL_FULL_ACCELERATION_ARB 0x2027 +#define WGL_SWAP_EXCHANGE_ARB 0x2028 +#define WGL_SWAP_COPY_ARB 0x2029 +#define WGL_SWAP_UNDEFINED_ARB 0x202A +#define WGL_TYPE_RGBA_ARB 0x202B +#define WGL_TYPE_COLORINDEX_ARB 0x202C +#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 +#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 +#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 +#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A +#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B + +typedef BOOL (WINAPI * glitz_wgl_get_pixel_format_attrib_iv_t) + (HDC hDC, + int iPixelFormat, + int iLayerPlane, + unsigned int nAttributes, + const int *piAttributes, + int *piValues); + +typedef BOOL (WINAPI * glitz_wgl_choose_pixel_format_t) + (HDC hDC, + const int *piAttribIList, + const float *pfAttribFList, + unsigned int nMaxFormats, + int *piFormats, + unsigned int *nNumFormats); + +/* WGL_ARB_make_current_read */ + +typedef HDC (WINAPI * glitz_wgl_get_current_read_dc_t) (VOID); +typedef BOOL (WINAPI * glitz_wgl_make_context_current_t) + (HDC hDrawDC, + HDC hReadDC, + HGLRC hglrc); + +/* WGL_ARB_multisample */ + +#define WGL_SAMPLE_BUFFERS_ARB 0x2041 +#define WGL_SAMPLES_ARB 0x2042 + +/* WGL_ARB_pbuffer */ + +#define WGL_DRAW_TO_PBUFFER_ARB 0x202D +#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E +#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F +#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030 +#define WGL_PBUFFER_LARGEST_ARB 0x2033 +#define WGL_PBUFFER_WIDTH_ARB 0x2034 +#define WGL_PBUFFER_HEIGHT_ARB 0x2035 +#define WGL_PBUFFER_LOST_ARB 0x2036 + +DECLARE_HANDLE(HPBUFFERARB); + +typedef HPBUFFERARB (WINAPI * glitz_wgl_create_pbuffer_t) + (HDC hDC, + int iPixelFormat, + int iWidth, + int iHeight, + const int *piAttribList); + +typedef HDC (WINAPI * glitz_wgl_get_pbuffer_dc_t) + (HPBUFFERARB hPbuffer); + +typedef int (WINAPI * glitz_wgl_release_pbuffer_dc_t) + (HPBUFFERARB hPbuffer, + HDC hDC); + +typedef BOOL (WINAPI * glitz_wgl_destroy_pbuffer_t) + (HPBUFFERARB hPbuffer); + +typedef BOOL (WINAPI * glitz_wgl_query_pbuffer_t) + (HPBUFFERARB hPbuffer, + int iAttribute, + int *piValue); + +#endif /* GLITZ_WGLEXT_H_INCLUDED */ diff --git a/src/wgl/glitz_wglint.h b/src/wgl/glitz_wglint.h new file mode 100644 index 0000000..05dc2cc --- /dev/null +++ b/src/wgl/glitz_wglint.h @@ -0,0 +1,196 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the names of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Based on glx code by David Reveman + * + * Contributors: + * Tor Lillqvist <tml@iki.fi> + * Vladimir Vukicevic <vladimir@pobox.com> + * + */ + +#ifndef GLITZ_WGLINT_H_INCLUDED +#define GLITZ_WGLINT_H_INCLUDED + +#include <windows.h> /* To let it define MAX/MINSHORT first */ +#undef MAXSHORT +#undef MINSHORT + +#include "glitzint.h" + +#include "glitz-wgl.h" + +#include <GL/gl.h> + +#ifdef USE_MESA +#define ChoosePixelFormat wglChoosePixelFormat +#define DescribePixelFormat wglDescribePixelFormat +#define GetPixelFormat wglGetPixelFormat +#define SetPixelFormat wglSetPixelFormat +#define SwapBuffers wglSwapBuffers +#endif + +#include "glitz_wglext.h" + +#define GLITZ_WGL_FEATURE_PIXEL_FORMAT_MASK (1L << 0) +#define GLITZ_WGL_FEATURE_PBUFFER_MASK (1L << 1) +#define GLITZ_WGL_FEATURE_MAKE_CURRENT_READ_MASK (1L << 2) +/* wglGetProcAddress is always present */ +#define GLITZ_WGL_FEATURE_MULTISAMPLE_MASK (1L << 4) +#define GLITZ_WGL_FEATURE_PBUFFER_MULTISAMPLE_MASK (1L << 5) + +typedef struct _glitz_wgl_drawable glitz_wgl_drawable_t; +typedef struct _glitz_wgl_screen_info_t glitz_wgl_screen_info_t; + +typedef struct _glitz_wgl_static_proc_address_list_t { + glitz_wgl_get_pixel_format_attrib_iv_t get_pixel_format_attrib_iv; + glitz_wgl_choose_pixel_format_t choose_pixel_format; + glitz_wgl_create_pbuffer_t create_pbuffer; + glitz_wgl_get_pbuffer_dc_t get_pbuffer_dc; + glitz_wgl_release_pbuffer_dc_t release_pbuffer_dc; + glitz_wgl_destroy_pbuffer_t destroy_pbuffer; + glitz_wgl_query_pbuffer_t query_pbuffer; + glitz_wgl_make_context_current_t make_context_current; +} glitz_wgl_static_proc_address_list_t; + +typedef struct _glitz_wgl_thread_info_t { + glitz_wgl_screen_info_t *screen; + char *gl_library; + HMODULE dlhand; +} glitz_wgl_thread_info_t; + +typedef struct _glitz_wgl_context_info_t { + glitz_wgl_drawable_t *drawable; + glitz_surface_t *surface; + glitz_constraint_t constraint; +} glitz_wgl_context_info_t; + +typedef struct _glitz_wgl_context_t { + glitz_context_t base; + + HGLRC context; + glitz_format_id_t id; + int pixel_format; + glitz_backend_t backend; + glitz_gl_int_t max_viewport_dims[2]; + glitz_bool_t initialized; +} glitz_wgl_context_t; + +struct _glitz_wgl_screen_info_t { + glitz_wgl_thread_info_t *thread_info; + int drawables; + glitz_int_drawable_format_t *formats; + int *format_ids; + int n_formats; + glitz_wgl_context_t **contexts; + int n_contexts; + glitz_wgl_context_info_t context_stack[GLITZ_CONTEXT_STACK_SIZE]; + int context_stack_size; + /* root_context is used only for sharing a single display-list space + * amont the Glitz rendering contexts. Nothing is ever actually + * rendered into it. The related root_dc and root_window are kept + * around only for proper destruction. + */ + HGLRC root_context; + HDC root_dc; + HWND root_window; + unsigned long wgl_feature_mask; + glitz_gl_float_t wgl_version; + glitz_wgl_static_proc_address_list_t wgl; + glitz_program_map_t program_map; +}; + +struct _glitz_wgl_drawable { + glitz_drawable_t base; + + glitz_wgl_screen_info_t *screen_info; + glitz_wgl_context_t *context; + HWND window; + HDC dc; + HPBUFFERARB pbuffer; +}; + +extern void __internal_linkage +glitz_wgl_query_extensions (glitz_wgl_screen_info_t *screen_info, + glitz_gl_float_t wgl_version); + +extern glitz_wgl_screen_info_t *__internal_linkage +glitz_wgl_screen_info_get (void); + +extern glitz_function_pointer_t __internal_linkage +glitz_wgl_get_proc_address (const char *name, + void *closure); + +extern glitz_wgl_context_t *__internal_linkage +glitz_wgl_context_get (glitz_wgl_screen_info_t *screen_info, + HDC dc, + glitz_drawable_format_t *format); + +extern void __internal_linkage +glitz_wgl_context_destroy (glitz_wgl_screen_info_t *screen_info, + glitz_wgl_context_t *context); + +extern void __internal_linkage +glitz_wgl_query_formats (glitz_wgl_screen_info_t *screen_info); + +extern HPBUFFERARB __internal_linkage +glitz_wgl_pbuffer_create (glitz_wgl_screen_info_t *screen_info, + int pixel_format, + unsigned int width, + unsigned int height, + HDC *dcp); + +extern void __internal_linkage +glitz_wgl_pbuffer_destroy (glitz_wgl_screen_info_t *screen_info, + HPBUFFERARB pbuffer, + HDC dc); + +extern glitz_drawable_t *__internal_linkage +glitz_wgl_create_pbuffer (void *abstract_templ, + glitz_drawable_format_t *format, + unsigned int width, + unsigned int height); + +extern glitz_bool_t __internal_linkage +glitz_wgl_push_current (void *abstract_drawable, + glitz_surface_t *surface, + glitz_constraint_t constraint); + +extern glitz_surface_t *__internal_linkage +glitz_wgl_pop_current (void *abstract_drawable); + +extern glitz_status_t __internal_linkage +glitz_wgl_make_current_read (void *abstract_surface); + +extern void __internal_linkage +glitz_wgl_destroy (void *abstract_drawable); + +extern glitz_bool_t __internal_linkage +glitz_wgl_swap_buffers (void *abstract_drawable); + +extern void __internal_linkage +glitz_wgl_print_win32_error_string (int error_code); + +extern void __internal_linkage +glitz_wgl_win32_api_failed (const char *api); + +#endif /* GLITZ_WGLINT_H_INCLUDED */ |