mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 05:21:31 +11:00
Update for changes in gl-rs
This commit is contained in:
parent
2e44edea60
commit
7ce851dad9
|
@ -31,7 +31,7 @@ pub struct Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(window: &glutin::Window) -> Context {
|
pub fn load(window: &glutin::Window) -> Context {
|
||||||
let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol));
|
let gl = gl::Gl::load(window);
|
||||||
|
|
||||||
let version = {
|
let version = {
|
||||||
use std::c_str::CString;
|
use std::c_str::CString;
|
||||||
|
@ -46,42 +46,46 @@ pub fn load(window: &glutin::Window) -> Context {
|
||||||
impl Context {
|
impl Context {
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
|
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
|
||||||
self.gl.ClearColor(color.0, color.1, color.2, color.3);
|
unsafe {
|
||||||
self.gl.Clear(gl::COLOR_BUFFER_BIT);
|
self.gl.ClearColor(color.0, color.1, color.2, color.3);
|
||||||
|
self.gl.Clear(gl::COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
self.gl.Begin(gl::TRIANGLES);
|
self.gl.Begin(gl::TRIANGLES);
|
||||||
self.gl.Color3f(1.0, 0.0, 0.0);
|
self.gl.Color3f(1.0, 0.0, 0.0);
|
||||||
self.gl.Vertex2f(-0.5, -0.5);
|
self.gl.Vertex2f(-0.5, -0.5);
|
||||||
self.gl.Color3f(0.0, 1.0, 0.0);
|
self.gl.Color3f(0.0, 1.0, 0.0);
|
||||||
self.gl.Vertex2f(0.0, 0.5);
|
self.gl.Vertex2f(0.0, 0.5);
|
||||||
self.gl.Color3f(0.0, 0.0, 1.0);
|
self.gl.Color3f(0.0, 0.0, 1.0);
|
||||||
self.gl.Vertex2f(0.5, -0.5);
|
self.gl.Vertex2f(0.5, -0.5);
|
||||||
self.gl.End();
|
self.gl.End();
|
||||||
|
|
||||||
self.gl.Flush();
|
self.gl.Flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
|
pub fn draw_frame(&self, color: (f32, f32, f32, f32)) {
|
||||||
self.gl.ClearColor(color.0, color.1, color.2, color.3);
|
|
||||||
self.gl.Clear(gl::COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
self.gl.EnableClientState(gl::VERTEX_ARRAY);
|
|
||||||
self.gl.EnableClientState(gl::COLOR_ARRAY);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
use std::mem;
|
self.gl.ClearColor(color.0, color.1, color.2, color.3);
|
||||||
self.gl.VertexPointer(2, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
|
self.gl.Clear(gl::COLOR_BUFFER_BIT);
|
||||||
mem::transmute(VERTEX_DATA.as_slice().as_ptr()));
|
|
||||||
self.gl.ColorPointer(3, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
|
|
||||||
mem::transmute(VERTEX_DATA.as_slice().as_ptr().offset(2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.gl.DrawArrays(gl::TRIANGLES, 0, 3);
|
self.gl.EnableClientState(gl::VERTEX_ARRAY);
|
||||||
self.gl.DisableClientState(gl::VERTEX_ARRAY);
|
self.gl.EnableClientState(gl::COLOR_ARRAY);
|
||||||
self.gl.DisableClientState(gl::COLOR_ARRAY);
|
|
||||||
|
unsafe {
|
||||||
self.gl.Flush();
|
use std::mem;
|
||||||
|
self.gl.VertexPointer(2, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
|
||||||
|
mem::transmute(VERTEX_DATA.as_slice().as_ptr()));
|
||||||
|
self.gl.ColorPointer(3, gl::FLOAT, (mem::size_of::<f32>() * 5) as i32,
|
||||||
|
mem::transmute(VERTEX_DATA.as_slice().as_ptr().offset(2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.gl.DrawArrays(gl::TRIANGLES, 0, 3);
|
||||||
|
self.gl.DisableClientState(gl::VERTEX_ARRAY);
|
||||||
|
self.gl.DisableClientState(gl::COLOR_ARRAY);
|
||||||
|
|
||||||
|
self.gl.Flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#[phase(plugin)] extern crate compile_msg;
|
#[phase(plugin)] extern crate compile_msg;
|
||||||
#[phase(plugin)] extern crate gl_generator;
|
#[phase(plugin)] extern crate gl_generator;
|
||||||
|
|
||||||
|
extern crate gl_common;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -397,6 +399,13 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "window")]
|
||||||
|
impl gl_common::GlFunctionsSource for Window {
|
||||||
|
fn get_proc_addr(&self, addr: &str) -> *const libc::c_void {
|
||||||
|
self.get_proc_address(addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a headless OpenGL context.
|
/// Represents a headless OpenGL context.
|
||||||
#[cfg(feature = "headless")]
|
#[cfg(feature = "headless")]
|
||||||
pub struct HeadlessContext {
|
pub struct HeadlessContext {
|
||||||
|
@ -421,6 +430,13 @@ impl HeadlessContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "headless")]
|
||||||
|
impl gl_common::GlFunctionsSource for HeadlessContext {
|
||||||
|
fn get_proc_addr(&self, addr: &str) -> *const libc::c_void {
|
||||||
|
self.get_proc_address(addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An iterator for the `poll_events` function.
|
/// An iterator for the `poll_events` function.
|
||||||
// Implementation note: we retreive the list once, then serve each element by one by one.
|
// Implementation note: we retreive the list once, then serve each element by one by one.
|
||||||
// This may change in the future.
|
// This may change in the future.
|
||||||
|
|
|
@ -350,7 +350,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
|
||||||
if builder_vsync {
|
if builder_vsync {
|
||||||
if extra_functions.SwapIntervalEXT.is_loaded() {
|
if extra_functions.SwapIntervalEXT.is_loaded() {
|
||||||
unsafe { ffi::wgl::MakeCurrent(hdc, context) };
|
unsafe { ffi::wgl::MakeCurrent(hdc, context) };
|
||||||
if extra_functions.SwapIntervalEXT(1) == 0 {
|
if unsafe { extra_functions.SwapIntervalEXT(1) } == 0 {
|
||||||
tx.send(Err(format!("wglSwapIntervalEXT failed")));
|
tx.send(Err(format!("wglSwapIntervalEXT failed")));
|
||||||
unsafe { ffi::wgl::DeleteContext(context); }
|
unsafe { ffi::wgl::DeleteContext(context); }
|
||||||
unsafe { ffi::DestroyWindow(real_window); }
|
unsafe { ffi::DestroyWindow(real_window); }
|
||||||
|
|
|
@ -24,12 +24,14 @@ fn main() {
|
||||||
|
|
||||||
let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol));
|
let gl = gl::Gl::load_with(|symbol| window.get_proc_address(symbol));
|
||||||
|
|
||||||
gl.ClearColor(0.0, 1.0, 0.0, 1.0);
|
unsafe {
|
||||||
gl.Clear(gl::COLOR_BUFFER_BIT);
|
gl.ClearColor(0.0, 1.0, 0.0, 1.0);
|
||||||
|
gl.Clear(gl::COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
let mut value: (u8, u8, u8, u8) = unsafe { std::mem::uninitialized() };
|
let mut value: (u8, u8, u8, u8) = std::mem::uninitialized();
|
||||||
unsafe { gl.ReadPixels(0, 0, 1, 1, gl::RGBA, gl::UNSIGNED_BYTE, std::mem::transmute(&mut value)) };
|
gl.ReadPixels(0, 0, 1, 1, gl::RGBA, gl::UNSIGNED_BYTE, std::mem::transmute(&mut value));
|
||||||
|
|
||||||
assert!(value == (0, 255, 0, 255) || value == (0, 64, 0, 255) ||
|
assert!(value == (0, 255, 0, 255) || value == (0, 64, 0, 255) ||
|
||||||
value == (0, 64, 0, 255) || value == (0, 64, 0, 0));
|
value == (0, 64, 0, 255) || value == (0, 64, 0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue