zlib="yes"
guest_agent="yes"
libiscsi=""
+gl="yes"
# for TIZEN-maru
maru="no"
;;
--enable-kvm) kvm="yes"
;;
+ --disable-gl) gl="no"
+ ;;
+ --enable-gl) gl="yes"
+ ;;
--disable-tcg-interpreter) tcg_interpreter="no"
;;
--enable-tcg-interpreter) tcg_interpreter="yes"
echo " --disable-slirp disable SLIRP userspace network connectivity"
echo " --disable-kvm disable KVM acceleration support"
echo " --enable-kvm enable KVM acceleration support"
+echo " --disable-gl disable GL acceleration support"
+echo " --enable-gl enable GL acceleration support"
echo " --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)"
echo " --disable-nptl disable usermode NPTL support"
echo " --enable-nptl enable usermode NPTL support"
echo "ATTR/XATTR support $attr"
echo "Install blobs $blobs"
echo "KVM support $kvm"
+echo "GL support $gl"
echo "TCG interpreter $tcg_interpreter"
echo "fdt support $fdt"
echo "preadv support $preadv"
else
echo "CONFIG_NO_XEN=y" >> $config_target_mak
fi
+ if test "$gl" = "yes" ; then
+ echo "CONFIG_GL=y" >> $config_target_mak
+ fi
;;
*)
echo "CONFIG_NO_XEN=y" >> $config_target_mak
;;
i386|mips|ppc)
cflags="-DHAS_AUDIO -DHAS_AUDIO_CHOICE $cflags"
+ if test "$gl" = "yes" ; then
+ echo "CONFIG_GL=y" >> $config_host_mak
+ if test "$mingw32" = "yes" ; then
+ echo "LIBS+=-lopengl32 -lglu32" >> $config_host_mak
+ else
+ echo "LIBS+=-lGL -lGLU -lXcomposite -lXext -ldl" >> $config_host_mak
+ fi
+ fi
;;
esac
fi
#define PCI_DEVICE_ID_VIRTIO_BALLOON 0x1002
#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003
+#define PCI_DEVICE_ID_VIRTIO_GL 0x1006
+
#define FMT_PCIBUS PRIx64
typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
return virtio_exit_pci(pci_dev);
}
+extern VirtIODevice *virtio_gl_init(DeviceState *dev);
+static int virtio_gl_init_pci(PCIDevice *pci_dev)
+{
+ VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+ VirtIODevice *vdev;
+
+ vdev = virtio_gl_init(&pci_dev->qdev);
+ if (!vdev) {
+ return -1;
+ }
+ virtio_init_pci(proxy, vdev);
+ return 0;
+}
+
static PCIDeviceInfo virtio_info[] = {
{
.qdev.name = "virtio-blk-pci",
},
.qdev.reset = virtio_pci_reset,
},{
+ .qdev.name = "virtio-gl-pci",
+ .qdev.alias = "virtio-gl",
+ .qdev.size = sizeof(VirtIOPCIProxy),
+ .init = virtio_gl_init_pci,
+ .exit = virtio_exit_pci,
+ .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+ .device_id = PCI_DEVICE_ID_VIRTIO_GL,
+ .revision = VIRTIO_PCI_ABI_VERSION,
+ .class_id = PCI_CLASS_OTHERS,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_END_OF_LIST(),
+ },
+ .qdev.reset = virtio_pci_reset,
+ },{
/* end of list */
}
};
#ifdef CONFIG_LINUX
#include "9p.h"
#endif
+#define VIRTIO_ID_GL 6
/* from Linux's linux/virtio_config.h */
if KVM support is enabled when compiling.
ETEXI
+DEF("enable-gl", 0, QEMU_OPTION_enable_gl, \
+ "-enable-gl enable OpenGL passthrough support\n", QEMU_ARCH_ALL)
+STEXI
+@item -enable-gl
+@findex -enable-gl
+Enable OpenGL passthrough support. This option requires the support of a
+special libGL installed on the guest OS.
+ETEXI
+
+
DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid,
"-xen-domid id specify xen guest domain id\n", QEMU_ARCH_ALL)
DEF("xen-create", 0, QEMU_OPTION_xen_create,
+++ /dev/null
-/* This is a generated file. Do not edit !*/
-typedef struct {
- GLuint count;
- GLenum token;
- const char *name;
-} GlGetConstant ;
-static const GlGetConstant gl_get_constants[] = {
- { 4, 0x0B00, "GL_CURRENT_COLOR" },
- { 1, 0x0B01, "GL_CURRENT_INDEX" },
- { 3, 0x0B02, "GL_CURRENT_NORMAL" },
- { 4, 0x0B03, "GL_CURRENT_TEXTURE_COORDS" },
- { 4, 0x0B04, "GL_CURRENT_RASTER_COLOR" },
- { 1, 0x0B05, "GL_CURRENT_RASTER_INDEX" },
- { 4, 0x0B06, "GL_CURRENT_RASTER_TEXTURE_COORDS" },
- { 4, 0x0B07, "GL_CURRENT_RASTER_POSITION" },
- { 1, 0x0B08, "GL_CURRENT_RASTER_POSITION_VALID" },
- { 1, 0x0B09, "GL_CURRENT_RASTER_DISTANCE" },
- { 1, 0x0B10, "GL_POINT_SMOOTH" },
- { 1, 0x0B11, "GL_POINT_SIZE" },
- { 2, 0x0B12, "GL_POINT_SIZE_RANGE" },
- { 1, 0x0B13, "GL_POINT_SIZE_GRANULARITY" },
- { 1, 0x0B20, "GL_LINE_SMOOTH" },
- { 1, 0x0B21, "GL_LINE_WIDTH" },
- { 2, 0x0B22, "GL_LINE_WIDTH_RANGE" },
- { 1, 0x0B23, "GL_LINE_WIDTH_GRANULARITY" },
- { 1, 0x0B24, "GL_LINE_STIPPLE" },
- { 1, 0x0B25, "GL_LINE_STIPPLE_PATTERN" },
- { 1, 0x0B26, "GL_LINE_STIPPLE_REPEAT" },
- { 1, 0x0B30, "GL_LIST_MODE" },
- { 1, 0x0B31, "GL_MAX_LIST_NESTING" },
- { 1, 0x0B32, "GL_LIST_BASE" },
- { 1, 0x0B33, "GL_LIST_INDEX" },
- { 2, 0x0B40, "GL_POLYGON_MODE" },
- { 1, 0x0B41, "GL_POLYGON_SMOOTH" },
- { 1, 0x0B42, "GL_POLYGON_STIPPLE" },
- { 1, 0x0B43, "GL_EDGE_FLAG" },
- { 1, 0x0B44, "GL_CULL_FACE" },
- { 1, 0x0B45, "GL_CULL_FACE_MODE" },
- { 1, 0x0B46, "GL_FRONT_FACE" },
- { 1, 0x0B50, "GL_LIGHTING" },
- { 1, 0x0B51, "GL_LIGHT_MODEL_LOCAL_VIEWER" },
- { 1, 0x0B52, "GL_LIGHT_MODEL_TWO_SIDE" },
- { 4, 0x0B53, "GL_LIGHT_MODEL_AMBIENT" },
- { 1, 0x0B54, "GL_SHADE_MODEL" },
- { 1, 0x0B55, "GL_COLOR_MATERIAL_FACE" },
- { 1, 0x0B56, "GL_COLOR_MATERIAL_PARAMETER" },
- { 1, 0x0B57, "GL_COLOR_MATERIAL" },
- { 1, 0x0B60, "GL_FOG" },
- { 1, 0x0B61, "GL_FOG_INDEX" },
- { 1, 0x0B62, "GL_FOG_DENSITY" },
- { 1, 0x0B63, "GL_FOG_START" },
- { 1, 0x0B64, "GL_FOG_END" },
- { 1, 0x0B65, "GL_FOG_MODE" },
- { 4, 0x0B66, "GL_FOG_COLOR" },
- { 2, 0x0B70, "GL_DEPTH_RANGE" },
- { 1, 0x0B71, "GL_DEPTH_TEST" },
- { 1, 0x0B72, "GL_DEPTH_WRITEMASK" },
- { 1, 0x0B73, "GL_DEPTH_CLEAR_VALUE" },
- { 1, 0x0B74, "GL_DEPTH_FUNC" },
- { 4, 0x0B80, "GL_ACCUM_CLEAR_VALUE" },
- { 1, 0x0B90, "GL_STENCIL_TEST" },
- { 1, 0x0B91, "GL_STENCIL_CLEAR_VALUE" },
- { 1, 0x0B92, "GL_STENCIL_FUNC" },
- { 1, 0x0B93, "GL_STENCIL_VALUE_MASK" },
- { 1, 0x0B94, "GL_STENCIL_FAIL" },
- { 1, 0x0B95, "GL_STENCIL_PASS_DEPTH_FAIL" },
- { 1, 0x0B96, "GL_STENCIL_PASS_DEPTH_PASS" },
- { 1, 0x0B97, "GL_STENCIL_REF" },
- { 1, 0x0B98, "GL_STENCIL_WRITEMASK" },
- { 1, 0x0BA0, "GL_MATRIX_MODE" },
- { 1, 0x0BA1, "GL_NORMALIZE" },
- { 4, 0x0BA2, "GL_VIEWPORT" },
- { 1, 0x0BA3, "GL_MODELVIEW_STACK_DEPTH" },
- { 1, 0x0BA4, "GL_PROJECTION_STACK_DEPTH" },
- { 1, 0x0BA5, "GL_TEXTURE_STACK_DEPTH" },
- { 16, 0x0BA6, "GL_MODELVIEW_MATRIX" },
- { 16, 0x0BA7, "GL_PROJECTION_MATRIX" },
- { 16, 0x0BA8, "GL_TEXTURE_MATRIX" },
- { 1, 0x0BB0, "GL_ATTRIB_STACK_DEPTH" },
- { 1, 0x0BB1, "GL_CLIENT_ATTRIB_STACK_DEPTH" },
- { 1, 0x0BC0, "GL_ALPHA_TEST" },
- { 1, 0x0BC1, "GL_ALPHA_TEST_FUNC" },
- { 1, 0x0BC2, "GL_ALPHA_TEST_REF" },
- { 1, 0x0BD0, "GL_DITHER" },
- { 1, 0x0BE0, "GL_BLEND_DST" },
- { 1, 0x0BE1, "GL_BLEND_SRC" },
- { 1, 0x0BE2, "GL_BLEND" },
- { 1, 0x0BF0, "GL_LOGIC_OP_MODE" },
- { 1, 0x0BF1, "GL_INDEX_LOGIC_OP" },
- { 1, 0x0BF2, "GL_COLOR_LOGIC_OP" },
- { 1, 0x0C00, "GL_AUX_BUFFERS" },
- { 1, 0x0C01, "GL_DRAW_BUFFER" },
- { 1, 0x0C02, "GL_READ_BUFFER" },
- { 4, 0x0C10, "GL_SCISSOR_BOX" },
- { 1, 0x0C11, "GL_SCISSOR_TEST" },
- { 1, 0x0C20, "GL_INDEX_CLEAR_VALUE" },
- { 1, 0x0C21, "GL_INDEX_WRITEMASK" },
- { 4, 0x0C22, "GL_COLOR_CLEAR_VALUE" },
- { 4, 0x0C23, "GL_COLOR_WRITEMASK" },
- { 1, 0x0C30, "GL_INDEX_MODE" },
- { 1, 0x0C31, "GL_RGBA_MODE" },
- { 1, 0x0C32, "GL_DOUBLEBUFFER" },
- { 1, 0x0C33, "GL_STEREO" },
- { 1, 0x0C40, "GL_RENDER_MODE" },
- { 1, 0x0C50, "GL_PERSPECTIVE_CORRECTION_HINT" },
- { 1, 0x0C51, "GL_POINT_SMOOTH_HINT" },
- { 1, 0x0C52, "GL_LINE_SMOOTH_HINT" },
- { 1, 0x0C53, "GL_POLYGON_SMOOTH_HINT" },
- { 1, 0x0C54, "GL_FOG_HINT" },
- { 1, 0x0C60, "GL_TEXTURE_GEN_S" },
- { 1, 0x0C61, "GL_TEXTURE_GEN_T" },
- { 1, 0x0C62, "GL_TEXTURE_GEN_R" },
- { 1, 0x0C63, "GL_TEXTURE_GEN_Q" },
- { 1, 0x0CB0, "GL_PIXEL_MAP_I_TO_I_SIZE" },
- { 1, 0x0CB1, "GL_PIXEL_MAP_S_TO_S_SIZE" },
- { 1, 0x0CB2, "GL_PIXEL_MAP_I_TO_R_SIZE" },
- { 1, 0x0CB3, "GL_PIXEL_MAP_I_TO_G_SIZE" },
- { 1, 0x0CB4, "GL_PIXEL_MAP_I_TO_B_SIZE" },
- { 1, 0x0CB5, "GL_PIXEL_MAP_I_TO_A_SIZE" },
- { 1, 0x0CB6, "GL_PIXEL_MAP_R_TO_R_SIZE" },
- { 1, 0x0CB7, "GL_PIXEL_MAP_G_TO_G_SIZE" },
- { 1, 0x0CB8, "GL_PIXEL_MAP_B_TO_B_SIZE" },
- { 1, 0x0CB9, "GL_PIXEL_MAP_A_TO_A_SIZE" },
- { 1, 0x0CF0, "GL_UNPACK_SWAP_BYTES" },
- { 1, 0x0CF1, "GL_UNPACK_LSB_FIRST" },
- { 1, 0x0CF2, "GL_UNPACK_ROW_LENGTH" },
- { 1, 0x0CF3, "GL_UNPACK_SKIP_ROWS" },
- { 1, 0x0CF4, "GL_UNPACK_SKIP_PIXELS" },
- { 1, 0x0CF5, "GL_UNPACK_ALIGNMENT" },
- { 1, 0x0D00, "GL_PACK_SWAP_BYTES" },
- { 1, 0x0D01, "GL_PACK_LSB_FIRST" },
- { 1, 0x0D02, "GL_PACK_ROW_LENGTH" },
- { 1, 0x0D03, "GL_PACK_SKIP_ROWS" },
- { 1, 0x0D04, "GL_PACK_SKIP_PIXELS" },
- { 1, 0x0D05, "GL_PACK_ALIGNMENT" },
- { 1, 0x0D10, "GL_MAP_COLOR" },
- { 1, 0x0D11, "GL_MAP_STENCIL" },
- { 1, 0x0D12, "GL_INDEX_SHIFT" },
- { 1, 0x0D13, "GL_INDEX_OFFSET" },
- { 1, 0x0D14, "GL_RED_SCALE" },
- { 1, 0x0D15, "GL_RED_BIAS" },
- { 1, 0x0D16, "GL_ZOOM_X" },
- { 1, 0x0D17, "GL_ZOOM_Y" },
- { 1, 0x0D18, "GL_GREEN_SCALE" },
- { 1, 0x0D19, "GL_GREEN_BIAS" },
- { 1, 0x0D1A, "GL_BLUE_SCALE" },
- { 1, 0x0D1B, "GL_BLUE_BIAS" },
- { 1, 0x0D1C, "GL_ALPHA_SCALE" },
- { 1, 0x0D1D, "GL_ALPHA_BIAS" },
- { 1, 0x0D1E, "GL_DEPTH_SCALE" },
- { 1, 0x0D1F, "GL_DEPTH_BIAS" },
- { 1, 0x0D30, "GL_MAX_EVAL_ORDER" },
- { 1, 0x0D31, "GL_MAX_LIGHTS" },
- { 1, 0x0D32, "GL_MAX_CLIP_PLANES" },
- { 1, 0x0D33, "GL_MAX_TEXTURE_SIZE" },
- { 1, 0x0D34, "GL_MAX_PIXEL_MAP_TABLE" },
- { 1, 0x0D35, "GL_MAX_ATTRIB_STACK_DEPTH" },
- { 1, 0x0D36, "GL_MAX_MODELVIEW_STACK_DEPTH" },
- { 1, 0x0D37, "GL_MAX_NAME_STACK_DEPTH" },
- { 1, 0x0D38, "GL_MAX_PROJECTION_STACK_DEPTH" },
- { 1, 0x0D39, "GL_MAX_TEXTURE_STACK_DEPTH" },
- { 2, 0x0D3A, "GL_MAX_VIEWPORT_DIMS" },
- { 1, 0x0D3B, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
- { 1, 0x0D50, "GL_SUBPIXEL_BITS" },
- { 1, 0x0D51, "GL_INDEX_BITS" },
- { 1, 0x0D52, "GL_RED_BITS" },
- { 1, 0x0D53, "GL_GREEN_BITS" },
- { 1, 0x0D54, "GL_BLUE_BITS" },
- { 1, 0x0D55, "GL_ALPHA_BITS" },
- { 1, 0x0D56, "GL_DEPTH_BITS" },
- { 1, 0x0D57, "GL_STENCIL_BITS" },
- { 1, 0x0D58, "GL_ACCUM_RED_BITS" },
- { 1, 0x0D59, "GL_ACCUM_GREEN_BITS" },
- { 1, 0x0D5A, "GL_ACCUM_BLUE_BITS" },
- { 1, 0x0D5B, "GL_ACCUM_ALPHA_BITS" },
- { 1, 0x0D70, "GL_NAME_STACK_DEPTH" },
- { 1, 0x0D80, "GL_AUTO_NORMAL" },
- { 1, 0x0D90, "GL_MAP1_COLOR_4" },
- { 1, 0x0D91, "GL_MAP1_INDEX" },
- { 1, 0x0D92, "GL_MAP1_NORMAL" },
- { 1, 0x0D93, "GL_MAP1_TEXTURE_COORD_1" },
- { 1, 0x0D94, "GL_MAP1_TEXTURE_COORD_2" },
- { 1, 0x0D95, "GL_MAP1_TEXTURE_COORD_3" },
- { 1, 0x0D96, "GL_MAP1_TEXTURE_COORD_4" },
- { 1, 0x0D97, "GL_MAP1_VERTEX_3" },
- { 1, 0x0D98, "GL_MAP1_VERTEX_4" },
- { 1, 0x0DB0, "GL_MAP2_COLOR_4" },
- { 1, 0x0DB1, "GL_MAP2_INDEX" },
- { 1, 0x0DB2, "GL_MAP2_NORMAL" },
- { 1, 0x0DB3, "GL_MAP2_TEXTURE_COORD_1" },
- { 1, 0x0DB4, "GL_MAP2_TEXTURE_COORD_2" },
- { 1, 0x0DB5, "GL_MAP2_TEXTURE_COORD_3" },
- { 1, 0x0DB6, "GL_MAP2_TEXTURE_COORD_4" },
- { 1, 0x0DB7, "GL_MAP2_VERTEX_3" },
- { 1, 0x0DB8, "GL_MAP2_VERTEX_4" },
- { 2, 0x0DD0, "GL_MAP1_GRID_DOMAIN" },
- { 1, 0x0DD1, "GL_MAP1_GRID_SEGMENTS" },
- { 4, 0x0DD2, "GL_MAP2_GRID_DOMAIN" },
- { 2, 0x0DD3, "GL_MAP2_GRID_SEGMENTS" },
- { 1, 0x0DE0, "GL_TEXTURE_1D" },
- { 1, 0x0DE1, "GL_TEXTURE_2D" },
- { 1, 0x0DF1, "GL_FEEDBACK_BUFFER_SIZE" },
- { 1, 0x0DF2, "GL_FEEDBACK_BUFFER_TYPE" },
- { 1, 0x0DF4, "GL_SELECTION_BUFFER_SIZE" },
- { 1, 0x2200, "GL_TEXTURE_ENV_MODE" },
- { 4, 0x2201, "GL_TEXTURE_ENV_COLOR" },
- { 1, 0x2A00, "GL_POLYGON_OFFSET_UNITS" },
- { 1, 0x3000, "GL_CLIP_PLANE0" },
- { 1, 0x3001, "GL_CLIP_PLANE1" },
- { 1, 0x3002, "GL_CLIP_PLANE2" },
- { 1, 0x3003, "GL_CLIP_PLANE3" },
- { 1, 0x3004, "GL_CLIP_PLANE4" },
- { 1, 0x3005, "GL_CLIP_PLANE5" },
- { 1, 0x4000, "GL_LIGHT0" },
- { 1, 0x4001, "GL_LIGHT1" },
- { 1, 0x4002, "GL_LIGHT2" },
- { 1, 0x4003, "GL_LIGHT3" },
- { 1, 0x4004, "GL_LIGHT4" },
- { 1, 0x4005, "GL_LIGHT5" },
- { 1, 0x4006, "GL_LIGHT6" },
- { 1, 0x4007, "GL_LIGHT7" },
- { 4, 0x8005, "GL_BLEND_COLOR_EXT" },
- { 1, 0x8009, "GL_BLEND_EQUATION" },
- { 1, 0x8010, "GL_CONVOLUTION_1D_EXT" },
- { 1, 0x8011, "GL_CONVOLUTION_2D_EXT" },
- { 1, 0x8012, "GL_SEPARABLE_2D_EXT" },
- { 1, 0x801C, "GL_POST_CONVOLUTION_RED_SCALE_EXT" },
- { 1, 0x801D, "GL_POST_CONVOLUTION_GREEN_SCALE_EXT" },
- { 1, 0x801E, "GL_POST_CONVOLUTION_BLUE_SCALE_EXT" },
- { 1, 0x801F, "GL_POST_CONVOLUTION_ALPHA_SCALE_EXT" },
- { 1, 0x8020, "GL_POST_CONVOLUTION_RED_BIAS_EXT" },
- { 1, 0x8021, "GL_POST_CONVOLUTION_GREEN_BIAS_EXT" },
- { 1, 0x8022, "GL_POST_CONVOLUTION_BLUE_BIAS_EXT" },
- { 1, 0x8023, "GL_POST_CONVOLUTION_ALPHA_BIAS_EXT" },
- { 1, 0x8024, "GL_HISTOGRAM" },
- { 1, 0x802E, "GL_MINMAX" },
- { 1, 0x8038, "GL_POLYGON_OFFSET_FACTOR" },
- { 1, 0x8039, "GL_POLYGON_OFFSET_BIAS_EXT" },
- { 1, 0x803A, "GL_RESCALE_NORMAL" },
- { 1, 0x8068, "GL_TEXTURE_BINDING_1D" },
- { 1, 0x8069, "GL_TEXTURE_BINDING_2D" },
- { 1, 0x806A, "GL_TEXTURE_BINDING_3D" },
- { 1, 0x806B, "GL_PACK_SKIP_IMAGES_EXT" },
- { 1, 0x806C, "GL_PACK_IMAGE_HEIGHT_EXT" },
- { 1, 0x806D, "GL_UNPACK_SKIP_IMAGES_EXT" },
- { 1, 0x806E, "GL_UNPACK_IMAGE_HEIGHT_EXT" },
- { 1, 0x806F, "GL_TEXTURE_3D" },
- { 1, 0x8073, "GL_MAX_3D_TEXTURE_SIZE" },
- { 1, 0x8074, "GL_VERTEX_ARRAY" },
- { 1, 0x8075, "GL_NORMAL_ARRAY" },
- { 1, 0x8076, "GL_COLOR_ARRAY" },
- { 1, 0x8077, "GL_INDEX_ARRAY" },
- { 1, 0x8078, "GL_TEXTURE_COORD_ARRAY" },
- { 1, 0x8079, "GL_EDGE_FLAG_ARRAY" },
- { 1, 0x807A, "GL_VERTEX_ARRAY_SIZE" },
- { 1, 0x807B, "GL_VERTEX_ARRAY_TYPE" },
- { 1, 0x807C, "GL_VERTEX_ARRAY_STRIDE" },
- { 1, 0x807D, "GL_VERTEX_ARRAY_COUNT_EXT" },
- { 1, 0x807E, "GL_NORMAL_ARRAY_TYPE" },
- { 1, 0x807F, "GL_NORMAL_ARRAY_STRIDE" },
- { 1, 0x8080, "GL_NORMAL_ARRAY_COUNT_EXT" },
- { 1, 0x8081, "GL_COLOR_ARRAY_SIZE" },
- { 1, 0x8082, "GL_COLOR_ARRAY_TYPE" },
- { 1, 0x8083, "GL_COLOR_ARRAY_STRIDE" },
- { 1, 0x8084, "GL_COLOR_ARRAY_COUNT_EXT" },
- { 1, 0x8085, "GL_INDEX_ARRAY_TYPE" },
- { 1, 0x8086, "GL_INDEX_ARRAY_STRIDE" },
- { 1, 0x8087, "GL_INDEX_ARRAY_COUNT_EXT" },
- { 1, 0x8088, "GL_TEXTURE_COORD_ARRAY_SIZE" },
- { 1, 0x8089, "GL_TEXTURE_COORD_ARRAY_TYPE" },
- { 1, 0x808A, "GL_TEXTURE_COORD_ARRAY_STRIDE" },
- { 1, 0x808B, "GL_TEXTURE_COORD_ARRAY_COUNT_EXT" },
- { 1, 0x808C, "GL_EDGE_FLAG_ARRAY_STRIDE" },
- { 1, 0x808D, "GL_EDGE_FLAG_ARRAY_COUNT_EXT" },
- { 1, 0x809D, "GL_MULTISAMPLE_ARB" },
- { 1, 0x809E, "GL_SAMPLE_ALPHA_TO_COVERAGE_ARB" },
- { 1, 0x809F, "GL_SAMPLE_ALPHA_TO_ONE_ARB" },
- { 1, 0x80A0, "GL_SAMPLE_COVERAGE_ARB" },
- { 1, 0x80A8, "GL_SAMPLE_BUFFERS_ARB" },
- { 1, 0x80A9, "GL_SAMPLES_ARB" },
- { 1, 0x80AA, "GL_SAMPLE_COVERAGE_VALUE_ARB" },
- { 1, 0x80AB, "GL_SAMPLE_COVERAGE_INVERT_ARB" },
- { 16, 0x80B1, "GL_COLOR_MATRIX_SGI" },
- { 1, 0x80B2, "GL_COLOR_MATRIX_STACK_DEPTH_SGI" },
- { 1, 0x80B3, "GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI" },
- { 1, 0x80B4, "GL_POST_COLOR_MATRIX_RED_SCALE_SGI" },
- { 1, 0x80B5, "GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI" },
- { 1, 0x80B6, "GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI" },
- { 1, 0x80B7, "GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI" },
- { 1, 0x80B8, "GL_POST_COLOR_MATRIX_RED_BIAS_SGI" },
- { 1, 0x80B9, "GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI" },
- { 1, 0x80BA, "GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI" },
- { 1, 0x80BB, "GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI" },
- { 1, 0x80BC, "GL_TEXTURE_COLOR_TABLE_SGI" },
- { 1, 0x80C8, "GL_BLEND_DST_RGB_EXT" },
- { 1, 0x80C9, "GL_BLEND_SRC_RGB_EXT" },
- { 1, 0x80CA, "GL_BLEND_DST_ALPHA_EXT" },
- { 1, 0x80CB, "GL_BLEND_SRC_ALPHA_EXT" },
- { 1, 0x80D0, "GL_COLOR_TABLE_SGI" },
- { 1, 0x80D1, "GL_POST_CONVOLUTION_COLOR_TABLE_SGI" },
- { 1, 0x80D2, "GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI" },
- { 1, 0x80E8, "GL_MAX_ELEMENTS_VERTICES" },
- { 1, 0x80E9, "GL_MAX_ELEMENTS_INDICES" },
- { 1, 0x8126, "GL_POINT_SIZE_MIN_EXT" },
- { 1, 0x8127, "GL_POINT_SIZE_MAX_EXT" },
- { 1, 0x8128, "GL_POINT_FADE_THRESHOLD_SIZE_EXT" },
- { 3, 0x8129, "GL_DISTANCE_ATTENUATION_EXT" },
- { 1, 0x8149, "GL_SPRITE_MODE_SGIX" },
- { 3, 0x814A, "GL_SPRITE_AXIS_SGIX " },
- { 3, 0x814B, "GL_SPRITE_TRANSLATION_SGIX" },
- { 4, 0x817E, "GL_REFERENCE_PLANE_EQUATION_SGIX" },
- { 1, 0x8192, "GL_GENERATE_MIPMAP_HINT_SGIS" },
- { 1, 0x81A8, "GL_ARRAY_ELEMENT_LOCK_FIRST_EXT" },
- { 1, 0x81A9, "GL_ARRAY_ELEMENT_LOCK_COUNT_EXT" },
- { 1, 0x81F8, "GL_LIGHT_MODEL_COLOR_CONTROL" },
- { 1, 0x81FB, "GL_SHARED_TEXTURE_PALETTE_EXT" },
- { 1, 0x8450, "GL_FOG_COORDINATE_SOURCE_EXT" },
- { 1, 0x8453, "GL_CURRENT_FOG_COORDINATE_EXT" },
- { 1, 0x8454, "GL_FOG_COORDINATE_ARRAY_TYPE_EXT" },
- { 1, 0x8455, "GL_FOG_COORDINATE_ARRAY_STRIDE_EXT" },
- { 1, 0x8457, "GL_FOG_COORDINATE_ARRAY_EXT" },
- { 1, 0x8458, "GL_COLOR_SUM_EXT" },
- { 4, 0x8459, "GL_CURRENT_SECONDARY_COLOR_EXT" },
- { 1, 0x845A, "GL_SECONDARY_COLOR_ARRAY_SIZE_EXT" },
- { 1, 0x845B, "GL_SECONDARY_COLOR_ARRAY_TYPE_EXT" },
- { 1, 0x845C, "GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT" },
- { 1, 0x845E, "GL_SECONDARY_COLOR_ARRAY_EXT" },
- { 4, 0x845F, "GL_CURRENT_RASTER_SECONDARY_COLOR" },
- { 2, 0x846D, "GL_ALIASED_POINT_SIZE_RANGE" },
- { 2, 0x846E, "GL_ALIASED_LINE_WIDTH_RANGE" },
- { 1, 0x84E0, "GL_ACTIVE_TEXTURE_ARB" },
- { 1, 0x84E1, "GL_CLIENT_ACTIVE_TEXTURE_ARB" },
- { 1, 0x84E2, "GL_MAX_TEXTURE_UNITS_ARB" },
- { 16, 0x84E3, "GL_TRANSPOSE_MODELVIEW_MATRIX_ARB" },
- { 16, 0x84E4, "GL_TRANSPOSE_PROJECTION_MATRIX_ARB" },
- { 16, 0x84E5, "GL_TRANSPOSE_TEXTURE_MATRIX_ARB" },
- { 16, 0x84E6, "GL_TRANSPOSE_COLOR_MATRIX_ARB" },
- { 1, 0x84E8, "GL_MAX_RENDERBUFFER_SIZE_EXT" },
- { 1, 0x84EF, "GL_TEXTURE_COMPRESSION_HINT_ARB" },
- { 1, 0x84F5, "GL_TEXTURE_RECTANGLE_NV" },
- { 1, 0x84F6, "GL_TEXTURE_BINDING_RECTANGLE_NV" },
- { 1, 0x84F8, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
- { 1, 0x84FD, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
- { 1, 0x84FF, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
- { 1, 0x8504, "GL_MAX_SHININESS_NV" },
- { 1, 0x8505, "GL_MAX_SPOT_EXPONENT_NV" },
- { 1, 0x8513, "GL_TEXTURE_CUBE_MAP_ARB" },
- { 1, 0x8514, "GL_TEXTURE_BINDING_CUBE_MAP_ARB" },
- { 1, 0x851C, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
- { 1, 0x854D, "GL_MAX_GENERAL_COMBINERS_NV" },
- { 1, 0x85B2, "GL_UNPACK_CLIENT_STORAGE_APPLE" },
- { 1, 0x8620, "GL_VERTEX_PROGRAM_ARB" },
- { 1, 0x862E, "GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB" },
- { 1, 0x862F, "GL_MAX_PROGRAM_MATRICES_ARB" },
- { 1, 0x8640, "GL_CURRENT_MATRIX_STACK_DEPTH_ARB" },
- { 16, 0x8641, "GL_CURRENT_MATRIX_ARB" },
- { 1, 0x8642, "GL_VERTEX_PROGRAM_POINT_SIZE_ARB" },
- { 1, 0x8643, "GL_VERTEX_PROGRAM_TWO_SIDE_ARB" },
- { 1, 0x864A, "GL_VERTEX_PROGRAM_BINDING_NV" },
- { 1, 0x864B, "GL_PROGRAM_ERROR_POSITION_ARB" },
- { 1, 0x8650, "GL_VERTEX_ATTRIB_ARRAY0_NV" },
- { 1, 0x8651, "GL_VERTEX_ATTRIB_ARRAY1_NV" },
- { 1, 0x8652, "GL_VERTEX_ATTRIB_ARRAY2_NV" },
- { 1, 0x8653, "GL_VERTEX_ATTRIB_ARRAY3_NV" },
- { 1, 0x8654, "GL_VERTEX_ATTRIB_ARRAY4_NV" },
- { 1, 0x8655, "GL_VERTEX_ATTRIB_ARRAY5_NV" },
- { 1, 0x8656, "GL_VERTEX_ATTRIB_ARRAY6_NV" },
- { 1, 0x8657, "GL_VERTEX_ATTRIB_ARRAY7_NV" },
- { 1, 0x8658, "GL_VERTEX_ATTRIB_ARRAY8_NV" },
- { 1, 0x8659, "GL_VERTEX_ATTRIB_ARRAY9_NV" },
- { 1, 0x865A, "GL_VERTEX_ATTRIB_ARRAY10_NV" },
- { 1, 0x865B, "GL_VERTEX_ATTRIB_ARRAY11_NV" },
- { 1, 0x865C, "GL_VERTEX_ATTRIB_ARRAY12_NV" },
- { 1, 0x865D, "GL_VERTEX_ATTRIB_ARRAY13_NV" },
- { 1, 0x865E, "GL_VERTEX_ATTRIB_ARRAY14_NV" },
- { 1, 0x865F, "GL_VERTEX_ATTRIB_ARRAY15_NV" },
- { 1, 0x8660, "GL_MAP1_VERTEX_ATTRIB0_4_NV" },
- { 1, 0x8661, "GL_MAP1_VERTEX_ATTRIB1_4_NV" },
- { 1, 0x8662, "GL_MAP1_VERTEX_ATTRIB2_4_NV" },
- { 1, 0x8663, "GL_MAP1_VERTEX_ATTRIB3_4_NV" },
- { 1, 0x8664, "GL_MAP1_VERTEX_ATTRIB4_4_NV" },
- { 1, 0x8665, "GL_MAP1_VERTEX_ATTRIB5_4_NV" },
- { 1, 0x8666, "GL_MAP1_VERTEX_ATTRIB6_4_NV" },
- { 1, 0x8667, "GL_MAP1_VERTEX_ATTRIB7_4_NV" },
- { 1, 0x8668, "GL_MAP1_VERTEX_ATTRIB8_4_NV" },
- { 1, 0x8669, "GL_MAP1_VERTEX_ATTRIB9_4_NV" },
- { 1, 0x866A, "GL_MAP1_VERTEX_ATTRIB10_4_NV" },
- { 1, 0x866B, "GL_MAP1_VERTEX_ATTRIB11_4_NV" },
- { 1, 0x866C, "GL_MAP1_VERTEX_ATTRIB12_4_NV" },
- { 1, 0x866D, "GL_MAP1_VERTEX_ATTRIB13_4_NV" },
- { 1, 0x866E, "GL_MAP1_VERTEX_ATTRIB14_4_NV" },
- { 1, 0x866F, "GL_MAP1_VERTEX_ATTRIB15_4_NV" },
- { 1, 0x86A2, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
- { 1, 0x8758, "GL_PACK_INVERT_MESA" },
- { 1, 0x87C5, "GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT" },
- { 1, 0x87C6, "GL_MAX_VERTEX_SHADER_VARIANTS_EXT" },
- { 1, 0x87C7, "GL_MAX_VERTEX_SHADER_INVARIANTS_EXT" },
- { 1, 0x87C8, "GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT" },
- { 1, 0x87C9, "GL_MAX_VERTEX_SHADER_LOCALS_EXT" },
- { 1, 0x87CA, "GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT" },
- { 1, 0x87CB, "GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT" },
- { 1, 0x87CC, "GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT" },
- { 1, 0x87CC, "GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT" },
- { 1, 0x87CD, "GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT" },
- { 1, 0x8800, "GL_STENCIL_BACK_FUNC" },
- { 1, 0x8801, "GL_STENCIL_BACK_FAIL" },
- { 1, 0x8802, "GL_STENCIL_BACK_PASS_DEPTH_FAIL" },
- { 1, 0x8803, "GL_STENCIL_BACK_PASS_DEPTH_PASS" },
- { 1, 0x8804, "GL_FRAGMENT_PROGRAM_ARB" },
- { 1, 0x8824, "GL_MAX_DRAW_BUFFERS_ARB" },
- { 1, 0x8825, "GL_DRAW_BUFFER0_ARB" },
- { 1, 0x8826, "GL_DRAW_BUFFER1_ARB" },
- { 1, 0x8827, "GL_DRAW_BUFFER2_ARB" },
- { 1, 0x8828, "GL_DRAW_BUFFER3_ARB" },
- { 1, 0x883D, "GL_BLEND_EQUATION_ALPHA_EXT" },
- { 1, 0x8861, "GL_POINT_SPRITE_NV" },
- { 1, 0x8863, "GL_POINT_SPRITE_R_MODE_NV" },
- { 1, 0x8868, "GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV" },
- { 1, 0x8869, "GL_MAX_VERTEX_ATTRIBS_ARB" },
- { 1, 0x8870, "GL_FRAGMENT_PROGRAM_NV" },
- { 1, 0x8871, "GL_MAX_TEXTURE_COORDS_ARB" },
- { 1, 0x8872, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
- { 1, 0x8873, "GL_FRAGMENT_PROGRAM_BINDING_NV" },
- { 1, 0x8890, "GL_DEPTH_BOUNDS_TEST_EXT" },
- { 2, 0x8891, "GL_DEPTH_BOUNDS_EXT" },
- { 1, 0x8894, "GL_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x8895, "GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x8896, "GL_VERTEX_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x8897, "GL_NORMAL_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x8898, "GL_COLOR_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x8899, "GL_INDEX_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x889A, "GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x889B, "GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x889C, "GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB" },
- { 1, 0x889D, "GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB" },
- { 16, 0x88B7, "GL_TRANSPOSE_CURRENT_MATRIX_ARB" },
- { 1, 0x88ED, "GL_PIXEL_PACK_BUFFER_BINDING_EXT" },
- { 1, 0x88EF, "GL_PIXEL_UNPACK_BUFFER_BINDING_EXT" },
- { 1, 0x8910, "GL_STENCIL_TEST_TWO_SIDE_EXT" },
- { 1, 0x8911, "GL_ACTIVE_STENCIL_FACE_EXT" },
- { 1, 0x896E, "GL_NUM_FRAGMENT_REGISTERS_ATI" },
- { 1, 0x896F, "GL_NUM_FRAGMENT_CONSTANTS_ATI" },
- { 1, 0x8970, "GL_NUM_PASSES_ATI" },
- { 1, 0x8971, "GL_NUM_INSTRUCTIONS_PER_PASS_ATI" },
- { 1, 0x8972, "GL_NUM_INSTRUCTIONS_TOTAL_ATI" },
- { 1, 0x8973, "GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI" },
- { 1, 0x8974, "GL_NUM_LOOPBACK_COMPONENTS_ATI" },
- { 1, 0x8975, "GL_COLOR_ALPHA_PAIRING_ATI" },
- { 1, 0x8B49, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
- { 1, 0x8B4A, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
- { 1, 0x8B4B, "GL_MAX_VARYING_FLOATS_ARB" },
- { 1, 0x8B4C, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
- { 1, 0x8B4D, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
- { 1, 0x8B8B, "GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB" },
- { 1, 0x8B9A, "GL_IMPLEMENTATION_COLOR_READ_TYPE_OES" },
- { 1, 0x8B9B, "GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES" },
- { 1, 0x8BB0, "GL_FRAGMENT_PROGRAM_POSITION_MESA" },
- { 1, 0x8BB1, "GL_FRAGMENT_PROGRAM_CALLBACK_MESA" },
- { 1, 0x8BB4, "GL_VERTEX_PROGRAM_POSITION_MESA" },
- { 1, 0x8BB5, "GL_VERTEX_PROGRAM_CALLBACK_MESA" },
- { 1, 0x8CA0, "GL_POINT_SPRITE_COORD_ORIGIN" },
- { 1, 0x8CA3, "GL_STENCIL_BACK_REF" },
- { 1, 0x8CA4, "GL_STENCIL_BACK_VALUE_MASK" },
- { 1, 0x8CA6, "GL_FRAMEBUFFER_BINDING_EXT" },
- { 1, 0x8CA7, "GL_RENDERBUFFER_BINDING_EXT" },
- { 1, 0x8CDF, "GL_MAX_COLOR_ATTACHMENTS_EXT" },
- { 1, 0x19262, "GL_RASTER_POSITION_UNCLIPPED_IBM" },
-};
+++ /dev/null
-/*
- * Host-side implementation of GL/GLX API
- *
- * Copyright (c) 2006,2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifdef _WIN32
-#ifndef _GNU_SOURCE
- #define _GNU_SOURCE
-#endif
-#endif
-
-#define _XOPEN_SOURCE 600
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-//#include "exec.h"
-#include "cpu.h"
-#include "dyngen-exec.h"
-
-#ifndef _WIN32
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#else
-#include <windows.h>
-
-typedef HDC GLDisplay;
-HWND displayHWND;
-#endif
-
-//## remove GCC warning
-//#include "qemu-common.h"
-//#include "opengl_func.h"
-#include "helper_opengl.h"
-
-#define ENABLE_GL_LOG
-
-//#ifdef _WIN32
-//extern int do_function_call(Display dpy, int func_number, int pid, int* args, char* ret_string);
-//#else
-//extern int do_function_call(Display* dpy, int func_number, int pid, int* args, char* ret_string);
-//#endif
-extern int last_process_id;
-
-#ifndef _WIN32
-extern void sdl_set_opengl_window(int x, int y, int width, int height);
-#endif
-
-#ifdef _WIN32
-static GLDisplay CreateDisplay(void)
-{
- HWND hWnd;
- WNDCLASS wc;
- LPCSTR ClassName ="DISPLAY";
- HINSTANCE hInstance = 0;
-
- /* only register the window class once - use hInstance as a flag. */
- hInstance = GetModuleHandle(NULL);
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = (WNDPROC)DefWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = ClassName;
-
- RegisterClass(&wc);
-
- displayHWND = CreateWindow(ClassName, ClassName, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU ),
- 0, 0, 10, 10, NULL, (HMENU)NULL, hInstance, NULL);
-
-
- ShowWindow(hWnd, SW_HIDE);
-
- return GetDC(displayHWND);
-}
-#endif
-
-static int must_save = 0;
-
-static inline void* get_phys_mem_addr(const CPUState *env, target_ulong addr)
-{
-#if 1
- void *ret;
- ret = qemu_get_ram_ptr(addr);
-
- return ret;
-#endif
-#if 0
- int is_user, index;
- index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
- is_user = ((env->hflags & HF_CPL_MASK) == 3);
- if (is_user == 0)
- {
- fprintf(stderr, "not in userland !!!\n");
- return NULL;
- }
- if (__builtin_expect(env->tlb_table[is_user][index].addr_code !=
- (addr & TARGET_PAGE_MASK), 0))
- {
- target_ulong ret = cpu_get_phys_page_debug((CPUState *)env, addr);
- if (ret == -1)
- {
- fprintf(stderr, "cpu_get_phys_page_debug(env, %x) == %x\n", addr, ret);
- fprintf(stderr, "not in phys mem %x (%x %x)\n", addr, env->tlb_table[is_user][index].addr_code, addr & TARGET_PAGE_MASK);
- fprintf(stderr, "cpu_x86_handle_mmu_fault = %d\n",
- cpu_x86_handle_mmu_fault((CPUState*)env, addr, 0, 1, 1));
- return NULL;
- }
- else
- {
- if (ret + TARGET_PAGE_SIZE <= ldl_phys(0))
- {
- //return phys_ram_base + ret + (((target_ulong)addr) & (TARGET_PAGE_SIZE - 1));
- //return qemu_get_buffer(ret + (((target_ulong)addr) & (TARGET_PAGE_SIZE - 1)));
- //return ldl_phys(0) + ret + (((target_ulong)addr) & (TARGET_PAGE_SIZE - 1));
- return qemu_get_ram_ptr(ret + (((target_ulong)addr) & (TARGET_PAGE_SIZE - 1)));
- }
- else
- {
- fprintf(stderr, "cpu_get_phys_page_debug(env, %x) == %xp\n", addr, ret);
- //fprintf(stderr, "ret=%x phys_ram_size=%x\n", ret, phys_ram_size);
- fprintf(stderr, "ret=%x ldl_phys(0)=%x\n", ret, ldl_phys(0));
- return NULL;
- }
- }
- }
- else
- {
- return (void*)(addr + env->tlb_table[is_user][index].addend);
- }
-#endif
-}
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-enum
-{
- NOT_MAPPED,
- MAPPED_CONTIGUOUS,
- MAPPED_NOT_CONTIGUOUS
-};
-
-#define TARGET_ADDR_LOW_ALIGN(x) ((target_ulong)(x) & ~(TARGET_PAGE_SIZE - 1))
-
-/* Return NOT_MAPPED if a page is not mapped into target physical memory */
-/* MAPPED_CONTIGUOUS if all pages are mapped into target physical memory and contiguous */
-/* MAPPED_NOT_CONTIGUOUS if all pages are mapped into target physical memory but not contiguous */
-static int get_target_mem_state(const CPUState *env, target_ulong target_addr, int len)
-{
- target_ulong aligned_target_addr = TARGET_ADDR_LOW_ALIGN(target_addr);
- int to_end_page = (long)aligned_target_addr + TARGET_PAGE_SIZE - (long)target_addr;
- int ret = MAPPED_CONTIGUOUS;
-
- if (aligned_target_addr != target_addr)
- {
- void* phys_addr = get_phys_mem_addr(env, aligned_target_addr);
- void* last_phys_addr = phys_addr;
- if (phys_addr == 0)
- {
- return NOT_MAPPED;
- }
- if (len > to_end_page)
- {
- len -= to_end_page;
- aligned_target_addr += TARGET_PAGE_SIZE;
- int i;
- for(i=0;i<len;i+=TARGET_PAGE_SIZE)
- {
- void* phys_addr = get_phys_mem_addr(env, aligned_target_addr + i);
- if (phys_addr == 0)
- {
- return NOT_MAPPED;
- }
- if (phys_addr != last_phys_addr + TARGET_PAGE_SIZE)
- ret = MAPPED_NOT_CONTIGUOUS;
- last_phys_addr = phys_addr;
- }
- }
- }
- else
- {
- void* last_phys_addr = NULL;
- int i;
- for(i=0;i<len;i+=TARGET_PAGE_SIZE)
- {
- void* phys_addr = get_phys_mem_addr(env, target_addr + i);
- if (phys_addr == 0)
- {
- return NOT_MAPPED;
- }
- if (i != 0 && phys_addr != last_phys_addr + TARGET_PAGE_SIZE)
- ret = MAPPED_NOT_CONTIGUOUS;
- last_phys_addr = phys_addr;
- }
- }
- return ret;
-}
-
-/* copy len bytes from host memory at addr host_addr to target memory at logical addr target_addr */
-/* Returns 1 if successfull, 0 if some target pages are not mapped into target physical memory */
-static int memcpy_host_to_target(const CPUState *env, target_ulong target_addr, const void* host_addr, int len)
-{
- int i;
- target_ulong aligned_target_addr = TARGET_ADDR_LOW_ALIGN(target_addr);
- int to_end_page = (long)aligned_target_addr + TARGET_PAGE_SIZE - (long)target_addr;
- int ret = get_target_mem_state(env, target_addr, len);
- if (ret == NOT_MAPPED)
- {
- return 0;
- }
-
- if (ret == MAPPED_CONTIGUOUS)
- {
- void *phys_addr = get_phys_mem_addr(env, target_addr);
- memcpy(phys_addr, host_addr, len);
- }
- else
- {
- if (aligned_target_addr != target_addr)
- {
- void* phys_addr = get_phys_mem_addr(env, target_addr);
- memcpy(phys_addr, host_addr, MIN(len, to_end_page));
- if (len <= to_end_page)
- {
- return 1;
- }
- len -= to_end_page;
- host_addr += to_end_page;
- target_addr = aligned_target_addr + TARGET_PAGE_SIZE;
- }
- for(i=0;i<len;i+=TARGET_PAGE_SIZE)
- {
- void *phys_addr = get_phys_mem_addr(env, target_addr + i);
- memcpy(phys_addr, host_addr + i, (i + TARGET_PAGE_SIZE <= len) ? TARGET_PAGE_SIZE : len & (TARGET_PAGE_SIZE - 1));
- }
- }
-
- return 1;
-}
-
-static int memcpy_target_to_host(const CPUState *env, void* host_addr, target_ulong target_addr, int len)
-{
- int i;
- target_ulong aligned_target_addr = TARGET_ADDR_LOW_ALIGN(target_addr);
- int to_end_page = (long)aligned_target_addr + TARGET_PAGE_SIZE - (long)target_addr;
- int ret = get_target_mem_state(env, target_addr, len);
- if (ret == NOT_MAPPED)
- {
- return 0;
- }
-
- if (ret == MAPPED_CONTIGUOUS)
- {
- void *phys_addr = get_phys_mem_addr(env, target_addr);
- memcpy(host_addr, phys_addr, len);
- }
- else
- {
- if (aligned_target_addr != target_addr)
- {
- void* phys_addr = get_phys_mem_addr(env, target_addr);
- memcpy(host_addr, phys_addr, MIN(len, to_end_page));
- if (len <= to_end_page)
- {
- return 1;
- }
- len -= to_end_page;
- host_addr += to_end_page;
- target_addr = aligned_target_addr + TARGET_PAGE_SIZE;
- }
- for(i=0;i<len;i+=TARGET_PAGE_SIZE)
- {
- void *phys_addr = get_phys_mem_addr(env, target_addr + i);
- memcpy(host_addr + i, phys_addr, (i + TARGET_PAGE_SIZE <= len) ? TARGET_PAGE_SIZE : len & (TARGET_PAGE_SIZE - 1));
- }
- }
-
- return 1;
-}
-
-static int host_offset = 0;
-static void reset_host_offset(void)
-{
- host_offset = 0;
-}
-
-/* Return a host pointer with the content of [target_addr, target_addr + len bytes[ */
-/* Do not free or modify */
-static const void* get_host_read_pointer(const CPUState *env, const target_ulong target_addr, int len)
-{
- int ret = get_target_mem_state(env, target_addr, len);
- if (ret == NOT_MAPPED)
- {
- return NULL;
- }
- else if (ret == MAPPED_CONTIGUOUS)
- {
- return get_phys_mem_addr(env, target_addr);
- }
- else
- {
- static int host_mem_size = 0;
- static void* host_mem = NULL;
- static void* ret;
- if (host_mem_size < host_offset + len)
- {
- host_mem_size = 2 * host_mem_size + host_offset + len;
- host_mem = realloc(host_mem, host_mem_size);
- }
- ret = host_mem + host_offset;
- assert(memcpy_target_to_host(env, ret, target_addr, len));
- host_offset += len;
- return ret;
- }
-}
-
-int doing_opengl = 0;
-static int last_func_number = -1;
-static size_t (*my_strlen)(const char*) = NULL;
-
-#ifdef ENABLE_GL_LOG
-static FILE* f = NULL;
-
-#define write_gl_debug_init() do { if (f == NULL) f = fopen("/tmp/debug_gl.bin", "wb"); } while(0)
-
-static int write_gl_debug_cmd_int(int my_int)
-{
- int r;
- write_gl_debug_init();
- r = fwrite(&my_int, sizeof(int), 1, f);
- fflush(f);
- return r;
-}
-
-static int write_gl_debug_cmd_short(int my_int)
-{
- int r;
- write_gl_debug_init();
- r = fwrite(&my_int, sizeof(short), 1, f);
- fflush(f);
- return r;
-}
-
-inline static int write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
-{
- int r;
- write_gl_debug_init();
- r = fwrite(&size, sizeof(int), 1, f);
- if (size)
- r += fwrite(buffer, size, 1, f);
- return r;
-}
-
-inline static int write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
-{
- int r = 0;
- write_gl_debug_init();
- if (size)
- r = fwrite(buffer, size, 1, f);
- return r;
-}
-
-static void write_gl_debug_end(void)
-{
- write_gl_debug_init();
- fclose(f);
- f = NULL;
-}
-
-#endif
-
-
-#if !defined( _WIN32 ) /* by 12.Nov.2009 */
-#include <dlfcn.h>
-#include <signal.h>
-
-static void (*anticrash_handler)(void*) = NULL;
-static void (*show_stack_from_signal_handler)(int, int, int) = NULL;
-
-static void my_anticrash_sigsegv_handler(int signum, siginfo_t* info, void* ptr)
-{
- static int counter = 0;
- counter++;
-
- printf("oops\n");
-
- /*if (show_stack_from_signal_handler && counter == 1)
- {
- struct ucontext* ctxt = (struct ucontext*)ptr;
- show_stack_from_signal_handler(10, ctxt->uc_mcontext.gregs[REG_EBP], ctxt->uc_mcontext.gregs[REG_ESP]);
- }*/
- anticrash_handler(ptr);
-
- counter--;
-}
-#endif
-
-#ifdef _WIN32
-
-static int decode_call_int(CPUState *env, int func_number, int pid, target_ulong target_ret_string,
- target_ulong in_args, target_ulong in_args_size)
-{
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int ret_type = signature->ret_type;
- //int has_out_parameters = signature->has_out_parameters;
- int nb_args = signature->nb_args;
- int* args_type = signature->args_type;
- int i;
- int ret;
- int* args_size = NULL;
- target_ulong saved_out_ptr[50];
- static char* ret_string = NULL;
- static target_ulong args[50];
- static GLDisplay dpy = 0;
-
- if (last_func_number == _exit_process_func && func_number == _exit_process_func)
- {
- last_func_number = -1;
- return 0;
- }
-
-#if 0
- if (last_process_id == 0)
- {
- last_process_id = pid;
- }
- else if (last_process_id != pid)
- {
- fprintf(stderr, "damnit. I don't support (yet) opengl calls coming from // processes... Sorry !\n");
- return 0;
- }
-#else
- last_process_id = pid;
-#endif
-
- if (dpy == NULL)
- {
- dpy = CreateDisplay();
- //init_process_tab();
- create_process_tab(NULL);
-
- ret_string = malloc(32768);
- my_strlen = strlen;
- }
-
- reset_host_offset();
-
- if (nb_args)
- {
- if (memcpy_target_to_host(env, args, in_args, sizeof(target_ulong) * nb_args) == 0)
- {
- fprintf(stderr, "call %s pid=%d\n", tab_opengl_calls_name[func_number], pid);
- fprintf(stderr, "cannot get call parameters\n");
- last_process_id = 0;
- return 0;
- }
-
- args_size = (int*)get_host_read_pointer(env, in_args_size, sizeof(int) * nb_args);
- if (args_size == NULL)
- {
- fprintf(stderr, "call %s pid=%d\n", tab_opengl_calls_name[func_number], pid);
- fprintf(stderr, "cannot get call parameters size\n");
- last_process_id = 0;
- return 0;
- }
- }
-
- if (func_number == _serialized_calls_func)
- {
- int command_buffer_size = args_size[0];
- const void* command_buffer = get_host_read_pointer(env, args[0], command_buffer_size);
- int commmand_buffer_offset = 0;
- args_size = NULL;
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(_serialized_calls_func);
-#endif
-
- while(commmand_buffer_offset < command_buffer_size)
- {
- func_number = *(short*)(command_buffer + commmand_buffer_offset);
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed at "
- "commmand_buffer_offset=%d (command_buffer_size=%d)\n",
- commmand_buffer_offset, command_buffer_size);
- return 0;
- }
- commmand_buffer_offset += sizeof(short);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(func_number);
-#endif
-
- signature = (Signature*)tab_opengl_calls[func_number];
- ret_type = signature->ret_type;
- assert(ret_type == TYPE_NONE);
- nb_args = signature->nb_args;
- args_type = signature->args_type;
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- {
- args[i] = *(int*)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- commmand_buffer_offset += sizeof(int);
- break;
- }
-
- case TYPE_NULL_TERMINATED_STRING:
- CASE_IN_UNKNOWN_SIZE_POINTERS:
- {
- int arg_size = *(int*)(command_buffer + commmand_buffer_offset);
- commmand_buffer_offset += sizeof(int);
-
- if (arg_size == 0)
- {
- args[i] = 0;
- }
- else
- {
- args[i] = (long)(command_buffer + commmand_buffer_offset);
- }
-
- if (args[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- }
- else
- {
- if (arg_size == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(arg_size, (void*)args[i]);
-#endif
- commmand_buffer_offset += arg_size;
-
- break;
- }
-
- CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- int arg_size = compute_arg_length(stderr, func_number, i, args);
- args[i] = (arg_size) ? (long)(command_buffer + commmand_buffer_offset) : 0;
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(arg_size, (void*)args[i]);
-#endif
- commmand_buffer_offset += arg_size;
- break;
- }
-
- CASE_OUT_POINTERS:
- {
- fprintf(stderr, "shouldn't happen TYPE_OUT_xxxx : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
-
- case TYPE_DOUBLE:
- CASE_IN_KNOWN_SIZE_POINTERS:
- args[i] = (long)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- commmand_buffer_offset += tab_args_type_length[args_type[i]];
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
- }
- do_function_call(dpy, func_number, pid, args, ret_string);
- }
-
- ret = 0;
- }
- else
- {
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(func_number);
-#endif
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- break;
-
- case TYPE_NULL_TERMINATED_STRING:
- CASE_IN_UNKNOWN_SIZE_POINTERS:
- if (args[i] == 0 && args_size[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- }
- else if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] == 0 && args_size[i] != 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- else if (args[i] != 0 && args_size[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] != 0 && args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- if (args[i])
- {
- args[i] = (target_ulong)get_host_read_pointer(env, args[i], args_size[i]);
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", args_size[i]);
- last_process_id = 0;
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
-#endif
- break;
-
- CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(stderr, func_number, i, args);
- args[i] = (args_size[i]) ? (target_ulong)get_host_read_pointer(env, args[i], args_size[i]) : 0;
- if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", args_size[i]);
- last_process_id = 0;
- return 0;
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
-#endif
- break;
- }
-
- CASE_OUT_POINTERS:
- {
- int mem_state;
-#ifdef ENABLE_GL_LOG
- if (must_save)
- {
- switch(args_type[i])
- {
- CASE_OUT_UNKNOWN_SIZE_POINTERS:
- write_gl_debug_cmd_int(args_size[i]);
- break;
-
- default:
- break;
- }
- }
-#endif
-
- if (func_number == glXQueryExtension_func && args[i] == 0)
- {
- saved_out_ptr[i] = 0;
- continue;
- }
- if (args[i] == 0 && args_size[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- else if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] == 0 && args_size[i] != 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- else if (args[i] != 0 && args_size[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] != 0 && args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- if (args[i])
- {
- mem_state = get_target_mem_state(env, args[i], args_size[i]);
- if (mem_state == NOT_MAPPED)
- {
- fprintf(stderr, "call %s arg %d pid=%d addr=%x size=%d NOT_MAPPED\n", tab_opengl_calls_name[func_number], i, pid, args[i], args_size[i]);
- last_process_id = 0;
- return 0;
- }
- else if (mem_state == MAPPED_CONTIGUOUS)
- {
- saved_out_ptr[i] = 0;
- args[i] = (target_ulong)get_phys_mem_addr(env, args[i]);
- }
- else
- {
- saved_out_ptr[i] = args[i];
- args[i] = (target_ulong)malloc(args_size[i]);
- }
- }
- else
- {
- saved_out_ptr[i] = 0;
- }
- break;
- }
-
- case TYPE_DOUBLE:
- CASE_IN_KNOWN_SIZE_POINTERS:
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", tab_args_type_length[args_type[i]]);
- last_process_id = 0;
- return 0;
- }
- args[i] = (int)get_host_read_pointer(env, args[i], tab_args_type_length[args_type[i]]);
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", tab_args_type_length[args_type[i]]);
- last_process_id = 0;
- return 0;
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
- }
-
- if (ret_type == TYPE_CONST_CHAR)
- {
- ret_string[0] = 0;
- }
-
- /*if (func_number == glDrawElements_func)
- {
- fprintf(stderr, "glDrawElements_func %d %d %d %X\n", args[0], args[1], args[2], args[3]);
- }*/
-
- if (func_number == _init_func)
- {
- must_save = args[0];
-#if 0
-#ifdef USE_KQEMU
- if (env->kqemu_enabled)
- *(int*)args[1] = 2;
- else
-#endif
-#endif
- *(int*)args[1] = 1;
- ret = 0;
- }
- else
- {
- ret = do_function_call(dpy, func_number, pid, args, ret_string);
- }
-#ifdef ENABLE_GL_LOG
- if (must_save && func_number == glXGetVisualFromFBConfig_func)
- {
- write_gl_debug_cmd_int(ret);
- }
-#endif
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- CASE_OUT_POINTERS:
- {
- if (saved_out_ptr[i])
- {
- if (memcpy_host_to_target(env, saved_out_ptr[i], (void*)args[i], args_size[i]) == 0)
- {
- fprintf(stderr, "cannot copy out parameters back to user space\n");
- last_process_id = 0;
- return 0;
- }
- free((void*)args[i]);
- }
- break;
- }
-
- default:
- break;
- }
- }
-
- if (ret_type == TYPE_CONST_CHAR)
- {
- if (target_ret_string)
- {
- /* the my_strlen stuff is a hack to workaround a GCC bug if using directly strlen... */
- if (memcpy_host_to_target(env, target_ret_string, ret_string, my_strlen(ret_string) + 1) == 0)
- {
- fprintf(stderr, "cannot copy out parameters back to user space\n");
- last_process_id = 0;
- return 0;
- }
- }
- }
- }
-
-#ifdef ENABLE_GL_LOG
- if (must_save && func_number == _exit_process_func)
- {
- write_gl_debug_end();
- }
-#endif
-
- return ret;
-}
-
-#else
-
-static int decode_call_int(CPUState *env, int func_number, int pid, target_ulong target_ret_string,
- target_ulong in_args, target_ulong in_args_size)
-{
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int ret_type = signature->ret_type;
- //int has_out_parameters = signature->has_out_parameters;
- int nb_args = signature->nb_args;
- int* args_type = signature->args_type;
- int i;
- int ret;
- int* args_size = NULL;
- target_ulong saved_out_ptr[50];
- static char* ret_string = NULL;
- static target_ulong args[50];
- static Display* dpy = NULL;
-
- if (last_func_number == _exit_process_func && func_number == _exit_process_func)
- {
- last_func_number = -1;
- return 0;
- }
-
- #if 0
- if (last_process_id == 0)
- {
- last_process_id = pid;
- }
- else if (last_process_id != pid)
- {
- fprintf(stderr, "damnit. I don't support (yet) opengl calls coming from // processes... Sorry !\n");
- return 0;
- }
- #else
- last_process_id = pid;
- #endif
-
- if (dpy == NULL)
- {
- void *handle = dlopen("libanticrash.so", RTLD_LAZY);
- if (handle)
- {
- anticrash_handler = dlsym(handle, "anticrash_handler");
- if (anticrash_handler)
- {
- fprintf(stderr, "anticrash handler enabled\n");
- struct sigaction sigsegv_action;
- struct sigaction old_sigsegv_action;
-
- sigsegv_action.sa_sigaction = my_anticrash_sigsegv_handler;
- sigemptyset(&(sigsegv_action.sa_mask));
- sigsegv_action.sa_flags = SA_SIGINFO | SA_NOMASK;
- sigaction(SIGSEGV, &sigsegv_action, &old_sigsegv_action);
- }
- }
- handle = dlopen("libgetstack.so", RTLD_LAZY);
- if (handle)
- {
- show_stack_from_signal_handler = dlsym(handle, "show_stack_from_signal_handler");
- }
-
- dpy = XOpenDisplay(NULL);
- /*init_process_tab();*/
- create_process_tab(NULL);
-
- ret_string = malloc(32768);
- my_strlen = strlen;
- }
-
- reset_host_offset();
-
- if (nb_args)
- {
- if (memcpy_target_to_host(env, args, in_args, sizeof(target_ulong) * nb_args) == 0)
- {
- fprintf(stderr, "call %s pid=%d\n", tab_opengl_calls_name[func_number], pid);
- fprintf(stderr, "cannot get call parameters\n");
- last_process_id = 0;
- return 0;
- }
-
- args_size = (int*)get_host_read_pointer(env, in_args_size, sizeof(int) * nb_args);
- if (args_size == NULL)
- {
- fprintf(stderr, "call %s pid=%d\n", tab_opengl_calls_name[func_number], pid);
- fprintf(stderr, "cannot get call parameters size\n");
- last_process_id = 0;
- return 0;
- }
- }
- if (func_number == _serialized_calls_func)
- {
- int command_buffer_size = args_size[0];
- const void* command_buffer = get_host_read_pointer(env, args[0], command_buffer_size);
- int commmand_buffer_offset = 0;
- args_size = NULL;
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(_serialized_calls_func);
-#endif
-
- while(commmand_buffer_offset < command_buffer_size)
- {
- func_number = *(short*)(command_buffer + commmand_buffer_offset);
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed at "
- "commmand_buffer_offset=%d (command_buffer_size=%d)\n",
- commmand_buffer_offset, command_buffer_size);
- return 0;
- }
- commmand_buffer_offset += sizeof(short);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(func_number);
-#endif
-
- signature = (Signature*)tab_opengl_calls[func_number];
- ret_type = signature->ret_type;
- assert(ret_type == TYPE_NONE);
- nb_args = signature->nb_args;
- args_type = signature->args_type;
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- {
- args[i] = *(int*)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- commmand_buffer_offset += sizeof(int);
- break;
- }
-
- case TYPE_NULL_TERMINATED_STRING:
- CASE_IN_UNKNOWN_SIZE_POINTERS:
- {
- int arg_size = *(int*)(command_buffer + commmand_buffer_offset);
- commmand_buffer_offset += sizeof(int);
-
- if (arg_size == 0)
- {
- args[i] = 0;
- }
- else
- {
- args[i] = (long)(command_buffer + commmand_buffer_offset);
- }
-
- if (args[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- }
- else
- {
- if (arg_size == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(arg_size, (void*)args[i]);
-#endif
- commmand_buffer_offset += arg_size;
-
- break;
- }
-
- CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- int arg_size = compute_arg_length(stderr, func_number, i, (void*)args);
- args[i] = (arg_size) ? (long)(command_buffer + commmand_buffer_offset) : 0;
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(arg_size, (void*)args[i]);
-#endif
- commmand_buffer_offset += arg_size;
- break;
- }
-
- CASE_OUT_POINTERS:
- {
- fprintf(stderr, "shouldn't happen TYPE_OUT_xxxx : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
-
- case TYPE_DOUBLE:
- CASE_IN_KNOWN_SIZE_POINTERS:
- args[i] = (long)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- commmand_buffer_offset += tab_args_type_length[args_type[i]];
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
- }
- do_function_call(dpy, func_number, pid, (void*)args, ret_string);
- }
-
- ret = 0;
- }
- else
- {
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_short(func_number);
-#endif
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- break;
-
- case TYPE_NULL_TERMINATED_STRING:
- CASE_IN_UNKNOWN_SIZE_POINTERS:
- if (args[i] == 0 && args_size[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- }
- else if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] == 0 && args_size[i] != 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- else if (args[i] != 0 && args_size[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] != 0 && args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- if (args[i])
- {
- args[i] = (target_ulong)get_host_read_pointer(env, args[i], args_size[i]);
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", args_size[i]);
- last_process_id = 0;
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
-#endif
- break;
-
- CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(stderr, func_number, i, (void*)args);
- args[i] = (args_size[i]) ? (target_ulong)get_host_read_pointer(env, args[i], args_size[i]) : 0;
- if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", args_size[i]);
- last_process_id = 0;
- return 0;
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
-#endif
- break;
- }
-
- CASE_OUT_POINTERS:
- {
- int mem_state;
-#ifdef ENABLE_GL_LOG
- if (must_save)
- {
- switch(args_type[i])
- {
- CASE_OUT_UNKNOWN_SIZE_POINTERS:
- write_gl_debug_cmd_int(args_size[i]);
- break;
-
- default:
- break;
- }
- }
-#endif
-
- if (func_number == glXQueryExtension_func && args[i] == 0)
- {
- saved_out_ptr[i] = 0;
- continue;
- }
- if (args[i] == 0 && args_size[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- }
- else if (args[i] == 0 && args_size[i] != 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] == 0 && args_size[i] != 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- else if (args[i] != 0 && args_size[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "args[i] != 0 && args_size[i] == 0 !!\n");
- last_process_id = 0;
- return 0;
- }
- if (args[i])
- {
- mem_state = get_target_mem_state(env, args[i], args_size[i]);
- if (mem_state == NOT_MAPPED)
- {
- fprintf(stderr, "call %s arg %d pid=%d addr=%x size=%d NOT_MAPPED\n", tab_opengl_calls_name[func_number], i, pid, args[i], args_size[i]);
- last_process_id = 0;
- return 0;
- }
- else if (mem_state == MAPPED_CONTIGUOUS)
- {
- saved_out_ptr[i] = 0;
- args[i] = (target_ulong)get_phys_mem_addr(env, args[i]);
- }
- else
- {
- saved_out_ptr[i] = args[i];
- args[i] = (target_ulong)malloc(args_size[i]);
- }
- }
- else
- {
- saved_out_ptr[i] = 0;
- }
- break;
- }
-
- case TYPE_DOUBLE:
- CASE_IN_KNOWN_SIZE_POINTERS:
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", tab_args_type_length[args_type[i]]);
- last_process_id = 0;
- return 0;
- }
- args[i] = (int)get_host_read_pointer(env, args[i], tab_args_type_length[args_type[i]]);
- if (args[i] == 0)
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- fprintf(stderr, "can not get %d bytes\n", tab_args_type_length[args_type[i]]);
- last_process_id = 0;
- return 0;
- }
-#ifdef ENABLE_GL_LOG
- if (must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- last_process_id = 0;
- return 0;
- break;
- }
- }
-
- if (ret_type == TYPE_CONST_CHAR)
- {
- ret_string[0] = 0;
- }
-
- /*if (func_number == glDrawElements_func)
- {
- fprintf(stderr, "glDrawElements_func %d %d %d %X\n", args[0], args[1], args[2], args[3]);
- }*/
-
- if (func_number == _init_func)
- {
- must_save = args[0];
-#if 0
-#ifdef USE_KQEMU
- if (env->kqemu_enabled)
- *(int*)args[1] = 2;
- else
-#endif
-#endif
- *(int*)args[1] = 1;
- ret = 0;
- }
- else
- {
-
- ret = do_function_call(dpy, func_number, pid, (void*)args, ret_string);
- }
-#ifdef ENABLE_GL_LOG
- if (must_save && func_number == glXGetVisualFromFBConfig_func)
- {
- write_gl_debug_cmd_int(ret);
- }
-#endif
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- CASE_OUT_POINTERS:
- {
- if (saved_out_ptr[i])
- {
- if (memcpy_host_to_target(env, saved_out_ptr[i], (void*)args[i], args_size[i]) == 0)
- {
- fprintf(stderr, "cannot copy out parameters back to user space\n");
- last_process_id = 0;
- return 0;
- }
- free((void*)args[i]);
- }
- break;
- }
-
- default:
- break;
- }
- }
-
- if (ret_type == TYPE_CONST_CHAR)
- {
- if (target_ret_string)
- {
- /* the my_strlen stuff is a hack to workaround a GCC bug if using directly strlen... */
- if (memcpy_host_to_target(env, target_ret_string, ret_string, my_strlen(ret_string) + 1) == 0)
- {
- fprintf(stderr, "cannot copy out parameters back to user space\n");
- last_process_id = 0;
- return 0;
- }
- }
- }
- }
-
-#ifdef ENABLE_GL_LOG
- if (must_save && func_number == _exit_process_func)
- {
- write_gl_debug_end();
- }
-#endif
-
- return ret;
-}
-
-#endif
-
-extern int decode_call(CPUState *env, int func_number, int pid, target_ulong target_ret_string,
- target_ulong in_args, target_ulong in_args_size)
-{
- int ret;
- //fprintf(stderr, "cr3 = %d\n", env->cr[3]);
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed(%d)\n", func_number);
- return 0;
- }
- ret = decode_call_int(env, func_number, pid, target_ret_string, in_args, in_args_size);
- if (func_number == glXCreateContext_func)
- {
- fprintf(stderr, "ret of glXCreateContext_func = %d\n", ret);
- }
- return ret;
-}
-
-//void helper_opengl()
-void helper_opengl(CPUState *env)
-{
- doing_opengl = 1;
-
- env->regs[R_EAX] = decode_call(env,
- env->regs[R_EAX],
- env->regs[R_EBX],
- env->regs[R_ECX],
- env->regs[R_EDX],
- env->regs[R_ESI]);
-
- doing_opengl = 0;
-}
+++ /dev/null
-#include "qemu-common.h"
-#include "opengl_func.h"
-
-extern int decode_call(CPUState *env, int func_number, int pid, target_ulong target_ret_string, target_ulong in_args, target_ulong in_args_size);
-extern void helper_opengl(CPUState *env);
+++ /dev/null
-/*
- * Mesa 3-D graphics library
- * Version: 6.5
- *
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifndef GLX_H
-#define GLX_H
-
-
-#if defined( _WIN32 ) /* by 13.Nov.2009 */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Tokens for glXChooseVisual and glXGetConfig:
- */
-#define GLX_USE_GL 1
-#define GLX_BUFFER_SIZE 2
-#define GLX_LEVEL 3
-#define GLX_RGBA 4
-#define GLX_DOUBLEBUFFER 5
-#define GLX_STEREO 6
-#define GLX_AUX_BUFFERS 7
-#define GLX_RED_SIZE 8
-#define GLX_GREEN_SIZE 9
-#define GLX_BLUE_SIZE 10
-#define GLX_ALPHA_SIZE 11
-#define GLX_DEPTH_SIZE 12
-#define GLX_STENCIL_SIZE 13
-#define GLX_ACCUM_RED_SIZE 14
-#define GLX_ACCUM_GREEN_SIZE 15
-#define GLX_ACCUM_BLUE_SIZE 16
-#define GLX_ACCUM_ALPHA_SIZE 17
-
-
-/*
- * Error codes returned by glXGetConfig:
- */
-#define GLX_BAD_SCREEN 1
-#define GLX_BAD_ATTRIBUTE 2
-#define GLX_NO_EXTENSION 3
-#define GLX_BAD_VISUAL 4
-#define GLX_BAD_CONTEXT 5
-#define GLX_BAD_VALUE 6
-#define GLX_BAD_ENUM 7
-
-
-/*
- * GLX 1.1 and later:
- */
-#define GLX_VENDOR 1
-#define GLX_VERSION 2
-#define GLX_EXTENSIONS 3
-
-
-/*
- * GLX 1.3 and later:
- */
-#define GLX_CONFIG_CAVEAT 0x20
-#define GLX_DONT_CARE 0xFFFFFFFF
-#define GLX_X_VISUAL_TYPE 0x22
-#define GLX_TRANSPARENT_TYPE 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE 0x24
-#define GLX_TRANSPARENT_RED_VALUE 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
-#define GLX_WINDOW_BIT 0x00000001
-#define GLX_PIXMAP_BIT 0x00000002
-#define GLX_PBUFFER_BIT 0x00000004
-#define GLX_AUX_BUFFERS_BIT 0x00000010
-#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
-#define GLX_DEPTH_BUFFER_BIT 0x00000020
-#define GLX_STENCIL_BUFFER_BIT 0x00000040
-#define GLX_ACCUM_BUFFER_BIT 0x00000080
-#define GLX_NONE 0x8000
-#define GLX_SLOW_CONFIG 0x8001
-#define GLX_TRUE_COLOR 0x8002
-#define GLX_DIRECT_COLOR 0x8003
-#define GLX_PSEUDO_COLOR 0x8004
-#define GLX_STATIC_COLOR 0x8005
-#define GLX_GRAY_SCALE 0x8006
-#define GLX_STATIC_GRAY 0x8007
-#define GLX_TRANSPARENT_RGB 0x8008
-#define GLX_TRANSPARENT_INDEX 0x8009
-#define GLX_VISUAL_ID 0x800B
-#define GLX_SCREEN 0x800C
-#define GLX_NON_CONFORMANT_CONFIG 0x800D
-#define GLX_DRAWABLE_TYPE 0x8010
-#define GLX_RENDER_TYPE 0x8011
-#define GLX_X_RENDERABLE 0x8012
-#define GLX_FBCONFIG_ID 0x8013
-#define GLX_RGBA_TYPE 0x8014
-#define GLX_COLOR_INDEX_TYPE 0x8015
-#define GLX_MAX_PBUFFER_WIDTH 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT 0x8017
-#define GLX_MAX_PBUFFER_PIXELS 0x8018
-#define GLX_PRESERVED_CONTENTS 0x801B
-#define GLX_LARGEST_PBUFFER 0x801C
-#define GLX_WIDTH 0x801D
-#define GLX_HEIGHT 0x801E
-#define GLX_EVENT_MASK 0x801F
-#define GLX_DAMAGED 0x8020
-#define GLX_SAVED 0x8021
-#define GLX_WINDOW 0x8022
-#define GLX_PBUFFER 0x8023
-#define GLX_PBUFFER_HEIGHT 0x8040
-#define GLX_PBUFFER_WIDTH 0x8041
-#define GLX_RGBA_BIT 0x00000001
-#define GLX_COLOR_INDEX_BIT 0x00000002
-#define GLX_PBUFFER_CLOBBER_MASK 0x08000000
-
-
-/*
- * GLX 1.4 and later:
- */
-#define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/
-#define GLX_SAMPLES 0x186a1 /*100001*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#else
-#ifdef __VMS
-#include <GL/vms_x_fix.h>
-# ifdef __cplusplus
-/* VMS Xlib.h gives problems with C++.
- * this avoids a bunch of trivial warnings */
-#pragma message disable nosimpint
-#endif
-#endif
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#ifdef __VMS
-# ifdef __cplusplus
-#pragma message enable nosimpint
-#endif
-#endif
-#include <mesa_gl.h>
-
-
-#if defined(USE_MGL_NAMESPACE)
-#include "glx_mangle.h"
-#endif
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define GLX_VERSION_1_1 1
-#define GLX_VERSION_1_2 1
-#define GLX_VERSION_1_3 1
-#define GLX_VERSION_1_4 1
-
-#define GLX_EXTENSION_NAME "GLX"
-
-
-
-/*
- * Tokens for glXChooseVisual and glXGetConfig:
- */
-#define GLX_USE_GL 1
-#define GLX_BUFFER_SIZE 2
-#define GLX_LEVEL 3
-#define GLX_RGBA 4
-#define GLX_DOUBLEBUFFER 5
-#define GLX_STEREO 6
-#define GLX_AUX_BUFFERS 7
-#define GLX_RED_SIZE 8
-#define GLX_GREEN_SIZE 9
-#define GLX_BLUE_SIZE 10
-#define GLX_ALPHA_SIZE 11
-#define GLX_DEPTH_SIZE 12
-#define GLX_STENCIL_SIZE 13
-#define GLX_ACCUM_RED_SIZE 14
-#define GLX_ACCUM_GREEN_SIZE 15
-#define GLX_ACCUM_BLUE_SIZE 16
-#define GLX_ACCUM_ALPHA_SIZE 17
-
-
-/*
- * Error codes returned by glXGetConfig:
- */
-#define GLX_BAD_SCREEN 1
-#define GLX_BAD_ATTRIBUTE 2
-#define GLX_NO_EXTENSION 3
-#define GLX_BAD_VISUAL 4
-#define GLX_BAD_CONTEXT 5
-#define GLX_BAD_VALUE 6
-#define GLX_BAD_ENUM 7
-
-
-/*
- * GLX 1.1 and later:
- */
-#define GLX_VENDOR 1
-#define GLX_VERSION 2
-#define GLX_EXTENSIONS 3
-
-
-/*
- * GLX 1.3 and later:
- */
-#define GLX_CONFIG_CAVEAT 0x20
-#define GLX_DONT_CARE 0xFFFFFFFF
-#define GLX_X_VISUAL_TYPE 0x22
-#define GLX_TRANSPARENT_TYPE 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE 0x24
-#define GLX_TRANSPARENT_RED_VALUE 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
-#define GLX_WINDOW_BIT 0x00000001
-#define GLX_PIXMAP_BIT 0x00000002
-#define GLX_PBUFFER_BIT 0x00000004
-#define GLX_AUX_BUFFERS_BIT 0x00000010
-#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
-#define GLX_DEPTH_BUFFER_BIT 0x00000020
-#define GLX_STENCIL_BUFFER_BIT 0x00000040
-#define GLX_ACCUM_BUFFER_BIT 0x00000080
-#define GLX_NONE 0x8000
-#define GLX_SLOW_CONFIG 0x8001
-#define GLX_TRUE_COLOR 0x8002
-#define GLX_DIRECT_COLOR 0x8003
-#define GLX_PSEUDO_COLOR 0x8004
-#define GLX_STATIC_COLOR 0x8005
-#define GLX_GRAY_SCALE 0x8006
-#define GLX_STATIC_GRAY 0x8007
-#define GLX_TRANSPARENT_RGB 0x8008
-#define GLX_TRANSPARENT_INDEX 0x8009
-#define GLX_VISUAL_ID 0x800B
-#define GLX_SCREEN 0x800C
-#define GLX_NON_CONFORMANT_CONFIG 0x800D
-#define GLX_DRAWABLE_TYPE 0x8010
-#define GLX_RENDER_TYPE 0x8011
-#define GLX_X_RENDERABLE 0x8012
-#define GLX_FBCONFIG_ID 0x8013
-#define GLX_RGBA_TYPE 0x8014
-#define GLX_COLOR_INDEX_TYPE 0x8015
-#define GLX_MAX_PBUFFER_WIDTH 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT 0x8017
-#define GLX_MAX_PBUFFER_PIXELS 0x8018
-#define GLX_PRESERVED_CONTENTS 0x801B
-#define GLX_LARGEST_PBUFFER 0x801C
-#define GLX_WIDTH 0x801D
-#define GLX_HEIGHT 0x801E
-#define GLX_EVENT_MASK 0x801F
-#define GLX_DAMAGED 0x8020
-#define GLX_SAVED 0x8021
-#define GLX_WINDOW 0x8022
-#define GLX_PBUFFER 0x8023
-#define GLX_PBUFFER_HEIGHT 0x8040
-#define GLX_PBUFFER_WIDTH 0x8041
-#define GLX_RGBA_BIT 0x00000001
-#define GLX_COLOR_INDEX_BIT 0x00000002
-#define GLX_PBUFFER_CLOBBER_MASK 0x08000000
-
-
-/*
- * GLX 1.4 and later:
- */
-#define GLX_SAMPLE_BUFFERS 0x186a0 /*100000*/
-#define GLX_SAMPLES 0x186a1 /*100001*/
-
-
-
-typedef struct __GLXcontextRec *GLXContext;
-typedef XID GLXPixmap;
-typedef XID GLXDrawable;
-/* GLX 1.3 and later */
-typedef struct __GLXFBConfigRec *GLXFBConfig;
-typedef XID GLXFBConfigID;
-typedef XID GLXContextID;
-typedef XID GLXWindow;
-typedef XID GLXPbuffer;
-
-
-
-extern XVisualInfo* glXChooseVisual( Display *dpy, int screen,
- int *attribList );
-
-extern GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
- GLXContext shareList, Bool direct );
-
-extern void glXDestroyContext( Display *dpy, GLXContext ctx );
-
-extern Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable,
- GLXContext ctx);
-
-extern void glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
- unsigned long mask );
-
-extern void glXSwapBuffers( Display *dpy, GLXDrawable drawable );
-
-extern GLXPixmap glXCreateGLXPixmap( Display *dpy, XVisualInfo *visual,
- Pixmap pixmap );
-
-extern void glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap );
-
-extern Bool glXQueryExtension( Display *dpy, int *errorb, int *event );
-
-extern Bool glXQueryVersion( Display *dpy, int *maj, int *min );
-
-extern Bool glXIsDirect( Display *dpy, GLXContext ctx );
-
-extern int glXGetConfig( Display *dpy, XVisualInfo *visual,
- int attrib, int *value );
-
-extern GLXContext glXGetCurrentContext( void );
-
-extern GLXDrawable glXGetCurrentDrawable( void );
-
-extern void glXWaitGL( void );
-
-extern void glXWaitX( void );
-
-extern void glXUseXFont( Font font, int first, int count, int list );
-
-
-
-/* GLX 1.1 and later */
-extern const char *glXQueryExtensionsString( Display *dpy, int screen );
-
-extern const char *glXQueryServerString( Display *dpy, int screen, int name );
-
-extern const char *glXGetClientString( Display *dpy, int name );
-
-
-/* GLX 1.2 and later */
-extern Display *glXGetCurrentDisplay( void );
-
-
-/* GLX 1.3 and later */
-extern GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen,
- const int *attribList, int *nitems );
-
-extern int glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
- int attribute, int *value );
-
-extern GLXFBConfig *glXGetFBConfigs( Display *dpy, int screen,
- int *nelements );
-
-extern XVisualInfo *glXGetVisualFromFBConfig( Display *dpy,
- GLXFBConfig config );
-
-extern GLXWindow glXCreateWindow( Display *dpy, GLXFBConfig config,
- Window win, const int *attribList );
-
-extern void glXDestroyWindow( Display *dpy, GLXWindow window );
-
-extern GLXPixmap glXCreatePixmap( Display *dpy, GLXFBConfig config,
- Pixmap pixmap, const int *attribList );
-
-extern void glXDestroyPixmap( Display *dpy, GLXPixmap pixmap );
-
-extern GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config,
- const int *attribList );
-
-extern void glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf );
-
-extern void glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
- unsigned int *value );
-
-extern GLXContext glXCreateNewContext( Display *dpy, GLXFBConfig config,
- int renderType, GLXContext shareList,
- Bool direct );
-
-extern Bool glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
- GLXDrawable read, GLXContext ctx );
-
-extern GLXDrawable glXGetCurrentReadDrawable( void );
-
-extern int glXQueryContext( Display *dpy, GLXContext ctx, int attribute,
- int *value );
-
-extern void glXSelectEvent( Display *dpy, GLXDrawable drawable,
- unsigned long mask );
-
-extern void glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
- unsigned long *mask );
-
-
-/* GLX 1.4 and later */
-extern void (*glXGetProcAddress(const GLubyte *procname))( void );
-
-
-#ifndef GLX_GLXEXT_LEGACY
-
-#include <mesa_glxext.h>
-
-#else
-
-
-
-/*
- * ARB 2. GLX_ARB_get_proc_address
- */
-#ifndef GLX_ARB_get_proc_address
-#define GLX_ARB_get_proc_address 1
-
-typedef void (*__GLXextFuncPtr)(void);
-extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
-
-#endif /* GLX_ARB_get_proc_address */
-
-
-
-#endif /* GLX_GLXEXT_LEGACY */
-
-
-/**
- ** The following aren't in glxext.h yet.
- **/
-
-
-/*
- * ???. GLX_NV_vertex_array_range
- */
-#ifndef GLX_NV_vertex_array_range
-#define GLX_NV_vertex_array_range
-
-extern void *glXAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
-extern void glXFreeMemoryNV(GLvoid *pointer);
-typedef void * ( * PFNGLXALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
-typedef void ( * PFNGLXFREEMEMORYNVPROC) (GLvoid *pointer);
-
-#endif /* GLX_NV_vertex_array_range */
-
-
-/*
- * ???. GLX_MESA_allocate_memory
- */
-#ifndef GLX_MESA_allocate_memory
-#define GLX_MESA_allocate_memory 1
-
-extern void *glXAllocateMemoryMESA(Display *dpy, int scrn, size_t size, float readfreq, float writefreq, float priority);
-extern void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer);
-extern GLuint glXGetMemoryOffsetMESA(Display *dpy, int scrn, const void *pointer);
-typedef void * ( * PFNGLXALLOCATEMEMORYMESAPROC) (Display *dpy, int scrn, size_t size, float readfreq, float writefreq, float priority);
-typedef void ( * PFNGLXFREEMEMORYMESAPROC) (Display *dpy, int scrn, void *pointer);
-typedef GLuint (* PFNGLXGETMEMORYOFFSETMESAPROC) (Display *dpy, int scrn, const void *pointer);
-
-#endif /* GLX_MESA_allocate_memory */
-
-
-/*
- * ARB ?. GLX_ARB_render_texture
- * XXX This was never finalized!
- */
-#ifndef GLX_ARB_render_texture
-#define GLX_ARB_render_texture 1
-
-extern Bool glXBindTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer);
-extern Bool glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer);
-extern Bool glXDrawableAttribARB(Display *dpy, GLXDrawable draw, const int *attribList);
-
-#endif /* GLX_ARB_render_texture */
-
-
-#ifndef GLX_ATI_render_texture
-#define GLX_ATI_render_texture 1
-
-extern void glXBindTexImageATI(Display *dpy, GLXPbuffer pbuffer, int buffer);
-extern void glXReleaseTexImageATI(Display *dpy, GLXPbuffer pbuffer, int buffer);
-extern void glXDrawableAttribATI(Display *dpy, GLXDrawable draw, const int *attribList);
-
-#endif /* GLX_ATI_render_texture */
-
-
-/*
- * Remove this when glxext.h is updated.
- */
-#ifndef GLX_NV_float_buffer
-#define GLX_NV_float_buffer 1
-
-#define GLX_FLOAT_COMPONENTS_NV 0x20B0
-
-#endif /* GLX_NV_float_buffer */
-
-
-
-/*
- * #?. GLX_MESA_swap_frame_usage
- */
-#ifndef GLX_MESA_swap_frame_usage
-#define GLX_MESA_swap_frame_usage 1
-
-extern int glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable, float *usage);
-extern int glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable);
-extern int glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable);
-extern int glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage);
-
-typedef int (*PFNGLXGETFRAMEUSAGEMESAPROC) (Display *dpy, GLXDrawable drawable, float *usage);
-typedef int (*PFNGLXBEGINFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable);
-typedef int (*PFNGLXENDFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable);
-typedef int (*PFNGLXQUERYFRAMETRACKINGMESAPROC)(Display *dpy, GLXDrawable drawable, int64_t *swapCount, int64_t *missedFrames, float *lastMissedUsage);
-
-#endif /* GLX_MESA_swap_frame_usage */
-
-
-
-/*
- * #?. GLX_MESA_swap_control
- */
-#ifndef GLX_MESA_swap_control
-#define GLX_MESA_swap_control 1
-
-extern int glXSwapIntervalMESA(unsigned int interval);
-extern int glXGetSwapIntervalMESA(void);
-
-typedef int (*PFNGLXSWAPINTERVALMESAPROC)(unsigned int interval);
-typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void);
-
-#endif /* GLX_MESA_swap_control */
-
-
-
-/*
- * #?. GLX_EXT_texture_from_pixmap
- * XXX not finished?
- */
-#ifndef GLX_EXT_texture_from_pixmap
-#define GLX_EXT_texture_from_pixmap 1
-
-#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0
-#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1
-#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2
-#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3
-#define GLX_Y_INVERTED_EXT 0x20D4
-
-#define GLX_TEXTURE_FORMAT_EXT 0x20D5
-#define GLX_TEXTURE_TARGET_EXT 0x20D6
-#define GLX_MIPMAP_TEXTURE_EXT 0x20D7
-
-#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8
-#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9
-#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA
-
-#define GLX_TEXTURE_1D_BIT_EXT 0x00000001
-#define GLX_TEXTURE_2D_BIT_EXT 0x00000002
-#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
-
-#define GLX_TEXTURE_1D_EXT 0x20DB
-#define GLX_TEXTURE_2D_EXT 0x20DC
-#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD
-
-#define GLX_FRONT_LEFT_EXT 0x20DE
-#define GLX_FRONT_RIGHT_EXT 0x20DF
-#define GLX_BACK_LEFT_EXT 0x20E0
-#define GLX_BACK_RIGHT_EXT 0x20E1
-#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT
-#define GLX_BACK_EXT GLX_BACK_LEFT_EXT
-#define GLX_AUX0_EXT 0x20E2
-#define GLX_AUX1_EXT 0x20E3
-#define GLX_AUX2_EXT 0x20E4
-#define GLX_AUX3_EXT 0x20E5
-#define GLX_AUX4_EXT 0x20E6
-#define GLX_AUX5_EXT 0x20E7
-#define GLX_AUX6_EXT 0x20E8
-#define GLX_AUX7_EXT 0x20E9
-#define GLX_AUX8_EXT 0x20EA
-#define GLX_AUX9_EXT 0x20EB
-
-extern void glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list);
-extern void glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer);
-
-#endif /* GLX_EXT_texture_from_pixmap */
-
-
-
-
-/*** Should these go here, or in another header? */
-/*
-** GLX Events
-*/
-typedef struct {
- int event_type; /* GLX_DAMAGED or GLX_SAVED */
- int draw_type; /* GLX_WINDOW or GLX_PBUFFER */
- unsigned long serial; /* # of last request processed by server */
- Bool send_event; /* true if this came for SendEvent request */
- Display *display; /* display the event was read from */
- GLXDrawable drawable; /* XID of Drawable */
- unsigned int buffer_mask; /* mask indicating which buffers are affected */
- unsigned int aux_buffer; /* which aux buffer was affected */
- int x, y;
- int width, height;
- int count; /* if nonzero, at least this many more */
-} GLXPbufferClobberEvent;
-
-typedef union __GLXEvent {
- GLXPbufferClobberEvent glxpbufferclobber;
- long pad[24];
-} GLXEvent;
-
-#ifdef __cplusplus
-}
-#endif
-#endif
-
-#endif
+++ /dev/null
-#ifndef __glxext_h_
-#define __glxext_h_
-
-/*
-** Copyright (c) 2007 The Khronos Group Inc.
-**
-** Permission is hereby granted, free of charge, to any person obtaining a
-** copy of this software and/or associated documentation files (the
-** "Materials"), to deal in the Materials without restriction, including
-** without limitation the rights to use, copy, modify, merge, publish,
-** distribute, sublicense, and/or sell copies of the Materials, and to
-** permit persons to whom the Materials are furnished to do so, subject to
-** the following conditions:
-**
-** The above copyright notice and this permission notice shall be included
-** in all copies or substantial portions of the Materials.
-**
-** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
-*/
-#if defined( _WIN32 ) /* by 16.Nov.2009 */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
-#define WIN32_LEAN_AND_MEAN 1
-#include <windows.h>
-#endif
-
-#ifndef APIENTRY
-#define APIENTRY
-#endif
-#ifndef APIENTRYP
-#define APIENTRYP APIENTRY *
-#endif
-#ifndef GLAPI
-#define GLAPI extern
-#endif
-
-/*************************************************************/
-
-/* Header file version number, required by OpenGL ABI for Linux */
-/* glxext.h last updated 2007/04/21 */
-/* Current version at http://www.opengl.org/registry/ */
-#define GLX_GLXEXT_VERSION 19
-
-#ifndef GLX_VERSION_1_3
-#define GLX_WINDOW_BIT 0x00000001
-#define GLX_PIXMAP_BIT 0x00000002
-#define GLX_PBUFFER_BIT 0x00000004
-#define GLX_RGBA_BIT 0x00000001
-#define GLX_COLOR_INDEX_BIT 0x00000002
-#define GLX_PBUFFER_CLOBBER_MASK 0x08000000
-#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
-#define GLX_AUX_BUFFERS_BIT 0x00000010
-#define GLX_DEPTH_BUFFER_BIT 0x00000020
-#define GLX_STENCIL_BUFFER_BIT 0x00000040
-#define GLX_ACCUM_BUFFER_BIT 0x00000080
-#define GLX_CONFIG_CAVEAT 0x20
-#define GLX_X_VISUAL_TYPE 0x22
-#define GLX_TRANSPARENT_TYPE 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE 0x24
-#define GLX_TRANSPARENT_RED_VALUE 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
-#define GLX_DONT_CARE 0xFFFFFFFF
-#define GLX_NONE 0x8000
-#define GLX_SLOW_CONFIG 0x8001
-#define GLX_TRUE_COLOR 0x8002
-#define GLX_DIRECT_COLOR 0x8003
-#define GLX_PSEUDO_COLOR 0x8004
-#define GLX_STATIC_COLOR 0x8005
-#define GLX_GRAY_SCALE 0x8006
-#define GLX_STATIC_GRAY 0x8007
-#define GLX_TRANSPARENT_RGB 0x8008
-#define GLX_TRANSPARENT_INDEX 0x8009
-#define GLX_VISUAL_ID 0x800B
-#define GLX_SCREEN 0x800C
-#define GLX_NON_CONFORMANT_CONFIG 0x800D
-#define GLX_DRAWABLE_TYPE 0x8010
-#define GLX_RENDER_TYPE 0x8011
-#define GLX_X_RENDERABLE 0x8012
-#define GLX_FBCONFIG_ID 0x8013
-#define GLX_RGBA_TYPE 0x8014
-#define GLX_COLOR_INDEX_TYPE 0x8015
-#define GLX_MAX_PBUFFER_WIDTH 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT 0x8017
-#define GLX_MAX_PBUFFER_PIXELS 0x8018
-#define GLX_PRESERVED_CONTENTS 0x801B
-#define GLX_LARGEST_PBUFFER 0x801C
-#define GLX_WIDTH 0x801D
-#define GLX_HEIGHT 0x801E
-#define GLX_EVENT_MASK 0x801F
-#define GLX_DAMAGED 0x8020
-#define GLX_SAVED 0x8021
-#define GLX_WINDOW 0x8022
-#define GLX_PBUFFER 0x8023
-#define GLX_PBUFFER_HEIGHT 0x8040
-#define GLX_PBUFFER_WIDTH 0x8041
-#endif
-
-#ifndef GLX_VERSION_1_4
-#define GLX_SAMPLE_BUFFERS 100000
-#define GLX_SAMPLES 100001
-#endif
-
-#ifndef GLX_ARB_get_proc_address
-#endif
-
-#ifndef GLX_ARB_multisample
-#define GLX_SAMPLE_BUFFERS_ARB 100000
-#define GLX_SAMPLES_ARB 100001
-#endif
-
-#ifndef GLX_ARB_fbconfig_float
-#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9
-#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004
-#endif
-
-#ifndef GLX_SGIS_multisample
-#define GLX_SAMPLE_BUFFERS_SGIS 100000
-#define GLX_SAMPLES_SGIS 100001
-#endif
-
-#ifndef GLX_EXT_visual_info
-#define GLX_X_VISUAL_TYPE_EXT 0x22
-#define GLX_TRANSPARENT_TYPE_EXT 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24
-#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28
-#define GLX_NONE_EXT 0x8000
-#define GLX_TRUE_COLOR_EXT 0x8002
-#define GLX_DIRECT_COLOR_EXT 0x8003
-#define GLX_PSEUDO_COLOR_EXT 0x8004
-#define GLX_STATIC_COLOR_EXT 0x8005
-#define GLX_GRAY_SCALE_EXT 0x8006
-#define GLX_STATIC_GRAY_EXT 0x8007
-#define GLX_TRANSPARENT_RGB_EXT 0x8008
-#define GLX_TRANSPARENT_INDEX_EXT 0x8009
-#endif
-
-#ifndef GLX_SGI_swap_control
-#endif
-
-#ifndef GLX_SGI_video_sync
-#endif
-
-#ifndef GLX_SGI_make_current_read
-#endif
-
-#ifndef GLX_SGIX_video_source
-#endif
-
-#ifndef GLX_EXT_visual_rating
-#define GLX_VISUAL_CAVEAT_EXT 0x20
-#define GLX_SLOW_VISUAL_EXT 0x8001
-#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
-/* reuse GLX_NONE_EXT */
-#endif
-
-#ifndef GLX_EXT_import_context
-#define GLX_SHARE_CONTEXT_EXT 0x800A
-#define GLX_VISUAL_ID_EXT 0x800B
-#define GLX_SCREEN_EXT 0x800C
-#endif
-
-#ifndef GLX_SGIX_fbconfig
-#define GLX_WINDOW_BIT_SGIX 0x00000001
-#define GLX_PIXMAP_BIT_SGIX 0x00000002
-#define GLX_RGBA_BIT_SGIX 0x00000001
-#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002
-#define GLX_DRAWABLE_TYPE_SGIX 0x8010
-#define GLX_RENDER_TYPE_SGIX 0x8011
-#define GLX_X_RENDERABLE_SGIX 0x8012
-#define GLX_FBCONFIG_ID_SGIX 0x8013
-#define GLX_RGBA_TYPE_SGIX 0x8014
-#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015
-/* reuse GLX_SCREEN_EXT */
-#endif
-
-#ifndef GLX_SGIX_pbuffer
-#define GLX_PBUFFER_BIT_SGIX 0x00000004
-#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000
-#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008
-#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010
-#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020
-#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040
-#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080
-#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100
-#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017
-#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018
-#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019
-#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A
-#define GLX_PRESERVED_CONTENTS_SGIX 0x801B
-#define GLX_LARGEST_PBUFFER_SGIX 0x801C
-#define GLX_WIDTH_SGIX 0x801D
-#define GLX_HEIGHT_SGIX 0x801E
-#define GLX_EVENT_MASK_SGIX 0x801F
-#define GLX_DAMAGED_SGIX 0x8020
-#define GLX_SAVED_SGIX 0x8021
-#define GLX_WINDOW_SGIX 0x8022
-#define GLX_PBUFFER_SGIX 0x8023
-#endif
-
-#ifndef GLX_SGI_cushion
-#endif
-
-#ifndef GLX_SGIX_video_resize
-#define GLX_SYNC_FRAME_SGIX 0x00000000
-#define GLX_SYNC_SWAP_SGIX 0x00000001
-#endif
-
-#ifndef GLX_SGIX_dmbuffer
-#define GLX_DIGITAL_MEDIA_PBUFFER_SGIX 0x8024
-#endif
-
-#ifndef GLX_SGIX_swap_group
-#endif
-
-#ifndef GLX_SGIX_swap_barrier
-#endif
-
-#ifndef GLX_SGIS_blended_overlay
-#define GLX_BLENDED_RGBA_SGIS 0x8025
-#endif
-
-#ifndef GLX_SGIS_shared_multisample
-#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026
-#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027
-#endif
-
-#ifndef GLX_SUN_get_transparent_index
-#endif
-
-#ifndef GLX_3DFX_multisample
-#define GLX_SAMPLE_BUFFERS_3DFX 0x8050
-#define GLX_SAMPLES_3DFX 0x8051
-#endif
-
-#ifndef GLX_MESA_copy_sub_buffer
-#endif
-
-#ifndef GLX_MESA_pixmap_colormap
-#endif
-
-#ifndef GLX_MESA_release_buffers
-#endif
-
-#ifndef GLX_MESA_set_3dfx_mode
-#define GLX_3DFX_WINDOW_MODE_MESA 0x1
-#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2
-#endif
-
-#ifndef GLX_SGIX_visual_select_group
-#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028
-#endif
-
-#ifndef GLX_OML_swap_method
-#define GLX_SWAP_METHOD_OML 0x8060
-#define GLX_SWAP_EXCHANGE_OML 0x8061
-#define GLX_SWAP_COPY_OML 0x8062
-#define GLX_SWAP_UNDEFINED_OML 0x8063
-#endif
-
-#ifndef GLX_OML_sync_control
-#endif
-
-#ifndef GLX_NV_float_buffer
-#define GLX_FLOAT_COMPONENTS_NV 0x20B0
-#endif
-
-#ifndef GLX_SGIX_hyperpipe
-#define GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX 80
-#define GLX_BAD_HYPERPIPE_CONFIG_SGIX 91
-#define GLX_BAD_HYPERPIPE_SGIX 92
-#define GLX_HYPERPIPE_DISPLAY_PIPE_SGIX 0x00000001
-#define GLX_HYPERPIPE_RENDER_PIPE_SGIX 0x00000002
-#define GLX_PIPE_RECT_SGIX 0x00000001
-#define GLX_PIPE_RECT_LIMITS_SGIX 0x00000002
-#define GLX_HYPERPIPE_STEREO_SGIX 0x00000003
-#define GLX_HYPERPIPE_PIXEL_AVERAGE_SGIX 0x00000004
-#define GLX_HYPERPIPE_ID_SGIX 0x8030
-#endif
-
-#ifndef GLX_MESA_agp_offset
-#endif
-
-#ifndef GLX_EXT_fbconfig_packed_float
-#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
-#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
-#endif
-
-#ifndef GLX_EXT_framebuffer_sRGB
-#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
-#endif
-
-#ifndef GLX_EXT_texture_from_pixmap
-#define GLX_TEXTURE_1D_BIT_EXT 0x00000001
-#define GLX_TEXTURE_2D_BIT_EXT 0x00000002
-#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
-#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0
-#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1
-#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2
-#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3
-#define GLX_Y_INVERTED_EXT 0x20D4
-#define GLX_TEXTURE_FORMAT_EXT 0x20D5
-#define GLX_TEXTURE_TARGET_EXT 0x20D6
-#define GLX_MIPMAP_TEXTURE_EXT 0x20D7
-#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8
-#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9
-#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA
-#define GLX_TEXTURE_1D_EXT 0x20DB
-#define GLX_TEXTURE_2D_EXT 0x20DC
-#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD
-#define GLX_FRONT_LEFT_EXT 0x20DE
-#define GLX_FRONT_RIGHT_EXT 0x20DF
-#define GLX_BACK_LEFT_EXT 0x20E0
-#define GLX_BACK_RIGHT_EXT 0x20E1
-#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT
-#define GLX_BACK_EXT GLX_BACK_LEFT_EXT
-#define GLX_AUX0_EXT 0x20E2
-#define GLX_AUX1_EXT 0x20E3
-#define GLX_AUX2_EXT 0x20E4
-#define GLX_AUX3_EXT 0x20E5
-#define GLX_AUX4_EXT 0x20E6
-#define GLX_AUX5_EXT 0x20E7
-#define GLX_AUX6_EXT 0x20E8
-#define GLX_AUX7_EXT 0x20E9
-#define GLX_AUX8_EXT 0x20EA
-#define GLX_AUX9_EXT 0x20EB
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-#else
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
-** Copyright (c) 2007 The Khronos Group Inc.
-**
-** Permission is hereby granted, free of charge, to any person obtaining a
-** copy of this software and/or associated documentation files (the
-** "Materials"), to deal in the Materials without restriction, including
-** without limitation the rights to use, copy, modify, merge, publish,
-** distribute, sublicense, and/or sell copies of the Materials, and to
-** permit persons to whom the Materials are furnished to do so, subject to
-** the following conditions:
-**
-** The above copyright notice and this permission notice shall be included
-** in all copies or substantial portions of the Materials.
-**
-** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
-*/
-
-#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
-#define WIN32_LEAN_AND_MEAN 1
-#include <windows.h>
-#endif
-
-#ifndef APIENTRY
-#define APIENTRY
-#endif
-#ifndef APIENTRYP
-#define APIENTRYP APIENTRY *
-#endif
-#ifndef GLAPI
-#define GLAPI extern
-#endif
-
-/*************************************************************/
-
-/* Header file version number, required by OpenGL ABI for Linux */
-/* glxext.h last updated 2007/04/21 */
-/* Current version at http://www.opengl.org/registry/ */
-#define GLX_GLXEXT_VERSION 19
-
-#ifndef GLX_VERSION_1_3
-#define GLX_WINDOW_BIT 0x00000001
-#define GLX_PIXMAP_BIT 0x00000002
-#define GLX_PBUFFER_BIT 0x00000004
-#define GLX_RGBA_BIT 0x00000001
-#define GLX_COLOR_INDEX_BIT 0x00000002
-#define GLX_PBUFFER_CLOBBER_MASK 0x08000000
-#define GLX_FRONT_LEFT_BUFFER_BIT 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT 0x00000008
-#define GLX_AUX_BUFFERS_BIT 0x00000010
-#define GLX_DEPTH_BUFFER_BIT 0x00000020
-#define GLX_STENCIL_BUFFER_BIT 0x00000040
-#define GLX_ACCUM_BUFFER_BIT 0x00000080
-#define GLX_CONFIG_CAVEAT 0x20
-#define GLX_X_VISUAL_TYPE 0x22
-#define GLX_TRANSPARENT_TYPE 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE 0x24
-#define GLX_TRANSPARENT_RED_VALUE 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
-#define GLX_DONT_CARE 0xFFFFFFFF
-#define GLX_NONE 0x8000
-#define GLX_SLOW_CONFIG 0x8001
-#define GLX_TRUE_COLOR 0x8002
-#define GLX_DIRECT_COLOR 0x8003
-#define GLX_PSEUDO_COLOR 0x8004
-#define GLX_STATIC_COLOR 0x8005
-#define GLX_GRAY_SCALE 0x8006
-#define GLX_STATIC_GRAY 0x8007
-#define GLX_TRANSPARENT_RGB 0x8008
-#define GLX_TRANSPARENT_INDEX 0x8009
-#define GLX_VISUAL_ID 0x800B
-#define GLX_SCREEN 0x800C
-#define GLX_NON_CONFORMANT_CONFIG 0x800D
-#define GLX_DRAWABLE_TYPE 0x8010
-#define GLX_RENDER_TYPE 0x8011
-#define GLX_X_RENDERABLE 0x8012
-#define GLX_FBCONFIG_ID 0x8013
-#define GLX_RGBA_TYPE 0x8014
-#define GLX_COLOR_INDEX_TYPE 0x8015
-#define GLX_MAX_PBUFFER_WIDTH 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT 0x8017
-#define GLX_MAX_PBUFFER_PIXELS 0x8018
-#define GLX_PRESERVED_CONTENTS 0x801B
-#define GLX_LARGEST_PBUFFER 0x801C
-#define GLX_WIDTH 0x801D
-#define GLX_HEIGHT 0x801E
-#define GLX_EVENT_MASK 0x801F
-#define GLX_DAMAGED 0x8020
-#define GLX_SAVED 0x8021
-#define GLX_WINDOW 0x8022
-#define GLX_PBUFFER 0x8023
-#define GLX_PBUFFER_HEIGHT 0x8040
-#define GLX_PBUFFER_WIDTH 0x8041
-#endif
-
-#ifndef GLX_VERSION_1_4
-#define GLX_SAMPLE_BUFFERS 100000
-#define GLX_SAMPLES 100001
-#endif
-
-#ifndef GLX_ARB_get_proc_address
-#endif
-
-#ifndef GLX_ARB_multisample
-#define GLX_SAMPLE_BUFFERS_ARB 100000
-#define GLX_SAMPLES_ARB 100001
-#endif
-
-#ifndef GLX_ARB_fbconfig_float
-#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9
-#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004
-#endif
-
-#ifndef GLX_SGIS_multisample
-#define GLX_SAMPLE_BUFFERS_SGIS 100000
-#define GLX_SAMPLES_SGIS 100001
-#endif
-
-#ifndef GLX_EXT_visual_info
-#define GLX_X_VISUAL_TYPE_EXT 0x22
-#define GLX_TRANSPARENT_TYPE_EXT 0x23
-#define GLX_TRANSPARENT_INDEX_VALUE_EXT 0x24
-#define GLX_TRANSPARENT_RED_VALUE_EXT 0x25
-#define GLX_TRANSPARENT_GREEN_VALUE_EXT 0x26
-#define GLX_TRANSPARENT_BLUE_VALUE_EXT 0x27
-#define GLX_TRANSPARENT_ALPHA_VALUE_EXT 0x28
-#define GLX_NONE_EXT 0x8000
-#define GLX_TRUE_COLOR_EXT 0x8002
-#define GLX_DIRECT_COLOR_EXT 0x8003
-#define GLX_PSEUDO_COLOR_EXT 0x8004
-#define GLX_STATIC_COLOR_EXT 0x8005
-#define GLX_GRAY_SCALE_EXT 0x8006
-#define GLX_STATIC_GRAY_EXT 0x8007
-#define GLX_TRANSPARENT_RGB_EXT 0x8008
-#define GLX_TRANSPARENT_INDEX_EXT 0x8009
-#endif
-
-#ifndef GLX_SGI_swap_control
-#endif
-
-#ifndef GLX_SGI_video_sync
-#endif
-
-#ifndef GLX_SGI_make_current_read
-#endif
-
-#ifndef GLX_SGIX_video_source
-#endif
-
-#ifndef GLX_EXT_visual_rating
-#define GLX_VISUAL_CAVEAT_EXT 0x20
-#define GLX_SLOW_VISUAL_EXT 0x8001
-#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
-/* reuse GLX_NONE_EXT */
-#endif
-
-#ifndef GLX_EXT_import_context
-#define GLX_SHARE_CONTEXT_EXT 0x800A
-#define GLX_VISUAL_ID_EXT 0x800B
-#define GLX_SCREEN_EXT 0x800C
-#endif
-
-#ifndef GLX_SGIX_fbconfig
-#define GLX_WINDOW_BIT_SGIX 0x00000001
-#define GLX_PIXMAP_BIT_SGIX 0x00000002
-#define GLX_RGBA_BIT_SGIX 0x00000001
-#define GLX_COLOR_INDEX_BIT_SGIX 0x00000002
-#define GLX_DRAWABLE_TYPE_SGIX 0x8010
-#define GLX_RENDER_TYPE_SGIX 0x8011
-#define GLX_X_RENDERABLE_SGIX 0x8012
-#define GLX_FBCONFIG_ID_SGIX 0x8013
-#define GLX_RGBA_TYPE_SGIX 0x8014
-#define GLX_COLOR_INDEX_TYPE_SGIX 0x8015
-/* reuse GLX_SCREEN_EXT */
-#endif
-
-#ifndef GLX_SGIX_pbuffer
-#define GLX_PBUFFER_BIT_SGIX 0x00000004
-#define GLX_BUFFER_CLOBBER_MASK_SGIX 0x08000000
-#define GLX_FRONT_LEFT_BUFFER_BIT_SGIX 0x00000001
-#define GLX_FRONT_RIGHT_BUFFER_BIT_SGIX 0x00000002
-#define GLX_BACK_LEFT_BUFFER_BIT_SGIX 0x00000004
-#define GLX_BACK_RIGHT_BUFFER_BIT_SGIX 0x00000008
-#define GLX_AUX_BUFFERS_BIT_SGIX 0x00000010
-#define GLX_DEPTH_BUFFER_BIT_SGIX 0x00000020
-#define GLX_STENCIL_BUFFER_BIT_SGIX 0x00000040
-#define GLX_ACCUM_BUFFER_BIT_SGIX 0x00000080
-#define GLX_SAMPLE_BUFFERS_BIT_SGIX 0x00000100
-#define GLX_MAX_PBUFFER_WIDTH_SGIX 0x8016
-#define GLX_MAX_PBUFFER_HEIGHT_SGIX 0x8017
-#define GLX_MAX_PBUFFER_PIXELS_SGIX 0x8018
-#define GLX_OPTIMAL_PBUFFER_WIDTH_SGIX 0x8019
-#define GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX 0x801A
-#define GLX_PRESERVED_CONTENTS_SGIX 0x801B
-#define GLX_LARGEST_PBUFFER_SGIX 0x801C
-#define GLX_WIDTH_SGIX 0x801D
-#define GLX_HEIGHT_SGIX 0x801E
-#define GLX_EVENT_MASK_SGIX 0x801F
-#define GLX_DAMAGED_SGIX 0x8020
-#define GLX_SAVED_SGIX 0x8021
-#define GLX_WINDOW_SGIX 0x8022
-#define GLX_PBUFFER_SGIX 0x8023
-#endif
-
-#ifndef GLX_SGI_cushion
-#endif
-
-#ifndef GLX_SGIX_video_resize
-#define GLX_SYNC_FRAME_SGIX 0x00000000
-#define GLX_SYNC_SWAP_SGIX 0x00000001
-#endif
-
-#ifndef GLX_SGIX_dmbuffer
-#define GLX_DIGITAL_MEDIA_PBUFFER_SGIX 0x8024
-#endif
-
-#ifndef GLX_SGIX_swap_group
-#endif
-
-#ifndef GLX_SGIX_swap_barrier
-#endif
-
-#ifndef GLX_SGIS_blended_overlay
-#define GLX_BLENDED_RGBA_SGIS 0x8025
-#endif
-
-#ifndef GLX_SGIS_shared_multisample
-#define GLX_MULTISAMPLE_SUB_RECT_WIDTH_SGIS 0x8026
-#define GLX_MULTISAMPLE_SUB_RECT_HEIGHT_SGIS 0x8027
-#endif
-
-#ifndef GLX_SUN_get_transparent_index
-#endif
-
-#ifndef GLX_3DFX_multisample
-#define GLX_SAMPLE_BUFFERS_3DFX 0x8050
-#define GLX_SAMPLES_3DFX 0x8051
-#endif
-
-#ifndef GLX_MESA_copy_sub_buffer
-#endif
-
-#ifndef GLX_MESA_pixmap_colormap
-#endif
-
-#ifndef GLX_MESA_release_buffers
-#endif
-
-#ifndef GLX_MESA_set_3dfx_mode
-#define GLX_3DFX_WINDOW_MODE_MESA 0x1
-#define GLX_3DFX_FULLSCREEN_MODE_MESA 0x2
-#endif
-
-#ifndef GLX_SGIX_visual_select_group
-#define GLX_VISUAL_SELECT_GROUP_SGIX 0x8028
-#endif
-
-#ifndef GLX_OML_swap_method
-#define GLX_SWAP_METHOD_OML 0x8060
-#define GLX_SWAP_EXCHANGE_OML 0x8061
-#define GLX_SWAP_COPY_OML 0x8062
-#define GLX_SWAP_UNDEFINED_OML 0x8063
-#endif
-
-#ifndef GLX_OML_sync_control
-#endif
-
-#ifndef GLX_NV_float_buffer
-#define GLX_FLOAT_COMPONENTS_NV 0x20B0
-#endif
-
-#ifndef GLX_SGIX_hyperpipe
-#define GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX 80
-#define GLX_BAD_HYPERPIPE_CONFIG_SGIX 91
-#define GLX_BAD_HYPERPIPE_SGIX 92
-#define GLX_HYPERPIPE_DISPLAY_PIPE_SGIX 0x00000001
-#define GLX_HYPERPIPE_RENDER_PIPE_SGIX 0x00000002
-#define GLX_PIPE_RECT_SGIX 0x00000001
-#define GLX_PIPE_RECT_LIMITS_SGIX 0x00000002
-#define GLX_HYPERPIPE_STEREO_SGIX 0x00000003
-#define GLX_HYPERPIPE_PIXEL_AVERAGE_SGIX 0x00000004
-#define GLX_HYPERPIPE_ID_SGIX 0x8030
-#endif
-
-#ifndef GLX_MESA_agp_offset
-#endif
-
-#ifndef GLX_EXT_fbconfig_packed_float
-#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
-#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
-#endif
-
-#ifndef GLX_EXT_framebuffer_sRGB
-#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
-#endif
-
-#ifndef GLX_EXT_texture_from_pixmap
-#define GLX_TEXTURE_1D_BIT_EXT 0x00000001
-#define GLX_TEXTURE_2D_BIT_EXT 0x00000002
-#define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
-#define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0
-#define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x20D1
-#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x20D2
-#define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x20D3
-#define GLX_Y_INVERTED_EXT 0x20D4
-#define GLX_TEXTURE_FORMAT_EXT 0x20D5
-#define GLX_TEXTURE_TARGET_EXT 0x20D6
-#define GLX_MIPMAP_TEXTURE_EXT 0x20D7
-#define GLX_TEXTURE_FORMAT_NONE_EXT 0x20D8
-#define GLX_TEXTURE_FORMAT_RGB_EXT 0x20D9
-#define GLX_TEXTURE_FORMAT_RGBA_EXT 0x20DA
-#define GLX_TEXTURE_1D_EXT 0x20DB
-#define GLX_TEXTURE_2D_EXT 0x20DC
-#define GLX_TEXTURE_RECTANGLE_EXT 0x20DD
-#define GLX_FRONT_LEFT_EXT 0x20DE
-#define GLX_FRONT_RIGHT_EXT 0x20DF
-#define GLX_BACK_LEFT_EXT 0x20E0
-#define GLX_BACK_RIGHT_EXT 0x20E1
-#define GLX_FRONT_EXT GLX_FRONT_LEFT_EXT
-#define GLX_BACK_EXT GLX_BACK_LEFT_EXT
-#define GLX_AUX0_EXT 0x20E2
-#define GLX_AUX1_EXT 0x20E3
-#define GLX_AUX2_EXT 0x20E4
-#define GLX_AUX3_EXT 0x20E5
-#define GLX_AUX4_EXT 0x20E6
-#define GLX_AUX5_EXT 0x20E7
-#define GLX_AUX6_EXT 0x20E8
-#define GLX_AUX7_EXT 0x20E9
-#define GLX_AUX8_EXT 0x20EA
-#define GLX_AUX9_EXT 0x20EB
-#endif
-
-
-/*************************************************************/
-
-#ifndef GLX_ARB_get_proc_address
-typedef void (*__GLXextFuncPtr)(void);
-#endif
-
-#ifndef GLX_SGIX_video_source
-typedef XID GLXVideoSourceSGIX;
-#endif
-
-#ifndef GLX_SGIX_fbconfig
-typedef XID GLXFBConfigIDSGIX;
-typedef struct __GLXFBConfigRec *GLXFBConfigSGIX;
-#endif
-
-#ifndef GLX_SGIX_pbuffer
-typedef XID GLXPbufferSGIX;
-typedef struct {
- int type;
- unsigned long serial; /* # of last request processed by server */
- Bool send_event; /* true if this came for SendEvent request */
- Display *display; /* display the event was read from */
- GLXDrawable drawable; /* i.d. of Drawable */
- int event_type; /* GLX_DAMAGED_SGIX or GLX_SAVED_SGIX */
- int draw_type; /* GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX */
- unsigned int mask; /* mask indicating which buffers are affected*/
- int x, y;
- int width, height;
- int count; /* if nonzero, at least this many more */
-} GLXBufferClobberEventSGIX;
-#endif
-
-#ifndef GLEXT_64_TYPES_DEFINED
-/* This code block is duplicated in glxext.h, so must be protected */
-#define GLEXT_64_TYPES_DEFINED
-/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
-/* (as used in the GLX_OML_sync_control extension). */
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-#include <inttypes.h>
-#elif defined(__sun__) || defined(__digital__)
-#include <inttypes.h>
-#if defined(__STDC__)
-#if defined(__arch64__)
-typedef long int int64_t;
-typedef unsigned long int uint64_t;
-#else
-typedef long long int int64_t;
-typedef unsigned long long int uint64_t;
-#endif /* __arch64__ */
-#endif /* __STDC__ */
-#elif defined( __VMS )
-#include <inttypes.h>
-#elif defined(__SCO__) || defined(__USLC__)
-#include <stdint.h>
-#elif defined(__UNIXOS2__) || defined(__SOL64__)
-typedef long int int32_t;
-typedef long long int int64_t;
-typedef unsigned long long int uint64_t;
-#elif defined(_WIN32) && defined(__GNUC__)
-#include <stdint.h>
-#elif defined(_WIN32)
-typedef __int32 int32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-#else
-#include <inttypes.h> /* Fallback option */
-#endif
-#endif
-
-#ifndef GLX_VERSION_1_3
-#define GLX_VERSION_1_3 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern GLXFBConfig * glXGetFBConfigs (Display *, int, int *);
-extern GLXFBConfig * glXChooseFBConfig (Display *, int, const int *, int *);
-extern int glXGetFBConfigAttrib (Display *, GLXFBConfig, int, int *);
-extern XVisualInfo * glXGetVisualFromFBConfig (Display *, GLXFBConfig);
-extern GLXWindow glXCreateWindow (Display *, GLXFBConfig, Window, const int *);
-extern void glXDestroyWindow (Display *, GLXWindow);
-extern GLXPixmap glXCreatePixmap (Display *, GLXFBConfig, Pixmap, const int *);
-extern void glXDestroyPixmap (Display *, GLXPixmap);
-extern GLXPbuffer glXCreatePbuffer (Display *, GLXFBConfig, const int *);
-extern void glXDestroyPbuffer (Display *, GLXPbuffer);
-extern void glXQueryDrawable (Display *, GLXDrawable, int, unsigned int *);
-extern GLXContext glXCreateNewContext (Display *, GLXFBConfig, int, GLXContext, Bool);
-extern Bool glXMakeContextCurrent (Display *, GLXDrawable, GLXDrawable, GLXContext);
-extern GLXDrawable glXGetCurrentReadDrawable (void);
-extern Display * glXGetCurrentDisplay (void);
-extern int glXQueryContext (Display *, GLXContext, int, int *);
-extern void glXSelectEvent (Display *, GLXDrawable, unsigned long);
-extern void glXGetSelectedEvent (Display *, GLXDrawable, unsigned long *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef GLXFBConfig * ( * PFNGLXGETFBCONFIGSPROC) (Display *dpy, int screen, int *nelements);
-typedef GLXFBConfig * ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements);
-typedef int ( * PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value);
-typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config);
-typedef GLXWindow ( * PFNGLXCREATEWINDOWPROC) (Display *dpy, GLXFBConfig config, Window win, const int *attrib_list);
-typedef void ( * PFNGLXDESTROYWINDOWPROC) (Display *dpy, GLXWindow win);
-typedef GLXPixmap ( * PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list);
-typedef void ( * PFNGLXDESTROYPIXMAPPROC) (Display *dpy, GLXPixmap pixmap);
-typedef GLXPbuffer ( * PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list);
-typedef void ( * PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf);
-typedef void ( * PFNGLXQUERYDRAWABLEPROC) (Display *dpy, GLXDrawable draw, int attribute, unsigned int *value);
-typedef GLXContext ( * PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
-typedef Bool ( * PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
-typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLEPROC) (void);
-typedef Display * ( * PFNGLXGETCURRENTDISPLAYPROC) (void);
-typedef int ( * PFNGLXQUERYCONTEXTPROC) (Display *dpy, GLXContext ctx, int attribute, int *value);
-typedef void ( * PFNGLXSELECTEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long event_mask);
-typedef void ( * PFNGLXGETSELECTEDEVENTPROC) (Display *dpy, GLXDrawable draw, unsigned long *event_mask);
-#endif
-
-#ifndef GLX_VERSION_1_4
-#define GLX_VERSION_1_4 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern __GLXextFuncPtr glXGetProcAddress (const GLubyte *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName);
-#endif
-
-#ifndef GLX_ARB_get_proc_address
-#define GLX_ARB_get_proc_address 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef __GLXextFuncPtr ( * PFNGLXGETPROCADDRESSARBPROC) (const GLubyte *procName);
-#endif
-
-#ifndef GLX_ARB_multisample
-#define GLX_ARB_multisample 1
-#endif
-
-#ifndef GLX_ARB_fbconfig_float
-#define GLX_ARB_fbconfig_float 1
-#endif
-
-#ifndef GLX_SGIS_multisample
-#define GLX_SGIS_multisample 1
-#endif
-
-#ifndef GLX_EXT_visual_info
-#define GLX_EXT_visual_info 1
-#endif
-
-#ifndef GLX_SGI_swap_control
-#define GLX_SGI_swap_control 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern int glXSwapIntervalSGI (int);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef int ( * PFNGLXSWAPINTERVALSGIPROC) (int interval);
-#endif
-
-#ifndef GLX_SGI_video_sync
-#define GLX_SGI_video_sync 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern int glXGetVideoSyncSGI (unsigned int *);
-extern int glXWaitVideoSyncSGI (int, int, unsigned int *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef int ( * PFNGLXGETVIDEOSYNCSGIPROC) (unsigned int *count);
-typedef int ( * PFNGLXWAITVIDEOSYNCSGIPROC) (int divisor, int remainder, unsigned int *count);
-#endif
-
-#ifndef GLX_SGI_make_current_read
-#define GLX_SGI_make_current_read 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Bool glXMakeCurrentReadSGI (Display *, GLXDrawable, GLXDrawable, GLXContext);
-extern GLXDrawable glXGetCurrentReadDrawableSGI (void);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Bool ( * PFNGLXMAKECURRENTREADSGIPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
-typedef GLXDrawable ( * PFNGLXGETCURRENTREADDRAWABLESGIPROC) (void);
-#endif
-
-#ifndef GLX_SGIX_video_source
-#define GLX_SGIX_video_source 1
-#ifdef _VL_H
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX (Display *, int, VLServer, VLPath, int, VLNode);
-extern void glXDestroyGLXVideoSourceSGIX (Display *, GLXVideoSourceSGIX);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef GLXVideoSourceSGIX ( * PFNGLXCREATEGLXVIDEOSOURCESGIXPROC) (Display *display, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode);
-typedef void ( * PFNGLXDESTROYGLXVIDEOSOURCESGIXPROC) (Display *dpy, GLXVideoSourceSGIX glxvideosource);
-#endif /* _VL_H */
-#endif
-
-#ifndef GLX_EXT_visual_rating
-#define GLX_EXT_visual_rating 1
-#endif
-
-#ifndef GLX_EXT_import_context
-#define GLX_EXT_import_context 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Display * glXGetCurrentDisplayEXT (void);
-extern int glXQueryContextInfoEXT (Display *, GLXContext, int, int *);
-extern GLXContextID glXGetContextIDEXT (const GLXContext);
-extern GLXContext glXImportContextEXT (Display *, GLXContextID);
-extern void glXFreeContextEXT (Display *, GLXContext);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Display * ( * PFNGLXGETCURRENTDISPLAYEXTPROC) (void);
-typedef int ( * PFNGLXQUERYCONTEXTINFOEXTPROC) (Display *dpy, GLXContext context, int attribute, int *value);
-typedef GLXContextID ( * PFNGLXGETCONTEXTIDEXTPROC) (const GLXContext context);
-typedef GLXContext ( * PFNGLXIMPORTCONTEXTEXTPROC) (Display *dpy, GLXContextID contextID);
-typedef void ( * PFNGLXFREECONTEXTEXTPROC) (Display *dpy, GLXContext context);
-#endif
-
-#ifndef GLX_SGIX_fbconfig
-#define GLX_SGIX_fbconfig 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern int glXGetFBConfigAttribSGIX (Display *, GLXFBConfigSGIX, int, int *);
-extern GLXFBConfigSGIX * glXChooseFBConfigSGIX (Display *, int, int *, int *);
-extern GLXPixmap glXCreateGLXPixmapWithConfigSGIX (Display *, GLXFBConfigSGIX, Pixmap);
-extern GLXContext glXCreateContextWithConfigSGIX (Display *, GLXFBConfigSGIX, int, GLXContext, Bool);
-extern XVisualInfo * glXGetVisualFromFBConfigSGIX (Display *, GLXFBConfigSGIX);
-extern GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX (Display *, XVisualInfo *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef int ( * PFNGLXGETFBCONFIGATTRIBSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value);
-typedef GLXFBConfigSGIX * ( * PFNGLXCHOOSEFBCONFIGSGIXPROC) (Display *dpy, int screen, int *attrib_list, int *nelements);
-typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap);
-typedef GLXContext ( * PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct);
-typedef XVisualInfo * ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLXFBConfigSGIX config);
-typedef GLXFBConfigSGIX ( * PFNGLXGETFBCONFIGFROMVISUALSGIXPROC) (Display *dpy, XVisualInfo *vis);
-#endif
-
-#ifndef GLX_SGIX_pbuffer
-#define GLX_SGIX_pbuffer 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern GLXPbufferSGIX glXCreateGLXPbufferSGIX (Display *, GLXFBConfigSGIX, unsigned int, unsigned int, int *);
-extern void glXDestroyGLXPbufferSGIX (Display *, GLXPbufferSGIX);
-extern int glXQueryGLXPbufferSGIX (Display *, GLXPbufferSGIX, int, unsigned int *);
-extern void glXSelectEventSGIX (Display *, GLXDrawable, unsigned long);
-extern void glXGetSelectedEventSGIX (Display *, GLXDrawable, unsigned long *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef GLXPbufferSGIX ( * PFNGLXCREATEGLXPBUFFERSGIXPROC) (Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list);
-typedef void ( * PFNGLXDESTROYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf);
-typedef int ( * PFNGLXQUERYGLXPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value);
-typedef void ( * PFNGLXSELECTEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long mask);
-typedef void ( * PFNGLXGETSELECTEDEVENTSGIXPROC) (Display *dpy, GLXDrawable drawable, unsigned long *mask);
-#endif
-
-#ifndef GLX_SGI_cushion
-#define GLX_SGI_cushion 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern void glXCushionSGI (Display *, Window, float);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef void ( * PFNGLXCUSHIONSGIPROC) (Display *dpy, Window window, float cushion);
-#endif
-
-#ifndef GLX_SGIX_video_resize
-#define GLX_SGIX_video_resize 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern int glXBindChannelToWindowSGIX (Display *, int, int, Window);
-extern int glXChannelRectSGIX (Display *, int, int, int, int, int, int);
-extern int glXQueryChannelRectSGIX (Display *, int, int, int *, int *, int *, int *);
-extern int glXQueryChannelDeltasSGIX (Display *, int, int, int *, int *, int *, int *);
-extern int glXChannelRectSyncSGIX (Display *, int, int, GLenum);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef int ( * PFNGLXBINDCHANNELTOWINDOWSGIXPROC) (Display *display, int screen, int channel, Window window);
-typedef int ( * PFNGLXCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int x, int y, int w, int h);
-typedef int ( * PFNGLXQUERYCHANNELRECTSGIXPROC) (Display *display, int screen, int channel, int *dx, int *dy, int *dw, int *dh);
-typedef int ( * PFNGLXQUERYCHANNELDELTASSGIXPROC) (Display *display, int screen, int channel, int *x, int *y, int *w, int *h);
-typedef int ( * PFNGLXCHANNELRECTSYNCSGIXPROC) (Display *display, int screen, int channel, GLenum synctype);
-#endif
-
-#ifndef GLX_SGIX_dmbuffer
-#define GLX_SGIX_dmbuffer 1
-#ifdef _DM_BUFFER_H_
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Bool glXAssociateDMPbufferSGIX (Display *, GLXPbufferSGIX, DMparams *, DMbuffer);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Bool ( * PFNGLXASSOCIATEDMPBUFFERSGIXPROC) (Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer);
-#endif /* _DM_BUFFER_H_ */
-#endif
-
-#ifndef GLX_SGIX_swap_group
-#define GLX_SGIX_swap_group 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern void glXJoinSwapGroupSGIX (Display *, GLXDrawable, GLXDrawable);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef void ( * PFNGLXJOINSWAPGROUPSGIXPROC) (Display *dpy, GLXDrawable drawable, GLXDrawable member);
-#endif
-
-#ifndef GLX_SGIX_swap_barrier
-#define GLX_SGIX_swap_barrier 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern void glXBindSwapBarrierSGIX (Display *, GLXDrawable, int);
-extern Bool glXQueryMaxSwapBarriersSGIX (Display *, int, int *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef void ( * PFNGLXBINDSWAPBARRIERSGIXPROC) (Display *dpy, GLXDrawable drawable, int barrier);
-typedef Bool ( * PFNGLXQUERYMAXSWAPBARRIERSSGIXPROC) (Display *dpy, int screen, int *max);
-#endif
-
-#ifndef GLX_SUN_get_transparent_index
-#define GLX_SUN_get_transparent_index 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Status glXGetTransparentIndexSUN (Display *, Window, Window, long *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Status ( * PFNGLXGETTRANSPARENTINDEXSUNPROC) (Display *dpy, Window overlay, Window underlay, long *pTransparentIndex);
-#endif
-
-#ifndef GLX_MESA_copy_sub_buffer
-#define GLX_MESA_copy_sub_buffer 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern void glXCopySubBufferMESA (Display *, GLXDrawable, int, int, int, int);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef void ( * PFNGLXCOPYSUBBUFFERMESAPROC) (Display *dpy, GLXDrawable drawable, int x, int y, int width, int height);
-#endif
-
-#ifndef GLX_MESA_pixmap_colormap
-#define GLX_MESA_pixmap_colormap 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern GLXPixmap glXCreateGLXPixmapMESA (Display *, XVisualInfo *, Pixmap, Colormap);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef GLXPixmap ( * PFNGLXCREATEGLXPIXMAPMESAPROC) (Display *dpy, XVisualInfo *visual, Pixmap pixmap, Colormap cmap);
-#endif
-
-#ifndef GLX_MESA_release_buffers
-#define GLX_MESA_release_buffers 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Bool glXReleaseBuffersMESA (Display *, GLXDrawable);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Bool ( * PFNGLXRELEASEBUFFERSMESAPROC) (Display *dpy, GLXDrawable drawable);
-#endif
-
-#ifndef GLX_MESA_set_3dfx_mode
-#define GLX_MESA_set_3dfx_mode 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Bool glXSet3DfxModeMESA (int);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Bool ( * PFNGLXSET3DFXMODEMESAPROC) (int mode);
-#endif
-
-#ifndef GLX_SGIX_visual_select_group
-#define GLX_SGIX_visual_select_group 1
-#endif
-
-#ifndef GLX_OML_swap_method
-#define GLX_OML_swap_method 1
-#endif
-
-#ifndef GLX_OML_sync_control
-#define GLX_OML_sync_control 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern Bool glXGetSyncValuesOML (Display *, GLXDrawable, int64_t *, int64_t *, int64_t *);
-extern Bool glXGetMscRateOML (Display *, GLXDrawable, int32_t *, int32_t *);
-extern int64_t glXSwapBuffersMscOML (Display *, GLXDrawable, int64_t, int64_t, int64_t);
-extern Bool glXWaitForMscOML (Display *, GLXDrawable, int64_t, int64_t, int64_t, int64_t *, int64_t *, int64_t *);
-extern Bool glXWaitForSbcOML (Display *, GLXDrawable, int64_t, int64_t *, int64_t *, int64_t *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef Bool ( * PFNGLXGETSYNCVALUESOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t *ust, int64_t *msc, int64_t *sbc);
-typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator);
-typedef int64_t ( * PFNGLXSWAPBUFFERSMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder);
-typedef Bool ( * PFNGLXWAITFORMSCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc);
-typedef Bool ( * PFNGLXWAITFORSBCOMLPROC) (Display *dpy, GLXDrawable drawable, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc);
-#endif
-
-#ifndef GLX_NV_float_buffer
-#define GLX_NV_float_buffer 1
-#endif
-
-#ifndef GLX_SGIX_hyperpipe
-#define GLX_SGIX_hyperpipe 1
-
-typedef struct {
- char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
- int networkId;
-} GLXHyperpipeNetworkSGIX;
-
-typedef struct {
- char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
- int channel;
- unsigned int
- participationType;
- int timeSlice;
-} GLXHyperpipeConfigSGIX;
-
-typedef struct {
- char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
- int srcXOrigin, srcYOrigin, srcWidth, srcHeight;
- int destXOrigin, destYOrigin, destWidth, destHeight;
-} GLXPipeRect;
-
-typedef struct {
- char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
- int XOrigin, YOrigin, maxHeight, maxWidth;
-} GLXPipeRectLimits;
-
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern GLXHyperpipeNetworkSGIX * glXQueryHyperpipeNetworkSGIX (Display *, int *);
-extern int glXHyperpipeConfigSGIX (Display *, int, int, GLXHyperpipeConfigSGIX *, int *);
-extern GLXHyperpipeConfigSGIX * glXQueryHyperpipeConfigSGIX (Display *, int, int *);
-extern int glXDestroyHyperpipeConfigSGIX (Display *, int);
-extern int glXBindHyperpipeSGIX (Display *, int);
-extern int glXQueryHyperpipeBestAttribSGIX (Display *, int, int, int, void *, void *);
-extern int glXHyperpipeAttribSGIX (Display *, int, int, int, void *);
-extern int glXQueryHyperpipeAttribSGIX (Display *, int, int, int, void *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef GLXHyperpipeNetworkSGIX * ( * PFNGLXQUERYHYPERPIPENETWORKSGIXPROC) (Display *dpy, int *npipes);
-typedef int ( * PFNGLXHYPERPIPECONFIGSGIXPROC) (Display *dpy, int networkId, int npipes, GLXHyperpipeConfigSGIX *cfg, int *hpId);
-typedef GLXHyperpipeConfigSGIX * ( * PFNGLXQUERYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId, int *npipes);
-typedef int ( * PFNGLXDESTROYHYPERPIPECONFIGSGIXPROC) (Display *dpy, int hpId);
-typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId);
-typedef int ( * PFNGLXQUERYHYPERPIPEBESTATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList, void *returnAttribList);
-typedef int ( * PFNGLXHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *attribList);
-typedef int ( * PFNGLXQUERYHYPERPIPEATTRIBSGIXPROC) (Display *dpy, int timeSlice, int attrib, int size, void *returnAttribList);
-#endif
-
-#ifndef GLX_MESA_agp_offset
-#define GLX_MESA_agp_offset 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern unsigned int glXGetAGPOffsetMESA (const void *);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef unsigned int ( * PFNGLXGETAGPOFFSETMESAPROC) (const void *pointer);
-#endif
-
-#ifndef GLX_EXT_fbconfig_packed_float
-#define GLX_EXT_fbconfig_packed_float 1
-#endif
-
-#ifndef GLX_EXT_framebuffer_sRGB
-#define GLX_EXT_framebuffer_sRGB 1
-#endif
-
-#ifndef GLX_EXT_texture_from_pixmap
-#define GLX_EXT_texture_from_pixmap 1
-#ifdef GLX_GLXEXT_PROTOTYPES
-extern void glXBindTexImageEXT (Display *, GLXDrawable, int, const int *);
-extern void glXReleaseTexImageEXT (Display *, GLXDrawable, int);
-#endif /* GLX_GLXEXT_PROTOTYPES */
-typedef void ( * PFNGLXBINDTEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer, const int *attrib_list);
-typedef void ( * PFNGLXRELEASETEXIMAGEEXTPROC) (Display *dpy, GLXDrawable drawable, int buffer);
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-#endif
+++ /dev/null
-/*
- * Guest-side implementation of GL/GLX API. Replacement of standard libGL.so
- *
- * Copyright (c) 2006,2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/* This library can also be used independly of qemu as a TCP/IP client with the opengl_server TCP/IP server */
-
-/* gcc -Wall -g -O2 opengl_client.c -shared -o libGL.so.1 */
-
-/* Windows compilations instructions */
-/* After building qemu, cd to target-i386 */
-/* i586-mingw32msvc-gcc -O2 -Wall opengl_client.c -c -I../i386-softmmu -I. -DBUILD_GL32 */
-/* i586-mingw32msvc-dllwrap -o opengl32.dll --def opengl32.def -Wl,-enable-stdcall-fixup opengl_client.o -lws2_32
- */
-
-
-/* objdump -T ../i386-softmmu/libGL.so | grep Base | awk '{print $7}' | grep gl | sort > opengl32_temp.def */
-
-
-/* HACK_XGL=true USE_TCP_COMMUNICATION=1 LD_LIBRARY_PATH=/home/even/qemu/cvs280207/qemu/i386-softmmu:/home/even/cairo/glitz-0.5.6/src/glx/.libs/:/home/even/cairo/glitz-0.5.6/src/.libsvalgrind Xgl -screen 800x600 :10 -ac */
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#define _XOPEN_SOURCE 600
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <assert.h>
-#include <math.h>
-#include <fcntl.h>
-
-#define GL_GLEXT_LEGACY
-#include "mesa_gl.h"
-#include "mesa_glext.h"
-
-#ifndef WIN32
-#include <dlfcn.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <pthread.h>
-
-#include <X11/X.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/Xfixes.h>
-
-#include <mesa_glx.h>
-#else
-#include <excpt.h>
-#include <windows.h>
-WINGDIAPI const char* WINAPI wglGetExtensionsStringARB(HDC hdc);
-#endif
-
-#define ENABLE_THREAD_SAFETY
-
-/* Opengl character device */
-#define DEV_NAME "/dev/opengl"
-int fd; /* file description */
-
-/*void *pthread_getspecific(pthread_key_t key);
- int pthread_setspecific(pthread_key_t key, const void *value);*/
-
-#define CHECK_ARGS(x, y) (1 / ((sizeof(x)/sizeof(x[0])) == (sizeof(y)/sizeof(y[0])) ? 1 : 0)) ? x : x, y
-
-#ifndef _WIN32
-
-#define TCP_COMMUNICATION_SUPPORT
-#define USE_TCP_METHOD
-//#define USE_DEVICE_METHOD
-//#define USE_SWI_METHOD
-#endif
-//#define PROVIDE_STUB_IMPLEMENTATION
-
-#define NOT_IMPLEMENTED(x) log_gl(#x " not implemented !\n")
-
-static void log_gl(const char* format, ...);
-
-static const char* interestingEnvVars[] =
-{
- "USE_TCP_COMMUNICATION", /* default : not set */
- "GET_IMG_FROM_SERVER", /* default : not set */ /* unsupported for Win32 guest */
- "GL_SERVER", /* default is localhost */
- "GL_SERVER_PORT", /* */
- "GL_ERR_FILE", /* default is stderr */
- "HACK_XGL", /* default : not set */ /* unsupported for Win32 guest */
- "DEBUG_GL", /* default : not set */
- "DEBUG_ARRAY_PTR", /* default : not set */
- "DISABLE_OPTIM", /* default : not set */
- "LIMIT_FPS", /* default : not set */ /* unsupported for Win32 guest */
- "ENABLE_GL_BUFFERING", /* default : set if TCP/IP communication or KQEMU detected */
- "NO_MOVE", /* default : set if TCP/IP communication */
-};
-
-
-#ifdef WIN32
-
-typedef struct
-{
- char* name;
- char* value;
-} EnvVarStruct;
-
-static int nbEnvVar = 0;
-static EnvVarStruct* envVar = NULL;
-
-const char* my_getenv(const char* name)
-{
- int i;
- for(i=0;i<nbEnvVar;i++)
- {
- if (strcmp(envVar[i].name, name) == 0)
- return envVar[i].value;
- }
- return getenv(name);
-}
-
-void my_setenv(const char* name, const char* value, int ignored)
-{
- int i;
- for(i=0;i<nbEnvVar;i++)
- {
- if (strcmp(envVar[i].name, name) == 0)
- {
- free(envVar[i].value);
- envVar[i].value = strdup(value);
- return;
- }
- }
- envVar = (EnvVarStruct*)realloc(envVar, sizeof(EnvVarStruct) * (nbEnvVar + 1));
- envVar[nbEnvVar].name = strdup(name);
- envVar[nbEnvVar].value = strdup(value);
- nbEnvVar++;
-}
-
-#define getenv my_getenv
-#define setenv my_setenv
-
-#endif
-
-#define EXT_FUNC(x) x
-
-#define CONCAT(a, b) a##b
-#define DEFINE_EXT(glFunc, paramsDecl, paramsCall) GLAPI void APIENTRY CONCAT(glFunc,EXT) paramsDecl { glFunc paramsCall; }
-
-#ifdef WIN32
-#define portableGetProcAddress wglGetProcAddress
-#else
-#define portableGetProcAddress glXGetProcAddress
-#endif
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-static FILE* get_err_file()
-{
- static FILE* err_file = NULL;
- if (err_file == NULL)
- {
- err_file = getenv("GL_ERR_FILE") ? fopen(getenv("GL_ERR_FILE"), "wt") : NULL;
- if (err_file == NULL)
- err_file = stderr;
- }
- return err_file;
-}
-
-#include "opengl_func.h"
-
-#include "glgetv_cst.h"
-
-typedef struct
-{
- int size;
- int type;
- int stride;
- const void* ptr;
-
- int index;
- int normalized;
-
- int enabled;
- int vbo_name;
-
- unsigned int last_crc;
-} ClientArray;
-
-typedef struct {
- GLboolean swapEndian;
- GLboolean lsbFirst;
- GLuint rowLength;
- GLuint imageHeight;
- GLuint skipRows;
- GLuint skipPixels;
- GLuint skipImages;
- GLuint alignment;
-} PixelStoreMode;
-
-typedef struct
-{
- int format;
- int stride;
- const void* ptr;
-} InterleavedArrays;
-
-typedef struct {
- ClientArray vertexArray;
- ClientArray normalArray;
- ClientArray colorArray;
- ClientArray secondaryColorArray;
- ClientArray indexArray;
- ClientArray edgeFlagArray;
- ClientArray weightArray;
- ClientArray matrixIndexArray;
- ClientArray fogCoordArray;
- ClientArray texCoordArray[NB_MAX_TEXTURES];
- ClientArray vertexAttribArray[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
- ClientArray vertexAttribArrayNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
- ClientArray variantPointer[MY_GL_MAX_VARIANT_POINTER_EXT];
- ClientArray elementArrayATI;
- InterleavedArrays interleavedArrays;
-} ClientArrays;
-
-
-
-
-typedef struct
-{
- GLbitfield mask;
- PixelStoreMode pack;
- PixelStoreMode unpack;
- ClientArrays arrays;
- int clientActiveTexture;
- int selectBufferSize;
- void* selectBufferPtr;
- int feedbackBufferSize;
- void* feedbackBufferPtr;
-} ClientState;
-
-
-typedef struct
-{
- int texture;
- int level;
-
- int width;
- int height;
-} Texture2DDim;
-
-typedef struct
-{
- float mode;
- float density;
- float start;
- float end;
- float index;
- float color[4];
-} Fog;
-
-#define N_CLIP_PLANES 8
-typedef struct
-{
- GLbitfield mask;
- int matrixMode;
- int bindTexture2D; /* optimization for openquartz */
- int bindTextureRectangle;
- int linesmoothEnabled; /* optimization for googleearth */
- int lightingEnabled;
- int texture2DEnabled;
- int blendEnabled;
- int scissorTestEnabled;
- int vertexProgramEnabled;
- int fogEnabled;
- int depthFunc;
- Fog fog;
-
- Texture2DDim* texture2DCache;
- int texture2DCacheDim;
- Texture2DDim* textureProxy2DCache;
- int textureProxy2DCacheDim;
- Texture2DDim* textureRectangleCache;
- int textureRectangleCacheDim;
- Texture2DDim* textureProxyRectangleCache;
- int textureProxyRectangleCacheDim;
-
- double clipPlanes[N_CLIP_PLANES][4];
-} ServerState;
-
-typedef struct
-{
- int size;
- void* ptr;
- int mapped;
- int usage;
- int access;
-} Buffer;
-
-typedef struct
-{
- int start;
- int length;
-} IntRange;
-
-typedef struct
-{
- IntRange* ranges;
- int nb;
- int maxNb;
-} IntSetRanges;
-
-typedef struct
-{
- int bufferid;
- int size;
- void* ptr;
- void* ptrMapped;
- IntSetRanges updatedRangesAfterMapping;
- void* ptrUpdatedWhileMapped;
-} ObjectBufferATI;
-
-typedef struct
-{
- GLuint program;
- char* txt;
- int location;
-} UniformLocation;
-
-
-#include "opengl_utils.h"
-
-/**/
-#define MAX_MATRIX_STACK_SIZE 64
-#define NB_GL_MATRIX (3+NB_MAX_TEXTURES+31)
-typedef struct
-{
- double val[16];
-} Matrixd;
-
-typedef struct
-{
- Matrixd stack[MAX_MATRIX_STACK_SIZE];
- Matrixd current;
- int sp;
-} GLMatrix;
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
-} ViewportStruct;
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
- int map_state;
-} WindowPosStruct;
-
-
-typedef struct
-{
- int id;
- int datatype;
- int components;
-} Symbol;
-
-typedef struct
-{
- Symbol* tab;
- int count;
-} Symbols;
-
-#define MAX_CLIENT_STATE_STACK_SIZE 16
-#define MAX_SERVER_STATE_STACK_SIZE 16
-
-typedef struct
-{
- int ref;
-#ifndef WIN32
- Display* display;
- GLXContext context;
- GLXDrawable current_drawable;
- GLXDrawable current_read_drawable;
- struct timeval last_swap_buffer_time;
- GLXContext shareList;
- XFixesCursorImage last_cursor;
- GLXPbuffer pbuffer;
-#endif
- int isAssociatedToFBConfigVisual;
-
- ClientState client_state_stack[MAX_CLIENT_STATE_STACK_SIZE];
- ClientState client_state;
- int client_state_sp;
-
- ServerState server_stack[MAX_SERVER_STATE_STACK_SIZE];
- ServerState current_server_state;
- int server_sp;
-
- int arrayBuffer; /* optimization for ww2d */
- int elementArrayBuffer;
- int pixelUnpackBuffer;
- int pixelPackBuffer;
-
- Buffer arrayBuffers[32768];
- Buffer elementArrayBuffers[32768];
- Buffer pixelUnpackBuffers[32768];
- Buffer pixelPackBuffers[32768];
-
- RangeAllocator ownTextureAllocator;
- RangeAllocator* textureAllocator;
- RangeAllocator ownBufferAllocator;
- RangeAllocator* bufferAllocator;
- RangeAllocator ownListAllocator;
- RangeAllocator* listAllocator;
-
- Symbols symbols;
-
- ObjectBufferATI objectBuffersATI[32768];
-
- UniformLocation* uniformLocations;
- int countUniformLocations;
-
- WindowPosStruct oldPos;
- ViewportStruct viewport;
- ViewportStruct scissorbox;
- int drawable_width;
- int drawable_height;
-
- int currentRasterPosKnown;
- float currentRasterPos[4];
-
- char* tuxRacerBuffer;
-
- int activeTexture;
-
- int isBetweenBegin;
-
- int lastGlError;
-
- int isBetweenLockArrays;
- int locked_first;
- int locked_count;
-
- GLMatrix matrix[NB_GL_MATRIX];
-} GLState;
-
-static GLState* new_gl_state()
-{
- int i, j;
- GLState* state;
-
- state = malloc(sizeof(GLState));
- memset(state, 0, sizeof(GLState));
- state->activeTexture = GL_TEXTURE0_ARB;
- state->client_state.pack.alignment = 4;
- state->client_state.unpack.alignment = 4;
- state->current_server_state.matrixMode = GL_MODELVIEW;
- state->current_server_state.depthFunc = GL_LESS;
- state->current_server_state.fog.mode = GL_EXP;
- state->current_server_state.fog.density = 1;
- state->current_server_state.fog.start = 0;
- state->current_server_state.fog.end = 1;
- state->current_server_state.fog.index = 0;
- state->textureAllocator = &state->ownTextureAllocator;
- state->bufferAllocator = &state->ownBufferAllocator;
- state->listAllocator = &state->ownListAllocator;
- state->currentRasterPosKnown = 1;
- state->currentRasterPos[0] = 0;
- state->currentRasterPos[1] = 0;
- state->currentRasterPos[2] = 0;
- state->currentRasterPos[3] = 1;
- for(i=0;i<NB_GL_MATRIX;i++)
- {
- state->matrix[i].sp = 0;
- for(j=0;j<16;j++)
- {
- state->matrix[i].current.val[j] = (j == 0 || j == 5 || j == 10 || j == 15);
- }
- }
- return state;
-}
-
-/* The access to the following global variables shoud be done under the global lock */
-static GLState* default_gl_state = NULL;
-static int nbGLStates = 0;
-static GLState** glstates = NULL;
-
-#define IS_GLX_CALL(x) (x >= glXChooseVisual_func && x <= glXReleaseTexImageARB_func)
-
-#ifdef ENABLE_THREAD_SAFETY
-
-/* Posix threading */
-/* The concepts used here are coming directly from http://www.mesa3d.org/dispatch.html */
-
-#ifndef WIN32
-static pthread_mutex_t global_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_key_t key_current_gl_state;
-#define GET_CURRENT_THREAD() pthread_self()
-
-static pthread_t last_current_thread = 0;
-static GLState* _mono_threaded_current_gl_state = NULL;
-#ifdef TEST_IF_LOCK_USE_IS_CORRECT_INTO_MONO_THREADED_CASE
-static int lock_count = 0;
-#define LOCK(func_number) int __lock__ = 0; assert(lock_count == 0); lock_count++; pthread_mutex_lock( &global_mutex );
-#define UNLOCK(func_number) assert(lock_count + __lock__ == 1); lock_count--; pthread_mutex_unlock( &global_mutex );
-#define IS_MT() 2
-static int _is_mt = 2;
-#else
-static int _is_mt = 0;
-static inline int is_mt()
-{
- if (_is_mt) return 1;
- pthread_t current_thread = GET_CURRENT_THREAD();
- if (last_current_thread == 0)
- last_current_thread = current_thread;
- if (current_thread != last_current_thread)
- {
- _is_mt = 1;
- log_gl("-------- Two threads at least are doing OpenGL ---------\n");
- pthread_key_create(&key_current_gl_state, NULL);
- }
- return _is_mt;
-}
-#define IS_MT() is_mt()
-
-/* The idea here is that the first GL/GLX call made in each thread is necessary a GLX call */
-/* So in the case where it's a GLX call we always take the lock and check if we're in MT case */
-/* otherwise (regular GL call), we have to take the lock only in the MT case */
-#define LOCK(func_number) do { if (IS_GLX_CALL(func_number)) { pthread_mutex_lock( &global_mutex ); IS_MT(); } else if (_is_mt) { pthread_mutex_lock( &global_mutex ); } } while(0)
-#define UNLOCK(func_number) do { if (IS_GLX_CALL(func_number) || _is_mt) pthread_mutex_unlock( &global_mutex ); } while(0)
-#endif
-static void set_current_state(GLState* current_gl_state)
-{
- if (_is_mt)
- pthread_setspecific(key_current_gl_state, current_gl_state);
- else
- _mono_threaded_current_gl_state = current_gl_state;
-}
-static inline GLState* get_current_state()
-{
- GLState* current_gl_state;
- if (_is_mt == 1 &&
- last_current_thread == GET_CURRENT_THREAD())
- {
- _is_mt = 2;
- set_current_state(_mono_threaded_current_gl_state);
- _mono_threaded_current_gl_state = NULL;
- }
- current_gl_state = (_is_mt) ? pthread_getspecific(key_current_gl_state) : _mono_threaded_current_gl_state;
- if (current_gl_state == NULL)
- {
- if (default_gl_state == NULL)
- {
- default_gl_state = new_gl_state();
- }
- current_gl_state = default_gl_state;
- set_current_state(current_gl_state);
- }
- return current_gl_state;
-}
-#define SET_CURRENT_STATE(_x) set_current_state(_x)
-
-/* Win32 threading : TODO !*/
-
-#else
-#define LOCK(func_number)
-#define UNLOCK(func_number)
-#define GET_CURRENT_THREAD() 0
-#define IS_MT() 0
-static GLState* current_gl_state = NULL;
-static inline GLState* get_current_state()
-{
- if (current_gl_state == NULL)
- {
- if (default_gl_state == NULL)
- {
- default_gl_state = new_gl_state();
- }
- return default_gl_state;
- }
- return current_gl_state;
-}
-#define SET_CURRENT_STATE(_x) current_gl_state = _x
-#endif
-
-/* No support for threading */
-#else
-#define LOCK(func_number)
-#define UNLOCK(func_number)
-#define GET_CURRENT_THREAD() 0
-#define IS_MT() 0
-static GLState* current_gl_state = NULL;
-static inline GLState* get_current_state()
-{
- if (current_gl_state == NULL)
- {
- if (default_gl_state == NULL)
- {
- default_gl_state = new_gl_state();
- }
- return default_gl_state;
- }
- return current_gl_state;
-}
-#define SET_CURRENT_STATE(_x) current_gl_state = _x
-#endif
-
-
-#define GET_CURRENT_STATE() GLState* state = get_current_state()
-
-static void log_gl(const char* format, ...)
-{
-#if 0
- va_list list;
- va_start(list, format);
-#ifdef ENABLE_THREAD_SAFETY
- if (IS_MT())
- fprintf(get_err_file(), "[thread %p] : ", (void*)GET_CURRENT_THREAD());
-#endif
- vfprintf(get_err_file(), format, list);
- va_end(list);
-#endif
-}
-
-
-/**/
-
-#ifndef WIN32
-typedef struct
-{
- int attrib;
- int value;
- int ret;
-} _glXGetConfigAttribs;
-
-typedef struct
-{
- int val;
- char* name;
-} glXAttrib;
-
-#define VAL_AND_NAME(x) { x, #x }
-
-static const glXAttrib tabRequestedAttribsPair[] =
-{
- VAL_AND_NAME(GLX_USE_GL),
- VAL_AND_NAME(GLX_BUFFER_SIZE),
- VAL_AND_NAME(GLX_LEVEL),
- VAL_AND_NAME(GLX_RGBA),
- VAL_AND_NAME(GLX_DOUBLEBUFFER),
- VAL_AND_NAME(GLX_STEREO),
- VAL_AND_NAME(GLX_AUX_BUFFERS),
- VAL_AND_NAME(GLX_RED_SIZE),
- VAL_AND_NAME(GLX_GREEN_SIZE),
- VAL_AND_NAME(GLX_BLUE_SIZE),
- VAL_AND_NAME(GLX_ALPHA_SIZE),
- VAL_AND_NAME(GLX_DEPTH_SIZE),
- VAL_AND_NAME(GLX_STENCIL_SIZE),
- VAL_AND_NAME(GLX_ACCUM_RED_SIZE),
- VAL_AND_NAME(GLX_ACCUM_GREEN_SIZE),
- VAL_AND_NAME(GLX_ACCUM_BLUE_SIZE),
- VAL_AND_NAME(GLX_ACCUM_ALPHA_SIZE),
- VAL_AND_NAME(GLX_CONFIG_CAVEAT),
- VAL_AND_NAME(GLX_X_VISUAL_TYPE),
- VAL_AND_NAME(GLX_TRANSPARENT_TYPE),
- VAL_AND_NAME(GLX_TRANSPARENT_INDEX_VALUE),
- VAL_AND_NAME(GLX_TRANSPARENT_RED_VALUE),
- VAL_AND_NAME(GLX_TRANSPARENT_GREEN_VALUE),
- VAL_AND_NAME(GLX_TRANSPARENT_BLUE_VALUE),
- VAL_AND_NAME(GLX_TRANSPARENT_ALPHA_VALUE),
- VAL_AND_NAME(GLX_SLOW_CONFIG),
- VAL_AND_NAME(GLX_TRUE_COLOR),
- VAL_AND_NAME(GLX_DIRECT_COLOR),
- VAL_AND_NAME(GLX_PSEUDO_COLOR),
- VAL_AND_NAME(GLX_STATIC_COLOR),
- VAL_AND_NAME(GLX_GRAY_SCALE),
- VAL_AND_NAME(GLX_STATIC_GRAY),
- VAL_AND_NAME(GLX_TRANSPARENT_RGB),
- VAL_AND_NAME(GLX_TRANSPARENT_INDEX),
- VAL_AND_NAME(GLX_VISUAL_ID),
- VAL_AND_NAME(GLX_DRAWABLE_TYPE),
- VAL_AND_NAME(GLX_RENDER_TYPE),
- VAL_AND_NAME(GLX_X_RENDERABLE),
- VAL_AND_NAME(GLX_FBCONFIG_ID),
- VAL_AND_NAME(GLX_RGBA_TYPE),
- VAL_AND_NAME(GLX_COLOR_INDEX_TYPE),
- VAL_AND_NAME(GLX_MAX_PBUFFER_WIDTH),
- VAL_AND_NAME(GLX_MAX_PBUFFER_HEIGHT),
- VAL_AND_NAME(GLX_MAX_PBUFFER_PIXELS),
- VAL_AND_NAME(GLX_PRESERVED_CONTENTS),
- VAL_AND_NAME(GLX_FLOAT_COMPONENTS_NV),
- VAL_AND_NAME(GLX_SAMPLE_BUFFERS),
- VAL_AND_NAME(GLX_SAMPLES)
-};
-#define N_REQUESTED_ATTRIBS (sizeof(tabRequestedAttribsPair)/sizeof(tabRequestedAttribsPair[0]))
-
-static int* getTabRequestedAttribsInt()
-{
- static int tabRequestedAttribsInt[N_REQUESTED_ATTRIBS] = { 0 };
- if (tabRequestedAttribsInt[0] == 0)
- {
- int i;
- for(i=0;i<N_REQUESTED_ATTRIBS;i++)
- tabRequestedAttribsInt[i] = tabRequestedAttribsPair[i].val;
- }
- return tabRequestedAttribsInt;
-}
-
-#define N_MAX_ATTRIBS N_REQUESTED_ATTRIBS+10
-typedef struct
-{
- int visualid;
- _glXGetConfigAttribs attribs[N_MAX_ATTRIBS];
- int nbAttribs;
-} _glXConfigs;
-#define N_MAX_CONFIGS 80
-static _glXConfigs configs[N_MAX_CONFIGS];
-static int nbConfigs = 0;
-
-typedef struct
-{
- GLXFBConfig config;
- _glXGetConfigAttribs attribs[N_MAX_ATTRIBS];
- int nbAttribs;
-} _glXFBConfig;
-
-static _glXFBConfig fbconfigs[N_MAX_CONFIGS];
-static int nbFBConfigs = 0;
-
-#define __CLIENT_WINDOW__
-
-#ifdef __CLIENT_WINDOW__
-/* Window Image�� �̿��� Guest Window Draw */
-#include <X11/extensions/XShm.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-static void glReadPixels_no_lock ( GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels );
-
-#define MAX_IMAGES 100
-
-typedef struct {
- Window win;
- GC win_gc;
- int width;
- int height ;
- unsigned int bytes_per_pixel;
- unsigned int bytes_per_line;
- char *rData;
-
- char *imageData;
- XImage *xImage;
- XShmSegmentInfo *shminfo;
-} WindowImage;
-
-WindowImage wImage[MAX_IMAGES];
-
-static Bool _create_image(Display *dpy, Window win, WindowImage *image)
-{
- XWindowAttributes XWinAttribs;
- XShmSegmentInfo *shmseginfo;
-
- XGetWindowAttributes( dpy, win, &XWinAttribs );
- shmseginfo = (XShmSegmentInfo *)malloc(sizeof(XShmSegmentInfo));
- if(!shmseginfo)
- {
- return False;
- }
- image->xImage = XShmCreateImage(dpy, XWinAttribs.visual, XWinAttribs.depth, ZPixmap, NULL, shmseginfo, XWinAttribs.width, XWinAttribs.height);
- if( image->xImage == NULL )
- {
- free( shmseginfo );
- return False;
- }
-
- image->width = XWinAttribs.width;
- image->height = XWinAttribs.height;
- image->bytes_per_pixel = image->xImage->bits_per_pixel / 8;
- image->bytes_per_line = image->width * image->bytes_per_pixel;
-
-
- shmseginfo->shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777);
- if(shmseginfo->shmid < 0 )
- {
- printf("shmget Err --------- \n");
- XDestroyImage(image->xImage);
- free( shmseginfo );
- return False;
- }
-
- shmseginfo->shmaddr = shmat(shmseginfo->shmid, NULL, 0);
- if(!shmseginfo->shmaddr)
- {
- printf("shmat Err --------- \n");
- XDestroyImage(image->xImage);
- shmctl(shmseginfo->shmid, IPC_RMID, NULL);
- free( shmseginfo );
- return False;
-
- }
- shmseginfo->readOnly = False;
-
- image->imageData = (char *) shmseginfo->shmaddr;
- image->rData = malloc(XWinAttribs.width * XWinAttribs.height * image->bytes_per_pixel);
-
- if(image->rData == NULL || !XShmAttach(dpy, shmseginfo))
- {
- XShmDetach(dpy, shmseginfo);
- XDestroyImage(image->xImage);
- shmdt(shmseginfo->shmaddr);
- shmctl(shmseginfo->shmid, IPC_RMID, NULL);
- free( shmseginfo );
- return False;
- }
-
- image->xImage->data = image->imageData;
- image->win = win;
- image->shminfo = shmseginfo;
-
- return True;
-}
-
-static void _destroy_image(Display *dpy, WindowImage *image)
-{
- XShmDetach(dpy, image->shminfo);
- XDestroyImage(image->xImage);
- image->imageData = NULL;
- image->win = 0;
-
- shmdt(image->shminfo->shmaddr);
- shmctl(image->shminfo->shmid, IPC_RMID, NULL);
- free( image->shminfo );
- image->shminfo = NULL;
-
- free(image->rData);
- image->rData = NULL;
-}
-
-static void _draw_image(Display *dpy, Window win, WindowImage *image)
-{
- int r, s;
- XWindowAttributes XWinAttribs;
-
- XGetWindowAttributes( dpy, win, &XWinAttribs );
- if( image->width != XWinAttribs.width || image->height != XWinAttribs.height )
- {
- _destroy_image( dpy, image);
- if( _create_image(dpy, win, image) == False )
- {
- XFreeGC(dpy, image->win_gc);
- image->win_gc = NULL;
- return;
- }
- }
- LOCK(glReadPixels_func);
- glReadPixels_no_lock(0, 0, image->width, image->height, GL_BGRA, GL_UNSIGNED_BYTE, image->rData);
- UNLOCK(glReadPixels_func);
-
- for(s = 0, r = image->height - 1; s < image->height; s++, r--)
- {
- memcpy(&image->imageData[image->bytes_per_line * s], &image->rData[image->bytes_per_line * r], image->bytes_per_line);
- }
-
- XShmPutImage(dpy, image->win, image->win_gc, image->xImage, 0, 0, 0, 0, image->width, image->height, False);
- XFlush(dpy);
-
- return;
-}
-#endif /*__CLIENT_WINDOW__*/
-#endif
-
-
-static int pagesize = 0;
-
-static int debug_gl = 0;
-static int debug_array_ptr = 0;
-static int disable_optim = 0;
-static int limit_fps = 0;
-
-#ifndef WIN32
-static struct sigaction old_action;
-
-static void sigsegv_handler(int signum, siginfo_t* info, void* ptr)
-{
- struct ucontext* context = (struct ucontext*)ptr;
-#if defined(__i386__)
- unsigned char* eip_ptr = (unsigned char*)context->uc_mcontext.gregs[REG_EIP];
-#elif defined(__x86_64__)
- unsigned char* eip_ptr = (unsigned char*)context->uc_mcontext.gregs[REG_RIP];
-#else
-#error "unsupported architecture"
-#endif
- if (eip_ptr[0] == 0xCD && eip_ptr[1] == 0x99)
- {
-#if defined(__i386__)
- context->uc_mcontext.gregs[REG_EIP] += 2;
-#elif defined(__x86_64__)
- context->uc_mcontext.gregs[REG_RIP] += 2;
-#else
-#error "unsupported architecture"
-#endif
- }
- else
- {
- log_gl("unhandled SIGSEGV\n");
- exit(-1); // FIXME
- if (old_action.sa_flags & SA_SIGINFO)
- {
- old_action.sa_sigaction(signum, info, ptr);
- }
- else
- {
- old_action.sa_handler(signum);
- }
- }
-}
-#endif
-
-#ifdef TCP_COMMUNICATION_SUPPORT
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#ifndef WIN32
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-static int sock;
-#else
-#include <windows.h>
-#include <winbase.h>
-#include <winuser.h>
-#include <ws2tcpip.h>
-SOCKET sock;
-#endif
-
-
-static void init_sockaddr (struct sockaddr_in *name,
- const char *hostname,
- uint16_t port)
-{
- struct hostent *hostinfo;
- name->sin_family = AF_INET;
- name->sin_port = htons (port);
- name->sin_addr.s_addr = inet_addr(hostname);
- if (name->sin_addr.s_addr != INADDR_NONE)
- return;
- hostinfo = gethostbyname (hostname);
- if (hostinfo == NULL)
- {
- log_gl("Unknown host %s.\n", hostname);
-#ifdef WIN32
- char msg[512];
- sprintf(msg, "Unknown host %s", hostname);
- MessageBox(NULL, msg, "Unknown host", 0);
-#endif
- exit (EXIT_FAILURE);
- }
- name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
-}
-
-static int total_written = 0;
-static void write_sock_data(void* data, int len)
-{
- if (len && data)
- {
- int offset = 0;
- //if (debug_gl) log_gl("to write : %d\n", len);
- while(offset < len)
- {
-#ifndef WIN32
- int nwritten = write(sock, data + offset, len - offset);
- if (nwritten == -1)
-#else
- int nwritten = send(sock, data + offset, len - offset, 0);
- if (nwritten == SOCKET_ERROR)
-#endif
- {
- if (errno == EINTR)
- continue;
- perror("write");
- assert(nwritten != -1);
- }
- offset += nwritten;
- total_written += nwritten;
- /*if (debug_gl)
- log_gl("total written : %d\n", total_written);
- if (debug_gl && offset < len) log_gl("remaining to write : %d\n", len - offset);*/
- }
- }
-}
-
-static void inline write_sock_int(int my_int)
-{
- write_sock_data(&my_int, sizeof(int));
-}
-
-static void inline write_sock_short(short my_int)
-{
- write_sock_data(&my_int, sizeof(short));
-}
-
-static void read_sock_data(void* data, int len)
-{
- if (len && data)
- {
- int offset = 0;
- while(offset < len)
- {
-#ifndef WIN32
- int nread = read(sock, data + offset, len - offset);
- if (nread == -1)
-#else
- int nread = recv(sock, data + offset, len - offset, 0);
- if (nread == SOCKET_ERROR)
-#endif
- {
- if (errno == EINTR)
- continue;
- perror("read");
- assert(nread != -1);
- }
- offset += nread;
- }
- }
-}
-
-static int inline read_sock_int()
-{
- int ret;
- read_sock_data(&ret, sizeof(int));
- return ret;
-}
-
-static int call_opengl_tcp(int func_number, int pid, void* ret_string, void* _args, void* _args_size)
-{
- int ret;
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int nb_args = signature->nb_args;
- int i;
- long* args = (long*)_args;
- int* args_size = (int*)_args_size;
- int* args_type = signature->args_type;
-
-
- write_sock_short(func_number);
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- {
- write_sock_int(args[i]);
- break;
- }
-
- case TYPE_ARRAY_DOUBLE:
- case TYPE_ARRAY_CHAR:
- case TYPE_ARRAY_INT:
- case TYPE_ARRAY_FLOAT:
- case TYPE_NULL_TERMINATED_STRING:
- {
- write_sock_int(args_size[i]);
- write_sock_data((void*)args[i], args_size[i]);
- break;
- }
-
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- int size = compute_arg_length(get_err_file(), func_number, i, args);
- if (size < 0)
- log_gl("TYPE_ARRAY_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS : length = %d\n", size);
- else
- write_sock_data((void*)args[i], size);
- break;
- }
-
- case TYPE_DOUBLE:
-CASE_IN_KNOWN_SIZE_POINTERS:
- {
- write_sock_data((void*)args[i], args_size[i]);
- break;
- }
-
- case TYPE_IN_IGNORED_POINTER:
- {
- break;
- }
-
-CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
-CASE_OUT_KNOWN_SIZE_POINTERS:
- {
- break;
- }
-
-CASE_OUT_UNKNOWN_SIZE_POINTERS:
- {
- write_sock_int((args[i]) ? args_size[i] : 0);
- break;
- }
-
- default:
- {
- log_gl("(0) unexpected arg type %d at i=%d\n", args_type[i], i);
- exit(-1);
- break;
- }
- }
- }
-
- if (signature->has_out_parameters)
- {
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
-CASE_OUT_POINTERS:
- {
- read_sock_data((void*)args[i], args_size[i]);
- break;
- }
-
- default:
- {
- break;
- }
- }
- }
- }
-
- if (signature->ret_type == TYPE_CONST_CHAR)
- {
- int len = read_sock_int();
- read_sock_data(ret_string, len);
- ret = 0;
- }
- else if (signature->ret_type != TYPE_NONE)
- {
- ret = read_sock_int();
- }
- else
- {
- ret = 0;
- }
-
- return ret;
-}
-#endif
-
-#ifdef WIN32
-static EXCEPTION_DISPOSITION win32_sigsegv_handler(struct _EXCEPTION_RECORD *exception_record,
- void * EstablisherFrame,
- struct _CONTEXT *ContextRecord,
- void * DispatcherContext)
-{
- /* If the exception is an access violation */
- if (exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION &&
- exception_record->NumberParameters >= 2)
- {
- //int accessMode = (int)exception_record->ExceptionInformation[0];
- //void* adr = (void *)exception_record->ExceptionInformation[1];
-
- unsigned char* eip_ptr = (unsigned char*)ContextRecord->Eip;
- if (eip_ptr[0] == 0xCD && eip_ptr[1] == 0x99)
- {
- ContextRecord->Eip += 2;
- return ExceptionContinueExecution;
- }
- else
- {
- log_gl("not handled exception : %X\n", (int)exception_record->ExceptionCode);
- fflush(get_err_file());
- return ExceptionContinueSearch;
- }
- }
- else
- {
- log_gl("not handled exception : %X\n", (int)exception_record->ExceptionCode);
- fflush(get_err_file());
- return ExceptionContinueSearch;
- }
-}
-#endif
-
-static int call_opengl_chardev(int func_number, int pid, void* ret_string, void *args, void* args_size)
-{
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- log_gl("func_number >= 0 && func_number < GL_N_CALLS failed\n");
- return 0;
- }
-
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int nb_args = signature->nb_args;
-
- int ret;
- struct accel {
- int func_number;
- int pid;
- void *ret_string;
- void *args;
- void *args_size;
- };
- struct accel accelMode;
-
- accelMode.func_number = func_number;
- accelMode.pid = pid;
- accelMode.ret_string = ret_string;
- accelMode.args = args;
- accelMode.args_size = args_size;
-
- write(fd, &accelMode, nb_args);
-
- ret = read(fd, NULL, 1);
-
- return ret;
-}
-
-static int call_opengl_qemu(int func_number, int pid, void* ret_string, void* args, void* args_size)
-{
-#if defined(__i386__)
- int ret;
-#ifdef WIN32
- __asm__ ("pushl %0;pushl %%fs:0;movl %%esp,%%fs:0;" : : "g" (win32_sigsegv_handler));
-#endif
- __asm__ ("push %ebx");
- __asm__ ("push %ecx");
- __asm__ ("push %edx");
- __asm__ ("push %esi");
- __asm__ ("mov %0, %%eax"::"m"(func_number));
- __asm__ ("mov %0, %%ebx"::"m"(pid));
- __asm__ ("mov %0, %%ecx"::"m"(ret_string));
- __asm__ ("mov %0, %%edx"::"m"(args));
- __asm__ ("mov %0, %%esi"::"m"(args_size));
- __asm__ ("int $0x99");
- __asm__ ("pop %esi");
- __asm__ ("pop %edx");
- __asm__ ("pop %ecx");
- __asm__ ("pop %ebx");
- __asm__ ("mov %%eax, %0"::"m"(ret));
-#ifdef WIN32
- __asm__ ("movl (%%esp),%%ecx;movl %%ecx,%%fs:0;addl $8,%%esp;" : : : "%ecx");
-#endif
- return ret;
-#elif defined(__x86_64__)
- int ret;
- __asm__ ("push %rbx");
- __asm__ ("push %rcx");
- __asm__ ("push %rdx");
- __asm__ ("push %rsi");
- __asm__ ("mov %0, %%eax"::"m"(func_number));
- __asm__ ("mov %0, %%ebx"::"m"(pid));
- __asm__ ("mov %0, %%rcx"::"m"(ret_string));
- __asm__ ("mov %0, %%rdx"::"m"(args));
- __asm__ ("mov %0, %%rsi"::"m"(args_size));
- __asm__ ("int $0x99");
- __asm__ ("pop %rsi");
- __asm__ ("pop %rdx");
- __asm__ ("pop %rcx");
- __asm__ ("pop %rbx");
- __asm__ ("mov %%eax, %0"::"m"(ret));
- return ret;
-#else
- fprintf(stderr, "unsupported architecture!\n");
- return 0;
-#endif
-}
-
-
-#ifdef TCP_COMMUNICATION_SUPPORT
-static int use_tcp_communication = 0;
-static int call_opengl(int func_number, int pid, void* ret_string, void* args, void* args_size)
-{
- if (!use_tcp_communication)
- return call_opengl_chardev(func_number, pid, ret_string, args, args_size);
- else
- return call_opengl_tcp(func_number, pid, ret_string, args, args_size);
-}
-#else
-static int call_opengl(int func_number, int pid, void* ret_string, void* args, void* args_size)
-{
- return call_opengl_qemu(func_number, pid, ret_string, args, args_size);
-}
-#endif
-
-
-static void do_init()
-{
-#ifdef TCP_COMMUNICATION_SUPPORT
- if (use_tcp_communication)
- {
- struct sockaddr_in servername;
-#ifdef WIN32
- WORD wVersionRequested;
- WSADATA WSAData; /* Structure WSADATA d�finie dans winsock.h */
- int err;
-
- wVersionRequested = MAKEWORD(2, 0); /* 1.1 Version voulut de Winsock */
- err = WSAStartup(wVersionRequested, &WSAData); /* Appel de notre fonction */
- if (err != 0)
- {
- MessageBox(NULL, "WSAStartup failed", "WSAStartup failed", 0);
- exit(EXIT_FAILURE);
- }
-#endif
- /* Create the socket. */
- sock = socket (AF_INET, SOCK_STREAM,
-#ifndef WIN32
- IPPROTO_TCP
-#else
- 0
-#endif
- );
- if (sock < 0)
- {
-#ifdef WIN32
- MessageBox(NULL, "socket (client)", "socket (client)", 0);
-#endif
- perror ("socket (client)");
- exit (EXIT_FAILURE);
- }
-
- /* Connect to the server. */
- int port;
- if (getenv("GL_SERVER_PORT"))
- port = atoi(getenv("GL_SERVER_PORT"));
-
- /* Get fixed host IP address and connect to server */
-#ifdef USE_TCP_METHOD
- //char fixed_host_ip[] = "10.0.2.2"; /* HOST_QEMU_ADDRESS */
- //init_sockaddr (&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : &fixed_host_ip[0], port);
-
- FILE *fp;
- char port_buffer[32] = {0};
- char ip_buffer[32] = "10.0.2.2";
-
- /*
- fp = fopen("/opt/home/opengl_ip.txt", "rt");
- if( fp== NULL ) {
- fprintf(stderr, "/opt/home/opengl_ip.txt file open error\n");
- exit(EXIT_FAILURE);
- }
- fgets(ip_buffer, 32, fp);
- fclose(fp);
- */
-
- fp = fopen("/opt/home/sdb_port.txt", "rt");
- if( fp== NULL ) {
- fprintf(stderr, "/opt/home/sdb_port.txt file open error\n");
- exit(EXIT_FAILURE);
- }
- fgets(port_buffer, 32, fp);
- fclose(fp);
-
- port = atoi(port_buffer) + 4;
- init_sockaddr(&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : ip_buffer, port);;
-
-#else
- init_sockaddr (&servername, getenv("GL_SERVER") ? getenv("GL_SERVER") : "localhost", port);
-#endif
-
- int flag = 1;
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,(char *)&flag, sizeof(int)) != 0)
- {
-#ifdef WIN32
- MessageBox(NULL, "setsockopt TCP_NODELAY", "setsockopt TCP_NODELAY", 0);
-#endif
- perror("setsockopt TCP_NODELAY");
- }
- if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,(char *)&flag, sizeof(int)) != 0)
- {
-#ifdef WIN32
- MessageBox(NULL, "setsockopt SO_KEEPALIVE", "setsockopt SO_KEEPALIVE", 0);
-#endif
- perror("setsockopt SO_KEEPALIVE");
- }
-
- if (0 > connect (sock,
- (struct sockaddr *) &servername,
- sizeof (servername)))
- {
-#ifdef WIN32
- MessageBox(NULL, "impossible to connect to server", "impossible to connect to server", 0);
-#endif
- perror ("impossible to connect to server");
- exit (EXIT_FAILURE);
- }
-
- setenv("ENABLE_GL_BUFFERING", "1", 1);
- setenv("NO_MOVE", "1", 1);
- }
- else
-#endif
- {
-#ifndef WIN32
- struct sigaction action;
- action.sa_sigaction = sigsegv_handler;
- sigemptyset(&(action.sa_mask));
- action.sa_flags = SA_SIGINFO;
- sigaction(SIGSEGV, &action, &old_action);
-
- int parent_pid = getpid();
- int pid_fork = fork();
- if (pid_fork == 0)
- {
- /* Sorry. This is really ugly, not portable, etc...
- This is the quickest way I've found
- to make sure that someone notices that the main program has stopped
- running and can warn the server */
- if (fork() != 0) exit(0);
- setsid();
- if (fork() != 0) exit(0);
- fcloseall();
- chdir("/");
-
- char processname[512];
- sprintf(processname, "/proc/%d", parent_pid);
- while(1)
- {
- struct stat buf;
- if (lstat(processname, &buf) < 0)
- {
- call_opengl(_exit_process_func, parent_pid, NULL, NULL, NULL);
- close(fd);
- exit(0);
- }
- sleep(1);
- }
- }
- else if (pid_fork > 0)
- {
- log_gl("go on...\n");
- }
- else
- {
- log_gl("fork failed\n");
- exit(-1);
- }
-#endif
- }
- /*
-#ifndef _WIN32
- if((fd = open(DEV_NAME, O_RDWR|O_NDELAY)) < 0)
-#else
- if((fd = open(DEV_NAME, O_RDWR)) < 0 )
-#endif
- {
- fprintf(stderr, "Device Open Error\n");
- return -1;
- }
- */
-}
-
-static int try_to_put_into_phys_memory(void* addr, int len)
-{
- if (addr == NULL || len == 0) return 0;
- int i;
- void* aligned_addr = (void*)((long)addr & (~(pagesize - 1)));
- int to_end_page = (long)aligned_addr + pagesize - (long)addr;
- char c = 0;
- if (aligned_addr != addr)
- {
- c += ((char*)addr)[0];
- if (len <= to_end_page)
- {
- return c;
- }
- len -= to_end_page;
- addr = aligned_addr + pagesize;
- }
- for(i=0;i<len;i+=pagesize)
- {
- c += ((char*)addr)[0];
- addr += pagesize;
- }
- return c;
-}
-
-#define RET_STRING_SIZE 32768
-#define SIZE_BUFFER_COMMAND 65536*16
-
-#define POINTER_TO_ARG(x) (long)(void*)(x)
-#define CHAR_TO_ARG(x) (long)(x)
-#define SHORT_TO_ARG(x) (long)(x)
-#define INT_TO_ARG(x) (long)(x)
-#define UNSIGNED_CHAR_TO_ARG(x) (long)(x)
-#define UNSIGNED_SHORT_TO_ARG(x) (long)(x)
-#define UNSIGNED_INT_TO_ARG(x) (long)(x)
-#define FLOAT_TO_ARG(x) (long)*((int*)(void*)(&x))
-#define DOUBLE_TO_ARG(x) (long)(&x)
-
-#ifdef WIN32
-static int getpagesize()
-{
- return 4096;
-}
-
-static void mlock(void* ptr, int size)
-{
-}
-
-static void posix_memalign(void** pptr, int alignment, int size)
-{
- *pptr = malloc(size);
-}
-
-#endif
-
-static int disable_warning_for_gl_read_pixels = 0;
-
-#ifndef WIN32
-static Bool glXMakeCurrent_no_lock( Display *dpy, GLXDrawable drawable, GLXContext ctx);
-static void glXSwapBuffers_no_lock( Display *dpy, GLXDrawable drawable );
-#endif
-
-static void glGetIntegerv_no_lock( GLenum pname, GLint *params );
-static void glPixelStorei_no_lock( GLenum pname, GLint param );
-static void glBindBufferARB_no_lock (GLenum target, GLuint buffer);
-#ifndef __CLIENT_WINDOW__
-static void glReadPixels_no_lock ( GLint x, GLint y,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLvoid *pixels );
-#endif
-
-#ifdef WIN32
-typedef void* __GLXextFuncPtr;
-#endif
-
-static __GLXextFuncPtr glXGetProcAddress_no_lock(const GLubyte * name);
-
-#define CHECK_PROC(x)
-#define CHECK_PROC_WITH_RET(x)
-
-/* Must only be called if the global lock has already been taken ! */
-static void do_opengl_call_no_lock(int func_number, void* ret_ptr, long* args, int* args_size_opt)
-{
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- log_gl("func_number >= 0 && func_number < GL_N_CALLS failed\n");
- goto end_do_opengl_call;
- }
-
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int nb_args = signature->nb_args;
- int* args_type = signature->args_type;
- int args_size[100] = {0,};
- int ret_int = 0;
- int i;
-
- static char* command_buffer = NULL;
- static int command_buffer_size = 0;
- static int last_command_buffer_size = -1;
- static char* ret_string = NULL;
- static int enable_gl_buffering = 0;
- static int last_current_thread = -1;
- static int exists_on_server_side[GL_N_CALLS];
-
- int current_thread = GET_CURRENT_THREAD();
-
- if (ret_string == NULL)
- {
- /* Sanity checks */
- assert(tab_args_type_length[TYPE_OUT_128UCHAR] == 128 * sizeof(char));
- assert(tab_args_type_length[TYPE_OUT_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS] == sizeof(double));
-
- assert(sizeof(tab_args_type_length)/sizeof(tab_args_type_length[0]) == TYPE_LAST);
-
- memset(exists_on_server_side, 255, sizeof(exists_on_server_side));
- exists_on_server_side[glXGetProcAddress_fake_func] = 1;
- exists_on_server_side[glXGetProcAddress_global_fake_func] = 1;
-
- FILE* f = fopen("/tmp/.opengl_client", "rb");
- if (!f)
- f = fopen("opengl_client.txt", "rb");
- if (f)
- {
- char buffer[80];
- while (fgets(buffer, 80, f))
- {
- for(i=0;i<sizeof(interestingEnvVars)/sizeof(interestingEnvVars[0]);i++)
- {
- char tmp[256];
- strcpy(tmp, interestingEnvVars[i]);
- strcat(tmp, "=");
- if (strncmp(buffer, tmp, strlen(tmp)) == 0)
- {
- char* c= strdup(buffer+strlen(tmp));
- char* c2 = strchr(c, '\n');
- if (c2) *c2 = 0;
- setenv(interestingEnvVars[i], c,1);
- break;
- }
- }
- }
- fclose(f);
- }
-
- last_current_thread = current_thread;
-
-#ifdef TCP_COMMUNICATION_SUPPORT
-#ifdef USE_TCP_METHOD
- use_tcp_communication = getenv("USE_TCP_COMMUNICATION") ? getenv("USE_TCP_COMMUNICATION") : 1;
-#else
- use_tcp_communication = getenv("USE_TCP_COMMUNICATION") != NULL;
-#endif
-#endif
- do_init();
-
- pagesize = getpagesize();
- debug_gl = getenv("DEBUG_GL") != NULL;
- debug_array_ptr = getenv("DEBUG_ARRAY_PTR") != NULL;
- disable_optim = getenv("DISABLE_OPTIM") != NULL;
- limit_fps = getenv("LIMIT_FPS") ? atoi(getenv("LIMIT_FPS")) : 0;
-
- posix_memalign((void**)(void*)&ret_string, pagesize, RET_STRING_SIZE);
- memset(ret_string, 0, RET_STRING_SIZE);
- mlock(ret_string, RET_STRING_SIZE);
-
- posix_memalign((void**)(void*)&command_buffer, pagesize, SIZE_BUFFER_COMMAND);
- mlock(command_buffer, SIZE_BUFFER_COMMAND);
-
- int init_ret = 0;
- long temp_args[] = { getenv("WRITE_GL") != NULL, POINTER_TO_ARG(&init_ret) };
- int temps_args_size[] = { 0, sizeof(int) };
- call_opengl(_init_func, getpid(), NULL, temp_args, temps_args_size);
- if (init_ret == 0)
- {
- log_gl("You maybe forgot to launch QEMU with -enable-gl argument.\n");
-#ifdef TCP_COMMUNICATION_SUPPORT
- if (getenv("USE_TCP_COMMUNICATION") != NULL)
- {
- log_gl("Trying TCP/IP communication instead\n");
- use_tcp_communication = 1;
- do_init();
- call_opengl(_init_func, getpid(), NULL, temp_args, temps_args_size);
- if (init_ret == 0)
- {
- log_gl("exiting !\n");
- exit(-1);
- }
- }
- else
-#endif
- {
- log_gl("exiting !\n");
- exit(-1);
- }
- }
- enable_gl_buffering = (init_ret == 2) || (getenv("ENABLE_GL_BUFFERING") != NULL);
- }
- if (exists_on_server_side[func_number] == -1)
- {
- if (strchr(tab_opengl_calls_name[func_number], '_'))
- {
- exists_on_server_side[func_number] = 1;
- }
- else
- {
- exists_on_server_side[func_number] = glXGetProcAddress_no_lock(tab_opengl_calls_name[func_number]) != NULL;
- }
- if (exists_on_server_side[func_number] == 0)
- {
- log_gl("Symbol %s not available in server libGL. Shouldn't have reach that point...\n",
- tab_opengl_calls_name[func_number]);
- goto end_do_opengl_call;
- }
- }
- else if (exists_on_server_side[func_number] == 0)
- {
- goto end_do_opengl_call;
- }
-
- GET_CURRENT_STATE();
-
-#ifdef ENABLE_THREAD_SAFETY
- if (last_current_thread != current_thread)
- {
- last_current_thread = current_thread;
- if (debug_gl) log_gl("gl thread switch\n");
-#ifndef WIN32
- glXMakeCurrent_no_lock(state->display, state->current_drawable, state->context);
-#else
- // FIXME
-#endif
- }
-#endif
-
-#ifndef WIN32
- if (func_number == glFlush_func && getenv("HACK_XGL"))
- {
- glXSwapBuffers_no_lock(state->display, state->current_drawable);
- goto end_do_opengl_call;
- }
- else if ((func_number == glDrawBuffer_func || func_number == glReadBuffer_func) && getenv("HACK_XGL"))
- {
- goto end_do_opengl_call;
- }
-#endif
-
- if ((func_number >= glRasterPos2d_func && func_number <= glRasterPos4sv_func) ||
- (func_number >= glWindowPos2d_func && func_number <= glWindowPos3sv_func) ||
- (func_number >= glWindowPos2dARB_func && func_number <= glWindowPos3svARB_func) ||
- (func_number >= glWindowPos2dMESA_func && func_number <= glWindowPos4svMESA_func))
-
- {
- state->currentRasterPosKnown = 0;
- }
-
- int this_func_parameter_size = sizeof(short); /* func_number */
-
- /* Compress consecutive glEnableClientState calls */
- if (!disable_optim &&
- last_command_buffer_size != -1 &&
- func_number == glClientActiveTexture_func &&
- *(short*)(command_buffer + last_command_buffer_size) == glClientActiveTexture_func)
- {
- *(int*)(command_buffer + last_command_buffer_size + sizeof(short)) = args[0];
- goto end_do_opengl_call;
- }
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- {
- /*
- args_size[i] = args_size_opt[i];
- if(args_size[i] < 0)
- {
- log_gl("size < 0 : func=%s, param=%d\n", tab_opengl_calls_name[func_number], i);
- goto end_do_opengl_call;
- }
- */
- this_func_parameter_size += sizeof(int);
- break;
- }
-
-CASE_IN_UNKNOWN_SIZE_POINTERS:
- {
- args_size[i] = args_size_opt[i];
- if (args_size[i] < 0)
- {
- log_gl("size < 0 : func=%s, param=%d\n", tab_opengl_calls_name[func_number], i);
- goto end_do_opengl_call;
- }
- try_to_put_into_phys_memory((void*)args[i], args_size[i]);
- this_func_parameter_size += sizeof(int) + args_size[i];
- break;
- }
-
- case TYPE_NULL_TERMINATED_STRING:
- {
- args_size[i] = strlen((const char*)args[i]) + 1;
- this_func_parameter_size += sizeof(int) + args_size[i];
- break;
- }
-
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
-CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(get_err_file(), func_number, i, args);
- this_func_parameter_size += args_size[i];
- break;
- }
-
- case TYPE_IN_IGNORED_POINTER:
- {
- args_size[i] = 0;
- break;
- }
-
-CASE_OUT_UNKNOWN_SIZE_POINTERS:
- {
- args_size[i] = args_size_opt[i];
- if (args_size[i] < 0)
- {
- log_gl("size < 0 : func=%s, param=%d\n", tab_opengl_calls_name[func_number], i);
- goto end_do_opengl_call;
- }
- try_to_put_into_phys_memory((void*)args[i], args_size[i]);
- break;
- }
-
- case TYPE_DOUBLE:
-CASE_KNOWN_SIZE_POINTERS:
- {
- args_size[i] = tab_args_type_length[args_type[i]];
- try_to_put_into_phys_memory((void*)args[i], args_size[i]);
- this_func_parameter_size += args_size[i];
- break;
- }
-
- default:
- {
- log_gl("(1) unexpected arg type %d at i=%d\n", args_type[i], i);
- exit(-1);
- break;
- }
- }
- }
-
- if (debug_gl) display_gl_call(get_err_file(), func_number, args, args_size);
-
- if (enable_gl_buffering && signature->ret_type == TYPE_NONE && signature->has_out_parameters == 0 &&
- func_number != _exit_process_func && !(func_number == glXSwapBuffers_func || func_number == glXDestroyWindow_func || func_number == glFlush_func || func_number == glFinish_func))
- {
- assert(ret_ptr == NULL);
- if (this_func_parameter_size + command_buffer_size >= SIZE_BUFFER_COMMAND)
- {
- if (debug_gl)
- log_gl("flush pending opengl calls...\n");
- try_to_put_into_phys_memory(command_buffer, command_buffer_size);
- call_opengl(_serialized_calls_func, getpid(), NULL, &command_buffer, &command_buffer_size);
- command_buffer_size = 0;
- last_command_buffer_size = -1;
- }
-
- if (this_func_parameter_size + command_buffer_size < SIZE_BUFFER_COMMAND)
- {
- /*if (debug_gl)
- log_gl("serializable opengl call.\n");*/
- last_command_buffer_size = command_buffer_size;
- *(short*)(command_buffer + command_buffer_size) = func_number;
- command_buffer_size += sizeof(short);
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- {
- *(int*)(command_buffer + command_buffer_size) = args[i];
- command_buffer_size += sizeof(int);
- break;
- }
-
-CASE_IN_UNKNOWN_SIZE_POINTERS:
- case TYPE_NULL_TERMINATED_STRING:
- {
- *(int*)(command_buffer + command_buffer_size) = args_size[i];
- command_buffer_size += sizeof(int);
-
- if (args_size[i])
- {
- memcpy(command_buffer + command_buffer_size, (void*)args[i], args_size[i]);
- command_buffer_size += args_size[i];
- }
- break;
- }
-
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- memcpy(command_buffer + command_buffer_size, (void*)args[i], args_size[i]);
- command_buffer_size += args_size[i];
- break;
- }
-
- case TYPE_IN_IGNORED_POINTER:
- {
- break;
- }
-
- case TYPE_DOUBLE:
-CASE_IN_KNOWN_SIZE_POINTERS:
- {
- memcpy(command_buffer + command_buffer_size, (void*)args[i], args_size[i]);
- command_buffer_size += args_size[i];
- break;
- }
-
- default:
- {
- log_gl("(2) unexpected arg type %d at i=%d\n", args_type[i], i);
- exit(-1);
- break;
- }
- }
- }
-
- try_to_put_into_phys_memory(command_buffer, command_buffer_size);
- call_opengl(_serialized_calls_func, getpid(), NULL, &command_buffer, &command_buffer_size);
- command_buffer_size = 0;
- last_command_buffer_size = -1;
- }
- else
- {
- if (debug_gl)
- log_gl("too large opengl call.\n");
- call_opengl(func_number, getpid(), NULL, args, args_size);
- }
- }
- else
- {
- if (command_buffer_size)
- {
- if (debug_gl)
- log_gl("flush pending opengl calls...\n");
- try_to_put_into_phys_memory(command_buffer, command_buffer_size);
- call_opengl(_serialized_calls_func, getpid(), NULL, &command_buffer, &command_buffer_size);
- command_buffer_size = 0;
- last_command_buffer_size = -1;
- }
-
- //if (!(func_number == glXSwapBuffers_func || func_number == glFlush_func || func_number == glFinish_func || (func_number == glReadPixels_func && disable_warning_for_gl_read_pixels)) && enable_gl_buffering)
- // log_gl("synchronous opengl call : %s.\n", tab_opengl_calls_name[func_number]);
-
- if (signature->ret_type == TYPE_CONST_CHAR)
- {
- try_to_put_into_phys_memory(ret_string, RET_STRING_SIZE);
- }
-
-#ifndef WIN32
- if (getenv("GET_IMG_FROM_SERVER") != NULL && func_number == glXSwapBuffers_func)
- {
- }
- else
-#endif
- ret_int = call_opengl(func_number, getpid(), (signature->ret_type == TYPE_CONST_CHAR) ? ret_string : NULL, args, args_size);
- if (func_number == glXCreateContext_func)
- {
- if (debug_gl)
- log_gl("ret_int = %d\n", ret_int);
- }
- else if (func_number == glXSwapBuffers_func || func_number == glXDestroyWindow_func || func_number == glFinish_func || func_number == glFlush_func)
- {
-#ifndef WIN32
- if (getenv("GET_IMG_FROM_SERVER"))
- {
- XWindowAttributes window_attributes_return;
- XGetWindowAttributes(state->display, state->current_drawable, &window_attributes_return);
- state->drawable_width = window_attributes_return.width;
- state->drawable_height = window_attributes_return.height;
-
- char* buf = malloc(4 * state->drawable_width * state->drawable_height);
- char* bufGL = malloc(4 * state->drawable_width * state->drawable_height);
- XImage* img = XCreateImage(state->display, 0, 24, ZPixmap, 0, buf, state->drawable_width, state->drawable_height, 8, 0);
- disable_warning_for_gl_read_pixels = 1;
-
- int pack_row_length, pack_alignment, pack_skip_rows, pack_skip_pixels;
- int pack_pbo = state->pixelPackBuffer;
- glGetIntegerv_no_lock(GL_PACK_ROW_LENGTH, &pack_row_length);
- glGetIntegerv_no_lock(GL_PACK_ALIGNMENT, &pack_alignment);
- glGetIntegerv_no_lock(GL_PACK_SKIP_ROWS, &pack_skip_rows);
- glGetIntegerv_no_lock(GL_PACK_SKIP_PIXELS, &pack_skip_pixels);
- glPixelStorei_no_lock(GL_PACK_ROW_LENGTH, 0);
- glPixelStorei_no_lock(GL_PACK_ALIGNMENT, 4);
- glPixelStorei_no_lock(GL_PACK_SKIP_ROWS, 0);
- glPixelStorei_no_lock(GL_PACK_SKIP_PIXELS, 0);
- if (pack_pbo)
- glBindBufferARB_no_lock(GL_PIXEL_PACK_BUFFER_EXT, 0);
- glReadPixels_no_lock(0, 0, state->drawable_width, state->drawable_height, GL_BGRA, GL_UNSIGNED_BYTE, bufGL);
- glPixelStorei_no_lock(GL_PACK_ROW_LENGTH, pack_row_length);
- glPixelStorei_no_lock(GL_PACK_ALIGNMENT, pack_alignment);
- glPixelStorei_no_lock(GL_PACK_SKIP_ROWS, pack_skip_rows);
- glPixelStorei_no_lock(GL_PACK_SKIP_PIXELS, pack_skip_pixels);
- if (pack_pbo)
- glBindBufferARB_no_lock(GL_PIXEL_PACK_BUFFER_EXT, pack_pbo);
- disable_warning_for_gl_read_pixels = 0;
- for(i=0;i<state->drawable_height;i++)
- {
- memcpy(buf + i * 4 * state->drawable_width,
- bufGL + (state->drawable_height-1-i) * 4 * state->drawable_width,
- 4 * state->drawable_width);
- }
- free(bufGL);
- GC gc = DefaultGC(state->display, DefaultScreen(state->display));
- XPutImage(state->display, state->current_drawable, gc, img, 0, 0, 0, 0, state->drawable_width, state->drawable_height);
- XDestroyImage(img);
- }
- else
-#endif
- call_opengl(_synchronize_func, getpid(), NULL, NULL, NULL);
- }
- if (signature->ret_type == TYPE_UNSIGNED_INT ||
- signature->ret_type == TYPE_INT)
- {
- *(int*)ret_ptr = ret_int;
- }
- else if (signature->ret_type == TYPE_UNSIGNED_CHAR ||
- signature->ret_type == TYPE_CHAR)
- {
- *(char*)ret_ptr = ret_int;
- }
- else if (signature->ret_type == TYPE_CONST_CHAR)
- {
- *(char**)(ret_ptr) = ret_string;
- }
- }
-
-end_do_opengl_call:
- (void)0;
-}
-
-static inline void do_opengl_call(int func_number, void* ret_ptr, long* args, int* args_size_opt)
-{
- LOCK(func_number);
- do_opengl_call_no_lock(func_number, ret_ptr, args, args_size_opt);
- UNLOCK(func_number);
-}
-
-#include "client_stub.c"
-
-GLAPI void APIENTRY glPushAttrib(GLbitfield mask)
-{
- GET_CURRENT_STATE();
- long args[] = { UNSIGNED_INT_TO_ARG(mask)};
- if (state->server_sp < MAX_SERVER_STATE_STACK_SIZE)
- {
- state->server_stack[state->server_sp].mask = mask;
- if (mask & GL_ENABLE_BIT)
- {
- state->server_stack[state->server_sp].linesmoothEnabled = state->current_server_state.linesmoothEnabled;
- state->server_stack[state->server_sp].lightingEnabled = state->current_server_state.lightingEnabled;
- state->server_stack[state->server_sp].texture2DEnabled = state->current_server_state.texture2DEnabled;
- state->server_stack[state->server_sp].blendEnabled = state->current_server_state.blendEnabled;
- }
- if (mask & GL_TRANSFORM_BIT)
- {
- state->server_stack[state->server_sp].matrixMode = state->current_server_state.matrixMode;
- }
- if (mask & GL_DEPTH_BUFFER_BIT)
- {
- state->server_stack[state->server_sp].depthFunc = state->current_server_state.depthFunc;
- }
- if (mask & GL_TEXTURE_BIT)
- {
- state->server_stack[state->server_sp].bindTexture2D = state->current_server_state.bindTexture2D;
- state->server_stack[state->server_sp].bindTextureRectangle = state->current_server_state.bindTextureRectangle;
- }
- if (mask & GL_FOG_BIT)
- {
- state->server_stack[state->server_sp].fog = state->current_server_state.fog;
- }
- state->server_sp++;
- }
- else
- {
- log_gl("server_sp > MAX_SERVER_STATE_STACK_SIZE\n");
- }
- do_opengl_call(glPushAttrib_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glPopAttrib()
-{
- GET_CURRENT_STATE();
- if (state->server_sp > 0)
- {
- state->server_sp--;
- if (state->server_stack[state->server_sp].mask & GL_ENABLE_BIT)
- {
- state->current_server_state.linesmoothEnabled = state->server_stack[state->server_sp].linesmoothEnabled;
- state->current_server_state.lightingEnabled = state->server_stack[state->server_sp].lightingEnabled;
- state->current_server_state.texture2DEnabled = state->server_stack[state->server_sp].texture2DEnabled;
- state->current_server_state.blendEnabled = state->server_stack[state->server_sp].blendEnabled;
- }
- if (state->server_stack[state->server_sp].mask & GL_TRANSFORM_BIT)
- {
- state->current_server_state.matrixMode = state->server_stack[state->server_sp].matrixMode;
- }
- if (state->server_stack[state->server_sp].mask & GL_DEPTH_BUFFER_BIT)
- {
- state->current_server_state.depthFunc = state->server_stack[state->server_sp].depthFunc;
- }
- if (state->server_stack[state->server_sp].mask & GL_TEXTURE_BIT)
- {
- state->current_server_state.bindTexture2D = state->server_stack[state->server_sp].bindTexture2D;
- state->current_server_state.bindTextureRectangle = state->server_stack[state->server_sp].bindTextureRectangle;
- }
- if (state->server_stack[state->server_sp].mask & GL_FOG_BIT)
- {
- state->current_server_state.fog = state->server_stack[state->server_sp].fog;
- }
- }
- else
- {
- log_gl("server_sp <= 0\n");
- }
- do_opengl_call(glPopAttrib_func, NULL, NULL, NULL);
-}
-
-/* 'glIsEnabled'�� ���� static function �� */
-static GLboolean APIENTRY _glIsEnabled( GLenum cap )
-{
- GLboolean ret = 0;
- GET_CURRENT_STATE();
- if (!disable_optim)
- {
- if (cap == GL_LINE_SMOOTH)
- {
- return state->current_server_state.linesmoothEnabled;
- }
- else if (cap == GL_LIGHTING)
- {
- return state->current_server_state.lightingEnabled;
- }
- else if (cap == GL_TEXTURE_2D)
- {
- return state->current_server_state.texture2DEnabled;
- }
- else if (cap == GL_BLEND)
- {
- return state->current_server_state.blendEnabled;
- }
- else if (cap == GL_SCISSOR_TEST)
- {
- return state->current_server_state.scissorTestEnabled;
- }
- else if (cap == GL_VERTEX_PROGRAM_NV)
- {
- return state->current_server_state.vertexProgramEnabled;
- }
- else if (cap == GL_FOG)
- {
- return state->current_server_state.fogEnabled;
- }
- }
- long args[] = { INT_TO_ARG(cap) };
- do_opengl_call(glIsEnabled_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI GLboolean APIENTRY glIsEnabled( GLenum cap )
-{
- GLboolean ret = 0;
-
- if (debug_gl) log_gl("glIsEnabled(0x%X)\n", cap);
-
- ret = _glIsEnabled(cap);
-
- if (debug_gl) log_gl("glIsEnabled(0x%X) = %d\n", cap, ret);
- return ret;
-}
-
-static ClientArray* _getArray(GLenum cap, int verbose)
-{
- GET_CURRENT_STATE();
- switch(cap)
- {
- case GL_VERTEX_ARRAY: return &state->client_state.arrays.vertexArray;
- case GL_COLOR_ARRAY: return &state->client_state.arrays.colorArray;
- case GL_SECONDARY_COLOR_ARRAY: return &state->client_state.arrays.secondaryColorArray;
- case GL_NORMAL_ARRAY: return &state->client_state.arrays.normalArray;
- case GL_INDEX_ARRAY: return &state->client_state.arrays.indexArray;
- case GL_TEXTURE_COORD_ARRAY:
- return &state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture];
- case GL_EDGE_FLAG_ARRAY: return &state->client_state.arrays.edgeFlagArray;
- case GL_WEIGHT_ARRAY_ARB: return &state->client_state.arrays.weightArray;
- case GL_MATRIX_INDEX_ARRAY_POINTER_ARB: return &state->client_state.arrays.matrixIndexArray;
- case GL_FOG_COORD_ARRAY: return &state->client_state.arrays.fogCoordArray;
- case GL_ELEMENT_ARRAY_ATI: return &state->client_state.arrays.elementArrayATI;
- default:
- if (cap >= GL_VERTEX_ATTRIB_ARRAY0_NV && cap < GL_VERTEX_ATTRIB_ARRAY0_NV + MY_GL_MAX_VERTEX_ATTRIBS_NV)
- return &state->client_state.arrays.vertexAttribArrayNV[cap - GL_VERTEX_ATTRIB_ARRAY0_NV];
- if (verbose) log_gl("unhandled cap : %d\n", cap); return NULL;
- }
-}
-
-
-GLAPI void APIENTRY glEnable(GLenum cap)
-{
- GET_CURRENT_STATE();
- /* Strange but some programs use glEnable(GL_VERTEX_ARRAY)
- instead of glEnableClientState(GL_VERTEX_ARRAY) ...
- I've discovered that while trying to make the spheres demo of chromium running
- and mesa confirms it too */
- if (_getArray(cap, 0))
- {
- glEnableClientState(cap);
- return;
- }
-
- if (cap == GL_LINE_SMOOTH)
- {
- state->current_server_state.linesmoothEnabled = 1;
- }
- else if (cap == GL_LIGHTING)
- {
- state->current_server_state.lightingEnabled = 1;
- }
- else if (cap == GL_TEXTURE_2D)
- {
- state->current_server_state.texture2DEnabled = 1;
- }
- else if (cap == GL_BLEND)
- {
- state->current_server_state.blendEnabled = 1;
- }
- else if (cap == GL_SCISSOR_TEST)
- {
- state->current_server_state.scissorTestEnabled = 1;
- }
- else if (cap == GL_VERTEX_PROGRAM_NV)
- {
- state->current_server_state.vertexProgramEnabled = 1;
- }
- else if (cap == GL_FOG)
- {
- state->current_server_state.fogEnabled = 1;
- }
- long args[] = { INT_TO_ARG(cap)};
- do_opengl_call(glEnable_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glDisable(GLenum cap)
-{
- GET_CURRENT_STATE();
- if (_getArray(cap, 0))
- {
- glDisableClientState(cap);
- return;
- }
-
- if (cap == GL_LINE_SMOOTH)
- {
- state->current_server_state.linesmoothEnabled = 0;
- }
- else if (cap == GL_LIGHTING)
- {
- state->current_server_state.lightingEnabled = 0;
- }
- else if (cap == GL_TEXTURE_2D)
- {
- state->current_server_state.texture2DEnabled = 0;
- }
- else if (cap == GL_BLEND)
- {
- state->current_server_state.blendEnabled = 0;
- }
- else if (cap == GL_SCISSOR_TEST)
- {
- state->current_server_state.scissorTestEnabled = 0;
- }
- else if (cap == GL_VERTEX_PROGRAM_NV)
- {
- state->current_server_state.vertexProgramEnabled = 0;
- }
- else if (cap == GL_FOG)
- {
- state->current_server_state.fogEnabled = 0;
- }
- long args[] = { INT_TO_ARG(cap)};
- do_opengl_call(glDisable_func, NULL, args, NULL);
-}
-
-#define GET_CAP_NAME(x) case x: return #x;
-static const char* _getArrayName(GLenum cap)
-{
- switch (cap)
- {
- GET_CAP_NAME(GL_VERTEX_ARRAY);
- GET_CAP_NAME(GL_COLOR_ARRAY);
- GET_CAP_NAME(GL_SECONDARY_COLOR_ARRAY);
- GET_CAP_NAME(GL_NORMAL_ARRAY);
- GET_CAP_NAME(GL_INDEX_ARRAY);
- GET_CAP_NAME(GL_TEXTURE_COORD_ARRAY);
- GET_CAP_NAME(GL_EDGE_FLAG_ARRAY);
- GET_CAP_NAME(GL_WEIGHT_ARRAY_ARB);
- GET_CAP_NAME(GL_MATRIX_INDEX_ARRAY_ARB);
- GET_CAP_NAME(GL_FOG_COORD_ARRAY);
- GET_CAP_NAME(GL_ELEMENT_ARRAY_ATI);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY0_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY1_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY2_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY3_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY4_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY5_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY6_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY7_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY8_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY9_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY10_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY11_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY12_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY13_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY14_NV);
- GET_CAP_NAME(GL_VERTEX_ATTRIB_ARRAY15_NV);
- }
- return "unknown";
-}
-
-GLAPI void APIENTRY EXT_FUNC(glEnableVertexAttribArrayARB)(GLuint index)
-{
- CHECK_PROC(glEnableVertexAttribArrayARB);
- GET_CURRENT_STATE();
- long args[] = { index };
- do_opengl_call(glEnableVertexAttribArrayARB_func, NULL, args, NULL);
-
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- state->client_state.arrays.vertexAttribArray[index].enabled = 1;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glEnableVertexAttribArray)(GLuint index)
-{
- CHECK_PROC(glEnableVertexAttribArray);
- GET_CURRENT_STATE();
- long args[] = { index };
- do_opengl_call(glEnableVertexAttribArray_func, NULL, args, NULL);
-
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- state->client_state.arrays.vertexAttribArray[index].enabled = 1;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- }
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glDisableVertexAttribArrayARB)(GLuint index)
-{
- CHECK_PROC(glDisableVertexAttribArrayARB);
- GET_CURRENT_STATE();
- long args[] = { index };
- do_opengl_call(glDisableVertexAttribArrayARB_func, NULL, args, NULL);
-
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- state->client_state.arrays.vertexAttribArray[index].enabled = 0;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glDisableVertexAttribArray)(GLuint index)
-{
- CHECK_PROC(glDisableVertexAttribArray);
- GET_CURRENT_STATE();
- long args[] = { index };
- do_opengl_call(glDisableVertexAttribArray_func, NULL, args, NULL);
-
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- state->client_state.arrays.vertexAttribArray[index].enabled = 0;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- }
-}
-
-GLAPI void APIENTRY glEnableClientState(GLenum cap)
-{
- if (cap == GL_VERTEX_ARRAY_RANGE_NV ||
- cap == GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV) return; /* FIXME */
- GET_CURRENT_STATE();
- ClientArray* array = _getArray(cap, 1);
- if (array == NULL) return;
- if (debug_array_ptr)
- {
- if (cap == GL_TEXTURE_COORD_ARRAY)
- log_gl("enable texture %d\n", state->client_state.clientActiveTexture);
- else
- log_gl("enable feature %s\n", _getArrayName(cap));
- }
- if ((!disable_optim) && array->enabled)
- {
- //log_gl("discard useless command\n");
- return;
- }
- array->enabled = 1;
- /*if ((!disable_optim) && cap == GL_TEXTURE_COORD_ARRAY)
- {
- long args[] = { UNSIGNED_INT_TO_ARG(state->client_state.clientActiveTexture + GL_TEXTURE0_ARB)};
- do_opengl_call(glClientActiveTexture_func, NULL, args, NULL);
- }*/
- long args[] = { UNSIGNED_INT_TO_ARG(cap)};
- do_opengl_call(glEnableClientState_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glDisableClientState(GLenum cap)
-{
- if (cap == GL_VERTEX_ARRAY_RANGE_NV ||
- cap == GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV) return; /* FIXME */
- GET_CURRENT_STATE();
- ClientArray* array = _getArray(cap, 1);
- if (array == NULL) return;
- if (debug_array_ptr)
- {
- if (cap == GL_TEXTURE_COORD_ARRAY)
- log_gl("disable texture %d\n", state->client_state.clientActiveTexture);
- else
- log_gl("disable feature %s\n", _getArrayName(cap));
- }
-
- if ((!disable_optim) && array->enabled == 0)
- {
- //log_gl("discard useless command\n");
- return;
- }
- array->enabled = 0;
- /*if ((!disable_optim) && cap == GL_TEXTURE_COORD_ARRAY)
- {
- long args[] = { UNSIGNED_INT_TO_ARG(state->client_state.clientActiveTexture + GL_TEXTURE0_ARB)};
- do_opengl_call(glClientActiveTexture_func, NULL, args, NULL);
- }*/
- long args[] = { UNSIGNED_INT_TO_ARG(cap)};
- do_opengl_call(glDisableClientState_func, NULL, args, NULL);
-}
-
-
-GLAPI void APIENTRY glClientActiveTexture(GLenum texture)
-{
- GET_CURRENT_STATE();
-
- if (disable_optim || state->client_state.clientActiveTexture != (int)texture - GL_TEXTURE0_ARB)
- {
- long args[] = { UNSIGNED_INT_TO_ARG(texture)};
- do_opengl_call(glClientActiveTexture_func, NULL, args, NULL);
- }
-
- state->client_state.clientActiveTexture = (int)texture - GL_TEXTURE0_ARB;
-
- assert(state->client_state.clientActiveTexture >= 0 &&
- state->client_state.clientActiveTexture < NB_MAX_TEXTURES);
-}
-
-GLAPI void APIENTRY glClientActiveTextureARB(GLenum texture)
-{
- glClientActiveTexture(texture);
-}
-
-GLAPI void APIENTRY glActiveTextureARB(GLenum texture)
-{
- GET_CURRENT_STATE();
- if (disable_optim || state->activeTexture != texture)
- {
- state->activeTexture = texture;
-
- long args[] = { INT_TO_ARG(texture) };
- do_opengl_call(glActiveTextureARB_func, NULL, args, NULL);
- }
-}
-
-GLAPI void APIENTRY glPushClientAttrib(GLbitfield mask)
-{
- GET_CURRENT_STATE();
- long args[] = { UNSIGNED_INT_TO_ARG(mask)};
- if (state->client_state_sp < MAX_CLIENT_STATE_STACK_SIZE)
- {
- state->client_state_stack[state->client_state_sp].mask = mask;
- if (mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- state->client_state_stack[state->client_state_sp].arrays = state->client_state.arrays;
- }
- if (mask & GL_CLIENT_PIXEL_STORE_BIT)
- {
- state->client_state_stack[state->client_state_sp].pack = state->client_state.pack;
- state->client_state_stack[state->client_state_sp].unpack = state->client_state.unpack;
- }
- state->client_state_sp++;
- }
- else
- {
- log_gl("state->client_state_sp > MAX_CLIENT_STATE_STACK_SIZE\n");
- }
- do_opengl_call(glPushClientAttrib_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glPopClientAttrib()
-{
- GET_CURRENT_STATE();
- if (state->client_state_sp > 0)
- {
- state->client_state_sp--;
- if (state->client_state_stack[state->client_state_sp].mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- state->client_state.arrays = state->client_state_stack[state->client_state_sp].arrays;
- }
- if (state->client_state_stack[state->client_state_sp].mask & GL_CLIENT_PIXEL_STORE_BIT)
- {
- state->client_state.pack = state->client_state_stack[state->client_state_sp].pack;
- state->client_state.unpack = state->client_state_stack[state->client_state_sp].unpack;
- }
- }
- else
- {
- log_gl("state->client_state_sp <= 0\n");
- }
- do_opengl_call(glPopClientAttrib_func, NULL, NULL, NULL);
-}
-
-static void _glPixelStore(GLenum pname, GLint param)
-{
- GET_CURRENT_STATE();
- switch (pname)
- {
- case GL_PACK_SWAP_BYTES: state->client_state.pack.swapEndian = param != 0; break;
- case GL_PACK_LSB_FIRST: state->client_state.pack.lsbFirst = param != 0; break;
- case GL_PACK_ROW_LENGTH: if (param >= 0) state->client_state.pack.rowLength = param; break;
- case GL_PACK_IMAGE_HEIGHT: if (param >= 0) state->client_state.pack.imageHeight = param; break;
- case GL_PACK_SKIP_ROWS: if (param >= 0) state->client_state.pack.skipRows = param; break;
- case GL_PACK_SKIP_PIXELS: if (param >= 0) state->client_state.pack.skipPixels = param; break;
- case GL_PACK_SKIP_IMAGES: if (param >= 0) state->client_state.pack.skipImages = param; break;
- case GL_PACK_ALIGNMENT: if (param == 1 || param == 2 || param == 4 || param == 8)
- state->client_state.pack.alignment = param; break;
- case GL_UNPACK_SWAP_BYTES: state->client_state.unpack.swapEndian = param != 0; break;
- case GL_UNPACK_LSB_FIRST: state->client_state.unpack.lsbFirst = param != 0; break;
- case GL_UNPACK_ROW_LENGTH: if (param >= 0) state->client_state.unpack.rowLength = param; break;
- case GL_UNPACK_IMAGE_HEIGHT: if (param >= 0) state->client_state.unpack.imageHeight = param; break;
- case GL_UNPACK_SKIP_ROWS: if (param >= 0) state->client_state.unpack.skipRows = param; break;
- case GL_UNPACK_SKIP_PIXELS: if (param >= 0) state->client_state.unpack.skipPixels = param; break;
- case GL_UNPACK_SKIP_IMAGES: if (param >= 0) state->client_state.unpack.skipImages = param; break;
- case GL_UNPACK_ALIGNMENT: if (param == 1 || param == 2 || param == 4 || param == 8)
- state->client_state.unpack.alignment = param; break;
- default: log_gl("unhandled pname %d\n", pname); break;
- }
-}
-
-GLAPI void APIENTRY glPixelStoref(GLenum pname, GLfloat param)
-{
- long args[] = { UNSIGNED_INT_TO_ARG(pname), FLOAT_TO_ARG(param)};
- if (!(pname == GL_PACK_SKIP_PIXELS || pname == GL_PACK_SKIP_PIXELS || pname == GL_PACK_SKIP_IMAGES ||
- pname == GL_UNPACK_SKIP_PIXELS || pname == GL_UNPACK_SKIP_PIXELS || pname == GL_UNPACK_SKIP_IMAGES))
- {
- _glPixelStore(pname, (GLint)(param + 0.5));
- do_opengl_call(glPixelStoref_func, NULL, args, NULL);
- }
-}
-
-static void glPixelStorei_no_lock(GLenum pname, GLint param)
-{
- _glPixelStore(pname, param);
- if (!(pname == GL_PACK_SKIP_PIXELS || pname == GL_PACK_SKIP_ROWS || pname == GL_PACK_SKIP_IMAGES ||
- pname == GL_UNPACK_SKIP_PIXELS || pname == GL_UNPACK_SKIP_ROWS || pname == GL_UNPACK_SKIP_IMAGES))
- {
- long args[] = { UNSIGNED_INT_TO_ARG(pname), INT_TO_ARG(param)};
- do_opengl_call_no_lock(glPixelStorei_func, NULL, args, NULL);
- }
-}
-
-GLAPI void APIENTRY glPixelStorei(GLenum pname, GLint param)
-{
- LOCK(glPixelStorei_func);
- glPixelStorei_no_lock(pname, param);
- UNLOCK(glPixelStorei_func);
-}
-
-static int get_nb_composants_of_gl_get_constant_compare(const void* a, const void* b)
-{
- GlGetConstant* constantA = (GlGetConstant*)a;
- GlGetConstant* constantB = (GlGetConstant*)b;
- return constantA->token - constantB->token;
-}
-
-static int get_size_get_boolean_integer_float_double_v(int func_number, int pname)
-{
- GlGetConstant constant;
- GlGetConstant* found;
- constant.token = pname;
- found = bsearch(&constant, gl_get_constants,
- sizeof(gl_get_constants) / sizeof(GlGetConstant), sizeof(GlGetConstant),
- get_nb_composants_of_gl_get_constant_compare);
- if (found)
- return found->count;
- else
- {
- log_gl("unknown name for %s : %d\n", tab_opengl_calls_name[func_number], pname);
- log_gl("hoping that size is 1...\n");
- return 1;
- }
-}
-
-
-#define AFFECT_N(x, y, N) do { int _i; for(_i=0;_i<N;_i++) x[_i]=y[_i]; } while(0)
-
-#define IS_VALID_MATRIX_MODE(mode) \
- ((mode >= GL_MODELVIEW && mode <= GL_TEXTURE) || \
- (mode == GL_MATRIX_PALETTE_ARB) || \
- (mode == GL_MODELVIEW1_ARB) || \
- (mode >= GL_MODELVIEW2_ARB && mode <= GL_MODELVIEW31_ARB))
-
-#define MATRIX_MODE_TO_MATRIX_INDEX(mode) \
- ((mode == GL_MODELVIEW) ? 0 : \
- (mode == GL_PROJECTION) ? 1 : \
- (mode == GL_TEXTURE) ? 2 + state->activeTexture - GL_TEXTURE0_ARB: \
- (mode == GL_MATRIX_PALETTE_ARB) ? 2 + NB_MAX_TEXTURES : \
- (mode == GL_MODELVIEW1_ARB) ? 3 + NB_MAX_TEXTURES : \
- (mode >= GL_MODELVIEW2_ARB && mode <= GL_MODELVIEW31_ARB) ? 4 + NB_MAX_TEXTURES + mode - GL_MODELVIEW2_ARB : -1)
-
-static int maxTextureSize = -1; /* optimization for ppracer */
-static int maxTextureUnits = -1;
-
-static int _glGetIntegerv(GLenum pname)
-{
- int ret;
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(&ret) };
- int args_size[] = { 0, sizeof(int) };
- do_opengl_call_no_lock(glGetIntegerv_func, NULL, CHECK_ARGS(args, args_size));
- return ret;
-}
-
-#define glGetf(funcName, funcNumber, cType, typeBase) \
- static void CONCAT(funcName,_no_lock)( GLenum pname, cType *params ) \
-{ \
- GET_CURRENT_STATE(); \
- switch (pname) \
- { \
- case GL_VERTEX_ARRAY: *params = state->client_state.arrays.vertexArray.enabled; break; \
- case GL_NORMAL_ARRAY: *params = state->client_state.arrays.normalArray.enabled; break; \
- case GL_COLOR_ARRAY: *params = state->client_state.arrays.colorArray.enabled; break; \
- case GL_INDEX_ARRAY: *params = state->client_state.arrays.indexArray.enabled; break; \
- case GL_TEXTURE_COORD_ARRAY: *params = state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].enabled; break; \
- case GL_EDGE_FLAG_ARRAY: *params = state->client_state.arrays.edgeFlagArray.enabled; break; \
- case GL_SECONDARY_COLOR_ARRAY: *params = state->client_state.arrays.secondaryColorArray.enabled; break; \
- case GL_FOG_COORDINATE_ARRAY: *params = state->client_state.arrays.fogCoordArray.enabled; break; \
- case GL_WEIGHT_ARRAY_ARB: *params = state->client_state.arrays.weightArray.enabled; break; \
- case GL_VERTEX_ARRAY_SIZE: *params = state->client_state.arrays.vertexArray.size; break; \
- case GL_VERTEX_ARRAY_TYPE: *params = state->client_state.arrays.vertexArray.type; break; \
- case GL_VERTEX_ARRAY_STRIDE: *params = state->client_state.arrays.vertexArray.stride; break; \
- case GL_NORMAL_ARRAY_TYPE: *params = state->client_state.arrays.normalArray.type; break; \
- case GL_NORMAL_ARRAY_STRIDE: *params = state->client_state.arrays.normalArray.stride; break; \
- case GL_COLOR_ARRAY_SIZE: *params = state->client_state.arrays.colorArray.size; break; \
- case GL_COLOR_ARRAY_TYPE: *params = state->client_state.arrays.colorArray.type; break; \
- case GL_COLOR_ARRAY_STRIDE: *params = state->client_state.arrays.colorArray.stride; break; \
- case GL_INDEX_ARRAY_TYPE: *params = state->client_state.arrays.indexArray.type; break; \
- case GL_INDEX_ARRAY_STRIDE: *params = state->client_state.arrays.indexArray.stride; break; \
- case GL_TEXTURE_COORD_ARRAY_SIZE: *params = state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].size; break; \
- case GL_TEXTURE_COORD_ARRAY_TYPE: *params = state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].type; break; \
- case GL_TEXTURE_COORD_ARRAY_STRIDE: *params = state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].stride; break; \
- case GL_EDGE_FLAG_ARRAY_STRIDE: *params = state->client_state.arrays.edgeFlagArray.stride; break; \
- case GL_SECONDARY_COLOR_ARRAY_SIZE: *params = state->client_state.arrays.secondaryColorArray.size; break; \
- case GL_SECONDARY_COLOR_ARRAY_TYPE: *params = state->client_state.arrays.secondaryColorArray.type; break; \
- case GL_SECONDARY_COLOR_ARRAY_STRIDE: *params = state->client_state.arrays.secondaryColorArray.stride; break; \
- case GL_FOG_COORDINATE_ARRAY_TYPE: *params = state->client_state.arrays.fogCoordArray.type; break; \
- case GL_FOG_COORDINATE_ARRAY_POINTER: *params = state->client_state.arrays.fogCoordArray.stride; break; \
- case GL_WEIGHT_ARRAY_SIZE_ARB: *params = state->client_state.arrays.weightArray.size; break; \
- case GL_WEIGHT_ARRAY_TYPE_ARB: *params = state->client_state.arrays.weightArray.type; break; \
- case GL_WEIGHT_ARRAY_STRIDE_ARB: *params = state->client_state.arrays.weightArray.stride; break; \
- case GL_MATRIX_INDEX_ARRAY_SIZE_ARB: *params = state->client_state.arrays.matrixIndexArray.size; break; \
- case GL_MATRIX_INDEX_ARRAY_TYPE_ARB: *params = state->client_state.arrays.matrixIndexArray.type; break; \
- case GL_MATRIX_INDEX_ARRAY_STRIDE_ARB: *params = state->client_state.arrays.matrixIndexArray.stride; break; \
- case GL_VERTEX_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.vertexArray.vbo_name; break; \
- case GL_NORMAL_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.normalArray.vbo_name; break; \
- case GL_COLOR_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.colorArray.vbo_name; break; \
- case GL_INDEX_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.indexArray.vbo_name; break; \
- case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].vbo_name; break; \
- case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.edgeFlagArray.vbo_name; break; \
- case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.secondaryColorArray.vbo_name; break; \
- case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.fogCoordArray.vbo_name; break; \
- case GL_WEIGHT_ARRAY_BUFFER_BINDING: *params = state->client_state.arrays.weightArray.vbo_name; break; \
- case GL_PACK_SWAP_BYTES: *params = state->client_state.pack.swapEndian; break; \
- case GL_PACK_LSB_FIRST: *params = state->client_state.pack.lsbFirst; break; \
- case GL_PACK_ROW_LENGTH: *params = state->client_state.pack.rowLength; break; \
- case GL_PACK_IMAGE_HEIGHT: *params = state->client_state.pack.imageHeight; break; \
- case GL_PACK_SKIP_ROWS: *params = state->client_state.pack.skipRows; break; \
- case GL_PACK_SKIP_PIXELS: *params = state->client_state.pack.skipPixels; break; \
- case GL_PACK_SKIP_IMAGES: *params = state->client_state.pack.skipImages; break; \
- case GL_PACK_ALIGNMENT: *params = state->client_state.pack.alignment; break; \
- case GL_UNPACK_SWAP_BYTES: *params = state->client_state.unpack.swapEndian; break; \
- case GL_UNPACK_LSB_FIRST: *params = state->client_state.unpack.lsbFirst; break; \
- case GL_UNPACK_ROW_LENGTH: *params = state->client_state.unpack.rowLength; break; \
- case GL_UNPACK_IMAGE_HEIGHT: *params = state->client_state.unpack.imageHeight; break; \
- case GL_UNPACK_SKIP_ROWS: *params = state->client_state.unpack.skipRows; break; \
- case GL_UNPACK_SKIP_PIXELS: *params = state->client_state.unpack.skipPixels; break; \
- case GL_UNPACK_SKIP_IMAGES: *params = state->client_state.unpack.skipImages; break; \
- case GL_UNPACK_ALIGNMENT: *params = state->client_state.unpack.alignment; break; \
- case GL_TEXTURE_2D_BINDING_EXT: *params = state->current_server_state.bindTexture2D; break; \
- case GL_TEXTURE_BINDING_RECTANGLE_ARB: *params = state->current_server_state.bindTextureRectangle; break; \
- case GL_VIEWPORT: params[0] = state->viewport.x; params[1] = state->viewport.y; params[2] = state->viewport.width; params[3] = state->viewport.height; break; \
- case GL_SCISSOR_BOX: params[0] = state->scissorbox.x; params[1] = state->scissorbox.y; params[2] = state->scissorbox.width; params[3] = state->scissorbox.height; break; \
- case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: *params = 16; break;\
- case GL_MATRIX_MODE: *params = state->current_server_state.matrixMode; break; \
- case GL_DEPTH_FUNC: *params = state->current_server_state.depthFunc; break; \
- case GL_FOG_MODE: *params = state->current_server_state.fog.mode; break; \
- case GL_FOG_DENSITY: *params = state->current_server_state.fog.density; break; \
- case GL_FOG_START: *params = state->current_server_state.fog.start; break; \
- case GL_FOG_END: *params = state->current_server_state.fog.end; break; \
- case GL_FOG_INDEX: *params = state->current_server_state.fog.index; break; \
- case GL_FOG_COLOR: AFFECT_N(params, state->current_server_state.fog.color, 4); break; \
- case GL_COMPRESSED_TEXTURE_FORMATS_ARB: \
- { \
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(params) }; \
- int args_size[] = { 0, 0 }; \
- int nb_compressed_texture_formats = 0; \
- glGetIntegerv_no_lock(GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &nb_compressed_texture_formats); \
- args_size[1] = tab_args_type_length[typeBase] * nb_compressed_texture_formats; \
- do_opengl_call_no_lock(funcNumber, NULL, CHECK_ARGS(args, args_size)); \
- break; \
- } \
- case GL_ARRAY_BUFFER_BINDING: *params = state->arrayBuffer; break; \
- case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB: *params = state->elementArrayBuffer; break; \
- case GL_MAX_TEXTURE_SIZE: if (maxTextureSize == -1) maxTextureSize = _glGetIntegerv(pname); *params = maxTextureSize; break; \
- case GL_MAX_TEXTURE_UNITS_ARB: if (maxTextureUnits == -1) maxTextureUnits = _glGetIntegerv(pname); *params = maxTextureUnits; break; \
- case GL_MODELVIEW_MATRIX: \
- case GL_PROJECTION_MATRIX: \
- case GL_TEXTURE_MATRIX: AFFECT_N(params, state->matrix[pname - GL_MODELVIEW_MATRIX].current.val, 16); break; \
- case GL_CURRENT_RASTER_POSITION: \
- { \
- if (!state->currentRasterPosKnown) \
- { \
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(state->currentRasterPos) }; \
- int args_size[] = { 0, 4 * sizeof(float) }; \
- log_gl("getting value 0x%X\n", pname); \
- do_opengl_call_no_lock(glGetFloatv_func, NULL, CHECK_ARGS(args, args_size)); \
- state->currentRasterPosKnown = 1; \
- } \
- AFFECT_N(params, state->currentRasterPos, 4); \
- break; \
- } \
- default: \
- { \
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(params) }; \
- int args_size[] = { 0, 0 }; \
- args_size[1] = tab_args_type_length[typeBase] * get_size_get_boolean_integer_float_double_v(funcNumber, pname); \
- log_gl("getting value 0x%X\n", pname); \
- do_opengl_call_no_lock(funcNumber, NULL, CHECK_ARGS(args, args_size)); \
- if (typeBase == TYPE_INT) log_gl("val=%d\n", (int)*params); \
- else if (typeBase == TYPE_FLOAT) log_gl("val=%f\n", (float)*params); \
- } \
- } \
-} \
-GLAPI void APIENTRY funcName( GLenum pname, cType *params ) \
-{ \
- LOCK(funcNumber); \
- CONCAT(funcName,_no_lock)(pname, params); \
- UNLOCK(funcNumber); \
-}
-
-glGetf(glGetBooleanv, glGetBooleanv_func, GLboolean, TYPE_CHAR);
-glGetf(glGetIntegerv, glGetIntegerv_func, GLint, TYPE_INT);
-glGetf(glGetFloatv, glGetFloatv_func, GLfloat, TYPE_FLOAT);
-glGetf(glGetDoublev, glGetDoublev_func, GLdouble, TYPE_DOUBLE);
-
-GLAPI void APIENTRY glDepthFunc(GLenum func)
-{
- long args[] = { UNSIGNED_INT_TO_ARG(func)};
- GET_CURRENT_STATE();
- state->current_server_state.depthFunc = func;
- do_opengl_call(glDepthFunc_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glClipPlane(GLenum plane, const GLdouble * equation)
-{
- GET_CURRENT_STATE();
- if (plane >= GL_CLIP_PLANE0 && plane < GL_CLIP_PLANE0 + N_CLIP_PLANES)
- memcpy(state->current_server_state.clipPlanes[plane-GL_CLIP_PLANE0], equation, 4 * sizeof(double));
- long args[] = { UNSIGNED_INT_TO_ARG(plane), POINTER_TO_ARG(equation)};
- do_opengl_call(glClipPlane_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glGetClipPlane(GLenum plane, GLdouble * equation)
-{
- GET_CURRENT_STATE();
- if (plane >= GL_CLIP_PLANE0 && plane < GL_CLIP_PLANE0 + N_CLIP_PLANES)
- {
- memcpy(equation, state->current_server_state.clipPlanes[plane-GL_CLIP_PLANE0], 4 * sizeof(double));
- return;
- }
- long args[] = { UNSIGNED_INT_TO_ARG(plane), POINTER_TO_ARG(equation)};
- do_opengl_call(glGetClipPlane_func, NULL, args, NULL);
-}
-
-
-GLAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
-{
- GET_CURRENT_STATE();
- long args[] = { INT_TO_ARG(x), INT_TO_ARG(y), INT_TO_ARG(width), INT_TO_ARG(height)};
- state->viewport.x = x;
- state->viewport.y = y;
- state->viewport.width = width;
- state->viewport.height = height;
- if (debug_gl) log_gl("viewport %d,%d,%d,%d\n", x, y, width, height);
- do_opengl_call(glViewport_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
-{
- GET_CURRENT_STATE();
- long args[] = { INT_TO_ARG(x), INT_TO_ARG(y), INT_TO_ARG(width), INT_TO_ARG(height)};
- state->scissorbox.x = x;
- state->scissorbox.y = y;
- state->scissorbox.width = width;
- state->scissorbox.height = height;
- do_opengl_call(glScissor_func, NULL, args, NULL);
-}
-
-
-/* Matrix optimization : openquartz */
-#if 1
-GLAPI void APIENTRY glMatrixMode(GLenum mode)
-{
- GET_CURRENT_STATE();
- long args[] = { UNSIGNED_INT_TO_ARG(mode)};
- if (IS_VALID_MATRIX_MODE(mode))
- state->current_server_state.matrixMode = mode;
- do_opengl_call(glMatrixMode_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glPushMatrix()
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- if (state->matrix[index_mode].sp < MAX_MATRIX_STACK_SIZE)
- {
- memcpy(state->matrix[index_mode].stack[state->matrix[index_mode].sp].val,
- state->matrix[index_mode].current.val,
- 16 * sizeof(double));
- state->matrix[index_mode].sp++;
- }
- else
- {
- log_gl("matrix[mode].sp >= MAX_MATRIX_STACK_SIZE\n");
- }
- }
-
- do_opengl_call(glPushMatrix_func, NULL, NULL, NULL);
-}
-
-GLAPI void APIENTRY glPopMatrix()
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- if (state->matrix[index_mode].sp > 0)
- {
- state->matrix[index_mode].sp--;
- memcpy(state->matrix[index_mode].current.val,
- state->matrix[index_mode].stack[state->matrix[index_mode].sp].val,
- 16 * sizeof(double));
- }
- else
- {
- log_gl("matrix[mode].sp <= 0\n");
- }
- }
-
- do_opengl_call(glPopMatrix_func, NULL, NULL, NULL);
-}
-
-GLAPI void APIENTRY glLoadIdentity()
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- int j;
- if (index_mode >= 0)
- {
- for(j=0;j<16;j++)
- {
- state->matrix[index_mode].current.val[j] = (j == 0 || j == 5 || j == 10 || j == 15);
- }
- }
- do_opengl_call(glLoadIdentity_func, NULL, NULL, NULL);
-}
-
-static void _internal_glLoadMatrixd(const GLdouble matrix[16])
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- memcpy(state->matrix[index_mode].current.val, matrix, 16 * sizeof(double));
-}
-
-static void _internal_glLoadMatrixf(const GLfloat matrix[16])
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- int i;
- for(i=0;i<16;i++)
- state->matrix[index_mode].current.val[i] = matrix[i];
- }
-}
-
-GLAPI void APIENTRY glLoadMatrixd(const GLdouble matrix[16])
-{
- _internal_glLoadMatrixd(matrix);
- long args[] = { POINTER_TO_ARG(matrix)};
- do_opengl_call(glLoadMatrixd_func, NULL, args, NULL);
-}
-
-static void matrixfToMatrixd(const GLfloat matrixf[16], GLdouble matrix[16])
-{
- int i;
- for(i=0;i<16;i++)
- {
- matrix[i] = matrixf[i];
- }
-}
-
-GLAPI void APIENTRY glLoadMatrixf(const GLfloat matrix[16])
-{
- _internal_glLoadMatrixf(matrix);
-
- long args[] = { POINTER_TO_ARG(matrix)};
- do_opengl_call(glLoadMatrixf_func, NULL, args, NULL);
-}
-
-static void _internal_glMultMatrixd(const GLdouble matrix[16])
-{
- GET_CURRENT_STATE();
- GLdouble destMatrix[16];
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* oriMatrix = state->matrix[index_mode].current.val;
-
- /* t(C)=t(A.B)=t(B).t(A) */
-
- destMatrix[0*4+0] = matrix[0*4+0] * oriMatrix[0*4+0] +
- matrix[0*4+1] * oriMatrix[1*4+0] +
- matrix[0*4+2] * oriMatrix[2*4+0] +
- matrix[0*4+3] * oriMatrix[3*4+0];
- destMatrix[0*4+1] = matrix[0*4+0] * oriMatrix[0*4+1] +
- matrix[0*4+1] * oriMatrix[1*4+1] +
- matrix[0*4+2] * oriMatrix[2*4+1] +
- matrix[0*4+3] * oriMatrix[3*4+1];
- destMatrix[0*4+2] = matrix[0*4+0] * oriMatrix[0*4+2] +
- matrix[0*4+1] * oriMatrix[1*4+2] +
- matrix[0*4+2] * oriMatrix[2*4+2] +
- matrix[0*4+3] * oriMatrix[3*4+2];
- destMatrix[0*4+3] = matrix[0*4+0] * oriMatrix[0*4+3] +
- matrix[0*4+1] * oriMatrix[1*4+3] +
- matrix[0*4+2] * oriMatrix[2*4+3] +
- matrix[0*4+3] * oriMatrix[3*4+3];
-
- destMatrix[1*4+0] = matrix[1*4+0] * oriMatrix[0*4+0] +
- matrix[1*4+1] * oriMatrix[1*4+0] +
- matrix[1*4+2] * oriMatrix[2*4+0] +
- matrix[1*4+3] * oriMatrix[3*4+0];
- destMatrix[1*4+1] = matrix[1*4+0] * oriMatrix[0*4+1] +
- matrix[1*4+1] * oriMatrix[1*4+1] +
- matrix[1*4+2] * oriMatrix[2*4+1] +
- matrix[1*4+3] * oriMatrix[3*4+1];
- destMatrix[1*4+2] = matrix[1*4+0] * oriMatrix[0*4+2] +
- matrix[1*4+1] * oriMatrix[1*4+2] +
- matrix[1*4+2] * oriMatrix[2*4+2] +
- matrix[1*4+3] * oriMatrix[3*4+2];
- destMatrix[1*4+3] = matrix[1*4+0] * oriMatrix[0*4+3] +
- matrix[1*4+1] * oriMatrix[1*4+3] +
- matrix[1*4+2] * oriMatrix[2*4+3] +
- matrix[1*4+3] * oriMatrix[3*4+3];
-
- destMatrix[2*4+0] = matrix[2*4+0] * oriMatrix[0*4+0] +
- matrix[2*4+1] * oriMatrix[1*4+0] +
- matrix[2*4+2] * oriMatrix[2*4+0] +
- matrix[2*4+3] * oriMatrix[3*4+0];
- destMatrix[2*4+1] = matrix[2*4+0] * oriMatrix[0*4+1] +
- matrix[2*4+1] * oriMatrix[1*4+1] +
- matrix[2*4+2] * oriMatrix[2*4+1] +
- matrix[2*4+3] * oriMatrix[3*4+1];
- destMatrix[2*4+2] = matrix[2*4+0] * oriMatrix[0*4+2] +
- matrix[2*4+1] * oriMatrix[1*4+2] +
- matrix[2*4+2] * oriMatrix[2*4+2] +
- matrix[2*4+3] * oriMatrix[3*4+2];
- destMatrix[2*4+3] = matrix[2*4+0] * oriMatrix[0*4+3] +
- matrix[2*4+1] * oriMatrix[1*4+3] +
- matrix[2*4+2] * oriMatrix[2*4+3] +
- matrix[2*4+3] * oriMatrix[3*4+3];
-
- destMatrix[3*4+0] = matrix[3*4+0] * oriMatrix[0*4+0] +
- matrix[3*4+1] * oriMatrix[1*4+0] +
- matrix[3*4+2] * oriMatrix[2*4+0] +
- matrix[3*4+3] * oriMatrix[3*4+0];
- destMatrix[3*4+1] = matrix[3*4+0] * oriMatrix[0*4+1] +
- matrix[3*4+1] * oriMatrix[1*4+1] +
- matrix[3*4+2] * oriMatrix[2*4+1] +
- matrix[3*4+3] * oriMatrix[3*4+1];
- destMatrix[3*4+2] = matrix[3*4+0] * oriMatrix[0*4+2] +
- matrix[3*4+1] * oriMatrix[1*4+2] +
- matrix[3*4+2] * oriMatrix[2*4+2] +
- matrix[3*4+3] * oriMatrix[3*4+2];
- destMatrix[3*4+3] = matrix[3*4+0] * oriMatrix[0*4+3] +
- matrix[3*4+1] * oriMatrix[1*4+3] +
- matrix[3*4+2] * oriMatrix[2*4+3] +
- matrix[3*4+3] * oriMatrix[3*4+3];
-
- memcpy(oriMatrix, destMatrix, 16 * sizeof(double));
- }
-}
-
-GLAPI void APIENTRY glMultMatrixd(const GLdouble matrix[16])
-{
- _internal_glMultMatrixd(matrix);
-
- long args[] = { POINTER_TO_ARG(matrix)};
- do_opengl_call(glMultMatrixd_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glMultMatrixf(const GLfloat matrix[16])
-{
- GLdouble matrixd[16];
- matrixfToMatrixd(matrix, matrixd);
- _internal_glMultMatrixd(matrixd);
-
- long args[] = { POINTER_TO_ARG(matrix)};
- do_opengl_call(glMultMatrixf_func, NULL, args, NULL);
-}
-
-/**
- * Transpose a GLfloat matrix.
- *
- * \param to destination array.
- * \param from source array.
- */
- static void
-_math_transposef( GLfloat to[16], const GLfloat from[16] )
-{
- to[0] = from[0];
- to[1] = from[4];
- to[2] = from[8];
- to[3] = from[12];
- to[4] = from[1];
- to[5] = from[5];
- to[6] = from[9];
- to[7] = from[13];
- to[8] = from[2];
- to[9] = from[6];
- to[10] = from[10];
- to[11] = from[14];
- to[12] = from[3];
- to[13] = from[7];
- to[14] = from[11];
- to[15] = from[15];
-}
-
-
-/**
- * Transpose a GLdouble matrix.
- *
- * \param to destination array.
- * \param from source array.
- */
- static void
-_math_transposed( GLdouble to[16], const GLdouble from[16] )
-{
- to[0] = from[0];
- to[1] = from[4];
- to[2] = from[8];
- to[3] = from[12];
- to[4] = from[1];
- to[5] = from[5];
- to[6] = from[9];
- to[7] = from[13];
- to[8] = from[2];
- to[9] = from[6];
- to[10] = from[10];
- to[11] = from[14];
- to[12] = from[3];
- to[13] = from[7];
- to[14] = from[11];
- to[15] = from[15];
-}
-
-GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat m[16])
-{
- GLfloat dest[16];
- _math_transposef(dest, m);
- glLoadMatrixf(dest);
-}
-
-GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble m[16])
-{
- GLdouble dest[16];
- _math_transposed(dest, m);
- glLoadMatrixd(dest);
-}
-
-GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat m[16])
-{
- GLfloat dest[16];
- _math_transposef(dest, m);
- glMultMatrixf(dest);
-}
-
-GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble m[16])
-{
- GLdouble dest[16];
- _math_transposed(dest, m);
- glMultMatrixd(dest);
-}
-
-GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat* m)
-{
- GLfloat dest[16];
- _math_transposef(dest, m);
- glLoadMatrixf(dest);
-}
-
-GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble* m)
-{
- GLdouble dest[16];
- _math_transposed(dest, m);
- glLoadMatrixd(dest);
-}
-
-GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat* m)
-{
- GLfloat dest[16];
- _math_transposef(dest, m);
- glMultMatrixf(dest);
-}
-
-GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble* m)
-{
- GLdouble dest[16];
- _math_transposed(dest, m);
- glMultMatrixd(dest);
-}
-
-GLAPI void APIENTRY glOrtho( GLdouble left,
- GLdouble right,
- GLdouble bottom,
- GLdouble top,
- GLdouble near_val,
- GLdouble far_val)
-{
- double tx, ty, tz;
- tx = -(right + left) / (right - left);
- ty = -(top + bottom) / (top - bottom);
- tz = -(far_val + near_val) / (far_val - near_val);
- double matrix[16] = { 2/(right - left), 0, 0, 0,
- 0, 2/(top-bottom), 0, 0,
- 0, 0, -2/(far_val - near_val), 0,
- tx, ty, tz, 1 };
- _internal_glMultMatrixd(matrix);
-
- long args[] = { DOUBLE_TO_ARG(left), DOUBLE_TO_ARG(right), DOUBLE_TO_ARG(bottom), DOUBLE_TO_ARG(top), DOUBLE_TO_ARG(near_val), DOUBLE_TO_ARG(far_val)};
- do_opengl_call(glOrtho_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glFrustum( GLdouble left,
- GLdouble right,
- GLdouble bottom,
- GLdouble top,
- GLdouble near_val,
- GLdouble far_val)
-{
- double V1, V2, A, B, C, D;
- V1 = 2 * near_val / (right - left);
- V2 = 2 * near_val / (top - bottom);
- A = (right + left) / (right - left);
- B = (top + bottom) / (top - bottom);
- C = -(far_val + near_val) / (far_val - near_val);
- D = -2 * far_val * near_val / (far_val - near_val);
- double matrix[16] = { V1, 0, 0, 0,
- 0, V2, 0, 0,
- A, B, C, -1,
- 0, 0, D, 0};
- _internal_glMultMatrixd(matrix);
-
- long args[] = { DOUBLE_TO_ARG(left), DOUBLE_TO_ARG(right), DOUBLE_TO_ARG(bottom), DOUBLE_TO_ARG(top), DOUBLE_TO_ARG(near_val), DOUBLE_TO_ARG(far_val)};
- do_opengl_call(glFrustum_func, NULL, args, NULL);
-
-}
-
-static void _glRotate_internal(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
-{
- double c = cos(angle / 180. * M_PI);
- double s = sin(angle / 180. * M_PI);
- if (x == 1 && y == 0 && z == 0)
- {
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* matrix = state->matrix[index_mode].current.val;
- double t, u;
-
- t = matrix[1*4+0];
- u = matrix[2*4+0];
- matrix[1*4+0] = c * t + s * u;
- matrix[2*4+0] = c * u - s * t;
-
- t = matrix[1*4+1];
- u = matrix[2*4+1];
- matrix[1*4+1] = c * t + s * u;
- matrix[2*4+1] = c * u - s * t;
-
- t = matrix[1*4+2];
- u = matrix[2*4+2];
- matrix[1*4+2] = c * t + s * u;
- matrix[2*4+2] = c * u - s * t;
-
- t = matrix[1*4+3];
- u = matrix[2*4+3];
- matrix[1*4+3] = c * t + s * u;
- matrix[2*4+3] = c * u - s * t;
- }
- }
- else if (x == 0 && y == 1 && z == 0)
- {
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* matrix = state->matrix[index_mode].current.val;
- double t, u;
-
- t = matrix[0*4+0];
- u = matrix[2*4+0];
- matrix[0*4+0] = c * t - s * u;
- matrix[2*4+0] = s * t + c * u;
-
- t = matrix[0*4+1];
- u = matrix[2*4+1];
- matrix[0*4+1] = c * t - s * u;
- matrix[2*4+1] = s * t + c * u;
-
- t = matrix[0*4+2];
- u = matrix[2*4+2];
- matrix[0*4+2] = c * t - s * u;
- matrix[2*4+2] = s * t + c * u;
-
- t = matrix[0*4+3];
- u = matrix[2*4+3];
- matrix[0*4+3] = c * t - s * u;
- matrix[2*4+3] = s * t + c * u;
- }
- }
- else if (x == 0 && y == 0 && z == 1)
- {
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* matrix = state->matrix[index_mode].current.val;
- double t, u;
-
- t = matrix[0*4+0];
- u = matrix[1*4+0];
- matrix[0*4+0] = c * t + s * u;
- matrix[1*4+0] = c * u - s * t;
-
- t = matrix[0*4+1];
- u = matrix[1*4+1];
- matrix[0*4+1] = c * t + s * u;
- matrix[1*4+1] = c * u - s * t;
-
- t = matrix[0*4+2];
- u = matrix[1*4+2];
- matrix[0*4+2] = c * t + s * u;
- matrix[1*4+2] = c * u - s * t;
-
- t = matrix[0*4+3];
- u = matrix[1*4+3];
- matrix[0*4+3] = c * t + s * u;
- matrix[1*4+3] = c * u - s * t;
- }
- }
- else
- {
- double sqrt_sum_sqr = sqrt(x*x+y*y+z*z);
- if (sqrt_sum_sqr < 1e-4) return;
- x /= sqrt_sum_sqr;
- y /= sqrt_sum_sqr;
- z /= sqrt_sum_sqr;
- double matrix[16] = { x*x*(1-c)+c, y*x*(1-c)+z*s, x*z*(1-c)-y*s, 0,
- x*y*(1-c)-z*s, y*y*(1-c)+c, y*z*(1-c)+x*s, 0,
- x*z*(1-c)+y*s, y*z*(1-c)-x*s, z*z*(1-c)+c, 0,
- 0, 0, 0, 1};
- _internal_glMultMatrixd(matrix);
- }
-}
-
-GLAPI void APIENTRY glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
-{
- _glRotate_internal(angle, x, y, z);
-
- long args[] = { DOUBLE_TO_ARG(angle), DOUBLE_TO_ARG(x), DOUBLE_TO_ARG(y), DOUBLE_TO_ARG(z)};
- do_opengl_call(glRotated_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
-{
- _glRotate_internal(angle, x, y, z);
-
- long args[] = { FLOAT_TO_ARG(angle), FLOAT_TO_ARG(x), FLOAT_TO_ARG(y), FLOAT_TO_ARG(z)};
- do_opengl_call(glRotatef_func, NULL, args, NULL);
-}
-
-static void _glScale_internal(double a, double b, double c)
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* matrix = state->matrix[index_mode].current.val;
- matrix[0*4+0] *= a;
- matrix[0*4+1] *= a;
- matrix[0*4+2] *= a;
- matrix[0*4+3] *= a;
- matrix[1*4+0] *= b;
- matrix[1*4+1] *= b;
- matrix[1*4+2] *= b;
- matrix[1*4+3] *= b;
- matrix[2*4+0] *= c;
- matrix[2*4+1] *= c;
- matrix[2*4+2] *= c;
- matrix[2*4+3] *= c;
- }
-}
-
-GLAPI void APIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z)
-{
- _glScale_internal(x, y, z);
-
- long args[] = { DOUBLE_TO_ARG(x), DOUBLE_TO_ARG(y), DOUBLE_TO_ARG(z)};
- do_opengl_call(glScaled_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z)
-{
- _glScale_internal(x, y, z);
-
- long args[] = { FLOAT_TO_ARG(x), FLOAT_TO_ARG(y), FLOAT_TO_ARG(z)};
- do_opengl_call(glScalef_func, NULL, args, NULL);
-}
-
-static void _glTranslate_internal(double a, double b, double c)
-{
- GET_CURRENT_STATE();
- int index_mode = MATRIX_MODE_TO_MATRIX_INDEX(state->current_server_state.matrixMode);
- if (index_mode >= 0)
- {
- GLdouble* matrix = state->matrix[index_mode].current.val;
-
- matrix[3*4+0] += a * matrix[0*4+0] + b * matrix[1*4+0] + c * matrix[2*4+0];
- matrix[3*4+1] += a * matrix[0*4+1] + b * matrix[1*4+1] + c * matrix[2*4+1];
- matrix[3*4+2] += a * matrix[0*4+2] + b * matrix[1*4+2] + c * matrix[2*4+2];
- matrix[3*4+3] += a * matrix[0*4+3] + b * matrix[1*4+3] + c * matrix[2*4+3];
- }
-}
-
-GLAPI void APIENTRY glTranslated(GLdouble x, GLdouble y, GLdouble z)
-{
- _glTranslate_internal(x, y, z);
-
- long args[] = { DOUBLE_TO_ARG(x), DOUBLE_TO_ARG(y), DOUBLE_TO_ARG(z)};
- do_opengl_call(glTranslated_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
-{
- _glTranslate_internal(x, y, z);
-
- long args[] = { FLOAT_TO_ARG(x), FLOAT_TO_ARG(y), FLOAT_TO_ARG(z)};
- do_opengl_call(glTranslatef_func, NULL, args, NULL);
-}
-#endif
-/* End of matrix optimization */
-
-static void glBindBufferARB_no_lock(GLenum target, GLuint buffer)
-{
- CHECK_PROC(glBindBufferARB);
- GET_CURRENT_STATE();
- if (buffer >= 32768)
- {
- log_gl("buffer >= 32768\n");
- return;
- }
- long args[] = {INT_TO_ARG(target), INT_TO_ARG(buffer)};
- if (target == GL_ARRAY_BUFFER_ARB)
- {
- //log_gl("glBindBufferARB(GL_ARRAY_BUFFER,%d)\n", buffer);
- state->arrayBuffer = buffer;
- }
- else if (target == GL_ELEMENT_ARRAY_BUFFER_ARB)
- {
- //log_gl("glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,%d)\n", buffer);
- state->elementArrayBuffer = buffer;
- }
- else if (target == GL_PIXEL_UNPACK_BUFFER_EXT)
- {
- //log_gl("glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT,%d)\n", buffer);
- state->pixelUnpackBuffer = buffer;
- }
- else if (target == GL_PIXEL_PACK_BUFFER_EXT)
- {
- //log_gl("glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT,%d)\n", buffer);
- state->pixelPackBuffer = buffer;
- }
- do_opengl_call_no_lock(glBindBufferARB_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glBindBufferARB) (GLenum target, GLuint buffer)
-{
- LOCK(glBindBufferARB_func);
- glBindBufferARB_no_lock(target, buffer);
- UNLOCK(glBindBufferARB_func);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glBindBuffer) (GLenum target, GLuint buffer)
-{
- glBindBufferARB(target, buffer);
-}
-
-GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint * tab)
-{
- CHECK_PROC(glGenBuffersARB);
- GET_CURRENT_STATE();
- if (n <= 0) { log_gl("n <= 0\n"); return; }
- alloc_range(state->bufferAllocator, n, tab);
- long args[] = { INT_TO_ARG(n) };
- do_opengl_call(glGenBuffersARB_fake_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint * tab)
-{
- glGenBuffersARB(n, tab);
-}
-
-GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint * tab)
-{
- CHECK_PROC(glDeleteBuffersARB);
- GET_CURRENT_STATE();
- if (n <= 0) { log_gl("n <= 0\n"); return; }
- delete_range(state->bufferAllocator, n, tab);
- long args[] = { INT_TO_ARG(n), POINTER_TO_ARG(tab) };
- do_opengl_call(glDeleteBuffersARB_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glDeleteBuffers(GLsizei n, const GLuint * tab)
-{
- glDeleteBuffersARB(n, tab);
-}
-
-static Buffer* _get_buffer(GLenum target)
-{
- GET_CURRENT_STATE();
- if (target == GL_ARRAY_BUFFER_ARB)
- {
- if (state->arrayBuffer)
- return &state->arrayBuffers[state->arrayBuffer];
- else
- return NULL;
- }
- else if (target == GL_ELEMENT_ARRAY_BUFFER_ARB)
- {
- if (state->elementArrayBuffer)
- return &state->elementArrayBuffers[state->elementArrayBuffer];
- else
- return NULL;
- }
- else if (target == GL_PIXEL_UNPACK_BUFFER_EXT)
- {
- if (state->pixelUnpackBuffer)
- return &state->pixelUnpackBuffers[state->pixelUnpackBuffer];
- else
- return NULL;
- }
- else if (target == GL_PIXEL_PACK_BUFFER_EXT)
- {
- if (state->pixelPackBuffer)
- return &state->pixelPackBuffers[state->pixelPackBuffer];
- else
- return NULL;
- }
- else
- {
- return NULL;
- }
-}
-
-GLAPI GLenum APIENTRY glGetError()
-{
- int ret = 0;
- if (disable_optim)
- {
- do_opengl_call(glGetError_func, &ret, NULL, NULL);
- log_gl("glGetError() = %d\n", ret);
- }
- else
- do_opengl_call(_glGetError_fake_func, NULL, NULL, NULL);
- return ret;
-}
-
-GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
-{
- CHECK_PROC(glBufferDataARB);
-
- Buffer* buffer = _get_buffer(target);
- if (buffer)
- {
- buffer->usage = usage;
- buffer->size = size;
- buffer->ptr = realloc(buffer->ptr, size);
- if (data) memcpy(buffer->ptr, data, size);
- }
- else
- {
- fprintf(stderr, "unknown buffer/buffer target : %d\n", target);
- }
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(size), POINTER_TO_ARG(data), INT_TO_ARG(usage) };
- int args_size[] = { 0, 0, (data) ? size : 0, 0 };
- do_opengl_call(glBufferDataARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
-{
- glBufferDataARB(target, size, data, usage);
-}
-
-GLAPI void APIENTRY glBufferSubDataARB(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data)
-{
- CHECK_PROC(glBufferSubDataARB);
-
- //log_gl("glBufferSubDataARB %d %d\n", offset, size);
-
- Buffer* buffer = _get_buffer(target);
- if (buffer)
- {
- assert(offset + size <= buffer->size);
- assert(buffer->ptr);
- memcpy(buffer->ptr + offset, data, size);
- }
- else
- {
- fprintf(stderr, "unknown buffer/buffer target : %d\n", target);
- }
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(offset), INT_TO_ARG(size), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, size };
- do_opengl_call(glBufferSubDataARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data)
-{
- glBufferSubDataARB(target, offset, size, data);
-}
-
-GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data)
-{
- CHECK_PROC(glGetBufferSubDataARB);
-
- Buffer* buffer = _get_buffer(target);
- if (!buffer) return;
-
- assert(offset + size <= buffer->size);
- assert(buffer->ptr);
-
- memcpy(data, buffer->ptr + offset, size);
-}
-
-GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data)
-{
- glGetBufferSubDataARB(target, offset, size, data);
-}
-
-GLvoid* glMapBufferARB (GLenum target, GLenum access)
-{
- CHECK_PROC_WITH_RET(glMapBufferARB);
-
- Buffer* buffer = _get_buffer(target);
- if (!buffer) return NULL;
- if (target == GL_PIXEL_PACK_BUFFER_EXT && (access == GL_READ_ONLY || access == GL_READ_WRITE))
- {
- int ret_int = 0;
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(buffer->size), POINTER_TO_ARG(buffer->ptr) };
- int args_size[] = { 0, 0, buffer->size };
- do_opengl_call(_glMapBufferARB_fake_func, &ret_int, CHECK_ARGS(args, args_size));
- if (ret_int == 0)
- return NULL;
- }
- buffer->access = access;
- buffer->mapped = 1;
- return buffer->ptr;
-}
-
-GLvoid* glMapBuffer(GLenum target, GLenum access)
-{
- return glMapBufferARB(target, access);
-}
-
-GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params)
-{
- CHECK_PROC(glGetBufferParameterivARB);
-
- Buffer* buffer = _get_buffer(target);
- if (!buffer) return;
-
- switch (pname)
- {
- case GL_BUFFER_SIZE_ARB: *params = buffer->size; break;
- case GL_BUFFER_USAGE_ARB: *params = buffer->usage; break;
- case GL_BUFFER_ACCESS_ARB: *params = buffer->access; break;
- case GL_BUFFER_MAPPED_ARB: *params = buffer->mapped; break;
- default:
- log_gl("unknown pname = 0x%X\n", pname);
- }
-}
-
-GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params)
-{
- glGetBufferParameterivARB(target, pname, params);
-}
-
-GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, GLvoid* *params)
-{
- CHECK_PROC(glGetBufferPointervARB);
- if (pname != GL_BUFFER_MAP_POINTER_ARB)
- {
- log_gl("glGetBufferPointervARB : unknown buffer data pname : %x\n", pname);
- return;
- }
- Buffer* buffer = _get_buffer(target);
- if (!buffer) return;
- if (buffer->mapped) *params = buffer->ptr; else *params = NULL;
-}
-
-GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params)
-{
- glGetBufferPointervARB(target, pname, params);
-}
-
-GLAPI GLboolean APIENTRY glUnmapBufferARB(GLenum target)
-{
- CHECK_PROC_WITH_RET(glUnmapBufferARB);
- Buffer* buffer = _get_buffer(target);
- if (!buffer) return 0;
- if (!buffer->mapped)
- {
- log_gl("unmapped buffer");
- return 0;
- }
- buffer->mapped = 0;
- if (buffer->access != GL_READ_ONLY)
- {
- glBufferSubDataARB(target, 0, buffer->size, buffer->ptr);
- }
- buffer->access = 0;
- return 1;
-}
-
-GLAPI GLboolean APIENTRY glUnmapBuffer(GLenum target)
-{
- return glUnmapBufferARB(target);
-}
-
-GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode )
-{
- long args[] = { INT_TO_ARG(list), INT_TO_ARG(mode) };
- GET_CURRENT_STATE();
- alloc_value(state->listAllocator, list);
- do_opengl_call(glNewList_func, NULL, args, NULL);
-}
-
-GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range )
-{
- long args[] = { INT_TO_ARG(list), INT_TO_ARG(range) };
- GET_CURRENT_STATE();
- delete_consecutive_values(state->listAllocator, list, range);
- do_opengl_call(glDeleteLists_func, NULL, args, NULL);
-}
-
-GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range )
-{
- GET_CURRENT_STATE();
- unsigned int firstValue = alloc_range(state->listAllocator, range, NULL);
- long args[] = { INT_TO_ARG(range) };
- do_opengl_call(glGenLists_fake_func, NULL, args, NULL);
- return firstValue;
-}
-
-GLAPI void APIENTRY glCallLists( GLsizei n,
- GLenum type,
- const GLvoid *lists )
-{
- long args[] = { INT_TO_ARG(n), INT_TO_ARG(type), POINTER_TO_ARG(lists) };
- int args_size[] = { 0, 0, 0 };
- int size = n;
- if (n <= 0) { log_gl("n <= 0\n"); return; }
- switch(type)
- {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- break;
-
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_2_BYTES:
- size *= 2;
- break;
-
- case GL_3_BYTES:
- size *= 3;
- break;
-
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- case GL_4_BYTES:
- size *= 4;
- break;
-
- default:
- log_gl("unsupported type = %d\n", type);
- return;
- }
- args_size[2] = size;
- do_opengl_call(glCallLists_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-
-static void removeUnwantedExtensions(char* ret)
-{
- char* toBeRemoved = getenv("GL_REMOVE_EXTENSIONS");
- if (toBeRemoved == NULL) return;
- toBeRemoved = strdup(toBeRemoved);
- char* iterToBeRemoved = toBeRemoved;
- while(*iterToBeRemoved)
- {
- char* cSpace = strchr(iterToBeRemoved, ' ');
- char* cComma = strchr(iterToBeRemoved, ',');
- char* c = (cSpace && cComma) ? MIN(cSpace, cComma) : (cSpace) ? cSpace : (cComma) ? cComma : NULL;
- if (c != NULL)
- {
- *c = 0;
- }
- if (!(*iterToBeRemoved == ' ' || *iterToBeRemoved == ',' || *iterToBeRemoved == 0))
- {
- log_gl("Trying to remove : %s (%d)\n", iterToBeRemoved, *iterToBeRemoved);
- char* c2 = strstr(ret, iterToBeRemoved);
- while (c2)
- {
- memset(c2, 'X', strlen(iterToBeRemoved));
- c2 = strstr(c2 + strlen(iterToBeRemoved), iterToBeRemoved);
- }
- }
- if (c == NULL)
- break;
- iterToBeRemoved = c + 1;
- }
- free(toBeRemoved);
-}
-
-#ifndef WIN32
-const char *glXQueryExtensionsString( Display *dpy, int screen )
-{
- LOCK(glXQueryExtensionsString_func);
- static char* ret = NULL;
- if (ret == NULL)
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen) };
- do_opengl_call_no_lock(glXQueryExtensionsString_func, &ret, args, NULL);
- ret = strdup(ret);
- removeUnwantedExtensions(ret);
- }
- UNLOCK(glXQueryExtensionsString_func);
- return ret;
-}
-
-
-typedef struct
-{
- XVisualInfo* vis;
- int visualid;
- GLXFBConfig fbconfig;
-} AssocVisualInfoVisualId;
-
-#define MAX_SIZE_TAB_ASSOC_VISUALINFO_VISUALID 100
-AssocVisualInfoVisualId tabAssocVisualInfoVisualId[MAX_SIZE_TAB_ASSOC_VISUALINFO_VISUALID];
-int nEltTabAssocVisualInfoVisualId = 0;
-
-static const char* _getAttribNameFromValue(int val)
-{
- int i;
- static char buffer[80];
- for(i=0;i<N_REQUESTED_ATTRIBS;i++)
- {
- if (tabRequestedAttribsPair[i].val == val)
- return tabRequestedAttribsPair[i].name;
- }
- sprintf(buffer, "(unknown name = %d, 0x%X)", val, val);
- return buffer;
-}
-
-static int _compute_length_of_attrib_list_including_zero(const int* attribList, int booleanMustHaveValue)
-{
- int i = 0;
- debug_gl = getenv("DEBUG_GL") != NULL;
- if (debug_gl) log_gl("attribList = \n");
- while(attribList[i])
- {
- if (booleanMustHaveValue ||
- !(attribList[i] == GLX_USE_GL ||
- attribList[i] == GLX_RGBA ||
- attribList[i] == GLX_DOUBLEBUFFER ||
- attribList[i] == GLX_STEREO))
- {
- if (debug_gl) log_gl("%s = %d\n", _getAttribNameFromValue(attribList[i]), attribList[i+1]);
- i+=2;
- }
- else
- {
- if (debug_gl) log_gl("%s\n", _getAttribNameFromValue(attribList[i]));
- i++;
- }
- }
- if (debug_gl) log_gl("\n");
- return i + 1;
-}
-
-
-XVisualInfo* glXChooseVisual( Display *dpy, int screen,
- int *attribList )
-{
- XVisualInfo temp, *vis;
- long mask;
- int n;
- int i;
-
- int visualid = 0;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen), POINTER_TO_ARG(attribList) };
- int args_size[] = { 0, 0, sizeof(int) * _compute_length_of_attrib_list_including_zero(attribList, 0) };
- do_opengl_call(glXChooseVisual_func, &visualid, CHECK_ARGS(args, args_size));
-
- if (visualid)
- {
- mask = VisualScreenMask | VisualDepthMask | VisualClassMask | VisualIDMask;
- temp.screen = screen;
- temp.depth = DefaultDepth(dpy,screen);
- temp.class = DefaultVisual(dpy,screen)->class;
- temp.visualid = DefaultVisual(dpy,screen)->visualid;
-
- vis = XGetVisualInfo( dpy, mask, &temp, &n );
- if (vis == NULL)
- log_gl("cannot get visual from client side\n");
-
- assert (nEltTabAssocVisualInfoVisualId < MAX_SIZE_TAB_ASSOC_VISUALINFO_VISUALID);
- for(i=0;i<nEltTabAssocVisualInfoVisualId;i++)
- {
- if (tabAssocVisualInfoVisualId[i].vis == vis) break;
- }
- if (i == nEltTabAssocVisualInfoVisualId)
- nEltTabAssocVisualInfoVisualId++;
- tabAssocVisualInfoVisualId[i].vis = vis;
- tabAssocVisualInfoVisualId[i].fbconfig = 0;
- tabAssocVisualInfoVisualId[i].visualid = visualid;
- }
- else
- {
- vis = NULL;
- }
-
- if (debug_gl) log_gl("glXChooseVisual returning vis %p (visualid=%d, 0x%X)\n", vis, visualid, visualid);
-
- return vis;
-}
-
-const char *glXQueryServerString( Display *dpy, int screen, int name )
-{
- LOCK(glXQueryServerString_func);
- static char* glXQueryServerString_ret[100] = {NULL};
- assert(name >= 0 && name < 100);
- if (glXQueryServerString_ret[name] == NULL)
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen), INT_TO_ARG(name) };
- do_opengl_call_no_lock(glXQueryServerString_func, &glXQueryServerString_ret[name], args, NULL);
- glXQueryServerString_ret[name] = strdup(glXQueryServerString_ret[name]);
- if (name == GLX_EXTENSIONS)
- {
- removeUnwantedExtensions(glXQueryServerString_ret[name]);
- }
- }
- UNLOCK(glXQueryServerString_func);
- return glXQueryServerString_ret[name];
-}
-
-const char *glXGetClientString( Display *dpy, int name )
-{
- LOCK(glXGetClientString_func);
- static char* glXGetClientString_ret[100] = {NULL};
- assert(name >= 0 && name < 100);
- if (glXGetClientString_ret[name] == NULL)
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(name) };
- do_opengl_call_no_lock(glXGetClientString_func, &glXGetClientString_ret[name], args, NULL);
- if (getenv("GLX_VENDOR") && name == GLX_VENDOR)
- {
- glXGetClientString_ret[name] = getenv("GLX_VENDOR");
- }
- else
- glXGetClientString_ret[name] = strdup(glXGetClientString_ret[name]);
- if (name == GLX_EXTENSIONS)
- {
- removeUnwantedExtensions(glXGetClientString_ret[name]);
- }
- }
- UNLOCK(glXGetClientString_func);
- return glXGetClientString_ret[name];
-}
-
-static void _create_context(GLXContext context, GLXContext shareList)
-{
- int i;
- glstates = realloc(glstates, (nbGLStates+1) * sizeof(GLState*));
- glstates[nbGLStates] = new_gl_state();
- glstates[nbGLStates]->ref = 1;
- glstates[nbGLStates]->context = context;
- glstates[nbGLStates]->shareList = shareList;
- glstates[nbGLStates]->pbuffer = 0;
- glstates[nbGLStates]->viewport.width = 0;
- if (shareList)
- {
- for(i=0; i<nbGLStates; i++)
- {
- if (glstates[i]->context == shareList)
- {
- glstates[i]->ref++;
- glstates[nbGLStates]->textureAllocator = glstates[i]->textureAllocator;
- glstates[nbGLStates]->bufferAllocator = glstates[i]->bufferAllocator;
- glstates[nbGLStates]->listAllocator = glstates[i]->listAllocator;
- break;
- }
- }
- if (i == nbGLStates)
- {
- log_gl("unknown shareList %p\n", (void*)shareList);
- }
- }
- nbGLStates++;
-}
-
-static GLXFBConfig* glXChooseFBConfig_no_lock( Display *dpy, int screen,
- const int *attribList, int *nitems );
-static XVisualInfo* glXGetVisualFromFBConfig_no_lock( Display *dpy, GLXFBConfig config );
-static GLXPbuffer glXCreatePbuffer_no_lock(Display *dpy,
- GLXFBConfig config,
- const int *attribList);
-
-GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
- GLXContext shareList, Bool direct )
-{
- LOCK(glXCreateContext_func);
- int isFbConfigVisual = 0;
- int i;
- int visualid = 0;
-
- for(i=0;i<nEltTabAssocVisualInfoVisualId;i++)
- {
- if (tabAssocVisualInfoVisualId[i].vis == vis)
- {
- if (tabAssocVisualInfoVisualId[i].fbconfig != NULL)
- {
- log_gl("isFbConfigVisual = 1\n");
- isFbConfigVisual = 1;
- }
- visualid = tabAssocVisualInfoVisualId[i].visualid;
- if (debug_gl) log_gl("found visualid %d corresponding to vis %p\n", visualid, vis);
- break;
- }
- }
-
- if (getenv("GET_IMG_FROM_SERVER"))
- {
- /* If the visual is already linked to a fbconfig, there's no use to create
- a new pbuffer ! */
- if (!isFbConfigVisual)
- {
- int nitems;
- int attribs[] = {
- GLX_DOUBLEBUFFER, True,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 8,
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
- None
- };
-
- GLXFBConfig* fbconfig = glXChooseFBConfig_no_lock(dpy,
- DefaultScreen( dpy ),
- attribs,
- &nitems);
- if (NULL == fbconfig) {
- log_gl("Error: couldn't get fbconfig\n");
- exit(1);
- }
-
- XVisualInfo *visinfo = glXGetVisualFromFBConfig_no_lock(dpy, fbconfig[0]);
- GLXContext ctxt = NULL;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(visinfo->visualid), INT_TO_ARG(shareList), INT_TO_ARG(direct) };
- do_opengl_call_no_lock(glXCreateContext_func, &ctxt, args, NULL);
-
- XFree(visinfo);
-
- if (ctxt)
- {
- _create_context(ctxt, shareList);
-
- int pbufAttrib[] = {
- GLX_PBUFFER_WIDTH, 1024,
- GLX_PBUFFER_HEIGHT, 1024,
- GLX_LARGEST_PBUFFER, GL_TRUE,
- None
- };
-
- glstates[nbGLStates-1]->isAssociatedToFBConfigVisual = isFbConfigVisual;
- glstates[nbGLStates-1]->pbuffer = glXCreatePbuffer_no_lock(dpy, fbconfig[0], pbufAttrib);
- assert(glstates[nbGLStates-1]->pbuffer);
- }
-
- XFree(fbconfig);
-
- goto end_of_create_context;
- }
- }
-
- GLXContext ctxt = NULL;
- if (i == nEltTabAssocVisualInfoVisualId)
- {
- visualid = vis->visualid;
- if (debug_gl) log_gl("not found vis %p in table, visualid=%d\n", vis, visualid);
- }
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(visualid), INT_TO_ARG(shareList), INT_TO_ARG(direct) };
- do_opengl_call_no_lock(glXCreateContext_func, &ctxt, args, NULL);
-
- if (ctxt)
- {
- _create_context(ctxt, shareList);
- glstates[nbGLStates-1]->isAssociatedToFBConfigVisual = isFbConfigVisual;
- }
-end_of_create_context:
- UNLOCK(glXCreateContext_func);
- return ctxt;
-}
-
-GLXContext glXGetCurrentContext (void)
-{
- GET_CURRENT_STATE();
- if (debug_gl) log_gl("glXGetCurrentContext() -> %p\n", state->context);
- return state->context;
-}
-
-GLXDrawable glXGetCurrentDrawable (void)
-{
- GET_CURRENT_STATE();
- if (debug_gl) log_gl("glXGetCurrentDrawable() -> %p\n", (void*)state->current_drawable);
- return state->current_drawable;
-}
-
-static void _free_context(Display* dpy, int i, GLState* state)
-{
- if (state->pbuffer) glXDestroyPbuffer(dpy, state->pbuffer);
- free(state->last_cursor.pixels);
- free(state->ownTextureAllocator.values);
- free(state->ownBufferAllocator.values);
- free(state->ownListAllocator.values);
- free(state);
- memmove(&state, &glstates[i+1], (nbGLStates-i-1) * sizeof(GLState*));
- nbGLStates--;
-}
-
-GLAPI void APIENTRY glXDestroyContext( Display *dpy, GLXContext ctx )
-{
- int i;
- LOCK(glXDestroyContext_func);
- GET_CURRENT_STATE();
- for(i=0;i<nbGLStates;i++)
- {
- if (glstates[i]->context == ctx)
- {
- long args[] = { POINTER_TO_ARG(dpy), POINTER_TO_ARG(ctx) };
- do_opengl_call_no_lock(glXDestroyContext_func, NULL, args, NULL);
- if (ctx == state->context)
- {
- SET_CURRENT_STATE(NULL);
- }
-
- GLXContext shareList = glstates[i]->shareList;
-
- glstates[i]->ref --;
- if (glstates[i]->ref == 0)
- {
- _free_context(dpy, i, glstates[i]);
- }
-
- if (shareList)
- {
- for(i=0; i<nbGLStates; i++)
- {
- if (glstates[i]->context == shareList)
- {
- glstates[i]->ref--;
- if (glstates[i]->ref == 0)
- {
- _free_context(dpy, i, glstates[i]);
- }
- break;
- }
- }
- }
- break;
- }
- }
- UNLOCK(glXDestroyContext_func);
-}
-
-Bool glXQueryVersion( Display *dpy, int *maj, int *min )
-{
- LOCK(glXQueryVersion_func);
- static Bool ret = -1;
- static int l_maj, l_min;
- if (ret == -1)
- {
- long args[] = { POINTER_TO_ARG(dpy), POINTER_TO_ARG(&l_maj), POINTER_TO_ARG(&l_min) };
- do_opengl_call_no_lock(glXQueryVersion_func, &ret, args, NULL);
- }
- if (maj) *maj = l_maj;
- if (min) *min = l_min;
- UNLOCK(glXQueryVersion_func);
- return ret;
-}
-
-
-static void _get_window_pos(Display *dpy, Window win, WindowPosStruct* pos)
-{
- XWindowAttributes window_attributes_return;
- Window child;
- int x, y;
- Window root = DefaultRootWindow(dpy);
- XGetWindowAttributes(dpy, win, &window_attributes_return);
- XTranslateCoordinates(dpy, win, root, 0, 0, &x, &y, &child);
- /*printf("%d %d %d %d\n", x, y, window_attributes_return.width, window_attributes_return.height);*/
- pos->x = x;
- pos->y = y;
- pos->width = window_attributes_return.width;
- pos->height = window_attributes_return.height;
- pos->map_state = window_attributes_return.map_state;
-}
-
-#define MAX_PBUFFERS 100
-
-/* Doit être appelé avec le lock */
-static void _move_win_if_necessary(Display *dpy, Window win)
-{
- GET_CURRENT_STATE();
- if ((int)win < MAX_PBUFFERS) /* FIXME */
- {
- return;
- }
-
- WindowPosStruct pos;
- _get_window_pos(dpy, win, &pos);
- if (memcmp(&pos, &state->oldPos, sizeof(state->oldPos)) != 0)
- {
- /* Host Window�� ��Ÿ���� �ʴ´�. if (pos.map_state != state->oldPos.map_state)
- {
- long args[] = { INT_TO_ARG(win), INT_TO_ARG(pos.map_state) };
- do_opengl_call_no_lock(_changeWindowState_func, NULL, args, NULL);
- }*/
- memcpy(&state->oldPos, &pos, sizeof(state->oldPos));
- long args[] = { INT_TO_ARG(win), POINTER_TO_ARG(&pos) };
- if (getenv("NO_MOVE"))
- {
- pos.x = 0;
- pos.y = 0;
- }
- do_opengl_call_no_lock(_moveResizeWindow_func, NULL, args, NULL);
- }
-}
-
-static Bool glXMakeCurrent_no_lock( Display *dpy, GLXDrawable drawable, GLXContext ctx)
-{
- Bool ret = False;
- int i;
-#if 0
- if (drawable == 0 && ctx == 0)
- return True;
- if (current_drawable == drawable && current_context == ctx) /* optimization */
- return True;
-#endif
- GET_CURRENT_STATE();
-
- if (!(drawable < MAX_PBUFFERS)) /* FIXME */
- {
- for(i=0; i<nbGLStates; i++)
- {
- if (glstates[i]->context == ctx && glstates[i]->viewport.width == 0)
- {
- XWindowAttributes window_attributes_return;
- XGetWindowAttributes(dpy, drawable, &window_attributes_return);
- glstates[i]->viewport.width = window_attributes_return.width;
- glstates[i]->viewport.height = window_attributes_return.height;
- if (debug_gl)
- log_gl("drawable 0x%X dim : %d x %d\n", (int)drawable, window_attributes_return.width,
- window_attributes_return.height);
- break;
- }
- }
- }
-
- if (getenv("GET_IMG_FROM_SERVER") && ctx != NULL)
- {
- for(i=0; i<nbGLStates; i++)
- {
- if (glstates[i]->context == ctx)
- {
- if (glstates[i]->pbuffer)
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(glstates[i]->pbuffer), INT_TO_ARG(ctx) };
- do_opengl_call_no_lock(glXMakeCurrent_func, NULL /*&ret*/, args, NULL);
- ret = True;
- }
- else
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(drawable), INT_TO_ARG(ctx) };
- do_opengl_call_no_lock(glXMakeCurrent_func, NULL /*&ret*/, args, NULL);
- ret = True;
- _move_win_if_necessary(dpy, drawable);
- }
- break;
- }
- }
- if (i == nbGLStates)
- {
- log_gl("unknown context %p\n", ctx);
- }
- }
- else
- {
- //log_gl("glXMakeCurrent %d %d\n", drawable, ctx);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(drawable), INT_TO_ARG(ctx) };
- do_opengl_call_no_lock(glXMakeCurrent_func, NULL /*&ret*/, args, NULL);
- ret = True;
- _move_win_if_necessary(dpy, drawable);
- }
-
- if (ret)
- {
- int i;
- if (ctx == 0)
- {
- state->context = NULL;
- }
- else
- {
- for(i=0; i<nbGLStates; i++)
- {
- if (glstates[i]->context == ctx)
- {
- state = glstates[i];
- SET_CURRENT_STATE(state);
- break;
- }
- }
- if (i == nbGLStates)
- {
- log_gl("cannot set current_gl_state\n");
- }
- }
-
- state->display = dpy;
- state->context = ctx;
- state->current_drawable = drawable;
- state->current_read_drawable = drawable;
- }
- return ret;
-}
-
-GLAPI Bool APIENTRY glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx)
-{
- Bool ret;
- LOCK(glXMakeCurrent_func);
- ret = glXMakeCurrent_no_lock(dpy, drawable, ctx);
- UNLOCK(glXMakeCurrent_func);
- return ret;
-}
-
-GLAPI void APIENTRY glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask )
-{
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(src), INT_TO_ARG(dst), INT_TO_ARG(mask) };
- do_opengl_call(glXCopyContext_func, NULL, args, NULL);
-}
-
-GLAPI Bool APIENTRY glXIsDirect( Display *dpy, GLXContext ctx )
-{
- Bool ret = False;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(ctx) };
- do_opengl_call(glXIsDirect_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI int APIENTRY glXGetConfig( Display *dpy, XVisualInfo *vis,
- int attrib, int *value )
-{
- int ret = 0;
- int i, j;
- if (vis == NULL || value == NULL) return 0;
- LOCK(glXGetConfig_func);
-
- int visualid = 0;
- for(i=0;i<nEltTabAssocVisualInfoVisualId;i++)
- {
- if (vis == tabAssocVisualInfoVisualId[i].vis)
- {
- visualid = tabAssocVisualInfoVisualId[i].visualid;
- if (debug_gl) log_gl("found visualid %d corresponding to vis %p\n", visualid, vis);
- break;
- }
- }
- if (i == nEltTabAssocVisualInfoVisualId)
- {
- if (debug_gl) log_gl("not found vis %p in table\n", vis);
- visualid = vis->visualid;
- }
-
- /* Optimization */
- for(i=0;i<nbConfigs;i++)
- {
- if (visualid == configs[i].visualid)
- {
- for(j=0;j<configs[i].nbAttribs;j++)
- {
- if (configs[i].attribs[j].attrib == attrib)
- {
- *value = configs[i].attribs[j].value;
- ret = configs[i].attribs[j].ret;
- if (debug_gl) log_gl("glXGetConfig(%s)=%d (%d)\n", _getAttribNameFromValue(attrib), *value, ret);
- goto end_of_glx_get_config;
- }
- }
- break;
- }
- }
-
- if (i < N_MAX_CONFIGS)
- {
- if (i == nbConfigs)
- {
- configs[i].visualid = visualid;
- configs[i].nbAttribs = 0;
- int tabGottenValues[N_REQUESTED_ATTRIBS];
- int tabGottenRes[N_REQUESTED_ATTRIBS];
- if (debug_gl) log_gl("glXGetConfig_extended visual=%p\n", vis);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(visualid), INT_TO_ARG(N_REQUESTED_ATTRIBS),
- POINTER_TO_ARG(getTabRequestedAttribsInt()), POINTER_TO_ARG(tabGottenValues),
- POINTER_TO_ARG(tabGottenRes) };
- int args_size[] = {0, 0, 0, N_REQUESTED_ATTRIBS*sizeof(int), N_REQUESTED_ATTRIBS*sizeof(int),
- N_REQUESTED_ATTRIBS*sizeof(int) };
- do_opengl_call_no_lock(glXGetConfig_extended_func, NULL, CHECK_ARGS(args, args_size));
-
- int j;
- int found = 0;
- int jDblBuffer = -1, jUseGL = -1;
- for(j=0;j<N_REQUESTED_ATTRIBS;j++)
- {
- if (GLX_USE_GL == tabRequestedAttribsPair[j].val)
- jUseGL = j;
- else if (GLX_DOUBLEBUFFER == tabRequestedAttribsPair[j].val)
- jDblBuffer = j;
- configs[i].attribs[j].attrib = tabRequestedAttribsPair[j].val;
- configs[i].attribs[j].value = tabGottenValues[j];
- configs[i].attribs[j].ret = tabGottenRes[j];
- configs[i].nbAttribs++;
- if (tabRequestedAttribsPair[j].val == attrib)
- {
- found = 1;
- *value = configs[i].attribs[j].value;
- ret = configs[i].attribs[j].ret;
- if (debug_gl) log_gl("glXGetConfig(%s)=%d (%d)\n", tabRequestedAttribsPair[j].name, *value, ret);
- }
- }
-
- if (getenv("DISABLE_DOUBLE_BUFFER"))
- {
- if (configs[i].attribs[jDblBuffer].value == 1)
- {
- if (attrib == GLX_USE_GL)
- *value = 0;
- configs[i].attribs[jUseGL].value = 0;
- }
- }
-
- nbConfigs++;
- if (found)
- goto end_of_glx_get_config;
- }
-
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(visualid), INT_TO_ARG(attrib), POINTER_TO_ARG(value) };
- do_opengl_call_no_lock(glXGetConfig_func, &ret, args, NULL);
- if (debug_gl) log_gl("glXGetConfig visual=%p, attrib=%d -> %d\n", vis, attrib, *value);
- if (configs[i].nbAttribs < N_MAX_ATTRIBS)
- {
- configs[i].attribs[configs[i].nbAttribs].attrib = attrib;
- configs[i].attribs[configs[i].nbAttribs].value = *value;
- configs[i].attribs[configs[i].nbAttribs].ret = ret;
- configs[i].nbAttribs++;
- }
- }
- }
- else
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(visualid), INT_TO_ARG(attrib), POINTER_TO_ARG(value) };
- do_opengl_call_no_lock(glXGetConfig_func, &ret, args, NULL);
- if (debug_gl) log_gl("glXGetConfig visual=%p, attrib=%d -> %d\n", vis, attrib, *value);
- }
-end_of_glx_get_config:
- UNLOCK(glXGetConfig_func);
- return ret;
-}
-
-#ifndef __CLIENT_WINDOW__
-/* Doit être appelé avec le lock */
-static void _send_cursor(Display* dpy, Window win)
-{
- GET_CURRENT_STATE();
- XFixesCursorImage* cursor = XFixesGetCursorImage(dpy);
- Window child_return, root_return;
- int root_x_return, root_y_return, win_x_return, win_y_return;
- unsigned int mask_return;
- XQueryPointer(dpy, win, &root_return, &child_return, &root_x_return, &root_y_return,
- &win_x_return, &win_y_return, &mask_return);
- cursor->x = win_x_return;
- cursor->y = win_y_return;
-
-
- if (cursor->width == state->last_cursor.width &&
- cursor->height == state->last_cursor.height &&
- cursor->xhot == state->last_cursor.xhot &&
- cursor->yhot == state->last_cursor.yhot &&
- memcmp(cursor->pixels, state->last_cursor.pixels, sizeof(long) * cursor->width * cursor->height) == 0)
- {
- if (!(cursor->x == state->last_cursor.x &&
- cursor->y == state->last_cursor.y))
- {
- long args[] = { INT_TO_ARG(cursor->x), INT_TO_ARG(cursor->y),
- INT_TO_ARG(cursor->width), INT_TO_ARG(cursor->height),
- INT_TO_ARG(cursor->xhot), INT_TO_ARG(cursor->yhot),
- 0 };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0 };
- do_opengl_call_no_lock(_send_cursor_func, NULL, CHECK_ARGS(args, args_size));
-
- state->last_cursor.x = cursor->x;
- state->last_cursor.y = cursor->y;
- }
- XFree(cursor);
- return;
- }
- int* data;
-
- /* Fun stuff about the 'pixels' field of XFixesCursorImage. It's a long instead of an int */
- /* The interface chosen for serialization is an array of int */
- if (sizeof(long) != sizeof(int))
- {
- data = malloc(sizeof(int) * cursor->width * cursor->height);
- int i;
- for(i=0;i<cursor->width*cursor->height;i++)
- {
- data[i] = (int)cursor->pixels[i];
- }
- }
- else
- {
- data = (int*)cursor->pixels;
- }
-
- long args[] = { INT_TO_ARG(cursor->x), INT_TO_ARG(cursor->y),
- INT_TO_ARG(cursor->width), INT_TO_ARG(cursor->height),
- INT_TO_ARG(cursor->xhot), INT_TO_ARG(cursor->yhot),
- POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, sizeof(int) * cursor->width * cursor->height };
- do_opengl_call_no_lock(_send_cursor_func, NULL, CHECK_ARGS(args, args_size));
-
- void* prev_ptr = state->last_cursor.pixels;
- memcpy(&state->last_cursor, cursor, sizeof(XFixesCursorImage));
- state->last_cursor.pixels = realloc(prev_ptr, sizeof(long) * cursor->width * cursor->height);
- memcpy(state->last_cursor.pixels, cursor->pixels, sizeof(long) * cursor->width * cursor->height);
-
- if (sizeof(long) != sizeof(int))
- {
- free(data);
- }
- XFree(cursor);
-}
-#endif
-
-static void glXSwapBuffers_no_lock( Display *dpy, GLXDrawable drawable )
-{
- //log_gl("glXSwapBuffers %d\n", drawable);
- int i;
-#ifdef __CLIENT_WINDOW__
- WindowImage *image = NULL;
-#else
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(drawable) };
- GET_CURRENT_STATE();
-#endif
-
-#ifndef __CLIENT_WINDOW__ /*Host window�� draw���� �ʴ´�.*/
- do_opengl_call_no_lock(glXSwapBuffers_func, NULL, args, NULL);
-#endif
-
- if (getenv("GET_IMG_FROM_SERVER") == NULL)
- {
- _move_win_if_necessary(dpy, drawable);
- }
-
-#ifndef __CLIENT_WINDOW__
- _send_cursor(dpy, drawable);
-
- if (limit_fps > 0)
- {
- if (state->last_swap_buffer_time.tv_sec != 0)
- {
- struct timeval current_time;
- gettimeofday(¤t_time, NULL);
- int diff_time = (current_time.tv_sec - state->last_swap_buffer_time.tv_sec) * 1000 + (current_time.tv_usec - state->last_swap_buffer_time.tv_usec) / 1000;
-
- if (diff_time < 1000 / limit_fps)
- {
- usleep( (1000 / limit_fps - diff_time) * 900);
- }
- }
- gettimeofday(&state->last_swap_buffer_time, NULL);
- }
-#endif
-
-#ifdef __CLIENT_WINDOW__
- for(i = 0; i < MAX_IMAGES; i++)
- {
- if( wImage[i].win == (Window)drawable )
- {
- image = &wImage[i];
- break;
- }
- }
-
- if( image && image->win )
- _draw_image(dpy, image->win, image);
-#endif
-
-}
-
-GLAPI void APIENTRY glXSwapBuffers( Display *dpy, GLXDrawable drawable )
-{
- LOCK(glXSwapBuffers_func);
- glXSwapBuffers_no_lock(dpy, drawable);
- UNLOCK(glXSwapBuffers_func);
-}
-
-GLAPI Bool APIENTRY glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
-{
- Bool ret;
- LOCK(glXQueryExtension_func);
- int fake_int;
- if (errorBase == NULL) errorBase = &fake_int;
- if (eventBase == NULL) eventBase = &fake_int;
- long args[] = { POINTER_TO_ARG(dpy), POINTER_TO_ARG(errorBase), POINTER_TO_ARG(eventBase) };
- do_opengl_call_no_lock(glXQueryExtension_func, &ret, args, NULL);
- UNLOCK(glXQueryExtension_func);
- return ret;
-}
-
-GLAPI void APIENTRY glXWaitGL (void)
-{
- int ret;
- do_opengl_call(glXWaitGL_func, &ret, NULL, NULL);
-}
-
-GLAPI void APIENTRY glXWaitX (void)
-{
- int ret;
- do_opengl_call(glXWaitX_func, &ret, NULL, NULL);
-}
-
-GLAPI Display* APIENTRY glXGetCurrentDisplay( void )
-{
- GET_CURRENT_STATE();
- return state->display;
-}
-
-static GLXFBConfig* glXChooseFBConfig_no_lock( Display *dpy, int screen,
- const int *attribList, int *nitems )
-{
- CHECK_PROC_WITH_RET(glXChooseFBConfig);
- GLXFBConfig* fbConfig = NULL;
- if (debug_gl) log_gl("glXChooseFBConfig\n");
- int i=0;
- int ret = 0;
- int emptyAttribList = None;
- if (attribList == NULL) attribList = &emptyAttribList;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen), POINTER_TO_ARG(attribList), POINTER_TO_ARG(nitems) };
- int args_size[] = { 0, 0, sizeof(int) * _compute_length_of_attrib_list_including_zero(attribList, 1), 0 };
- do_opengl_call_no_lock(glXChooseFBConfig_func, &ret, args, args_size);
- if (debug_gl) log_gl("nitems = %d\n", *nitems);
- if (*nitems == 0)
- return NULL;
- fbConfig = malloc(sizeof(GLXFBConfig) * (*nitems));
- for(i=0;i<*nitems;i++)
- {
- fbConfig[i] = (GLXFBConfig)(long)(ret + i);
- if (debug_gl && (i == 0 || i == *nitems-1)) log_gl("config %d = %d\n", i, ret+i);
- }
- return fbConfig;
-}
-
-GLAPI GLXFBConfig* APIENTRY glXChooseFBConfig( Display *dpy, int screen,
- const int *attribList, int *nitems )
-{
- GLXFBConfig* fbconfig;
- LOCK(glXChooseFBConfig_func);
- fbconfig = glXChooseFBConfig_no_lock(dpy, screen, attribList, nitems);
- UNLOCK(glXChooseFBConfig_func);
- return fbconfig;
-}
-
-GLAPI GLXFBConfigSGIX* APIENTRY glXChooseFBConfigSGIX( Display *dpy, int screen,
- const int *attribList, int *nitems )
-{
- CHECK_PROC_WITH_RET(glXChooseFBConfigSGIX);
- GLXFBConfigSGIX* fbConfig = NULL;
- if (debug_gl) log_gl("glXChooseFBConfigSGIX\n");
- int i = 0;
- int ret = 0;
- int emptyAttribList = None;
- if (attribList == NULL) attribList = &emptyAttribList;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen), POINTER_TO_ARG(attribList), POINTER_TO_ARG(nitems) };
- int args_size[] = { 0, 0, sizeof(int) * _compute_length_of_attrib_list_including_zero(attribList, 1), 0 };
- do_opengl_call(glXChooseFBConfigSGIX_func, &ret, args, args_size);
- if (debug_gl) log_gl("nitems = %d\n", *nitems);
- fbConfig = malloc(sizeof(GLXFBConfigSGIX) * (*nitems));
- for(i=0;i<*nitems;i++)
- {
- fbConfig[i] = (GLXFBConfig)(long)(ret + i);
- if (debug_gl && (i == 0 || i == *nitems-1)) log_gl("config %d = %d\n", i, ret+i);
- }
- return fbConfig;
-}
-
-GLAPI GLXFBConfig* APIENTRY glXGetFBConfigs( Display *dpy, int screen, int *nitems )
-{
- CHECK_PROC_WITH_RET(glXGetFBConfigs);
- if (debug_gl) log_gl("glXGetFBConfigs\n");
- int i = 0;
- GLXFBConfig* fbConfig;
- int ret = 0;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen), POINTER_TO_ARG(nitems) };
- do_opengl_call(glXGetFBConfigs_func, &ret, args, NULL);
- if (debug_gl) log_gl("nitems = %d\n", *nitems);
- fbConfig = malloc(sizeof(GLXFBConfig) * (*nitems));
- for(i=0;i<*nitems;i++)
- {
- fbConfig[i] = (GLXFBConfig)(long)(ret + i);
- if (debug_gl && (i == 0 || i == *nitems-1)) log_gl("config %d = %d\n", i, ret+i);
- }
- return fbConfig;
-}
-
-
-GLAPI int APIENTRY glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attrib, int *value)
-{
- CHECK_PROC_WITH_RET(glXGetFBConfigAttrib);
- LOCK(glXGetFBConfigAttrib_func);
- int ret = 0;
- int i, j;
-
- /* Optimization */
- for(i=0;i<nbFBConfigs;i++)
- {
- if (config == fbconfigs[i].config)
- {
- for(j=0;j<fbconfigs[i].nbAttribs;j++)
- {
- if (fbconfigs[i].attribs[j].attrib == attrib)
- {
- *value = fbconfigs[i].attribs[j].value;
- ret = fbconfigs[i].attribs[j].ret;
- if (debug_gl)
- {
- log_gl("glXGetFBConfigAttrib(config=%p,%s)=%d (%d)\n", config,
- _getAttribNameFromValue(attrib), *value, ret);
- }
- goto end_of_glx_get_fb_config_attrib;
- }
- }
- break;
- }
- }
-
- if (i < N_MAX_CONFIGS)
- {
- if (i == nbFBConfigs)
- {
- fbconfigs[i].config = config;
- fbconfigs[i].nbAttribs = 0;
- int tabGottenValues[N_REQUESTED_ATTRIBS];
- int tabGottenRes[N_REQUESTED_ATTRIBS];
- if (debug_gl) log_gl("glXGetFBConfigAttrib_extended config=%p\n", config);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(N_REQUESTED_ATTRIBS),
- POINTER_TO_ARG(getTabRequestedAttribsInt()), POINTER_TO_ARG(tabGottenValues),
- POINTER_TO_ARG(tabGottenRes) };
- int args_size[] = {0, 0, 0, N_REQUESTED_ATTRIBS*sizeof(int), N_REQUESTED_ATTRIBS*sizeof(int),
- N_REQUESTED_ATTRIBS*sizeof(int) };
- do_opengl_call_no_lock(glXGetFBConfigAttrib_extended_func, NULL, CHECK_ARGS(args, args_size));
-
- int j;
- int found = 0;
- for(j=0;j<N_REQUESTED_ATTRIBS;j++)
- {
- fbconfigs[i].attribs[j].attrib = tabRequestedAttribsPair[j].val;
- fbconfigs[i].attribs[j].value = tabGottenValues[j];
- fbconfigs[i].attribs[j].ret = tabGottenRes[j];
- fbconfigs[i].nbAttribs++;
- if (tabRequestedAttribsPair[j].val == attrib)
- {
- found = 1;
- *value = fbconfigs[i].attribs[j].value;
- ret = fbconfigs[i].attribs[j].ret;
- if (debug_gl) log_gl("glXGetFBConfigAttrib(config=%p, %s)=%d (%d)\n",
- config, tabRequestedAttribsPair[j].name, *value, ret);
- }
- }
- nbFBConfigs++;
- if (found)
- goto end_of_glx_get_fb_config_attrib;
- }
-
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(attrib), POINTER_TO_ARG(value) };
- do_opengl_call_no_lock(glXGetFBConfigAttrib_func, &ret, args, NULL);
- if (debug_gl) log_gl("glXGetFBConfigAttrib config=%p, attrib=%d -> %d\n", config, attrib, *value);
- if (fbconfigs[i].nbAttribs < N_MAX_ATTRIBS)
- {
- fbconfigs[i].attribs[fbconfigs[i].nbAttribs].attrib = attrib;
- fbconfigs[i].attribs[fbconfigs[i].nbAttribs].value = *value;
- fbconfigs[i].attribs[fbconfigs[i].nbAttribs].ret = ret;
- fbconfigs[i].nbAttribs++;
- }
- }
- }
- else
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(attrib), POINTER_TO_ARG(value) };
- do_opengl_call_no_lock(glXGetFBConfigAttrib_func, &ret, args, NULL);
- if (debug_gl) log_gl("glXGetFBConfigAttrib config=%p, attrib=%d -> %d\n", config, attrib, *value);
- }
-end_of_glx_get_fb_config_attrib:
- UNLOCK(glXGetFBConfigAttrib_func);
- return ret;
-}
-
-GLAPI int APIENTRY glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
-{
- CHECK_PROC_WITH_RET(glXGetFBConfigAttribSGIX);
- int ret = 0;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(attribute), POINTER_TO_ARG(value) };
- do_opengl_call(glXGetFBConfigAttribSGIX_func, &ret, args, NULL);
- if (debug_gl)
- {
- if (attribute < 0x20)
- log_gl("glXGetFBConfigAttribSGIX %p %d = %d\n", (void*)config, attribute, *value);
- else
- log_gl("glXGetFBConfigAttribSGIX %p 0x%X = %d\n", (void*)config, attribute, *value);
- }
- return ret;
-}
-
-GLAPI int APIENTRY glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
-{
- CHECK_PROC_WITH_RET(glXQueryContext);
- int ret = 0;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(ctx), INT_TO_ARG(attribute), POINTER_TO_ARG(value) };
- do_opengl_call(glXQueryContext_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI void APIENTRY glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, unsigned int *value )
-{
- CHECK_PROC(glXQueryDrawable);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(draw), INT_TO_ARG(attribute), POINTER_TO_ARG(value) };
- do_opengl_call(glXQueryDrawable_func, NULL, args, NULL);
-}
-
-GLAPI int APIENTRY glXQueryGLXPbufferSGIX( Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value )
-{
- CHECK_PROC_WITH_RET(glXQueryGLXPbufferSGIX);
- int ret = 0;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuf), INT_TO_ARG(attribute), POINTER_TO_ARG(value) };
- do_opengl_call(glXQueryGLXPbufferSGIX_func, &ret, args, NULL);
- return ret;
-}
-
-static GLXPbuffer glXCreatePbuffer_no_lock(Display *dpy,
- GLXFBConfig config,
- const int *attribList)
-{
- CHECK_PROC_WITH_RET(glXCreatePbuffer);
- if (debug_gl) log_gl("glXCreatePbuffer %p\n", (void*)config);
-
- GLXPbuffer pbuffer;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), POINTER_TO_ARG(attribList) };
- int args_size[] = { 0, 0, sizeof(int) * _compute_length_of_attrib_list_including_zero(attribList, 1)};
- do_opengl_call_no_lock(glXCreatePbuffer_func, &pbuffer, args, args_size);
-
- return pbuffer;
-}
-
-GLAPI GLXPbuffer APIENTRY glXCreatePbuffer(Display *dpy,
- GLXFBConfig config,
- const int *attribList)
-{
- GLXPbuffer pbuffer;
- LOCK(glXCreatePbuffer_func);
- pbuffer = glXCreatePbuffer_no_lock(dpy, config, attribList);
- UNLOCK(glXCreatePbuffer_func);
- return pbuffer;
-}
-
-GLAPI GLXPbufferSGIX APIENTRY glXCreateGLXPbufferSGIX( Display *dpy,
- GLXFBConfigSGIX config,
- unsigned int width,
- unsigned int height,
- int *attribList )
-{
- CHECK_PROC_WITH_RET(glXCreateGLXPbufferSGIX);
- if (debug_gl) log_gl("glXCreateGLXPbufferSGIX %p\n", (void*)config);
-
- GLXPbufferSGIX pbuffer;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(width), INT_TO_ARG(height), POINTER_TO_ARG(attribList) };
- int args_size[] = { 0, 0, 0, 0, sizeof(int) * _compute_length_of_attrib_list_including_zero(attribList, 1)};
- do_opengl_call(glXCreateGLXPbufferSGIX_func, &pbuffer, args, args_size);
-
- return pbuffer;
-}
-
-void glXBindTexImageATI(Display *dpy, GLXPbuffer pbuffer, int buffer)
-{
- CHECK_PROC(glXBindTexImageATI);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer), INT_TO_ARG(buffer) };
- do_opengl_call(glXBindTexImageATI_func, NULL, args, NULL);
-}
-
-void glXReleaseTexImageATI(Display *dpy, GLXPbuffer pbuffer, int buffer)
-{
- CHECK_PROC(glXReleaseTexImageATI);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer), INT_TO_ARG(buffer) };
- do_opengl_call(glXReleaseTexImageATI_func, NULL, args, NULL);
-}
-
-Bool glXBindTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer)
-{
- Bool ret = 0;
- CHECK_PROC_WITH_RET(glXBindTexImageARB);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer), INT_TO_ARG(buffer) };
- do_opengl_call(glXBindTexImageARB_func, &ret, args, NULL);
- return ret;
-}
-
-Bool glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer)
-{
- Bool ret = 0;
- CHECK_PROC_WITH_RET(glXReleaseTexImageARB);
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer), INT_TO_ARG(buffer) };
- do_opengl_call(glXReleaseTexImageARB_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI void APIENTRY glXDestroyPbuffer(Display* dpy, GLXPbuffer pbuffer)
-{
- CHECK_PROC(glXDestroyPbuffer);
- if (debug_gl) log_gl("glXDestroyPbuffer %d\n", (int)pbuffer);
-
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer) };
- do_opengl_call(glXDestroyPbuffer_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glXDestroyGLXPbufferSGIX(Display* dpy, GLXPbufferSGIX pbuffer)
-{
- CHECK_PROC(glXDestroyGLXPbufferSGIX);
- if (debug_gl) log_gl("glXDestroyGLXPbufferSGIX %d\n", (int)pbuffer);
-
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(pbuffer) };
- do_opengl_call(glXDestroyGLXPbufferSGIX_func, NULL, args, NULL);
-}
-
-static XVisualInfo* glXGetVisualFromFBConfig_no_lock( Display *dpy, GLXFBConfig config )
-{
- CHECK_PROC_WITH_RET(glXGetVisualFromFBConfig);
- int screen = 0;
-
- if (debug_gl) log_gl("glXGetVisualFromFBConfig %p\n", (void*)config);
-
- XVisualInfo temp, *vis;
- long mask;
- int n;
- int i;
-
- mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
- temp.screen = screen;
- temp.depth = DefaultDepth(dpy,screen);
- temp.class = DefaultVisual(dpy,screen)->class;
- temp.visualid = DefaultVisual(dpy,screen)->visualid;
- mask |= VisualIDMask;
-
- vis = XGetVisualInfo( dpy, mask, &temp, &n );
-
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config)};
- int visualid;
- do_opengl_call_no_lock(glXGetVisualFromFBConfig_func, &visualid, args, NULL);
-
- /*host vid�� tabAssocVisualInfoVisualId[]�� �����Ͽ� ��������� guest vi�� ����� �ʿ� ����*/
- /*vis->visualid = visualid;*/
-
- assert (nEltTabAssocVisualInfoVisualId < MAX_SIZE_TAB_ASSOC_VISUALINFO_VISUALID);
- for(i=0;i<nEltTabAssocVisualInfoVisualId;i++)
- {
- if (tabAssocVisualInfoVisualId[i].vis == vis) break;
- }
- if (i == nEltTabAssocVisualInfoVisualId)
- nEltTabAssocVisualInfoVisualId++;
- tabAssocVisualInfoVisualId[i].vis = vis;
- tabAssocVisualInfoVisualId[i].fbconfig = config;
- tabAssocVisualInfoVisualId[i].visualid = visualid;
-
- if (debug_gl) log_gl("glXGetVisualFromFBConfig returning vis %p (visualid=%d, 0x%X)\n", vis, visualid, visualid);
-
- return vis;
-}
-
-GLAPI XVisualInfo* APIENTRY glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
-{
- XVisualInfo* vis;
- LOCK(glXGetVisualFromFBConfig_func);
- vis = glXGetVisualFromFBConfig_no_lock(dpy, config);
- UNLOCK(glXGetVisualFromFBConfig_func);
- return vis;
-}
-
-GLAPI GLXContext APIENTRY glXCreateNewContext(Display * dpy,
- GLXFBConfig fbconfig,
- int renderType,
- GLXContext shareList,
- Bool direct)
-{
- CHECK_PROC_WITH_RET(glXCreateNewContext);
- LOCK(glXCreateNewContext_func);
- if (debug_gl) log_gl("glXCreateNewContext %p\n", (void*)fbconfig);
-
- GLXContext ctxt;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(fbconfig), INT_TO_ARG(renderType), INT_TO_ARG(shareList),
- INT_TO_ARG(direct) };
- do_opengl_call_no_lock(glXCreateNewContext_func, &ctxt, args, NULL);
- if (ctxt)
- {
- _create_context(ctxt, shareList);
- if (getenv("GET_IMG_FROM_SERVER"))
- {
- int pbufAttrib[] = {
- GLX_PBUFFER_WIDTH, 1024,
- GLX_PBUFFER_HEIGHT, 1024,
- GLX_LARGEST_PBUFFER, GL_TRUE,
- None
- };
- glstates[nbGLStates-1]->pbuffer = glXCreatePbuffer(dpy, fbconfig, pbufAttrib);
- assert(glstates[nbGLStates-1]->pbuffer);
- }
- }
- UNLOCK(glXCreateNewContext_func);
- return ctxt;
-}
-
-GLAPI Bool APIENTRY glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
- GLXDrawable read, GLXContext ctx )
-{
- Bool ret;
- GET_CURRENT_STATE();
- if (draw != read)
- {
- static int first_time = 1;
- if (first_time)
- {
- first_time = 0;
- log_gl("using glXMakeCurrent instead of real glXMakeContextCurrent... may help some program work...\n");
- }
- }
- ret = glXMakeCurrent(dpy, draw, ctx);
- if (ret)
- state->current_read_drawable = read;
- return ret;
-}
-
-GLAPI GLXContext APIENTRY glXCreateContextWithConfigSGIX( Display *dpy,
- GLXFBConfigSGIX config,
- int renderType,
- GLXContext shareList,
- Bool direct )
-{
- CHECK_PROC_WITH_RET(glXCreateContextWithConfigSGIX);
- if (debug_gl) log_gl("glXCreateContextWithConfigSGIX %p\n", (void*)config);
-
- GLXContext ctxt;
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(config), INT_TO_ARG(renderType), INT_TO_ARG(shareList),
- INT_TO_ARG(direct) };
- do_opengl_call(glXCreateContextWithConfigSGIX_func, &ctxt, args, NULL);
- return ctxt;
-}
-
-GLAPI GLXWindow APIENTRY glXCreateWindow( Display *dpy, GLXFBConfig config, Window win, const int *attribList )
-{
- CHECK_PROC_WITH_RET(glXCreateWindow);
- /* do nothing. Not sure about this implementation. FIXME */
-
-#ifdef __CLIENT_WINDOW__
- int i;
- WindowImage *image = NULL;
-
- for(i = 0; i < MAX_IMAGES; i++)
- {
- if( wImage[i].win == 0 && image == NULL )
- {
- image = &wImage[i];
- break;
- }
- else if( wImage[i].win == win )
- {
- image = &wImage[i];
- return (GLXWindow)win;
- }
- }
-
- if( image )
- {
- image->win_gc = XCreateGC(dpy, win, 0, NULL);
- if( image->win_gc == NULL )
- {
- log_gl("Winodow GC Create Fail \n");
- return (GLXWindow)win;
- }
-
- if( _create_image(dpy, win, image) == False )
- {
- XFreeGC(dpy, image->win_gc);
- image->win_gc = NULL;
- log_gl("Window Image Create Fail \n");
- return (GLXWindow)win;
- }
- }
-#endif
-
- return (GLXWindow)win;
-}
-
-GLAPI void APIENTRY glXDestroyWindow( Display *dpy, GLXWindow window )
-{
- CHECK_PROC(glXDestroyWindow);
- /* Destroy Sub-Window of Host OS */
-
-#ifdef __CLIENT_WINDOW__
- int i;
- WindowImage *image = NULL;
-
- if (debug_gl) log_gl("glXDestroyWindow %d\n", (int)window);
-
- for(i = 0; i < MAX_IMAGES; i++)
- {
- if( wImage[i].win == (Window)window )
- {
- image = &wImage[i];
- break;
- }
- }
-
- if( image && image->win)
- {
- _destroy_image(dpy, image);
-
- XFreeGC(dpy, image->win_gc);
- image->win_gc = NULL;
- }
-#endif
-
- if ( window ) {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(window) };
- do_opengl_call(glXDestroyWindow_func, NULL, args, NULL);
- }
-}
-
-GLAPI GLXPixmap APIENTRY glXCreateGLXPixmap( Display *dpy,
- XVisualInfo *vis,
- Pixmap pixmap )
-{
- CHECK_PROC_WITH_RET(glXCreateGLXPixmap);
- /* FIXME */
- log_gl("glXCreateGLXPixmap : sorry, unsupported call and I don't really see how I could implement it...");
- return 0;
-}
-
-GLAPI void APIENTRY glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
-{
- CHECK_PROC(glXDestroyGLXPixmap);
- /* FIXME */
- log_gl("glXDestroyGLXPixmap : sorry, unsupported call and I don't really see how I could implement it...");
-}
-
-GLAPI GLXPixmap APIENTRY glXCreatePixmap( Display *dpy, GLXFBConfig config,
- Pixmap pixmap, const int *attribList )
-{
- CHECK_PROC_WITH_RET(glXCreatePixmap);
- /* FIXME */
- log_gl("glXCreatePixmap : sorry, unsupported call and I don't really see how I could implement it...");
- return 0;
-}
-
-GLAPI void APIENTRY glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
-{
- CHECK_PROC(glXDestroyPixmap);
- /* FIXME */
- log_gl("glXDestroyPixmap : sorry, unsupported call and I don't really see how I could implement it...");
-}
-
-GLAPI GLXDrawable APIENTRY glXGetCurrentReadDrawable( void )
-{
- CHECK_PROC_WITH_RET(glXGetCurrentReadDrawable);
- GET_CURRENT_STATE();
- return state->current_read_drawable;
-}
-
-GLAPI void APIENTRY glXSelectEvent( Display *dpy, GLXDrawable drawable,
- unsigned long mask )
-{
- CHECK_PROC(glXSelectEvent);
- log_gl("glXSelectEvent : sorry, unsupported call");
-}
-
-GLAPI void APIENTRY glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
- unsigned long *mask )
-{
- CHECK_PROC(glXGetSelectedEvent);
- log_gl("glXGetSelectedEvent : sorry, unsupported call");
-}
-
-
-#include "opengl_client_xfonts.c"
-
-GLAPI const char * APIENTRY EXT_FUNC(glXGetScreenDriver) (Display *dpy, int screen)
-{
- static const char* ret = NULL;
- LOCK(glXGetScreenDriver_func);
- CHECK_PROC_WITH_RET(glXGetScreenDriver);
- if (ret == NULL)
- {
- long args[] = { POINTER_TO_ARG(dpy), INT_TO_ARG(screen) };
- do_opengl_call_no_lock(glXGetScreenDriver_func, &ret, args, NULL);
- ret = strdup(ret);
- }
- UNLOCK(glXGetScreenDriver_func);
- return ret;
-}
-
-GLAPI const char * APIENTRY EXT_FUNC(glXGetDriverConfig) (const char *drivername)
-{
- static const char* ret = NULL;
- CHECK_PROC_WITH_RET(glXGetDriverConfig);
- long args[] = { POINTER_TO_ARG(drivername) };
- if (ret) free((void*)ret);
- do_opengl_call(glXGetDriverConfig_func, &ret, args, NULL);
- ret = strdup(ret);
- return ret;
-}
-
-/* For googleearth */
-static int counterSync = 0;
-
-GLAPI int APIENTRY EXT_FUNC(glXWaitVideoSyncSGI) ( int divisor, int remainder, unsigned int *count )
-{
- CHECK_PROC_WITH_RET(glXWaitVideoSyncSGI);
- //log_gl("glXWaitVideoSyncSGI %d %d\n", divisor, remainder);
- *count = counterSync++; // FIXME ?
- return 0;
-}
-
-GLAPI int APIENTRY EXT_FUNC(glXGetVideoSyncSGI)( unsigned int *count )
-{
- CHECK_PROC_WITH_RET(glXGetVideoSyncSGI);
- //log_gl("glXGetVideoSyncSGI\n");
- *count = counterSync++; // FIXME ?
- return 0;
-}
-
-GLAPI int APIENTRY EXT_FUNC(glXSwapIntervalSGI) ( int interval )
-{
- CHECK_PROC_WITH_RET(glXSwapIntervalSGI);
- long args[] = { INT_TO_ARG(interval) };
- int ret = 0;
- do_opengl_call(glXSwapIntervalSGI_func, &ret, args, NULL);
- //log_gl("glXSwapIntervalSGI(%d) = %d\n", interval, ret);
- return ret;
-}
-
-#endif
-
-GLAPI const GLubyte * APIENTRY glGetString( GLenum name )
-{
- int i;
- static GLubyte* glStrings[6] = {NULL};
- static const char* glGetStringsName[] = {
- "GL_VENDOR",
- "GL_RENDERER",
- "GL_VERSION",
- "GL_EXTENSIONS",
- "GL_SHADING_LANGUAGE_VERSION",
- };
-
- if (name >= GL_VENDOR && name <= GL_EXTENSIONS)
- i = name - GL_VENDOR;
- else if (name == GL_SHADING_LANGUAGE_VERSION)
- i = 4;
- else if (name == GL_PROGRAM_ERROR_STRING_NV)
- i = 5;
- else
- {
- log_gl("assert(name >= GL_VENDOR && name <= GL_EXTENSIONS || name == GL_SHADING_LANGUAGE_VERSION || name == GL_PROGRAM_ERROR_STRING_NV)\n");
- return NULL;
- }
- LOCK(glGetString_func);
- if (glStrings[i] == NULL)
- {
- if (i <= 4 && getenv(glGetStringsName[i]))
- {
- glStrings[i] = getenv(glGetStringsName[i]);
- }
- else
- {
- long args[] = { INT_TO_ARG(name) };
- do_opengl_call_no_lock(glGetString_func, &glStrings[i], args, NULL);
- }
-
- log_gl("glGetString(0x%X) = %s\n", name, glStrings[i]);
- glStrings[name - GL_VENDOR] = strdup((char*)glStrings[i]);
- if (name == GL_EXTENSIONS)
- {
- removeUnwantedExtensions(glStrings[i]);
- }
- }
- UNLOCK(glGetString_func);
- return glStrings[i];
-}
-
-#define CASE_GL_PIXEL_MAP(x) case GL_PIXEL_MAP_##x: glGetIntegerv_no_lock(CONCAT(GL_PIXEL_MAP_##x,_SIZE), &value); return value;
-
-static int get_glgetpixelmapv_size(int map)
-{
- int value;
- switch (map)
- {
- LOCK(glGetIntegerv_func);
- CASE_GL_PIXEL_MAP(I_TO_I);
- CASE_GL_PIXEL_MAP(S_TO_S);
- CASE_GL_PIXEL_MAP(I_TO_R);
- CASE_GL_PIXEL_MAP(I_TO_G);
- CASE_GL_PIXEL_MAP(I_TO_B);
- CASE_GL_PIXEL_MAP(I_TO_A);
- CASE_GL_PIXEL_MAP(R_TO_R);
- CASE_GL_PIXEL_MAP(G_TO_G);
- CASE_GL_PIXEL_MAP(B_TO_B);
- CASE_GL_PIXEL_MAP(A_TO_A);
- UNLOCK(glGetIntegerv_func);
- default :
- {
- log_gl("unhandled map = %d\n", map);
- return 0;
- }
- }
-}
-
-GLAPI void APIENTRY glGetPixelMapfv( GLenum map, GLfloat *values )
-{
- long args[] = { INT_TO_ARG(map), POINTER_TO_ARG(values) };
- int args_size[] = { 0, get_glgetpixelmapv_size(map) * sizeof(float) };
- if (args_size[1] == 0) return;
- do_opengl_call(glGetPixelMapfv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glGetPixelMapuiv( GLenum map, GLuint *values )
-{
- long args[] = { INT_TO_ARG(map), POINTER_TO_ARG(values) };
- int args_size[] = { 0, get_glgetpixelmapv_size(map) * sizeof(int) };
- if (args_size[1] == 0) return;
- do_opengl_call(glGetPixelMapuiv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glGetPixelMapusv( GLenum map, GLushort *values )
-{
- long args[] = { INT_TO_ARG(map), POINTER_TO_ARG(values) };
- int args_size[] = { 0, get_glgetpixelmapv_size(map) * sizeof(short) };
- if (args_size[1] == 0) return;
- do_opengl_call(glGetPixelMapusv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-static int glMap1_get_multiplier(GLenum target)
-{
- switch (target)
- {
- case GL_MAP1_VERTEX_3:
- case GL_MAP1_NORMAL:
- case GL_MAP1_TEXTURE_COORD_3:
- return 3;
- break;
-
- case GL_MAP1_VERTEX_4:
- case GL_MAP1_COLOR_4:
- case GL_MAP1_TEXTURE_COORD_4:
- return 4;
- break;
-
- case GL_MAP1_INDEX:
- case GL_MAP1_TEXTURE_COORD_1:
- return 1;
- break;
-
- case GL_MAP1_TEXTURE_COORD_2:
- return 2;
- break;
-
- default:
- if (target >= GL_MAP1_VERTEX_ATTRIB0_4_NV && target <= GL_MAP1_VERTEX_ATTRIB15_4_NV)
- return 4;
- log_gl("unhandled target = %d\n", target);
- return 0;
- }
-}
-
-
-static int glMap2_get_multiplier(GLenum target)
-{
- switch (target)
- {
- case GL_MAP2_VERTEX_3:
- case GL_MAP2_NORMAL:
- case GL_MAP2_TEXTURE_COORD_3:
- return 3;
- break;
-
- case GL_MAP2_VERTEX_4:
- case GL_MAP2_COLOR_4:
- case GL_MAP2_TEXTURE_COORD_4:
- return 4;
- break;
-
- case GL_MAP2_INDEX:
- case GL_MAP2_TEXTURE_COORD_1:
- return 1;
- break;
-
- case GL_MAP2_TEXTURE_COORD_2:
- return 2;
- break;
-
- default:
- if (target >= GL_MAP2_VERTEX_ATTRIB0_4_NV && target <= GL_MAP2_VERTEX_ATTRIB15_4_NV)
- return 4;
- log_gl("unhandled target = %d\n", target);
- return 0;
- }
-}
-
-static int get_dimensionnal_evaluator(GLenum target)
-{
- switch(target)
- {
- case GL_MAP1_COLOR_4:
- case GL_MAP1_INDEX:
- case GL_MAP1_NORMAL:
- case GL_MAP1_TEXTURE_COORD_1:
- case GL_MAP1_TEXTURE_COORD_2:
- case GL_MAP1_TEXTURE_COORD_3:
- case GL_MAP1_TEXTURE_COORD_4:
- case GL_MAP1_VERTEX_3:
- case GL_MAP1_VERTEX_4:
- return 1;
-
- case GL_MAP2_COLOR_4:
- case GL_MAP2_INDEX:
- case GL_MAP2_NORMAL:
- case GL_MAP2_TEXTURE_COORD_1:
- case GL_MAP2_TEXTURE_COORD_2:
- case GL_MAP2_TEXTURE_COORD_3:
- case GL_MAP2_TEXTURE_COORD_4:
- case GL_MAP2_VERTEX_3:
- case GL_MAP2_VERTEX_4:
- return 2;
-
- default:
- log_gl("unhandled target %d\n", target);
- return 0;
- }
-}
-
-GLAPI void APIENTRY glMap1f( GLenum target,
- GLfloat u1,
- GLfloat u2,
- GLint stride,
- GLint order,
- const GLfloat *points )
-{
- long args[] = { INT_TO_ARG(target), FLOAT_TO_ARG(u1), FLOAT_TO_ARG(u2),
- INT_TO_ARG(stride), INT_TO_ARG(order), POINTER_TO_ARG(points) };
- int args_size[] = { 0, 0, 0, 0, 0, 0 };
- int num_points = order;
- int multiplier = glMap1_get_multiplier(target);
- if (multiplier)
- {
- num_points *= multiplier;
- args_size[5] = num_points * sizeof(float);
- do_opengl_call(glMap1f_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-GLAPI void APIENTRY glMap1d( GLenum target,
- GLdouble u1,
- GLdouble u2,
- GLint stride,
- GLint order,
- const GLdouble *points )
-{
- long args[] = { INT_TO_ARG(target), DOUBLE_TO_ARG(u1), DOUBLE_TO_ARG(u2),
- INT_TO_ARG(stride), INT_TO_ARG(order), POINTER_TO_ARG(points) };
- int args_size[] = { 0, 0, 0, 0, 0, 0 };
- int num_points = order;
- int multiplier = glMap1_get_multiplier(target);
- if (multiplier)
- {
- num_points *= multiplier;
- args_size[5] = num_points * sizeof(double);
- do_opengl_call(glMap1d_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-GLAPI void APIENTRY glMap2f( GLenum target,
- GLfloat u1,
- GLfloat u2,
- GLint ustride,
- GLint uorder,
- GLfloat v1,
- GLfloat v2,
- GLint vstride,
- GLint vorder,
- const GLfloat *points )
-{
- long args[] = { INT_TO_ARG(target),
- FLOAT_TO_ARG(u1), FLOAT_TO_ARG(u2),
- INT_TO_ARG(ustride), INT_TO_ARG(uorder),
- FLOAT_TO_ARG(v1), FLOAT_TO_ARG(v2),
- INT_TO_ARG(vstride), INT_TO_ARG(vorder),
- POINTER_TO_ARG(points) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- int num_points = uorder * vorder;
- int multiplier = glMap2_get_multiplier(target);
- if (multiplier)
- {
- num_points *= multiplier;
- args_size[9] = num_points * sizeof(float);
- do_opengl_call(glMap2f_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-
-GLAPI void APIENTRY glMap2d( GLenum target,
- GLdouble u1,
- GLdouble u2,
- GLint ustride,
- GLint uorder,
- GLdouble v1,
- GLdouble v2,
- GLint vstride,
- GLint vorder,
- const GLdouble *points )
-{
- long args[] = { INT_TO_ARG(target),
- DOUBLE_TO_ARG(u1), DOUBLE_TO_ARG(u2),
- INT_TO_ARG(ustride), INT_TO_ARG(uorder),
- DOUBLE_TO_ARG(v1), DOUBLE_TO_ARG(v2),
- INT_TO_ARG(vstride), INT_TO_ARG(vorder),
- POINTER_TO_ARG(points) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- int num_points = uorder * vorder;
- int multiplier = glMap2_get_multiplier(target);
- if (multiplier)
- {
- num_points *= multiplier;
- args_size[9] = num_points * sizeof(double);
- do_opengl_call(glMap2d_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-static int _glGetMapv_get_n_components( GLenum target, GLenum query)
-{
- int dim = get_dimensionnal_evaluator(target);
- if (query == GL_COEFF)
- {
- int orders[2] = { 1, 1 };
- glGetMapiv(target, GL_ORDER, orders);
- return orders[0] * orders[1] * ((dim == 1) ? glMap1_get_multiplier(target) : glMap2_get_multiplier(target));
- }
- else if (query == GL_ORDER)
- {
- return dim;
- }
- else if (query == GL_DOMAIN)
- {
- return 2 * dim;
- }
- else
- return 0;
-}
-
-
-GLAPI void APIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v )
-{
- int dim = get_dimensionnal_evaluator(target);
- if (dim == 0) return;
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(query), POINTER_TO_ARG(v) };
- int args_size[] = { 0, 0, _glGetMapv_get_n_components(target, query) * sizeof(double) };
- do_opengl_call(glGetMapdv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v )
-{
- int dim = get_dimensionnal_evaluator(target);
- if (dim == 0) return;
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(query), POINTER_TO_ARG(v) };
- int args_size[] = { 0, 0, _glGetMapv_get_n_components(target, query) * sizeof(float) };
- do_opengl_call(glGetMapfv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v )
-{
- int dim = get_dimensionnal_evaluator(target);
- if (dim == 0) return;
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(query), POINTER_TO_ARG(v) };
- int args_size[] = { 0, 0, _glGetMapv_get_n_components(target, query) * sizeof(int) };
- do_opengl_call(glGetMapiv_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-
-GLAPI void APIENTRY glBindTexture(GLenum target, GLuint texture)
-{
- CHECK_PROC(glBindTexture);
- GET_CURRENT_STATE();
- alloc_value(state->textureAllocator, texture);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(texture) };
- if (target == GL_TEXTURE_2D)
- {
- state->current_server_state.bindTexture2D = texture;
- }
- else if (target == GL_TEXTURE_RECTANGLE_ARB)
- {
- state->current_server_state.bindTextureRectangle = texture;
- }
- do_opengl_call(glBindTexture_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glBindTextureEXT) (GLenum target, GLuint texture)
-{
- glBindTexture(target, texture);
-}
-
-
-GLAPI void APIENTRY glGenTextures( GLsizei n, GLuint *textures )
-{
- CHECK_PROC(glGenTextures);
- GET_CURRENT_STATE();
- if (n <= 0) { log_gl("n <= 0\n"); return; }
- alloc_range(state->textureAllocator, n, textures);
- long args[] = { n };
- do_opengl_call(glGenTextures_fake_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glGenTexturesEXT( GLsizei n, GLuint *textures )
-{
- glGenTextures(n, textures);
-}
-
-GLAPI void APIENTRY glDeleteTextures ( GLsizei n, const GLuint *textures )
-{
- CHECK_PROC(glDeleteTextures);
- GET_CURRENT_STATE();
- if (n <= 0) { log_gl("n <= 0\n"); return; }
- delete_range(state->textureAllocator, n, textures);
- long args[] = { INT_TO_ARG(n), POINTER_TO_ARG(textures) };
- do_opengl_call(glDeleteTextures_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glDeleteTexturesEXT ( GLsizei n, const GLuint *textures )
-{
- glDeleteTextures(n, textures);
-}
-
-static int getTexImageTypeSizeSimple(int format, int type)
-{
- switch (type)
- {
- case GL_UNSIGNED_BYTE:
- case GL_BYTE:
- return 1;
-
- case GL_UNSIGNED_SHORT:
- case GL_SHORT:
- return 2;
-
- case GL_UNSIGNED_INT:
- case GL_INT:
- case GL_UNSIGNED_INT_24_8_EXT:
- case GL_FLOAT:
- return 4;
-
- default:
- log_gl("unknown texture type %d for texture format %d\n", type, format);
- return 0;
- }
-}
-
-static int getTexImageFactorFromFormatAndType(int format, int type)
-{
- switch (format)
- {
- case GL_COLOR_INDEX:
- case GL_RED:
- case GL_GREEN:
- case GL_BLUE:
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_INTENSITY:
- case GL_DEPTH_COMPONENT:
- case GL_STENCIL_INDEX:
- case GL_DEPTH_STENCIL_EXT:
- return 1 * getTexImageTypeSizeSimple(format, type);
- break;
-
- case GL_LUMINANCE_ALPHA:
- return 2 * getTexImageTypeSizeSimple(format, type);
- break;
-
- case GL_YCBCR_MESA:
- {
- switch (type)
- {
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- return 2;
-
- default:
- log_gl("unknown texture type %d for texture format %d\n", type, format);
- return 0;
- }
- }
-
- case GL_RGB:
- case GL_BGR:
- {
- switch (type)
- {
- case GL_UNSIGNED_BYTE:
- case GL_BYTE:
- return 1 * 3;
-
- case GL_UNSIGNED_SHORT:
- case GL_SHORT:
- return 2 * 3;
-
- case GL_UNSIGNED_INT:
- case GL_INT:
- case GL_FLOAT:
- return 4 * 3;
-
- case GL_UNSIGNED_BYTE_3_3_2:
- case GL_UNSIGNED_BYTE_2_3_3_REV:
- return 1;
-
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_5_6_5_REV:
- case GL_UNSIGNED_SHORT_8_8_MESA:
- case GL_UNSIGNED_SHORT_8_8_REV_MESA:
- return 2;
-
- default:
- log_gl("unknown texture type %d for texture format %d\n", type, format);
- return 0;
- }
- }
-
- case GL_RGBA:
- case GL_BGRA:
- case GL_ABGR_EXT:
- {
- switch (type)
- {
- case GL_UNSIGNED_BYTE:
- case GL_BYTE:
- return 1 * 4;
-
- case GL_UNSIGNED_SHORT:
- case GL_SHORT:
- return 2 * 4;
-
- case GL_UNSIGNED_INT:
- case GL_INT:
- case GL_FLOAT:
- return 4 * 4;
-
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_4_4_4_4_REV:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- case GL_UNSIGNED_SHORT_1_5_5_5_REV:
- return 2;
-
- case GL_UNSIGNED_INT_8_8_8_8:
- case GL_UNSIGNED_INT_8_8_8_8_REV:
- case GL_UNSIGNED_INT_10_10_10_2:
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- return 4;
-
- default:
- log_gl("unknown texture type %d for texture format %d\n", type, format);
- return 0;
- }
- }
-
- default:
- log_gl("unknown texture format : %d\n", format);
- return 0;
- }
-}
-
-static void* _calcReadSize(int width, int height, int depth, GLenum format, GLenum type, void* pixels, int* p_size)
-{
- int pack_row_length, pack_alignment, pack_skip_rows, pack_skip_pixels;
-
- LOCK(glGetIntegerv_func);
- glGetIntegerv_no_lock(GL_PACK_ROW_LENGTH, &pack_row_length);
- glGetIntegerv_no_lock(GL_PACK_ALIGNMENT, &pack_alignment);
- glGetIntegerv_no_lock(GL_PACK_SKIP_ROWS, &pack_skip_rows);
- glGetIntegerv_no_lock(GL_PACK_SKIP_PIXELS, &pack_skip_pixels);
- UNLOCK(glGetIntegerv_func);
-
- int w = (pack_row_length == 0) ? width : pack_row_length;
- int size = ((width * getTexImageFactorFromFormatAndType(format, type) + pack_alignment - 1) & (~(pack_alignment-1))) * depth;
- if (height >= 1)
- size += ((w * getTexImageFactorFromFormatAndType(format, type) + pack_alignment - 1) & (~(pack_alignment-1)))* (height-1) * depth ;
- *p_size = size;
-
- pixels += (pack_skip_pixels + pack_skip_rows * w) * getTexImageFactorFromFormatAndType(format, type);
-
- return pixels;
-}
-
-static const void* _calcWriteSize(int width, int height, int depth, GLenum format, GLenum type, const void* pixels, int* p_size)
-{
- int unpack_row_length, unpack_alignment, unpack_skip_rows, unpack_skip_pixels;
-
- LOCK(glGetIntegerv_func);
- glGetIntegerv_no_lock(GL_UNPACK_ROW_LENGTH, &unpack_row_length);
- glGetIntegerv_no_lock(GL_UNPACK_ALIGNMENT, &unpack_alignment);
- glGetIntegerv_no_lock(GL_UNPACK_SKIP_ROWS, &unpack_skip_rows);
- glGetIntegerv_no_lock(GL_UNPACK_SKIP_PIXELS, &unpack_skip_pixels);
- UNLOCK(glGetIntegerv_func);
-
- int w = (unpack_row_length == 0) ? width : unpack_row_length;
- int size = ((width * getTexImageFactorFromFormatAndType(format, type) + unpack_alignment - 1) & (~(unpack_alignment-1))) * depth;
- if (height >= 1)
- size += ((w * getTexImageFactorFromFormatAndType(format, type) + unpack_alignment - 1) & (~(unpack_alignment-1))) * (height-1) * depth;
- *p_size = size;
-
- pixels += (unpack_skip_pixels + unpack_skip_rows * w) * getTexImageFactorFromFormatAndType(format, type);
-
- return pixels;
-}
-
-GLAPI void APIENTRY glTexImage1D(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, 1, 1, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(border), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, (pixels == NULL) ? 0 : size };
- do_opengl_call(glTexImage1D_func, NULL, CHECK_ARGS(args, args_size));
-
-}
-
-GLAPI void APIENTRY glTexImage1DEXT(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- glTexImage1D(target, level, internalFormat, width, border, format, type, pixels);
-}
-
-GLAPI GLint GLAPIENTRY gluBuild2DMipmaps (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
-{
- int size = 0;
- pixels = _calcWriteSize(width, height, 1, format, type, pixels, &size);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, size };
- do_opengl_call(fake_gluBuild2DMipmaps_func, NULL, CHECK_ARGS(args, args_size));
- return 0;
-}
-
-GLAPI void APIENTRY glTexImage2D( GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_STATE();
- int i;
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, height, 1, format, type, pixels, &size);
-
- if (target == GL_TEXTURE_2D)
- {
- for(i=0;i<state->current_server_state.texture2DCacheDim;i++)
- {
- if (state->current_server_state.texture2DCache[i].texture == state->current_server_state.bindTexture2D &&
- state->current_server_state.texture2DCache[i].level == level)
- {
- state->current_server_state.texture2DCache[i].width = width;
- state->current_server_state.texture2DCache[i].height = height;
- break;
- }
- }
- if (i == state->current_server_state.texture2DCacheDim)
- {
- state->current_server_state.texture2DCache =
- realloc(state->current_server_state.texture2DCache, sizeof(Texture2DDim) *
- (state->current_server_state.texture2DCacheDim + 1));
- i = state->current_server_state.texture2DCacheDim;
- state->current_server_state.texture2DCache[i].texture = state->current_server_state.bindTexture2D;
- state->current_server_state.texture2DCache[i].level = level;
- state->current_server_state.texture2DCache[i].width = width;
- state->current_server_state.texture2DCache[i].height = height;
- state->current_server_state.texture2DCacheDim++;
- }
- }
- else if (target == GL_PROXY_TEXTURE_2D_EXT)
- {
- for(i=0;i<state->current_server_state.textureProxy2DCacheDim;i++)
- {
- if (state->current_server_state.textureProxy2DCache[i].level == level)
- {
- state->current_server_state.textureProxy2DCache[i].width = width;
- state->current_server_state.textureProxy2DCache[i].height = height;
- break;
- }
- }
- if (i == state->current_server_state.textureProxy2DCacheDim)
- {
- state->current_server_state.textureProxy2DCache =
- realloc(state->current_server_state.textureProxy2DCache, sizeof(Texture2DDim) *
- (state->current_server_state.textureProxy2DCacheDim + 1));
- i = state->current_server_state.textureProxy2DCacheDim;
- state->current_server_state.textureProxy2DCache[i].level = level;
- state->current_server_state.textureProxy2DCache[i].width = width;
- state->current_server_state.textureProxy2DCache[i].height = height;
- state->current_server_state.textureProxy2DCacheDim++;
- }
- }
- else if (target == GL_TEXTURE_RECTANGLE_ARB)
- {
- for(i=0;i<state->current_server_state.textureRectangleCacheDim;i++)
- {
- if (state->current_server_state.textureRectangleCache[i].texture == state->current_server_state.bindTextureRectangle &&
- state->current_server_state.textureRectangleCache[i].level == level)
- {
- state->current_server_state.textureRectangleCache[i].width = width;
- state->current_server_state.textureRectangleCache[i].height = height;
- break;
- }
- }
- if (i == state->current_server_state.textureRectangleCacheDim)
- {
- state->current_server_state.textureRectangleCache =
- realloc(state->current_server_state.textureRectangleCache, sizeof(Texture2DDim) *
- (state->current_server_state.textureRectangleCacheDim + 1));
- i = state->current_server_state.textureRectangleCacheDim;
- state->current_server_state.textureRectangleCache[i].texture = state->current_server_state.bindTextureRectangle;
- state->current_server_state.textureRectangleCache[i].level = level;
- state->current_server_state.textureRectangleCache[i].width = width;
- state->current_server_state.textureRectangleCache[i].height = height;
- state->current_server_state.textureRectangleCacheDim++;
- }
- }
- else if (target == GL_PROXY_TEXTURE_RECTANGLE_ARB)
- {
- for(i=0;i<state->current_server_state.textureProxyRectangleCacheDim;i++)
- {
- if (state->current_server_state.textureProxyRectangleCache[i].level == level)
- {
- state->current_server_state.textureProxyRectangleCache[i].width = width;
- state->current_server_state.textureProxyRectangleCache[i].height = height;
- break;
- }
- }
- if (i == state->current_server_state.textureProxyRectangleCacheDim)
- {
- state->current_server_state.textureProxyRectangleCache =
- realloc(state->current_server_state.textureProxyRectangleCache, sizeof(Texture2DDim) *
- (state->current_server_state.textureProxyRectangleCacheDim + 1));
- i = state->current_server_state.textureProxyRectangleCacheDim;
- state->current_server_state.textureProxyRectangleCache[i].level = level;
- state->current_server_state.textureProxyRectangleCache[i].width = width;
- state->current_server_state.textureProxyRectangleCache[i].height = height;
- state->current_server_state.textureProxyRectangleCacheDim++;
- }
- }
-
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(border), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, (pixels == NULL) ? 0 : size };
- do_opengl_call(glTexImage2D_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glTexImage2DEXT(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
-}
-
-GLAPI void APIENTRY glTexImage3D( GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, height, depth, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(depth), INT_TO_ARG(border), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, (pixels == NULL) ? 0 : size };
- do_opengl_call(glTexImage3D_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glTexImage3DEXT)(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLint border,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- CHECK_PROC(glTexImage3DEXT);
- glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, pixels);
-}
-
-GLAPI void APIENTRY glTexSubImage1D( GLenum target,
- GLint level,
- GLint xoffset,
- GLsizei width,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, 1, 1, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset),
- INT_TO_ARG(width), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, size };
- do_opengl_call(glTexSubImage1D_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glTexSubImage1DEXT)( GLenum target,
- GLint level,
- GLint xoffset,
- GLsizei width,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- CHECK_PROC(glTexSubImage1DEXT);
- glTexSubImage1D(target, level, xoffset, width, format, type, pixels);
-}
-
-GLAPI void APIENTRY glTexSubImage2D( GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, height, 1, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset), INT_TO_ARG(yoffset),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, size };
- do_opengl_call(glTexSubImage2D_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glTexSubImage2DEXT)( GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- CHECK_PROC(glTexSubImage2DEXT);
- glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
-}
-
-GLAPI void APIENTRY glTexSubImage3D( GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLint zoffset,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- int size = 0;
- if (pixels)
- pixels = _calcWriteSize(width, height, depth, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset), INT_TO_ARG(yoffset), INT_TO_ARG(zoffset),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(depth), INT_TO_ARG(format), INT_TO_ARG(type),
- POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, size };
- do_opengl_call(glTexSubImage3D_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glTexSubImage3DEXT)( GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLint zoffset,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- CHECK_PROC(glTexSubImage3DEXT);
- glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
-}
-GLAPI void APIENTRY glSelectBuffer( GLsizei size, GLuint *buffer )
-{
- if (size <= 0) return;
- GET_CURRENT_STATE();
- state->client_state.selectBufferSize = size;
- state->client_state.selectBufferPtr = buffer;
- long args[] = { INT_TO_ARG(size) };
- do_opengl_call(_glSelectBuffer_fake_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer )
-{
- if (size <= 0) return;
- GET_CURRENT_STATE();
- state->client_state.feedbackBufferSize = size;
- state->client_state.feedbackBufferPtr = buffer;
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type) };
- do_opengl_call(_glFeedbackBuffer_fake_func, NULL, args, NULL);
-}
-
-GLAPI GLint APIENTRY glRenderMode(GLenum mode)
-{
- GLint ret;
- GET_CURRENT_STATE();
- long args[] = { UNSIGNED_INT_TO_ARG(mode)};
- do_opengl_call(glRenderMode_func, &ret, args, NULL);
- if (mode == GL_SELECT && state->client_state.selectBufferPtr)
- {
- long args[] = { POINTER_TO_ARG(state->client_state.selectBufferPtr) };
- int args_size[] = { state->client_state.selectBufferSize * 4 };
- do_opengl_call(_glGetSelectBuffer_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
- else if (mode == GL_FEEDBACK && state->client_state.selectBufferPtr)
- {
- long args[] = { POINTER_TO_ARG(state->client_state.feedbackBufferPtr) };
- int args_size[] = { state->client_state.feedbackBufferSize * 4 };
- do_opengl_call(_glGetFeedbackBuffer_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
- return ret;
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetCompressedTexImageARB)(GLenum target, GLint level, GLvoid *img)
-{
- CHECK_PROC(glGetCompressedTexImageARB);
-
- int imageSize = 0;
- glGetTexLevelParameteriv(target, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &imageSize);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), POINTER_TO_ARG(img) };
- int args_size[] = { 0, 0, imageSize };
- do_opengl_call(glGetCompressedTexImageARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetCompressedTexImage)(GLenum target, GLint level, GLvoid *img)
-{
- glGetCompressedTexImageARB(target, level, img);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage1DARB)(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexImage1DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(border), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexImage1DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage1D)(GLenum target,
- GLint level,
- GLenum internalFormat,
- GLsizei width,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexImage1DARB(target, level, internalFormat, width, border, imageSize, data);
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage2DARB)(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexImage2DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(border), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexImage2DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage2D)(GLenum target,
- GLint level,
- GLenum internalFormat,
- GLsizei width,
- GLsizei height,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexImage2DARB(target, level, internalFormat, width, height, border, imageSize, data);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage3DARB)(GLenum target,
- GLint level,
- GLint internalFormat,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexImage3DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(internalFormat),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(depth), INT_TO_ARG(border), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexImage3DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexImage3D)(GLenum target,
- GLint level,
- GLenum internalFormat,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLint border,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexImage3DARB(target, level, internalFormat, width, height, depth, border, imageSize, data);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage1DARB)(GLenum target,
- GLint level,
- GLint xoffset,
- GLsizei width,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexSubImage1DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset),
- INT_TO_ARG(width), INT_TO_ARG(format), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexSubImage1DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage1D)(GLenum target,
- GLint level,
- GLint xoffset,
- GLsizei width,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexSubImage1DARB(target, level, xoffset, width, format, imageSize, data);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage2DARB)(GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexSubImage2DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset), INT_TO_ARG(yoffset),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(format), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexSubImage2DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage2D)(GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexSubImage2DARB(target, level, xoffset, yoffset, width, height, format, imageSize, data);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage3DARB)(GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLint zoffset,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- CHECK_PROC(glCompressedTexSubImage3DARB);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(xoffset), INT_TO_ARG(yoffset), INT_TO_ARG(zoffset),
- INT_TO_ARG(width), INT_TO_ARG(height), INT_TO_ARG(depth), INT_TO_ARG(format), INT_TO_ARG(imageSize), POINTER_TO_ARG(data) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, imageSize };
- do_opengl_call(glCompressedTexSubImage3DARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glCompressedTexSubImage3D)(GLenum target,
- GLint level,
- GLint xoffset,
- GLint yoffset,
- GLint zoffset,
- GLsizei width,
- GLsizei height,
- GLsizei depth,
- GLenum format,
- GLsizei imageSize,
- const GLvoid * data)
-{
- glCompressedTexSubImage3DARB(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
-}
-
-
-GLAPI void APIENTRY glGetTexLevelParameteriv( GLenum target,
- GLint level,
- GLenum pname,
- GLint *params )
-{
- int i;
- GET_CURRENT_STATE();
-
- if (target == GL_TEXTURE_2D && (pname == GL_TEXTURE_WIDTH || pname == GL_TEXTURE_HEIGHT))
- {
- for(i=0;i<state->current_server_state.texture2DCacheDim;i++)
- {
- if (state->current_server_state.texture2DCache[i].texture == state->current_server_state.bindTexture2D &&
- state->current_server_state.texture2DCache[i].level == level)
- {
- if (pname == GL_TEXTURE_WIDTH)
- {
- *params = state->current_server_state.texture2DCache[i].width;
- return;
- }
- if (pname == GL_TEXTURE_HEIGHT)
- {
- *params = state->current_server_state.texture2DCache[i].height;
- return;
- }
- }
- }
- }
- else if (target == GL_PROXY_TEXTURE_2D_EXT && (pname == GL_TEXTURE_WIDTH || pname == GL_TEXTURE_HEIGHT))
- {
- for(i=0;i<state->current_server_state.textureProxy2DCacheDim;i++)
- {
- if (state->current_server_state.textureProxy2DCache[i].level == level)
- {
- if (pname == GL_TEXTURE_WIDTH)
- {
- *params = state->current_server_state.textureProxy2DCache[i].width;
- return;
- }
- if (pname == GL_TEXTURE_HEIGHT)
- {
- *params = state->current_server_state.textureProxy2DCache[i].height;
- return;
- }
- }
- }
- }
- else if (target == GL_TEXTURE_RECTANGLE_ARB && (pname == GL_TEXTURE_WIDTH || pname == GL_TEXTURE_HEIGHT))
- {
- for(i=0;i<state->current_server_state.textureRectangleCacheDim;i++)
- {
- if (state->current_server_state.textureRectangleCache[i].texture == state->current_server_state.bindTextureRectangle &&
- state->current_server_state.textureRectangleCache[i].level == level)
- {
- if (pname == GL_TEXTURE_WIDTH)
- {
- *params = state->current_server_state.textureRectangleCache[i].width;
- return;
- }
- if (pname == GL_TEXTURE_HEIGHT)
- {
- *params = state->current_server_state.textureRectangleCache[i].height;
- return;
- }
- }
- }
- }
- else if (target == GL_PROXY_TEXTURE_RECTANGLE_ARB && (pname == GL_TEXTURE_WIDTH || pname == GL_TEXTURE_HEIGHT))
- {
- for(i=0;i<state->current_server_state.textureProxyRectangleCacheDim;i++)
- {
- if (state->current_server_state.textureProxyRectangleCache[i].level == level)
- {
- if (pname == GL_TEXTURE_WIDTH)
- {
- *params = state->current_server_state.textureProxyRectangleCache[i].width;
- return;
- }
- if (pname == GL_TEXTURE_HEIGHT)
- {
- *params = state->current_server_state.textureProxyRectangleCache[i].height;
- return;
- }
- }
- }
- }
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(pname), POINTER_TO_ARG(params) };
- do_opengl_call(glGetTexLevelParameteriv_func, NULL, args, NULL);
-
-}
-
-
-GLAPI void APIENTRY glGetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
-{
- if (pname == GL_TEXTURE_MAX_ANISOTROPY_EXT)
- *params = 1;
- else
- {
- int size = __glTexParameter_size(get_err_file(), pname);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(pname), POINTER_TO_ARG(params) };
- int args_size[] = { 0, 0, size * sizeof(GLfloat) };
- do_opengl_call(glGetTexParameterfv_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-GLAPI void APIENTRY glFogf(GLenum pname, GLfloat param)
-{
- GET_CURRENT_STATE();
- if (pname == GL_FOG_MODE)
- state->current_server_state.fog.mode = param;
- else if (pname == GL_FOG_DENSITY)
- state->current_server_state.fog.density = param;
- else if (pname == GL_FOG_START)
- state->current_server_state.fog.start = param;
- else if (pname == GL_FOG_END)
- state->current_server_state.fog.end = param;
- else if (pname == GL_FOG_INDEX)
- state->current_server_state.fog.index = param;
- long args[] = { UNSIGNED_INT_TO_ARG(pname), FLOAT_TO_ARG(param)};
- do_opengl_call(glFogf_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glFogi(GLenum pname, GLint param)
-{
- GET_CURRENT_STATE();
- if (pname == GL_FOG_MODE)
- state->current_server_state.fog.mode = param;
- else if (pname == GL_FOG_DENSITY)
- state->current_server_state.fog.density = param;
- else if (pname == GL_FOG_START)
- state->current_server_state.fog.start = param;
- else if (pname == GL_FOG_END)
- state->current_server_state.fog.end = param;
- else if (pname == GL_FOG_INDEX)
- state->current_server_state.fog.index = param;
- long args[] = { UNSIGNED_INT_TO_ARG(pname), INT_TO_ARG(param)};
- do_opengl_call(glFogi_func, NULL, args, NULL);
-}
-
-
-GLAPI void APIENTRY glFogfv( GLenum pname, const GLfloat *params )
-{
- if (pname != GL_FOG_COLOR)
- {
- glFogf(pname, *params);
- return;
- }
- GET_CURRENT_STATE();
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(params) };
- memcpy(state->current_server_state.fog.color, params, 4 * sizeof(float));
- do_opengl_call(glFogfv_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glFogiv( GLenum pname, const GLint *params )
-{
- if (pname != GL_FOG_COLOR)
- {
- glFogi(pname, *params);
- return;
- }
- long args[] = { INT_TO_ARG(pname), POINTER_TO_ARG(params) };
- do_opengl_call(glFogiv_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 )
-{
- glRectd(v1[0], v1[1], v2[0], v2[1]);
-}
-GLAPI void APIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 )
-{
- glRectf(v1[0], v1[1], v2[0], v2[1]);
-}
-GLAPI void APIENTRY glRectiv( const GLint *v1, const GLint *v2 )
-{
- glRecti(v1[0], v1[1], v2[0], v2[1]);
-}
-GLAPI void APIENTRY glRectsv( const GLshort *v1, const GLshort *v2 )
-{
- glRects(v1[0], v1[1], v2[0], v2[1]);
-}
-
-
-GLAPI void APIENTRY glBitmap(GLsizei width,
- GLsizei height,
- GLfloat xorig,
- GLfloat yorig,
- GLfloat xmove,
- GLfloat ymove,
- const GLubyte *bitmap )
-{
- GET_CURRENT_STATE();
- int unpack_alignment, unpack_row_length;
- LOCK(glGetIntegerv_func);
- glGetIntegerv_no_lock(GL_UNPACK_ROW_LENGTH, &unpack_row_length);
- glGetIntegerv_no_lock(GL_UNPACK_ALIGNMENT, &unpack_alignment);
- UNLOCK(glGetIntegerv_func);
- int w = (unpack_row_length == 0) ? width : unpack_row_length;
- int size = ((w + unpack_alignment - 1) & (~(unpack_alignment-1))) * height;
- long args[] = { INT_TO_ARG(width), INT_TO_ARG(height), FLOAT_TO_ARG(xorig), FLOAT_TO_ARG(yorig),
- FLOAT_TO_ARG(xmove), FLOAT_TO_ARG(ymove), POINTER_TO_ARG(bitmap) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, size };
- do_opengl_call(glBitmap_func, NULL, CHECK_ARGS(args, args_size));
-
- state->currentRasterPos[0] += xmove;
- state->currentRasterPos[1] += ymove;
-}
-
-
-GLAPI void APIENTRY glGetTexImage( GLenum target,
- GLint level,
- GLenum format,
- GLenum type,
- GLvoid *pixels )
-{
- int size = 0, width, height = 1, depth = 1;
- if (target == GL_PROXY_TEXTURE_1D || target == GL_PROXY_TEXTURE_2D || target == GL_PROXY_TEXTURE_3D)
- {
- log_gl("unhandled target : %d\n", target);
- return;
- }
- glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
- if (target == GL_TEXTURE_2D || target == GL_TEXTURE_RECTANGLE_ARB || target == GL_TEXTURE_3D)
- glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
- if (target == GL_TEXTURE_3D)
- glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
-
- pixels = _calcReadSize(width, height, depth, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(level), INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, size };
- do_opengl_call(glGetTexImage_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-static void glReadPixels_no_lock(GLint x,
- GLint y,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- GLvoid *pixels )
-{
- GET_CURRENT_STATE();
- if (state->pixelPackBuffer)
- {
- int fake_ret;
- long args[] = { INT_TO_ARG(x), INT_TO_ARG(y), INT_TO_ARG(width), INT_TO_ARG(height),
- INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- /* Make it synchronous, otherwise it floods server */
- do_opengl_call_no_lock(_glReadPixels_pbo_func, &fake_ret, args, NULL);
- }
- else
- {
- int size = 0;
-
- pixels = _calcReadSize(width, height, 1, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(x), INT_TO_ARG(y), INT_TO_ARG(width), INT_TO_ARG(height),
- INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, size };
-
- do_opengl_call_no_lock(glReadPixels_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-GLAPI void APIENTRY glReadPixels(GLint x,
- GLint y,
- GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- GLvoid *pixels )
-{
- LOCK(glReadPixels_func);
- glReadPixels_no_lock(x, y, width, height, format, type, pixels);
- UNLOCK(glReadPixels_func);
-}
-
-GLAPI void APIENTRY glDrawPixels(GLsizei width,
- GLsizei height,
- GLenum format,
- GLenum type,
- const GLvoid *pixels )
-{
- GET_CURRENT_STATE();
- if (state->pixelUnpackBuffer)
- {
- long args[] = { INT_TO_ARG(width), INT_TO_ARG(height),
- INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- do_opengl_call(_glDrawPixels_pbo_func, NULL, args, NULL);
- }
- else
- {
- int size = 0;
-
- pixels = _calcWriteSize(width, height, 1, format, type, pixels, &size);
-
- long args[] = { INT_TO_ARG(width), INT_TO_ARG(height),
- INT_TO_ARG(format), INT_TO_ARG(type), POINTER_TO_ARG(pixels) };
- int args_size[] = { 0, 0, 0, 0, size };
- do_opengl_call(glDrawPixels_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-GLAPI void APIENTRY glInterleavedArrays( GLenum format,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glInterleavedArrays);
- GET_CURRENT_STATE();
- if (debug_array_ptr)
- log_gl("glInterleavedArrays format=%d stride=%d ptr=%p\n", format, stride, ptr);
- state->client_state.arrays.interleavedArrays.format = format;
- state->client_state.arrays.interleavedArrays.stride = stride;
- state->client_state.arrays.interleavedArrays.ptr = ptr;
-}
-
-GLAPI void APIENTRY glVertexPointer( GLint size,
- GLenum type,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glVertexPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.vertexArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.vertexArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glVertexPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.vertexArray.size == size &&
- state->client_state.arrays.vertexArray.type == type &&
- state->client_state.arrays.vertexArray.stride == stride &&
- state->client_state.arrays.vertexArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glVertexPointer size=%d type=%d stride=%d ptr=%p\n", size, type, stride, ptr);
- state->client_state.arrays.vertexArray.size = size;
- state->client_state.arrays.vertexArray.type = type;
- state->client_state.arrays.vertexArray.stride = stride;
- state->client_state.arrays.vertexArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glVertexPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr), (size, type, stride, ptr));
-
-GLAPI void APIENTRY glNormalPointer( GLenum type,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glNormalPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.normalArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.normalArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glNormalPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.normalArray.type == type &&
- state->client_state.arrays.normalArray.stride == stride &&
- state->client_state.arrays.normalArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glNormalPointer type=%d stride=%d ptr=%p\n", type, stride, ptr);
- state->client_state.arrays.normalArray.size = 3;
- state->client_state.arrays.normalArray.type = type;
- state->client_state.arrays.normalArray.stride = stride;
- state->client_state.arrays.normalArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glNormalPointer, (GLenum type, GLsizei stride, const GLvoid *ptr), (type, stride, ptr));
-
-GLAPI void APIENTRY glIndexPointer( GLenum type,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glIndexPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.indexArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.indexArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glIndexPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.indexArray.type == type &&
- state->client_state.arrays.indexArray.stride == stride &&
- state->client_state.arrays.indexArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glIndexPointer type=%d stride=%d ptr=%p\n", type, stride, ptr);
- state->client_state.arrays.indexArray.size = 1;
- state->client_state.arrays.indexArray.type = type;
- state->client_state.arrays.indexArray.stride = stride;
- state->client_state.arrays.indexArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glIndexPointer, (GLenum type, GLsizei stride, const GLvoid *ptr), (type, stride, ptr));
-
-GLAPI void APIENTRY glColorPointer( GLint size,
- GLenum type,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glColorPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.colorArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.colorArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glColorPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.colorArray.size == size &&
- state->client_state.arrays.colorArray.type == type &&
- state->client_state.arrays.colorArray.stride == stride &&
- state->client_state.arrays.colorArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glColorPointer size=%d type=%d stride=%d ptr=%p\n", size, type, stride, ptr);
- state->client_state.arrays.colorArray.size = size;
- state->client_state.arrays.colorArray.type = type;
- state->client_state.arrays.colorArray.stride = stride;
- state->client_state.arrays.colorArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glColorPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr), (size, type, stride, ptr));
-
-GLAPI void APIENTRY glSecondaryColorPointer( GLint size,
- GLenum type,
- GLsizei stride,
- const GLvoid *ptr )
-{
- CHECK_PROC(glSecondaryColorPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.secondaryColorArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.secondaryColorArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glSecondaryColorPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.secondaryColorArray.size == size &&
- state->client_state.arrays.secondaryColorArray.type == type &&
- state->client_state.arrays.secondaryColorArray.stride == stride &&
- state->client_state.arrays.secondaryColorArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glSecondaryColorPointer size=%d type=%d stride=%d ptr=%p\n", size, type, stride, ptr);
- state->client_state.arrays.secondaryColorArray.size = size;
- state->client_state.arrays.secondaryColorArray.type = type;
- state->client_state.arrays.secondaryColorArray.stride = stride;
- state->client_state.arrays.secondaryColorArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glSecondaryColorPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr), (size, type, stride, ptr));
-
-GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr )
-{
- CHECK_PROC(glTexCoordPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glTexCoordPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].size == size &&
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].type == type &&
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].stride == stride &&
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glTexCoordPointer[%d] size=%d type=%d stride=%d ptr=%p\n",
- state->client_state.clientActiveTexture, size, type, stride, ptr);
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].index =
- state->client_state.clientActiveTexture;
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].size = size;
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].type = type;
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].stride = stride;
- state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].ptr = ptr;
- }
-}
-
-DEFINE_EXT(glTexCoordPointer, (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr), (size, type, stride, ptr));
-
-GLAPI void APIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr )
-{
- CHECK_PROC(glEdgeFlagPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.edgeFlagArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.edgeFlagArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glEdgeFlagPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.edgeFlagArray.stride == stride &&
- state->client_state.arrays.edgeFlagArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("edgeFlagArray stride=%d ptr=%p\n", stride, ptr);
- state->client_state.arrays.edgeFlagArray.size = 1;
- state->client_state.arrays.edgeFlagArray.type = GL_BYTE;
- state->client_state.arrays.edgeFlagArray.stride = stride;
- state->client_state.arrays.edgeFlagArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glEdgeFlagPointer, (GLsizei stride, const GLvoid *ptr), (stride, ptr));
-
-GLAPI void APIENTRY glFogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- CHECK_PROC(glFogCoordPointer);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.fogCoordArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.fogCoordArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glFogCoordPointer_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (state->client_state.arrays.fogCoordArray.type == type &&
- state->client_state.arrays.fogCoordArray.stride == stride &&
- state->client_state.arrays.fogCoordArray.ptr == ptr)
- {
- }
- else
- {
- if (debug_array_ptr)
- log_gl("glFogCoordPointer type=%d stride=%d ptr=%p\n", type, stride, ptr);
- state->client_state.arrays.fogCoordArray.size = 1;
- state->client_state.arrays.fogCoordArray.type = type;
- state->client_state.arrays.fogCoordArray.stride = stride;
- state->client_state.arrays.fogCoordArray.ptr = ptr;
- }
-}
-
-DEFINE_EXT(glFogCoordPointer, (GLenum type, GLsizei stride, const GLvoid *ptr), (type, stride, ptr));
-
-
-GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- CHECK_PROC(glWeightPointerARB);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.weightArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.weightArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glWeightPointerARB_buffer_func, NULL, args, NULL);
- return;
- }
-
- log_gl("glWeightPointerARB\n");
- fflush(get_err_file());
- if (debug_array_ptr)
- log_gl("weightArray size=%d type=%d stride=%d ptr=%p\n", size, type, stride, ptr);
- state->client_state.arrays.weightArray.size = size;
- state->client_state.arrays.weightArray.type = type;
- state->client_state.arrays.weightArray.stride = stride;
- state->client_state.arrays.weightArray.ptr = ptr;
-}
-
-
-GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
-{
- CHECK_PROC(glMatrixIndexPointerARB);
- GET_CURRENT_STATE();
-
- state->client_state.arrays.matrixIndexArray.vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.matrixIndexArray.vbo_name)
- {
- long args[] = { INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glMatrixIndexPointerARB_buffer_func, NULL, args, NULL);
- return;
- }
-
- log_gl("glMatrixIndexPointerARB\n");
- fflush(get_err_file());
- if (debug_array_ptr)
- log_gl("matrixIndexArray size=%d type=%d stride=%d ptr=%p\n", size, type, stride, ptr);
- state->client_state.arrays.matrixIndexArray.size = size;
- state->client_state.arrays.matrixIndexArray.type = type;
- state->client_state.arrays.matrixIndexArray.stride = stride;
- state->client_state.arrays.matrixIndexArray.ptr = ptr;
-}
-
-#define glMatrixIndexvARB(name, type) \
- GLAPI void APIENTRY name (GLint size, const type *indices) \
-{ \
- CHECK_PROC(name); \
- long args[] = { INT_TO_ARG(size), POINTER_TO_ARG(indices) }; \
- int args_size[] = { 0, size * sizeof(type) }; \
- do_opengl_call(CONCAT(name, _func), NULL, CHECK_ARGS(args, args_size)); \
-}
-
-glMatrixIndexvARB(glMatrixIndexubvARB, GLubyte);
-glMatrixIndexvARB(glMatrixIndexusvARB, GLushort);
-glMatrixIndexvARB(glMatrixIndexuivARB, GLuint);
-
-
-GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight)
-{
- log_gl("glVertexWeightfEXT : deprecated API. unimplemented\n");
-}
-
-GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight)
-{
- log_gl("glVertexWeightfvEXT : deprecated API. unimplemented\n");
-}
-
-GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer)
-{
- log_gl("glVertexWeightPointerEXT : deprecated API. unimplemented\n");
-}
-
-
-
-GLAPI void APIENTRY EXT_FUNC(glVertexAttribPointerARB)(GLuint index,
- GLint size,
- GLenum type,
- GLboolean normalized,
- GLsizei stride,
- const GLvoid *ptr)
-{
- CHECK_PROC(glVertexAttribPointerARB);
-
- GET_CURRENT_STATE();
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- state->client_state.arrays.vertexAttribArray[index].vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.vertexAttribArray[index].vbo_name)
- {
- long args[] = { INT_TO_ARG(index), INT_TO_ARG(size), INT_TO_ARG(type), INT_TO_ARG(normalized), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glVertexAttribPointerARB_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (debug_array_ptr)
- log_gl("glVertexAttribPointerARB[%d] size=%d type=%d normalized=%d stride=%d ptr=%p\n",
- index, size, type, normalized, stride, ptr);
- state->client_state.arrays.vertexAttribArray[index].index = index;
- state->client_state.arrays.vertexAttribArray[index].size = size;
- state->client_state.arrays.vertexAttribArray[index].type = type;
- state->client_state.arrays.vertexAttribArray[index].normalized = normalized;
- state->client_state.arrays.vertexAttribArray[index].stride = stride;
- state->client_state.arrays.vertexAttribArray[index].ptr = ptr;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glVertexAttribPointer)(GLuint index,
- GLint size,
- GLenum type,
- GLboolean normalized,
- GLsizei stride,
- const GLvoid *ptr)
-{
- glVertexAttribPointerARB(index, size, type, normalized, stride, ptr);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glVertexAttribPointerNV)(GLuint index,
- GLint size,
- GLenum type,
- GLsizei stride,
- const GLvoid *ptr)
-{
- CHECK_PROC(glVertexAttribPointerNV);
-
- GET_CURRENT_STATE();
- if (index < MY_GL_MAX_VERTEX_ATTRIBS_NV)
- {
- if (debug_array_ptr)
- log_gl("glVertexAttribPointerNV[%d] size=%d type=%d stride=%d ptr=%p\n",
- index, size, type, stride, ptr);
- state->client_state.arrays.vertexAttribArrayNV[index].index = index;
- state->client_state.arrays.vertexAttribArrayNV[index].size = size;
- state->client_state.arrays.vertexAttribArrayNV[index].type = type;
- state->client_state.arrays.vertexAttribArrayNV[index].stride = stride;
- state->client_state.arrays.vertexAttribArrayNV[index].ptr = ptr;
- }
- else
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_NV\n");
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glElementPointerATI) (GLenum type, const GLvoid * ptr)
-{
- CHECK_PROC(glElementPointerATI);
- GET_CURRENT_STATE();
- state->client_state.arrays.elementArrayATI.size = 1;
- state->client_state.arrays.elementArrayATI.type = type;
- state->client_state.arrays.elementArrayATI.stride = 0;
- state->client_state.arrays.elementArrayATI.ptr = ptr;
-}
-
-GLAPI void APIENTRY glGetPointerv( GLenum pname, void **params )
-{
- GET_CURRENT_STATE();
- switch (pname)
- {
- case GL_COLOR_ARRAY_POINTER: *params = (void*)state->client_state.arrays.colorArray.ptr; break;
- case GL_SECONDARY_COLOR_ARRAY_POINTER: *params = (void*)state->client_state.arrays.secondaryColorArray.ptr; break;
- case GL_NORMAL_ARRAY_POINTER: *params = (void*)state->client_state.arrays.normalArray.ptr; break;
- case GL_INDEX_ARRAY_POINTER: *params = (void*)state->client_state.arrays.indexArray.ptr; break;
- case GL_TEXTURE_COORD_ARRAY_POINTER: *params = (void*)state->client_state.arrays.texCoordArray[state->client_state.clientActiveTexture].ptr; break;
- case GL_VERTEX_ARRAY_POINTER: *params = (void*)state->client_state.arrays.vertexArray.ptr; break;
- case GL_EDGE_FLAG_ARRAY_POINTER: *params = (void*)state->client_state.arrays.edgeFlagArray.ptr; break;
- case GL_WEIGHT_ARRAY_POINTER_ARB: *params = (void*)state->client_state.arrays.weightArray.ptr; break;
- case GL_MATRIX_INDEX_ARRAY_POINTER_ARB: *params = (void*)state->client_state.arrays.matrixIndexArray.ptr; break;
- case GL_FOG_COORD_ARRAY_POINTER: *params = (void*)state->client_state.arrays.fogCoordArray.ptr; break;
- case GL_ELEMENT_ARRAY_POINTER_ATI: *params = (void*)state->client_state.arrays.elementArrayATI.ptr; break;
- case GL_SELECTION_BUFFER_POINTER: *params = (void*)state->client_state.selectBufferPtr; break;
- case GL_FEEDBACK_BUFFER_POINTER: *params = (void*)state->client_state.feedbackBufferPtr; break;
- default:
- {
- log_gl("not yet handled pname %d\n", pname);
- *params = NULL;
- }
- }
-}
-
-GLAPI void APIENTRY glGetPointervEXT( GLenum pname, void **params )
-{
- glGetPointerv(pname, params);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetVertexAttribPointervARB)(GLuint index,
- GLenum pname,
- GLvoid **pointer)
-{
- GET_CURRENT_STATE();
-
- if (index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n");
- return;
- }
-
- switch (pname)
- {
- case GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB:
- {
- *pointer = (void*)state->client_state.arrays.vertexAttribArray[index].ptr;
- break;
- }
- default:
- log_gl("glGetVertexAttribPointervARB : bad pname=0x%X", pname);
- break;
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetVertexAttribPointerv)(GLuint index,
- GLenum pname,
- GLvoid **pointer)
-{
- glGetVertexAttribPointervARB(index, pname, pointer);
-}
-
-GLAPI void APIENTRY EXT_FUNC(_glGetVertexAttribiv)(int func_number, GLuint index, GLenum pname, GLint *params)
-{
- if (index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB)
- {
- log_gl("%s: index >= MY_GL_MAX_VERTEX_ATTRIBS_ARB\n", tab_opengl_calls_name[func_number]);
- return;
- }
-
- GET_CURRENT_STATE();
- switch (pname)
- {
- case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].enabled;
- break;
- case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].size;
- break;
- case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].stride;
- break;
- case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].type;
- break;
- case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].normalized;
- break;
- case GL_CURRENT_VERTEX_ATTRIB_ARB:
- *params = state->client_state.arrays.vertexAttribArray[index].vbo_name;
- break;
- default:
- log_gl("%s : bad pname=0x%X", tab_opengl_calls_name[func_number], pname);
- break;
- }
-}
-
-#define DEFINE_glGetVertexAttribv(funcName, type) \
- GLAPI void APIENTRY EXT_FUNC(funcName)(GLuint index, GLenum pname, type *params) \
-{ \
- CHECK_PROC(funcName); \
- if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) \
- { \
- long args[] = { UNSIGNED_INT_TO_ARG(index), UNSIGNED_INT_TO_ARG(pname), POINTER_TO_ARG(params)}; \
- do_opengl_call(CONCAT(funcName,_func), NULL, args, NULL); \
- return; \
- } \
- int i_params; \
- _glGetVertexAttribiv(CONCAT(funcName,_func), index, pname, &i_params); \
- *params = i_params; \
-}
-
-DEFINE_glGetVertexAttribv(glGetVertexAttribivARB, GLint);
-DEFINE_glGetVertexAttribv(glGetVertexAttribiv, GLint);
-DEFINE_glGetVertexAttribv(glGetVertexAttribfvARB, GLfloat);
-DEFINE_glGetVertexAttribv(glGetVertexAttribfv, GLfloat);
-DEFINE_glGetVertexAttribv(glGetVertexAttribdvARB, GLdouble);
-DEFINE_glGetVertexAttribv(glGetVertexAttribdv, GLdouble);
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetVertexAttribPointervNV)(GLuint index,
- GLenum pname,
- GLvoid **pointer)
-{
- CHECK_PROC(glGetVertexAttribPointervNV);
- GET_CURRENT_STATE();
- if (index >= MY_GL_MAX_VERTEX_ATTRIBS_NV)
- {
- log_gl("index >= MY_GL_MAX_VERTEX_ATTRIBS_NV\n");
- return;
- }
- switch (pname)
- {
- case GL_ATTRIB_ARRAY_POINTER_NV:
- {
- *pointer = (void*)state->client_state.arrays.vertexAttribArrayNV[index].ptr;
- break;
- }
- default:
- log_gl("glGetVertexAttribPointervNV : bad pname=0x%X", pname);
- break;
- }
-}
-
-static int getGlTypeByteSize(int type)
-{
- switch(type)
- {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- return 1;
- break;
-
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- return 2;
- break;
-
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- return 4;
- break;
-
- case GL_DOUBLE:
- return 8;
- break;
-
- default:
- log_gl("unsupported type = %d\n", type);
- return 0;
- }
-}
-
-static int getMulFactorFromPointerArray(ClientArray* array)
-{
- if (array->stride)
- return array->stride;
-
- return getGlTypeByteSize(array->type) * array->size;
-}
-
-static void _glArraySend(GLState* state, const char* func_name, int func, ClientArray* array, int first, int last)
-{
- if (array->ptr == NULL || array->vbo_name || array->enabled == 0) return;
- int offset = first * getMulFactorFromPointerArray(array);
- int size = (last - first + 1) * getMulFactorFromPointerArray(array);
- if (size == 0) return;
-
-#if 0
- unsigned int crc = calc_checksum(array->ptr + offset, size, 0xFFFFFFFF);
- crc = calc_checksum(&offset, sizeof(int), crc);
- crc = calc_checksum(&size, sizeof(int), crc);
- crc = calc_checksum(&array->size, sizeof(int), crc);
- crc = calc_checksum(&array->type, sizeof(int), crc);
-
- if (crc == 0)
- {
- /*int i;
- unsigned char* ptr = (unsigned char*)(array->ptr + offset);
- for(i=0;i<size;i++)
- {
- log_gl("%d ", (int)ptr[i]);
- }*/
- log_gl("strange : crc = 0\n");
- }
-
- if (crc == array->last_crc)
- {
- if (debug_array_ptr)
- {
- log_gl("%s : same crc. Saving %d bytes\n", func_name, size);
- }
- return;
- }
-
- array->last_crc = crc;
-#endif
-
- if (debug_array_ptr)
- {
- unsigned int crc = calc_checksum(array->ptr + offset, size, 0xFFFFFFFF);
- crc = calc_checksum(&offset, sizeof(int), crc);
- crc = calc_checksum(&size, sizeof(int), crc);
- crc = calc_checksum(&array->size, sizeof(int), crc);
- crc = calc_checksum(&array->type, sizeof(int), crc);
-
- log_gl("%s sending %d bytes from %d : crc = %d\n", func_name, size, offset, crc);
- }
-
- int currentArrayBuffer = state->arrayBuffer;
- if (currentArrayBuffer)
- {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- }
-
- switch(func)
- {
- case glEdgeFlagPointer_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- case glNormalPointer_fake_func:
- case glIndexPointer_fake_func:
- case glFogCoordPointer_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->type),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- case glVertexPointer_fake_func:
- case glColorPointer_fake_func:
- case glSecondaryColorPointer_fake_func:
- case glWeightPointerARB_fake_func:
- case glMatrixIndexPointerARB_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->size),
- INT_TO_ARG(array->type),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- case glTexCoordPointer_fake_func:
- case glVertexAttribPointerNV_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->index),
- INT_TO_ARG(array->size),
- INT_TO_ARG(array->type),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- case glVertexAttribPointerARB_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->index),
- INT_TO_ARG(array->size),
- INT_TO_ARG(array->type),
- INT_TO_ARG(array->normalized),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- case glVariantPointerEXT_fake_func:
- {
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(array->index),
- INT_TO_ARG(array->type),
- INT_TO_ARG(array->stride),
- INT_TO_ARG(size),
- POINTER_TO_ARG(array->ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, size};
- do_opengl_call(func, NULL, CHECK_ARGS(args, args_size));
- break;
- }
-
- default:
- log_gl("shoudln't reach that point\n");
- break;
- }
-
- if (currentArrayBuffer)
- {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, currentArrayBuffer);
- }
-}
-
-
-#define ARRAY_SEND_FUNC(x) #x, CONCAT(x,_fake_func)
-
-static int _calc_interleaved_arrays_stride(GLenum format)
-{
- switch(format)
- {
- case GL_V2F: return 2 * sizeof(float); break;
- case GL_V3F: return 3 * sizeof(float); break;
- case GL_C4UB_V2F: return 4 * sizeof(char) + 2 * sizeof(float); break;
- case GL_C4UB_V3F: return 4 * sizeof(char) + 3 * sizeof(float); break;
- case GL_C3F_V3F: return 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_N3F_V3F: return 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_C4F_N3F_V3F: return 4 * sizeof(float) + 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_T2F_V3F: return 2 * sizeof(float) + 3 * sizeof(float); break;
- case GL_T4F_V4F: return 4 * sizeof(float) + 4 * sizeof(float); break;
- case GL_T2F_C4UB_V3F: return 2 * sizeof(float) + 4 * sizeof(char) + 3 * sizeof(float); break;
- case GL_T2F_C3F_V3F: return 2 * sizeof(float) + 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_T2F_N3F_V3F: return 2 * sizeof(float) + 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_T2F_C4F_N3F_V3F: return 2 * sizeof(float) + 4 * sizeof(float) + 3 * sizeof(float) + 3 * sizeof(float); break;
- case GL_T4F_C4F_N3F_V4F: return 4 * sizeof(float) + 4 * sizeof(float) + 3 * sizeof(float) + 4 * sizeof(float); break;
- default: log_gl("unknown interleaved array format : %d\n", format); return 0;
- }
-}
-
-
-enum
-{
- TEXCOORD_FUNC,
- COLOR_FUNC,
- NORMAL_FUNC,
- INDEX_FUNC,
- VERTEX_FUNC
-};
-
-typedef void (*vector_func_type)(const void*);
-
-typedef struct
-{
- int type;
- int size;
- int typeFunc;
- vector_func_type vector_func;
-} VectorFuncStruct;
-
-VectorFuncStruct vectorFuncArray[] =
-{
- { GL_DOUBLE, 1, TEXCOORD_FUNC, (vector_func_type)glTexCoord1dv },
- { GL_DOUBLE, 2, TEXCOORD_FUNC, (vector_func_type)glTexCoord2dv },
- { GL_DOUBLE, 3, TEXCOORD_FUNC, (vector_func_type)glTexCoord3dv },
- { GL_DOUBLE, 4, TEXCOORD_FUNC, (vector_func_type)glTexCoord4dv },
- { GL_FLOAT, 1, TEXCOORD_FUNC, (vector_func_type)glTexCoord1fv },
- { GL_FLOAT, 2, TEXCOORD_FUNC, (vector_func_type)glTexCoord2fv },
- { GL_FLOAT, 3, TEXCOORD_FUNC, (vector_func_type)glTexCoord3fv },
- { GL_FLOAT, 4, TEXCOORD_FUNC, (vector_func_type)glTexCoord4fv },
- { GL_INT, 1, TEXCOORD_FUNC, (vector_func_type)glTexCoord1iv },
- { GL_INT, 2, TEXCOORD_FUNC, (vector_func_type)glTexCoord2iv },
- { GL_INT, 3, TEXCOORD_FUNC, (vector_func_type)glTexCoord3iv },
- { GL_INT, 4, TEXCOORD_FUNC, (vector_func_type)glTexCoord4iv },
- { GL_SHORT, 1, TEXCOORD_FUNC, (vector_func_type)glTexCoord1sv },
- { GL_SHORT, 2, TEXCOORD_FUNC, (vector_func_type)glTexCoord2sv },
- { GL_SHORT, 3, TEXCOORD_FUNC, (vector_func_type)glTexCoord3sv },
- { GL_SHORT, 4, TEXCOORD_FUNC, (vector_func_type)glTexCoord4sv },
-
- { GL_BYTE, 3, COLOR_FUNC, (vector_func_type)glColor3bv },
- { GL_DOUBLE, 3, COLOR_FUNC, (vector_func_type)glColor3dv },
- { GL_FLOAT, 3, COLOR_FUNC, (vector_func_type)glColor3fv },
- { GL_INT, 3, COLOR_FUNC, (vector_func_type)glColor3iv },
- { GL_SHORT, 3, COLOR_FUNC, (vector_func_type)glColor3sv },
- { GL_UNSIGNED_BYTE, 3, COLOR_FUNC, (vector_func_type)glColor3ubv },
- { GL_UNSIGNED_INT, 3, COLOR_FUNC, (vector_func_type)glColor3uiv },
- { GL_UNSIGNED_SHORT, 3, COLOR_FUNC, (vector_func_type)glColor3usv },
- { GL_BYTE, 4, COLOR_FUNC, (vector_func_type)glColor4bv },
- { GL_DOUBLE, 4, COLOR_FUNC, (vector_func_type)glColor4dv },
- { GL_FLOAT, 4, COLOR_FUNC, (vector_func_type)glColor4fv },
- { GL_INT, 4, COLOR_FUNC, (vector_func_type)glColor4iv },
- { GL_SHORT, 4, COLOR_FUNC, (vector_func_type)glColor4sv },
- { GL_UNSIGNED_BYTE, 4, COLOR_FUNC, (vector_func_type)glColor4ubv },
- { GL_UNSIGNED_INT, 4, COLOR_FUNC, (vector_func_type)glColor4uiv },
- { GL_UNSIGNED_SHORT, 4, COLOR_FUNC, (vector_func_type)glColor4usv },
-
- { GL_BYTE, 3, NORMAL_FUNC, (vector_func_type)glNormal3bv },
- { GL_DOUBLE, 3, NORMAL_FUNC, (vector_func_type)glNormal3dv },
- { GL_FLOAT, 3, NORMAL_FUNC, (vector_func_type)glNormal3fv },
- { GL_INT, 3, NORMAL_FUNC, (vector_func_type)glNormal3iv },
- { GL_SHORT, 3, NORMAL_FUNC, (vector_func_type)glNormal3sv },
-
- { GL_DOUBLE, 1, INDEX_FUNC, (vector_func_type)glIndexdv },
- { GL_FLOAT, 1, INDEX_FUNC, (vector_func_type)glIndexfv },
- { GL_INT, 1, INDEX_FUNC, (vector_func_type)glIndexiv },
- { GL_SHORT, 1, INDEX_FUNC, (vector_func_type)glIndexsv },
- { GL_UNSIGNED_BYTE, 1, INDEX_FUNC, (vector_func_type)glIndexubv },
-
- { GL_DOUBLE, 2, VERTEX_FUNC, (vector_func_type)glVertex2dv },
- { GL_FLOAT, 2, VERTEX_FUNC, (vector_func_type)glVertex2fv },
- { GL_INT, 2, VERTEX_FUNC, (vector_func_type)glVertex2iv },
- { GL_SHORT, 2, VERTEX_FUNC, (vector_func_type)glVertex2sv },
- { GL_DOUBLE, 3, VERTEX_FUNC, (vector_func_type)glVertex3dv },
- { GL_FLOAT, 3, VERTEX_FUNC, (vector_func_type)glVertex3fv },
- { GL_INT, 3, VERTEX_FUNC, (vector_func_type)glVertex3iv },
- { GL_SHORT, 4, VERTEX_FUNC, (vector_func_type)glVertex4sv },
- { GL_DOUBLE, 4, VERTEX_FUNC, (vector_func_type)glVertex4dv },
- { GL_FLOAT, 4, VERTEX_FUNC, (vector_func_type)glVertex4fv },
- { GL_INT, 4, VERTEX_FUNC, (vector_func_type)glVertex4iv },
- { GL_SHORT, 4, VERTEX_FUNC, (vector_func_type)glVertex4sv },
-};
-
-static vector_func_type _get_vector_func(int type, int size, int typeFunc)
-{
- int i;
- for(i=0;i<sizeof(vectorFuncArray)/sizeof(vectorFuncArray[0]);i++)
- {
- if (vectorFuncArray[i].type == type &&
- vectorFuncArray[i].size == size &&
- vectorFuncArray[i].typeFunc == typeFunc)
- return vectorFuncArray[i].vector_func;
- }
- log_gl("can't find vector_func(type=%X, size=%d, typeFunc=%d)\n", type, size, typeFunc);
- return NULL;
-}
-
-static void _glElementArrayImmediate_one(ClientArray* array, int indice, int typeFunc)
-{
- if (array->enabled)
- {
- vector_func_type vector_func =
- _get_vector_func(array->type, array->size, typeFunc);
- if (vector_func)
- {
- vector_func(array->ptr + getMulFactorFromPointerArray(array) * indice);
- }
- }
-}
-
-static void _glElementArrayImmediate(int indice)
-{
- GET_CURRENT_STATE();
-
- if (state->client_state.arrays.interleavedArrays.ptr != NULL &&
- state->client_state.arrays.vertexArray.ptr == NULL)
- {
- GLboolean tflag, cflag, nflag; /* enable/disable flags */
- GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
- GLenum ctype = 0; /* color type */
- GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
- const GLint toffset = 0; /* always zero */
- GLint defstride; /* default stride */
- GLint c, f;
-
- int stride = state->client_state.arrays.interleavedArrays.stride;
-
- f = sizeof(GLfloat);
- c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
-
- switch (state->client_state.arrays.interleavedArrays.format) {
- case GL_V2F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 0; vcomps = 2;
- voffset = 0;
- defstride = 2*f;
- break;
- case GL_V3F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 0; vcomps = 3;
- voffset = 0;
- defstride = 3*f;
- break;
- case GL_C4UB_V2F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 4; vcomps = 2;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 0;
- voffset = c;
- defstride = c + 2*f;
- break;
- case GL_C4UB_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 4; vcomps = 3;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 0;
- voffset = c;
- defstride = c + 3*f;
- break;
- case GL_C3F_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 0; ccomps = 3; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 0;
- voffset = 3*f;
- defstride = 6*f;
- break;
- case GL_N3F_V3F:
- tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
- tcomps = 0; ccomps = 0; vcomps = 3;
- noffset = 0;
- voffset = 3*f;
- defstride = 6*f;
- break;
- case GL_C4F_N3F_V3F:
- tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 0; ccomps = 4; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 0;
- noffset = 4*f;
- voffset = 7*f;
- defstride = 10*f;
- break;
- case GL_T2F_V3F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 0; vcomps = 3;
- voffset = 2*f;
- defstride = 5*f;
- break;
- case GL_T4F_V4F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
- tcomps = 4; ccomps = 0; vcomps = 4;
- voffset = 4*f;
- defstride = 8*f;
- break;
- case GL_T2F_C4UB_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 4; vcomps = 3;
- ctype = GL_UNSIGNED_BYTE;
- coffset = 2*f;
- voffset = c+2*f;
- defstride = c+5*f;
- break;
- case GL_T2F_C3F_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
- tcomps = 2; ccomps = 3; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 2*f;
- voffset = 5*f;
- defstride = 8*f;
- break;
- case GL_T2F_N3F_V3F:
- tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
- tcomps = 2; ccomps = 0; vcomps = 3;
- noffset = 2*f;
- voffset = 5*f;
- defstride = 8*f;
- break;
- case GL_T2F_C4F_N3F_V3F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 2; ccomps = 4; vcomps = 3;
- ctype = GL_FLOAT;
- coffset = 2*f;
- noffset = 6*f;
- voffset = 9*f;
- defstride = 12*f;
- break;
- case GL_T4F_C4F_N3F_V4F:
- tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
- tcomps = 4; ccomps = 4; vcomps = 4;
- ctype = GL_FLOAT;
- coffset = 4*f;
- noffset = 8*f;
- voffset = 11*f;
- defstride = 15*f;
- break;
- default:
- log_gl("unknown interleaved array format : %d\n", state->client_state.arrays.interleavedArrays.format);
- return;
- }
-
- if (stride==0) {
- stride = defstride;
- }
-
- const void* ptr = state->client_state.arrays.interleavedArrays.ptr + indice * stride;
-
- if (tflag)
- {
- if (tcomps == 2)
- glTexCoord2fv(ptr + toffset);
- else if (tcomps == 4)
- glTexCoord4fv(ptr + toffset);
- else
- assert(0);
- }
-
- if (cflag)
- {
- if (ctype == GL_FLOAT)
- {
- if (ccomps == 3)
- glColor3fv(ptr + coffset);
- else if (ccomps == 4)
- glColor4fv(ptr + coffset);
- else
- assert(0);
- }
- else if (ctype == GL_UNSIGNED_BYTE)
- {
- if (ccomps == 4)
- glColor4ubv(ptr + coffset);
- else
- assert(0);
- }
- else
- assert(0);
- }
-
- if (nflag)
- glNormal3fv(ptr + noffset);
-
- if (vcomps == 2)
- glVertex2fv(ptr + voffset);
- else if (vcomps == 3)
- glVertex3fv(ptr + voffset);
- else if (vcomps == 4)
- glVertex4fv(ptr + voffset);
- else
- assert(0);
-
- return;
- }
-
- int i;
-
- int prevActiveTexture = state->activeTexture;
- for(i=0;i<NB_MAX_TEXTURES;i++)
- {
- if (state->client_state.arrays.texCoordArray[i].enabled)
- {
- if (i != 0 || state->activeTexture != GL_TEXTURE0_ARB)
- glActiveTextureARB(GL_TEXTURE0_ARB + i);
- _glElementArrayImmediate_one(&state->client_state.arrays.texCoordArray[i], indice, TEXCOORD_FUNC);
- }
- }
- glActiveTextureARB(prevActiveTexture);
-
- _glElementArrayImmediate_one(&state->client_state.arrays.normalArray, indice, NORMAL_FUNC);
- _glElementArrayImmediate_one(&state->client_state.arrays.colorArray, indice, COLOR_FUNC);
- _glElementArrayImmediate_one(&state->client_state.arrays.indexArray, indice, INDEX_FUNC);
- _glElementArrayImmediate_one(&state->client_state.arrays.vertexArray, indice, VERTEX_FUNC);
-}
-
-static void _glArraysSend(int first, int last)
-{
- GET_CURRENT_STATE();
- if (debug_array_ptr)
- {
- log_gl("_glArraysSend from %d to %d\n", first, last);
- }
-
-
- int startIndiceTextureToDealtWith = 0;
- int i;
- int nbElts = 1 + last;
-
- if (_glIsEnabled(GL_VERTEX_PROGRAM_NV))
- {
- int vertexProgramNV = 0;
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_NV;i++)
- {
- ClientArray* array = &state->client_state.arrays.vertexAttribArrayNV[i];
- if (!(array->ptr == NULL || array->enabled == 0))
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glVertexAttribPointerNV), array, first, last);
- vertexProgramNV = 1;
- }
- }
- if (vertexProgramNV)
- return;
- }
-
- if (state->client_state.arrays.interleavedArrays.ptr != NULL &&
- state->client_state.arrays.vertexArray.ptr == NULL)
- {
- int stride;
- if (state->client_state.arrays.interleavedArrays.stride)
- stride = state->client_state.arrays.interleavedArrays.stride;
- else
- stride = _calc_interleaved_arrays_stride(state->client_state.arrays.interleavedArrays.format);
- if (stride == 0) return;
- int offset = stride * first;
- int size = (last - first + 1) * stride;
- long args[] = { offset,
- state->client_state.arrays.interleavedArrays.format,
- state->client_state.arrays.interleavedArrays.stride,
- size,
- POINTER_TO_ARG(state->client_state.arrays.interleavedArrays.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, size };
- do_opengl_call(glInterleavedArrays_fake_func, NULL, CHECK_ARGS(args, args_size));
- return;
- }
-
- int normalArrayOffset = (long)state->client_state.arrays.normalArray.ptr -
- (long)state->client_state.arrays.vertexArray.ptr;
- int colorArrayOffset = (long)state->client_state.arrays.colorArray.ptr -
- (long)state->client_state.arrays.vertexArray.ptr;
- int texCoord0PointerOffset = (long)state->client_state.arrays.texCoordArray[0].ptr -
- (long)state->client_state.arrays.vertexArray.ptr;
- int texCoord1PointerOffset = (long)state->client_state.arrays.texCoordArray[1].ptr -
- (long)state->client_state.arrays.vertexArray.ptr;
- int texCoord2PointerOffset = (long)state->client_state.arrays.texCoordArray[2].ptr -
- (long)state->client_state.arrays.vertexArray.ptr;
-
- if (state->client_state.arrays.vertexArray.vbo_name ||
- state->client_state.arrays.colorArray.vbo_name ||
- state->client_state.arrays.normalArray.vbo_name ||
- state->client_state.arrays.texCoordArray[0].vbo_name ||
- state->client_state.arrays.texCoordArray[1].vbo_name ||
- state->client_state.arrays.texCoordArray[2].vbo_name)
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glVertexPointer), &state->client_state.arrays.vertexArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glNormalPointer), &state->client_state.arrays.normalArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glColorPointer), &state->client_state.arrays.colorArray, first, last);
- }
- else
- if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled == 0 &&
- state->client_state.arrays.colorArray.enabled &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.colorArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexColorTexCoord0PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(colorArrayOffset),
- INT_TO_ARG(state->client_state.arrays.colorArray.size),
- INT_TO_ARG(state->client_state.arrays.colorArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexColorTexCoord0PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 1;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.texCoordArray[2].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[1].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[2].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord1PointerOffset >= 0 &&
- texCoord1PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord2PointerOffset >= 0 &&
- texCoord2PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 4 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalColorTexCoord012PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(colorArrayOffset),
- INT_TO_ARG(state->client_state.arrays.colorArray.size),
- INT_TO_ARG(state->client_state.arrays.colorArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(texCoord1PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].type),
- INT_TO_ARG(texCoord2PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[2].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[2].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalColorTexCoord012PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 3;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[1].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord1PointerOffset >= 0 &&
- texCoord1PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalColorTexCoord01PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(colorArrayOffset),
- INT_TO_ARG(state->client_state.arrays.colorArray.size),
- INT_TO_ARG(state->client_state.arrays.colorArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(texCoord1PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalColorTexCoord01PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 2;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled == 0 &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.texCoordArray[2].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[1].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[2].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord1PointerOffset >= 0 &&
- texCoord1PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord2PointerOffset >= 0 &&
- texCoord2PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalTexCoord012PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(texCoord1PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].type),
- INT_TO_ARG(texCoord2PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[2].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[2].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalTexCoord012PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 3;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled == 0 &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[1].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord1PointerOffset >= 0 &&
- texCoord1PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalTexCoord01PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(texCoord1PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[1].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalTexCoord01PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 2;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled == 0 &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalTexCoord0PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalTexCoord0PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 1;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.colorArray.enabled &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.colorArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.texCoordArray[0].stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < state->client_state.arrays.vertexArray.stride &&
- texCoord0PointerOffset >= 0 &&
- texCoord0PointerOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalColorTexCoord0PointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(colorArrayOffset),
- INT_TO_ARG(state->client_state.arrays.colorArray.size),
- INT_TO_ARG(state->client_state.arrays.colorArray.type),
- INT_TO_ARG(texCoord0PointerOffset),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalColorTexCoord0PointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 1;
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- getMulFactorFromPointerArray(&state->client_state.arrays.vertexArray) ==
- getMulFactorFromPointerArray(&state->client_state.arrays.normalArray) &&
- state->client_state.arrays.vertexArray.ptr == state->client_state.arrays.normalArray.ptr)
- {
- /* Special optimization for earth3d */
- int data_size = nbElts * getMulFactorFromPointerArray(&state->client_state.arrays.vertexArray);
-
- if (debug_array_ptr)
- {
- log_gl("glVertexAndNormalPointer_fake_func sending %d bytes from %d\n",
- data_size,
- 0);
- }
-
- long args[] = { INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(state->client_state.arrays.normalArray.stride),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, data_size };
- do_opengl_call(glVertexAndNormalPointer_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
-
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- /*state->client_state.arrays.colorArray.enabled && */
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.colorArray.stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* Special optimization for tuxracer */
- /*
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer( 3, GL_FLOAT, STRIDE_GL_ARRAY, vnc_array );
-
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer( GL_FLOAT, STRIDE_GL_ARRAY,
- vnc_array + 4*sizeof(GLfloat) );
-
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer( 4, GL_UNSIGNED_BYTE, STRIDE_GL_ARRAY,
- vnc_array + 8*sizeof(GLfloat) );
- */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalColorPointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(colorArrayOffset),
- INT_TO_ARG(state->client_state.arrays.colorArray.size),
- INT_TO_ARG(state->client_state.arrays.colorArray.type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- data_size};
- do_opengl_call(glVertexNormalColorPointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
- else if (state->client_state.arrays.vertexArray.enabled &&
- state->client_state.arrays.normalArray.enabled &&
- state->client_state.arrays.vertexArray.ptr != NULL &&
- state->client_state.arrays.vertexArray.stride != 0 &&
- state->client_state.arrays.vertexArray.stride == state->client_state.arrays.normalArray.stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < state->client_state.arrays.vertexArray.stride)
- {
- /* For unreal tournament 3 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int offset = first * state->client_state.arrays.vertexArray.stride;
- int data_size = (last - first + 1) * state->client_state.arrays.vertexArray.stride;
-
- if (debug_array_ptr)
- {
- log_gl("glVertexNormalPointerInterlaced_fake_func sending %d bytes from %d\n",
- data_size,
- offset);
- }
- long args[] = { INT_TO_ARG(offset),
- INT_TO_ARG(state->client_state.arrays.vertexArray.size),
- INT_TO_ARG(state->client_state.arrays.vertexArray.type),
- INT_TO_ARG(state->client_state.arrays.vertexArray.stride),
- INT_TO_ARG(normalArrayOffset),
- INT_TO_ARG(state->client_state.arrays.normalArray.type),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.vertexArray.ptr + offset) };
- int args_size[] = { 0, 0, 0, 0, 0, 0, 0, data_size};
- do_opengl_call(glVertexNormalPointerInterlaced_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- _glArraySend(state, ARRAY_SEND_FUNC(glColorPointer), &state->client_state.arrays.colorArray, first, last);
- }
- else
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glVertexPointer), &state->client_state.arrays.vertexArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glNormalPointer), &state->client_state.arrays.normalArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glColorPointer), &state->client_state.arrays.colorArray, first, last);
- }
-
- _glArraySend(state, ARRAY_SEND_FUNC(glSecondaryColorPointer), &state->client_state.arrays.secondaryColorArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glEdgeFlagPointer), &state->client_state.arrays.edgeFlagArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glIndexPointer), &state->client_state.arrays.indexArray, first, last);
-
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glVertexAttribPointerARB), &state->client_state.arrays.vertexAttribArray[i], first, last);
- }
- for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glVariantPointerEXT), &state->client_state.arrays.variantPointer[i], first, last);
- }
-
- if (startIndiceTextureToDealtWith == 0 &&
- state->client_state.arrays.texCoordArray[0].vbo_name == 0 &&
- state->client_state.arrays.texCoordArray[1].vbo_name == 0 &&
- state->client_state.arrays.texCoordArray[2].vbo_name == 0 &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.texCoordArray[2].enabled &&
- state->client_state.arrays.texCoordArray[0].ptr &&
- state->client_state.arrays.texCoordArray[0].ptr == state->client_state.arrays.texCoordArray[1].ptr &&
- state->client_state.arrays.texCoordArray[0].size == state->client_state.arrays.texCoordArray[1].size &&
- state->client_state.arrays.texCoordArray[0].type == state->client_state.arrays.texCoordArray[1].type &&
- state->client_state.arrays.texCoordArray[0].stride == state->client_state.arrays.texCoordArray[1].stride &&
- state->client_state.arrays.texCoordArray[0].ptr == state->client_state.arrays.texCoordArray[2].ptr &&
- state->client_state.arrays.texCoordArray[0].size == state->client_state.arrays.texCoordArray[2].size &&
- state->client_state.arrays.texCoordArray[0].type == state->client_state.arrays.texCoordArray[2].type &&
- state->client_state.arrays.texCoordArray[0].stride == state->client_state.arrays.texCoordArray[2].stride)
- {
- /* For unreal tournament 4 with GL_EXTENSIONS="GL_EXT_bgra GL_EXT_texture_compression_s3tc" */
- int data_size = nbElts * getMulFactorFromPointerArray(&state->client_state.arrays.texCoordArray[0]);
- if (debug_array_ptr)
- {
- log_gl("glTexCoordPointer012_fake_func sending %d bytes from %d\n",
- data_size,
- 0);
- }
-
- long args[] = { INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].stride),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.texCoordArray[0].ptr) };
- int args_size[] = { 0, 0, 0, 0, data_size };
- do_opengl_call(glTexCoordPointer012_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 3;
- }
- else
- if (startIndiceTextureToDealtWith == 0 &&
- state->client_state.arrays.texCoordArray[0].vbo_name == 0 &&
- state->client_state.arrays.texCoordArray[1].vbo_name == 0 &&
- state->client_state.arrays.texCoordArray[0].enabled &&
- state->client_state.arrays.texCoordArray[1].enabled &&
- state->client_state.arrays.texCoordArray[0].ptr &&
- state->client_state.arrays.texCoordArray[0].ptr == state->client_state.arrays.texCoordArray[1].ptr &&
- state->client_state.arrays.texCoordArray[0].size == state->client_state.arrays.texCoordArray[1].size &&
- state->client_state.arrays.texCoordArray[0].type == state->client_state.arrays.texCoordArray[1].type &&
- state->client_state.arrays.texCoordArray[0].stride == state->client_state.arrays.texCoordArray[1].stride)
- {
- /* Special optimization for earth3d */
- int data_size = nbElts * getMulFactorFromPointerArray(&state->client_state.arrays.texCoordArray[0]);
- if (debug_array_ptr)
- {
- log_gl("glTexCoordPointer01_fake_func sending %d bytes from %d\n",
- data_size,
- 0);
- }
-
- long args[] = { INT_TO_ARG(state->client_state.arrays.texCoordArray[0].size),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].type),
- INT_TO_ARG(state->client_state.arrays.texCoordArray[0].stride),
- INT_TO_ARG(data_size),
- POINTER_TO_ARG(state->client_state.arrays.texCoordArray[0].ptr) };
- int args_size[] = { 0, 0, 0, 0, data_size };
- do_opengl_call(glTexCoordPointer01_fake_func, NULL, CHECK_ARGS(args, args_size));
-
- startIndiceTextureToDealtWith = 2;
- }
-
- for(i=startIndiceTextureToDealtWith;i<NB_MAX_TEXTURES;i++)
- {
- _glArraySend(state, ARRAY_SEND_FUNC(glTexCoordPointer), &state->client_state.arrays.texCoordArray[i], first, last);
- }
-
- _glArraySend(state, ARRAY_SEND_FUNC(glWeightPointerARB), &state->client_state.arrays.weightArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glMatrixIndexPointerARB), &state->client_state.arrays.matrixIndexArray, first, last);
- _glArraySend(state, ARRAY_SEND_FUNC(glFogCoordPointer), &state->client_state.arrays.fogCoordArray, first, last);
-}
-
-#define ASSERT_COND(cond, val) do { if (!(val)) { state->lastGlError = val; return; } } while(0)
-#define CLEAR_ERROR_STATE() do { state->lastGlError = 0; } while(0)
-
-
-GLAPI void APIENTRY EXT_FUNC(glLockArraysEXT) (GLint first, GLsizei count)
-{
- /* Quite difficult to be correctly implemented IMHO for a doubtful performance gain */
- /* You need to send data for enabled arrays at this moment, but then for */
- /* the glDrawArrays, glDrawElements, etc... you need to check if enough data has been sent */
- /* For ex consider the following code :
- glVertexPointer(.....);
- glColorPointer(......);
- glNormalPointer(.....);
- glEnableClientState(GL_VERTEX_ARRAY);
- glLockArraysEXT(0, 16); (1)
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glDrawArrays(GL_TRIANGLE, 0, 20); (2)
- glUnlockArraysEXT();
- */
- /* At (1), you need to send 16 vertices, but at (2) you need to send the */
- /* 4 following ones, or either the whole 20... */
- CHECK_PROC(glLockArraysEXT);
- GET_CURRENT_STATE();
- ASSERT_COND(first >= 0, GL_INVALID_VALUE);
- ASSERT_COND(count > 0, GL_INVALID_VALUE);
- ASSERT_COND(state->isBetweenLockArrays == 0, GL_INVALID_OPERATION);
- ASSERT_COND(state->isBetweenBegin == 0, GL_INVALID_OPERATION);
-
- if (debug_array_ptr)
- {
- log_gl("glLockArraysEXT(%d,%d)\n", first, count);
- }
-
- state->isBetweenLockArrays = 1;
-
- state->locked_first = first;
- state->locked_count = count;
-
- CLEAR_ERROR_STATE();
-}
-
-GLAPI void APIENTRY EXT_FUNC(glUnlockArraysEXT) ()
-{
- CHECK_PROC(glUnlockArraysEXT);
- GET_CURRENT_STATE();
- ASSERT_COND(state->isBetweenLockArrays == 1, GL_INVALID_OPERATION);
- ASSERT_COND(state->isBetweenBegin == 0, GL_INVALID_OPERATION);
-
- if (debug_array_ptr)
- {
- log_gl("glUnlockArraysEXT()\n");
- }
-
- state->isBetweenLockArrays = 0;
-
- CLEAR_ERROR_STATE();
-}
-
-GLAPI void APIENTRY glArrayElement( GLint i )
-{
- Buffer* buffer = _get_buffer(GL_ARRAY_BUFFER_ARB);
- if (buffer)
- {
- long args[] = { INT_TO_ARG(i) };
- do_opengl_call(glArrayElement_func, NULL, args, NULL);
- }
- else
- {
- _glElementArrayImmediate(i);
- }
-}
-
-GLAPI void APIENTRY glDrawArrays( GLenum mode,
- GLint first,
- GLsizei count )
-{
- if (debug_array_ptr) log_gl("glDrawArrays(%d,%d,%d)\n", mode, first, count);
-
- _glArraysSend(first, first + count - 1);
-
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(first), INT_TO_ARG(count) };
- do_opengl_call(glDrawArrays_func, NULL, args, NULL);
-}
-
-static int _isTuxRacer(GLState* state)
-{
- int i;
- ClientArrays* arrays = &state->client_state.arrays;
- if (arrays->vertexArray.vbo_name ||
- arrays->normalArray.vbo_name ||
- arrays->colorArray.vbo_name ||
- arrays->vertexArray.enabled == 0 ||
- arrays->normalArray.enabled == 0)
- return 0;
-
- int normalArrayOffset = (long)arrays->normalArray.ptr - (long)arrays->vertexArray.ptr;
- int colorArrayOffset = (long)arrays->colorArray.ptr - (long)arrays->vertexArray.ptr;
-
- if (!(arrays->vertexArray.ptr != NULL &&
- arrays->vertexArray.stride != 0 &&
- arrays->vertexArray.stride == arrays->normalArray.stride &&
- arrays->vertexArray.stride == arrays->colorArray.stride &&
- normalArrayOffset >= 0 &&
- normalArrayOffset < arrays->vertexArray.stride &&
- colorArrayOffset >= 0 &&
- colorArrayOffset < arrays->vertexArray.stride))
- return 0;
-
- if (!(arrays->vertexArray.type == GL_FLOAT && arrays->vertexArray.size == 3 &&
- arrays->normalArray.type == GL_FLOAT &&
- arrays->colorArray.type == GL_UNSIGNED_BYTE && arrays->colorArray.size == 4))
- return 0;
-
- if (arrays->secondaryColorArray.enabled ||
- arrays->indexArray.enabled ||
- arrays->edgeFlagArray.enabled ||
- arrays->weightArray.enabled ||
- arrays->matrixIndexArray.enabled ||
- arrays->fogCoordArray.enabled)
- return 0;
-
- for(i=0;i<NB_MAX_TEXTURES;i++)
- {
- if (arrays->texCoordArray[i].enabled)
- return 0;
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
- {
- if (arrays->vertexAttribArray[i].enabled)
- return 0;
- }
- return 1;
-}
-
-static int _check_if_enabled_non_vbo_array()
-{
- int i;
- GET_CURRENT_STATE();
- ClientArrays* arrays = &state->client_state.arrays;
-
- if (arrays->vertexArray.vbo_name == 0 && arrays->vertexArray.enabled)
- return 1;
- if (arrays->normalArray.vbo_name == 0 && arrays->normalArray.enabled)
- return 1;
- if (arrays->colorArray.vbo_name == 0 && arrays->colorArray.enabled)
- return 1;
- if (arrays->secondaryColorArray.vbo_name == 0 && arrays->secondaryColorArray.enabled)
- return 1;
- if (arrays->indexArray.vbo_name == 0 && arrays->indexArray.enabled)
- return 1;
- if (arrays->edgeFlagArray.vbo_name == 0 && arrays->edgeFlagArray.enabled)
- return 1;
- if (arrays->weightArray.vbo_name == 0 && arrays->weightArray.enabled)
- return 1;
- if (arrays->matrixIndexArray.vbo_name == 0 && arrays->matrixIndexArray.enabled)
- return 1;
- if (arrays->fogCoordArray.vbo_name == 0 && arrays->fogCoordArray.enabled)
- return 1;
- for(i=0;i<NB_MAX_TEXTURES;i++)
- {
- if (arrays->texCoordArray[i].vbo_name == 0 && arrays->texCoordArray[i].enabled)
- return 1;
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
- {
- if (arrays->vertexAttribArray[i].vbo_name == 0 && arrays->vertexAttribArray[i].enabled)
- return 1;
- }
- for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
- {
- if (arrays->variantPointer[i].vbo_name == 0 && arrays->variantPointer[i].enabled)
- return 1;
- }
-
- return 0;
-}
-
-GLAPI void APIENTRY glDrawElements( GLenum mode,
- GLsizei count,
- GLenum type,
- const GLvoid *indices )
-{
- CHECK_PROC(glDrawElements);
- int i;
- int size = count;
- //Buffer* bufferArray;
- Buffer* bufferElement;
-
- if (debug_array_ptr) log_gl("glDrawElements(%d,%d,%d,%p)\n", mode, count, type, indices);
-
- if (count == 0) return;
-
- //bufferArray = _get_buffer(GL_ARRAY_BUFFER_ARB);
- bufferElement = _get_buffer(GL_ELEMENT_ARRAY_BUFFER_ARB);
- if (bufferElement)
- {
- if (_check_if_enabled_non_vbo_array())
- {
- log_gl("sorry : unsupported : glDrawElements in EBO with a non VBO array enabled\n");
- return;
- }
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(count), INT_TO_ARG(type), POINTER_TO_ARG(indices) };
- do_opengl_call(_glDrawElements_buffer_func, NULL, args, NULL);
- return;
- }
-
-
- int minIndice = 0;
- int maxIndice = -1;
-
- switch(type)
- {
- case GL_UNSIGNED_BYTE:
- {
- //if (!bufferArray)
- {
- unsigned char* tab_indices = (unsigned char*)indices;
- minIndice = tab_indices[0];
- maxIndice = tab_indices[0];
- for(i=1;i<count;i++)
- {
- if (tab_indices[i] < minIndice) minIndice = tab_indices[i];
- if (tab_indices[i] > maxIndice) maxIndice = tab_indices[i];
- }
- }
- break;
- }
-
- case GL_UNSIGNED_SHORT:
- {
- size *= 2;
- //if (!bufferArray)
- {
- unsigned short* tab_indices = (unsigned short*)indices;
- minIndice = tab_indices[0];
- maxIndice = tab_indices[0];
- for(i=1;i<count;i++)
- {
- if (tab_indices[i] < minIndice) minIndice = tab_indices[i];
- if (tab_indices[i] > maxIndice) maxIndice = tab_indices[i];
- }
- }
- break;
- }
-
- case GL_UNSIGNED_INT:
- {
- size *= 4;
- //if (!bufferArray)
- {
- unsigned int* tab_indices = (unsigned int*)indices;
- minIndice = tab_indices[0];
- maxIndice = tab_indices[0];
- for(i=1;i<count;i++)
- {
- if (tab_indices[i] < minIndice) minIndice = tab_indices[i];
- if (tab_indices[i] > maxIndice) maxIndice = tab_indices[i];
- }
- //log_gl("maxIndice = %d\n", maxIndice);
- if (maxIndice > 100 * 1024 * 1024)
- {
- log_gl("too big indice : %d\n",maxIndice);
- return;
- }
- }
- break;
- }
-
- default:
- log_gl("unsupported type = %d\n", type);
- return;
- }
-
- GET_CURRENT_STATE();
- if (_isTuxRacer(state) && type == GL_UNSIGNED_INT)
- {
- /* Special optimization for tuxracer */
- /*
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer( 3, GL_FLOAT, STRIDE_GL_ARRAY, vnc_array );
-
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer( GL_FLOAT, STRIDE_GL_ARRAY,
- vnc_array + 4*sizeof(GLfloat) );
-
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer( 4, GL_UNSIGNED_BYTE, STRIDE_GL_ARRAY,
- vnc_array + 8*sizeof(GLfloat) );
- */
- ClientArrays* arrays = &state->client_state.arrays;
- int stride = arrays->vertexArray.stride;
- int bufferSize = (maxIndice - minIndice + 1) * stride + sizeof(int) * count;
- int eltSize = 6 * sizeof(float) + ((arrays->colorArray.enabled) ? 4 * sizeof(unsigned char) : 0);
- int singleCommandSize = count * eltSize;
- if (count < bufferSize)
- {
- unsigned int* tab_indices = (unsigned int*)indices;
- const char* vertexArray = (const char*)arrays->vertexArray.ptr;
- int normalArrayOffset = (long)arrays->normalArray.ptr - (long)arrays->vertexArray.ptr;
- int colorArrayOffset = (long)arrays->colorArray.ptr - (long)arrays->vertexArray.ptr;
- state->tuxRacerBuffer = realloc(state->tuxRacerBuffer, singleCommandSize);
-
- for(i=0;i<count;i++)
- {
- int ind = tab_indices[i];
- memcpy(&state->tuxRacerBuffer[i * eltSize], &vertexArray[ind * stride], 3 * sizeof(float));
- memcpy(&state->tuxRacerBuffer[i * eltSize + 3 * sizeof(float)],
- &vertexArray[ind * stride + normalArrayOffset], 3 * sizeof(float));
- if (arrays->colorArray.enabled)
- memcpy(&state->tuxRacerBuffer[i * eltSize + 6 * sizeof(float)],
- &vertexArray[ind * stride + colorArrayOffset], 4 * sizeof(unsigned char));
- }
-
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(count), INT_TO_ARG(arrays->colorArray.enabled), POINTER_TO_ARG(state->tuxRacerBuffer) };
- int args_size[] = { 0, 0, 0, singleCommandSize} ;
- do_opengl_call(glTuxRacerDrawElements_fake_func, NULL, CHECK_ARGS(args, args_size));
- return;
- }
- }
- _glArraysSend(minIndice, maxIndice);
-
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(count), INT_TO_ARG(type), POINTER_TO_ARG(indices) };
- int args_size[] = { 0, 0, 0, (indices) ? size : 0 } ;
- do_opengl_call(glDrawElements_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-GLAPI void APIENTRY glDrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices )
-{
- CHECK_PROC(glDrawRangeElements);
- int size = count;
- Buffer* bufferElement;
-
- if (debug_array_ptr) log_gl("glDrawRangeElements(0x%X, %d, %d, %d, %d, %p)\n", mode, start, end, count, type, indices);
-
- if (count == 0) return;
-
- /* Yes : try to send regular arrays even if GL_ELEMENT_ARRAY_BUFFER_ARB is enabled.
- This is necessary for nexuiz 2.3 where in GL_ELEMENT_ARRAY_BUFFER_ARB some arrays are regular array pointers,
- and some others are stored in VBO... */
- _glArraysSend(start, end);
-
- bufferElement = _get_buffer(GL_ELEMENT_ARRAY_BUFFER_ARB);
- if (bufferElement)
- {
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(start), INT_TO_ARG(end), INT_TO_ARG(count), INT_TO_ARG(type), POINTER_TO_ARG(indices) };
- do_opengl_call(_glDrawRangeElements_buffer_func, NULL, args, NULL);
- return;
- }
-#if 0
- int i;
- switch(type)
- {
- case GL_UNSIGNED_BYTE:
- {
- unsigned char* tab_indices = (unsigned char*)indices;
- for(i=0;i<count;i++)
- {
- if (tab_indices[i] < start || tab_indices[i] > end)
- {
- log_gl("indice out of bounds at offset %d\n", i);
- }
- }
- break;
- }
-
- case GL_UNSIGNED_SHORT:
- {
- size *= 2;
- unsigned short* tab_indices = (unsigned short*)indices;
- for(i=0;i<count;i++)
- {
- if (tab_indices[i] < start || tab_indices[i] > end)
- {
- log_gl("indice out of bounds at offset %d\n", i);
- }
- }
- break;
- }
-
- case GL_UNSIGNED_INT:
- {
- size *= 4;
- unsigned int* tab_indices = (unsigned int*)indices;
- for(i=0;i<count;i++)
- {
- if (tab_indices[i] < start || tab_indices[i] > end)
- {
- log_gl("indice out of bounds at offset %d\n", i);
- }
- }
- break;
- }
-
- default:
- log_gl("unsupported type = %d\n", type);
- return;
- }
-#else
- switch(type)
- {
- case GL_UNSIGNED_BYTE:
- {
- }
-
- case GL_UNSIGNED_SHORT:
- {
- size *= 2;
- break;
- }
-
- case GL_UNSIGNED_INT:
- {
- size *= 4;
- break;
- }
-
- default:
- log_gl("unsupported type = %d\n", type);
- return;
- }
-#endif
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(start), INT_TO_ARG(end),
- INT_TO_ARG(count), INT_TO_ARG(type), POINTER_TO_ARG(indices) };
- int args_size[] = { 0, 0, 0, 0, 0, size } ;
- do_opengl_call(glDrawRangeElements_func, NULL, CHECK_ARGS(args, args_size));
-
-}
-
-DEFINE_EXT(glDrawRangeElements, ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ),
- (mode, start, end, count, type, indices) )
-
-
-GLAPI void APIENTRY glMultiDrawArrays( GLenum mode, GLint *first,
- GLsizei *count, GLsizei primcount )
-{
- GLint i;
-
- for (i = 0; i < primcount; i++) {
- if (count[i] > 0) {
- glDrawArrays(mode, first[i], count[i]);
- }
- }
-}
-
-DEFINE_EXT(glMultiDrawArrays, ( GLenum mode, GLint *first,
- GLsizei *count, GLsizei primcount ),
- (mode, first, count, primcount) )
-
-GLAPI void APIENTRY glMultiDrawElements( GLenum mode, const GLsizei *count, GLenum type,
- const GLvoid **indices, GLsizei primcount )
-{
- GLint i;
- CHECK_PROC(glMultiDrawElements);
-
- Buffer* bufferElement = _get_buffer(GL_ELEMENT_ARRAY_BUFFER_ARB);
- if (bufferElement && primcount > 1)
- {
- if (_check_if_enabled_non_vbo_array())
- {
- log_gl("sorry : unsupported : glMultiDrawElements in EBO with a non VBO array enabled\n");
- return;
- }
- long args[] = { INT_TO_ARG(mode), POINTER_TO_ARG(count), INT_TO_ARG(type),
- POINTER_TO_ARG(indices), INT_TO_ARG(primcount) };
- int args_size[] = { 0, primcount * sizeof(int), 0, primcount * sizeof(void*), 0 };
- do_opengl_call(_glMultiDrawElements_buffer_func, NULL, args, args_size);
- return;
- }
-
- for (i = 0; i < primcount; i++) {
- if (count[i] > 0) {
- glDrawElements(mode, count[i], type, indices[i]);
- }
- }
-}
-
-DEFINE_EXT(glMultiDrawElements, ( GLenum mode, const GLsizei *count, GLenum type,
- const GLvoid **indices, GLsizei primcount ),
- (mode, count, type, indices, primcount) )
-
-
-#if 0
-GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset)
-{
- CHECK_PROC(glArrayObjectATI);
- //log_gl("glArrayObjectATI(array=%p, size=%d, type=%p, stride=%d, buffer=%d, offset=%d)\n", array, size, type, stride, buffer, offset);
- long args[] = { UNSIGNED_INT_TO_ARG(array), INT_TO_ARG(size), UNSIGNED_INT_TO_ARG(type), INT_TO_ARG(stride), UNSIGNED_INT_TO_ARG(buffer), UNSIGNED_INT_TO_ARG(offset)};
- do_opengl_call(glArrayObjectATI_func, NULL, args, NULL);
-}
-#endif
-
-GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count)
-{
- CHECK_PROC(glDrawElementArrayATI);
- GET_CURRENT_STATE();
-
- if (state->client_state.arrays.elementArrayATI.enabled &&
- state->client_state.arrays.elementArrayATI.ptr != NULL)
- {
- int size = count * getMulFactorFromPointerArray(&state->client_state.arrays.elementArrayATI);
- long args[] = { INT_TO_ARG(state->client_state.arrays.elementArrayATI.type),
- INT_TO_ARG(size),
- INT_TO_ARG(state->client_state.arrays.elementArrayATI.ptr) };
- int args_size[] = {0, 0, size};
- do_opengl_call(glElementPointerATI_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
-
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(count) };
- do_opengl_call(glDrawElementArrayATI_func, NULL, args, NULL);
-}
-
-GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count)
-{
- CHECK_PROC(glDrawRangeElementArrayATI);
- GET_CURRENT_STATE();
-
- if (state->client_state.arrays.elementArrayATI.enabled &&
- state->client_state.arrays.elementArrayATI.ptr != NULL)
- {
- int size = count * getMulFactorFromPointerArray(&state->client_state.arrays.elementArrayATI);
- long args[] = { INT_TO_ARG(state->client_state.arrays.elementArrayATI.type),
- INT_TO_ARG(size),
- INT_TO_ARG(state->client_state.arrays.elementArrayATI.ptr) };
- int args_size[] = {0, 0, size};
- do_opengl_call(glElementPointerATI_fake_func, NULL, CHECK_ARGS(args, args_size));
- }
-
- long args[] = { INT_TO_ARG(mode), INT_TO_ARG(start), INT_TO_ARG(end), INT_TO_ARG(count) };
- do_opengl_call(glDrawRangeElementArrayATI_func, NULL, args, NULL);
-}
-
-GLAPI GLuint APIENTRY glGenSymbolsEXT(GLenum datatype, GLenum storagetype, GLenum range, GLuint components)
-{
- GLuint id = 0;
- CHECK_PROC_WITH_RET(glGenSymbolsEXT);
- GET_CURRENT_STATE();
- long args[] = { datatype, storagetype, range, components };
- do_opengl_call(glGenSymbolsEXT_func, &id, args, NULL);
- if (id != 0)
- {
- state->symbols.tab = realloc(state->symbols.tab, (state->symbols.count+1) * sizeof(Symbol));
- state->symbols.tab[state->symbols.count].id = id;
- state->symbols.tab[state->symbols.count].datatype = datatype;
- state->symbols.tab[state->symbols.count].components = components;
- state->symbols.count++;
- }
- return id;
-}
-
-static int get_vertex_shader_var_nb_composants(GLuint id)
-{
- GET_CURRENT_STATE();
- int i;
- for(i=0;i<state->symbols.count;i++)
- {
- if (id >= state->symbols.tab[i].id && id < state->symbols.tab[i].id + state->symbols.tab[i].components)
- {
- int size = 0;
-
- if (state->symbols.tab[i].datatype == GL_SCALAR_EXT)
- size = 1;
- else if (state->symbols.tab[i].datatype == GL_VECTOR_EXT)
- size = 4;
- else if (state->symbols.tab[i].datatype == GL_MATRIX_EXT)
- size = 16;
- else
- {
- log_gl("unknown datatype %d\n", state->symbols.tab[i].datatype);
- return 0;
- }
-
- return size;
- }
- }
- log_gl("unknown id %d\n", id);
- return 0;
-}
-
-GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const GLvoid *addr)
-{
- CHECK_PROC(glSetLocalConstantEXT);
- int size = get_vertex_shader_var_nb_composants(id) * getGlTypeByteSize(type);
- if (size)
- {
- long args[] = { id, type, POINTER_TO_ARG(addr) };
- int args_size[] = { 0, 0, size };
-
- do_opengl_call(glSetLocalConstantEXT_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const GLvoid *addr)
-{
- CHECK_PROC(glSetInvariantEXT);
- int size = get_vertex_shader_var_nb_composants(id) * getGlTypeByteSize(type);
- if (size)
- {
- long args[] = { id, type, POINTER_TO_ARG(addr) };
- int args_size[] = { 0, 0, size };
-
- do_opengl_call(glSetInvariantEXT_func, NULL, CHECK_ARGS(args, args_size));
- }
-}
-
-#define glVariantGeneric(func_name, gltype) \
- GLAPI void APIENTRY func_name (GLuint id, const gltype * addr)\
-{\
- CHECK_PROC(func_name); \
- int size = get_vertex_shader_var_nb_composants(id) * sizeof(gltype); \
- if (size) \
- { \
- long args[] = { id, POINTER_TO_ARG(addr) }; \
- int args_size[] = { 0, size }; \
- do_opengl_call(CONCAT(func_name,_func), NULL, CHECK_ARGS(args, args_size)); \
- } \
-}
-
-glVariantGeneric(glVariantbvEXT, GLbyte);
-glVariantGeneric(glVariantsvEXT, GLshort);
-glVariantGeneric(glVariantivEXT, GLint);
-glVariantGeneric(glVariantfvEXT, GLfloat);
-glVariantGeneric(glVariantdvEXT, GLdouble);
-glVariantGeneric(glVariantubvEXT, GLubyte);
-glVariantGeneric(glVariantusvEXT, GLushort);
-glVariantGeneric(glVariantuivEXT, GLuint);
-
-GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id)
-{
- CHECK_PROC(glEnableVariantClientStateEXT);
- long args[] = { id };
- do_opengl_call(glEnableVariantClientStateEXT_func, NULL, args, NULL);
- if (id < MY_GL_MAX_VARIANT_POINTER_EXT)
- {
- GET_CURRENT_STATE();
- state->client_state.arrays.variantPointer[id].enabled = 1;
- }
-}
-
-GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id)
-{
- CHECK_PROC(glDisableVariantClientStateEXT);
- long args[] = { id };
- do_opengl_call(glDisableVariantClientStateEXT_func, NULL, args, NULL);
- if (id < MY_GL_MAX_VARIANT_POINTER_EXT)
- {
- GET_CURRENT_STATE();
- state->client_state.arrays.variantPointer[id].enabled = 0;
- }
-}
-
-GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const GLvoid *ptr)
-{
- CHECK_PROC(glVariantPointerEXT);
-
- GET_CURRENT_STATE();
- if (id < MY_GL_MAX_VARIANT_POINTER_EXT)
- {
- state->client_state.arrays.variantPointer[id].vbo_name = state->arrayBuffer;
- if (state->client_state.arrays.variantPointer[id].vbo_name)
- {
- long args[] = { INT_TO_ARG(id), INT_TO_ARG(type), INT_TO_ARG(stride), POINTER_TO_ARG(ptr) };
- do_opengl_call(_glVariantPointerEXT_buffer_func, NULL, args, NULL);
- return;
- }
-
- if (debug_array_ptr)
- log_gl("glVariantPointerEXT[%d] type=%dstride=%d ptr=%p\n",
- id, type, stride, ptr);
- state->client_state.arrays.variantPointer[id].index = id;
- state->client_state.arrays.variantPointer[id].size = 4;
- state->client_state.arrays.variantPointer[id].type = type;
- state->client_state.arrays.variantPointer[id].stride = stride;
- state->client_state.arrays.variantPointer[id].ptr = ptr;
- }
- else
- {
- log_gl("id >= MY_GL_MAX_VARIANT_POINTER_EXT\n");
- }
-}
-
-#define glGetVariantGeneric(func_name, gltype) \
- GLAPI void APIENTRY func_name (GLuint id, GLenum name, gltype* addr)\
-{\
- CHECK_PROC(func_name); \
- int size = (name == GL_VARIANT_VALUE_EXT) ? get_vertex_shader_var_nb_composants(id) * sizeof(gltype) : sizeof(gltype); \
- if (size) \
- { \
- long args[] = { id, name, POINTER_TO_ARG(addr) }; \
- int args_size[] = { 0, 0, size }; \
- do_opengl_call(CONCAT(func_name,_func), NULL, CHECK_ARGS(args, args_size)); \
- } \
-}
-
-glGetVariantGeneric(glGetVariantBooleanvEXT, GLboolean);
-glGetVariantGeneric(glGetVariantIntegervEXT, GLint);
-glGetVariantGeneric(glGetVariantFloatvEXT, GLfloat);
-
-GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum name, GLvoid* *addr)
-{
- CHECK_PROC(glGetVariantPointervEXT);
-
- GET_CURRENT_STATE();
- if (id < MY_GL_MAX_VARIANT_POINTER_EXT)
- {
- if (name == GL_VARIANT_ARRAY_POINTER_EXT)
- *addr = (void*)state->client_state.arrays.variantPointer[id].ptr;
- }
- else
- {
- log_gl("id >= MY_GL_MAX_VARIANT_POINTER_EXT\n");
- }
-}
-
-#define glGetInvariantGeneric(func_name, gltype) \
- GLAPI void APIENTRY func_name (GLuint id, GLenum name, gltype* addr)\
-{\
- CHECK_PROC(func_name); \
- int size = (name == GL_INVARIANT_VALUE_EXT) ? get_vertex_shader_var_nb_composants(id) * sizeof(gltype) : sizeof(gltype); \
- if (size) \
- { \
- long args[] = { id, name, POINTER_TO_ARG(addr) }; \
- int args_size[] = { 0, 0, size }; \
- do_opengl_call(CONCAT(func_name,_func), NULL, CHECK_ARGS(args, args_size)); \
- } \
-}
-
-glGetInvariantGeneric(glGetInvariantBooleanvEXT, GLboolean);
-glGetInvariantGeneric(glGetInvariantIntegervEXT, GLint);
-glGetInvariantGeneric(glGetInvariantFloatvEXT, GLfloat);
-
-#define glGetLocalConstantGeneric(func_name, gltype) \
- GLAPI void APIENTRY func_name (GLuint id, GLenum name, gltype* addr)\
-{\
- CHECK_PROC(func_name); \
- int size = (name == GL_LOCAL_CONSTANT_VALUE_EXT) ? get_vertex_shader_var_nb_composants(id) * sizeof(gltype) : sizeof(gltype); \
- if (size) \
- { \
- long args[] = { id, name, POINTER_TO_ARG(addr) }; \
- int args_size[] = { 0, 0, size }; \
- do_opengl_call(CONCAT(func_name,_func), NULL, CHECK_ARGS(args, args_size)); \
- } \
-}
-
-glGetLocalConstantGeneric(glGetLocalConstantBooleanvEXT, GLboolean);
-glGetLocalConstantGeneric(glGetLocalConstantIntegervEXT, GLint);
-glGetLocalConstantGeneric(glGetLocalConstantFloatvEXT, GLfloat);
-
-
-static void _glShaderSource(int func_number, GLhandleARB handle, GLsizei size, const GLcharARB** tab_prog, const GLint* tab_length)
-{
- int i;
- int* my_tab_length;
- int total_length = 0;
- int acc_length = 0;
- GLcharARB* all_progs;
-
- if (size <= 0 || tab_prog == NULL)
- {
- log_gl("size <= 0 || tab_prog == NULL\n");
- return;
- }
- my_tab_length = malloc(sizeof(int) * size);
- for(i=0;i<size;i++)
- {
- if (tab_prog[i] == NULL)
- {
- log_gl("tab_prog[%d] == NULL\n", i);
- free(my_tab_length);
- return ;
- }
- my_tab_length[i] = (tab_length && tab_length[i]) ? tab_length[i] : strlen(tab_prog[i]);
- total_length += my_tab_length[i];
- }
- all_progs = malloc(total_length+1);
- for(i=0;i<size;i++)
- {
- char* str_tmp = all_progs + acc_length;
- memcpy(str_tmp, tab_prog[i], my_tab_length[i]);
- str_tmp[my_tab_length[i]] = 0;
- if (debug_gl) log_gl("glShaderSource[%d] : %s\n", i, str_tmp);
- char* version_ptr = strstr(str_tmp, "#version");
- if (version_ptr && version_ptr != str_tmp)
- {
- /* ATI driver won't be happy if "#version" is not at beginning of program */
- /* Necessary for "Danger from the Deep 0.3.0" */
- int offset = version_ptr - str_tmp;
- char* eol = strchr(version_ptr, '\n');
- if (eol)
- {
- int len = eol - version_ptr + 1;
- memcpy(str_tmp, tab_prog[i] + offset, len);
- memcpy(str_tmp + len, tab_prog[i], offset);
- }
- }
- acc_length += my_tab_length[i];
- }
- long args[] = { INT_TO_ARG(handle), INT_TO_ARG(size), POINTER_TO_ARG(all_progs), POINTER_TO_ARG(my_tab_length) } ;
- int args_size[] = { 0, 0, total_length, sizeof(int) * size };
- do_opengl_call(func_number, NULL, CHECK_ARGS(args, args_size));
- free(my_tab_length);
- free(all_progs);
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glShaderSourceARB) (GLhandleARB handle, GLsizei size, const GLcharARB** tab_prog, const GLint* tab_length)
-{
- CHECK_PROC(glShaderSourceARB);
- _glShaderSource(glShaderSourceARB_fake_func, handle, size, tab_prog, tab_length);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glShaderSource) (GLhandleARB handle, GLsizei size, const GLcharARB** tab_prog, const GLint* tab_length)
-{
- CHECK_PROC(glShaderSource);
- _glShaderSource(glShaderSource_fake_func, handle, size, tab_prog, tab_length);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetProgramInfoLog)(GLuint program,
- GLsizei maxLength,
- GLsizei *length,
- GLchar *infoLog)
-{
- CHECK_PROC(glGetProgramInfoLog);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(infoLog) };
- int args_size[] = { 0, 0, sizeof(int), maxLength };
- do_opengl_call(glGetProgramInfoLog_func, NULL, CHECK_ARGS(args, args_size));
- log_gl("glGetProgramInfoLog: %s\n", infoLog);
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetProgramStringARB) (GLenum target, GLenum pname, GLvoid *string)
-{
- int size = 0;
- CHECK_PROC(glGetProgramStringARB);
- glGetProgramivARB(target, GL_PROGRAM_LENGTH_ARB, &size);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(pname), POINTER_TO_ARG(string) };
- int args_size[] = { 0, 0, size };
- do_opengl_call(glGetProgramStringARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetProgramStringNV) (GLenum target, GLenum pname, GLvoid *string)
-{
- int size = 0;
- CHECK_PROC(glGetProgramStringNV);
- glGetProgramivNV(target, GL_PROGRAM_LENGTH_NV, &size);
- long args[] = { INT_TO_ARG(target), INT_TO_ARG(pname), POINTER_TO_ARG(string) };
- int args_size[] = { 0, 0, size };
- do_opengl_call(glGetProgramStringNV_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetInfoLogARB)(GLhandleARB object,
- GLsizei maxLength,
- GLsizei *length,
- GLcharARB *infoLog)
-{
- CHECK_PROC(glGetInfoLogARB);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(object), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(infoLog) };
- /*int size = 0;
- glGetObjectParameterARBiv(object, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);*/
- int args_size[] = { 0, 0, sizeof(int), maxLength };
- do_opengl_call(glGetInfoLogARB_func, NULL, CHECK_ARGS(args, args_size));
- log_gl("glGetInfoLogARB : %s\n", infoLog);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetAttachedObjectsARB)(GLhandleARB program,
- GLsizei maxCount,
- GLsizei *count,
- GLhandleARB *objects)
-{
- CHECK_PROC(glGetAttachedObjectsARB);
- int fake_count;
- if (count == NULL) count = &fake_count;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(maxCount), POINTER_TO_ARG(count), POINTER_TO_ARG(objects) };
- /*int size = 0;
- glGetObjectParameterARBiv(object, GL_OBJECT_ATTACHED_OBJECTS_ARB, &size);*/
- int args_size[] = { 0, 0, sizeof(int), maxCount * sizeof(int) };
- do_opengl_call(glGetAttachedObjectsARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetAttachedShaders)(GLuint program,
- GLsizei maxCount,
- GLsizei *count,
- GLuint *shaders)
-{
- CHECK_PROC(glGetAttachedShaders);
- int fake_count;
- if (count == NULL) count = &fake_count;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(maxCount), POINTER_TO_ARG(count), POINTER_TO_ARG(shaders) };
- int args_size[] = { 0, 0, sizeof(int), maxCount * sizeof(int) };
- do_opengl_call(glGetAttachedShaders_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI GLint EXT_FUNC(glGetUniformLocationARB) (GLuint program, const GLcharARB *txt)
-{
- int i;
- int ret = -1;
- GET_CURRENT_STATE();
- for(i=0;i<state->countUniformLocations;i++)
- {
- if (state->uniformLocations[i].program == program &&
- strcmp(state->uniformLocations[i].txt, txt) == 0)
- {
- return state->uniformLocations[i].location;
- }
- }
-
- CHECK_PROC_WITH_RET(glGetUniformLocationARB);
- long args[] = { INT_TO_ARG(program), POINTER_TO_ARG(txt) } ;
- do_opengl_call(glGetUniformLocationARB_func, &ret, args, NULL);
-
- state->uniformLocations = realloc(state->uniformLocations, sizeof(UniformLocation) * (state->countUniformLocations+1));
- state->uniformLocations[state->countUniformLocations].program = program;
- state->uniformLocations[state->countUniformLocations].txt = strdup(txt);
- state->uniformLocations[state->countUniformLocations].location = ret;
- state->countUniformLocations++;
-
- return ret;
-}
-
-GLAPI GLint EXT_FUNC(glGetUniformLocation) (GLuint program, const GLcharARB *txt)
-{
- int i;
- int ret = -1;
- GET_CURRENT_STATE();
- for(i=0;i<state->countUniformLocations;i++)
- {
- if (state->uniformLocations[i].program == program &&
- strcmp(state->uniformLocations[i].txt, txt) == 0)
- {
- return state->uniformLocations[i].location;
- }
- }
-
- CHECK_PROC_WITH_RET(glGetUniformLocation);
- long args[] = { INT_TO_ARG(program), POINTER_TO_ARG(txt) } ;
- do_opengl_call(glGetUniformLocation_func, &ret, args, NULL);
-
- state->uniformLocations = realloc(state->uniformLocations, sizeof(UniformLocation) * (state->countUniformLocations+1));
- state->uniformLocations[state->countUniformLocations].program = program;
- state->uniformLocations[state->countUniformLocations].txt = strdup(txt);
- state->uniformLocations[state->countUniformLocations].location = ret;
- state->countUniformLocations++;
-
- return ret;
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetActiveUniformARB)(GLuint program,
- GLuint index,
- GLsizei maxLength,
- GLsizei *length,
- GLint *size,
- GLenum *type,
- GLcharARB *name)
-{
- CHECK_PROC(glGetActiveUniformARB);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(index), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(size), POINTER_TO_ARG(type), POINTER_TO_ARG(name) };
- int args_size[] = { 0, 0, 0, sizeof(int), sizeof(int), sizeof(int), maxLength };
- do_opengl_call(glGetActiveUniformARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetActiveUniform)(GLuint program,
- GLuint index,
- GLsizei maxLength,
- GLsizei *length,
- GLint *size,
- GLenum *type,
- GLcharARB *name)
-{
- CHECK_PROC(glGetActiveUniform);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(index), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(size), POINTER_TO_ARG(type), POINTER_TO_ARG(name) };
- int args_size[] = { 0, 0, 0, sizeof(int), sizeof(int), sizeof(int), maxLength };
- do_opengl_call(glGetActiveUniform_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetActiveVaryingNV)(GLuint program,
- GLuint index,
- GLsizei bufSize,
- GLsizei *length,
- GLsizei *size,
- GLenum *type,
- GLchar *name)
-{
- CHECK_PROC(glGetActiveVaryingNV);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(index), INT_TO_ARG(bufSize), POINTER_TO_ARG(length), POINTER_TO_ARG(size), POINTER_TO_ARG(type), POINTER_TO_ARG(name) };
- int args_size[] = { 0, 0, 0, sizeof(int), sizeof(int), sizeof(int), bufSize };
- do_opengl_call(glGetActiveVaryingNV_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-static int _get_size_of_gl_uniform_variables(GLenum type)
-{
- switch(type)
- {
- case GL_FLOAT: return sizeof(float);
- case GL_FLOAT_VEC2: return 2*sizeof(float);
- case GL_FLOAT_VEC3: return 3*sizeof(float);
- case GL_FLOAT_VEC4: return 4*sizeof(float);
- case GL_INT: return sizeof(int);
- case GL_INT_VEC2: return 2*sizeof(int);
- case GL_INT_VEC3: return 3*sizeof(int);
- case GL_INT_VEC4: return 4*sizeof(int);
- case GL_BOOL: return sizeof(int);
- case GL_BOOL_VEC2: return 2*sizeof(int);
- case GL_BOOL_VEC3: return 3*sizeof(int);
- case GL_BOOL_VEC4: return 4*sizeof(int);
- case GL_FLOAT_MAT2: return 2*2*sizeof(float);
- case GL_FLOAT_MAT3: return 3*3*sizeof(float);
- case GL_FLOAT_MAT4: return 4*4*sizeof(float);
- case GL_FLOAT_MAT2x3:return 2*3*sizeof(float);
- case GL_FLOAT_MAT2x4:return 2*4*sizeof(float);
- case GL_FLOAT_MAT3x2:return 3*2*sizeof(float);
- case GL_FLOAT_MAT3x4:return 3*4*sizeof(float);
- case GL_FLOAT_MAT4x2:return 4*2*sizeof(float);
- case GL_FLOAT_MAT4x3:return 4*3*sizeof(float);
- case GL_SAMPLER_1D:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_3D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_1D_SHADOW:
- case GL_SAMPLER_2D_SHADOW:
- return sizeof(int);
-
- default:
- log_gl("unknown type for a uniform variable : %X\n", type);
- return 0;
- }
-}
-
-static void _gl_get_uniform(PFNGLGETPROGRAMIVPROC getProgramiv,
- PFNGLGETACTIVEUNIFORMPROC getActiveUniform,
- int func_number,
- GLuint program,
- GLint location,
- void* params)
-{
- GET_CURRENT_STATE();
- int nActiveUniforms = 0;
- int nameMaxLength = 0;
- int i;
-
- getProgramiv(program, GL_ACTIVE_UNIFORMS, &nActiveUniforms);
- getProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &nameMaxLength);
-
- char* name = malloc(nameMaxLength+1);
- char* uniformName = NULL;
- for(i=0;i<state->countUniformLocations;i++)
- {
- if (state->uniformLocations[i].program == program &&
- state->uniformLocations[i].location == location)
- {
- uniformName = state->uniformLocations[i].txt;
- break;
- }
- }
- if (uniformName == NULL)
- {
- log_gl("unknown uniform location : %d\n", location);
- return;
- }
- char* uniformName2 = NULL;
- if (strchr(uniformName, '[') == 0)
- {
- uniformName2 = malloc(strlen(uniformName) + 3 + 1);
- strcpy(uniformName2, uniformName);
- strcat(uniformName2, "[0]");
- }
- /*log_gl("nActiveUniforms=%d\n", nActiveUniforms);*/
- for(i=0;i<nActiveUniforms;i++)
- {
- int actualLength, size, type;
- int index = (i == 0 && location < nActiveUniforms) ? location : (i == location) ? 0 : i;
- getActiveUniform(program, index, nameMaxLength, &actualLength, &size, &type, name);
- /*log_gl("[%d] %s\n", i, name);*/
- if (strcmp(name, uniformName) == 0 || (uniformName2 && strcmp(name, uniformName2) == 0))
- {
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(location), POINTER_TO_ARG(params) };
- int args_size[] = { 0, 0, size * _get_size_of_gl_uniform_variables(type) };
- do_opengl_call(func_number, NULL, CHECK_ARGS(args, args_size));
- break;
- }
- }
- if (i == nActiveUniforms)
- {
- log_gl("sorry : I can't retrieve %s in the list of active uniforms\n", uniformName);
- }
- free(uniformName2);
- free(name);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetUniformfvARB)(GLuint program,
- GLint location,
- GLfloat *params)
-{
- CHECK_PROC(glGetUniformfvARB);
- _gl_get_uniform(glGetProgramivARB, glGetActiveUniformARB, glGetUniformfvARB_func, program, location, params);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetUniformfv)(GLuint program,
- GLint location,
- GLfloat *params)
-{
- CHECK_PROC(glGetUniformfv);
- _gl_get_uniform(glGetProgramiv, glGetActiveUniform, glGetUniformfv_func, program, location, params);
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetUniformivARB)(GLuint program,
- GLint location,
- GLint *params)
-{
- CHECK_PROC(glGetUniformivARB);
- _gl_get_uniform(glGetProgramivARB, glGetActiveUniformARB, glGetUniformivARB_func, program, location, params);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetUniformuivEXT)(GLuint program,
- GLint location,
- GLuint *params)
-{
- CHECK_PROC(glGetUniformuivEXT);
- _gl_get_uniform(glGetProgramivARB, glGetActiveUniformARB, glGetUniformuivEXT_func, program, location, params);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetUniformiv)(GLuint program,
- GLint location,
- GLint *params)
-{
- CHECK_PROC(glGetUniformiv);
- _gl_get_uniform(glGetProgramiv, glGetActiveUniform, glGetUniformiv_func, program, location, params);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetShaderSourceARB)(GLuint shader,
- GLsizei maxLength,
- GLsizei *length,
- GLcharARB *source)
-{
- CHECK_PROC(glGetShaderSourceARB);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(shader), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(source) };
- int args_size[] = { 0, 0, sizeof(int), maxLength };
- do_opengl_call(glGetShaderSourceARB_func, NULL, CHECK_ARGS(args, args_size));
- log_gl("glGetShaderSourceARB : %s\n", source);
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetShaderSource)(GLuint shader,
- GLsizei maxLength,
- GLsizei *length,
- GLcharARB *source)
-{
- CHECK_PROC(glGetShaderSource);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(shader), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(source) };
- int args_size[] = { 0, 0, sizeof(int), maxLength };
- do_opengl_call(glGetShaderSource_func, NULL, CHECK_ARGS(args, args_size));
- log_gl("glGetShaderSource : %s\n", source);
-}
-
-
-GLAPI void APIENTRY EXT_FUNC(glGetShaderInfoLog)(GLuint shader,
- GLsizei maxLength,
- GLsizei *length,
- GLchar *infoLog)
-{
- CHECK_PROC(glGetShaderInfoLog);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(shader), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(infoLog) };
- int args_size[] = { 0, 0, sizeof(int), maxLength };
- do_opengl_call(glGetShaderInfoLog_func, NULL, CHECK_ARGS(args, args_size));
- log_gl("glGetShaderInfoLog: %s\n", infoLog);
-}
-
-
-static ObjectBufferATI* _new_object_buffer_ATI()
-{
- GET_CURRENT_STATE();
- int i;
- for(i=0;i<32768;i++)
- {
- if (state->objectBuffersATI[i].bufferid == 0)
- {
- memset(&state->objectBuffersATI[i], 0, sizeof(ObjectBufferATI));
- return &state->objectBuffersATI[i];
- }
- }
- return NULL;
-}
-
-static ObjectBufferATI* _find_object_buffer_ATI_from_id(GLuint buffer)
-{
- GET_CURRENT_STATE();
- int i;
- for(i=0;i<32768;i++)
- {
- if (state->objectBuffersATI[i].bufferid == buffer)
- {
- return &state->objectBuffersATI[i];
- }
- }
- return NULL;
-}
-
-static void _free_object_buffer_ATI(ObjectBufferATI* objectBufferATI)
-{
- if (objectBufferATI == NULL) return;
-
- if (objectBufferATI->ptr)
- free(objectBufferATI->ptr);
- objectBufferATI->ptr = NULL;
- if (objectBufferATI->ptrMapped)
- free(objectBufferATI->ptrMapped);
- objectBufferATI->ptrMapped = NULL;
- if (objectBufferATI->ptrUpdatedWhileMapped)
- free(objectBufferATI->ptrUpdatedWhileMapped);
- objectBufferATI->ptrUpdatedWhileMapped = NULL;
- if (objectBufferATI->updatedRangesAfterMapping.ranges)
- free(objectBufferATI->updatedRangesAfterMapping.ranges);
- objectBufferATI->updatedRangesAfterMapping.ranges = NULL;
- objectBufferATI->updatedRangesAfterMapping.nb = 0;
- objectBufferATI->bufferid = 0;
- objectBufferATI->size = 0;
-}
-
-GLAPI GLuint APIENTRY EXT_FUNC(glNewObjectBufferATI) (GLsizei size, const GLvoid *pointer, GLenum usage)
-{
- int buffer = 0;
- CHECK_PROC_WITH_RET(glNewObjectBufferATI);
- long args[] = { INT_TO_ARG(size), POINTER_TO_ARG(pointer), INT_TO_ARG(usage) };
- int args_size[] = { 0, (pointer) ? size : 0, 0 };
- do_opengl_call(glNewObjectBufferATI_func, &buffer, CHECK_ARGS(args, args_size));
- //log_gl("glNewObjectBufferATI(%d,%p) --> %d\n", size, pointer, buffer);
-
- if (buffer != 0)
- {
- ObjectBufferATI* objectBufferATI = _new_object_buffer_ATI();
- if (objectBufferATI)
- {
- objectBufferATI->bufferid = buffer;
- objectBufferATI->size = size;
- objectBufferATI->ptr = malloc(size);
- objectBufferATI->ptrMapped = NULL;
- if (pointer)
- memcpy(objectBufferATI->ptr, pointer, size);
- }
- }
-
- return buffer;
-}
-
-GLAPI void APIENTRY EXT_FUNC(glFreeObjectBufferATI) (GLuint buffer)
-{
- CHECK_PROC(glFreeObjectBufferATI);
- long args[] = { UNSIGNED_INT_TO_ARG(buffer)};
- do_opengl_call(glFreeObjectBufferATI_func, NULL, args, NULL);
- _free_object_buffer_ATI(_find_object_buffer_ATI_from_id(buffer));
-}
-
-static void _add_int_range_to_ranges(IntSetRanges* ranges, int start, int length)
-{
- int i,j;
- for(i=0;i<ranges->nb;i++)
- {
- IntRange* range = &ranges->ranges[i];
- if (start <= range->start)
- {
- if (start + length < range->start)
- {
- if (ranges->nb == ranges->maxNb)
- ranges->ranges = realloc(ranges->ranges, sizeof(IntRange) * (ranges->nb+1));
- memmove(&ranges->ranges[i+1], &ranges->ranges[i], sizeof(IntRange) * (ranges->nb - i));
- ranges->nb++;
- if (ranges->nb > ranges->maxNb)
- ranges->maxNb = ranges->nb;
- ranges->ranges[i].start = start;
- ranges->ranges[i].length = length;
- return;
- }
- else if (start + length <= range->start + range->length)
- {
- range->length = range->start + range->length - start;
- range->start = start;
- return;
- }
- else
- {
- j = i + 1;
- range->start = start;
- range->length = start + length - range->start;
- while(j < ranges->nb && start + length >= ranges->ranges[j].start)
- {
- if (start + length <= ranges->ranges[j].start + ranges->ranges[j].length)
- {
- range->length = ranges->ranges[j].start + ranges->ranges[j].length - range->start;
- j++;
- break;
- }
- j++;
- }
- if (i+1<j && j < ranges->nb)
- memmove(&ranges->ranges[i+1], &ranges->ranges[j], sizeof(IntRange) * (j - (i + 1)));
- ranges->nb -= j - (i+1);
- return;
- }
- }
- else
- {
- if (start > range->start + range->length)
- {
- continue;
- }
- else if (start + length <= range->start + range->length)
- {
- return;
- }
- else
- {
- j = i + 1;
- range->length = start + length - range->start;
- while(j < ranges->nb && start + length >= ranges->ranges[j].start)
- {
- if (start + length <= ranges->ranges[j].start + ranges->ranges[j].length)
- {
- range->length = ranges->ranges[j].start + ranges->ranges[j].length - range->start;
- j++;
- break;
- }
- j++;
- }
- if (i+1<j && j < ranges->nb)
- memmove(&ranges->ranges[i+1], &ranges->ranges[j], sizeof(IntRange) * (j - (i + 1)));
- ranges->nb -= j - (i+1);
- return;
- }
- }
- }
- if (ranges->nb == ranges->maxNb)
- ranges->ranges = realloc(ranges->ranges, sizeof(IntRange) * (ranges->nb+1));
- ranges->ranges[ranges->nb].start = start;
- ranges->ranges[ranges->nb].length = length;
- ranges->nb++;
- if (ranges->nb > ranges->maxNb)
- ranges->maxNb = ranges->nb;
- return;
-}
-
-static IntSetRanges _get_empty_ranges(IntSetRanges* inRanges, int start, int length)
-{
- IntSetRanges outRanges = {0};
- int i;
- int end = start+length;
- int last_end = 0x80000000;
- for(i=0;i<=inRanges->nb;i++)
- {
- int cur_start, cur_end;
- if (i == inRanges->nb)
- {
- cur_start = cur_end = 0x7FFFFFFF;
- }
- else
- {
- IntRange* range = &inRanges->ranges[i];
- cur_start = range->start;
- cur_end = range->start + range->length;
- }
-
- /* [last_end,cur_start[ inter [start,end[ */
- if ((last_end >= start && last_end < end) || (start >= last_end && start < cur_start))
- {
- outRanges.ranges = realloc(outRanges.ranges, sizeof(IntRange) * (outRanges.nb+1));
- outRanges.ranges[outRanges.nb].start = MAX(start,last_end);
- outRanges.ranges[outRanges.nb].length = MIN(end,cur_start) - outRanges.ranges[outRanges.nb].start;
- outRanges.nb++;
- }
-
- last_end = cur_end;
- }
- return outRanges;
-}
-
-GLAPI void APIENTRY EXT_FUNC(glUpdateObjectBufferATI) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve)
-{
- CHECK_PROC(glUpdateObjectBufferATI);
- //log_gl("glUpdateObjectBufferATI(%d, %d, %d)\n", buffer, offset, size);
- long args[] = { INT_TO_ARG(buffer), INT_TO_ARG(offset), INT_TO_ARG(size), POINTER_TO_ARG(pointer), INT_TO_ARG(preserve) };
- int args_size[] = { 0, 0, 0, size, 0 };
- do_opengl_call(glUpdateObjectBufferATI_func, NULL, CHECK_ARGS(args, args_size));
- ObjectBufferATI* objectBufferATI = _find_object_buffer_ATI_from_id(buffer);
- if (objectBufferATI)
- {
- if (offset >= 0 && offset + size <= objectBufferATI->size)
- {
- if (objectBufferATI->ptrMapped)
- {
- log_gl("you shouldn't call glUpdateObjectBufferATI after glMapObjectBufferATI. we're emulating ATI fglrx (strange) behaviour\n");
- objectBufferATI->updatedRangesAfterMapping.nb = 0;
- _add_int_range_to_ranges(&objectBufferATI->updatedRangesAfterMapping, offset, size);
- objectBufferATI->ptrUpdatedWhileMapped = realloc(objectBufferATI->ptrUpdatedWhileMapped, size);
- memcpy(objectBufferATI->ptrUpdatedWhileMapped, pointer, size);
- }
- else
- {
- memcpy(objectBufferATI->ptr + offset, pointer, size);
- }
- }
- else
- {
- log_gl("offset >= 0 && offset + size <= state->objectBuffersATI[i].size failed\n");
- }
- }
-}
-
-GLAPI GLvoid* APIENTRY EXT_FUNC(glMapObjectBufferATI) (GLuint buffer)
-{
- CHECK_PROC_WITH_RET(glMapObjectBufferATI);
- //log_gl("glMapObjectBufferATI(%d)\n", buffer);
- ObjectBufferATI* objectBufferATI = _find_object_buffer_ATI_from_id(buffer);
- if (objectBufferATI)
- {
- if (objectBufferATI->ptrMapped == NULL)
- {
- objectBufferATI->ptrMapped = malloc(objectBufferATI->size);
- memcpy(objectBufferATI->ptrMapped,
- objectBufferATI->ptr,
- objectBufferATI->size);
- return objectBufferATI->ptrMapped;
- }
- else
- return NULL;
- }
- else
- return NULL;
-}
-
-GLAPI void APIENTRY EXT_FUNC(glUnmapObjectBufferATI) (GLuint buffer)
-{
- CHECK_PROC(glUnmapObjectBufferATI);
- //log_gl("glUnmapObjectBufferATI(%d)\n", buffer);
- ObjectBufferATI* objectBufferATI = _find_object_buffer_ATI_from_id(buffer);
- if (objectBufferATI)
- {
- if (objectBufferATI->ptrMapped)
- {
- IntSetRanges outRanges = _get_empty_ranges(&objectBufferATI->updatedRangesAfterMapping, 0, objectBufferATI->size);
- int i;
- void* ptrMapped = objectBufferATI->ptrMapped;
- if (objectBufferATI->ptrUpdatedWhileMapped)
- {
- assert(objectBufferATI->updatedRangesAfterMapping.nb == 1);
- memcpy(objectBufferATI->ptr + objectBufferATI->updatedRangesAfterMapping.ranges[0].start,
- objectBufferATI->ptrUpdatedWhileMapped,
- objectBufferATI->updatedRangesAfterMapping.ranges[0].length);
- free(objectBufferATI->ptrUpdatedWhileMapped);
- objectBufferATI->ptrUpdatedWhileMapped = NULL;
- }
- objectBufferATI->updatedRangesAfterMapping.nb = 0;
- objectBufferATI->ptrMapped = NULL;
- for(i=0;i<outRanges.nb;i++)
- {
- glUpdateObjectBufferATI(buffer, outRanges.ranges[i].start, outRanges.ranges[i].length,
- ptrMapped, GL_DISCARD_ATI);
- }
- free(outRanges.ranges);
- free(ptrMapped);
- }
- }
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetActiveAttribARB)(GLhandleARB program,
- GLuint index,
- GLsizei maxLength,
- GLsizei *length,
- GLint *size,
- GLenum *type,
- GLcharARB *name)
-{
- CHECK_PROC(glGetActiveAttribARB);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(index), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(size), POINTER_TO_ARG(type), POINTER_TO_ARG(name) };
- int args_size[] = { 0, 0, 0, sizeof(int), sizeof(int), sizeof(int), maxLength };
- do_opengl_call(glGetActiveAttribARB_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY EXT_FUNC(glGetActiveAttrib)(GLhandleARB program,
- GLuint index,
- GLsizei maxLength,
- GLsizei *length,
- GLint *size,
- GLenum *type,
- GLcharARB *name)
-{
- CHECK_PROC(glGetActiveAttrib);
- int fake_length;
- if (length == NULL) length = &fake_length;
- long args[] = { INT_TO_ARG(program), INT_TO_ARG(index), INT_TO_ARG(maxLength), POINTER_TO_ARG(length), POINTER_TO_ARG(size), POINTER_TO_ARG(type), POINTER_TO_ARG(name) };
- int args_size[] = { 0, 0, 0, sizeof(int), sizeof(int), sizeof(int), maxLength };
- do_opengl_call(glGetActiveAttrib_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI GLint APIENTRY EXT_FUNC(glGetAttribLocationARB)(GLhandleARB program,
- const GLcharARB *name)
-{
- CHECK_PROC_WITH_RET(glGetAttribLocationARB);
- int ret = 0;
- long args[] = { INT_TO_ARG(program), POINTER_TO_ARG(name) };
- do_opengl_call(glGetAttribLocationARB_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI GLint APIENTRY EXT_FUNC(glGetAttribLocation)(GLhandleARB program,
- const GLcharARB *name)
-{
- CHECK_PROC_WITH_RET(glGetAttribLocation);
- int ret = 0;
- long args[] = { INT_TO_ARG(program), POINTER_TO_ARG(name) };
- do_opengl_call(glGetAttribLocation_func, &ret, args, NULL);
- return ret;
-}
-
-GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points)
-{
- int npoints = 0;
- CHECK_PROC(glGetDetailTexFuncSGIS);
- glGetTexParameteriv(target, GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS, &npoints);
- long args[] = { INT_TO_ARG(target), POINTER_TO_ARG(points) };
- int args_size[] = { 0, 2 * npoints * sizeof(float) };
- do_opengl_call(glGetDetailTexFuncSGIS_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points)
-{
- int npoints = 0;
- CHECK_PROC(glGetSharpenTexFuncSGIS);
- glGetTexParameteriv(target, GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS, &npoints);
- long args[] = { INT_TO_ARG(target), POINTER_TO_ARG(points) };
- int args_size[] = { 0, 2 * npoints * sizeof(float) };
- do_opengl_call(glGetSharpenTexFuncSGIS_func, NULL, CHECK_ARGS(args, args_size));
-}
-
-GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table)
-{
- NOT_IMPLEMENTED(glColorTable);
-}
-
-GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table)
-{
- NOT_IMPLEMENTED(glColorTableEXT);
-}
-
-
-GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data)
-{
- NOT_IMPLEMENTED(glColorSubTable);
-}
-
-GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data)
-{
- NOT_IMPLEMENTED(glColorSubTableEXT);
-}
-
-
-GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, GLvoid *table)
-{
- NOT_IMPLEMENTED(glGetColorTable);
-}
-
-GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, GLvoid *table)
-{
- NOT_IMPLEMENTED(glGetColorTableEXT);
-}
-
-
-GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image)
-{
- NOT_IMPLEMENTED(glConvolutionFilter1D);
-}
-
-GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image)
-{
- NOT_IMPLEMENTED(glConvolutionFilter1DEXT);
-}
-
-GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image)
-{
- NOT_IMPLEMENTED(glConvolutionFilter2D);
-}
-
-GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image)
-{
- NOT_IMPLEMENTED(glConvolutionFilter2DEXT);
-}
-
-
-GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, GLvoid *image)
-{
- NOT_IMPLEMENTED(glGetConvolutionFilter);
-}
-
-GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *image)
-{
- NOT_IMPLEMENTED(glGetConvolutionFilterEXT);
-}
-
-GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span)
-{
- NOT_IMPLEMENTED(glGetSeparableFilter);
-}
-
-GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span)
-{
- NOT_IMPLEMENTED(glGetSeparableFilterEXT);
-}
-
-GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column)
-{
- NOT_IMPLEMENTED(glSeparableFilter2D);
-}
-
-GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column)
-{
- NOT_IMPLEMENTED(glSeparableFilter2DEXT);
-}
-
-
-GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
-{
- NOT_IMPLEMENTED(glGetHistogram);
-}
-
-GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
-{
- NOT_IMPLEMENTED(glGetHistogramEXT);
-}
-
-
-GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
-{
- NOT_IMPLEMENTED(glGetMinmax);
-}
-
-GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
-{
- NOT_IMPLEMENTED(glGetMinmaxEXT);
-}
-
-GLAPI void* APIENTRY glXAllocateMemoryNV(GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority)
-{
- return malloc(size);
-}
-
-GLAPI void APIENTRY glXFreeMemoryNV(GLvoid *pointer)
-{
- free(pointer);
-}
-
-GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, GLvoid *pointer)
-{
- CHECK_PROC(glPixelDataRangeNV);
- /* do nothing is a possible implementation... */
-}
-
-GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target)
-{
- CHECK_PROC(glFlushPixelDataRangeNV);
- /* do nothing is a possible implementation... */
-}
-
-GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei size, const GLvoid *ptr)
-{
- CHECK_PROC(glVertexArrayRangeNV);
- /* do nothing is a possible implementation... */
-}
-
-GLAPI void APIENTRY glFlushVertexArrayRangeNV (void)
-{
- CHECK_PROC(glFlushVertexArrayRangeNV);
- /* do nothing is a possible implementation... */
-}
-
-
-static unsigned int str_hash (const void* v)
-{
- /* 31 bit hash function */
- const signed char *p = v;
- unsigned int h = *p;
-
- if (h)
- for (p += 1; *p != '\0'; p++)
- h = (h << 5) - h + *p;
-
- return h;
-}
-
-static const char* global_glXGetProcAddress_request =
-{
- "glAccum\0"
- "glActiveStencilFaceEXT\0"
- "glActiveTexture\0"
- "glActiveTextureARB\0"
- "glActiveVaryingNV\0"
- "glAddSwapHintRectWIN\0"
- "glAlphaFragmentOp1ATI\0"
- "glAlphaFragmentOp2ATI\0"
- "glAlphaFragmentOp3ATI\0"
- "glAlphaFunc\0"
- "glApplyTextureEXT\0"
- "glAreProgramsResidentNV\0"
- "glAreTexturesResident\0"
- "glAreTexturesResidentEXT\0"
- "glArrayElement\0"
- "glArrayElementEXT\0"
- "glArrayObjectATI\0"
- "glAsyncMarkerSGIX\0"
- "glAttachObjectARB\0"
- "glAttachShader\0"
- "glBegin\0"
- "glBeginConditionalRenderNVX\0"
- "glBeginDefineVisibilityQueryATI\0"
- "glBeginFragmentShaderATI\0"
- "glBeginOcclusionQuery\0"
- "glBeginOcclusionQueryNV\0"
- "glBeginQuery\0"
- "glBeginQueryARB\0"
- "glBeginSceneEXT\0"
- "glBeginTransformFeedbackNV\0"
- "glBeginUseVisibilityQueryATI\0"
- "glBeginVertexShaderEXT\0"
- "glBindArraySetARB\0"
- "glBindAttribLocation\0"
- "glBindAttribLocationARB\0"
- "glBindBuffer\0"
- "glBindBufferARB\0"
- "glBindBufferBaseNV\0"
- "glBindBufferOffsetNV\0"
- "glBindBufferRangeNV\0"
- "glBindFragDataLocationEXT\0"
- "glBindFragmentShaderATI\0"
- "glBindFramebufferEXT\0"
- "glBindLightParameterEXT\0"
- "glBindMaterialParameterEXT\0"
- "glBindParameterEXT\0"
- "glBindProgramARB\0"
- "glBindProgramNV\0"
- "glBindRenderbufferEXT\0"
- "glBindTexGenParameterEXT\0"
- "glBindTexture\0"
- "glBindTextureEXT\0"
- "glBindTextureUnitParameterEXT\0"
- "glBindVertexArrayAPPLE\0"
- "glBindVertexShaderEXT\0"
- "glBinormal3bEXT\0"
- "glBinormal3bvEXT\0"
- "glBinormal3dEXT\0"
- "glBinormal3dvEXT\0"
- "glBinormal3fEXT\0"
- "glBinormal3fvEXT\0"
- "glBinormal3iEXT\0"
- "glBinormal3ivEXT\0"
- "glBinormal3sEXT\0"
- "glBinormal3svEXT\0"
- "glBinormalArrayEXT\0"
- "glBitmap\0"
- "glBlendColor\0"
- "glBlendColorEXT\0"
- "glBlendEquation\0"
- "glBlendEquationEXT\0"
- "glBlendEquationSeparate\0"
- "glBlendEquationSeparateATI\0"
- "glBlendEquationSeparateEXT\0"
- "glBlendFunc\0"
- "glBlendFuncSeparate\0"
- "glBlendFuncSeparateEXT\0"
- "glBlendFuncSeparateINGR\0"
- "glBlitFramebufferEXT\0"
- "glBufferData\0"
- "glBufferDataARB\0"
- "glBufferParameteriAPPLE\0"
- "glBufferRegionEnabled\0"
- "glBufferRegionEnabledEXT\0"
- "glBufferSubData\0"
- "glBufferSubDataARB\0"
- "glCallList\0"
- "glCallLists\0"
- "glCheckFramebufferStatusEXT\0"
- "glClampColorARB\0"
- "glClear\0"
- "glClearAccum\0"
- "glClearColor\0"
- "glClearColorIiEXT\0"
- "glClearColorIuiEXT\0"
- "glClearDepth\0"
- "glClearDepthdNV\0"
- "glClearIndex\0"
- "glClearStencil\0"
- "glClientActiveTexture\0"
- "glClientActiveTextureARB\0"
- "glClientActiveVertexStreamATI\0"
- "glClipPlane\0"
- "glColor3b\0"
- "glColor3bv\0"
- "glColor3d\0"
- "glColor3dv\0"
- "glColor3f\0"
- "glColor3fv\0"
- "glColor3fVertex3fSUN\0"
- "glColor3fVertex3fvSUN\0"
- "glColor3hNV\0"
- "glColor3hvNV\0"
- "glColor3i\0"
- "glColor3iv\0"
- "glColor3s\0"
- "glColor3sv\0"
- "glColor3ub\0"
- "glColor3ubv\0"
- "glColor3ui\0"
- "glColor3uiv\0"
- "glColor3us\0"
- "glColor3usv\0"
- "glColor4b\0"
- "glColor4bv\0"
- "glColor4d\0"
- "glColor4dv\0"
- "glColor4f\0"
- "glColor4fNormal3fVertex3fSUN\0"
- "glColor4fNormal3fVertex3fvSUN\0"
- "glColor4fv\0"
- "glColor4hNV\0"
- "glColor4hvNV\0"
- "glColor4i\0"
- "glColor4iv\0"
- "glColor4s\0"
- "glColor4sv\0"
- "glColor4ub\0"
- "glColor4ubv\0"
- "glColor4ubVertex2fSUN\0"
- "glColor4ubVertex2fvSUN\0"
- "glColor4ubVertex3fSUN\0"
- "glColor4ubVertex3fvSUN\0"
- "glColor4ui\0"
- "glColor4uiv\0"
- "glColor4us\0"
- "glColor4usv\0"
- "glColorFragmentOp1ATI\0"
- "glColorFragmentOp2ATI\0"
- "glColorFragmentOp3ATI\0"
- "glColorMask\0"
- "glColorMaskIndexedEXT\0"
- "glColorMaterial\0"
- "glColorPointer\0"
- "glColorPointerEXT\0"
- "glColorPointerListIBM\0"
- "glColorPointervINTEL\0"
- "glColorSubTable\0"
- "glColorSubTableEXT\0"
- "glColorTable\0"
- "glColorTableEXT\0"
- "glColorTableParameterfv\0"
- "glColorTableParameterfvSGI\0"
- "glColorTableParameteriv\0"
- "glColorTableParameterivSGI\0"
- "glColorTableSGI\0"
- "glCombinerInputNV\0"
- "glCombinerOutputNV\0"
- "glCombinerParameterfNV\0"
- "glCombinerParameterfvNV\0"
- "glCombinerParameteriNV\0"
- "glCombinerParameterivNV\0"
- "glCombinerStageParameterfvNV\0"
- "glCompileShader\0"
- "glCompileShaderARB\0"
- "glCompressedTexImage1D\0"
- "glCompressedTexImage1DARB\0"
- "glCompressedTexImage2D\0"
- "glCompressedTexImage2DARB\0"
- "glCompressedTexImage3D\0"
- "glCompressedTexImage3DARB\0"
- "glCompressedTexSubImage1D\0"
- "glCompressedTexSubImage1DARB\0"
- "glCompressedTexSubImage2D\0"
- "glCompressedTexSubImage2DARB\0"
- "glCompressedTexSubImage3D\0"
- "glCompressedTexSubImage3DARB\0"
- "glConvolutionFilter1D\0"
- "glConvolutionFilter1DEXT\0"
- "glConvolutionFilter2D\0"
- "glConvolutionFilter2DEXT\0"
- "glConvolutionParameterf\0"
- "glConvolutionParameterfEXT\0"
- "glConvolutionParameterfv\0"
- "glConvolutionParameterfvEXT\0"
- "glConvolutionParameteri\0"
- "glConvolutionParameteriEXT\0"
- "glConvolutionParameteriv\0"
- "glConvolutionParameterivEXT\0"
- "glCopyColorSubTable\0"
- "glCopyColorSubTableEXT\0"
- "glCopyColorTable\0"
- "glCopyColorTableSGI\0"
- "glCopyConvolutionFilter1D\0"
- "glCopyConvolutionFilter1DEXT\0"
- "glCopyConvolutionFilter2D\0"
- "glCopyConvolutionFilter2DEXT\0"
- "glCopyPixels\0"
- "glCopyTexImage1D\0"
- "glCopyTexImage1DEXT\0"
- "glCopyTexImage2D\0"
- "glCopyTexImage2DEXT\0"
- "glCopyTexSubImage1D\0"
- "glCopyTexSubImage1DEXT\0"
- "glCopyTexSubImage2D\0"
- "glCopyTexSubImage2DEXT\0"
- "glCopyTexSubImage3D\0"
- "glCopyTexSubImage3DEXT\0"
- "glCreateProgram\0"
- "glCreateProgramObjectARB\0"
- "glCreateShader\0"
- "glCreateShaderObjectARB\0"
- "glCullFace\0"
- "glCullParameterdvEXT\0"
- "glCullParameterfvEXT\0"
- "glCurrentPaletteMatrixARB\0"
- "glDeformationMap3dSGIX\0"
- "glDeformationMap3fSGIX\0"
- "glDeformSGIX\0"
- "glDeleteArraySetsARB\0"
- "glDeleteAsyncMarkersSGIX\0"
- "glDeleteBufferRegion\0"
- "glDeleteBufferRegionEXT\0"
- "glDeleteBuffers\0"
- "glDeleteBuffersARB\0"
- "glDeleteFencesAPPLE\0"
- "glDeleteFencesNV\0"
- "glDeleteFragmentShaderATI\0"
- "glDeleteFramebuffersEXT\0"
- "glDeleteLists\0"
- "glDeleteObjectARB\0"
- "glDeleteObjectBufferATI\0"
- "glDeleteOcclusionQueries\0"
- "glDeleteOcclusionQueriesNV\0"
- "glDeleteProgram\0"
- "glDeleteProgramsARB\0"
- "glDeleteProgramsNV\0"
- "glDeleteQueries\0"
- "glDeleteQueriesARB\0"
- "glDeleteRenderbuffersEXT\0"
- "glDeleteShader\0"
- "glDeleteTextures\0"
- "glDeleteTexturesEXT\0"
- "glDeleteVertexArraysAPPLE\0"
- "glDeleteVertexShaderEXT\0"
- "glDeleteVisibilityQueriesATI\0"
- "glDepthBoundsdNV\0"
- "glDepthBoundsEXT\0"
- "glDepthFunc\0"
- "glDepthMask\0"
- "glDepthRange\0"
- "glDepthRangedNV\0"
- "glDetachObjectARB\0"
- "glDetachShader\0"
- "glDetailTexFuncSGIS\0"
- "glDisable\0"
- "glDisableClientState\0"
- "glDisableIndexedEXT\0"
- "glDisableVariantClientStateEXT\0"
- "glDisableVertexAttribAPPLE\0"
- "glDisableVertexAttribArray\0"
- "glDisableVertexAttribArrayARB\0"
- "glDrawArrays\0"
- "glDrawArraysEXT\0"
- "glDrawArraysInstancedEXT\0"
- "glDrawBuffer\0"
- "glDrawBufferRegion\0"
- "glDrawBufferRegionEXT\0"
- "glDrawBuffers\0"
- "glDrawBuffersARB\0"
- "glDrawBuffersATI\0"
- "glDrawElementArrayAPPLE\0"
- "glDrawElementArrayATI\0"
- "glDrawElements\0"
- "glDrawElementsFGL\0"
- "glDrawElementsInstancedEXT\0"
- "glDrawMeshArraysSUN\0"
- "glDrawMeshNV\0"
- "glDrawPixels\0"
- "glDrawRangeElementArrayAPPLE\0"
- "glDrawRangeElementArrayATI\0"
- "glDrawRangeElements\0"
- "glDrawRangeElementsEXT\0"
- "glDrawWireTrianglesFGL\0"
- "glEdgeFlag\0"
- "glEdgeFlagPointer\0"
- "glEdgeFlagPointerEXT\0"
- "glEdgeFlagPointerListIBM\0"
- "glEdgeFlagv\0"
- "glElementPointerAPPLE\0"
- "glElementPointerATI\0"
- "glEnable\0"
- "glEnableClientState\0"
- "glEnableIndexedEXT\0"
- "glEnableVariantClientStateEXT\0"
- "glEnableVertexAttribAPPLE\0"
- "glEnableVertexAttribArray\0"
- "glEnableVertexAttribArrayARB\0"
- "glEnd\0"
- "glEndConditionalRenderNVX\0"
- "glEndDefineVisibilityQueryATI\0"
- "glEndFragmentShaderATI\0"
- "glEndList\0"
- "glEndOcclusionQuery\0"
- "glEndOcclusionQueryNV\0"
- "glEndQuery\0"
- "glEndQueryARB\0"
- "glEndSceneEXT\0"
- "glEndTransformFeedbackNV\0"
- "glEndUseVisibilityQueryATI\0"
- "glEndVertexShaderEXT\0"
- "glEvalCoord1d\0"
- "glEvalCoord1dv\0"
- "glEvalCoord1f\0"
- "glEvalCoord1fv\0"
- "glEvalCoord2d\0"
- "glEvalCoord2dv\0"
- "glEvalCoord2f\0"
- "glEvalCoord2fv\0"
- "glEvalMapsNV\0"
- "glEvalMesh1\0"
- "glEvalMesh2\0"
- "glEvalPoint1\0"
- "glEvalPoint2\0"
- "glExecuteProgramNV\0"
- "glExtractComponentEXT\0"
- "glFeedbackBuffer\0"
- "glFinalCombinerInputNV\0"
- "glFinish\0"
- "glFinishAsyncSGIX\0"
- "glFinishFenceAPPLE\0"
- "glFinishFenceNV\0"
- "glFinishObjectAPPLE\0"
- "glFinishRenderAPPLE\0"
- "glFinishTextureSUNX\0"
- "glFlush\0"
- "glFlushMappedBufferRangeAPPLE\0"
- "glFlushPixelDataRangeNV\0"
- "glFlushRasterSGIX\0"
- "glFlushRenderAPPLE\0"
- "glFlushVertexArrayRangeAPPLE\0"
- "glFlushVertexArrayRangeNV\0"
- "glFogCoordd\0"
- "glFogCoorddEXT\0"
- "glFogCoorddv\0"
- "glFogCoorddvEXT\0"
- "glFogCoordf\0"
- "glFogCoordfEXT\0"
- "glFogCoordfv\0"
- "glFogCoordfvEXT\0"
- "glFogCoordhNV\0"
- "glFogCoordhvNV\0"
- "glFogCoordPointer\0"
- "glFogCoordPointerEXT\0"
- "glFogCoordPointerListIBM\0"
- "glFogf\0"
- "glFogFuncSGIS\0"
- "glFogfv\0"
- "glFogi\0"
- "glFogiv\0"
- "glFragmentColorMaterialEXT\0"
- "glFragmentColorMaterialSGIX\0"
- "glFragmentLightfEXT\0"
- "glFragmentLightfSGIX\0"
- "glFragmentLightfvEXT\0"
- "glFragmentLightfvSGIX\0"
- "glFragmentLightiEXT\0"
- "glFragmentLightiSGIX\0"
- "glFragmentLightivEXT\0"
- "glFragmentLightivSGIX\0"
- "glFragmentLightModelfEXT\0"
- "glFragmentLightModelfSGIX\0"
- "glFragmentLightModelfvEXT\0"
- "glFragmentLightModelfvSGIX\0"
- "glFragmentLightModeliEXT\0"
- "glFragmentLightModeliSGIX\0"
- "glFragmentLightModelivEXT\0"
- "glFragmentLightModelivSGIX\0"
- "glFragmentMaterialfEXT\0"
- "glFragmentMaterialfSGIX\0"
- "glFragmentMaterialfvEXT\0"
- "glFragmentMaterialfvSGIX\0"
- "glFragmentMaterialiEXT\0"
- "glFragmentMaterialiSGIX\0"
- "glFragmentMaterialivEXT\0"
- "glFragmentMaterialivSGIX\0"
- "glFramebufferRenderbufferEXT\0"
- "glFramebufferTexture1DEXT\0"
- "glFramebufferTexture2DEXT\0"
- "glFramebufferTexture3DEXT\0"
- "glFramebufferTextureEXT\0"
- "glFramebufferTextureFaceEXT\0"
- "glFramebufferTextureLayerEXT\0"
- "glFrameZoomSGIX\0"
- "glFreeObjectBufferATI\0"
- "glFrontFace\0"
- "glFrustum\0"
- "glGenArraySetsARB\0"
- "glGenAsyncMarkersSGIX\0"
- "glGenBuffers\0"
- "glGenBuffersARB\0"
- "glGenerateMipmapEXT\0"
- "glGenFencesAPPLE\0"
- "glGenFencesNV\0"
- "glGenFragmentShadersATI\0"
- "glGenFramebuffersEXT\0"
- "glGenLists\0"
- "glGenOcclusionQueries\0"
- "glGenOcclusionQueriesNV\0"
- "glGenProgramsARB\0"
- "glGenProgramsNV\0"
- "glGenQueries\0"
- "glGenQueriesARB\0"
- "glGenRenderbuffersEXT\0"
- "glGenSymbolsEXT\0"
- "glGenTextures\0"
- "glGenTexturesEXT\0"
- "glGenVertexArraysAPPLE\0"
- "glGenVertexShadersEXT\0"
- "glGenVisibilityQueriesATI\0"
- "glGetActiveAttrib\0"
- "glGetActiveAttribARB\0"
- "glGetActiveUniform\0"
- "glGetActiveUniformARB\0"
- "glGetActiveVaryingNV\0"
- "glGetArrayObjectfvATI\0"
- "glGetArrayObjectivATI\0"
- "glGetAttachedObjectsARB\0"
- "glGetAttachedShaders\0"
- "glGetAttribLocation\0"
- "glGetAttribLocationARB\0"
- "glGetBooleanIndexedvEXT\0"
- "glGetBooleanv\0"
- "glGetBufferParameteriv\0"
- "glGetBufferParameterivARB\0"
- "glGetBufferPointerv\0"
- "glGetBufferPointervARB\0"
- "glGetBufferSubData\0"
- "glGetBufferSubDataARB\0"
- "glGetClipPlane\0"
- "glGetColorTable\0"
- "glGetColorTableEXT\0"
- "glGetColorTableParameterfv\0"
- "glGetColorTableParameterfvEXT\0"
- "glGetColorTableParameterfvSGI\0"
- "glGetColorTableParameteriv\0"
- "glGetColorTableParameterivEXT\0"
- "glGetColorTableParameterivSGI\0"
- "glGetColorTableSGI\0"
- "glGetCombinerInputParameterfvNV\0"
- "glGetCombinerInputParameterivNV\0"
- "glGetCombinerOutputParameterfvNV\0"
- "glGetCombinerOutputParameterivNV\0"
- "glGetCombinerStageParameterfvNV\0"
- "glGetCompressedTexImage\0"
- "glGetCompressedTexImageARB\0"
- "glGetConvolutionFilter\0"
- "glGetConvolutionFilterEXT\0"
- "glGetConvolutionParameterfv\0"
- "glGetConvolutionParameterfvEXT\0"
- "glGetConvolutionParameteriv\0"
- "glGetConvolutionParameterivEXT\0"
- "glGetDetailTexFuncSGIS\0"
- "glGetDoublev\0"
- "glGetError\0"
- "glGetFenceivNV\0"
- "glGetFinalCombinerInputParameterfvNV\0"
- "glGetFinalCombinerInputParameterivNV\0"
- "glGetFloatv\0"
- "glGetFogFuncSGIS\0"
- "glGetFragDataLocationEXT\0"
- "glGetFragmentLightfvEXT\0"
- "glGetFragmentLightfvSGIX\0"
- "glGetFragmentLightivEXT\0"
- "glGetFragmentLightivSGIX\0"
- "glGetFragmentMaterialfvEXT\0"
- "glGetFragmentMaterialfvSGIX\0"
- "glGetFragmentMaterialivEXT\0"
- "glGetFragmentMaterialivSGIX\0"
- "glGetFramebufferAttachmentParameterivEXT\0"
- "glGetHandleARB\0"
- "glGetHistogram\0"
- "glGetHistogramEXT\0"
- "glGetHistogramParameterfv\0"
- "glGetHistogramParameterfvEXT\0"
- "glGetHistogramParameteriv\0"
- "glGetHistogramParameterivEXT\0"
- "glGetImageTransformParameterfvHP\0"
- "glGetImageTransformParameterivHP\0"
- "glGetInfoLogARB\0"
- "glGetInstrumentsSGIX\0"
- "glGetIntegerIndexedvEXT\0"
- "glGetIntegerv\0"
- "glGetInvariantBooleanvEXT\0"
- "glGetInvariantFloatvEXT\0"
- "glGetInvariantIntegervEXT\0"
- "glGetLightfv\0"
- "glGetLightiv\0"
- "glGetListParameterfvSGIX\0"
- "glGetListParameterivSGIX\0"
- "glGetLocalConstantBooleanvEXT\0"
- "glGetLocalConstantFloatvEXT\0"
- "glGetLocalConstantIntegervEXT\0"
- "glGetMapAttribParameterfvNV\0"
- "glGetMapAttribParameterivNV\0"
- "glGetMapControlPointsNV\0"
- "glGetMapdv\0"
- "glGetMapfv\0"
- "glGetMapiv\0"
- "glGetMapParameterfvNV\0"
- "glGetMapParameterivNV\0"
- "glGetMaterialfv\0"
- "glGetMaterialiv\0"
- "glGetMinmax\0"
- "glGetMinmaxEXT\0"
- "glGetMinmaxParameterfv\0"
- "glGetMinmaxParameterfvEXT\0"
- "glGetMinmaxParameteriv\0"
- "glGetMinmaxParameterivEXT\0"
- "glGetObjectBufferfvATI\0"
- "glGetObjectBufferivATI\0"
- "glGetObjectParameterfvARB\0"
- "glGetObjectParameterivARB\0"
- "glGetOcclusionQueryiv\0"
- "glGetOcclusionQueryivNV\0"
- "glGetOcclusionQueryuiv\0"
- "glGetOcclusionQueryuivNV\0"
- "glGetPixelMapfv\0"
- "glGetPixelMapuiv\0"
- "glGetPixelMapusv\0"
- "glGetPixelTexGenParameterfvSGIS\0"
- "glGetPixelTexGenParameterivSGIS\0"
- "glGetPixelTransformParameterfvEXT\0"
- "glGetPixelTransformParameterivEXT\0"
- "glGetPointerv\0"
- "glGetPointervEXT\0"
- "glGetPolygonStipple\0"
- "glGetProgramEnvParameterdvARB\0"
- "glGetProgramEnvParameterfvARB\0"
- "glGetProgramEnvParameterIivNV\0"
- "glGetProgramEnvParameterIuivNV\0"
- "glGetProgramInfoLog\0"
- "glGetProgramiv\0"
- "glGetProgramivARB\0"
- "glGetProgramivNV\0"
- "glGetProgramLocalParameterdvARB\0"
- "glGetProgramLocalParameterfvARB\0"
- "glGetProgramLocalParameterIivNV\0"
- "glGetProgramLocalParameterIuivNV\0"
- "glGetProgramNamedParameterdvNV\0"
- "glGetProgramNamedParameterfvNV\0"
- "glGetProgramParameterdvNV\0"
- "glGetProgramParameterfvNV\0"
- "glGetProgramRegisterfvMESA\0"
- "glGetProgramStringARB\0"
- "glGetProgramStringNV\0"
- "glGetQueryiv\0"
- "glGetQueryivARB\0"
- "glGetQueryObjecti64vEXT\0"
- "glGetQueryObjectiv\0"
- "glGetQueryObjectivARB\0"
- "glGetQueryObjectui64vEXT\0"
- "glGetQueryObjectuiv\0"
- "glGetQueryObjectuivARB\0"
- "glGetRenderbufferParameterivEXT\0"
- "glGetSeparableFilter\0"
- "glGetSeparableFilterEXT\0"
- "glGetShaderInfoLog\0"
- "glGetShaderiv\0"
- "glGetShaderSource\0"
- "glGetShaderSourceARB\0"
- "glGetSharpenTexFuncSGIS\0"
- "glGetString\0"
- "glGetTexBumpParameterfvATI\0"
- "glGetTexBumpParameterivATI\0"
- "glGetTexEnvfv\0"
- "glGetTexEnviv\0"
- "glGetTexFilterFuncSGIS\0"
- "glGetTexGendv\0"
- "glGetTexGenfv\0"
- "glGetTexGeniv\0"
- "glGetTexImage\0"
- "glGetTexLevelParameterfv\0"
- "glGetTexLevelParameteriv\0"
- "glGetTexParameterfv\0"
- "glGetTexParameterIivEXT\0"
- "glGetTexParameterIuivEXT\0"
- "glGetTexParameteriv\0"
- "glGetTexParameterPointervAPPLE\0"
- "glGetTrackMatrixivNV\0"
- "glGetTransformFeedbackVaryingNV\0"
- "glGetUniformBufferSizeEXT\0"
- "glGetUniformfv\0"
- "glGetUniformfvARB\0"
- "glGetUniformiv\0"
- "glGetUniformivARB\0"
- "glGetUniformLocation\0"
- "glGetUniformLocationARB\0"
- "glGetUniformOffsetEXT\0"
- "glGetUniformuivEXT\0"
- "glGetVariantArrayObjectfvATI\0"
- "glGetVariantArrayObjectivATI\0"
- "glGetVariantBooleanvEXT\0"
- "glGetVariantFloatvEXT\0"
- "glGetVariantIntegervEXT\0"
- "glGetVariantPointervEXT\0"
- "glGetVaryingLocationNV\0"
- "glGetVertexAttribArrayObjectfvATI\0"
- "glGetVertexAttribArrayObjectivATI\0"
- "glGetVertexAttribdv\0"
- "glGetVertexAttribdvARB\0"
- "glGetVertexAttribdvNV\0"
- "glGetVertexAttribfv\0"
- "glGetVertexAttribfvARB\0"
- "glGetVertexAttribfvNV\0"
- "glGetVertexAttribIivEXT\0"
- "glGetVertexAttribIuivEXT\0"
- "glGetVertexAttribiv\0"
- "glGetVertexAttribivARB\0"
- "glGetVertexAttribivNV\0"
- "glGetVertexAttribPointerv\0"
- "glGetVertexAttribPointervARB\0"
- "glGetVertexAttribPointervNV\0"
- "glGlobalAlphaFactorbSUN\0"
- "glGlobalAlphaFactordSUN\0"
- "glGlobalAlphaFactorfSUN\0"
- "glGlobalAlphaFactoriSUN\0"
- "glGlobalAlphaFactorsSUN\0"
- "glGlobalAlphaFactorubSUN\0"
- "glGlobalAlphaFactoruiSUN\0"
- "glGlobalAlphaFactorusSUN\0"
- "glHint\0"
- "glHintPGI\0"
- "glHistogram\0"
- "glHistogramEXT\0"
- "glIglooInterfaceSGIX\0"
- "glImageTransformParameterfHP\0"
- "glImageTransformParameterfvHP\0"
- "glImageTransformParameteriHP\0"
- "glImageTransformParameterivHP\0"
- "glIndexd\0"
- "glIndexdv\0"
- "glIndexf\0"
- "glIndexFuncEXT\0"
- "glIndexfv\0"
- "glIndexi\0"
- "glIndexiv\0"
- "glIndexMask\0"
- "glIndexMaterialEXT\0"
- "glIndexPointer\0"
- "glIndexPointerEXT\0"
- "glIndexPointerListIBM\0"
- "glIndexs\0"
- "glIndexsv\0"
- "glIndexub\0"
- "glIndexubv\0"
- "glInitNames\0"
- "glInsertComponentEXT\0"
- "glInstrumentsBufferSGIX\0"
- "glInterleavedArrays\0"
- "glIsArraySetARB\0"
- "glIsAsyncMarkerSGIX\0"
- "glIsBuffer\0"
- "glIsBufferARB\0"
- "glIsEnabled\0"
- "glIsEnabledIndexedEXT\0"
- "glIsFenceAPPLE\0"
- "glIsFenceNV\0"
- "glIsFramebufferEXT\0"
- "glIsList\0"
- "glIsObjectBufferATI\0"
- "glIsOcclusionQuery\0"
- "_glIsOcclusionQueryNV\0"
- "glIsOcclusionQueryNV\0"
- "glIsProgram\0"
- "glIsProgramARB\0"
- "glIsProgramNV\0"
- "glIsQuery\0"
- "glIsQueryARB\0"
- "glIsRenderbufferEXT\0"
- "glIsShader\0"
- "glIsTexture\0"
- "glIsTextureEXT\0"
- "glIsVariantEnabledEXT\0"
- "glIsVertexArrayAPPLE\0"
- "glIsVertexAttribEnabledAPPLE\0"
- "glLightEnviEXT\0"
- "glLightEnviSGIX\0"
- "glLightf\0"
- "glLightfv\0"
- "glLighti\0"
- "glLightiv\0"
- "glLightModelf\0"
- "glLightModelfv\0"
- "glLightModeli\0"
- "glLightModeliv\0"
- "glLineStipple\0"
- "glLineWidth\0"
- "glLinkProgram\0"
- "glLinkProgramARB\0"
- "glListBase\0"
- "glListParameterfSGIX\0"
- "glListParameterfvSGIX\0"
- "glListParameteriSGIX\0"
- "glListParameterivSGIX\0"
- "glLoadIdentity\0"
- "glLoadIdentityDeformationMapSGIX\0"
- "glLoadMatrixd\0"
- "glLoadMatrixf\0"
- "glLoadName\0"
- "glLoadProgramNV\0"
- "glLoadTransposeMatrixd\0"
- "glLoadTransposeMatrixdARB\0"
- "glLoadTransposeMatrixf\0"
- "glLoadTransposeMatrixfARB\0"
- "glLockArraysEXT\0"
- "glLogicOp\0"
- "glMap1d\0"
- "glMap1f\0"
- "glMap2d\0"
- "glMap2f\0"
- "glMapBuffer\0"
- "glMapBufferARB\0"
- "glMapControlPointsNV\0"
- "glMapGrid1d\0"
- "glMapGrid1f\0"
- "glMapGrid2d\0"
- "glMapGrid2f\0"
- "glMapObjectBufferATI\0"
- "glMapParameterfvNV\0"
- "glMapParameterivNV\0"
- "glMapTexture3DATI\0"
- "glMapVertexAttrib1dAPPLE\0"
- "glMapVertexAttrib1fAPPLE\0"
- "glMapVertexAttrib2dAPPLE\0"
- "glMapVertexAttrib2fAPPLE\0"
- "glMaterialf\0"
- "glMaterialfv\0"
- "glMateriali\0"
- "glMaterialiv\0"
- "glMatrixIndexPointerARB\0"
- "glMatrixIndexubvARB\0"
- "glMatrixIndexuivARB\0"
- "glMatrixIndexusvARB\0"
- "glMatrixMode\0"
- "glMinmax\0"
- "glMinmaxEXT\0"
- "glMultiDrawArrays\0"
- "glMultiDrawArraysEXT\0"
- "glMultiDrawElementArrayAPPLE\0"
- "glMultiDrawElements\0"
- "glMultiDrawElementsEXT\0"
- "glMultiDrawRangeElementArrayAPPLE\0"
- "glMultiModeDrawArraysIBM\0"
- "glMultiModeDrawElementsIBM\0"
- "glMultiTexCoord1d\0"
- "glMultiTexCoord1dARB\0"
- "glMultiTexCoord1dSGIS\0"
- "glMultiTexCoord1dv\0"
- "glMultiTexCoord1dvARB\0"
- "glMultiTexCoord1dvSGIS\0"
- "glMultiTexCoord1f\0"
- "glMultiTexCoord1fARB\0"
- "glMultiTexCoord1fSGIS\0"
- "glMultiTexCoord1fv\0"
- "glMultiTexCoord1fvARB\0"
- "glMultiTexCoord1fvSGIS\0"
- "glMultiTexCoord1hNV\0"
- "glMultiTexCoord1hvNV\0"
- "glMultiTexCoord1i\0"
- "glMultiTexCoord1iARB\0"
- "glMultiTexCoord1iSGIS\0"
- "glMultiTexCoord1iv\0"
- "glMultiTexCoord1ivARB\0"
- "glMultiTexCoord1ivSGIS\0"
- "glMultiTexCoord1s\0"
- "glMultiTexCoord1sARB\0"
- "glMultiTexCoord1sSGIS\0"
- "glMultiTexCoord1sv\0"
- "glMultiTexCoord1svARB\0"
- "glMultiTexCoord1svSGIS\0"
- "glMultiTexCoord2d\0"
- "glMultiTexCoord2dARB\0"
- "glMultiTexCoord2dSGIS\0"
- "glMultiTexCoord2dv\0"
- "glMultiTexCoord2dvARB\0"
- "glMultiTexCoord2dvSGIS\0"
- "glMultiTexCoord2f\0"
- "glMultiTexCoord2fARB\0"
- "glMultiTexCoord2fSGIS\0"
- "glMultiTexCoord2fv\0"
- "glMultiTexCoord2fvARB\0"
- "glMultiTexCoord2fvSGIS\0"
- "glMultiTexCoord2hNV\0"
- "glMultiTexCoord2hvNV\0"
- "glMultiTexCoord2i\0"
- "glMultiTexCoord2iARB\0"
- "glMultiTexCoord2iSGIS\0"
- "glMultiTexCoord2iv\0"
- "glMultiTexCoord2ivARB\0"
- "glMultiTexCoord2ivSGIS\0"
- "glMultiTexCoord2s\0"
- "glMultiTexCoord2sARB\0"
- "glMultiTexCoord2sSGIS\0"
- "glMultiTexCoord2sv\0"
- "glMultiTexCoord2svARB\0"
- "glMultiTexCoord2svSGIS\0"
- "glMultiTexCoord3d\0"
- "glMultiTexCoord3dARB\0"
- "glMultiTexCoord3dSGIS\0"
- "glMultiTexCoord3dv\0"
- "glMultiTexCoord3dvARB\0"
- "glMultiTexCoord3dvSGIS\0"
- "glMultiTexCoord3f\0"
- "glMultiTexCoord3fARB\0"
- "glMultiTexCoord3fSGIS\0"
- "glMultiTexCoord3fv\0"
- "glMultiTexCoord3fvARB\0"
- "glMultiTexCoord3fvSGIS\0"
- "glMultiTexCoord3hNV\0"
- "glMultiTexCoord3hvNV\0"
- "glMultiTexCoord3i\0"
- "glMultiTexCoord3iARB\0"
- "glMultiTexCoord3iSGIS\0"
- "glMultiTexCoord3iv\0"
- "glMultiTexCoord3ivARB\0"
- "glMultiTexCoord3ivSGIS\0"
- "glMultiTexCoord3s\0"
- "glMultiTexCoord3sARB\0"
- "glMultiTexCoord3sSGIS\0"
- "glMultiTexCoord3sv\0"
- "glMultiTexCoord3svARB\0"
- "glMultiTexCoord3svSGIS\0"
- "glMultiTexCoord4d\0"
- "glMultiTexCoord4dARB\0"
- "glMultiTexCoord4dSGIS\0"
- "glMultiTexCoord4dv\0"
- "glMultiTexCoord4dvARB\0"
- "glMultiTexCoord4dvSGIS\0"
- "glMultiTexCoord4f\0"
- "glMultiTexCoord4fARB\0"
- "glMultiTexCoord4fSGIS\0"
- "glMultiTexCoord4fv\0"
- "glMultiTexCoord4fvARB\0"
- "glMultiTexCoord4fvSGIS\0"
- "glMultiTexCoord4hNV\0"
- "glMultiTexCoord4hvNV\0"
- "glMultiTexCoord4i\0"
- "glMultiTexCoord4iARB\0"
- "glMultiTexCoord4iSGIS\0"
- "glMultiTexCoord4iv\0"
- "glMultiTexCoord4ivARB\0"
- "glMultiTexCoord4ivSGIS\0"
- "glMultiTexCoord4s\0"
- "glMultiTexCoord4sARB\0"
- "glMultiTexCoord4sSGIS\0"
- "glMultiTexCoord4sv\0"
- "glMultiTexCoord4svARB\0"
- "glMultiTexCoord4svSGIS\0"
- "glMultiTexCoordPointerSGIS\0"
- "glMultMatrixd\0"
- "glMultMatrixf\0"
- "glMultTransposeMatrixd\0"
- "glMultTransposeMatrixdARB\0"
- "glMultTransposeMatrixf\0"
- "glMultTransposeMatrixfARB\0"
- "glNewBufferRegion\0"
- "glNewBufferRegionEXT\0"
- "glNewList\0"
- "glNewObjectBufferATI\0"
- "glNormal3b\0"
- "glNormal3bv\0"
- "glNormal3d\0"
- "glNormal3dv\0"
- "glNormal3f\0"
- "glNormal3fv\0"
- "glNormal3fVertex3fSUN\0"
- "glNormal3fVertex3fvSUN\0"
- "glNormal3hNV\0"
- "glNormal3hvNV\0"
- "glNormal3i\0"
- "glNormal3iv\0"
- "glNormal3s\0"
- "glNormal3sv\0"
- "glNormalPointer\0"
- "glNormalPointerEXT\0"
- "glNormalPointerListIBM\0"
- "glNormalPointervINTEL\0"
- "glNormalStream3bATI\0"
- "glNormalStream3bvATI\0"
- "glNormalStream3dATI\0"
- "glNormalStream3dvATI\0"
- "glNormalStream3fATI\0"
- "glNormalStream3fvATI\0"
- "glNormalStream3iATI\0"
- "glNormalStream3ivATI\0"
- "glNormalStream3sATI\0"
- "glNormalStream3svATI\0"
- "glOrtho\0"
- "glPassTexCoordATI\0"
- "glPassThrough\0"
- "glPixelDataRangeNV\0"
- "glPixelMapfv\0"
- "glPixelMapuiv\0"
- "glPixelMapusv\0"
- "glPixelStoref\0"
- "glPixelStorei\0"
- "glPixelTexGenParameterfSGIS\0"
- "glPixelTexGenParameterfvSGIS\0"
- "glPixelTexGenParameteriSGIS\0"
- "glPixelTexGenParameterivSGIS\0"
- "glPixelTexGenSGIX\0"
- "glPixelTransferf\0"
- "glPixelTransferi\0"
- "glPixelTransformParameterfEXT\0"
- "glPixelTransformParameterfvEXT\0"
- "glPixelTransformParameteriEXT\0"
- "glPixelTransformParameterivEXT\0"
- "glPixelZoom\0"
- "glPNTrianglesfATI\0"
- "glPNTrianglesiATI\0"
- "glPointParameterf\0"
- "glPointParameterfARB\0"
- "glPointParameterfEXT\0"
- "glPointParameterfSGIS\0"
- "glPointParameterfv\0"
- "glPointParameterfvARB\0"
- "glPointParameterfvEXT\0"
- "glPointParameterfvSGIS\0"
- "glPointParameteri\0"
- "glPointParameteriEXT\0"
- "glPointParameteriNV\0"
- "glPointParameteriv\0"
- "glPointParameterivEXT\0"
- "glPointParameterivNV\0"
- "glPointSize\0"
- "glPollAsyncSGIX\0"
- "glPollInstrumentsSGIX\0"
- "glPolygonMode\0"
- "glPolygonOffset\0"
- "glPolygonOffsetEXT\0"
- "glPolygonStipple\0"
- "glPopAttrib\0"
- "glPopClientAttrib\0"
- "glPopMatrix\0"
- "glPopName\0"
- "glPrimitiveRestartIndexNV\0"
- "glPrimitiveRestartNV\0"
- "glPrioritizeTextures\0"
- "glPrioritizeTexturesEXT\0"
- "glProgramBufferParametersfvNV\0"
- "glProgramBufferParametersIivNV\0"
- "glProgramBufferParametersIuivNV\0"
- "glProgramCallbackMESA\0"
- "glProgramEnvParameter4dARB\0"
- "glProgramEnvParameter4dvARB\0"
- "glProgramEnvParameter4fARB\0"
- "glProgramEnvParameter4fvARB\0"
- "glProgramEnvParameterI4iNV\0"
- "glProgramEnvParameterI4ivNV\0"
- "glProgramEnvParameterI4uiNV\0"
- "glProgramEnvParameterI4uivNV\0"
- "glProgramEnvParameters4fvEXT\0"
- "glProgramEnvParametersI4ivNV\0"
- "glProgramEnvParametersI4uivNV\0"
- "glProgramLocalParameter4dARB\0"
- "glProgramLocalParameter4dvARB\0"
- "glProgramLocalParameter4fARB\0"
- "glProgramLocalParameter4fvARB\0"
- "glProgramLocalParameterI4iNV\0"
- "glProgramLocalParameterI4ivNV\0"
- "glProgramLocalParameterI4uiNV\0"
- "glProgramLocalParameterI4uivNV\0"
- "glProgramLocalParameters4fvEXT\0"
- "glProgramLocalParametersI4ivNV\0"
- "glProgramLocalParametersI4uivNV\0"
- "glProgramNamedParameter4dNV\0"
- "glProgramNamedParameter4dvNV\0"
- "glProgramNamedParameter4fNV\0"
- "glProgramNamedParameter4fvNV\0"
- "glProgramParameter4dNV\0"
- "glProgramParameter4dvNV\0"
- "glProgramParameter4fNV\0"
- "glProgramParameter4fvNV\0"
- "glProgramParameteriEXT\0"
- "glProgramParameters4dvNV\0"
- "glProgramParameters4fvNV\0"
- "glProgramStringARB\0"
- "glProgramVertexLimitNV\0"
- "glPushAttrib\0"
- "glPushClientAttrib\0"
- "glPushMatrix\0"
- "glPushName\0"
- "glRasterPos2d\0"
- "glRasterPos2dv\0"
- "glRasterPos2f\0"
- "glRasterPos2fv\0"
- "glRasterPos2i\0"
- "glRasterPos2iv\0"
- "glRasterPos2s\0"
- "glRasterPos2sv\0"
- "glRasterPos3d\0"
- "glRasterPos3dv\0"
- "glRasterPos3f\0"
- "glRasterPos3fv\0"
- "glRasterPos3i\0"
- "glRasterPos3iv\0"
- "glRasterPos3s\0"
- "glRasterPos3sv\0"
- "glRasterPos4d\0"
- "glRasterPos4dv\0"
- "glRasterPos4f\0"
- "glRasterPos4fv\0"
- "glRasterPos4i\0"
- "glRasterPos4iv\0"
- "glRasterPos4s\0"
- "glRasterPos4sv\0"
- "glReadBuffer\0"
- "glReadBufferRegion\0"
- "glReadBufferRegionEXT\0"
- "glReadInstrumentsSGIX\0"
- "glReadPixels\0"
- "glReadVideoPixelsSUN\0"
- "glRectd\0"
- "glRectdv\0"
- "glRectf\0"
- "glRectfv\0"
- "glRecti\0"
- "glRectiv\0"
- "glRects\0"
- "glRectsv\0"
- "glReferencePlaneSGIX\0"
- "glRenderbufferStorageEXT\0"
- "glRenderbufferStorageMultisampleCoverageNV\0"
- "glRenderbufferStorageMultisampleEXT\0"
- "glRenderMode\0"
- "glReplacementCodePointerSUN\0"
- "glReplacementCodeubSUN\0"
- "glReplacementCodeubvSUN\0"
- "glReplacementCodeuiColor3fVertex3fSUN\0"
- "glReplacementCodeuiColor3fVertex3fvSUN\0"
- "glReplacementCodeuiColor4fNormal3fVertex3fSUN\0"
- "glReplacementCodeuiColor4fNormal3fVertex3fvSUN\0"
- "glReplacementCodeuiColor4ubVertex3fSUN\0"
- "glReplacementCodeuiColor4ubVertex3fvSUN\0"
- "glReplacementCodeuiNormal3fVertex3fSUN\0"
- "glReplacementCodeuiNormal3fVertex3fvSUN\0"
- "glReplacementCodeuiSUN\0"
- "glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN\0"
- "glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN\0"
- "glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN\0"
- "glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN\0"
- "glReplacementCodeuiTexCoord2fVertex3fSUN\0"
- "glReplacementCodeuiTexCoord2fVertex3fvSUN\0"
- "glReplacementCodeuiVertex3fSUN\0"
- "glReplacementCodeuiVertex3fvSUN\0"
- "glReplacementCodeuivSUN\0"
- "glReplacementCodeusSUN\0"
- "glReplacementCodeusvSUN\0"
- "glRequestResidentProgramsNV\0"
- "glResetHistogram\0"
- "glResetHistogramEXT\0"
- "glResetMinmax\0"
- "glResetMinmaxEXT\0"
- "glResizeBuffersMESA\0"
- "glRotated\0"
- "glRotatef\0"
- "glSampleCoverage\0"
- "glSampleCoverageARB\0"
- "glSampleMapATI\0"
- "glSampleMaskEXT\0"
- "glSampleMaskSGIS\0"
- "glSamplePassARB\0"
- "glSamplePatternEXT\0"
- "glSamplePatternSGIS\0"
- "glScaled\0"
- "glScalef\0"
- "glScissor\0"
- "glSecondaryColor3b\0"
- "glSecondaryColor3bEXT\0"
- "glSecondaryColor3bv\0"
- "glSecondaryColor3bvEXT\0"
- "glSecondaryColor3d\0"
- "glSecondaryColor3dEXT\0"
- "glSecondaryColor3dv\0"
- "glSecondaryColor3dvEXT\0"
- "glSecondaryColor3f\0"
- "glSecondaryColor3fEXT\0"
- "glSecondaryColor3fv\0"
- "glSecondaryColor3fvEXT\0"
- "glSecondaryColor3hNV\0"
- "glSecondaryColor3hvNV\0"
- "glSecondaryColor3i\0"
- "glSecondaryColor3iEXT\0"
- "glSecondaryColor3iv\0"
- "glSecondaryColor3ivEXT\0"
- "glSecondaryColor3s\0"
- "glSecondaryColor3sEXT\0"
- "glSecondaryColor3sv\0"
- "glSecondaryColor3svEXT\0"
- "glSecondaryColor3ub\0"
- "glSecondaryColor3ubEXT\0"
- "glSecondaryColor3ubv\0"
- "glSecondaryColor3ubvEXT\0"
- "glSecondaryColor3ui\0"
- "glSecondaryColor3uiEXT\0"
- "glSecondaryColor3uiv\0"
- "glSecondaryColor3uivEXT\0"
- "glSecondaryColor3us\0"
- "glSecondaryColor3usEXT\0"
- "glSecondaryColor3usv\0"
- "glSecondaryColor3usvEXT\0"
- "glSecondaryColorPointer\0"
- "glSecondaryColorPointerEXT\0"
- "glSecondaryColorPointerListIBM\0"
- "glSelectBuffer\0"
- "glSelectTextureCoordSetSGIS\0"
- "glSelectTextureSGIS\0"
- "glSelectTextureTransformSGIS\0"
- "glSeparableFilter2D\0"
- "glSeparableFilter2DEXT\0"
- "glSetFenceAPPLE\0"
- "glSetFenceNV\0"
- "glSetFragmentShaderConstantATI\0"
- "glSetInvariantEXT\0"
- "glSetLocalConstantEXT\0"
- "glShadeModel\0"
- "glShaderOp1EXT\0"
- "glShaderOp2EXT\0"
- "glShaderOp3EXT\0"
- "glShaderSource\0"
- "glShaderSourceARB\0"
- "glSharpenTexFuncSGIS\0"
- "glSpriteParameterfSGIX\0"
- "glSpriteParameterfvSGIX\0"
- "glSpriteParameteriSGIX\0"
- "glSpriteParameterivSGIX\0"
- "glStartInstrumentsSGIX\0"
- "glStencilClearTagEXT\0"
- "glStencilFunc\0"
- "glStencilFuncSeparate\0"
- "glStencilFuncSeparateATI\0"
- "glStencilMask\0"
- "glStencilMaskSeparate\0"
- "glStencilOp\0"
- "glStencilOpSeparate\0"
- "glStencilOpSeparateATI\0"
- "glStopInstrumentsSGIX\0"
- "glStringMarkerGREMEDY\0"
- "glSwapAPPLE\0"
- "glSwizzleEXT\0"
- "glTagSampleBufferSGIX\0"
- "glTangent3bEXT\0"
- "glTangent3bvEXT\0"
- "glTangent3dEXT\0"
- "glTangent3dvEXT\0"
- "glTangent3fEXT\0"
- "glTangent3fvEXT\0"
- "glTangent3iEXT\0"
- "glTangent3ivEXT\0"
- "glTangent3sEXT\0"
- "glTangent3svEXT\0"
- "glTangentPointerEXT\0"
- "glTbufferMask3DFX\0"
- "glTestFenceAPPLE\0"
- "glTestFenceNV\0"
- "glTestObjectAPPLE\0"
- "glTexBufferEXT\0"
- "glTexBumpParameterfvATI\0"
- "glTexBumpParameterivATI\0"
- "glTexCoord1d\0"
- "glTexCoord1dv\0"
- "glTexCoord1f\0"
- "glTexCoord1fv\0"
- "glTexCoord1hNV\0"
- "glTexCoord1hvNV\0"
- "glTexCoord1i\0"
- "glTexCoord1iv\0"
- "glTexCoord1s\0"
- "glTexCoord1sv\0"
- "glTexCoord2d\0"
- "glTexCoord2dv\0"
- "glTexCoord2f\0"
- "glTexCoord2fColor3fVertex3fSUN\0"
- "glTexCoord2fColor3fVertex3fvSUN\0"
- "glTexCoord2fColor4fNormal3fVertex3fSUN\0"
- "glTexCoord2fColor4fNormal3fVertex3fvSUN\0"
- "glTexCoord2fColor4ubVertex3fSUN\0"
- "glTexCoord2fColor4ubVertex3fvSUN\0"
- "glTexCoord2fNormal3fVertex3fSUN\0"
- "glTexCoord2fNormal3fVertex3fvSUN\0"
- "glTexCoord2fv\0"
- "glTexCoord2fVertex3fSUN\0"
- "glTexCoord2fVertex3fvSUN\0"
- "glTexCoord2hNV\0"
- "glTexCoord2hvNV\0"
- "glTexCoord2i\0"
- "glTexCoord2iv\0"
- "glTexCoord2s\0"
- "glTexCoord2sv\0"
- "glTexCoord3d\0"
- "glTexCoord3dv\0"
- "glTexCoord3f\0"
- "glTexCoord3fv\0"
- "glTexCoord3hNV\0"
- "glTexCoord3hvNV\0"
- "glTexCoord3i\0"
- "glTexCoord3iv\0"
- "glTexCoord3s\0"
- "glTexCoord3sv\0"
- "glTexCoord4d\0"
- "glTexCoord4dv\0"
- "glTexCoord4f\0"
- "glTexCoord4fColor4fNormal3fVertex4fSUN\0"
- "glTexCoord4fColor4fNormal3fVertex4fvSUN\0"
- "glTexCoord4fv\0"
- "glTexCoord4fVertex4fSUN\0"
- "glTexCoord4fVertex4fvSUN\0"
- "glTexCoord4hNV\0"
- "glTexCoord4hvNV\0"
- "glTexCoord4i\0"
- "glTexCoord4iv\0"
- "glTexCoord4s\0"
- "glTexCoord4sv\0"
- "glTexCoordPointer\0"
- "glTexCoordPointerEXT\0"
- "glTexCoordPointerListIBM\0"
- "glTexCoordPointervINTEL\0"
- "glTexEnvf\0"
- "glTexEnvfv\0"
- "glTexEnvi\0"
- "glTexEnviv\0"
- "glTexFilterFuncSGIS\0"
- "glTexGend\0"
- "glTexGendv\0"
- "glTexGenf\0"
- "glTexGenfv\0"
- "glTexGeni\0"
- "glTexGeniv\0"
- "glTexImage1D\0"
- "glTexImage2D\0"
- "glTexImage3D\0"
- "glTexImage3DEXT\0"
- "glTexImage4DSGIS\0"
- "glTexParameterf\0"
- "glTexParameterfv\0"
- "glTexParameteri\0"
- "glTexParameterIivEXT\0"
- "glTexParameterIuivEXT\0"
- "glTexParameteriv\0"
- "glTexScissorFuncINTEL\0"
- "glTexScissorINTEL\0"
- "glTexSubImage1D\0"
- "glTexSubImage1DEXT\0"
- "glTexSubImage2D\0"
- "glTexSubImage2DEXT\0"
- "glTexSubImage3D\0"
- "glTexSubImage3DEXT\0"
- "glTexSubImage4DSGIS\0"
- "glTextureColorMaskSGIS\0"
- "glTextureFogSGIX\0"
- "glTextureLightEXT\0"
- "glTextureMaterialEXT\0"
- "glTextureNormalEXT\0"
- "glTextureRangeAPPLE\0"
- "glTrackMatrixNV\0"
- "glTransformFeedbackAttribsNV\0"
- "glTransformFeedbackVaryingsNV\0"
- "glTranslated\0"
- "glTranslatef\0"
- "glUniform1f\0"
- "glUniform1fARB\0"
- "glUniform1fv\0"
- "glUniform1fvARB\0"
- "glUniform1i\0"
- "glUniform1iARB\0"
- "glUniform1iv\0"
- "glUniform1ivARB\0"
- "glUniform1uiEXT\0"
- "glUniform1uivEXT\0"
- "glUniform2f\0"
- "glUniform2fARB\0"
- "glUniform2fv\0"
- "glUniform2fvARB\0"
- "glUniform2i\0"
- "glUniform2iARB\0"
- "glUniform2iv\0"
- "glUniform2ivARB\0"
- "glUniform2uiEXT\0"
- "glUniform2uivEXT\0"
- "glUniform3f\0"
- "glUniform3fARB\0"
- "glUniform3fv\0"
- "glUniform3fvARB\0"
- "glUniform3i\0"
- "glUniform3iARB\0"
- "glUniform3iv\0"
- "glUniform3ivARB\0"
- "glUniform3uiEXT\0"
- "glUniform3uivEXT\0"
- "glUniform4f\0"
- "glUniform4fARB\0"
- "glUniform4fv\0"
- "glUniform4fvARB\0"
- "glUniform4i\0"
- "glUniform4iARB\0"
- "glUniform4iv\0"
- "glUniform4ivARB\0"
- "glUniform4uiEXT\0"
- "glUniform4uivEXT\0"
- "glUniformBufferEXT\0"
- "glUniformMatrix2fv\0"
- "glUniformMatrix2fvARB\0"
- "glUniformMatrix2x3fv\0"
- "glUniformMatrix2x4fv\0"
- "glUniformMatrix3fv\0"
- "glUniformMatrix3fvARB\0"
- "glUniformMatrix3x2fv\0"
- "glUniformMatrix3x4fv\0"
- "glUniformMatrix4fv\0"
- "glUniformMatrix4fvARB\0"
- "glUniformMatrix4x2fv\0"
- "glUniformMatrix4x3fv\0"
- "glUnlockArraysEXT\0"
- "glUnmapBuffer\0"
- "glUnmapBufferARB\0"
- "glUnmapObjectBufferATI\0"
- "glUnmapTexture3DATI\0"
- "glUpdateObjectBufferATI\0"
- "glUseProgram\0"
- "glUseProgramObjectARB\0"
- "glValidateProgram\0"
- "glValidateProgramARB\0"
- "glValidBackBufferHintAutodesk\0"
- "glVariantArrayObjectATI\0"
- "glVariantbvEXT\0"
- "glVariantdvEXT\0"
- "glVariantfvEXT\0"
- "glVariantivEXT\0"
- "glVariantPointerEXT\0"
- "glVariantsvEXT\0"
- "glVariantubvEXT\0"
- "glVariantuivEXT\0"
- "glVariantusvEXT\0"
- "glVertex2d\0"
- "glVertex2dv\0"
- "glVertex2f\0"
- "glVertex2fv\0"
- "glVertex2hNV\0"
- "glVertex2hvNV\0"
- "glVertex2i\0"
- "glVertex2iv\0"
- "glVertex2s\0"
- "glVertex2sv\0"
- "glVertex3d\0"
- "glVertex3dv\0"
- "glVertex3f\0"
- "glVertex3fv\0"
- "glVertex3hNV\0"
- "glVertex3hvNV\0"
- "glVertex3i\0"
- "glVertex3iv\0"
- "glVertex3s\0"
- "glVertex3sv\0"
- "glVertex4d\0"
- "glVertex4dv\0"
- "glVertex4f\0"
- "glVertex4fv\0"
- "glVertex4hNV\0"
- "glVertex4hvNV\0"
- "glVertex4i\0"
- "glVertex4iv\0"
- "glVertex4s\0"
- "glVertex4sv\0"
- "glVertexArrayParameteriAPPLE\0"
- "glVertexArrayRangeAPPLE\0"
- "glVertexArrayRangeNV\0"
- "glVertexAttrib1d\0"
- "glVertexAttrib1dARB\0"
- "glVertexAttrib1dNV\0"
- "glVertexAttrib1dv\0"
- "glVertexAttrib1dvARB\0"
- "glVertexAttrib1dvNV\0"
- "glVertexAttrib1f\0"
- "glVertexAttrib1fARB\0"
- "glVertexAttrib1fNV\0"
- "glVertexAttrib1fv\0"
- "glVertexAttrib1fvARB\0"
- "glVertexAttrib1fvNV\0"
- "glVertexAttrib1hNV\0"
- "glVertexAttrib1hvNV\0"
- "glVertexAttrib1s\0"
- "glVertexAttrib1sARB\0"
- "glVertexAttrib1sNV\0"
- "glVertexAttrib1sv\0"
- "glVertexAttrib1svARB\0"
- "glVertexAttrib1svNV\0"
- "glVertexAttrib2d\0"
- "glVertexAttrib2dARB\0"
- "glVertexAttrib2dNV\0"
- "glVertexAttrib2dv\0"
- "glVertexAttrib2dvARB\0"
- "glVertexAttrib2dvNV\0"
- "glVertexAttrib2f\0"
- "glVertexAttrib2fARB\0"
- "glVertexAttrib2fNV\0"
- "glVertexAttrib2fv\0"
- "glVertexAttrib2fvARB\0"
- "glVertexAttrib2fvNV\0"
- "glVertexAttrib2hNV\0"
- "glVertexAttrib2hvNV\0"
- "glVertexAttrib2s\0"
- "glVertexAttrib2sARB\0"
- "glVertexAttrib2sNV\0"
- "glVertexAttrib2sv\0"
- "glVertexAttrib2svARB\0"
- "glVertexAttrib2svNV\0"
- "glVertexAttrib3d\0"
- "glVertexAttrib3dARB\0"
- "glVertexAttrib3dNV\0"
- "glVertexAttrib3dv\0"
- "glVertexAttrib3dvARB\0"
- "glVertexAttrib3dvNV\0"
- "glVertexAttrib3f\0"
- "glVertexAttrib3fARB\0"
- "glVertexAttrib3fNV\0"
- "glVertexAttrib3fv\0"
- "glVertexAttrib3fvARB\0"
- "glVertexAttrib3fvNV\0"
- "glVertexAttrib3hNV\0"
- "glVertexAttrib3hvNV\0"
- "glVertexAttrib3s\0"
- "glVertexAttrib3sARB\0"
- "glVertexAttrib3sNV\0"
- "glVertexAttrib3sv\0"
- "glVertexAttrib3svARB\0"
- "glVertexAttrib3svNV\0"
- "glVertexAttrib4bv\0"
- "glVertexAttrib4bvARB\0"
- "glVertexAttrib4d\0"
- "glVertexAttrib4dARB\0"
- "glVertexAttrib4dNV\0"
- "glVertexAttrib4dv\0"
- "glVertexAttrib4dvARB\0"
- "glVertexAttrib4dvNV\0"
- "glVertexAttrib4f\0"
- "glVertexAttrib4fARB\0"
- "glVertexAttrib4fNV\0"
- "glVertexAttrib4fv\0"
- "glVertexAttrib4fvARB\0"
- "glVertexAttrib4fvNV\0"
- "glVertexAttrib4hNV\0"
- "glVertexAttrib4hvNV\0"
- "glVertexAttrib4iv\0"
- "glVertexAttrib4ivARB\0"
- "glVertexAttrib4Nbv\0"
- "glVertexAttrib4NbvARB\0"
- "glVertexAttrib4Niv\0"
- "glVertexAttrib4NivARB\0"
- "glVertexAttrib4Nsv\0"
- "glVertexAttrib4NsvARB\0"
- "glVertexAttrib4Nub\0"
- "glVertexAttrib4NubARB\0"
- "glVertexAttrib4Nubv\0"
- "glVertexAttrib4NubvARB\0"
- "glVertexAttrib4Nuiv\0"
- "glVertexAttrib4NuivARB\0"
- "glVertexAttrib4Nusv\0"
- "glVertexAttrib4NusvARB\0"
- "glVertexAttrib4s\0"
- "glVertexAttrib4sARB\0"
- "glVertexAttrib4sNV\0"
- "glVertexAttrib4sv\0"
- "glVertexAttrib4svARB\0"
- "glVertexAttrib4svNV\0"
- "glVertexAttrib4ubNV\0"
- "glVertexAttrib4ubv\0"
- "glVertexAttrib4ubvARB\0"
- "glVertexAttrib4ubvNV\0"
- "glVertexAttrib4uiv\0"
- "glVertexAttrib4uivARB\0"
- "glVertexAttrib4usv\0"
- "glVertexAttrib4usvARB\0"
- "glVertexAttribArrayObjectATI\0"
- "glVertexAttribI1iEXT\0"
- "glVertexAttribI1ivEXT\0"
- "glVertexAttribI1uiEXT\0"
- "glVertexAttribI1uivEXT\0"
- "glVertexAttribI2iEXT\0"
- "glVertexAttribI2ivEXT\0"
- "glVertexAttribI2uiEXT\0"
- "glVertexAttribI2uivEXT\0"
- "glVertexAttribI3iEXT\0"
- "glVertexAttribI3ivEXT\0"
- "glVertexAttribI3uiEXT\0"
- "glVertexAttribI3uivEXT\0"
- "glVertexAttribI4bvEXT\0"
- "glVertexAttribI4iEXT\0"
- "glVertexAttribI4ivEXT\0"
- "glVertexAttribI4svEXT\0"
- "glVertexAttribI4ubvEXT\0"
- "glVertexAttribI4uiEXT\0"
- "glVertexAttribI4uivEXT\0"
- "glVertexAttribI4usvEXT\0"
- "glVertexAttribIPointerEXT\0"
- "glVertexAttribPointer\0"
- "glVertexAttribPointerARB\0"
- "glVertexAttribPointerNV\0"
- "glVertexAttribs1dvNV\0"
- "glVertexAttribs1fvNV\0"
- "glVertexAttribs1hvNV\0"
- "glVertexAttribs1svNV\0"
- "glVertexAttribs2dvNV\0"
- "glVertexAttribs2fvNV\0"
- "glVertexAttribs2hvNV\0"
- "glVertexAttribs2svNV\0"
- "glVertexAttribs3dvNV\0"
- "glVertexAttribs3fvNV\0"
- "glVertexAttribs3hvNV\0"
- "glVertexAttribs3svNV\0"
- "glVertexAttribs4dvNV\0"
- "glVertexAttribs4fvNV\0"
- "glVertexAttribs4hvNV\0"
- "glVertexAttribs4svNV\0"
- "glVertexAttribs4ubvNV\0"
- "glVertexBlendARB\0"
- "glVertexBlendEnvfATI\0"
- "glVertexBlendEnviATI\0"
- "glVertexPointer\0"
- "glVertexPointerEXT\0"
- "glVertexPointerListIBM\0"
- "glVertexPointervINTEL\0"
- "glVertexStream1dATI\0"
- "glVertexStream1dvATI\0"
- "glVertexStream1fATI\0"
- "glVertexStream1fvATI\0"
- "glVertexStream1iATI\0"
- "glVertexStream1ivATI\0"
- "glVertexStream1sATI\0"
- "glVertexStream1svATI\0"
- "glVertexStream2dATI\0"
- "glVertexStream2dvATI\0"
- "glVertexStream2fATI\0"
- "glVertexStream2fvATI\0"
- "glVertexStream2iATI\0"
- "glVertexStream2ivATI\0"
- "glVertexStream2sATI\0"
- "glVertexStream2svATI\0"
- "glVertexStream3dATI\0"
- "glVertexStream3dvATI\0"
- "glVertexStream3fATI\0"
- "glVertexStream3fvATI\0"
- "glVertexStream3iATI\0"
- "glVertexStream3ivATI\0"
- "glVertexStream3sATI\0"
- "glVertexStream3svATI\0"
- "glVertexStream4dATI\0"
- "glVertexStream4dvATI\0"
- "glVertexStream4fATI\0"
- "glVertexStream4fvATI\0"
- "glVertexStream4iATI\0"
- "glVertexStream4ivATI\0"
- "glVertexStream4sATI\0"
- "glVertexStream4svATI\0"
- "glVertexWeightfEXT\0"
- "glVertexWeightfvEXT\0"
- "glVertexWeighthNV\0"
- "glVertexWeighthvNV\0"
- "glVertexWeightPointerEXT\0"
- "glViewport\0"
- "glWeightbvARB\0"
- "glWeightdvARB\0"
- "glWeightfvARB\0"
- "glWeightivARB\0"
- "glWeightPointerARB\0"
- "glWeightsvARB\0"
- "glWeightubvARB\0"
- "glWeightuivARB\0"
- "glWeightusvARB\0"
- "glWindowBackBufferHintAutodesk\0"
- "glWindowPos2d\0"
- "glWindowPos2dARB\0"
- "glWindowPos2dMESA\0"
- "glWindowPos2dv\0"
- "glWindowPos2dvARB\0"
- "glWindowPos2dvMESA\0"
- "glWindowPos2f\0"
- "glWindowPos2fARB\0"
- "glWindowPos2fMESA\0"
- "glWindowPos2fv\0"
- "glWindowPos2fvARB\0"
- "glWindowPos2fvMESA\0"
- "glWindowPos2i\0"
- "glWindowPos2iARB\0"
- "glWindowPos2iMESA\0"
- "glWindowPos2iv\0"
- "glWindowPos2ivARB\0"
- "glWindowPos2ivMESA\0"
- "glWindowPos2s\0"
- "glWindowPos2sARB\0"
- "glWindowPos2sMESA\0"
- "glWindowPos2sv\0"
- "glWindowPos2svARB\0"
- "glWindowPos2svMESA\0"
- "glWindowPos3d\0"
- "glWindowPos3dARB\0"
- "glWindowPos3dMESA\0"
- "glWindowPos3dv\0"
- "glWindowPos3dvARB\0"
- "glWindowPos3dvMESA\0"
- "glWindowPos3f\0"
- "glWindowPos3fARB\0"
- "glWindowPos3fMESA\0"
- "glWindowPos3fv\0"
- "glWindowPos3fvARB\0"
- "glWindowPos3fvMESA\0"
- "glWindowPos3i\0"
- "glWindowPos3iARB\0"
- "glWindowPos3iMESA\0"
- "glWindowPos3iv\0"
- "glWindowPos3ivARB\0"
- "glWindowPos3ivMESA\0"
- "glWindowPos3s\0"
- "glWindowPos3sARB\0"
- "glWindowPos3sMESA\0"
- "glWindowPos3sv\0"
- "glWindowPos3svARB\0"
- "glWindowPos3svMESA\0"
- "glWindowPos4dMESA\0"
- "glWindowPos4dvMESA\0"
- "glWindowPos4fMESA\0"
- "glWindowPos4fvMESA\0"
- "glWindowPos4iMESA\0"
- "glWindowPos4ivMESA\0"
- "glWindowPos4sMESA\0"
- "glWindowPos4svMESA\0"
- "glWriteMaskEXT\0"
-#ifndef WIN32
- "glXAllocateMemoryMESA\0"
- "glXAllocateMemoryNV\0"
- "glXBindChannelToWindowSGIX\0"
- "glXBindHyperpipeSGIX\0"
- "glXBindSwapBarrierNV\0"
- "glXBindSwapBarrierSGIX\0"
- "glXBindTexImageARB\0"
- "glXBindTexImageATI\0"
- "glXBindTexImageEXT\0"
- "glXBindVideoImageNV\0"
- "glXChannelRectSGIX\0"
- "glXChannelRectSyncSGIX\0"
- "glXChooseFBConfig\0"
- "glXChooseFBConfigSGIX\0"
- "glXChooseVisual\0"
- "glXCopyContext\0"
- "glXCopySubBufferMESA\0"
- "glXCreateContext\0"
- "glXCreateContextWithConfigSGIX\0"
- "glXCreateGLXPbufferSGIX\0"
- "glXCreateGLXPixmap\0"
- "glXCreateGLXPixmapMESA\0"
- "glXCreateGLXPixmapWithConfigSGIX\0"
- "glXCreateNewContext\0"
- "glXCreatePbuffer\0"
- "glXCreatePixmap\0"
- "glXCreateWindow\0"
- "glXCushionSGI\0"
- "glXDestroyContext\0"
- "glXDestroyGLXPbufferSGIX\0"
- "glXDestroyGLXPixmap\0"
- "glXDestroyHyperpipeConfigSGIX\0"
- "glXDestroyPbuffer\0"
- "glXDestroyPixmap\0"
- "glXDestroyWindow\0"
- "glXDrawableAttribARB\0"
- "glXDrawableAttribATI\0"
- "glXFreeContextEXT\0"
- "glXFreeMemoryMESA\0"
- "glXFreeMemoryNV\0"
- "glXGetAGPOffsetMESA\0"
- "glXGetClientString\0"
- "glXGetConfig\0"
- "glXGetContextIDEXT\0"
- "glXGetCurrentContext\0"
- "glXGetCurrentDisplay\0"
- "glXGetCurrentDisplayEXT\0"
- "glXGetCurrentDrawable\0"
- "glXGetCurrentReadDrawable\0"
- "glXGetCurrentReadDrawableSGI\0"
- "glXGetDriverConfig\0"
- "glXGetFBConfigAttrib\0"
- "glXGetFBConfigAttribSGIX\0"
- "glXGetFBConfigFromVisualSGIX\0"
- "glXGetFBConfigs\0"
- "glXGetMemoryOffsetMESA\0"
- "glXGetMscRateOML\0"
- "glXGetProcAddress\0"
- "glXGetProcAddressARB\0"
- "glXGetRefreshRateSGI\0"
- "glXGetScreenDriver\0"
- "glXGetSelectedEvent\0"
- "glXGetSelectedEventSGIX\0"
- "glXGetSyncValuesOML\0"
- "glXGetTransparentIndexSUN\0"
- "glXGetVideoDeviceNV\0"
- "glXGetVideoInfoNV\0"
- "glXGetVideoResizeSUN\0"
- "glXGetVideoSyncSGI\0"
- "glXGetVisualFromFBConfig\0"
- "glXGetVisualFromFBConfigSGIX\0"
- "glXHyperpipeAttribSGIX\0"
- "glXHyperpipeConfigSGIX\0"
- "glXImportContextEXT\0"
- "glXIsDirect\0"
- "glXJoinSwapGroupNV\0"
- "glXJoinSwapGroupSGIX\0"
- "glXMakeContextCurrent\0"
- "glXMakeCurrent\0"
- "glXMakeCurrentReadSGI\0"
- "glXQueryChannelDeltasSGIX\0"
- "glXQueryChannelRectSGIX\0"
- "glXQueryContext\0"
- "glXQueryContextInfoEXT\0"
- "glXQueryDrawable\0"
- "glXQueryExtension\0"
- "glXQueryExtensionsString\0"
- "glXQueryFrameCountNV\0"
- "glXQueryGLXPbufferSGIX\0"
- "glXQueryHyperpipeAttribSGIX\0"
- "glXQueryHyperpipeBestAttribSGIX\0"
- "glXQueryHyperpipeConfigSGIX\0"
- "glXQueryHyperpipeNetworkSGIX\0"
- "glXQueryMaxSwapBarriersSGIX\0"
- "glXQueryMaxSwapGroupsNV\0"
- "glXQueryServerString\0"
- "glXQuerySwapGroupNV\0"
- "glXQueryVersion\0"
- "glXReleaseBuffersMESA\0"
- "glXReleaseTexImageARB\0"
- "glXReleaseTexImageATI\0"
- "glXReleaseTexImageEXT\0"
- "glXReleaseVideoDeviceNV\0"
- "glXReleaseVideoImageNV\0"
- "glXResetFrameCountNV\0"
- "glXSelectEvent\0"
- "glXSelectEventSGIX\0"
- "glXSendPbufferToVideoNV\0"
- "glXSet3DfxModeMESA\0"
- "glXSwapBuffers\0"
- "glXSwapBuffersMscOML\0"
- "glXSwapIntervalSGI\0"
- "glXUseXFont\0"
- "glXVideoResizeSUN\0"
- "glXWaitForMscOML\0"
- "glXWaitForSbcOML\0"
- "glXWaitGL\0"
- "glXWaitVideoSyncSGI\0"
- "glXWaitX\0"
-#endif
- "\0"
-};
-
-typedef struct
-{
- unsigned int hash;
- char* name;
- __GLXextFuncPtr func;
- int found_on_client_side;
- int found_on_server_side;
- int alreadyAsked;
-} AssocProcAdress;
-
-#ifdef PROVIDE_STUB_IMPLEMENTATION
-static void _glStubImplementation()
-{
- log_gl("This function is a stub !!!\n");
-}
-#endif
-
-static __GLXextFuncPtr glXGetProcAddress_no_lock(const GLubyte * _name)
-{
- static int nbElts = 0;
- static int tabSize = 0;
- static AssocProcAdress* tab_assoc = NULL;
- static void* handle = NULL;
- __GLXextFuncPtr ret = NULL;
-
- const char* name = (const char*)_name;
- log_gl("looking for \"%s\",\n", name);
- int i;
-
- if (name == NULL)
- {
- goto end_of_glx_get_proc_address;
- }
-
-#ifdef WIN32
- if (strcmp(name, "wglGetExtensionsStringARB") == 0 ||
- strcmp(name, "wglGetExtensionsStringEXT") == 0)
- {
- ret = wglGetExtensionsStringARB;
- goto end_of_glx_get_proc_address;
- }
-#endif
- if (tabSize == 0)
- {
- tabSize = 2000;
- tab_assoc = calloc(tabSize, sizeof(AssocProcAdress));
-
-#ifndef WIN32
- handle = dlopen(getenv("REAL_LIBGL") ? getenv("REAL_LIBGL") : "libGL.so" ,RTLD_LAZY);
- if (!handle) {
- log_gl("%s\n", dlerror());
- exit(1);
- }
-#else
- handle = (void *)LoadLibrary("opengl32.dll");
- if (!handle) {
- log_gl("can't load opengl32.dll\n");
- exit(1);
- }
-#endif
-
- {
- log_gl("global_glXGetProcAddress request\n");
- int sizeOfString = 0;
- int nbRequestElts = 0;
- int i = 0;
- while(1)
- {
- if (global_glXGetProcAddress_request[i] == '\0')
- {
- nbRequestElts++;
- if (global_glXGetProcAddress_request[i + 1] == '\0')
- {
- sizeOfString = i + 1;
- break;
- }
- }
- i++;
- }
- log_gl("nbRequestElts=%d\n", nbRequestElts);
- char* result = (char*)malloc(nbRequestElts);
- long args[] = { INT_TO_ARG(nbRequestElts), POINTER_TO_ARG(global_glXGetProcAddress_request), POINTER_TO_ARG(result) };
- int args_size[] = { 0, sizeOfString, nbRequestElts };
- do_opengl_call_no_lock(glXGetProcAddress_global_fake_func, NULL, CHECK_ARGS(args, args_size));
- int offset = 0;
- for(i=0; i<nbRequestElts;i++)
- {
- const char* funcName = global_glXGetProcAddress_request + offset;
-#ifndef WIN32
- void* func = dlsym(handle, funcName);
-#else
- void* func = GetProcAddress(handle, funcName);
-#endif
-#ifdef PROVIDE_STUB_IMPLEMENTATION
- if (func == NULL)
- func = _glStubImplementation;
-#endif
- if (result[i] && func == NULL)
- log_gl("%s %d %d\n", funcName, result[i], func != NULL);
-
- if (result[i] == 0)
- {
- if (nbElts < tabSize)
- {
- int hash = str_hash(funcName);
- tab_assoc[nbElts].alreadyAsked = 0;
- tab_assoc[nbElts].found_on_server_side = 0;
- tab_assoc[nbElts].found_on_client_side = func != NULL;
- tab_assoc[nbElts].hash = hash;
- tab_assoc[nbElts].name = strdup(funcName);
- tab_assoc[nbElts].func = NULL;
- nbElts ++;
- }
- }
- else
- {
- if (nbElts < tabSize)
- {
- int hash = str_hash(funcName);
- tab_assoc[nbElts].alreadyAsked = 0;
- tab_assoc[nbElts].found_on_server_side = 1;
- tab_assoc[nbElts].found_on_client_side = func != NULL;
- tab_assoc[nbElts].hash = hash;
- tab_assoc[nbElts].name = strdup(funcName);
- tab_assoc[nbElts].func = func;
- nbElts ++;
- }
- }
- offset += strlen(funcName) + 1;
- }
- free(result);
- ret = glXGetProcAddress_no_lock(_name);
- goto end_of_glx_get_proc_address;
- }
- }
-
- int hash = str_hash(name);
- for(i=0;i<nbElts;i++)
- {
- if (tab_assoc[i].hash == hash && strcmp(tab_assoc[i].name, name) == 0)
- {
- if (tab_assoc[i].alreadyAsked == 0)
- {
- tab_assoc[i].alreadyAsked = 1;
- if (tab_assoc[i].found_on_server_side == 0 && tab_assoc[i].found_on_client_side == 0)
- {
- log_gl("not found name on server and client side = %s\n", name);
- }
- else if (tab_assoc[i].found_on_server_side == 0)
- {
- log_gl("not found name on server side = %s\n", name);
- }
- else if (tab_assoc[i].found_on_client_side == 0)
- {
- log_gl("not found name on client side = %s\n", name);
- }
- }
- ret = (__GLXextFuncPtr)tab_assoc[i].func;
- goto end_of_glx_get_proc_address;
- }
- }
- log_gl("looking for \"%s\",\n", name);
- int ret_call = 0;
- long args[] = { INT_TO_ARG(name) };
- do_opengl_call_no_lock(glXGetProcAddress_fake_func, &ret_call, args, NULL);
-#ifndef WIN32
- void* func = dlsym(handle, name);
-#else
- void* func = GetProcAddress(handle, name);
-#endif
-#ifdef PROVIDE_STUB_IMPLEMENTATION
- if (func == NULL)
- func = _glStubImplementation;
-#endif
- if (ret_call == 0)
- {
- if (nbElts < tabSize)
- {
- tab_assoc[nbElts].alreadyAsked = 1;
- tab_assoc[nbElts].found_on_server_side = 0;
- tab_assoc[nbElts].found_on_client_side = func != NULL;
- tab_assoc[nbElts].hash = hash;
- tab_assoc[nbElts].name = strdup(name);
- tab_assoc[nbElts].func = NULL;
- nbElts ++;
- }
- if (func == NULL)
- {
- log_gl("not found name on server and client side = %s\n", name);
- }
- else
- {
- log_gl("not found name on server side = %s\n", name);
- }
- ret = NULL;
- goto end_of_glx_get_proc_address;
- }
- else
- {
- if (func == NULL)
- {
- log_gl("not found name on client side = %s\n", name);
- }
- if (nbElts < tabSize)
- {
- tab_assoc[nbElts].alreadyAsked = 1;
- tab_assoc[nbElts].found_on_server_side = 1;
- tab_assoc[nbElts].found_on_client_side = func != NULL;
- tab_assoc[nbElts].hash = hash;
- tab_assoc[nbElts].name = strdup(name);
- tab_assoc[nbElts].func = func;
- nbElts ++;
- }
- ret = func;
- goto end_of_glx_get_proc_address;
- }
-end_of_glx_get_proc_address:
- return ret;
-}
-
-__GLXextFuncPtr glXGetProcAddress(const GLubyte * name)
-{
- __GLXextFuncPtr ret;
- LOCK(glXGetProcAddress_fake_func);
- ret = glXGetProcAddress_no_lock(name);
- UNLOCK(glXGetProcAddress_fake_func);
- return ret;
-}
-
-__GLXextFuncPtr glXGetProcAddressARB (const GLubyte * name)
-{
- return glXGetProcAddress(name);
-}
-
-#ifdef WIN32
-
-WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR _name)
-{
- return glXGetProcAddress(_name);
-}
-
-WINGDIAPI PROC WINAPI wglGetDefaultProcAddress(LPCSTR _name)
-{
- return glXGetProcAddress(_name);
-}
-
-WINGDIAPI int WINAPI wglChoosePixelFormat(HDC hdc,CONST PIXELFORMATDESCRIPTOR* b)
-{
- log_gl("wglChoosePixelFormat : stub\n");
- return 1; /* FIXME ? */
-}
-
-WINGDIAPI BOOL WINAPI wglCopyContext (HGLRC a, HGLRC ctxt, UINT c)
-{
- log_gl("wglCopyContext : stub\n");
- return 0;
-}
-
-/*
- static void __attribute__ ((constructor)) gl_init (void)
- {
- MessageBox(NULL, "gl_init", "gl_init", 0);
- }*/
-
-WINGDIAPI HGLRC WINAPI wglCreateContext (HDC hdc)
-{
- HGLRC ret;
- long args[] = { POINTER_TO_ARG(/*dpy*/0), INT_TO_ARG(/*visualid*/0), INT_TO_ARG(/*shareList*/0), INT_TO_ARG(/*direct*/1) };
- do_opengl_call(glXCreateContext_func, &ret, args, NULL);
- /*MessageBox(NULL, "wglCreateContext", "wglCreateContext", 0);*/
- return ret;
-}
-
-WINGDIAPI HGLRC WINAPI wglCreateLayerContext (HDC hdc, int b)
-{
- log_gl("wglCreateLayerContext : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglDeleteContext (HGLRC a)
-{
- long args[] = { POINTER_TO_ARG(/*dpy*/0), POINTER_TO_ARG(a) };
- do_opengl_call(glXDestroyContext_func, NULL, args, NULL);
-
- /* FIXME ! */
- call_opengl(_exit_process_func, getpid(), NULL, NULL, NULL);
- close(fd);
-
- return 1;
-}
-
-WINGDIAPI BOOL WINAPI wglDescribeLayerPlane (HDC hdc, int b, int c, UINT d, LPLAYERPLANEDESCRIPTOR e)
-{
- log_gl("wglDescribeLayerPlane : stub\n");
- return 0;
-}
-
-WINGDIAPI int WINAPI wglDescribePixelFormat (HDC hdc, int b, UINT c, LPPIXELFORMATDESCRIPTOR d)
-{
- log_gl("wglDescribePixelFormat : stub\n");
- return 0;
-}
-
-WINGDIAPI HGLRC WINAPI wglGetCurrentContext (void)
-{
- log_gl("wglGetCurrentContext : stub\n");
- return 0;
-}
-WINGDIAPI HDC WINAPI wglGetCurrentDC (void)
-{
- log_gl("wglGetCurrentDC : stub\n");
- return 0;
-}
-
-WINGDIAPI int WINAPI wglGetLayerPaletteEntries(HDC hdc, int b, int c, int d, COLORREF *e)
-{
- log_gl("wglGetLayerPaletteEntries : stub\n");
- return 0;
-}
-
-WINGDIAPI int WINAPI wglGetPixelFormat (HDC hdc)
-{
- log_gl("wglGetPixelFormat : stub\n");
- return 0;
-}
-
-#define IsViewable 2
-
-static RECT oldRect = {0, 0, 0, 0};
-
-static void _move_win_if_necessary(HDC hdc)
-{
- HWND hwnd = WindowFromDC(hdc);
- if (hwnd)
- {
- RECT rect;
- if (GetWindowRect(hwnd, &rect) == 0)
- {
- log_gl("arg. cannot retrieve window size\n");
- return;
- }
- if (oldRect.left != rect.left || oldRect.top != rect.top ||
- oldRect.right != rect.right || oldRect.bottom != rect.bottom)
- {
- {
- long args[] = { INT_TO_ARG(hdc), INT_TO_ARG(IsViewable) }; /* FIXME */
- do_opengl_call(_changeWindowState_func, NULL, args, NULL);
- }
- {
- int standardizedPos[] = { rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top };
- long args[] = { INT_TO_ARG(hdc), POINTER_TO_ARG(standardizedPos)};
- do_opengl_call(_moveResizeWindow_func, NULL, args, NULL);
- }
-
- memcpy(&oldRect, &rect, sizeof(rect));
- }
- }
- else
- {
- log_gl("arg. cannot retrieve window from DC\n");
- }
-}
-
-WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC ctxt)
-{
- long args[] = { POINTER_TO_ARG(/*dpy*/0), INT_TO_ARG(/*drawable*/hdc), INT_TO_ARG(/*ctx*/ctxt) };
- do_opengl_call(glXMakeCurrent_func, NULL, args, NULL);
- if (hdc != NULL)
- _move_win_if_necessary(hdc);
- return 1;
-}
-
-WINGDIAPI BOOL WINAPI wglRealizeLayerPalette (HDC hdc, int b, BOOL c)
-{
- log_gl("wglRealizeLayerPalette : stub\n");
- return 0;
-}
-
-WINGDIAPI int WINAPI wglSetLayerPaletteEntries(HDC hdc, int b, int c, int d, CONST COLORREF *e)
-{
- log_gl("wglSetLayerPaletteEntries : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglSetPixelFormat (HDC hdc, int b, CONST PIXELFORMATDESCRIPTOR *c)
-{
- log_gl("wglSetPixelFormat : stub\n");
- return 1; /* FIXME ? */
-}
-
-WINGDIAPI BOOL WINAPI wglShareLists (HGLRC a, HGLRC ctxt)
-{
- log_gl("wglShareLists : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglSwapBuffers (HDC hdc)
-{
- _move_win_if_necessary(hdc);
- long args[] = { POINTER_TO_ARG(/*dpy*/0), INT_TO_ARG(/*drawable*/hdc) };
- do_opengl_call(glXSwapBuffers_func, NULL, args, NULL);
- return 1;
-}
-
-WINGDIAPI BOOL WINAPI wglSwapLayerBuffers (HDC hdc, UINT b)
-{
- log_gl("wglSwapLayerBuffers : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglUseFontBitmapsA (HDC hdc, DWORD b, DWORD c, DWORD d)
-{
- log_gl("wglUseFontBitmapsA : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglUseFontBitmapsW (HDC hdc, DWORD b, DWORD c, DWORD d)
-{
- log_gl("wglUseFontBitmapsW : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglUseFontOutlinesA (HDC hdc, DWORD b, DWORD c, DWORD d, FLOAT e, FLOAT f, int g, LPGLYPHMETRICSFLOAT h)
-{
- log_gl("wglUseFontOutlinesA : stub\n");
- return 0;
-}
-
-WINGDIAPI BOOL WINAPI wglUseFontOutlinesW (HDC hdc, DWORD b, DWORD c, DWORD d, FLOAT e, FLOAT f, int g, LPGLYPHMETRICSFLOAT h)
-{
- log_gl("wglUseFontOutlinesW : stub\n");
- return 0;
-}
-
-#define GLX_EXTENSIONS 3
-
-WINGDIAPI const char* WINAPI wglGetExtensionsStringARB(HDC hdc)
-{
- int i;
- char* glxClientExtensions = NULL;
- char* glxServerExtensions = NULL;
- char* glExtensions = NULL;
- static char* extensions = NULL;
- if (extensions)
- return extensions;
-
- {
- long args[] = { POINTER_TO_ARG(/*dpy*/0), INT_TO_ARG(GLX_EXTENSIONS) };
- do_opengl_call(glXGetClientString_func, &glxClientExtensions, args, NULL);
- glxClientExtensions = strdup(glxClientExtensions);
- }
- {
- long args[] = { POINTER_TO_ARG(/*dpy*/0), INT_TO_ARG(/*screen*/0), INT_TO_ARG(GLX_EXTENSIONS) };
- do_opengl_call(glXQueryServerString_func, &glxServerExtensions, args, NULL);
- glxServerExtensions = strdup(glxServerExtensions);
- }
- glExtensions = glGetString(GL_EXTENSIONS);
-
- extensions = malloc(strlen("WGL_ARB_extensions_string") + 1 +
- strlen(glxClientExtensions) + 1 +
- strlen(glxServerExtensions) + 1 +
- strlen(glExtensions) + 1);
- strcpy(extensions, "WGL_ARB_extensions_string ");
- strcat(extensions, glxClientExtensions);
- strcat(extensions, " ");
- strcat(extensions, glxServerExtensions);
- strcat(extensions, " ");
- strcat(extensions, glExtensions);
-
- free(glxClientExtensions);
- free(glxServerExtensions);
-
- i = 0;
- while(extensions[i])
- {
- if (strncmp(extensions + i, "GLX", 3) == 0)
- {
- extensions[i] = 'W';
- extensions[i+1] = 'G';
- extensions[i+2] = 'L';
- }
- i++;
- }
-
- return extensions;
-}
-
-
-#endif
+++ /dev/null
-/* Adapted for qemu/OpenGL. Copyright (C) 2007, Even Rouault */
-
-/*
- * Mesa 3-D graphics library
- * Version: 3.5
- *
- * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/* xfonts.c -- glXUseXFont() for Mesa written by
- * Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de
- */
-
-/* Implementation. */
-
-/* Fill a BITMAP with a character C from thew current font
- in the graphics context GC. WIDTH is the width in bytes
- and HEIGHT is the height in bits.
-
- Note that the generated bitmaps must be used with
-
- glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
- glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
- glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
- glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
- glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
-
- Possible optimizations:
-
- * use only one reusable pixmap with the maximum dimensions.
- * draw the entire font into a single pixmap (careful with
- proportional fonts!).
-*/
-
-
-/*
- * Generate OpenGL-compatible bitmap.
- */
-static void
-fill_bitmap(Display * dpy, Window win, GC gc,
- unsigned int width, unsigned int height,
- int x0, int y0, unsigned int c, GLubyte * bitmap)
-{
- XImage *image;
- unsigned int x, y;
- Pixmap pixmap;
- XChar2b char2b;
-
- pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1);
- XSetForeground(dpy, gc, 0);
- XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height);
- XSetForeground(dpy, gc, 1);
-
- char2b.byte1 = (c >> 8) & 0xff;
- char2b.byte2 = (c & 0xff);
-
- XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1);
-
- image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap);
- if (image) {
- /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */
- for (y = 0; y < height; y++)
- for (x = 0; x < 8 * width; x++)
- if (XGetPixel(image, x, y))
- bitmap[width * (height - y - 1) + x / 8] |=
- (1 << (7 - (x % 8)));
- XDestroyImage(image);
- }
-
- XFreePixmap(dpy, pixmap);
-}
-
-/*
- * determine if a given glyph is valid and return the
- * corresponding XCharStruct.
- */
-static XCharStruct *
-isvalid(XFontStruct * fs, unsigned int which)
-{
- unsigned int rows, pages;
- unsigned int byte1 = 0, byte2 = 0;
- int i, valid = 1;
-
- rows = fs->max_byte1 - fs->min_byte1 + 1;
- pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
-
- if (rows == 1) {
- /* "linear" fonts */
- if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which))
- valid = 0;
- }
- else {
- /* "matrix" fonts */
- byte2 = which & 0xff;
- byte1 = which >> 8;
- if ((fs->min_char_or_byte2 > byte2) ||
- (fs->max_char_or_byte2 < byte2) ||
- (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1))
- valid = 0;
- }
-
- if (valid) {
- if (fs->per_char) {
- if (rows == 1) {
- /* "linear" fonts */
- return (fs->per_char + (which - fs->min_char_or_byte2));
- }
- else {
- /* "matrix" fonts */
- i = ((byte1 - fs->min_byte1) * pages) +
- (byte2 - fs->min_char_or_byte2);
- return (fs->per_char + i);
- }
- }
- else {
- return (&fs->min_bounds);
- }
- }
- return (NULL);
-}
-
-
-GLAPI void APIENTRY glXUseXFont( Font font, int first, int count, int listbase )
-{
- Display *dpy;
- Window win;
- Pixmap pixmap;
- GC gc;
- XGCValues values;
- unsigned long valuemask;
- XFontStruct *fs;
- GLint swapbytes, lsbfirst, rowlength;
- GLint skiprows, skippixels, alignment;
- unsigned int max_width, max_height, max_bm_width, max_bm_height;
- GLubyte *bm;
- int i;
-
- dpy = glXGetCurrentDisplay();
- if (!dpy)
- return; /* I guess glXMakeCurrent wasn't called */
- win = RootWindow(dpy, DefaultScreen(dpy));
-
- fs = XQueryFont(dpy, font);
- if (!fs) {
- /*_mesa_error(NULL, GL_INVALID_VALUE,
- "Couldn't get font structure information");*/
- return;
- }
-
- /* Allocate a bitmap that can fit all characters. */
- max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing;
- max_height = fs->max_bounds.ascent + fs->max_bounds.descent;
- max_bm_width = (max_width + 7) / 8;
- max_bm_height = max_height;
-
- bm = (GLubyte *) malloc((max_bm_width * max_bm_height) * sizeof(GLubyte));
- if (!bm) {
- XFreeFontInfo(NULL, fs, 1);
- /*_mesa_error(NULL, GL_OUT_OF_MEMORY,
- "Couldn't allocate bitmap in glXUseXFont()");*/
- return;
- }
-
-#if 0
- /* get the page info */
- pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
- firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2;
- lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2;
- rows = fs->max_byte1 - fs->min_byte1 + 1;
- unsigned int first_char, last_char, pages, rows;
-#endif
-
- /* Save the current packing mode for bitmaps. */
- glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
- glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
- glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
- glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
- glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
- glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
-
- /* Enforce a standard packing mode which is compatible with
- fill_bitmap() from above. This is actually the default mode,
- except for the (non)alignment. */
- glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
- glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
- glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- pixmap = XCreatePixmap(dpy, win, 10, 10, 1);
- values.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- values.background = WhitePixel(dpy, DefaultScreen(dpy));
- values.font = fs->fid;
- valuemask = GCForeground | GCBackground | GCFont;
- gc = XCreateGC(dpy, pixmap, valuemask, &values);
- XFreePixmap(dpy, pixmap);
-
-#ifdef DEBUG
- if (debug_xfonts)
- dump_font_struct(fs);
-#endif
-
- for (i = 0; i < count; i++) {
- unsigned int width, height, bm_width, bm_height;
- GLfloat x0, y0, dx, dy;
- XCharStruct *ch;
- int x, y;
- unsigned int c = first + i;
- int list = listbase + i;
- int valid;
-
- /* check on index validity and get the bounds */
- ch = isvalid(fs, c);
- if (!ch) {
- ch = &fs->max_bounds;
- valid = 0;
- }
- else {
- valid = 1;
- }
-
-#ifdef DEBUG
- if (debug_xfonts) {
- char s[7];
- sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
- dump_char_struct(ch, s);
- }
-#endif
-
- /* glBitmap()' parameters:
- straight from the glXUseXFont(3) manpage. */
- width = ch->rbearing - ch->lbearing;
- height = ch->ascent + ch->descent;
- x0 = -ch->lbearing;
- y0 = ch->descent - 0; /* XXX used to subtract 1 here */
- /* but that caused a conformace failure */
- dx = ch->width;
- dy = 0;
-
- /* X11's starting point. */
- x = -ch->lbearing;
- y = ch->ascent;
-
- /* Round the width to a multiple of eight. We will use this also
- for the pixmap for capturing the X11 font. This is slightly
- inefficient, but it makes the OpenGL part real easy. */
- bm_width = (width + 7) / 8;
- bm_height = height;
-
- glNewList(list, GL_COMPILE);
- if (valid && (bm_width > 0) && (bm_height > 0)) {
-
- memset(bm, '\0', bm_width * bm_height);
- fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
-
- glBitmap(width, height, x0, y0, dx, dy, bm);
-#ifdef DEBUG
- if (debug_xfonts) {
- printf("width/height = %u/%u\n", width, height);
- printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
- dump_bitmap(bm_width, bm_height, bm);
- }
-#endif
- }
- else {
- glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
- }
- glEndList();
- }
-
- free(bm);
- XFreeFontInfo(NULL, fs, 1);
- XFreeGC(dpy, gc);
-
- /* Restore saved packing modes. */
- glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
- glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
- glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
- glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
- glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
-}
+++ /dev/null
-/*
- * Host-side implementation of GL/GLX API
- *
- * Copyright (c) 2006,2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-void init_process_tab(void);
-
-#ifdef _WIN32
-
-#include <windows.h>
-
-//#define _MK_DBG_
-
-#define IsViewable 2
-#define False 0
-#define True 1
-
-
-#define GL_GLEXT_PROTOTYPES
-#include "opengl_func.h"
-#include "opengl_utils.h"
-#include "mesa_glx.h"
-#include "mesa_glxext.h"
-#include "mesa_glu.h"
-#include "mesa_mipmap.c"
-
-typedef struct
-{
- HGLRC context;
- void *backBuffer;
- int width;
- int height;
- int colorFormat;
- unsigned int colorBits;
-} PbufferInfo;
-
-typedef struct
-{
- void* key;
- void* value;
- void* hWnd; /* Surface?? ˤ?? Window Handle*/
- void* cDC; /*Context?? ˤ?? Dummy Window Handle*/
-} Assoc;
-
-#define MAX_HANDLED_PROCESS 100
-#define MAX_ASSOC_SIZE 100
-#define MAX_FBCONFIG 10
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
- int map_state;
-} WindowPosStruct;
-
-typedef struct
-{
- GLbitfield mask;
- int activeTextureIndex;
-} ClientState;
-
-#define MAX_CLIENT_STATE_STACK_SIZE 16
-#define NB_MAX_TEXTURES 16
-#define MY_GL_MAX_VERTEX_ATTRIBS_ARB 16
-#define MY_GL_MAX_VERTEX_ATTRIBS_NV 16
-#define MY_GL_MAX_VARIANT_POINTER_EXT 16
-
-typedef struct
-{
- int ref;
- int fake_ctxt;
- int fake_shareList;
- HGLRC context;
- HDC drawable;
-
- void* vertexPointer;
- void* normalPointer;
- void* colorPointer;
- void* secondaryColorPointer;
- void* indexPointer;
- void* texCoordPointer[NB_MAX_TEXTURES];
- void* edgeFlagPointer;
- void* vertexAttribPointer[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
- void* vertexAttribPointerNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
- void* weightPointer;
- void* matrixIndexPointer;
- void* fogCoordPointer;
- void* variantPointerEXT[MY_GL_MAX_VARIANT_POINTER_EXT];
- void* interleavedArrays;
- void* elementPointerATI;
-
- int vertexPointerSize;
- int normalPointerSize;
- int colorPointerSize;
- int secondaryColorPointerSize;
- int indexPointerSize;
- int texCoordPointerSize[NB_MAX_TEXTURES];
- int edgeFlagPointerSize;
- int vertexAttribPointerSize[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
- int vertexAttribPointerNVSize[MY_GL_MAX_VERTEX_ATTRIBS_NV];
- int weightPointerSize;
- int matrixIndexPointerSize;
- int fogCoordPointerSize;
- int variantPointerEXTSize[MY_GL_MAX_VARIANT_POINTER_EXT];
- int interleavedArraysSize;
- int elementPointerATISize;
-
- int selectBufferSize;
- void* selectBufferPtr;
- int feedbackBufferSize;
- void* feedbackBufferPtr;
-
- ClientState clientStateStack[MAX_CLIENT_STATE_STACK_SIZE];
- int clientStateSp;
- int activeTextureIndex;
-
- unsigned int ownTabTextures[32768];
- unsigned int* tabTextures;
- RangeAllocator ownTextureAllocator;
- RangeAllocator* textureAllocator;
-
- unsigned int ownTabBuffers[32768];
- unsigned int* tabBuffers;
- RangeAllocator ownBufferAllocator;
- RangeAllocator* bufferAllocator;
-
- unsigned int ownTabLists[32768];
- unsigned int* tabLists;
- RangeAllocator ownListAllocator;
- RangeAllocator* listAllocator;
-
-#ifdef SYSTEMATIC_ERROR_CHECK
- int last_error;
-#endif
-} GLState;
-
-typedef struct
-{
- PIXELFORMATDESCRIPTOR pfd;
- unsigned int visualID;
-} WGLFBConfig;
-
-typedef struct
-{
- int internal_num;
- int process_id;
- int instr_counter;
-
- int x, y, width, height;
- WindowPosStruct currentDrawablePos;
-
- int next_available_context_number;
- int next_available_pbuffer_number;
-
- int nbGLStates;
- GLState default_state;
- GLState** glstates;
- GLState* current_state;
-
- int nfbconfig;
- WGLFBConfig* fbconfigs[MAX_FBCONFIG];
- int fbconfigs_max[MAX_FBCONFIG];
- int nfbconfig_total;
-
- Assoc association_fakecontext_glxcontext[MAX_ASSOC_SIZE];
- Assoc association_fakepbuffer_pbuffer[MAX_ASSOC_SIZE];
- Assoc association_clientdrawable_serverdrawable[MAX_ASSOC_SIZE];
- Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
-} ProcessStruct;
-
-int last_process_id = 0;
-
-
-typedef struct
-{
- int attribListLength;
- int* attribList;
- unsigned int visualID;
- /*PIXELFORMATDESCRIPTOR* visInfo;*/
-} AssocAttribListVisual;
-
-#define ARG_TO_CHAR(x) (char)(x)
-#define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
-#define ARG_TO_SHORT(x) (short)(x)
-#define ARG_TO_UNSIGNED_SHORT(x) (unsigned short)(x)
-#define ARG_TO_INT(x) (int)(x)
-#define ARG_TO_UNSIGNED_INT(x) (unsigned int)(x)
-#define ARG_TO_FLOAT(x) (*(float*)&(x))
-#define ARG_TO_DOUBLE(x) (*(double*)(x))
-
-#define GET_EXT_PTR(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)wglGetProcAddress((const GLubyte*)#funcname); \
- assert (ptr_func_##funcname); \
-}
-
-#define GET_EXT_PTR_NO_FAIL(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)wglGetProcAddress((const GLubyte*)#funcname); \
-}
-
-
-#include "server_stub.c"
-
-static void* get_glu_ptr(const char* name)
-{
- static void* handle = (void*)-1;
- if (handle == (void*)-1)
- {
-#ifndef WIN32
- handle = dlopen("libGLU.so" ,RTLD_LAZY);
- if (!handle) {
- fprintf (stderr, "can't load libGLU.so : %s\n", dlerror());
- }
-#else
- handle = (void *)LoadLibrary("glu32.dll");
- if (!handle) {
- fprintf (stderr, "can't load glu32.dll\n");
- }
-#endif
- }
- if (handle)
- {
-#ifndef WIN32
- return dlsym(handle, name);
-#else
- return GetProcAddress(handle, name);
-#endif
- }
- return NULL;
-}
-
-
-
-#define GET_GLU_PTR(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)get_glu_ptr(#funcname); \
-}
-
-
-static void _get_window_pos(HWND hWnd, WindowPosStruct* pos)
-{
- RECT rcWindow;
-
- GetWindowRect(hWnd, &rcWindow);
-
- pos->x = rcWindow.left;
- pos->y = rcWindow.top;
-
- pos->width = rcWindow.right - rcWindow.left;
- pos->height = rcWindow.bottom - rcWindow.top;
-
- pos->map_state = IsViewable;
-}
-
-
-int display_function_call = 0;
-
-static void init_gl_state(GLState* state)
-{
- state->textureAllocator = &state->ownTextureAllocator;
- state->tabTextures = state->ownTabTextures;
- state->bufferAllocator = &state->ownBufferAllocator;
- state->tabBuffers = state->ownTabBuffers;
- state->listAllocator = &state->ownListAllocator;
- state->tabLists = state->ownTabLists;
-}
-
-
-static void destroy_gl_state(GLState* state)
-{
- int i;
- if (state->vertexPointer) free(state->vertexPointer);
- if (state->normalPointer) free(state->normalPointer);
- if (state->indexPointer) free(state->indexPointer);
- if (state->colorPointer) free(state->colorPointer);
- if (state->secondaryColorPointer) free(state->secondaryColorPointer);
- for(i=0;i<NB_MAX_TEXTURES;i++)
- {
- if (state->texCoordPointer[i]) free(state->texCoordPointer[i]);
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
- {
- if (state->vertexAttribPointer[i]) free(state->vertexAttribPointer[i]);
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_NV;i++)
- {
- if (state->vertexAttribPointerNV[i]) free(state->vertexAttribPointerNV[i]);
- }
- if (state->weightPointer) free(state->weightPointer);
- if (state->matrixIndexPointer) free(state->matrixIndexPointer);
- if (state->fogCoordPointer) free(state->fogCoordPointer);
- for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
- {
- if (state->variantPointerEXT[i]) free(state->variantPointerEXT[i]);
- }
- if (state->interleavedArrays) free(state->interleavedArrays);
- if (state->elementPointerATI) free(state->elementPointerATI);
-}
-
-static void _create_context(ProcessStruct* process, HGLRC ctxt, int fake_ctxt, HGLRC shareList, int fake_shareList)
-{
- process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
- process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
- memset(process->glstates[process->nbGLStates], 0, sizeof(GLState));
- process->glstates[process->nbGLStates]->ref = 1;
- process->glstates[process->nbGLStates]->context = ctxt;
- process->glstates[process->nbGLStates]->fake_ctxt = fake_ctxt;
- process->glstates[process->nbGLStates]->fake_shareList = fake_shareList;
- init_gl_state(process->glstates[process->nbGLStates]);
- if (shareList && fake_shareList)
- {
- int i;
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_shareList)
- {
- process->glstates[i]->ref ++;
- process->glstates[process->nbGLStates]->textureAllocator =
- process->glstates[i]->textureAllocator;
- process->glstates[process->nbGLStates]->tabTextures =
- process->glstates[i]->tabTextures;
- process->glstates[process->nbGLStates]->bufferAllocator =
- process->glstates[i]->bufferAllocator;
- process->glstates[process->nbGLStates]->tabBuffers =
- process->glstates[i]->tabBuffers;
- process->glstates[process->nbGLStates]->listAllocator =
- process->glstates[i]->listAllocator;
- process->glstates[process->nbGLStates]->tabLists =
- process->glstates[i]->tabLists;
- break;
- }
- }
- }
- process->nbGLStates++;
-}
-
-WGLFBConfig* get_pfDescriptor(ProcessStruct* process, int client_pfd)
-{
- int i;
- int nbtotal = 0;
- for(i=0;i<process->nfbconfig;i++)
- {
- assert(client_pfd >= 1 + nbtotal);
- if (client_pfd <= nbtotal + process->fbconfigs_max[i])
- {
- return (WGLFBConfig*) (&process->fbconfigs[i][client_pfd-1 - nbtotal]);
- }
- nbtotal += process->fbconfigs_max[i];
- }
- return 0;
-}
-
-int get_pfdAttrib(PIXELFORMATDESCRIPTOR *ppfd, int attrib, int *value)
-{
- int answer = 0;
-
- switch(attrib)
- {
- case GLX_FBCONFIG_ID:
- answer = (int) ppfd;
- break;
-
- case GLX_AUX_BUFFERS:
- answer = ppfd->cAuxBuffers;
- break;
-
- case GLX_STEREO:
- answer = (int)False;
- break;
-
- case GLX_ACCUM_RED_SIZE:
- answer = ppfd->cAccumRedBits;
- break;
-
- case GLX_ACCUM_GREEN_SIZE:
- answer = ppfd->cAccumGreenBits;
- break;
-
- case GLX_ACCUM_BLUE_SIZE:
- answer = ppfd->cAccumBlueBits;
- break;
-
- case GLX_ACCUM_ALPHA_SIZE:
- answer = ppfd->cAccumAlphaBits;
- break;
-
- case GLX_RENDER_TYPE:
- answer = (ppfd->iPixelType == PFD_TYPE_RGBA) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
- break;
-
- case GLX_RGBA:
- case GLX_RGBA_TYPE:
- answer = (ppfd->iPixelType == PFD_TYPE_RGBA) ? (int)True : (int)False;
- break;
-
- case GLX_COLOR_INDEX_TYPE:
- answer = (ppfd->iPixelType == PFD_TYPE_COLORINDEX) ? (int)True : (int)False;
- break;
-
- case GLX_USE_GL:
- answer = ((ppfd->dwFlags & PFD_SUPPORT_OPENGL) != 0) ? (int)True : (int)False;
- break;
-
- case GLX_DOUBLEBUFFER:
- answer = ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != 0) ? (int)True : (int)False;
- break;
-
- case GLX_DRAWABLE_TYPE:
- answer = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
- break;
-
-#ifdef GLX_CONFIG_CAVEAT
- case GLX_CONFIG_CAVEAT:
- answer = GLX_NONE;
- break;
-
- case GLX_SLOW_CONFIG:
- case GLX_NON_CONFORMANT_CONFIG:
- answer = (int)False;
- break;
-#endif /*GLX_CONFIG_CAVEAT not support*/
-
- case GLX_X_RENDERABLE:
- answer = 1;
- break;
-
- case GLX_BUFFER_SIZE:
- answer = ppfd->cColorBits;
- break;
-
- case GLX_RED_SIZE:
- answer = ppfd->cRedBits;
- break;
-
- case GLX_GREEN_SIZE:
- answer = ppfd->cGreenBits;
- break;
-
- case GLX_BLUE_SIZE:
- answer = ppfd->cBlueBits;
- break;
-
- case GLX_ALPHA_SIZE:
- answer = ppfd->cAlphaBits;
- break;
-
- case GLX_DEPTH_SIZE:
- answer = ppfd->cDepthBits;
- break;
-
- case GLX_STENCIL_SIZE:
- answer = ppfd->cStencilBits;
- break;
-
- case GLX_LEVEL:
- answer = 0;
- break;
-
- case GLX_MAX_PBUFFER_WIDTH:
- answer = 480;
- break;
-
- case GLX_MAX_PBUFFER_HEIGHT:
- answer = 800;
- break;
-
- case GLX_MAX_PBUFFER_PIXELS:
- answer = 384000;
- break;
-
- case GLX_VISUAL_ID:
- answer = 0;
- break;
-
-#ifdef GLX_X_VISUAL_TYPE
- case GLX_X_VISUAL_TYPE:
- answer = GLX_NONE;
- break;
-
- case GLX_TRUE_COLOR:
- case GLX_DIRECT_COLOR:
- case GLX_PSEUDO_COLOR:
- case GLX_STATIC_COLOR:
- case GLX_GRAY_SCALE:
- case GLX_STATIC_GRAY:
- answer = False;
- break;
-#endif /*GLX_X_VISUAL_TYPE not support*/
-
- case GLX_SAMPLE_BUFFERS:
- case GLX_SAMPLES:
- answer = 0;
- break;
-
-#ifdef GLX_TRANSPARENT_TYPE
- case GLX_TRANSPARENT_TYPE:
- answer = GLX_NONE;
- break;
-
- case GLX_TRANSPARENT_INDEX_VALUE:
- case GLX_TRANSPARENT_RED_VALUE:
- case GLX_TRANSPARENT_GREEN_VALUE:
- case GLX_TRANSPARENT_ALPHA_VALUE:
- case GLX_TRANSPARENT_BLUE_VALUE:
- answer = GLX_DONT_CARE;
- break;
-
- case GLX_TRANSPARENT_RGB:
- case GLX_TRANSPARENT_INDEX:
- answer = (int)False;
- break;
-#endif /*GLX_X_VISUAL_TYPE not support*/
-
- case GLX_FLOAT_COMPONENTS_NV:
- case GLX_PRESERVED_CONTENTS:
- answer = (int)False;
- break;
-
- default:
- answer = GLX_BAD_ATTRIBUTE;
-
- }
-
- *value = answer;
-
- return 0;
-}
-
-void* get_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- return process->association_fakecontext_glxcontext[i].value;
- }
- return NULL;
-}
-
-void set_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext, void* glxcontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakecontext_glxcontext[i].key = fakecontext;
- process->association_fakecontext_glxcontext[i].value = glxcontext;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void get_association_fakecontext_glxwnd(ProcessStruct* process, void* fakecontext, HWND rWnd, HDC rDC)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- rWnd = (HWND)process->association_fakecontext_glxcontext[i].hWnd;
- rDC = (HDC)process->association_fakecontext_glxcontext[i].cDC;
- return;
- }
- }
-
- rWnd = NULL;
- rDC = NULL;
-}
-
-void set_association_fakecontext_glxwnd(ProcessStruct* process, void* fakecontext, void* glxwnd, void *glxhdc)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakecontext_glxcontext[i].key = fakecontext;
- process->association_fakecontext_glxcontext[i].hWnd = glxwnd;
- process->association_fakecontext_glxcontext[i].cDC = glxhdc;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void unset_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- memmove(&process->association_fakecontext_glxcontext[i],
- &process->association_fakecontext_glxcontext[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-unsigned int get_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
- {
- if (process->association_fakecontext_visual[i].key == fakecontext)
- return (unsigned int)process->association_fakecontext_visual[i].value;
- }
- return 0;
-}
-
-void set_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext, unsigned int visualid)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
- {
- if (process->association_fakecontext_visual[i].key == fakecontext)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakecontext_visual[i].key = fakecontext;
- process->association_fakecontext_visual[i].value = (void *)(long)visualid;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void unset_association_fakecontext_visualid(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
- {
- if (process->association_fakecontext_visual[i].key == fakecontext)
- {
- memmove(&process->association_fakecontext_visual[i],
- &process->association_fakecontext_visual[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-HWND get_association_clientdrawable_serverwnd(ProcessStruct* process, HDC clientdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL; i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
- return (HWND)process->association_clientdrawable_serverdrawable[i].hWnd;
- }
- return (HWND)0;
-}
-
-HDC get_association_clientdrawable_serverdrawable(ProcessStruct* process, HDC clientdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
- return (HDC)process->association_clientdrawable_serverdrawable[i].value;
- }
- return (HDC)0;
-}
-
-void set_association_clientdrawable_serverwnd(ProcessStruct* process, void* clientdrawable, void* serverwnd)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
- process->association_clientdrawable_serverdrawable[i].hWnd = serverwnd;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void set_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable, void* serverdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
- process->association_clientdrawable_serverdrawable[i].value = serverdrawable;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void unset_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
- {
- memmove(&process->association_clientdrawable_serverdrawable[i],
- &process->association_clientdrawable_serverdrawable[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-HWND get_association_fakepbuffer_pbufferwnd(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL; i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- return (HWND)process->association_fakepbuffer_pbuffer[i].hWnd;
- }
- return (HWND)0;
-}
-
-void set_association_fakepbuffer_pbufferwnd(ProcessStruct* process, void* fakepbuffer, void* pbufferwnd)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
- process->association_fakepbuffer_pbuffer[i].hWnd = pbufferwnd;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-PbufferInfo *get_association_fakepbuffer_pbinfo(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL; i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- return (PbufferInfo *)process->association_fakepbuffer_pbuffer[i].cDC;
- }
- return (PbufferInfo *)0;
-}
-
-void set_association_fakepbuffer_pbinfo(ProcessStruct* process, void* fakepbuffer, void* pbuffer_info)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
- process->association_fakepbuffer_pbuffer[i].cDC= pbuffer_info;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-HDC get_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- return (HDC)process->association_fakepbuffer_pbuffer[i].value;
- }
- return (HDC)NULL;
-}
-
-void set_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer, void* pbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
- process->association_fakepbuffer_pbuffer[i].value = pbuffer;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-void unset_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- memmove(&process->association_fakepbuffer_pbuffer[i],
- &process->association_fakepbuffer_pbuffer[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-static int get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid, PIXELFORMATDESCRIPTOR* rpfd)
-{
- int i;
- if( 0 < visualid )
- {
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
- for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
- {
- if ( tabAssocAttribListVisual[i].visualID == visualid)
- {
- DescribePixelFormat((HDC)pConn->Display, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), rpfd);
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-static int get_default_visual(Display dpy, PIXELFORMATDESCRIPTOR* rpfd)
-{
- HDC hdc;
- hdc = (HDC)dpy;
- int n;
-
- if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
- {
- int i;
- for (i = 0; i < n; i++)
- {
- DescribePixelFormat(hdc, i, sizeof( PIXELFORMATDESCRIPTOR), rpfd);
- if (!(rpfd->dwFlags & PFD_SUPPORT_OPENGL)) continue;
- if (!(rpfd->dwFlags & PFD_DRAW_TO_WINDOW)) continue;
- if (!(rpfd->dwFlags & PFD_DOUBLEBUFFER)) continue;
- if (rpfd->iPixelType != PFD_TYPE_RGBA) continue;
- if (rpfd->cRedBits < 8) continue;
- if (rpfd->cGreenBits < 8) continue;
- if (rpfd->cBlueBits < 8) continue;
- if (rpfd->cAlphaBits < 8) continue;
- if (rpfd->cDepthBits < 16) continue;
- if (rpfd->cStencilBits < 8) continue;
-
- break;
- }
-
- if( i < n ) return i + 1;
- }
-
- return 0;
-}
-
-/* Surface?? 위?? Window ????*/
-static HDC create_swindow(OGLS_Conn *pConn, HDC clientdrawable, ProcessStruct* process, int x, int y, int width, int height)
-{
- RECT rect;
- HWND hWnd;
- HDC hDC;
- WNDCLASS wc;
- LPSTR lpszClassWindowSurface ="WindowSurface";
-
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = (WNDPROC)DefWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = lpszClassWindowSurface;
-
- RegisterClass(&wc);
-
- rect.left = x;
- rect.top = y;
- rect.right = width;
- rect.bottom = height;
- AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
-
- hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
- (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
- rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
- NULL, (HMENU)NULL, NULL, NULL);
-
- hDC = GetDC(hWnd);
- if(hDC)
- {
- pConn->active_win = hDC;
- ShowWindow(hWnd,SW_HIDE);
- set_association_clientdrawable_serverwnd(process, (void *) clientdrawable, (void *) hWnd);
- }
-
- return hDC;
-}
-
-/* pbuffer?? 위?? Window ????*/
-static HDC create_pbwindow(void *fakepbuffer, ProcessStruct* process, int x, int y, int width, int height)
-{
- RECT rect;
- HWND hWnd;
- HDC hDC;
- WNDCLASS wc;
- LPSTR lpszClassWindowSurface ="PBuffer";
-
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = (WNDPROC)DefWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = lpszClassWindowSurface;
-
- RegisterClass(&wc);
-
- rect.left = x;
- rect.top = y;
- rect.right = width;
- rect.bottom = height;
- AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
-
- hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
- (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
- rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
- NULL, (HMENU)NULL, NULL, NULL);
-
- hDC = GetDC(hWnd);
- if(hDC)
- {
- ShowWindow(hWnd,SW_HIDE);
- set_association_fakepbuffer_pbufferwnd(process, fakepbuffer, (void *) hWnd);
- }
-
- return hDC;
-}
-
-/* context?? ˤ?? Dummy Window ????*/
-static HDC create_cwindow(int fake_ctx, ProcessStruct* process, int x, int y, int width, int height)
-{
- RECT rect;
- HWND hWnd;
- HDC hDC;
- WNDCLASS wc;
- LPSTR lpszClassWindowSurface ="Context";
-
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = (WNDPROC)DefWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = lpszClassWindowSurface;
-
- RegisterClass(&wc);
-
- rect.left = x;
- rect.top = y;
- rect.right = width;
- rect.bottom = height;
- AdjustWindowRect(&rect, (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU), False);
-
- hWnd = CreateWindow(lpszClassWindowSurface, lpszClassWindowSurface,
- (WS_OVERLAPPED |WS_POPUP |WS_SYSMENU ),
- rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
- NULL, (HMENU)NULL, NULL, NULL);
-
- hDC = GetDC(hWnd);
- if(hDC)
- {
- ShowWindow(hWnd,SW_HIDE);
- set_association_fakecontext_glxwnd(process, (void *) (long)fake_ctx, (void *)hWnd, (void *)hDC);
- }
-
- return hDC;
-}
-
-static void destroy_glwindow(OGLS_Conn *pConn, HWND hWnd, HDC hDC )
-{
- ReleaseDC( hWnd, hDC );
- DestroyWindow(hWnd);
-
- /*PostQuitMessage(0);*/
-
- if( pConn->active_win == hDC)
- pConn->active_win = 0;
-}
-
-static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
-{
- unsigned int server_texture = 0;
- if (client_texture < 32768)
- {
- server_texture = process->current_state->tabTextures[client_texture];
- }
- else
- {
- fprintf(stderr, "invalid texture name %d\n", client_texture);
- }
- return server_texture;
-}
-
-static int get_server_list(ProcessStruct* process, unsigned int client_list)
-{
- unsigned int server_list = 0;
- if (client_list < 32768)
- {
- server_list = process->current_state->tabLists[client_list];
- }
- else
- {
- fprintf(stderr, "invalid list name %d\n", client_list);
- }
- return server_list;
-}
-
-static int get_server_buffer(ProcessStruct* process, unsigned int client_buffer)
-{
- unsigned int server_buffer = 0;
- if (client_buffer < 32768)
- {
- server_buffer = process->current_state->tabBuffers[client_buffer];
- }
- else
- {
- fprintf(stderr, "invalid buffer name %d\n", client_buffer);
- }
- return server_buffer;
-}
-
-
-static void do_glClientActiveTextureARB(int texture)
-{
- GET_EXT_PTR_NO_FAIL(void, glClientActiveTextureARB, (int));
- if (ptr_func_glClientActiveTextureARB)
- {
- ptr_func_glClientActiveTextureARB(texture);
- }
-}
-
-
-/*
- * Translate the nth element of list from type to GLuint.
- */
- static GLuint
-translate_id(GLsizei n, GLenum type, const GLvoid * list)
-{
- GLbyte *bptr;
- GLubyte *ubptr;
- GLshort *sptr;
- GLushort *usptr;
- GLint *iptr;
- GLuint *uiptr;
- GLfloat *fptr;
-
- switch (type) {
- case GL_BYTE:
- bptr = (GLbyte *) list;
- return (GLuint) *(bptr + n);
- case GL_UNSIGNED_BYTE:
- ubptr = (GLubyte *) list;
- return (GLuint) *(ubptr + n);
- case GL_SHORT:
- sptr = (GLshort *) list;
- return (GLuint) *(sptr + n);
- case GL_UNSIGNED_SHORT:
- usptr = (GLushort *) list;
- return (GLuint) *(usptr + n);
- case GL_INT:
- iptr = (GLint *) list;
- return (GLuint) *(iptr + n);
- case GL_UNSIGNED_INT:
- uiptr = (GLuint *) list;
- return (GLuint) *(uiptr + n);
- case GL_FLOAT:
- fptr = (GLfloat *) list;
- return (GLuint) *(fptr + n);
- case GL_2_BYTES:
- ubptr = ((GLubyte *) list) + 2 * n;
- return (GLuint) *ubptr * 256 + (GLuint) * (ubptr + 1);
- case GL_3_BYTES:
- ubptr = ((GLubyte *) list) + 3 * n;
- return (GLuint) * ubptr * 65536
- + (GLuint) *(ubptr + 1) * 256 + (GLuint) * (ubptr + 2);
- case GL_4_BYTES:
- ubptr = ((GLubyte *) list) + 4 * n;
- return (GLuint) *ubptr * 16777216
- + (GLuint) *(ubptr + 1) * 65536
- + (GLuint) *(ubptr + 2) * 256 + (GLuint) * (ubptr + 3);
- default:
- return 0;
- }
-}
-
-
-static const char *opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
-{
- char *start;
- char *ret;
- char *p;
- int retlen;
- static const char *delim = " \t\n\r/";
-
- if (prevbuf)
- free(prevbuf);
-
- if (s) {
- *saveptr = s;
- } else {
- if (!(*saveptr) || !(*n))
- return NULL;
- s = *saveptr;
- }
-
- for (; *n && strchr(delim, *s); s++, (*n)--) {
- if (*s == '/' && *n > 1) {
- if (s[1] == '/') {
- do {
- s++, (*n)--;
- } while (*n > 1 && s[1] != '\n' && s[1] != '\r');
- } else if (s[1] == '*') {
- do {
- s++, (*n)--;
- } while (*n > 2 && (s[1] != '*' || s[2] != '/'));
- s++, (*n)--;
- }
- }
- }
-
- start = s;
- for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
- if (*n > 0)
- s++, (*n)--;
-
- *saveptr = s;
-
- retlen = s - start;
- ret = malloc(retlen + 1);
- p = ret;
-
- while (retlen > 0) {
- if (*start == '/' && retlen > 1) {
- if (start[1] == '/') {
- do {
- start++, retlen--;
- } while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
- start++, retlen--;
- continue;
- } else if (start[1] == '*') {
- do {
- start++, retlen--;
- } while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
- start += 3, retlen -= 3;
- continue;
- }
- }
- *(p++) = *(start++), retlen--;
- }
-
- *p = 0;
- return ret;
-}
-
-static char *do_eglShaderPatch(const char *source, int length, int *patched_len)
-{
- char *saveptr = NULL;
- char *sp;
- char *p = NULL;
-
- if (!length)
- length = strlen(source);
-
- *patched_len = 0;
- int patched_size = length;
- char *patched = malloc(patched_size + 1);
-
- if (!patched)
- return NULL;
-
- p = opengl_strtok(source, &length, &saveptr, NULL);
- for (; p; p = opengl_strtok(0, &length, &saveptr, p)) {
- if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) {
- continue;
- } else if (!strncmp(p, "precision", 9)) {
- while ((p = opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
- } else {
- if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) {
- p = "(gl_MaxVertexUniformComponents / 4)";
- } else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) {
- p = "(gl_MaxFragmentUniformComponents / 4)";
- } else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) {
- p = "(gl_MaxVaryingFloats / 4)";
- }
-
- int new_len = strlen(p);
- if (*patched_len + new_len > patched_size) {
- patched_size *= 2;
- patched = realloc(patched, patched_size + 1);
-
- if (!patched)
- return NULL;
- }
-
- memcpy(patched + *patched_len, p, new_len);
- *patched_len += new_len;
- }
- }
-
- patched[*patched_len] = 0;
- /* check that we don't leave dummy preprocessor lines */
- for (sp = patched; *sp;) {
- for (; *sp == ' ' || *sp == '\t'; sp++);
- if (!strncmp(sp, "#define", 7)) {
- for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
- if (*p == '\n' || *p == '\r' || *p == '/') {
- memset(sp, 0x20, 7);
- }
- }
- for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
- for (; *sp == '\n' || *sp == '\r'; sp++);
- }
- return patched;
-}
-
-static int
-shadersrc_gles_to_gl(GLsizei count, const char** string, char **s, const GLint* length, GLint *l)
-{
- int i;
-
- for(i = 0; i < count; ++i) {
- GLint len;
- if(length) {
- len = length[i];
- if (len < 0)
- len = string[i] ? strlen(string[i]) : 0;
- } else
- len = string[i] ? strlen(string[i]) : 0;
-
- if(string[i]) {
- s[i] = do_eglShaderPatch(string[i], len, &l[i]);
- if(!s[i]) {
- while(i)
- free(s[--i]);
-
- free(l);
- free(s);
- return -1;
- }
- } else {
- s[i] = NULL;
- l[i] = 0;
- }
- }
-
- return 0;
-}
-
-
-int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
-{
- char ret_char = 0;
- int ret_int = 0;
- const char* ret_str = NULL;
- int iProcess;
- ProcessStruct* process = NULL;
- ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
-
- for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
- {
- ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
- if (processTab[iProcess].process_id == pid)
- {
- process = &processTab[iProcess];
- break;
- }
- else if (processTab[iProcess].process_id == 0)
- {
- process = &processTab[iProcess];
- memset(process, 0, sizeof(ProcessStruct));
- process->process_id = pid;
- process->internal_num = pConn->last_assigned_internal_num++;
- init_gl_state(&process->default_state);
- process->current_state = &process->default_state;
- break;
- }
- }
- if (process == NULL)
- {
- fprintf(stderr, "Too many processes !\n");
- return 0;
- }
-
- if (process->internal_num != pConn->last_active_internal_num)
- {
- wglMakeCurrent(process->current_state->drawable, process->current_state->context);
- pConn->last_active_internal_num = process->internal_num;
- }
-
- process->instr_counter++;
- if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
-
-#if defined( _MK_DBG_ )
- //printf(" %s Function(%d) \n", tab_opengl_calls_name[func_number], func_number);
-#endif
-
- switch (func_number)
- {
- case _init_func:
- {
- *(int*)args[1] = 1;
- break;
- }
-
- case _synchronize_func:
- {
- ret_int = 1;
- break;
- }
-
- case _exit_process_func:
- {
- int i;
- HWND hWnd;
- HDC hDC;
- HGLRC hRC;
- PbufferInfo *pb_info;
-
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- hRC = process->association_fakecontext_glxcontext[i].value;
- hWnd = (HWND) process->association_fakecontext_glxcontext[i].hWnd;
- hDC = (HDC) process->association_fakecontext_glxcontext[i].cDC;
-
- fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
- (long)process->association_fakecontext_glxcontext[i].key);
-
- wglDeleteContext(hRC);
- ReleaseDC(hWnd, hDC);
- DestroyWindow(hWnd);
- }
-
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- hWnd = (HWND) process->association_fakepbuffer_pbuffer[i].hWnd;
- hDC = (HDC)process->association_fakepbuffer_pbuffer[i].value;
- pb_info = (PbufferInfo *) process->association_fakepbuffer_pbuffer[i].cDC;
-
- fprintf(stderr, "Destroy pbuffer corresponding to client_drawable = %p\n",
- process->association_fakepbuffer_pbuffer[i].key);
-
- free(pb_info->backBuffer);
- free(pb_info);
-
- ReleaseDC(hWnd, hDC);
- DestroyWindow(hWnd);
- }
-
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL; i++)
- {
- hWnd = (HWND) process->association_clientdrawable_serverdrawable[i].hWnd;
- hDC = (HDC)process->association_clientdrawable_serverdrawable[i].value;
-
- fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
- process->association_clientdrawable_serverdrawable[i].key);
-
- ReleaseDC(hWnd, hDC);
- DestroyWindow(hWnd);
- }
-
- for(i=0;i<process->nfbconfig;i++)
- {
- free(process->fbconfigs[i]);
- }
-
- for(i=0;i<process->nbGLStates;i++)
- {
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- }
-
- destroy_gl_state(&process->default_state);
- free(process->glstates);
-
- pConn->active_win = 0;
-
- memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
-
- last_process_id = 0;
-
- break;
- }
-
- case _changeWindowState_func:
- {
- HDC client_drawable = (HDC) args[0];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- HWND hWnd = get_association_clientdrawable_serverwnd(process, client_drawable);
- if (hWnd && (args[1] == IsViewable))
- {
- ShowWindow(hWnd, SW_SHOW);
- }
-
- break;
- }
-
- case _moveResizeWindow_func:
- {
- int* params = (int*)args[1];
- HDC client_drawable = (HDC)args[0];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- HWND hWnd = get_association_clientdrawable_serverwnd(process, client_drawable);
- if (hWnd)
- {
- WindowPosStruct pos;
- _get_window_pos(hWnd, &pos);
- if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
- {
- int redim = !(params[2] == pos.width && params[3] == pos.height);
- pConn->active_win_x = params[0];
- pConn->active_win_y = params[1];
-
- //fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
- //fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
-
- if (redim)
- {
- MoveWindow(hWnd, params[0], params[1], params[2], params[3], False);
- _get_window_pos(hWnd, &pos);
- process->currentDrawablePos = pos;
-
- glViewport(0, 0, pos.width, pos.height);
- }
- }
- }
- break;
- }
-
- case _send_cursor_func:
- {
- fprintf(stderr, "_send_cursor_func not support \n");
- break;
- }
-
- case glXWaitGL_func:
- {
- ret_int = 0;
- break;
- }
-
- case glXWaitX_func:
- {
- ret_int = 0;
- break;
- }
-
- case glXGetFBConfigs_func:
- {
- ret_int = 0;
-
- fprintf(stderr, "glXGetFBConfigs not support \n");
-
- /*TODO*/
- /*TODO*/
- break;
- }
-
-
- case glXChooseFBConfig_func:
- case glXChooseFBConfigSGIX_func:
- {
- HDC hdc;
- WGLFBConfig *fbConfigs, *c;
- int n;
-
- if (process->nfbconfig == MAX_FBCONFIG)
- {
- *(int*)args[3] = 0;
- ret_int = 0;
- }
- else
- {
- hdc = (HDC) pConn->Display;
-
- if ((n = DescribePixelFormat(hdc, 0, 0, NULL)) > 0)
- {
- int i, j;
- PIXELFORMATDESCRIPTOR pfd;
- for (j = i = 0; i < n; i++)
- {
- DescribePixelFormat(hdc, i, sizeof pfd, &pfd);
- if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
- if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
- if (!(pfd.dwFlags & PFD_DOUBLEBUFFER)) continue;
- if (pfd.iPixelType != PFD_TYPE_RGBA) continue;
- j++;
- }
-
- c = fbConfigs = (WGLFBConfig *)malloc(sizeof(WGLFBConfig) * j);
-
- for (i = 0; i < n; i++) {
- DescribePixelFormat(hdc, i, sizeof pfd, &pfd);
- if (!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) continue;
- if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW)) continue;
- if (!(pfd.dwFlags & PFD_DOUBLEBUFFER)) continue;
- if (pfd.iPixelType != PFD_TYPE_RGBA) continue;
-
- c->visualID = i + 1;
- memcpy(&c->pfd, &pfd, sizeof(PIXELFORMATDESCRIPTOR));
-#if defined( _MK_DBG_ ) /* by 19.Nov.2009 */
- printf("Choose Config:0x%p VisualID : %d\n ",c, c->visualID);
-#endif
- c++;
- }
-
- *(int*)args[3] = j;
-
- if (fbConfigs)
- {
- process->fbconfigs[process->nfbconfig] = fbConfigs;
- process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
- process->nfbconfig++;
- ret_int = 1 + process->nfbconfig_total;
- process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
-
-#if defined( _MK_DBG_ )
- printf(" DescribePixelFormat Num : %d \n", j);
-#endif
- }
- else
- {
- ret_int = 0;
- *(int*)args[3] = 0;
- }
- }
- else
- {
- ret_int = 0;
- *(int*)args[3] = 0;
- printf(" DescribePixelFormat - NULL \n");
- }
-
- }
-
- break;
- }
-
- case glXGetFBConfigAttrib_func:
- case glXGetFBConfigAttribSGIX_func:
- {
- int client_pfd = args[1];
- WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
-
- ret_int = 0;
-
- if (fbConfig)
- ret_int = get_pfdAttrib(&fbConfig->pfd, args[2], (int*)args[3]);
-
- break;
- }
-
- case glXGetFBConfigAttrib_extended_func:
- {
- int client_pfd = args[1];
- int n = args[2];
- int i;
- int* attribs = (int*)args[3];
- int* values = (int*)args[4];
- int* res = (int*)args[5];
- WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
-
- for(i=0;i<n;i++)
- {
- if (fbConfig)
- {
- res[i] = get_pfdAttrib(&fbConfig->pfd, attribs[i], &values[i]);
- }
- else
- {
- res[i] = 0;
- }
- }
- break;
- }
-
- case glXGetVisualFromFBConfig_func:
- {
- int client_pfd = args[1];
- int i;
- unsigned int visualid;
- WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
-
- ret_int = 0;
-
- if (fbConfig)
- {
- visualid = fbConfig->visualID;
- ret_int = visualid;
-
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
- for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
-
- if( i >= pConn->nTabAssocAttribListVisual )
- {
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
-
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = visualid;
- pConn->nTabAssocAttribListVisual++;
- }
-
- if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
- }
-
- break;
- }
-
- case glXCreateNewContext_func:
- {
- int client_pfd = args[1];
- WGLFBConfig *fbConfig = get_pfDescriptor(process, client_pfd);
- ret_int = 0;
-
-#if defined( _MK_DBG_ )
- printf(" Config 0x%p - client_pfd %d \n", fbConfig, client_pfd);
-#endif
-
- if (fbConfig)
- {
- int fake_shareList = args[3];
- HGLRC ctxt;
- HGLRC shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
- int fake_ctxt = process->next_available_context_number + 1;
- HDC hdc = create_cwindow(fake_ctxt, process, 0, 0, 10, 10);
-
- if(SetPixelFormat(hdc, fbConfig->visualID - 1, NULL))
- {
- ctxt = wglCreateContext (hdc);
-#if defined( _MK_DBG_ )
- printf("HGLRC 0x%p = wglCreateNewContext(HDC 0x%p) visualID:%d fake_ctx:%d\n", ctxt, hdc, fbConfig->visualID, fake_ctxt);
-#endif
-
- if(ctxt)
- {
- process->next_available_context_number ++;
- set_association_fakecontext_visualid(process, (void*)(long)fake_ctxt, fbConfig->visualID);
- set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
- _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
- ret_int = fake_ctxt;
- }
- }
-
- if( 0 == ret_int )
- {
- int i;
-
- for(i=0; i < MAX_ASSOC_SIZE; i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == (void *) (long)fake_ctxt)
- {
- process->association_fakecontext_glxcontext[i].key = NULL;
- process->association_fakecontext_glxcontext[i].value = NULL;
- process->association_fakecontext_glxcontext[i].hWnd = NULL;
- process->association_fakecontext_glxcontext[i].cDC= NULL;
- break;
- }
- }
- printf("wglCreateContext Fail - HDC: 0x%p, visual ID: %d, Error : %d \n", hdc, fbConfig->visualID, (unsigned int)GetLastError());
- }
- }
-
- break;
- }
-
- case glXCreateContext_func:
- {
- int visualid = (int)args[1];
- int fake_shareList = (int)args[2];
- PIXELFORMATDESCRIPTOR pfd;
- HGLRC shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
- HGLRC ctxt = 0;
- int fake_ctxt = process->next_available_context_number + 1;
- HDC hdc = create_cwindow(fake_ctxt, process, 0, 0, 10, 10);
-
- ret_int = 0;
-
- if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
-
- if(get_visual_info_from_visual_id(pConn, visualid, &pfd))
- {
- SetPixelFormat(hdc, visualid - 1, &pfd);
- ctxt = wglCreateContext (hdc);
- }
- else
- {
- if((visualid = get_default_visual(pConn->Display, &pfd)))
- {
- SetPixelFormat(hdc, visualid - 1, &pfd);
- ctxt = wglCreateContext (hdc);
- }
- }
-
- printf("HGLRC 0x%p = wglCreateContext(HDC 0x%p) visualID:%d \n", ctxt, hdc, visualid);
-
- if (ctxt)
- {
- process->next_available_context_number ++;
- set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
- set_association_fakecontext_visualid(process, (void*)(long)fake_ctxt, visualid);
- _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
- ret_int = fake_ctxt;
- }
-
- if( 0 == ret_int )
- {
- int i;
-
- for(i=0; i < MAX_ASSOC_SIZE; i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == (void *) (long)fake_ctxt)
- {
- process->association_fakecontext_glxcontext[i].key = NULL;
- process->association_fakecontext_glxcontext[i].value = NULL;
- process->association_fakecontext_glxcontext[i].hWnd = NULL;
- process->association_fakecontext_glxcontext[i].cDC= NULL;
- break;
- }
- }
- printf("wglCreateContext Fail - HDC: 0x%p, visual ID: %d, Error : %d \n", hdc, visualid, (unsigned int)GetLastError());
- }
-
- break;
- }
-
- case glXMakeCurrent_func:
- {
- int i;
- HDC client_drawable = (HDC)args[1];
- HDC drawable = 0;
- PIXELFORMATDESCRIPTOR pfd;
- int fake_ctxt = args[2];
- unsigned int visualid = 0;
-
- if (display_function_call) fprintf(stderr, "client_drawable=%p fake_ctx=%d\n", (void*)client_drawable, fake_ctxt);
-
- if (client_drawable == 0 && fake_ctxt == 0)
- {
- ret_int = wglMakeCurrent(NULL, NULL);
- ret_int = 1;
- process->current_state = &process->default_state;
- }
- else if ((drawable = (HDC)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
- {
- HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void*)client_drawable);
-
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%d) (*)!\n", fake_ctxt);
- ret_int = 0;
- }
- else
- {
- if( pb_info )
- {
- pb_info->context = ctxt;
- }
-
- visualid = get_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
- if(visualid)
- {
- /*DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), &pfd);*/
-
- if(SetPixelFormat(drawable, visualid - 1, &pfd))
- {
- ret_int = wglMakeCurrent(drawable, ctxt);
-#if defined( _MK_DBG_ )
- printf("%d = wglMakeCurrentPBuffer(HDC 0x%p, HGLRC 0x%p) - visualID:%d client_drawable:0x%p\n", ret_int, drawable, ctxt, visualid, client_drawable);
-#endif
- }
- else
- {
- fprintf(stderr, "SetPixelFormat Error......\n");
- ret_int = 0;
- }
-
- }
- else
- {
- ret_int = 0;
- }
- }
- }
- else
- {
- HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%d)!\n", fake_ctxt);
- ret_int = 0;
- }
- else
- {
- visualid = get_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
-
- if( visualid == 0 )
- {
- visualid = get_default_visual(pConn->Display, &pfd);
- }
-
- drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable == 0)
- {
-
- drawable = create_swindow(pConn, client_drawable, process, 0, 0, 480, 800);
- set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
- }
-
- /*DescribePixelFormat((HDC)dpy, (visualid -1), sizeof( PIXELFORMATDESCRIPTOR), &pfd);*/
- if(SetPixelFormat(drawable, visualid - 1, &pfd))
- {
- ret_int = wglMakeCurrent(drawable, ctxt);
-#if defined( _MK_DBG_ )
- printf("%d = wglMakeCurrent(HDC 0x%p, HGLRC 0x%p) - visualID:%d client_drawable:0x%p\n", ret_int, drawable, ctxt, visualid, client_drawable);
-#endif
- }
- else
- {
- fprintf(stderr, "SetPixelFormat Error......\n");
- ret_int = 0;
- }
- }
- }
-
- if (ret_int)
- {
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_ctxt)
- {
- process->current_state = process->glstates[i]; /* HACK !!! REMOVE */
- process->current_state->drawable = drawable;
- break;
- }
- }
- }
- break;
- }
-
- case glXGetConfig_func:
- {
- int visualid = args[1];
- PIXELFORMATDESCRIPTOR pfd;
-
- if (visualid)
- {
- if( get_visual_info_from_visual_id(pConn, visualid, &pfd))
- {
- ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
- }
- else
- {
- if( get_default_visual(pConn->Display, &pfd))
- ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
- else
- ret_int = GLX_BAD_VISUAL;
- }
- }
- else
- {
- if( get_default_visual(pConn->Display, &pfd))
- ret_int = get_pfdAttrib(&pfd, args[2], (int*)args[3]);
- else
- ret_int = GLX_BAD_VISUAL;
- }
-
- break;
- }
-
- case glXChooseVisual_func:
- {
- PIXELFORMATDESCRIPTOR pfd;
- unsigned int visualid = 0;
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
-
- int i;
-
- if ((int*)args[2] == NULL)
- ret_int = 0;
-
- visualid = get_default_visual(pConn->Display, &pfd);
-
- for( i = 0; i < pConn->nTabAssocAttribListVisual && (tabAssocAttribListVisual[i].visualID != visualid); i++ );
-
- if( i >= pConn->nTabAssocAttribListVisual ) {
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
-
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visualID = i;
- pConn->nTabAssocAttribListVisual++;
- }
-
- ret_int = visualid;
- break;
- }
-
- case glXDestroyWindow_func:
- {
- int i;
- HDC client_drawable = (HDC)args[1];
- HDC drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- HWND hWnd = get_association_clientdrawable_serverwnd( process, client_drawable);
-
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- if( drawable && hWnd )
- {
- destroy_glwindow(pConn, hWnd, drawable);
-
-#if defined( _MK_DBG_ )
- printf("DestoryWindw( HWND 0x%p, HDC 0x%p) Client Drawable 0x%p\n", hWnd, drawable, client_drawable);
-#endif
-
- unset_association_clientdrawable_serverdrawable(process, (void *) (long)client_drawable);
-
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->drawable == drawable)
- {
- process->glstates[i]->drawable = 0;
- }
- }
-
- if( process->current_state->drawable == drawable )
- process->current_state = &process->default_state;
- }
-
- break;
- }
-
-
- case glXDestroyContext_func:
- {
- int fake_ctxt = (int)args[1];
- HWND hWnd = NULL;
- HDC hdc = NULL;
- HGLRC ctxt = (HGLRC)get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
-
- if (display_function_call) fprintf(stderr, "fake_ctxt=%d\n", fake_ctxt);
-
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%p) !\n", (void*)(long)fake_ctxt);
- }
- else
- {
- int i;
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_ctxt)
- {
- if (ctxt == process->current_state->context)
- process->current_state = &process->default_state;
-
- int fake_shareList = process->glstates[i]->fake_shareList;
- process->glstates[i]->ref --;
- if (process->glstates[i]->ref == 0)
- {
- fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
- process->nbGLStates--;
- }
-
- if (fake_shareList)
- {
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_shareList)
- {
- process->glstates[i]->ref --;
- if (process->glstates[i]->ref == 0)
- {
- fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
- process->nbGLStates--;
- }
- break;
- }
- }
- }
-
- wglDeleteContext(ctxt);
-
- get_association_fakecontext_glxwnd(process, (void*)(long)fake_ctxt, hWnd, hdc);
- destroy_glwindow(pConn, hWnd, hdc);
-
- unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- unset_association_fakecontext_visualid(process, (void*)(long)fake_ctxt);
-
-#if defined( _MK_DBG_ )
- printf("Destory Context Window ( WHND 0x%p, HRC 0x%p)", hWnd, hdc);
- printf("wglDestroyContext(HGLRC 0x%p) - fake context : %d\n", ctxt, fake_ctxt);
-#endif
- break;
- }
- }
- }
- break;
- }
-
- case glXGetProcAddress_fake_func:
- {
- char *fun_name = (char*)args[0];
- if (display_function_call) fprintf(stderr, "%s\n", fun_name);
-
- ret_int = 1;
- break;
- }
-
- case glXGetProcAddress_global_fake_func:
- {
- int nbElts = args[0];
- char* huge_buffer = (char*)args[1];
- char* result = (char*)args[2];
- int i;
- for(i=0;i<nbElts;i++)
- {
- int len = strlen(huge_buffer);
-
- result[i] = 1;
- huge_buffer += len + 1;
- }
- break;
- }
-
- case glXSwapBuffers_func:
- {
- HDC client_drawable = (HDC)args[1];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- HDC drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable == 0)
- {
- fprintf(stderr, "unknown client_drawable (%p) !\n", (void*)client_drawable);
- }
- else
- {
-#if defined( _MK_DBG_ ) /* by 20.Nov.2009 */
- printf("SwapBuffers( HDC 0x%p)\n", drawable);
-#endif
- SwapBuffers(drawable);
- }
- break;
- }
-
- case glXQueryVersion_func:
- {
- int *pMajorVersion = (int *)args[1];
- int *pMinorVersion = (int *)args[2];
- int rVersion;
-
- rVersion = GetVersion();
-
- *pMajorVersion = (rVersion & 0x0000FF00) >> 8;
- *pMinorVersion = rVersion & 0x000000FF;
-
-
-#if defined( _MK_DBG_ ) /* by 20.Nov.2009 */
- printf(" Major Version : %d - Minor Version : %d \n",*pMajorVersion, *pMinorVersion);
-#endif
- break;
- }
-
- case glXQueryExtensionsString_func:
- {
-
- fprintf(stderr, "glXQueryExtensionsString not support (Current WIN32 System)\n");
- ret_str = NULL;
- break;
- }
-
- case glXGetClientString_func:
- {
- static char *ventor = "support WGL of Microsoft Corporation";
- ret_str = ventor;//glXGetClientString(dpy, args[1]);
- break;
- }
-
- case glXQueryServerString_func:
- {
- static char *ventor = "support WGL of Microsoft Corporation";
- ret_str = ventor; //glXQueryServerString(dpy, 0, args[2]);
- break;
- }
-
- case glXGetScreenDriver_func:
- {
- fprintf(stderr, "glXGetScreenDriver not support (Current WIN32 System)\n");
- ret_str = NULL;
- break;
- }
-
- case glXGetDriverConfig_func:
- {
- fprintf(stderr, "glXGetDriverConfig not support (Current WIN32 System)\n");
- ret_str = NULL;
- break;
- }
-
- case glXCreatePbuffer_func:
- {
- int client_fbconfig = args[1];
- int pb_width = 0, pb_height = 0;
- int *attrib_list = (int*)args[2];
- int fake_pbuffer = process->next_available_pbuffer_number + 1;
- HDC pbuffer;
- WGLFBConfig *fbconfig = get_pfDescriptor(process, client_fbconfig);
-
- ret_int = 0;
-
- while (attrib_list && *attrib_list != GLX_NONE) {
- switch (*attrib_list++) {
- case GLX_WIDTH:
- pb_width = *attrib_list++;
- break;
-
- case GLX_HEIGHT:
- pb_height = *attrib_list++;
- break;
-
- default:
- break;
- }
- }
-
- if(fbconfig)
- {
- pbuffer = create_pbwindow((void *) ( fake_pbuffer), process, 0, 0, pb_width, pb_height);
-
-#if defined( _MK_DBG_ )
- printf(" pbuffer 0x%p = Create_pbwindow( fakebuffer : %d , width : %d, height : %d\n", pbuffer, fake_pbuffer, pb_width, pb_height);
-#endif
-
- if (pbuffer)
- {
- PbufferInfo *pb_info = (PbufferInfo *)malloc( sizeof(PbufferInfo) );
- memset((void *) pb_info, 0, sizeof(PbufferInfo));
-
- process->next_available_pbuffer_number ++;
- set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
- ret_int = fake_pbuffer;
-
- pb_info->width = pb_width;
- pb_info->height = pb_height;
- pb_info->colorFormat = GLX_RGBA;
- get_pfdAttrib(&fbconfig->pfd, GLX_BUFFER_SIZE, &pb_info->colorBits);
-
- pb_info->backBuffer = malloc( pb_width * pb_height * sizeof(int));
- set_association_fakepbuffer_pbinfo( process, (void *)(long)fake_pbuffer, (void *) pb_info );
- }
- }
-
- break;
- }
-
- case glXCreateGLXPbufferSGIX_func:
- {
- int client_fbconfig = args[1];
- int pb_width = 0, pb_height = 0;
- int fake_pbuffer = process->next_available_pbuffer_number + 1;
- HDC pbuffer;
- WGLFBConfig *fbconfig = get_pfDescriptor(process, client_fbconfig);
-
- ret_int = 0;
-
- pb_width = args[2];
- pb_height = args[3];
-
- if(fbconfig)
- {
- pbuffer = create_pbwindow((void *) ( fake_pbuffer), process, 0, 0, pb_width, pb_height);
-#if defined( _MK_DBG_ )
- printf(" pbuffer 0x%p = Create_pbwindow( fakebuffer : %d , width : %d, height : %d\n", pbuffer, fake_pbuffer, pb_width, pb_height);
-#endif
- if (pbuffer)
- {
- PbufferInfo *pb_info = (PbufferInfo *)malloc( sizeof(PbufferInfo) );
- memset((void *) pb_info, 0, sizeof(PbufferInfo));
-
- process->next_available_pbuffer_number ++;
- set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
- ret_int = fake_pbuffer;
-
- pb_info->width = pb_width;
- pb_info->height = pb_height;
- pb_info->colorFormat = GLX_RGBA;
- get_pfdAttrib(&fbconfig->pfd, GLX_BUFFER_SIZE, &pb_info->colorBits);
-
- pb_info->backBuffer = malloc( pb_width * pb_height * sizeof(int));
- set_association_fakepbuffer_pbinfo( process, (void *)(long)fake_pbuffer, (void *) pb_info );
- }
- }
-
- break;
- }
-
- case glXDestroyPbuffer_func:
- case glXDestroyGLXPbufferSGIX_func:
- {
- HDC fakepbuffer = (HDC)args[1];
- HDC pbuffer = get_association_fakepbuffer_pbuffer(process, (void *)fakepbuffer);
- HWND hWnd = get_association_fakepbuffer_pbufferwnd( process, (void *)fakepbuffer);
- PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void *) fakepbuffer);
-
- if( pbuffer && hWnd )
- {
- if(pb_info)
- {
- free(pb_info->backBuffer);
- free(pb_info);
- }
-
- destroy_glwindow(pConn, hWnd, pbuffer);
-
-#if defined( _MK_DBG_ )
- printf("DestoryPbuffer( HWND 0x%p, HDC 0x%p) fake pbuffer 0x%p\n", hWnd, pbuffer, fakepbuffer);
-#endif
-
- unset_association_fakepbuffer_pbuffer(process, (void *) (long)fakepbuffer);
- }
-
- break;
- }
-
- case glXBindTexImageARB_func:
- case glXBindTexImageATI_func:
- {
- HGLRC pb_context, cur_context;
- HDC pb_drawable, cur_drawable;
- int fake_pbuffer = (int)args[1];
- PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void *) (long) fake_pbuffer);
-
- ret_int = 0;
-
- if( pb_info )
- {
-
- pb_context = pb_info->context;
- pb_drawable =get_association_fakepbuffer_pbuffer(process, (void *) (long) fake_pbuffer);
-
- if( pb_context && pb_drawable )
- {
- cur_context = wglGetCurrentContext( );
- cur_drawable = wglGetCurrentDC( );
-
- wglMakeCurrent(pb_drawable, pb_context);
- glReadPixels(0, 0, pb_info->width, pb_info->height, pb_info->colorFormat, GL_UNSIGNED_BYTE, pb_info->backBuffer);
- wglMakeCurrent(cur_drawable, cur_context);
-
- glTexImage2D(GL_TEXTURE_2D, 0, pb_info->colorFormat, pb_info->width, pb_info->height,
- 0, pb_info->colorFormat, GL_UNSIGNED_BYTE, pb_info->backBuffer);
- ret_int = 1;
- }
- else
- {
- fprintf(stderr, "glXBindTexImage Error - pbuffer Null...\n");
- }
-
- }
- else
- {
- fprintf(stderr, "glXBindTexImage Error - pbuffer information Null...\n");
- }
-
-
- /*TODO*/
- /*TODO*/
- break;
- }
-
- case glXReleaseTexImageARB_func:
- case glXReleaseTexImageATI_func:
- {
- int fake_pbuffer = (int)args[1];
- HDC pbuffer = get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- PbufferInfo *pb_info = get_association_fakepbuffer_pbinfo(process, (void*)fake_pbuffer);
-
- ret_int = 0;
-
- if ( pbuffer )
- {
- if(pb_info)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, pb_info->colorFormat, pb_info->width, pb_info->height, 0, pb_info->colorFormat, GL_UNSIGNED_BYTE, NULL);
- ret_int = 1;
- }
- else
- {
- fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
- }
- else
- {
- fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
-
- break;
- }
-
- case glXQueryContext_func:
- {
- ret_int = 0;
- fprintf(stderr, "glXCreateGLXPbufferSGIX not support (Current WIN32 System)\n");
- break;
- }
-
- case glXQueryDrawable_func:
- {
- fprintf(stderr, "glXQueryDrawable not support \n");
-
- /*TODO*/
- /*TODO*/
- break;
- }
-
- case glXQueryGLXPbufferSGIX_func:
- {
- ret_int = 0;
-
- fprintf(stderr, "glXCreateGLXPbufferSGIX not support (Current WIN32 System)\n");
- break;
- }
-
- case glXCreateContextWithConfigSGIX_func:
- {
- ret_int = 0;
-
- fprintf(stderr, "glXCreateContextWithConfigSGIX not support (Current WIN32 System)\n");
- break;
- }
-
- case glXSwapIntervalSGI_func:
- {
- ret_int = 0;
-
- fprintf(stderr, "glXSwapIntervalSGI not support (Current WIN32 System)\n");
- break;
- }
-
- case glXCopyContext_func:
- {
- HGLRC fake_src_ctxt = (HGLRC)args[1];
- HGLRC fake_dst_ctxt = (HGLRC)args[2];
-
- if (display_function_call) fprintf(stderr, "fake_src_ctxt=%p, fake_dst_ctxt=%p\n", fake_src_ctxt, fake_dst_ctxt);
-
- fprintf(stderr, "glXCopyContext not support (Current WIN32 System)\n");
- break;
- }
-
- case glXIsDirect_func:
- {
- ret_char = False;
- fprintf(stderr, "glXCopyContext not support (Current WIN32 System)\n");
- break;
- }
-
- case glGetString_func:
- {
- ret_str = (char*)glGetString(args[0]);
- break;
- }
-
- /* Begin of texture stuff */
- case glBindTexture_func:
- case glBindTextureEXT_func:
- {
- int target = args[0];
- unsigned int client_texture = args[1];
- unsigned int server_texture;
-
- if (client_texture == 0)
- {
- glBindTexture(target, 0);
- }
- else
- {
- alloc_value(process->current_state->textureAllocator, client_texture);
- server_texture = process->current_state->tabTextures[client_texture];
- if (server_texture == 0)
- {
- glGenTextures(1, &server_texture);
- process->current_state->tabTextures[client_texture] = server_texture;
- }
- glBindTexture(target, server_texture);
- }
- break;
- }
-
- case glGenTextures_fake_func:
- {
- //GET_EXT_PTR(void, glGenTextures, (GLsizei n, GLuint *textures));
- int i;
- int n = args[0];
- unsigned int* clientTabTextures = malloc(n * sizeof(int));
- unsigned int* serverTabTextures = malloc(n * sizeof(int));
-
- alloc_range(process->current_state->textureAllocator, n, clientTabTextures);
-
- glGenTextures(n, serverTabTextures);
- for(i=0;i<n;i++)
- {
- process->current_state->tabTextures[clientTabTextures[i]] = serverTabTextures[i];
- }
-
- free(clientTabTextures);
- free(serverTabTextures);
- break;
- }
-
- case glDeleteTextures_func:
- {
- //GET_EXT_PTR(void, glDeleteTextures, (GLsizei n, const GLuint *textures));
- int i;
- int n = args[0];
- unsigned int* clientTabTextures = (unsigned int*)args[1];
-
- delete_range(process->current_state->textureAllocator, n, clientTabTextures);
-
- unsigned int* serverTabTextures = malloc(n * sizeof(int));
- for(i=0;i<n;i++)
- {
- serverTabTextures[i] = get_server_texture(process, clientTabTextures[i]);
- }
- glDeleteTextures(n, serverTabTextures);
- for(i=0;i<n;i++)
- {
- process->current_state->tabTextures[clientTabTextures[i]] = 0;
- }
- free(serverTabTextures);
- break;
- }
-
- case glPrioritizeTextures_func:
- {
- GET_EXT_PTR(void, glPrioritizeTextures, (GLsizei n, const GLuint *textures, const GLclampf *priorities));
-
- int i;
- int n = args[0];
- unsigned int* textures = (unsigned int*)args[1];
- for(i=0;i<n;i++)
- {
- textures[i] = get_server_texture(process, textures[i]);
- }
- ptr_func_glPrioritizeTextures(n, textures, (const GLclampf*)args[2]);
- break;
- }
-
- case glAreTexturesResident_func:
- {
- GET_EXT_PTR(void, glAreTexturesResident, (GLsizei n, const GLuint *textures, GLboolean *residences));
- int i;
- int n = args[0];
- unsigned int* textures = (unsigned int*)args[1];
- for(i=0;i<n;i++)
- {
- textures[i] = get_server_texture(process, textures[i]);
- }
- ptr_func_glAreTexturesResident(n, textures, (GLboolean*)args[2]);
- break;
- }
-
- case glIsTexture_func:
- case glIsTextureEXT_func:
- {
- GET_EXT_PTR(GLboolean, glIsTexture, (GLuint texture ));
- unsigned int client_texture = args[0];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ret_char = ptr_func_glIsTexture(server_texture);
- else
- ret_char = 0;
- break;
- }
-
- case glFramebufferTexture1DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture1DEXT, (int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture1DEXT(args[0], args[1], args[2], server_texture, args[4]);
- break;
- }
-
- case glFramebufferTexture2DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture2DEXT, (int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture2DEXT(args[0], args[1], args[2], server_texture, args[4]);
- break;
- }
-
- case glFramebufferTexture3DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture3DEXT, (int, int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture3DEXT(args[0], args[1], args[2], server_texture, args[4], args[5]);
- break;
- }
- /* End of texture stuff */
-
- /* Begin of list stuff */
- case glIsList_func:
- {
- unsigned int client_list = args[0];
- unsigned int server_list = get_server_list(process, client_list);
- if (server_list)
- ret_char = glIsList(server_list);
- else
- ret_char = 0;
- break;
- }
-
- case glDeleteLists_func:
- {
- int i;
- unsigned int first_client = args[0];
- int n = args[1];
-
- unsigned int first_server = get_server_list(process, first_client);
- for(i=0;i<n;i++)
- {
- if (get_server_list(process, first_client + i) != first_server + i)
- break;
- }
- if (i == n)
- {
- glDeleteLists(first_server, n);
- }
- else
- {
- for(i=0;i<n;i++)
- {
- glDeleteLists(get_server_list(process, first_client + i), 1);
- }
- }
-
- for(i=0;i<n;i++)
- {
- process->current_state->tabLists[first_client + i] = 0;
- }
- delete_consecutive_values(process->current_state->listAllocator, first_client, n);
- break;
- }
-
- case glGenLists_fake_func:
- {
- int i;
- int n = args[0];
- unsigned int server_first = glGenLists(n);
- if (server_first)
- {
- unsigned int client_first = alloc_range(process->current_state->listAllocator, n, NULL);
- for(i=0;i<n;i++)
- {
- process->current_state->tabLists[client_first + i] = server_first + i;
- }
- }
- break;
- }
-
- case glNewList_func:
- {
- unsigned int client_list = args[0];
- int mode = args[1];
- alloc_value(process->current_state->listAllocator, client_list);
- unsigned int server_list = get_server_list(process, client_list);
- if (server_list == 0)
- {
- server_list = glGenLists(1);
- process->current_state->tabLists[client_list] = server_list;
- }
- glNewList(server_list, mode);
- break;
- }
-
- case glCallList_func:
- {
- unsigned int client_list = args[0];
- unsigned int server_list = get_server_list(process, client_list);
- glCallList(server_list);
- break;
- }
-
- case glCallLists_func:
- {
- int i;
- int n = args[0];
- int type = args[1];
- const GLvoid* lists = (const GLvoid*)args[2];
- int* new_lists = malloc(sizeof(int) * n);
- for(i=0;i<n;i++)
- {
- new_lists[i] = get_server_list(process, translate_id(i, type, lists));
- }
- glCallLists(n, GL_UNSIGNED_INT, new_lists);
- free(new_lists);
- break;
- }
- /* End of list stuff */
-
- /* Begin of buffer stuff */
- case glBindBufferARB_func:
- {
- GET_EXT_PTR(void, glBindBufferARB, (int,int));
- int target = args[0];
- unsigned int client_buffer = args[1];
- unsigned int server_buffer;
-
- if (client_buffer == 0)
- {
- ptr_func_glBindBufferARB(target, 0);
- }
- else
- {
- server_buffer = get_server_buffer(process, client_buffer);
- ptr_func_glBindBufferARB(target, server_buffer);
- }
- break;
- }
-
- case glGenBuffersARB_fake_func:
- {
- GET_EXT_PTR(void, glGenBuffersARB, (int,unsigned int*));
- int i;
- int n = args[0];
- unsigned int* clientTabBuffers = malloc(n * sizeof(int));
- unsigned int* serverTabBuffers = malloc(n * sizeof(int));
-
- alloc_range(process->current_state->bufferAllocator, n, clientTabBuffers);
-
- ptr_func_glGenBuffersARB(n, serverTabBuffers);
- for(i=0;i<n;i++)
- {
- process->current_state->tabBuffers[clientTabBuffers[i]] = serverTabBuffers[i];
- }
-
- free(clientTabBuffers);
- free(serverTabBuffers);
- break;
- }
-
-
- case glDeleteBuffersARB_func:
- {
- GET_EXT_PTR(void, glDeleteBuffersARB, (int,int*));
- int i;
- int n = args[0];
- unsigned int* clientTabBuffers = (unsigned int*)args[1];
-
- delete_range(process->current_state->bufferAllocator, n, clientTabBuffers);
-
- int* serverTabBuffers = malloc(n * sizeof(int));
- for(i=0;i<n;i++)
- {
- serverTabBuffers[i] = get_server_buffer(process, clientTabBuffers[i]);
- }
- ptr_func_glDeleteBuffersARB(n, serverTabBuffers);
- for(i=0;i<n;i++)
- {
- process->current_state->tabBuffers[clientTabBuffers[i]] = 0;
- }
- free(serverTabBuffers);
- break;
- }
-
- case glIsBufferARB_func:
- {
- GET_EXT_PTR(int, glIsBufferARB, (int));
- unsigned int client_buffer = args[0];
- unsigned int server_buffer = get_server_buffer(process, client_buffer);
- if (server_buffer)
- ret_int = ptr_func_glIsBufferARB(server_buffer);
- else
- ret_int = 0;
- break;
- }
- /* Endo of buffer stuff */
-
- case glShaderSourceARB_fake_func:
- {
- GET_EXT_PTR(void, glShaderSourceARB, (int,int,char**,void*));
- int size = args[1];
- int i;
- int acc_length = 0;
- GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
- int* tab_length = (int*)args[3];
- for(i=0;i<size;i++)
- {
- tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
- acc_length += tab_length[i];
- }
- ptr_func_glShaderSourceARB(args[0], args[1], tab_prog, tab_length);
- free(tab_prog);
- break;
- }
-
- case glShaderSource_fake_func:
- {
- GET_EXT_PTR(void, glShaderSource, (int,int,char**,void*));
- int size = args[1];
- int i;
- int acc_length = 0;
- GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
- int* tab_length = (int*)args[3];
-
- char **tab_prog_new;
- GLint *tab_length_new;
-
- tab_prog_new = malloc(args[1]* sizeof(char*));
- tab_length_new = malloc(args[1]* sizeof(GLint));
-
- memset(tab_prog_new, 0, args[1] * sizeof(char*));
- memset(tab_length_new, 0, args[1] * sizeof(GLint));
-
-
- for(i=0;i<size;i++)
- {
- tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
- acc_length += tab_length[i];
- }
-
- shadersrc_gles_to_gl(args[1], tab_prog, tab_prog_new, tab_length, tab_length_new);
-
- if (!tab_prog_new || !tab_length_new)
- break;
-
- ptr_func_glShaderSource(args[0], args[1], tab_prog_new, tab_length_new);
-
- for (i = 0; i < args[1]; i++)
- free(tab_prog_new[i]);
- free(tab_prog_new);
- free(tab_length_new);
-
- free(tab_prog);
- break;
- }
-
- case glVertexPointer_fake_func:
- {
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glVertexPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- glVertexPointer(size, type, stride, process->current_state->vertexPointer);
- break;
- }
-
- case glNormalPointer_fake_func:
- {
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->normalPointerSize = MAX(process->current_state->normalPointerSize, offset + bytes_size);
- process->current_state->normalPointer = realloc(process->current_state->normalPointer, process->current_state->normalPointerSize);
- memcpy(process->current_state->normalPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glNormalPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- glNormalPointer(type, stride, process->current_state->normalPointer);
- break;
- }
-
- case glIndexPointer_fake_func:
- {
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->indexPointerSize = MAX(process->current_state->indexPointerSize, offset + bytes_size);
- process->current_state->indexPointer = realloc(process->current_state->indexPointer, process->current_state->indexPointerSize);
- memcpy(process->current_state->indexPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glIndexPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- glIndexPointer(type, stride, process->current_state->indexPointer);
- break;
- }
-
- case glEdgeFlagPointer_fake_func:
- {
- int offset = args[0];
- int stride = args[1];
- int bytes_size = args[2];
- process->current_state->edgeFlagPointerSize = MAX(process->current_state->edgeFlagPointerSize, offset + bytes_size);
- process->current_state->edgeFlagPointer = realloc(process->current_state->edgeFlagPointer, process->current_state->edgeFlagPointerSize);
- memcpy(process->current_state->edgeFlagPointer + offset, (void*)args[3], bytes_size );
- //fprintf(stderr, "glEdgeFlagPointer_fake_func stride = %d, bytes_size=%d\n", stride, bytes_size);
- glEdgeFlagPointer(stride, process->current_state->edgeFlagPointer);
- break;
- }
-
- case glVertexAttribPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int normalized = args[4];
- int stride = args[5];
- int bytes_size = args[6];
- process->current_state->vertexAttribPointerSize[index] = MAX(process->current_state->vertexAttribPointerSize[index], offset + bytes_size);
- process->current_state->vertexAttribPointer[index] = realloc(process->current_state->vertexAttribPointer[index],
- process->current_state->vertexAttribPointerSize[index]);
- memcpy(process->current_state->vertexAttribPointer[index] + offset, (void*)args[7], bytes_size);
- ptr_func_glVertexAttribPointerARB(index, size, type, normalized, stride,
- process->current_state->vertexAttribPointer[index]);
- break;
- }
-
- case glVertexAttribPointerNV_fake_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerNV, (int,int,int,int,void*));
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int stride = args[4];
- int bytes_size = args[5];
- process->current_state->vertexAttribPointerNVSize[index] = MAX(process->current_state->vertexAttribPointerNVSize[index], offset + bytes_size);
- process->current_state->vertexAttribPointerNV[index] = realloc(process->current_state->vertexAttribPointerNV[index],
- process->current_state->vertexAttribPointerNVSize[index]);
- memcpy(process->current_state->vertexAttribPointerNV[index] + offset, (void*)args[6], bytes_size);
- ptr_func_glVertexAttribPointerNV(index, size, type, stride,
- process->current_state->vertexAttribPointerNV[index]);
- break;
- }
-
- case glColorPointer_fake_func:
- {
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->colorPointerSize = MAX(process->current_state->colorPointerSize, offset + bytes_size);
- process->current_state->colorPointer = realloc(process->current_state->colorPointer, process->current_state->colorPointerSize);
- memcpy(process->current_state->colorPointer + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glColorPointer_fake_func bytes_size = %d\n", bytes_size);
- glColorPointer(size, type, stride, process->current_state->colorPointer);
-
- break;
- }
-
- case glSecondaryColorPointer_fake_func:
- {
- GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->secondaryColorPointerSize = MAX(process->current_state->secondaryColorPointerSize, offset + bytes_size);
- process->current_state->secondaryColorPointer = realloc(process->current_state->secondaryColorPointer, process->current_state->secondaryColorPointerSize);
- memcpy(process->current_state->secondaryColorPointer + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glSecondaryColorPointer_fake_func bytes_size = %d\n", bytes_size);
- ptr_func_glSecondaryColorPointer(size, type, stride, process->current_state->secondaryColorPointer);
-
- break;
- }
-
- case glPushClientAttrib_func:
- {
- int mask = args[0];
- if (process->current_state->clientStateSp < MAX_CLIENT_STATE_STACK_SIZE)
- {
- process->current_state->clientStateStack[process->current_state->clientStateSp].mask = mask;
- if (mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex =
- process->current_state->activeTextureIndex;
- }
- process->current_state->clientStateSp++;
- }
- glPushClientAttrib(mask);
- break;
- }
-
- case glPopClientAttrib_func:
- {
- if (process->current_state->clientStateSp > 0)
- {
- process->current_state->clientStateSp--;
- if (process->current_state->clientStateStack[process->current_state->clientStateSp].mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- process->current_state->activeTextureIndex =
- process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex;
- }
- }
- glPopClientAttrib();
- break;
- }
-
- case glClientActiveTexture_func:
- case glClientActiveTextureARB_func:
- {
- int activeTexture = args[0];
- process->current_state->activeTextureIndex = activeTexture - GL_TEXTURE0_ARB;
- do_glClientActiveTextureARB(activeTexture);
- break;
- }
-
- case glTexCoordPointer_fake_func:
- {
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int stride = args[4];
- int bytes_size = args[5];
- process->current_state->texCoordPointerSize[index] = MAX(process->current_state->texCoordPointerSize[index], offset + bytes_size);
- process->current_state->texCoordPointer[index] = realloc(process->current_state->texCoordPointer[index], process->current_state->texCoordPointerSize[index]);
- memcpy(process->current_state->texCoordPointer[index] + offset, (void*)args[6], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + index);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[index]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glWeightPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->weightPointerSize = MAX(process->current_state->weightPointerSize, offset + bytes_size);
- process->current_state->weightPointer = realloc(process->current_state->weightPointer, process->current_state->weightPointerSize);
- memcpy(process->current_state->weightPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glWeightPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- ptr_func_glWeightPointerARB(size, type, stride, process->current_state->weightPointer);
- break;
- }
-
- case glMatrixIndexPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->matrixIndexPointerSize = MAX(process->current_state->matrixIndexPointerSize, offset + bytes_size);
- process->current_state->matrixIndexPointer = realloc(process->current_state->matrixIndexPointer, process->current_state->matrixIndexPointerSize);
- memcpy(process->current_state->matrixIndexPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glMatrixIndexPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- ptr_func_glMatrixIndexPointerARB(size, type, stride, process->current_state->matrixIndexPointer);
- break;
- }
-
- case glFogCoordPointer_fake_func:
- {
- GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->fogCoordPointerSize = MAX(process->current_state->fogCoordPointerSize, offset + bytes_size);
- process->current_state->fogCoordPointer = realloc(process->current_state->fogCoordPointer, process->current_state->fogCoordPointerSize);
- memcpy(process->current_state->fogCoordPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glFogCoordPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- ptr_func_glFogCoordPointer(type, stride, process->current_state->fogCoordPointer);
- break;
- }
-
- case glVariantPointerEXT_fake_func:
- {
- GET_EXT_PTR(void, glVariantPointerEXT, (int,int,int,void*));
- int offset = args[0];
- int id = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->variantPointerEXTSize[id] = MAX(process->current_state->variantPointerEXTSize[id], offset + bytes_size);
- process->current_state->variantPointerEXT[id] = realloc(process->current_state->variantPointerEXT[id], process->current_state->variantPointerEXTSize[id]);
- memcpy(process->current_state->variantPointerEXT[id] + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glVariantPointerEXT_fake_func[%d] type=%d, stride=%d, byte_size=%d\n", id, type, stride, bytes_size);
- ptr_func_glVariantPointerEXT(id, type, stride, process->current_state->variantPointerEXT[id]);
- break;
- }
-
- case glInterleavedArrays_fake_func:
- {
- GET_EXT_PTR(void, glInterleavedArrays, (int,int,void*));
- int offset = args[0];
- int format = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->interleavedArraysSize = MAX(process->current_state->interleavedArraysSize, offset + bytes_size);
- process->current_state->interleavedArrays = realloc(process->current_state->interleavedArrays, process->current_state->interleavedArraysSize);
- memcpy(process->current_state->interleavedArrays + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glInterleavedArrays_fake_func format=%d, stride=%d, byte_size=%d\n", format, stride, bytes_size);
- ptr_func_glInterleavedArrays(format, stride, process->current_state->interleavedArrays);
- break;
- }
-
- case glElementPointerATI_fake_func:
- {
- GET_EXT_PTR(void, glElementPointerATI, (int,void*));
- int type = args[0];
- int bytes_size = args[1];
- process->current_state->elementPointerATISize = bytes_size;
- process->current_state->elementPointerATI = realloc(process->current_state->elementPointerATI, process->current_state->elementPointerATISize);
- memcpy(process->current_state->elementPointerATI, (void*)args[2], bytes_size);
- //fprintf(stderr, "glElementPointerATI_fake_func type=%d, byte_size=%d\n", type, bytes_size);
- ptr_func_glElementPointerATI(type, process->current_state->elementPointerATI);
- break;
- }
-
- case glTexCoordPointer01_fake_func:
- {
- int size = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->texCoordPointerSize[0] = bytes_size;
- process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
- memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer01_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glTexCoordPointer012_fake_func:
- {
- int size = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->texCoordPointerSize[0] = bytes_size;
- process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
- memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer012_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexAndNormalPointer_fake_func:
- {
- int vertexPointerSize = args[0];
- int vertexPointerType = args[1];
- int vertexPointerStride = args[2];
- int normalPointerType = args[3];
- int normalPointerStride = args[4];
- int bytes_size = args[5];
- void* ptr = (void*)args[6];
- process->current_state->vertexPointerSize = bytes_size;
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, bytes_size);
- memcpy(process->current_state->vertexPointer, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, vertexPointerStride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, normalPointerStride, process->current_state->vertexPointer);
- break;
- }
-
- case glVertexNormalPointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset= args[i++];
- int normalPointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- break;
- }
-
- case glTuxRacerDrawElements_fake_func:
- {
- int mode = args[0];
- int count = args[1];
- int isColorEnabled = args[2];
- void* ptr = (void*)args[3];
- int stride = 6 * sizeof(float) + ((isColorEnabled) ? 4 * sizeof(unsigned char) : 0);
- glVertexPointer( 3, GL_FLOAT, stride, ptr);
- glNormalPointer( GL_FLOAT, stride, ptr + 3 * sizeof(float));
- if (isColorEnabled)
- glColorPointer( 4, GL_UNSIGNED_BYTE, stride, ptr + 6 * sizeof(float));
- glDrawArrays(mode, 0, count);
- break;
- }
-
- case glVertexNormalColorPointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset= args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- break;
- }
-
- case glVertexColorTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord01PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord012PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int texCoord2PointerOffset = args[i++];
- int texCoord2PointerSize = args[i++];
- int texCoord2PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord01PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord012PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int texCoord2PointerOffset = args[i++];
- int texCoord2PointerSize = args[i++];
- int texCoord2PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case _glVertexPointer_buffer_func:
- {
- glVertexPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glNormalPointer_buffer_func:
- {
- glNormalPointer(args[0],args[1],(void*)args[2]);
- break;
- }
-
- case _glColorPointer_buffer_func:
- {
- glColorPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glSecondaryColorPointer_buffer_func:
- {
- GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
- ptr_func_glSecondaryColorPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glIndexPointer_buffer_func:
- {
- glIndexPointer(args[0],args[1],(void*)args[2]);
- break;
- }
-
- case _glTexCoordPointer_buffer_func:
- {
- glTexCoordPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glEdgeFlagPointer_buffer_func:
- {
- glEdgeFlagPointer(args[0],(void*)args[1]);
- break;
- }
-
- case _glVertexAttribPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
- ptr_func_glVertexAttribPointerARB(args[0], args[1], args[2], args[3], args[4], (void*)args[5]);
- break;
- }
-
- case _glWeightPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
- ptr_func_glWeightPointerARB(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glMatrixIndexPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
- ptr_func_glMatrixIndexPointerARB(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glFogCoordPointer_buffer_func:
- {
- GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
- ptr_func_glFogCoordPointer(args[0], args[1], (void*)args[2]);
- break;
- }
-
- case _glVariantPointerEXT_buffer_func:
- {
- GET_EXT_PTR(void, glVariantPointerEXT, (int, int,int,void*));
- ptr_func_glVariantPointerEXT(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glDrawElements_buffer_func:
- {
- glDrawElements(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glDrawRangeElements_buffer_func:
- {
- GET_EXT_PTR(void, glDrawRangeElements, ( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ));
- ptr_func_glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
- break;
- }
-
- case _glMultiDrawElements_buffer_func:
- {
- GET_EXT_PTR(void, glMultiDrawElements, (int,int*,int,void**, int));
- ptr_func_glMultiDrawElements(args[0],(int*)args[1],args[2],(void**)args[3],args[4]);
- break;
- }
-
- case _glGetError_fake_func:
- {
- break;
- }
-
- case glGetIntegerv_func:
- {
- glGetIntegerv(args[0], (int*)args[1]);
- break;
- }
-
- case _glReadPixels_pbo_func:
- {
- glReadPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (void*)(args[6]));
- break;
- }
-
- case _glDrawPixels_pbo_func:
- {
- glDrawPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), ARG_TO_UNSIGNED_INT(args[3]), (const void*)(args[4]));
- break;
- }
-
- case _glMapBufferARB_fake_func:
- {
- GET_EXT_PTR(GLvoid*, glMapBufferARB, (GLenum, GLenum));
- GET_EXT_PTR(GLboolean, glUnmapBufferARB, (GLenum));
- int target = args[0];
- int size = args[1];
- void* dst_ptr = (void*)args[2];
- void* src_ptr = ptr_func_glMapBufferARB(target, GL_READ_ONLY);
- if (src_ptr)
- {
- memcpy(dst_ptr, src_ptr, size);
- ret_int = ptr_func_glUnmapBufferARB(target);
- }
- else
- {
- ret_int = 0;
- }
- break;
- }
-
- case fake_gluBuild2DMipmaps_func:
- {
- GET_GLU_PTR(GLint, gluBuild2DMipmaps, (GLenum arg_0, GLint arg_1, GLsizei arg_2, GLsizei arg_3, GLenum arg_4, GLenum arg_5, const GLvoid * arg_6));
- if (ptr_func_gluBuild2DMipmaps == NULL)
- ptr_func_gluBuild2DMipmaps = mesa_gluBuild2DMipmaps;
- ptr_func_gluBuild2DMipmaps(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (const void*)(args[6]));
- break;
- }
-
- case _glSelectBuffer_fake_func:
- {
- process->current_state->selectBufferSize = args[0] * 4;
- process->current_state->selectBufferPtr = realloc(process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
- glSelectBuffer(args[0], process->current_state->selectBufferPtr);
- break;
- }
-
- case _glGetSelectBuffer_fake_func:
- {
- void* ptr = (void*)args[0];
- memcpy(ptr, process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
- break;
- }
-
- case _glFeedbackBuffer_fake_func:
- {
- process->current_state->feedbackBufferSize = args[0] * 4;
- process->current_state->feedbackBufferPtr = realloc(process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
- glFeedbackBuffer(args[0], args[1], process->current_state->feedbackBufferPtr);
- break;
- }
-
- case _glGetFeedbackBuffer_fake_func:
- {
- void* ptr = (void*)args[0];
- memcpy(ptr, process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
- break;
- }
-
- case glGetError_func:
- {
- ret_int = glGetError();
- break;
- }
-
- case glNewObjectBufferATI_func:
- {
- GET_EXT_PTR(int, glNewObjectBufferATI, (int,void*, int));
- ret_int = ptr_func_glNewObjectBufferATI(args[0], (void*)args[1], args[2]);
- break;
- }
-
- default:
- execute_func(func_number, args, &ret_int, &ret_char);
- break;
- }
-
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int ret_type = signature->ret_type;
- switch(ret_type)
- {
- case TYPE_NONE:
- break;
-
- case TYPE_CHAR:
- case TYPE_UNSIGNED_CHAR:
- ret_int = ret_char;
- break;
-
- case TYPE_INT:
- case TYPE_UNSIGNED_INT:
- break;
-
- case TYPE_CONST_CHAR:
- {
- strncpy(ret_string, (ret_str) ? ret_str : "", 32768);
- break;
- }
-
- default:
- fprintf(stderr, "unexpected ret type : %d\n", ret_type);
- exit(-1);
- break;
- }
-
- return ret_int;
-}
-
-#else
-
-#include <arpa/inet.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-#define GL_GLEXT_PROTOTYPES
-#define GLX_GLXEXT_PROTOTYPES
-
-#include "opengl_func.h"
-#include "opengl_utils.h"
-#include "mesa_gl.h"
-#include "mesa_glx.h"
-#include "mesa_glu.h"
-#include "mesa_mipmap.c"
-
-//#define SYSTEMATIC_ERROR_CHECK
-
-#define GET_EXT_PTR(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)glXGetProcAddressARB((const GLubyte*)#funcname); \
- assert (ptr_func_##funcname); \
-}
-
-#define GET_EXT_PTR_NO_FAIL(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)glXGetProcAddressARB((const GLubyte*)#funcname); \
-}
-
-#ifndef WIN32
-#include <dlfcn.h>
-#endif
-
-static void* get_glu_ptr(const char* name)
-{
- static void* handle = (void*)-1;
- if (handle == (void*)-1)
- {
-#ifndef WIN32
- handle = dlopen("libGLU.so" ,RTLD_LAZY);
- if (!handle) {
- fprintf (stderr, "can't load libGLU.so : %s\n", dlerror());
- }
-#else
- handle = (void *)LoadLibrary("glu32.dll");
- if (!handle) {
- fprintf (stderr, "can't load glu32.dll\n");
- }
-#endif
- }
- if (handle)
- {
-#ifndef WIN32
- return dlsym(handle, name);
-#else
- return GetProcAddress(handle, name);
-#endif
- }
- return NULL;
-}
-
-#define GET_GLU_PTR(type, funcname, args_decl) \
- static int detect_##funcname = 0; \
-static type(*ptr_func_##funcname)args_decl = NULL; \
-if (detect_##funcname == 0) \
-{ \
- detect_##funcname = 1; \
- ptr_func_##funcname = (type(*)args_decl)get_glu_ptr(#funcname); \
-}
-
-int display_function_call = 0;
-
-static const int defaultAttribList[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DOUBLEBUFFER,
- None
-};
-
-static XVisualInfo* get_default_visual(Display* dpy)
-{
- fprintf(stderr, "get_default_visual\n");
- static XVisualInfo* vis = NULL;
- XVisualInfo theTemplate;
- int numVisuals;
- if (vis) return vis;
- /*if (vis == NULL)
- vis = glXChooseVisual(dpy, 0, (int*)defaultAttribList);*/
- theTemplate.screen = 0;
- vis = XGetVisualInfo(dpy, VisualScreenMask, &theTemplate, &numVisuals);
- return vis;
-}
-
-void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window)
-{
- pConn->parent_dpy = pConn->Display;
- pConn->qemu_parent_window = _parent_window;
- if (pConn->active_win)
- {
- XReparentWindow(pConn->Display, pConn->active_win, _parent_window, pConn->active_win_x, pConn->active_win_y);
- }
-}
-
-static Window create_window(OGLS_Conn *pConn, Window local_parent_window, XVisualInfo* vis, const char *name,
- int x, int y, int width, int height)
-{
- int scrnum;
- XSetWindowAttributes attr = {0};
- unsigned long mask;
- Window root;
- Window win;
-
- scrnum = DefaultScreen( pConn->Display );
- root = RootWindow( pConn->Display, scrnum );
-
- /* window attributes */
- attr.background_pixel = 0;
- attr.border_pixel = 0;
- attr.colormap = XCreateColormap( pConn->Display, root, vis->visual, AllocNone);
- attr.event_mask = StructureNotifyMask | ExposureMask /*| KeyPressMask*/;
- attr.save_under = True;
- //if (local_parent_window == NULL && qemu_parent_window == NULL)
- attr.override_redirect = False;
- //else
- // attr.override_redirect = True;
- attr.cursor = None;
- mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect | CWSaveUnder ;
-
- if (local_parent_window)
- {
- win = XCreateWindow( pConn->Display, local_parent_window, 0, 0, width, height,
- 0, vis->depth, InputOutput,
- vis->visual, mask, &attr );
- }
- else if (pConn->qemu_parent_window)
- {
- win = XCreateWindow( pConn->Display, pConn->qemu_parent_window, 0, 0, width, height,
- 0, vis->depth, InputOutput,
- vis->visual, mask, &attr );
- }
- else
- {
- win = XCreateWindow( pConn->Display, root, 0, 0, width, height,
- 0, vis->depth, InputOutput,
- vis->visual, mask, &attr );
- }
-
- /* set hints and properties */
- {
- XSizeHints sizehints;
- sizehints.x = x;
- sizehints.y = y;
- sizehints.width = width;
- sizehints.height = height;
- sizehints.flags = USSize | USPosition;
- XSetWMNormalHints(pConn->Display, win, &sizehints);
- XSetStandardProperties(pConn->Display, win, name, name,
- None, (char **)NULL, 0, &sizehints);
- }
-
- /* Host Window?? ?琉??? ?苛쨈?. if( win )
- XMapWindow(pConn->Display, win);*/
-
- XSync(pConn->Display, 0);
-
- /*
- int loop = 1;
- while (loop) {
- while (XPending(pConn->Display) > 0) {
- XEvent event;
- XNextEvent(pConn->Display, &event);
- switch (event.type) {
- case CreateNotify:
- {
- if (((XCreateWindowEvent*)&event)->window == win)
- {
- loop = 0;
- }
- break;
- }
- }
- }
- }*/
-
- pConn->active_win = win;
-
- return win;
-}
-
-static void destroy_window(OGLS_Conn *pConn, Window win )
-{
- /*int i;*/
-
- XDestroyWindow(pConn->Display, win);
-
- XSync(pConn->Display, 0);
- /*int loop = 1;
- while (loop) {
- while (XPending(pConn->Display) > 0) {
- XEvent event;
- XNextEvent(pConn->Display, &event);
- switch (event.type) {
- case DestroyNotify:
- {
- if (((XDestroyWindowEvent*)&event)->window == win)
- {
- loop = 0;
- }
- break;
- }
- }
- }
- }*/
-
- if( pConn->active_win == win)
- pConn->active_win = 0;
-
-}
-
-
-typedef struct
-{
- void* key;
- void* value;
-} Assoc;
-
-
-#define MAX_HANDLED_PROCESS 100
-#define MAX_ASSOC_SIZE 100
-
-#define MAX_FBCONFIG 10
-
-
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
- int map_state;
-} WindowPosStruct;
-
-typedef struct
-{
- GLbitfield mask;
- int activeTextureIndex;
-} ClientState;
-
-#define MAX_CLIENT_STATE_STACK_SIZE 16
-
-typedef struct
-{
- int ref;
- int fake_ctxt;
- int fake_shareList;
- GLXContext context;
- GLXDrawable drawable;
-
- void* vertexPointer;
- void* normalPointer;
- void* colorPointer;
- void* secondaryColorPointer;
- void* indexPointer;
- void* texCoordPointer[NB_MAX_TEXTURES];
- void* edgeFlagPointer;
- void* vertexAttribPointer[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
- void* vertexAttribPointerNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
- void* weightPointer;
- void* matrixIndexPointer;
- void* fogCoordPointer;
- void* variantPointerEXT[MY_GL_MAX_VARIANT_POINTER_EXT];
- void* interleavedArrays;
- void* elementPointerATI;
-
- int vertexPointerSize;
- int normalPointerSize;
- int colorPointerSize;
- int secondaryColorPointerSize;
- int indexPointerSize;
- int texCoordPointerSize[NB_MAX_TEXTURES];
- int edgeFlagPointerSize;
- int vertexAttribPointerSize[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
- int vertexAttribPointerNVSize[MY_GL_MAX_VERTEX_ATTRIBS_NV];
- int weightPointerSize;
- int matrixIndexPointerSize;
- int fogCoordPointerSize;
- int variantPointerEXTSize[MY_GL_MAX_VARIANT_POINTER_EXT];
- int interleavedArraysSize;
- int elementPointerATISize;
-
- int selectBufferSize;
- void* selectBufferPtr;
- int feedbackBufferSize;
- void* feedbackBufferPtr;
-
- ClientState clientStateStack[MAX_CLIENT_STATE_STACK_SIZE];
- int clientStateSp;
- int activeTextureIndex;
-
- unsigned int ownTabTextures[32768];
- unsigned int* tabTextures;
- RangeAllocator ownTextureAllocator;
- RangeAllocator* textureAllocator;
-
- unsigned int ownTabBuffers[32768];
- unsigned int* tabBuffers;
- RangeAllocator ownBufferAllocator;
- RangeAllocator* bufferAllocator;
-
- unsigned int ownTabLists[32768];
- unsigned int* tabLists;
- RangeAllocator ownListAllocator;
- RangeAllocator* listAllocator;
-
-#ifdef SYSTEMATIC_ERROR_CHECK
- int last_error;
-#endif
-} GLState;
-
-typedef struct
-{
- int internal_num;
- int process_id;
- int instr_counter;
-
- int x, y, width, height;
- WindowPosStruct currentDrawablePos;
-
- int next_available_context_number;
- int next_available_pbuffer_number;
-
- int nbGLStates;
- GLState default_state;
- GLState** glstates;
- GLState* current_state;
-
- int nfbconfig;
- GLXFBConfig* fbconfigs[MAX_FBCONFIG];
- int fbconfigs_max[MAX_FBCONFIG];
- int nfbconfig_total;
-
- Assoc association_fakecontext_glxcontext[MAX_ASSOC_SIZE];
- Assoc association_fakepbuffer_pbuffer[MAX_ASSOC_SIZE];
- Assoc association_clientdrawable_serverdrawable[MAX_ASSOC_SIZE];
- Assoc association_fakecontext_visual[MAX_ASSOC_SIZE];
-} ProcessStruct;
-
-int last_process_id = 0;
-
-
-#define ARG_TO_CHAR(x) (char)(x)
-#define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
-#define ARG_TO_SHORT(x) (short)(x)
-#define ARG_TO_UNSIGNED_SHORT(x) (unsigned short)(x)
-#define ARG_TO_INT(x) (int)(x)
-#define ARG_TO_UNSIGNED_INT(x) (unsigned int)(x)
-#define ARG_TO_FLOAT(x) (*(float*)&(x))
-#define ARG_TO_DOUBLE(x) (*(double*)(x))
-
-#include "server_stub.c"
-
-/* ---- */
-
-static void* get_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- return process->association_fakecontext_glxcontext[i].value;
- }
- return NULL;
-}
-
-static void set_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext, void* glxcontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakecontext_glxcontext[i].key = fakecontext;
- process->association_fakecontext_glxcontext[i].value = glxcontext;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-static void unset_association_fakecontext_glxcontext(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- if (process->association_fakecontext_glxcontext[i].key == fakecontext)
- {
- memmove(&process->association_fakecontext_glxcontext[i],
- &process->association_fakecontext_glxcontext[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-/* ---- */
-
-static void* get_association_fakecontext_visual(ProcessStruct* process, void* fakecontext)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
- {
- if (process->association_fakecontext_visual[i].key == fakecontext)
- return process->association_fakecontext_visual[i].value;
- }
- return NULL;
-}
-
-static void set_association_fakecontext_visual(ProcessStruct* process, void* fakecontext, void* visual)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_visual[i].key != NULL;i++)
- {
- if (process->association_fakecontext_visual[i].key == fakecontext)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakecontext_visual[i].key = fakecontext;
- process->association_fakecontext_visual[i].value = visual;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-/* ---- */
-
-static void* get_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- return process->association_fakepbuffer_pbuffer[i].value;
- }
- return NULL;
-}
-static void set_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer, void* pbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_fakepbuffer_pbuffer[i].key = fakepbuffer;
- process->association_fakepbuffer_pbuffer[i].value = pbuffer;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-static void unset_association_fakepbuffer_pbuffer(ProcessStruct* process, void* fakepbuffer)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- if (process->association_fakepbuffer_pbuffer[i].key == fakepbuffer)
- {
- memmove(&process->association_fakepbuffer_pbuffer[i],
- &process->association_fakepbuffer_pbuffer[i+1],
- sizeof(Assoc) * (MAX_ASSOC_SIZE - 1 - i));
- return;
- }
- }
-}
-
-/* ---- */
-
-
-static GLXDrawable get_association_clientdrawable_serverdrawable(ProcessStruct* process, GLXDrawable clientdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == (void*)clientdrawable)
- return (GLXDrawable)process->association_clientdrawable_serverdrawable[i].value;
- }
- return (GLXDrawable)0;
-}
-
-#if 0
-static void* get_association_serverdrawable_clientdrawable(ProcessStruct* process, GLXDrawable serverdrawable)
-{
- int i;
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if ((GLXDrawable)process->association_clientdrawable_serverdrawable[i].value == serverdrawable)
- return process->association_clientdrawable_serverdrawable[i].key;
- }
- return NULL;
-}
-#endif
-
-static void set_association_clientdrawable_serverdrawable(ProcessStruct* process, void* clientdrawable, void* serverdrawable)
-{
- int i;
- for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == clientdrawable)
- {
- break;
- }
- }
- if (i < MAX_ASSOC_SIZE)
- {
- process->association_clientdrawable_serverdrawable[i].key = clientdrawable;
- process->association_clientdrawable_serverdrawable[i].value = serverdrawable;
- }
- else
- {
- fprintf(stderr, "MAX_ASSOC_SIZE reached\n");
- }
-}
-
-static void _get_window_pos(Display *dpy, Window win, WindowPosStruct* pos)
-{
- XWindowAttributes window_attributes_return;
- Window child;
- int x, y;
- Window root = DefaultRootWindow(dpy);
- XGetWindowAttributes(dpy, win, &window_attributes_return);
- XTranslateCoordinates(dpy, win, root, 0, 0, &x, &y, &child);
- /*printf("%d %d %d %d\n", x, y,
- window_attributes_return.width, window_attributes_return.height);*/
- pos->x = x;
- pos->y = y;
- pos->width = window_attributes_return.width;
- pos->height = window_attributes_return.height;
- pos->map_state = window_attributes_return.map_state;
-}
-
-static int is_gl_vendor_ati(Display* dpy)
-{
- static int is_gl_vendor_ati_flag = 0;
- static int has_init = 0;
- if (has_init == 0)
- {
- has_init = 1;
- is_gl_vendor_ati_flag = (strncmp(glXGetClientString(dpy, GLX_VENDOR), "ATI", 3) == 0);
- }
- return is_gl_vendor_ati_flag;
-}
-
-static int get_server_texture(ProcessStruct* process, unsigned int client_texture)
-{
- unsigned int server_texture = 0;
- if (client_texture < 32768)
- {
- server_texture = process->current_state->tabTextures[client_texture];
- }
- else
- {
- fprintf(stderr, "invalid texture name %d\n", client_texture);
- }
- return server_texture;
-}
-
-static int get_server_buffer(ProcessStruct* process, unsigned int client_buffer)
-{
- unsigned int server_buffer = 0;
- if (client_buffer < 32768)
- {
- server_buffer = process->current_state->tabBuffers[client_buffer];
- }
- else
- {
- fprintf(stderr, "invalid buffer name %d\n", client_buffer);
- }
- return server_buffer;
-}
-
-
-static int get_server_list(ProcessStruct* process, unsigned int client_list)
-{
- unsigned int server_list = 0;
- if (client_list < 32768)
- {
- server_list = process->current_state->tabLists[client_list];
- }
- else
- {
- fprintf(stderr, "invalid list name %d\n", client_list);
- }
- return server_list;
-}
-
-static GLXFBConfig get_fbconfig(ProcessStruct* process, int client_fbconfig)
-{
- int i;
- int nbtotal = 0;
- for(i=0;i<process->nfbconfig;i++)
- {
- assert(client_fbconfig >= 1 + nbtotal);
- if (client_fbconfig <= nbtotal + process->fbconfigs_max[i])
- {
- return process->fbconfigs[i][client_fbconfig-1 - nbtotal];
- }
- nbtotal += process->fbconfigs_max[i];
- }
- return 0;
-}
-
-typedef struct
-{
- int attribListLength;
- int* attribList;
- XVisualInfo* visInfo;
-} AssocAttribListVisual;
-
-static int _compute_length_of_attrib_list_including_zero(const int* attribList, int booleanMustHaveValue)
-{
- int i = 0;
- while(attribList[i])
- {
- if (booleanMustHaveValue ||
- !(attribList[i] == GLX_USE_GL ||
- attribList[i] == GLX_RGBA ||
- attribList[i] == GLX_DOUBLEBUFFER ||
- attribList[i] == GLX_STEREO))
- {
- i+=2;
- }
- else
- {
- i++;
- }
- }
- return i + 1;
-}
-
-static int glXChooseVisualFunc( OGLS_Conn *pConn, const int* _attribList)
-{
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
-
- if (_attribList == NULL)
- return 0;
- int attribListLength = _compute_length_of_attrib_list_including_zero(_attribList, 0);
- int i;
-
- int* attribList = malloc(sizeof(int) * attribListLength);
- memcpy(attribList, _attribList, sizeof(int) * attribListLength);
-
- i = 0;
- while(attribList[i])
- {
- if (!(attribList[i] == GLX_USE_GL ||
- attribList[i] == GLX_RGBA ||
- attribList[i] == GLX_DOUBLEBUFFER ||
- attribList[i] == GLX_STEREO))
- {
- if (attribList[i] == GLX_SAMPLE_BUFFERS && attribList[i+1] != 0 && getenv("DISABLE_SAMPLE_BUFFERS"))
- {
- fprintf(stderr, "Disabling GLX_SAMPLE_BUFFERS\n");
- attribList[i+1] = 0;
- }
- i+=2;
- }
- else
- {
- i++;
- }
- }
-
- for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
- {
- if (tabAssocAttribListVisual[i].attribListLength == attribListLength &&
- memcmp(tabAssocAttribListVisual[i].attribList, attribList, attribListLength * sizeof(int)) == 0)
- {
- free(attribList);
- return (tabAssocAttribListVisual[i].visInfo) ? tabAssocAttribListVisual[i].visInfo->visualid : 0;
- }
- }
- XVisualInfo* visInfo = glXChooseVisual(pConn->Display, 0, attribList);
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = attribListLength;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = (int*)malloc(sizeof(int) * attribListLength);
- memcpy(tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList, attribList, sizeof(int) * attribListLength);
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
- pConn->nTabAssocAttribListVisual++;
- free(attribList);
- return (visInfo) ? visInfo->visualid : 0;
-}
-
-static XVisualInfo* get_visual_info_from_visual_id( OGLS_Conn *pConn, int visualid)
-{
- int i, n;
- XVisualInfo template;
- XVisualInfo* visInfo;
-
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
-
- for(i=0;i<pConn->nTabAssocAttribListVisual;i++)
- {
- if (tabAssocAttribListVisual[i].visInfo &&
- tabAssocAttribListVisual[i].visInfo->visualid == visualid)
- {
- return tabAssocAttribListVisual[i].visInfo;
- }
- }
- template.visualid = visualid;
- visInfo = XGetVisualInfo(pConn->Display, VisualIDMask, &template, &n);
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = visInfo;
- pConn->nTabAssocAttribListVisual++;
- return visInfo;
-}
-
-typedef struct
-{
- int x;
- int y;
- int width;
- int height;
- int xhot;
- int yhot;
- int* pixels;
-} ClientCursor;
-
-static ClientCursor client_cursor = { 0 };
-
-static void do_glClientActiveTextureARB(int texture)
-{
- GET_EXT_PTR_NO_FAIL(void, glClientActiveTextureARB, (int));
- if (ptr_func_glClientActiveTextureARB)
- {
- ptr_func_glClientActiveTextureARB(texture);
- }
-}
-
-static void do_glActiveTextureARB(int texture)
-{
- GET_EXT_PTR_NO_FAIL(void, glActiveTextureARB, (int));
- if (ptr_func_glActiveTextureARB)
- {
- ptr_func_glActiveTextureARB(texture);
- }
-}
-
-static void do_glUseProgramObjectARB(GLhandleARB programObj)
-{
- GET_EXT_PTR_NO_FAIL(void, glUseProgramObjectARB, (GLhandleARB));
- if (ptr_func_glUseProgramObjectARB)
- {
- ptr_func_glUseProgramObjectARB(programObj);
- }
-}
-
-static void destroy_gl_state(GLState* state)
-{
- int i;
- if (state->vertexPointer) free(state->vertexPointer);
- if (state->normalPointer) free(state->normalPointer);
- if (state->indexPointer) free(state->indexPointer);
- if (state->colorPointer) free(state->colorPointer);
- if (state->secondaryColorPointer) free(state->secondaryColorPointer);
- for(i=0;i<NB_MAX_TEXTURES;i++)
- {
- if (state->texCoordPointer[i]) free(state->texCoordPointer[i]);
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_ARB;i++)
- {
- if (state->vertexAttribPointer[i]) free(state->vertexAttribPointer[i]);
- }
- for(i=0;i<MY_GL_MAX_VERTEX_ATTRIBS_NV;i++)
- {
- if (state->vertexAttribPointerNV[i]) free(state->vertexAttribPointerNV[i]);
- }
- if (state->weightPointer) free(state->weightPointer);
- if (state->matrixIndexPointer) free(state->matrixIndexPointer);
- if (state->fogCoordPointer) free(state->fogCoordPointer);
- for(i=0;i<MY_GL_MAX_VARIANT_POINTER_EXT;i++)
- {
- if (state->variantPointerEXT[i]) free(state->variantPointerEXT[i]);
- }
- if (state->interleavedArrays) free(state->interleavedArrays);
- if (state->elementPointerATI) free(state->elementPointerATI);
-}
-
-static void init_gl_state(GLState* state)
-{
- state->textureAllocator = &state->ownTextureAllocator;
- state->tabTextures = state->ownTabTextures;
- state->bufferAllocator = &state->ownBufferAllocator;
- state->tabBuffers = state->ownTabBuffers;
- state->listAllocator = &state->ownListAllocator;
- state->tabLists = state->ownTabLists;
-}
-
-/*
- * Translate the nth element of list from type to GLuint.
- */
- static GLuint
-translate_id(GLsizei n, GLenum type, const GLvoid * list)
-{
- GLbyte *bptr;
- GLubyte *ubptr;
- GLshort *sptr;
- GLushort *usptr;
- GLint *iptr;
- GLuint *uiptr;
- GLfloat *fptr;
-
- switch (type) {
- case GL_BYTE:
- bptr = (GLbyte *) list;
- return (GLuint) *(bptr + n);
- case GL_UNSIGNED_BYTE:
- ubptr = (GLubyte *) list;
- return (GLuint) *(ubptr + n);
- case GL_SHORT:
- sptr = (GLshort *) list;
- return (GLuint) *(sptr + n);
- case GL_UNSIGNED_SHORT:
- usptr = (GLushort *) list;
- return (GLuint) *(usptr + n);
- case GL_INT:
- iptr = (GLint *) list;
- return (GLuint) *(iptr + n);
- case GL_UNSIGNED_INT:
- uiptr = (GLuint *) list;
- return (GLuint) *(uiptr + n);
- case GL_FLOAT:
- fptr = (GLfloat *) list;
- return (GLuint) *(fptr + n);
- case GL_2_BYTES:
- ubptr = ((GLubyte *) list) + 2 * n;
- return (GLuint) *ubptr * 256 + (GLuint) * (ubptr + 1);
- case GL_3_BYTES:
- ubptr = ((GLubyte *) list) + 3 * n;
- return (GLuint) * ubptr * 65536
- + (GLuint) *(ubptr + 1) * 256 + (GLuint) * (ubptr + 2);
- case GL_4_BYTES:
- ubptr = ((GLubyte *) list) + 4 * n;
- return (GLuint) *ubptr * 16777216
- + (GLuint) *(ubptr + 1) * 65536
- + (GLuint) *(ubptr + 2) * 256 + (GLuint) * (ubptr + 3);
- default:
- return 0;
- }
-}
-
-static void _create_context(ProcessStruct* process, GLXContext ctxt, int fake_ctxt, GLXContext shareList, int fake_shareList)
-{
- process->glstates = realloc(process->glstates, (process->nbGLStates+1)*sizeof(GLState*));
- process->glstates[process->nbGLStates] = malloc(sizeof(GLState));
- memset(process->glstates[process->nbGLStates], 0, sizeof(GLState));
- process->glstates[process->nbGLStates]->ref = 1;
- process->glstates[process->nbGLStates]->context = ctxt;
- process->glstates[process->nbGLStates]->fake_ctxt = fake_ctxt;
- process->glstates[process->nbGLStates]->fake_shareList = fake_shareList;
- init_gl_state(process->glstates[process->nbGLStates]);
- if (shareList && fake_shareList)
- {
- int i;
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_shareList)
- {
- process->glstates[i]->ref ++;
- process->glstates[process->nbGLStates]->textureAllocator =
- process->glstates[i]->textureAllocator;
- process->glstates[process->nbGLStates]->tabTextures =
- process->glstates[i]->tabTextures;
- process->glstates[process->nbGLStates]->bufferAllocator =
- process->glstates[i]->bufferAllocator;
- process->glstates[process->nbGLStates]->tabBuffers =
- process->glstates[i]->tabBuffers;
- process->glstates[process->nbGLStates]->listAllocator =
- process->glstates[i]->listAllocator;
- process->glstates[process->nbGLStates]->tabLists =
- process->glstates[i]->tabLists;
- break;
- }
- }
- }
- process->nbGLStates++;
-}
-
-static const char *opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
-{
- char *start;
- char *ret;
- char *p;
- int retlen;
- static const char *delim = " \t\n\r/";
-
- if (prevbuf)
- free(prevbuf);
-
- if (s) {
- *saveptr = s;
- } else {
- if (!(*saveptr) || !(*n))
- return NULL;
- s = *saveptr;
- }
-
- for (; *n && strchr(delim, *s); s++, (*n)--) {
- if (*s == '/' && *n > 1) {
- if (s[1] == '/') {
- do {
- s++, (*n)--;
- } while (*n > 1 && s[1] != '\n' && s[1] != '\r');
- } else if (s[1] == '*') {
- do {
- s++, (*n)--;
- } while (*n > 2 && (s[1] != '*' || s[2] != '/'));
- s++, (*n)--;
- }
- }
- }
-
- start = s;
- for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
- if (*n > 0)
- s++, (*n)--;
-
- *saveptr = s;
-
- retlen = s - start;
- ret = malloc(retlen + 1);
- p = ret;
-
- while (retlen > 0) {
- if (*start == '/' && retlen > 1) {
- if (start[1] == '/') {
- do {
- start++, retlen--;
- } while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
- start++, retlen--;
- continue;
- } else if (start[1] == '*') {
- do {
- start++, retlen--;
- } while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
- start += 3, retlen -= 3;
- continue;
- }
- }
- *(p++) = *(start++), retlen--;
- }
-
- *p = 0;
- return ret;
-}
-
-static char *do_eglShaderPatch(const char *source, int length, int *patched_len)
-{
- char *saveptr = NULL;
- char *sp;
- char *p = NULL;
-
- if (!length)
- length = strlen(source);
-
- *patched_len = 0;
- int patched_size = length;
- char *patched = malloc(patched_size + 1);
-
- if (!patched)
- return NULL;
-
- p = opengl_strtok(source, &length, &saveptr, NULL);
- for (; p; p = opengl_strtok(0, &length, &saveptr, p)) {
- if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) {
- continue;
- } else if (!strncmp(p, "precision", 9)) {
- while ((p = opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
- } else {
- if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) {
- p = "(gl_MaxVertexUniformComponents / 4)";
- } else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) {
- p = "(gl_MaxFragmentUniformComponents / 4)";
- } else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) {
- p = "(gl_MaxVaryingFloats / 4)";
- }
-
- int new_len = strlen(p);
- if (*patched_len + new_len > patched_size) {
- patched_size *= 2;
- patched = realloc(patched, patched_size + 1);
-
- if (!patched)
- return NULL;
- }
-
- memcpy(patched + *patched_len, p, new_len);
- *patched_len += new_len;
- }
- }
-
- patched[*patched_len] = 0;
- /* check that we don't leave dummy preprocessor lines */
- for (sp = patched; *sp;) {
- for (; *sp == ' ' || *sp == '\t'; sp++);
- if (!strncmp(sp, "#define", 7)) {
- for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
- if (*p == '\n' || *p == '\r' || *p == '/') {
- memset(sp, 0x20, 7);
- }
- }
- for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
- for (; *sp == '\n' || *sp == '\r'; sp++);
- }
- return patched;
-}
-
-static int
-shadersrc_gles_to_gl(GLsizei count, const char** string, char **s, const GLint* length, GLint *l)
-{
- int i;
-
- for(i = 0; i < count; ++i) {
- GLint len;
- if(length) {
- len = length[i];
- if (len < 0)
- len = string[i] ? strlen(string[i]) : 0;
- } else
- len = string[i] ? strlen(string[i]) : 0;
-
- if(string[i]) {
- s[i] = do_eglShaderPatch(string[i], len, &l[i]);
- if(!s[i]) {
- while(i)
- free(s[--i]);
-
- free(l);
- free(s);
- return -1;
- }
- } else {
- s[i] = NULL;
- l[i] = 0;
- }
- }
-
- return 0;
-}
-
-int do_function_call(OGLS_Conn *pConn, int func_number, int pid, long* args, char* ret_string)
-{
- char ret_char = 0;
- int ret_int = 0;
- const char* ret_str = NULL;
- int iProcess;
- ProcessStruct* process = NULL;
- ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
-
- if (pConn->parent_dpy)
- {
- pConn->Display = pConn->parent_dpy;
- }
-
- for(iProcess=0;iProcess<MAX_HANDLED_PROCESS;iProcess++)
- {
- ProcessStruct *processTab = (ProcessStruct *) pConn->processTab;
- if (processTab[iProcess].process_id == pid)
- {
- process = &processTab[iProcess];
- break;
- }
- else if (processTab[iProcess].process_id == 0)
- {
- process = &processTab[iProcess];
- memset(process, 0, sizeof(ProcessStruct));
- process->process_id = pid;
- process->internal_num = pConn->last_assigned_internal_num++;
- init_gl_state(&process->default_state);
- process->current_state = &process->default_state;
- break;
- }
- }
- if (process == NULL)
- {
- fprintf(stderr, "Too many processes !\n");
- return 0;
- }
- if (process->internal_num != pConn->last_active_internal_num)
- {
- glXMakeCurrent(pConn->Display, process->current_state->drawable, process->current_state->context);
- pConn->last_active_internal_num = process->internal_num;
- }
-
- process->instr_counter++;
-
- if (display_function_call) fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
- //fprintf(stderr, "[%d]> %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
-
- switch (func_number)
- {
- case _init_func:
- {
- *(int*)args[1] = 1;
- break;
- }
-
- case _synchronize_func:
- {
- ret_int = 1;
- break;
- }
-
- case _exit_process_func:
- {
- int i;
-
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakecontext_glxcontext[i].key != NULL;i++)
- {
- GLXContext ctxt = process->association_fakecontext_glxcontext[i].value;
- //fprintf(stderr, "Destroy context corresponding to fake_context = %ld\n",
- // (long)process->association_fakecontext_glxcontext[i].key);
- glXDestroyContext(pConn->Display, ctxt);
- }
-
- GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
- for(i=0;i < MAX_ASSOC_SIZE && process->association_fakepbuffer_pbuffer[i].key != NULL;i++)
- {
- GLXPbuffer pbuffer = (GLXPbuffer)process->association_fakepbuffer_pbuffer[i].value;
- fprintf(stderr, "Destroy pbuffer corresponding to fake_pbuffer = %ld\n",
- (long)process->association_fakepbuffer_pbuffer[i].key);
- if (!is_gl_vendor_ati(pConn->Display))
- ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
- }
-
- for(i=0;i < MAX_ASSOC_SIZE && process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- //fprintf(stderr, "Destroy window corresponding to client_drawable = %p\n",
- // process->association_clientdrawable_serverdrawable[i].key);
-
- Window win = (Window)process->association_clientdrawable_serverdrawable[i].value;
- XDestroyWindow(pConn->Display, win);
-
- int loop = 1;
- while (loop) {
- while (XPending(pConn->Display) > 0) {
- XEvent event;
- XNextEvent(pConn->Display, &event);
- switch (event.type) {
- case DestroyNotify:
- {
- if (((XDestroyWindowEvent*)&event)->window == win)
- {
- loop = 0;
- }
- break;
- }
- }
- }
- }
- }
-
- for(i=0;i<process->nbGLStates;i++)
- {
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- }
- destroy_gl_state(&process->default_state);
- free(process->glstates);
-
- pConn->active_win = 0;
-
- memmove(&processTab[iProcess], &processTab[iProcess+1], (MAX_HANDLED_PROCESS - 1 - iProcess) * sizeof(ProcessStruct));
-
- last_process_id = 0;
-
- break;
- }
-
- case _changeWindowState_func:
- {
- GLXDrawable client_drawable = args[0];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable)
- {
- if (args[1] == IsViewable)
- {
- WindowPosStruct pos;
- _get_window_pos(pConn->Display, drawable, &pos);
- if (pos.map_state != args[1])
- {
- XMapWindow(pConn->Display, drawable);
-
- int loop = 0; //1;
- while (loop) {
- while (XPending(pConn->Display) > 0) {
- XEvent event;
- XNextEvent(pConn->Display, &event);
- switch (event.type) {
- case ConfigureNotify:
- {
- if (((XConfigureEvent*)&event)->window == drawable)
- {
- loop = 0;
- }
- break;
- }
- }
- }
- }
- }
- }
- }
-
- break;
- }
-
- case _moveResizeWindow_func:
- {
- int* params = (int*)args[1];
- GLXDrawable client_drawable = args[0];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable)
- {
- WindowPosStruct pos;
- _get_window_pos(pConn->Display, drawable, &pos);
- if (!(params[0] == pos.x && params[1] == pos.y && params[2] == pos.width && params[3] == pos.height))
- {
- int redim = !(params[2] == pos.width && params[3] == pos.height);
- pConn->active_win_x = params[0];
- pConn->active_win_y = params[1];
-
- /*
- fprintf(stderr, "old x=%d y=%d width=%d height=%d\n", pos.x, pos.y, pos.width, pos.height);
- fprintf(stderr, "new x=%d y=%d width=%d height=%d\n", params[0], params[1], params[2], params[3]);
- */
-
- XMoveResizeWindow(pConn->Display, drawable, params[0], params[1], params[2], params[3]);
- _get_window_pos(pConn->Display, drawable, &pos);
- process->currentDrawablePos = pos;
- //if (getenv("FORCE_GL_VIEWPORT"))
- if (redim)
- glViewport(0, 0, params[2], params[3]);
- int loop = 0; //1;
- while (loop) {
- while (XPending(pConn->Display) > 0) {
- XEvent event;
- XNextEvent(pConn->Display, &event);
- switch (event.type) {
- case ConfigureNotify:
- {
- if (((XConfigureEvent*)&event)->window == drawable)
- {
- loop = 0;
- }
- break;
- }
- }
- }
- }
- }
- }
- break;
- }
-
- case _send_cursor_func:
- {
- int x = args[0];
- int y = args[1];
- int width = args[2];
- int height = args[3];
- int xhot = args[4];
- int yhot = args[5];
- int* pixels = (int*)args[6];
- client_cursor.x = x;
- client_cursor.y = y;
- client_cursor.width = width;
- client_cursor.height = height;
- client_cursor.xhot = xhot;
- client_cursor.yhot = yhot;
- if (pixels)
- {
- client_cursor.pixels = realloc(client_cursor.pixels, client_cursor.width * client_cursor.height * sizeof(int));
- memcpy(client_cursor.pixels, pixels, client_cursor.width * client_cursor.height * sizeof(int));
- }
- //int in_window = (x >= 0 && y >= 0 &&
- //x < process->currentDrawablePos.width &&
- //y < process->currentDrawablePos.height);
- //fprintf(stderr, "cursor at %d %d (%s)\n", x, y, (in_window) ? "in window" : "not in window");
- break;
- }
-
- case glXWaitGL_func:
- {
- glXWaitGL();
- ret_int = 0;
- break;
- }
-
- case glXWaitX_func:
- {
- glXWaitX();
- ret_int = 0;
- break;
- }
-
- case glXChooseVisual_func:
- {
- ret_int = glXChooseVisualFunc(pConn, (int*)args[2]);
- break;
- }
-
- case glXQueryExtensionsString_func:
- {
- ret_str = glXQueryExtensionsString(pConn->Display, 0);
- break;
- }
-
- case glXQueryServerString_func:
- {
- ret_str = glXQueryServerString(pConn->Display, 0, args[2]);
- break;
- }
-
- case glXGetClientString_func:
- {
- ret_str = glXGetClientString(pConn->Display, args[1]);
- break;
- }
-
- case glXGetScreenDriver_func:
- {
- GET_EXT_PTR(const char*, glXGetScreenDriver, (Display* , int ));
- ret_str = ptr_func_glXGetScreenDriver(pConn->Display, 0);
- break;
- }
-
- case glXGetDriverConfig_func:
- {
- GET_EXT_PTR(const char*, glXGetDriverConfig, (const char* ));
- ret_str = ptr_func_glXGetDriverConfig((const char*)args[0]);
- break;
- }
-
- case glXCreateContext_func:
- {
- int visualid = (int)args[1];
- int fake_shareList = (int)args[2];
- if (1 || display_function_call) fprintf(stderr, "visualid=%d, fake_shareList=%d\n", visualid, fake_shareList);
-
- GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
- XVisualInfo* vis = get_visual_info_from_visual_id(pConn, visualid);
- GLXContext ctxt;
- if (vis)
- {
- ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
- }
- else
- {
- vis = get_default_visual(pConn->Display);
- int saved_visualid = vis->visualid;
- vis->visualid = (visualid) ? visualid : saved_visualid;
- ctxt = glXCreateContext(pConn->Display, vis, shareList, args[3]);
- vis->visualid = saved_visualid;
- }
-
- if (ctxt)
- {
- process->next_available_context_number ++;
- int fake_ctxt = process->next_available_context_number;
- set_association_fakecontext_visual(process, (void*)(long)fake_ctxt, vis);
- set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
- ret_int = fake_ctxt;
-
- _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
- }
- else
- {
- ret_int = 0;
- }
-
- break;
- }
-
-
- case glXCreateNewContext_func:
- {
- GET_EXT_PTR(GLXContext, glXCreateNewContext, (Display*, GLXFBConfig, int, GLXContext, int));
- GET_EXT_PTR(XVisualInfo*, glXGetVisualFromFBConfig, (Display*, GLXFBConfig));
- int client_fbconfig = args[1];
- XVisualInfo* vis = NULL;
-
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- {
- int fake_shareList = args[3];
- GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)(long)fake_shareList);
- process->next_available_context_number ++;
- int fake_ctxt = process->next_available_context_number;
- GLXContext ctxt = ptr_func_glXCreateNewContext(pConn->Display, fbconfig, args[2], shareList, args[4]);
- set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
-
- vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig); /* visual info ????*/
- set_association_fakecontext_visual(process, (void *)(long)fake_ctxt, vis);
-
- ret_int = fake_ctxt;
-
- _create_context(process, ctxt, fake_ctxt, shareList, fake_shareList);
- }
- break;
- }
-
- case glXCopyContext_func:
- {
- GLXContext fake_src_ctxt = (GLXContext)args[1];
- GLXContext fake_dst_ctxt = (GLXContext)args[2];
- GLXContext src_ctxt;
- GLXContext dst_ctxt;
- if (display_function_call) fprintf(stderr, "fake_src_ctxt=%p, fake_dst_ctxt=%p\n", fake_src_ctxt, fake_dst_ctxt);
-
- if ((src_ctxt = get_association_fakecontext_glxcontext(process, fake_src_ctxt)) == NULL)
- {
- fprintf(stderr, "invalid fake_src_ctxt (%p) !\n", fake_src_ctxt);
- }
- else if ((dst_ctxt = get_association_fakecontext_glxcontext(process, fake_dst_ctxt)) == NULL)
- {
- fprintf(stderr, "invalid fake_dst_ctxt (%p) !\n", fake_dst_ctxt);
- }
- else
- {
- glXCopyContext(pConn->Display, src_ctxt, dst_ctxt, args[3]);
- }
- break;
- }
-
- case glXDestroyContext_func:
- {
- int fake_ctxt = (int)args[1];
- if (display_function_call) fprintf(stderr, "fake_ctxt=%d\n", fake_ctxt);
-
- GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%p) !\n", (void*)(long)fake_ctxt);
- }
- else
- {
- int i;
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_ctxt)
- {
- if (ctxt == process->current_state->context)
- process->current_state = &process->default_state;
-
- int fake_shareList = process->glstates[i]->fake_shareList;
- process->glstates[i]->ref --;
- if (process->glstates[i]->ref == 0)
- {
- fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
- process->nbGLStates--;
- }
-
- if (fake_shareList)
- {
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_shareList)
- {
- process->glstates[i]->ref --;
- if (process->glstates[i]->ref == 0)
- {
- fprintf(stderr, "destroy_gl_state fake_ctxt = %d\n", process->glstates[i]->fake_ctxt);
- destroy_gl_state(process->glstates[i]);
- free(process->glstates[i]);
- memmove(&process->glstates[i], &process->glstates[i+1], (process->nbGLStates-i-1) * sizeof(GLState*));
- process->nbGLStates--;
- }
- break;
- }
- }
- }
-
- glXDestroyContext(pConn->Display, ctxt);
- unset_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
-
- break;
- }
- }
- }
- break;
- }
-
- case glXQueryVersion_func:
- {
- ret_int = glXQueryVersion(pConn->Display, (int*)args[1], (int*)args[2]);
- break;
- }
-
- case glGetString_func:
- {
- ret_str = (char*)glGetString(args[0]);
- break;
- }
-
- case glXMakeCurrent_func:
- {
- int i;
- GLXDrawable client_drawable = (GLXDrawable)args[1];
- GLXDrawable drawable = 0;
- int fake_ctxt = args[2];
- if (display_function_call) fprintf(stderr, "client_drawable=%p fake_ctx=%d\n", (void*)client_drawable, fake_ctxt);
-
- if (client_drawable == 0 && fake_ctxt == 0)
- {
- ret_int = glXMakeCurrent(pConn->Display, 0, NULL);
- process->current_state = &process->default_state;
- }
- else if ((drawable = (GLXDrawable)get_association_fakepbuffer_pbuffer(process, (void*)client_drawable)))
- {
- GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%d) (*)!\n", fake_ctxt);
- ret_int = 0;
- }
- else
- {
- ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
- }
- }
- else
- {
- GLXContext ctxt = get_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%d)!\n", fake_ctxt);
- ret_int = 0;
- }
- else
- {
- drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable == 0)
- {
- XVisualInfo* vis = (XVisualInfo*)get_association_fakecontext_visual(process, (void*)(long)fake_ctxt);
- if (vis == NULL)
- vis = get_default_visual(pConn->Display);
- /*if (pConn->local_connection)
- drawable = client_drawable;
- else*/
- {
- if (/*pConn->local_connection &&*/ client_drawable == RootWindow(pConn->Display, 0))
- {
- drawable = client_drawable;
- }
- else
- {
- drawable = create_window(pConn, (pConn->local_connection) ? (Window)client_drawable : 0, vis, "", 0, 0, 480, 800);/* Default Window 크?綬�Simulator 크???? ?????磯?.*/
- }
- //fprintf(stderr, "creating window\n");
- }
- set_association_clientdrawable_serverdrawable(process, (void*)client_drawable, (void*)drawable);
- }
-
- ret_int = glXMakeCurrent(pConn->Display, drawable, ctxt);
- }
- }
-
- if (ret_int)
- {
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->fake_ctxt == fake_ctxt)
- {
- process->current_state = process->glstates[i]; /* HACK !!! REMOVE */
- process->current_state->drawable = drawable;
- break;
- }
- }
- }
- break;
- }
-
- case glXSwapBuffers_func:
- {
- GLXDrawable client_drawable = args[1];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (drawable == 0)
- {
- fprintf(stderr, "unknown client_drawable (%p) !\n", (void*)client_drawable);
- }
- else
- {
- if (client_cursor.pixels && pConn->local_connection == 0)
- {
- glPushAttrib(GL_ALL_ATTRIB_BITS);
- glPushClientAttrib(GL_ALL_ATTRIB_BITS);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(0,process->currentDrawablePos.width,process->currentDrawablePos.height,0,-1,1);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glPixelZoom(1,-1);
-
- glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
- glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
- glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- glShadeModel(GL_SMOOTH);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- int i,numUnits;
- glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &numUnits);
- for(i=0;i<numUnits;i++)
- {
- do_glActiveTextureARB(GL_TEXTURE0_ARB + i);
- glDisable(GL_TEXTURE_1D);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_TEXTURE_3D);
- }
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_FRAGMENT_PROGRAM_ARB);
- glDisable(GL_VERTEX_PROGRAM_ARB);
- do_glUseProgramObjectARB (0);
-
- //memset(client_cursor.pixels, 255, client_cursor.width * client_cursor.height * sizeof(int));
-
- glRasterPos2d(client_cursor.x - client_cursor.xhot,
- client_cursor.y - client_cursor.yhot);
- glDrawPixels(client_cursor.width, client_cursor.height,
- GL_BGRA, GL_UNSIGNED_BYTE,
- client_cursor.pixels);
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- glPopClientAttrib();
- glPopAttrib();
- }
-
- glXSwapBuffers(pConn->Display, drawable);
- }
- break;
- }
-
- case glXIsDirect_func:
- {
- GLXContext fake_ctxt = (GLXContext)args[1];
- if (display_function_call) fprintf(stderr, "fake_ctx=%p\n", fake_ctxt);
- GLXContext ctxt = get_association_fakecontext_glxcontext(process, fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%p) !\n", fake_ctxt);
- ret_char = False;
- }
- else
- {
- ret_char = glXIsDirect(pConn->Display, ctxt);
- }
- break;
- }
-
- case glXGetConfig_func:
- {
- int visualid = args[1];
- XVisualInfo* vis = NULL;
- if (visualid)
- vis = get_visual_info_from_visual_id(pConn, visualid);
- if (vis == NULL)
- vis = get_default_visual(pConn->Display);
- ret_int = glXGetConfig(pConn->Display, vis, args[2], (int*)args[3]);
- break;
- }
-
- case glXGetConfig_extended_func:
- {
- int visualid = args[1];
- int n = args[2];
- int i;
- XVisualInfo* vis = NULL;
- int* attribs = (int*)args[3];
- int* values = (int*)args[4];
- int* res = (int*)args[5];
-
- if (visualid)
- vis = get_visual_info_from_visual_id(pConn, visualid);
- if (vis == NULL)
- vis = get_default_visual(pConn->Display);
-
- for(i=0;i<n;i++)
- {
- res[i] = glXGetConfig(pConn->Display, vis, attribs[i], &values[i]);
- }
- break;
- }
-
- case glXUseXFont_func:
- {
- /* implementation is client-side only :-) */
- break;
- }
-
-
- case glXQueryExtension_func:
- {
- ret_int = glXQueryExtension(pConn->Display, (int*)args[1], (int*)args[2]);
- break;
- }
-
- case glXChooseFBConfig_func:
- {
- GET_EXT_PTR(GLXFBConfig*, glXChooseFBConfig, (Display*, int, int*, int*));
- if (process->nfbconfig == MAX_FBCONFIG)
- {
- *(int*)args[3] = 0;
- ret_int = 0;
- }
- else
- {
- GLXFBConfig* fbconfigs = ptr_func_glXChooseFBConfig(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
- if (fbconfigs)
- {
- process->fbconfigs[process->nfbconfig] = fbconfigs;
- process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
- process->nfbconfig++;
- ret_int = 1 + process->nfbconfig_total;
- process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
- }
- else
- {
- ret_int = 0;
- }
- }
- break;
- }
-
- case glXChooseFBConfigSGIX_func:
- {
- GET_EXT_PTR(GLXFBConfigSGIX*, glXChooseFBConfigSGIX, (Display*, int, int*, int*));
- if (process->nfbconfig == MAX_FBCONFIG)
- {
- *(int*)args[3] = 0;
- ret_int = 0;
- }
- else
- {
- GLXFBConfigSGIX* fbconfigs = ptr_func_glXChooseFBConfigSGIX(pConn->Display, args[1], (int*)args[2], (int*)args[3]);
- if (fbconfigs)
- {
- process->fbconfigs[process->nfbconfig] = fbconfigs;
- process->fbconfigs_max[process->nfbconfig] = *(int*)args[3];
- process->nfbconfig++;
- ret_int = 1 + process->nfbconfig_total;
- process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
- }
- else
- {
- ret_int = 0;
- }
- }
- break;
- }
-
- case glXGetFBConfigs_func:
- {
- GET_EXT_PTR(GLXFBConfig*, glXGetFBConfigs, (Display*, int, int*));
- if (process->nfbconfig == MAX_FBCONFIG)
- {
- *(int*)args[2] = 0;
- ret_int = 0;
- }
- else
- {
- GLXFBConfig* fbconfigs = ptr_func_glXGetFBConfigs(pConn->Display, args[1], (int*)args[2]);
- if (fbconfigs)
- {
- process->fbconfigs[process->nfbconfig] = fbconfigs;
- process->fbconfigs_max[process->nfbconfig] = *(int*)args[2];
- process->nfbconfig++;
- ret_int = 1 + process->nfbconfig_total;
- process->nfbconfig_total += process->fbconfigs_max[process->nfbconfig];
- }
- else
- {
- ret_int = 0;
- }
- }
- break;
- }
-
- case glXDestroyWindow_func:
- {
- GLXDrawable client_drawable = args[1];
- if (display_function_call) fprintf(stderr, "client_drawable=%p\n", (void*)client_drawable);
-
- GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
-
- destroy_window(pConn, (Window)drawable);
-
- int i;
- for(i=0;process->association_clientdrawable_serverdrawable[i].key != NULL;i++)
- {
- if (process->association_clientdrawable_serverdrawable[i].key == (void *) client_drawable)
- {
- process->association_clientdrawable_serverdrawable[i].key = NULL;
- process->association_clientdrawable_serverdrawable[i].value = NULL;
- }
- }
-
- for(i=0;i<process->nbGLStates;i++)
- {
- if (process->glstates[i]->drawable == drawable)
- {
- process->glstates[i]->drawable = 0;
- }
- }
-
- if( process->current_state->drawable == drawable )
- process->current_state = &process->default_state;
-
- break;
- }
-
-
- case glXCreatePbuffer_func:
- {
- GET_EXT_PTR(GLXPbuffer, glXCreatePbuffer, (Display*, GLXFBConfig, int*));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- {
- GLXPbuffer pbuffer = ptr_func_glXCreatePbuffer(pConn->Display, fbconfig, (int*)args[2]);
- fprintf(stderr, "glXCreatePbuffer --> %X\n", (int)pbuffer);
- if (pbuffer)
- {
- process->next_available_pbuffer_number ++;
- int fake_pbuffer = process->next_available_pbuffer_number;
- set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
- fprintf(stderr, "set_association_fakepbuffer_pbuffer(%d, %X)\n", fake_pbuffer, (int)pbuffer);
- ret_int = fake_pbuffer;
- }
- }
- break;
- }
-
- case glXCreateGLXPbufferSGIX_func:
- {
- GET_EXT_PTR(GLXPbufferSGIX, glXCreateGLXPbufferSGIX, (Display*, GLXFBConfig, int, int, int*));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- {
- GLXPbufferSGIX pbuffer = ptr_func_glXCreateGLXPbufferSGIX(pConn->Display, fbconfig, args[2], args[3], (int*)args[4]);
- if (pbuffer)
- {
- process->next_available_pbuffer_number ++;
- int fake_pbuffer = process->next_available_pbuffer_number;
- set_association_fakepbuffer_pbuffer(process, (void*)(long)fake_pbuffer, (void*)pbuffer);
- ret_int = fake_pbuffer;
- }
- }
- break;
- }
-
- case glXDestroyPbuffer_func:
- {
- GET_EXT_PTR(void, glXDestroyPbuffer, (Display*, GLXPbuffer));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
- else
- {
- if (!is_gl_vendor_ati(pConn->Display))
- ptr_func_glXDestroyPbuffer(pConn->Display, pbuffer);
- unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- }
- break;
- }
-
- case glXDestroyGLXPbufferSGIX_func:
- {
- GET_EXT_PTR(void, glXDestroyGLXPbufferSGIX, (Display*, GLXPbuffer));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
- else
- {
- if (!is_gl_vendor_ati(pConn->Display))
- ptr_func_glXDestroyGLXPbufferSGIX(pConn->Display, pbuffer);
- unset_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- }
- break;
- }
-
- case glXBindTexImageATI_func:
- {
- GET_EXT_PTR(void, glXBindTexImageATI, (Display*, GLXPbuffer, int));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "glXBindTexImageATI : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
- else
- {
- ptr_func_glXBindTexImageATI(pConn->Display, pbuffer, args[2]);
- }
- break;
- }
-
- case glXReleaseTexImageATI_func:
- {
- GET_EXT_PTR(void, glXReleaseTexImageATI, (Display*, GLXPbuffer, int));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "glXReleaseTexImageATI : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- }
- else
- {
- ptr_func_glXReleaseTexImageATI(pConn->Display, pbuffer, args[2]);
- }
- break;
- }
-
- case glXBindTexImageARB_func:
- {
- GET_EXT_PTR(Bool, glXBindTexImageARB, (Display*, GLXPbuffer, int));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "glXBindTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- ret_int = 0;
- }
- else
- {
- ret_int = ptr_func_glXBindTexImageARB(pConn->Display, pbuffer, args[2]);
- }
- break;
- }
-
- case glXReleaseTexImageARB_func:
- {
- GET_EXT_PTR(Bool, glXReleaseTexImageARB, (Display*, GLXPbuffer, int));
- GLXPbuffer fake_pbuffer = (GLXPbuffer)args[1];
- if (display_function_call) fprintf(stderr, "fake_pbuffer=%d\n", (int)fake_pbuffer);
-
- GLXPbuffer pbuffer = (GLXPbuffer)get_association_fakepbuffer_pbuffer(process, (void*)fake_pbuffer);
- if (pbuffer == 0)
- {
- fprintf(stderr, "glXReleaseTexImageARB : invalid fake_pbuffer (%d) !\n", (int)fake_pbuffer);
- ret_int = 0;
- }
- else
- {
- ret_int = ptr_func_glXReleaseTexImageARB(pConn->Display, pbuffer, args[2]);
- }
- break;
- }
-
- case glXGetFBConfigAttrib_func:
- {
- GET_EXT_PTR(int, glXGetFBConfigAttrib, (Display*, GLXFBConfig, int, int*));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- ret_int = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, args[2], (int*)args[3]);
- break;
- }
-
- case glXGetFBConfigAttrib_extended_func:
- {
- GET_EXT_PTR(int, glXGetFBConfigAttrib, (Display*, GLXFBConfig, int, int*));
- int client_fbconfig = args[1];
- int n = args[2];
- int i;
- int* attribs = (int*)args[3];
- int* values = (int*)args[4];
- int* res = (int*)args[5];
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
-
- for(i=0;i<n;i++)
- {
- if (fbconfig)
- {
- res[i] = ptr_func_glXGetFBConfigAttrib(pConn->Display, fbconfig, attribs[i], &values[i]);
- }
- else
- {
- res[i] = 0;
- }
- }
- break;
- }
-
- case glXGetFBConfigAttribSGIX_func:
- {
- GET_EXT_PTR(int, glXGetFBConfigAttribSGIX, (Display*, GLXFBConfigSGIX, int, int*));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- ret_int = ptr_func_glXGetFBConfigAttribSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
- break;
- }
-
- case glXQueryContext_func:
- {
- GET_EXT_PTR(int, glXQueryContext, (Display*, GLXContext, int, int*));
- GLXContext fake_ctxt = (GLXContext)args[1];
- if (display_function_call) fprintf(stderr, "fake_ctx=%p\n", fake_ctxt);
- GLXContext ctxt = get_association_fakecontext_glxcontext(process, fake_ctxt);
- if (ctxt == NULL)
- {
- fprintf(stderr, "invalid fake_ctxt (%p) !\n", fake_ctxt);
- ret_int = 0;
- }
- else
- {
- ret_int = ptr_func_glXQueryContext(pConn->Display, ctxt, args[2], (int*)args[3]);
- }
- break;
- }
-
- case glXQueryDrawable_func:
- {
- GET_EXT_PTR(void, glXQueryDrawable, (Display*, GLXDrawable, int, int*));
- GLXDrawable client_drawable = (GLXDrawable)args[1];
- GLXDrawable drawable = get_association_clientdrawable_serverdrawable(process, client_drawable);
- if (display_function_call) fprintf(stderr, "client_drawable=%d\n", (int)client_drawable);
- if (drawable == 0)
- {
- fprintf(stderr, "invalid client_drawable (%d) !\n", (int)client_drawable);
- }
- else
- {
- ptr_func_glXQueryDrawable(pConn->Display, drawable, args[2], (int*)args[3]);
- }
- break;
- }
-
- case glXQueryGLXPbufferSGIX_func:
- {
- GET_EXT_PTR(int, glXQueryGLXPbufferSGIX, (Display*, GLXFBConfigSGIX, int, int*));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- ret_int = ptr_func_glXQueryGLXPbufferSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], (int*)args[3]);
- break;
- }
-
- case glXCreateContextWithConfigSGIX_func:
- {
- GET_EXT_PTR(GLXContext, glXCreateContextWithConfigSGIX, (Display*, GLXFBConfigSGIX, int, GLXContext, int));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- {
- GLXContext shareList = get_association_fakecontext_glxcontext(process, (void*)args[3]);
- process->next_available_context_number ++;
- int fake_ctxt = process->next_available_context_number;
- GLXContext ctxt = ptr_func_glXCreateContextWithConfigSGIX(pConn->Display, (GLXFBConfigSGIX)fbconfig, args[2], shareList, args[4]);
- set_association_fakecontext_glxcontext(process, (void*)(long)fake_ctxt, ctxt);
- ret_int = fake_ctxt;
- }
- break;
- }
-
- case glXGetVisualFromFBConfig_func:
- {
- GET_EXT_PTR(XVisualInfo*, glXGetVisualFromFBConfig, (Display*, GLXFBConfig));
- int client_fbconfig = args[1];
- ret_int = 0;
- GLXFBConfig fbconfig = get_fbconfig(process, client_fbconfig);
- if (fbconfig)
- {
- AssocAttribListVisual *tabAssocAttribListVisual = (AssocAttribListVisual *)pConn->tabAssocAttribListVisual ;
- XVisualInfo* vis = ptr_func_glXGetVisualFromFBConfig(pConn->Display, fbconfig);
- ret_int = (vis) ? vis->visualid : 0;
- if (vis)
- {
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual =
- realloc(tabAssocAttribListVisual, sizeof(AssocAttribListVisual) * (pConn->nTabAssocAttribListVisual+1));
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribListLength = 0;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].attribList = NULL;
- tabAssocAttribListVisual[pConn->nTabAssocAttribListVisual].visInfo = vis;
- pConn->nTabAssocAttribListVisual++;
- pConn->tabAssocAttribListVisual = tabAssocAttribListVisual;
- }
- if (display_function_call) fprintf(stderr, "visualid = %d\n", ret_int);
- }
- break;
- }
-
- case glXSwapIntervalSGI_func:
- {
- GET_EXT_PTR(int, glXSwapIntervalSGI, (int));
- ret_int = ptr_func_glXSwapIntervalSGI(args[0]);
- break;
- }
-
- case glXGetProcAddress_fake_func:
- {
- if (display_function_call) fprintf(stderr, "%s\n", (char*)args[0]);
- ret_int = glXGetProcAddressARB((const GLubyte*)args[0]) != NULL;
- break;
- }
-
- case glXGetProcAddress_global_fake_func:
- {
- int nbElts = args[0];
- char* huge_buffer = (char*)args[1];
- char* result = (char*)args[2];
- int i;
-
- for(i=0;i<nbElts;i++)
- {
- int len = strlen(huge_buffer);
- result[i] = glXGetProcAddressARB((const GLubyte*)huge_buffer) != NULL;
- huge_buffer += len + 1;
- }
- break;
- }
-
- /* Begin of texture stuff */
- case glBindTexture_func:
- case glBindTextureEXT_func:
- {
- int target = args[0];
- unsigned int client_texture = args[1];
- unsigned int server_texture;
-
- if (client_texture == 0)
- {
- glBindTexture(target, 0);
- }
- else
- {
- alloc_value(process->current_state->textureAllocator, client_texture);
- server_texture = process->current_state->tabTextures[client_texture];
- if (server_texture == 0)
- {
- glGenTextures(1, &server_texture);
- process->current_state->tabTextures[client_texture] = server_texture;
- }
- glBindTexture(target, server_texture);
- }
- break;
- }
-
- case glGenTextures_fake_func:
- {
- GET_EXT_PTR(void, glGenTextures, (GLsizei n, GLuint *textures));
- int i;
- int n = args[0];
- unsigned int* clientTabTextures = malloc(n * sizeof(int));
- unsigned int* serverTabTextures = malloc(n * sizeof(int));
-
- alloc_range(process->current_state->textureAllocator, n, clientTabTextures);
-
- ptr_func_glGenTextures(n, serverTabTextures);
- for(i=0;i<n;i++)
- {
- process->current_state->tabTextures[clientTabTextures[i]] = serverTabTextures[i];
- }
-
- free(clientTabTextures);
- free(serverTabTextures);
- break;
- }
-
-
- case glDeleteTextures_func:
- {
- GET_EXT_PTR(void, glDeleteTextures, (GLsizei n, const GLuint *textures));
- int i;
- int n = args[0];
- unsigned int* clientTabTextures = (unsigned int*)args[1];
-
- delete_range(process->current_state->textureAllocator, n, clientTabTextures);
-
- unsigned int* serverTabTextures = malloc(n * sizeof(int));
- for(i=0;i<n;i++)
- {
- serverTabTextures[i] = get_server_texture(process, clientTabTextures[i]);
- }
- ptr_func_glDeleteTextures(n, serverTabTextures);
- for(i=0;i<n;i++)
- {
- process->current_state->tabTextures[clientTabTextures[i]] = 0;
- }
- free(serverTabTextures);
- break;
- }
-
- case glPrioritizeTextures_func:
- {
- GET_EXT_PTR(void, glPrioritizeTextures, (GLsizei n, const GLuint *textures, const GLclampf *priorities));
-
- int i;
- int n = args[0];
- unsigned int* textures = (unsigned int*)args[1];
- for(i=0;i<n;i++)
- {
- textures[i] = get_server_texture(process, textures[i]);
- }
- ptr_func_glPrioritizeTextures(n, textures, (const GLclampf*)args[2]);
- break;
- }
-
- case glAreTexturesResident_func:
- {
- GET_EXT_PTR(void, glAreTexturesResident, (GLsizei n, const GLuint *textures, GLboolean *residences));
- int i;
- int n = args[0];
- unsigned int* textures = (unsigned int*)args[1];
- for(i=0;i<n;i++)
- {
- textures[i] = get_server_texture(process, textures[i]);
- }
- ptr_func_glAreTexturesResident(n, textures, (GLboolean*)args[2]);
- break;
- }
-
- case glIsTexture_func:
- case glIsTextureEXT_func:
- {
- GET_EXT_PTR(GLboolean, glIsTexture, (GLuint texture ));
- unsigned int client_texture = args[0];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ret_char = ptr_func_glIsTexture(server_texture);
- else
- ret_char = 0;
- break;
- }
-
- case glFramebufferTexture1DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture1DEXT, (int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture1DEXT(args[0], args[1], args[2], server_texture, args[4]);
- break;
- }
-
- case glFramebufferTexture2DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture2DEXT, (int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture2DEXT(args[0], args[1], args[2], server_texture, args[4]);
- break;
- }
-
- case glFramebufferTexture3DEXT_func:
- {
- GET_EXT_PTR(void, glFramebufferTexture3DEXT, (int, int, int, int, int, int));
- unsigned int client_texture = args[3];
- unsigned int server_texture = get_server_texture(process, client_texture);
- if (server_texture)
- ptr_func_glFramebufferTexture3DEXT(args[0], args[1], args[2], server_texture, args[4], args[5]);
- break;
- }
- /* End of texture stuff */
-
- /* Begin of list stuff */
- case glIsList_func:
- {
- unsigned int client_list = args[0];
- unsigned int server_list = get_server_list(process, client_list);
- if (server_list)
- ret_char = glIsList(server_list);
- else
- ret_char = 0;
- break;
- }
-
- case glDeleteLists_func:
- {
- int i;
- unsigned int first_client = args[0];
- int n = args[1];
-
- unsigned int first_server = get_server_list(process, first_client);
- for(i=0;i<n;i++)
- {
- if (get_server_list(process, first_client + i) != first_server + i)
- break;
- }
- if (i == n)
- {
- glDeleteLists(first_server, n);
- }
- else
- {
- for(i=0;i<n;i++)
- {
- glDeleteLists(get_server_list(process, first_client + i), 1);
- }
- }
-
- for(i=0;i<n;i++)
- {
- process->current_state->tabLists[first_client + i] = 0;
- }
- delete_consecutive_values(process->current_state->listAllocator, first_client, n);
- break;
- }
-
- case glGenLists_fake_func:
- {
- int i;
- int n = args[0];
- unsigned int server_first = glGenLists(n);
- if (server_first)
- {
- unsigned int client_first = alloc_range(process->current_state->listAllocator, n, NULL);
- for(i=0;i<n;i++)
- {
- process->current_state->tabLists[client_first + i] = server_first + i;
- }
- }
- break;
- }
-
- case glNewList_func:
- {
- unsigned int client_list = args[0];
- int mode = args[1];
- alloc_value(process->current_state->listAllocator, client_list);
- unsigned int server_list = get_server_list(process, client_list);
- if (server_list == 0)
- {
- server_list = glGenLists(1);
- process->current_state->tabLists[client_list] = server_list;
- }
- glNewList(server_list, mode);
- break;
- }
-
- case glCallList_func:
- {
- unsigned int client_list = args[0];
- unsigned int server_list = get_server_list(process, client_list);
- glCallList(server_list);
- break;
- }
-
- case glCallLists_func:
- {
- int i;
- int n = args[0];
- int type = args[1];
- const GLvoid* lists = (const GLvoid*)args[2];
- int* new_lists = malloc(sizeof(int) * n);
- for(i=0;i<n;i++)
- {
- new_lists[i] = get_server_list(process, translate_id(i, type, lists));
- }
- glCallLists(n, GL_UNSIGNED_INT, new_lists);
- free(new_lists);
- break;
- }
-
-
- /* End of list stuff */
-
- /* Begin of buffer stuff */
- case glBindBufferARB_func:
- {
- GET_EXT_PTR(void, glBindBufferARB, (int,int));
- int target = args[0];
- unsigned int client_buffer = args[1];
- unsigned int server_buffer;
-
- if (client_buffer == 0)
- {
- ptr_func_glBindBufferARB(target, 0);
- }
- else
- {
- server_buffer = get_server_buffer(process, client_buffer);
- ptr_func_glBindBufferARB(target, server_buffer);
- }
- break;
- }
-
- case glGenBuffersARB_fake_func:
- {
- GET_EXT_PTR(void, glGenBuffersARB, (int,unsigned int*));
- int i;
- int n = args[0];
- unsigned int* clientTabBuffers = malloc(n * sizeof(int));
- unsigned int* serverTabBuffers = malloc(n * sizeof(int));
-
- alloc_range(process->current_state->bufferAllocator, n, clientTabBuffers);
-
- ptr_func_glGenBuffersARB(n, serverTabBuffers);
- for(i=0;i<n;i++)
- {
- process->current_state->tabBuffers[clientTabBuffers[i]] = serverTabBuffers[i];
- }
-
- free(clientTabBuffers);
- free(serverTabBuffers);
- break;
- }
-
-
- case glDeleteBuffersARB_func:
- {
- GET_EXT_PTR(void, glDeleteBuffersARB, (int,int*));
- int i;
- int n = args[0];
- unsigned int* clientTabBuffers = (unsigned int*)args[1];
-
- delete_range(process->current_state->bufferAllocator, n, clientTabBuffers);
-
- int* serverTabBuffers = malloc(n * sizeof(int));
- for(i=0;i<n;i++)
- {
- serverTabBuffers[i] = get_server_buffer(process, clientTabBuffers[i]);
- }
- ptr_func_glDeleteBuffersARB(n, serverTabBuffers);
- for(i=0;i<n;i++)
- {
- process->current_state->tabBuffers[clientTabBuffers[i]] = 0;
- }
- free(serverTabBuffers);
- break;
- }
-
- case glIsBufferARB_func:
- {
- GET_EXT_PTR(int, glIsBufferARB, (int));
- unsigned int client_buffer = args[0];
- unsigned int server_buffer = get_server_buffer(process, client_buffer);
- if (server_buffer)
- ret_int = ptr_func_glIsBufferARB(server_buffer);
- else
- ret_int = 0;
- break;
- }
-
- /* Endo of buffer stuff */
-
- case glShaderSourceARB_fake_func:
- {
- GET_EXT_PTR(void, glShaderSourceARB, (int,int,char**,void*));
- int size = args[1];
- int i;
- int acc_length = 0;
- GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
- int* tab_length = (int*)args[3];
- for(i=0;i<size;i++)
- {
- tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
- acc_length += tab_length[i];
- }
- ptr_func_glShaderSourceARB(args[0], args[1], tab_prog, tab_length);
- free(tab_prog);
- break;
- }
-
- case glShaderSource_fake_func:
- {
- GET_EXT_PTR(void, glShaderSource, (int,int,char**,void*));
- int size = args[1];
- int i;
- int acc_length = 0;
- GLcharARB** tab_prog = malloc(size * sizeof(GLcharARB*));
- int* tab_length = (int*)args[3];
-
- char **tab_prog_new;
- GLint *tab_length_new;
-
- tab_prog_new = malloc(args[1]* sizeof(char*));
- tab_length_new = malloc(args[1]* sizeof(GLint));
-
- memset(tab_prog_new, 0, args[1] * sizeof(char*));
- memset(tab_length_new, 0, args[1] * sizeof(GLint));
-
-
- for(i=0;i<size;i++)
- {
- tab_prog[i] = ((GLcharARB*)args[2]) + acc_length;
- acc_length += tab_length[i];
- }
-
- shadersrc_gles_to_gl(args[1], tab_prog, tab_prog_new, tab_length, tab_length_new);
-
- if (!tab_prog_new || !tab_length_new)
- break;
-
- ptr_func_glShaderSource(args[0], args[1], tab_prog_new, tab_length_new);
-
- for (i = 0; i < args[1]; i++)
- free(tab_prog_new[i]);
- free(tab_prog_new);
- free(tab_length_new);
-
- free(tab_prog);
- break;
- }
-
- case glVertexPointer_fake_func:
- {
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glVertexPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- glVertexPointer(size, type, stride, process->current_state->vertexPointer);
- break;
- }
-
- case glNormalPointer_fake_func:
- {
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->normalPointerSize = MAX(process->current_state->normalPointerSize, offset + bytes_size);
- process->current_state->normalPointer = realloc(process->current_state->normalPointer, process->current_state->normalPointerSize);
- memcpy(process->current_state->normalPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glNormalPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- glNormalPointer(type, stride, process->current_state->normalPointer);
- break;
- }
-
- case glIndexPointer_fake_func:
- {
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->indexPointerSize = MAX(process->current_state->indexPointerSize, offset + bytes_size);
- process->current_state->indexPointer = realloc(process->current_state->indexPointer, process->current_state->indexPointerSize);
- memcpy(process->current_state->indexPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glIndexPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- glIndexPointer(type, stride, process->current_state->indexPointer);
- break;
- }
-
- case glEdgeFlagPointer_fake_func:
- {
- int offset = args[0];
- int stride = args[1];
- int bytes_size = args[2];
- process->current_state->edgeFlagPointerSize = MAX(process->current_state->edgeFlagPointerSize, offset + bytes_size);
- process->current_state->edgeFlagPointer = realloc(process->current_state->edgeFlagPointer, process->current_state->edgeFlagPointerSize);
- memcpy(process->current_state->edgeFlagPointer + offset, (void*)args[3], bytes_size );
- //fprintf(stderr, "glEdgeFlagPointer_fake_func stride = %d, bytes_size=%d\n", stride, bytes_size);
- glEdgeFlagPointer(stride, process->current_state->edgeFlagPointer);
- break;
- }
-
- case glVertexAttribPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int normalized = args[4];
- int stride = args[5];
- int bytes_size = args[6];
- process->current_state->vertexAttribPointerSize[index] = MAX(process->current_state->vertexAttribPointerSize[index], offset + bytes_size);
- process->current_state->vertexAttribPointer[index] = realloc(process->current_state->vertexAttribPointer[index],
- process->current_state->vertexAttribPointerSize[index]);
- memcpy(process->current_state->vertexAttribPointer[index] + offset, (void*)args[7], bytes_size);
- ptr_func_glVertexAttribPointerARB(index, size, type, normalized, stride,
- process->current_state->vertexAttribPointer[index]);
- break;
- }
-
- case glVertexAttribPointerNV_fake_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerNV, (int,int,int,int,void*));
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int stride = args[4];
- int bytes_size = args[5];
- process->current_state->vertexAttribPointerNVSize[index] = MAX(process->current_state->vertexAttribPointerNVSize[index], offset + bytes_size);
- process->current_state->vertexAttribPointerNV[index] = realloc(process->current_state->vertexAttribPointerNV[index],
- process->current_state->vertexAttribPointerNVSize[index]);
- memcpy(process->current_state->vertexAttribPointerNV[index] + offset, (void*)args[6], bytes_size);
- ptr_func_glVertexAttribPointerNV(index, size, type, stride,
- process->current_state->vertexAttribPointerNV[index]);
- break;
- }
-
- case glColorPointer_fake_func:
- {
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->colorPointerSize = MAX(process->current_state->colorPointerSize, offset + bytes_size);
- process->current_state->colorPointer = realloc(process->current_state->colorPointer, process->current_state->colorPointerSize);
- memcpy(process->current_state->colorPointer + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glColorPointer_fake_func bytes_size = %d\n", bytes_size);
- glColorPointer(size, type, stride, process->current_state->colorPointer);
-
- break;
- }
-
- case glSecondaryColorPointer_fake_func:
- {
- GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->secondaryColorPointerSize = MAX(process->current_state->secondaryColorPointerSize, offset + bytes_size);
- process->current_state->secondaryColorPointer = realloc(process->current_state->secondaryColorPointer, process->current_state->secondaryColorPointerSize);
- memcpy(process->current_state->secondaryColorPointer + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glSecondaryColorPointer_fake_func bytes_size = %d\n", bytes_size);
- ptr_func_glSecondaryColorPointer(size, type, stride, process->current_state->secondaryColorPointer);
-
- break;
- }
-
- case glPushClientAttrib_func:
- {
- int mask = args[0];
- if (process->current_state->clientStateSp < MAX_CLIENT_STATE_STACK_SIZE)
- {
- process->current_state->clientStateStack[process->current_state->clientStateSp].mask = mask;
- if (mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex =
- process->current_state->activeTextureIndex;
- }
- process->current_state->clientStateSp++;
- }
- glPushClientAttrib(mask);
- break;
- }
-
- case glPopClientAttrib_func:
- {
- if (process->current_state->clientStateSp > 0)
- {
- process->current_state->clientStateSp--;
- if (process->current_state->clientStateStack[process->current_state->clientStateSp].mask & GL_CLIENT_VERTEX_ARRAY_BIT)
- {
- process->current_state->activeTextureIndex =
- process->current_state->clientStateStack[process->current_state->clientStateSp].activeTextureIndex;
- }
- }
- glPopClientAttrib();
- break;
- }
-
- case glClientActiveTexture_func:
- case glClientActiveTextureARB_func:
- {
- int activeTexture = args[0];
- process->current_state->activeTextureIndex = activeTexture - GL_TEXTURE0_ARB;
- do_glClientActiveTextureARB(activeTexture);
- break;
- }
-
- case glTexCoordPointer_fake_func:
- {
- int offset = args[0];
- int index = args[1];
- int size = args[2];
- int type = args[3];
- int stride = args[4];
- int bytes_size = args[5];
- process->current_state->texCoordPointerSize[index] = MAX(process->current_state->texCoordPointerSize[index], offset + bytes_size);
- process->current_state->texCoordPointer[index] = realloc(process->current_state->texCoordPointer[index], process->current_state->texCoordPointerSize[index]);
- memcpy(process->current_state->texCoordPointer[index] + offset, (void*)args[6], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + index);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[index]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glWeightPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->weightPointerSize = MAX(process->current_state->weightPointerSize, offset + bytes_size);
- process->current_state->weightPointer = realloc(process->current_state->weightPointer, process->current_state->weightPointerSize);
- memcpy(process->current_state->weightPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glWeightPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- ptr_func_glWeightPointerARB(size, type, stride, process->current_state->weightPointer);
- break;
- }
-
- case glMatrixIndexPointerARB_fake_func:
- {
- GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
- int offset = args[0];
- int size = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->matrixIndexPointerSize = MAX(process->current_state->matrixIndexPointerSize, offset + bytes_size);
- process->current_state->matrixIndexPointer = realloc(process->current_state->matrixIndexPointer, process->current_state->matrixIndexPointerSize);
- memcpy(process->current_state->matrixIndexPointer + offset, (void*)args[5], bytes_size);
- /*fprintf(stderr, "glMatrixIndexPointerARB_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- ptr_func_glMatrixIndexPointerARB(size, type, stride, process->current_state->matrixIndexPointer);
- break;
- }
-
- case glFogCoordPointer_fake_func:
- {
- GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
- int offset = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->fogCoordPointerSize = MAX(process->current_state->fogCoordPointerSize, offset + bytes_size);
- process->current_state->fogCoordPointer = realloc(process->current_state->fogCoordPointer, process->current_state->fogCoordPointerSize);
- memcpy(process->current_state->fogCoordPointer + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glFogCoordPointer_fake_func type=%d, stride=%d, byte_size=%d\n", type, stride, bytes_size);
- ptr_func_glFogCoordPointer(type, stride, process->current_state->fogCoordPointer);
- break;
- }
-
- case glVariantPointerEXT_fake_func:
- {
- GET_EXT_PTR(void, glVariantPointerEXT, (int,int,int,void*));
- int offset = args[0];
- int id = args[1];
- int type = args[2];
- int stride = args[3];
- int bytes_size = args[4];
- process->current_state->variantPointerEXTSize[id] = MAX(process->current_state->variantPointerEXTSize[id], offset + bytes_size);
- process->current_state->variantPointerEXT[id] = realloc(process->current_state->variantPointerEXT[id], process->current_state->variantPointerEXTSize[id]);
- memcpy(process->current_state->variantPointerEXT[id] + offset, (void*)args[5], bytes_size);
- //fprintf(stderr, "glVariantPointerEXT_fake_func[%d] type=%d, stride=%d, byte_size=%d\n", id, type, stride, bytes_size);
- ptr_func_glVariantPointerEXT(id, type, stride, process->current_state->variantPointerEXT[id]);
- break;
- }
-
- case glInterleavedArrays_fake_func:
- {
- GET_EXT_PTR(void, glInterleavedArrays, (int,int,void*));
- int offset = args[0];
- int format = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->interleavedArraysSize = MAX(process->current_state->interleavedArraysSize, offset + bytes_size);
- process->current_state->interleavedArrays = realloc(process->current_state->interleavedArrays, process->current_state->interleavedArraysSize);
- memcpy(process->current_state->interleavedArrays + offset, (void*)args[4], bytes_size);
- //fprintf(stderr, "glInterleavedArrays_fake_func format=%d, stride=%d, byte_size=%d\n", format, stride, bytes_size);
- ptr_func_glInterleavedArrays(format, stride, process->current_state->interleavedArrays);
- break;
- }
-
- case glElementPointerATI_fake_func:
- {
- GET_EXT_PTR(void, glElementPointerATI, (int,void*));
- int type = args[0];
- int bytes_size = args[1];
- process->current_state->elementPointerATISize = bytes_size;
- process->current_state->elementPointerATI = realloc(process->current_state->elementPointerATI, process->current_state->elementPointerATISize);
- memcpy(process->current_state->elementPointerATI, (void*)args[2], bytes_size);
- //fprintf(stderr, "glElementPointerATI_fake_func type=%d, byte_size=%d\n", type, bytes_size);
- ptr_func_glElementPointerATI(type, process->current_state->elementPointerATI);
- break;
- }
-
- case glTexCoordPointer01_fake_func:
- {
- int size = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->texCoordPointerSize[0] = bytes_size;
- process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
- memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer01_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glTexCoordPointer012_fake_func:
- {
- int size = args[0];
- int type = args[1];
- int stride = args[2];
- int bytes_size = args[3];
- process->current_state->texCoordPointerSize[0] = bytes_size;
- process->current_state->texCoordPointer[0] = realloc(process->current_state->texCoordPointer[0], bytes_size);
- memcpy(process->current_state->texCoordPointer[0], (void*)args[4], bytes_size);
- /*fprintf(stderr, "glTexCoordPointer012_fake_func size=%d, type=%d, stride=%d, byte_size=%d\n",
- size, type, stride, bytes_size);*/
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(size, type, stride, process->current_state->texCoordPointer[0]);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
-
- case glVertexAndNormalPointer_fake_func:
- {
- int vertexPointerSize = args[0];
- int vertexPointerType = args[1];
- int vertexPointerStride = args[2];
- int normalPointerType = args[3];
- int normalPointerStride = args[4];
- int bytes_size = args[5];
- void* ptr = (void*)args[6];
- process->current_state->vertexPointerSize = bytes_size;
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, bytes_size);
- memcpy(process->current_state->vertexPointer, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, vertexPointerStride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, normalPointerStride, process->current_state->vertexPointer);
- break;
- }
-
- case glVertexNormalPointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset= args[i++];
- int normalPointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- break;
- }
-
- case glTuxRacerDrawElements_fake_func:
- {
- int mode = args[0];
- int count = args[1];
- int isColorEnabled = args[2];
- void* ptr = (void*)args[3];
- int stride = 6 * sizeof(float) + ((isColorEnabled) ? 4 * sizeof(unsigned char) : 0);
- glVertexPointer( 3, GL_FLOAT, stride, ptr);
- glNormalPointer( GL_FLOAT, stride, ptr + 3 * sizeof(float));
- if (isColorEnabled)
- glColorPointer( 4, GL_UNSIGNED_BYTE, stride, ptr + 6 * sizeof(float));
- glDrawArrays(mode, 0, count);
- break;
- }
-
- case glVertexNormalColorPointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset= args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- break;
- }
-
- case glVertexColorTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord01PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalTexCoord012PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int texCoord2PointerOffset = args[i++];
- int texCoord2PointerSize = args[i++];
- int texCoord2PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord0PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord01PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case glVertexNormalColorTexCoord012PointerInterlaced_fake_func:
- {
- int i = 0;
- int offset = args[i++];
- int vertexPointerSize = args[i++];
- int vertexPointerType = args[i++];
- int stride = args[i++];
- int normalPointerOffset = args[i++];
- int normalPointerType = args[i++];
- int colorPointerOffset = args[i++];
- int colorPointerSize = args[i++];
- int colorPointerType = args[i++];
- int texCoord0PointerOffset = args[i++];
- int texCoord0PointerSize = args[i++];
- int texCoord0PointerType = args[i++];
- int texCoord1PointerOffset = args[i++];
- int texCoord1PointerSize = args[i++];
- int texCoord1PointerType = args[i++];
- int texCoord2PointerOffset = args[i++];
- int texCoord2PointerSize = args[i++];
- int texCoord2PointerType = args[i++];
- int bytes_size = args[i++];
- void* ptr = (void*)args[i++];
- process->current_state->vertexPointerSize = MAX(process->current_state->vertexPointerSize, offset + bytes_size);
- process->current_state->vertexPointer = realloc(process->current_state->vertexPointer, process->current_state->vertexPointerSize);
- memcpy(process->current_state->vertexPointer + offset, ptr, bytes_size);
- glVertexPointer(vertexPointerSize, vertexPointerType, stride, process->current_state->vertexPointer);
- glNormalPointer(normalPointerType, stride, process->current_state->vertexPointer + normalPointerOffset);
- glColorPointer(colorPointerSize, colorPointerType, stride, process->current_state->vertexPointer + colorPointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
- glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType, stride, process->current_state->vertexPointer + texCoord0PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
- glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType, stride, process->current_state->vertexPointer + texCoord1PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
- glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType, stride, process->current_state->vertexPointer + texCoord2PointerOffset);
- do_glClientActiveTextureARB(GL_TEXTURE0_ARB + process->current_state->activeTextureIndex);
- break;
- }
-
- case _glVertexPointer_buffer_func:
- {
- glVertexPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glNormalPointer_buffer_func:
- {
- glNormalPointer(args[0],args[1],(void*)args[2]);
- break;
- }
-
- case _glColorPointer_buffer_func:
- {
- glColorPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glSecondaryColorPointer_buffer_func:
- {
- GET_EXT_PTR(void, glSecondaryColorPointer, (int,int,int,void*));
- ptr_func_glSecondaryColorPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glIndexPointer_buffer_func:
- {
- glIndexPointer(args[0],args[1],(void*)args[2]);
- break;
- }
-
- case _glTexCoordPointer_buffer_func:
- {
- glTexCoordPointer(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glEdgeFlagPointer_buffer_func:
- {
- glEdgeFlagPointer(args[0],(void*)args[1]);
- break;
- }
-
- case _glVertexAttribPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glVertexAttribPointerARB, (int,int,int,int,int,void*));
- ptr_func_glVertexAttribPointerARB(args[0], args[1], args[2], args[3], args[4], (void*)args[5]);
- break;
- }
-
- case _glWeightPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glWeightPointerARB, (int,int,int,void*));
- ptr_func_glWeightPointerARB(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glMatrixIndexPointerARB_buffer_func:
- {
- GET_EXT_PTR(void, glMatrixIndexPointerARB, (int,int,int,void*));
- ptr_func_glMatrixIndexPointerARB(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glFogCoordPointer_buffer_func:
- {
- GET_EXT_PTR(void, glFogCoordPointer, (int,int,void*));
- ptr_func_glFogCoordPointer(args[0], args[1], (void*)args[2]);
- break;
- }
-
- case _glVariantPointerEXT_buffer_func:
- {
- GET_EXT_PTR(void, glVariantPointerEXT, (int, int,int,void*));
- ptr_func_glVariantPointerEXT(args[0], args[1], args[2], (void*)args[3]);
- break;
- }
-
- case _glDrawElements_buffer_func:
- {
- glDrawElements(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case _glDrawRangeElements_buffer_func:
- {
- glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
- break;
- }
-
- case _glMultiDrawElements_buffer_func:
- {
- GET_EXT_PTR(void, glMultiDrawElements, (int,int*,int,void**, int));
- ptr_func_glMultiDrawElements(args[0],(int*)args[1],args[2],(void**)args[3],args[4]);
- break;
- }
-
- case _glGetError_fake_func:
- {
- break;
- }
-
- case glGetIntegerv_func:
- {
- glGetIntegerv(args[0], (int*)args[1]);
- //fprintf(stderr,"glGetIntegerv(%X)=%d\n", (int)args[0], *(int*)args[1]);
- break;
- }
-
- case _glReadPixels_pbo_func:
- {
- glReadPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (void*)(args[6]));
- break;
- }
-
- case _glDrawPixels_pbo_func:
- {
- glDrawPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_UNSIGNED_INT(args[2]), ARG_TO_UNSIGNED_INT(args[3]), (const void*)(args[4]));
- break;
- }
-
- case _glMapBufferARB_fake_func:
- {
- GET_EXT_PTR(GLvoid*, glMapBufferARB, (GLenum, GLenum));
- GET_EXT_PTR(GLboolean, glUnmapBufferARB, (GLenum));
- int target = args[0];
- int size = args[1];
- void* dst_ptr = (void*)args[2];
- void* src_ptr = ptr_func_glMapBufferARB(target, GL_READ_ONLY);
- if (src_ptr)
- {
- memcpy(dst_ptr, src_ptr, size);
- ret_int = ptr_func_glUnmapBufferARB(target);
- }
- else
- {
- ret_int = 0;
- }
- break;
- }
-
- case fake_gluBuild2DMipmaps_func:
- {
- GET_GLU_PTR(GLint, gluBuild2DMipmaps, (GLenum arg_0, GLint arg_1, GLsizei arg_2, GLsizei arg_3, GLenum arg_4, GLenum arg_5, const GLvoid * arg_6));
- if (ptr_func_gluBuild2DMipmaps == NULL)
- ptr_func_gluBuild2DMipmaps = mesa_gluBuild2DMipmaps;
- ptr_func_gluBuild2DMipmaps(ARG_TO_UNSIGNED_INT(args[0]), ARG_TO_INT(args[1]), ARG_TO_INT(args[2]), ARG_TO_INT(args[3]), ARG_TO_UNSIGNED_INT(args[4]), ARG_TO_UNSIGNED_INT(args[5]), (const void*)(args[6]));
- break;
- }
-
- case _glSelectBuffer_fake_func:
- {
- process->current_state->selectBufferSize = args[0] * 4;
- process->current_state->selectBufferPtr = realloc(process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
- glSelectBuffer(args[0], process->current_state->selectBufferPtr);
- break;
- }
-
- case _glGetSelectBuffer_fake_func:
- {
- void* ptr = (void*)args[0];
- memcpy(ptr, process->current_state->selectBufferPtr, process->current_state->selectBufferSize);
- break;
- }
-
- case _glFeedbackBuffer_fake_func:
- {
- process->current_state->feedbackBufferSize = args[0] * 4;
- process->current_state->feedbackBufferPtr = realloc(process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
- glFeedbackBuffer(args[0], args[1], process->current_state->feedbackBufferPtr);
- break;
- }
-
- case _glGetFeedbackBuffer_fake_func:
- {
- void* ptr = (void*)args[0];
- memcpy(ptr, process->current_state->feedbackBufferPtr, process->current_state->feedbackBufferSize);
- break;
- }
-
- /*
- case glEnableClientState_func:
- {
- if (display_function_call) fprintf(stderr, "cap : %s\n", nameArrays[args[0] - GL_VERTEX_ARRAY]);
- glEnableClientState(args[0]);
- break;
- }
-
- case glDisableClientState_func:
- {
- if (display_function_call) fprintf(stderr, "cap : %s\n", nameArrays[args[0] - GL_VERTEX_ARRAY]);
- glDisableClientState(args[0]);
- break;
- }
-
- case glClientActiveTexture_func:
- case glClientActiveTextureARB_func:
- {
- if (display_function_call) fprintf(stderr, "client activeTexture %d\n", args[0] - GL_TEXTURE0_ARB);
- glClientActiveTextureARB(args[0]);
- break;
- }
-
- case glActiveTextureARB_func:
- {
- if (display_function_call) fprintf(stderr, "server activeTexture %d\n", args[0] - GL_TEXTURE0_ARB);
- glActiveTextureARB(args[0]);
- break;
- }
-
- case glLockArraysEXT_func:
- break;
-
- case glUnlockArraysEXT_func:
- break;
-
- case glArrayElement_func:
- {
- glArrayElement(args[0]);
- break;
- }
-
- case glDrawArrays_func:
- {
- glDrawArrays(args[0],args[1],args[2]);
- break;
- }
-
- case glDrawElements_func:
- {
- glDrawElements(args[0],args[1],args[2],(void*)args[3]);
- break;
- }
-
- case glDrawRangeElements_func:
- {
- glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
- break;
- }
- */
-
- case glGetError_func:
- {
-#ifdef SYSTEMATIC_ERROR_CHECK
- ret_int = process->current_state->last_error;
-#else
- ret_int = glGetError();
-#endif
- break;
- }
-
- case glNewObjectBufferATI_func:
- {
- GET_EXT_PTR(int, glNewObjectBufferATI, (int,void*, int));
- ret_int = ptr_func_glNewObjectBufferATI(args[0], (void*)args[1], args[2]);
- break;
- }
-
- default:
- execute_func(func_number, args, &ret_int, &ret_char);
- break;
- }
-
-#ifdef SYSTEMATIC_ERROR_CHECK
- if (func_number == glGetError_func)
- {
- process->current_state->last_error = 0;
- }
- else
- {
- process->current_state->last_error = glGetError();
- if (process->current_state->last_error != 0)
- {
- printf("error %s 0x%X\n", tab_opengl_calls_name[func_number], process->current_state->last_error);
- }
- }
-#endif
-
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int ret_type = signature->ret_type;
- //int nb_args = signature->nb_args;
- switch(ret_type)
- {
- case TYPE_NONE:
- break;
-
- case TYPE_CHAR:
- case TYPE_UNSIGNED_CHAR:
- ret_int = ret_char;
- break;
-
- case TYPE_INT:
- case TYPE_UNSIGNED_INT:
- break;
-
- case TYPE_CONST_CHAR:
- {
- strncpy(ret_string, (ret_str) ? ret_str : "", 32768);
- break;
- }
-
- default:
- fprintf(stderr, "unexpected ret type : %d\n", ret_type);
- exit(-1);
- break;
- }
-
- if (display_function_call) fprintf(stderr, "[%d]< %s\n", process->instr_counter, tab_opengl_calls_name[func_number]);
-
- return ret_int;
-}
-#endif
-
-void create_process_tab( OGLS_Conn *pConn )
-{
- if (pConn == NULL) {
- fprintf(stderr, "create_process_tab: pConn is NULL.\n");
- return;
- }
- pConn->processTab = malloc( sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
- if( !pConn->processTab )
- {
- perror( "init_process_tab" );
- return ;
- }
-
- memset(pConn->processTab, 0, sizeof(ProcessStruct)*MAX_HANDLED_PROCESS );
-}
-
-void remove_process_tab( OGLS_Conn *pConn )
-{
- if( !pConn->processTab ) return ;
- free( pConn->processTab );
- pConn->processTab = NULL;
-}
+++ /dev/null
-/*
- * Main header for both host and guest sides
- *
- * Copyright (c) 2006,2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "mesa_gl.h"
-#include "mesa_glext.h"
-#include "opengl_server.h"
-
-/* To remove GCC warnings */
-//extern void opengl_exec_set_parent_window(Display* _dpy, Window _parent_window);
-extern void opengl_exec_set_parent_window(OGLS_Conn *pConn, Window _parent_window);
-extern void opengl_exec_set_local_connection(void);
-
-//#ifdef _WIN32
-//extern int do_function_call(Display dpy, int func_number, int pid, int* args, char* ret_string);
-//#else
-//extern int do_function_call(Display* dpy, int func_number, int pid, long* args, char* ret_string);
-//#endif
-
-extern int do_function_call(OGLS_Conn *, int, int, long*, char*);
-extern void execute_func(int func_number, long* args, int* pret_int, char* pret_char);
-extern void create_process_tab( OGLS_Conn *pConn );
-extern void remove_process_tab( OGLS_Conn *pConn );
-
-enum
-{
- TYPE_NONE,
- TYPE_CHAR,
- TYPE_UNSIGNED_CHAR,
- TYPE_SHORT,
- TYPE_UNSIGNED_SHORT,
- TYPE_INT,
- TYPE_UNSIGNED_INT,
- TYPE_FLOAT,
- TYPE_DOUBLE,
- TYPE_1CHAR,
- TYPE_2CHAR,
- TYPE_3CHAR,
- TYPE_4CHAR,
- TYPE_128UCHAR,
- TYPE_1SHORT,
- TYPE_2SHORT,
- TYPE_3SHORT,
- TYPE_4SHORT,
- TYPE_1INT,
- TYPE_2INT,
- TYPE_3INT,
- TYPE_4INT,
- TYPE_1FLOAT,
- TYPE_2FLOAT,
- TYPE_3FLOAT,
- TYPE_4FLOAT,
- TYPE_16FLOAT,
- TYPE_1DOUBLE,
- TYPE_2DOUBLE,
- TYPE_3DOUBLE,
- TYPE_4DOUBLE,
- TYPE_16DOUBLE,
- TYPE_OUT_1INT,
- TYPE_OUT_1FLOAT,
- TYPE_OUT_4CHAR,
- TYPE_OUT_4INT,
- TYPE_OUT_4FLOAT,
- TYPE_OUT_4DOUBLE,
- TYPE_OUT_128UCHAR,
- TYPE_CONST_CHAR,
- TYPE_ARRAY_CHAR,
- TYPE_ARRAY_SHORT,
- TYPE_ARRAY_INT,
- TYPE_ARRAY_FLOAT,
- TYPE_ARRAY_DOUBLE,
- TYPE_IN_IGNORED_POINTER,
- TYPE_OUT_ARRAY_CHAR,
- TYPE_OUT_ARRAY_SHORT,
- TYPE_OUT_ARRAY_INT,
- TYPE_OUT_ARRAY_FLOAT,
- TYPE_OUT_ARRAY_DOUBLE,
- TYPE_NULL_TERMINATED_STRING,
-
- TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- /* .... */
- TYPE_LAST,
- /* .... */
- TYPE_1UCHAR = TYPE_CHAR,
- TYPE_1USHORT = TYPE_1SHORT,
- TYPE_1UINT = TYPE_1INT,
- TYPE_OUT_1UINT = TYPE_OUT_1INT,
- TYPE_OUT_4UCHAR = TYPE_OUT_4CHAR,
- TYPE_ARRAY_VOID = TYPE_ARRAY_CHAR,
- TYPE_ARRAY_SIGNED_CHAR = TYPE_ARRAY_CHAR,
- TYPE_ARRAY_UNSIGNED_CHAR = TYPE_ARRAY_CHAR,
- TYPE_ARRAY_UNSIGNED_SHORT = TYPE_ARRAY_SHORT,
- TYPE_ARRAY_UNSIGNED_INT = TYPE_ARRAY_INT,
- TYPE_OUT_ARRAY_VOID = TYPE_OUT_ARRAY_CHAR,
- TYPE_OUT_ARRAY_SIGNED_CHAR = TYPE_OUT_ARRAY_CHAR,
- TYPE_OUT_ARRAY_UNSIGNED_CHAR = TYPE_OUT_ARRAY_CHAR,
- TYPE_OUT_ARRAY_UNSIGNED_SHORT = TYPE_OUT_ARRAY_SHORT,
- TYPE_OUT_ARRAY_UNSIGNED_INT = TYPE_OUT_ARRAY_INT,
- TYPE_ARRAY_VOID_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_SIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_UNSIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_UNSIGNED_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_ARRAY_UNSIGNED_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_VOID_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_SIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_UNSIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_UNSIGNED_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
- TYPE_OUT_ARRAY_UNSIGNED_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS = TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
-};
-
-#define CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS \
- case TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
-
-#define CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS \
- case TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_OUT_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
-case TYPE_OUT_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
-
-#define CASE_IN_UNKNOWN_SIZE_POINTERS \
- case TYPE_ARRAY_CHAR: \
-case TYPE_ARRAY_SHORT: \
-case TYPE_ARRAY_INT: \
-case TYPE_ARRAY_FLOAT: \
-case TYPE_ARRAY_DOUBLE
-
-#define CASE_IN_KNOWN_SIZE_POINTERS \
- case TYPE_1CHAR:\
-case TYPE_2CHAR:\
-case TYPE_3CHAR:\
-case TYPE_4CHAR:\
-case TYPE_128UCHAR:\
-case TYPE_1SHORT:\
-case TYPE_2SHORT:\
-case TYPE_3SHORT:\
-case TYPE_4SHORT:\
-case TYPE_1INT:\
-case TYPE_2INT:\
-case TYPE_3INT:\
-case TYPE_4INT:\
-case TYPE_1FLOAT:\
-case TYPE_2FLOAT:\
-case TYPE_3FLOAT:\
-case TYPE_4FLOAT:\
-case TYPE_16FLOAT:\
-case TYPE_1DOUBLE:\
-case TYPE_2DOUBLE:\
-case TYPE_3DOUBLE:\
-case TYPE_4DOUBLE:\
-case TYPE_16DOUBLE
-
-#define CASE_OUT_UNKNOWN_SIZE_POINTERS \
- case TYPE_OUT_ARRAY_CHAR: \
-case TYPE_OUT_ARRAY_SHORT: \
-case TYPE_OUT_ARRAY_INT: \
-case TYPE_OUT_ARRAY_FLOAT: \
-case TYPE_OUT_ARRAY_DOUBLE
-
-#define CASE_OUT_KNOWN_SIZE_POINTERS \
- case TYPE_OUT_1INT: \
-case TYPE_OUT_1FLOAT: \
-case TYPE_OUT_4CHAR: \
-case TYPE_OUT_4INT: \
-case TYPE_OUT_4FLOAT: \
-case TYPE_OUT_4DOUBLE: \
-case TYPE_OUT_128UCHAR \
-
-#define CASE_IN_POINTERS CASE_IN_UNKNOWN_SIZE_POINTERS: CASE_IN_KNOWN_SIZE_POINTERS: CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
-#define CASE_OUT_POINTERS CASE_OUT_UNKNOWN_SIZE_POINTERS: CASE_OUT_KNOWN_SIZE_POINTERS: CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
-
-#define CASE_POINTERS CASE_IN_POINTERS: CASE_OUT_POINTERS
-#define CASE_KNOWN_SIZE_POINTERS CASE_IN_KNOWN_SIZE_POINTERS: CASE_OUT_KNOWN_SIZE_POINTERS
-
-
-#define IS_ARRAY_CHAR(type) (type == TYPE_ARRAY_CHAR || type == TYPE_1CHAR || type == TYPE_2CHAR || type == TYPE_3CHAR || type == TYPE_4CHAR || type == TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
-#define IS_ARRAY_SHORT(type) (type == TYPE_ARRAY_SHORT || type == TYPE_1SHORT || type == TYPE_2SHORT || type == TYPE_3SHORT || type == TYPE_4SHORT || type == TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
-#define IS_ARRAY_INT(type) (type == TYPE_ARRAY_INT || type == TYPE_1INT || type == TYPE_2INT || type == TYPE_3INT || type == TYPE_4INT || type == TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
-#define IS_ARRAY_FLOAT(type) (type == TYPE_ARRAY_FLOAT || type == TYPE_1FLOAT || type == TYPE_2FLOAT || type == TYPE_3FLOAT || type == TYPE_4FLOAT || type == TYPE_16FLOAT || type == TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
-#define IS_ARRAY_DOUBLE(type) (type == TYPE_ARRAY_DOUBLE || type == TYPE_1DOUBLE || type == TYPE_2DOUBLE || type == TYPE_3DOUBLE || type == TYPE_4DOUBLE || type == TYPE_16DOUBLE || type == TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
-
-#define NB_MAX_TEXTURES 16
-#define MY_GL_MAX_VERTEX_ATTRIBS_ARB 16
-#define MY_GL_MAX_VERTEX_ATTRIBS_NV 16
-#define MY_GL_MAX_VARIANT_POINTER_EXT 16
-
-static int tab_args_type_length[] =
-{
- 0,
- sizeof(char),
- sizeof(unsigned char),
- sizeof(short),
- sizeof(unsigned short),
- sizeof(int),
- sizeof(unsigned int),
- sizeof(float),
- sizeof(double),
- 1 * sizeof(char),
- 2 * sizeof(char),
- 3 * sizeof(char),
- 4 * sizeof(char),
- 128 * sizeof(char),
- 1 * sizeof(short),
- 2 * sizeof(short),
- 3 * sizeof(short),
- 4 * sizeof(short),
- 1 * sizeof(int),
- 2 * sizeof(int),
- 3 * sizeof(int),
- 4 * sizeof(int),
- 1 * sizeof(float),
- 2 * sizeof(float),
- 3 * sizeof(float),
- 4 * sizeof(float),
- 16 * sizeof(float),
- 1 * sizeof(double),
- 2 * sizeof(double),
- 3 * sizeof(double),
- 4 * sizeof(double),
- 16 * sizeof(double),
- sizeof(int),
- sizeof(float),
- 4 * sizeof(char),
- 4 * sizeof(int),
- 4 * sizeof(float),
- 4 * sizeof(double),
- 128 * sizeof(char),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
-
- /* the following sizes are the size of 1 element of the array */
- sizeof(char),
- sizeof(short),
- sizeof(int),
- sizeof(float),
- sizeof(double),
- sizeof(char),
- sizeof(short),
- sizeof(int),
- sizeof(float),
- sizeof(double),
-};
-
-typedef struct
-{
- int ret_type;
- int has_out_parameters;
- int nb_args;
- int args_type[0];
-} Signature;
-
-static const int _init_signature[] = { TYPE_NONE, 1, 2, TYPE_INT, TYPE_OUT_1INT};
-
-static const int _synchronize_signature[] = { TYPE_INT, 0, 0 };
-
-static const int _serialized_calls_signature[] = { TYPE_NONE, 0, 1, TYPE_ARRAY_CHAR };
-
-static const int _exit_process_signature[] = {TYPE_NONE, 0, 0};
-
-static const int _changeWindowState_signature[] = {TYPE_NONE, 0, 2, TYPE_INT, TYPE_INT};
-
-static const int _moveResizeWindow_signature[] = {TYPE_NONE, 0, 2, TYPE_INT, TYPE_4INT};
-
-static const int _send_cursor_signature[] = {TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT,
- TYPE_INT, TYPE_INT,
- TYPE_INT, TYPE_INT,
- TYPE_ARRAY_INT };
-
-/* XVisualInfo* glXChooseVisual( Display *dpy, int screen, int *attribList ) */
-static const int glXChooseVisual_signature[] = {TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT };
-
-/*GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
- GLXContext shareList, Bool direct )*/
-static const int glXCreateContext_signature[] = {TYPE_INT, 0, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT};
-
-static const int glXCopyContext_signature[] = {TYPE_NONE, 0, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT};
-
-/* void glXDestroyContext( Display *dpy, GLXContext ctx ) */
-static const int glXDestroyContext_signature[] = {TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/* Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx) */
-//static const int glXMakeCurrent_signature[] = {TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT};
-/* making it asynchronous */
-static const int glXMakeCurrent_signature[] = {TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT};
-
-/*int glXGetConfig( Display *dpy, XVisualInfo *visual,
- int attrib, int *value )*/
-static const int glXGetConfig_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-/* "glXGetConfig_extended"(dpy, visual_id, int n, int* attribs, int* values, int* rets) */
-static const int glXGetConfig_extended_signature[] = {TYPE_NONE, 1, 6, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_ARRAY_INT, TYPE_OUT_ARRAY_INT, TYPE_OUT_ARRAY_INT};
-
-/* void glXSwapBuffers( Display *dpy, GLXDrawable drawable ); */
-static const int glXSwapBuffers_signature[] = {TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/* Bool glXQueryVersion( Display *dpy, int *maj, int *min ) */
-static const int glXQueryVersion_signature[] = {TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_OUT_1INT, TYPE_OUT_1INT};
-
-/* Bool glXQueryExtension( Display *dpy, int *errorBase, int *eventBase ) */
-static const int glXQueryExtension_signature[] = {TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_OUT_1INT, TYPE_OUT_1INT};
-
-static const int glXWaitGL_signature[] = { TYPE_INT, 0, 0 };
-static const int glXWaitX_signature[] = { TYPE_INT, 0, 0 };
-
-/* GLX 1.1 and later */
-
-/* const char *glXGetClientString( Display *dpy, int name ) */
-static const int glXGetClientString_signature[] = {TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/*const char *glXQueryExtensionsString( Display *dpy, int screen ) */
-static const int glXQueryExtensionsString_signature[] = {TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/* const char *glXQueryServerString( Display *dpy, int screen, int name ) */
-static const int glXQueryServerString_signature[] = {TYPE_CONST_CHAR, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT};
-
-
-static const int glXGetProcAddress_fake_signature[] = {TYPE_INT, 0, 1, TYPE_NULL_TERMINATED_STRING};
-
-static const int glXGetProcAddress_global_fake_signature[] = {TYPE_NONE, 1, 3, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_OUT_ARRAY_CHAR};
-
-
-/* GLX 1.3 and later */
-
-/*
- GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen,
- const int *attribList, int *nitems ); */
-static const int glXChooseFBConfig_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT, TYPE_OUT_1INT};
-
-static const int glXChooseFBConfigSGIX_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT, TYPE_OUT_1INT};
-
-static const int glXGetFBConfigs_signature[] = {TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_OUT_1INT};
-
-/* "glXGetFBConfigAttrib_extended"(dpy, fbconfig, int n, int* attribs, int* values, int* rets) */
-static const int glXGetFBConfigAttrib_extended_signature[] = {TYPE_NONE, 1, 6, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_ARRAY_INT, TYPE_OUT_ARRAY_INT, TYPE_OUT_ARRAY_INT};
-
-static const int glXDestroyWindow_signature[] = {TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT}; // mkjung
-
-
-/* GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config,
- const int *attribList ) */
-static const int glXCreatePbuffer_signature[] = {TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT};
-
-static const int glXCreateGLXPbufferSGIX_signature[] = {TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_INT};
-
-static const int glXDestroyPbuffer_signature[] = {TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-static const int glXDestroyGLXPbufferSGIX_signature[] = {TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/* GLXContext glXCreateNewContext(Display * dpy
- GLXFBConfig config
- int renderType
- GLXContext ShareList
- Bool Direct) */
-static const int glXCreateNewContext_signature[] = {TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-
-static const int glXCreateContextWithConfigSGIX_signature[] = {TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-
-/*XVisualInfo *glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) */
-static const int glXGetVisualFromFBConfig_signature[] = {TYPE_INT, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT};
-
-/*int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value)*/
-static const int glXGetFBConfigAttrib_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-static const int glXGetFBConfigAttribSGIX_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-static const int glXQueryContext_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-static const int glXQueryGLXPbufferSGIX_signature[] = {TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-static const int glXQueryDrawable_signature[] = {TYPE_NONE, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_OUT_1INT};
-
-/* void glXUseXFont( Font font, int first, int count, int list ) */
-static const int glXUseXFont_signature[] = {TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-
-/* Bool glXIsDirect( Display *dpy, GLXContext ctx ) */
-static const int glXIsDirect_signature[] = {TYPE_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
-
-static const int glXGetScreenDriver_signature[] = { TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
-
-static const int glXGetDriverConfig_signature[] = { TYPE_CONST_CHAR, 0, 1, TYPE_NULL_TERMINATED_STRING };
-
-
-static const int glXWaitVideoSyncSGI_signature[] = { TYPE_INT, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_1INT };
-
-static const int glXGetVideoSyncSGI_signature[] = { TYPE_INT, 1, 1, TYPE_OUT_1INT };
-
-static const int glXSwapIntervalSGI_signature[] = { TYPE_INT, 0, 1, TYPE_INT };
-
-static const int glXBindTexImageATI_signature[] = { TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
-static const int glXReleaseTexImageATI_signature[] = { TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
-static const int glXBindTexImageARB_signature[] = { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
-static const int glXReleaseTexImageARB_signature[] = { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
-
-/* const GLubyte * glGetString( GLenum name ) */
-static const int glGetString_signature[] = {TYPE_CONST_CHAR, 0, 1, TYPE_INT};
-
-/* void glShaderSourceARB (GLhandleARB handle , GLsizei size, const GLcharARB* *p_tab_prog, const GLint * tab_length) */
-/* --> void glShaderSourceARB (GLhandleARB handle , GLsizei size, const GLcharARB* all_progs, const GLint * tab_length) */
-static const int glShaderSourceARB_fake_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_ARRAY_INT};
-static const int glShaderSource_fake_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_ARRAY_INT};
-
-static const int glVertexPointer_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glNormalPointer_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glColorPointer_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glSecondaryColorPointer_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glIndexPointer_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glTexCoordPointer_fake_signature[] = { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glEdgeFlagPointer_fake_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexAttribPointerARB_fake_signature[] = { TYPE_NONE, 0, 8, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexAttribPointerNV_fake_signature[] = { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glWeightPointerARB_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glMatrixIndexPointerARB_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glFogCoordPointer_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glInterleavedArrays_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glElementPointerATI_fake_signature[] = { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVariantPointerEXT_fake_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glTuxRacerDrawElements_fake_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexAndNormalPointer_fake_signature[] = { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glTexCoordPointer01_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glTexCoordPointer012_fake_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalPointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 8, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalColorPointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 11, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexColorTexCoord0PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 12, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalTexCoord0PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 11, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalTexCoord01PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 14, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalTexCoord012PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 17, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalColorTexCoord0PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 14, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalColorTexCoord01PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 17, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-static const int glVertexNormalColorTexCoord012PointerInterlaced_fake_signature[] = {TYPE_NONE, 0, 20, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
-
-static const int glGenTextures_fake_signature[] = { TYPE_NONE, 0, 1, TYPE_INT};
-static const int glGenBuffersARB_fake_signature[] = { TYPE_NONE, 0, 1, TYPE_INT};
-static const int glGenLists_fake_signature[] = { TYPE_NONE, 0, 1, TYPE_INT};
-
-static const int _glDrawElements_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glDrawRangeElements_buffer_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glMultiDrawElements_buffer_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_ARRAY_INT, TYPE_INT, TYPE_ARRAY_INT, TYPE_INT };
-
-static const int _glVertexPointer_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glNormalPointer_buffer_signature[] = { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glColorPointer_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glSecondaryColorPointer_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glIndexPointer_buffer_signature[] = { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glTexCoordPointer_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glEdgeFlagPointer_buffer_signature[] = { TYPE_NONE, 0, 2, TYPE_INT, TYPE_INT};
-static const int _glVertexAttribPointerARB_buffer_signature[] = { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glWeightPointerARB_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glMatrixIndexPointerARB_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glFogCoordPointer_buffer_signature[] = { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glVariantPointerEXT_buffer_signature[] = { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-
-static const int _glReadPixels_pbo_signature[] = { TYPE_INT, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glDrawPixels_pbo_signature[] = { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT};
-static const int _glMapBufferARB_fake_signature[] = { TYPE_INT, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_ARRAY_CHAR };
-
-static const int _glSelectBuffer_fake_signature[] = { TYPE_NONE, 0, 1, TYPE_INT };
-static const int _glGetSelectBuffer_fake_signature[] = { TYPE_NONE, 1, 1, TYPE_ARRAY_CHAR };
-static const int _glFeedbackBuffer_fake_signature[] = { TYPE_NONE, 0, 2, TYPE_INT, TYPE_INT };
-static const int _glGetFeedbackBuffer_fake_signature[] = { TYPE_NONE, 1, 1, TYPE_ARRAY_CHAR };
-
-static const int _glGetError_fake_signature[] = { TYPE_NONE, 0, 0 };
-
-#define timesynchro_func -1
-#define memorize_array_func -2
-#define reuse_array_func -3
-
-#include "gl_func.h"
-
-
-static GLint __glTexParameter_size(FILE* err_file, GLenum pname)
-{
- switch (pname) {
- case GL_TEXTURE_MAG_FILTER:
- case GL_TEXTURE_MIN_FILTER:
- case GL_TEXTURE_WRAP_S:
- case GL_TEXTURE_WRAP_T:
- case GL_TEXTURE_PRIORITY:
- case GL_TEXTURE_WRAP_R:
- case GL_TEXTURE_COMPARE_FAIL_VALUE_ARB:
- /* case GL_SHADOW_AMBIENT_SGIX:*/
- case GL_TEXTURE_MIN_LOD:
- case GL_TEXTURE_MAX_LOD:
- case GL_TEXTURE_BASE_LEVEL:
- case GL_TEXTURE_MAX_LEVEL:
- case GL_TEXTURE_CLIPMAP_FRAME_SGIX:
- case GL_TEXTURE_LOD_BIAS_S_SGIX:
- case GL_TEXTURE_LOD_BIAS_T_SGIX:
- case GL_TEXTURE_LOD_BIAS_R_SGIX:
- case GL_GENERATE_MIPMAP:
- /* case GL_GENERATE_MIPMAP_SGIS:*/
- case GL_TEXTURE_COMPARE_SGIX:
- case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
- case GL_TEXTURE_MAX_CLAMP_S_SGIX:
- case GL_TEXTURE_MAX_CLAMP_T_SGIX:
- case GL_TEXTURE_MAX_CLAMP_R_SGIX:
- case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- case GL_TEXTURE_LOD_BIAS:
- /* case GL_TEXTURE_LOD_BIAS_EXT:*/
- case GL_DEPTH_TEXTURE_MODE:
- /* case GL_DEPTH_TEXTURE_MODE_ARB:*/
- case GL_TEXTURE_COMPARE_MODE:
- /* case GL_TEXTURE_COMPARE_MODE_ARB:*/
- case GL_TEXTURE_COMPARE_FUNC:
- /* case GL_TEXTURE_COMPARE_FUNC_ARB:*/
- case GL_TEXTURE_UNSIGNED_REMAP_MODE_NV:
- return 1;
- case GL_TEXTURE_CLIPMAP_CENTER_SGIX:
- case GL_TEXTURE_CLIPMAP_OFFSET_SGIX:
- return 2;
- case GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX:
- return 3;
- case GL_TEXTURE_BORDER_COLOR:
- case GL_POST_TEXTURE_FILTER_BIAS_SGIX:
- case GL_POST_TEXTURE_FILTER_SCALE_SGIX:
- return 4;
- default:
- fprintf(err_file, "unhandled pname = %d\n", pname);
- return 0;
- }
-}
-
-static int __glLight_size(FILE* err_file, GLenum pname)
-{
- switch(pname)
- {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- case GL_POSITION:
- return 4;
- break;
-
- case GL_SPOT_DIRECTION:
- return 3;
- break;
-
- case GL_SPOT_EXPONENT:
- case GL_SPOT_CUTOFF:
- case GL_CONSTANT_ATTENUATION:
- case GL_LINEAR_ATTENUATION:
- case GL_QUADRATIC_ATTENUATION:
- return 1;
- break;
-
- default:
- fprintf(err_file, "unhandled pname = %d\n", pname);
- return 0;
- }
-}
-
-static int __glMaterial_size(FILE* err_file, GLenum pname)
-{
- switch(pname)
- {
- case GL_AMBIENT:
- case GL_DIFFUSE:
- case GL_SPECULAR:
- case GL_EMISSION:
- case GL_AMBIENT_AND_DIFFUSE:
- return 4;
- break;
-
- case GL_SHININESS:
- return 1;
- break;
-
- case GL_COLOR_INDEXES:
- return 3;
- break;
-
- default:
- fprintf(err_file, "unhandled pname = %d\n", pname);
- return 0;
- }
-}
-
-
-static inline int compute_arg_length(FILE* err_file, int func_number, int arg_i, long* args)
-{
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int* args_type = signature->args_type;
-
- switch (func_number)
- {
- case glProgramNamedParameter4fNV_func:
- case glProgramNamedParameter4dNV_func:
- case glProgramNamedParameter4fvNV_func:
- case glProgramNamedParameter4dvNV_func:
- case glGetProgramNamedParameterfvNV_func:
- case glGetProgramNamedParameterdvNV_func:
- if (arg_i == 2)
- return 1 * args[arg_i-1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glProgramStringARB_func:
- case glLoadProgramNV_func:
- case glGenProgramsNV_func:
- case glDeleteProgramsNV_func:
- case glGenProgramsARB_func:
- case glDeleteProgramsARB_func:
- case glRequestResidentProgramsNV_func:
- case glDrawBuffers_func:
- case glDrawBuffersARB_func:
- case glDrawBuffersATI_func:
- case glDeleteBuffers_func:
- case glDeleteBuffersARB_func:
- case glDeleteTextures_func:
- case glDeleteTexturesEXT_func:
- case glGenFramebuffersEXT_func:
- case glDeleteFramebuffersEXT_func:
- case glGenRenderbuffersEXT_func:
- case glDeleteRenderbuffersEXT_func:
- case glGenQueries_func:
- case glGenQueriesARB_func:
- case glDeleteQueries_func:
- case glDeleteQueriesARB_func:
- case glGenOcclusionQueriesNV_func:
- case glDeleteOcclusionQueriesNV_func:
- case glGenFencesNV_func:
- case glDeleteFencesNV_func:
- case glUniform1fv_func:
- case glUniform1iv_func:
- case glUniform1fvARB_func:
- case glUniform1ivARB_func:
- case glUniform1uivEXT_func:
- case glVertexAttribs1dvNV_func:
- case glVertexAttribs1fvNV_func:
- case glVertexAttribs1svNV_func:
- case glVertexAttribs1hvNV_func:
- case glWeightbvARB_func:
- case glWeightsvARB_func:
- case glWeightivARB_func:
- case glWeightfvARB_func:
- case glWeightdvARB_func:
- case glWeightubvARB_func:
- case glWeightusvARB_func:
- case glWeightuivARB_func:
- case glPixelMapfv_func:
- case glPixelMapuiv_func:
- case glPixelMapusv_func:
- case glProgramBufferParametersfvNV_func:
- case glProgramBufferParametersIivNV_func:
- case glProgramBufferParametersIuivNV_func:
- case glTransformFeedbackAttribsNV_func:
- case glTransformFeedbackVaryingsNV_func:
- if (arg_i == signature->nb_args - 1)
- return 1 * args[arg_i-1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniform2fv_func:
- case glUniform2iv_func:
- case glUniform2fvARB_func:
- case glUniform2ivARB_func:
- case glUniform2uivEXT_func:
- case glVertexAttribs2dvNV_func:
- case glVertexAttribs2fvNV_func:
- case glVertexAttribs2svNV_func:
- case glVertexAttribs2hvNV_func:
- case glDetailTexFuncSGIS_func:
- case glSharpenTexFuncSGIS_func:
- if (arg_i == signature->nb_args - 1)
- return 2 * args[arg_i-1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniform3fv_func:
- case glUniform3iv_func:
- case glUniform3fvARB_func:
- case glUniform3ivARB_func:
- case glUniform3uivEXT_func:
- case glVertexAttribs3dvNV_func:
- case glVertexAttribs3fvNV_func:
- case glVertexAttribs3svNV_func:
- case glVertexAttribs3hvNV_func:
- if (arg_i == signature->nb_args - 1)
- return 3 * args[arg_i-1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniform4fv_func:
- case glUniform4iv_func:
- case glUniform4fvARB_func:
- case glUniform4ivARB_func:
- case glUniform4uivEXT_func:
- case glVertexAttribs4dvNV_func:
- case glVertexAttribs4fvNV_func:
- case glVertexAttribs4svNV_func:
- case glVertexAttribs4hvNV_func:
- case glVertexAttribs4ubvNV_func:
- case glProgramParameters4fvNV_func:
- case glProgramParameters4dvNV_func:
- case glProgramLocalParameters4fvEXT_func:
- case glProgramEnvParameters4fvEXT_func:
- case glProgramLocalParametersI4ivNV_func:
- case glProgramLocalParametersI4uivNV_func:
- case glProgramEnvParametersI4ivNV_func:
- case glProgramEnvParametersI4uivNV_func:
- if (arg_i == signature->nb_args - 1)
- return 4 * args[arg_i-1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glPrioritizeTextures_func:
- case glPrioritizeTexturesEXT_func:
- case glAreProgramsResidentNV_func:
- case glAreTexturesResident_func:
- case glAreTexturesResidentEXT_func:
- if (arg_i == 1 || arg_i == 2)
- return args[0] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glLightfv_func:
- case glLightiv_func:
- case glGetLightfv_func:
- case glGetLightiv_func:
- case glFragmentLightfvSGIX_func:
- case glFragmentLightivSGIX_func:
- case glGetFragmentLightfvSGIX_func:
- case glGetFragmentLightivSGIX_func:
- if (arg_i == signature->nb_args - 1)
- return __glLight_size(err_file, args[arg_i-1]) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glLightModelfv_func:
- case glLightModeliv_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_LIGHT_MODEL_AMBIENT) ? 4 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glFragmentLightModelfvSGIX_func:
- case glFragmentLightModelivSGIX_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX) ? 4 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glMaterialfv_func:
- case glMaterialiv_func:
- case glGetMaterialfv_func:
- case glGetMaterialiv_func:
- case glFragmentMaterialfvSGIX_func:
- case glFragmentMaterialivSGIX_func:
- case glGetFragmentMaterialfvSGIX_func:
- case glGetFragmentMaterialivSGIX_func:
- if (arg_i == signature->nb_args - 1)
- return __glMaterial_size(err_file, args[arg_i-1]) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glTexParameterfv_func:
- case glTexParameteriv_func:
- case glGetTexParameterfv_func:
- case glGetTexParameteriv_func:
- case glTexParameterIivEXT_func:
- case glTexParameterIuivEXT_func:
- case glGetTexParameterIivEXT_func:
- case glGetTexParameterIuivEXT_func:
- if (arg_i == signature->nb_args - 1)
- return __glTexParameter_size(err_file, args[arg_i-1]) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glFogiv_func:
- case glFogfv_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_FOG_COLOR) ? 4 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glTexGendv_func:
- case glTexGenfv_func:
- case glTexGeniv_func:
- case glGetTexGendv_func:
- case glGetTexGenfv_func:
- case glGetTexGeniv_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_TEXTURE_GEN_MODE) ? 1 : 4) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glTexEnvfv_func:
- case glTexEnviv_func:
- case glGetTexEnvfv_func:
- case glGetTexEnviv_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_TEXTURE_ENV_MODE) ? 1 : 4) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glConvolutionParameterfv_func:
- case glConvolutionParameteriv_func:
- case glGetConvolutionParameterfv_func:
- case glGetConvolutionParameteriv_func:
- case glConvolutionParameterfvEXT_func:
- case glConvolutionParameterivEXT_func:
- case glGetConvolutionParameterfvEXT_func:
- case glGetConvolutionParameterivEXT_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_CONVOLUTION_BORDER_COLOR ||
- args[arg_i-1] == GL_CONVOLUTION_FILTER_SCALE ||
- args[arg_i-1] == GL_CONVOLUTION_FILTER_BIAS) ? 4 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glGetVertexAttribfvARB_func:
- case glGetVertexAttribfvNV_func:
- case glGetVertexAttribfv_func:
- case glGetVertexAttribdvARB_func:
- case glGetVertexAttribdvNV_func:
- case glGetVertexAttribdv_func:
- case glGetVertexAttribivARB_func:
- case glGetVertexAttribivNV_func:
- case glGetVertexAttribiv_func:
- case glGetVertexAttribIivEXT_func:
- case glGetVertexAttribIuivEXT_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_CURRENT_VERTEX_ATTRIB_ARB) ? 4 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
-
- case glPointParameterfv_func:
- case glPointParameterfvEXT_func:
- case glPointParameterfvARB_func:
- case glPointParameterfvSGIS_func:
- case glPointParameteriv_func:
- case glPointParameterivEXT_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_POINT_DISTANCE_ATTENUATION) ? 3 : 1) * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix2fv_func:
- case glUniformMatrix2fvARB_func:
- if (arg_i == signature->nb_args - 1)
- return 2 * 2 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix3fv_func:
- case glUniformMatrix3fvARB_func:
- if (arg_i == signature->nb_args - 1)
- return 3 * 3 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix4fv_func:
- case glUniformMatrix4fvARB_func:
- if (arg_i == signature->nb_args - 1)
- return 4 * 4 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix2x3fv_func:
- case glUniformMatrix3x2fv_func:
- if (arg_i == signature->nb_args - 1)
- return 2 * 3 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix2x4fv_func:
- case glUniformMatrix4x2fv_func:
- if (arg_i == signature->nb_args - 1)
- return 2 * 4 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glUniformMatrix3x4fv_func:
- case glUniformMatrix4x3fv_func:
- if (arg_i == signature->nb_args - 1)
- return 3 * 4 * args[1] * tab_args_type_length[args_type[arg_i]];
- break;
-
- case glSpriteParameterivSGIX_func:
- case glSpriteParameterfvSGIX_func:
- if (arg_i == signature->nb_args - 1)
- return ((args[arg_i-1] == GL_SPRITE_MODE_SGIX) ? 1 : 3) * tab_args_type_length[args_type[arg_i]];
- break;
-
- default:
- break;
- }
-
- fprintf(err_file, "invalid combination for compute_arg_length : func_number=%d, arg_i=%d\n", func_number, arg_i);
- return 0;
-}
-
-#define IS_NULL_POINTER_OK_FOR_FUNC(func_number) \
- (func_number == glBitmap_func || \
- func_number == _send_cursor_func || \
- func_number == glTexImage1D_func || \
- func_number == glTexImage2D_func || \
- func_number == glTexImage3D_func || \
- func_number == glBufferDataARB_func || \
- func_number == glNewObjectBufferATI_func)
+++ /dev/null
-/*
- * TCP/IP OpenGL server
- *
- * Copyright (c) 2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/* gcc -Wall -O2 -g opengl_server.c opengl_exec.c -o opengl_server -I../i386-softmmu -I. -I.. -lGL */
-/* gcc -g -o opengl_server opengl_server.c opengl_exec.c -I../i386-softmmu -I. -I.. -I/c/mingw/include -lopengl32 -lws2_32 -lgdi32 -lpthread */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <pthread.h>
-
-#ifdef _WIN32 // or __MINGW32__
- #include <windows.h>
- #include <winsock2.h>
-#else // _WIN32
-// #include <sys/types.h>
-// #include <sys/time.h>
-// #include <unistd.h>
-// #include <arpa/inet.h>
-// #include <errno.h>
-// #include <sys/socket.h>
-// #include <netinet/in.h>
-// #include <netinet/tcp.h>
-// #include <netdb.h>
-// #include <signal.h>
-// #include <X11/Xlib.h>
-// #include <X11/Xutil.h>
-#endif // _WIN32
-
-#define ENABLE_GL_LOG
-
-#include "opengl_func.h"
-#include "opengl_utils.h"
-#include "opengl_server.h"
-#include "sdb.h"
-
-#include "../tizen/src/debug_ch.h"
-
-MULTI_DEBUG_CHANNEL(qemu,opengl_server);
-
-
-extern int display_function_call;
-
-#ifdef _WIN32
-HWND displayHWND;
-static Display CreateDisplay(void)
-{
- HWND hWnd;
- WNDCLASS wc;
- LPSTR ClassName ="DISPLAY";
- HINSTANCE hInstance = 0;
-
- /* only register the window class once - use hInstance as a flag. */
- hInstance = GetModuleHandle(NULL);
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = (WNDPROC)DefWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = ClassName;
-
- RegisterClass(&wc);
-
- displayHWND = CreateWindow(ClassName, ClassName, (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU ),
- 0, 0, 10, 10, NULL, (HMENU)NULL, hInstance, NULL);
-
-
- ShowWindow(hWnd, SW_HIDE);
-
- return GetDC(displayHWND);
-}
-#endif // _WIN32
-
-#ifdef ENABLE_GL_LOG
-static FILE* f = NULL;
-
-static const char* filename = "/tmp/debug_gl.bin";
-
-#define write_gl_debug_init() do { if (f == NULL) f = fopen(filename, "wb"); } while(0)
-
-inline static void write_gl_debug_cmd_char(char my_int)
-{
- write_gl_debug_init();
- fwrite(&my_int, sizeof(my_int), 1, f);
-}
-
-inline static void write_gl_debug_cmd_short(short my_int)
-{
- write_gl_debug_init();
- fwrite(&my_int, sizeof(my_int), 1, f);
-}
-
-inline static void write_gl_debug_cmd_int(int my_int)
-{
- write_gl_debug_init();
- fwrite(&my_int, sizeof(my_int), 1, f);
-}
-
-inline static void write_gl_debug_cmd_longlong(long long my_longlong)
-{
- write_gl_debug_init();
- fwrite(&my_longlong, sizeof(my_longlong), 1, f);
-}
-
-inline static void write_gl_debug_cmd_buffer_with_size(int size, void* buffer)
-{
- write_gl_debug_init();
- fwrite(&size, sizeof(int), 1, f);
- if (size)
- fwrite(buffer, size, 1, f);
-}
-
-inline static void write_gl_debug_cmd_buffer_without_size(int size, void* buffer)
-{
- write_gl_debug_init();
- if (size)
- fwrite(buffer, size, 1, f);
-}
-
-inline static void write_gl_debug_end(void)
-{
- write_gl_debug_init();
- fclose(f);
- f = NULL;
-}
-
-#endif
-
-static int write_sock_data(int sock, void* data, int len)
-{
- int offset = 0;
-
- if (len && data)
- {
- while(offset < len)
- {
- int nwritten = send(sock, data + offset, len - offset, 0);
- if (nwritten == -1)
- {
-#ifndef _WIN32
- if (errno == EINTR)
- continue;
-#endif
- ERR("write error : %s(%d)\n", strerror(errno), errno);
- //assert(nwritten != -1);
- return -1;
- }
- offset += nwritten;
- }
- }
-
- return offset;
-}
-
-inline static int write_sock_int(int sock, int my_int)
-{
- return write_sock_data(sock, &my_int, sizeof(int));
-}
-
-static int total_read = 0;
-static void read_sock_data(int sock, void* data, int len)
-{
- if (len)
- {
- int offset = 0;
- while(offset < len)
- {
- int nread = recv(sock, data + offset, len - offset, 0);
- if (nread == -1)
- {
-#ifndef _WIN32
- if (errno == EINTR)
- continue;
-#endif
- ERR("read(%d) error : %s(%d)\n", sock, strerror(errno), errno);
- //assert(nread != -1);
- }
- if (nread == 0)
- {
- //fprintf(stderr, "nread = 0\n");
- }
- //assert(nread > 0);
- if (nread > 0)
- {
- offset += nread;
- total_read += nread;
- }
- }
- }
-}
-
-inline static int read_sock_int(int sock)
-{
- int ret;
- read_sock_data(sock, &ret, sizeof(int));
- return ret;
-}
-
-inline static short read_sock_short(int sock)
-{
- short ret;
- read_sock_data(sock, &ret, sizeof(short));
- return ret;
-}
-
-static int OGLS_readConn( OGLS_Conn *pConn )
-{
- int sock = pConn->sock;
- long args[50];
- int args_size[50];
- char ret_string[32768];
- char command_buffer[65536*16];
-
- if( pConn->Display == NULL )
- {
- create_process_tab(pConn);
-#ifdef _WIN32
- pConn->Display = CreateDisplay();
-#else
- pConn->Display = XOpenDisplay(NULL);
- if (pConn->pOption->parent_xid != -1)
- {
- opengl_exec_set_parent_window(pConn, pConn->pOption->parent_xid);
- }
-#endif // _WIN32
- }
-
- int i;
- int func_number = read_sock_short(sock);
-
- TRACE("OGLS_readConn (%s)\n", tab_opengl_calls_name[func_number]);
-
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int ret_type = signature->ret_type;
- int nb_args = signature->nb_args;
- int* args_type = signature->args_type;
- int pid = 0;
-
- if (func_number == _serialized_calls_func)
- {
- int command_buffer_size = read_sock_int(sock);
- int commmand_buffer_offset = 0;
- read_sock_data(sock, command_buffer, command_buffer_size);
-
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_short(_serialized_calls_func);
-#endif
-
- while(commmand_buffer_offset < command_buffer_size)
- {
- func_number = *(short*)(command_buffer + commmand_buffer_offset);
- if( ! (func_number >= 0 && func_number < GL_N_CALLS) )
- {
- fprintf(stderr, "func_number >= 0 && func_number < GL_N_CALLS failed at "
- "commmand_buffer_offset=%d (command_buffer_size=%d)\n",
- commmand_buffer_offset, command_buffer_size);
- //exit(-1);
- return -1;
- }
-
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_short(func_number);
-#endif
- TRACE("serialized call is %s\n", tab_opengl_calls_name[func_number]);
-
- commmand_buffer_offset += sizeof(short);
-
-
- signature = (Signature*)tab_opengl_calls[func_number];
- ret_type = signature->ret_type;
- assert(ret_type == TYPE_NONE);
- nb_args = signature->nb_args;
- args_type = signature->args_type;
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- {
- args[i] = *(int*)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
-#endif
- commmand_buffer_offset += sizeof(int);
- break;
- }
-
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- {
- args[i] = *(int*)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
-#endif
- commmand_buffer_offset += sizeof(int);
- break;
- }
-
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_FLOAT:
- {
- args[i] = *(int*)(command_buffer + commmand_buffer_offset);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- commmand_buffer_offset += sizeof(int);
- break;
- }
-
- case TYPE_NULL_TERMINATED_STRING:
-CASE_IN_UNKNOWN_SIZE_POINTERS:
- {
- args_size[i] = *(int*)(command_buffer + commmand_buffer_offset);
- commmand_buffer_offset += sizeof(int);
-
- if (args_size[i] == 0)
- {
- args[i] = 0;
- }
- else
- {
- args[i] = (long)(command_buffer + commmand_buffer_offset);
- }
-
- if (args[i] == 0)
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
-#endif
- commmand_buffer_offset += args_size[i];
-
- break;
- }
-
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(stderr, func_number, i, args);
- args[i] = (args_size[i]) ? (long)(command_buffer + commmand_buffer_offset) : 0;
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
-#endif
- commmand_buffer_offset += args_size[i];
- break;
- }
-
-CASE_OUT_POINTERS:
- {
- fprintf(stderr, "shouldn't happen TYPE_OUT_xxxx : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- return 0;
- break;
- }
-
- case TYPE_DOUBLE:
-CASE_IN_KNOWN_SIZE_POINTERS:
- args[i] = (long)(command_buffer + commmand_buffer_offset);
- args_size[i] = tab_args_type_length[args_type[i]];
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- commmand_buffer_offset += tab_args_type_length[args_type[i]];
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- return 0;
- break;
- }
- }
-
- if (display_function_call) display_gl_call(stderr, func_number, args, args_size);
- do_function_call(pConn, func_number, 1, args, ret_string);
- }
- }
- else
- {
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save && func_number != _synchronize_func) write_gl_debug_cmd_short(func_number);
-#endif
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- args[i] = read_sock_int(sock);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_char(args[i]);
-#endif
- break;
-
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- args[i] = read_sock_int(sock);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_short(args[i]);
-#endif
- break;
-
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_FLOAT:
- args[i] = read_sock_int(sock);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_int(args[i]);
-#endif
- break;
-
- case TYPE_NULL_TERMINATED_STRING:
-CASE_IN_UNKNOWN_SIZE_POINTERS:
- {
- args_size[i] = read_sock_int(sock);
- if (args_size[i])
- {
- args[i] = (long)malloc(args_size[i]);
- read_sock_data(sock, (void*)args[i], args_size[i]);
- }
- else
- {
- args[i] = 0;
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d\n", tab_opengl_calls_name[func_number], i);
- return 0;
- }
- }
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_with_size(args_size[i], (void*)args[i]);
-#endif
- break;
- }
-
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(stderr, func_number, i, args);
- args[i] = (args_size[i]) ? (long)malloc(args_size[i]) : 0;
- read_sock_data(sock, (void*)args[i], args_size[i]);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(args_size[i], (void*)args[i]);
-#endif
- break;
- }
-
-CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- {
- args_size[i] = compute_arg_length(stderr, func_number, i, args);
- args[i] = (long)malloc(args_size[i]);
- break;
- }
-
-CASE_OUT_UNKNOWN_SIZE_POINTERS:
- {
- args_size[i] = read_sock_int(sock);
- if (func_number == glGetProgramLocalParameterdvARB_func)
- {
- fprintf(stderr, "size = %d\n", args_size[i]);
- }
- if (args_size[i])
- {
- args[i] = (long)malloc(args_size[i]);
- }
- else
- {
- if (!IS_NULL_POINTER_OK_FOR_FUNC(func_number))
- {
- fprintf(stderr, "call %s arg %d pid=%d\n", tab_opengl_calls_name[func_number], i, pid);
- return 0;
- };
- args[i] = 0;
- }
- //fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_int(args_size[i]);
-#endif
- break;
- }
-
-CASE_OUT_KNOWN_SIZE_POINTERS:
- {
- args_size[i] = tab_args_type_length[args_type[i]];
- assert(args_size[i]);
- args[i] = (long)malloc(args_size[i]);
- //fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
- break;
- }
-
- case TYPE_DOUBLE:
-CASE_IN_KNOWN_SIZE_POINTERS:
- args_size[i] = tab_args_type_length[args_type[i]];
- args[i] = (long)malloc(args_size[i]);
- read_sock_data(sock, (void*)args[i], args_size[i]);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save) write_gl_debug_cmd_buffer_without_size(tab_args_type_length[args_type[i]], (void*)args[i]);
-#endif
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d\n", tab_opengl_calls_name[func_number], i);
- return 0;
- break;
- }
- }
-
- if (display_function_call) display_gl_call(stderr, func_number, args, args_size);
-
- if (getenv("ALWAYS_FLUSH")) fflush(f);
-
- int ret = do_function_call(pConn, func_number, 1, args, ret_string);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save && func_number == glXGetVisualFromFBConfig_func)
- {
- write_gl_debug_cmd_int(ret);
- }
-#endif
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- case TYPE_FLOAT:
- break;
-
- case TYPE_NULL_TERMINATED_STRING:
- case TYPE_DOUBLE:
-CASE_IN_POINTERS:
- if (args[i]) free((void*)args[i]);
- break;
-
-CASE_OUT_POINTERS:
- //fprintf(stderr, "%p %d\n", (void*)args[i], args_size[i]);
- if( 0> write_sock_data(sock, (void*)args[i], args_size[i]) )
- {
- perror( "write_sock_data" ) ;
- return -1 ;
- }
-
- if (display_function_call)
- {
- if (args_type[i] == TYPE_OUT_1INT)
- {
- fprintf(stderr, "out[%d] : %d\n", i, *(int*)args[i]);
- }
- else if (args_type[i] == TYPE_OUT_1FLOAT)
- {
- fprintf(stderr, "out[%d] : %f\n", i, *(float*)args[i]);
- }
- }
- if (args[i]) free((void*)args[i]);
- break;
-
- case TYPE_IN_IGNORED_POINTER:
- args[i] = 0;
- break;
-
- default:
- fprintf(stderr, "shouldn't happen : call %s arg %d\n", tab_opengl_calls_name[func_number], i);
- return 0;
- break;
- }
- }
-
- if (signature->ret_type == TYPE_CONST_CHAR)
- {
- if( 0 > write_sock_int(sock, strlen(ret_string) + 1) )
- {
- perror( "write_sock_int" ) ;
- return -1 ;
- }
- if( 0 > write_sock_data(sock, ret_string, strlen(ret_string) + 1) )
- {
- perror( "write_sock_data" ) ;
- return -1 ;
- }
- }
- else if (signature->ret_type != TYPE_NONE)
- {
- if( 0 > write_sock_int(sock, ret) )
- {
- perror( "write_sock_int" ) ;
- return -1 ;
- }
- }
-
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save && func_number == _exit_process_func)
- {
- write_gl_debug_end();
- }
-#endif
- if (func_number == _exit_process_func)
- {
- return -1;
- }
- else if (func_number == glXSwapBuffers_func)
- {
- int diff_time;
- pConn->count_current++;
- gettimeofday(&pConn->current_time, NULL);
-#ifdef ENABLE_GL_LOG
- if (pConn->pOption->must_save && pConn->pOption->timestamp)
- {
- long long ts = (pConn->current_time.tv_sec - pConn->time_stamp_start.tv_sec) * (long long)1000000 + pConn->current_time.tv_usec - pConn->time_stamp_start.tv_usec;
- /* -1 is special code that indicates time synchro */
- write_gl_debug_cmd_short(timesynchro_func);
- write_gl_debug_cmd_longlong(ts);
- }
-#endif
- diff_time = (pConn->current_time.tv_sec - pConn->last_time.tv_sec) * 1000 + (pConn->current_time.tv_usec - pConn->last_time.tv_usec) / 1000;
- if (diff_time > pConn->pOption->refresh_rate)
- {
-#ifdef ENABLE_GL_LOG
- fflush(f);
-#endif
- printf("%d frames in %.1f seconds = %.3f FPS\n",
- pConn->count_current - pConn->count_last_time,
- diff_time / 1000.,
- (pConn->count_current - pConn->count_last_time) * 1000. / diff_time);
- pConn->last_time.tv_sec = pConn->current_time.tv_sec;
- pConn->last_time.tv_usec = pConn->current_time.tv_usec;
- pConn->count_last_time = pConn->count_current;
- }
- }
- }
- return 0;
-}
-
-static int OGLS_createListenSocket (uint16_t port)
-{
- int sock;
- struct sockaddr_in name;
-
- /* Create the socket. */
- sock = socket (PF_INET, SOCK_STREAM, 0);
- if (sock < 0)
- {
- ERR("socket error : %s(%d)\n", strerror(errno), errno);
- //exit (EXIT_FAILURE);
- return -1;
- }
-
- int flag = 1;
- if (setsockopt(sock, IPPROTO_IP, SO_REUSEADDR,(char *)&flag, sizeof(int)) != 0)
- {
- ERR("setsockopt error(SO_REUSEADDR) : %s(%d)\n", strerror(errno), errno);
- }
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,(char *)&flag, sizeof(int)) != 0)
- {
- ERR("setsockopt error(TCP_NODELAY) : %s(%d)\n", strerror(errno), errno);
- }
-
- /* Give the socket a name. */
- name.sin_family = AF_INET;
- name.sin_port = htons (port);
- name.sin_addr.s_addr = htonl (INADDR_ANY);
- if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
- {
- fprintf(stderr, "bind(INADDR_ANY:%d): errorno = %d(%s)\n", port, errno, strerror(errno));
- ERR("bind error : %s(%d)\n", strerror(errno), errno);
- //exit (EXIT_FAILURE);
- //exit (EXIT_FAILURE);
- return -1;
- }
-
- //fprintf(stderr, "Port(%d/tcp) listen for opengl \n", port);
-
- return sock;
-}
-
-static OGLS_Conn * OGLS_createConn( OGLS_Opts *pOption )
-{
- OGLS_Conn *pConn = malloc(sizeof(OGLS_Conn));
- if( !pConn )
- {
- return NULL ;
- }
-
- memset( pConn, 0, sizeof(*pConn) );
- pConn->pOption = pOption;
- return pConn;
-}
-
-static void OGLS_removeConn( OGLS_Conn *pConn )
-{
- if( !pConn ) return ;
-
- if( pConn->sock > 0 )
- {
- closesocket(pConn->sock);
- pConn->sock = 0 ;
- }
-
- if( pConn->Display )
- {
-#ifdef _WIN32
- // ReleaseDC(pConn->Display);
-#else
- XCloseDisplay( pConn->Display );
- pConn->Display = NULL;
-#endif // _WIN32
- }
-
- remove_process_tab(pConn);
-
- free( pConn );
-}
-
-static void OGLS_loop( OGLS_Conn *pConn )
-{
- //fprintf (stderr, "Server: connect from host %s, port %hd.\n",
- // inet_ntoa (pConn->clientname.sin_addr),
- // ntohs (pConn->clientname.sin_port));
-
- gettimeofday(&pConn->last_time, NULL);
- gettimeofday(&pConn->last_read_time, NULL);
-
-#ifndef _WIN32
- if (strcmp(inet_ntoa(pConn->clientname.sin_addr), "127.0.0.1") == 0 &&
- pConn->pOption->different_windows == 0)
- {
- pConn->local_connection = 1;
- }
-#endif // _WIN32
-
- if( pConn->pOption->timestamp )
- {
- gettimeofday(&pConn->time_stamp_start, NULL);
- }
-
- while( OGLS_readConn(pConn) >= 0 );
-
- do_function_call(pConn, _exit_process_func, 1, NULL, NULL);
-
- //fprintf (stderr, "Server: disconnect from host %s, port %hd.\n",
- // inet_ntoa (pConn->clientname.sin_addr),
- // ntohs (pConn->clientname.sin_port));
-
- OGLS_removeConn( pConn );
-}
-
-#ifndef _WIN32
-int has_x_error = 0;
-static int OGLS_x_error_handler(Display *display, XErrorEvent *error)
-{
- char buf[64];
- XGetErrorText(display, error->error_code, buf, 63);
- fprintf (stderr, "The program received an X Window System error.\n"
- "This probably reflects a bug in the program.\n"
- "The error was '%s'.\n"
- " (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
- buf,
- error->serial,
- error->error_code,
- error->request_code,
- error->minor_code);
- has_x_error = 1;
- return 0;
-}
-#endif // _WIN32
-
-static void OGLS_main( OGLS_Opts *pOption )
-{
- int sock;
- fd_set active_fd_set, read_fd_set;
-
- socklen_t size;
-
-#ifndef _WIN32
- XSetErrorHandler(OGLS_x_error_handler);
-#endif // _WIN32
-
- /* Create the socket and set it up to accept connections. */
- sock = OGLS_createListenSocket( pOption->port );
- if (sock < 0)
- return;
-
- if (listen (sock, 1) < 0)
- {
- ERR("listen error : %s(%d)\n", strerror(errno), errno);
- //exit (EXIT_FAILURE);
- return;
- }
-
- FD_ZERO (&active_fd_set);
- FD_SET (sock, &active_fd_set);
-
- while(1)
- {
- OGLS_Conn *pConn = NULL;
- pthread_t taskid;
-
- read_fd_set = active_fd_set;
- if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0)
- {
-#ifndef _WIN32
- if (errno == EINTR) {
- continue;
- }
-#endif
- ERR("select error : %s(%d)\n", strerror(errno), errno);
- //exit (EXIT_FAILURE);
- break;
- }
-
- pConn = OGLS_createConn( pOption );
- if( !pConn )
- {
- perror( "OGLS_createConn" );
- continue;
- }
-
- size = sizeof(pConn->clientname);
- pConn->sock = accept (sock, (struct sockaddr *) &pConn->clientname, &size);
- if (pConn->sock < 0)
- {
- ERR("accept error : %s(%d)\n", strerror(errno), errno);
- OGLS_removeConn( pConn );
- continue;
- }
-
- if( pthread_create( (pthread_t *)&taskid, NULL, (void *(*)(void *))OGLS_loop, (void *)pConn ) )
- {
- ERR("pthread_create error : %s(%d)\n", strerror(errno), errno);
- OGLS_removeConn( pConn );
- continue;
- }
- }
-
- closesocket( sock );
-}
-
-#if 0
-static void usage(void)
-{
- printf("Usage : opengl_server [OPTION]\n\n");
- printf("The following options are available :\n");
- printf("--port=XXXX : set XXX as the port number for the TCP/IP server \n");
- printf("--debug : output debugging trace on stderr\n");
- printf("--save : dump the serialialized OpenGL flow in a file (default : /tmp/debug_gl.bin)\n");
- printf("--filename=X : the file where to write the serailized OpenGL flow\n");
- printf("--different-windows : even if the client is on 127.0.0.1, display OpenGL on a new X window\n");
- printf("--parent-xid=XXX : use XXX as the XID of the parent X window where to display the OpenGL flow\n");
- printf(" This is useful if you want to run accelerated OpenGL inside a non-patched QEMU\n");
- printf(" or from another emulator, through TCP/IP\n");
- printf("--h or --help : display this help\n");
-}
-#endif
-
-//int main (int argc, char* argv[])
-void *init_opengl_server(void *arg)
-{
- OGLS_Opts option;
-
- memset( &option, 0, sizeof(option) );
-
- // set default values
- option.port = get_sdb_base_port() + SDB_TCP_OPENGL_INDEX;
- option.parent_xid = -1;
- option.refresh_rate = 1000;
- option.timestamp = 1; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
-
-#if 0
- for(i=1;i<argc;i++)
- {
- if (argv[i][0] == '-' && argv[i][1] == '-')
- argv[i] = argv[i]+1;
-
- if (strcmp(argv[i], "-debug") == 0)
- {
- option.display_function_call = 1;
- }
- else if (strcmp(argv[i], "-save") == 0)
- {
- option.must_save = 1;
- }
- else if (strncmp(argv[i], "-port=",6) == 0)
- {
- option.port = atoi(argv[i] + 6);
- }
- else if (strncmp(argv[i], "-filename=",strlen("-filename=")) == 0)
- {
- filename = argv[i] + strlen("-filename=");
- }
- else if (strncmp(argv[i], "-parent-xid=",strlen("-parent-xid=")) == 0)
- {
- char* c = argv[i] + strlen("-parent-xid=");
- option.parent_xid = strtol(c, NULL, 0);
- option.different_windows = 1;
- }
- else if (strcmp(argv[i], "-different-windows") == 0)
- {
- option.different_windows = 1;
- }
- else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0)
- {
- usage();
- return 0;
- }
- else
- {
- fprintf(stderr, "unknown parameter : %s\n", argv[i]);
- usage();
- return -1;
- }
- }
-#endif /* 0 */
-
- OGLS_main(&option);
- return 0;
-}
+++ /dev/null
-/*
- * opengl_server.h
- *
- * Created on: 2011. 6. 30.
- * Author: dhhong
- */
-
-#ifndef OPENGL_SERVER_H_
-#define OPENGL_SERVER_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <pthread.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <signal.h>
-
-#ifndef _WIN32
- #include <arpa/inet.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netinet/tcp.h>
- #include <netdb.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
-#else
- #include <windows.h>
- #include <winsock.h>
-#endif /* _WIN32 */
-
-#ifdef _WIN32
-#define socklen_t int
-typedef HDC Display;
-typedef unsigned long Window;
-#else
-#define closesocket close
-#endif
-
-typedef struct {
- int port;
- int different_windows;
- int display_function_call;
- int must_save;
- int parent_xid;
- int refresh_rate;
- int timestamp; /* only valid if must_save == 1. include timestamps in the save file to enable real-time playback */
-} OGLS_Opts;
-
-typedef struct {
- int sock;
- int count_last_time, count_current;
- struct timeval last_time, current_time, time_stamp_start;
- struct timeval last_read_time, current_read_time;
-
- struct sockaddr_in clientname;
-#ifdef _WIN32
- Display Display;
- HDC active_win; /* FIXME */
-#else
- Display* parent_dpy;
- Window qemu_parent_window;
-
- Display* Display;
- Window active_win; /* FIXME */
-#endif
- int active_win_x;
- int active_win_y;
-
- int local_connection;
-
- int last_assigned_internal_num;
- int last_active_internal_num;
-
- int nTabAssocAttribListVisual ;
- void* tabAssocAttribListVisual ;
- void * processTab;
-
- OGLS_Opts *pOption;
-} OGLS_Conn ;
-
-/* opengl_server main function */
-void *init_opengl_server(void *arg);
-
-#endif /* OPENGL_SERVER_H_ */
+++ /dev/null
-/*
- * Functions used by host & client sides
- *
- * Copyright (c) 2007 Even Rouault
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#ifndef _OPENGL_UTILS
-#define _OPENGL_UTILS
-
-typedef struct
-{
- unsigned int* values;
- int nbValues;
-} RangeAllocator;
-
-/*
- static void print_range(RangeAllocator* range)
- {
- int i;
- printf("%s", "table : ");
- for(i=0;i<range->nbValues;i++)
- {
- printf("%d ", range->values[i]);
- }
- printf("\n");
- }
- */
-
-static void alloc_value(RangeAllocator* range, unsigned int value)
-{
- if (value == 0) return;
- if (range->nbValues >= 1)
- {
- int lower = 0;
- int upper = range->nbValues-1;
- while(1)
- {
- int mid = (lower + upper) / 2;
- if (range->values[mid] > value)
- upper = mid;
- else if (range->values[mid] < value)
- lower = mid;
- else
- break;
- if (upper - lower <= 1)
- {
- if (value < range->values[lower])
- {
- range->values = realloc(range->values, (range->nbValues+1) * sizeof(int));
- memmove(&range->values[lower+1], &range->values[lower], (range->nbValues - lower) * sizeof(int));
- range->values[lower] = value;
- range->nbValues++;
- }
- else if (value == range->values[lower])
- {
- }
- else if (value < range->values[upper])
- {
- range->values = realloc(range->values, (range->nbValues+1) * sizeof(int));
- memmove(&range->values[upper+1], &range->values[upper], (range->nbValues - upper) * sizeof(int));
- range->values[upper] = value;
- range->nbValues++;
- }
- else if (value == range->values[upper])
- {
- }
- else
- {
- upper++;
-
- range->values = realloc(range->values, (range->nbValues+1) * sizeof(int));
- memmove(&range->values[upper+1], &range->values[upper], (range->nbValues - upper) * sizeof(int));
- range->values[upper] = value;
- range->nbValues++;
- }
- break;
- }
- }
- }
- else
- {
- range->values = malloc(sizeof(int));
- range->values[0] = value;
- range->nbValues = 1;
- }
-}
-
-/* return first value */
-static unsigned int alloc_range(RangeAllocator* range, int n, unsigned int* values)
-{
- int i, j;
- if (range->nbValues == 0)
- {
- range->nbValues = n;
- range->values = malloc(n * sizeof(int));
- for(i=0;i<n;i++)
- {
- range->values[i] = i+1;
- if (values)
- values[i] = range->values[i];
- }
- return 1;
- }
- else
- {
- int lastValue = 1;
- for(i=0;i<range->nbValues;i++)
- {
- if ((int)range->values[i] - (int)lastValue - 1 >= n)
- {
- range->values = realloc(range->values, (range->nbValues+n) * sizeof(int));
- memmove(&range->values[i+n], &range->values[i], (range->nbValues - i) * sizeof(int));
- for(j=0;j<n;j++)
- {
- range->values[i+j] = lastValue + 1 + j;
- if (values)
- values[j] = range->values[i+j];
- }
- range->nbValues += n;
- break;
- }
- else
- lastValue = range->values[i];
- }
- if (i == range->nbValues)
- {
- range->values = realloc(range->values, (range->nbValues+n) * sizeof(int));
- for(j=0;j<n;j++)
- {
- range->values[i+j] = lastValue + 1 + j;
- if (values)
- values[j] = range->values[i+j];
- }
- range->nbValues += n;
- }
- return lastValue + 1;
- }
-}
-
-static void delete_value(RangeAllocator* range, unsigned int value)
-{
- if (value == 0)
- return;
- if (range->nbValues >= 1)
- {
- int lower = 0;
- int upper = range->nbValues-1;
- while(1)
- {
- int mid = (lower + upper) / 2;
- if (range->values[mid] > value)
- upper = mid;
- else if (range->values[mid] < value)
- lower = mid;
- else
- {
- lower = upper = mid;
- }
- if (upper - lower <= 1)
- {
- if (value == range->values[lower])
- {
- memmove(&range->values[lower], &range->values[lower+1], (range->nbValues - lower-1) * sizeof(int));
- range->nbValues--;
- }
- else if (value == range->values[upper])
- {
- memmove(&range->values[upper], &range->values[upper+1], (range->nbValues - upper-1) * sizeof(int));
- range->nbValues--;
- }
- break;
- }
- }
- }
-}
-
-static void delete_range(RangeAllocator* range, int n, const unsigned int* values)
-{
- int i;
- for(i=0;i<n;i++)
- {
- delete_value(range, values[i]);
- }
-}
-
-static void delete_consecutive_values(RangeAllocator* range, unsigned int first, int n)
-{
- int i;
- for(i=0;i<n;i++)
- {
- delete_value(range, first + i);
- }
-}
-
-
-/*****************************************************************/
-/* */
-/* CRC LOOKUP TABLE */
-/* ================ */
-/* The following CRC lookup table was generated automagically */
-/* by the Rocksoft^tm Model CRC Algorithm Table Generation */
-/* Program V1.0 using the following model parameters: */
-/* */
-/* Width : 4 bytes. */
-/* Poly : 0x04C11DB7L */
-/* Reverse : TRUE. */
-/* */
-/* For more information on the Rocksoft^tm Model CRC Algorithm, */
-/* see the document titled "A Painless Guide to CRC Error */
-/* Detection Algorithms" by Ross Williams */
-/* (ross@guest.adelaide.edu.au.). This document is likely to be */
-/* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */
-/* */
-/*****************************************************************/
-
-static const unsigned int crctable[256] =
-{
- 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
- 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
- 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
- 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
- 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
- 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
- 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
- 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
- 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
- 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
- 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
- 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
- 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
- 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
- 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
- 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
- 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
- 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
- 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
- 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
- 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
- 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
- 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
- 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
- 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
- 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
- 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
- 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
- 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
- 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
- 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
- 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
- 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
- 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
- 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
- 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
- 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
- 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
- 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
- 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
- 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
- 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
- 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
- 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
- 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
- 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
- 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
- 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
- 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
- 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
- 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
- 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
- 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
- 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
- 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
- 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
- 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
- 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
- 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
- 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
- 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
- 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
- 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
- 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
-};
-#ifdef _WIN32
-static unsigned int calc_checksum(const void* _ptr, int length, unsigned int seed)
-#else
-static inline unsigned int calc_checksum(const void* _ptr, int length, unsigned int seed)
-#endif
-{
- int i;
- unsigned int crc = seed;
- unsigned char* ptr = (unsigned char*)_ptr;
- if (ptr == NULL)
- return -1;
- for(i=0;i<length;i++)
- {
- crc = crctable[(crc ^ *ptr++) & 0xFF] ^ (crc >> 8);
- }
- return crc;
-}
-
-
-#ifdef _WIN32
-static void display_gl_call(FILE* f, int func_number, long* args, int* args_size)
-#else
-static inline void display_gl_call(FILE* f, int func_number, long* args, int* args_size)
-#endif
-{
- int i;
- if (func_number < 0)
- {
- fprintf(f, "unknown call : %d\n", func_number);
- return;
- }
- Signature* signature = (Signature*)tab_opengl_calls[func_number];
- int nb_args = signature->nb_args;
- int* args_type = signature->args_type;
-
- //fprintf(f, "%s(", tab_opengl_calls_name[func_number]);
-
- for(i=0;i<nb_args;i++)
- {
- switch(args_type[i])
- {
- case TYPE_UNSIGNED_CHAR:
- case TYPE_CHAR:
- {
- fprintf(f, "%d", (char)args[i]);
- break;
- }
-
- case TYPE_UNSIGNED_SHORT:
- case TYPE_SHORT:
- {
- fprintf(f, "%d", (short)args[i]);
- break;
- }
-
- case TYPE_UNSIGNED_INT:
- case TYPE_INT:
- {
- fprintf(f, "%d", (int)args[i]);
- break;
- }
-
- case TYPE_FLOAT:
- fprintf(f, "%f", *(float*)&args[i]);
- break;
-
- case TYPE_DOUBLE:
-CASE_IN_KNOWN_SIZE_POINTERS:
- case TYPE_NULL_TERMINATED_STRING:
-CASE_IN_UNKNOWN_SIZE_POINTERS:
-CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
- if (args_type[i] == TYPE_NULL_TERMINATED_STRING)
- {
- fprintf(f, "\"%s\"", (char*)args[i]);
- }
- else if (args_type[i] == TYPE_DOUBLE)
- fprintf(f, "%f", *(double*)args[i]);
- else if (IS_ARRAY_CHAR(args_type[i]) && args_size[i] <= 4 * sizeof(char))
- {
- int j;
- int n = args_size[i] / sizeof(char);
- fprintf(f, "(");
- for(j=0;j<n;j++)
- {
- fprintf(f, "%d", ((unsigned char*)args[i])[j]);
- if (j != n - 1)
- fprintf(f, ", ");
- }
- fprintf(f, ")");
- }
- else if (IS_ARRAY_SHORT(args_type[i]) && args_size[i] <= 4 * sizeof(short))
- {
- int j;
- int n = args_size[i] / sizeof(short);
- fprintf(f, "(");
- for(j=0;j<n;j++)
- {
- fprintf(f, "%d", ((short*)args[i])[j]);
- if (j != n - 1)
- fprintf(f, ", ");
- }
- fprintf(f, ")");
- }
- else if (IS_ARRAY_INT(args_type[i]) && args_size[i] <= 4 * sizeof(int))
- {
- int j;
- int n = args_size[i] / sizeof(int);
- fprintf(f, "(");
- for(j=0;j<n;j++)
- {
- fprintf(f, "%d", ((int*)args[i])[j]);
- if (j != n - 1)
- fprintf(f, ", ");
- }
- fprintf(f, ")");
- }
- else if (IS_ARRAY_FLOAT(args_type[i]) && args_size[i] <= 4 * sizeof(float))
- {
- int j;
- int n = args_size[i] / sizeof(float);
- fprintf(f, "(");
- for(j=0;j<n;j++)
- {
- fprintf(f, "%f", ((float*)args[i])[j]);
- if (j != n - 1)
- fprintf(f, ", ");
- }
- fprintf(f, ")");
- }
- else if (IS_ARRAY_DOUBLE(args_type[i]) && args_size[i] <= 4 * sizeof(double))
- {
- int j;
- int n = args_size[i] / sizeof(double);
- fprintf(f, "(");
- for(j=0;j<n;j++)
- {
- fprintf(f, "%f", ((double*)args[i])[j]);
- if (j != n - 1)
- fprintf(f, ", ");
- }
- fprintf(f, ")");
- }
- else
- {
- fprintf(f, "%d bytes", args_size[i]);
- fprintf(f, "(crc = 0x%X)", calc_checksum((void*)args[i], args_size[i], 0xFFFFFFFF));
- }
- break;
-
-CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
-CASE_OUT_UNKNOWN_SIZE_POINTERS:
-CASE_OUT_KNOWN_SIZE_POINTERS:
- {
- fprintf(f, "%d bytes (OUT)", args_size[i]);
- break;
- }
-
- case TYPE_IN_IGNORED_POINTER:
- break;
-
- default:
- fprintf(f, "shouldn't happen : call %s arg %d\n", tab_opengl_calls_name[func_number], i);
- return;
- break;
- }
- if (i < nb_args - 1) fprintf(f, ", ");
- }
- fprintf(f, ")\n");
-}
-
-#endif
--disable-vnc-tls \
--audio-card-list=ac97 \
--enable-ldst-optimization \
- --enable-maru
+ --enable-maru \
+ --enable-gl
# --enable-ffmpeg
# --enable-v4l2 \
# --enable-debug \
--enable-mixemu \
--disable-vnc-tls \
--enable-ldst-optimization \
- --enable-maru
+ --enable-maru \
+ --enable-gl
# --enable-ffmpeg
# --disable-vnc-jpeg \
# --disable-jpeg
QEMU_CFLAGS += -I$(SRC_PATH)/tizen/distrib/ffmpeg/include
QEMU_CFLAGS += -L$(SRC_PATH)/tizen/distrib/ffmpeg/lib
QEMU_CFLAGS += $(SDL_CFLAGS)
+QEMU_CFLAGS += $(GLIB_CFLAGS)
ifdef CONFIG_WIN32
LIBS += -lavformat -lavcodec -lavutil -lm
LIBS += -lavformat -lavcodec -lavutil -lm -lGL
endif
+ifdef CONFIG_DEBUG_EXEC
+GL_CFLAGS := -Wall -g -O0 -fno-strict-aliasing
+else
+GL_CFLAGS := -Wall -g -O2 -fno-strict-aliasing
+endif
+
+###########################################################
+## Build openGL
+# i386
+ifeq ($(TARGET_ARCH), i386)
+
+GL_CUR_PATH = $(SRC_PATH)/tizen/src/hw
+
+GL_CFLAGS += -I$(QEMU_CFLAGS) -I$(GL_CUR_PATH) -I$(SRC_PATH)/fpu -I$(SRC_PATH)/$(TARGET_DIRS)
+
+parse_gl_h: parse_gl_h.c
+ $(CC) -g -o $@ $<
+server_stub.c: parse_gl_h
+ ./parse_gl_h 2>/dev/null
+gl_func.h: parse_gl_h
+ ./parse_gl_h 2>/dev/null
+opengl_func.h: gl_func.h
+helper_opengl.o: helper_opengl.c opengl_func.h server_stub.c opengl_process.h
+ $(CC) $(GL_CFLAGS) $(DEFINES) $(GL_LDFLAGS) -c -o $@ $<
+gl_beginend.h: $(GL_CUR_PATH)/beginend_funcs.sh
+ $< > $@
+mesa_mipmap.o : mesa_mipmap.c
+ $(CC) $(GL_CFLAGS) $(DEFINES) $(GL_LDFLAGS) -c -o $@ $<
+opengl_exec.o : opengl_exec.c server_stub.c opengl_func.h gl_beginend.h opengl_process.h mesa_mipmap.o
+ $(CC) $(GL_CFLAGS) $(DEFINES) $(GL_LDFLAGS) -c -o $@ $<
+
+endif #($(TARGET_ARCH), i386)
+###########################################################
+
# maru loader
obj-y += emulator.o emul_state.o process.o option.o maru_signal.o maru_sdl.o
obj-i386-y += guest_server.o
ifndef CONFIG_WIN32
-##########################################################
-# opengl library for i386
-obj-i386-y += helper_opengl.o opengl_exec.o opengl_server.o
-##########################################################
-
-##########################################################
-# Build openGL
-# i386
-ifeq ($(TARGET_ARCH), i386)
-parse_gl_h: $(TARGET_PATH)/parse_gl_h.c
- $(CC) -Wall -O2 -g $< -o $@
-
-client_stub.c server_stub.c gl_func.h: parse_gl_h
- ./parse_gl_h
-
-opengl_exec.o: opengl_exec.c server_stub.c gl_func.h
-
-opengl_server.o: opengl_server.c opengl_exec.c
-
-helper_opengl.o: gl_func.h
-
-$(TARGET_PATH)/libGL.so.1: opengl_client.c gl_func.h
- $(CC) -I$(TARGET_PATH) -I. -Wall -g -O2 $< -shared -o $@
-endif
-
-# arm
-#gles1_calls.o: gles1_calls.c gles2.h gles2_calls.h
-#gles2_calls.o: gles2_calls.c gles2.h gles2_calls.h
-#gles2.o: gles2.c gles2.h gles2_calls.h
-
-##########################################################
-endif
-
+###########################################################
+## opengl library for i386
+obj-i386-y += virtio-gl.o helper_opengl.o opengl_exec.o mesa_mipmap.o gloffscreen_common.o gloffscreen_xcomposite.o gloffscreen_wgl.o gloffscreen_test.o
+###########################################################
+endif
\ No newline at end of file
--- /dev/null
+#! /bin/bash
+# Copyright 2008 (C) Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISiNG FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# echo names of functions that are legal between a glBegin and glEnd pair.
+echo -e MAGIC_MACRO\(glVertex{2,3,4}{s,i,f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glTexCoord{1,2,3,4}{s,i,f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glMultiTexCoord{1,2,3,4}{s,i,f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glNormal3{b,s,i,f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glFogCoord{f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glColor{3,4}{b,s,i,f,d,ub,us,ui}{,v}\)\\n
+echo -e MAGIC_MACRO\(glSecondaryColor3{b,s,i,f,d,ub,us,ui}{,v}\)\\n
+echo -e MAGIC_MACRO\(glIndex{s,i,f,d,ub}{,v}\)\\n
+echo -e MAGIC_MACRO\(glVertexAttrib{1,2,3,4}{s,f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glVertexAttrib4{b,i,ub,us,ui}v\)\\n
+echo -e MAGIC_MACRO\(glVertexAttrib4Nub\)\\n
+echo -e MAGIC_MACRO\(glVertexAttrib4N{b,s,i,ub,us,ui}v\)\\n
+echo -e MAGIC_MACRO\(glArrayElement\)\\n
+echo -e MAGIC_MACRO\(glEvalCoord{1,2}{f,d}{,v}\)\\n
+echo -e MAGIC_MACRO\(glEvalPoint{1,2}\)\\n
+echo -e MAGIC_MACRO\(glMaterial{i,f}{,v}\)\\n
+echo -e MAGIC_MACRO\(glCallList\)\\n
+echo -e MAGIC_MACRO\(glCallLists\)\\n
+echo -e MAGIC_MACRO\(glEdgeFlag{,v}\)\\n
* THE SOFTWARE.
*/
-MAGIC_MACRO(_init),
-MAGIC_MACRO(_synchronize),
-MAGIC_MACRO(_serialized_calls),
-MAGIC_MACRO(_exit_process),
-MAGIC_MACRO(_moveResizeWindow),
-MAGIC_MACRO(_changeWindowState),
-MAGIC_MACRO(_send_cursor),
+MAGIC_MACRO(_init32),
+MAGIC_MACRO(_init64),
+MAGIC_MACRO(_resize_surface),
+MAGIC_MACRO(_render_surface),
/* When you add a glX call here, you HAVE TO update IS_GLX_CALL */
MAGIC_MACRO(glXChooseVisual),
MAGIC_MACRO(glXWaitX),
MAGIC_MACRO(glXGetFBConfigAttrib_extended),
MAGIC_MACRO(glXChooseFBConfig),
-MAGIC_MACRO(glXChooseFBConfigSGIX),
MAGIC_MACRO(glXGetFBConfigs),
-MAGIC_MACRO(glXDestroyWindow),
-MAGIC_MACRO(glXCreatePbuffer),
-MAGIC_MACRO(glXCreateGLXPbufferSGIX),
-MAGIC_MACRO(glXDestroyPbuffer),
-MAGIC_MACRO(glXDestroyGLXPbufferSGIX),
MAGIC_MACRO(glXCreateNewContext),
-MAGIC_MACRO(glXCreateContextWithConfigSGIX),
MAGIC_MACRO(glXGetVisualFromFBConfig),
MAGIC_MACRO(glXGetFBConfigAttrib),
-MAGIC_MACRO(glXGetFBConfigAttribSGIX),
MAGIC_MACRO(glXQueryContext),
MAGIC_MACRO(glXQueryDrawable),
-MAGIC_MACRO(glXQueryGLXPbufferSGIX),
MAGIC_MACRO(glXUseXFont),
MAGIC_MACRO(glXIsDirect),
MAGIC_MACRO(glXGetProcAddress_fake),
MAGIC_MACRO(glXGetScreenDriver),
MAGIC_MACRO(glXGetDriverConfig),
MAGIC_MACRO(glXSwapIntervalSGI),
-MAGIC_MACRO(glXBindTexImageATI),
-MAGIC_MACRO(glXReleaseTexImageATI),
-MAGIC_MACRO(glXBindTexImageARB),
-MAGIC_MACRO(glXReleaseTexImageARB),
MAGIC_MACRO(glGetString),
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef GLOFFSCREEN_H_
+#define GLOFFSCREEN_H_
+
+/* Used to hold data for the OpenGL context */
+struct _GloContext;
+typedef struct _GloContext GloContext;
+/* Used to hold data for an offscreen surface. */
+struct _GloSurface;
+typedef struct _GloSurface GloSurface;
+
+/* Format flags for glo_surface_create */
+#define GLO_FF_ALPHA_MASK (0x0001)
+#define GLO_FF_NOALPHA (0x0000)
+#define GLO_FF_ALPHA (0x0001)
+
+#define GLO_FF_BITS_MASK (0x00F0)
+#define GLO_FF_BITS_16 (0x0020)
+#define GLO_FF_BITS_24 (0x0030)
+#define GLO_FF_BITS_32 (0x0040)
+
+#define GLO_FF_DEPTH_MASK (0x0F00)
+#define GLO_FF_DEPTH_16 (0x0100)
+#define GLO_FF_DEPTH_24 (0x0200)
+#define GLO_FF_DEPTH_32 (0x0300)
+
+#define GLO_FF_STENCIL_MASK (0xF000)
+#define GLO_FF_STENCIL_8 (0x1000)
+
+/* The only currently supported format */
+#define GLO_FF_DEFAULT (GLO_FF_BITS_24|GLO_FF_DEPTH_24)
+
+/* Has gloffscreen been previously initialised? */
+extern int glo_initialised(void);
+
+/* Initialise gloffscreen */
+extern void glo_init(void);
+
+/* Uninitialise gloffscreen */
+extern void glo_kill(void);
+
+/* Like wglGetProcAddress/glxGetProcAddress */
+extern void *glo_getprocaddress(const char *procName);
+
+/* OS-independent glXQueryExtensionsString */
+extern const char *glo_glXQueryExtensionsString(void);
+
+/* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
+extern GloContext *glo_context_create(int formatFlags, GloContext *shareLists);
+
+/* Destroy a previouslu created OpenGL context */
+extern void glo_context_destroy(GloContext *context);
+
+/* Create a surface with given width and height, */
+extern GloSurface *glo_surface_create(int width, int height, GloContext *context);
+
+/* Destroy the given surface */
+extern void glo_surface_destroy(GloSurface *surface);
+
+/* Make the given surface current */
+extern int glo_surface_makecurrent(GloSurface *surface);
+
+/* Get the contents of the given surface. Note that this is top-down, not
+ * bottom-up as glReadPixels would do. */
+extern void glo_surface_getcontents(GloSurface *surface, int stride, int type, void *data);
+
+/* Return the width and height of the given surface */
+extern void glo_surface_get_size(GloSurface *surface, int *width, int *height);
+
+/* Functions to decode the format flags */
+extern int glo_flags_get_depth_bits(int formatFlags);
+extern int glo_flags_get_stencil_bits(int formatFlags);
+extern void glo_flags_get_rgba_bits(int formatFlags, int *rgba);
+extern int glo_flags_get_bytes_per_pixel(int formatFlags);
+extern void glo_flags_get_readpixel_type(int formatFlags, int *glFormat, int *glType);
+/* Score how close the given format flags match. 0=great, >0 not so great */
+extern int glo_flags_score(int formatFlagsExpected, int formatFlagsReal);
+
+/* Create a set of format flags from a null-terminated list
+ * of GLX fbConfig flags. If assumeBooleans is set, items such
+ * as GLX_RGBA/GLX_DOUBLEBUFFER are treated as booleans, not key-value pairs
+ * (glXChooseVisual treats them as booleans, glXChooseFBConfig as key-value pairs)
+ */
+extern int glo_flags_get_from_glx(const int *fbConfig, int assumeBooleans);
+/* Use in place of glxGetConfig - returns information from flags based on a GLX enum */
+extern int glo_get_glx_from_flags(int formatFlags, int glxEnum);
+
+
+/* In terms of speed, glReadPixels actually seems the best we can do.
+ * * On Windows PFB_DRAW_TO_BITMAP is software-only.
+ * * http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt would be
+ * useful if we didn't want the data right away (as we could avoid flushing the
+ * pipeline).
+ * * The internal data format seems to be GL_BGRA - and this is indeed faster.
+ * * Apple suggests using GL_UNSIGNED_INT_8_8_8_8_REV instead of
+ * GL_UNSIGNED_BYTE, but there don't appear to be any speed increase from
+ * doing this on Windows at least.
+ */
+
+#endif /* GLOFFSCREEN_H_ */
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer - Common utilities
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "gloffscreen.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glext.h>
+#else
+#include <GL/gl.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void *g_malloc(size_t size);
+void *g_realloc(void *ptr, size_t size);
+void g_free(void *ptr);
+
+// ---------------------------------------------------
+// Copied from glx.h as we need them in windows too
+/*
+ * Tokens for glXChooseVisual and glXGetConfig:
+ */
+#define GLX_USE_GL 1
+#define GLX_BUFFER_SIZE 2
+#define GLX_LEVEL 3
+#define GLX_RGBA 4
+#define GLX_DOUBLEBUFFER 5
+#define GLX_STEREO 6
+#define GLX_AUX_BUFFERS 7
+#define GLX_RED_SIZE 8
+#define GLX_GREEN_SIZE 9
+#define GLX_BLUE_SIZE 10
+#define GLX_ALPHA_SIZE 11
+#define GLX_DEPTH_SIZE 12
+#define GLX_STENCIL_SIZE 13
+#define GLX_ACCUM_RED_SIZE 14
+#define GLX_ACCUM_GREEN_SIZE 15
+#define GLX_ACCUM_BLUE_SIZE 16
+#define GLX_ACCUM_ALPHA_SIZE 17
+/*
+ * GLX 1.3 and later:
+ */
+#define GLX_CONFIG_CAVEAT 0x20
+#define GLX_DONT_CARE 0xFFFFFFFF
+#define GLX_X_VISUAL_TYPE 0x22
+#define GLX_TRANSPARENT_TYPE 0x23
+#define GLX_TRANSPARENT_INDEX_VALUE 0x24
+#define GLX_TRANSPARENT_RED_VALUE 0x25
+#define GLX_TRANSPARENT_GREEN_VALUE 0x26
+#define GLX_TRANSPARENT_BLUE_VALUE 0x27
+#define GLX_TRANSPARENT_ALPHA_VALUE 0x28
+#define GLX_WINDOW_BIT 0x00000001
+#define GLX_NONE 0x8000
+#define GLX_TRUE_COLOR 0x8002
+#define GLX_VISUAL_ID 0x800B
+#define GLX_DRAWABLE_TYPE 0x8010
+#define GLX_RENDER_TYPE 0x8011
+#define GLX_X_RENDERABLE 0x8012
+#define GLX_FBCONFIG_ID 0x8013
+#define GLX_RGBA_TYPE 0x8014
+#define GLX_MAX_PBUFFER_WIDTH 0x8016
+#define GLX_MAX_PBUFFER_HEIGHT 0x8017
+#define GLX_MAX_PBUFFER_PIXELS 0x8018
+#define GLX_LARGEST_PBUFFER 0x801C
+#define GLX_RGBA_BIT 0x00000001
+
+// ---------------------------------------------------
+
+extern void glo_surface_getcontents_readpixels(int formatFlags, int stride,
+ int bpp, int width, int height, void *data);
+
+// ---------------------------------------------------
+
+int glo_flags_get_depth_bits(int formatFlags) {
+ switch ( formatFlags & GLO_FF_DEPTH_MASK ) {
+ case GLO_FF_DEPTH_16: return 16;
+ case GLO_FF_DEPTH_24: return 24;
+ case GLO_FF_DEPTH_32: return 32;
+ default: return 0;
+ }
+}
+
+int glo_flags_get_stencil_bits(int formatFlags) {
+ switch ( formatFlags & GLO_FF_STENCIL_MASK ) {
+ case GLO_FF_STENCIL_8: return 8;
+ default: return 0;
+ }
+}
+
+void glo_flags_get_rgba_bits(int formatFlags, int *rgba) {
+ int alpha = (formatFlags & GLO_FF_ALPHA) != 0;
+ switch ( formatFlags & GLO_FF_BITS_MASK ) {
+ case GLO_FF_BITS_16:
+ rgba[0] = alpha ? 4 : 5;
+ rgba[1] = alpha ? 4 : 6;
+ rgba[2] = alpha ? 4 : 5;
+ rgba[3] = alpha ? 4 : 0;
+ break;
+ case GLO_FF_BITS_24:
+ // ignore alpha
+ rgba[0] = 8;
+ rgba[1] = 8;
+ rgba[2] = 8;
+ rgba[3] = 0;
+ break;
+ case GLO_FF_BITS_32:
+ rgba[0] = 8;
+ rgba[1] = 8;
+ rgba[2] = 8;
+ rgba[3] = 8;
+ break;
+ default:
+ rgba[0] = 8;
+ rgba[1] = 8;
+ rgba[2] = 8;
+ rgba[3] = 0;
+ break;
+ }
+}
+
+int glo_flags_get_bytes_per_pixel(int formatFlags) {
+ switch ( formatFlags & GLO_FF_BITS_MASK ) {
+ case GLO_FF_BITS_16: return 2;
+ case GLO_FF_BITS_24: return 3;
+ case GLO_FF_BITS_32: return 4;
+ default: return 3;
+ }
+}
+
+void glo_flags_get_readpixel_type(int formatFlags, int *glFormat, int *glType) {
+ GLenum gFormat, gType;
+
+ if (formatFlags & GLO_FF_ALPHA) {
+ switch ( formatFlags & GLO_FF_BITS_MASK ) {
+ case GLO_FF_BITS_16:
+ gFormat = GL_RGBA;
+ gType = GL_UNSIGNED_SHORT_4_4_4_4;
+ break;
+ case GLO_FF_BITS_24:
+ case GLO_FF_BITS_32:
+ default:
+ gFormat = GL_BGRA;
+ gType = GL_UNSIGNED_BYTE;
+ break;
+ }
+ } else {
+ switch ( formatFlags & GLO_FF_BITS_MASK ) {
+ case GLO_FF_BITS_16:
+ gFormat = GL_RGB;
+ gType = GL_UNSIGNED_SHORT_5_6_5;
+ break;
+ case GLO_FF_BITS_24:
+ case GLO_FF_BITS_32:
+ default:
+ gFormat = GL_BGR;
+ gType = GL_UNSIGNED_BYTE;
+ break;
+ }
+ }
+
+ if (glFormat)
+ *glFormat = gFormat;
+ if (glType)
+ *glType = gType;
+}
+
+#if 0
+// seems wrong below.
+int glo_flags_score(int formatFlagsExpected, int formatFlagsReal) {
+
+ if (formatFlagsExpected == formatFlagsReal)
+ return 0;
+
+ int score = 1;
+
+ // we wanted alpha, but we didn't get it
+ if ((formatFlagsExpected&GLO_FF_ALPHA_MASK) <
+ (formatFlagsReal&GLO_FF_ALPHA_MASK))
+ score++;
+ // less bits than we expected
+ if ((formatFlagsExpected&GLO_FF_BITS_MASK) <
+ !(formatFlagsReal&GLO_FF_BITS_MASK))
+ score++;
+ // less depth bits than we expected
+ if ((formatFlagsExpected&GLO_FF_DEPTH_MASK) <
+ !(formatFlagsReal&GLO_FF_DEPTH_MASK))
+ score++;
+ // less stencil bits than we expected
+ if ((formatFlagsExpected&GLO_FF_STENCIL_MASK) <
+ !(formatFlagsReal&GLO_FF_STENCIL_MASK))
+ score++;
+
+ return score;
+}
+#else
+int glo_flags_score(int formatFlagsExpected, int formatFlagsReal) {
+
+ if (formatFlagsExpected == formatFlagsReal)
+ return 0;
+
+ int score = 1;
+
+ // we wanted alpha, but we didn't get it
+ if ((formatFlagsReal & GLO_FF_ALPHA_MASK) <
+ (formatFlagsExpected & GLO_FF_ALPHA_MASK))
+ score++;
+ // less bits than we expected
+ if ((formatFlagsReal & GLO_FF_BITS_MASK) <
+ (formatFlagsExpected & GLO_FF_BITS_MASK))
+ score++;
+ // less depth bits than we expected
+ if ((formatFlagsReal & GLO_FF_DEPTH_MASK) <
+ (formatFlagsExpected & GLO_FF_DEPTH_MASK))
+ score++;
+ // less stencil bits than we expected
+ if ((formatFlagsReal & GLO_FF_STENCIL_MASK) <
+ (formatFlagsExpected & GLO_FF_STENCIL_MASK))
+ score++;
+
+ return score;
+}
+#endif
+
+int glo_flags_get_from_glx(const int *fbConfig, int assumeBooleans) {
+ int bufferSize = 0;
+ int depthSize = 0;
+ int stencilSize = 0;
+ int rgbaSize[] = {0,0,0,0};
+ int flags = 0;
+
+ while (*fbConfig) {
+ int isSingle = 0;
+ switch (*fbConfig) {
+ case GLX_USE_GL:
+ isSingle = 1;
+ break;
+ case GLX_BUFFER_SIZE:
+ bufferSize = fbConfig[1];
+ break;
+ case GLX_LEVEL:
+ break;
+ case GLX_RGBA:
+ flags |= GLO_FF_ALPHA;
+ break;
+ case GLX_DOUBLEBUFFER:
+ isSingle = 1;
+ break;
+ case GLX_STEREO:
+ isSingle = 1;
+ break;
+ case GLX_AUX_BUFFERS:
+ break;
+ case GLX_RED_SIZE:
+ rgbaSize[0] = fbConfig[1];
+ break;
+ case GLX_GREEN_SIZE:
+ rgbaSize[1] = fbConfig[1];
+ break;
+ case GLX_BLUE_SIZE:
+ rgbaSize[2] = fbConfig[1];
+ break;
+ case GLX_ALPHA_SIZE:
+ rgbaSize[3] = fbConfig[1];
+ break;
+ case GLX_DEPTH_SIZE:
+ depthSize = fbConfig[1];
+ break;
+ case GLX_STENCIL_SIZE:
+ stencilSize = fbConfig[1];
+ break;
+ case GLX_ACCUM_RED_SIZE:
+ case GLX_ACCUM_GREEN_SIZE:
+ case GLX_ACCUM_BLUE_SIZE:
+ case GLX_ACCUM_ALPHA_SIZE:
+ break;
+ }
+
+ // go to next
+ if (isSingle && assumeBooleans)
+ fbConfig++;
+ else
+ fbConfig+=2;
+ }
+
+ if (rgbaSize[3])
+ flags |= GLO_FF_ALPHA;
+ // ensure we have room for *some* alpha
+ if ((flags & GLO_FF_ALPHA) && (rgbaSize[3]==0))
+ rgbaSize[3] = 1;
+ // Buffer size flag
+ if (bufferSize==0)
+ bufferSize = rgbaSize[0]+rgbaSize[1]+rgbaSize[2]+rgbaSize[3];
+ if (bufferSize==0)
+ bufferSize = (flags & GLO_FF_ALPHA) ? 32 : 24;
+ if (bufferSize<=16)
+ flags |= GLO_FF_BITS_16;
+ else if (bufferSize<=24)
+ flags |= GLO_FF_BITS_24;
+ else
+ flags |= GLO_FF_BITS_32;
+
+ // Depth
+ if (depthSize<=16)
+ flags |= GLO_FF_DEPTH_16;
+ else if (depthSize<=24)
+ flags |= GLO_FF_DEPTH_24;
+ else
+ flags |= GLO_FF_DEPTH_32;
+ // Stencil
+ if (stencilSize>0)
+ flags |= GLO_FF_STENCIL_8;
+
+ return flags;
+}
+
+void glo_surface_getcontents_readpixels(int formatFlags, int stride, int bpp,
+ int width, int height, void *data) {
+ int glFormat, glType, rl, pa;
+ static int once;
+
+ glo_flags_get_readpixel_type(formatFlags, &glFormat, &glType);
+ switch(bpp) {
+ case 24:
+ if(glFormat != GL_BGR) {
+ if(!once) {
+ fprintf(stderr, "Warning: compressing alpha\n");
+ once = 1;
+ }
+ glFormat = GL_BGR;
+ }
+ break;
+ case 32:
+ if(glFormat != GL_BGRA) {
+ fprintf(stderr, "Warning: expanding alpha!\n");
+ glFormat = GL_BGRA;
+ }
+ break;
+ default:
+ fprintf(stderr, "Warning: unsupported colourdepth\n");
+ break;
+ }
+
+ // Save guest processes GL state before we ReadPixels()
+ glGetIntegerv(GL_PACK_ROW_LENGTH, &rl);
+ glGetIntegerv(GL_PACK_ALIGNMENT, &pa);
+ glPixelStorei(GL_PACK_ROW_LENGTH, 0);
+ glPixelStorei(GL_PACK_ALIGNMENT, 4);
+
+#ifdef GETCONTENTS_INDIVIDUAL
+ GLubyte *b = (GLubyte *)data;
+ int irow;
+ for(irow = height-1 ; irow >= 0 ; irow--) {
+ glReadPixels(0, irow, width, 1, glFormat, glType, b);
+ b += stride;
+ }
+#else
+ // Faster buffer flip
+ GLubyte *b = (GLubyte *)data;
+ GLubyte *c = &((GLubyte *)data)[stride*(height-1)];
+ GLubyte *tmp = (GLubyte*)g_malloc(stride);
+ int irow;
+
+ glReadPixels(0, 0, width, height, glFormat, glType, data);
+
+ for(irow = 0; irow < height/2; irow++) {
+ memcpy(tmp, b, stride);
+ memcpy(b, c, stride);
+ memcpy(c, tmp, stride);
+ b += stride;
+ c -= stride;
+ }
+ g_free(tmp);
+
+#endif
+
+ // Restore GL state
+ glPixelStorei(GL_PACK_ROW_LENGTH, rl);
+ glPixelStorei(GL_PACK_ALIGNMENT, pa);
+}
+
+int glo_get_glx_from_flags(int formatFlags, int glxEnum) {
+ int rgba[4];
+ glo_flags_get_rgba_bits(formatFlags, rgba);
+
+ switch (glxEnum) {
+ case GLX_USE_GL: return 1;
+ case GLX_BUFFER_SIZE:
+ return glo_flags_get_bytes_per_pixel(formatFlags)*8;
+ case GLX_LEVEL: return 0;
+ case GLX_RGBA: return formatFlags & GLO_FF_ALPHA;
+ case GLX_DOUBLEBUFFER: return 1;
+ case GLX_STEREO: return 0;
+ case GLX_AUX_BUFFERS: return 0;
+ case GLX_RED_SIZE: return rgba[0];
+ case GLX_GREEN_SIZE: return rgba[1];
+ case GLX_BLUE_SIZE: return rgba[2];
+ case GLX_ALPHA_SIZE: return rgba[3];
+ case GLX_DEPTH_SIZE: return glo_flags_get_depth_bits(formatFlags);
+ case GLX_STENCIL_SIZE: return glo_flags_get_stencil_bits(formatFlags);
+ case GLX_ACCUM_RED_SIZE:
+ case GLX_ACCUM_GREEN_SIZE:
+ case GLX_ACCUM_BLUE_SIZE:
+ case GLX_ACCUM_ALPHA_SIZE:
+ return 0;
+ //the attributes for glXGetFBConfigAttrib
+ case GLX_FBCONFIG_ID: return 0;
+ case GLX_RENDER_TYPE: return GLX_RGBA_BIT;
+ case GLX_DRAWABLE_TYPE: return GLX_WINDOW_BIT;
+ case GLX_X_RENDERABLE: return 1;
+ case GLX_VISUAL_ID:
+ case GLX_X_VISUAL_TYPE:
+ // the real value is obtained in client side.
+ return 0;
+ case GLX_CONFIG_CAVEAT: return GLX_NONE;
+ case GLX_TRANSPARENT_TYPE: return GLX_NONE;
+ case GLX_TRANSPARENT_INDEX_VALUE:
+ case GLX_TRANSPARENT_RED_VALUE:
+ case GLX_TRANSPARENT_GREEN_VALUE:
+ case GLX_TRANSPARENT_BLUE_VALUE:
+ case GLX_TRANSPARENT_ALPHA_VALUE:
+ return 0;
+ case GLX_MAX_PBUFFER_WIDTH:
+ case GLX_MAX_PBUFFER_HEIGHT:
+ case GLX_MAX_PBUFFER_PIXELS:
+ return 0;
+ }
+ return 0;
+}
+
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer - GLX specific
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef _WIN32
+#include "gloffscreen.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+struct GloMain {
+ Display *dpy;
+ int use_ximage;
+};
+struct GloMain glo;
+int glo_inited = 0;
+
+struct _GloContext {
+ GLuint formatFlags;
+
+ GLXFBConfig fbConfig;
+ GLXContext context;
+};
+
+struct _GloSurface {
+ GLuint width;
+ GLuint height;
+
+ GloContext *context;
+ Pixmap xPixmap;
+ GLXPixmap glxPixmap;
+
+ // For use by the 'fast' copy code.
+ XImage *image;
+ XShmSegmentInfo shminfo;
+};
+
+extern void glo_surface_getcontents_readpixels(int formatFlags, int stride,
+ int bpp, int width, int height, void *data);
+static void glo_test_readback_methods(void);
+
+/* ------------------------------------------------------------------------ */
+
+int glo_initialised(void) {
+ return glo_inited;
+}
+
+/* Initialise gloffscreen */
+void glo_init(void) {
+ if (glo_inited) {
+ printf( "gloffscreen already inited\n" );
+ exit( EXIT_FAILURE );
+ }
+ /* Open a connection to the X server */
+ glo.dpy = XOpenDisplay( NULL );
+ if ( glo.dpy == NULL ) {
+ printf( "Unable to open a connection to the X server\n" );
+ exit( EXIT_FAILURE );
+ }
+ glo_inited = 1;
+ glo_test_readback_methods();
+}
+
+/* Uninitialise gloffscreen */
+void glo_kill(void) {
+ XCloseDisplay(glo.dpy);
+ glo.dpy = NULL;
+}
+
+
+/* Like wglGetProcAddress/glxGetProcAddress */
+void *glo_getprocaddress(const char *procName) {
+ if (!glo_inited)
+ glo_init();
+ return glXGetProcAddressARB((const GLubyte *) procName);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
+GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
+ if (!glo_inited)
+ glo_init();
+
+ GLXFBConfig *fbConfigs;
+ int numReturned;
+ GloContext *context;
+ int rgbaBits[4];
+ int bufferAttributes[] = {
+ GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
+ GLX_STENCIL_SIZE, 0,
+ None
+ };
+
+ if (!glo_inited)
+ glo_init();
+
+ // set up the surface format from the flags we were given
+ glo_flags_get_rgba_bits(formatFlags, rgbaBits);
+ bufferAttributes[5] = rgbaBits[0];
+ bufferAttributes[7] = rgbaBits[1];
+ bufferAttributes[9] = rgbaBits[2];
+ bufferAttributes[11] = rgbaBits[3];
+ bufferAttributes[13] = glo_flags_get_depth_bits(formatFlags);
+ bufferAttributes[15] = glo_flags_get_stencil_bits(formatFlags);
+
+ //printf("Got R%d, G%d, B%d, A%d\n", rgbaBits[0], rgbaBits[1], rgbaBits[2], rgbaBits[3]);
+
+ fbConfigs = glXChooseFBConfig( glo.dpy, DefaultScreen(glo.dpy),
+ bufferAttributes, &numReturned );
+ if (numReturned==0) {
+ printf( "No matching configs found.\n" );
+ exit( EXIT_FAILURE );
+ }
+ context = (GloContext*)qemu_malloc(sizeof(GloContext));
+ memset(context, 0, sizeof(GloContext));
+ context->formatFlags = formatFlags;
+ context->fbConfig = fbConfigs[0];
+
+ /* Create a GLX context for OpenGL rendering */
+ context->context = glXCreateNewContext(glo.dpy, context->fbConfig,
+ GLX_RGBA_TYPE,
+ shareLists ? shareLists->context: NULL,
+ True );
+
+ if (!context->context) {
+ printf( "glXCreateNewContext failed\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ return context;
+}
+
+/* Destroy a previouslu created OpenGL context */
+void glo_context_destroy(GloContext *context) {
+ if (!context) return;
+ // TODO: check for GloSurfaces using this?
+ glXDestroyContext( glo.dpy, context->context);
+ qemu_free(context);
+}
+
+static void glo_surface_free_xshm_image(GloSurface *surface) {
+ XShmDetach(glo.dpy, &surface->shminfo);
+ surface->image->data = NULL;
+ XDestroyImage(surface->image);
+ shmdt(surface->shminfo.shmaddr);
+ shmctl(surface->shminfo.shmid, IPC_RMID, NULL);
+}
+
+//FIXMEIM - handle failure to allocate.
+static void glo_surface_try_alloc_xshm_image(GloSurface *surface) {
+ if(surface->image)
+ glo_surface_free_xshm_image(surface);
+
+ surface->image =
+ XShmCreateImage(glo.dpy, DefaultVisual(glo.dpy, 0), 24, ZPixmap, NULL,
+ &surface->shminfo, surface->width, surface->height);
+ surface->shminfo.shmid = shmget(IPC_PRIVATE,
+ surface->image->bytes_per_line *
+ surface->height,
+ IPC_CREAT | 0777);
+ surface->shminfo.shmaddr = shmat(surface->shminfo.shmid, NULL, 0);
+ surface->image->data = surface->shminfo.shmaddr;
+ surface->shminfo.readOnly = False;
+ XShmAttach(glo.dpy, &surface->shminfo);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create a surface with given width and height, formatflags are from the
+ * GLO_ constants */
+GloSurface *glo_surface_create(int width, int height, GloContext *context) {
+ GloSurface *surface;
+
+ if (!context) return 0;
+
+ surface = (GloSurface*)qemu_malloc(sizeof(GloSurface));
+ memset(surface, 0, sizeof(GloSurface));
+ surface->width = width;
+ surface->height = height;
+ surface->context = context;
+ surface->xPixmap = XCreatePixmap( glo.dpy, DefaultRootWindow(glo.dpy),
+ width, height,
+ glo_flags_get_bytes_per_pixel(context->formatFlags)*8);
+
+ if (!surface->xPixmap) {
+ printf( "XCreatePixmap failed\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ /* Create a GLX window to associate the frame buffer configuration
+ ** with the created X window */
+ surface->glxPixmap = glXCreatePixmap( glo.dpy, context->fbConfig, surface->xPixmap, NULL );
+ if (!surface->glxPixmap) {
+ printf( "glXCreatePixmap failed\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ // If we're using XImages to pull the data from the graphics card...
+ glo_surface_try_alloc_xshm_image(surface);
+
+ return surface;
+}
+
+/* Destroy the given surface */
+void glo_surface_destroy(GloSurface *surface) {
+ glXDestroyPixmap( glo.dpy, surface->glxPixmap);
+ XFreePixmap( glo.dpy, surface->xPixmap);
+ if(surface->image)
+ glo_surface_free_xshm_image(surface);
+ qemu_free(surface);
+}
+
+/* Make the given surface current */
+int glo_surface_makecurrent(GloSurface *surface) {
+ int ret;
+
+ if (!glo_inited)
+ glo_init();
+
+ if (surface) {
+ ret = glXMakeCurrent(glo.dpy, surface->glxPixmap, surface->context->context);
+ } else {
+ ret = glXMakeCurrent(glo.dpy, 0, NULL);
+ }
+
+ return ret;
+}
+
+/*
+#define geti(a) \
+ do { \
+ int b; \
+ glGetIntegerv(a, &b); \
+ fprintf(stderr, "%s: %d\n", #a, b); \
+ } while (0);
+*/
+
+/* Get the contents of the given surface */
+void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *data) {
+ static int once;
+ XImage *img;
+
+ if (!surface)
+ return;
+
+ if(glo.use_ximage) {
+ glXWaitGL();
+
+ if(surface->image) {
+ XShmGetImage (glo.dpy, surface->xPixmap, surface->image, 0, 0, AllPlanes);
+ img = surface->image;
+ }
+ else {
+ img = XGetImage(glo.dpy, surface->xPixmap, 0, 0, surface->width, surface->height, AllPlanes, ZPixmap);
+ }
+
+ if (img) {
+ if(bpp != 32 && bpp != 24 && !once) {
+ fprintf(stderr, "Warning: unsupported colourdepth\n");
+ once = 1;
+ }
+
+ if(bpp == img->bits_per_pixel && stride == img->bytes_per_line)
+ {
+ memcpy(data, img->data, stride * surface->height);
+ }
+ else
+ {
+ int x, y;
+ for(y = 0 ; y < surface->height ; y++) {
+ for(x = 0 ; x < surface->width ; x++) {
+ char *src = ((char*)img->data) + (x*(img->bits_per_pixel/8)) + (y*img->bytes_per_line);
+ char *dst = ((char*)data) + x*(bpp/8) + (y*stride);
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ if(bpp == 32)
+ dst[3] = 0xff; // if guest is 32 bit and host is 24
+ }
+ }
+ }
+
+ // If we're not using Shm
+ if(!surface->image)
+ XDestroyImage(img);
+
+ return; // We're done.
+ }
+ // Uh oh... better fallback. Perhaps get glo.use_ximage to 0?
+ }
+
+ // Compatible / fallback method.
+ glo_surface_getcontents_readpixels(surface->context->formatFlags,
+ stride, bpp, surface->width,
+ surface->height, data);
+}
+
+// while(0) {
+// char fname[30];
+// int y;
+// sprintf(fname, "dbg_%08x_%dx%d.rgb", surface, surface->width, surface->height);
+// FILE *d = fopen(fname, "wb");
+// for(y = 0 ; y < surface->height ; y++)
+// fwrite(data + (y*stride), surface->width*3, 1, d);
+// fclose(d);
+// }
+
+/* Return the width and height of the given surface */
+void glo_surface_get_size(GloSurface *surface, int *width, int *height) {
+ if (width)
+ *width = surface->width;
+ if (height)
+ *height = surface->height;
+}
+
+/* Abstract glXQueryExtensionString() */
+const char *glo_glXQueryExtensionsString(void) {
+ return glXQueryExtensionsString(glo.dpy, 0);
+}
+
+
+#define TX (17)
+#define TY (16)
+
+static int glo_can_readback(void) {
+ GloContext *context;
+ GloSurface *surface;
+
+ unsigned char *datain = (unsigned char *)qemu_malloc(4*TX*TY);
+ unsigned char *datain_flip = (unsigned char *)qemu_malloc(4*TX*TY); // flipped input data (for GL)
+ unsigned char *dataout = (unsigned char *)qemu_malloc(4*TX*TY);
+ unsigned char *p;
+ int x,y;
+
+ const int bufferAttributes[] = {
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
+ GLX_STENCIL_SIZE, 0,
+ 0,
+ };
+
+ int bufferFlags = glo_flags_get_from_glx(bufferAttributes, 0);
+ int bpp = glo_flags_get_bytes_per_pixel(bufferFlags);
+ int glFormat, glType;
+
+ memset(datain_flip, 0, TX*TY*4);
+ memset(datain, 0, TX*TY*4);
+
+ p = datain;
+ for (y=0;y<TY;y++) {
+ for (x=0;x<TX;x++) {
+ p[0] = x;
+ p[1] = y;
+ //if (y&1) { p[0]=0; p[1]=0; }
+ if (bpp>2) p[2] = 0;
+ if (bpp>3) p[3] = 0xFF;
+ p+=bpp;
+ }
+ memcpy(&datain_flip[((TY-1)-y)*bpp*TX], &datain[y*bpp*TX], bpp*TX);
+ }
+
+ context = glo_context_create(bufferFlags, 0);
+ surface = glo_surface_create(TX, TY, context);
+
+ glo_surface_makecurrent(surface);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0,TX, 0,TY, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRasterPos2f(0,0);
+ glo_flags_get_readpixel_type(bufferFlags, &glFormat, &glType);
+ glDrawPixels(TX,TY,glFormat, glType, datain_flip);
+ glFlush();
+
+ memset(dataout, 0, bpp*TX*TY);
+
+ glo_surface_getcontents(surface, TX*4, bpp*8, dataout);
+
+ glo_surface_destroy(surface);
+ glo_context_destroy(context);
+
+ if (memcmp(datain, dataout, bpp*TX*TY)==0)
+ return 1;
+
+ return 0;
+}
+
+static void glo_test_readback_methods(void) {
+ glo.use_ximage = 1;
+ if(!glo_can_readback())
+ glo.use_ximage = 0;
+
+ fprintf(stderr, "VM GL: Using %s readback\n", glo.use_ximage?"XImage":"glReadPixels");
+}
+
+#endif
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "gloffscreen.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef _WIN32
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glext.h>
+#else
+#include <GL/gl.h>
+#include <sys/time.h>
+#endif
+
+// ---------------------------------------------------
+// Copied from glx.h as we need them in windows too
+/*
+ * Tokens for glXChooseVisual and glXGetConfig:
+ */
+#define GLX_USE_GL 1
+#define GLX_BUFFER_SIZE 2
+#define GLX_LEVEL 3
+#define GLX_RGBA 4
+#define GLX_DOUBLEBUFFER 5
+#define GLX_STEREO 6
+#define GLX_AUX_BUFFERS 7
+#define GLX_RED_SIZE 8
+#define GLX_GREEN_SIZE 9
+#define GLX_BLUE_SIZE 10
+#define GLX_ALPHA_SIZE 11
+#define GLX_DEPTH_SIZE 12
+#define GLX_STENCIL_SIZE 13
+#define GLX_ACCUM_RED_SIZE 14
+#define GLX_ACCUM_GREEN_SIZE 15
+#define GLX_ACCUM_BLUE_SIZE 16
+#define GLX_ACCUM_ALPHA_SIZE 17
+// ---------------------------------------------------
+
+#define TX (32)
+#define TY (32)
+
+int gl_acceleration_capability_check (void) {
+ int test_failure = 0;
+ GloContext *context;
+ GloSurface *surface;
+ unsigned char *datain = (unsigned char *)malloc(4*TX*TY);
+ unsigned char *datain_flip = (unsigned char *)malloc(4*TX*TY); // flipped input data (for GL)
+ unsigned char *dataout = (unsigned char *)malloc(4*TX*TY);
+ unsigned char *p;
+ int x,y;
+ unsigned int bufferAttributes[] = {
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
+ GLX_STENCIL_SIZE, 0,
+ 0,
+ };
+ int bufferFlags = glo_flags_get_from_glx(bufferAttributes, 0);
+ int bpp = glo_flags_get_bytes_per_pixel(bufferFlags);
+ int glFormat, glType;
+
+ if (glo_sanity_test () != 0) {
+ // test failed.
+ return 1;
+ }
+
+ memset(datain_flip, 0, TX*TY*4);
+ memset(datain, 0, TX*TY*4);
+ p = datain;
+ for (y=0;y<TY;y++) {
+ for (x=0;x<TX;x++) {
+ p[0] = x;
+ p[1] = y;
+ //if (y&1) { p[0]=0; p[1]=0; }
+ if (bpp>2) p[2] = 0;
+ if (bpp>3) p[3] = 0xFF;
+ p+=bpp;
+ }
+ memcpy(&datain_flip[((TY-1)-y)*bpp*TX], &datain[y*bpp*TX], bpp*TX);
+ }
+
+ glo_init();
+ // new surface
+ context = glo_context_create(bufferFlags, 0);
+ surface = glo_surface_create(TX, TY, context);
+ glo_surface_makecurrent(surface);
+ printf("GL VENDOR %s\n", glGetString(GL_VENDOR));
+ printf("GL RENDERER %s\n", glGetString(GL_RENDERER));
+ printf("GL VERSION %s\n", glGetString(GL_VERSION));
+
+ if (strstr (glGetString(GL_RENDERER), "Software")) {
+ printf ("Host does not have GL hardware acceleration!\n");
+ test_failure = 1;
+ goto TEST_END;
+ }
+
+ // fill with stuff (in correctly ordered way)
+ glClear(GL_COLOR_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0,TX, 0,TY, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRasterPos2f(0,0);
+ glo_flags_get_readpixel_type(bufferFlags, &glFormat, &glType);
+ printf("glFormat: 0x%08X glType: 0x%08X\n", glFormat, glType);
+ glDrawPixels(TX,TY,glFormat, glType, datain_flip);
+ glFlush();
+
+ memset(dataout, 0, bpp*TX*TY);
+
+ glo_surface_getcontents(surface, TX*bpp, bpp*8, dataout);
+
+ // destroy surface
+ glo_surface_destroy(surface);
+ glo_context_destroy(context);
+ // compare
+ if (memcmp(datain, dataout, bpp*TX*TY)!=0) {
+ test_failure = 1;
+ }
+TEST_END:
+ //glo_kill();
+ //printf ("Testing %s\n", (test_failure ? "FAILED" : "PASSED"));
+ free (datain);
+ free (datain_flip);
+ free (dataout);
+ return test_failure;
+}
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer - WGL (windows) specific
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifdef _WIN32
+#include "gloffscreen.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <windows.h>
+#include <wingdi.h>
+#include <GL/gl.h>
+#include <GL/glext.h>
+#include <GL/wglext.h>
+
+/* In Windows, you must create a window *before* you can create a pbuffer or
+ * get a context. So we create a hidden Window on startup (see glo_init/GloMain).
+ *
+ * Also, you can't share contexts that have different pixel formats, so we can't just
+ * create a new context from the window. We must create a whole new PBuffer just for
+ * a context :(
+ */
+
+struct GloMain {
+ HINSTANCE hInstance;
+ HDC hDC;
+ HWND hWnd; /* Our hidden window */
+ HGLRC hContext;
+};
+struct GloMain glo;
+int glo_inited = 0;
+
+struct _GloContext {
+ int formatFlags;
+
+ /* Pixel format returned by wglChoosePixelFormat */
+ int wglPixelFormat;
+ /* We need a pbuffer to make a context of the right pixelformat :( */
+ HPBUFFERARB hPBuffer;
+ HDC hDC;
+ HGLRC hContext;
+};
+
+struct _GloSurface {
+ GLuint width;
+ GLuint height;
+
+ GloContext *context;
+ HPBUFFERARB hPBuffer;
+ HDC hDC;
+};
+
+#define GLO_WINDOW_CLASS "QEmuGLClass"
+#define DEFAULT_DEPTH_BUFFER (16)
+
+PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
+PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB;
+PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
+PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
+PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+
+/* ------------------------------------------------------------------------ */
+
+extern const char *glo_glXQueryExtensionsString(void);
+
+extern void glo_surface_getcontents_readpixels(int formatFlags, int stride,
+ int bpp, int width, int height, void *data);
+
+/* ------------------------------------------------------------------------ */
+
+int glo_initialised(void) {
+ return glo_inited;
+}
+
+/* Sanity test of the host GL capabilities to see whether the gl offscreen
+ * could be well supported
+ */
+int glo_sanity_test (void) {
+ PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
+ PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB;
+ PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB;
+ PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB;
+ PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB;
+
+ wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+ wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
+ wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
+ wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
+ wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
+ if (!wglChoosePixelFormatARB ||
+ !wglGetPbufferDCARB ||
+ !wglReleasePbufferDCARB ||
+ !wglCreatePbufferARB ||
+ !wglDestroyPbufferARB) {
+ fprintf (stderr, "Unable to load the required WGL extensions\n");
+ return 1;
+ }
+ // check the shader support. It is for mcompositor to run.
+
+ if (!wglGetProcAddress("glShaderSource")) {
+ fprintf (stderr, "Unable to find shader support\n");
+ return 1;
+ }
+ return 0;
+}
+
+/* Initialise gloffscreen */
+void glo_init(void) {
+ WNDCLASSEX wcx;
+ PIXELFORMATDESCRIPTOR pfd;
+
+ if (glo_inited) {
+ printf( "gloffscreen already inited\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ glo.hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
+
+ wcx.cbSize = sizeof(wcx);
+ wcx.style = 0;
+ wcx.lpfnWndProc = DefWindowProc;
+ wcx.cbClsExtra = 0;
+ wcx.cbWndExtra = 0;
+ wcx.hInstance = glo.hInstance;
+ wcx.hIcon = NULL;
+ wcx.hCursor = NULL;
+ wcx.hbrBackground = NULL;
+ wcx.lpszMenuName = NULL;
+ wcx.lpszClassName = GLO_WINDOW_CLASS;
+ wcx.hIconSm = NULL;
+ RegisterClassEx(&wcx);
+ glo.hWnd = CreateWindow(
+ GLO_WINDOW_CLASS,
+ "QEmuGL",
+ 0,0,0,0,0,
+ (HWND)NULL, (HMENU)NULL,
+ glo.hInstance,
+ (LPVOID) NULL);
+
+ if (!glo.hWnd) {
+ printf( "Unable to create window\n" );
+ exit( EXIT_FAILURE );
+ }
+ glo.hDC = GetDC(glo.hWnd);
+
+ memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
+ pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 24;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ unsigned int pixelFormat = ChoosePixelFormat(glo.hDC, &pfd);
+ DescribePixelFormat(glo.hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+ if (!SetPixelFormat(glo.hDC, pixelFormat, &pfd))
+ return;
+
+ glo.hContext = wglCreateContext(glo.hDC);
+ if (glo.hContext == NULL) {
+ printf( "Unable to create GL context\n" );
+ exit( EXIT_FAILURE );
+ }
+ wglMakeCurrent(glo.hDC, glo.hContext);
+
+ // FIXME GW
+ // Need to share lists AND copy state
+
+ // load in the extensions we need
+ //const char *ext = wglGetExtensionsStringARB(hdc);
+ //"WGL_ARB_pixel_format" "WGL_ARB_pbuffer"
+
+ wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
+ wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
+ wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
+ wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
+ wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
+ if (!wglChoosePixelFormatARB ||
+ !wglGetPbufferDCARB ||
+ !wglReleasePbufferDCARB ||
+ !wglCreatePbufferARB ||
+ !wglDestroyPbufferARB) {
+ printf( "Unable to load the required WGL extensions\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ glo_inited = 1;
+}
+
+/* Uninitialise gloffscreen */
+void glo_kill(void) {
+ if (glo.hContext) {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(glo.hContext);
+ glo.hContext = NULL;
+ }
+ if (glo.hDC) {
+ ReleaseDC(glo.hWnd, glo.hDC);
+ glo.hDC = NULL;
+ }
+ if (glo.hWnd) {
+ DestroyWindow(glo.hWnd);
+ glo.hWnd = NULL;
+ }
+ UnregisterClass(GLO_WINDOW_CLASS, glo.hInstance);
+}
+
+const char *glo_glXQueryExtensionsString(void) {
+ return "";
+}
+
+
+static const char *STANDARD_GL_FUNCTIONS ={
+/* Miscellaneous */
+"glClearIndex\0"
+"glClearColor\0"
+"glClear\0"
+"glIndexMask\0"
+"glColorMask\0"
+"glAlphaFunc\0"
+"glBlendFunc\0"
+"glLogicOp\0"
+"glCullFace\0"
+"glFrontFace\0"
+"glPointSize\0"
+"glLineWidth\0"
+"glLineStipple\0"
+"glPolygonMode\0"
+"glPolygonOffset\0"
+"glPolygonStipple\0"
+"glGetPolygonStipple\0"
+"glEdgeFlag\0"
+"glEdgeFlagv\0"
+"glScissor\0"
+"glClipPlane\0"
+"glGetClipPlane\0"
+"glDrawBuffer\0"
+"glReadBuffer\0"
+"glEnable\0"
+"glDisable\0"
+"glIsEnabled\0"
+"glEnableClientState\0"
+"glDisableClientState\0"
+"glGetBooleanv\0"
+"glGetDoublev\0"
+"glGetFloatv\0"
+"glGetIntegerv\0"
+"glPushAttrib\0"
+"glPopAttrib\0"
+"glPushClientAttrib\0"
+"glPopClientAttrib\0"
+"glRenderMode\0"
+"glGetError\0"
+"glGetString\0"
+"glFinish\0"
+"glFlush\0"
+"glHint\0"
+/* Depth Buffer */
+"glClearDepth\0"
+"glDepthFunc\0"
+"glDepthMask\0"
+"glDepthRange\0"
+/* Accumulation Buffer */
+"glClearAccum\0"
+"glAccum\0"
+/* Transformation */
+"glMatrixMode\0"
+"glOrtho\0"
+"glFrustum\0"
+"glViewport\0"
+"glPushMatrix\0"
+"glPopMatrix\0"
+"glLoadIdentity\0"
+"glLoadMatrixd\0"
+"glLoadMatrixf\0"
+"glMultMatrixd\0"
+"glMultMatrixf\0"
+"glRotated\0"
+"glRotatef\0"
+"glScaled\0"
+"glScalef\0"
+"glTranslated\0"
+"glTranslatef\0"
+/* Display Lists */
+"glIsList\0"
+"glDeleteLists\0"
+"glGenLists\0"
+"glNewList\0"
+"glEndList\0"
+"glCallList\0"
+"glCallLists\0"
+"glListBase\0"
+/* Drawing Functions */
+"glBegin\0"
+"glEnd\0"
+"glVertex2d\0"
+"glVertex2f\0"
+"glVertex2i\0"
+"glVertex2s\0"
+"glVertex3d\0"
+"glVertex3f\0"
+"glVertex3i\0"
+"glVertex3s\0"
+"glVertex4d\0"
+"glVertex4f\0"
+"glVertex4i\0"
+"glVertex4s\0"
+"glVertex2dv\0"
+"glVertex2fv\0"
+"glVertex2iv\0"
+"glVertex2sv\0"
+"glVertex3dv\0"
+"glVertex3fv\0"
+"glVertex3iv\0"
+"glVertex3sv\0"
+"glVertex4dv\0"
+"glVertex4fv\0"
+"glVertex4iv\0"
+"glVertex4sv\0"
+"glNormal3b\0"
+"glNormal3d\0"
+"glNormal3f\0"
+"glNormal3i\0"
+"glNormal3s\0"
+"glNormal3bv\0"
+"glNormal3dv\0"
+"glNormal3fv\0"
+"glNormal3iv\0"
+"glNormal3sv\0"
+"glIndexd\0"
+"glIndexf\0"
+"glIndexi\0"
+"glIndexs\0"
+"glIndexub\0"
+"glIndexdv\0"
+"glIndexfv\0"
+"glIndexiv\0"
+"glIndexsv\0"
+"glIndexubv\0"
+"glColor3b\0"
+"glColor3d\0"
+"glColor3f\0"
+"glColor3i\0"
+"glColor3s\0"
+"glColor3ub\0"
+"glColor3ui\0"
+"glColor3us\0"
+"glColor4b\0"
+"glColor4d\0"
+"glColor4f\0"
+"glColor4i\0"
+"glColor4s\0"
+"glColor4ub\0"
+"glColor4ui\0"
+"glColor4us\0"
+"glColor3bv\0"
+"glColor3dv\0"
+"glColor3fv\0"
+"glColor3iv\0"
+"glColor3sv\0"
+"glColor3ubv\0"
+"glColor3uiv\0"
+"glColor3usv\0"
+"glColor4bv\0"
+"glColor4dv\0"
+"glColor4fv\0"
+"glColor4iv\0"
+"glColor4sv\0"
+"glColor4ubv\0"
+"glColor4uiv\0"
+"glColor4usv\0"
+"glTexCoord1d\0"
+"glTexCoord1f\0"
+"glTexCoord1i\0"
+"glTexCoord1s\0"
+"glTexCoord2d\0"
+"glTexCoord2f\0"
+"glTexCoord2i\0"
+"glTexCoord2s\0"
+"glTexCoord3d\0"
+"glTexCoord3f\0"
+"glTexCoord3i\0"
+"glTexCoord3s\0"
+"glTexCoord4d\0"
+"glTexCoord4f\0"
+"glTexCoord4i\0"
+"glTexCoord4s\0"
+"glTexCoord1dv\0"
+"glTexCoord1fv\0"
+"glTexCoord1iv\0"
+"glTexCoord1sv\0"
+"glTexCoord2dv\0"
+"glTexCoord2fv\0"
+"glTexCoord2iv\0"
+"glTexCoord2sv\0"
+"glTexCoord3dv\0"
+"glTexCoord3fv\0"
+"glTexCoord3iv\0"
+"glTexCoord3sv\0"
+"glTexCoord4dv\0"
+"glTexCoord4fv\0"
+"glTexCoord4iv\0"
+"glTexCoord4sv\0"
+"glRasterPos2d\0"
+"glRasterPos2f\0"
+"glRasterPos2i\0"
+"glRasterPos2s\0"
+"glRasterPos3d\0"
+"glRasterPos3f\0"
+"glRasterPos3i\0"
+"glRasterPos3s\0"
+"glRasterPos4d\0"
+"glRasterPos4f\0"
+"glRasterPos4i\0"
+"glRasterPos4s\0"
+"glRasterPos2dv\0"
+"glRasterPos2fv\0"
+"glRasterPos2iv\0"
+"glRasterPos2sv\0"
+"glRasterPos3dv\0"
+"glRasterPos3fv\0"
+"glRasterPos3iv\0"
+"glRasterPos3sv\0"
+"glRasterPos4dv\0"
+"glRasterPos4fv\0"
+"glRasterPos4iv\0"
+"glRasterPos4sv\0"
+"glRectd\0"
+"glRectf\0"
+"glRecti\0"
+"glRects\0"
+"glRectdv\0"
+"glRectfv\0"
+"glRectiv\0"
+"glRectsv\0"
+/* Lighting */
+"glShadeModel\0"
+"glLightf\0"
+"glLighti\0"
+"glLightfv\0"
+"glLightiv\0"
+"glGetLightfv\0"
+"glGetLightiv\0"
+"glLightModelf\0"
+"glLightModeli\0"
+"glLightModelfv\0"
+"glLightModeliv\0"
+"glMaterialf\0"
+"glMateriali\0"
+"glMaterialfv\0"
+"glMaterialiv\0"
+"glGetMaterialfv\0"
+"glGetMaterialiv\0"
+"glColorMaterial\0"
+/* Raster functions */
+"glPixelZoom\0"
+"glPixelStoref\0"
+"glPixelStorei\0"
+"glPixelTransferf\0"
+"glPixelTransferi\0"
+"glPixelMapfv\0"
+"glPixelMapuiv\0"
+"glPixelMapusv\0"
+"glGetPixelMapfv\0"
+"glGetPixelMapuiv\0"
+"glGetPixelMapusv\0"
+"glBitmap\0"
+"glReadPixels\0"
+"glDrawPixels\0"
+"glCopyPixels\0"
+/* Stenciling */
+"glStencilFunc\0"
+"glStencilMask\0"
+"glStencilOp\0"
+"glClearStencil\0"
+/* Texture mapping */
+"glTexGend\0"
+"glTexGenf\0"
+"glTexGeni\0"
+"glTexGendv\0"
+"glTexGenfv\0"
+"glTexGeniv\0"
+"glGetTexGendv\0"
+"glGetTexGenfv\0"
+"glGetTexGeniv\0"
+"glTexEnvf\0"
+"glTexEnvi\0"
+"glTexEnvfv\0"
+"glTexEnviv\0"
+"glGetTexEnvfv\0"
+"glGetTexEnviv\0"
+"glTexParameterf\0"
+"glTexParameteri\0"
+"glTexParameterfv\0"
+"glTexParameteriv\0"
+"glGetTexParameterfv\0"
+"glGetTexParameteriv\0"
+"glGetTexLevelParameterfv\0"
+"glGetTexLevelParameteriv\0"
+"glTexImage1D\0"
+"glTexImage2D\0"
+"glGetTexImage\0"
+/* Evaluators */
+"glMap1d\0"
+"glMap1f\0"
+"glMap2d\0"
+"glMap2f\0"
+"glGetMapdv\0"
+"glGetMapfv\0"
+"glGetMapiv\0"
+"glEvalCoord1d\0"
+"glEvalCoord1f\0"
+"glEvalCoord1dv\0"
+"glEvalCoord1fv\0"
+"glEvalCoord2d\0"
+"glEvalCoord2f\0"
+"glEvalCoord2dv\0"
+"glEvalCoord2fv\0"
+"glMapGrid1d\0"
+"glMapGrid1f\0"
+"glMapGrid2d\0"
+"glMapGrid2f\0"
+"glEvalPoint1\0"
+"glEvalPoint2\0"
+"glEvalMesh1\0"
+"glEvalMesh2\0"
+/* Fog */
+"glFogf\0"
+"glFogi\0"
+"glFogfv\0"
+"glFogiv\0"
+/* Selection and Feedback */
+"glFeedbackBuffer\0"
+"glPassThrough\0"
+"glSelectBuffer\0"
+"glInitNames\0"
+"glLoadName\0"
+"glPushName\0"
+"glPopName\0"
+/* 1.1 functions */
+/* texture objects */
+"glGenTextures\0"
+"glDeleteTextures\0"
+"glBindTexture\0"
+"glPrioritizeTextures\0"
+"glAreTexturesResident\0"
+"glIsTexture\0"
+/* texture mapping */
+"glTexSubImage1D\0"
+"glTexSubImage2D\0"
+"glCopyTexImage1D\0"
+"glCopyTexImage2D\0"
+"glCopyTexSubImage1D\0"
+"glCopyTexSubImage2D\0"
+/* vertex arrays */
+"glVertexPointer\0"
+"glNormalPointer\0"
+"glColorPointer\0"
+"glIndexPointer\0"
+"glTexCoordPointer\0"
+"glEdgeFlagPointer\0"
+"glGetPointerv\0"
+"glArrayElement\0"
+"glDrawArrays\0"
+"glDrawElements\0"
+"glInterleavedArrays\0"
+/* GLX */
+"glXChooseVisual\0"
+"glXQueryExtensionsString\0"
+"glXQueryServerString\0"
+"glXGetClientString\0"
+"glXCreateContext\0"
+"glXCreateNewContext\0"
+"glXCopyContext\0"
+"glXDestroyContext\0"
+"glXQueryVersion\0"
+"glXMakeCurrent\0"
+"glXSwapBuffers\0"
+"glXGetConfig\0"
+"glXQueryExtension\0"
+"glXChooseFBConfig\0"
+"glXGetFBConfigs\0"
+"glXGetFBConfigAttrib\0"
+"glXQueryContext\0"
+"glXQueryDrawable\0"
+"glXGetVisualFromFBConfig\0"
+"glXIsDirect\0"
+"\0"
+};
+
+/* Like wglGetProcAddress/glxGetProcAddress */
+void *glo_getprocaddress(const char *procName) {
+ HGLRC oldCtx;
+ HDC oldDC;
+ if (!glo_inited)
+ glo_init();
+
+ oldCtx = wglGetCurrentContext();
+ oldDC = wglGetCurrentDC();
+ if (oldDC!=glo.hDC || oldCtx!=glo.hContext)
+ wglMakeCurrent(glo.hDC, glo.hContext);
+
+ void *procAddr = wglGetProcAddress(procName);
+
+ if (oldDC!=glo.hDC || oldCtx!=glo.hContext)
+ wglMakeCurrent(oldDC, oldCtx);
+
+ /* wgl doesn't know about the glx functions - but
+ we never call these anyway (they're implemented in
+ opengl_exec), so all we need to do is return a nunzero value...
+
+ But we also have to check for 'standard' GL function names
+ too as wgl doesn't return those either! */
+ if (procAddr==0) {
+ const char *p = STANDARD_GL_FUNCTIONS;
+ while (*p) {
+ if (!strcmp(procName, p)) {
+ procAddr = (void*)1;
+ break;
+ }
+ // skip to the next '0' and then just over it
+ while (*p) p++;
+ p++;
+ }
+ }
+
+ /*printf("wglGetProcAddress '%s' -> %p\n", procName, procAddr);
+ fflush(stdout);*/
+
+ return procAddr;
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create an OpenGL context for a certain pixel format. formatflags are from the GLO_ constants */
+GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
+ GloContext *context;
+ // pixel format attributes
+ int pf_attri[] = {
+ WGL_SUPPORT_OPENGL_ARB, TRUE,
+ WGL_DRAW_TO_PBUFFER_ARB, TRUE,
+ WGL_RED_BITS_ARB, 8,
+ WGL_GREEN_BITS_ARB, 8,
+ WGL_BLUE_BITS_ARB, 8,
+ WGL_ALPHA_BITS_ARB, 8,
+ WGL_DEPTH_BITS_ARB, 0,
+ WGL_STENCIL_BITS_ARB, 0,
+ WGL_DOUBLE_BUFFER_ARB, FALSE,
+ 0
+ };
+ float pf_attrf[] = {0, 0};
+ unsigned int numReturned = 0;
+ int pb_attr[] = { 0 };
+ int rgbaBits[4];
+
+
+ if (!glo_inited)
+ glo_init();
+
+ context = (GloContext*)malloc(sizeof(GloContext));
+ memset(context, 0, sizeof(GloContext));
+ context->formatFlags = formatFlags;
+
+ // set up the surface format from the flags we were given
+ glo_flags_get_rgba_bits(context->formatFlags, rgbaBits);
+ pf_attri[5] = rgbaBits[0];
+ pf_attri[7] = rgbaBits[1];
+ pf_attri[9] = rgbaBits[2];
+ pf_attri[11] = rgbaBits[3];
+ pf_attri[13] = glo_flags_get_depth_bits(context->formatFlags);
+ pf_attri[15] = glo_flags_get_stencil_bits(context->formatFlags);
+
+ // find out what pixel format to use
+ wglChoosePixelFormatARB( glo.hDC, pf_attri, pf_attrf, 1, &context->wglPixelFormat, &numReturned);
+ if( numReturned == 0 ) {
+ printf( "No matching configs found.\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ // We create a tiny pbuffer - just so we can make a context of the right pixel format
+ context->hPBuffer = wglCreatePbufferARB( glo.hDC, context->wglPixelFormat,
+ 16, 16, pb_attr );
+ if( !context->hPBuffer ) {
+ printf( "Couldn't create the PBuffer\n" );
+ exit( EXIT_FAILURE );
+ }
+ context->hDC = wglGetPbufferDCARB( context->hPBuffer );
+ if( !context->hDC ) {
+ printf( "Couldn't create the DC\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ context->hContext = wglCreateContext(context->hDC);
+ if (context->hContext == NULL) {
+ printf( "Unable to create GL context\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ if (shareLists) {
+ // Need to share lists...
+ wglShareLists(shareLists->hContext, context->hContext);
+ }
+
+ return context;
+}
+
+/* Destroy a previouslu created OpenGL context */
+void glo_context_destroy(GloContext *context) {
+ if (!context) return;
+
+ wglMakeCurrent( NULL, NULL );
+ if( context->hPBuffer != NULL ) {
+ wglReleasePbufferDCARB( context->hPBuffer, context->hDC );
+ wglDestroyPbufferARB( context->hPBuffer );
+ }
+ if( context->hDC != NULL ) {
+ ReleaseDC( glo.hWnd, context->hDC );
+ }
+ if (context->hContext) {
+ wglDeleteContext(context->hContext);
+ }
+ free(context);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create a surface with given width and height, formatflags are from the
+ * GLO_ constants */
+GloSurface *glo_surface_create(int width, int height, GloContext *context) {
+ GloSurface *surface;
+ int pb_attr[] = { 0 };
+
+ // Create the p-buffer...
+ surface = (GloSurface*)malloc(sizeof(GloSurface));
+ memset(surface, 0, sizeof(GloSurface));
+ surface->width = width;
+ surface->height = height;
+ surface->context = context;
+
+ surface->hPBuffer = wglCreatePbufferARB( glo.hDC, context->wglPixelFormat,
+ surface->width, surface->height, pb_attr );
+ if( !surface->hPBuffer ) {
+ printf( "Couldn't create the PBuffer\n" );
+ exit( EXIT_FAILURE );
+ }
+ surface->hDC = wglGetPbufferDCARB( surface->hPBuffer );
+ if( !surface->hDC ) {
+ printf( "Couldn't create the DC\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ return surface;
+}
+
+/* Destroy the given surface */
+void glo_surface_destroy(GloSurface *surface) {
+ if (!surface) return;
+
+ wglMakeCurrent( NULL, NULL );
+ if( surface->hPBuffer != NULL ) {
+ wglReleasePbufferDCARB( surface->hPBuffer, surface->hDC );
+ wglDestroyPbufferARB( surface->hPBuffer );
+ }
+ if( surface->hDC != NULL ) {
+ ReleaseDC( glo.hWnd, surface->hDC );
+ }
+ free(surface);
+}
+
+/* Make the given surface current */
+int glo_surface_makecurrent(GloSurface *surface) {
+ if (surface) {
+ return wglMakeCurrent( surface->hDC, surface->context->hContext );
+ } else {
+ return wglMakeCurrent( NULL, NULL );
+ }
+}
+
+/* Get the contents of the given surface */
+void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *data) {
+
+ if (!surface)
+ return;
+ // Compatible / fallback method.
+ glo_surface_getcontents_readpixels(surface->context->formatFlags,
+ stride, bpp, surface->width,
+ surface->height, data);
+}
+
+/* Return the width and height of the given surface */
+void glo_surface_get_size(GloSurface *surface, int *width, int *height) {
+ if (width)
+ *width = surface->width;
+ if (height)
+ *height = surface->height;
+}
+
+#endif
--- /dev/null
+/*
+ * Offscreen OpenGL abstraction layer - GLX specific
+ *
+ * Copyright (c) 2010 Intel
+ * Written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef _WIN32
+#include "gloffscreen.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+#include <X11/extensions/Xcomposite.h>
+
+void *g_malloc(size_t size);
+void *g_realloc(void *ptr, size_t size);
+void g_free(void *ptr);
+
+struct GloMain {
+ Display *dpy;
+ int use_ximage;
+};
+struct GloMain glo;
+int glo_inited = 0;
+
+struct _GloContext {
+ GLuint formatFlags;
+
+ GLXFBConfig fbConfig;
+ GLXContext context;
+};
+
+struct _GloSurface {
+ GLuint width;
+ GLuint height;
+
+ GloContext *context;
+ Window window;
+
+ // For use by the 'fast' copy code.
+ Pixmap pixmap;
+ XImage *image;
+ XShmSegmentInfo shminfo;
+};
+
+extern void glo_surface_getcontents_readpixels(int formatFlags, int stride,
+ int bpp, int width, int height, void *data);
+static void glo_test_readback_methods(void);
+
+/* ------------------------------------------------------------------------ */
+
+int glo_initialised(void) {
+ return glo_inited;
+}
+
+/*
+ * The X error was disabled, otherwise QEMU will abort. Printing more error
+ * messages inside below function could help debug potential bugs. On the
+ * other hand, since the X errors could be caused by the GL calls forwarded
+ * from client OS side, which does not make sense to abort the whole QEMU,
+ * so it is reasonable to redirect error handler here.
+ *
+ */
+static int x_errhandler(Display *dpy, XErrorEvent *e)
+{
+ //fprintf (stderr, "X Error Happened!\n");
+ return 0;
+}
+
+/* Sanity test of the host GL capabilities to see whether the gl offscreen
+ * could be well supported
+ */
+int glo_sanity_test (void) {
+ return 0;
+}
+
+/* Initialise gloffscreen */
+void glo_init(void) {
+ if (glo_inited) {
+ printf( "gloffscreen already inited\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ /* Open a connection to the X server */
+ glo.dpy = XOpenDisplay( NULL );
+ if ( glo.dpy == NULL ) {
+ printf( "Unable to open a connection to the X server\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ glo_inited = 1; // safe because we are single threaded. Otherwise we cause
+ // recursion on the next call.
+ // set the X error handler.
+ XErrorHandler old_handler = XSetErrorHandler (x_errhandler);
+ glo_test_readback_methods();
+}
+
+/* Uninitialise gloffscreen */
+void glo_kill(void) {
+ XCloseDisplay(glo.dpy);
+ glo.dpy = NULL;
+}
+
+
+/* Like wglGetProcAddress/glxGetProcAddress */
+void *glo_getprocaddress(const char *procName) {
+ if (!glo_inited)
+ glo_init();
+
+ return glXGetProcAddressARB((const GLubyte *) procName);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create an OpenGL context for a certain pixel format.
+ formatflags are from the GLO_ constants */
+
+GloContext *glo_context_create(int formatFlags, GloContext *shareLists) {
+ if (!glo_inited)
+ glo_init();
+
+ GLXFBConfig *fbConfigs;
+ int numReturned;
+ GloContext *context;
+ int rgbaBits[4];
+ int bufferAttributes[] = {
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
+ GLX_STENCIL_SIZE, 0,
+ None
+ };
+
+ if (!glo_inited)
+ glo_init();
+
+ // set up the surface format from the flags we were given
+ glo_flags_get_rgba_bits(formatFlags, rgbaBits);
+ bufferAttributes[5] = rgbaBits[0];
+ bufferAttributes[7] = rgbaBits[1];
+ bufferAttributes[9] = rgbaBits[2];
+ bufferAttributes[11] = rgbaBits[3];
+ bufferAttributes[13] = glo_flags_get_depth_bits(formatFlags);
+ bufferAttributes[15] = glo_flags_get_stencil_bits(formatFlags);
+
+ fbConfigs = glXChooseFBConfig( glo.dpy, DefaultScreen(glo.dpy),
+ bufferAttributes, &numReturned );
+ if (numReturned==0) {
+ printf( "No matching configs found.\n" );
+ exit( EXIT_FAILURE );
+ }
+ context = (GloContext*)g_malloc(sizeof(GloContext));
+ memset(context, 0, sizeof(GloContext));
+ context->formatFlags = formatFlags;
+ context->fbConfig = fbConfigs[0];
+
+ /* Create a GLX context for OpenGL rendering */
+ context->context = glXCreateNewContext(glo.dpy, context->fbConfig,
+ GLX_RGBA_TYPE,
+ shareLists ? shareLists->context: NULL,
+ True );
+
+ if (!context->context) {
+ printf( "glXCreateNewContext failed\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ return context;
+}
+
+/* Destroy a previously created OpenGL context */
+void glo_context_destroy(GloContext *context) {
+ if (!context) return;
+
+ // TODO: check for GloSurfaces using this?
+ glXDestroyContext( glo.dpy, context->context);
+ g_free(context);
+}
+
+static void glo_surface_free_xshm_image(GloSurface *surface) {
+ XShmDetach(glo.dpy, &surface->shminfo);
+ surface->image->data = NULL;
+ XDestroyImage(surface->image);
+ shmdt(surface->shminfo.shmaddr);
+ shmctl(surface->shminfo.shmid, IPC_RMID, NULL);
+}
+
+//FIXMEIM - handle failure to allocate.
+static void glo_surface_try_alloc_xshm_image(GloSurface *surface) {
+
+ if(surface->image)
+ glo_surface_free_xshm_image(surface);
+
+ surface->image =
+ XShmCreateImage(glo.dpy, DefaultVisual(glo.dpy, 0), 24, ZPixmap, NULL,
+ &surface->shminfo, surface->width, surface->height);
+
+ surface->shminfo.shmid = shmget(IPC_PRIVATE,
+ surface->image->bytes_per_line *
+ surface->height,
+ IPC_CREAT | 0777);
+ surface->shminfo.shmaddr = shmat(surface->shminfo.shmid, NULL, 0);
+ surface->image->data = surface->shminfo.shmaddr;
+ surface->shminfo.readOnly = False;
+ XShmAttach(glo.dpy, &surface->shminfo);
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Create a surface with given width and height, formatflags are from the
+ * GLO_ constants */
+GloSurface *glo_surface_create(int width, int height, GloContext *context) {
+ GloSurface *surface;
+ XSetWindowAttributes attr = { 0 };
+ unsigned long mask;
+ XVisualInfo *vis;
+
+ if (!context)
+ return 0;
+
+ surface = (GloSurface*)g_malloc(sizeof(GloSurface));
+ memset(surface, 0, sizeof(GloSurface));
+ surface->width = width;
+ surface->height = height;
+ surface->context = context;
+
+ vis = glXGetVisualFromFBConfig(glo.dpy, ((struct _GloContext*)context)->fbConfig);
+
+ attr.background_pixel = 0xff000000;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(glo.dpy, DefaultRootWindow(glo.dpy),
+ vis->visual, AllocNone);
+ attr.event_mask = 0;
+ attr.save_under = True;
+ attr.override_redirect = True;
+ attr.cursor = None;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask |
+ CWOverrideRedirect | CWSaveUnder;
+
+ surface->window = XCreateWindow(glo.dpy, DefaultRootWindow(glo.dpy), -width-1000, 0, width, height, 0, vis->depth, InputOutput, vis->visual, mask, &attr);
+
+ if (!surface->window) {
+ printf( "XCreateWindow failed\n" );
+ exit( EXIT_FAILURE );
+ }
+
+ XMapWindow(glo.dpy, surface->window);
+ XCompositeRedirectWindow (glo.dpy, surface->window, CompositeRedirectAutomatic);
+
+ if(glo.use_ximage) {
+ surface->pixmap = XCompositeNameWindowPixmap(glo.dpy, surface->window);
+ } else {
+ surface->pixmap = XCreatePixmap( glo.dpy, DefaultRootWindow(glo.dpy),
+ width, height,
+ glo_flags_get_bytes_per_pixel(context->formatFlags)*8);
+ }
+
+ if(surface->pixmap == 0) {
+ fprintf(stderr, "Failed to allocate pixmap!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ XSync(glo.dpy, 0);
+
+ /* set hints and properties */
+ {
+ XSizeHints sizehints;
+
+ sizehints.x = 0;
+ sizehints.y = 0;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize | USPosition;
+ XSetWMNormalHints(glo.dpy, surface->window, &sizehints);
+ XSetStandardProperties(glo.dpy, surface->window, "", "", None,
+ (char **) NULL, 0, &sizehints);
+ }
+
+ XSync(glo.dpy, 0);
+
+ // If we're using XImages to pull the data from the graphics card...
+ glo_surface_try_alloc_xshm_image(surface);
+
+ return surface;
+}
+
+/* Destroy the given surface */
+void glo_surface_destroy(GloSurface *surface) {
+
+ if(surface->pixmap)
+ XFreePixmap( glo.dpy, surface->pixmap);
+ XDestroyWindow( glo.dpy, surface->window);
+ if(surface->image)
+ glo_surface_free_xshm_image(surface);
+ g_free(surface);
+
+}
+
+/* Make the given surface current */
+int glo_surface_makecurrent(GloSurface *surface) {
+ int ret;
+
+ if (!glo_inited)
+ glo_init();
+
+ if (surface)
+ ret = glXMakeCurrent(glo.dpy, surface->window,
+ surface->context->context);
+ else
+ ret = glXMakeCurrent(glo.dpy, 0, NULL);
+
+ return ret;
+}
+
+/* Get the contents of the given surface */
+void glo_surface_getcontents(GloSurface *surface, int stride, int bpp, void *data) {
+ static int once;
+ XImage *img;
+
+ if (!surface)
+ return;
+
+ if(glo.use_ximage) {
+ glXWaitGL();
+
+ if(surface->image) {
+ XShmGetImage (glo.dpy, surface->pixmap, surface->image, 0, 0, AllPlanes);
+ img = surface->image;
+ }
+ else {
+ img = XGetImage(glo.dpy, surface->pixmap, 0, 0, surface->width, surface->height, AllPlanes, ZPixmap);
+ }
+
+ if (img) {
+ if(bpp != 32 && bpp != 24 && !once) {
+ fprintf(stderr, "Warning: unsupported colourdepth\n");
+ once = 1;
+ }
+
+ if(bpp == img->bits_per_pixel && stride == img->bytes_per_line)
+ {
+ memcpy(data, img->data, stride * surface->height);
+ }
+ else
+ {
+ int x, y;
+ for(y = 0 ; y < surface->height ; y++) {
+ for(x = 0 ; x < surface->width ; x++) {
+ char *src = ((char*)img->data) +
+ (x*(img->bits_per_pixel/8)) +
+ (y*img->bytes_per_line);
+ char *dst = ((char*)data) + x*(bpp/8) + (y*stride);
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ if(bpp == 32)
+ dst[3] = 0xff; // if guest is 32 bit and host is 24
+ }
+ }
+ }
+
+ // If we're not using Shm
+ if(!surface->image)
+ XDestroyImage(img);
+
+ return; // We're done.
+ }
+ // Uh oh... better fallback. Perhaps get glo.use_ximage to 0?
+ }
+
+ // Compatible / fallback method.
+ glo_surface_getcontents_readpixels(surface->context->formatFlags,
+ stride, bpp, surface->width,
+ surface->height, data);
+}
+
+/* Return the width and height of the given surface */
+void glo_surface_get_size(GloSurface *surface, int *width, int *height) {
+ if (width)
+ *width = surface->width;
+ if (height)
+ *height = surface->height;
+}
+
+/* Abstract glXQueryExtensionString() */
+const char *glo_glXQueryExtensionsString(void) {
+ return glXQueryExtensionsString(glo.dpy, 0);
+}
+
+
+#define TX (17)
+#define TY (16)
+
+static int glo_can_readback(void) {
+ GloContext *context;
+ GloSurface *surface;
+
+ unsigned char *datain = (unsigned char *)g_malloc(4*TX*TY);
+ unsigned char *datain_flip = (unsigned char *)g_malloc(4*TX*TY); // flipped input data (for GL)
+ unsigned char *dataout = (unsigned char *)g_malloc(4*TX*TY);
+ unsigned char *p;
+ int x,y;
+
+ const int bufferAttributes[] = {
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 0,
+ GLX_STENCIL_SIZE, 0,
+ 0,
+ };
+
+ int bufferFlags = glo_flags_get_from_glx(bufferAttributes, 0);
+ int bpp = glo_flags_get_bytes_per_pixel(bufferFlags);
+ int glFormat, glType;
+
+ memset(datain_flip, 0, TX*TY*4);
+ memset(datain, 0, TX*TY*4);
+
+ p = datain;
+ for (y=0;y<TY;y++) {
+ for (x=0;x<TX;x++) {
+ p[0] = x;
+ p[1] = y;
+ if (bpp>2) p[2] = 0;
+ if (bpp>3) p[3] = 0xFF;
+ p+=bpp;
+ }
+ memcpy(&datain_flip[((TY-1)-y)*bpp*TX], &datain[y*bpp*TX], bpp*TX);
+ }
+
+ context = glo_context_create(bufferFlags, 0);
+ surface = glo_surface_create(TX, TY, context);
+
+ glo_surface_makecurrent(surface);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0,TX, 0,TY, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glRasterPos2f(0,0);
+ glo_flags_get_readpixel_type(bufferFlags, &glFormat, &glType);
+ glDrawPixels(TX,TY,glFormat, glType, datain_flip);
+ glFlush();
+
+ memset(dataout, 0, bpp*TX*TY);
+
+ glo_surface_getcontents(surface, TX*4, bpp*8, dataout);
+
+ glo_surface_destroy(surface);
+ glo_context_destroy(context);
+
+ if (memcmp(datain, dataout, bpp*TX*TY)==0)
+ return 1;
+
+ return 0;
+}
+
+static void glo_test_readback_methods(void) {
+ glo.use_ximage = 1;
+ if(!glo_can_readback())
+ glo.use_ximage = 0;
+
+ //fprintf(stderr, "VM GL: Using %s readback\n", glo.use_ximage?"XImage":"glReadPixels");
+}
+
+#endif
--- /dev/null
+/*
+ * Host-side implementation of GL/GLX API
+ *
+ * Copyright (c) 2006,2007 Even Rouault
+ * Modified by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#define _XOPEN_SOURCE 600
+
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "osdep.h"
+#include "opengl_func.h"
+#include "opengl_process.h"
+#include "opengl_exec.h"
+
+#include "tizen/src/debug_ch.h"
+MULTI_DEBUG_CHANNEL(qemu, opengl);
+#define DEBUGF TRACE
+
+#if 0
+#ifdef _WIN32
+#define DEBUGF(...) printf(__VA_ARGS__)
+#else
+extern struct FILE *stderr; /* Standard error output stream. */
+#define DEBUGF(...) fprintf(stderr, __VA_ARGS__)
+#endif
+#endif
+
+/* do_decode_call_int()
+ *
+ * Loop through the buffered command stream executing each OpenGL call in
+ * sequence. due to the way calls are buffered, only the last call in the
+ * buffer may have 'out' parameters or a non-void return code. This allows
+ * for efficient buffering whilst avoiding un-necessary buffer flushes.
+ */
+
+typedef unsigned long host_ptr;
+
+static inline int do_decode_call_int(ProcessStruct *process, void *args_in, int args_len, char *r_buffer)
+{
+ Signature *signature;
+ int i, ret;
+ char *argptr, *tmp;
+ static void* args[50];
+ int func_number;
+
+ if(!args_len)
+ return 0;
+
+ argptr = args_in;
+
+ while((char*)argptr < (char*)args_in + args_len) {
+ func_number = *(short*)argptr;
+ argptr += 2;
+
+ if(func_number >= GL_N_CALLS) {
+ DEBUGF("Bad function number or corrupt command queue\n");
+ return 0;
+ }
+
+ signature = (Signature *) tab_opengl_calls[func_number];
+
+ tmp = argptr;
+
+ for (i = 0; i < signature->nb_args; i++) {
+ int args_size = *(int*)argptr;
+ argptr+=4;
+ switch (signature->args_type[i]) {
+ case TYPE_UNSIGNED_INT:
+ case TYPE_INT:
+ case TYPE_UNSIGNED_CHAR:
+ case TYPE_CHAR:
+ case TYPE_UNSIGNED_SHORT:
+ case TYPE_SHORT:
+ case TYPE_FLOAT:
+ args[i] = *(int*)argptr;
+ break;
+
+ case TYPE_NULL_TERMINATED_STRING:
+ CASE_IN_UNKNOWN_SIZE_POINTERS:
+ {
+ if(*(int*)argptr)
+ args[i] = (host_ptr)argptr+4;
+ else
+ args[i] = (host_ptr)NULL;
+
+ if ((args[i] == 0 && args_size == 0 &&
+ !IS_NULL_POINTER_OK_FOR_FUNC(func_number)) ||
+ (args[i] == 0 && args_size != 0) ||
+ (args[i] != 0 && args_size == 0))
+ return 0;
+
+ argptr += 4;
+ break;
+ }
+
+ CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS:
+ {
+ if(*(int*)argptr)
+ args[i] = (host_ptr)argptr+4;
+ else
+ args[i] = (host_ptr)NULL;
+
+ if (args[i] == 0 && args_size != 0)
+ return 0;
+
+ argptr += 4;
+ break;
+ }
+
+ CASE_OUT_POINTERS:
+ {
+ /* It seems that we never experience NULL out pointers!!! */
+ if (args_size == 0 && func_number != 4) // FIXMEIM - hack for now
+ return 0;
+
+ if(*(int*)argptr) {
+ *(int*)r_buffer = args_size;
+ r_buffer+=4;
+ args[i] = (host_ptr)r_buffer;
+ r_buffer += args_size;
+ }
+ else {
+ args[i] = 0;
+ }
+
+ argptr += 4;
+ args_size = 0;
+ break;
+ }
+
+ case TYPE_DOUBLE:
+ CASE_IN_KNOWN_SIZE_POINTERS:
+ {
+ if(*(int*)argptr)
+ args[i] = (host_ptr)argptr+4;
+ else
+ args[i] = (host_ptr)NULL;
+
+ if (args[i] == 0 && args_size != 0)
+ return 0;
+
+ argptr += 4;
+ break;
+ }
+
+ case TYPE_IN_IGNORED_POINTER:
+ args[i] = 0;
+ break;
+
+ default:
+ DEBUGF( "Oops : call %s arg %d pid=%d\n",
+ tab_opengl_calls_name[func_number], i,
+ process->process_id);
+ return 0;
+ }
+ argptr += args_size;
+ }
+
+ if((char*)argptr > (char*)args_in + args_len) {
+ DEBUGF("Client bug: malformed command, killing process\n");
+ return 0;
+ }
+
+ if (signature->ret_type == TYPE_CONST_CHAR)
+ r_buffer[0] = 0; // In case high bits are set.
+
+ ret = do_function_call(process, func_number, args, r_buffer);
+
+ } // endwhile
+
+ switch(signature->ret_type) {
+ case TYPE_INT:
+ case TYPE_UNSIGNED_INT:
+ memcpy(r_buffer, &ret, sizeof(int));
+ break;
+ case TYPE_CHAR:
+ case TYPE_UNSIGNED_CHAR:
+ *r_buffer = ret & 0xff;
+ break;
+ case TYPE_CONST_CHAR:
+ case TYPE_NONE:
+ break;
+ default:
+ DEBUGF("Unsupported GL API return type %i!\n", signature->ret_type);
+ exit (-1);
+ }
+
+ return 1;
+}
+#define GL_PASSINGTHROUGH_ABI 1
+
+#define GLINIT_FAIL_ABI 3
+#define GLINIT_QUEUE 2
+#define GLINIT_NOQUEUE 1
+
+int decode_call_int(ProcessStruct *process, char *in_args, int args_len, char *r_buffer)
+{
+ static ProcessStruct *cur_process = NULL;
+ int ret;
+ int first_func = *(short*)in_args;
+
+ /* Select the appropriate context for this pid if it isnt already active
+ * Note: if we're about to execute glXMakeCurrent() then we tell the
+ * renderer not to waste its time switching contexts
+ */
+
+ if (cur_process != process) {
+ cur_process = process;
+ vmgl_context_switch(cur_process, (first_func == glXMakeCurrent_func)?0:1);
+ }
+
+ if(unlikely(first_func == _init32_func || first_func == _init64_func)) {
+ if(!cur_process->wordsize) {
+ int *version = (int*)(in_args+2);
+ cur_process->wordsize = first_func == _init32_func?4:8;
+
+ if((version[0] != 1) || (version[1] < GL_PASSINGTHROUGH_ABI)) {
+ *(int*)r_buffer = GLINIT_FAIL_ABI; // ABI check FAIL
+ TRACE("Error! The GL passing through package in the image does not match the version of QEMUGL. Please update the image!\n");
+ exit (1);
+ } else if(version[1] > GL_PASSINGTHROUGH_ABI) {
+ *(int*)r_buffer = GLINIT_FAIL_ABI; // ABI check FAIL
+ TRACE("Error! The GL passing through package in the image does not match the version of QEMUGL. Please update the QEMUGL!\n");
+ exit (1);
+ }
+ else
+ *(int*)r_buffer = GLINIT_QUEUE; // Indicate that we can buffer commands
+
+ return 1; // Initialisation done
+ }
+ else {
+ DEBUGF("Attempt to init twice. Continuing regardless.\n");
+ return 1;
+ }
+ }
+
+ if(unlikely(first_func == -1 || !cur_process->wordsize)) {
+ if(!cur_process->wordsize && first_func != -1)
+ DEBUGF("commands submitted before process init.\n");
+ ret = 0;
+ }
+ else {
+ ret = do_decode_call_int(cur_process, in_args, args_len, r_buffer);
+ }
+
+ if(!ret)
+ cur_process = NULL;
+
+ return ret;
+}
#define __WIN32__
#endif
-/* GLAPI, part 1 (use WINGDIAPI, if defined) */
-#if defined(__WIN32__) && defined(WINGDIAPI)
-# define GLAPI WINGDIAPI
-#endif
-
-
-#if !defined(GLAPI)
#if !defined(OPENSTEP) && (defined(__WIN32__) && !defined(__CYGWIN__))
# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */
# define GLAPI __declspec(dllexport)
# define GLAPI __attribute__((visibility("default")))
# define GLAPIENTRY
#endif /* WIN32 && !CYGWIN */
-#else
-#if !defined(GLAPIENTRY)
-# if defined(__WIN32__)
-# define GLAPIENTRY __stdcall
-# else
-# define GLAPIENTRY
-# endif
-#endif
-#endif
#if (defined(__BEOS__) && defined(__POWERPC__)) || defined(__QUICKDRAW__)
# define PRAGMA_EXPORT_SUPPORTED 1
GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum);
GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, GLuint, GLint);
GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, GLuint, GLint);
+GLAPI void APIENTRY glFramebufferTexture2D (GLenum, GLenum, GLenum, GLuint, GLint);
GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLint);
GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, GLuint);
GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, GLenum, GLenum, GLint *);
#undef GLAPI
#endif
-/* __WIN32__ */
-#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__))
-# define __WIN32__
-#endif
-
-/* GLAPI, part 1 (use WINGDIAPI, if defined) */
-#if defined(__WIN32__) && defined(WINGDIAPI)
-# define GLAPI WINGDIAPI
-#endif
-
-#if !defined(GLAPI)
# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GLU32)
# define GLAPI __declspec(dllexport)
# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
# define GLAPI extern
# endif /* _STATIC_MESA support */
-#endif
#ifndef GLAPI
#define GLAPI
#define GLU_TESS_MAX_COORD 1.0e150
/* Internal convenience typedefs */
-typedef void (GLAPIENTRYP _GLUfuncptr)(void);
+typedef void (GLAPIENTRYP _GLUfuncptr)();
GLAPI void GLAPIENTRY gluBeginCurve (GLUnurbs* nurb);
GLAPI void GLAPIENTRY gluBeginPolygon (GLUtesselator* tess);
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "mesa_glu.h"
#ifdef PC_HEADER
#include "all.h"
/* To work around optimizer bug in MSVC4.1 */
#if defined(__WIN32__) && !defined(OPENSTEP)
-void dummy(GLuint j, GLuint k);
-void dummy(GLuint j, GLuint k)
+void
+dummy(GLuint j, GLuint k)
{
}
#else
-#if 0
/*
* Return the largest k such that 2^k <= n.
*/
for (k = 0; n >>= 1; k++);
return k;
}
-#endif
-#if 0
/*
* WARNING: This function isn't finished and has never been tested!!!!
*/
return 0;
}
-#endif
-static GLint GLAPIENTRY
+GLint GLAPIENTRY
mesa_gluBuild2DMipmaps(GLenum target, GLint components,
GLsizei width, GLsizei height, GLenum format,
GLenum type, const void *data)
--- /dev/null
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-2000 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+extern GLint GLAPIENTRY
+mesa_gluBuild2DMipmaps(GLenum target, GLint components,
+ GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const void *data);
--- /dev/null
+/*
+ * i386 helpers
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <math.h>
+#include "cpu.h"
+#include "dyngen-exec.h"
+#include "host-utils.h"
+#include "ioport.h"
+#include "qemu-common.h"
+#include "qemu-log.h"
+#include "cpu-defs.h"
+#include "helper.h"
+
+#if !defined(CONFIG_USER_ONLY)
+#include "softmmu_exec.h"
+#endif /* !defined(CONFIG_USER_ONLY) */
+
+//#define DEBUG_PCALL
+
+#ifdef DEBUG_PCALL
+# define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__)
+# define LOG_PCALL_STATE(env) \
+ log_cpu_state_mask(CPU_LOG_PCALL, (env), X86_DUMP_CCOP)
+#else
+# define LOG_PCALL(...) do { } while (0)
+# define LOG_PCALL_STATE(env) do { } while (0)
+#endif
+
+/* n must be a constant to be efficient */
+static inline target_long lshift(target_long x, int n)
+{
+ if (n >= 0) {
+ return x << n;
+ } else {
+ return x >> (-n);
+ }
+}
+
+#define RC_MASK 0xc00
+#define RC_NEAR 0x000
+#define RC_DOWN 0x400
+#define RC_UP 0x800
+#define RC_CHOP 0xc00
+
+#define MAXTAN 9223372036854775808.0
+
+/* the following deal with x86 long double-precision numbers */
+#define MAXEXPD 0x7fff
+#define EXPBIAS 16383
+#define EXPD(fp) (fp.l.upper & 0x7fff)
+#define SIGND(fp) ((fp.l.upper) & 0x8000)
+#define MANTD(fp) (fp.l.lower)
+#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
+
+static inline void fpush(void)
+{
+ env->fpstt = (env->fpstt - 1) & 7;
+ env->fptags[env->fpstt] = 0; /* validate stack entry */
+}
+
+static inline void fpop(void)
+{
+ env->fptags[env->fpstt] = 1; /* invvalidate stack entry */
+ env->fpstt = (env->fpstt + 1) & 7;
+}
+
+static inline floatx80 helper_fldt(target_ulong ptr)
+{
+ CPU_LDoubleU temp;
+
+ temp.l.lower = ldq(ptr);
+ temp.l.upper = lduw(ptr + 8);
+ return temp.d;
+}
+
+static inline void helper_fstt(floatx80 f, target_ulong ptr)
+{
+ CPU_LDoubleU temp;
+
+ temp.d = f;
+ stq(ptr, temp.l.lower);
+ stw(ptr + 8, temp.l.upper);
+}
+
+#define FPUS_IE (1 << 0)
+#define FPUS_DE (1 << 1)
+#define FPUS_ZE (1 << 2)
+#define FPUS_OE (1 << 3)
+#define FPUS_UE (1 << 4)
+#define FPUS_PE (1 << 5)
+#define FPUS_SF (1 << 6)
+#define FPUS_SE (1 << 7)
+#define FPUS_B (1 << 15)
+
+#define FPUC_EM 0x3f
+
+static inline uint32_t compute_eflags(void)
+{
+ return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
+}
+
+/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
+static inline void load_eflags(int eflags, int update_mask)
+{
+ CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+ DF = 1 - (2 * ((eflags >> 10) & 1));
+ env->eflags = (env->eflags & ~update_mask) |
+ (eflags & update_mask) | 0x2;
+}
+
+/* load efer and update the corresponding hflags. XXX: do consistency
+ checks with cpuid bits ? */
+static inline void cpu_load_efer(CPUState *env, uint64_t val)
+{
+ env->efer = val;
+ env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK);
+ if (env->efer & MSR_EFER_LMA) {
+ env->hflags |= HF_LMA_MASK;
+ }
+ if (env->efer & MSR_EFER_SVME) {
+ env->hflags |= HF_SVME_MASK;
+ }
+}
+
+#if 0
+#define raise_exception_err(a, b)\
+do {\
+ qemu_log("raise_exception line=%d\n", __LINE__);\
+ (raise_exception_err)(a, b);\
+} while (0)
+#endif
+
+static void QEMU_NORETURN raise_exception_err(int exception_index,
+ int error_code);
+
+static const uint8_t parity_table[256] = {
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
+ 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
+};
+
+/* modulo 17 table */
+static const uint8_t rclw_table[32] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9,10,11,12,13,14,15,
+ 16, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9,10,11,12,13,14,
+};
+
+/* modulo 9 table */
+static const uint8_t rclb_table[32] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 0, 1, 2, 3, 4, 5,
+ 6, 7, 8, 0, 1, 2, 3, 4,
+};
+
+#define floatx80_lg2 make_floatx80( 0x3ffd, 0x9a209a84fbcff799LL )
+#define floatx80_l2e make_floatx80( 0x3fff, 0xb8aa3b295c17f0bcLL )
+#define floatx80_l2t make_floatx80( 0x4000, 0xd49a784bcd1b8afeLL )
+
+/* broken thread support */
+
+static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
+
+void helper_lock(void)
+{
+ spin_lock(&global_cpu_lock);
+}
+
+void helper_unlock(void)
+{
+ spin_unlock(&global_cpu_lock);
+}
+
+void helper_write_eflags(target_ulong t0, uint32_t update_mask)
+{
+ load_eflags(t0, update_mask);
+}
+
+target_ulong helper_read_eflags(void)
+{
+ uint32_t eflags;
+ eflags = helper_cc_compute_all(CC_OP);
+ eflags |= (DF & DF_MASK);
+ eflags |= env->eflags & ~(VM_MASK | RF_MASK);
+ return eflags;
+}
+
+/* return non zero if error */
+static inline int load_segment(uint32_t *e1_ptr, uint32_t *e2_ptr,
+ int selector)
+{
+ SegmentCache *dt;
+ int index;
+ target_ulong ptr;
+
+ if (selector & 0x4)
+ dt = &env->ldt;
+ else
+ dt = &env->gdt;
+ index = selector & ~7;
+ if ((index + 7) > dt->limit)
+ return -1;
+ ptr = dt->base + index;
+ *e1_ptr = ldl_kernel(ptr);
+ *e2_ptr = ldl_kernel(ptr + 4);
+ return 0;
+}
+
+static inline unsigned int get_seg_limit(uint32_t e1, uint32_t e2)
+{
+ unsigned int limit;
+ limit = (e1 & 0xffff) | (e2 & 0x000f0000);
+ if (e2 & DESC_G_MASK)
+ limit = (limit << 12) | 0xfff;
+ return limit;
+}
+
+static inline uint32_t get_seg_base(uint32_t e1, uint32_t e2)
+{
+ return ((e1 >> 16) | ((e2 & 0xff) << 16) | (e2 & 0xff000000));
+}
+
+static inline void load_seg_cache_raw_dt(SegmentCache *sc, uint32_t e1, uint32_t e2)
+{
+ sc->base = get_seg_base(e1, e2);
+ sc->limit = get_seg_limit(e1, e2);
+ sc->flags = e2;
+}
+
+/* init the segment cache in vm86 mode. */
+static inline void load_seg_vm(int seg, int selector)
+{
+ selector &= 0xffff;
+ cpu_x86_load_seg_cache(env, seg, selector,
+ (selector << 4), 0xffff, 0);
+}
+
+static inline void get_ss_esp_from_tss(uint32_t *ss_ptr,
+ uint32_t *esp_ptr, int dpl)
+{
+ int type, index, shift;
+
+#if 0
+ {
+ int i;
+ printf("TR: base=%p limit=%x\n", env->tr.base, env->tr.limit);
+ for(i=0;i<env->tr.limit;i++) {
+ printf("%02x ", env->tr.base[i]);
+ if ((i & 7) == 7) printf("\n");
+ }
+ printf("\n");
+ }
+#endif
+
+ if (!(env->tr.flags & DESC_P_MASK))
+ cpu_abort(env, "invalid tss");
+ type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf;
+ if ((type & 7) != 1)
+ cpu_abort(env, "invalid tss type");
+ shift = type >> 3;
+ index = (dpl * 4 + 2) << shift;
+ if (index + (4 << shift) - 1 > env->tr.limit)
+ raise_exception_err(EXCP0A_TSS, env->tr.selector & 0xfffc);
+ if (shift == 0) {
+ *esp_ptr = lduw_kernel(env->tr.base + index);
+ *ss_ptr = lduw_kernel(env->tr.base + index + 2);
+ } else {
+ *esp_ptr = ldl_kernel(env->tr.base + index);
+ *ss_ptr = lduw_kernel(env->tr.base + index + 4);
+ }
+}
+
+/* XXX: merge with load_seg() */
+static void tss_load_seg(int seg_reg, int selector)
+{
+ uint32_t e1, e2;
+ int rpl, dpl, cpl;
+
+ if ((selector & 0xfffc) != 0) {
+ if (load_segment(&e1, &e2, selector) != 0)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ if (!(e2 & DESC_S_MASK))
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ if (seg_reg == R_CS) {
+ if (!(e2 & DESC_CS_MASK))
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ /* XXX: is it correct ? */
+ if (dpl != rpl)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ if ((e2 & DESC_C_MASK) && dpl > rpl)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ } else if (seg_reg == R_SS) {
+ /* SS must be writable data */
+ if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK))
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ if (dpl != cpl || dpl != rpl)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ } else {
+ /* not readable code */
+ if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK))
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ /* if data or non conforming code, checks the rights */
+ if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) {
+ if (dpl < cpl || dpl < rpl)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ }
+ }
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+ cpu_x86_load_seg_cache(env, seg_reg, selector,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ } else {
+ if (seg_reg == R_SS || seg_reg == R_CS)
+ raise_exception_err(EXCP0A_TSS, selector & 0xfffc);
+ }
+}
+
+#define SWITCH_TSS_JMP 0
+#define SWITCH_TSS_IRET 1
+#define SWITCH_TSS_CALL 2
+
+/* XXX: restore CPU state in registers (PowerPC case) */
+static void switch_tss(int tss_selector,
+ uint32_t e1, uint32_t e2, int source,
+ uint32_t next_eip)
+{
+ int tss_limit, tss_limit_max, type, old_tss_limit_max, old_type, v1, v2, i;
+ target_ulong tss_base;
+ uint32_t new_regs[8], new_segs[6];
+ uint32_t new_eflags, new_eip, new_cr3, new_ldt, new_trap;
+ uint32_t old_eflags, eflags_mask;
+ SegmentCache *dt;
+ int index;
+ target_ulong ptr;
+
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ LOG_PCALL("switch_tss: sel=0x%04x type=%d src=%d\n", tss_selector, type, source);
+
+ /* if task gate, we read the TSS segment and we load it */
+ if (type == 5) {
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, tss_selector & 0xfffc);
+ tss_selector = e1 >> 16;
+ if (tss_selector & 4)
+ raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc);
+ if (load_segment(&e1, &e2, tss_selector) != 0)
+ raise_exception_err(EXCP0D_GPF, tss_selector & 0xfffc);
+ if (e2 & DESC_S_MASK)
+ raise_exception_err(EXCP0D_GPF, tss_selector & 0xfffc);
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ if ((type & 7) != 1)
+ raise_exception_err(EXCP0D_GPF, tss_selector & 0xfffc);
+ }
+
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, tss_selector & 0xfffc);
+
+ if (type & 8)
+ tss_limit_max = 103;
+ else
+ tss_limit_max = 43;
+ tss_limit = get_seg_limit(e1, e2);
+ tss_base = get_seg_base(e1, e2);
+ if ((tss_selector & 4) != 0 ||
+ tss_limit < tss_limit_max)
+ raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc);
+ old_type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf;
+ if (old_type & 8)
+ old_tss_limit_max = 103;
+ else
+ old_tss_limit_max = 43;
+
+ /* read all the registers from the new TSS */
+ if (type & 8) {
+ /* 32 bit */
+ new_cr3 = ldl_kernel(tss_base + 0x1c);
+ new_eip = ldl_kernel(tss_base + 0x20);
+ new_eflags = ldl_kernel(tss_base + 0x24);
+ for(i = 0; i < 8; i++)
+ new_regs[i] = ldl_kernel(tss_base + (0x28 + i * 4));
+ for(i = 0; i < 6; i++)
+ new_segs[i] = lduw_kernel(tss_base + (0x48 + i * 4));
+ new_ldt = lduw_kernel(tss_base + 0x60);
+ new_trap = ldl_kernel(tss_base + 0x64);
+ } else {
+ /* 16 bit */
+ new_cr3 = 0;
+ new_eip = lduw_kernel(tss_base + 0x0e);
+ new_eflags = lduw_kernel(tss_base + 0x10);
+ for(i = 0; i < 8; i++)
+ new_regs[i] = lduw_kernel(tss_base + (0x12 + i * 2)) | 0xffff0000;
+ for(i = 0; i < 4; i++)
+ new_segs[i] = lduw_kernel(tss_base + (0x22 + i * 4));
+ new_ldt = lduw_kernel(tss_base + 0x2a);
+ new_segs[R_FS] = 0;
+ new_segs[R_GS] = 0;
+ new_trap = 0;
+ }
+ /* XXX: avoid a compiler warning, see
+ http://support.amd.com/us/Processor_TechDocs/24593.pdf
+ chapters 12.2.5 and 13.2.4 on how to implement TSS Trap bit */
+ (void)new_trap;
+
+ /* NOTE: we must avoid memory exceptions during the task switch,
+ so we make dummy accesses before */
+ /* XXX: it can still fail in some cases, so a bigger hack is
+ necessary to valid the TLB after having done the accesses */
+
+ v1 = ldub_kernel(env->tr.base);
+ v2 = ldub_kernel(env->tr.base + old_tss_limit_max);
+ stb_kernel(env->tr.base, v1);
+ stb_kernel(env->tr.base + old_tss_limit_max, v2);
+
+ /* clear busy bit (it is restartable) */
+ if (source == SWITCH_TSS_JMP || source == SWITCH_TSS_IRET) {
+ target_ulong ptr;
+ uint32_t e2;
+ ptr = env->gdt.base + (env->tr.selector & ~7);
+ e2 = ldl_kernel(ptr + 4);
+ e2 &= ~DESC_TSS_BUSY_MASK;
+ stl_kernel(ptr + 4, e2);
+ }
+ old_eflags = compute_eflags();
+ if (source == SWITCH_TSS_IRET)
+ old_eflags &= ~NT_MASK;
+
+ /* save the current state in the old TSS */
+ if (type & 8) {
+ /* 32 bit */
+ stl_kernel(env->tr.base + 0x20, next_eip);
+ stl_kernel(env->tr.base + 0x24, old_eflags);
+ stl_kernel(env->tr.base + (0x28 + 0 * 4), EAX);
+ stl_kernel(env->tr.base + (0x28 + 1 * 4), ECX);
+ stl_kernel(env->tr.base + (0x28 + 2 * 4), EDX);
+ stl_kernel(env->tr.base + (0x28 + 3 * 4), EBX);
+ stl_kernel(env->tr.base + (0x28 + 4 * 4), ESP);
+ stl_kernel(env->tr.base + (0x28 + 5 * 4), EBP);
+ stl_kernel(env->tr.base + (0x28 + 6 * 4), ESI);
+ stl_kernel(env->tr.base + (0x28 + 7 * 4), EDI);
+ for(i = 0; i < 6; i++)
+ stw_kernel(env->tr.base + (0x48 + i * 4), env->segs[i].selector);
+ } else {
+ /* 16 bit */
+ stw_kernel(env->tr.base + 0x0e, next_eip);
+ stw_kernel(env->tr.base + 0x10, old_eflags);
+ stw_kernel(env->tr.base + (0x12 + 0 * 2), EAX);
+ stw_kernel(env->tr.base + (0x12 + 1 * 2), ECX);
+ stw_kernel(env->tr.base + (0x12 + 2 * 2), EDX);
+ stw_kernel(env->tr.base + (0x12 + 3 * 2), EBX);
+ stw_kernel(env->tr.base + (0x12 + 4 * 2), ESP);
+ stw_kernel(env->tr.base + (0x12 + 5 * 2), EBP);
+ stw_kernel(env->tr.base + (0x12 + 6 * 2), ESI);
+ stw_kernel(env->tr.base + (0x12 + 7 * 2), EDI);
+ for(i = 0; i < 4; i++)
+ stw_kernel(env->tr.base + (0x22 + i * 4), env->segs[i].selector);
+ }
+
+ /* now if an exception occurs, it will occurs in the next task
+ context */
+
+ if (source == SWITCH_TSS_CALL) {
+ stw_kernel(tss_base, env->tr.selector);
+ new_eflags |= NT_MASK;
+ }
+
+ /* set busy bit */
+ if (source == SWITCH_TSS_JMP || source == SWITCH_TSS_CALL) {
+ target_ulong ptr;
+ uint32_t e2;
+ ptr = env->gdt.base + (tss_selector & ~7);
+ e2 = ldl_kernel(ptr + 4);
+ e2 |= DESC_TSS_BUSY_MASK;
+ stl_kernel(ptr + 4, e2);
+ }
+
+ /* set the new CPU state */
+ /* from this point, any exception which occurs can give problems */
+ env->cr[0] |= CR0_TS_MASK;
+ env->hflags |= HF_TS_MASK;
+ env->tr.selector = tss_selector;
+ env->tr.base = tss_base;
+ env->tr.limit = tss_limit;
+ env->tr.flags = e2 & ~DESC_TSS_BUSY_MASK;
+
+ if ((type & 8) && (env->cr[0] & CR0_PG_MASK)) {
+ cpu_x86_update_cr3(env, new_cr3);
+ }
+
+ /* load all registers without an exception, then reload them with
+ possible exception */
+ env->eip = new_eip;
+ eflags_mask = TF_MASK | AC_MASK | ID_MASK |
+ IF_MASK | IOPL_MASK | VM_MASK | RF_MASK | NT_MASK;
+ if (!(type & 8))
+ eflags_mask &= 0xffff;
+ load_eflags(new_eflags, eflags_mask);
+ /* XXX: what to do in 16 bit case ? */
+ EAX = new_regs[0];
+ ECX = new_regs[1];
+ EDX = new_regs[2];
+ EBX = new_regs[3];
+ ESP = new_regs[4];
+ EBP = new_regs[5];
+ ESI = new_regs[6];
+ EDI = new_regs[7];
+ if (new_eflags & VM_MASK) {
+ for(i = 0; i < 6; i++)
+ load_seg_vm(i, new_segs[i]);
+ /* in vm86, CPL is always 3 */
+ cpu_x86_set_cpl(env, 3);
+ } else {
+ /* CPL is set the RPL of CS */
+ cpu_x86_set_cpl(env, new_segs[R_CS] & 3);
+ /* first just selectors as the rest may trigger exceptions */
+ for(i = 0; i < 6; i++)
+ cpu_x86_load_seg_cache(env, i, new_segs[i], 0, 0, 0);
+ }
+
+ env->ldt.selector = new_ldt & ~4;
+ env->ldt.base = 0;
+ env->ldt.limit = 0;
+ env->ldt.flags = 0;
+
+ /* load the LDT */
+ if (new_ldt & 4)
+ raise_exception_err(EXCP0A_TSS, new_ldt & 0xfffc);
+
+ if ((new_ldt & 0xfffc) != 0) {
+ dt = &env->gdt;
+ index = new_ldt & ~7;
+ if ((index + 7) > dt->limit)
+ raise_exception_err(EXCP0A_TSS, new_ldt & 0xfffc);
+ ptr = dt->base + index;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+ if ((e2 & DESC_S_MASK) || ((e2 >> DESC_TYPE_SHIFT) & 0xf) != 2)
+ raise_exception_err(EXCP0A_TSS, new_ldt & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0A_TSS, new_ldt & 0xfffc);
+ load_seg_cache_raw_dt(&env->ldt, e1, e2);
+ }
+
+ /* load the segments */
+ if (!(new_eflags & VM_MASK)) {
+ tss_load_seg(R_CS, new_segs[R_CS]);
+ tss_load_seg(R_SS, new_segs[R_SS]);
+ tss_load_seg(R_ES, new_segs[R_ES]);
+ tss_load_seg(R_DS, new_segs[R_DS]);
+ tss_load_seg(R_FS, new_segs[R_FS]);
+ tss_load_seg(R_GS, new_segs[R_GS]);
+ }
+
+ /* check that EIP is in the CS segment limits */
+ if (new_eip > env->segs[R_CS].limit) {
+ /* XXX: different exception if CALL ? */
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+
+#ifndef CONFIG_USER_ONLY
+ /* reset local breakpoints */
+ if (env->dr[7] & 0x55) {
+ for (i = 0; i < 4; i++) {
+ if (hw_breakpoint_enabled(env->dr[7], i) == 0x1)
+ hw_breakpoint_remove(env, i);
+ }
+ env->dr[7] &= ~0x55;
+ }
+#endif
+}
+
+/* check if Port I/O is allowed in TSS */
+static inline void check_io(int addr, int size)
+{
+ int io_offset, val, mask;
+
+ /* TSS must be a valid 32 bit one */
+ if (!(env->tr.flags & DESC_P_MASK) ||
+ ((env->tr.flags >> DESC_TYPE_SHIFT) & 0xf) != 9 ||
+ env->tr.limit < 103)
+ goto fail;
+ io_offset = lduw_kernel(env->tr.base + 0x66);
+ io_offset += (addr >> 3);
+ /* Note: the check needs two bytes */
+ if ((io_offset + 1) > env->tr.limit)
+ goto fail;
+ val = lduw_kernel(env->tr.base + io_offset);
+ val >>= (addr & 7);
+ mask = (1 << size) - 1;
+ /* all bits must be zero to allow the I/O */
+ if ((val & mask) != 0) {
+ fail:
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+}
+
+void helper_check_iob(uint32_t t0)
+{
+ check_io(t0, 1);
+}
+
+void helper_check_iow(uint32_t t0)
+{
+ check_io(t0, 2);
+}
+
+void helper_check_iol(uint32_t t0)
+{
+ check_io(t0, 4);
+}
+
+void helper_outb(uint32_t port, uint32_t data)
+{
+ cpu_outb(port, data & 0xff);
+}
+
+target_ulong helper_inb(uint32_t port)
+{
+ return cpu_inb(port);
+}
+
+void helper_outw(uint32_t port, uint32_t data)
+{
+ cpu_outw(port, data & 0xffff);
+}
+
+target_ulong helper_inw(uint32_t port)
+{
+ return cpu_inw(port);
+}
+
+void helper_outl(uint32_t port, uint32_t data)
+{
+ cpu_outl(port, data);
+}
+
+target_ulong helper_inl(uint32_t port)
+{
+ return cpu_inl(port);
+}
+
+static inline unsigned int get_sp_mask(unsigned int e2)
+{
+ if (e2 & DESC_B_MASK)
+ return 0xffffffff;
+ else
+ return 0xffff;
+}
+
+static int exeption_has_error_code(int intno)
+{
+ switch(intno) {
+ case 8:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 17:
+ return 1;
+ }
+ return 0;
+}
+
+#ifdef TARGET_X86_64
+#define SET_ESP(val, sp_mask)\
+do {\
+ if ((sp_mask) == 0xffff)\
+ ESP = (ESP & ~0xffff) | ((val) & 0xffff);\
+ else if ((sp_mask) == 0xffffffffLL)\
+ ESP = (uint32_t)(val);\
+ else\
+ ESP = (val);\
+} while (0)
+#else
+#define SET_ESP(val, sp_mask) ESP = (ESP & ~(sp_mask)) | ((val) & (sp_mask))
+#endif
+
+/* in 64-bit machines, this can overflow. So this segment addition macro
+ * can be used to trim the value to 32-bit whenever needed */
+#define SEG_ADDL(ssp, sp, sp_mask) ((uint32_t)((ssp) + (sp & (sp_mask))))
+
+/* XXX: add a is_user flag to have proper security support */
+#define PUSHW(ssp, sp, sp_mask, val)\
+{\
+ sp -= 2;\
+ stw_kernel((ssp) + (sp & (sp_mask)), (val));\
+}
+
+#define PUSHL(ssp, sp, sp_mask, val)\
+{\
+ sp -= 4;\
+ stl_kernel(SEG_ADDL(ssp, sp, sp_mask), (uint32_t)(val));\
+}
+
+#define POPW(ssp, sp, sp_mask, val)\
+{\
+ val = lduw_kernel((ssp) + (sp & (sp_mask)));\
+ sp += 2;\
+}
+
+#define POPL(ssp, sp, sp_mask, val)\
+{\
+ val = (uint32_t)ldl_kernel(SEG_ADDL(ssp, sp, sp_mask));\
+ sp += 4;\
+}
+
+/* protected mode interrupt */
+static void do_interrupt_protected(int intno, int is_int, int error_code,
+ unsigned int next_eip, int is_hw)
+{
+ SegmentCache *dt;
+ target_ulong ptr, ssp;
+ int type, dpl, selector, ss_dpl, cpl;
+ int has_error_code, new_stack, shift;
+ uint32_t e1, e2, offset, ss = 0, esp, ss_e1 = 0, ss_e2 = 0;
+ uint32_t old_eip, sp_mask;
+
+ has_error_code = 0;
+ if (!is_int && !is_hw)
+ has_error_code = exeption_has_error_code(intno);
+ if (is_int)
+ old_eip = next_eip;
+ else
+ old_eip = env->eip;
+
+ dt = &env->idt;
+ if (intno * 8 + 7 > dt->limit)
+ raise_exception_err(EXCP0D_GPF, intno * 8 + 2);
+ ptr = dt->base + intno * 8;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+ /* check gate type */
+ type = (e2 >> DESC_TYPE_SHIFT) & 0x1f;
+ switch(type) {
+ case 5: /* task gate */
+ /* must do that check here to return the correct error code */
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, intno * 8 + 2);
+ switch_tss(intno * 8, e1, e2, SWITCH_TSS_CALL, old_eip);
+ if (has_error_code) {
+ int type;
+ uint32_t mask;
+ /* push the error code */
+ type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf;
+ shift = type >> 3;
+ if (env->segs[R_SS].flags & DESC_B_MASK)
+ mask = 0xffffffff;
+ else
+ mask = 0xffff;
+ esp = (ESP - (2 << shift)) & mask;
+ ssp = env->segs[R_SS].base + esp;
+ if (shift)
+ stl_kernel(ssp, error_code);
+ else
+ stw_kernel(ssp, error_code);
+ SET_ESP(esp, mask);
+ }
+ return;
+ case 6: /* 286 interrupt gate */
+ case 7: /* 286 trap gate */
+ case 14: /* 386 interrupt gate */
+ case 15: /* 386 trap gate */
+ break;
+ default:
+ raise_exception_err(EXCP0D_GPF, intno * 8 + 2);
+ break;
+ }
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ /* check privilege if software int */
+ if (is_int && dpl < cpl)
+ raise_exception_err(EXCP0D_GPF, intno * 8 + 2);
+ /* check valid bit */
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, intno * 8 + 2);
+ selector = e1 >> 16;
+ offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff);
+ if ((selector & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, 0);
+
+ if (load_segment(&e1, &e2, selector) != 0)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK)))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (dpl > cpl)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+ if (!(e2 & DESC_C_MASK) && dpl < cpl) {
+ /* to inner privilege */
+ get_ss_esp_from_tss(&ss, &esp, dpl);
+ if ((ss & 0xfffc) == 0)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if ((ss & 3) != dpl)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (load_segment(&ss_e1, &ss_e2, ss) != 0)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3;
+ if (ss_dpl != dpl)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (!(ss_e2 & DESC_S_MASK) ||
+ (ss_e2 & DESC_CS_MASK) ||
+ !(ss_e2 & DESC_W_MASK))
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (!(ss_e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ new_stack = 1;
+ sp_mask = get_sp_mask(ss_e2);
+ ssp = get_seg_base(ss_e1, ss_e2);
+ } else if ((e2 & DESC_C_MASK) || dpl == cpl) {
+ /* to same privilege */
+ if (env->eflags & VM_MASK)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ new_stack = 0;
+ sp_mask = get_sp_mask(env->segs[R_SS].flags);
+ ssp = env->segs[R_SS].base;
+ esp = ESP;
+ dpl = cpl;
+ } else {
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ new_stack = 0; /* avoid warning */
+ sp_mask = 0; /* avoid warning */
+ ssp = 0; /* avoid warning */
+ esp = 0; /* avoid warning */
+ }
+
+ shift = type >> 3;
+
+#if 0
+ /* XXX: check that enough room is available */
+ push_size = 6 + (new_stack << 2) + (has_error_code << 1);
+ if (env->eflags & VM_MASK)
+ push_size += 8;
+ push_size <<= shift;
+#endif
+ if (shift == 1) {
+ if (new_stack) {
+ if (env->eflags & VM_MASK) {
+ PUSHL(ssp, esp, sp_mask, env->segs[R_GS].selector);
+ PUSHL(ssp, esp, sp_mask, env->segs[R_FS].selector);
+ PUSHL(ssp, esp, sp_mask, env->segs[R_DS].selector);
+ PUSHL(ssp, esp, sp_mask, env->segs[R_ES].selector);
+ }
+ PUSHL(ssp, esp, sp_mask, env->segs[R_SS].selector);
+ PUSHL(ssp, esp, sp_mask, ESP);
+ }
+ PUSHL(ssp, esp, sp_mask, compute_eflags());
+ PUSHL(ssp, esp, sp_mask, env->segs[R_CS].selector);
+ PUSHL(ssp, esp, sp_mask, old_eip);
+ if (has_error_code) {
+ PUSHL(ssp, esp, sp_mask, error_code);
+ }
+ } else {
+ if (new_stack) {
+ if (env->eflags & VM_MASK) {
+ PUSHW(ssp, esp, sp_mask, env->segs[R_GS].selector);
+ PUSHW(ssp, esp, sp_mask, env->segs[R_FS].selector);
+ PUSHW(ssp, esp, sp_mask, env->segs[R_DS].selector);
+ PUSHW(ssp, esp, sp_mask, env->segs[R_ES].selector);
+ }
+ PUSHW(ssp, esp, sp_mask, env->segs[R_SS].selector);
+ PUSHW(ssp, esp, sp_mask, ESP);
+ }
+ PUSHW(ssp, esp, sp_mask, compute_eflags());
+ PUSHW(ssp, esp, sp_mask, env->segs[R_CS].selector);
+ PUSHW(ssp, esp, sp_mask, old_eip);
+ if (has_error_code) {
+ PUSHW(ssp, esp, sp_mask, error_code);
+ }
+ }
+
+ if (new_stack) {
+ if (env->eflags & VM_MASK) {
+ cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0, 0);
+ cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0, 0);
+ cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0, 0);
+ cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0, 0);
+ }
+ ss = (ss & ~3) | dpl;
+ cpu_x86_load_seg_cache(env, R_SS, ss,
+ ssp, get_seg_limit(ss_e1, ss_e2), ss_e2);
+ }
+ SET_ESP(esp, sp_mask);
+
+ selector = (selector & ~3) | dpl;
+ cpu_x86_load_seg_cache(env, R_CS, selector,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ cpu_x86_set_cpl(env, dpl);
+ env->eip = offset;
+
+ /* interrupt gate clear IF mask */
+ if ((type & 1) == 0) {
+ env->eflags &= ~IF_MASK;
+ }
+ env->eflags &= ~(TF_MASK | VM_MASK | RF_MASK | NT_MASK);
+}
+
+#ifdef TARGET_X86_64
+
+#define PUSHQ(sp, val)\
+{\
+ sp -= 8;\
+ stq_kernel(sp, (val));\
+}
+
+#define POPQ(sp, val)\
+{\
+ val = ldq_kernel(sp);\
+ sp += 8;\
+}
+
+static inline target_ulong get_rsp_from_tss(int level)
+{
+ int index;
+
+#if 0
+ printf("TR: base=" TARGET_FMT_lx " limit=%x\n",
+ env->tr.base, env->tr.limit);
+#endif
+
+ if (!(env->tr.flags & DESC_P_MASK))
+ cpu_abort(env, "invalid tss");
+ index = 8 * level + 4;
+ if ((index + 7) > env->tr.limit)
+ raise_exception_err(EXCP0A_TSS, env->tr.selector & 0xfffc);
+ return ldq_kernel(env->tr.base + index);
+}
+
+/* 64 bit interrupt */
+static void do_interrupt64(int intno, int is_int, int error_code,
+ target_ulong next_eip, int is_hw)
+{
+ SegmentCache *dt;
+ target_ulong ptr;
+ int type, dpl, selector, cpl, ist;
+ int has_error_code, new_stack;
+ uint32_t e1, e2, e3, ss;
+ target_ulong old_eip, esp, offset;
+
+ has_error_code = 0;
+ if (!is_int && !is_hw)
+ has_error_code = exeption_has_error_code(intno);
+ if (is_int)
+ old_eip = next_eip;
+ else
+ old_eip = env->eip;
+
+ dt = &env->idt;
+ if (intno * 16 + 15 > dt->limit)
+ raise_exception_err(EXCP0D_GPF, intno * 16 + 2);
+ ptr = dt->base + intno * 16;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+ e3 = ldl_kernel(ptr + 8);
+ /* check gate type */
+ type = (e2 >> DESC_TYPE_SHIFT) & 0x1f;
+ switch(type) {
+ case 14: /* 386 interrupt gate */
+ case 15: /* 386 trap gate */
+ break;
+ default:
+ raise_exception_err(EXCP0D_GPF, intno * 16 + 2);
+ break;
+ }
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ /* check privilege if software int */
+ if (is_int && dpl < cpl)
+ raise_exception_err(EXCP0D_GPF, intno * 16 + 2);
+ /* check valid bit */
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, intno * 16 + 2);
+ selector = e1 >> 16;
+ offset = ((target_ulong)e3 << 32) | (e2 & 0xffff0000) | (e1 & 0x0000ffff);
+ ist = e2 & 7;
+ if ((selector & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, 0);
+
+ if (load_segment(&e1, &e2, selector) != 0)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK)))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (dpl > cpl)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+ if (!(e2 & DESC_L_MASK) || (e2 & DESC_B_MASK))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if ((!(e2 & DESC_C_MASK) && dpl < cpl) || ist != 0) {
+ /* to inner privilege */
+ if (ist != 0)
+ esp = get_rsp_from_tss(ist + 3);
+ else
+ esp = get_rsp_from_tss(dpl);
+ esp &= ~0xfLL; /* align stack */
+ ss = 0;
+ new_stack = 1;
+ } else if ((e2 & DESC_C_MASK) || dpl == cpl) {
+ /* to same privilege */
+ if (env->eflags & VM_MASK)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ new_stack = 0;
+ if (ist != 0)
+ esp = get_rsp_from_tss(ist + 3);
+ else
+ esp = ESP;
+ esp &= ~0xfLL; /* align stack */
+ dpl = cpl;
+ } else {
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ new_stack = 0; /* avoid warning */
+ esp = 0; /* avoid warning */
+ }
+
+ PUSHQ(esp, env->segs[R_SS].selector);
+ PUSHQ(esp, ESP);
+ PUSHQ(esp, compute_eflags());
+ PUSHQ(esp, env->segs[R_CS].selector);
+ PUSHQ(esp, old_eip);
+ if (has_error_code) {
+ PUSHQ(esp, error_code);
+ }
+
+ if (new_stack) {
+ ss = 0 | dpl;
+ cpu_x86_load_seg_cache(env, R_SS, ss, 0, 0, 0);
+ }
+ ESP = esp;
+
+ selector = (selector & ~3) | dpl;
+ cpu_x86_load_seg_cache(env, R_CS, selector,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ cpu_x86_set_cpl(env, dpl);
+ env->eip = offset;
+
+ /* interrupt gate clear IF mask */
+ if ((type & 1) == 0) {
+ env->eflags &= ~IF_MASK;
+ }
+ env->eflags &= ~(TF_MASK | VM_MASK | RF_MASK | NT_MASK);
+}
+#endif
+
+#ifdef TARGET_X86_64
+#if defined(CONFIG_USER_ONLY)
+void helper_syscall(int next_eip_addend)
+{
+ env->exception_index = EXCP_SYSCALL;
+ env->exception_next_eip = env->eip + next_eip_addend;
+ cpu_loop_exit(env);
+}
+#else
+void helper_syscall(int next_eip_addend)
+{
+ int selector;
+
+ if (!(env->efer & MSR_EFER_SCE)) {
+ raise_exception_err(EXCP06_ILLOP, 0);
+ }
+ selector = (env->star >> 32) & 0xffff;
+ if (env->hflags & HF_LMA_MASK) {
+ int code64;
+
+ ECX = env->eip + next_eip_addend;
+ env->regs[11] = compute_eflags();
+
+ code64 = env->hflags & HF_CS64_MASK;
+
+ cpu_x86_set_cpl(env, 0);
+ cpu_x86_load_seg_cache(env, R_CS, selector & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | DESC_L_MASK);
+ cpu_x86_load_seg_cache(env, R_SS, (selector + 8) & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_W_MASK | DESC_A_MASK);
+ env->eflags &= ~env->fmask;
+ load_eflags(env->eflags, 0);
+ if (code64)
+ env->eip = env->lstar;
+ else
+ env->eip = env->cstar;
+ } else {
+ ECX = (uint32_t)(env->eip + next_eip_addend);
+
+ cpu_x86_set_cpl(env, 0);
+ cpu_x86_load_seg_cache(env, R_CS, selector & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
+ cpu_x86_load_seg_cache(env, R_SS, (selector + 8) & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_W_MASK | DESC_A_MASK);
+ env->eflags &= ~(IF_MASK | RF_MASK | VM_MASK);
+ env->eip = (uint32_t)env->star;
+ }
+}
+#endif
+#endif
+
+#ifdef TARGET_X86_64
+void helper_sysret(int dflag)
+{
+ int cpl, selector;
+
+ if (!(env->efer & MSR_EFER_SCE)) {
+ raise_exception_err(EXCP06_ILLOP, 0);
+ }
+ cpl = env->hflags & HF_CPL_MASK;
+ if (!(env->cr[0] & CR0_PE_MASK) || cpl != 0) {
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+ selector = (env->star >> 48) & 0xffff;
+ if (env->hflags & HF_LMA_MASK) {
+ if (dflag == 2) {
+ cpu_x86_load_seg_cache(env, R_CS, (selector + 16) | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK |
+ DESC_L_MASK);
+ env->eip = ECX;
+ } else {
+ cpu_x86_load_seg_cache(env, R_CS, selector | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
+ env->eip = (uint32_t)ECX;
+ }
+ cpu_x86_load_seg_cache(env, R_SS, selector + 8,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_W_MASK | DESC_A_MASK);
+ load_eflags((uint32_t)(env->regs[11]), TF_MASK | AC_MASK | ID_MASK |
+ IF_MASK | IOPL_MASK | VM_MASK | RF_MASK | NT_MASK);
+ cpu_x86_set_cpl(env, 3);
+ } else {
+ cpu_x86_load_seg_cache(env, R_CS, selector | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
+ env->eip = (uint32_t)ECX;
+ cpu_x86_load_seg_cache(env, R_SS, selector + 8,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_W_MASK | DESC_A_MASK);
+ env->eflags |= IF_MASK;
+ cpu_x86_set_cpl(env, 3);
+ }
+}
+#endif
+
+/* real mode interrupt */
+static void do_interrupt_real(int intno, int is_int, int error_code,
+ unsigned int next_eip)
+{
+ SegmentCache *dt;
+ target_ulong ptr, ssp;
+ int selector;
+ uint32_t offset, esp;
+ uint32_t old_cs, old_eip;
+
+ /* real mode (simpler !) */
+ dt = &env->idt;
+ if (intno * 4 + 3 > dt->limit)
+ raise_exception_err(EXCP0D_GPF, intno * 8 + 2);
+ ptr = dt->base + intno * 4;
+ offset = lduw_kernel(ptr);
+ selector = lduw_kernel(ptr + 2);
+ esp = ESP;
+ ssp = env->segs[R_SS].base;
+ if (is_int)
+ old_eip = next_eip;
+ else
+ old_eip = env->eip;
+ old_cs = env->segs[R_CS].selector;
+ /* XXX: use SS segment size ? */
+ PUSHW(ssp, esp, 0xffff, compute_eflags());
+ PUSHW(ssp, esp, 0xffff, old_cs);
+ PUSHW(ssp, esp, 0xffff, old_eip);
+
+ /* update processor state */
+ ESP = (ESP & ~0xffff) | (esp & 0xffff);
+ env->eip = offset;
+ env->segs[R_CS].selector = selector;
+ env->segs[R_CS].base = (selector << 4);
+ env->eflags &= ~(IF_MASK | TF_MASK | AC_MASK | RF_MASK);
+}
+
+#if defined(CONFIG_USER_ONLY)
+/* fake user mode interrupt */
+static void do_interrupt_user(int intno, int is_int, int error_code,
+ target_ulong next_eip)
+{
+ SegmentCache *dt;
+ target_ulong ptr;
+ int dpl, cpl, shift;
+ uint32_t e2;
+
+ dt = &env->idt;
+ if (env->hflags & HF_LMA_MASK) {
+ shift = 4;
+ } else {
+ shift = 3;
+ }
+ ptr = dt->base + (intno << shift);
+ e2 = ldl_kernel(ptr + 4);
+
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ /* check privilege if software int */
+ if (is_int && dpl < cpl)
+ raise_exception_err(EXCP0D_GPF, (intno << shift) + 2);
+
+ /* Since we emulate only user space, we cannot do more than
+ exiting the emulation with the suitable exception and error
+ code */
+ if (is_int)
+ EIP = next_eip;
+}
+
+#else
+
+static void handle_even_inj(int intno, int is_int, int error_code,
+ int is_hw, int rm)
+{
+ uint32_t event_inj = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj));
+ if (!(event_inj & SVM_EVTINJ_VALID)) {
+ int type;
+ if (is_int)
+ type = SVM_EVTINJ_TYPE_SOFT;
+ else
+ type = SVM_EVTINJ_TYPE_EXEPT;
+ event_inj = intno | type | SVM_EVTINJ_VALID;
+ if (!rm && exeption_has_error_code(intno)) {
+ event_inj |= SVM_EVTINJ_VALID_ERR;
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err), error_code);
+ }
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj);
+ }
+}
+#endif
+
+/*
+ * Begin execution of an interruption. is_int is TRUE if coming from
+ * the int instruction. next_eip is the EIP value AFTER the interrupt
+ * instruction. It is only relevant if is_int is TRUE.
+ */
+static void do_interrupt_all(int intno, int is_int, int error_code,
+ target_ulong next_eip, int is_hw)
+{
+ if (qemu_loglevel_mask(CPU_LOG_INT)) {
+ if ((env->cr[0] & CR0_PE_MASK)) {
+ static int count;
+ qemu_log("%6d: v=%02x e=%04x i=%d cpl=%d IP=%04x:" TARGET_FMT_lx " pc=" TARGET_FMT_lx " SP=%04x:" TARGET_FMT_lx,
+ count, intno, error_code, is_int,
+ env->hflags & HF_CPL_MASK,
+ env->segs[R_CS].selector, EIP,
+ (int)env->segs[R_CS].base + EIP,
+ env->segs[R_SS].selector, ESP);
+ if (intno == 0x0e) {
+ qemu_log(" CR2=" TARGET_FMT_lx, env->cr[2]);
+ } else {
+ qemu_log(" EAX=" TARGET_FMT_lx, EAX);
+ }
+ qemu_log("\n");
+ log_cpu_state(env, X86_DUMP_CCOP);
+#if 0
+ {
+ int i;
+ target_ulong ptr;
+ qemu_log(" code=");
+ ptr = env->segs[R_CS].base + env->eip;
+ for(i = 0; i < 16; i++) {
+ qemu_log(" %02x", ldub(ptr + i));
+ }
+ qemu_log("\n");
+ }
+#endif
+ count++;
+ }
+ }
+ if (env->cr[0] & CR0_PE_MASK) {
+#if !defined(CONFIG_USER_ONLY)
+ if (env->hflags & HF_SVMI_MASK)
+ handle_even_inj(intno, is_int, error_code, is_hw, 0);
+#endif
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK) {
+ do_interrupt64(intno, is_int, error_code, next_eip, is_hw);
+ } else
+#endif
+ {
+ do_interrupt_protected(intno, is_int, error_code, next_eip, is_hw);
+ }
+ } else {
+#if !defined(CONFIG_USER_ONLY)
+ if (env->hflags & HF_SVMI_MASK)
+ handle_even_inj(intno, is_int, error_code, is_hw, 1);
+#endif
+ do_interrupt_real(intno, is_int, error_code, next_eip);
+ }
+
+#if !defined(CONFIG_USER_ONLY)
+ if (env->hflags & HF_SVMI_MASK) {
+ uint32_t event_inj = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj));
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj & ~SVM_EVTINJ_VALID);
+ }
+#endif
+}
+
+void do_interrupt(CPUState *env1)
+{
+ CPUState *saved_env;
+
+ saved_env = env;
+ env = env1;
+#if defined(CONFIG_USER_ONLY)
+ /* if user mode only, we simulate a fake exception
+ which will be handled outside the cpu execution
+ loop */
+ do_interrupt_user(env->exception_index,
+ env->exception_is_int,
+ env->error_code,
+ env->exception_next_eip);
+ /* successfully delivered */
+ env->old_exception = -1;
+#else
+ /* simulate a real cpu exception. On i386, it can
+ trigger new exceptions, but we do not handle
+ double or triple faults yet. */
+ do_interrupt_all(env->exception_index,
+ env->exception_is_int,
+ env->error_code,
+ env->exception_next_eip, 0);
+ /* successfully delivered */
+ env->old_exception = -1;
+#endif
+ env = saved_env;
+}
+
+void do_interrupt_x86_hardirq(CPUState *env1, int intno, int is_hw)
+{
+ CPUState *saved_env;
+
+ saved_env = env;
+ env = env1;
+ do_interrupt_all(intno, 0, 0, 0, is_hw);
+ env = saved_env;
+}
+
+/* This should come from sysemu.h - if we could include it here... */
+void qemu_system_reset_request(void);
+
+/*
+ * Check nested exceptions and change to double or triple fault if
+ * needed. It should only be called, if this is not an interrupt.
+ * Returns the new exception number.
+ */
+static int check_exception(int intno, int *error_code)
+{
+ int first_contributory = env->old_exception == 0 ||
+ (env->old_exception >= 10 &&
+ env->old_exception <= 13);
+ int second_contributory = intno == 0 ||
+ (intno >= 10 && intno <= 13);
+
+ qemu_log_mask(CPU_LOG_INT, "check_exception old: 0x%x new 0x%x\n",
+ env->old_exception, intno);
+
+#if !defined(CONFIG_USER_ONLY)
+ if (env->old_exception == EXCP08_DBLE) {
+ if (env->hflags & HF_SVMI_MASK)
+ helper_vmexit(SVM_EXIT_SHUTDOWN, 0); /* does not return */
+
+ qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
+
+ qemu_system_reset_request();
+ return EXCP_HLT;
+ }
+#endif
+
+ if ((first_contributory && second_contributory)
+ || (env->old_exception == EXCP0E_PAGE &&
+ (second_contributory || (intno == EXCP0E_PAGE)))) {
+ intno = EXCP08_DBLE;
+ *error_code = 0;
+ }
+
+ if (second_contributory || (intno == EXCP0E_PAGE) ||
+ (intno == EXCP08_DBLE))
+ env->old_exception = intno;
+
+ return intno;
+}
+
+/*
+ * Signal an interruption. It is executed in the main CPU loop.
+ * is_int is TRUE if coming from the int instruction. next_eip is the
+ * EIP value AFTER the interrupt instruction. It is only relevant if
+ * is_int is TRUE.
+ */
+static void QEMU_NORETURN raise_interrupt(int intno, int is_int, int error_code,
+ int next_eip_addend)
+{
+ if (!is_int) {
+ helper_svm_check_intercept_param(SVM_EXIT_EXCP_BASE + intno, error_code);
+ intno = check_exception(intno, &error_code);
+ } else {
+ helper_svm_check_intercept_param(SVM_EXIT_SWINT, 0);
+ }
+
+ env->exception_index = intno;
+ env->error_code = error_code;
+ env->exception_is_int = is_int;
+ env->exception_next_eip = env->eip + next_eip_addend;
+ cpu_loop_exit(env);
+}
+
+/* shortcuts to generate exceptions */
+
+static void QEMU_NORETURN raise_exception_err(int exception_index,
+ int error_code)
+{
+ raise_interrupt(exception_index, 0, error_code, 0);
+}
+
+void raise_exception_err_env(CPUState *nenv, int exception_index,
+ int error_code)
+{
+ env = nenv;
+ raise_interrupt(exception_index, 0, error_code, 0);
+}
+
+static void QEMU_NORETURN raise_exception(int exception_index)
+{
+ raise_interrupt(exception_index, 0, 0, 0);
+}
+
+void raise_exception_env(int exception_index, CPUState *nenv)
+{
+ env = nenv;
+ raise_exception(exception_index);
+}
+/* SMM support */
+
+#if defined(CONFIG_USER_ONLY)
+
+void do_smm_enter(CPUState *env1)
+{
+}
+
+void helper_rsm(void)
+{
+}
+
+#else
+
+#ifdef TARGET_X86_64
+#define SMM_REVISION_ID 0x00020064
+#else
+#define SMM_REVISION_ID 0x00020000
+#endif
+
+void do_smm_enter(CPUState *env1)
+{
+ target_ulong sm_state;
+ SegmentCache *dt;
+ int i, offset;
+ CPUState *saved_env;
+
+ saved_env = env;
+ env = env1;
+
+ qemu_log_mask(CPU_LOG_INT, "SMM: enter\n");
+ log_cpu_state_mask(CPU_LOG_INT, env, X86_DUMP_CCOP);
+
+ env->hflags |= HF_SMM_MASK;
+ cpu_smm_update(env);
+
+ sm_state = env->smbase + 0x8000;
+
+#ifdef TARGET_X86_64
+ for(i = 0; i < 6; i++) {
+ dt = &env->segs[i];
+ offset = 0x7e00 + i * 16;
+ stw_phys(sm_state + offset, dt->selector);
+ stw_phys(sm_state + offset + 2, (dt->flags >> 8) & 0xf0ff);
+ stl_phys(sm_state + offset + 4, dt->limit);
+ stq_phys(sm_state + offset + 8, dt->base);
+ }
+
+ stq_phys(sm_state + 0x7e68, env->gdt.base);
+ stl_phys(sm_state + 0x7e64, env->gdt.limit);
+
+ stw_phys(sm_state + 0x7e70, env->ldt.selector);
+ stq_phys(sm_state + 0x7e78, env->ldt.base);
+ stl_phys(sm_state + 0x7e74, env->ldt.limit);
+ stw_phys(sm_state + 0x7e72, (env->ldt.flags >> 8) & 0xf0ff);
+
+ stq_phys(sm_state + 0x7e88, env->idt.base);
+ stl_phys(sm_state + 0x7e84, env->idt.limit);
+
+ stw_phys(sm_state + 0x7e90, env->tr.selector);
+ stq_phys(sm_state + 0x7e98, env->tr.base);
+ stl_phys(sm_state + 0x7e94, env->tr.limit);
+ stw_phys(sm_state + 0x7e92, (env->tr.flags >> 8) & 0xf0ff);
+
+ stq_phys(sm_state + 0x7ed0, env->efer);
+
+ stq_phys(sm_state + 0x7ff8, EAX);
+ stq_phys(sm_state + 0x7ff0, ECX);
+ stq_phys(sm_state + 0x7fe8, EDX);
+ stq_phys(sm_state + 0x7fe0, EBX);
+ stq_phys(sm_state + 0x7fd8, ESP);
+ stq_phys(sm_state + 0x7fd0, EBP);
+ stq_phys(sm_state + 0x7fc8, ESI);
+ stq_phys(sm_state + 0x7fc0, EDI);
+ for(i = 8; i < 16; i++)
+ stq_phys(sm_state + 0x7ff8 - i * 8, env->regs[i]);
+ stq_phys(sm_state + 0x7f78, env->eip);
+ stl_phys(sm_state + 0x7f70, compute_eflags());
+ stl_phys(sm_state + 0x7f68, env->dr[6]);
+ stl_phys(sm_state + 0x7f60, env->dr[7]);
+
+ stl_phys(sm_state + 0x7f48, env->cr[4]);
+ stl_phys(sm_state + 0x7f50, env->cr[3]);
+ stl_phys(sm_state + 0x7f58, env->cr[0]);
+
+ stl_phys(sm_state + 0x7efc, SMM_REVISION_ID);
+ stl_phys(sm_state + 0x7f00, env->smbase);
+#else
+ stl_phys(sm_state + 0x7ffc, env->cr[0]);
+ stl_phys(sm_state + 0x7ff8, env->cr[3]);
+ stl_phys(sm_state + 0x7ff4, compute_eflags());
+ stl_phys(sm_state + 0x7ff0, env->eip);
+ stl_phys(sm_state + 0x7fec, EDI);
+ stl_phys(sm_state + 0x7fe8, ESI);
+ stl_phys(sm_state + 0x7fe4, EBP);
+ stl_phys(sm_state + 0x7fe0, ESP);
+ stl_phys(sm_state + 0x7fdc, EBX);
+ stl_phys(sm_state + 0x7fd8, EDX);
+ stl_phys(sm_state + 0x7fd4, ECX);
+ stl_phys(sm_state + 0x7fd0, EAX);
+ stl_phys(sm_state + 0x7fcc, env->dr[6]);
+ stl_phys(sm_state + 0x7fc8, env->dr[7]);
+
+ stl_phys(sm_state + 0x7fc4, env->tr.selector);
+ stl_phys(sm_state + 0x7f64, env->tr.base);
+ stl_phys(sm_state + 0x7f60, env->tr.limit);
+ stl_phys(sm_state + 0x7f5c, (env->tr.flags >> 8) & 0xf0ff);
+
+ stl_phys(sm_state + 0x7fc0, env->ldt.selector);
+ stl_phys(sm_state + 0x7f80, env->ldt.base);
+ stl_phys(sm_state + 0x7f7c, env->ldt.limit);
+ stl_phys(sm_state + 0x7f78, (env->ldt.flags >> 8) & 0xf0ff);
+
+ stl_phys(sm_state + 0x7f74, env->gdt.base);
+ stl_phys(sm_state + 0x7f70, env->gdt.limit);
+
+ stl_phys(sm_state + 0x7f58, env->idt.base);
+ stl_phys(sm_state + 0x7f54, env->idt.limit);
+
+ for(i = 0; i < 6; i++) {
+ dt = &env->segs[i];
+ if (i < 3)
+ offset = 0x7f84 + i * 12;
+ else
+ offset = 0x7f2c + (i - 3) * 12;
+ stl_phys(sm_state + 0x7fa8 + i * 4, dt->selector);
+ stl_phys(sm_state + offset + 8, dt->base);
+ stl_phys(sm_state + offset + 4, dt->limit);
+ stl_phys(sm_state + offset, (dt->flags >> 8) & 0xf0ff);
+ }
+ stl_phys(sm_state + 0x7f14, env->cr[4]);
+
+ stl_phys(sm_state + 0x7efc, SMM_REVISION_ID);
+ stl_phys(sm_state + 0x7ef8, env->smbase);
+#endif
+ /* init SMM cpu state */
+
+#ifdef TARGET_X86_64
+ cpu_load_efer(env, 0);
+#endif
+ load_eflags(0, ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
+ env->eip = 0x00008000;
+ cpu_x86_load_seg_cache(env, R_CS, (env->smbase >> 4) & 0xffff, env->smbase,
+ 0xffffffff, 0);
+ cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0xffffffff, 0);
+ cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0xffffffff, 0);
+ cpu_x86_load_seg_cache(env, R_SS, 0, 0, 0xffffffff, 0);
+ cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0xffffffff, 0);
+ cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0xffffffff, 0);
+
+ cpu_x86_update_cr0(env,
+ env->cr[0] & ~(CR0_PE_MASK | CR0_EM_MASK | CR0_TS_MASK | CR0_PG_MASK));
+ cpu_x86_update_cr4(env, 0);
+ env->dr[7] = 0x00000400;
+ CC_OP = CC_OP_EFLAGS;
+ env = saved_env;
+}
+
+void helper_rsm(void)
+{
+ target_ulong sm_state;
+ int i, offset;
+ uint32_t val;
+
+ sm_state = env->smbase + 0x8000;
+#ifdef TARGET_X86_64
+ cpu_load_efer(env, ldq_phys(sm_state + 0x7ed0));
+
+ for(i = 0; i < 6; i++) {
+ offset = 0x7e00 + i * 16;
+ cpu_x86_load_seg_cache(env, i,
+ lduw_phys(sm_state + offset),
+ ldq_phys(sm_state + offset + 8),
+ ldl_phys(sm_state + offset + 4),
+ (lduw_phys(sm_state + offset + 2) & 0xf0ff) << 8);
+ }
+
+ env->gdt.base = ldq_phys(sm_state + 0x7e68);
+ env->gdt.limit = ldl_phys(sm_state + 0x7e64);
+
+ env->ldt.selector = lduw_phys(sm_state + 0x7e70);
+ env->ldt.base = ldq_phys(sm_state + 0x7e78);
+ env->ldt.limit = ldl_phys(sm_state + 0x7e74);
+ env->ldt.flags = (lduw_phys(sm_state + 0x7e72) & 0xf0ff) << 8;
+
+ env->idt.base = ldq_phys(sm_state + 0x7e88);
+ env->idt.limit = ldl_phys(sm_state + 0x7e84);
+
+ env->tr.selector = lduw_phys(sm_state + 0x7e90);
+ env->tr.base = ldq_phys(sm_state + 0x7e98);
+ env->tr.limit = ldl_phys(sm_state + 0x7e94);
+ env->tr.flags = (lduw_phys(sm_state + 0x7e92) & 0xf0ff) << 8;
+
+ EAX = ldq_phys(sm_state + 0x7ff8);
+ ECX = ldq_phys(sm_state + 0x7ff0);
+ EDX = ldq_phys(sm_state + 0x7fe8);
+ EBX = ldq_phys(sm_state + 0x7fe0);
+ ESP = ldq_phys(sm_state + 0x7fd8);
+ EBP = ldq_phys(sm_state + 0x7fd0);
+ ESI = ldq_phys(sm_state + 0x7fc8);
+ EDI = ldq_phys(sm_state + 0x7fc0);
+ for(i = 8; i < 16; i++)
+ env->regs[i] = ldq_phys(sm_state + 0x7ff8 - i * 8);
+ env->eip = ldq_phys(sm_state + 0x7f78);
+ load_eflags(ldl_phys(sm_state + 0x7f70),
+ ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
+ env->dr[6] = ldl_phys(sm_state + 0x7f68);
+ env->dr[7] = ldl_phys(sm_state + 0x7f60);
+
+ cpu_x86_update_cr4(env, ldl_phys(sm_state + 0x7f48));
+ cpu_x86_update_cr3(env, ldl_phys(sm_state + 0x7f50));
+ cpu_x86_update_cr0(env, ldl_phys(sm_state + 0x7f58));
+
+ val = ldl_phys(sm_state + 0x7efc); /* revision ID */
+ if (val & 0x20000) {
+ env->smbase = ldl_phys(sm_state + 0x7f00) & ~0x7fff;
+ }
+#else
+ cpu_x86_update_cr0(env, ldl_phys(sm_state + 0x7ffc));
+ cpu_x86_update_cr3(env, ldl_phys(sm_state + 0x7ff8));
+ load_eflags(ldl_phys(sm_state + 0x7ff4),
+ ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
+ env->eip = ldl_phys(sm_state + 0x7ff0);
+ EDI = ldl_phys(sm_state + 0x7fec);
+ ESI = ldl_phys(sm_state + 0x7fe8);
+ EBP = ldl_phys(sm_state + 0x7fe4);
+ ESP = ldl_phys(sm_state + 0x7fe0);
+ EBX = ldl_phys(sm_state + 0x7fdc);
+ EDX = ldl_phys(sm_state + 0x7fd8);
+ ECX = ldl_phys(sm_state + 0x7fd4);
+ EAX = ldl_phys(sm_state + 0x7fd0);
+ env->dr[6] = ldl_phys(sm_state + 0x7fcc);
+ env->dr[7] = ldl_phys(sm_state + 0x7fc8);
+
+ env->tr.selector = ldl_phys(sm_state + 0x7fc4) & 0xffff;
+ env->tr.base = ldl_phys(sm_state + 0x7f64);
+ env->tr.limit = ldl_phys(sm_state + 0x7f60);
+ env->tr.flags = (ldl_phys(sm_state + 0x7f5c) & 0xf0ff) << 8;
+
+ env->ldt.selector = ldl_phys(sm_state + 0x7fc0) & 0xffff;
+ env->ldt.base = ldl_phys(sm_state + 0x7f80);
+ env->ldt.limit = ldl_phys(sm_state + 0x7f7c);
+ env->ldt.flags = (ldl_phys(sm_state + 0x7f78) & 0xf0ff) << 8;
+
+ env->gdt.base = ldl_phys(sm_state + 0x7f74);
+ env->gdt.limit = ldl_phys(sm_state + 0x7f70);
+
+ env->idt.base = ldl_phys(sm_state + 0x7f58);
+ env->idt.limit = ldl_phys(sm_state + 0x7f54);
+
+ for(i = 0; i < 6; i++) {
+ if (i < 3)
+ offset = 0x7f84 + i * 12;
+ else
+ offset = 0x7f2c + (i - 3) * 12;
+ cpu_x86_load_seg_cache(env, i,
+ ldl_phys(sm_state + 0x7fa8 + i * 4) & 0xffff,
+ ldl_phys(sm_state + offset + 8),
+ ldl_phys(sm_state + offset + 4),
+ (ldl_phys(sm_state + offset) & 0xf0ff) << 8);
+ }
+ cpu_x86_update_cr4(env, ldl_phys(sm_state + 0x7f14));
+
+ val = ldl_phys(sm_state + 0x7efc); /* revision ID */
+ if (val & 0x20000) {
+ env->smbase = ldl_phys(sm_state + 0x7ef8) & ~0x7fff;
+ }
+#endif
+ CC_OP = CC_OP_EFLAGS;
+ env->hflags &= ~HF_SMM_MASK;
+ cpu_smm_update(env);
+
+ qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n");
+ log_cpu_state_mask(CPU_LOG_INT, env, X86_DUMP_CCOP);
+}
+
+#endif /* !CONFIG_USER_ONLY */
+
+
+/* division, flags are undefined */
+
+void helper_divb_AL(target_ulong t0)
+{
+ unsigned int num, den, q, r;
+
+ num = (EAX & 0xffff);
+ den = (t0 & 0xff);
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ if (q > 0xff)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xff;
+ r = (num % den) & 0xff;
+ EAX = (EAX & ~0xffff) | (r << 8) | q;
+}
+
+void helper_idivb_AL(target_ulong t0)
+{
+ int num, den, q, r;
+
+ num = (int16_t)EAX;
+ den = (int8_t)t0;
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ if (q != (int8_t)q)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xff;
+ r = (num % den) & 0xff;
+ EAX = (EAX & ~0xffff) | (r << 8) | q;
+}
+
+void helper_divw_AX(target_ulong t0)
+{
+ unsigned int num, den, q, r;
+
+ num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
+ den = (t0 & 0xffff);
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ if (q > 0xffff)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xffff;
+ r = (num % den) & 0xffff;
+ EAX = (EAX & ~0xffff) | q;
+ EDX = (EDX & ~0xffff) | r;
+}
+
+void helper_idivw_AX(target_ulong t0)
+{
+ int num, den, q, r;
+
+ num = (EAX & 0xffff) | ((EDX & 0xffff) << 16);
+ den = (int16_t)t0;
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ if (q != (int16_t)q)
+ raise_exception(EXCP00_DIVZ);
+ q &= 0xffff;
+ r = (num % den) & 0xffff;
+ EAX = (EAX & ~0xffff) | q;
+ EDX = (EDX & ~0xffff) | r;
+}
+
+void helper_divl_EAX(target_ulong t0)
+{
+ unsigned int den, r;
+ uint64_t num, q;
+
+ num = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32);
+ den = t0;
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ r = (num % den);
+ if (q > 0xffffffff)
+ raise_exception(EXCP00_DIVZ);
+ EAX = (uint32_t)q;
+ EDX = (uint32_t)r;
+}
+
+void helper_idivl_EAX(target_ulong t0)
+{
+ int den, r;
+ int64_t num, q;
+
+ num = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32);
+ den = t0;
+ if (den == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ q = (num / den);
+ r = (num % den);
+ if (q != (int32_t)q)
+ raise_exception(EXCP00_DIVZ);
+ EAX = (uint32_t)q;
+ EDX = (uint32_t)r;
+}
+
+/* bcd */
+
+/* XXX: exception */
+void helper_aam(int base)
+{
+ int al, ah;
+ al = EAX & 0xff;
+ ah = al / base;
+ al = al % base;
+ EAX = (EAX & ~0xffff) | al | (ah << 8);
+ CC_DST = al;
+}
+
+void helper_aad(int base)
+{
+ int al, ah;
+ al = EAX & 0xff;
+ ah = (EAX >> 8) & 0xff;
+ al = ((ah * base) + al) & 0xff;
+ EAX = (EAX & ~0xffff) | al;
+ CC_DST = al;
+}
+
+void helper_aaa(void)
+{
+ int icarry;
+ int al, ah, af;
+ int eflags;
+
+ eflags = helper_cc_compute_all(CC_OP);
+ af = eflags & CC_A;
+ al = EAX & 0xff;
+ ah = (EAX >> 8) & 0xff;
+
+ icarry = (al > 0xf9);
+ if (((al & 0x0f) > 9 ) || af) {
+ al = (al + 6) & 0x0f;
+ ah = (ah + 1 + icarry) & 0xff;
+ eflags |= CC_C | CC_A;
+ } else {
+ eflags &= ~(CC_C | CC_A);
+ al &= 0x0f;
+ }
+ EAX = (EAX & ~0xffff) | al | (ah << 8);
+ CC_SRC = eflags;
+}
+
+void helper_aas(void)
+{
+ int icarry;
+ int al, ah, af;
+ int eflags;
+
+ eflags = helper_cc_compute_all(CC_OP);
+ af = eflags & CC_A;
+ al = EAX & 0xff;
+ ah = (EAX >> 8) & 0xff;
+
+ icarry = (al < 6);
+ if (((al & 0x0f) > 9 ) || af) {
+ al = (al - 6) & 0x0f;
+ ah = (ah - 1 - icarry) & 0xff;
+ eflags |= CC_C | CC_A;
+ } else {
+ eflags &= ~(CC_C | CC_A);
+ al &= 0x0f;
+ }
+ EAX = (EAX & ~0xffff) | al | (ah << 8);
+ CC_SRC = eflags;
+}
+
+void helper_daa(void)
+{
+ int old_al, al, af, cf;
+ int eflags;
+
+ eflags = helper_cc_compute_all(CC_OP);
+ cf = eflags & CC_C;
+ af = eflags & CC_A;
+ old_al = al = EAX & 0xff;
+
+ eflags = 0;
+ if (((al & 0x0f) > 9 ) || af) {
+ al = (al + 6) & 0xff;
+ eflags |= CC_A;
+ }
+ if ((old_al > 0x99) || cf) {
+ al = (al + 0x60) & 0xff;
+ eflags |= CC_C;
+ }
+ EAX = (EAX & ~0xff) | al;
+ /* well, speed is not an issue here, so we compute the flags by hand */
+ eflags |= (al == 0) << 6; /* zf */
+ eflags |= parity_table[al]; /* pf */
+ eflags |= (al & 0x80); /* sf */
+ CC_SRC = eflags;
+}
+
+void helper_das(void)
+{
+ int al, al1, af, cf;
+ int eflags;
+
+ eflags = helper_cc_compute_all(CC_OP);
+ cf = eflags & CC_C;
+ af = eflags & CC_A;
+ al = EAX & 0xff;
+
+ eflags = 0;
+ al1 = al;
+ if (((al & 0x0f) > 9 ) || af) {
+ eflags |= CC_A;
+ if (al < 6 || cf)
+ eflags |= CC_C;
+ al = (al - 6) & 0xff;
+ }
+ if ((al1 > 0x99) || cf) {
+ al = (al - 0x60) & 0xff;
+ eflags |= CC_C;
+ }
+ EAX = (EAX & ~0xff) | al;
+ /* well, speed is not an issue here, so we compute the flags by hand */
+ eflags |= (al == 0) << 6; /* zf */
+ eflags |= parity_table[al]; /* pf */
+ eflags |= (al & 0x80); /* sf */
+ CC_SRC = eflags;
+}
+
+void helper_into(int next_eip_addend)
+{
+ int eflags;
+ eflags = helper_cc_compute_all(CC_OP);
+ if (eflags & CC_O) {
+ raise_interrupt(EXCP04_INTO, 1, 0, next_eip_addend);
+ }
+}
+
+void helper_cmpxchg8b(target_ulong a0)
+{
+ uint64_t d;
+ int eflags;
+
+ eflags = helper_cc_compute_all(CC_OP);
+ d = ldq(a0);
+ if (d == (((uint64_t)EDX << 32) | (uint32_t)EAX)) {
+ stq(a0, ((uint64_t)ECX << 32) | (uint32_t)EBX);
+ eflags |= CC_Z;
+ } else {
+ /* always do the store */
+ stq(a0, d);
+ EDX = (uint32_t)(d >> 32);
+ EAX = (uint32_t)d;
+ eflags &= ~CC_Z;
+ }
+ CC_SRC = eflags;
+}
+
+#ifdef TARGET_X86_64
+void helper_cmpxchg16b(target_ulong a0)
+{
+ uint64_t d0, d1;
+ int eflags;
+
+ if ((a0 & 0xf) != 0)
+ raise_exception(EXCP0D_GPF);
+ eflags = helper_cc_compute_all(CC_OP);
+ d0 = ldq(a0);
+ d1 = ldq(a0 + 8);
+ if (d0 == EAX && d1 == EDX) {
+ stq(a0, EBX);
+ stq(a0 + 8, ECX);
+ eflags |= CC_Z;
+ } else {
+ /* always do the store */
+ stq(a0, d0);
+ stq(a0 + 8, d1);
+ EDX = d1;
+ EAX = d0;
+ eflags &= ~CC_Z;
+ }
+ CC_SRC = eflags;
+}
+#endif
+
+void helper_single_step(void)
+{
+#ifndef CONFIG_USER_ONLY
+ check_hw_breakpoints(env, 1);
+ env->dr[6] |= DR6_BS;
+#endif
+ raise_exception(EXCP01_DB);
+}
+
+void helper_cpuid(void)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ helper_svm_check_intercept_param(SVM_EXIT_CPUID, 0);
+
+ cpu_x86_cpuid(env, (uint32_t)EAX, (uint32_t)ECX, &eax, &ebx, &ecx, &edx);
+ EAX = eax;
+ EBX = ebx;
+ ECX = ecx;
+ EDX = edx;
+}
+
+void helper_enter_level(int level, int data32, target_ulong t1)
+{
+ target_ulong ssp;
+ uint32_t esp_mask, esp, ebp;
+
+ esp_mask = get_sp_mask(env->segs[R_SS].flags);
+ ssp = env->segs[R_SS].base;
+ ebp = EBP;
+ esp = ESP;
+ if (data32) {
+ /* 32 bit */
+ esp -= 4;
+ while (--level) {
+ esp -= 4;
+ ebp -= 4;
+ stl(ssp + (esp & esp_mask), ldl(ssp + (ebp & esp_mask)));
+ }
+ esp -= 4;
+ stl(ssp + (esp & esp_mask), t1);
+ } else {
+ /* 16 bit */
+ esp -= 2;
+ while (--level) {
+ esp -= 2;
+ ebp -= 2;
+ stw(ssp + (esp & esp_mask), lduw(ssp + (ebp & esp_mask)));
+ }
+ esp -= 2;
+ stw(ssp + (esp & esp_mask), t1);
+ }
+}
+
+#ifdef TARGET_X86_64
+void helper_enter64_level(int level, int data64, target_ulong t1)
+{
+ target_ulong esp, ebp;
+ ebp = EBP;
+ esp = ESP;
+
+ if (data64) {
+ /* 64 bit */
+ esp -= 8;
+ while (--level) {
+ esp -= 8;
+ ebp -= 8;
+ stq(esp, ldq(ebp));
+ }
+ esp -= 8;
+ stq(esp, t1);
+ } else {
+ /* 16 bit */
+ esp -= 2;
+ while (--level) {
+ esp -= 2;
+ ebp -= 2;
+ stw(esp, lduw(ebp));
+ }
+ esp -= 2;
+ stw(esp, t1);
+ }
+}
+#endif
+
+void helper_lldt(int selector)
+{
+ SegmentCache *dt;
+ uint32_t e1, e2;
+ int index, entry_limit;
+ target_ulong ptr;
+
+ selector &= 0xffff;
+ if ((selector & 0xfffc) == 0) {
+ /* XXX: NULL selector case: invalid LDT */
+ env->ldt.base = 0;
+ env->ldt.limit = 0;
+ } else {
+ if (selector & 0x4)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ dt = &env->gdt;
+ index = selector & ~7;
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK)
+ entry_limit = 15;
+ else
+#endif
+ entry_limit = 7;
+ if ((index + entry_limit) > dt->limit)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ ptr = dt->base + index;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+ if ((e2 & DESC_S_MASK) || ((e2 >> DESC_TYPE_SHIFT) & 0xf) != 2)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK) {
+ uint32_t e3;
+ e3 = ldl_kernel(ptr + 8);
+ load_seg_cache_raw_dt(&env->ldt, e1, e2);
+ env->ldt.base |= (target_ulong)e3 << 32;
+ } else
+#endif
+ {
+ load_seg_cache_raw_dt(&env->ldt, e1, e2);
+ }
+ }
+ env->ldt.selector = selector;
+}
+
+void helper_ltr(int selector)
+{
+ SegmentCache *dt;
+ uint32_t e1, e2;
+ int index, type, entry_limit;
+ target_ulong ptr;
+
+ selector &= 0xffff;
+ if ((selector & 0xfffc) == 0) {
+ /* NULL selector case: invalid TR */
+ env->tr.base = 0;
+ env->tr.limit = 0;
+ env->tr.flags = 0;
+ } else {
+ if (selector & 0x4)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ dt = &env->gdt;
+ index = selector & ~7;
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK)
+ entry_limit = 15;
+ else
+#endif
+ entry_limit = 7;
+ if ((index + entry_limit) > dt->limit)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ ptr = dt->base + index;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ if ((e2 & DESC_S_MASK) ||
+ (type != 1 && type != 9))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK) {
+ uint32_t e3, e4;
+ e3 = ldl_kernel(ptr + 8);
+ e4 = ldl_kernel(ptr + 12);
+ if ((e4 >> DESC_TYPE_SHIFT) & 0xf)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ load_seg_cache_raw_dt(&env->tr, e1, e2);
+ env->tr.base |= (target_ulong)e3 << 32;
+ } else
+#endif
+ {
+ load_seg_cache_raw_dt(&env->tr, e1, e2);
+ }
+ e2 |= DESC_TSS_BUSY_MASK;
+ stl_kernel(ptr + 4, e2);
+ }
+ env->tr.selector = selector;
+}
+
+/* only works if protected mode and not VM86. seg_reg must be != R_CS */
+void helper_load_seg(int seg_reg, int selector)
+{
+ uint32_t e1, e2;
+ int cpl, dpl, rpl;
+ SegmentCache *dt;
+ int index;
+ target_ulong ptr;
+
+ selector &= 0xffff;
+ cpl = env->hflags & HF_CPL_MASK;
+ if ((selector & 0xfffc) == 0) {
+ /* null selector case */
+ if (seg_reg == R_SS
+#ifdef TARGET_X86_64
+ && (!(env->hflags & HF_CS64_MASK) || cpl == 3)
+#endif
+ )
+ raise_exception_err(EXCP0D_GPF, 0);
+ cpu_x86_load_seg_cache(env, seg_reg, selector, 0, 0, 0);
+ } else {
+
+ if (selector & 0x4)
+ dt = &env->ldt;
+ else
+ dt = &env->gdt;
+ index = selector & ~7;
+ if ((index + 7) > dt->limit)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ ptr = dt->base + index;
+ e1 = ldl_kernel(ptr);
+ e2 = ldl_kernel(ptr + 4);
+
+ if (!(e2 & DESC_S_MASK))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (seg_reg == R_SS) {
+ /* must be writable segment */
+ if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (rpl != cpl || dpl != cpl)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ } else {
+ /* must be readable segment */
+ if ((e2 & (DESC_CS_MASK | DESC_R_MASK)) == DESC_CS_MASK)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+
+ if (!(e2 & DESC_CS_MASK) || !(e2 & DESC_C_MASK)) {
+ /* if not conforming code, test rights */
+ if (dpl < cpl || dpl < rpl)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ }
+ }
+
+ if (!(e2 & DESC_P_MASK)) {
+ if (seg_reg == R_SS)
+ raise_exception_err(EXCP0C_STACK, selector & 0xfffc);
+ else
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+ }
+
+ /* set the access bit if not already set */
+ if (!(e2 & DESC_A_MASK)) {
+ e2 |= DESC_A_MASK;
+ stl_kernel(ptr + 4, e2);
+ }
+
+ cpu_x86_load_seg_cache(env, seg_reg, selector,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+#if 0
+ qemu_log("load_seg: sel=0x%04x base=0x%08lx limit=0x%08lx flags=%08x\n",
+ selector, (unsigned long)sc->base, sc->limit, sc->flags);
+#endif
+ }
+}
+
+/* protected mode jump */
+void helper_ljmp_protected(int new_cs, target_ulong new_eip,
+ int next_eip_addend)
+{
+ int gate_cs, type;
+ uint32_t e1, e2, cpl, dpl, rpl, limit;
+ target_ulong next_eip;
+
+ if ((new_cs & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, 0);
+ if (load_segment(&e1, &e2, new_cs) != 0)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ cpl = env->hflags & HF_CPL_MASK;
+ if (e2 & DESC_S_MASK) {
+ if (!(e2 & DESC_CS_MASK))
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (e2 & DESC_C_MASK) {
+ /* conforming code segment */
+ if (dpl > cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ } else {
+ /* non conforming code segment */
+ rpl = new_cs & 3;
+ if (rpl > cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ if (dpl != cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ }
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_cs & 0xfffc);
+ limit = get_seg_limit(e1, e2);
+ if (new_eip > limit &&
+ !(env->hflags & HF_LMA_MASK) && !(e2 & DESC_L_MASK))
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
+ get_seg_base(e1, e2), limit, e2);
+ EIP = new_eip;
+ } else {
+ /* jump to call or task gate */
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ rpl = new_cs & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ switch(type) {
+ case 1: /* 286 TSS */
+ case 9: /* 386 TSS */
+ case 5: /* task gate */
+ if (dpl < cpl || dpl < rpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ next_eip = env->eip + next_eip_addend;
+ switch_tss(new_cs, e1, e2, SWITCH_TSS_JMP, next_eip);
+ CC_OP = CC_OP_EFLAGS;
+ break;
+ case 4: /* 286 call gate */
+ case 12: /* 386 call gate */
+ if ((dpl < cpl) || (dpl < rpl))
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_cs & 0xfffc);
+ gate_cs = e1 >> 16;
+ new_eip = (e1 & 0xffff);
+ if (type == 12)
+ new_eip |= (e2 & 0xffff0000);
+ if (load_segment(&e1, &e2, gate_cs) != 0)
+ raise_exception_err(EXCP0D_GPF, gate_cs & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ /* must be code segment */
+ if (((e2 & (DESC_S_MASK | DESC_CS_MASK)) !=
+ (DESC_S_MASK | DESC_CS_MASK)))
+ raise_exception_err(EXCP0D_GPF, gate_cs & 0xfffc);
+ if (((e2 & DESC_C_MASK) && (dpl > cpl)) ||
+ (!(e2 & DESC_C_MASK) && (dpl != cpl)))
+ raise_exception_err(EXCP0D_GPF, gate_cs & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0D_GPF, gate_cs & 0xfffc);
+ limit = get_seg_limit(e1, e2);
+ if (new_eip > limit)
+ raise_exception_err(EXCP0D_GPF, 0);
+ cpu_x86_load_seg_cache(env, R_CS, (gate_cs & 0xfffc) | cpl,
+ get_seg_base(e1, e2), limit, e2);
+ EIP = new_eip;
+ break;
+ default:
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ break;
+ }
+ }
+}
+
+/* real mode call */
+void helper_lcall_real(int new_cs, target_ulong new_eip1,
+ int shift, int next_eip)
+{
+ int new_eip;
+ uint32_t esp, esp_mask;
+ target_ulong ssp;
+
+ new_eip = new_eip1;
+ esp = ESP;
+ esp_mask = get_sp_mask(env->segs[R_SS].flags);
+ ssp = env->segs[R_SS].base;
+ if (shift) {
+ PUSHL(ssp, esp, esp_mask, env->segs[R_CS].selector);
+ PUSHL(ssp, esp, esp_mask, next_eip);
+ } else {
+ PUSHW(ssp, esp, esp_mask, env->segs[R_CS].selector);
+ PUSHW(ssp, esp, esp_mask, next_eip);
+ }
+
+ SET_ESP(esp, esp_mask);
+ env->eip = new_eip;
+ env->segs[R_CS].selector = new_cs;
+ env->segs[R_CS].base = (new_cs << 4);
+}
+
+/* protected mode call */
+void helper_lcall_protected(int new_cs, target_ulong new_eip,
+ int shift, int next_eip_addend)
+{
+ int new_stack, i;
+ uint32_t e1, e2, cpl, dpl, rpl, selector, offset, param_count;
+ uint32_t ss = 0, ss_e1 = 0, ss_e2 = 0, sp, type, ss_dpl, sp_mask;
+ uint32_t val, limit, old_sp_mask;
+ target_ulong ssp, old_ssp, next_eip;
+
+ next_eip = env->eip + next_eip_addend;
+ LOG_PCALL("lcall %04x:%08x s=%d\n", new_cs, (uint32_t)new_eip, shift);
+ LOG_PCALL_STATE(env);
+ if ((new_cs & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, 0);
+ if (load_segment(&e1, &e2, new_cs) != 0)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ cpl = env->hflags & HF_CPL_MASK;
+ LOG_PCALL("desc=%08x:%08x\n", e1, e2);
+ if (e2 & DESC_S_MASK) {
+ if (!(e2 & DESC_CS_MASK))
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (e2 & DESC_C_MASK) {
+ /* conforming code segment */
+ if (dpl > cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ } else {
+ /* non conforming code segment */
+ rpl = new_cs & 3;
+ if (rpl > cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ if (dpl != cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ }
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_cs & 0xfffc);
+
+#ifdef TARGET_X86_64
+ /* XXX: check 16/32 bit cases in long mode */
+ if (shift == 2) {
+ target_ulong rsp;
+ /* 64 bit case */
+ rsp = ESP;
+ PUSHQ(rsp, env->segs[R_CS].selector);
+ PUSHQ(rsp, next_eip);
+ /* from this point, not restartable */
+ ESP = rsp;
+ cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2), e2);
+ EIP = new_eip;
+ } else
+#endif
+ {
+ sp = ESP;
+ sp_mask = get_sp_mask(env->segs[R_SS].flags);
+ ssp = env->segs[R_SS].base;
+ if (shift) {
+ PUSHL(ssp, sp, sp_mask, env->segs[R_CS].selector);
+ PUSHL(ssp, sp, sp_mask, next_eip);
+ } else {
+ PUSHW(ssp, sp, sp_mask, env->segs[R_CS].selector);
+ PUSHW(ssp, sp, sp_mask, next_eip);
+ }
+
+ limit = get_seg_limit(e1, e2);
+ if (new_eip > limit)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ /* from this point, not restartable */
+ SET_ESP(sp, sp_mask);
+ cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
+ get_seg_base(e1, e2), limit, e2);
+ EIP = new_eip;
+ }
+ } else {
+ /* check gate type */
+ type = (e2 >> DESC_TYPE_SHIFT) & 0x1f;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ rpl = new_cs & 3;
+ switch(type) {
+ case 1: /* available 286 TSS */
+ case 9: /* available 386 TSS */
+ case 5: /* task gate */
+ if (dpl < cpl || dpl < rpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ switch_tss(new_cs, e1, e2, SWITCH_TSS_CALL, next_eip);
+ CC_OP = CC_OP_EFLAGS;
+ return;
+ case 4: /* 286 call gate */
+ case 12: /* 386 call gate */
+ break;
+ default:
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ break;
+ }
+ shift = type >> 3;
+
+ if (dpl < cpl || dpl < rpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ /* check valid bit */
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_cs & 0xfffc);
+ selector = e1 >> 16;
+ offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff);
+ param_count = e2 & 0x1f;
+ if ((selector & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, 0);
+
+ if (load_segment(&e1, &e2, selector) != 0)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK)))
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (dpl > cpl)
+ raise_exception_err(EXCP0D_GPF, selector & 0xfffc);
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, selector & 0xfffc);
+
+ if (!(e2 & DESC_C_MASK) && dpl < cpl) {
+ /* to inner privilege */
+ get_ss_esp_from_tss(&ss, &sp, dpl);
+ LOG_PCALL("new ss:esp=%04x:%08x param_count=%d ESP=" TARGET_FMT_lx "\n",
+ ss, sp, param_count, ESP);
+ if ((ss & 0xfffc) == 0)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if ((ss & 3) != dpl)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (load_segment(&ss_e1, &ss_e2, ss) != 0)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3;
+ if (ss_dpl != dpl)
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (!(ss_e2 & DESC_S_MASK) ||
+ (ss_e2 & DESC_CS_MASK) ||
+ !(ss_e2 & DESC_W_MASK))
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+ if (!(ss_e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0A_TSS, ss & 0xfffc);
+
+ // push_size = ((param_count * 2) + 8) << shift;
+
+ old_sp_mask = get_sp_mask(env->segs[R_SS].flags);
+ old_ssp = env->segs[R_SS].base;
+
+ sp_mask = get_sp_mask(ss_e2);
+ ssp = get_seg_base(ss_e1, ss_e2);
+ if (shift) {
+ PUSHL(ssp, sp, sp_mask, env->segs[R_SS].selector);
+ PUSHL(ssp, sp, sp_mask, ESP);
+ for(i = param_count - 1; i >= 0; i--) {
+ val = ldl_kernel(old_ssp + ((ESP + i * 4) & old_sp_mask));
+ PUSHL(ssp, sp, sp_mask, val);
+ }
+ } else {
+ PUSHW(ssp, sp, sp_mask, env->segs[R_SS].selector);
+ PUSHW(ssp, sp, sp_mask, ESP);
+ for(i = param_count - 1; i >= 0; i--) {
+ val = lduw_kernel(old_ssp + ((ESP + i * 2) & old_sp_mask));
+ PUSHW(ssp, sp, sp_mask, val);
+ }
+ }
+ new_stack = 1;
+ } else {
+ /* to same privilege */
+ sp = ESP;
+ sp_mask = get_sp_mask(env->segs[R_SS].flags);
+ ssp = env->segs[R_SS].base;
+ // push_size = (4 << shift);
+ new_stack = 0;
+ }
+
+ if (shift) {
+ PUSHL(ssp, sp, sp_mask, env->segs[R_CS].selector);
+ PUSHL(ssp, sp, sp_mask, next_eip);
+ } else {
+ PUSHW(ssp, sp, sp_mask, env->segs[R_CS].selector);
+ PUSHW(ssp, sp, sp_mask, next_eip);
+ }
+
+ /* from this point, not restartable */
+
+ if (new_stack) {
+ ss = (ss & ~3) | dpl;
+ cpu_x86_load_seg_cache(env, R_SS, ss,
+ ssp,
+ get_seg_limit(ss_e1, ss_e2),
+ ss_e2);
+ }
+
+ selector = (selector & ~3) | dpl;
+ cpu_x86_load_seg_cache(env, R_CS, selector,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ cpu_x86_set_cpl(env, dpl);
+ SET_ESP(sp, sp_mask);
+ EIP = offset;
+ }
+}
+
+/* real and vm86 mode iret */
+void helper_iret_real(int shift)
+{
+ uint32_t sp, new_cs, new_eip, new_eflags, sp_mask;
+ target_ulong ssp;
+ int eflags_mask;
+
+ sp_mask = 0xffff; /* XXXX: use SS segment size ? */
+ sp = ESP;
+ ssp = env->segs[R_SS].base;
+ if (shift == 1) {
+ /* 32 bits */
+ POPL(ssp, sp, sp_mask, new_eip);
+ POPL(ssp, sp, sp_mask, new_cs);
+ new_cs &= 0xffff;
+ POPL(ssp, sp, sp_mask, new_eflags);
+ } else {
+ /* 16 bits */
+ POPW(ssp, sp, sp_mask, new_eip);
+ POPW(ssp, sp, sp_mask, new_cs);
+ POPW(ssp, sp, sp_mask, new_eflags);
+ }
+ ESP = (ESP & ~sp_mask) | (sp & sp_mask);
+ env->segs[R_CS].selector = new_cs;
+ env->segs[R_CS].base = (new_cs << 4);
+ env->eip = new_eip;
+ if (env->eflags & VM_MASK)
+ eflags_mask = TF_MASK | AC_MASK | ID_MASK | IF_MASK | RF_MASK | NT_MASK;
+ else
+ eflags_mask = TF_MASK | AC_MASK | ID_MASK | IF_MASK | IOPL_MASK | RF_MASK | NT_MASK;
+ if (shift == 0)
+ eflags_mask &= 0xffff;
+ load_eflags(new_eflags, eflags_mask);
+ env->hflags2 &= ~HF2_NMI_MASK;
+}
+
+static inline void validate_seg(int seg_reg, int cpl)
+{
+ int dpl;
+ uint32_t e2;
+
+ /* XXX: on x86_64, we do not want to nullify FS and GS because
+ they may still contain a valid base. I would be interested to
+ know how a real x86_64 CPU behaves */
+ if ((seg_reg == R_FS || seg_reg == R_GS) &&
+ (env->segs[seg_reg].selector & 0xfffc) == 0)
+ return;
+
+ e2 = env->segs[seg_reg].flags;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (!(e2 & DESC_CS_MASK) || !(e2 & DESC_C_MASK)) {
+ /* data or non conforming code segment */
+ if (dpl < cpl) {
+ cpu_x86_load_seg_cache(env, seg_reg, 0, 0, 0, 0);
+ }
+ }
+}
+
+/* protected mode iret */
+static inline void helper_ret_protected(int shift, int is_iret, int addend)
+{
+ uint32_t new_cs, new_eflags, new_ss;
+ uint32_t new_es, new_ds, new_fs, new_gs;
+ uint32_t e1, e2, ss_e1, ss_e2;
+ int cpl, dpl, rpl, eflags_mask, iopl;
+ target_ulong ssp, sp, new_eip, new_esp, sp_mask;
+
+#ifdef TARGET_X86_64
+ if (shift == 2)
+ sp_mask = -1;
+ else
+#endif
+ sp_mask = get_sp_mask(env->segs[R_SS].flags);
+ sp = ESP;
+ ssp = env->segs[R_SS].base;
+ new_eflags = 0; /* avoid warning */
+#ifdef TARGET_X86_64
+ if (shift == 2) {
+ POPQ(sp, new_eip);
+ POPQ(sp, new_cs);
+ new_cs &= 0xffff;
+ if (is_iret) {
+ POPQ(sp, new_eflags);
+ }
+ } else
+#endif
+ if (shift == 1) {
+ /* 32 bits */
+ POPL(ssp, sp, sp_mask, new_eip);
+ POPL(ssp, sp, sp_mask, new_cs);
+ new_cs &= 0xffff;
+ if (is_iret) {
+ POPL(ssp, sp, sp_mask, new_eflags);
+ if (new_eflags & VM_MASK)
+ goto return_to_vm86;
+ }
+ } else {
+ /* 16 bits */
+ POPW(ssp, sp, sp_mask, new_eip);
+ POPW(ssp, sp, sp_mask, new_cs);
+ if (is_iret)
+ POPW(ssp, sp, sp_mask, new_eflags);
+ }
+ LOG_PCALL("lret new %04x:" TARGET_FMT_lx " s=%d addend=0x%x\n",
+ new_cs, new_eip, shift, addend);
+ LOG_PCALL_STATE(env);
+ if ((new_cs & 0xfffc) == 0)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ if (load_segment(&e1, &e2, new_cs) != 0)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ if (!(e2 & DESC_S_MASK) ||
+ !(e2 & DESC_CS_MASK))
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ cpl = env->hflags & HF_CPL_MASK;
+ rpl = new_cs & 3;
+ if (rpl < cpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ if (e2 & DESC_C_MASK) {
+ if (dpl > rpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ } else {
+ if (dpl != rpl)
+ raise_exception_err(EXCP0D_GPF, new_cs & 0xfffc);
+ }
+ if (!(e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_cs & 0xfffc);
+
+ sp += addend;
+ if (rpl == cpl && (!(env->hflags & HF_CS64_MASK) ||
+ ((env->hflags & HF_CS64_MASK) && !is_iret))) {
+ /* return to same privilege level */
+ cpu_x86_load_seg_cache(env, R_CS, new_cs,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ } else {
+ /* return to different privilege level */
+#ifdef TARGET_X86_64
+ if (shift == 2) {
+ POPQ(sp, new_esp);
+ POPQ(sp, new_ss);
+ new_ss &= 0xffff;
+ } else
+#endif
+ if (shift == 1) {
+ /* 32 bits */
+ POPL(ssp, sp, sp_mask, new_esp);
+ POPL(ssp, sp, sp_mask, new_ss);
+ new_ss &= 0xffff;
+ } else {
+ /* 16 bits */
+ POPW(ssp, sp, sp_mask, new_esp);
+ POPW(ssp, sp, sp_mask, new_ss);
+ }
+ LOG_PCALL("new ss:esp=%04x:" TARGET_FMT_lx "\n",
+ new_ss, new_esp);
+ if ((new_ss & 0xfffc) == 0) {
+#ifdef TARGET_X86_64
+ /* NULL ss is allowed in long mode if cpl != 3*/
+ /* XXX: test CS64 ? */
+ if ((env->hflags & HF_LMA_MASK) && rpl != 3) {
+ cpu_x86_load_seg_cache(env, R_SS, new_ss,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (rpl << DESC_DPL_SHIFT) |
+ DESC_W_MASK | DESC_A_MASK);
+ ss_e2 = DESC_B_MASK; /* XXX: should not be needed ? */
+ } else
+#endif
+ {
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+ } else {
+ if ((new_ss & 3) != rpl)
+ raise_exception_err(EXCP0D_GPF, new_ss & 0xfffc);
+ if (load_segment(&ss_e1, &ss_e2, new_ss) != 0)
+ raise_exception_err(EXCP0D_GPF, new_ss & 0xfffc);
+ if (!(ss_e2 & DESC_S_MASK) ||
+ (ss_e2 & DESC_CS_MASK) ||
+ !(ss_e2 & DESC_W_MASK))
+ raise_exception_err(EXCP0D_GPF, new_ss & 0xfffc);
+ dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3;
+ if (dpl != rpl)
+ raise_exception_err(EXCP0D_GPF, new_ss & 0xfffc);
+ if (!(ss_e2 & DESC_P_MASK))
+ raise_exception_err(EXCP0B_NOSEG, new_ss & 0xfffc);
+ cpu_x86_load_seg_cache(env, R_SS, new_ss,
+ get_seg_base(ss_e1, ss_e2),
+ get_seg_limit(ss_e1, ss_e2),
+ ss_e2);
+ }
+
+ cpu_x86_load_seg_cache(env, R_CS, new_cs,
+ get_seg_base(e1, e2),
+ get_seg_limit(e1, e2),
+ e2);
+ cpu_x86_set_cpl(env, rpl);
+ sp = new_esp;
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_CS64_MASK)
+ sp_mask = -1;
+ else
+#endif
+ sp_mask = get_sp_mask(ss_e2);
+
+ /* validate data segments */
+ validate_seg(R_ES, rpl);
+ validate_seg(R_DS, rpl);
+ validate_seg(R_FS, rpl);
+ validate_seg(R_GS, rpl);
+
+ sp += addend;
+ }
+ SET_ESP(sp, sp_mask);
+ env->eip = new_eip;
+ if (is_iret) {
+ /* NOTE: 'cpl' is the _old_ CPL */
+ eflags_mask = TF_MASK | AC_MASK | ID_MASK | RF_MASK | NT_MASK;
+ if (cpl == 0)
+ eflags_mask |= IOPL_MASK;
+ iopl = (env->eflags >> IOPL_SHIFT) & 3;
+ if (cpl <= iopl)
+ eflags_mask |= IF_MASK;
+ if (shift == 0)
+ eflags_mask &= 0xffff;
+ load_eflags(new_eflags, eflags_mask);
+ }
+ return;
+
+ return_to_vm86:
+ POPL(ssp, sp, sp_mask, new_esp);
+ POPL(ssp, sp, sp_mask, new_ss);
+ POPL(ssp, sp, sp_mask, new_es);
+ POPL(ssp, sp, sp_mask, new_ds);
+ POPL(ssp, sp, sp_mask, new_fs);
+ POPL(ssp, sp, sp_mask, new_gs);
+
+ /* modify processor state */
+ load_eflags(new_eflags, TF_MASK | AC_MASK | ID_MASK |
+ IF_MASK | IOPL_MASK | VM_MASK | NT_MASK | VIF_MASK | VIP_MASK);
+ load_seg_vm(R_CS, new_cs & 0xffff);
+ cpu_x86_set_cpl(env, 3);
+ load_seg_vm(R_SS, new_ss & 0xffff);
+ load_seg_vm(R_ES, new_es & 0xffff);
+ load_seg_vm(R_DS, new_ds & 0xffff);
+ load_seg_vm(R_FS, new_fs & 0xffff);
+ load_seg_vm(R_GS, new_gs & 0xffff);
+
+ env->eip = new_eip & 0xffff;
+ ESP = new_esp;
+}
+
+void helper_iret_protected(int shift, int next_eip)
+{
+ int tss_selector, type;
+ uint32_t e1, e2;
+
+ /* specific case for TSS */
+ if (env->eflags & NT_MASK) {
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK)
+ raise_exception_err(EXCP0D_GPF, 0);
+#endif
+ tss_selector = lduw_kernel(env->tr.base + 0);
+ if (tss_selector & 4)
+ raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc);
+ if (load_segment(&e1, &e2, tss_selector) != 0)
+ raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc);
+ type = (e2 >> DESC_TYPE_SHIFT) & 0x17;
+ /* NOTE: we check both segment and busy TSS */
+ if (type != 3)
+ raise_exception_err(EXCP0A_TSS, tss_selector & 0xfffc);
+ switch_tss(tss_selector, e1, e2, SWITCH_TSS_IRET, next_eip);
+ } else {
+ helper_ret_protected(shift, 1, 0);
+ }
+ env->hflags2 &= ~HF2_NMI_MASK;
+}
+
+void helper_lret_protected(int shift, int addend)
+{
+ helper_ret_protected(shift, 0, addend);
+}
+
+void helper_sysenter(void)
+{
+ if (env->sysenter_cs == 0) {
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+ env->eflags &= ~(VM_MASK | IF_MASK | RF_MASK);
+ cpu_x86_set_cpl(env, 0);
+
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK) {
+ cpu_x86_load_seg_cache(env, R_CS, env->sysenter_cs & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | DESC_L_MASK);
+ } else
+#endif
+ {
+ cpu_x86_load_seg_cache(env, R_CS, env->sysenter_cs & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
+ }
+ cpu_x86_load_seg_cache(env, R_SS, (env->sysenter_cs + 8) & 0xfffc,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK |
+ DESC_W_MASK | DESC_A_MASK);
+ ESP = env->sysenter_esp;
+ EIP = env->sysenter_eip;
+}
+
+void helper_sysexit(int dflag)
+{
+ int cpl;
+
+ cpl = env->hflags & HF_CPL_MASK;
+ if (env->sysenter_cs == 0 || cpl != 0) {
+ raise_exception_err(EXCP0D_GPF, 0);
+ }
+ cpu_x86_set_cpl(env, 3);
+#ifdef TARGET_X86_64
+ if (dflag == 2) {
+ cpu_x86_load_seg_cache(env, R_CS, ((env->sysenter_cs + 32) & 0xfffc) | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | DESC_L_MASK);
+ cpu_x86_load_seg_cache(env, R_SS, ((env->sysenter_cs + 40) & 0xfffc) | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_W_MASK | DESC_A_MASK);
+ } else
+#endif
+ {
+ cpu_x86_load_seg_cache(env, R_CS, ((env->sysenter_cs + 16) & 0xfffc) | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK);
+ cpu_x86_load_seg_cache(env, R_SS, ((env->sysenter_cs + 24) & 0xfffc) | 3,
+ 0, 0xffffffff,
+ DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
+ DESC_S_MASK | (3 << DESC_DPL_SHIFT) |
+ DESC_W_MASK | DESC_A_MASK);
+ }
+ ESP = ECX;
+ EIP = EDX;
+}
+
+#if defined(CONFIG_USER_ONLY)
+target_ulong helper_read_crN(int reg)
+{
+ return 0;
+}
+
+void helper_write_crN(int reg, target_ulong t0)
+{
+}
+
+void helper_movl_drN_T0(int reg, target_ulong t0)
+{
+}
+#else
+target_ulong helper_read_crN(int reg)
+{
+ target_ulong val;
+
+ helper_svm_check_intercept_param(SVM_EXIT_READ_CR0 + reg, 0);
+ switch(reg) {
+ default:
+ val = env->cr[reg];
+ break;
+ case 8:
+ if (!(env->hflags2 & HF2_VINTR_MASK)) {
+ val = cpu_get_apic_tpr(env->apic_state);
+ } else {
+ val = env->v_tpr;
+ }
+ break;
+ }
+ return val;
+}
+
+void helper_write_crN(int reg, target_ulong t0)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_WRITE_CR0 + reg, 0);
+ switch(reg) {
+ case 0:
+ cpu_x86_update_cr0(env, t0);
+ break;
+ case 3:
+ cpu_x86_update_cr3(env, t0);
+ break;
+ case 4:
+ cpu_x86_update_cr4(env, t0);
+ break;
+ case 8:
+ if (!(env->hflags2 & HF2_VINTR_MASK)) {
+ cpu_set_apic_tpr(env->apic_state, t0);
+ }
+ env->v_tpr = t0 & 0x0f;
+ break;
+ default:
+ env->cr[reg] = t0;
+ break;
+ }
+}
+
+void helper_movl_drN_T0(int reg, target_ulong t0)
+{
+ int i;
+
+ if (reg < 4) {
+ hw_breakpoint_remove(env, reg);
+ env->dr[reg] = t0;
+ hw_breakpoint_insert(env, reg);
+ } else if (reg == 7) {
+ for (i = 0; i < 4; i++)
+ hw_breakpoint_remove(env, i);
+ env->dr[7] = t0;
+ for (i = 0; i < 4; i++)
+ hw_breakpoint_insert(env, i);
+ } else
+ env->dr[reg] = t0;
+}
+#endif
+
+void helper_lmsw(target_ulong t0)
+{
+ /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
+ if already set to one. */
+ t0 = (env->cr[0] & ~0xe) | (t0 & 0xf);
+ helper_write_crN(0, t0);
+}
+
+void helper_clts(void)
+{
+ env->cr[0] &= ~CR0_TS_MASK;
+ env->hflags &= ~HF_TS_MASK;
+}
+
+void helper_invlpg(target_ulong addr)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_INVLPG, 0);
+ tlb_flush_page(env, addr);
+}
+
+void helper_rdtsc(void)
+{
+ uint64_t val;
+
+ if ((env->cr[4] & CR4_TSD_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
+ raise_exception(EXCP0D_GPF);
+ }
+ helper_svm_check_intercept_param(SVM_EXIT_RDTSC, 0);
+
+ val = cpu_get_tsc(env) + env->tsc_offset;
+ EAX = (uint32_t)(val);
+ EDX = (uint32_t)(val >> 32);
+}
+
+void helper_rdtscp(void)
+{
+ helper_rdtsc();
+ ECX = (uint32_t)(env->tsc_aux);
+}
+
+void helper_rdpmc(void)
+{
+ if ((env->cr[4] & CR4_PCE_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
+ raise_exception(EXCP0D_GPF);
+ }
+ helper_svm_check_intercept_param(SVM_EXIT_RDPMC, 0);
+
+ /* currently unimplemented */
+ raise_exception_err(EXCP06_ILLOP, 0);
+}
+
+#if defined(CONFIG_USER_ONLY)
+void helper_wrmsr(void)
+{
+}
+
+void helper_rdmsr(void)
+{
+}
+#else
+void helper_wrmsr(void)
+{
+ uint64_t val;
+
+ helper_svm_check_intercept_param(SVM_EXIT_MSR, 1);
+
+ val = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32);
+
+ switch((uint32_t)ECX) {
+ case MSR_IA32_SYSENTER_CS:
+ env->sysenter_cs = val & 0xffff;
+ break;
+ case MSR_IA32_SYSENTER_ESP:
+ env->sysenter_esp = val;
+ break;
+ case MSR_IA32_SYSENTER_EIP:
+ env->sysenter_eip = val;
+ break;
+ case MSR_IA32_APICBASE:
+ cpu_set_apic_base(env->apic_state, val);
+ break;
+ case MSR_EFER:
+ {
+ uint64_t update_mask;
+ update_mask = 0;
+ if (env->cpuid_ext2_features & CPUID_EXT2_SYSCALL)
+ update_mask |= MSR_EFER_SCE;
+ if (env->cpuid_ext2_features & CPUID_EXT2_LM)
+ update_mask |= MSR_EFER_LME;
+ if (env->cpuid_ext2_features & CPUID_EXT2_FFXSR)
+ update_mask |= MSR_EFER_FFXSR;
+ if (env->cpuid_ext2_features & CPUID_EXT2_NX)
+ update_mask |= MSR_EFER_NXE;
+ if (env->cpuid_ext3_features & CPUID_EXT3_SVM)
+ update_mask |= MSR_EFER_SVME;
+ if (env->cpuid_ext2_features & CPUID_EXT2_FFXSR)
+ update_mask |= MSR_EFER_FFXSR;
+ cpu_load_efer(env, (env->efer & ~update_mask) |
+ (val & update_mask));
+ }
+ break;
+ case MSR_STAR:
+ env->star = val;
+ break;
+ case MSR_PAT:
+ env->pat = val;
+ break;
+ case MSR_VM_HSAVE_PA:
+ env->vm_hsave = val;
+ break;
+#ifdef TARGET_X86_64
+ case MSR_LSTAR:
+ env->lstar = val;
+ break;
+ case MSR_CSTAR:
+ env->cstar = val;
+ break;
+ case MSR_FMASK:
+ env->fmask = val;
+ break;
+ case MSR_FSBASE:
+ env->segs[R_FS].base = val;
+ break;
+ case MSR_GSBASE:
+ env->segs[R_GS].base = val;
+ break;
+ case MSR_KERNELGSBASE:
+ env->kernelgsbase = val;
+ break;
+#endif
+ case MSR_MTRRphysBase(0):
+ case MSR_MTRRphysBase(1):
+ case MSR_MTRRphysBase(2):
+ case MSR_MTRRphysBase(3):
+ case MSR_MTRRphysBase(4):
+ case MSR_MTRRphysBase(5):
+ case MSR_MTRRphysBase(6):
+ case MSR_MTRRphysBase(7):
+ env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base = val;
+ break;
+ case MSR_MTRRphysMask(0):
+ case MSR_MTRRphysMask(1):
+ case MSR_MTRRphysMask(2):
+ case MSR_MTRRphysMask(3):
+ case MSR_MTRRphysMask(4):
+ case MSR_MTRRphysMask(5):
+ case MSR_MTRRphysMask(6):
+ case MSR_MTRRphysMask(7):
+ env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask = val;
+ break;
+ case MSR_MTRRfix64K_00000:
+ env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix64K_00000] = val;
+ break;
+ case MSR_MTRRfix16K_80000:
+ case MSR_MTRRfix16K_A0000:
+ env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1] = val;
+ break;
+ case MSR_MTRRfix4K_C0000:
+ case MSR_MTRRfix4K_C8000:
+ case MSR_MTRRfix4K_D0000:
+ case MSR_MTRRfix4K_D8000:
+ case MSR_MTRRfix4K_E0000:
+ case MSR_MTRRfix4K_E8000:
+ case MSR_MTRRfix4K_F0000:
+ case MSR_MTRRfix4K_F8000:
+ env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3] = val;
+ break;
+ case MSR_MTRRdefType:
+ env->mtrr_deftype = val;
+ break;
+ case MSR_MCG_STATUS:
+ env->mcg_status = val;
+ break;
+ case MSR_MCG_CTL:
+ if ((env->mcg_cap & MCG_CTL_P)
+ && (val == 0 || val == ~(uint64_t)0))
+ env->mcg_ctl = val;
+ break;
+ case MSR_TSC_AUX:
+ env->tsc_aux = val;
+ break;
+ case MSR_IA32_MISC_ENABLE:
+ env->msr_ia32_misc_enable = val;
+ break;
+ default:
+ if ((uint32_t)ECX >= MSR_MC0_CTL
+ && (uint32_t)ECX < MSR_MC0_CTL + (4 * env->mcg_cap & 0xff)) {
+ uint32_t offset = (uint32_t)ECX - MSR_MC0_CTL;
+ if ((offset & 0x3) != 0
+ || (val == 0 || val == ~(uint64_t)0))
+ env->mce_banks[offset] = val;
+ break;
+ }
+ /* XXX: exception ? */
+ break;
+ }
+}
+
+void helper_rdmsr(void)
+{
+ uint64_t val;
+
+ helper_svm_check_intercept_param(SVM_EXIT_MSR, 0);
+
+ switch((uint32_t)ECX) {
+ case MSR_IA32_SYSENTER_CS:
+ val = env->sysenter_cs;
+ break;
+ case MSR_IA32_SYSENTER_ESP:
+ val = env->sysenter_esp;
+ break;
+ case MSR_IA32_SYSENTER_EIP:
+ val = env->sysenter_eip;
+ break;
+ case MSR_IA32_APICBASE:
+ val = cpu_get_apic_base(env->apic_state);
+ break;
+ case MSR_EFER:
+ val = env->efer;
+ break;
+ case MSR_STAR:
+ val = env->star;
+ break;
+ case MSR_PAT:
+ val = env->pat;
+ break;
+ case MSR_VM_HSAVE_PA:
+ val = env->vm_hsave;
+ break;
+ case MSR_IA32_PERF_STATUS:
+ /* tsc_increment_by_tick */
+ val = 1000ULL;
+ /* CPU multiplier */
+ val |= (((uint64_t)4ULL) << 40);
+ break;
+#ifdef TARGET_X86_64
+ case MSR_LSTAR:
+ val = env->lstar;
+ break;
+ case MSR_CSTAR:
+ val = env->cstar;
+ break;
+ case MSR_FMASK:
+ val = env->fmask;
+ break;
+ case MSR_FSBASE:
+ val = env->segs[R_FS].base;
+ break;
+ case MSR_GSBASE:
+ val = env->segs[R_GS].base;
+ break;
+ case MSR_KERNELGSBASE:
+ val = env->kernelgsbase;
+ break;
+ case MSR_TSC_AUX:
+ val = env->tsc_aux;
+ break;
+#endif
+ case MSR_MTRRphysBase(0):
+ case MSR_MTRRphysBase(1):
+ case MSR_MTRRphysBase(2):
+ case MSR_MTRRphysBase(3):
+ case MSR_MTRRphysBase(4):
+ case MSR_MTRRphysBase(5):
+ case MSR_MTRRphysBase(6):
+ case MSR_MTRRphysBase(7):
+ val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysBase(0)) / 2].base;
+ break;
+ case MSR_MTRRphysMask(0):
+ case MSR_MTRRphysMask(1):
+ case MSR_MTRRphysMask(2):
+ case MSR_MTRRphysMask(3):
+ case MSR_MTRRphysMask(4):
+ case MSR_MTRRphysMask(5):
+ case MSR_MTRRphysMask(6):
+ case MSR_MTRRphysMask(7):
+ val = env->mtrr_var[((uint32_t)ECX - MSR_MTRRphysMask(0)) / 2].mask;
+ break;
+ case MSR_MTRRfix64K_00000:
+ val = env->mtrr_fixed[0];
+ break;
+ case MSR_MTRRfix16K_80000:
+ case MSR_MTRRfix16K_A0000:
+ val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix16K_80000 + 1];
+ break;
+ case MSR_MTRRfix4K_C0000:
+ case MSR_MTRRfix4K_C8000:
+ case MSR_MTRRfix4K_D0000:
+ case MSR_MTRRfix4K_D8000:
+ case MSR_MTRRfix4K_E0000:
+ case MSR_MTRRfix4K_E8000:
+ case MSR_MTRRfix4K_F0000:
+ case MSR_MTRRfix4K_F8000:
+ val = env->mtrr_fixed[(uint32_t)ECX - MSR_MTRRfix4K_C0000 + 3];
+ break;
+ case MSR_MTRRdefType:
+ val = env->mtrr_deftype;
+ break;
+ case MSR_MTRRcap:
+ if (env->cpuid_features & CPUID_MTRR)
+ val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT | MSR_MTRRcap_WC_SUPPORTED;
+ else
+ /* XXX: exception ? */
+ val = 0;
+ break;
+ case MSR_MCG_CAP:
+ val = env->mcg_cap;
+ break;
+ case MSR_MCG_CTL:
+ if (env->mcg_cap & MCG_CTL_P)
+ val = env->mcg_ctl;
+ else
+ val = 0;
+ break;
+ case MSR_MCG_STATUS:
+ val = env->mcg_status;
+ break;
+ case MSR_IA32_MISC_ENABLE:
+ val = env->msr_ia32_misc_enable;
+ break;
+ default:
+ if ((uint32_t)ECX >= MSR_MC0_CTL
+ && (uint32_t)ECX < MSR_MC0_CTL + (4 * env->mcg_cap & 0xff)) {
+ uint32_t offset = (uint32_t)ECX - MSR_MC0_CTL;
+ val = env->mce_banks[offset];
+ break;
+ }
+ /* XXX: exception ? */
+ val = 0;
+ break;
+ }
+ EAX = (uint32_t)(val);
+ EDX = (uint32_t)(val >> 32);
+}
+#endif
+
+target_ulong helper_lsl(target_ulong selector1)
+{
+ unsigned int limit;
+ uint32_t e1, e2, eflags, selector;
+ int rpl, dpl, cpl, type;
+
+ selector = selector1 & 0xffff;
+ eflags = helper_cc_compute_all(CC_OP);
+ if ((selector & 0xfffc) == 0)
+ goto fail;
+ if (load_segment(&e1, &e2, selector) != 0)
+ goto fail;
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ if (e2 & DESC_S_MASK) {
+ if ((e2 & DESC_CS_MASK) && (e2 & DESC_C_MASK)) {
+ /* conforming */
+ } else {
+ if (dpl < cpl || dpl < rpl)
+ goto fail;
+ }
+ } else {
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ switch(type) {
+ case 1:
+ case 2:
+ case 3:
+ case 9:
+ case 11:
+ break;
+ default:
+ goto fail;
+ }
+ if (dpl < cpl || dpl < rpl) {
+ fail:
+ CC_SRC = eflags & ~CC_Z;
+ return 0;
+ }
+ }
+ limit = get_seg_limit(e1, e2);
+ CC_SRC = eflags | CC_Z;
+ return limit;
+}
+
+target_ulong helper_lar(target_ulong selector1)
+{
+ uint32_t e1, e2, eflags, selector;
+ int rpl, dpl, cpl, type;
+
+ selector = selector1 & 0xffff;
+ eflags = helper_cc_compute_all(CC_OP);
+ if ((selector & 0xfffc) == 0)
+ goto fail;
+ if (load_segment(&e1, &e2, selector) != 0)
+ goto fail;
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ if (e2 & DESC_S_MASK) {
+ if ((e2 & DESC_CS_MASK) && (e2 & DESC_C_MASK)) {
+ /* conforming */
+ } else {
+ if (dpl < cpl || dpl < rpl)
+ goto fail;
+ }
+ } else {
+ type = (e2 >> DESC_TYPE_SHIFT) & 0xf;
+ switch(type) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 9:
+ case 11:
+ case 12:
+ break;
+ default:
+ goto fail;
+ }
+ if (dpl < cpl || dpl < rpl) {
+ fail:
+ CC_SRC = eflags & ~CC_Z;
+ return 0;
+ }
+ }
+ CC_SRC = eflags | CC_Z;
+ return e2 & 0x00f0ff00;
+}
+
+void helper_verr(target_ulong selector1)
+{
+ uint32_t e1, e2, eflags, selector;
+ int rpl, dpl, cpl;
+
+ selector = selector1 & 0xffff;
+ eflags = helper_cc_compute_all(CC_OP);
+ if ((selector & 0xfffc) == 0)
+ goto fail;
+ if (load_segment(&e1, &e2, selector) != 0)
+ goto fail;
+ if (!(e2 & DESC_S_MASK))
+ goto fail;
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ if (e2 & DESC_CS_MASK) {
+ if (!(e2 & DESC_R_MASK))
+ goto fail;
+ if (!(e2 & DESC_C_MASK)) {
+ if (dpl < cpl || dpl < rpl)
+ goto fail;
+ }
+ } else {
+ if (dpl < cpl || dpl < rpl) {
+ fail:
+ CC_SRC = eflags & ~CC_Z;
+ return;
+ }
+ }
+ CC_SRC = eflags | CC_Z;
+}
+
+void helper_verw(target_ulong selector1)
+{
+ uint32_t e1, e2, eflags, selector;
+ int rpl, dpl, cpl;
+
+ selector = selector1 & 0xffff;
+ eflags = helper_cc_compute_all(CC_OP);
+ if ((selector & 0xfffc) == 0)
+ goto fail;
+ if (load_segment(&e1, &e2, selector) != 0)
+ goto fail;
+ if (!(e2 & DESC_S_MASK))
+ goto fail;
+ rpl = selector & 3;
+ dpl = (e2 >> DESC_DPL_SHIFT) & 3;
+ cpl = env->hflags & HF_CPL_MASK;
+ if (e2 & DESC_CS_MASK) {
+ goto fail;
+ } else {
+ if (dpl < cpl || dpl < rpl)
+ goto fail;
+ if (!(e2 & DESC_W_MASK)) {
+ fail:
+ CC_SRC = eflags & ~CC_Z;
+ return;
+ }
+ }
+ CC_SRC = eflags | CC_Z;
+}
+
+/* x87 FPU helpers */
+
+static inline double floatx80_to_double(floatx80 a)
+{
+ union {
+ float64 f64;
+ double d;
+ } u;
+
+ u.f64 = floatx80_to_float64(a, &env->fp_status);
+ return u.d;
+}
+
+static inline floatx80 double_to_floatx80(double a)
+{
+ union {
+ float64 f64;
+ double d;
+ } u;
+
+ u.d = a;
+ return float64_to_floatx80(u.f64, &env->fp_status);
+}
+
+static void fpu_set_exception(int mask)
+{
+ env->fpus |= mask;
+ if (env->fpus & (~env->fpuc & FPUC_EM))
+ env->fpus |= FPUS_SE | FPUS_B;
+}
+
+static inline floatx80 helper_fdiv(floatx80 a, floatx80 b)
+{
+ if (floatx80_is_zero(b)) {
+ fpu_set_exception(FPUS_ZE);
+ }
+ return floatx80_div(a, b, &env->fp_status);
+}
+
+static void fpu_raise_exception(void)
+{
+ if (env->cr[0] & CR0_NE_MASK) {
+ raise_exception(EXCP10_COPR);
+ }
+#if !defined(CONFIG_USER_ONLY)
+ else {
+ cpu_set_ferr(env);
+ }
+#endif
+}
+
+void helper_flds_FT0(uint32_t val)
+{
+ union {
+ float32 f;
+ uint32_t i;
+ } u;
+ u.i = val;
+ FT0 = float32_to_floatx80(u.f, &env->fp_status);
+}
+
+void helper_fldl_FT0(uint64_t val)
+{
+ union {
+ float64 f;
+ uint64_t i;
+ } u;
+ u.i = val;
+ FT0 = float64_to_floatx80(u.f, &env->fp_status);
+}
+
+void helper_fildl_FT0(int32_t val)
+{
+ FT0 = int32_to_floatx80(val, &env->fp_status);
+}
+
+void helper_flds_ST0(uint32_t val)
+{
+ int new_fpstt;
+ union {
+ float32 f;
+ uint32_t i;
+ } u;
+ new_fpstt = (env->fpstt - 1) & 7;
+ u.i = val;
+ env->fpregs[new_fpstt].d = float32_to_floatx80(u.f, &env->fp_status);
+ env->fpstt = new_fpstt;
+ env->fptags[new_fpstt] = 0; /* validate stack entry */
+}
+
+void helper_fldl_ST0(uint64_t val)
+{
+ int new_fpstt;
+ union {
+ float64 f;
+ uint64_t i;
+ } u;
+ new_fpstt = (env->fpstt - 1) & 7;
+ u.i = val;
+ env->fpregs[new_fpstt].d = float64_to_floatx80(u.f, &env->fp_status);
+ env->fpstt = new_fpstt;
+ env->fptags[new_fpstt] = 0; /* validate stack entry */
+}
+
+void helper_fildl_ST0(int32_t val)
+{
+ int new_fpstt;
+ new_fpstt = (env->fpstt - 1) & 7;
+ env->fpregs[new_fpstt].d = int32_to_floatx80(val, &env->fp_status);
+ env->fpstt = new_fpstt;
+ env->fptags[new_fpstt] = 0; /* validate stack entry */
+}
+
+void helper_fildll_ST0(int64_t val)
+{
+ int new_fpstt;
+ new_fpstt = (env->fpstt - 1) & 7;
+ env->fpregs[new_fpstt].d = int64_to_floatx80(val, &env->fp_status);
+ env->fpstt = new_fpstt;
+ env->fptags[new_fpstt] = 0; /* validate stack entry */
+}
+
+uint32_t helper_fsts_ST0(void)
+{
+ union {
+ float32 f;
+ uint32_t i;
+ } u;
+ u.f = floatx80_to_float32(ST0, &env->fp_status);
+ return u.i;
+}
+
+uint64_t helper_fstl_ST0(void)
+{
+ union {
+ float64 f;
+ uint64_t i;
+ } u;
+ u.f = floatx80_to_float64(ST0, &env->fp_status);
+ return u.i;
+}
+
+int32_t helper_fist_ST0(void)
+{
+ int32_t val;
+ val = floatx80_to_int32(ST0, &env->fp_status);
+ if (val != (int16_t)val)
+ val = -32768;
+ return val;
+}
+
+int32_t helper_fistl_ST0(void)
+{
+ int32_t val;
+ val = floatx80_to_int32(ST0, &env->fp_status);
+ return val;
+}
+
+int64_t helper_fistll_ST0(void)
+{
+ int64_t val;
+ val = floatx80_to_int64(ST0, &env->fp_status);
+ return val;
+}
+
+int32_t helper_fistt_ST0(void)
+{
+ int32_t val;
+ val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status);
+ if (val != (int16_t)val)
+ val = -32768;
+ return val;
+}
+
+int32_t helper_fisttl_ST0(void)
+{
+ int32_t val;
+ val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status);
+ return val;
+}
+
+int64_t helper_fisttll_ST0(void)
+{
+ int64_t val;
+ val = floatx80_to_int64_round_to_zero(ST0, &env->fp_status);
+ return val;
+}
+
+void helper_fldt_ST0(target_ulong ptr)
+{
+ int new_fpstt;
+ new_fpstt = (env->fpstt - 1) & 7;
+ env->fpregs[new_fpstt].d = helper_fldt(ptr);
+ env->fpstt = new_fpstt;
+ env->fptags[new_fpstt] = 0; /* validate stack entry */
+}
+
+void helper_fstt_ST0(target_ulong ptr)
+{
+ helper_fstt(ST0, ptr);
+}
+
+void helper_fpush(void)
+{
+ fpush();
+}
+
+void helper_fpop(void)
+{
+ fpop();
+}
+
+void helper_fdecstp(void)
+{
+ env->fpstt = (env->fpstt - 1) & 7;
+ env->fpus &= (~0x4700);
+}
+
+void helper_fincstp(void)
+{
+ env->fpstt = (env->fpstt + 1) & 7;
+ env->fpus &= (~0x4700);
+}
+
+/* FPU move */
+
+void helper_ffree_STN(int st_index)
+{
+ env->fptags[(env->fpstt + st_index) & 7] = 1;
+}
+
+void helper_fmov_ST0_FT0(void)
+{
+ ST0 = FT0;
+}
+
+void helper_fmov_FT0_STN(int st_index)
+{
+ FT0 = ST(st_index);
+}
+
+void helper_fmov_ST0_STN(int st_index)
+{
+ ST0 = ST(st_index);
+}
+
+void helper_fmov_STN_ST0(int st_index)
+{
+ ST(st_index) = ST0;
+}
+
+void helper_fxchg_ST0_STN(int st_index)
+{
+ floatx80 tmp;
+ tmp = ST(st_index);
+ ST(st_index) = ST0;
+ ST0 = tmp;
+}
+
+/* FPU operations */
+
+static const int fcom_ccval[4] = {0x0100, 0x4000, 0x0000, 0x4500};
+
+void helper_fcom_ST0_FT0(void)
+{
+ int ret;
+
+ ret = floatx80_compare(ST0, FT0, &env->fp_status);
+ env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret + 1];
+}
+
+void helper_fucom_ST0_FT0(void)
+{
+ int ret;
+
+ ret = floatx80_compare_quiet(ST0, FT0, &env->fp_status);
+ env->fpus = (env->fpus & ~0x4500) | fcom_ccval[ret+ 1];
+}
+
+static const int fcomi_ccval[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
+
+void helper_fcomi_ST0_FT0(void)
+{
+ int eflags;
+ int ret;
+
+ ret = floatx80_compare(ST0, FT0, &env->fp_status);
+ eflags = helper_cc_compute_all(CC_OP);
+ eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
+ CC_SRC = eflags;
+}
+
+void helper_fucomi_ST0_FT0(void)
+{
+ int eflags;
+ int ret;
+
+ ret = floatx80_compare_quiet(ST0, FT0, &env->fp_status);
+ eflags = helper_cc_compute_all(CC_OP);
+ eflags = (eflags & ~(CC_Z | CC_P | CC_C)) | fcomi_ccval[ret + 1];
+ CC_SRC = eflags;
+}
+
+void helper_fadd_ST0_FT0(void)
+{
+ ST0 = floatx80_add(ST0, FT0, &env->fp_status);
+}
+
+void helper_fmul_ST0_FT0(void)
+{
+ ST0 = floatx80_mul(ST0, FT0, &env->fp_status);
+}
+
+void helper_fsub_ST0_FT0(void)
+{
+ ST0 = floatx80_sub(ST0, FT0, &env->fp_status);
+}
+
+void helper_fsubr_ST0_FT0(void)
+{
+ ST0 = floatx80_sub(FT0, ST0, &env->fp_status);
+}
+
+void helper_fdiv_ST0_FT0(void)
+{
+ ST0 = helper_fdiv(ST0, FT0);
+}
+
+void helper_fdivr_ST0_FT0(void)
+{
+ ST0 = helper_fdiv(FT0, ST0);
+}
+
+/* fp operations between STN and ST0 */
+
+void helper_fadd_STN_ST0(int st_index)
+{
+ ST(st_index) = floatx80_add(ST(st_index), ST0, &env->fp_status);
+}
+
+void helper_fmul_STN_ST0(int st_index)
+{
+ ST(st_index) = floatx80_mul(ST(st_index), ST0, &env->fp_status);
+}
+
+void helper_fsub_STN_ST0(int st_index)
+{
+ ST(st_index) = floatx80_sub(ST(st_index), ST0, &env->fp_status);
+}
+
+void helper_fsubr_STN_ST0(int st_index)
+{
+ ST(st_index) = floatx80_sub(ST0, ST(st_index), &env->fp_status);
+}
+
+void helper_fdiv_STN_ST0(int st_index)
+{
+ floatx80 *p;
+ p = &ST(st_index);
+ *p = helper_fdiv(*p, ST0);
+}
+
+void helper_fdivr_STN_ST0(int st_index)
+{
+ floatx80 *p;
+ p = &ST(st_index);
+ *p = helper_fdiv(ST0, *p);
+}
+
+/* misc FPU operations */
+void helper_fchs_ST0(void)
+{
+ ST0 = floatx80_chs(ST0);
+}
+
+void helper_fabs_ST0(void)
+{
+ ST0 = floatx80_abs(ST0);
+}
+
+void helper_fld1_ST0(void)
+{
+ ST0 = floatx80_one;
+}
+
+void helper_fldl2t_ST0(void)
+{
+ ST0 = floatx80_l2t;
+}
+
+void helper_fldl2e_ST0(void)
+{
+ ST0 = floatx80_l2e;
+}
+
+void helper_fldpi_ST0(void)
+{
+ ST0 = floatx80_pi;
+}
+
+void helper_fldlg2_ST0(void)
+{
+ ST0 = floatx80_lg2;
+}
+
+void helper_fldln2_ST0(void)
+{
+ ST0 = floatx80_ln2;
+}
+
+void helper_fldz_ST0(void)
+{
+ ST0 = floatx80_zero;
+}
+
+void helper_fldz_FT0(void)
+{
+ FT0 = floatx80_zero;
+}
+
+uint32_t helper_fnstsw(void)
+{
+ return (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
+}
+
+uint32_t helper_fnstcw(void)
+{
+ return env->fpuc;
+}
+
+static void update_fp_status(void)
+{
+ int rnd_type;
+
+ /* set rounding mode */
+ switch(env->fpuc & RC_MASK) {
+ default:
+ case RC_NEAR:
+ rnd_type = float_round_nearest_even;
+ break;
+ case RC_DOWN:
+ rnd_type = float_round_down;
+ break;
+ case RC_UP:
+ rnd_type = float_round_up;
+ break;
+ case RC_CHOP:
+ rnd_type = float_round_to_zero;
+ break;
+ }
+ set_float_rounding_mode(rnd_type, &env->fp_status);
+ switch((env->fpuc >> 8) & 3) {
+ case 0:
+ rnd_type = 32;
+ break;
+ case 2:
+ rnd_type = 64;
+ break;
+ case 3:
+ default:
+ rnd_type = 80;
+ break;
+ }
+ set_floatx80_rounding_precision(rnd_type, &env->fp_status);
+}
+
+void helper_fldcw(uint32_t val)
+{
+ env->fpuc = val;
+ update_fp_status();
+}
+
+void helper_fclex(void)
+{
+ env->fpus &= 0x7f00;
+}
+
+void helper_fwait(void)
+{
+ if (env->fpus & FPUS_SE)
+ fpu_raise_exception();
+}
+
+void helper_fninit(void)
+{
+ env->fpus = 0;
+ env->fpstt = 0;
+ env->fpuc = 0x37f;
+ env->fptags[0] = 1;
+ env->fptags[1] = 1;
+ env->fptags[2] = 1;
+ env->fptags[3] = 1;
+ env->fptags[4] = 1;
+ env->fptags[5] = 1;
+ env->fptags[6] = 1;
+ env->fptags[7] = 1;
+}
+
+/* BCD ops */
+
+void helper_fbld_ST0(target_ulong ptr)
+{
+ floatx80 tmp;
+ uint64_t val;
+ unsigned int v;
+ int i;
+
+ val = 0;
+ for(i = 8; i >= 0; i--) {
+ v = ldub(ptr + i);
+ val = (val * 100) + ((v >> 4) * 10) + (v & 0xf);
+ }
+ tmp = int64_to_floatx80(val, &env->fp_status);
+ if (ldub(ptr + 9) & 0x80) {
+ floatx80_chs(tmp);
+ }
+ fpush();
+ ST0 = tmp;
+}
+
+void helper_fbst_ST0(target_ulong ptr)
+{
+ int v;
+ target_ulong mem_ref, mem_end;
+ int64_t val;
+
+ val = floatx80_to_int64(ST0, &env->fp_status);
+ mem_ref = ptr;
+ mem_end = mem_ref + 9;
+ if (val < 0) {
+ stb(mem_end, 0x80);
+ val = -val;
+ } else {
+ stb(mem_end, 0x00);
+ }
+ while (mem_ref < mem_end) {
+ if (val == 0)
+ break;
+ v = val % 100;
+ val = val / 100;
+ v = ((v / 10) << 4) | (v % 10);
+ stb(mem_ref++, v);
+ }
+ while (mem_ref < mem_end) {
+ stb(mem_ref++, 0);
+ }
+}
+
+void helper_f2xm1(void)
+{
+ double val = floatx80_to_double(ST0);
+ val = pow(2.0, val) - 1.0;
+ ST0 = double_to_floatx80(val);
+}
+
+void helper_fyl2x(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if (fptemp>0.0){
+ fptemp = log(fptemp)/log(2.0); /* log2(ST) */
+ fptemp *= floatx80_to_double(ST1);
+ ST1 = double_to_floatx80(fptemp);
+ fpop();
+ } else {
+ env->fpus &= (~0x4700);
+ env->fpus |= 0x400;
+ }
+}
+
+void helper_fptan(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
+ env->fpus |= 0x400;
+ } else {
+ fptemp = tan(fptemp);
+ ST0 = double_to_floatx80(fptemp);
+ fpush();
+ ST0 = floatx80_one;
+ env->fpus &= (~0x400); /* C2 <-- 0 */
+ /* the above code is for |arg| < 2**52 only */
+ }
+}
+
+void helper_fpatan(void)
+{
+ double fptemp, fpsrcop;
+
+ fpsrcop = floatx80_to_double(ST1);
+ fptemp = floatx80_to_double(ST0);
+ ST1 = double_to_floatx80(atan2(fpsrcop, fptemp));
+ fpop();
+}
+
+void helper_fxtract(void)
+{
+ CPU_LDoubleU temp;
+
+ temp.d = ST0;
+
+ if (floatx80_is_zero(ST0)) {
+ /* Easy way to generate -inf and raising division by 0 exception */
+ ST0 = floatx80_div(floatx80_chs(floatx80_one), floatx80_zero, &env->fp_status);
+ fpush();
+ ST0 = temp.d;
+ } else {
+ int expdif;
+
+ expdif = EXPD(temp) - EXPBIAS;
+ /*DP exponent bias*/
+ ST0 = int32_to_floatx80(expdif, &env->fp_status);
+ fpush();
+ BIASEXPONENT(temp);
+ ST0 = temp.d;
+ }
+}
+
+void helper_fprem1(void)
+{
+ double st0, st1, dblq, fpsrcop, fptemp;
+ CPU_LDoubleU fpsrcop1, fptemp1;
+ int expdif;
+ signed long long int q;
+
+ st0 = floatx80_to_double(ST0);
+ st1 = floatx80_to_double(ST1);
+
+ if (isinf(st0) || isnan(st0) || isnan(st1) || (st1 == 0.0)) {
+ ST0 = double_to_floatx80(0.0 / 0.0); /* NaN */
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ return;
+ }
+
+ fpsrcop = st0;
+ fptemp = st1;
+ fpsrcop1.d = ST0;
+ fptemp1.d = ST1;
+ expdif = EXPD(fpsrcop1) - EXPD(fptemp1);
+
+ if (expdif < 0) {
+ /* optimisation? taken from the AMD docs */
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ /* ST0 is unchanged */
+ return;
+ }
+
+ if (expdif < 53) {
+ dblq = fpsrcop / fptemp;
+ /* round dblq towards nearest integer */
+ dblq = rint(dblq);
+ st0 = fpsrcop - fptemp * dblq;
+
+ /* convert dblq to q by truncating towards zero */
+ if (dblq < 0.0)
+ q = (signed long long int)(-dblq);
+ else
+ q = (signed long long int)dblq;
+
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ /* (C0,C3,C1) <-- (q2,q1,q0) */
+ env->fpus |= (q & 0x4) << (8 - 2); /* (C0) <-- q2 */
+ env->fpus |= (q & 0x2) << (14 - 1); /* (C3) <-- q1 */
+ env->fpus |= (q & 0x1) << (9 - 0); /* (C1) <-- q0 */
+ } else {
+ env->fpus |= 0x400; /* C2 <-- 1 */
+ fptemp = pow(2.0, expdif - 50);
+ fpsrcop = (st0 / st1) / fptemp;
+ /* fpsrcop = integer obtained by chopping */
+ fpsrcop = (fpsrcop < 0.0) ?
+ -(floor(fabs(fpsrcop))) : floor(fpsrcop);
+ st0 -= (st1 * fpsrcop * fptemp);
+ }
+ ST0 = double_to_floatx80(st0);
+}
+
+void helper_fprem(void)
+{
+ double st0, st1, dblq, fpsrcop, fptemp;
+ CPU_LDoubleU fpsrcop1, fptemp1;
+ int expdif;
+ signed long long int q;
+
+ st0 = floatx80_to_double(ST0);
+ st1 = floatx80_to_double(ST1);
+
+ if (isinf(st0) || isnan(st0) || isnan(st1) || (st1 == 0.0)) {
+ ST0 = double_to_floatx80(0.0 / 0.0); /* NaN */
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ return;
+ }
+
+ fpsrcop = st0;
+ fptemp = st1;
+ fpsrcop1.d = ST0;
+ fptemp1.d = ST1;
+ expdif = EXPD(fpsrcop1) - EXPD(fptemp1);
+
+ if (expdif < 0) {
+ /* optimisation? taken from the AMD docs */
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ /* ST0 is unchanged */
+ return;
+ }
+
+ if ( expdif < 53 ) {
+ dblq = fpsrcop/*ST0*/ / fptemp/*ST1*/;
+ /* round dblq towards zero */
+ dblq = (dblq < 0.0) ? ceil(dblq) : floor(dblq);
+ st0 = fpsrcop/*ST0*/ - fptemp * dblq;
+
+ /* convert dblq to q by truncating towards zero */
+ if (dblq < 0.0)
+ q = (signed long long int)(-dblq);
+ else
+ q = (signed long long int)dblq;
+
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ /* (C0,C3,C1) <-- (q2,q1,q0) */
+ env->fpus |= (q & 0x4) << (8 - 2); /* (C0) <-- q2 */
+ env->fpus |= (q & 0x2) << (14 - 1); /* (C3) <-- q1 */
+ env->fpus |= (q & 0x1) << (9 - 0); /* (C1) <-- q0 */
+ } else {
+ int N = 32 + (expdif % 32); /* as per AMD docs */
+ env->fpus |= 0x400; /* C2 <-- 1 */
+ fptemp = pow(2.0, (double)(expdif - N));
+ fpsrcop = (st0 / st1) / fptemp;
+ /* fpsrcop = integer obtained by chopping */
+ fpsrcop = (fpsrcop < 0.0) ?
+ -(floor(fabs(fpsrcop))) : floor(fpsrcop);
+ st0 -= (st1 * fpsrcop * fptemp);
+ }
+ ST0 = double_to_floatx80(st0);
+}
+
+void helper_fyl2xp1(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if ((fptemp+1.0)>0.0) {
+ fptemp = log(fptemp+1.0) / log(2.0); /* log2(ST+1.0) */
+ fptemp *= floatx80_to_double(ST1);
+ ST1 = double_to_floatx80(fptemp);
+ fpop();
+ } else {
+ env->fpus &= (~0x4700);
+ env->fpus |= 0x400;
+ }
+}
+
+void helper_fsqrt(void)
+{
+ if (floatx80_is_neg(ST0)) {
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ env->fpus |= 0x400;
+ }
+ ST0 = floatx80_sqrt(ST0, &env->fp_status);
+}
+
+void helper_fsincos(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
+ env->fpus |= 0x400;
+ } else {
+ ST0 = double_to_floatx80(sin(fptemp));
+ fpush();
+ ST0 = double_to_floatx80(cos(fptemp));
+ env->fpus &= (~0x400); /* C2 <-- 0 */
+ /* the above code is for |arg| < 2**63 only */
+ }
+}
+
+void helper_frndint(void)
+{
+ ST0 = floatx80_round_to_int(ST0, &env->fp_status);
+}
+
+void helper_fscale(void)
+{
+ if (floatx80_is_any_nan(ST1)) {
+ ST0 = ST1;
+ } else {
+ int n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
+ ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
+ }
+}
+
+void helper_fsin(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if ((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
+ env->fpus |= 0x400;
+ } else {
+ ST0 = double_to_floatx80(sin(fptemp));
+ env->fpus &= (~0x400); /* C2 <-- 0 */
+ /* the above code is for |arg| < 2**53 only */
+ }
+}
+
+void helper_fcos(void)
+{
+ double fptemp = floatx80_to_double(ST0);
+
+ if((fptemp > MAXTAN)||(fptemp < -MAXTAN)) {
+ env->fpus |= 0x400;
+ } else {
+ ST0 = double_to_floatx80(cos(fptemp));
+ env->fpus &= (~0x400); /* C2 <-- 0 */
+ /* the above code is for |arg5 < 2**63 only */
+ }
+}
+
+void helper_fxam_ST0(void)
+{
+ CPU_LDoubleU temp;
+ int expdif;
+
+ temp.d = ST0;
+
+ env->fpus &= (~0x4700); /* (C3,C2,C1,C0) <-- 0000 */
+ if (SIGND(temp))
+ env->fpus |= 0x200; /* C1 <-- 1 */
+
+ /* XXX: test fptags too */
+ expdif = EXPD(temp);
+ if (expdif == MAXEXPD) {
+ if (MANTD(temp) == 0x8000000000000000ULL)
+ env->fpus |= 0x500 /*Infinity*/;
+ else
+ env->fpus |= 0x100 /*NaN*/;
+ } else if (expdif == 0) {
+ if (MANTD(temp) == 0)
+ env->fpus |= 0x4000 /*Zero*/;
+ else
+ env->fpus |= 0x4400 /*Denormal*/;
+ } else {
+ env->fpus |= 0x400;
+ }
+}
+
+void helper_fstenv(target_ulong ptr, int data32)
+{
+ int fpus, fptag, exp, i;
+ uint64_t mant;
+ CPU_LDoubleU tmp;
+
+ fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
+ fptag = 0;
+ for (i=7; i>=0; i--) {
+ fptag <<= 2;
+ if (env->fptags[i]) {
+ fptag |= 3;
+ } else {
+ tmp.d = env->fpregs[i].d;
+ exp = EXPD(tmp);
+ mant = MANTD(tmp);
+ if (exp == 0 && mant == 0) {
+ /* zero */
+ fptag |= 1;
+ } else if (exp == 0 || exp == MAXEXPD
+ || (mant & (1LL << 63)) == 0
+ ) {
+ /* NaNs, infinity, denormal */
+ fptag |= 2;
+ }
+ }
+ }
+ if (data32) {
+ /* 32 bit */
+ stl(ptr, env->fpuc);
+ stl(ptr + 4, fpus);
+ stl(ptr + 8, fptag);
+ stl(ptr + 12, 0); /* fpip */
+ stl(ptr + 16, 0); /* fpcs */
+ stl(ptr + 20, 0); /* fpoo */
+ stl(ptr + 24, 0); /* fpos */
+ } else {
+ /* 16 bit */
+ stw(ptr, env->fpuc);
+ stw(ptr + 2, fpus);
+ stw(ptr + 4, fptag);
+ stw(ptr + 6, 0);
+ stw(ptr + 8, 0);
+ stw(ptr + 10, 0);
+ stw(ptr + 12, 0);
+ }
+}
+
+void helper_fldenv(target_ulong ptr, int data32)
+{
+ int i, fpus, fptag;
+
+ if (data32) {
+ env->fpuc = lduw(ptr);
+ fpus = lduw(ptr + 4);
+ fptag = lduw(ptr + 8);
+ }
+ else {
+ env->fpuc = lduw(ptr);
+ fpus = lduw(ptr + 2);
+ fptag = lduw(ptr + 4);
+ }
+ env->fpstt = (fpus >> 11) & 7;
+ env->fpus = fpus & ~0x3800;
+ for(i = 0;i < 8; i++) {
+ env->fptags[i] = ((fptag & 3) == 3);
+ fptag >>= 2;
+ }
+}
+
+void helper_fsave(target_ulong ptr, int data32)
+{
+ floatx80 tmp;
+ int i;
+
+ helper_fstenv(ptr, data32);
+
+ ptr += (14 << data32);
+ for(i = 0;i < 8; i++) {
+ tmp = ST(i);
+ helper_fstt(tmp, ptr);
+ ptr += 10;
+ }
+
+ /* fninit */
+ env->fpus = 0;
+ env->fpstt = 0;
+ env->fpuc = 0x37f;
+ env->fptags[0] = 1;
+ env->fptags[1] = 1;
+ env->fptags[2] = 1;
+ env->fptags[3] = 1;
+ env->fptags[4] = 1;
+ env->fptags[5] = 1;
+ env->fptags[6] = 1;
+ env->fptags[7] = 1;
+}
+
+void helper_frstor(target_ulong ptr, int data32)
+{
+ floatx80 tmp;
+ int i;
+
+ helper_fldenv(ptr, data32);
+ ptr += (14 << data32);
+
+ for(i = 0;i < 8; i++) {
+ tmp = helper_fldt(ptr);
+ ST(i) = tmp;
+ ptr += 10;
+ }
+}
+
+
+#if defined(CONFIG_USER_ONLY)
+void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector)
+{
+ CPUX86State *saved_env;
+
+ saved_env = env;
+ env = s;
+ if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) {
+ selector &= 0xffff;
+ cpu_x86_load_seg_cache(env, seg_reg, selector,
+ (selector << 4), 0xffff, 0);
+ } else {
+ helper_load_seg(seg_reg, selector);
+ }
+ env = saved_env;
+}
+
+void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32)
+{
+ CPUX86State *saved_env;
+
+ saved_env = env;
+ env = s;
+
+ helper_fsave(ptr, data32);
+
+ env = saved_env;
+}
+
+void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32)
+{
+ CPUX86State *saved_env;
+
+ saved_env = env;
+ env = s;
+
+ helper_frstor(ptr, data32);
+
+ env = saved_env;
+}
+#endif
+
+void helper_fxsave(target_ulong ptr, int data64)
+{
+ int fpus, fptag, i, nb_xmm_regs;
+ floatx80 tmp;
+ target_ulong addr;
+
+ /* The operand must be 16 byte aligned */
+ if (ptr & 0xf) {
+ raise_exception(EXCP0D_GPF);
+ }
+
+ fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
+ fptag = 0;
+ for(i = 0; i < 8; i++) {
+ fptag |= (env->fptags[i] << i);
+ }
+ stw(ptr, env->fpuc);
+ stw(ptr + 2, fpus);
+ stw(ptr + 4, fptag ^ 0xff);
+#ifdef TARGET_X86_64
+ if (data64) {
+ stq(ptr + 0x08, 0); /* rip */
+ stq(ptr + 0x10, 0); /* rdp */
+ } else
+#endif
+ {
+ stl(ptr + 0x08, 0); /* eip */
+ stl(ptr + 0x0c, 0); /* sel */
+ stl(ptr + 0x10, 0); /* dp */
+ stl(ptr + 0x14, 0); /* sel */
+ }
+
+ addr = ptr + 0x20;
+ for(i = 0;i < 8; i++) {
+ tmp = ST(i);
+ helper_fstt(tmp, addr);
+ addr += 16;
+ }
+
+ if (env->cr[4] & CR4_OSFXSR_MASK) {
+ /* XXX: finish it */
+ stl(ptr + 0x18, env->mxcsr); /* mxcsr */
+ stl(ptr + 0x1c, 0x0000ffff); /* mxcsr_mask */
+ if (env->hflags & HF_CS64_MASK)
+ nb_xmm_regs = 16;
+ else
+ nb_xmm_regs = 8;
+ addr = ptr + 0xa0;
+ /* Fast FXSAVE leaves out the XMM registers */
+ if (!(env->efer & MSR_EFER_FFXSR)
+ || (env->hflags & HF_CPL_MASK)
+ || !(env->hflags & HF_LMA_MASK)) {
+ for(i = 0; i < nb_xmm_regs; i++) {
+ stq(addr, env->xmm_regs[i].XMM_Q(0));
+ stq(addr + 8, env->xmm_regs[i].XMM_Q(1));
+ addr += 16;
+ }
+ }
+ }
+}
+
+void helper_fxrstor(target_ulong ptr, int data64)
+{
+ int i, fpus, fptag, nb_xmm_regs;
+ floatx80 tmp;
+ target_ulong addr;
+
+ /* The operand must be 16 byte aligned */
+ if (ptr & 0xf) {
+ raise_exception(EXCP0D_GPF);
+ }
+
+ env->fpuc = lduw(ptr);
+ fpus = lduw(ptr + 2);
+ fptag = lduw(ptr + 4);
+ env->fpstt = (fpus >> 11) & 7;
+ env->fpus = fpus & ~0x3800;
+ fptag ^= 0xff;
+ for(i = 0;i < 8; i++) {
+ env->fptags[i] = ((fptag >> i) & 1);
+ }
+
+ addr = ptr + 0x20;
+ for(i = 0;i < 8; i++) {
+ tmp = helper_fldt(addr);
+ ST(i) = tmp;
+ addr += 16;
+ }
+
+ if (env->cr[4] & CR4_OSFXSR_MASK) {
+ /* XXX: finish it */
+ env->mxcsr = ldl(ptr + 0x18);
+ //ldl(ptr + 0x1c);
+ if (env->hflags & HF_CS64_MASK)
+ nb_xmm_regs = 16;
+ else
+ nb_xmm_regs = 8;
+ addr = ptr + 0xa0;
+ /* Fast FXRESTORE leaves out the XMM registers */
+ if (!(env->efer & MSR_EFER_FFXSR)
+ || (env->hflags & HF_CPL_MASK)
+ || !(env->hflags & HF_LMA_MASK)) {
+ for(i = 0; i < nb_xmm_regs; i++) {
+ env->xmm_regs[i].XMM_Q(0) = ldq(addr);
+ env->xmm_regs[i].XMM_Q(1) = ldq(addr + 8);
+ addr += 16;
+ }
+ }
+ }
+}
+
+void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
+{
+ CPU_LDoubleU temp;
+
+ temp.d = f;
+ *pmant = temp.l.lower;
+ *pexp = temp.l.upper;
+}
+
+floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
+{
+ CPU_LDoubleU temp;
+
+ temp.l.upper = upper;
+ temp.l.lower = mant;
+ return temp.d;
+}
+
+#ifdef TARGET_X86_64
+
+//#define DEBUG_MULDIV
+
+static void add128(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
+{
+ *plow += a;
+ /* carry test */
+ if (*plow < a)
+ (*phigh)++;
+ *phigh += b;
+}
+
+static void neg128(uint64_t *plow, uint64_t *phigh)
+{
+ *plow = ~ *plow;
+ *phigh = ~ *phigh;
+ add128(plow, phigh, 1, 0);
+}
+
+/* return TRUE if overflow */
+static int div64(uint64_t *plow, uint64_t *phigh, uint64_t b)
+{
+ uint64_t q, r, a1, a0;
+ int i, qb, ab;
+
+ a0 = *plow;
+ a1 = *phigh;
+ if (a1 == 0) {
+ q = a0 / b;
+ r = a0 % b;
+ *plow = q;
+ *phigh = r;
+ } else {
+ if (a1 >= b)
+ return 1;
+ /* XXX: use a better algorithm */
+ for(i = 0; i < 64; i++) {
+ ab = a1 >> 63;
+ a1 = (a1 << 1) | (a0 >> 63);
+ if (ab || a1 >= b) {
+ a1 -= b;
+ qb = 1;
+ } else {
+ qb = 0;
+ }
+ a0 = (a0 << 1) | qb;
+ }
+#if defined(DEBUG_MULDIV)
+ printf("div: 0x%016" PRIx64 "%016" PRIx64 " / 0x%016" PRIx64 ": q=0x%016" PRIx64 " r=0x%016" PRIx64 "\n",
+ *phigh, *plow, b, a0, a1);
+#endif
+ *plow = a0;
+ *phigh = a1;
+ }
+ return 0;
+}
+
+/* return TRUE if overflow */
+static int idiv64(uint64_t *plow, uint64_t *phigh, int64_t b)
+{
+ int sa, sb;
+ sa = ((int64_t)*phigh < 0);
+ if (sa)
+ neg128(plow, phigh);
+ sb = (b < 0);
+ if (sb)
+ b = -b;
+ if (div64(plow, phigh, b) != 0)
+ return 1;
+ if (sa ^ sb) {
+ if (*plow > (1ULL << 63))
+ return 1;
+ *plow = - *plow;
+ } else {
+ if (*plow >= (1ULL << 63))
+ return 1;
+ }
+ if (sa)
+ *phigh = - *phigh;
+ return 0;
+}
+
+void helper_mulq_EAX_T0(target_ulong t0)
+{
+ uint64_t r0, r1;
+
+ mulu64(&r0, &r1, EAX, t0);
+ EAX = r0;
+ EDX = r1;
+ CC_DST = r0;
+ CC_SRC = r1;
+}
+
+void helper_imulq_EAX_T0(target_ulong t0)
+{
+ uint64_t r0, r1;
+
+ muls64(&r0, &r1, EAX, t0);
+ EAX = r0;
+ EDX = r1;
+ CC_DST = r0;
+ CC_SRC = ((int64_t)r1 != ((int64_t)r0 >> 63));
+}
+
+target_ulong helper_imulq_T0_T1(target_ulong t0, target_ulong t1)
+{
+ uint64_t r0, r1;
+
+ muls64(&r0, &r1, t0, t1);
+ CC_DST = r0;
+ CC_SRC = ((int64_t)r1 != ((int64_t)r0 >> 63));
+ return r0;
+}
+
+void helper_divq_EAX(target_ulong t0)
+{
+ uint64_t r0, r1;
+ if (t0 == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ r0 = EAX;
+ r1 = EDX;
+ if (div64(&r0, &r1, t0))
+ raise_exception(EXCP00_DIVZ);
+ EAX = r0;
+ EDX = r1;
+}
+
+void helper_idivq_EAX(target_ulong t0)
+{
+ uint64_t r0, r1;
+ if (t0 == 0) {
+ raise_exception(EXCP00_DIVZ);
+ }
+ r0 = EAX;
+ r1 = EDX;
+ if (idiv64(&r0, &r1, t0))
+ raise_exception(EXCP00_DIVZ);
+ EAX = r0;
+ EDX = r1;
+}
+#endif
+
+static void do_hlt(void)
+{
+ env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
+ env->halted = 1;
+ env->exception_index = EXCP_HLT;
+ cpu_loop_exit(env);
+}
+
+void helper_hlt(int next_eip_addend)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_HLT, 0);
+ EIP += next_eip_addend;
+
+ do_hlt();
+}
+
+void helper_monitor(target_ulong ptr)
+{
+ if ((uint32_t)ECX != 0)
+ raise_exception(EXCP0D_GPF);
+ /* XXX: store address ? */
+ helper_svm_check_intercept_param(SVM_EXIT_MONITOR, 0);
+}
+
+void helper_mwait(int next_eip_addend)
+{
+ if ((uint32_t)ECX != 0)
+ raise_exception(EXCP0D_GPF);
+ helper_svm_check_intercept_param(SVM_EXIT_MWAIT, 0);
+ EIP += next_eip_addend;
+
+ /* XXX: not complete but not completely erroneous */
+ if (env->cpu_index != 0 || env->next_cpu != NULL) {
+ /* more than one CPU: do not sleep because another CPU may
+ wake this one */
+ } else {
+ do_hlt();
+ }
+}
+
+void helper_debug(void)
+{
+ env->exception_index = EXCP_DEBUG;
+ cpu_loop_exit(env);
+}
+
+void helper_reset_rf(void)
+{
+ env->eflags &= ~RF_MASK;
+}
+
+void helper_raise_interrupt(int intno, int next_eip_addend)
+{
+ raise_interrupt(intno, 1, 0, next_eip_addend);
+}
+
+void helper_raise_exception(int exception_index)
+{
+ raise_exception(exception_index);
+}
+
+void helper_cli(void)
+{
+ env->eflags &= ~IF_MASK;
+}
+
+void helper_sti(void)
+{
+ env->eflags |= IF_MASK;
+}
+
+#if 0
+/* vm86plus instructions */
+void helper_cli_vm(void)
+{
+ env->eflags &= ~VIF_MASK;
+}
+
+void helper_sti_vm(void)
+{
+ env->eflags |= VIF_MASK;
+ if (env->eflags & VIP_MASK) {
+ raise_exception(EXCP0D_GPF);
+ }
+}
+#endif
+
+void helper_set_inhibit_irq(void)
+{
+ env->hflags |= HF_INHIBIT_IRQ_MASK;
+}
+
+void helper_reset_inhibit_irq(void)
+{
+ env->hflags &= ~HF_INHIBIT_IRQ_MASK;
+}
+
+void helper_boundw(target_ulong a0, int v)
+{
+ int low, high;
+ low = ldsw(a0);
+ high = ldsw(a0 + 2);
+ v = (int16_t)v;
+ if (v < low || v > high) {
+ raise_exception(EXCP05_BOUND);
+ }
+}
+
+void helper_boundl(target_ulong a0, int v)
+{
+ int low, high;
+ low = ldl(a0);
+ high = ldl(a0 + 4);
+ if (v < low || v > high) {
+ raise_exception(EXCP05_BOUND);
+ }
+}
+
+#if !defined(CONFIG_USER_ONLY)
+
+#define MMUSUFFIX _mmu
+
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+#endif
+
+#if !defined(CONFIG_USER_ONLY)
+/* try to fill the TLB and return an exception if error. If retaddr is
+ NULL, it means that the function was called in C code (i.e. not
+ from generated code or from helper.c) */
+/* XXX: fix it to restore all registers */
+void tlb_fill(CPUState *env1, target_ulong addr, int is_write, int mmu_idx,
+ void *retaddr)
+{
+ TranslationBlock *tb;
+ int ret;
+ unsigned long pc;
+ CPUX86State *saved_env;
+
+ saved_env = env;
+ env = env1;
+
+ ret = cpu_x86_handle_mmu_fault(env, addr, is_write, mmu_idx);
+ if (ret) {
+ if (retaddr) {
+ /* now we have a real cpu fault */
+ pc = (unsigned long)retaddr;
+ tb = tb_find_pc(pc);
+ if (tb) {
+ /* the PC is inside the translated code. It means that we have
+ a virtual CPU fault */
+ cpu_restore_state(tb, env, pc);
+ }
+ }
+ raise_exception_err(env->exception_index, env->error_code);
+ }
+ env = saved_env;
+}
+#endif
+
+/* Secure Virtual Machine helpers */
+
+#if defined(CONFIG_USER_ONLY)
+
+void helper_vmrun(int aflag, int next_eip_addend)
+{
+}
+void helper_vmmcall(void)
+{
+}
+void helper_vmload(int aflag)
+{
+}
+void helper_vmsave(int aflag)
+{
+}
+void helper_stgi(void)
+{
+}
+void helper_clgi(void)
+{
+}
+void helper_skinit(void)
+{
+}
+void helper_invlpga(int aflag)
+{
+}
+void helper_vmexit(uint32_t exit_code, uint64_t exit_info_1)
+{
+}
+void helper_svm_check_intercept_param(uint32_t type, uint64_t param)
+{
+}
+
+void svm_check_intercept(CPUState *env1, uint32_t type)
+{
+}
+
+void helper_svm_check_io(uint32_t port, uint32_t param,
+ uint32_t next_eip_addend)
+{
+}
+#else
+
+static inline void svm_save_seg(target_phys_addr_t addr,
+ const SegmentCache *sc)
+{
+ stw_phys(addr + offsetof(struct vmcb_seg, selector),
+ sc->selector);
+ stq_phys(addr + offsetof(struct vmcb_seg, base),
+ sc->base);
+ stl_phys(addr + offsetof(struct vmcb_seg, limit),
+ sc->limit);
+ stw_phys(addr + offsetof(struct vmcb_seg, attrib),
+ ((sc->flags >> 8) & 0xff) | ((sc->flags >> 12) & 0x0f00));
+}
+
+static inline void svm_load_seg(target_phys_addr_t addr, SegmentCache *sc)
+{
+ unsigned int flags;
+
+ sc->selector = lduw_phys(addr + offsetof(struct vmcb_seg, selector));
+ sc->base = ldq_phys(addr + offsetof(struct vmcb_seg, base));
+ sc->limit = ldl_phys(addr + offsetof(struct vmcb_seg, limit));
+ flags = lduw_phys(addr + offsetof(struct vmcb_seg, attrib));
+ sc->flags = ((flags & 0xff) << 8) | ((flags & 0x0f00) << 12);
+}
+
+static inline void svm_load_seg_cache(target_phys_addr_t addr,
+ CPUState *env, int seg_reg)
+{
+ SegmentCache sc1, *sc = &sc1;
+ svm_load_seg(addr, sc);
+ cpu_x86_load_seg_cache(env, seg_reg, sc->selector,
+ sc->base, sc->limit, sc->flags);
+}
+
+void helper_vmrun(int aflag, int next_eip_addend)
+{
+ target_ulong addr;
+ uint32_t event_inj;
+ uint32_t int_ctl;
+
+ helper_svm_check_intercept_param(SVM_EXIT_VMRUN, 0);
+
+ if (aflag == 2)
+ addr = EAX;
+ else
+ addr = (uint32_t)EAX;
+
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmrun! " TARGET_FMT_lx "\n", addr);
+
+ env->vm_vmcb = addr;
+
+ /* save the current CPU state in the hsave page */
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.base), env->gdt.base);
+ stl_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.limit), env->gdt.limit);
+
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.base), env->idt.base);
+ stl_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.limit), env->idt.limit);
+
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr0), env->cr[0]);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr2), env->cr[2]);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr3), env->cr[3]);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr4), env->cr[4]);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr6), env->dr[6]);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr7), env->dr[7]);
+
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.efer), env->efer);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rflags), compute_eflags());
+
+ svm_save_seg(env->vm_hsave + offsetof(struct vmcb, save.es),
+ &env->segs[R_ES]);
+ svm_save_seg(env->vm_hsave + offsetof(struct vmcb, save.cs),
+ &env->segs[R_CS]);
+ svm_save_seg(env->vm_hsave + offsetof(struct vmcb, save.ss),
+ &env->segs[R_SS]);
+ svm_save_seg(env->vm_hsave + offsetof(struct vmcb, save.ds),
+ &env->segs[R_DS]);
+
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rip),
+ EIP + next_eip_addend);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rsp), ESP);
+ stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rax), EAX);
+
+ /* load the interception bitmaps so we do not need to access the
+ vmcb in svm mode */
+ env->intercept = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept));
+ env->intercept_cr_read = lduw_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept_cr_read));
+ env->intercept_cr_write = lduw_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept_cr_write));
+ env->intercept_dr_read = lduw_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept_dr_read));
+ env->intercept_dr_write = lduw_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept_dr_write));
+ env->intercept_exceptions = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.intercept_exceptions));
+
+ /* enable intercepts */
+ env->hflags |= HF_SVMI_MASK;
+
+ env->tsc_offset = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.tsc_offset));
+
+ env->gdt.base = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.base));
+ env->gdt.limit = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.limit));
+
+ env->idt.base = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.base));
+ env->idt.limit = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.limit));
+
+ /* clear exit_info_2 so we behave like the real hardware */
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2), 0);
+
+ cpu_x86_update_cr0(env, ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr0)));
+ cpu_x86_update_cr4(env, ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr4)));
+ cpu_x86_update_cr3(env, ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr3)));
+ env->cr[2] = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr2));
+ int_ctl = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl));
+ env->hflags2 &= ~(HF2_HIF_MASK | HF2_VINTR_MASK);
+ if (int_ctl & V_INTR_MASKING_MASK) {
+ env->v_tpr = int_ctl & V_TPR_MASK;
+ env->hflags2 |= HF2_VINTR_MASK;
+ if (env->eflags & IF_MASK)
+ env->hflags2 |= HF2_HIF_MASK;
+ }
+
+ cpu_load_efer(env,
+ ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.efer)));
+ env->eflags = 0;
+ load_eflags(ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rflags)),
+ ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
+ CC_OP = CC_OP_EFLAGS;
+
+ svm_load_seg_cache(env->vm_vmcb + offsetof(struct vmcb, save.es),
+ env, R_ES);
+ svm_load_seg_cache(env->vm_vmcb + offsetof(struct vmcb, save.cs),
+ env, R_CS);
+ svm_load_seg_cache(env->vm_vmcb + offsetof(struct vmcb, save.ss),
+ env, R_SS);
+ svm_load_seg_cache(env->vm_vmcb + offsetof(struct vmcb, save.ds),
+ env, R_DS);
+
+ EIP = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rip));
+ env->eip = EIP;
+ ESP = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rsp));
+ EAX = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rax));
+ env->dr[7] = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr7));
+ env->dr[6] = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr6));
+ cpu_x86_set_cpl(env, ldub_phys(env->vm_vmcb + offsetof(struct vmcb, save.cpl)));
+
+ /* FIXME: guest state consistency checks */
+
+ switch(ldub_phys(env->vm_vmcb + offsetof(struct vmcb, control.tlb_ctl))) {
+ case TLB_CONTROL_DO_NOTHING:
+ break;
+ case TLB_CONTROL_FLUSH_ALL_ASID:
+ /* FIXME: this is not 100% correct but should work for now */
+ tlb_flush(env, 1);
+ break;
+ }
+
+ env->hflags2 |= HF2_GIF_MASK;
+
+ if (int_ctl & V_IRQ_MASK) {
+ env->interrupt_request |= CPU_INTERRUPT_VIRQ;
+ }
+
+ /* maybe we need to inject an event */
+ event_inj = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj));
+ if (event_inj & SVM_EVTINJ_VALID) {
+ uint8_t vector = event_inj & SVM_EVTINJ_VEC_MASK;
+ uint16_t valid_err = event_inj & SVM_EVTINJ_VALID_ERR;
+ uint32_t event_inj_err = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err));
+
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "Injecting(%#hx): ", valid_err);
+ /* FIXME: need to implement valid_err */
+ switch (event_inj & SVM_EVTINJ_TYPE_MASK) {
+ case SVM_EVTINJ_TYPE_INTR:
+ env->exception_index = vector;
+ env->error_code = event_inj_err;
+ env->exception_is_int = 0;
+ env->exception_next_eip = -1;
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "INTR");
+ /* XXX: is it always correct ? */
+ do_interrupt_all(vector, 0, 0, 0, 1);
+ break;
+ case SVM_EVTINJ_TYPE_NMI:
+ env->exception_index = EXCP02_NMI;
+ env->error_code = event_inj_err;
+ env->exception_is_int = 0;
+ env->exception_next_eip = EIP;
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "NMI");
+ cpu_loop_exit(env);
+ break;
+ case SVM_EVTINJ_TYPE_EXEPT:
+ env->exception_index = vector;
+ env->error_code = event_inj_err;
+ env->exception_is_int = 0;
+ env->exception_next_eip = -1;
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "EXEPT");
+ cpu_loop_exit(env);
+ break;
+ case SVM_EVTINJ_TYPE_SOFT:
+ env->exception_index = vector;
+ env->error_code = event_inj_err;
+ env->exception_is_int = 1;
+ env->exception_next_eip = EIP;
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "SOFT");
+ cpu_loop_exit(env);
+ break;
+ }
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, " %#x %#x\n", env->exception_index, env->error_code);
+ }
+}
+
+void helper_vmmcall(void)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_VMMCALL, 0);
+ raise_exception(EXCP06_ILLOP);
+}
+
+void helper_vmload(int aflag)
+{
+ target_ulong addr;
+ helper_svm_check_intercept_param(SVM_EXIT_VMLOAD, 0);
+
+ if (aflag == 2)
+ addr = EAX;
+ else
+ addr = (uint32_t)EAX;
+
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmload! " TARGET_FMT_lx "\nFS: %016" PRIx64 " | " TARGET_FMT_lx "\n",
+ addr, ldq_phys(addr + offsetof(struct vmcb, save.fs.base)),
+ env->segs[R_FS].base);
+
+ svm_load_seg_cache(addr + offsetof(struct vmcb, save.fs),
+ env, R_FS);
+ svm_load_seg_cache(addr + offsetof(struct vmcb, save.gs),
+ env, R_GS);
+ svm_load_seg(addr + offsetof(struct vmcb, save.tr),
+ &env->tr);
+ svm_load_seg(addr + offsetof(struct vmcb, save.ldtr),
+ &env->ldt);
+
+#ifdef TARGET_X86_64
+ env->kernelgsbase = ldq_phys(addr + offsetof(struct vmcb, save.kernel_gs_base));
+ env->lstar = ldq_phys(addr + offsetof(struct vmcb, save.lstar));
+ env->cstar = ldq_phys(addr + offsetof(struct vmcb, save.cstar));
+ env->fmask = ldq_phys(addr + offsetof(struct vmcb, save.sfmask));
+#endif
+ env->star = ldq_phys(addr + offsetof(struct vmcb, save.star));
+ env->sysenter_cs = ldq_phys(addr + offsetof(struct vmcb, save.sysenter_cs));
+ env->sysenter_esp = ldq_phys(addr + offsetof(struct vmcb, save.sysenter_esp));
+ env->sysenter_eip = ldq_phys(addr + offsetof(struct vmcb, save.sysenter_eip));
+}
+
+void helper_vmsave(int aflag)
+{
+ target_ulong addr;
+ helper_svm_check_intercept_param(SVM_EXIT_VMSAVE, 0);
+
+ if (aflag == 2)
+ addr = EAX;
+ else
+ addr = (uint32_t)EAX;
+
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmsave! " TARGET_FMT_lx "\nFS: %016" PRIx64 " | " TARGET_FMT_lx "\n",
+ addr, ldq_phys(addr + offsetof(struct vmcb, save.fs.base)),
+ env->segs[R_FS].base);
+
+ svm_save_seg(addr + offsetof(struct vmcb, save.fs),
+ &env->segs[R_FS]);
+ svm_save_seg(addr + offsetof(struct vmcb, save.gs),
+ &env->segs[R_GS]);
+ svm_save_seg(addr + offsetof(struct vmcb, save.tr),
+ &env->tr);
+ svm_save_seg(addr + offsetof(struct vmcb, save.ldtr),
+ &env->ldt);
+
+#ifdef TARGET_X86_64
+ stq_phys(addr + offsetof(struct vmcb, save.kernel_gs_base), env->kernelgsbase);
+ stq_phys(addr + offsetof(struct vmcb, save.lstar), env->lstar);
+ stq_phys(addr + offsetof(struct vmcb, save.cstar), env->cstar);
+ stq_phys(addr + offsetof(struct vmcb, save.sfmask), env->fmask);
+#endif
+ stq_phys(addr + offsetof(struct vmcb, save.star), env->star);
+ stq_phys(addr + offsetof(struct vmcb, save.sysenter_cs), env->sysenter_cs);
+ stq_phys(addr + offsetof(struct vmcb, save.sysenter_esp), env->sysenter_esp);
+ stq_phys(addr + offsetof(struct vmcb, save.sysenter_eip), env->sysenter_eip);
+}
+
+void helper_stgi(void)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_STGI, 0);
+ env->hflags2 |= HF2_GIF_MASK;
+}
+
+void helper_clgi(void)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_CLGI, 0);
+ env->hflags2 &= ~HF2_GIF_MASK;
+}
+
+void helper_skinit(void)
+{
+ helper_svm_check_intercept_param(SVM_EXIT_SKINIT, 0);
+ /* XXX: not implemented */
+ raise_exception(EXCP06_ILLOP);
+}
+
+void helper_invlpga(int aflag)
+{
+ target_ulong addr;
+ helper_svm_check_intercept_param(SVM_EXIT_INVLPGA, 0);
+
+ if (aflag == 2)
+ addr = EAX;
+ else
+ addr = (uint32_t)EAX;
+
+ /* XXX: could use the ASID to see if it is needed to do the
+ flush */
+ tlb_flush_page(env, addr);
+}
+
+void helper_svm_check_intercept_param(uint32_t type, uint64_t param)
+{
+ if (likely(!(env->hflags & HF_SVMI_MASK)))
+ return;
+ switch(type) {
+ case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR0 + 8:
+ if (env->intercept_cr_read & (1 << (type - SVM_EXIT_READ_CR0))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR0 + 8:
+ if (env->intercept_cr_write & (1 << (type - SVM_EXIT_WRITE_CR0))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR0 + 7:
+ if (env->intercept_dr_read & (1 << (type - SVM_EXIT_READ_DR0))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR0 + 7:
+ if (env->intercept_dr_write & (1 << (type - SVM_EXIT_WRITE_DR0))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 31:
+ if (env->intercept_exceptions & (1 << (type - SVM_EXIT_EXCP_BASE))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ case SVM_EXIT_MSR:
+ if (env->intercept & (1ULL << (SVM_EXIT_MSR - SVM_EXIT_INTR))) {
+ /* FIXME: this should be read in at vmrun (faster this way?) */
+ uint64_t addr = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.msrpm_base_pa));
+ uint32_t t0, t1;
+ switch((uint32_t)ECX) {
+ case 0 ... 0x1fff:
+ t0 = (ECX * 2) % 8;
+ t1 = (ECX * 2) / 8;
+ break;
+ case 0xc0000000 ... 0xc0001fff:
+ t0 = (8192 + ECX - 0xc0000000) * 2;
+ t1 = (t0 / 8);
+ t0 %= 8;
+ break;
+ case 0xc0010000 ... 0xc0011fff:
+ t0 = (16384 + ECX - 0xc0010000) * 2;
+ t1 = (t0 / 8);
+ t0 %= 8;
+ break;
+ default:
+ helper_vmexit(type, param);
+ t0 = 0;
+ t1 = 0;
+ break;
+ }
+ if (ldub_phys(addr + t1) & ((1 << param) << t0))
+ helper_vmexit(type, param);
+ }
+ break;
+ default:
+ if (env->intercept & (1ULL << (type - SVM_EXIT_INTR))) {
+ helper_vmexit(type, param);
+ }
+ break;
+ }
+}
+
+void svm_check_intercept(CPUState *env1, uint32_t type)
+{
+ CPUState *saved_env;
+
+ saved_env = env;
+ env = env1;
+ helper_svm_check_intercept_param(type, 0);
+ env = saved_env;
+}
+
+void helper_svm_check_io(uint32_t port, uint32_t param,
+ uint32_t next_eip_addend)
+{
+ if (env->intercept & (1ULL << (SVM_EXIT_IOIO - SVM_EXIT_INTR))) {
+ /* FIXME: this should be read in at vmrun (faster this way?) */
+ uint64_t addr = ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.iopm_base_pa));
+ uint16_t mask = (1 << ((param >> 4) & 7)) - 1;
+ if(lduw_phys(addr + port / 8) & (mask << (port & 7))) {
+ /* next EIP */
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2),
+ env->eip + next_eip_addend);
+ helper_vmexit(SVM_EXIT_IOIO, param | (port << 16));
+ }
+ }
+}
+
+/* Note: currently only 32 bits of exit_code are used */
+void helper_vmexit(uint32_t exit_code, uint64_t exit_info_1)
+{
+ uint32_t int_ctl;
+
+ qemu_log_mask(CPU_LOG_TB_IN_ASM, "vmexit(%08x, %016" PRIx64 ", %016" PRIx64 ", " TARGET_FMT_lx ")!\n",
+ exit_code, exit_info_1,
+ ldq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2)),
+ EIP);
+
+ if(env->hflags & HF_INHIBIT_IRQ_MASK) {
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_state), SVM_INTERRUPT_SHADOW_MASK);
+ env->hflags &= ~HF_INHIBIT_IRQ_MASK;
+ } else {
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_state), 0);
+ }
+
+ /* Save the VM state in the vmcb */
+ svm_save_seg(env->vm_vmcb + offsetof(struct vmcb, save.es),
+ &env->segs[R_ES]);
+ svm_save_seg(env->vm_vmcb + offsetof(struct vmcb, save.cs),
+ &env->segs[R_CS]);
+ svm_save_seg(env->vm_vmcb + offsetof(struct vmcb, save.ss),
+ &env->segs[R_SS]);
+ svm_save_seg(env->vm_vmcb + offsetof(struct vmcb, save.ds),
+ &env->segs[R_DS]);
+
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.base), env->gdt.base);
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, save.gdtr.limit), env->gdt.limit);
+
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.base), env->idt.base);
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, save.idtr.limit), env->idt.limit);
+
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.efer), env->efer);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr0), env->cr[0]);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr2), env->cr[2]);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr3), env->cr[3]);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.cr4), env->cr[4]);
+
+ int_ctl = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl));
+ int_ctl &= ~(V_TPR_MASK | V_IRQ_MASK);
+ int_ctl |= env->v_tpr & V_TPR_MASK;
+ if (env->interrupt_request & CPU_INTERRUPT_VIRQ)
+ int_ctl |= V_IRQ_MASK;
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), int_ctl);
+
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rflags), compute_eflags());
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rip), env->eip);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rsp), ESP);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.rax), EAX);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr7), env->dr[7]);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, save.dr6), env->dr[6]);
+ stb_phys(env->vm_vmcb + offsetof(struct vmcb, save.cpl), env->hflags & HF_CPL_MASK);
+
+ /* Reload the host state from vm_hsave */
+ env->hflags2 &= ~(HF2_HIF_MASK | HF2_VINTR_MASK);
+ env->hflags &= ~HF_SVMI_MASK;
+ env->intercept = 0;
+ env->intercept_exceptions = 0;
+ env->interrupt_request &= ~CPU_INTERRUPT_VIRQ;
+ env->tsc_offset = 0;
+
+ env->gdt.base = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.base));
+ env->gdt.limit = ldl_phys(env->vm_hsave + offsetof(struct vmcb, save.gdtr.limit));
+
+ env->idt.base = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.base));
+ env->idt.limit = ldl_phys(env->vm_hsave + offsetof(struct vmcb, save.idtr.limit));
+
+ cpu_x86_update_cr0(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr0)) | CR0_PE_MASK);
+ cpu_x86_update_cr4(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr4)));
+ cpu_x86_update_cr3(env, ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.cr3)));
+ /* we need to set the efer after the crs so the hidden flags get
+ set properly */
+ cpu_load_efer(env,
+ ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.efer)));
+ env->eflags = 0;
+ load_eflags(ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rflags)),
+ ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK));
+ CC_OP = CC_OP_EFLAGS;
+
+ svm_load_seg_cache(env->vm_hsave + offsetof(struct vmcb, save.es),
+ env, R_ES);
+ svm_load_seg_cache(env->vm_hsave + offsetof(struct vmcb, save.cs),
+ env, R_CS);
+ svm_load_seg_cache(env->vm_hsave + offsetof(struct vmcb, save.ss),
+ env, R_SS);
+ svm_load_seg_cache(env->vm_hsave + offsetof(struct vmcb, save.ds),
+ env, R_DS);
+
+ EIP = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rip));
+ ESP = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rsp));
+ EAX = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.rax));
+
+ env->dr[6] = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr6));
+ env->dr[7] = ldq_phys(env->vm_hsave + offsetof(struct vmcb, save.dr7));
+
+ /* other setups */
+ cpu_x86_set_cpl(env, 0);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_code), exit_code);
+ stq_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_info_1), exit_info_1);
+
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info),
+ ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj)));
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.exit_int_info_err),
+ ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj_err)));
+ stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.event_inj), 0);
+
+ env->hflags2 &= ~HF2_GIF_MASK;
+ /* FIXME: Resets the current ASID register to zero (host ASID). */
+
+ /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */
+
+ /* Clears the TSC_OFFSET inside the processor. */
+
+ /* If the host is in PAE mode, the processor reloads the host's PDPEs
+ from the page table indicated the host's CR3. If the PDPEs contain
+ illegal state, the processor causes a shutdown. */
+
+ /* Forces CR0.PE = 1, RFLAGS.VM = 0. */
+ env->cr[0] |= CR0_PE_MASK;
+ env->eflags &= ~VM_MASK;
+
+ /* Disables all breakpoints in the host DR7 register. */
+
+ /* Checks the reloaded host state for consistency. */
+
+ /* If the host's rIP reloaded by #VMEXIT is outside the limit of the
+ host's code segment or non-canonical (in the case of long mode), a
+ #GP fault is delivered inside the host.) */
+
+ /* remove any pending exception */
+ env->exception_index = -1;
+ env->error_code = 0;
+ env->old_exception = -1;
+
+ cpu_loop_exit(env);
+}
+
+#endif
+
+/* MMX/SSE */
+/* XXX: optimize by storing fptt and fptags in the static cpu state */
+void helper_enter_mmx(void)
+{
+ env->fpstt = 0;
+ *(uint32_t *)(env->fptags) = 0;
+ *(uint32_t *)(env->fptags + 4) = 0;
+}
+
+void helper_emms(void)
+{
+ /* set to empty state */
+ *(uint32_t *)(env->fptags) = 0x01010101;
+ *(uint32_t *)(env->fptags + 4) = 0x01010101;
+}
+
+/* XXX: suppress */
+void helper_movq(void *d, void *s)
+{
+ *(uint64_t *)d = *(uint64_t *)s;
+}
+
+#define SHIFT 0
+#include "ops_sse.h"
+
+#define SHIFT 1
+#include "ops_sse.h"
+
+#define SHIFT 0
+#include "helper_template.h"
+#undef SHIFT
+
+#define SHIFT 1
+#include "helper_template.h"
+#undef SHIFT
+
+#define SHIFT 2
+#include "helper_template.h"
+#undef SHIFT
+
+#ifdef TARGET_X86_64
+
+#define SHIFT 3
+#include "helper_template.h"
+#undef SHIFT
+
+#endif
+
+/* bit operations */
+target_ulong helper_bsf(target_ulong t0)
+{
+ int count;
+ target_ulong res;
+
+ res = t0;
+ count = 0;
+ while ((res & 1) == 0) {
+ count++;
+ res >>= 1;
+ }
+ return count;
+}
+
+target_ulong helper_lzcnt(target_ulong t0, int wordsize)
+{
+ int count;
+ target_ulong res, mask;
+
+ if (wordsize > 0 && t0 == 0) {
+ return wordsize;
+ }
+ res = t0;
+ count = TARGET_LONG_BITS - 1;
+ mask = (target_ulong)1 << (TARGET_LONG_BITS - 1);
+ while ((res & mask) == 0) {
+ count--;
+ res <<= 1;
+ }
+ if (wordsize > 0) {
+ return wordsize - 1 - count;
+ }
+ return count;
+}
+
+target_ulong helper_bsr(target_ulong t0)
+{
+ return helper_lzcnt(t0, 0);
+}
+
+static int compute_all_eflags(void)
+{
+ return CC_SRC;
+}
+
+static int compute_c_eflags(void)
+{
+ return CC_SRC & CC_C;
+}
+
+uint32_t helper_cc_compute_all(int op)
+{
+ switch (op) {
+ default: /* should never happen */ return 0;
+
+ case CC_OP_EFLAGS: return compute_all_eflags();
+
+ case CC_OP_MULB: return compute_all_mulb();
+ case CC_OP_MULW: return compute_all_mulw();
+ case CC_OP_MULL: return compute_all_mull();
+
+ case CC_OP_ADDB: return compute_all_addb();
+ case CC_OP_ADDW: return compute_all_addw();
+ case CC_OP_ADDL: return compute_all_addl();
+
+ case CC_OP_ADCB: return compute_all_adcb();
+ case CC_OP_ADCW: return compute_all_adcw();
+ case CC_OP_ADCL: return compute_all_adcl();
+
+ case CC_OP_SUBB: return compute_all_subb();
+ case CC_OP_SUBW: return compute_all_subw();
+ case CC_OP_SUBL: return compute_all_subl();
+
+ case CC_OP_SBBB: return compute_all_sbbb();
+ case CC_OP_SBBW: return compute_all_sbbw();
+ case CC_OP_SBBL: return compute_all_sbbl();
+
+ case CC_OP_LOGICB: return compute_all_logicb();
+ case CC_OP_LOGICW: return compute_all_logicw();
+ case CC_OP_LOGICL: return compute_all_logicl();
+
+ case CC_OP_INCB: return compute_all_incb();
+ case CC_OP_INCW: return compute_all_incw();
+ case CC_OP_INCL: return compute_all_incl();
+
+ case CC_OP_DECB: return compute_all_decb();
+ case CC_OP_DECW: return compute_all_decw();
+ case CC_OP_DECL: return compute_all_decl();
+
+ case CC_OP_SHLB: return compute_all_shlb();
+ case CC_OP_SHLW: return compute_all_shlw();
+ case CC_OP_SHLL: return compute_all_shll();
+
+ case CC_OP_SARB: return compute_all_sarb();
+ case CC_OP_SARW: return compute_all_sarw();
+ case CC_OP_SARL: return compute_all_sarl();
+
+#ifdef TARGET_X86_64
+ case CC_OP_MULQ: return compute_all_mulq();
+
+ case CC_OP_ADDQ: return compute_all_addq();
+
+ case CC_OP_ADCQ: return compute_all_adcq();
+
+ case CC_OP_SUBQ: return compute_all_subq();
+
+ case CC_OP_SBBQ: return compute_all_sbbq();
+
+ case CC_OP_LOGICQ: return compute_all_logicq();
+
+ case CC_OP_INCQ: return compute_all_incq();
+
+ case CC_OP_DECQ: return compute_all_decq();
+
+ case CC_OP_SHLQ: return compute_all_shlq();
+
+ case CC_OP_SARQ: return compute_all_sarq();
+#endif
+ }
+}
+
+uint32_t cpu_cc_compute_all(CPUState *env1, int op)
+{
+ CPUState *saved_env;
+ uint32_t ret;
+
+ saved_env = env;
+ env = env1;
+ ret = helper_cc_compute_all(op);
+ env = saved_env;
+ return ret;
+}
+
+uint32_t helper_cc_compute_c(int op)
+{
+ switch (op) {
+ default: /* should never happen */ return 0;
+
+ case CC_OP_EFLAGS: return compute_c_eflags();
+
+ case CC_OP_MULB: return compute_c_mull();
+ case CC_OP_MULW: return compute_c_mull();
+ case CC_OP_MULL: return compute_c_mull();
+
+ case CC_OP_ADDB: return compute_c_addb();
+ case CC_OP_ADDW: return compute_c_addw();
+ case CC_OP_ADDL: return compute_c_addl();
+
+ case CC_OP_ADCB: return compute_c_adcb();
+ case CC_OP_ADCW: return compute_c_adcw();
+ case CC_OP_ADCL: return compute_c_adcl();
+
+ case CC_OP_SUBB: return compute_c_subb();
+ case CC_OP_SUBW: return compute_c_subw();
+ case CC_OP_SUBL: return compute_c_subl();
+
+ case CC_OP_SBBB: return compute_c_sbbb();
+ case CC_OP_SBBW: return compute_c_sbbw();
+ case CC_OP_SBBL: return compute_c_sbbl();
+
+ case CC_OP_LOGICB: return compute_c_logicb();
+ case CC_OP_LOGICW: return compute_c_logicw();
+ case CC_OP_LOGICL: return compute_c_logicl();
+
+ case CC_OP_INCB: return compute_c_incl();
+ case CC_OP_INCW: return compute_c_incl();
+ case CC_OP_INCL: return compute_c_incl();
+
+ case CC_OP_DECB: return compute_c_incl();
+ case CC_OP_DECW: return compute_c_incl();
+ case CC_OP_DECL: return compute_c_incl();
+
+ case CC_OP_SHLB: return compute_c_shlb();
+ case CC_OP_SHLW: return compute_c_shlw();
+ case CC_OP_SHLL: return compute_c_shll();
+
+ case CC_OP_SARB: return compute_c_sarl();
+ case CC_OP_SARW: return compute_c_sarl();
+ case CC_OP_SARL: return compute_c_sarl();
+
+#ifdef TARGET_X86_64
+ case CC_OP_MULQ: return compute_c_mull();
+
+ case CC_OP_ADDQ: return compute_c_addq();
+
+ case CC_OP_ADCQ: return compute_c_adcq();
+
+ case CC_OP_SUBQ: return compute_c_subq();
+
+ case CC_OP_SBBQ: return compute_c_sbbq();
+
+ case CC_OP_LOGICQ: return compute_c_logicq();
+
+ case CC_OP_INCQ: return compute_c_incl();
+
+ case CC_OP_DECQ: return compute_c_incl();
+
+ case CC_OP_SHLQ: return compute_c_shlq();
+
+ case CC_OP_SARQ: return compute_c_sarl();
+#endif
+ }
+}
--- /dev/null
+/*
+ * Host-side implementation of GL/GLX API
+ *
+ * Copyright (c) 2006,2007 Even Rouault
+ *
+ * modified by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISiNG FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <sys/types.h> // for pid_t
+
+#include "qemu-common.h"
+
+/* GW: dyngen-exec.h defines its own version of stuff that is in stdio.h -
+ only it misses things and is mildly different to stdio \o/. Hence
+ don't include stdio and make our own defines. */
+
+/*
+#ifdef DEBUG_GL
+#ifdef _WIN32
+#define DEBUGF(...) printf(__VA_ARGS__)
+#else
+#define DEBUGF(...) fprintf(stderr, __VA_ARGS__)
+#endif
+#else
+#define DEBUGF(...) while(0) {printf(__VA_ARGS__); }
+#endif
+*/
+#include "tizen/src/debug_ch.h"
+MULTI_DEBUG_CHANNEL(qemu, opengl);
+#define DEBUGF TRACE
+
+#define GL_GLEXT_PROTOTYPES
+#define GLX_GLXEXT_PROTOTYPES
+#include <mesa_gl.h>
+
+#include "qemu-queue.h"
+#include "opengl_func.h"
+#include "mesa_mipmap.h"
+#include "opengl_process.h"
+#include "range_alloc.h"
+#include "gloffscreen.h"
+
+
+/** Misc X11/GLX defines - we don't want to include the whole files for these
+ * as we need them on Windows too */
+typedef int Bool;
+const Bool True = 1;
+const Bool False = 0;
+typedef struct __GLXFBConfigRec GLXFBConfig;
+struct __GLXFBConfigRec {
+ int formatFlags;
+};
+
+// #defines from glx.h
+#define GLX_VENDOR 1
+#define GLX_VERSION 2
+#define GLX_EXTENSIONS 3
+
+/* We'll say the XVisual Id is actually just an index into here */
+const GLXFBConfig FBCONFIGS[] = {
+ {GLO_FF_ALPHA|GLO_FF_BITS_32},
+ {GLO_FF_ALPHA|GLO_FF_BITS_32|GLO_FF_DEPTH_24},
+ {GLO_FF_ALPHA|GLO_FF_BITS_32|GLO_FF_DEPTH_24|GLO_FF_STENCIL_8},
+/*
+ {GLO_FF_BITS_32},
+ {GLO_FF_BITS_32|GLO_FF_DEPTH_24},
+ {GLO_FF_BITS_32|GLO_FF_DEPTH_24|GLO_FF_STENCIL_8},
+
+ {GLO_FF_BITS_24},
+ {GLO_FF_BITS_24|GLO_FF_DEPTH_24},
+ {GLO_FF_BITS_24|GLO_FF_DEPTH_24|GLO_FF_STENCIL_8},
+*/
+/*
+ {GLO_FF_BITS_16},
+ {GLO_FF_BITS_16|GLO_FF_DEPTH_24},
+ {GLO_FF_BITS_16|GLO_FF_DEPTH_24|GLO_FF_STENCIL_8},*/
+};
+
+#define FAKE_GL_VENDOR "Qemu"
+#define FAKE_GL_RENDERER "VMGL Passthrough"
+#define FAKE_GL_VERSION "1.4"
+#define FAKE_GL_MAJOR 1
+
+
+#define FAKE_GLX_VENDOR "Qemu"
+#define FAKE_GLX_VERSION_STRING "1.2"
+#define FAKE_GLX_VERSION_MAJOR 1
+#define FAKE_GLX_VERSION_MINOR 2
+
+void *g_malloc(size_t size);
+void *g_realloc(void *ptr, size_t size);
+void g_free(void *ptr);
+
+#define glGetError() 0
+
+#define GET_EXT_PTR(type, funcname, args_decl) \
+ static int detect_##funcname = 0; \
+ static type(*ptr_func_##funcname)args_decl = NULL; \
+ if (detect_##funcname == 0) \
+ { \
+ detect_##funcname = 1; \
+ ptr_func_##funcname = (type(*)args_decl)glo_getprocaddress((const char*)#funcname); \
+ assert (ptr_func_##funcname); \
+ }
+
+#define GET_EXT_PTR_NO_FAIL(type, funcname, args_decl) \
+ static int detect_##funcname = 0; \
+ static type(*ptr_func_##funcname)args_decl = NULL; \
+ if (detect_##funcname == 0) \
+ { \
+ detect_##funcname = 1; \
+ ptr_func_##funcname = (type(*)args_decl)glo_getprocaddress((const char*)#funcname); \
+ }
+
+#ifndef WIN32
+#include <dlfcn.h>
+#endif
+
+static void *get_glu_ptr(const char *name)
+{
+ static void *handle = (void *) -1;
+
+ if (handle == (void *) -1) {
+#ifndef WIN32
+ handle = dlopen("libGLU.so", RTLD_LAZY);
+ if (!handle)
+ DEBUGF("can't load libGLU.so : %s\n", dlerror());
+#else
+ handle = (void *) LoadLibrary("glu32.dll");
+ if (!handle)
+ DEBUGF("can't load glu32.dll\n");
+#endif
+ }
+ if (handle) {
+#ifndef WIN32
+ return dlsym(handle, name);
+#else
+ return GetProcAddress(handle, name);
+#endif
+ }
+ return NULL;
+}
+
+#define GET_GLU_PTR(type, funcname, args_decl) \
+ static int detect_##funcname = 0; \
+ static type(*ptr_func_##funcname)args_decl = NULL; \
+ if (detect_##funcname == 0) \
+ { \
+ detect_##funcname = 1; \
+ ptr_func_##funcname = (type(*)args_decl)get_glu_ptr(#funcname); \
+ }
+
+int display_function_call = 0;
+extern int kill_process;
+
+typedef struct {
+ void *key;
+ void *value;
+} Assoc;
+
+#define MAX_HANDLED_PROCESS 100
+#define MAX_ASSOC_SIZE 100
+
+#define MAX_FBCONFIG 10
+
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define DIM(X) (sizeof(X) / sizeof(X[0]))
+
+typedef struct {
+ GLbitfield mask;
+ int activeTextureIndex;
+} ClientState;
+
+#define MAX_CLIENT_STATE_STACK_SIZE 16
+
+typedef void *ClientGLXDrawable;
+
+typedef struct GLState GLState;
+
+typedef struct QGloSurface {
+ GLState *glstate;
+ GloSurface *surface;
+ ClientGLXDrawable *client_drawable;
+ int ready;
+ int ref;
+ QTAILQ_ENTRY(QGloSurface) next;
+} QGloSurface;
+
+struct GLState {
+ int ref;
+ int fake_ctxt;
+ int fake_shareList;
+
+ GloContext *context; // context (owned by this)
+ QGloSurface *current_qsurface; // current rendering surface/drawable
+ QTAILQ_HEAD(, QGloSurface) qsurfaces; // list of surfaces/drawables for
+ // this context
+
+ void *vertexPointer;
+ void *normalPointer;
+ void *colorPointer;
+ void *secondaryColorPointer;
+ void *indexPointer;
+ void *texCoordPointer[NB_MAX_TEXTURES];
+ void *edgeFlagPointer;
+ void *vertexAttribPointer[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
+ void *vertexAttribPointerNV[MY_GL_MAX_VERTEX_ATTRIBS_NV];
+ void *weightPointer;
+ void *matrixIndexPointer;
+ void *fogCoordPointer;
+ void *variantPointerEXT[MY_GL_MAX_VARIANT_POINTER_EXT];
+ void *interleavedArrays;
+ void *elementPointerATI;
+
+ int vertexPointerSize;
+ int normalPointerSize;
+ int colorPointerSize;
+ int secondaryColorPointerSize;
+ int indexPointerSize;
+ int texCoordPointerSize[NB_MAX_TEXTURES];
+ int edgeFlagPointerSize;
+ int vertexAttribPointerSize[MY_GL_MAX_VERTEX_ATTRIBS_ARB];
+ int vertexAttribPointerNVSize[MY_GL_MAX_VERTEX_ATTRIBS_NV];
+ int weightPointerSize;
+ int matrixIndexPointerSize;
+ int fogCoordPointerSize;
+ int variantPointerEXTSize[MY_GL_MAX_VARIANT_POINTER_EXT];
+ int interleavedArraysSize;
+ int elementPointerATISize;
+
+ int selectBufferSize;
+ void *selectBufferPtr;
+ int feedbackBufferSize;
+ void *feedbackBufferPtr;
+
+ ClientState clientStateStack[MAX_CLIENT_STATE_STACK_SIZE];
+ int clientStateSp;
+ int activeTextureIndex;
+
+ unsigned int ownTabTextures[32768];
+ unsigned int *tabTextures;
+ RangeAllocator ownTextureAllocator;
+ RangeAllocator *textureAllocator;
+
+ unsigned int ownTabBuffers[32768];
+ unsigned int *tabBuffers;
+ RangeAllocator ownBufferAllocator;
+ RangeAllocator *bufferAllocator;
+
+ unsigned int ownTabLists[32768];
+ unsigned int *tabLists;
+ RangeAllocator ownListAllocator;
+ RangeAllocator *listAllocator;
+
+};
+
+typedef struct {
+ ProcessStruct p;
+
+ int next_available_context_number;
+
+ int nb_states;
+ GLState default_state;
+ GLState **glstates;
+ GLState *current_state;
+
+ int nfbconfig;
+ const GLXFBConfig *fbconfigs[MAX_FBCONFIG];
+ int fbconfigs_max[MAX_FBCONFIG];
+ int nfbconfig_total;
+
+ int primitive;
+ int bufsize;
+ int bufstart;
+ arg_t *cmdbuf;
+} ProcessState;
+
+static ProcessState processes[MAX_HANDLED_PROCESS];
+
+static char *strip_extensions(const char *avail, const char *ext[]) {
+ char *pos, *supported, *srcp;
+
+ supported = (char *)g_malloc(strlen(avail) + 2);
+
+ pos = supported;
+ while(*ext) {
+ srcp = (char*)avail;
+ while((srcp = strstr(srcp, *ext))) {
+ int len = strlen(*ext);
+ if(*(srcp+len) == ' ' || *(srcp+len) == '\0') {
+ strcpy(pos, *ext);
+ pos += len;
+ if(*(srcp+len) == ' ') {
+ *pos = ' ';
+ pos++;
+ }
+ break;
+ }
+ srcp += len;
+ }
+ ext++;
+ }
+ *pos = ' ';
+ *pos = '\0';
+
+ return supported;
+}
+
+static const char *glx_ext_supported[] = {
+ "GLX_ARB_multisample",
+ 0
+};
+
+static char *supported_glx_extensions() {
+ static char *supported;
+
+ if(!supported)
+ supported = strip_extensions(glo_glXQueryExtensionsString(),
+ glx_ext_supported);
+
+ return supported;
+}
+
+static const char *gl_ext_supported[] = {
+// Mandatory OpenGL 1.4 Extensions
+ "GL_ARB_depth_texture",
+ "GL_ARB_multisample",
+ "GL_ARB_multitexture",
+ "GL_ARB_point_parameters",
+ "GL_ARB_shadow",
+ "GL_ARB_texture_border_clamp",
+ "GL_ARB_texture_compression",
+ "GL_ARB_texture_cube_map",
+ "GL_ARB_texture_env_add",
+ "GL_ARB_texture_env_combine",
+ "GL_ARB_texture_env_crossbar",
+ "GL_ARB_texture_env_dot3",
+ "GL_ARB_texture_mirrored_repeat",
+ "GL_ARB_transpose_matrix",
+ "GL_ARB_window_pos",
+ "GL_EXT_bgra",
+ "GL_EXT_blend_color",
+ "GL_EXT_blend_func_separate",
+ "GL_EXT_blend_logic_op",
+ "GL_EXT_blend_minmax",
+ "GL_EXT_blend_subtract",
+ "GL_EXT_copy_texture",
+ "GL_EXT_draw_range_elements",
+ "GL_EXT_fog_coord",
+ "GL_EXT_multi_draw_arrays",
+ "GL_EXT_packed_pixels",
+ "GL_EXT_point_parameters",
+ "GL_EXT_polygon_offset",
+ "GL_EXT_rescale_normal",
+ "GL_EXT_secondary_color",
+ "GL_EXT_separate_specular_color",
+ "GL_EXT_stencil_wrap",
+ "GL_EXT_subtexture",
+ "GL_EXT_texture",
+ "GL_EXT_texture3D",
+ "GL_EXT_texture_edge_clamp",
+ "GL_EXT_texture_env_add",
+ "GL_EXT_texture_env_combine",
+ "GL_EXT_texture_lod",
+ "GL_EXT_texture_lod_bias",
+ "GL_EXT_texture_object",
+ "GL_APPLE_packed_pixels",
+ "GL_NV_blend_square",
+ "GL_SGIS_generate_mipmap",
+ "GL_SGIS_texture_border_clamp",
+ "GL_SGIS_texture_edge_clamp",
+ "GL_SGIS_texture_lod",
+// Optional extensions. If you get problems try disabling the below.
+ "GL_EXT_compiled_vertex_array",
+ "GL_ARB_copy_buffer",
+ "GL_ARB_depth_clamp",
+ "GL_ARB_draw_buffers ",
+ "GL_ARB_draw_elements_base_vertex",
+ "GL_ARB_fragment_program",
+ "GL_ARB_fragment_program_shadow",
+ "GL_ARB_fragment_shader",
+ "GL_ARB_framebuffer_object",
+ "GL_ARB_half_float_pixel",
+ "GL_ARB_map_buffer_range",
+ "GL_ARB_occlusion_query",
+ "GL_ARB_pixel_buffer_object",
+ "GL_ARB_point_sprite",
+ "GL_ARB_provoking_vertex",
+ "GL_ARB_seamless_cube_map",
+ "GL_ARB_shader_objects",
+ "GL_ARB_shading_language_100",
+ "GL_ARB_shading_language_120",
+ "GL_ARB_sync",
+ "GL_ARB_texture_non_power_of_two",
+ "GL_ARB_texture_rectangle",
+ "GL_ARB_vertex_array_bgra",
+ "GL_ARB_vertex_array_object",
+ "GL_ARB_vertex_buffer_object",
+ "GL_ARB_vertex_program",
+ "GL_ARB_vertex_shader,"
+ "GL_EXT_abgr",
+ "GL_EXT_blend_equation_separate",
+ "GL_EXT_cull_vertex",
+ "GL_EXT_framebuffer_blit",
+ "GL_EXT_framebuffer_object",
+ "GL_EXT_gpu_program_parameters",
+ "GL_EXT_packed_depth_stencil",
+ "GL_EXT_pixel_buffer_object",
+ "GL_EXT_provoking_vertex",
+ "GL_EXT_shadow_funcs",
+ "GL_EXT_stencil_two_side",
+ "GL_EXT_texture_cube_map",
+ "GL_EXT_texture_env_dot3",
+ "GL_EXT_texture_filter_anisotropic",
+ "GL_EXT_texture_rectangle",
+ "GL_EXT_texture_sRGB",
+ "GL_EXT_texture_swizzle",
+ "GL_EXT_vertex_array",
+ "GL_EXT_vertex_array_bgra",
+ "GL_3DFX_texture_compression_FXT1",
+ "GL_APPLE_client_storage",
+ "GL_APPLE_vertex_array_object",
+ "GL_ATI_blend_equation_separate",
+ "GL_ATI_envmap_bumpmap",
+ "GL_ATI_texture_env_combine3",
+ "GL_ATI_separate_stencil",
+ "GL_IBM_multimode_draw_arrays",
+ "GL_IBM_rasterpos_clip",
+ "GL_IBM_texture_mirrored_repeat",
+ "GL_INGR_blend_func_separate",
+ "GL_MESA_pack_invert",
+ "GL_MESA_texture_signed_rgba",
+ "GL_MESA_ycbcr_texture",
+ "GL_MESA_window_pos",
+ "GL_NV_depth_clamp",
+ "GL_NV_light_max_exponent",
+ "GL_NV_packed_depth_stencil",
+ "GL_NV_texture_env_combine4",
+ "GL_NV_texture_rectangle",
+ "GL_NV_texgen_reflection",
+ "GL_NV_vertex_program",
+ "GL_NV_vertex_program1_1",
+ "GL_OES_read_format",
+ "GL_SUN_multi_draw_arrays",
+ 0
+};
+
+static char *compute_gl_extensions() {
+ static char *supported;
+
+ if(!supported)
+ supported = strip_extensions((const char *)glGetString(GL_EXTENSIONS),
+ gl_ext_supported);
+
+ return supported;
+}
+
+static inline QGloSurface *get_qsurface_from_client_drawable(GLState *state, ClientGLXDrawable client_drawable) {
+ QGloSurface *qsurface;
+
+ if(state->current_qsurface->client_drawable == client_drawable)
+ return state->current_qsurface;
+
+ QTAILQ_FOREACH(qsurface, &state->qsurfaces, next) {
+ if (qsurface->client_drawable == client_drawable)
+ return qsurface;
+ }
+
+ return NULL;
+}
+
+// This must always be called only on surfaces belonging to the current context
+static inline void render_surface(QGloSurface *qsurface, int bpp, int stride, char *buffer)
+{
+ int w, h;
+ if(!qsurface->ready)
+ return;
+
+ glo_surface_get_size(qsurface->surface, &w, &h);
+
+ glo_surface_getcontents(qsurface->surface, stride, bpp, buffer);
+}
+
+// This must always be called only on surfaces belonging to the current context
+static inline void resize_surface(ProcessState *process, QGloSurface *qsurface,
+ int w, int h) {
+ GLState *glstate = qsurface->glstate;
+ GloSurface *old_surface = qsurface->surface;
+ GloSurface *surface;
+
+ DEBUGF("resize_start\n");
+
+ glo_surface_destroy(old_surface);
+
+ surface = glo_surface_create(w, h, glstate->context);
+ qsurface->surface = surface;
+
+ // Client doesnt know surface is new - need to MakeCurrent
+ if(process->current_state == qsurface->glstate) {
+ glo_surface_makecurrent(qsurface->surface);
+ }
+ else {
+ DEBUGF("Error: Surface is not current! %p %p\n",
+ process->current_state,
+ process->current_state->current_qsurface);
+ exit(1);
+ }
+
+ glstate->current_qsurface->ready = 1;
+ DEBUGF( "resize_done\n");
+}
+
+
+void init_process_tab()
+{
+ memset(processes, 0, sizeof(processes));
+}
+
+#define ARG_TO_CHAR(x) (char)(x)
+#define ARG_TO_UNSIGNED_CHAR(x) (unsigned char)(x)
+#define ARG_TO_SHORT(x) (short)(x)
+#define ARG_TO_UNSIGNED_SHORT(x) (unsigned short)(x)
+#define ARG_TO_INT(x) (int)(x)
+#define ARG_TO_UNSIGNED_INT(x) (unsigned int)(x)
+#define ARG_TO_FLOAT(x) (*(float*)&(x))
+#define ARG_TO_DOUBLE(x) (*(double*)(x))
+
+#include "server_stub.c"
+
+//typedef void *ClientGLXDrawable;
+static inline ClientGLXDrawable to_drawable(arg_t arg)
+{
+#ifdef TARGET_X86_64
+ if (arg > (unsigned long) -1) {
+ DEBUGF( "GLXDrawable too big for this implementation\n");
+ exit(-1);
+ }
+#endif
+ return (void *) (unsigned long) arg;
+}
+
+/* ---- */
+
+/* Bind a qsurface to a context (GLState) */
+static void bind_qsurface(GLState *state,
+ QGloSurface *qsurface)
+{
+ qsurface->glstate = state;
+
+ QTAILQ_INSERT_HEAD(&state->qsurfaces, qsurface, next);
+
+ state->current_qsurface = qsurface;
+}
+
+/* Make the appropriate qsurface current for a given client_drawable */
+static int set_current_qsurface(GLState *state,
+ ClientGLXDrawable client_drawable)
+{
+ QGloSurface *qsurface;
+
+ if(state->current_qsurface && state->current_qsurface->client_drawable == client_drawable)
+ return 1;
+
+ QTAILQ_FOREACH(qsurface, &state->qsurfaces, next) {
+ if(qsurface->client_drawable == client_drawable) {
+ state->current_qsurface = qsurface;
+ return 1;
+ }
+ }
+
+ state->current_qsurface = NULL;
+
+ return 0;
+}
+
+static int get_server_texture(ProcessState *process,
+ unsigned int client_texture)
+{
+ unsigned int server_texture = 0;
+
+ if (client_texture < 32768) {
+ server_texture = process->current_state->tabTextures[client_texture];
+ } else {
+ DEBUGF( "invalid texture name %d\n", client_texture);
+ }
+ return server_texture;
+}
+
+static int get_server_buffer(ProcessState *process,
+ unsigned int client_buffer)
+{
+ unsigned int server_buffer = 0;
+
+ if (client_buffer < 32768) {
+ server_buffer = process->current_state->tabBuffers[client_buffer];
+ } else {
+ DEBUGF( "invalid buffer name %d\n", client_buffer);
+ }
+ return server_buffer;
+}
+
+
+static int get_server_list(ProcessState *process, unsigned int client_list)
+{
+ unsigned int server_list = 0;
+
+ if (client_list < 32768) {
+ server_list = process->current_state->tabLists[client_list];
+ } else {
+ DEBUGF( "invalid list name %d\n", client_list);
+ }
+ return server_list;
+}
+
+const GLXFBConfig *get_fbconfig(ProcessState *process, int client_fbconfig)
+{
+ int i;
+ int nbtotal = 0;
+
+ for (i = 0; i < process->nfbconfig; i++) {
+ assert(client_fbconfig >= 1 + nbtotal);
+ if (client_fbconfig <= nbtotal + process->fbconfigs_max[i]) {
+ return &process->fbconfigs[i][client_fbconfig - 1 - nbtotal];
+ }
+ nbtotal += process->fbconfigs_max[i];
+ }
+ return 0;
+}
+
+static int glXChooseVisualFunc(const int *attrib_list)
+{
+ if (attrib_list == NULL)
+ return 0;
+
+ int formatFlags = glo_flags_get_from_glx(attrib_list, True);
+ int i;
+ int bestConfig = 0;
+ int bestScore = -1;
+
+ for (i=0;i<DIM(FBCONFIGS);i++) {
+ int score = glo_flags_score(formatFlags, FBCONFIGS[i].formatFlags);
+ if (bestScore < 0 || score<=bestScore) {
+ bestScore = score;
+ bestConfig = i;
+ }
+ }
+
+ if (bestScore > 0)
+ DEBUGF( "Got format flags %d but we couldn't find an exactly matching config, chose %d\n", formatFlags, bestConfig);
+
+ return bestConfig;
+}
+
+static int glXGetConfigFunc(int visualid, int attrib, int *value) {
+ const GLXFBConfig *config = &FBCONFIGS[0]; // default
+ int v;
+
+ if (visualid>=0 && visualid<DIM(FBCONFIGS))
+ config = &FBCONFIGS[visualid];
+ else
+ DEBUGF( "Unknown visual ID %d\n", visualid);
+
+ v = glo_get_glx_from_flags(config->formatFlags, attrib);
+ if (value)
+ *value = v;
+ return 0;
+}
+
+static const GLXFBConfig * glXGetFBConfigsFunc(int screen, int *nelements) {
+ *nelements = DIM(FBCONFIGS);
+ return &FBCONFIGS[0];
+}
+
+static int glXGetFBConfigAttribFunc(const GLXFBConfig *fbconfig, int attrib, int *value) {
+ // TODO other enums - see http://www.opengl.org/sdk/docs/man/xhtml/glXGetFBConfigAttrib.xml
+
+ int v = glo_get_glx_from_flags(fbconfig->formatFlags, attrib);
+ if (value) *value = v;
+ return 0;
+}
+
+static const GLXFBConfig *glXChooseFBConfigFunc(int screen, const int *attrib_list, int *nelements) {
+ if (attrib_list != NULL) {
+ int formatFlags = glo_flags_get_from_glx(attrib_list, False);
+ int i;
+ int bestConfig = 0;
+ int bestScore = -1;
+
+ for (i=0;i<DIM(FBCONFIGS);i++) {
+ int score = glo_flags_score(formatFlags, FBCONFIGS[i].formatFlags);
+ if (bestScore < 0 || score<=bestScore) {
+ bestScore = score;
+ bestConfig = i;
+ }
+ }
+
+ if (bestScore > 0) {
+ DEBUGF( "Got format flags %d but we couldn't find an exactly matching config, chose %d\n", formatFlags, bestConfig);
+ }
+
+ if (nelements)
+ *nelements=1;
+
+ return &FBCONFIGS[bestConfig];
+ }
+
+ if (nelements)
+ *nelements=0;
+
+ return 0;
+}
+
+static void do_glClientActiveTextureARB(int texture)
+{
+ GET_EXT_PTR_NO_FAIL(void, glClientActiveTextureARB, (int));
+
+ if (ptr_func_glClientActiveTextureARB) {
+ ptr_func_glClientActiveTextureARB(texture);
+ }
+}
+
+static void destroy_gl_state(GLState *state)
+{
+ int i;
+ QGloSurface *qsurface, *tmp;
+
+ QTAILQ_FOREACH_SAFE(qsurface, &state->qsurfaces, next, tmp) {
+ glo_surface_destroy(qsurface->surface);
+ QTAILQ_REMOVE(&state->qsurfaces, qsurface, next);
+ g_free(qsurface);
+ }
+
+ if (state->context)
+ glo_context_destroy(state->context);
+
+ if (state->vertexPointer)
+ g_free(state->vertexPointer);
+ if (state->normalPointer)
+ g_free(state->normalPointer);
+ if (state->indexPointer)
+ g_free(state->indexPointer);
+ if (state->colorPointer)
+ g_free(state->colorPointer);
+ if (state->secondaryColorPointer)
+ g_free(state->secondaryColorPointer);
+ for (i = 0; i < NB_MAX_TEXTURES; i++) {
+ if (state->texCoordPointer[i])
+ g_free(state->texCoordPointer[i]);
+ }
+ for (i = 0; i < MY_GL_MAX_VERTEX_ATTRIBS_ARB; i++) {
+ if (state->vertexAttribPointer[i])
+ g_free(state->vertexAttribPointer[i]);
+ }
+ for (i = 0; i < MY_GL_MAX_VERTEX_ATTRIBS_NV; i++) {
+ if (state->vertexAttribPointerNV[i])
+ g_free(state->vertexAttribPointerNV[i]);
+ }
+ if (state->weightPointer)
+ g_free(state->weightPointer);
+ if (state->matrixIndexPointer)
+ g_free(state->matrixIndexPointer);
+ if (state->fogCoordPointer)
+ g_free(state->fogCoordPointer);
+ for (i = 0; i < MY_GL_MAX_VARIANT_POINTER_EXT; i++) {
+ if (state->variantPointerEXT[i])
+ g_free(state->variantPointerEXT[i]);
+ }
+ if (state->interleavedArrays)
+ g_free(state->interleavedArrays);
+ if (state->elementPointerATI)
+ g_free(state->elementPointerATI);
+}
+
+static void init_gl_state(GLState *state)
+{
+ state->textureAllocator = &state->ownTextureAllocator;
+ state->tabTextures = state->ownTabTextures;
+ state->bufferAllocator = &state->ownBufferAllocator;
+ state->tabBuffers = state->ownTabBuffers;
+ state->listAllocator = &state->ownListAllocator;
+ state->tabLists = state->ownTabLists;
+}
+
+/*
+ * Translate the nth element of list from type to GLuint.
+ */
+static GLuint translate_id(GLsizei n, GLenum type, const GLvoid *list)
+{
+ GLbyte *bptr;
+ GLubyte *ubptr;
+ GLshort *sptr;
+ GLushort *usptr;
+ GLint *iptr;
+ GLuint *uiptr;
+ GLfloat *fptr;
+
+ switch (type) {
+ case GL_BYTE:
+ bptr = (GLbyte *) list;
+ return (GLuint) *(bptr + n);
+ case GL_UNSIGNED_BYTE:
+ ubptr = (GLubyte *) list;
+ return (GLuint) *(ubptr + n);
+ case GL_SHORT:
+ sptr = (GLshort *) list;
+ return (GLuint) *(sptr + n);
+ case GL_UNSIGNED_SHORT:
+ usptr = (GLushort *) list;
+ return (GLuint) *(usptr + n);
+ case GL_INT:
+ iptr = (GLint *) list;
+ return (GLuint) *(iptr + n);
+ case GL_UNSIGNED_INT:
+ uiptr = (GLuint *) list;
+ return (GLuint) *(uiptr + n);
+ case GL_FLOAT:
+ fptr = (GLfloat *) list;
+ return (GLuint) *(fptr + n);
+ case GL_2_BYTES:
+ ubptr = ((GLubyte *) list) + 2 * n;
+ return (GLuint) (*ubptr << 8) + (GLuint) *(ubptr + 1);
+ case GL_3_BYTES:
+ ubptr = ((GLubyte *) list) + 3 * n;
+ return (GLuint) (*ubptr << 16) + (GLuint) (*(ubptr + 1) << 8) +
+ (GLuint) *(ubptr + 2);
+ case GL_4_BYTES:
+ ubptr = ((GLubyte *) list) + 4 * n;
+ return (GLuint) (*ubptr << 24) + (GLuint) (*(ubptr + 1) << 16) +
+ (GLuint) (*(ubptr + 2) << 8) + (GLuint) *(ubptr + 3);
+ default:
+ return 0;
+ }
+}
+
+GLState *_create_context(ProcessState *process, int fake_ctxt, int fake_shareList)
+{
+ // FIXMEIM - realloc? really?
+ process->glstates = g_realloc(process->glstates,
+ (process->nb_states + 1) * sizeof(GLState *));
+
+ process->glstates[process->nb_states] = g_malloc(sizeof(GLState));
+ memset(process->glstates[process->nb_states], 0, sizeof(GLState));
+
+ process->glstates[process->nb_states]->ref = 1;
+ process->glstates[process->nb_states]->fake_ctxt = fake_ctxt;
+ process->glstates[process->nb_states]->fake_shareList = fake_shareList;
+
+ init_gl_state(process->glstates[process->nb_states]);
+
+ if (fake_shareList) {
+ int i;
+
+ for (i = 0; i < process->nb_states; i++) {
+ if (process->glstates[i]->fake_ctxt == fake_shareList) {
+ process->glstates[i]->ref++;
+ process->glstates[process->nb_states]->textureAllocator =
+ process->glstates[i]->textureAllocator;
+ process->glstates[process->nb_states]->tabTextures =
+ process->glstates[i]->tabTextures;
+ process->glstates[process->nb_states]->bufferAllocator =
+ process->glstates[i]->bufferAllocator;
+ process->glstates[process->nb_states]->tabBuffers =
+ process->glstates[i]->tabBuffers;
+ process->glstates[process->nb_states]->listAllocator =
+ process->glstates[i]->listAllocator;
+ process->glstates[process->nb_states]->tabLists =
+ process->glstates[i]->tabLists;
+ break;
+ }
+ }
+ }
+ process->nb_states++;
+
+ return process->glstates[process->nb_states-1];
+}
+
+GLState *get_glstate_for_fake_ctxt(ProcessState *process, int fake_ctxt)
+{
+ int i;
+ for (i = 0; i < process->nb_states; i++)
+ if (process->glstates[i]->fake_ctxt == fake_ctxt)
+ return process->glstates[i];
+ return 0;
+}
+
+void gl_disconnect(ProcessState *process)
+{
+ int i;
+ for (i = 0; i < process->nb_states; i++) {
+ destroy_gl_state(process->glstates[i]);
+ g_free(process->glstates[i]);
+ }
+ destroy_gl_state(&process->default_state);
+ g_free(process->glstates);
+
+ if (process->cmdbuf)
+ g_free(process->cmdbuf);
+
+ for (i = 0; &processes[i] != process; i ++);
+ memmove(&processes[i], &processes[i + 1],
+ (MAX_HANDLED_PROCESS - 1 - i) * sizeof(ProcessState));
+}
+
+static const int beginend_allowed[GL_N_CALLS] = {
+#undef MAGIC_MACRO
+#define MAGIC_MACRO(name) [name ## _func] = 1,
+#include "gl_beginend.h"
+};
+
+ProcessStruct *vmgl_get_process(pid_t pid)
+{
+ ProcessState *process = NULL;
+ static int first;
+ int i;
+
+ if(!first) {
+ first = 1;
+ init_process_tab();
+ }
+
+ /* Lookup a process stuct. If there isnt one associated with this pid
+ * then we create one.
+ * process->current_state contains info on which of the guests contexts is
+ * current.
+ */
+ for (i = 0; i < MAX_HANDLED_PROCESS; i ++)
+ if (processes[i].p.process_id == pid) {
+ process = &processes[i];
+ break;
+ } else if (processes[i].p.process_id == 0) {
+ process = &processes[i];
+ memset(process, 0, sizeof(ProcessState));
+ process->p.process_id = pid;
+ init_gl_state(&process->default_state);
+ process->current_state = &process->default_state;
+ break;
+ }
+
+ if (process == NULL) {
+ DEBUGF( "Too many processes !\n");
+ exit(-1);
+ }
+
+ return (ProcessStruct *)process; // Cast is ok due to struct defn.
+}
+
+void vmgl_context_switch(ProcessStruct *p, int switch_gl_context)
+{
+ ProcessState *process = (ProcessState *)p;
+ if(switch_gl_context) {
+ if(process->current_state->current_qsurface)
+ glo_surface_makecurrent(process->current_state->current_qsurface->surface);
+ else
+ glo_surface_makecurrent(0); // should never happen
+ }
+}
+
+static const char *opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
+{
+ char *start;
+ char *ret;
+ char *p;
+ int retlen;
+ static const char *delim = " \t\n\r/";
+
+ if (prevbuf)
+ free(prevbuf);
+
+ if (s) {
+ *saveptr = s;
+ } else {
+ if (!(*saveptr) || !(*n))
+ return NULL;
+ s = *saveptr;
+ }
+
+ for (; *n && strchr(delim, *s); s++, (*n)--) {
+ if (*s == '/' && *n > 1) {
+ if (s[1] == '/') {
+ do {
+ s++, (*n)--;
+ } while (*n > 1 && s[1] != '\n' && s[1] != '\r');
+ } else if (s[1] == '*') {
+ do {
+ s++, (*n)--;
+ } while (*n > 2 && (s[1] != '*' || s[2] != '/'));
+ s++, (*n)--;
+ }
+ }
+ }
+
+ start = s;
+ for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
+ if (*n > 0)
+ s++, (*n)--;
+
+ *saveptr = s;
+
+ retlen = s - start;
+ ret = malloc(retlen + 1);
+ p = ret;
+
+ while (retlen > 0) {
+ if (*start == '/' && retlen > 1) {
+ if (start[1] == '/') {
+ do {
+ start++, retlen--;
+ } while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
+ start++, retlen--;
+ continue;
+ } else if (start[1] == '*') {
+ do {
+ start++, retlen--;
+ } while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
+ start += 3, retlen -= 3;
+ continue;
+ }
+ }
+ *(p++) = *(start++), retlen--;
+ }
+
+ *p = 0;
+ return ret;
+}
+
+static char *do_eglShaderPatch(const char *source, int length, int *patched_len)
+{
+ char *saveptr = NULL;
+ char *sp;
+ char *p = NULL;
+
+ if (!length)
+ length = strlen(source);
+
+ *patched_len = 0;
+ int patched_size = length;
+ char *patched = malloc(patched_size + 1);
+
+ if (!patched)
+ return NULL;
+
+ p = opengl_strtok(source, &length, &saveptr, NULL);
+ for (; p; p = opengl_strtok(0, &length, &saveptr, p)) {
+ if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) {
+ continue;
+ } else if (!strncmp(p, "precision", 9)) {
+ while ((p = opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
+ } else {
+ if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) {
+ p = "(gl_MaxVertexUniformComponents / 4)";
+ } else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) {
+ p = "(gl_MaxFragmentUniformComponents / 4)";
+ } else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) {
+ p = "(gl_MaxVaryingFloats / 4)";
+ }
+
+ int new_len = strlen(p);
+ if (*patched_len + new_len > patched_size) {
+ patched_size *= 2;
+ patched = realloc(patched, patched_size + 1);
+
+ if (!patched)
+ return NULL;
+ }
+
+ memcpy(patched + *patched_len, p, new_len);
+ *patched_len += new_len;
+ }
+ }
+
+ patched[*patched_len] = 0;
+ /* check that we don't leave dummy preprocessor lines */
+ for (sp = patched; *sp;) {
+ for (; *sp == ' ' || *sp == '\t'; sp++);
+ if (!strncmp(sp, "#define", 7)) {
+ for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
+ if (*p == '\n' || *p == '\r' || *p == '/') {
+ memset(sp, 0x20, 7);
+ }
+ }
+ for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
+ for (; *sp == '\n' || *sp == '\r'; sp++);
+ }
+ return patched;
+}
+
+static int
+shadersrc_gles_to_gl(GLsizei count, const char** string, char **s, const GLint* length, GLint *l)
+{
+ int i;
+
+ for(i = 0; i < count; ++i) {
+ GLint len;
+ if(length) {
+ len = length[i];
+ if (len < 0)
+ len = string[i] ? strlen(string[i]) : 0;
+ } else
+ len = string[i] ? strlen(string[i]) : 0;
+
+ if(string[i]) {
+ s[i] = do_eglShaderPatch(string[i], len, &l[i]);
+ if(!s[i]) {
+ while(i)
+ free(s[--i]);
+
+ free(l);
+ free(s);
+ return -1;
+ }
+ } else {
+ s[i] = NULL;
+ l[i] = 0;
+ }
+ }
+
+ return 0;
+}
+
+
+int do_function_call(ProcessState *process, int func_number, unsigned long *args, char *ret_string)
+{
+ union gl_ret_type ret;
+
+ Signature *signature = (Signature *) tab_opengl_calls[func_number];
+ int ret_type = signature->ret_type;
+
+ ret.s = NULL;
+
+ if (display_function_call) {
+ DEBUGF( "[%d]> %s\n", process->p.process_id,
+ tab_opengl_calls_name[func_number]);
+ }
+ TRACE( "[%d]> %s\n", process->p.process_id,
+ tab_opengl_calls_name[func_number]);
+
+ switch (func_number) {
+ case -1:
+ break;
+
+ case _resize_surface_func:
+ {
+ ClientGLXDrawable client_drawable = to_drawable(args[0]);
+ QGloSurface *qsurface = get_qsurface_from_client_drawable(
+ process->current_state, client_drawable);
+
+ // We have to assume the current context here
+ // since we assume that a drawable must belong to a specific context
+ resize_surface(process, qsurface, (int)args[1], (int)args[2]);
+ break;
+
+ }
+
+ case _render_surface_func:
+ {
+ ClientGLXDrawable client_drawable = to_drawable(args[0]);
+ QGloSurface *qsurface = get_qsurface_from_client_drawable(
+ process->current_state, client_drawable);
+ int bpp = (int)args[1];
+ int stride = (int)args[2];
+ char *render_buffer = (char*)args[3];
+
+// DEBUGF( "win: %08x stride: %d buf: %08x cl_dr: %08x qsurf: %08x\n", args[0], args[1], args[2], client_drawable, qsurface);
+
+ // We have to assume the current context here
+ // since we assume that a drawable must belong to a specific context
+ render_surface(qsurface, bpp, stride, render_buffer);
+ break;
+
+ }
+
+ case glXWaitGL_func:
+ {
+ glFinish(); //glXWaitGL();
+ ret.i = 0;
+ break;
+ }
+
+ case glXWaitX_func:
+ {
+ // FIXME GW Maybe we should just do this on the server?
+ //glXWaitX();
+ ret.i = 0;
+ break;
+ }
+
+ case glXChooseVisual_func:
+ {
+ ret.i = glXChooseVisualFunc((int *) &args[2]);
+ break;
+ }
+
+ case glXQueryExtensionsString_func:
+ {
+ ret.s = supported_glx_extensions();//glXQueryExtensionsString(dpy, 0);
+ break;
+ }
+
+ case glXQueryServerString_func:
+ {
+ switch (args[2]) {
+ case GLX_VENDOR : ret.s = FAKE_GLX_VENDOR; break;
+ case GLX_VERSION : ret.s = FAKE_GLX_VERSION_STRING; break;
+ case GLX_EXTENSIONS : ret.s = supported_glx_extensions(); break;
+ default: ret.s = 0;
+ }
+ break;
+ }
+
+ case glXGetClientString_func:
+ {
+ switch (args[1]) {
+ case GLX_VENDOR : ret.s = FAKE_GLX_VENDOR; break;
+ case GLX_VERSION : ret.s = FAKE_GLX_VERSION_STRING; break;
+ case GLX_EXTENSIONS : ret.s = "GLX_ARB_get_proc_address "; break;
+ default: ret.s = 0;
+ }
+ break;
+ }
+
+ case glXGetScreenDriver_func:
+ {
+ // FIXME GW What is this? not documented anywhere!!
+ //GET_EXT_PTR(const char *, glXGetScreenDriver, (Display *, int));
+ //ret.s = ptr_func_glXGetScreenDriver(dpy, 0);
+ ret.s = "";
+ break;
+ }
+
+ case glXGetDriverConfig_func:
+ {
+ // FIXME GW What is this? not documented anywhere!!
+ //GET_EXT_PTR(const char *, glXGetDriverConfig, (const char *));
+ //ret.s = ptr_func_glXGetDriverConfig((const char *) args[0]);
+ ret.s = "";
+ break;
+ }
+
+ case glXCreateContext_func:
+ {
+ int visualid = (int) args[1];
+ int fake_shareList = (int) args[2];
+
+ if (display_function_call)
+ DEBUGF( "visualid=%d, fake_shareList=%d\n", visualid,
+ fake_shareList);
+
+ GLState *shareListState = get_glstate_for_fake_ctxt(process, fake_shareList);
+ int fake_ctxt = ++process->next_available_context_number;
+
+ ret.i = fake_ctxt;
+
+ // Work out format flags from visual id
+ int formatFlags = GLO_FF_DEFAULT;
+ if (visualid>=0 && visualid<DIM(FBCONFIGS))
+ formatFlags = FBCONFIGS[visualid].formatFlags;
+
+ GLState *state = _create_context(process, fake_ctxt, fake_shareList);
+ state->context = glo_context_create(formatFlags,
+ (GloContext*)shareListState?shareListState->context:0);
+
+ DEBUGF( " created context %p for %08x\n", state, fake_ctxt);
+ break;
+ }
+
+
+ case glXCreateNewContext_func:
+ {
+ int client_fbconfig = args[1];
+
+ ret.i = 0;
+ const GLXFBConfig *fbconfig = get_fbconfig(process, client_fbconfig);
+
+ if (fbconfig) {
+ int fake_shareList = args[3];
+ GLState *shareListState = get_glstate_for_fake_ctxt(process, fake_shareList);
+
+ process->next_available_context_number++;
+ int fake_ctxt = process->next_available_context_number;
+ ret.i = fake_ctxt;
+
+ GLState *state = _create_context(process, fake_ctxt, fake_shareList);
+ state->context = glo_context_create(fbconfig->formatFlags,
+ shareListState?shareListState->context:0); // FIXME GW get from fbconfig
+ }
+ break;
+ }
+
+ case glXCopyContext_func:
+ {
+ DEBUGF( " glXCopyContext not supported (does anything use it?)\n");
+ break;
+ }
+
+ case glXDestroyContext_func:
+ {
+ int fake_ctxt = (int) args[1];
+
+ if (display_function_call)
+ DEBUGF( "fake_ctxt=%d\n", fake_ctxt);
+
+ int i;
+ for (i = 0; i < process->nb_states; i ++) {
+ if (process->glstates[i]->fake_ctxt == fake_ctxt) {
+ // this was our GLState...
+ process->current_state = &process->default_state;
+
+ int fake_shareList =
+ process->glstates[i]->fake_shareList;
+ process->glstates[i]->ref--;
+ if (process->glstates[i]->ref == 0) {
+ DEBUGF(
+ "destroy_gl_state fake_ctxt = %d\n",
+ process->glstates[i]->fake_ctxt);
+ destroy_gl_state(process->glstates[i]);
+ g_free(process->glstates[i]);
+ memmove(&process->glstates[i],
+ &process->glstates[i + 1],
+ (process->nb_states - i - 1) *
+ sizeof(GLState *));
+ process->nb_states --;
+ }
+
+ if (fake_shareList) {
+ for (i = 0; i < process->nb_states; i++) {
+ if (process->glstates[i]->fake_ctxt ==
+ fake_shareList) {
+ process->glstates[i]->ref--;
+ if (process->glstates[i]->ref == 0) {
+ DEBUGF(
+ "destroy_gl_state fake_ctxt = %d\n",
+ process->glstates[i]->
+ fake_ctxt);
+ destroy_gl_state(process->
+ glstates[i]);
+ g_free(process->glstates[i]);
+ memmove(&process->glstates[i],
+ &process->glstates[i + 1],
+ (process->nb_states - i - 1) *
+ sizeof(GLState *));
+ process->nb_states --;
+ }
+ break;
+ }
+ }
+ }
+
+ break;
+ }
+ }
+ break;
+ }
+
+ case glXQueryVersion_func:
+ {
+ int *major = (int *) args[1];
+ int *minor = (int *) args[2];
+ //ret.i = glXQueryVersion(dpy, (int *) args[1], (int *) args[2]);
+ if (major) *major=FAKE_GLX_VERSION_MAJOR;
+ if (minor) *minor=FAKE_GLX_VERSION_MINOR;
+ ret.i = True;
+ break;
+ }
+
+ case glGetString_func:
+ {
+ switch (args[0]) {
+ case GL_VENDOR:
+ ret.s = FAKE_GL_VENDOR;
+ break;
+ case GL_RENDERER:
+ ret.s = FAKE_GL_RENDERER;
+ break;
+ case GL_VERSION:
+ ret.s = FAKE_GL_VERSION;
+ break;
+ case GL_EXTENSIONS:
+ ret.s = compute_gl_extensions();
+ break;
+ case GL_SHADING_LANGUAGE_VERSION:
+ if(FAKE_GL_MAJOR < 2) {
+ ret.s = "";
+ break;
+ }
+ // Fall through.
+ default:
+ ret.s = (char *) glGetString(args[0]);
+ break;
+ }
+ break;
+ }
+
+ case glXMakeCurrent_func:
+ {
+ ClientGLXDrawable client_drawable = to_drawable(args[1]);
+ int fake_ctxt = (int) args[2];
+ GLState *glstate = NULL;
+
+// DEBUGF( "Makecurrent: fake_ctx=%d client_drawable=%08x\n", fake_ctxt, client_drawable);
+
+ if (client_drawable == 0 && fake_ctxt == 0) {
+ /* Release context */
+ if(process->current_state->current_qsurface)
+ process->current_state->current_qsurface->ref--;
+ process->current_state = &process->default_state;
+
+// DEBUGF( " --release\n");
+ glo_surface_makecurrent(0);
+ } else { /* Lookup GLState struct for this context */
+ glstate = get_glstate_for_fake_ctxt(process, fake_ctxt);
+ if (!glstate) {
+ DEBUGF( " --invalid fake_ctxt (%d)!\n", fake_ctxt);
+ } else {
+ if(!set_current_qsurface(glstate, client_drawable)) {
+ // If there is no surface, create one.
+ QGloSurface *qsurface = calloc(1, sizeof(QGloSurface));
+ qsurface->surface = glo_surface_create(4, 4,
+ glstate->context);
+ qsurface->client_drawable = client_drawable;
+ qsurface->ref = 1;
+
+ bind_qsurface(glstate, qsurface);
+// DEBUGF( " --Client drawable not found, create new surface: %16x %16lx\n", (unsigned int)qsurface, (unsigned long int)client_drawable);
+
+ }
+ else {
+// DEBUGF( " --Client drawable found, using surface: %16x %16lx\n", (unsigned int)glstate->current_qsurface, (unsigned long int)client_drawable);
+ }
+
+ process->current_state = glstate;
+
+ ret.i = glo_surface_makecurrent(glstate->current_qsurface->surface);
+ }
+ }
+ break;
+ }
+
+ case glXSwapBuffers_func:
+ {
+ // Does nothing - window data is copied via render_surface()
+ break;
+ }
+ case glXIsDirect_func:
+ {
+ // int fake_ctxt = (int) args[1];
+
+ // Does this go direct and skip the X server? We'll just say
+ // yes for now.
+ ret.c = True;
+
+ break;
+ }
+
+ case glXGetConfig_func:
+ {
+ int visualid = args[1];
+ ret.i = glXGetConfigFunc(visualid, args[2], (int *) args[3]);
+ break;
+ }
+
+ case glXGetConfig_extended_func:
+ {
+ int visualid = args[1];
+ int n = args[2];
+ int i;
+ int *attribs = (int *) args[3];
+ int *values = (int *) args[4];
+ int *res = (int *) args[5];
+
+ for (i = 0; i < n; i++) {
+ res[i] = glXGetConfigFunc(visualid, attribs[i], &values[i]);
+ }
+ break;
+ }
+
+ case glXUseXFont_func:
+ {
+ /* implementation is client-side only :-) */
+ break;
+ }
+
+ case glXQueryExtension_func:
+ {
+ int *errorBase = (int *) args[1];
+ int *eventBase = (int *) args[2];
+ if (errorBase) *errorBase = 0; /* FIXME GW */
+ if (eventBase) *eventBase = 0; /* FIXME GW */
+ ret.i = True;
+ break;
+ }
+
+ case glXChooseFBConfig_func:
+ {
+ if (process->nfbconfig == MAX_FBCONFIG) {
+ *(int *) args[3] = 0;
+ ret.i = 0;
+ } else {
+ const GLXFBConfig *fbconfigs =
+ glXChooseFBConfigFunc(args[1], (int *) args[2], (int *) args[3]);
+ if (fbconfigs) {
+ process->fbconfigs[process->nfbconfig] = fbconfigs;
+ process->fbconfigs_max[process->nfbconfig] =
+ *(int *) args[3];
+ process->nfbconfig++;
+ ret.i = 1 + process->nfbconfig_total;
+ process->nfbconfig_total +=
+ process->fbconfigs_max[process->nfbconfig];
+ } else {
+ ret.i = 0;
+ }
+ }
+ break;
+ }
+ case glXGetFBConfigs_func:
+ {
+ if (process->nfbconfig == MAX_FBCONFIG) {
+ *(int *) args[2] = 0;
+ ret.i = 0;
+ } else {
+ const GLXFBConfig *fbconfigs =
+ glXGetFBConfigsFunc(args[1], (int *) args[2]);
+ if (fbconfigs) {
+ process->fbconfigs[process->nfbconfig] = fbconfigs;
+ process->fbconfigs_max[process->nfbconfig] =
+ *(int *) args[2];
+ process->nfbconfig++;
+ ret.i = 1 + process->nfbconfig_total;
+ process->nfbconfig_total +=
+ process->fbconfigs_max[process->nfbconfig];
+ } else {
+ ret.i = 0;
+ }
+ }
+ break;
+ }
+ case glXGetFBConfigAttrib_func:
+ {
+ int client_fbconfig = args[1];
+
+ ret.i = 0;
+ const GLXFBConfig *fbconfig = get_fbconfig(process, client_fbconfig);
+
+ if (fbconfig)
+ ret.i =
+ glXGetFBConfigAttribFunc(fbconfig, args[2], (int *) args[3]);
+ break;
+ }
+
+ case glXGetFBConfigAttrib_extended_func:
+ {
+ int client_fbconfig = args[1];
+ int n = args[2];
+ int i;
+ int *attribs = (int *) args[3];
+ int *values = (int *) args[4];
+ int *res = (int *) args[5];
+ const GLXFBConfig *fbconfig = get_fbconfig(process, client_fbconfig);
+
+ for (i = 0; i < n; i++) {
+ if (fbconfig) {
+ res[i] =
+ glXGetFBConfigAttribFunc(fbconfig, attribs[i], &values[i]);
+ } else {
+ res[i] = 0;
+ }
+ }
+ break;
+ }
+ case glXQueryContext_func:
+ {
+ DEBUGF( "glXQueryContext not implemented\n");
+ ret.i = 0;
+#if 0 //GW
+ GET_EXT_PTR(int, glXQueryContext,
+ (Display *, GLXContext, int, int *));
+ int fake_ctxt = (int) args[1];
+
+ if (display_function_call)
+ DEBUGF( "fake_ctx=%i\n", fake_ctxt);
+ GLXContext ctxt =
+ get_association_fakecontext_glxcontext(process, fake_ctxt);
+ if (ctxt == NULL) {
+ DEBUGF( "invalid fake_ctxt (%i) !\n", fake_ctxt);
+ ret.i = 0;
+ } else {
+ ret.i =
+ ptr_func_glXQueryContext(dpy, ctxt, args[2],
+ (int *) args[3]);
+ }
+#endif
+ break;
+ }
+
+ case glXQueryDrawable_func:
+ {
+ // TODO GW one of:
+ // GLX_WIDTH, GLX_HEIGHT, GLX_PRESERVED_CONTENTS, GLX_LARGEST_PBUFFER, GLX_FBCONFIG_ID
+ DEBUGF( "FIXME: glXQueryDrawable not implemented\n");
+ ret.i = 0;
+#if 0 //GW
+ GET_EXT_PTR(void, glXQueryDrawable,
+ (Display *, GLXDrawable, int, int *));
+ ClientGLXDrawable client_drawable = to_drawable(args[1]);
+ GLXDrawable drawable =
+ get_association_clientdrawable_serverdrawable(
+ glstate, client_drawable);
+
+ if (display_function_call)
+ DEBUGF( "client_drawable=%p\n",
+ client_drawable);
+
+ if (!drawable)
+ DEBUGF( "invalid client_drawable (%p) !\n",
+ client_drawable);
+ else
+ ptr_func_glXQueryDrawable(dpy, drawable,
+ args[2], (int *) args[3]);
+#endif
+ break;
+ }
+ case glXGetVisualFromFBConfig_func:
+ {
+ int client_fbconfig = args[1];
+
+ ret.i = 0;
+ const GLXFBConfig *fbconfig = get_fbconfig(process, client_fbconfig);
+
+ if (fbconfig) {
+ // we tread visualid as the index into the fbconfigs array
+ ret.i = &FBCONFIGS[0] - fbconfig;
+ if (display_function_call)
+ DEBUGF( "visualid = %d\n", ret.i);
+ }
+ break;
+ }
+ case glXSwapIntervalSGI_func:
+ {
+ /*GET_EXT_PTR(int, glXSwapIntervalSGI, (int));
+ ret.i = ptr_func_glXSwapIntervalSGI(args[0]);*/
+ ret.i = 0;
+ break;
+ }
+
+ case glXGetProcAddress_fake_func:
+ {
+// if (display_function_call)
+ //DEBUGF( "glXGetProcAddress %s ", (char *) args[0]);
+ ret.i = glo_getprocaddress((const char *) args[0]) != NULL;
+ // DEBUGF( " == %08x\n", ret.i);
+ ret.i = 0;
+ break;
+ }
+
+ case glXGetProcAddress_global_fake_func:
+ {
+ int nbElts = args[0];
+ char *huge_buffer = (char *) args[1];
+ char *result = (char *) args[2];
+ int i;
+
+ for (i = 0; i < nbElts; i++) {
+ int len = strlen(huge_buffer);
+ //DEBUGF( "glXGetProcAddress_global %s ", (char *)huge_buffer);
+ result[i] =
+ glo_getprocaddress((const char *) huge_buffer) !=
+ NULL;
+ huge_buffer += len + 1;
+ }
+ break;
+ }
+/* Begin of texture stuff */
+ case glBindTexture_func:
+ case glBindTextureEXT_func:
+ {
+ int target = args[0];
+ unsigned int client_texture = args[1];
+ unsigned int server_texture;
+
+ if (client_texture == 0) {
+ glBindTexture(target, 0);
+ } else {
+ alloc_value(process->current_state->textureAllocator,
+ client_texture);
+ server_texture =
+ process->current_state->tabTextures[client_texture];
+ if (server_texture == 0) {
+ glGenTextures(1, &server_texture);
+ process->current_state->tabTextures[client_texture] =
+ server_texture;
+ }
+ glBindTexture(target, server_texture);
+ }
+ break;
+ }
+
+ case glGenTextures_fake_func:
+ {
+ GET_EXT_PTR(void, glGenTextures, (GLsizei n, GLuint *textures));
+ int i;
+ int n = args[0];
+ unsigned int *clientTabTextures = g_malloc(n * sizeof(int));
+ unsigned int *serverTabTextures = g_malloc(n * sizeof(int));
+
+ alloc_range(process->current_state->textureAllocator, n,
+ clientTabTextures);
+
+ ptr_func_glGenTextures(n, serverTabTextures);
+ for (i = 0; i < n; i++) {
+ process->current_state->tabTextures[clientTabTextures[i]] =
+ serverTabTextures[i];
+ }
+
+ g_free(clientTabTextures);
+ g_free(serverTabTextures);
+ break;
+ }
+
+
+ case glDeleteTextures_func:
+ {
+ GET_EXT_PTR(void, glDeleteTextures,
+ (GLsizei n, const GLuint *textures));
+ int i;
+ int n = args[0];
+ unsigned int *clientTabTextures = (unsigned int *) args[1];
+
+ delete_range(process->current_state->textureAllocator, n,
+ clientTabTextures);
+
+ unsigned int *serverTabTextures = g_malloc(n * sizeof(int));
+
+ for (i = 0; i < n; i++) {
+ serverTabTextures[i] =
+ get_server_texture(process, clientTabTextures[i]);
+ }
+ ptr_func_glDeleteTextures(n, serverTabTextures);
+ for (i = 0; i < n; i++) {
+ process->current_state->tabTextures[clientTabTextures[i]] = 0;
+ }
+ g_free(serverTabTextures);
+ break;
+ }
+
+ case glPrioritizeTextures_func:
+ {
+ GET_EXT_PTR(void, glPrioritizeTextures,
+ (GLsizei n, const GLuint *textures,
+ const GLclampf *priorities));
+
+ int i;
+ int n = args[0];
+ unsigned int *textures = (unsigned int *) args[1];
+
+ for (i = 0; i < n; i++) {
+ textures[i] = get_server_texture(process, textures[i]);
+ }
+ ptr_func_glPrioritizeTextures(n, textures,
+ (const GLclampf *) args[2]);
+ break;
+ }
+
+ case glAreTexturesResident_func:
+ {
+ GET_EXT_PTR(void, glAreTexturesResident,
+ (GLsizei n, const GLuint *textures,
+ GLboolean *residences));
+ int i;
+ int n = args[0];
+ unsigned int *textures = (unsigned int *) args[1];
+
+ for (i = 0; i < n; i++) {
+ textures[i] = get_server_texture(process, textures[i]);
+ }
+ ptr_func_glAreTexturesResident(n, textures,
+ (GLboolean *) args[2]);
+ break;
+ }
+
+ case glIsTexture_func:
+ case glIsTextureEXT_func:
+ {
+ GET_EXT_PTR(GLboolean, glIsTexture, (GLuint texture));
+ unsigned int client_texture = args[0];
+ unsigned int server_texture =
+ get_server_texture(process, client_texture);
+ if (server_texture)
+ ret.c = ptr_func_glIsTexture(server_texture);
+ else
+ ret.c = 0;
+ break;
+ }
+
+ case glFramebufferTexture1DEXT_func:
+ {
+ GET_EXT_PTR(void, glFramebufferTexture1DEXT,
+ (int, int, int, int, int));
+ unsigned int client_texture = args[3];
+ unsigned int server_texture =
+ get_server_texture(process, client_texture);
+ if (server_texture)
+ ptr_func_glFramebufferTexture1DEXT(args[0], args[1], args[2],
+ server_texture, args[4]);
+ break;
+ }
+
+ case glFramebufferTexture2D_func:
+ //DEBUGF( "wooooot!\n");
+ case glFramebufferTexture2DEXT_func:
+ {
+ GET_EXT_PTR(void, glFramebufferTexture2DEXT,
+ (int, int, int, int, int));
+ unsigned int client_texture = args[3];
+ unsigned int server_texture =
+ get_server_texture(process, client_texture);
+ if (server_texture)
+ ptr_func_glFramebufferTexture2DEXT(args[0], args[1], args[2],
+ server_texture, args[4]);
+ break;
+ }
+
+ case glFramebufferTexture3DEXT_func:
+ {
+ GET_EXT_PTR(void, glFramebufferTexture3DEXT,
+ (int, int, int, int, int, int));
+ unsigned int client_texture = args[3];
+ unsigned int server_texture =
+ get_server_texture(process, client_texture);
+ if (server_texture)
+ ptr_func_glFramebufferTexture3DEXT(args[0], args[1], args[2],
+ server_texture, args[4],
+ args[5]);
+ break;
+ }
+/* End of texture stuff */
+
+/* Begin of list stuff */
+ case glIsList_func:
+ {
+ unsigned int client_list = args[0];
+ unsigned int server_list = get_server_list(process, client_list);
+
+ if (server_list)
+ ret.c = glIsList(server_list);
+ else
+ ret.c = 0;
+ break;
+ }
+
+ case glDeleteLists_func:
+ {
+ int i;
+ unsigned int first_client = args[0];
+ int n = args[1];
+
+ unsigned int first_server =
+ get_server_list(process, first_client);
+ for (i = 0; i < n; i++) {
+ if (get_server_list(process, first_client + i) !=
+ first_server + i)
+ break;
+ }
+ if (i == n) {
+ glDeleteLists(first_server, n);
+ } else {
+ for (i = 0; i < n; i++) {
+ glDeleteLists(get_server_list(process, first_client + i),
+ 1);
+ }
+ }
+
+ for (i = 0; i < n; i++) {
+ process->current_state->tabLists[first_client + i] = 0;
+ }
+ delete_consecutive_values(process->current_state->listAllocator,
+ first_client, n);
+ break;
+ }
+
+ case glGenLists_fake_func:
+ {
+ int i;
+ int n = args[0];
+ unsigned int server_first = glGenLists(n);
+
+ if (server_first) {
+ unsigned int client_first =
+ alloc_range(process->current_state->listAllocator, n,
+ NULL);
+ for (i = 0; i < n; i++) {
+ process->current_state->tabLists[client_first + i] =
+ server_first + i;
+ }
+ }
+ break;
+ }
+
+ case glNewList_func:
+ {
+ unsigned int client_list = args[0];
+ int mode = args[1];
+
+ alloc_value(process->current_state->listAllocator, client_list);
+ unsigned int server_list = get_server_list(process, client_list);
+
+ if (server_list == 0) {
+ server_list = glGenLists(1);
+ process->current_state->tabLists[client_list] = server_list;
+ }
+ glNewList(server_list, mode);
+ break;
+ }
+
+ case glCallList_func:
+ {
+ unsigned int client_list = args[0];
+ unsigned int server_list = get_server_list(process, client_list);
+
+ glCallList(server_list);
+ break;
+ }
+
+ case glCallLists_func:
+ {
+ int i;
+ int n = args[0];
+ int type = args[1];
+ const GLvoid *lists = (const GLvoid *) args[2];
+ int *new_lists = g_malloc(sizeof(int) * n);
+
+ for (i = 0; i < n; i++) {
+ new_lists[i] =
+ get_server_list(process, translate_id(i, type, lists));
+ }
+ glCallLists(n, GL_UNSIGNED_INT, new_lists);
+ g_free(new_lists);
+ break;
+ }
+
+
+/* End of list stuff */
+
+/* Begin of buffer stuff */
+ case glBindBufferARB_func:
+ {
+ GET_EXT_PTR(void, glBindBufferARB, (int, int));
+ int target = args[0];
+ unsigned int client_buffer = args[1];
+ unsigned int server_buffer;
+
+ if (client_buffer == 0) {
+ ptr_func_glBindBufferARB(target, 0);
+ } else {
+ server_buffer = get_server_buffer(process, client_buffer);
+ ptr_func_glBindBufferARB(target, server_buffer);
+ }
+ break;
+ }
+
+ case glGenBuffersARB_fake_func:
+ {
+ GET_EXT_PTR(void, glGenBuffersARB, (int, unsigned int *));
+ int i;
+ int n = args[0];
+ unsigned int *clientTabBuffers = g_malloc(n * sizeof(int));
+ unsigned int *serverTabBuffers = g_malloc(n * sizeof(int));
+
+ alloc_range(process->current_state->bufferAllocator, n,
+ clientTabBuffers);
+
+ ptr_func_glGenBuffersARB(n, serverTabBuffers);
+ for (i = 0; i < n; i++) {
+ process->current_state->tabBuffers[clientTabBuffers[i]] =
+ serverTabBuffers[i];
+ }
+
+ g_free(clientTabBuffers);
+ g_free(serverTabBuffers);
+ break;
+ }
+
+
+ case glDeleteBuffersARB_func:
+ {
+ GET_EXT_PTR(void, glDeleteBuffersARB, (int, int *));
+ int i;
+ int n = args[0];
+ unsigned int *clientTabBuffers = (unsigned int *) args[1];
+
+ delete_range(process->current_state->bufferAllocator, n,
+ clientTabBuffers);
+
+ int *serverTabBuffers = g_malloc(n * sizeof(int));
+
+ for (i = 0; i < n; i++) {
+ serverTabBuffers[i] =
+ get_server_buffer(process, clientTabBuffers[i]);
+ }
+ ptr_func_glDeleteBuffersARB(n, serverTabBuffers);
+ for (i = 0; i < n; i++) {
+ process->current_state->tabBuffers[clientTabBuffers[i]] = 0;
+ }
+ g_free(serverTabBuffers);
+ break;
+ }
+
+ case glIsBufferARB_func:
+ {
+ GET_EXT_PTR(int, glIsBufferARB, (int));
+ unsigned int client_buffer = args[0];
+ unsigned int server_buffer =
+ get_server_buffer(process, client_buffer);
+ if (server_buffer)
+ ret.i = ptr_func_glIsBufferARB(server_buffer);
+ else
+ ret.i = 0;
+ break;
+ }
+
+/* End of buffer stuff */
+
+ case glShaderSourceARB_fake_func:
+ {
+ GET_EXT_PTR(void, glShaderSourceARB, (int, int, char **, void *));
+ int size = args[1];
+ int i;
+ int acc_length = 0;
+ GLcharARB **tab_prog = g_malloc(size * sizeof(GLcharARB *));
+ int *tab_length = (int *) args[3];
+
+ for (i = 0; i < size; i++) {
+ tab_prog[i] = ((GLcharARB *) args[2]) + acc_length;
+ acc_length += tab_length[i];
+ }
+ ptr_func_glShaderSourceARB(args[0], args[1], tab_prog,
+ tab_length);
+ g_free(tab_prog);
+ break;
+ }
+
+ case glShaderSource_fake_func:
+ {
+ GET_EXT_PTR(void, glShaderSource, (int, int, char **, void *));
+ int size = args[1];
+ int i;
+ int acc_length = 0;
+ GLcharARB **tab_prog = g_malloc(size * sizeof(GLcharARB *));
+ int *tab_length = (int *) args[3];
+
+ char **tab_prog_new;
+ GLint *tab_length_new;
+
+ tab_prog_new = malloc(args[1]* sizeof(char*));
+ tab_length_new = malloc(args[1]* sizeof(GLint));
+
+ memset(tab_prog_new, 0, args[1] * sizeof(char*));
+ memset(tab_length_new, 0, args[1] * sizeof(GLint));
+
+
+ for (i = 0; i < size; i++) {
+ tab_prog[i] = ((GLcharARB *) args[2]) + acc_length;
+ acc_length += tab_length[i];
+ }
+
+ shadersrc_gles_to_gl(args[1], tab_prog, tab_prog_new, tab_length, tab_length_new);
+
+ if (!tab_prog_new || !tab_length_new)
+ break;
+
+ ptr_func_glShaderSource(args[0], args[1], tab_prog_new, tab_length_new);
+
+ for (i = 0; i < args[1]; i++)
+ free(tab_prog_new[i]);
+ free(tab_prog_new);
+ free(tab_length_new);
+
+ free(tab_prog);
+
+ break;
+ }
+
+ case glVertexPointer_fake_func:
+ {
+ int offset = args[0];
+ int size = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset,
+ (void *) args[5], bytes_size);
+ /* DEBUGF( "glVertexPointer_fake_func size=%d, type=%d,
+ * stride=%d, byte_size=%d\n", size, type, stride, bytes_size); */
+ glVertexPointer(size, type, stride,
+ process->current_state->vertexPointer);
+ break;
+ }
+
+ case glNormalPointer_fake_func:
+ {
+ int offset = args[0];
+ int type = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->normalPointerSize =
+ MAX(process->current_state->normalPointerSize,
+ offset + bytes_size);
+ process->current_state->normalPointer =
+ g_realloc(process->current_state->normalPointer,
+ process->current_state->normalPointerSize);
+ memcpy(process->current_state->normalPointer + offset,
+ (void *) args[4], bytes_size);
+ // DEBUGF( "glNormalPointer_fake_func type=%d, stride=%d,
+ // byte_size=%d\n", type, stride, bytes_size);
+ glNormalPointer(type, stride,
+ process->current_state->normalPointer);
+ break;
+ }
+
+ case glIndexPointer_fake_func:
+ {
+ int offset = args[0];
+ int type = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->indexPointerSize =
+ MAX(process->current_state->indexPointerSize,
+ offset + bytes_size);
+ process->current_state->indexPointer =
+ g_realloc(process->current_state->indexPointer,
+ process->current_state->indexPointerSize);
+ memcpy(process->current_state->indexPointer + offset,
+ (void *) args[4], bytes_size);
+ // DEBUGF( "glIndexPointer_fake_func type=%d, stride=%d,
+ // byte_size=%d\n", type, stride, bytes_size);
+ glIndexPointer(type, stride,
+ process->current_state->indexPointer);
+ break;
+ }
+
+ case glEdgeFlagPointer_fake_func:
+ {
+ int offset = args[0];
+ int stride = args[1];
+ int bytes_size = args[2];
+
+ process->current_state->edgeFlagPointerSize =
+ MAX(process->current_state->edgeFlagPointerSize,
+ offset + bytes_size);
+ process->current_state->edgeFlagPointer =
+ g_realloc(process->current_state->edgeFlagPointer,
+ process->current_state->edgeFlagPointerSize);
+ memcpy(process->current_state->edgeFlagPointer + offset,
+ (void *) args[3], bytes_size);
+ // DEBUGF( "glEdgeFlagPointer_fake_func stride = %d,
+ // bytes_size=%d\n", stride, bytes_size);
+ glEdgeFlagPointer(stride,
+ process->current_state->edgeFlagPointer);
+ break;
+ }
+
+ case glVertexAttribPointerARB_fake_func:
+ {
+ GET_EXT_PTR(void, glVertexAttribPointerARB,
+ (int, int, int, int, int, void *));
+ int offset = args[0];
+ int index = args[1];
+ int size = args[2];
+ int type = args[3];
+ int normalized = args[4];
+ int stride = args[5];
+ int bytes_size = args[6];
+
+ process->current_state->vertexAttribPointerSize[index] =
+ MAX(process->current_state->vertexAttribPointerSize[index],
+ offset + bytes_size);
+ process->current_state->vertexAttribPointer[index] =
+ g_realloc(process->current_state->vertexAttribPointer[index],
+ process->current_state->
+ vertexAttribPointerSize[index]);
+ memcpy(process->current_state->vertexAttribPointer[index] +
+ offset, (void *) args[7], bytes_size);
+ ptr_func_glVertexAttribPointerARB(index, size, type, normalized,
+ stride,
+ process->current_state->
+ vertexAttribPointer[index]);
+ break;
+ }
+
+ case glVertexAttribPointerNV_fake_func:
+ {
+ GET_EXT_PTR(void, glVertexAttribPointerNV,
+ (int, int, int, int, void *));
+ int offset = args[0];
+ int index = args[1];
+ int size = args[2];
+ int type = args[3];
+ int stride = args[4];
+ int bytes_size = args[5];
+
+ process->current_state->vertexAttribPointerNVSize[index] =
+ MAX(process->current_state->vertexAttribPointerNVSize[index],
+ offset + bytes_size);
+ process->current_state->vertexAttribPointerNV[index] =
+ g_realloc(process->current_state->vertexAttribPointerNV[index],
+ process->current_state->
+ vertexAttribPointerNVSize[index]);
+ memcpy(process->current_state->vertexAttribPointerNV[index] +
+ offset, (void *) args[6], bytes_size);
+ ptr_func_glVertexAttribPointerNV(index, size, type, stride,
+ process->current_state->
+ vertexAttribPointerNV[index]);
+ break;
+ }
+
+ case glColorPointer_fake_func:
+ {
+ int offset = args[0];
+ int size = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->colorPointerSize =
+ MAX(process->current_state->colorPointerSize,
+ offset + bytes_size);
+ process->current_state->colorPointer =
+ g_realloc(process->current_state->colorPointer,
+ process->current_state->colorPointerSize);
+ memcpy(process->current_state->colorPointer + offset,
+ (void *) args[5], bytes_size);
+ // DEBUGF( "glColorPointer_fake_func bytes_size = %d\n",
+ // bytes_size);
+ glColorPointer(size, type, stride,
+ process->current_state->colorPointer);
+
+ break;
+ }
+
+ case glSecondaryColorPointer_fake_func:
+ {
+ GET_EXT_PTR(void, glSecondaryColorPointer,
+ (int, int, int, void *));
+ int offset = args[0];
+ int size = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->secondaryColorPointerSize =
+ MAX(process->current_state->secondaryColorPointerSize,
+ offset + bytes_size);
+ process->current_state->secondaryColorPointer =
+ g_realloc(process->current_state->secondaryColorPointer,
+ process->current_state->secondaryColorPointerSize);
+ memcpy(process->current_state->secondaryColorPointer + offset,
+ (void *) args[5], bytes_size);
+ // DEBUGF( "glSecondaryColorPointer_fake_func bytes_size
+ // = %d\n", bytes_size);
+ ptr_func_glSecondaryColorPointer(size, type, stride,
+ process->current_state->
+ secondaryColorPointer);
+
+ break;
+ }
+
+ case glPushClientAttrib_func:
+ {
+ int mask = args[0];
+
+ if (process->current_state->clientStateSp <
+ MAX_CLIENT_STATE_STACK_SIZE) {
+ process->current_state->clientStateStack[process->
+ current_state->
+ clientStateSp].mask =
+ mask;
+ if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
+ process->current_state->clientStateStack[process->
+ current_state->
+ clientStateSp].
+ activeTextureIndex =
+ process->current_state->activeTextureIndex;
+ }
+ process->current_state->clientStateSp++;
+ }
+ glPushClientAttrib(mask);
+ break;
+ }
+
+ case glPopClientAttrib_func:
+ {
+ if (process->current_state->clientStateSp > 0) {
+ process->current_state->clientStateSp--;
+ if (process->current_state->
+ clientStateStack[process->current_state->clientStateSp].
+ mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
+ process->current_state->activeTextureIndex =
+ process->current_state->clientStateStack[process->
+ current_state->
+ clientStateSp].
+ activeTextureIndex;
+ }
+ }
+ glPopClientAttrib();
+ break;
+ }
+
+ case glClientActiveTexture_func:
+ case glClientActiveTextureARB_func:
+ {
+ int activeTexture = args[0];
+
+ process->current_state->activeTextureIndex =
+ activeTexture - GL_TEXTURE0_ARB;
+ do_glClientActiveTextureARB(activeTexture);
+ break;
+ }
+
+ case glTexCoordPointer_fake_func:
+ {
+ int offset = args[0];
+ int index = args[1];
+ int size = args[2];
+ int type = args[3];
+ int stride = args[4];
+ int bytes_size = args[5];
+
+ process->current_state->texCoordPointerSize[index] =
+ MAX(process->current_state->texCoordPointerSize[index],
+ offset + bytes_size);
+ process->current_state->texCoordPointer[index] =
+ g_realloc(process->current_state->texCoordPointer[index],
+ process->current_state->texCoordPointerSize[index]);
+ memcpy(process->current_state->texCoordPointer[index] + offset,
+ (void *) args[6], bytes_size);
+ /* DEBUGF( "glTexCoordPointer_fake_func size=%d, type=%d,
+ * stride=%d, byte_size=%d\n", size, type, stride, bytes_size); */
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + index);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[index]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glWeightPointerARB_fake_func:
+ {
+ GET_EXT_PTR(void, glWeightPointerARB, (int, int, int, void *));
+ int offset = args[0];
+ int size = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->weightPointerSize =
+ MAX(process->current_state->weightPointerSize,
+ offset + bytes_size);
+ process->current_state->weightPointer =
+ g_realloc(process->current_state->weightPointer,
+ process->current_state->weightPointerSize);
+ memcpy(process->current_state->weightPointer + offset,
+ (void *) args[5], bytes_size);
+ /* DEBUGF( "glWeightPointerARB_fake_func size=%d,
+ * type=%d, stride=%d, byte_size=%d\n", size, type, stride,
+ * bytes_size); */
+ ptr_func_glWeightPointerARB(size, type, stride,
+ process->current_state->
+ weightPointer);
+ break;
+ }
+
+ case glMatrixIndexPointerARB_fake_func:
+ {
+ GET_EXT_PTR(void, glMatrixIndexPointerARB,
+ (int, int, int, void *));
+ int offset = args[0];
+ int size = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->matrixIndexPointerSize =
+ MAX(process->current_state->matrixIndexPointerSize,
+ offset + bytes_size);
+ process->current_state->matrixIndexPointer =
+ g_realloc(process->current_state->matrixIndexPointer,
+ process->current_state->matrixIndexPointerSize);
+ memcpy(process->current_state->matrixIndexPointer + offset,
+ (void *) args[5], bytes_size);
+ /* DEBUGF( "glMatrixIndexPointerARB_fake_func size=%d,
+ * type=%d, stride=%d, byte_size=%d\n", size, type, stride,
+ * bytes_size); */
+ ptr_func_glMatrixIndexPointerARB(size, type, stride,
+ process->current_state->
+ matrixIndexPointer);
+ break;
+ }
+
+ case glFogCoordPointer_fake_func:
+ {
+ GET_EXT_PTR(void, glFogCoordPointer, (int, int, void *));
+ int offset = args[0];
+ int type = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->fogCoordPointerSize =
+ MAX(process->current_state->fogCoordPointerSize,
+ offset + bytes_size);
+ process->current_state->fogCoordPointer =
+ g_realloc(process->current_state->fogCoordPointer,
+ process->current_state->fogCoordPointerSize);
+ memcpy(process->current_state->fogCoordPointer + offset,
+ (void *) args[4], bytes_size);
+ // DEBUGF( "glFogCoordPointer_fake_func type=%d,
+ // stride=%d, byte_size=%d\n", type, stride, bytes_size);
+ ptr_func_glFogCoordPointer(type, stride,
+ process->current_state->
+ fogCoordPointer);
+ break;
+ }
+
+ case glVariantPointerEXT_fake_func:
+ {
+ GET_EXT_PTR(void, glVariantPointerEXT, (int, int, int, void *));
+ int offset = args[0];
+ int id = args[1];
+ int type = args[2];
+ int stride = args[3];
+ int bytes_size = args[4];
+
+ process->current_state->variantPointerEXTSize[id] =
+ MAX(process->current_state->variantPointerEXTSize[id],
+ offset + bytes_size);
+ process->current_state->variantPointerEXT[id] =
+ g_realloc(process->current_state->variantPointerEXT[id],
+ process->current_state->variantPointerEXTSize[id]);
+ memcpy(process->current_state->variantPointerEXT[id] + offset,
+ (void *) args[5], bytes_size);
+ // DEBUGF( "glVariantPointerEXT_fake_func[%d] type=%d,
+ // stride=%d, byte_size=%d\n", id, type, stride, bytes_size);
+ ptr_func_glVariantPointerEXT(id, type, stride,
+ process->current_state->
+ variantPointerEXT[id]);
+ break;
+ }
+
+ case glInterleavedArrays_fake_func:
+ {
+ GET_EXT_PTR(void, glInterleavedArrays, (int, int, void *));
+ int offset = args[0];
+ int format = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->interleavedArraysSize =
+ MAX(process->current_state->interleavedArraysSize,
+ offset + bytes_size);
+ process->current_state->interleavedArrays =
+ g_realloc(process->current_state->interleavedArrays,
+ process->current_state->interleavedArraysSize);
+ memcpy(process->current_state->interleavedArrays + offset,
+ (void *) args[4], bytes_size);
+ // DEBUGF( "glInterleavedArrays_fake_func format=%d,
+ // stride=%d, byte_size=%d\n", format, stride, bytes_size);
+ ptr_func_glInterleavedArrays(format, stride,
+ process->current_state->
+ interleavedArrays);
+ break;
+ }
+
+ case glElementPointerATI_fake_func:
+ {
+ GET_EXT_PTR(void, glElementPointerATI, (int, void *));
+ int type = args[0];
+ int bytes_size = args[1];
+
+ process->current_state->elementPointerATISize = bytes_size;
+ process->current_state->elementPointerATI =
+ g_realloc(process->current_state->elementPointerATI,
+ process->current_state->elementPointerATISize);
+ memcpy(process->current_state->elementPointerATI,
+ (void *) args[2], bytes_size);
+ // DEBUGF( "glElementPointerATI_fake_func type=%d,
+ // byte_size=%d\n", type, bytes_size);
+ ptr_func_glElementPointerATI(type,
+ process->current_state->
+ elementPointerATI);
+ break;
+ }
+
+ case glTexCoordPointer01_fake_func:
+ {
+ int size = args[0];
+ int type = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->texCoordPointerSize[0] = bytes_size;
+ process->current_state->texCoordPointer[0] =
+ g_realloc(process->current_state->texCoordPointer[0],
+ bytes_size);
+ memcpy(process->current_state->texCoordPointer[0],
+ (void *) args[4], bytes_size);
+ /* DEBUGF( "glTexCoordPointer01_fake_func size=%d,
+ * type=%d, stride=%d, byte_size=%d\n", size, type, stride,
+ * bytes_size); */
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[0]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[0]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glTexCoordPointer012_fake_func:
+ {
+ int size = args[0];
+ int type = args[1];
+ int stride = args[2];
+ int bytes_size = args[3];
+
+ process->current_state->texCoordPointerSize[0] = bytes_size;
+ process->current_state->texCoordPointer[0] =
+ g_realloc(process->current_state->texCoordPointer[0],
+ bytes_size);
+ memcpy(process->current_state->texCoordPointer[0],
+ (void *) args[4], bytes_size);
+ /* DEBUGF( "glTexCoordPointer012_fake_func size=%d,
+ * type=%d, stride=%d, byte_size=%d\n", size, type, stride,
+ * bytes_size); */
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[0]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[0]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
+ glTexCoordPointer(size, type, stride,
+ process->current_state->texCoordPointer[0]);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexAndNormalPointer_fake_func:
+ {
+ int vertexPointerSize = args[0];
+ int vertexPointerType = args[1];
+ int vertexPointerStride = args[2];
+ int normalPointerType = args[3];
+ int normalPointerStride = args[4];
+ int bytes_size = args[5];
+ void *ptr = (void *) args[6];
+
+ process->current_state->vertexPointerSize = bytes_size;
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer, bytes_size);
+ memcpy(process->current_state->vertexPointer, ptr, bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType,
+ vertexPointerStride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, normalPointerStride,
+ process->current_state->vertexPointer);
+ break;
+ }
+
+ case glVertexNormalPointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ break;
+ }
+
+ case glTuxRacerDrawElements_fake_func:
+ {
+ int mode = args[0];
+ int count = args[1];
+ int isColorEnabled = args[2];
+ void *ptr = (void *) args[3];
+ int stride =
+ 6 * sizeof(float) +
+ ((isColorEnabled) ? 4 * sizeof(unsigned char) : 0);
+ glVertexPointer(3, GL_FLOAT, stride, ptr);
+ glNormalPointer(GL_FLOAT, stride, ptr + 3 * sizeof(float));
+ if (isColorEnabled)
+ glColorPointer(4, GL_UNSIGNED_BYTE, stride,
+ ptr + 6 * sizeof(float));
+ glDrawArrays(mode, 0, count);
+ break;
+ }
+
+ case glVertexNormalColorPointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int colorPointerOffset = args[i++];
+ int colorPointerSize = args[i++];
+ int colorPointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ glColorPointer(colorPointerSize, colorPointerType, stride,
+ process->current_state->vertexPointer +
+ colorPointerOffset);
+ break;
+ }
+
+ case glVertexColorTexCoord0PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int colorPointerOffset = args[i++];
+ int colorPointerSize = args[i++];
+ int colorPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glColorPointer(colorPointerSize, colorPointerType, stride,
+ process->current_state->vertexPointer +
+ colorPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalTexCoord0PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalTexCoord01PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int texCoord1PointerOffset = args[i++];
+ int texCoord1PointerSize = args[i++];
+ int texCoord1PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord1PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalTexCoord012PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int texCoord1PointerOffset = args[i++];
+ int texCoord1PointerSize = args[i++];
+ int texCoord1PointerType = args[i++];
+ int texCoord2PointerOffset = args[i++];
+ int texCoord2PointerSize = args[i++];
+ int texCoord2PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord1PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
+ glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord2PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalColorTexCoord0PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int colorPointerOffset = args[i++];
+ int colorPointerSize = args[i++];
+ int colorPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ glColorPointer(colorPointerSize, colorPointerType, stride,
+ process->current_state->vertexPointer +
+ colorPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalColorTexCoord01PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int colorPointerOffset = args[i++];
+ int colorPointerSize = args[i++];
+ int colorPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int texCoord1PointerOffset = args[i++];
+ int texCoord1PointerSize = args[i++];
+ int texCoord1PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ glColorPointer(colorPointerSize, colorPointerType, stride,
+ process->current_state->vertexPointer +
+ colorPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord1PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case glVertexNormalColorTexCoord012PointerInterlaced_fake_func:
+ {
+ int i = 0;
+ int offset = args[i++];
+ int vertexPointerSize = args[i++];
+ int vertexPointerType = args[i++];
+ int stride = args[i++];
+ int normalPointerOffset = args[i++];
+ int normalPointerType = args[i++];
+ int colorPointerOffset = args[i++];
+ int colorPointerSize = args[i++];
+ int colorPointerType = args[i++];
+ int texCoord0PointerOffset = args[i++];
+ int texCoord0PointerSize = args[i++];
+ int texCoord0PointerType = args[i++];
+ int texCoord1PointerOffset = args[i++];
+ int texCoord1PointerSize = args[i++];
+ int texCoord1PointerType = args[i++];
+ int texCoord2PointerOffset = args[i++];
+ int texCoord2PointerSize = args[i++];
+ int texCoord2PointerType = args[i++];
+ int bytes_size = args[i++];
+ void *ptr = (void *) args[i++];
+
+ process->current_state->vertexPointerSize =
+ MAX(process->current_state->vertexPointerSize,
+ offset + bytes_size);
+ process->current_state->vertexPointer =
+ g_realloc(process->current_state->vertexPointer,
+ process->current_state->vertexPointerSize);
+ memcpy(process->current_state->vertexPointer + offset, ptr,
+ bytes_size);
+ glVertexPointer(vertexPointerSize, vertexPointerType, stride,
+ process->current_state->vertexPointer);
+ glNormalPointer(normalPointerType, stride,
+ process->current_state->vertexPointer +
+ normalPointerOffset);
+ glColorPointer(colorPointerSize, colorPointerType, stride,
+ process->current_state->vertexPointer +
+ colorPointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 0);
+ glTexCoordPointer(texCoord0PointerSize, texCoord0PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord0PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 1);
+ glTexCoordPointer(texCoord1PointerSize, texCoord1PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord1PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB + 2);
+ glTexCoordPointer(texCoord2PointerSize, texCoord2PointerType,
+ stride,
+ process->current_state->vertexPointer +
+ texCoord2PointerOffset);
+ do_glClientActiveTextureARB(GL_TEXTURE0_ARB +
+ process->current_state->
+ activeTextureIndex);
+ break;
+ }
+
+ case _glVertexPointer_buffer_func:
+ {
+ glVertexPointer(args[0], args[1], args[2], (void *) args[3]);
+ break;
+ }
+
+ case _glNormalPointer_buffer_func:
+ {
+ glNormalPointer(args[0], args[1], (void *) args[2]);
+ break;
+ }
+
+ case _glColorPointer_buffer_func:
+ {
+ glColorPointer(args[0], args[1], args[2], (void *) args[3]);
+ break;
+ }
+
+ case _glSecondaryColorPointer_buffer_func:
+ {
+ GET_EXT_PTR(void, glSecondaryColorPointer,
+ (int, int, int, void *));
+ ptr_func_glSecondaryColorPointer(args[0], args[1], args[2],
+ (void *) args[3]);
+ break;
+ }
+
+ case _glIndexPointer_buffer_func:
+ {
+ glIndexPointer(args[0], args[1], (void *) args[2]);
+ break;
+ }
+
+ case _glTexCoordPointer_buffer_func:
+ {
+ glTexCoordPointer(args[0], args[1], args[2], (void *) args[3]);
+ break;
+ }
+
+ case _glEdgeFlagPointer_buffer_func:
+ {
+ glEdgeFlagPointer(args[0], (void *) args[1]);
+ break;
+ }
+
+ case _glVertexAttribPointerARB_buffer_func:
+ {
+ GET_EXT_PTR(void, glVertexAttribPointerARB,
+ (int, int, int, int, int, void *));
+ ptr_func_glVertexAttribPointerARB(args[0], args[1], args[2],
+ args[3], args[4],
+ (void *) args[5]);
+ break;
+ }
+
+ case _glWeightPointerARB_buffer_func:
+ {
+ GET_EXT_PTR(void, glWeightPointerARB, (int, int, int, void *));
+
+ ptr_func_glWeightPointerARB(args[0], args[1], args[2],
+ (void *) args[3]);
+ break;
+ }
+
+ case _glMatrixIndexPointerARB_buffer_func:
+ {
+ GET_EXT_PTR(void, glMatrixIndexPointerARB,
+ (int, int, int, void *));
+ ptr_func_glMatrixIndexPointerARB(args[0], args[1], args[2],
+ (void *) args[3]);
+ break;
+ }
+
+ case _glFogCoordPointer_buffer_func:
+ {
+ GET_EXT_PTR(void, glFogCoordPointer, (int, int, void *));
+
+ ptr_func_glFogCoordPointer(args[0], args[1], (void *) args[2]);
+ break;
+ }
+
+ case _glVariantPointerEXT_buffer_func:
+ {
+ GET_EXT_PTR(void, glVariantPointerEXT, (int, int, int, void *));
+
+ ptr_func_glVariantPointerEXT(args[0], args[1], args[2],
+ (void *) args[3]);
+ break;
+ }
+
+ case _glDrawElements_buffer_func:
+ {
+ glDrawElements(args[0], args[1], args[2], (void *) args[3]);
+ break;
+ }
+#ifndef _WIN32
+ case _glDrawRangeElements_buffer_func:
+ {
+ glDrawRangeElements(args[0], args[1], args[2], args[3], args[4],
+ (void *) args[5]);
+ break;
+ }
+#endif
+ case _glMultiDrawElements_buffer_func:
+ {
+ GET_EXT_PTR(void, glMultiDrawElements,
+ (int, int *, int, void **, int));
+ ptr_func_glMultiDrawElements(args[0], (int *) args[1], args[2],
+ (void **) args[3], args[4]);
+ break;
+ }
+
+ case _glGetError_fake_func:
+ {
+ break;
+ }
+
+ case glGetIntegerv_func:
+ {
+ glGetIntegerv(args[0], (int *) args[1]);
+ break;
+ }
+
+ case _glReadPixels_pbo_func:
+ {
+ glReadPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]),
+ ARG_TO_INT(args[2]), ARG_TO_INT(args[3]),
+ ARG_TO_UNSIGNED_INT(args[4]),
+ ARG_TO_UNSIGNED_INT(args[5]), (void *) (args[6]));
+ break;
+ }
+
+ case _glDrawPixels_pbo_func:
+ {
+ glDrawPixels(ARG_TO_INT(args[0]), ARG_TO_INT(args[1]),
+ ARG_TO_UNSIGNED_INT(args[2]),
+ ARG_TO_UNSIGNED_INT(args[3]),
+ (const void *) (args[4]));
+ break;
+ }
+
+ case _glMapBufferARB_fake_func:
+ {
+ GET_EXT_PTR(GLvoid *, glMapBufferARB, (GLenum, GLenum));
+ GET_EXT_PTR(GLboolean, glUnmapBufferARB, (GLenum));
+ int target = args[0];
+ int size = args[1];
+ void *dst_ptr = (void *) args[2];
+ void *src_ptr = ptr_func_glMapBufferARB(target, GL_READ_ONLY);
+
+ if (src_ptr) {
+ memcpy(dst_ptr, src_ptr, size);
+ ret.i = ptr_func_glUnmapBufferARB(target);
+ } else {
+ ret.i = 0;
+ }
+ break;
+ }
+
+ case fake_gluBuild2DMipmaps_func:
+ {
+ GET_GLU_PTR(GLint, gluBuild2DMipmaps,
+ (GLenum arg_0, GLint arg_1, GLsizei arg_2,
+ GLsizei arg_3, GLenum arg_4, GLenum arg_5,
+ const GLvoid *arg_6));
+ if (ptr_func_gluBuild2DMipmaps == NULL)
+ ptr_func_gluBuild2DMipmaps = mesa_gluBuild2DMipmaps;
+ ptr_func_gluBuild2DMipmaps(ARG_TO_UNSIGNED_INT(args[0]),
+ ARG_TO_INT(args[1]),
+ ARG_TO_INT(args[2]),
+ ARG_TO_INT(args[3]),
+ ARG_TO_UNSIGNED_INT(args[4]),
+ ARG_TO_UNSIGNED_INT(args[5]),
+ (const void *) (args[6]));
+ break;
+ }
+
+ case _glSelectBuffer_fake_func:
+ {
+ process->current_state->selectBufferSize = args[0] * 4;
+ process->current_state->selectBufferPtr =
+ g_realloc(process->current_state->selectBufferPtr,
+ process->current_state->selectBufferSize);
+ glSelectBuffer(args[0], process->current_state->selectBufferPtr);
+ break;
+ }
+
+ case _glGetSelectBuffer_fake_func:
+ {
+ void *ptr = (void *) args[0];
+
+ memcpy(ptr, process->current_state->selectBufferPtr,
+ process->current_state->selectBufferSize);
+ break;
+ }
+
+ case _glFeedbackBuffer_fake_func:
+ {
+ process->current_state->feedbackBufferSize = args[0] * 4;
+ process->current_state->feedbackBufferPtr =
+ g_realloc(process->current_state->feedbackBufferPtr,
+ process->current_state->feedbackBufferSize);
+ glFeedbackBuffer((GLsizei)args[0], (GLenum) args[1],
+ process->current_state->feedbackBufferPtr);
+ break;
+ }
+
+ case _glGetFeedbackBuffer_fake_func:
+ {
+ void *ptr = (void *) args[0];
+
+ memcpy(ptr, process->current_state->feedbackBufferPtr,
+ process->current_state->feedbackBufferSize);
+ break;
+ }
+
+ /*
+ * case glEnableClientState_func: { if (display_function_call)
+ * DEBUGF( "cap : %s\n", nameArrays[args[0] -
+ * GL_VERTEX_ARRAY]); glEnableClientState(args[0]); break; }
+ *
+ * case glDisableClientState_func: { if (display_function_call)
+ * DEBUGF( "cap : %s\n", nameArrays[args[0] -
+ * GL_VERTEX_ARRAY]); glDisableClientState(args[0]); break; }
+ *
+ * case glClientActiveTexture_func: case
+ * glClientActiveTextureARB_func: { if (display_function_call)
+ * DEBUGF( "client activeTexture %d\n", args[0] -
+ * GL_TEXTURE0_ARB); glClientActiveTextureARB(args[0]); break; }
+ *
+ * case glActiveTextureARB_func: { if (display_function_call)
+ * DEBUGF( "server activeTexture %d\n", args[0] -
+ * GL_TEXTURE0_ARB); glActiveTextureARB(args[0]); break; }
+ *
+ * case glLockArraysEXT_func: break;
+ *
+ * case glUnlockArraysEXT_func: break;
+ *
+ * case glArrayElement_func: { glArrayElement(args[0]); break; }
+ *
+ * case glDrawArrays_func: { glDrawArrays(args[0],args[1],args[2]);
+ * break; }
+ *
+ * case glDrawElements_func: {
+ * glDrawElements(args[0],args[1],args[2],(void*)args[3]); break; }
+ *
+ * case glDrawRangeElements_func: {
+ * glDrawRangeElements(args[0],args[1],args[2],args[3],args[4],(void*)args[5]);
+ * break; } */
+
+ case glGetError_func:
+ {
+ ret.i = glGetError();
+ break;
+ }
+
+ case glNewObjectBufferATI_func:
+ {
+ GET_EXT_PTR(int, glNewObjectBufferATI, (int, void *, int));
+
+ ret.i = ptr_func_glNewObjectBufferATI(args[0],
+ (void *) args[1], args[2]);
+ break;
+ }
+
+ case glClear_func:
+ glClear((GLbitfield)args[0]);
+ break;
+#if 0
+ /* HACK workaround for an unexplainable issue */
+ if (args[0] & GL_COLOR_BUFFER_BIT)
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (args[0] & GL_STENCIL_BUFFER_BIT)
+ glClear(GL_STENCIL_BUFFER_BIT);
+ if (args[0] & GL_DEPTH_BUFFER_BIT)
+ glClear(GL_DEPTH_BUFFER_BIT);
+ if (args[0] & GL_ACCUM_BUFFER_BIT)
+ glClear(GL_ACCUM_BUFFER_BIT);
+ break;
+#endif
+
+ default:
+ execute_func(func_number, (void**)args, &ret);
+ break;
+ }
+
+ switch (ret_type) {
+ case TYPE_NONE:
+ case TYPE_CHAR:
+ case TYPE_UNSIGNED_CHAR:
+ case TYPE_INT:
+ case TYPE_UNSIGNED_INT:
+ break;
+
+ case TYPE_CONST_CHAR:
+ {
+ strncpy(ret_string, (ret.s) ? ret.s : "", 32768);
+ break;
+ }
+
+ default:
+ DEBUGF( "unexpected ret type : %d\n", ret_type);
+ exit(-1);
+ break;
+ }
+
+ if (display_function_call)
+ DEBUGF( "[%d]< %s\n", process->p.process_id,
+ tab_opengl_calls_name[func_number]);
+
+ return ret.i;
+}
--- /dev/null
+/*
+ * Copyright (c) 2006,2007 Even Rouault
+ *
+ * Modified by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include <sys/types.h>
+
+extern void gl_disconnect(ProcessStruct *process);
+extern ProcessStruct *vmgl_get_process(pid_t pid);
+extern void vmgl_context_switch(ProcessStruct *process, int switch_gl_context);
+extern int do_function_call(ProcessStruct *process, int func_number,
+ unsigned long *args, char *ret_string);
--- /dev/null
+/*
+ * Copyright (c) 2006,2007 Even Rouault
+ *
+ * Parts written by:
+ * Gordon Williams <gordon.williams@collabora.co.uk>
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef INCLUDE_OPENGL_FUNC_H
+#define INCLUDE_OPENGL_FUNC_H
+
+#include "mesa_gl.h"
+#include "mesa_glext.h"
+
+#ifdef TARGET_X86_64
+#define TARGET_LONG_BITS 64
+#define TARGET_PHYS_ADDR_BITS 64
+#else
+#define TARGET_LONG_BITS 32
+#define TARGET_PHYS_ADDR_BITS 32
+#endif
+
+//#define NEED_CPU_H
+//#include "exec.h" // For arg_t typedef
+//#undef NEED_CPU_H
+#include "targphys.h"
+
+/* Argument list are internally of a type that can hold a target pointer
+ * or a host pointer. */
+typedef target_phys_addr_t arg_t;
+
+enum {
+ TYPE_NONE,
+ TYPE_CHAR,
+ TYPE_UNSIGNED_CHAR,
+ TYPE_SHORT,
+ TYPE_UNSIGNED_SHORT,
+ TYPE_INT,
+ TYPE_UNSIGNED_INT,
+ TYPE_FLOAT,
+ TYPE_DOUBLE,
+ TYPE_1CHAR,
+ TYPE_2CHAR,
+ TYPE_3CHAR,
+ TYPE_4CHAR,
+ TYPE_128UCHAR,
+ TYPE_1SHORT,
+ TYPE_2SHORT,
+ TYPE_3SHORT,
+ TYPE_4SHORT,
+ TYPE_1INT,
+ TYPE_2INT,
+ TYPE_3INT,
+ TYPE_4INT,
+ TYPE_1FLOAT,
+ TYPE_2FLOAT,
+ TYPE_3FLOAT,
+ TYPE_4FLOAT,
+ TYPE_16FLOAT,
+ TYPE_1DOUBLE,
+ TYPE_2DOUBLE,
+ TYPE_3DOUBLE,
+ TYPE_4DOUBLE,
+ TYPE_16DOUBLE,
+ TYPE_OUT_1INT,
+ TYPE_OUT_1FLOAT,
+ TYPE_OUT_4CHAR,
+ TYPE_OUT_4INT,
+ TYPE_OUT_4FLOAT,
+ TYPE_OUT_4DOUBLE,
+ TYPE_OUT_128UCHAR,
+ TYPE_CONST_CHAR,
+ TYPE_ARRAY_CHAR,
+ TYPE_ARRAY_SHORT,
+ TYPE_ARRAY_INT,
+ TYPE_ARRAY_FLOAT,
+ TYPE_ARRAY_DOUBLE,
+ TYPE_IN_IGNORED_POINTER,
+ TYPE_OUT_ARRAY_CHAR,
+ TYPE_OUT_ARRAY_SHORT,
+ TYPE_OUT_ARRAY_INT,
+ TYPE_OUT_ARRAY_FLOAT,
+ TYPE_OUT_ARRAY_DOUBLE,
+ TYPE_NULL_TERMINATED_STRING,
+
+ TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ /* .... */
+ TYPE_LAST,
+ /* .... */
+ TYPE_1UCHAR = TYPE_CHAR,
+ TYPE_1USHORT = TYPE_1SHORT,
+ TYPE_1UINT = TYPE_1INT,
+ TYPE_OUT_1UINT = TYPE_OUT_1INT,
+ TYPE_OUT_4UCHAR = TYPE_OUT_4CHAR,
+ TYPE_ARRAY_VOID = TYPE_ARRAY_CHAR,
+ TYPE_ARRAY_SIGNED_CHAR = TYPE_ARRAY_CHAR,
+ TYPE_ARRAY_UNSIGNED_CHAR = TYPE_ARRAY_CHAR,
+ TYPE_ARRAY_UNSIGNED_SHORT = TYPE_ARRAY_SHORT,
+ TYPE_ARRAY_UNSIGNED_INT = TYPE_ARRAY_INT,
+ TYPE_OUT_ARRAY_VOID = TYPE_OUT_ARRAY_CHAR,
+ TYPE_OUT_ARRAY_SIGNED_CHAR = TYPE_OUT_ARRAY_CHAR,
+ TYPE_OUT_ARRAY_UNSIGNED_CHAR = TYPE_OUT_ARRAY_CHAR,
+ TYPE_OUT_ARRAY_UNSIGNED_SHORT = TYPE_OUT_ARRAY_SHORT,
+ TYPE_OUT_ARRAY_UNSIGNED_INT = TYPE_OUT_ARRAY_INT,
+ TYPE_ARRAY_VOID_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_SIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_UNSIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_UNSIGNED_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_ARRAY_UNSIGNED_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_VOID_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_SIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_UNSIGNED_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_UNSIGNED_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+ TYPE_OUT_ARRAY_UNSIGNED_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS =
+ TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS,
+};
+
+#define CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS \
+ case TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
+
+#define CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS \
+ case TYPE_OUT_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_OUT_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_OUT_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_OUT_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS: \
+ case TYPE_OUT_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
+
+#define CASE_IN_UNKNOWN_SIZE_POINTERS \
+ case TYPE_ARRAY_CHAR: \
+ case TYPE_ARRAY_SHORT: \
+ case TYPE_ARRAY_INT: \
+ case TYPE_ARRAY_FLOAT: \
+ case TYPE_ARRAY_DOUBLE
+
+#define CASE_IN_KNOWN_SIZE_POINTERS \
+ case TYPE_1CHAR:\
+ case TYPE_2CHAR:\
+ case TYPE_3CHAR:\
+ case TYPE_4CHAR:\
+ case TYPE_128UCHAR:\
+ case TYPE_1SHORT:\
+ case TYPE_2SHORT:\
+ case TYPE_3SHORT:\
+ case TYPE_4SHORT:\
+ case TYPE_1INT:\
+ case TYPE_2INT:\
+ case TYPE_3INT:\
+ case TYPE_4INT:\
+ case TYPE_1FLOAT:\
+ case TYPE_2FLOAT:\
+ case TYPE_3FLOAT:\
+ case TYPE_4FLOAT:\
+ case TYPE_16FLOAT:\
+ case TYPE_1DOUBLE:\
+ case TYPE_2DOUBLE:\
+ case TYPE_3DOUBLE:\
+ case TYPE_4DOUBLE:\
+ case TYPE_16DOUBLE
+
+#define CASE_OUT_UNKNOWN_SIZE_POINTERS \
+ case TYPE_OUT_ARRAY_CHAR: \
+ case TYPE_OUT_ARRAY_SHORT: \
+ case TYPE_OUT_ARRAY_INT: \
+ case TYPE_OUT_ARRAY_FLOAT: \
+ case TYPE_OUT_ARRAY_DOUBLE
+
+#define CASE_OUT_KNOWN_SIZE_POINTERS \
+ case TYPE_OUT_1INT: \
+ case TYPE_OUT_1FLOAT: \
+ case TYPE_OUT_4CHAR: \
+ case TYPE_OUT_4INT: \
+ case TYPE_OUT_4FLOAT: \
+ case TYPE_OUT_4DOUBLE: \
+ case TYPE_OUT_128UCHAR \
+
+#define CASE_IN_POINTERS CASE_IN_UNKNOWN_SIZE_POINTERS: CASE_IN_KNOWN_SIZE_POINTERS: CASE_IN_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
+#define CASE_OUT_POINTERS CASE_OUT_UNKNOWN_SIZE_POINTERS: CASE_OUT_KNOWN_SIZE_POINTERS: CASE_OUT_LENGTH_DEPENDING_ON_PREVIOUS_ARGS
+
+#define CASE_POINTERS CASE_IN_POINTERS: CASE_OUT_POINTERS
+#define CASE_KNOWN_SIZE_POINTERS CASE_IN_KNOWN_SIZE_POINTERS: CASE_OUT_KNOWN_SIZE_POINTERS
+
+
+#define IS_ARRAY_CHAR(type) (type == TYPE_ARRAY_CHAR || type == TYPE_1CHAR || type == TYPE_2CHAR || type == TYPE_3CHAR || type == TYPE_4CHAR || type == TYPE_ARRAY_CHAR_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
+#define IS_ARRAY_SHORT(type) (type == TYPE_ARRAY_SHORT || type == TYPE_1SHORT || type == TYPE_2SHORT || type == TYPE_3SHORT || type == TYPE_4SHORT || type == TYPE_ARRAY_SHORT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
+#define IS_ARRAY_INT(type) (type == TYPE_ARRAY_INT || type == TYPE_1INT || type == TYPE_2INT || type == TYPE_3INT || type == TYPE_4INT || type == TYPE_ARRAY_INT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
+#define IS_ARRAY_FLOAT(type) (type == TYPE_ARRAY_FLOAT || type == TYPE_1FLOAT || type == TYPE_2FLOAT || type == TYPE_3FLOAT || type == TYPE_4FLOAT || type == TYPE_16FLOAT || type == TYPE_ARRAY_FLOAT_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
+#define IS_ARRAY_DOUBLE(type) (type == TYPE_ARRAY_DOUBLE || type == TYPE_1DOUBLE || type == TYPE_2DOUBLE || type == TYPE_3DOUBLE || type == TYPE_4DOUBLE || type == TYPE_16DOUBLE || type == TYPE_ARRAY_DOUBLE_OF_LENGTH_DEPENDING_ON_PREVIOUS_ARGS)
+
+#define NB_MAX_TEXTURES 16
+#define MY_GL_MAX_VERTEX_ATTRIBS_ARB 16
+#define MY_GL_MAX_VERTEX_ATTRIBS_NV 16
+#define MY_GL_MAX_VARIANT_POINTER_EXT 16
+
+typedef struct {
+ int ret_type;
+ int has_out_parameters;
+ int nb_args;
+ int args_type[0];
+} Signature;
+
+static const int _init32_signature[] =
+ { TYPE_NONE, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_1INT };
+static const int _init64_signature[] =
+ { TYPE_NONE, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_1INT };
+
+static const int _resize_surface_signature[] =
+ {TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT};
+
+static const int _render_surface_signature[] =
+ {TYPE_NONE, 1, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_OUT_ARRAY_CHAR};
+
+/* XVisualInfo* glXChooseVisual( Display *dpy, int screen, int *attribList ) */
+static const int glXChooseVisual_signature[] =
+ { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT };
+
+/*GLXContext glXCreateContext( Display *dpy, XVisualInfo *vis,
+ GLXContext shareList, Bool direct )*/
+static const int glXCreateContext_signature[] =
+ { TYPE_INT, 0, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT };
+
+static const int glXCopyContext_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_INT };
+
+/* void glXDestroyContext( Display *dpy, GLXContext ctx ) */
+static const int glXDestroyContext_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/* Bool glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx) */
+/* making it asynchronous */
+static const int glXMakeCurrent_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+
+/*int glXGetConfig( Display *dpy, XVisualInfo *visual,
+ int attrib, int *value )*/
+static const int glXGetConfig_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+/* "glXGetConfig_extended"(dpy, visual_id, int n, int* attribs, int* values, int* rets) */
+static const int glXGetConfig_extended_signature[] =
+ { TYPE_NONE, 1, 6, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_INT, TYPE_OUT_ARRAY_INT, TYPE_OUT_ARRAY_INT };
+
+/* void glXSwapBuffers( Display *dpy, GLXDrawable drawable ); */
+static const int glXSwapBuffers_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/* Bool glXQueryVersion( Display *dpy, int *maj, int *min ) */
+static const int glXQueryVersion_signature[] =
+ { TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_OUT_1INT, TYPE_OUT_1INT };
+
+/* Bool glXQueryExtension( Display *dpy, int *errorBase, int *eventBase ) */
+static const int glXQueryExtension_signature[] =
+ { TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_OUT_1INT, TYPE_OUT_1INT };
+
+static const int glXWaitGL_signature[] = { TYPE_INT, 0, 0 };
+static const int glXWaitX_signature[] = { TYPE_INT, 0, 0 };
+
+/* GLX 1.1 and later */
+
+/* const char *glXGetClientString( Display *dpy, int name ) */
+static const int glXGetClientString_signature[] =
+ { TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/*const char *glXQueryExtensionsString( Display *dpy, int screen ) */
+static const int glXQueryExtensionsString_signature[] =
+ { TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/* const char *glXQueryServerString( Display *dpy, int screen, int name ) */
+static const int glXQueryServerString_signature[] =
+ { TYPE_CONST_CHAR, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+
+
+static const int glXGetProcAddress_fake_signature[] =
+ { TYPE_INT, 0, 1, TYPE_NULL_TERMINATED_STRING };
+
+static const int glXGetProcAddress_global_fake_signature[] =
+ { TYPE_NONE, 1, 3, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_OUT_ARRAY_CHAR };
+
+
+/* GLX 1.3 and later */
+
+/*
+GLXFBConfig *glXChooseFBConfig( Display *dpy, int screen,
+ const int *attribList, int *nitems ); */
+static const int glXChooseFBConfig_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT,
+TYPE_OUT_1INT };
+
+static const int glXChooseFBConfigSGIX_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT,
+TYPE_OUT_1INT };
+
+static const int glXGetFBConfigs_signature[] =
+ { TYPE_INT, 1, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_OUT_1INT };
+
+/* "glXGetFBConfigAttrib_extended"(dpy, fbconfig, int n, int* attribs, int* values, int* rets) */
+static const int glXGetFBConfigAttrib_extended_signature[] =
+ { TYPE_NONE, 1, 6, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_INT, TYPE_OUT_ARRAY_INT, TYPE_OUT_ARRAY_INT };
+
+
+/* GLXPbuffer glXCreatePbuffer( Display *dpy, GLXFBConfig config,
+ const int *attribList ) */
+static const int glXCreatePbuffer_signature[] =
+ { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_ARRAY_INT };
+
+static const int glXCreateGLXPbufferSGIX_signature[] =
+ { TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_INT };
+
+static const int glXDestroyPbuffer_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+static const int glXDestroyGLXPbufferSGIX_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/* GLXContext glXCreateNewContext(Display * dpy
+ GLXFBConfig config
+ int renderType
+ GLXContext ShareList
+ Bool Direct) */
+static const int glXCreateNewContext_signature[] =
+ { TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT };
+
+static const int glXCreateContextWithConfigSGIX_signature[] =
+ { TYPE_INT, 0, 5, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT };
+
+/*XVisualInfo *glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) */
+static const int glXGetVisualFromFBConfig_signature[] =
+ { TYPE_INT, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+/*int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value)*/
+static const int glXGetFBConfigAttrib_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+static const int glXGetFBConfigAttribSGIX_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+static const int glXQueryContext_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+static const int glXQueryGLXPbufferSGIX_signature[] =
+ { TYPE_INT, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+static const int glXQueryDrawable_signature[] =
+ { TYPE_NONE, 1, 4, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT,
+TYPE_OUT_1INT };
+
+/* void glXUseXFont( Font font, int first, int count, int list ) */
+static const int glXUseXFont_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+
+/* Bool glXIsDirect( Display *dpy, GLXContext ctx ) */
+static const int glXIsDirect_signature[] =
+ { TYPE_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+static const int glXGetScreenDriver_signature[] =
+ { TYPE_CONST_CHAR, 0, 2, TYPE_IN_IGNORED_POINTER, TYPE_INT };
+
+static const int glXGetDriverConfig_signature[] =
+ { TYPE_CONST_CHAR, 0, 1, TYPE_NULL_TERMINATED_STRING };
+
+
+static const int glXWaitVideoSyncSGI_signature[] =
+ { TYPE_INT, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_1INT };
+
+static const int glXGetVideoSyncSGI_signature[] =
+ { TYPE_INT, 1, 1, TYPE_OUT_1INT };
+
+static const int glXSwapIntervalSGI_signature[] =
+ { TYPE_INT, 0, 1, TYPE_INT };
+
+static const int glXBindTexImageATI_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+static const int glXReleaseTexImageATI_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+static const int glXBindTexImageARB_signature[] =
+ { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+static const int glXReleaseTexImageARB_signature[] =
+ { TYPE_INT, 0, 3, TYPE_IN_IGNORED_POINTER, TYPE_INT, TYPE_INT };
+
+/* const GLubyte * glGetString( GLenum name ) */
+static const int glGetString_signature[] =
+ { TYPE_CONST_CHAR, 0, 1, TYPE_INT };
+
+/* void glShaderSourceARB (GLhandleARB handle , GLsizei size, const GLcharARB* *p_tab_prog, const GLint * tab_length) */
+/* --> void glShaderSourceARB (GLhandleARB handle , GLsizei size, const GLcharARB* all_progs, const GLint * tab_length) */
+static const int glShaderSourceARB_fake_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_ARRAY_INT };
+static const int glShaderSource_fake_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR, TYPE_ARRAY_INT };
+
+static const int glVertexPointer_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glNormalPointer_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glColorPointer_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glSecondaryColorPointer_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glIndexPointer_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glTexCoordPointer_fake_signature[] =
+ { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glEdgeFlagPointer_fake_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexAttribPointerARB_fake_signature[] =
+ { TYPE_NONE, 0, 8, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexAttribPointerNV_fake_signature[] =
+ { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glWeightPointerARB_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glMatrixIndexPointerARB_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glFogCoordPointer_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glInterleavedArrays_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glElementPointerATI_fake_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVariantPointerEXT_fake_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glTuxRacerDrawElements_fake_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexAndNormalPointer_fake_signature[] =
+ { TYPE_NONE, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glTexCoordPointer01_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glTexCoordPointer012_fake_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int glVertexNormalPointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 8, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexNormalColorPointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 11, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexColorTexCoord0PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 12, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexNormalTexCoord0PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 11, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexNormalTexCoord01PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 14, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int glVertexNormalTexCoord012PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 17, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int
+ glVertexNormalColorTexCoord0PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 14, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_ARRAY_CHAR };
+static const int
+ glVertexNormalColorTexCoord01PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 17, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+static const int
+ glVertexNormalColorTexCoord012PointerInterlaced_fake_signature[] =
+ { TYPE_NONE, 0, 20, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_ARRAY_CHAR };
+
+static const int glGenTextures_fake_signature[] =
+ { TYPE_NONE, 0, 1, TYPE_INT };
+static const int glGenBuffersARB_fake_signature[] =
+ { TYPE_NONE, 0, 1, TYPE_INT };
+static const int glGenLists_fake_signature[] = { TYPE_NONE, 0, 1, TYPE_INT };
+
+static const int _glDrawElements_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glDrawRangeElements_buffer_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT };
+static const int _glMultiDrawElements_buffer_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_ARRAY_INT, TYPE_INT, TYPE_ARRAY_INT,
+TYPE_INT };
+
+static const int _glVertexPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glNormalPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glColorPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glSecondaryColorPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glIndexPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glTexCoordPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glEdgeFlagPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_INT, TYPE_INT };
+static const int _glVertexAttribPointerARB_buffer_signature[] =
+ { TYPE_NONE, 0, 6, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT };
+static const int _glWeightPointerARB_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glMatrixIndexPointerARB_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glFogCoordPointer_buffer_signature[] =
+ { TYPE_NONE, 0, 3, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glVariantPointerEXT_buffer_signature[] =
+ { TYPE_NONE, 0, 4, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+
+static const int _glReadPixels_pbo_signature[] =
+ { TYPE_INT, 0, 7, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT,
+TYPE_INT, TYPE_INT };
+static const int _glDrawPixels_pbo_signature[] =
+ { TYPE_NONE, 0, 5, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT };
+static const int _glMapBufferARB_fake_signature[] =
+ { TYPE_INT, 1, 3, TYPE_INT, TYPE_INT, TYPE_OUT_ARRAY_CHAR };
+
+static const int _glSelectBuffer_fake_signature[] =
+ { TYPE_NONE, 0, 1, TYPE_INT };
+static const int _glGetSelectBuffer_fake_signature[] =
+ { TYPE_NONE, 1, 1, TYPE_ARRAY_CHAR };
+static const int _glFeedbackBuffer_fake_signature[] =
+ { TYPE_NONE, 0, 2, TYPE_INT, TYPE_INT };
+static const int _glGetFeedbackBuffer_fake_signature[] =
+ { TYPE_NONE, 1, 1, TYPE_ARRAY_CHAR };
+
+static const int _glGetError_fake_signature[] = { TYPE_NONE, 0, 0 };
+
+#include "gl_func.h"
+
+#define IS_NULL_POINTER_OK_FOR_FUNC(func_number) \
+ (func_number == glBitmap_func || \
+ func_number == glTexImage1D_func || \
+ func_number == glTexImage2D_func || \
+ func_number == glTexImage3D_func || \
+ func_number == glBufferDataARB_func || \
+ func_number == glNewObjectBufferATI_func)
+
+#endif // INCLUDE_OPENGL_FUNC_H
+
--- /dev/null
+/*
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISiNG FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+typedef struct {
+ int process_id;
+ int wordsize;
+ int rq_l, rrq_l;
+ int sum; // Debugging only
+ char *rq, *rq_p;
+ char *rrq, *rrq_p;
+} ProcessStruct;
+
#include <string.h>
#include <assert.h>
+#define GL_INCLUDE_PATH "../tizen/src/hw/"
+
+
int isExtByName(const char* name)
{
return (strstr(name, "ARB") != NULL) ||
void get_func_dealt_by_hand()
{
- FILE* f = fopen("../target-i386/gl_func_perso.h", "r");
+ FILE* f = fopen(GL_INCLUDE_PATH"gl_func_perso.h", "r");
char buffer[256];
int i = 0;
char* c;
static void fprintf_prototype_args(FILE* f, FuncDesc* funcDesc)
{
int j;
- if (!funcDesc->nargs)
- {
- fprintf(f, "void");
- return;
- }
for(j=0;j<funcDesc->nargs;j++)
{
if (j != 0) fprintf(f,", ");
FuncDesc funcDesc[3000];
int funcDescCount = 0;
FILE* f;
-
- f = fopen("../target-i386/mesa_gl.h", "r");
+
+ printf("***** path : %s\n", GL_INCLUDE_PATH"mesa_gl.h");
+ f = fopen(GL_INCLUDE_PATH"mesa_gl.h", "r");
assert(f);
/*if (!f)
f = fopen("/usr/include/GL/gl.h", "r");*/
funcDescCount = parse(f, funcDesc, 0, 1);
fclose(f);
- f = fopen("../target-i386/mesa_glext.h", "r");
+ f = fopen(GL_INCLUDE_PATH"mesa_glext.h", "r");
assert(f);
/*if (!f)
f = fopen("/usr/include/GL/glext.h", "r");*/
FILE* header = fopen("gl_func.h", "w");
FILE* client_stub = fopen("client_stub.c", "w");
FILE* server_stub = fopen("server_stub.c", "w");
-
- fprintf(header, "/* This is a generated file. DO NOT EDIT ! */\n\n");
+
+ fprintf(header, "/* This is a generated file by parse_gl_h.c - DO NOT EDIT ! */\n\n");
+ fprintf(header, "union gl_ret_type {\n"
+ "const char *s;\n"
+ "int i;\n"
+ "char c;\n"
+ "};\n");
+
fprintf(header, "#define COMPOSE(x,y) x##y\n");
fprintf(header, "#define MAGIC_MACRO(x) COMPOSE(x,_func)\n");
fprintf(header, "enum {\n"
"#include \"gl_func_perso.h\"\n");
-
- fprintf(client_stub, "/* This is a generated file. DO NOT EDIT ! */\n\n");
-
- fprintf(server_stub, "/* This is a generated file. DO NOT EDIT ! */\n\n");
-
+
+ fprintf(client_stub, "/* This is a generated file by parse_gl_h.c - DO NOT EDIT ! */\n\n");
+
+ fprintf(server_stub, "/* This is a generated file by parse_gl_h.c - DO NOT EDIT ! */\n\n");
+
int i;
for(i=0;i<funcDescCount;i++)
{
}
fprintf(header, " GL_N_CALLS\n};\n");
-
-
- fprintf(server_stub, "void execute_func(int func_number, long* args, int* pret_int, char* pret_char)\n");
+
+
+ fprintf(server_stub, "void execute_func(int func_number, void **args, union gl_ret_type *pret)\n");
fprintf(server_stub, "{\n");
fprintf(server_stub, " switch(func_number)\n");
fprintf(server_stub, " {\n");
;
else if (strcmp(get_type_string(funcDesc[i].type), "TYPE_INT") == 0 ||
strcmp(get_type_string(funcDesc[i].type), "TYPE_UNSIGNED_INT") == 0)
- fprintf(server_stub, "*pret_int = ");
+ fprintf(server_stub, "pret->i = ");
else if (strcmp(get_type_string(funcDesc[i].type), "TYPE_CHAR") == 0 ||
strcmp(get_type_string(funcDesc[i].type), "TYPE_UNSIGNED_CHAR") == 0)
- fprintf(server_stub, "*pret_char = ");
+ fprintf(server_stub, "pret->c = ");
else
{
fprintf(stderr, "unknown ret type = %s\n", get_type_string(funcDesc[i].type));
}
fprintf(server_stub, " default:\n");
- fprintf(server_stub, " fprintf(stderr, \"unknown=%%d\", func_number);\n");
+ fprintf(server_stub, " DEBUGF(\"unknown=%%d\", func_number);\n");
fprintf(server_stub, " break;\n");
fprintf(server_stub, " }\n");
fprintf(server_stub, "}\n");
--- /dev/null
+/*
+ * Copyright (c) 2007 Even Rouault
+ *
+ * Modified by Ian Molton 2010
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#ifndef _OPENGL_UTILS
+#define _OPENGL_UTILS
+
+void *g_malloc(size_t size);
+void *g_realloc(void *ptr, size_t size);
+void g_free(void *ptr);
+
+typedef struct {
+ unsigned int *values;
+ int nbValues;
+} RangeAllocator;
+
+/*
+static void print_range(RangeAllocator* range)
+{
+ int i;
+ printf("%s", "table : ");
+ for(i=0;i<range->nbValues;i++)
+ {
+ printf("%d ", range->values[i]);
+ }
+ printf("\n");
+}
+*/
+
+static inline void alloc_value(RangeAllocator *range, unsigned int value)
+{
+ if (value == 0)
+ return;
+ if (range->nbValues >= 1) {
+ int lower = 0;
+ int upper = range->nbValues - 1;
+
+ while (1) {
+ int mid = (lower + upper) / 2;
+
+ if (range->values[mid] > value)
+ upper = mid;
+ else if (range->values[mid] < value)
+ lower = mid;
+ else
+ break;
+ if (upper - lower <= 1) {
+ if (value < range->values[lower]) {
+ range->values =
+ realloc(range->values,
+ (range->nbValues + 1) * sizeof(int));
+ memmove(&range->values[lower + 1], &range->values[lower],
+ (range->nbValues - lower) * sizeof(int));
+ range->values[lower] = value;
+ range->nbValues++;
+ } else if (value == range->values[lower]) {
+ } else if (value < range->values[upper]) {
+ range->values =
+ realloc(range->values,
+ (range->nbValues + 1) * sizeof(int));
+ memmove(&range->values[upper + 1], &range->values[upper],
+ (range->nbValues - upper) * sizeof(int));
+ range->values[upper] = value;
+ range->nbValues++;
+ } else if (value == range->values[upper]) {
+ } else {
+ upper++;
+
+ range->values =
+ realloc(range->values,
+ (range->nbValues + 1) * sizeof(int));
+ memmove(&range->values[upper + 1], &range->values[upper],
+ (range->nbValues - upper) * sizeof(int));
+ range->values[upper] = value;
+ range->nbValues++;
+ }
+ break;
+ }
+ }
+ } else {
+ range->values = g_malloc(sizeof(int));
+ range->values[0] = value;
+ range->nbValues = 1;
+ }
+}
+
+/* return first value */
+static inline unsigned int alloc_range(RangeAllocator *range, int n,
+ unsigned int *values)
+{
+ int i, j;
+
+ if (range->nbValues == 0) {
+ range->nbValues = n;
+ range->values = g_malloc(n * sizeof(int));
+ for (i = 0; i < n; i++) {
+ range->values[i] = i + 1;
+ if (values)
+ values[i] = range->values[i];
+ }
+ return 1;
+ } else {
+ int lastValue = 1;
+
+ for (i = 0; i < range->nbValues; i++) {
+ if ((int) range->values[i] - (int) lastValue - 1 >= n) {
+ range->values =
+ realloc(range->values,
+ (range->nbValues + n) * sizeof(int));
+ memmove(&range->values[i + n], &range->values[i],
+ (range->nbValues - i) * sizeof(int));
+ for (j = 0; j < n; j++) {
+ range->values[i + j] = lastValue + 1 + j;
+ if (values)
+ values[j] = range->values[i + j];
+ }
+ range->nbValues += n;
+ break;
+ } else
+ lastValue = range->values[i];
+ }
+ if (i == range->nbValues) {
+ range->values =
+ realloc(range->values, (range->nbValues + n) * sizeof(int));
+ for (j = 0; j < n; j++) {
+ range->values[i + j] = lastValue + 1 + j;
+ if (values)
+ values[j] = range->values[i + j];
+ }
+ range->nbValues += n;
+ }
+ return lastValue + 1;
+ }
+}
+
+static inline void delete_value(RangeAllocator *range, unsigned int value)
+{
+ if (value == 0)
+ return;
+ if (range->nbValues >= 1) {
+ int lower = 0;
+ int upper = range->nbValues - 1;
+
+ while (1) {
+ int mid = (lower + upper) / 2;
+
+ if (range->values[mid] > value)
+ upper = mid;
+ else if (range->values[mid] < value)
+ lower = mid;
+ else {
+ lower = upper = mid;
+ }
+ if (upper - lower <= 1) {
+ if (value == range->values[lower]) {
+ memmove(&range->values[lower], &range->values[lower + 1],
+ (range->nbValues - lower - 1) * sizeof(int));
+ range->nbValues--;
+ } else if (value == range->values[upper]) {
+ memmove(&range->values[upper], &range->values[upper + 1],
+ (range->nbValues - upper - 1) * sizeof(int));
+ range->nbValues--;
+ }
+ break;
+ }
+ }
+ }
+}
+
+static inline void delete_range(RangeAllocator *range, int n,
+ const unsigned int *values)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ delete_value(range, values[i]);
+ }
+}
+
+static inline void delete_consecutive_values(RangeAllocator *range,
+ unsigned int first, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ delete_value(range, first + i);
+ }
+}
+
+#endif
--- /dev/null
+/*
+ * Virtio GL Device
+ *
+ * Copyright (c) 2010 Intel Corporation
+ * Written by:
+ * Ian Molton <ian.molton@collabora.co.uk>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "virtio.h"
+
+typedef target_phys_addr_t arg_t;
+#include "opengl_process.h"
+#include "opengl_exec.h"
+#include <sys/time.h>
+
+#include "tizen/src/debug_ch.h"
+MULTI_DEBUG_CHANNEL(qemu, virtio-gl);
+
+int decode_call_int(ProcessStruct *p, char *in_args, int args_len, char *r_buffer);
+
+/* Uncomment to enable debugging - WARNING!!! changes ABI! */
+//#define DEBUG_GLIO
+
+typedef struct VirtIOGL
+{
+ VirtIODevice vdev;
+ VirtQueue *vq;
+} VirtIOGL;
+
+struct d_hdr
+{
+ int pid;
+ int rq_l;
+ int rrq_l;
+#ifdef DEBUG_GLIO
+ int sum;
+#endif
+};
+
+#define SIZE_OUT_HEADER sizeof(struct d_hdr)
+
+#ifdef DEBUG_GLIO
+#define SIZE_IN_HEADER (4*2)
+#else
+#define SIZE_IN_HEADER 4
+#endif
+
+static void virtio_gl_handle(VirtIODevice *vdev, VirtQueue *vq)
+{
+ VirtQueueElement elem;
+ int nkill = 1;
+
+ TRACE("virtio_gl_handle called. \n");
+
+ while(virtqueue_pop(vq, &elem)) {
+ struct d_hdr *hdr = (struct d_hdr*)elem.out_sg[0].iov_base;
+ ProcessStruct *process;
+ int i, remain;
+ int ret = 0;
+
+ if(!elem.out_num) {
+ fprintf(stderr, "Bad packet\n");
+ goto done;
+ }
+
+ process = vmgl_get_process(hdr->pid);
+
+ if(hdr->rq_l) {
+
+ if(hdr->rrq_l) {
+ if(process->rq) { // Usually only the quit packet...
+ free(process->rq);
+ free(process->rrq);
+ }
+ // process->rq = process->rq_p = qemu_malloc(hdr->rq_l);
+ // process->rrq = process->rrq_p = qemu_malloc(hdr->rrq_l);
+ process->rq = process->rq_p = g_malloc(hdr->rq_l);
+ process->rrq = process->rrq_p = g_malloc(hdr->rrq_l);
+ process->rq_l = hdr->rq_l - SIZE_OUT_HEADER;
+ process->rrq_l = hdr->rrq_l;
+#ifdef DEBUG_GLIO
+ process->sum = hdr->sum;
+#endif
+ }
+
+ i = 0;
+ remain = process->rq_l - (process->rq_p - process->rq);
+ while(remain && i < elem.out_num){
+ char *src = (char *)elem.out_sg[i].iov_base;
+ int ilen = elem.out_sg[i].iov_len;
+ int len = remain;
+
+ if(i == 0) {
+ src += SIZE_OUT_HEADER;
+ ilen -= SIZE_OUT_HEADER;
+ }
+
+ if(len > ilen)
+ len = ilen;
+
+ memcpy(process->rq_p, src, len);
+ process->rq_p += len;
+ remain -= len;
+ i++;
+ }
+
+ if(process->rq_p >= process->rq + process->rq_l) {
+
+#ifdef DEBUG_GLIO
+ int sum = 0;
+ for(i = 0; i < process->rq_l ; i++)
+ sum += process->rq[i];
+ if(sum != process->sum)
+ fprintf(stderr, "Checksum fail\n");
+#endif
+
+ *(int*)process->rrq = nkill = decode_call_int(process,
+ process->rq, /* command_buffer */
+ process->rq_l, /* cmd buffer length */
+ process->rrq + SIZE_IN_HEADER); /* return buffer */
+
+ //qemu_free(process->rq);
+ g_free(process->rq);
+ process->rq = NULL;
+
+#ifdef DEBUG_GLIO
+ sum = 0;
+ for(i = SIZE_IN_BUFFER; i < process->rrq_l ; i++)
+ sum += process->rrq[i];
+ *(int*)(process->rrq+sizeof(int)) = sum;
+#endif
+
+ }
+ }
+
+ if(hdr->rrq_l && process->rq == NULL) {
+
+ i = 0;
+ remain = process->rrq_l - (process->rrq_p - process->rrq);
+ while(remain && i < elem.in_num) {
+ char *dst = elem.in_sg[i].iov_base;
+ int len = remain;
+ int ilen = elem.in_sg[i].iov_len;
+
+ if(len > ilen)
+ len = ilen;
+
+ memcpy(dst, process->rrq_p, len);
+ process->rrq_p += len;
+ remain -= len;
+ ret += len;
+ i++;
+ }
+
+ if(remain <= 0) {
+ //qemu_free(process->rrq);
+ g_free(process->rrq);
+ if(!nkill)
+ gl_disconnect(process);
+ }
+ }
+done:
+ virtqueue_push(vq, &elem, ret);
+
+ virtio_notify(vdev, vq);
+ }
+}
+
+static uint32_t virtio_gl_get_features(VirtIODevice *vdev, uint32_t f)
+{
+ return 0;
+}
+
+static void virtio_gl_save(QEMUFile *f, void *opaque)
+{
+ VirtIOGL *s = opaque;
+
+ virtio_save(&s->vdev, f);
+}
+
+static int virtio_gl_load(QEMUFile *f, void *opaque, int version_id)
+{
+ VirtIOGL *s = opaque;
+
+ if (version_id != 1)
+ return -EINVAL;
+
+ virtio_load(&s->vdev, f);
+ return 0;
+}
+
+VirtIODevice *virtio_gl_init(DeviceState *dev)
+{
+ VirtIOGL *s;
+
+ s = (VirtIOGL *)virtio_common_init("virtio-gl", VIRTIO_ID_GL,
+ 0, sizeof(VirtIOGL));
+ if (!s)
+ return NULL;
+
+ s->vdev.get_features = virtio_gl_get_features;
+ s->vq = virtio_add_queue(&s->vdev, 128, virtio_gl_handle);
+ register_savevm(dev, "virtio-gl", -1, 1, virtio_gl_save, virtio_gl_load, s);
+
+ return &s->vdev;
+}
+
#define MAX_VIRTIO_CONSOLES 1
+#define VIRTIOGL_DEV_NAME "virtio-gl-pci"
+extern int gl_acceleration_capability_check (void);
static const char *data_dir;
const char *bios_name = NULL;
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
int boot_splash_filedata_size;
uint8_t qemu_extra_params_fw[2];
+//virtio-gl
+int enable_gl = 1;
+
typedef struct FWBootEntry FWBootEntry;
struct FWBootEntry {
{
DeviceState *dev;
+ // virtio-gl pci device
+ if (!enable_gl) {
+ // ignore virtio-gl-pci device, even if users set it in option.
+ const char *driver = qemu_opt_get(opts, "driver");
+ if (driver && (strcmp (driver, VIRTIOGL_DEV_NAME) == 0)) {
+ return 0;
+ }
+ }
+
dev = qdev_device_add(opts);
if (!dev)
return -1;
free(mem);
}
+// virtio-gl pci device lookup
+typedef struct {
+ const char *device_name;
+ int found;
+} device_opt_finding_t;
+
+static int find_device_opt (QemuOpts *opts, void *opaque)
+{
+ device_opt_finding_t *devp = (device_opt_finding_t *) opaque;
+ if (devp->found == 1) {
+ return 0;
+ }
+
+ const char *str = qemu_opt_get (opts, "driver");
+ if (strcmp (str, devp->device_name) == 0) {
+ devp->found = 1;
+ }
+ return 0;
+}
+
int use_qemu_display = 0; //0:use tizen qemu sdl, 1:use original qemu sdl
int main(int argc, char **argv, char **envp)
{
qemu_opts_reset(olist);
qemu_opts_parse(olist, "accel=kvm", 0);
break;
+ case QEMU_OPTION_enable_gl:
+ enable_gl = 1;
+ break;
case QEMU_OPTION_machine:
olist = qemu_find_opts("machine");
qemu_opts_reset(olist);
}
loc_set_none();
+ if (enable_gl && (gl_acceleration_capability_check () != 0)) {
+ enable_gl = 0;
+ fprintf (stderr, "Warn: GL acceleration was disabled due to the fail of GL check!\n");
+ }
+
+ if (enable_gl) {
+ device_opt_finding_t devp = {VIRTIOGL_DEV_NAME, 0};
+ qemu_opts_foreach(qemu_find_opts("device"), find_device_opt, &devp, 0);
+ if (devp.found == 0) {
+ if (!qemu_opts_parse(qemu_find_opts("device"), VIRTIOGL_DEV_NAME, "driver")) {
+ exit(1);
+ }
+ }
+ }
+
+
/* Open the logfile at this point, if necessary. We can't open the logfile
* when encountering either of the logging options (-d or -D) because the
* other one may be encountered later on the command line, changing the