diff --git a/glucose/glitz_gl.h b/glucose/glitz_gl.h new file mode 100644 index 000000000..3036bc68e --- /dev/null +++ b/glucose/glitz_gl.h @@ -0,0 +1,578 @@ +/* + * 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. + * + * Authors: David Reveman + * Peter Nilsson + */ + +#ifndef GLITZ_GL_H_INCLUDED +#define GLITZ_GL_H_INCLUDED + +#include + +#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; +typedef int glitz_gl_int_t; +typedef unsigned int glitz_gl_uint_t; +typedef int glitz_gl_sizei_t; +typedef double glitz_gl_double_t; +typedef float glitz_gl_float_t; +typedef unsigned short glitz_gl_ushort_t; +typedef short glitz_gl_short_t; +typedef unsigned int glitz_gl_bitfield_t; +typedef double glitz_gl_clampd_t; +typedef float glitz_gl_clampf_t; +typedef unsigned char glitz_gl_ubyte_t; +typedef ptrdiff_t glitz_gl_intptr_t; +typedef ptrdiff_t glitz_gl_sizeiptr_t; + + +#define GLITZ_GL_FALSE 0x0 +#define GLITZ_GL_TRUE 0x1 + +#define GLITZ_GL_NO_ERROR 0x0 +#define GLITZ_GL_INVALID_OPERATION 0x0502 + +#define GLITZ_GL_VENDOR 0x1F00 +#define GLITZ_GL_RENDERER 0x1F01 +#define GLITZ_GL_VERSION 0x1F02 +#define GLITZ_GL_EXTENSIONS 0x1F03 + +#define GLITZ_GL_UNSIGNED_BYTE 0x1401 +#define GLITZ_GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GLITZ_GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GLITZ_GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GLITZ_GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GLITZ_GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GLITZ_GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GLITZ_GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GLITZ_GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GLITZ_GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GLITZ_GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GLITZ_GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 + +#define GLITZ_GL_MODELVIEW 0x1700 +#define GLITZ_GL_PROJECTION 0x1701 + +#define GLITZ_GL_SHORT 0x1402 +#define GLITZ_GL_INT 0x1404 +#define GLITZ_GL_FLOAT 0x1406 +#define GLITZ_GL_DOUBLE 0x140A + +#define GLITZ_GL_POINTS 0x0000 +#define GLITZ_GL_LINES 0x0001 +#define GLITZ_GL_LINE_LOOP 0x0002 +#define GLITZ_GL_LINE_STRIP 0x0003 +#define GLITZ_GL_TRIANGLES 0x0004 +#define GLITZ_GL_TRIANGLE_STRIP 0x0005 +#define GLITZ_GL_TRIANGLE_FAN 0x0006 +#define GLITZ_GL_QUADS 0x0007 +#define GLITZ_GL_QUAD_STRIP 0x0008 +#define GLITZ_GL_POLYGON 0x0009 + +#define GLITZ_GL_VERTEX_ARRAY 0x8074 +#define GLITZ_GL_TEXTURE_COORD_ARRAY 0x8078 + +#define GLITZ_GL_FILL 0x1B02 +#define GLITZ_GL_FRONT 0x0404 +#define GLITZ_GL_BACK 0x0405 +#define GLITZ_GL_CULL_FACE 0x0B44 + +#define GLITZ_GL_POINT_SMOOTH 0x0B10 +#define GLITZ_GL_LINE_SMOOTH 0x0B20 +#define GLITZ_GL_POLYGON_SMOOTH 0x0B41 + +#define GLITZ_GL_SCISSOR_TEST 0x0C11 + +#define GLITZ_GL_MAX_TEXTURE_SIZE 0x0D33 +#define GLITZ_GL_MAX_VIEWPORT_DIMS 0x0D3A + +#define GLITZ_GL_TEXTURE_WIDTH 0x1000 +#define GLITZ_GL_TEXTURE_HEIGHT 0x1001 +#define GLITZ_GL_TEXTURE_BORDER_COLOR 0x1004 + +#define GLITZ_GL_TEXTURE_BINDING_2D 0x8069 +#define GLITZ_GL_TEXTURE_BINDING_RECTANGLE 0x84F6 + +#define GLITZ_GL_TEXTURE_ENV 0x2300 +#define GLITZ_GL_TEXTURE_ENV_MODE 0x2200 +#define GLITZ_GL_TEXTURE_2D 0x0DE1 +#define GLITZ_GL_PROXY_TEXTURE_2D 0x8064 +#define GLITZ_GL_TEXTURE_WRAP_S 0x2802 +#define GLITZ_GL_TEXTURE_WRAP_T 0x2803 +#define GLITZ_GL_TEXTURE_MAG_FILTER 0x2800 +#define GLITZ_GL_TEXTURE_MIN_FILTER 0x2801 +#define GLITZ_GL_TEXTURE_ENV_COLOR 0x2201 +#define GLITZ_GL_TEXTURE_GEN_S 0x0C60 +#define GLITZ_GL_TEXTURE_GEN_T 0x0C61 +#define GLITZ_GL_TEXTURE_GEN_MODE 0x2500 +#define GLITZ_GL_EYE_LINEAR 0x2400 +#define GLITZ_GL_EYE_PLANE 0x2502 +#define GLITZ_GL_S 0x2000 +#define GLITZ_GL_T 0x2001 + +#define GLITZ_GL_MODULATE 0x2100 +#define GLITZ_GL_NEAREST 0x2600 +#define GLITZ_GL_LINEAR 0x2601 +#define GLITZ_GL_CLAMP 0x2900 +#define GLITZ_GL_REPEAT 0x2901 +#define GLITZ_GL_CLAMP_TO_EDGE 0x812F +#define GLITZ_GL_CLAMP_TO_BORDER 0x812D +#define GLITZ_GL_TEXTURE_RED_SIZE 0x805C +#define GLITZ_GL_TEXTURE_GREEN_SIZE 0x805D +#define GLITZ_GL_TEXTURE_BLUE_SIZE 0x805E +#define GLITZ_GL_TEXTURE_ALPHA_SIZE 0x805F + +#define GLITZ_GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GLITZ_GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GLITZ_GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GLITZ_GL_LINEAR_MIPMAP_LINEAR 0x2703 + +#define GLITZ_GL_TEXTURE 0x1702 +#define GLITZ_GL_SRC_COLOR 0x0300 + +#define GLITZ_GL_COMBINE 0x8570 +#define GLITZ_GL_COMBINE_RGB 0x8571 +#define GLITZ_GL_COMBINE_ALPHA 0x8572 +#define GLITZ_GL_SOURCE0_RGB 0x8580 +#define GLITZ_GL_SOURCE1_RGB 0x8581 +#define GLITZ_GL_SOURCE2_RGB 0x8582 +#define GLITZ_GL_SOURCE0_ALPHA 0x8588 +#define GLITZ_GL_SOURCE1_ALPHA 0x8589 +#define GLITZ_GL_SOURCE2_ALPHA 0x858A +#define GLITZ_GL_OPERAND0_RGB 0x8590 +#define GLITZ_GL_OPERAND1_RGB 0x8591 +#define GLITZ_GL_OPERAND2_RGB 0x8592 +#define GLITZ_GL_OPERAND0_ALPHA 0x8598 +#define GLITZ_GL_OPERAND1_ALPHA 0x8599 +#define GLITZ_GL_OPERAND2_ALPHA 0x859A +#define GLITZ_GL_RGB_SCALE 0x8573 +#define GLITZ_GL_ADD_SIGNED 0x8574 +#define GLITZ_GL_INTERPOLATE 0x8575 +#define GLITZ_GL_SUBTRACT 0x84E7 +#define GLITZ_GL_CONSTANT 0x8576 +#define GLITZ_GL_PRIMARY_COLOR 0x8577 +#define GLITZ_GL_PREVIOUS 0x8578 +#define GLITZ_GL_DOT3_RGB 0x86AE +#define GLITZ_GL_DOT3_RGBA 0x86AF + +#define GLITZ_GL_STENCIL_TEST 0x0B90 +#define GLITZ_GL_KEEP 0x1E00 +#define GLITZ_GL_REPLACE 0x1E01 +#define GLITZ_GL_INCR 0x1E02 +#define GLITZ_GL_DECR 0x1E03 + +#define GLITZ_GL_LESS 0x0201 +#define GLITZ_GL_EQUAL 0x0202 +#define GLITZ_GL_LEQUAL 0x0203 +#define GLITZ_GL_ALWAYS 0x0207 +#define GLITZ_GL_DEPTH_TEST 0x0B71 + +#define GLITZ_GL_STENCIL_BUFFER_BIT 0x00000400 +#define GLITZ_GL_VIEWPORT_BIT 0x00000800 +#define GLITZ_GL_TRANSFORM_BIT 0x00001000 +#define GLITZ_GL_COLOR_BUFFER_BIT 0x00004000 + +#define GLITZ_GL_STENCIL_INDEX 0x1901 +#define GLITZ_GL_DEPTH_COMPONENT 0x1902 + +#define GLITZ_GL_ALPHA 0x1906 +#define GLITZ_GL_RGB 0x1907 +#define GLITZ_GL_LUMINANCE 0x1909 +#define GLITZ_GL_COLOR 0x1800 +#define GLITZ_GL_DITHER 0x0BD0 +#define GLITZ_GL_RGBA 0x1908 +#define GLITZ_GL_BGR 0x80E0 +#define GLITZ_GL_BGRA 0x80E1 + +#define GLITZ_GL_ALPHA4 0x803B +#define GLITZ_GL_ALPHA8 0x803C +#define GLITZ_GL_ALPHA12 0x803D +#define GLITZ_GL_ALPHA16 0x803E +#define GLITZ_GL_LUMINANCE8 0x8040 +#define GLITZ_GL_R3_G3_B2 0x2A10 +#define GLITZ_GL_RGB4 0x804F +#define GLITZ_GL_RGB5 0x8050 +#define GLITZ_GL_RGB8 0x8051 +#define GLITZ_GL_RGB10 0x8052 +#define GLITZ_GL_RGB12 0x8053 +#define GLITZ_GL_RGB16 0x8054 +#define GLITZ_GL_RGBA2 0x8055 +#define GLITZ_GL_RGBA4 0x8056 +#define GLITZ_GL_RGB5_A1 0x8057 +#define GLITZ_GL_RGBA8 0x8058 +#define GLITZ_GL_RGB10_A2 0x8059 +#define GLITZ_GL_RGBA12 0x805A +#define GLITZ_GL_RGBA16 0x805B + +#define GLITZ_GL_FRONT_AND_BACK 0x0408 +#define GLITZ_GL_FLAT 0x1D00 +#define GLITZ_GL_SMOOTH 0x1D01 + +#define GLITZ_GL_BLEND 0x0BE2 +#define GLITZ_GL_ZERO 0x0000 +#define GLITZ_GL_ONE 0x0001 +#define GLITZ_GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GLITZ_GL_SRC_ALPHA 0x0302 +#define GLITZ_GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GLITZ_GL_DST_ALPHA 0x0304 +#define GLITZ_GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GLITZ_GL_SRC_ALPHA_SATURATE 0x0308 +#define GLITZ_GL_CONSTANT_COLOR 0x8001 + +#define GLITZ_GL_PACK_ALIGNMENT 0x0D05 +#define GLITZ_GL_PACK_LSB_FIRST 0x0D01 +#define GLITZ_GL_PACK_ROW_LENGTH 0x0D02 +#define GLITZ_GL_PACK_SKIP_PIXELS 0x0D04 +#define GLITZ_GL_PACK_SKIP_ROWS 0x0D03 +#define GLITZ_GL_UNPACK_ALIGNMENT 0x0CF5 +#define GLITZ_GL_UNPACK_LSB_FIRST 0x0CF1 +#define GLITZ_GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GLITZ_GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GLITZ_GL_UNPACK_SKIP_ROWS 0x0CF3 + +#define GLITZ_GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GLITZ_GL_FASTEST 0x1101 +#define GLITZ_GL_NICEST 0x1102 + +#define GLITZ_GL_COMPILE 0x1300 + +#define GLITZ_GL_TEXTURE_RECTANGLE 0x84F5 +#define GLITZ_GL_PROXY_TEXTURE_RECTANGLE 0x84F7 +#define GLITZ_GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8 + +#define GLITZ_GL_MIRRORED_REPEAT 0x8370 + +#define GLITZ_GL_TEXTURE0 0x84C0 +#define GLITZ_GL_TEXTURE1 0x84C1 +#define GLITZ_GL_TEXTURE2 0x84C2 +#define GLITZ_GL_ACTIVE_TEXTURE 0x84E0 +#define GLITZ_GL_MAX_TEXTURE_UNITS 0x84E2 + +#define GLITZ_GL_MULTISAMPLE 0x809D + +#define GLITZ_GL_MULTISAMPLE_FILTER_HINT 0x8534 + +#define GLITZ_GL_FRAGMENT_PROGRAM 0x8804 +#define GLITZ_GL_PROGRAM_STRING 0x8628 +#define GLITZ_GL_PROGRAM_FORMAT_ASCII 0x8875 +#define GLITZ_GL_PROGRAM_ERROR_POSITION 0x864B +#define GLITZ_GL_MAX_PROGRAM_LOCAL_PARAMETERS 0x88B4 +#define GLITZ_GL_PROGRAM_INSTRUCTIONS 0x88A0 +#define GLITZ_GL_MAX_PROGRAM_INSTRUCTIONS 0x88A1 +#define GLITZ_GL_PROGRAM_NATIVE_INSTRUCTIONS 0x88A2 +#define GLITZ_GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS 0x88A3 +#define GLITZ_GL_PROGRAM_PARAMETERS 0x88A8 +#define GLITZ_GL_MAX_PROGRAM_PARAMETERS 0x88A9 +#define GLITZ_GL_PROGRAM_NATIVE_PARAMETERS 0x88AA +#define GLITZ_GL_MAX_PROGRAM_NATIVE_PARAMETERS 0x88AB +#define GLITZ_GL_PROGRAM_UNDER_NATIVE_LIMITS 0x88B6 +#define GLITZ_GL_PROGRAM_ALU_INSTRUCTIONS 0x8805 +#define GLITZ_GL_PROGRAM_TEX_INSTRUCTIONS 0x8806 +#define GLITZ_GL_PROGRAM_TEX_INDIRECTIONS 0x8807 +#define GLITZ_GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS 0x8808 +#define GLITZ_GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS 0x8809 +#define GLITZ_GL_PROGRAM_NATIVE_TEX_INDIRECTIONS 0x880A +#define GLITZ_GL_MAX_PROGRAM_ALU_INSTRUCTIONS 0x880B +#define GLITZ_GL_MAX_PROGRAM_TEX_INSTRUCTIONS 0x880C +#define GLITZ_GL_MAX_PROGRAM_TEX_INDIRECTIONS 0x880D +#define GLITZ_GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS 0x880E +#define GLITZ_GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS 0x880F +#define GLITZ_GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS 0x8810 + +#define GLITZ_GL_ARRAY_BUFFER 0x8892 +#define GLITZ_GL_PIXEL_PACK_BUFFER 0x88EB +#define GLITZ_GL_PIXEL_UNPACK_BUFFER 0x88EC + +#define GLITZ_GL_STREAM_DRAW 0x88E0 +#define GLITZ_GL_STREAM_READ 0x88E1 +#define GLITZ_GL_STREAM_COPY 0x88E2 +#define GLITZ_GL_STATIC_DRAW 0x88E4 +#define GLITZ_GL_STATIC_READ 0x88E5 +#define GLITZ_GL_STATIC_COPY 0x88E6 +#define GLITZ_GL_DYNAMIC_DRAW 0x88E8 +#define GLITZ_GL_DYNAMIC_READ 0x88E9 +#define GLITZ_GL_DYNAMIC_COPY 0x88EA + +#define GLITZ_GL_READ_ONLY 0x88B8 +#define GLITZ_GL_WRITE_ONLY 0x88B9 +#define GLITZ_GL_READ_WRITE 0x88BA + +#define GLITZ_GL_FRAMEBUFFER 0x8D40 +#define GLITZ_GL_RENDERBUFFER 0x8D41 + +#define GLITZ_GL_COLOR_ATTACHMENT0 0x8CE0 +#define GLITZ_GL_COLOR_ATTACHMENT1 0x8CE1 +#define GLITZ_GL_DEPTH_ATTACHMENT 0x8D00 +#define GLITZ_GL_STENCIL_ATTACHMENT 0x8D20 + +#define GLITZ_GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6 +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7 +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT 0x8CD8 +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9 +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_FORMATS 0x8CDA +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB +#define GLITZ_GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC +#define GLITZ_GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD +#define GLITZ_GL_FRAMEBUFFER_STATUS_ERROR 0x8CDE + +#define GLITZ_GL_RENDERBUFFER_RED_SIZE 0x8D50 +#define GLITZ_GL_RENDERBUFFER_GREEN_SIZE 0x8D51 +#define GLITZ_GL_RENDERBUFFER_BLUE_SIZE 0x8D52 +#define GLITZ_GL_RENDERBUFFER_ALPHA_SIZE 0x8D53 +#define GLITZ_GL_RENDERBUFFER_DEPTH_SIZE 0x8D54 +#define GLITZ_GL_RENDERBUFFER_STENCIL_SIZE 0x8D55 + +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_API_ATTRIBUTE * glitz_gl_disable_t) + (glitz_gl_enum_t cap); +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_API_ATTRIBUTE * glitz_gl_get_string_t) + (glitz_gl_enum_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_API_ATTRIBUTE * glitz_gl_disable_client_state_t) + (glitz_gl_enum_t cap); +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_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_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_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_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_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_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_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_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_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_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_API_ATTRIBUTE * glitz_gl_blend_func_t) + (glitz_gl_enum_t sfactor, glitz_gl_enum_t dfactor); +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_API_ATTRIBUTE * glitz_gl_clear_t) + (glitz_gl_bitfield_t mask); +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_API_ATTRIBUTE * glitz_gl_clear_stencil_t) + (glitz_gl_int_t s); +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_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_API_ATTRIBUTE * glitz_gl_push_attrib_t) + (glitz_gl_bitfield_t mask); +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_API_ATTRIBUTE * glitz_gl_matrix_mode_t) + (glitz_gl_enum_t mode); +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_API_ATTRIBUTE * glitz_gl_pop_matrix_t) + (glitz_gl_void_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_API_ATTRIBUTE * glitz_gl_load_matrix_f_t) + (const glitz_gl_float_t *m); +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_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_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_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_API_ATTRIBUTE * glitz_gl_read_buffer_t) + (glitz_gl_enum_t mode); +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_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_API_ATTRIBUTE * glitz_gl_flush_t) + (glitz_gl_void_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_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_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_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_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_API_ATTRIBUTE * glitz_gl_hint_t) + (glitz_gl_enum_t target, glitz_gl_enum_t mode); +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_API_ATTRIBUTE * glitz_gl_polygon_mode_t) + (glitz_gl_enum_t face, glitz_gl_enum_t mode); +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_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_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_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_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_API_ATTRIBUTE * glitz_gl_gen_textures_t) + (glitz_gl_sizei_t n, glitz_gl_uint_t *textures); +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_API_ATTRIBUTE * glitz_gl_bind_texture_t) + (glitz_gl_enum_t target, glitz_gl_uint_t texture); +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_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_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_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_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_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_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_API_ATTRIBUTE * glitz_gl_active_texture_t) + (glitz_gl_enum_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_API_ATTRIBUTE * glitz_gl_gen_programs_t) + (glitz_gl_sizei_t, glitz_gl_uint_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_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_API_ATTRIBUTE * glitz_gl_bind_program_t) + (glitz_gl_enum_t, glitz_gl_uint_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_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_API_ATTRIBUTE * glitz_gl_gen_buffers_t) + (glitz_gl_sizei_t, glitz_gl_uint_t *buffers); +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_API_ATTRIBUTE * glitz_gl_bind_buffer_t) + (glitz_gl_enum_t, glitz_gl_uint_t buffer); +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_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_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_API_ATTRIBUTE * glitz_gl_map_buffer_t) + (glitz_gl_enum_t, glitz_gl_enum_t); +typedef glitz_gl_boolean_t (GLITZ_GL_API_ATTRIBUTE * glitz_gl_unmap_buffer_t) + (glitz_gl_enum_t); +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_framebuffers_t) + (glitz_gl_sizei_t, glitz_gl_uint_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_API_ATTRIBUTE * glitz_gl_bind_framebuffer_t) + (glitz_gl_enum_t, glitz_gl_uint_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_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_API_ATTRIBUTE * glitz_gl_check_framebuffer_status_t) + (glitz_gl_enum_t); +typedef void (GLITZ_GL_API_ATTRIBUTE * glitz_gl_gen_renderbuffers_t) + (glitz_gl_sizei_t, glitz_gl_uint_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_API_ATTRIBUTE * glitz_gl_bind_renderbuffer_t) + (glitz_gl_enum_t, glitz_gl_uint_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_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/glucose/glitz_glucose.h b/glucose/glitz_glucose.h new file mode 100644 index 000000000..26540b727 --- /dev/null +++ b/glucose/glitz_glucose.h @@ -0,0 +1,179 @@ +/* + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * Author: David Reveman + * + * This file has been modified from the GLitz GLX code for use with glucose + * by: Alan Hourihane + * + **************************************************************************/ + +#ifndef GLITZ_GLUCOSE_H_INCLUDED +#define GLITZ_GLUCOSE_H_INCLUDED + +#include "glitzint.h" + +typedef glitz_function_pointer_t (* glitz_glucose_get_proc_address_t) + (const glitz_gl_ubyte_t *); +typedef Bool (* glitz_glucose_make_context_current_t) + (__GLXcontext *baseContext); +typedef __GLXcontext (* glitz_glucose_create_new_context_t) + (__GLXscreen *display, int config, int render_type, + __GLXcontext share_list, Bool direct); +typedef void *(* glitz_glucose_copy_sub_buffer_t) + (__GLXscreen *display, __GLXdrawable *draw, int x, int y, int w, int h); + +typedef struct _glitz_glucose_drawable glitz_glucose_drawable_t; +typedef struct _glitz_glucose_screen_info_t glitz_glucose_screen_info_t; +typedef struct _glitz_glucose_display_info_t glitz_glucose_display_info_t; + +typedef struct _glitz_glucose_static_proc_address_list_t { + glitz_glucose_get_proc_address_t get_proc_address; + glitz_glucose_make_context_current_t make_context_current; + glitz_glucose_create_new_context_t create_new_context; + glitz_glucose_copy_sub_buffer_t copy_sub_buffer; +} glitz_glucose_static_proc_address_list_t; + +typedef struct _glitz_glucose_thread_info_t { + glitz_glucose_display_info_t **displays; + int n_displays; + glitz_context_t *cctx; +} glitz_glucose_thread_info_t; + +struct _glitz_glucose_display_info_t { + glitz_glucose_thread_info_t *thread_info; + __GLXscreen *display; + glitz_glucose_screen_info_t **screens; + int n_screens; +}; + +typedef struct _glitz_glucose_context_info_t { + glitz_glucose_drawable_t *drawable; + glitz_surface_t *surface; + glitz_constraint_t constraint; +} glitz_glucose_context_info_t; + +typedef struct _glitz_glucose_context_t { + glitz_context_t base; + __GLXcontext *context; + glitz_format_id_t id; + glitz_backend_t backend; + glitz_bool_t initialized; +} glitz_glucose_context_t; + +struct _glitz_glucose_screen_info_t { + __GLXscreen *screen; + glitz_glucose_display_info_t *display_info; + int drawables; + glitz_int_drawable_format_t *formats; + int n_formats; + glitz_glucose_context_t **contexts; + int n_contexts; + glitz_glucose_context_info_t context_stack[GLITZ_CONTEXT_STACK_SIZE]; + int context_stack_size; + __GLXcontext *root_context; + unsigned long glx_feature_mask; + glitz_gl_float_t glx_version; + glitz_glucose_static_proc_address_list_t glx; + glitz_program_map_t program_map; +}; + +struct _glitz_glucose_drawable { + glitz_drawable_t base; + + glitz_glucose_screen_info_t *screen_info; + glitz_glucose_context_t *context; + __GLXdrawable *drawable; + int width; + int height; +}; + +extern void +glitz_glucose_query_extensions (glitz_glucose_screen_info_t *screen_info, + glitz_gl_float_t glx_version); + +extern glitz_glucose_screen_info_t * +glitz_glucose_screen_info_get (__GLXscreen *display); + +extern glitz_function_pointer_t +glitz_glucose_get_proc_address (const char *name, + void *closure); + +extern glitz_glucose_context_t * +glitz_glucose_context_get (glitz_glucose_screen_info_t *screen_info, + glitz_drawable_format_t *format); + +extern void +glitz_glucose_context_destroy (glitz_glucose_screen_info_t *screen_info, + glitz_glucose_context_t *context); + +extern void +glitz_glucose_query_formats (glitz_glucose_screen_info_t *screen_info); + +extern glitz_bool_t +_glitz_glucose_drawable_update_size (glitz_glucose_drawable_t *drawable, + int width, + int height); + +extern glitz_bool_t +glitz_glucose_push_current (void *abstract_drawable, + glitz_surface_t *surface, + glitz_constraint_t constraint, + glitz_bool_t *restore_state); + +extern glitz_surface_t * +glitz_glucose_pop_current (void *abstract_drawable); + +void +glitz_glucose_make_current (void *abstract_drawable, + glitz_constraint_t constraint); + +extern glitz_status_t +glitz_glucose_make_current_read (void *abstract_surface); + +extern void +glitz_glucose_destroy (void *abstract_drawable); + +extern glitz_bool_t +glitz_glucose_swap_buffers (void *abstract_drawable); + +extern glitz_bool_t +glitz_glucose_copy_sub_buffer (void *abstract_drawable, + int x, + int y, + int width, + int height); + +glitz_drawable_format_t * +glitz_glucose_find_window_format (__GLXscreen *screen, + unsigned long mask, + const glitz_drawable_format_t *templ, + int count); + +glitz_drawable_t * +glitz_glucose_create_drawable_for_window (__GLXscreen *screen, + glitz_drawable_format_t *format, + __GLXdrawable *window, + unsigned int width, + unsigned int height); + +#endif /* GLITZ_GLUCOSE_H_INCLUDED */ diff --git a/glucose/glitzint.h b/glucose/glitzint.h new file mode 100644 index 000000000..1a04799aa --- /dev/null +++ b/glucose/glitzint.h @@ -0,0 +1,995 @@ +/* + * 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 name 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. + * + * Author: David Reveman + */ + +#ifndef GLITZINT_H_INCLUDED +#define GLITZINT_H_INCLUDED + +#ifdef _MSC_VER +#define _USE_MATH_DEFINES +#endif + +#include +#include +#include +#include + +#include "glitz.h" + +#if defined(__SVR4) && defined(__sun) +# include +#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 +# else +# include +# endif +#endif + +#if defined(__APPLE__) || defined(__sun__) +# define floorf(a) floor (a) +# define ceilf(a) ceil (a) +# define sinf(a) sin (a) +# define cosf(a) cos (a) +# define tanf(a) tan (a) +# define asinf(a) asin (a) +# define acosf(a) acos (a) +# define atanf(a) atan (a) +# define atan2f(a, b) atan2 (a, b) +# define sqrtf(a) sqrt (a) +#endif + +#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) +#define __internal_linkage __attribute__((__visibility__("hidden"))) +#else +#define __internal_linkage +#endif + +#ifndef __GNUC__ +#define __attribute__(x) +#endif + +#define GLITZ_STATUS_NO_MEMORY_MASK (1L << 0) +#define GLITZ_STATUS_BAD_COORDINATE_MASK (1L << 1) +#define GLITZ_STATUS_NOT_SUPPORTED_MASK (1L << 2) +#define GLITZ_STATUS_CONTENT_DESTROYED_MASK (1L << 3) + +#define GLITZ_DRAWABLE_FORMAT_ALL_EXCEPT_ID_MASK ((1L << 11) - 2) + +#include "glitz_gl.h" + +#define GLITZ_CONTEXT_STACK_SIZE 16 + +typedef struct _glitz_gl_proc_address_list_t { + + /* core */ + glitz_gl_enable_t enable; + glitz_gl_disable_t disable; + glitz_gl_get_error_t get_error; + glitz_gl_get_string_t get_string; + glitz_gl_enable_client_state_t enable_client_state; + glitz_gl_disable_client_state_t disable_client_state; + glitz_gl_vertex_pointer_t vertex_pointer; + glitz_gl_tex_coord_pointer_t tex_coord_pointer; + glitz_gl_draw_arrays_t draw_arrays; + glitz_gl_tex_env_f_t tex_env_f; + glitz_gl_tex_env_fv_t tex_env_fv; + glitz_gl_tex_gen_i_t tex_gen_i; + glitz_gl_tex_gen_fv_t tex_gen_fv; + glitz_gl_color_4us_t color_4us; + glitz_gl_color_4f_t color_4f; + glitz_gl_scissor_t scissor; + glitz_gl_blend_func_t blend_func; + glitz_gl_clear_t clear; + glitz_gl_clear_color_t clear_color; + glitz_gl_clear_stencil_t clear_stencil; + glitz_gl_stencil_func_t stencil_func; + glitz_gl_stencil_op_t stencil_op; + glitz_gl_push_attrib_t push_attrib; + glitz_gl_pop_attrib_t pop_attrib; + glitz_gl_matrix_mode_t matrix_mode; + glitz_gl_push_matrix_t push_matrix; + glitz_gl_pop_matrix_t pop_matrix; + glitz_gl_load_identity_t load_identity; + glitz_gl_load_matrix_f_t load_matrix_f; + glitz_gl_depth_range_t depth_range; + glitz_gl_viewport_t viewport; + glitz_gl_raster_pos_2f_t raster_pos_2f; + glitz_gl_bitmap_t bitmap; + glitz_gl_read_buffer_t read_buffer; + glitz_gl_draw_buffer_t draw_buffer; + glitz_gl_copy_pixels_t copy_pixels; + glitz_gl_flush_t flush; + glitz_gl_finish_t finish; + glitz_gl_pixel_store_i_t pixel_store_i; + glitz_gl_ortho_t ortho; + glitz_gl_scale_f_t scale_f; + glitz_gl_translate_f_t translate_f; + glitz_gl_hint_t hint; + glitz_gl_depth_mask_t depth_mask; + glitz_gl_polygon_mode_t polygon_mode; + glitz_gl_shade_model_t shade_model; + glitz_gl_color_mask_t color_mask; + glitz_gl_read_pixels_t read_pixels; + glitz_gl_get_tex_image_t get_tex_image; + glitz_gl_tex_sub_image_2d_t tex_sub_image_2d; + glitz_gl_gen_textures_t gen_textures; + glitz_gl_delete_textures_t delete_textures; + glitz_gl_bind_texture_t bind_texture; + glitz_gl_tex_image_2d_t tex_image_2d; + glitz_gl_tex_parameter_i_t tex_parameter_i; + glitz_gl_tex_parameter_fv_t tex_parameter_fv; + glitz_gl_get_tex_level_parameter_iv_t get_tex_level_parameter_iv; + glitz_gl_copy_tex_sub_image_2d_t copy_tex_sub_image_2d; + glitz_gl_get_integer_v_t get_integer_v; + + /* extensions */ + glitz_gl_blend_color_t blend_color; + glitz_gl_active_texture_t active_texture; + glitz_gl_client_active_texture_t client_active_texture; + glitz_gl_multi_draw_arrays_t multi_draw_arrays; + glitz_gl_gen_programs_t gen_programs; + glitz_gl_delete_programs_t delete_programs; + glitz_gl_program_string_t program_string; + glitz_gl_bind_program_t bind_program; + glitz_gl_program_local_param_4fv_t program_local_param_4fv; + glitz_gl_get_program_iv_t get_program_iv; + glitz_gl_gen_buffers_t gen_buffers; + glitz_gl_delete_buffers_t delete_buffers; + glitz_gl_bind_buffer_t bind_buffer; + glitz_gl_buffer_data_t buffer_data; + glitz_gl_buffer_sub_data_t buffer_sub_data; + glitz_gl_get_buffer_sub_data_t get_buffer_sub_data; + glitz_gl_map_buffer_t map_buffer; + glitz_gl_unmap_buffer_t unmap_buffer; + glitz_gl_gen_framebuffers_t gen_framebuffers; + glitz_gl_delete_framebuffers_t delete_framebuffers; + glitz_gl_bind_framebuffer_t bind_framebuffer; + glitz_gl_framebuffer_renderbuffer_t framebuffer_renderbuffer; + glitz_gl_framebuffer_texture_2d_t framebuffer_texture_2d; + glitz_gl_check_framebuffer_status_t check_framebuffer_status; + glitz_gl_gen_renderbuffers_t gen_renderbuffers; + glitz_gl_delete_renderbuffers_t delete_renderbuffers; + glitz_gl_bind_renderbuffer_t bind_renderbuffer; + glitz_gl_renderbuffer_storage_t renderbuffer_storage; + glitz_gl_get_renderbuffer_parameter_iv_t get_renderbuffer_parameter_iv; +} glitz_gl_proc_address_list_t; + +typedef int glitz_surface_type_t; + +#define GLITZ_SURFACE_TYPE_NA -1 +#define GLITZ_SURFACE_TYPE_NULL 0 +#define GLITZ_SURFACE_TYPE_ARGB 1 +#define GLITZ_SURFACE_TYPE_ARGBC 2 +#define GLITZ_SURFACE_TYPE_ARGBF 3 +#define GLITZ_SURFACE_TYPE_SOLID 4 +#define GLITZ_SURFACE_TYPE_SOLIDC 5 +#define GLITZ_SURFACE_TYPES 6 + +typedef int glitz_combine_type_t; + +#define GLITZ_COMBINE_TYPE_NA 0 +#define GLITZ_COMBINE_TYPE_ARGB 1 +#define GLITZ_COMBINE_TYPE_ARGB_ARGB 2 +#define GLITZ_COMBINE_TYPE_ARGB_ARGBC 3 +#define GLITZ_COMBINE_TYPE_ARGB_ARGBF 4 +#define GLITZ_COMBINE_TYPE_ARGB_SOLID 5 +#define GLITZ_COMBINE_TYPE_ARGB_SOLIDC 6 +#define GLITZ_COMBINE_TYPE_ARGBF 7 +#define GLITZ_COMBINE_TYPE_ARGBF_ARGB 8 +#define GLITZ_COMBINE_TYPE_ARGBF_ARGBC 9 +#define GLITZ_COMBINE_TYPE_ARGBF_ARGBF 10 +#define GLITZ_COMBINE_TYPE_ARGBF_SOLID 11 +#define GLITZ_COMBINE_TYPE_ARGBF_SOLIDC 12 +#define GLITZ_COMBINE_TYPE_SOLID 13 +#define GLITZ_COMBINE_TYPE_SOLID_ARGB 14 +#define GLITZ_COMBINE_TYPE_SOLID_ARGBC 15 +#define GLITZ_COMBINE_TYPE_SOLID_ARGBF 16 +#define GLITZ_COMBINE_TYPE_SOLID_SOLID 17 +#define GLITZ_COMBINE_TYPE_SOLID_SOLIDC 18 +#define GLITZ_COMBINE_TYPES 19 + +#define GLITZ_TEXTURE_NONE 0 +#define GLITZ_TEXTURE_2D 1 +#define GLITZ_TEXTURE_RECT 2 +#define GLITZ_TEXTURE_LAST 3 + +#define GLITZ_FP_CONVOLUTION 0 +#define GLITZ_FP_LINEAR_GRADIENT_TRANSPARENT 1 +#define GLITZ_FP_LINEAR_GRADIENT_NEAREST 2 +#define GLITZ_FP_LINEAR_GRADIENT_REPEAT 3 +#define GLITZ_FP_LINEAR_GRADIENT_REFLECT 4 +#define GLITZ_FP_RADIAL_GRADIENT_TRANSPARENT 5 +#define GLITZ_FP_RADIAL_GRADIENT_NEAREST 6 +#define GLITZ_FP_RADIAL_GRADIENT_REPEAT 7 +#define GLITZ_FP_RADIAL_GRADIENT_REFLECT 8 +#define GLITZ_FP_COLORSPACE_YV12 9 +#define GLITZ_FP_UNSUPPORTED 10 +#define GLITZ_FP_TYPES 11 + +typedef struct _glitz_program_t { + glitz_gl_int_t *name; + unsigned int size; +} glitz_program_t; + +typedef struct _glitz_filter_map_t { + glitz_program_t fp[GLITZ_TEXTURE_LAST][GLITZ_TEXTURE_LAST][2]; +} glitz_filter_map_t; + +typedef struct _glitz_program_map_t { + glitz_filter_map_t filters[GLITZ_COMBINE_TYPES][GLITZ_FP_TYPES]; +} glitz_program_map_t; + +typedef enum { + GLITZ_NONE, + GLITZ_ANY_CONTEXT_CURRENT, + GLITZ_CONTEXT_CURRENT, + GLITZ_DRAWABLE_CURRENT +} glitz_constraint_t; + +typedef struct _glitz_region_t { + glitz_box_t extents; + glitz_box_t *box; + int n_box; + void *data; + int size; +} glitz_region_t; + +extern glitz_status_t __internal_linkage +glitz_region_union (glitz_region_t *region, + glitz_box_t *box); + +#define GLITZ_DRAWABLE_TYPE_WINDOW_MASK (1L << 0) +#define GLITZ_DRAWABLE_TYPE_PBUFFER_MASK (1L << 1) +#define GLITZ_DRAWABLE_TYPE_FBO_MASK (1L << 2) + +#define GLITZ_INT_FORMAT_WINDOW_MASK (1L << 17) +#define GLITZ_INT_FORMAT_PBUFFER_MASK (1L << 18) +#define GLITZ_INT_FORMAT_FBO_MASK (1L << 19) + +typedef struct _glitz_int_drawable_format_t { + glitz_drawable_format_t d; + unsigned int types; + int caveat; + union { + void *ptr; + long val; + unsigned long uval; + void *(*fptr) (void); + } u; +} glitz_int_drawable_format_t; + +typedef struct glitz_backend { + glitz_drawable_t * + (*create_pbuffer) (void *drawable, + glitz_drawable_format_t *format, + unsigned int width, + unsigned int height); + + void + (*destroy) (void *drawable); + + glitz_bool_t + (*push_current) (void *drawable, + glitz_surface_t *surface, + glitz_constraint_t constraint, + glitz_bool_t *restore_state); + + glitz_surface_t * + (*pop_current) (void *drawable); + + void + (*attach_notify) (void *drawable, + glitz_surface_t *surface); + + void + (*detach_notify) (void *drawable, + glitz_surface_t *surface); + + glitz_bool_t + (*swap_buffers) (void *drawable); + + glitz_bool_t + (*copy_sub_buffer) (void *drawable, + int x, + int y, + int width, + int height); + + glitz_context_t * + (*create_context) (void *drawable, + glitz_drawable_format_t *format); + + void + (*destroy_context) (void *context); + + void + (*copy_context) (void *src, + void *dst, + unsigned long mask); + + void + (*make_current) (void *drawable, + void *context); + + void + (*draw_buffer) (void *drawable, + const glitz_gl_enum_t buffer); + + void + (*read_buffer) (void *drawable, + const glitz_gl_enum_t buffer); + + glitz_function_pointer_t + (*get_proc_address) (void *context, + const char *name); + + glitz_gl_proc_address_list_t *gl; + + glitz_int_drawable_format_t *drawable_formats; + int n_drawable_formats; + + glitz_gl_int_t *texture_formats; + glitz_format_t *formats; + int n_formats; + + glitz_gl_float_t gl_version; + glitz_gl_int_t max_viewport_dims[2]; + glitz_gl_int_t max_texture_2d_size; + glitz_gl_int_t max_texture_rect_size; + unsigned long feature_mask; + + glitz_program_map_t *program_map; +} glitz_backend_t; + +struct _glitz_drawable { + glitz_backend_t *backend; + int ref_count; + glitz_int_drawable_format_t *format; + int width, height; + glitz_rectangle_t viewport; + glitz_bool_t update_all; + glitz_bool_t flushed; + glitz_bool_t finished; + glitz_surface_t *front; + glitz_surface_t *back; +}; + +#define GLITZ_GL_DRAWABLE(drawable) \ + glitz_gl_proc_address_list_t *gl = (drawable)->backend->gl; + +#define DRAWABLE_IS_FBO(drawable) \ + ((drawable)->format->types == GLITZ_DRAWABLE_TYPE_FBO_MASK) + +typedef struct _glitz_vec2_t { + glitz_float_t v[2]; +} glitz_vec2_t; + +typedef struct _glitz_vec4_t { + glitz_float_t v[4]; +} glitz_vec4_t; + +#define GLITZ_TEXTURE_FLAG_ALLOCATED_MASK (1L << 0) +#define GLITZ_TEXTURE_FLAG_CLAMPABLE_MASK (1L << 1) +#define GLITZ_TEXTURE_FLAG_REPEATABLE_MASK (1L << 2) +#define GLITZ_TEXTURE_FLAG_PADABLE_MASK (1L << 3) +#define GLITZ_TEXTURE_FLAG_INVALID_SIZE_MASK (1L << 4) + +#define TEXTURE_ALLOCATED(texture) \ + ((texture)->flags & GLITZ_TEXTURE_FLAG_ALLOCATED_MASK) + +#define TEXTURE_CLAMPABLE(texture) \ + ((texture)->flags & GLITZ_TEXTURE_FLAG_CLAMPABLE_MASK) + +#define TEXTURE_REPEATABLE(texture) \ + ((texture)->flags & GLITZ_TEXTURE_FLAG_REPEATABLE_MASK) + +#define TEXTURE_PADABLE(texture) \ + ((texture)->flags & GLITZ_TEXTURE_FLAG_PADABLE_MASK) + +#define TEXTURE_INVALID_SIZE(texture) \ + ((texture)->flags & GLITZ_TEXTURE_FLAG_INVALID_SIZE_MASK) + +typedef struct _glitz_texture_parameters { + glitz_gl_enum_t filter[2]; + glitz_gl_enum_t wrap[2]; + glitz_color_t border_color; +} glitz_texture_parameters_t; + +typedef struct _glitz_texture { + glitz_gl_uint_t name; + glitz_gl_enum_t target; + glitz_gl_int_t format; + glitz_fourcc_t fourcc; + unsigned long flags; + + glitz_texture_parameters_t param; + + int width; + int height; + + glitz_box_t box; + + glitz_float_t texcoord_width_unit; + glitz_float_t texcoord_height_unit; +} glitz_texture_t; + +struct _glitz_texture_object { + glitz_surface_t *surface; + int ref_count; + glitz_texture_parameters_t param; +}; + +struct _glitz_buffer { + glitz_gl_uint_t name; + glitz_gl_enum_t target; + void *data; + int owns_data; + int ref_count; + glitz_surface_t *front_surface; + glitz_surface_t *back_surface; + glitz_drawable_t *drawable; +}; + +struct _glitz_multi_array { + int ref_count; + int size; + int n_arrays; + int *first; + int *sizes; + int *count; + int *span, *current_span; + glitz_vec2_t *off; +}; + +typedef struct _glitz_int_coordinate { + glitz_gl_enum_t type; + int size, offset; +} glitz_int_coordinate_t; + +typedef struct _glitz_vertex_info { + glitz_gl_enum_t prim; + glitz_gl_enum_t type; + glitz_int_coordinate_t src; + glitz_int_coordinate_t mask; +} glitz_vertex_info_t; + +typedef struct _glitz_bitmap_info { + glitz_bool_t top_down; + glitz_gl_int_t pad; + glitz_gl_ubyte_t *base; +} glitz_bitmap_info_t; + +typedef struct _glitz_geometry { + glitz_geometry_type_t type; + glitz_buffer_t *buffer; + glitz_gl_sizei_t stride; + glitz_gl_float_t data[8]; + glitz_gl_int_t first; + glitz_gl_int_t size; + glitz_gl_sizei_t count; + glitz_vec2_t off; + glitz_multi_array_t *array; + unsigned long attributes; + union { + glitz_vertex_info_t v; + glitz_bitmap_info_t b; + } u; +} glitz_geometry_t; + +#define GLITZ_SURFACE_FLAG_SOLID_MASK (1L << 0) +#define GLITZ_SURFACE_FLAG_REPEAT_MASK (1L << 1) +#define GLITZ_SURFACE_FLAG_MIRRORED_MASK (1L << 2) +#define GLITZ_SURFACE_FLAG_PAD_MASK (1L << 3) +#define GLITZ_SURFACE_FLAG_COMPONENT_ALPHA_MASK (1L << 4) +#define GLITZ_SURFACE_FLAG_DITHER_MASK (1L << 5) +#define GLITZ_SURFACE_FLAG_MULTISAMPLE_MASK (1L << 6) +#define GLITZ_SURFACE_FLAG_NICEST_MULTISAMPLE_MASK (1L << 7) +#define GLITZ_SURFACE_FLAG_SOLID_DAMAGE_MASK (1L << 8) +#define GLITZ_SURFACE_FLAG_FRAGMENT_FILTER_MASK (1L << 9) +#define GLITZ_SURFACE_FLAG_LINEAR_TRANSFORM_FILTER_MASK (1L << 10) +#define GLITZ_SURFACE_FLAG_IGNORE_WRAP_MASK (1L << 11) +#define GLITZ_SURFACE_FLAG_EYE_COORDS_MASK (1L << 12) +#define GLITZ_SURFACE_FLAG_TRANSFORM_MASK (1L << 13) +#define GLITZ_SURFACE_FLAG_PROJECTIVE_TRANSFORM_MASK (1L << 14) +#define GLITZ_SURFACE_FLAG_GEN_S_COORDS_MASK (1L << 15) +#define GLITZ_SURFACE_FLAG_GEN_T_COORDS_MASK (1L << 16) + +#define GLITZ_SURFACE_FLAGS_GEN_COORDS_MASK \ + (GLITZ_SURFACE_FLAG_GEN_S_COORDS_MASK | \ + GLITZ_SURFACE_FLAG_GEN_T_COORDS_MASK) + +#define SURFACE_SOLID(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_SOLID_MASK) + +#define SURFACE_REPEAT(surface) \ + (((surface)->flags & GLITZ_SURFACE_FLAG_REPEAT_MASK) && \ + (!((surface)->flags & GLITZ_SURFACE_FLAG_IGNORE_WRAP_MASK))) + +#define SURFACE_MIRRORED(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_MIRRORED_MASK) + +#define SURFACE_PAD(surface) \ + (((surface)->flags & GLITZ_SURFACE_FLAG_PAD_MASK) && \ + (!((surface)->flags & GLITZ_SURFACE_FLAG_IGNORE_WRAP_MASK))) + +#define SURFACE_COMPONENT_ALPHA(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_COMPONENT_ALPHA_MASK) + +#define SURFACE_DITHER(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_DITHER_MASK) + +#define SURFACE_SOLID_DAMAGE(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_SOLID_DAMAGE_MASK) + +#define SURFACE_FRAGMENT_FILTER(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_FRAGMENT_FILTER_MASK) + +#define SURFACE_LINEAR_TRANSFORM_FILTER(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_LINEAR_TRANSFORM_FILTER_MASK) + +#define SURFACE_EYE_COORDS(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_EYE_COORDS_MASK) + +#define SURFACE_TRANSFORM(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_TRANSFORM_MASK) + +#define SURFACE_PROJECTIVE_TRANSFORM(surface) \ + ((surface)->flags & GLITZ_SURFACE_FLAG_PROJECTIVE_TRANSFORM_MASK) + +typedef struct _glitz_filter_params_t glitz_filter_params_t; + +typedef struct _glitz_matrix { + glitz_float_t t[16]; + glitz_float_t m[16]; +} glitz_matrix_t; + +#define GLITZ_DAMAGE_TEXTURE_MASK (1 << 0) +#define GLITZ_DAMAGE_DRAWABLE_MASK (1 << 1) +#define GLITZ_DAMAGE_SOLID_MASK (1 << 2) + +struct _glitz_surface { + int ref_count; + glitz_format_t *format; + glitz_texture_t texture; + glitz_drawable_t *drawable; + glitz_drawable_t *attached; + unsigned long status_mask; + glitz_filter_t filter; + glitz_filter_params_t *filter_params; + glitz_matrix_t *transform; + int x, y; + glitz_box_t box; + short x_clip, y_clip; + glitz_box_t *clip; + int n_clip; + glitz_gl_enum_t buffer; + unsigned long flags; + glitz_color_t solid; + glitz_geometry_t geometry; + void *arrays; + int n_arrays; + int *first; + unsigned int *count; + glitz_vec2_t *off; + int default_first; + unsigned int default_count; + glitz_vec2_t default_off; + int *primcount; + glitz_region_t texture_damage; + glitz_region_t drawable_damage; + unsigned int flip_count; + glitz_gl_int_t fb; +}; + +#define GLITZ_GL_SURFACE(surface) \ + glitz_gl_proc_address_list_t *gl = (surface)->drawable->backend->gl; + +struct _glitz_context { + int ref_count; + glitz_drawable_t *drawable; + void *closure; + glitz_lose_current_function_t lose_current; +}; + +typedef struct _glitz_composite_op_t glitz_composite_op_t; + +typedef void (*glitz_combine_function_t) (glitz_composite_op_t *); + +typedef struct _glitz_combine_t { + glitz_combine_type_t type; + glitz_combine_function_t enable; + int texture_units; + int source_shader; +} glitz_combine_t; + +struct _glitz_composite_op_t { + glitz_combine_type_t type; + glitz_combine_t *combine; + glitz_gl_proc_address_list_t *gl; + glitz_operator_t render_op; + glitz_surface_t *src; + glitz_surface_t *mask; + glitz_surface_t *dst; + glitz_color_t *solid; + glitz_color_t alpha_mask; + int per_component; + glitz_gl_uint_t fp; + int count; +}; + +typedef struct _glitz_extension_map { + glitz_gl_float_t version; + char *name; + int mask; +} glitz_extension_map; + +extern void __internal_linkage +glitz_set_operator (glitz_gl_proc_address_list_t *gl, + glitz_operator_t op); + +unsigned long +glitz_extensions_query (glitz_gl_float_t version, + const char *extensions_string, + glitz_extension_map *extensions_map); + +typedef glitz_function_pointer_t (* glitz_get_proc_address_proc_t) + (const char *name, void *closure); + +void +glitz_backend_init (glitz_backend_t *backend, + glitz_get_proc_address_proc_t get_proc_address, + void *closure); + +extern unsigned int __internal_linkage +glitz_uint_to_power_of_two (unsigned int x); + +extern void __internal_linkage +glitz_set_raster_pos (glitz_gl_proc_address_list_t *gl, + glitz_float_t x, + glitz_float_t y); + +extern void __internal_linkage +glitz_clamp_value (glitz_float_t *value, + glitz_float_t min, + glitz_float_t max); + +void +glitz_initiate_state (glitz_gl_proc_address_list_t *gl); + +void +glitz_create_surface_formats (glitz_gl_proc_address_list_t *gl, + glitz_format_t **formats, + glitz_gl_int_t **texture_formats, + int *n_formats, + unsigned long features); + +extern void __internal_linkage +_glitz_add_drawable_formats (glitz_gl_proc_address_list_t *gl, + unsigned long feature_mask, + glitz_int_drawable_format_t **formats, + int *n_formats); + +void +glitz_drawable_format_copy (const glitz_drawable_format_t *src, + glitz_drawable_format_t *dst, + unsigned long mask); + +glitz_drawable_format_t * +glitz_drawable_format_find (glitz_int_drawable_format_t *formats, + int n_formats, + unsigned long mask, + const glitz_int_drawable_format_t *templ, + int count); + +void +glitz_texture_init (glitz_texture_t *texture, + int width, + int height, + glitz_gl_int_t texture_format, + glitz_fourcc_t fourcc, + unsigned long feature_mask, + glitz_bool_t unnormalized); + +void +glitz_texture_fini (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture); + +void +glitz_texture_size_check (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + glitz_gl_int_t max_2d, + glitz_gl_int_t max_rect); + +void +glitz_texture_allocate (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture); + +extern void __internal_linkage +glitz_texture_ensure_parameters (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + glitz_texture_parameters_t *param); + +void +glitz_texture_bind (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture); + +void +glitz_texture_unbind (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture); + +void +glitz_texture_copy_drawable (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + glitz_drawable_t *drawable, + int x_drawable, + int y_drawable, + int width, + int height, + int x_texture, + int y_texture); + +void +glitz_texture_set_tex_gen (glitz_gl_proc_address_list_t *gl, + glitz_texture_t *texture, + glitz_geometry_t *geometry, + int x_src, + int y_src, + unsigned long flags, + glitz_int_coordinate_t *coord); + +extern void __internal_linkage +_glitz_surface_sync_texture (glitz_surface_t *surface); + +extern glitz_texture_t __internal_linkage * +glitz_surface_get_texture (glitz_surface_t *surface, + glitz_bool_t allocate); + +extern void __internal_linkage +glitz_surface_sync_solid (glitz_surface_t *surface); + +extern glitz_bool_t __internal_linkage +glitz_surface_push_current (glitz_surface_t *surface, + glitz_constraint_t constraint); + +extern void __internal_linkage +glitz_surface_pop_current (glitz_surface_t *surface); + +extern void __internal_linkage +glitz_surface_damage (glitz_surface_t *surface, + glitz_box_t *box, + int what); + +extern void __internal_linkage +glitz_surface_sync_drawable (glitz_surface_t *surface); + +extern void __internal_linkage +glitz_surface_status_add (glitz_surface_t *surface, + int flags); + +extern unsigned long __internal_linkage +glitz_status_to_status_mask (glitz_status_t status); + +extern glitz_status_t __internal_linkage +glitz_status_pop_from_mask (unsigned long *mask); + +void +glitz_program_map_init (glitz_program_map_t *map); + +void +glitz_program_map_fini (glitz_gl_proc_address_list_t *gl, + glitz_program_map_t *map); + +extern glitz_gl_uint_t __internal_linkage +glitz_get_fragment_program (glitz_composite_op_t *op, + int fp_type, + int id); + +extern void __internal_linkage +glitz_composite_op_init (glitz_composite_op_t *op, + glitz_operator_t render_op, + glitz_surface_t *src, + glitz_surface_t *mask, + glitz_surface_t *dst); + +extern void __internal_linkage +glitz_composite_enable (glitz_composite_op_t *op); + +extern void __internal_linkage +glitz_composite_disable (glitz_composite_op_t *op); + +extern void __internal_linkage * +glitz_buffer_bind (glitz_buffer_t *buffer, + glitz_gl_enum_t target); + +extern void __internal_linkage +glitz_buffer_unbind (glitz_buffer_t *buffer); + +extern glitz_status_t __internal_linkage +glitz_filter_set_params (glitz_surface_t *surface, + glitz_filter_t filter, + glitz_fixed16_16_t *params, + int n_params); + +extern void __internal_linkage +glitz_filter_set_type (glitz_surface_t *surface, + glitz_filter_t filter); + +extern glitz_gl_uint_t __internal_linkage +glitz_filter_get_vertex_program (glitz_surface_t *surface, + glitz_composite_op_t *op); + +extern glitz_gl_uint_t __internal_linkage +glitz_filter_get_fragment_program (glitz_surface_t *surface, + glitz_composite_op_t *op); + +extern void __internal_linkage +glitz_filter_enable (glitz_surface_t *surface, + glitz_composite_op_t *op); + +extern void __internal_linkage +glitz_geometry_enable_none (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst, + glitz_box_t *box); + +extern void __internal_linkage +glitz_geometry_enable (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst, + glitz_box_t *box); + +extern void __internal_linkage +glitz_geometry_disable (glitz_surface_t *dst); + +extern void __internal_linkage +glitz_geometry_draw_arrays (glitz_gl_proc_address_list_t *gl, + glitz_surface_t *dst, + glitz_geometry_type_t type, + glitz_box_t *bounds, + int damage); + +void +_glitz_drawable_init (glitz_drawable_t *drawable, + glitz_int_drawable_format_t *format, + glitz_backend_t *backend, + int width, + int height); + +void +_glitz_drawable_draw_buffer (void *abstract_drawable, + const glitz_gl_enum_t buffer); + +void +_glitz_drawable_read_buffer (void *abstract_drawable, + const glitz_gl_enum_t buffer); + +extern glitz_drawable_t __internal_linkage * +_glitz_fbo_drawable_create (glitz_drawable_t *other, + glitz_int_drawable_format_t *format, + int width, + int height); + +void +_glitz_context_init (glitz_context_t *context, + glitz_drawable_t *drawable); + +void +_glitz_context_fini (glitz_context_t *context); + + +#define MAXSHORT SHRT_MAX +#define MINSHORT SHRT_MIN + +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) + +#define LSBFirst 0 +#define MSBFirst 1 + +#ifdef WORDS_BIGENDIAN +# define IMAGE_BYTE_ORDER MSBFirst +# define BITMAP_BIT_ORDER MSBFirst +#else +# define IMAGE_BYTE_ORDER LSBFirst +# define BITMAP_BIT_ORDER LSBFirst +#endif + +#define GLITZ_PI 3.14159265358979323846f + +/* Fixed point updates from Carl Worth, USC, Information Sciences Institute */ + +#ifdef _MSC_VER +typedef __int64 glitz_fixed_32_32; +#else +# if defined(__alpha__) || defined(__alpha) || \ + defined(ia64) || defined(__ia64__) || \ + defined(__sparc64__) || \ + defined(__s390x__) || \ + defined(x86_64) || defined (__x86_64__) +typedef long glitz_fixed_32_32; +# else +# if defined(__GNUC__) && \ + ((__GNUC__ > 2) || \ + ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 7))) +__extension__ +# endif +typedef long long int glitz_fixed_32_32; +# endif +#endif + +typedef uint32_t glitz_fixed_1_31; +typedef uint32_t glitz_fixed_1_16; +typedef int32_t glitz_fixed_16_16; + +/* + * An unadorned "glitz_fixed" is the same as glitz_fixed_16_16, + * (since it's quite common in the code) + */ +typedef glitz_fixed_16_16 glitz_fixed; + +#define FIXED_BITS 16 + +#define FIXED_TO_INT(f) (int) ((f) >> FIXED_BITS) +#define INT_TO_FIXED(i) ((glitz_fixed) (i) << FIXED_BITS) +#define FIXED_E ((glitz_fixed) 1) +#define FIXED1 (INT_TO_FIXED (1)) +#define FIXED1_MINUS_E (FIXED1 - FIXED_E) +#define FIXED_FRAC(f) ((f) & FIXED1_MINUS_E) +#define FIXED_FLOOR(f) ((f) & ~FIXED1_MINUS_E) +#define FIXED_CEIL(f) FIXED_FLOOR ((f) + FIXED1_MINUS_E) + +#define FIXED_FRACTION(f) ((f) & FIXED1_MINUS_E) +#define FIXED_MOD2(f) ((f) & (FIXED1 | FIXED1_MINUS_E)) + +#define FIXED_TO_FLOAT(f) (((glitz_float_t) (f)) / 65536) +#define FLOAT_TO_FIXED(f) ((int) ((f) * 65536)) + +#define SHORT_MULT(s1, s2) \ + ((s1 == 0xffff)? s2: ((s2 == 0xffff)? s1: \ + ((unsigned short) (((unsigned int) s1 * s2) / 0xffff)))) + +#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 + +#endif /* GLITZINT_H_INCLUDED */ diff --git a/glucose/glucose.c b/glucose/glucose.c new file mode 100644 index 000000000..efecd7ef7 --- /dev/null +++ b/glucose/glucose.c @@ -0,0 +1,789 @@ +/* + * Copyright 2006 Zack Rusin + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * ZACK RUSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ZACK RUSIN 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. + * + * Authors: Alan Hourihane + * + * Re-written from original code by Zack Rusin + * + **************************************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include +#endif + +#include "glxserver.h" +#include "glucose.h" +#include "glitz_glucose.h" + +#include "xgl.h" + +#include "xf86str.h" +#include "xf86.h" + +#ifdef MITSHM +#include "shmint.h" +static ShmFuncs shmFuncs = { NULL, xglShmPutImage }; +#endif + +extern __GLXscreen **__glXActiveScreens; +int xglScreenGeneration; +int xglScreenPrivateIndex; +int xglGCPrivateIndex; +int xglPixmapPrivateIndex; +int xglWinPrivateIndex; +#ifdef RENDER +int xglGlyphPrivateIndex; +#endif + +static int glucoseGeneration = -1; +int glucoseScreenPrivateIndex; +int glucoseCreateScreenResourcesIndex; + +xglScreenInfoRec xglScreenInfo = { + NULL, 0, 0, 0, 0, 0, + DEFAULT_GEOMETRY_DATA_TYPE, + DEFAULT_GEOMETRY_USAGE, + FALSE, + XGL_DEFAULT_PBO_MASK, + FALSE, + FALSE, + FilterBilinear, + { + { FALSE, FALSE, { 0, 0, 0, 0 } }, + { FALSE, FALSE, { 0, 0, 0, 0 } }, + { FALSE, FALSE, { 0, 0, 0, 0 } }, + { FALSE, FALSE, { 0, 0, 0, 0 } } + } +}; + +static glitz_drawable_format_t * +glucoseInitOutput(__GLXscreen *screen); + +static Bool +glucoseCreateScreenResources(ScreenPtr pScreen) +{ + int ret = TRUE; + CreateScreenResourcesProcPtr CreateScreenResources = + (CreateScreenResourcesProcPtr)(pScreen->devPrivates[glucoseCreateScreenResourcesIndex].ptr); + GlucoseScreenPrivPtr pScreenPriv = GlucoseGetScreenPriv(pScreen); + int err; + + xf86DrvMsg(pScreen->myNum, X_INFO, + "Glucose initializing screen %d\n",pScreen->myNum); + + if ( pScreen->CreateScreenResources != glucoseCreateScreenResources ) { + /* Can't find hook we are hung on */ + xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */, + "glucoseCreateScreenResources %p called when not in pScreen->CreateScreenResources %p n", + (void *)glucoseCreateScreenResources, + (void *)pScreen->CreateScreenResources ); + } + + /* Unhook this function ... */ + pScreen->CreateScreenResources = CreateScreenResources; + pScreen->devPrivates[glucoseCreateScreenResourcesIndex].ptr = NULL; + + /* ... and call the previous CreateScreenResources fuction, if any */ + if (NULL!=pScreen->CreateScreenResources) { + ret = (*pScreen->CreateScreenResources)(pScreen); + } + + xglScreenInfo.width = pScreen->width; + xglScreenInfo.height = pScreen->height; + xglScreenInfo.widthMm = pScreen->mmWidth; + xglScreenInfo.heightMm = pScreen->mmHeight; + + pScreenPriv->screen = __glXActiveScreens[pScreen->myNum]; + + { + glitz_drawable_t *drawable; + glitz_drawable_format_t *format; + __GLcontextModes *modes = pScreenPriv->screen->modes; + PixmapPtr pPixmap = pScreen->GetScreenPixmap(pScreen); + xglScreenPtr xglScreenPriv = XGL_GET_SCREEN_PRIV (pScreen); + + /* track root pixmap */ + if (pPixmap) + { + pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; + pPixmap->drawable.id = FakeClientID(0); + AddResource(pPixmap->drawable.id, RT_PIXMAP, (pointer)pPixmap); + } + + pScreenPriv->rootDrawable = pScreenPriv->screen->createDrawable(pScreenPriv->screen, (DrawablePtr)pPixmap, pPixmap->drawable.id, modes); + + if (!pScreenPriv->rootDrawable) + return FALSE; + + pScreenPriv->rootContext = pScreenPriv->screen->createContext(pScreenPriv->screen, modes, NULL); + + if (!pScreenPriv->rootContext) + return FALSE; + + pScreenPriv->rootContext->drawPriv = + pScreenPriv->rootContext->readPriv = pScreenPriv->rootDrawable; + + __glXleaveServer(); + err = pScreenPriv->rootContext->makeCurrent(pScreenPriv->rootContext); + if (!err) + ErrorF("makecurrent failed, err is %d\n",err); + + format = glucoseInitOutput(pScreenPriv->screen); + + drawable = glitz_glucose_create_drawable_for_window(pScreenPriv->screen, + format, pScreenPriv->rootDrawable, + pPixmap->drawable.width, + pPixmap->drawable.height); + + if (!drawable) { + xf86DrvMsg(pScreen->myNum, X_ERROR, + "Glucose could not create glitz drawable, not initializing.\n"); + + pScreenPriv->rootContext->destroy(pScreenPriv->rootContext); + pScreenPriv->rootContext = NULL; + pScreenPriv->rootDrawable->destroy(pScreenPriv->rootDrawable); + pScreenPriv->rootDrawable = NULL; + __glXenterServer(); + return FALSE; + } + + xglScreenInfo.drawable = xglScreenPriv->drawable = drawable; + xglScreenPriv->features = + glitz_drawable_get_features (xglScreenInfo.drawable); + + xf86DrvMsg(pScreen->myNum, X_INFO, + "Glucose reports GLitz features as 0x%lx\n",xglScreenPriv->features); + + glucoseFinishScreenInit(pScreen); + __glXenterServer(); + + /* now fixup root pixmap */ + pPixmap = pScreen->GetScreenPixmap(pScreen); + xglPixmapPtr pPixmapPriv = XGL_GET_PIXMAP_PRIV (pPixmap); + + xglPixmapSurfaceInit(pPixmap, xglScreenPriv->features, 0, 0); + + REGION_UNINIT (pPixmap->drawable.pScreen, &pPixmapPriv->bitRegion); + + xglPixmapSurfaceInit(pPixmap, xglScreenPriv->features, pPixmap->drawable.width, pPixmap->drawable.height); + + if (pScreen->devPrivate && pPixmapPriv->pDamage) { + RegionPtr pRegion = DamageRegion (pPixmapPriv->pDamage); + + REGION_UNINIT (pPixmap->drawable.pScreen, pRegion); + REGION_INIT (pPixmap->drawable.pScreen, pRegion, NullBox, 0); + REGION_SUBTRACT (pPixmap->drawable.pScreen, pRegion, + &pPixmapPriv->bitRegion, pRegion); + + } + + pPixmapPriv->pVisual = xglScreenPriv->rootVisual; + + pPixmapPriv->target = xglPixmapTargetIn; + + xglScreenPriv->pScreenPixmap = pPixmap; + + glitz_drawable_reference (xglScreenPriv->drawable); + pPixmapPriv->drawable = xglScreenPriv->drawable; + + glitz_surface_reference (xglScreenPriv->surface); + pPixmapPriv->surface = xglScreenPriv->surface; + } + + return (ret); +} + +static Bool +glucoseAllocatePrivates(ScreenPtr pScreen) +{ + GlucoseScreenPrivPtr pScreenPriv; + + if (glucoseGeneration != serverGeneration) { + glucoseScreenPrivateIndex = AllocateScreenPrivateIndex(); + if (glucoseScreenPrivateIndex < 0) + return FALSE; + glucoseCreateScreenResourcesIndex = AllocateScreenPrivateIndex(); + if (glucoseCreateScreenResourcesIndex < 0) + return FALSE; + + glucoseGeneration = serverGeneration; + } + + pScreenPriv = xalloc(sizeof(GlucoseScreenPrivRec)); + if (!pScreenPriv) { + LogMessage(X_WARNING, "Glucose(%d): Failed to allocate screen private\n", + pScreen->myNum); + return FALSE; + } + + pScreen->devPrivates[glucoseScreenPrivateIndex].ptr = (pointer) pScreenPriv; + + pScreen->devPrivates[glucoseCreateScreenResourcesIndex].ptr + = (void*)(pScreen->CreateScreenResources); + pScreen->CreateScreenResources = glucoseCreateScreenResources; + + return TRUE; +} + +static glitz_drawable_format_t * +glucoseInitOutput(__GLXscreen *screen) +{ + glitz_drawable_format_t *format, templ; + int i; + unsigned long mask; + unsigned long extraMask[] = { + GLITZ_FORMAT_DOUBLEBUFFER_MASK | GLITZ_FORMAT_ALPHA_SIZE_MASK, + GLITZ_FORMAT_DOUBLEBUFFER_MASK, + GLITZ_FORMAT_ALPHA_SIZE_MASK, + 0 + }; + + templ.samples = 1; + templ.doublebuffer = 1; + templ.color.fourcc = GLITZ_FOURCC_RGB; + templ.color.alpha_size = 8; + + mask = GLITZ_FORMAT_SAMPLES_MASK | GLITZ_FORMAT_FOURCC_MASK; + + for (i = 0; i < sizeof(extraMask) / sizeof(extraMask[0]); i++) + { + format = glitz_glucose_find_window_format(screen, + mask | extraMask[i], + &templ, 0); + if (format) + break; + } + + if (!format) + FatalError("no visual format found"); + + xglScreenInfo.depth = + format->color.red_size + + format->color.green_size + + format->color.blue_size; + + return format; +} + +/* Here to mimick the xgl counterpart */ +static Bool +xglAllocatePrivates (ScreenPtr pScreen) +{ + xglScreenPtr pScreenPriv; + + if (xglScreenGeneration != serverGeneration) + { + xglScreenPrivateIndex = AllocateScreenPrivateIndex (); + if (xglScreenPrivateIndex < 0) + return FALSE; + + xglGCPrivateIndex = AllocateGCPrivateIndex (); + if (xglGCPrivateIndex < 0) + return FALSE; + + xglPixmapPrivateIndex = AllocatePixmapPrivateIndex (); + if (xglPixmapPrivateIndex < 0) + return FALSE; + + xglWinPrivateIndex = AllocateWindowPrivateIndex (); + if (xglWinPrivateIndex < 0) + return FALSE; + +#ifdef RENDER + xglGlyphPrivateIndex = AllocateGlyphPrivateIndex (); + if (xglGlyphPrivateIndex < 0) + return FALSE; +#endif + + xglScreenGeneration = serverGeneration; + } + + if (!AllocateGCPrivate (pScreen, xglGCPrivateIndex, sizeof (xglGCRec))) + return FALSE; + + if (!AllocatePixmapPrivate (pScreen, xglPixmapPrivateIndex, + sizeof (xglPixmapRec))) + return FALSE; + + if (!AllocateWindowPrivate (pScreen, xglWinPrivateIndex, + sizeof (xglWinRec))) + return FALSE; + + pScreenPriv = xalloc (sizeof (xglScreenRec)); + if (!pScreenPriv) + return FALSE; + memset(pScreenPriv, 0, sizeof(xglScreenRec)); + + XGL_SET_SCREEN_PRIV (pScreen, pScreenPriv); + + return TRUE; +} + +Bool +glucoseScreenInit (ScreenPtr pScreen) +{ + xglScreenPtr pScreenPriv; + +#ifdef RENDER + PictureScreenPtr pPictureScreen; +#endif + + if (!glucoseAllocatePrivates(pScreen)) + return FALSE; + + if (!xglAllocatePrivates (pScreen)) + return FALSE; + + pScreenPriv = XGL_GET_SCREEN_PRIV (pScreen); + + pScreenPriv->pScreenPixmap = NULL; + + pScreenPriv->pVisual = 0; + + pScreenPriv->rootVisual = 0; + + GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry, + GLITZ_GEOMETRY_TYPE_VERTEX, + pScreenPriv->geometryUsage, 0); + + pScreenPriv->geometryDataType = xglScreenInfo.geometryDataType; + pScreenPriv->geometryUsage = xglScreenInfo.geometryUsage; + pScreenPriv->yInverted = xglScreenInfo.yInverted; + pScreenPriv->pboMask = xglScreenInfo.pboMask; + pScreenPriv->lines = xglScreenInfo.lines; + pScreenPriv->noYuv = xglScreenInfo.noYuv; + pScreenPriv->xvFilter = xglScreenInfo.xvFilter; + pScreenPriv->accel = xglScreenInfo.accel; + + + pScreen->CreatePixmap = xglCreatePixmap; + pScreen->DestroyPixmap = xglDestroyPixmap; + +#ifdef MITSHM + ShmRegisterFuncs (pScreen, &shmFuncs); +#endif + + XGL_SCREEN_WRAP (GetImage, xglGetImage); + XGL_SCREEN_WRAP (GetSpans, xglGetSpans); + + XGL_SCREEN_WRAP (CopyWindow, xglCopyWindow); + XGL_SCREEN_WRAP (CreateWindow, xglCreateWindow); + XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow); + XGL_SCREEN_WRAP (ChangeWindowAttributes, xglChangeWindowAttributes); + XGL_SCREEN_WRAP (PaintWindowBackground, xglPaintWindowBackground); + XGL_SCREEN_WRAP (PaintWindowBorder, xglPaintWindowBorder); + + XGL_SCREEN_WRAP (CreateGC, xglCreateGC); + +#if 0 +#define xglQueryBestSize (void *) NoopDDA +#define xglSaveScreen (void *) NoopDDA + +#define xglConstrainCursor (void *) NoopDDA +#define xglCursorLimits (void *) NoopDDA +#define xglDisplayCursor (void *) NoopDDA +#define xglRealizeCursor (void *) NoopDDA +#define xglUnrealizeCursor (void *) NoopDDA +#define xglRecolorCursor (void *) NoopDDA +#define xglSetCursorPosition (void *) NoopDDA + + /* Might be nice to provide a textured hw cursor at some point */ + pScreen->ConstrainCursor = xglConstrainCursor; + pScreen->CursorLimits = xglCursorLimits; + pScreen->DisplayCursor = xglDisplayCursor; + pScreen->RealizeCursor = xglRealizeCursor; + pScreen->UnrealizeCursor = xglUnrealizeCursor; + pScreen->RecolorCursor = xglRecolorCursor; + pScreen->SetCursorPosition = xglSetCursorPosition; +#endif + + pScreen->ModifyPixmapHeader = xglModifyPixmapHeader; + + XGL_SCREEN_WRAP (BitmapToRegion, xglPixmapToRegion); + + pScreen->GetWindowPixmap = xglGetWindowPixmap; + + XGL_SCREEN_WRAP (SetWindowPixmap, xglSetWindowPixmap); + +#ifdef RENDER + pPictureScreen = GetPictureScreenIfSet (pScreen); + if (pPictureScreen) + { + if (!AllocateGlyphPrivate (pScreen, xglGlyphPrivateIndex, + sizeof (xglGlyphRec))) + return FALSE; + + XGL_PICTURE_SCREEN_WRAP (Composite, xglComposite); + XGL_PICTURE_SCREEN_WRAP (RealizeGlyph, xglRealizeGlyph); + XGL_PICTURE_SCREEN_WRAP (UnrealizeGlyph, xglUnrealizeGlyph); + XGL_PICTURE_SCREEN_WRAP (Glyphs, xglGlyphs); + XGL_PICTURE_SCREEN_WRAP (Trapezoids, xglTrapezoids); + XGL_PICTURE_SCREEN_WRAP (AddTraps, xglAddTraps); + XGL_PICTURE_SCREEN_WRAP (AddTriangles, xglAddTriangles); + XGL_PICTURE_SCREEN_WRAP (ChangePicture, xglChangePicture); + XGL_PICTURE_SCREEN_WRAP (ChangePictureTransform, + xglChangePictureTransform); + XGL_PICTURE_SCREEN_WRAP (ChangePictureFilter, xglChangePictureFilter); + } +#endif + + XGL_SCREEN_WRAP (BackingStoreFuncs.SaveAreas, xglSaveAreas); + XGL_SCREEN_WRAP (BackingStoreFuncs.RestoreAreas, xglRestoreAreas); + +#if 0 +#ifdef COMPOSITE +#warning "composite building" + if (!compScreenInit (pScreen)) + return FALSE; +#endif +#endif + + /* Damage is required */ + DamageSetup (pScreen); + + XGL_SCREEN_WRAP (CloseScreen, glucoseCloseScreen); + + return TRUE; +} + +static Bool +glucoseInitVisual (ScreenPtr pScreen, + xglVisualPtr pVisual, + xglPixelFormatPtr pPixel, + VisualID vid) +{ + glitz_format_t *format; + + XGL_SCREEN_PRIV (pScreen); + + format = xglFindBestSurfaceFormat (pScreen, pPixel); + if (format) + { + glitz_drawable_format_t templ; + unsigned long mask; + + templ.color = format->color; + templ.depth_size = 0; + templ.stencil_size = 0; + templ.doublebuffer = 0; + templ.samples = 1; + + mask = + GLITZ_FORMAT_FOURCC_MASK | + GLITZ_FORMAT_RED_SIZE_MASK | + GLITZ_FORMAT_GREEN_SIZE_MASK | + GLITZ_FORMAT_BLUE_SIZE_MASK | + GLITZ_FORMAT_ALPHA_SIZE_MASK | + GLITZ_FORMAT_DEPTH_SIZE_MASK | + GLITZ_FORMAT_STENCIL_SIZE_MASK | + GLITZ_FORMAT_DOUBLEBUFFER_MASK | + GLITZ_FORMAT_SAMPLES_MASK; + + pVisual->next = 0; + pVisual->vid = vid; + pVisual->pPixel = pPixel; + pVisual->pbuffer = FALSE; + + pVisual->format.surface = format; + pVisual->format.drawable = + glitz_find_drawable_format (pScreenPriv->drawable, + mask, &templ, 0); + + return TRUE; + } + + return FALSE; +} + +static void +glucoseInitVisuals (ScreenPtr pScreen) +{ + xglVisualPtr v, new, *prev; + xglPixelFormatPtr pPixel = NULL; + int i,j; + + XGL_SCREEN_PRIV (pScreen); + + for (j = 0; j < pScreen->numVisuals; j++) + { + pPixel = NULL; + for (i = 0; i < xglNumPixelFormats(); i++) + { + if (pScreen->visuals[j].nplanes == xglPixelFormats[i].depth && + BitsPerPixel(pScreen->visuals[j].nplanes) == xglPixelFormats[i].masks.bpp) + pPixel = &xglPixelFormats[i]; + } + if (pPixel) { + new = xalloc (sizeof (xglVisualRec)); + if (new) + { + if (glucoseInitVisual (pScreen, new, pPixel, + pScreen->visuals[j].vid)) + { + new->next = 0; + + prev = &pScreenPriv->pVisual; + while ((v = *prev)) { + prev = &v->next; + } + + *prev = new; + } + else + { + xfree (new); + } + } + } + } +} + +Bool +glucoseFinishScreenInit (ScreenPtr pScreen) +{ + xglVisualPtr v; + +#ifdef RENDER + glitz_vertex_format_t *format; + static glitz_color_t clearBlack = { 0x0, 0x0, 0x0, 0x0 }; + static glitz_color_t solidWhite = { 0xffff, 0xffff, 0xffff, 0xffff }; + int i; +#endif + + XGL_SCREEN_PRIV (pScreen); + + glucoseInitVisuals (pScreen); + + for (v = pScreenPriv->pVisual; v; v = v->next) + { + if (v->vid == pScreen->rootVisual) + pScreenPriv->rootVisual = v; + } + + if (!pScreenPriv->rootVisual || !pScreenPriv->rootVisual->format.surface) + return FALSE; + + pScreenPriv->surface = + glitz_surface_create (pScreenPriv->drawable, + pScreenPriv->rootVisual->format.surface, + pScreen->width, pScreen->height, + 0, NULL); + if (!pScreenPriv->surface) + return FALSE; + + glitz_surface_attach (pScreenPriv->surface, + pScreenPriv->drawable, + GLITZ_DRAWABLE_BUFFER_FRONT_COLOR); + +#ifdef RENDER + for (i = 0; i < 33; i++) + pScreenPriv->glyphCache[i].pScreen = NULL; + + for (v = pScreenPriv->pVisual; v; v = v->next) + { + if (v->pPixel->depth == 8) + break; + } + + pScreenPriv->pSolidAlpha = 0; + pScreenPriv->trapInfo.pMask = 0; + + /* An accelerated alpha only Xgl visual is required for trapezoid + acceleration */ + if (v && v->format.surface) + { + glitz_surface_t *mask; + + mask = glitz_surface_create (pScreenPriv->drawable, + v->format.surface, + 2, 1, 0, NULL); + if (mask) + { + glitz_set_rectangle (mask, &clearBlack, 0, 0, 1, 1); + glitz_set_rectangle (mask, &solidWhite, 1, 0, 1, 1); + + glitz_surface_set_fill (mask, GLITZ_FILL_NEAREST); + glitz_surface_set_filter (mask, GLITZ_FILTER_BILINEAR, NULL, 0); + + pScreenPriv->trapInfo.pMask = xglCreateDevicePicture (mask); + if (!pScreenPriv->trapInfo.pMask) + return FALSE; + } + } + + format = &pScreenPriv->trapInfo.format.vertex; + format->primitive = GLITZ_PRIMITIVE_QUADS; + format->attributes = GLITZ_VERTEX_ATTRIBUTE_MASK_COORD_MASK; + + format->mask.type = GLITZ_DATA_TYPE_FLOAT; + format->mask.size = GLITZ_COORDINATE_SIZE_X; + format->bytes_per_vertex = sizeof (glitz_float_t); + + if (pScreenPriv->geometryDataType) + { + format->type = GLITZ_DATA_TYPE_FLOAT; + format->bytes_per_vertex += 2 * sizeof (glitz_float_t); + format->mask.offset = 2 * sizeof (glitz_float_t); + } + else + { + format->type = GLITZ_DATA_TYPE_SHORT; + format->bytes_per_vertex += 2 * sizeof (glitz_short_t); + format->mask.offset = 2 * sizeof (glitz_short_t); + } +#endif + +#if 0 /* Let the driver do this ! */ +#ifdef XV + if (!xglXvScreenInit (pScreen)) + return FALSE; +#endif +#endif + + return TRUE; +} + +Bool +glucoseCloseScreen (int index, + ScreenPtr pScreen) +{ + xglVisualPtr v; + + XGL_SCREEN_PRIV (pScreen); + XGL_PIXMAP_PRIV (pScreenPriv->pScreenPixmap); + XGL_SCREEN_UNWRAP (CloseScreen); + + { + GlucoseScreenPrivPtr pScreenPriv = GlucoseGetScreenPriv(pScreen); + + pScreenPriv->rootContext->makeCurrent(pScreenPriv->rootContext); + } + +#ifdef RENDER + int i; + + for (i = 0; i < 33; i++) + xglFiniGlyphCache (&pScreenPriv->glyphCache[i]); + + if (pScreenPriv->pSolidAlpha) + FreePicture ((pointer) pScreenPriv->pSolidAlpha, 0); + + if (pScreenPriv->trapInfo.pMask) + FreePicture ((pointer) pScreenPriv->trapInfo.pMask, 0); +#endif + + xglFiniPixmap (pScreenPriv->pScreenPixmap); + if (pPixmapPriv->pDamage) + DamageDestroy (pPixmapPriv->pDamage); + + if (pScreenPriv->surface) + glitz_surface_destroy (pScreenPriv->surface); + pPixmapPriv->surface = NULL; + pScreenPriv->surface = NULL; + + GEOMETRY_UNINIT (&pScreenPriv->scratchGeometry); + + if (pScreenPriv->drawable) + glitz_drawable_destroy(pScreenPriv->drawable); + pPixmapPriv->drawable = NULL; + pScreenPriv->drawable = NULL; + xglScreenInfo.drawable = NULL; + + while (pScreenPriv->pVisual) + { + v = pScreenPriv->pVisual; + pScreenPriv->pVisual = v->next; + xfree (v); + } + xfree(pScreenPriv); + pScreenPriv = NULL; + + /* tear down glucose now */ + { + GlucoseScreenPrivPtr pScreenPriv = GlucoseGetScreenPriv(pScreen); + + pScreenPriv->rootContext->destroy(pScreenPriv->rootContext); + pScreenPriv->rootDrawable->destroy(pScreenPriv->rootDrawable); + + xfree(pScreenPriv); + pScreenPriv = NULL; + } + + return (*pScreen->CloseScreen) (index, pScreen); +} + + +static MODULESETUPPROTO(glucoseSetup); + +static const OptionInfoRec GlucoseOptions[] = { + { -1, NULL, + OPTV_NONE, {0}, FALSE } +}; + +/*ARGSUSED*/ +static const OptionInfoRec * +GlucoseAvailableOptions(void *unused) +{ + return (GlucoseOptions); +} + +static XF86ModuleVersionInfo glucoseVersRec = +{ + "glucose", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + GLUCOSE_VERSION_MAJOR, GLUCOSE_VERSION_MINOR, GLUCOSE_VERSION_RELEASE, + ABI_CLASS_VIDEODRV, /* requires the video driver ABI */ + ABI_VIDEODRV_VERSION, + MOD_CLASS_NONE, + {0,0,0,0} +}; + +XF86ModuleData glucoseModuleData = { &glucoseVersRec, glucoseSetup, NULL }; + +ModuleInfoRec Glucose = { + 1, + "Glucose", + NULL, + 0, + GlucoseAvailableOptions, +}; + +/*ARGSUSED*/ +static pointer +glucoseSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor) +{ + static Bool Initialised = FALSE; + + if (!Initialised) { + Initialised = TRUE; +#ifndef REMOVE_LOADER_CHECK_MODULE_INFO + if (xf86LoaderCheckSymbol("xf86AddModuleInfo")) +#endif + xf86AddModuleInfo(&Glucose, Module); + } + + return (pointer)TRUE; +} diff --git a/glucose/glucose.h b/glucose/glucose.h new file mode 100644 index 000000000..7768ae3d0 --- /dev/null +++ b/glucose/glucose.h @@ -0,0 +1,64 @@ +/* + * Copyright 2006 Zack Rusin + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * ZACK RUSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ZACK RUSIN 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. + * + * Authors: Alan Hourihane + * + * Re-written from original code by Zack Rusin + * + **************************************************************************/ + +#ifndef GLUCOSE_H +#define GLUCOSE_H + +#define GLUCOSE_VERSION_MAJOR 1 +#define GLUCOSE_VERSION_MINOR 0 +#define GLUCOSE_VERSION_RELEASE 0 + + +#define GLUCOSE_MAKE_VERSION(a, b, c) (((a) << 16) | ((b) << 8) | (c)) +#define GLUCOSE_VERSION \ + GLUCOSE_MAKE_VERSION(GLUCOSE_VERSION_MAJOR, GLUCOSE_VERSION_MINOR, GLUCOSE_VERSION_RELEASE) +#define GLUCOSE_IS_VERSION(a,b,c) (GLUCOSE_VERSION >= GLUCOSE_MAKE_VERSION(a,b,c)) + +Bool +glucoseCloseScreen (int index, + ScreenPtr pScreen); + +Bool +glucoseFinishScreenInit (ScreenPtr pScreen); + +Bool +glucoseScreenInit (ScreenPtr pScreen); + +typedef struct { + __GLXdrawable *rootDrawable; + __GLXcontext *rootContext; + CloseScreenProcPtr CloseScreen; + __GLXscreen *screen; +} GlucoseScreenPrivRec, *GlucoseScreenPrivPtr; + +extern int glucoseScreenPrivateIndex; +#define GlucoseGetScreenPriv(s) ((GlucoseScreenPrivPtr)(s)->devPrivates[glucoseScreenPrivateIndex].ptr) +#define GlucoseScreenPriv(s) GlucoseScreenPrivPtr pGlucoseScr = GlucoseGetScreenPriv(s) + +#endif /* GLUCOSE_H */ diff --git a/glucose/glucose_context.c b/glucose/glucose_context.c new file mode 100644 index 000000000..7e6c71bea --- /dev/null +++ b/glucose/glucose_context.c @@ -0,0 +1,434 @@ +/* + * Copyright © 2004 David Reveman + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * Author: David Reveman + * + * This file has been modified from the GLitz GLX code for use with glucose + * by: Alan Hourihane + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "dix-config.h" +#endif + +#include "glxserver.h" +#include "glcontextmodes.h" +#include "glitz.h" +#include "glitz_glucose.h" +#include "glthread.h" +#include "dispatch.h" +#include "glapi.h" +#include + +extern __GLXcontext *__glXLastContext; +extern glitz_gl_proc_address_list_t _glitz_glucose_gl_proc_address; + +static void +_glitz_glucose_context_create (glitz_glucose_screen_info_t *screen_info, + int visualid, + __GLXcontext *share_list, + glitz_glucose_context_t *context) +{ + __GLXscreen *screen = screen_info->display_info->display; + __GLcontextModes *mode; + + mode = _gl_context_modes_find_visual(screen->modes, visualid); + + context->context = screen->createContext (screen, mode, share_list); + context->id = visualid; +} + +static glitz_context_t * +_glitz_glucose_create_context (void *abstract_drawable, + glitz_drawable_format_t *format) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + glitz_glucose_screen_info_t *screen_info = drawable->screen_info; + unsigned long format_id = + screen_info->formats[format->id].u.uval; + glitz_glucose_context_t *context; + + context = malloc (sizeof (glitz_glucose_context_t)); + if (!context) + return NULL; + + _glitz_context_init (&context->base, &drawable->base); + + _glitz_glucose_context_create (screen_info, + format_id, + screen_info->root_context, + context); + + return (glitz_context_t *) context; +} + +static void +_glitz_glucose_context_destroy (void *abstract_context) +{ + glitz_glucose_context_t *context = (glitz_glucose_context_t *) abstract_context; + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + context->base.drawable; + + if (drawable->screen_info->display_info->thread_info->cctx == + &context->base) + { + __glXDeassociateContext(context->context); + __glXLastContext = NULL; + + drawable->screen_info->display_info->thread_info->cctx = NULL; + } + + context->context->destroy(context->context); + + _glitz_context_fini (&context->base); + + free (context); +} + +static void +_glitz_glucose_copy_context (void *abstract_src, + void *abstract_dst, + unsigned long mask) +{ + glitz_glucose_context_t *src = (glitz_glucose_context_t *) abstract_src; + glitz_glucose_context_t *dst = (glitz_glucose_context_t *) abstract_dst; + + src->context->copy(dst->context, src->context, mask); +} + +static void +_glitz_glucose_make_current (void *abstract_drawable, + void *abstract_context) +{ + glitz_glucose_context_t *context = (glitz_glucose_context_t *) abstract_context; + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + glitz_glucose_display_info_t *display_info = + drawable->screen_info->display_info; + + if (drawable->base.width != drawable->width || + drawable->base.height != drawable->height) + _glitz_glucose_drawable_update_size (drawable, + drawable->base.width, + drawable->base.height); + + if ((__glXLastContext != context->context) || + (__glXLastContext->drawPriv != drawable->drawable)) + { + if (display_info->thread_info->cctx) + { + glitz_context_t *ctx = display_info->thread_info->cctx; + + if (ctx->lose_current) + ctx->lose_current (ctx->closure); + } + + context->context->drawPriv = drawable->drawable; + context->context->readPriv = drawable->drawable; + context->context->makeCurrent( context->context ); + __glXAssociateContext(context->context); + __glXLastContext = context->context; + context->context->isCurrent = TRUE; + } + + display_info->thread_info->cctx = &context->base; +} + +static void +_glitz_glucose_notify_dummy (void *abstract_drawable, + glitz_surface_t *surface) {} + +static glitz_function_pointer_t +_glitz_glucose_context_get_proc_address (void *abstract_context, + const char *name) +{ + glitz_glucose_context_t *context = (glitz_glucose_context_t *) abstract_context; + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + context->base.drawable; + + return glitz_glucose_get_proc_address (name, drawable->screen_info); +} + +glitz_glucose_context_t * +glitz_glucose_context_get (glitz_glucose_screen_info_t *screen_info, + glitz_drawable_format_t *format) +{ + glitz_glucose_context_t *context; + glitz_glucose_context_t **contexts = screen_info->contexts; + int index, n_contexts = screen_info->n_contexts; + unsigned long format_id; + + for (; n_contexts; n_contexts--, contexts++) + if ((*contexts)->id == screen_info->formats[format->id].u.uval) + return *contexts; + + index = screen_info->n_contexts++; + + screen_info->contexts = + realloc (screen_info->contexts, + sizeof (glitz_glucose_context_t *) * screen_info->n_contexts); + if (!screen_info->contexts) + return NULL; + + context = malloc (sizeof (glitz_glucose_context_t)); + if (!context) + return NULL; + + screen_info->contexts[index] = context; + + format_id = screen_info->formats[format->id].u.uval; + + _glitz_glucose_context_create (screen_info, + format_id, + screen_info->root_context, + context); + + if (!screen_info->root_context) + screen_info->root_context = context->context; + + context->backend.gl = &_glitz_glucose_gl_proc_address; + + context->backend.create_pbuffer = NULL; + context->backend.destroy = glitz_glucose_destroy; + context->backend.push_current = glitz_glucose_push_current; + context->backend.pop_current = glitz_glucose_pop_current; + context->backend.attach_notify = _glitz_glucose_notify_dummy; + context->backend.detach_notify = _glitz_glucose_notify_dummy; + context->backend.swap_buffers = glitz_glucose_swap_buffers; + context->backend.copy_sub_buffer = glitz_glucose_copy_sub_buffer; + + context->backend.create_context = _glitz_glucose_create_context; + context->backend.destroy_context = _glitz_glucose_context_destroy; + context->backend.copy_context = _glitz_glucose_copy_context; + context->backend.make_current = _glitz_glucose_make_current; + context->backend.get_proc_address = _glitz_glucose_context_get_proc_address; + + context->backend.draw_buffer = _glitz_drawable_draw_buffer; + context->backend.read_buffer = _glitz_drawable_read_buffer; + + context->backend.drawable_formats = NULL; + context->backend.n_drawable_formats = 0; + + if (screen_info->n_formats) + { + int size; + + size = sizeof (glitz_int_drawable_format_t) * screen_info->n_formats; + context->backend.drawable_formats = malloc (size); + if (context->backend.drawable_formats) + { + memcpy (context->backend.drawable_formats, screen_info->formats, + size); + 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_glucose_context_destroy (glitz_glucose_screen_info_t *screen_info, + glitz_glucose_context_t *context) +{ + if (context->backend.drawable_formats) + free (context->backend.drawable_formats); + + if (context->backend.formats) + free (context->backend.formats); + + if (context->backend.texture_formats) + free (context->backend.texture_formats); + + context->context->destroy (context->context); + + free(context); +} + +static void +_glitz_glucose_context_initialize (glitz_glucose_screen_info_t *screen_info, + glitz_glucose_context_t *context) +{ + glitz_backend_init (&context->backend, + glitz_glucose_get_proc_address, + (void *) screen_info); + + glitz_initiate_state (&_glitz_glucose_gl_proc_address); + + context->initialized = 1; +} + +static void +_glitz_glucose_context_make_current (glitz_glucose_drawable_t *drawable, + glitz_bool_t finish) +{ + glitz_glucose_display_info_t *display_info = + drawable->screen_info->display_info; + GLenum err; + + if (finish) + { + CALL_Finish ( GET_DISPATCH(), () ); + drawable->base.finished = 1; + } + + if (display_info->thread_info->cctx) + { + glitz_context_t *ctx = display_info->thread_info->cctx; + + if (ctx->lose_current) + ctx->lose_current (ctx->closure); + + display_info->thread_info->cctx = NULL; + } + + drawable->context->context->drawPriv = drawable->drawable; + drawable->context->context->readPriv = drawable->drawable; + err = drawable->context->context->makeCurrent(drawable->context->context); + __glXAssociateContext(drawable->context->context); + __glXLastContext = drawable->context->context; + drawable->context->context->isCurrent = TRUE; + + drawable->base.update_all = 1; + + if (!drawable->context->initialized) + _glitz_glucose_context_initialize (drawable->screen_info, + drawable->context); +} + +static void +_glitz_glucose_context_update (glitz_glucose_drawable_t *drawable, + glitz_constraint_t constraint, + glitz_bool_t *restore_state) +{ + glitz_glucose_display_info_t *dinfo = drawable->screen_info->display_info; + __GLXcontext *context = NULL; + + if (restore_state && constraint == GLITZ_ANY_CONTEXT_CURRENT) + { + if (dinfo->thread_info->cctx) + { + *restore_state = 1; + return; + } + } + + drawable->base.flushed = drawable->base.finished = 0; + + switch (constraint) { + case GLITZ_NONE: + break; + case GLITZ_ANY_CONTEXT_CURRENT: + if (!dinfo->thread_info->cctx) + context = __glXLastContext; + + if (!context) + _glitz_glucose_context_make_current (drawable, 0); + break; + case GLITZ_CONTEXT_CURRENT: + if (!dinfo->thread_info->cctx) + context = __glXLastContext; + + if (context != drawable->context->context) + _glitz_glucose_context_make_current (drawable, (context)? 1: 0); + break; + case GLITZ_DRAWABLE_CURRENT: + if (drawable->base.width != drawable->width || + drawable->base.height != drawable->height) + _glitz_glucose_drawable_update_size (drawable, + drawable->base.width, + drawable->base.height); + + if (!dinfo->thread_info->cctx) + context = __glXLastContext; + + if ((context != drawable->context->context) || + (__glXLastContext->drawPriv != drawable->drawable)) + _glitz_glucose_context_make_current (drawable, (context)? 1: 0); + break; + } +} + +glitz_bool_t +glitz_glucose_push_current (void *abstract_drawable, + glitz_surface_t *surface, + glitz_constraint_t constraint, + glitz_bool_t *restore_state) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + glitz_glucose_context_info_t *context_info; + int index; + + if (restore_state) + *restore_state = 0; + + index = drawable->screen_info->context_stack_size++; + + if (index > GLITZ_CONTEXT_STACK_SIZE) + FatalError("glitz context stack failure\n"); + + context_info = &drawable->screen_info->context_stack[index]; + context_info->drawable = drawable; + context_info->surface = surface; + context_info->constraint = constraint; + + _glitz_glucose_context_update (context_info->drawable, constraint, + restore_state); + + return 1; +} + +glitz_surface_t * +glitz_glucose_pop_current (void *abstract_drawable) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + glitz_glucose_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_glucose_context_update (context_info->drawable, + context_info->constraint, + NULL); + + if (context_info->constraint == GLITZ_DRAWABLE_CURRENT) + return context_info->surface; + + return NULL; +} diff --git a/glucose/glucose_drawable.c b/glucose/glucose_drawable.c new file mode 100644 index 000000000..c35dfa9dc --- /dev/null +++ b/glucose/glucose_drawable.c @@ -0,0 +1,180 @@ +/* + * Copyright © 2004 David Reveman + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * Author: David Reveman + * + * This file has been modified from the GLitz GLX code for use with glucose + * by: Alan Hourihane + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "dix-config.h" +#endif + +#include "glxserver.h" +#include "glitz_glucose.h" + +extern __GLXcontext *__glXLastContext; + +static glitz_glucose_drawable_t * +_glitz_glucose_create_drawable (glitz_glucose_screen_info_t *screen_info, + glitz_glucose_context_t *context, + glitz_drawable_format_t *format, + __GLXdrawable *glx_drawable, + int width, + int height) +{ + glitz_glucose_drawable_t *drawable; + + drawable = (glitz_glucose_drawable_t *) malloc (sizeof (glitz_glucose_drawable_t)); + if (drawable == NULL) + return NULL; + + drawable->screen_info = screen_info; + drawable->context = context; + drawable->drawable = glx_drawable; + drawable->width = width; + drawable->height = height; + + _glitz_drawable_init (&drawable->base, + &screen_info->formats[format->id], + &context->backend, + width, height); + + if (!context->initialized) { + glitz_glucose_push_current (drawable, NULL, GLITZ_CONTEXT_CURRENT, NULL); + glitz_glucose_pop_current (drawable); + } + + if (width > context->backend.max_viewport_dims[0] || + height > context->backend.max_viewport_dims[1]) { + free (drawable); + return NULL; + } + + screen_info->drawables++; + + return drawable; +} + +glitz_bool_t +_glitz_glucose_drawable_update_size (glitz_glucose_drawable_t *drawable, + int width, + int height) +{ + drawable->width = width; + drawable->height = height; + + return 1; +} + +glitz_drawable_t * +glitz_glucose_create_drawable_for_window (__GLXscreen *screen, + glitz_drawable_format_t *format, + __GLXdrawable *window, + unsigned int width, + unsigned int height) +{ + glitz_glucose_drawable_t *drawable; + glitz_glucose_screen_info_t *screen_info; + glitz_glucose_context_t *context; + glitz_int_drawable_format_t *iformat; + + screen_info = glitz_glucose_screen_info_get (screen); + if (!screen_info) + return NULL; + + if (format->id >= screen_info->n_formats) + return NULL; + + iformat = &screen_info->formats[format->id]; + if (!(iformat->types & GLITZ_DRAWABLE_TYPE_WINDOW_MASK)) + return NULL; + + context = glitz_glucose_context_get (screen_info, format); + if (!context) + return NULL; + + drawable = _glitz_glucose_create_drawable (screen_info, context, format, + window, + width, height); + if (!drawable) + return NULL; + + return &drawable->base; +} + +void +glitz_glucose_destroy (void *abstract_drawable) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_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_glucose_push_current (abstract_drawable, NULL, + GLITZ_CONTEXT_CURRENT, NULL); + glitz_program_map_fini (drawable->base.backend->gl, + &drawable->screen_info->program_map); + glitz_program_map_init (&drawable->screen_info->program_map); + glitz_glucose_pop_current (abstract_drawable); + } + + if (__glXLastContext->drawPriv == drawable->drawable) { + __glXDeassociateContext(drawable->context->context); + __glXLastContext = NULL; + } + + free (drawable); +} + +glitz_bool_t +glitz_glucose_swap_buffers (void *abstract_drawable) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + + drawable->drawable->swapBuffers (drawable->drawable); + + return 1; +} + +glitz_bool_t +glitz_glucose_copy_sub_buffer (void *abstract_drawable, + int x, + int y, + int width, + int height) +{ + glitz_glucose_drawable_t *drawable = (glitz_glucose_drawable_t *) + abstract_drawable; + + drawable->drawable->copySubBuffer (drawable->drawable, x, y, width, height); + + return 1; +} diff --git a/glucose/glucose_format.c b/glucose/glucose_format.c new file mode 100644 index 000000000..fdfde0ae5 --- /dev/null +++ b/glucose/glucose_format.c @@ -0,0 +1,240 @@ +/* + * Copyright © 2004 David Reveman + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * Author: David Reveman + * + * This file has been modified from the GLitz GLX code for use with glucose + * by: Alan Hourihane + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "dix-config.h" +#endif + +#if 0 +#include "glxserver.h" +#else +#include "scrnintstr.h" +#include "window.h" +#include "pixmap.h" +#include +#include +/* For glxscreens.h */ +typedef struct __GLXdrawable __GLXdrawable; +typedef struct __GLXcontext __GLXcontext; + +#include "glxscreens.h" +#include "glxdrawable.h" +#include "glxcontext.h" +#endif +#include "glcontextmodes.h" +#include "glitz_glucose.h" + +#include +#include + +static int +_glitz_glucose_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.fourcc != GLITZ_FOURCC_RGB) + score[i] -= 1000; + + 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] -= 1000; + } + + return score[1] - score[0]; +} + +static void +_glitz_add_format (glitz_glucose_screen_info_t *screen_info, + glitz_int_drawable_format_t *format) +{ + int n = screen_info->n_formats; + + screen_info->formats = + realloc (screen_info->formats, + sizeof (glitz_int_drawable_format_t) * (n + 1)); + if (screen_info->formats) + { + screen_info->formats[n] = *format; + screen_info->formats[n].d.id = n; + screen_info->n_formats++; + } +} + +static void +_glitz_glucose_query_formats (glitz_glucose_screen_info_t *screen_info) +{ + __GLXscreen *screen = screen_info->display_info->display; + __GLcontextModes *mode; + glitz_int_drawable_format_t format; + int i; + + format.types = GLITZ_DRAWABLE_TYPE_WINDOW_MASK; + format.d.id = 0; + format.d.color.fourcc = GLITZ_FOURCC_RGB; + + mode = screen->modes; + + for (i = 0; i < screen->numVisuals; i++) + { + int value; + + if ((_gl_get_context_mode_data(mode, GLX_USE_GL, &value) != 0) || + (value == 0)) + continue; + + _gl_get_context_mode_data(mode, GLX_RGBA, &value); + if (value == 0) + continue; + + /* Stereo is not supported yet */ + _gl_get_context_mode_data(mode, GLX_STEREO, &value); + if (value != 0) + continue; + + _gl_get_context_mode_data(mode, GLX_RED_SIZE, &value); + format.d.color.red_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_GREEN_SIZE, &value); + format.d.color.green_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_BLUE_SIZE, &value); + format.d.color.blue_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_ALPHA_SIZE, &value); + format.d.color.alpha_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_DEPTH_SIZE, &value); + format.d.depth_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_STENCIL_SIZE, &value); + format.d.stencil_size = (unsigned short) value; + _gl_get_context_mode_data(mode, GLX_DOUBLEBUFFER, &value); + format.d.doublebuffer = (value) ? 1: 0; + + _gl_get_context_mode_data(mode, GLX_VISUAL_CAVEAT_EXT, &value); + switch (value) { + case GLX_SLOW_VISUAL_EXT: + case GLX_NON_CONFORMANT_VISUAL_EXT: + format.caveat = 1; + break; + default: + format.caveat = 0; + break; + } + + _gl_get_context_mode_data(mode, GLX_SAMPLE_BUFFERS_ARB, &value); + if (value) + { + _gl_get_context_mode_data(mode, GLX_SAMPLES_ARB, &value); + format.d.samples = (unsigned short) (value > 1)? value: 1; + } + else + format.d.samples = 1; + + format.u.uval = mode->visualID; + + _glitz_add_format (screen_info, &format); + + mode = mode->next; + } +} + +void +glitz_glucose_query_formats (glitz_glucose_screen_info_t *screen_info) +{ + int i; + + _glitz_glucose_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_glucose_format_compare); + + for (i = 0; i < screen_info->n_formats; i++) + screen_info->formats[i].d.id = i; +} + +glitz_drawable_format_t * +glitz_glucose_find_window_format (__GLXscreen *screen, + unsigned long mask, + const glitz_drawable_format_t *templ, + int count) +{ + glitz_int_drawable_format_t itempl; + glitz_glucose_screen_info_t *screen_info = + glitz_glucose_screen_info_get (screen); + + 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); +} diff --git a/glucose/glucose_info.c b/glucose/glucose_info.c new file mode 100644 index 000000000..5acbf4e5e --- /dev/null +++ b/glucose/glucose_info.c @@ -0,0 +1,958 @@ +/* + * Copyright © 2004 David Reveman + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * + * 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 name 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. + * + * Author: David Reveman + * + * This file has been modified from the GLitz GLX code for use with glucose + * by: Alan Hourihane + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "dix-config.h" +#endif + +#include "glxserver.h" +#include "glapi.h" +#include "glthread.h" +#include "dispatch.h" +#include "glitz_glucose.h" + +#include +#include + +#if DEBUG +#define glucoseFailure(n) \ + { \ + int err = CALL_GetError( GET_DISPATCH(), () ); \ + if (err) \ + ErrorF("GL operation (" n ",%d) failed\n",err); \ + } +#else +#define glucoseFailure(n) +#endif + +static void glucoseEnable( GLenum cap ) +{ + CALL_Enable( GET_DISPATCH(), (cap) ); + glucoseFailure("Enable"); +} + +static void glucoseDisable( GLenum cap ) +{ + CALL_Disable( GET_DISPATCH(), (cap) ); + glucoseFailure("Disable"); +} + +static GLenum glucoseGetError( void ) +{ + return CALL_GetError( GET_DISPATCH(), () ); +} + +static const GLubyte * glucoseGetString( GLenum name ) +{ + return CALL_GetString( GET_DISPATCH(), (name) ); +} + +static void glucoseEnableClientState( GLenum cap ) +{ + CALL_EnableClientState( GET_DISPATCH(), (cap) ); + glucoseFailure("EnableClientState"); +} + +static void glucoseDisableClientState( GLenum cap ) +{ + CALL_DisableClientState( GET_DISPATCH(), (cap) ); + glucoseFailure("DisableClientState"); +} + +static void +glucoseVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *p) +{ + CALL_VertexPointer( GET_DISPATCH(), (size, type, stride, p) ); + glucoseFailure("VertexPointer"); +} + +static void +glucoseTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *p) +{ + CALL_TexCoordPointer( GET_DISPATCH(), (size, type, stride, p) ); + glucoseFailure("TexCoordPointer"); +} + +static void +glucoseDrawArrays( GLenum mode, GLint first, GLsizei count ) +{ + CALL_DrawArrays( GET_DISPATCH(), (mode, first, count) ); + glucoseFailure("DrawArrays"); +} + +static void +glucoseTexEnvf( GLenum target, GLenum pname, GLfloat param ) +{ + CALL_TexEnvf( GET_DISPATCH(), (target, pname, param) ); + glucoseFailure("TexEnvf"); +} + +static void +glucoseTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) +{ + CALL_TexEnvfv( GET_DISPATCH(), (target, pname, params) ); + glucoseFailure("TexEnvfv"); +} + +static void +glucoseTexGeni( GLenum coord, GLenum pname, GLint param ) +{ + CALL_TexGeni( GET_DISPATCH(), (coord, pname, param) ); + glucoseFailure("TexGeni"); +} + +static void +glucoseTexGenfv( GLenum coord, GLenum pname, const GLfloat *params ) +{ + CALL_TexGenfv( GET_DISPATCH(), (coord, pname, params) ); + glucoseFailure("TexGenfv"); +} + +static void +glucoseColor4us( GLushort red, GLushort green, GLushort blue, GLushort alpha ) +{ + CALL_Color4us( GET_DISPATCH(), (red, green, blue, alpha) ); + glucoseFailure("Color4us"); +} + +static void +glucoseColor4f( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha ) +{ + CALL_Color4f( GET_DISPATCH(), (red, green, blue, alpha) ); + glucoseFailure("Color4f"); +} + +static void +glucoseScissor( GLint x, GLint y, GLsizei width, GLsizei height) +{ + CALL_Scissor( GET_DISPATCH(), (x, y, width, height) ); + glucoseFailure("Scissor"); +} + +static void +glucoseBlendFunc( GLenum sfactor, GLenum dfactor ) +{ + CALL_BlendFunc( GET_DISPATCH(), (sfactor, dfactor) ); + glucoseFailure("BlendFunc"); +} + +static void +glucoseClear( GLbitfield mask ) +{ + CALL_Clear( GET_DISPATCH(), (mask) ); + glucoseFailure("Clear"); +} + +static void +glucoseClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) +{ + CALL_ClearColor( GET_DISPATCH(), (red, green, blue, alpha) ); + glucoseFailure("ClearColor"); +} + +static void +glucoseClearStencil( GLint s ) +{ + CALL_ClearStencil( GET_DISPATCH(), (s) ); + glucoseFailure("ClearStencil"); +} + +static void +glucoseStencilFunc( GLenum func, GLint ref, GLuint mask ) +{ + CALL_StencilFunc( GET_DISPATCH(), (func, ref, mask) ); + glucoseFailure("StencilFunc"); +} + +static void +glucoseStencilOp( GLenum fail, GLenum zfail, GLenum zpass ) +{ + CALL_StencilOp( GET_DISPATCH(), (fail, zfail, zpass) ); + glucoseFailure("StencilOp"); +} + +static void +glucosePushAttrib( GLbitfield mask ) +{ + CALL_PushAttrib( GET_DISPATCH(), (mask) ); + glucoseFailure("PushAttrib"); +} + +static void +glucosePopAttrib( void ) +{ + CALL_PopAttrib( GET_DISPATCH(), () ); + glucoseFailure("PopAttrib"); +} + +static void +glucoseMatrixMode( GLenum mode ) +{ + CALL_MatrixMode( GET_DISPATCH(), (mode) ); + glucoseFailure("MatrixMode"); +} + +static void +glucosePushMatrix( void ) +{ + CALL_PushMatrix( GET_DISPATCH(), () ); + glucoseFailure("PushMatrix"); +} + +static void +glucosePopMatrix( void ) +{ + CALL_PopMatrix( GET_DISPATCH(), () ); + glucoseFailure("PopMatrix"); +} + +static void +glucoseLoadIdentity( void ) +{ + CALL_LoadIdentity( GET_DISPATCH(), () ); + glucoseFailure("LoadIdentity"); +} + +static void +glucoseLoadMatrixf( const GLfloat *m ) +{ + CALL_LoadMatrixf( GET_DISPATCH(), (m) ); + glucoseFailure("LoadMatrixf"); +} + +static void +glucoseDepthRange( GLclampd near_val, GLclampd far_val ) +{ + CALL_DepthRange( GET_DISPATCH(), (near_val, far_val) ); + glucoseFailure("DepthRange"); +} + +static void +glucoseViewport( GLint x, GLint y, GLsizei width, GLsizei height) +{ + CALL_Viewport( GET_DISPATCH(), (x, y, width, height) ); + glucoseFailure("Viewport"); +} + +static void +glucoseRasterPos2f( GLfloat x, GLfloat y ) +{ + CALL_RasterPos2f( GET_DISPATCH(), (x, y) ); + glucoseFailure("RasterPos2f"); +} + +static void +glucoseBitmap( GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap ) +{ + CALL_Bitmap( GET_DISPATCH(), (width, height, xorig, yorig, xmove, ymove, bitmap) ); + glucoseFailure("Bitmap"); +} + +static void +glucoseReadBuffer( GLenum mode ) +{ + CALL_ReadBuffer( GET_DISPATCH(), (mode) ); + glucoseFailure("ReadBuffer"); +} + +static void +glucoseDrawBuffer( GLenum mode ) +{ + CALL_DrawBuffer( GET_DISPATCH(), (mode) ); + glucoseFailure("DrawBuffer"); +} + +static void +glucoseCopyPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum type ) +{ + CALL_CopyPixels( GET_DISPATCH(), (x, y, width, height, type) ); + glucoseFailure("CopyPixels"); +} + +static void +glucoseFlush( void ) +{ + CALL_Flush( GET_DISPATCH(), () ); + glucoseFailure("Flush"); +} + +static void +glucoseFinish( void ) +{ + CALL_Finish( GET_DISPATCH(), () ); + glucoseFailure("Finish"); +} + +static void +glucosePixelStorei( GLenum pname, GLint param ) +{ + CALL_PixelStorei( GET_DISPATCH(), (pname, param) ); + glucoseFailure("PixelStorei"); +} + +static void +glucoseOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) +{ + CALL_Ortho( GET_DISPATCH(), (left, right, bottom, top, near_val, far_val) ); + glucoseFailure("Ortho"); +} + +static void +glucoseScalef( GLfloat x, GLfloat y, GLfloat z ) +{ + CALL_Scalef( GET_DISPATCH(), (x, y, z) ); + glucoseFailure("Scalef"); +} + +static void +glucoseTranslatef( GLfloat x, GLfloat y, GLfloat z ) +{ + CALL_Translatef( GET_DISPATCH(), (x, y, z) ); + glucoseFailure("Translatef"); +} + +static void +glucoseHint( GLenum target, GLenum mode ) +{ + CALL_Hint( GET_DISPATCH(), (target, mode) ); + glucoseFailure("Hint"); +} + +static void +glucoseDepthMask( GLboolean flag ) +{ + CALL_DepthMask( GET_DISPATCH(), (flag) ); + glucoseFailure("DepthMask"); +} + +static void +glucosePolygonMode( GLenum face, GLenum mode ) +{ + CALL_PolygonMode( GET_DISPATCH(), (face, mode) ); + glucoseFailure("PolygonMode"); +} + +static void +glucoseShadeModel( GLenum mode ) +{ + CALL_ShadeModel( GET_DISPATCH(), (mode) ); + glucoseFailure("ShadeModel"); +} + +static void +glucoseColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ) +{ + CALL_ColorMask( GET_DISPATCH(), (red, green, blue, alpha) ); + glucoseFailure("ColorMask"); +} + +static void +glucoseReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels ) +{ + CALL_ReadPixels( GET_DISPATCH(), (x, y, width, height, format, type, pixels) ); + glucoseFailure("ReadPixels"); +} + +static void +glucoseGetTexImage( GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels ) +{ + CALL_GetTexImage( GET_DISPATCH(), (target, level, format, type, pixels) ); + glucoseFailure("GetTexImage"); +} + +static void +glucoseTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels ) +{ + CALL_TexSubImage2D( GET_DISPATCH(), (target, level, xoffset, yoffset, width, height, format, type, pixels) ); + glucoseFailure("TexSubImage2D"); +} + +static void +glucoseGenTextures( GLsizei n, GLuint *textures ) +{ + CALL_GenTextures( GET_DISPATCH(), (n, textures) ); + glucoseFailure("GenTextures"); +} + +static void +glucoseDeleteTextures( GLsizei n, const GLuint *textures) +{ + CALL_DeleteTextures( GET_DISPATCH(), (n, textures) ); + glucoseFailure("DeleteTextures"); +} + +static void +glucoseBindTexture( GLenum target, GLuint texture ) +{ + CALL_BindTexture( GET_DISPATCH(), (target, texture) ); + glucoseFailure("BindTexture"); +} + +static void +glucoseTexImage2D( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ) +{ + CALL_TexImage2D( GET_DISPATCH(), (target, level, internalFormat, width, height, border, format, type, pixels) ); + glucoseFailure("TexImage2D"); +} + +static void +glucoseTexParameteri( GLenum target, GLenum pname, GLint param ) +{ + CALL_TexParameteri( GET_DISPATCH(), (target, pname, param) ); + glucoseFailure("TexParameteri"); +} + +static void +glucoseTexParameterfv( GLenum target, GLenum pname, const GLfloat *params ) +{ + CALL_TexParameterfv( GET_DISPATCH(), (target, pname, params) ); + glucoseFailure("TexParameterfv"); +} + +static void +glucoseGetTexLevelParameteriv( GLenum target, GLint level, GLenum pname, GLint *params ) +{ + CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, pname, params) ); + glucoseFailure("GetTexLevelParameteriv"); +} + +static void +glucoseCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height ) +{ + CALL_CopyTexSubImage2D( GET_DISPATCH(), (target, level, xoffset, yoffset, x, y, width, height) ); + glucoseFailure("CopyTexSubImage2D"); +} + +static void +glucoseGetIntegerv( GLenum pname, GLint *params ) +{ + CALL_GetIntegerv( GET_DISPATCH(), (pname, params) ); + glucoseFailure("GetIntegerv"); +} + +static void +glucoseBlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) +{ + CALL_BlendColor( GET_DISPATCH(), (red, green, blue, alpha) ); + glucoseFailure("BlendColor"); +} + +static void +glucoseActiveTexture( GLenum texture ) +{ + CALL_ActiveTextureARB( GET_DISPATCH(), (texture) ); + glucoseFailure("ActiveTexture"); +} + +static void +glucoseClientActiveTexture( GLenum texture ) +{ + CALL_ClientActiveTextureARB( GET_DISPATCH(), (texture) ); + glucoseFailure("ClientActiveTexture"); +} + +static void +glucoseMultiDrawArrays( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount ) +{ + CALL_MultiDrawArraysEXT( GET_DISPATCH(), (mode, first, count, primcount) ); + glucoseFailure("MultiDrawArrays"); +} + +static void +glucoseGenPrograms( GLsizei n, GLuint *ids ) +{ + CALL_GenProgramsNV( GET_DISPATCH(), (n, ids) ); +} + +static void +glucoseDeletePrograms( GLsizei n, const GLuint *ids ) +{ + CALL_DeleteProgramsNV( GET_DISPATCH(), (n, ids) ); +} + +static void +glucoseProgramString( GLenum target, GLenum format, GLsizei len, const GLubyte *program ) +{ + CALL_ProgramStringARB( GET_DISPATCH(), (target, format, len, program) ); +} + +static void +glucoseBindProgram( GLenum target, GLuint id ) +{ + CALL_BindProgramNV( GET_DISPATCH(), (target, id) ); +} + +static void +glucoseProgramLocalParameter4fv( GLenum target, GLuint id, const GLfloat *params ) +{ + CALL_ProgramLocalParameter4fvARB( GET_DISPATCH(), (target, id, params) ); +} + +static void +glucoseGetProgramiv( GLuint program, GLenum pname, GLint *params ) +{ + CALL_GetProgramiv( GET_DISPATCH(), (program, pname, params) ); +} + +static void +glucoseGenBuffers( GLsizei n, GLuint *buffers ) +{ + CALL_GenBuffersARB( GET_DISPATCH(), (n, buffers) ); +} + +static void +glucoseDeleteBuffers( GLsizei n, const GLuint *buffers ) +{ + CALL_DeleteBuffersARB( GET_DISPATCH(), (n, buffers) ); +} + +static void +glucoseBindBuffer( GLenum target, GLuint buffer ) +{ + CALL_BindBufferARB( GET_DISPATCH(), (target, buffer) ); + glucoseFailure("BindBuffer"); +} + +static void +glucoseBufferData( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) +{ + CALL_BufferDataARB( GET_DISPATCH(), (target, size, data, usage) ); +} + +static void +glucoseBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data ) +{ + CALL_BufferSubDataARB( GET_DISPATCH(), (target, offset, size, data) ); +} + +static void +glucoseGetBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data) +{ + CALL_GetBufferSubDataARB( GET_DISPATCH(), (target, offset, size, data) ); +} + +static void +glucoseMapBuffer(GLenum target, GLenum access) +{ + CALL_MapBufferARB( GET_DISPATCH(), (target, access) ); + glucoseFailure("MapBuffer"); +} + +static void +glucoseUnmapBuffer(GLenum target) +{ + CALL_UnmapBufferARB( GET_DISPATCH(), (target) ); + glucoseFailure("UnmapBuffer"); +} + +static void +glucoseGenFramebuffers(GLsizei n, GLuint *framebuffers) +{ + CALL_GenFramebuffersEXT( GET_DISPATCH(), (n, framebuffers) ); +} + +static void +glucoseDeleteFramebuffers(GLsizei n, const GLuint *framebuffers) +{ + CALL_DeleteFramebuffersEXT( GET_DISPATCH(), (n, framebuffers) ); +} + +static void +glucoseBindFramebuffer(GLenum target, GLuint framebuffer) +{ + CALL_BindFramebufferEXT( GET_DISPATCH(), (target, framebuffer) ); +} + +static void +glucoseFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) +{ + CALL_FramebufferRenderbufferEXT( GET_DISPATCH(), (target, attachment, renderbuffertarget, renderbuffer) ); +} + +static void +glucoseFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) +{ + CALL_FramebufferTexture2DEXT( GET_DISPATCH(), (target, attachment, textarget, texture, level) ); +} + +static void +glucoseCheckFramebufferStatus(GLenum target) +{ + CALL_CheckFramebufferStatusEXT( GET_DISPATCH(), (target) ); +} + +static void +glucoseGenRenderbuffers(GLsizei n, GLuint *renderbuffers) +{ + CALL_GenRenderbuffersEXT( GET_DISPATCH(), (n, renderbuffers) ); +} + +static void +glucoseDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) +{ + CALL_DeleteRenderbuffersEXT( GET_DISPATCH(), (n, renderbuffers) ); +} + +static void +glucoseBindRenderbuffer(GLenum target, GLuint renderbuffer) +{ + CALL_BindRenderbufferEXT( GET_DISPATCH(), (target, renderbuffer) ); +} + +static void +glucoseRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height) +{ + CALL_RenderbufferStorageEXT( GET_DISPATCH(), (target, internalformat, width, height) ); +} + +static void +glucoseGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) +{ + CALL_GetRenderbufferParameterivEXT( GET_DISPATCH(), (target, pname, params) ); +} + +glitz_gl_proc_address_list_t _glitz_glucose_gl_proc_address = { + + /* core */ + (glitz_gl_enable_t) glucoseEnable, + (glitz_gl_disable_t) glucoseDisable, + (glitz_gl_get_error_t) glucoseGetError, + (glitz_gl_get_string_t) glucoseGetString, + (glitz_gl_enable_client_state_t) glucoseEnableClientState, + (glitz_gl_disable_client_state_t) glucoseDisableClientState, + (glitz_gl_vertex_pointer_t) glucoseVertexPointer, + (glitz_gl_tex_coord_pointer_t) glucoseTexCoordPointer, + (glitz_gl_draw_arrays_t) glucoseDrawArrays, + (glitz_gl_tex_env_f_t) glucoseTexEnvf, + (glitz_gl_tex_env_fv_t) glucoseTexEnvfv, + (glitz_gl_tex_gen_i_t) glucoseTexGeni, + (glitz_gl_tex_gen_fv_t) glucoseTexGenfv, + (glitz_gl_color_4us_t) glucoseColor4us, + (glitz_gl_color_4f_t) glucoseColor4f, + (glitz_gl_scissor_t) glucoseScissor, + (glitz_gl_blend_func_t) glucoseBlendFunc, + (glitz_gl_clear_t) glucoseClear, + (glitz_gl_clear_color_t) glucoseClearColor, + (glitz_gl_clear_stencil_t) glucoseClearStencil, + (glitz_gl_stencil_func_t) glucoseStencilFunc, + (glitz_gl_stencil_op_t) glucoseStencilOp, + (glitz_gl_push_attrib_t) glucosePushAttrib, + (glitz_gl_pop_attrib_t) glucosePopAttrib, + (glitz_gl_matrix_mode_t) glucoseMatrixMode, + (glitz_gl_push_matrix_t) glucosePushMatrix, + (glitz_gl_pop_matrix_t) glucosePopMatrix, + (glitz_gl_load_identity_t) glucoseLoadIdentity, + (glitz_gl_load_matrix_f_t) glucoseLoadMatrixf, + (glitz_gl_depth_range_t) glucoseDepthRange, + (glitz_gl_viewport_t) glucoseViewport, + (glitz_gl_raster_pos_2f_t) glucoseRasterPos2f, + (glitz_gl_bitmap_t) glucoseBitmap, + (glitz_gl_read_buffer_t) glucoseReadBuffer, + (glitz_gl_draw_buffer_t) glucoseDrawBuffer, + (glitz_gl_copy_pixels_t) glucoseCopyPixels, + (glitz_gl_flush_t) glucoseFlush, + (glitz_gl_finish_t) glucoseFinish, + (glitz_gl_pixel_store_i_t) glucosePixelStorei, + (glitz_gl_ortho_t) glucoseOrtho, + (glitz_gl_scale_f_t) glucoseScalef, + (glitz_gl_translate_f_t) glucoseTranslatef, + (glitz_gl_hint_t) glucoseHint, + (glitz_gl_depth_mask_t) glucoseDepthMask, + (glitz_gl_polygon_mode_t) glucosePolygonMode, + (glitz_gl_shade_model_t) glucoseShadeModel, + (glitz_gl_color_mask_t) glucoseColorMask, + (glitz_gl_read_pixels_t) glucoseReadPixels, + (glitz_gl_get_tex_image_t) glucoseGetTexImage, + (glitz_gl_tex_sub_image_2d_t) glucoseTexSubImage2D, + (glitz_gl_gen_textures_t) glucoseGenTextures, + (glitz_gl_delete_textures_t) glucoseDeleteTextures, + (glitz_gl_bind_texture_t) glucoseBindTexture, + (glitz_gl_tex_image_2d_t) glucoseTexImage2D, + (glitz_gl_tex_parameter_i_t) glucoseTexParameteri, + (glitz_gl_tex_parameter_fv_t) glucoseTexParameterfv, + (glitz_gl_get_tex_level_parameter_iv_t) glucoseGetTexLevelParameteriv, + (glitz_gl_copy_tex_sub_image_2d_t) glucoseCopyTexSubImage2D, + (glitz_gl_get_integer_v_t) glucoseGetIntegerv, + + /* 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_glucose_get_proc_address (const char *name, + void *closure) +{ + glitz_function_pointer_t address = NULL; +#if 0 + /* Unfortunately this doesn't work for us because glapi.c doesn't get + * compiled with USE_X86_ASM, or appropriate, so never gets a generated + * function pointer. Further investigation required..... + */ + address = _glapi_get_proc_address(name); +#else + + if (!strncmp(name, "glBlendColor", 12)) + address = (glitz_function_pointer_t) glucoseBlendColor; + else if (!strncmp(name, "glActiveTexture", 15)) + address = (glitz_function_pointer_t) glucoseActiveTexture; + else if (!strncmp(name, "glClientActiveTexture", 21)) + address = (glitz_function_pointer_t) glucoseClientActiveTexture; + else if (!strncmp(name, "glMultiDrawArraysEXT", 20)) + address = (glitz_function_pointer_t) glucoseMultiDrawArrays; + else if (!strncmp(name, "glGenProgramsARB", 16)) + address = (glitz_function_pointer_t) glucoseGenPrograms; + else if (!strncmp(name, "glDeleteProgramsARB", 19)) + address = (glitz_function_pointer_t) glucoseDeletePrograms; + else if (!strncmp(name, "glProgramStringARB", 18)) + address = (glitz_function_pointer_t) glucoseProgramString; + else if (!strncmp(name, "glBindProgramARB", 16)) + address = (glitz_function_pointer_t) glucoseBindProgram; + else if (!strncmp(name, "glProgramLocalParameter4fvARB", 29)) + address = (glitz_function_pointer_t) glucoseProgramLocalParameter4fv; + else if (!strncmp(name, "glGetProgramivARB", 17)) + address = (glitz_function_pointer_t) glucoseGetProgramiv; + else if (!strncmp(name, "glGenBuffers", 12)) + address = (glitz_function_pointer_t) glucoseGenBuffers; + else if (!strncmp(name, "glDeleteBuffers", 15)) + address = (glitz_function_pointer_t) glucoseDeleteBuffers; + else if (!strncmp(name, "glBindBuffer", 12)) + address = (glitz_function_pointer_t) glucoseBindBuffer; + else if (!strncmp(name, "glBufferData", 12)) + address = (glitz_function_pointer_t) glucoseBufferData; + else if (!strncmp(name, "glBufferSubData", 15)) + address = (glitz_function_pointer_t) glucoseBufferSubData; + else if (!strncmp(name, "glGetBufferSubData", 18)) + address = (glitz_function_pointer_t) glucoseGetBufferSubData; + else if (!strncmp(name, "glMapBuffer", 11)) + address = (glitz_function_pointer_t) glucoseMapBuffer; + else if (!strncmp(name, "glUnmapBuffer", 13)) + address = (glitz_function_pointer_t) glucoseUnmapBuffer; + else if (!strncmp(name, "glGenFramebuffersEXT", 20)) + address = (glitz_function_pointer_t) glucoseGenFramebuffers; + else if (!strncmp(name, "glDeleteFramebuffersEXT", 23)) + address = (glitz_function_pointer_t) glucoseDeleteFramebuffers; + else if (!strncmp(name, "glBindFramebufferEXT", 20)) + address = (glitz_function_pointer_t) glucoseBindFramebuffer; + else if (!strncmp(name, "glFramebufferRenderbufferEXT", 28)) + address = (glitz_function_pointer_t) glucoseFramebufferRenderbuffer; + else if (!strncmp(name, "glFramebufferTexture2DEXT", 25)) + address = (glitz_function_pointer_t) glucoseFramebufferTexture2D; + else if (!strncmp(name, "glCheckFramebufferStatusEXT", 27)) + address = (glitz_function_pointer_t) glucoseCheckFramebufferStatus; + else if (!strncmp(name, "glGenRenderbuffersEXT", 21)) + address = (glitz_function_pointer_t) glucoseGenRenderbuffers; + else if (!strncmp(name, "glDeleteRenderbuffersEXT", 24)) + address = (glitz_function_pointer_t) glucoseDeleteRenderbuffers; + else if (!strncmp(name, "glBindRenderbufferEXT", 21)) + address = (glitz_function_pointer_t) glucoseBindRenderbuffer; + else if (!strncmp(name, "glRenderbufferStorageEXT", 24)) + address = (glitz_function_pointer_t) glucoseRenderbufferStorage; + else if (!strncmp(name, "glGetRenderbufferParameterivEXT", 31)) + address = (glitz_function_pointer_t) glucoseGetRenderbufferParameteriv; +#endif + +#if 0 + ErrorF("FUNCTION %s = %p\n",name,address); +#endif + + return address; +} + +static void +_glitz_glucose_display_destroy (glitz_glucose_display_info_t *display_info); + +static void +_glitz_glucose_screen_destroy (glitz_glucose_screen_info_t *screen_info); + +static void +_glitz_glucose_thread_info_fini (glitz_glucose_thread_info_t *thread_info) +{ + int i; + + for (i = 0; i < thread_info->n_displays; i++) + _glitz_glucose_display_destroy (thread_info->displays[i]); + + free (thread_info->displays); + + thread_info->displays = NULL; + thread_info->n_displays = 0; + + thread_info->cctx = NULL; +} + +static glitz_glucose_thread_info_t thread_info = { + NULL, + 0, + NULL +}; + +static glitz_glucose_thread_info_t * +_glitz_glucose_thread_info_get (const char *gl_library) +{ + return &thread_info; +} + +static glitz_glucose_display_info_t * +_glitz_glucose_display_info_get (__GLXscreen *display) +{ + glitz_glucose_display_info_t *display_info; + glitz_glucose_thread_info_t *thread_info = _glitz_glucose_thread_info_get (NULL); + glitz_glucose_display_info_t **displays = thread_info->displays; + int index, n_displays = thread_info->n_displays; + + for (; n_displays; n_displays--, displays++) + if ((*displays)->display == display) + return *displays; + + index = thread_info->n_displays++; + + thread_info->displays = + realloc (thread_info->displays, + sizeof (glitz_glucose_display_info_t *) * + thread_info->n_displays); + + display_info = malloc (sizeof (glitz_glucose_display_info_t)); + thread_info->displays[index] = display_info; + + display_info->thread_info = thread_info; + display_info->display = display; + display_info->screens = NULL; + display_info->n_screens = 0; + + return display_info; +} + +static void +_glitz_glucose_display_destroy (glitz_glucose_display_info_t *display_info) +{ + int i; + + for (i = 0; i < display_info->n_screens; i++) + _glitz_glucose_screen_destroy (display_info->screens[i]); + + if (display_info->screens) + free (display_info->screens); + + free (display_info); +} + +glitz_glucose_screen_info_t * +glitz_glucose_screen_info_get (__GLXscreen *display) +{ + glitz_glucose_screen_info_t *screen_info; + glitz_glucose_display_info_t *display_info = + _glitz_glucose_display_info_get (display); + glitz_glucose_screen_info_t **screens = display_info->screens; + int index, n_screens = display_info->n_screens; + + for (; n_screens; n_screens--, screens++) + if ((*screens)->screen == display) + return *screens; + + index = display_info->n_screens++; + + display_info->screens = + realloc (display_info->screens, + sizeof (glitz_glucose_screen_info_t *) * display_info->n_screens); + + screen_info = malloc (sizeof (glitz_glucose_screen_info_t)); + display_info->screens[index] = screen_info; + + screen_info->display_info = display_info; + screen_info->drawables = 0; + screen_info->formats = NULL; + screen_info->n_formats = 0; + + screen_info->contexts = NULL; + screen_info->n_contexts = 0; + + glitz_program_map_init (&screen_info->program_map); + + screen_info->root_context = (__GLXcontext *)NULL; + screen_info->glx_feature_mask = 0; + + glitz_glucose_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_glucose_screen_destroy (glitz_glucose_screen_info_t *screen_info) +{ + int i; + + if (screen_info->root_context) + screen_info->root_context->makeCurrent (NULL); + + for (i = 0; i < screen_info->n_contexts; i++) + glitz_glucose_context_destroy (screen_info, screen_info->contexts[i]); + + if (screen_info->contexts) + free (screen_info->contexts); + + if (screen_info->formats) + free (screen_info->formats); + + free (screen_info); +} diff --git a/glucose/symlink-xgl.sh b/glucose/symlink-xgl.sh new file mode 100755 index 000000000..32da1106e --- /dev/null +++ b/glucose/symlink-xgl.sh @@ -0,0 +1,166 @@ +#!/bin/sh + +# +# A script that symlinks source files from xgl to glucose +# +# Author: Soren Sandmann (sandmann@redhat.com) (original) +# adapted for glucose by Alan Hourihane + +# +# Things we would like to do +# +# - Check that all the relevant files exist +# - AUTHORS, autogen.sh, configure.ac, ... +# - Check that we have actually linked everything +# - if a file doesn't need to be linked, then it needs +# to be listed as "not-linked" +# - Compute diffs between all the files (shouldn't be necessary) +# - possibly check that files are listet in Makefile.am's +# - Clean target directory of irrelevant files +# + +check_destinations () { + # don't do anything - we are relying on the side + # effect of dst_dir + true +} + +check_exist() { + # Check whether $1 exists + + if [ ! -e $1 ] ; then + error "$1 not found" + fi +} + +delete_existing() { + # Delete $2 + + rm -f $2 +} + +link_files() { + # Link $1 to $2 + + if [ ! -e $2 ] ; then + ln -s $1 $2 + fi +} + +main() { + check_args $1 $2 + + run check_destinations "Creating destination directories" + run check_exist "Checking that the source files exist" + run delete_existing "Deleting existing files" + run link_files "Linking files" +} + +## actual symlinking + +symlink_xgl() { + src_dir . + dst_dir . + + for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do + action `basename $src` + done +} + +######### +# +# Helper functions +# +######### + +error() { + echo + echo \ \ \ error:\ \ \ $1 + exit 1 +} + +# printing out what's going on +run_module() { + # $1 module + # $2 explanation + echo -n $EXPLANATION for $1 module ...\ + symlink_$1 + echo DONE +} + +run() { + # $1 what to do + # $2 explanation + + ACTION=$1 EXPLANATION=$2 run_module xgl +} + +src_dir() { + REAL_SRC_DIR=$SRC_DIR/$1 + if [ ! -d $REAL_SRC_DIR ] ; then + error "Source directory $REAL_SRC_DIR does not exist" + fi +} + +dst_dir() { + REAL_DST_DIR=$DST_DIR/$1 + if [ ! -d $REAL_DST_DIR ] ; then + mkdir -p $REAL_DST_DIR + fi +} + +action() { + if [ -z $2 ] ; then + $ACTION $REAL_SRC_DIR/$1 $REAL_DST_DIR/$1 + else + $ACTION $REAL_SRC_DIR/$1 $REAL_DST_DIR/$2 + fi +} + +usage() { + echo symlink-xgl.sh src-dir dst-dir + echo src-dir: the xgl source directory + echo dst-dir: the glucose directory +} + +# Check commandline args +check_args() { + if [ -z $1 ] ; then + echo Missing source dir + usage + exit 1 + fi + + if [ -z $2 ] ; then + echo Missing destination dir + usage + exit 1 + fi + + if [ ! -d $1 ] ; then + echo $1 is not a dir + usage + exit 1 + fi + + if [ ! -d $2 ] ; then + echo $2 is not a dir + usage + exit 1 + fi + + if [ $1 = $2 ] ; then + echo source and destination can\'t be the same + usage + exit 1 + fi + + D=`dirname "$relpath"` + B=`basename "$relpath"` + abspath="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B" + + SRC_DIR=`( cd $1 ; pwd )` + DST_DIR=`(cd $2 ; pwd )` +} + +main $1 $2