aboutsummaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-09-13 09:01:21 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-09-13 09:01:21 +0200
commitf3e0c571582683647e0c1d16ebf16fc2be77cbfc (patch)
treeb0f73686f691f86d29fc2aa93c168cfa4b3e7948 /src/android
parentf91bd5d2d8817920e4067ee6c12f7fba9e1a620e (diff)
downloadglutin-f3e0c571582683647e0c1d16ebf16fc2be77cbfc.tar.gz
glutin-f3e0c571582683647e0c1d16ebf16fc2be77cbfc.zip
Use gl_generator to generate EGL bindings for Android
Diffstat (limited to 'src/android')
-rw-r--r--src/android/ffi.rs169
-rw-r--r--src/android/mod.rs48
2 files changed, 47 insertions, 170 deletions
diff --git a/src/android/ffi.rs b/src/android/ffi.rs
index 123a3f0..583109f 100644
--- a/src/android/ffi.rs
+++ b/src/android/ffi.rs
@@ -4,156 +4,33 @@
use libc;
-pub type EGLBoolean = libc::c_int;
-pub type EGLint = i32;
-pub type EGLDisplay = *const libc::c_void;
-pub type EGLConfig = *const libc::c_void;
-pub type EGLSurface = *const libc::c_void;
-pub type EGLContext = *const libc::c_void;
-
-pub type NativePixmapType = *const libc::c_void; // FIXME: egl_native_pixmap_t instead
-pub type NativeWindowType = *const ANativeWindow;
-
-pub static EGL_DEFAULT_DISPLAY: EGLint = 0;
-/*pub static EGL_NO_CONTEXT: EGLContext = { use std::ptr; ptr::null() };
-pub static EGL_NO_DISPLAY: EGLDisplay = { use std::ptr; ptr::null() };
-pub static EGL_NO_SURFACE: EGLSurface = { use std::ptr; ptr::null() };*/
-
-pub static EGL_VERSION_1_0: EGLint = 1;
-pub static EGL_VERSION_1_1: EGLint = 1;
-
-pub static EGL_FALSE: EGLint = 0;
-pub static EGL_TRUE: EGLint = 1;
-
-pub static EGL_SUCCESS: EGLint = 0x3000;
-pub static EGL_NOT_INITIALIZED: EGLint = 0x3001;
-pub static EGL_BAD_ACCESS: EGLint = 0x3002;
-pub static EGL_BAD_ALLOC: EGLint = 0x3003;
-pub static EGL_BAD_ATTRIBUTE: EGLint = 0x3004;
-pub static EGL_BAD_CONFIG: EGLint = 0x3005;
-pub static EGL_BAD_CONTEXT: EGLint = 0x3006;
-pub static EGL_BAD_CURRENT_SURFACE: EGLint = 0x3007;
-pub static EGL_BAD_DISPLAY: EGLint = 0x3008;
-pub static EGL_BAD_MATCH: EGLint = 0x3009;
-pub static EGL_BAD_NATIVE_PIXMAP: EGLint = 0x300A;
-pub static EGL_BAD_NATIVE_WINDOW: EGLint = 0x300B;
-pub static EGL_BAD_PARAMETER: EGLint = 0x300C;
-pub static EGL_BAD_SURFACE: EGLint = 0x300D;
-pub static EGL_CONTEXT_LOST: EGLint = 0x300E;
-
-pub static EGL_BUFFER_SIZE: EGLint = 0x3020;
-pub static EGL_ALPHA_SIZE: EGLint = 0x3021;
-pub static EGL_BLUE_SIZE: EGLint = 0x3022;
-pub static EGL_GREEN_SIZE: EGLint = 0x3023;
-pub static EGL_RED_SIZE: EGLint = 0x3024;
-pub static EGL_DEPTH_SIZE: EGLint = 0x3025;
-pub static EGL_STENCIL_SIZE: EGLint = 0x3026;
-pub static EGL_CONFIG_CAVEAT: EGLint = 0x3027;
-pub static EGL_CONFIG_ID: EGLint = 0x3028;
-pub static EGL_LEVEL: EGLint = 0x3029;
-pub static EGL_MAX_PBUFFER_HEIGHT: EGLint = 0x302A;
-pub static EGL_MAX_PBUFFER_PIXELS: EGLint = 0x302B;
-pub static EGL_MAX_PBUFFER_WIDTH: EGLint = 0x302C;
-pub static EGL_NATIVE_RENDERABLE: EGLint = 0x302D;
-pub static EGL_NATIVE_VISUAL_ID: EGLint = 0x302E;
-pub static EGL_NATIVE_VISUAL_TYPE: EGLint = 0x302F;
-/*pub static EGL_PRESERVED_RESOURCES: EGLint = 0x3030;*/
-pub static EGL_SAMPLES: EGLint = 0x3031;
-pub static EGL_SAMPLE_BUFFERS: EGLint = 0x3032;
-pub static EGL_SURFACE_TYPE: EGLint = 0x3033;
-pub static EGL_TRANSPARENT_TYPE: EGLint = 0x3034;
-pub static EGL_TRANSPARENT_BLUE_VALUE: EGLint = 0x3035;
-pub static EGL_TRANSPARENT_GREEN_VALUE: EGLint = 0x3036;
-pub static EGL_TRANSPARENT_RED_VALUE: EGLint = 0x3037;
-pub static EGL_NONE: EGLint = 0x3038 /* Also a config value */;
-pub static EGL_BIND_TO_TEXTURE_RGB: EGLint = 0x3039;
-pub static EGL_BIND_TO_TEXTURE_RGBA: EGLint = 0x303A;
-pub static EGL_MIN_SWAP_INTERVAL: EGLint = 0x303B;
-pub static EGL_MAX_SWAP_INTERVAL: EGLint = 0x303C;
-
-
-pub static EGL_DONT_CARE: EGLint = -1;
-pub static EGL_SLOW_CONFIG: EGLint = 0x3050 /* EGL_CONFIG_CAVEAT value */;
-pub static EGL_NON_CONFORMANT_CONFIG: EGLint = 0x3051 /* " */;
-pub static EGL_TRANSPARENT_RGB: EGLint = 0x3052 /* EGL_TRANSPARENT_TYPE value */;
-pub static EGL_NO_TEXTURE: EGLint = 0x305C /* EGL_TEXTURE_FORMAT/TARGET value */;
-pub static EGL_TEXTURE_RGB: EGLint = 0x305D /* EGL_TEXTURE_FORMAT value */;
-pub static EGL_TEXTURE_RGBA: EGLint = 0x305E /* " */;
-pub static EGL_TEXTURE_2D: EGLint = 0x305F /* EGL_TEXTURE_TARGET value */;
-
-pub static EGL_PBUFFER_BIT: EGLint = 0x01 /* EGL_SURFACE_TYPE mask bit */;
-pub static EGL_PIXMAP_BIT: EGLint = 0x02 /* " */;
-pub static EGL_WINDOW_BIT: EGLint = 0x04 /* " */;
-
-pub static EGL_VENDOR: EGLint = 0x3053 /* eglQueryString target */;
-pub static EGL_VERSION: EGLint = 0x3054 /* " */;
-pub static EGL_EXTENSIONS: EGLint = 0x3055 /* " */;
-
-pub static EGL_HEIGHT: EGLint = 0x3056;
-pub static EGL_WIDTH: EGLint = 0x3057;
-pub static EGL_LARGEST_PBUFFER: EGLint = 0x3058;
-pub static EGL_TEXTURE_FORMAT: EGLint = 0x3080 /* For pbuffers bound as textures */;
-pub static EGL_TEXTURE_TARGET: EGLint = 0x3081 /* " */;
-pub static EGL_MIPMAP_TEXTURE: EGLint = 0x3082 /* " */;
-pub static EGL_MIPMAP_LEVEL: EGLint = 0x3083 /* " */;
-
-pub static EGL_BACK_BUFFER: EGLint = 0x3084;
-
-pub static EGL_DRAW: EGLint = 0x3059;
-pub static EGL_READ: EGLint = 0x305A;
-
-pub static EGL_CORE_NATIVE_ENGINE: EGLint = 0x305B;
+pub mod egl {
+ pub type khronos_utime_nanoseconds_t = super::khronos_utime_nanoseconds_t;
+ pub type khronos_uint64_t = super::khronos_uint64_t;
+ pub type khronos_ssize_t = super::khronos_ssize_t;
+ pub type EGLNativeDisplayType = super::EGLNativeDisplayType;
+ pub type EGLNativePixmapType = super::EGLNativePixmapType;
+ pub type EGLNativeWindowType = super::EGLNativeWindowType;
+ pub type EGLint = super::EGLint;
+ pub type NativeDisplayType = super::EGLNativeDisplayType;
+ pub type NativePixmapType = super::EGLNativePixmapType;
+ pub type NativeWindowType = super::EGLNativeWindowType;
+
+ generate_gl_bindings!("egl", "core", "1.5", "static")
+}
+
+pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
+pub type khronos_uint64_t = libc::uint64_t;
+pub type khronos_ssize_t = libc::c_long;
+pub type EGLint = libc::int32_t;
+pub type EGLNativeDisplayType = *const libc::c_void;
+pub type EGLNativePixmapType = *const libc::c_void; // FIXME: egl_native_pixmap_t instead
+pub type EGLNativeWindowType = *const ANativeWindow;
#[link(name = "android")]
#[link(name = "EGL")]
#[link(name = "GLESv2")]
-extern {
- pub fn eglGetError() -> EGLint;
-
- pub fn eglGetDisplay(display: *const ()/*NativeDisplayType*/) -> EGLDisplay;
- pub fn eglInitialize(dpy: EGLDisplay, major: *mut EGLint, minor: *mut EGLint) -> EGLBoolean;
- pub fn eglTerminate(dpy: EGLDisplay) -> EGLBoolean;
- pub fn eglQueryString(dpy: EGLDisplay, name: EGLint) -> *const libc::c_char;
- pub fn eglGetProcAddress(procname: *const libc::c_char) -> *const ();
-
- pub fn eglGetConfigs(dpy: EGLDisplay, configs: *mut EGLConfig, config_size: EGLint,
- num_config: *mut EGLint) -> EGLBoolean;
- pub fn eglChooseConfig(dpy: EGLDisplay, attrib_list: *const EGLint, configs: *mut EGLConfig,
- config_size: EGLint, num_config: *mut EGLint) -> EGLBoolean;
- pub fn eglGetConfigAttrib(dpy: EGLDisplay, config: EGLConfig, attribute: EGLint,
- value: *mut EGLint) -> EGLBoolean;
-
- pub fn eglCreateWindowSurface(dpy: EGLDisplay, config: EGLConfig, window: NativeWindowType, attrib_list: *const EGLint) -> EGLSurface;
- pub fn eglCreatePixmapSurface(dpy: EGLDisplay, config: EGLConfig, pixmap: NativePixmapType, attrib_list: *const EGLint) -> EGLSurface;
- pub fn eglCreatePbufferSurface(dpy: EGLDisplay, config: EGLConfig,
- attrib_list: *const EGLint) -> EGLSurface;
- pub fn eglDestroySurface(dpy: EGLDisplay, surface: EGLSurface) -> EGLBoolean;
- pub fn eglQuerySurface(dpy: EGLDisplay, surface: EGLSurface, attribute: EGLint,
- value: *mut EGLint) -> EGLBoolean;
-
- pub fn eglSurfaceAttrib(dpy: EGLDisplay, surface: EGLSurface, attribute: EGLint,
- value: EGLint) -> EGLBoolean;
- pub fn eglBindTexImage(dpy: EGLDisplay, surface: EGLSurface, buffer: EGLint) -> EGLBoolean;
- pub fn eglReleaseTexImage(dpy: EGLDisplay, surface: EGLSurface, buffer: EGLint) -> EGLBoolean;
-
- pub fn eglSwapInterval(dpy: EGLDisplay, interval: EGLint) -> EGLBoolean;
-
- pub fn eglCreateContext(dpy: EGLDisplay, config: EGLConfig, share_list: EGLContext,
- attrib_list: *const EGLint) -> EGLContext;
- pub fn eglDestroyContext(dpy: EGLDisplay, ctx: EGLContext) -> EGLBoolean;
- pub fn eglMakeCurrent(dpy: EGLDisplay, draw: EGLSurface, read: EGLSurface,
- ctx: EGLContext) -> EGLBoolean;
- pub fn eglGetCurrentContext() -> EGLContext;
- pub fn eglGetCurrentSurface(readdraw: EGLint) -> EGLSurface;
- pub fn eglGetCurrentDisplay() -> EGLDisplay;
- pub fn eglQueryContext(dpy: EGLDisplay, ctx: EGLContext, attribute: EGLint,
- value: *mut EGLint) -> EGLBoolean;
-
- pub fn eglWaitGL() -> EGLBoolean;
- pub fn eglWaitNative(engine: EGLint) -> EGLBoolean;
- pub fn eglSwapBuffers(dpy: EGLDisplay, draw: EGLSurface) -> EGLBoolean;
- //pub fn eglCopyBuffers(dpy: EGLDisplay, surface: EGLSurface, target: NativePixmapType) -> EGLBoolean;
-}
+extern {}
/**
* asset_manager.h
diff --git a/src/android/mod.rs b/src/android/mod.rs
index 74a07e6..a544864 100644
--- a/src/android/mod.rs
+++ b/src/android/mod.rs
@@ -6,9 +6,9 @@ use self::native::NativeTaskBuilder;
use {Event, WindowBuilder};
pub struct Window {
- display: ffi::EGLDisplay,
- context: ffi::EGLContext,
- surface: ffi::EGLSurface,
+ display: ffi::egl::types::EGLDisplay,
+ context: ffi::egl::types::EGLContext,
+ surface: ffi::egl::types::EGLSurface,
}
pub struct MonitorID;
@@ -46,7 +46,7 @@ impl Window {
}
let display = unsafe {
- let display = ffi::eglGetDisplay(mem::transmute(ffi::EGL_DEFAULT_DISPLAY));
+ let display = ffi::egl::GetDisplay(mem::transmute(ffi::egl::DEFAULT_DISPLAY));
if display.is_null() {
return Err("No EGL display connection available".to_string());
}
@@ -56,10 +56,10 @@ impl Window {
android_glue::write_log("eglGetDisplay succeeded");
let (_major, _minor) = unsafe {
- let mut major: ffi::EGLint = mem::uninitialized();
- let mut minor: ffi::EGLint = mem::uninitialized();
+ let mut major: ffi::egl::types::EGLint = mem::uninitialized();
+ let mut minor: ffi::egl::types::EGLint = mem::uninitialized();
- if ffi::eglInitialize(display, &mut major, &mut minor) != ffi::EGL_TRUE {
+ if ffi::egl::Initialize(display, &mut major, &mut minor) == 0 {
return Err(format!("eglInitialize failed"))
}
@@ -70,16 +70,16 @@ impl Window {
let config = unsafe {
let attribute_list = [
- ffi::EGL_RED_SIZE, 1,
- ffi::EGL_GREEN_SIZE, 1,
- ffi::EGL_BLUE_SIZE, 1,
- ffi::EGL_NONE
+ ffi::egl::RED_SIZE as i32, 1,
+ ffi::egl::GREEN_SIZE as i32, 1,
+ ffi::egl::BLUE_SIZE as i32, 1,
+ ffi::egl::NONE as i32
];
- let mut num_config: ffi::EGLint = mem::uninitialized();
- let mut config: ffi::EGLConfig = mem::uninitialized();
- if ffi::eglChooseConfig(display, attribute_list.as_ptr(), &mut config, 1,
- &mut num_config) != ffi::EGL_TRUE
+ let mut num_config: ffi::egl::types::EGLint = mem::uninitialized();
+ let mut config: ffi::egl::types::EGLConfig = mem::uninitialized();
+ if ffi::egl::ChooseConfig(display, attribute_list.as_ptr(), &mut config, 1,
+ &mut num_config) == 0
{
return Err(format!("eglChooseConfig failed"))
}
@@ -94,7 +94,7 @@ impl Window {
android_glue::write_log("eglChooseConfig succeeded");
let context = unsafe {
- let context = ffi::eglCreateContext(display, config, ptr::null(), ptr::null());
+ let context = ffi::egl::CreateContext(display, config, ptr::null(), ptr::null());
if context.is_null() {
return Err(format!("eglCreateContext failed"))
}
@@ -104,7 +104,7 @@ impl Window {
android_glue::write_log("eglCreateContext succeeded");
let surface = unsafe {
- let surface = ffi::eglCreateWindowSurface(display, config, native_window, ptr::null());
+ let surface = ffi::egl::CreateWindowSurface(display, config, native_window, ptr::null());
if surface.is_null() {
return Err(format!("eglCreateWindowSurface failed"))
}
@@ -170,7 +170,7 @@ impl Window {
pub fn make_current(&self) {
unsafe {
- ffi::eglMakeCurrent(self.display, self.surface, self.surface, self.context);
+ ffi::egl::MakeCurrent(self.display, self.surface, self.surface, self.context);
}
}
@@ -179,14 +179,14 @@ impl Window {
unsafe {
addr.with_c_str(|s| {
- ffi::eglGetProcAddress(s) as *const ()
+ ffi::egl::GetProcAddress(s) as *const ()
})
}
}
pub fn swap_buffers(&self) {
unsafe {
- ffi::eglSwapBuffers(self.display, self.surface);
+ ffi::egl::SwapBuffers(self.display, self.surface);
}
}
}
@@ -198,10 +198,10 @@ impl Drop for Window {
unsafe {
android_glue::write_log("Destroying gl-init window");
- ffi::eglMakeCurrent(self.display, ptr::null(), ptr::null(), ptr::null());
- ffi::eglDestroySurface(self.display, self.surface);
- ffi::eglDestroyContext(self.display, self.context);
- ffi::eglTerminate(self.display);
+ ffi::egl::MakeCurrent(self.display, ptr::null(), ptr::null(), ptr::null());
+ ffi::egl::DestroySurface(self.display, self.surface);
+ ffi::egl::DestroyContext(self.display, self.context);
+ ffi::egl::Terminate(self.display);
}
}
}