From 8ee0302f97682a5b73667a596ae019ebfc571121 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 21 Oct 2013 17:14:13 -0700 Subject: [PATCH] Add GLX and improved CGL support --- cgl.rs | 3 +- glx.rs | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib.rs | 3 ++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 glx.rs diff --git a/cgl.rs b/cgl.rs index 5606b01..a7c5ef6 100644 --- a/cgl.rs +++ b/cgl.rs @@ -42,6 +42,7 @@ extern { // Context functions pub fn CGLCreateContext(pix: CGLPixelFormatObj, share: CGLContextObj, ctx: *CGLContextObj) -> CGLError; + pub fn CGLGetPixelFormat(ctx: CGLContextObj) -> CGLPixelFormatObj; // Locking functions pub fn CGLLockContext(ctx: CGLContextObj) -> CGLError; @@ -52,4 +53,4 @@ extern { pub fn CGLTexImageIOSurface2D(ctx: CGLContextObj, target: GLenum, internal_format: GLenum, width: GLsizei, height: GLsizei, format: GLenum, ty: GLenum, ioSurface: IOSurfaceRef, plane: GLuint) -> CGLError; -} \ No newline at end of file +} diff --git a/glx.rs b/glx.rs new file mode 100644 index 0000000..adeae78 --- /dev/null +++ b/glx.rs @@ -0,0 +1,123 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Functions for X11 support. + +use std::libc::{c_char, c_int, c_ulong}; + +// Types + +pub struct Display { + priv opaque: (), +} + +pub type GLXDrawable = c_ulong; + +pub struct __GLXFBConfig { + priv opaque: (), +} + +pub type GLXFBConfig = *__GLXFBConfig; + +pub type GLXPixmap = c_ulong; + +pub type Pixmap = c_ulong; + +pub struct __XVisualInfo { + priv opaque: (), +} + +pub type XVisualInfo = *__XVisualInfo; + +// Constants + +pub static GLX_BIND_TO_TEXTURE_RGB_EXT: c_int = 0x20d0; +pub static GLX_BIND_TO_TEXTURE_RGBA_EXT: c_int = 0x20d1; +pub static GLX_BIND_TO_MIPMAP_TEXTURE_EXT: c_int = 0x20d2; +pub static GLX_BIND_TO_TEXTURE_TARGETS_EXT: c_int = 0x20d3; +pub static GLX_Y_INVERTED_EXT: c_int = 0x20d4; + +pub static GLX_TEXTURE_FORMAT_EXT: c_int = 0x20d5; +pub static GLX_TEXTURE_TARGET_EXT: c_int = 0x20d6; +pub static GLX_MIPMAP_TEXTURE_EXT: c_int = 0x20d7; + +pub static GLX_TEXTURE_FORMAT_NONE_EXT: c_int = 0x20d8; +pub static GLX_TEXTURE_FORMAT_RGB_EXT: c_int = 0x20d9; +pub static GLX_TEXTURE_FORMAT_RGBA_EXT: c_int = 0x20da; + +pub static GLX_TEXTURE_1D_BIT_EXT: c_int = 0x1; +pub static GLX_TEXTURE_2D_BIT_EXT: c_int = 0x2; +pub static GLX_TEXTURE_RECTANGLE_BIT_EXT: c_int = 0x4; + +pub static GLX_TEXTURE_1D_EXT: c_int = 0x20db; +pub static GLX_TEXTURE_2D_EXT: c_int = 0x20dc; +pub static GLX_TEXTURE_RECTANGLE_EXT: c_int = 0x20dd; + +pub static GLX_FRONT_LEFT_EXT: c_int = 0x20de; +pub static GLX_FRONT_RIGHT_EXT: c_int = 0x20df; +pub static GLX_BACK_LEFT_EXT: c_int = 0x20e0; +pub static GLX_BACK_RIGHT_EXT: c_int = 0x20e1; +pub static GLX_FRONT_EXT: c_int = GLX_FRONT_LEFT_EXT; +pub static GLX_BACK_EXT: c_int = GLX_BACK_LEFT_EXT; +pub static GLX_AUX0_EXT: c_int = 0x20e2; +pub static GLX_AUX1_EXT: c_int = 0x20e3; +pub static GLX_AUX2_EXT: c_int = 0x20e4; +pub static GLX_AUX3_EXT: c_int = 0x20e5; +pub static GLX_AUX4_EXT: c_int = 0x20e6; +pub static GLX_AUX5_EXT: c_int = 0x20e7; +pub static GLX_AUX6_EXT: c_int = 0x20e8; +pub static GLX_AUX7_EXT: c_int = 0x20e9; +pub static GLX_AUX8_EXT: c_int = 0x20ea; +pub static GLX_AUX9_EXT: c_int = 0x20eb; + +pub static GLX_DRAWABLE_TYPE: c_int = 0x8010; + +pub static GLX_RGBA: c_int = 4; +pub static GLX_DEPTH_SIZE: c_int = 12; + +pub static GLX_WINDOW_BIT: c_int = 0x01; +pub static GLX_PIXMAP_BIT: c_int = 0x02; +pub static GLX_PBUFFER_BIT: c_int = 0x04; +pub static GLX_AUX_BUFFERS_BIT: c_int = 0x10; + +// Functions + +extern { + pub fn glXGetProcAddress(procName: *c_char) -> extern "C" fn(); + + pub fn glXReleaseTexImageEXT(dpy: *Display, drawable: GLXDrawable, buffer: c_int); + + pub fn glXChooseFBConfig(dpy: *Display, + screen: c_int, + attrib_list: *c_int, + n_elements: *mut c_int) + -> *GLXFBConfig; + + pub fn glXChooseVisual(dpy: *Display, screen: c_int, attribList: *c_int) -> *XVisualInfo; + + pub fn glXCreatePixmap(dpy: *Display, config: GLXFBConfig, pixmap: Pixmap, attribList: *c_int) + -> GLXPixmap; + + pub fn glXDestroyPixmap(dpy: *Display, pixmap: GLXPixmap); + + pub fn glXCreateGLXPixmap(dpy: *Display, visual: *XVisualInfo, pixmap: Pixmap) -> GLXPixmap; + + pub fn glXDestroyGLXPixmap(dpy: *Display, pix: GLXPixmap); + + pub fn glXGetFBConfigAttrib(dpy: *Display, + config: GLXFBConfig, + attribute: c_int, + value: *mut c_int) + -> c_int; + + pub fn glXGetFBConfigs(dpy: *Display, screen: c_int, nelements: *mut c_int) -> *GLXFBConfig; + + pub fn glXGetVisualFromFBConfig(dpy: *Display, config: GLXFBConfig) -> *XVisualInfo; +} + diff --git a/lib.rs b/lib.rs index 8d67c76..2cc5bfc 100644 --- a/lib.rs +++ b/lib.rs @@ -15,6 +15,9 @@ extern mod std; pub mod gl2; +#[cfg(target_os="linux")] +pub mod glx; + #[cfg(target_os="macos")] pub mod cgl;