first push, simple setup to use opengl

It's all insired in copy/paste style by: https://github.com/Nercury/rust-and-opengl-lessons
This commit is contained in:
Lapin 2021-07-21 19:39:59 +02:00
commit cf64bec257
24 changed files with 3139 additions and 0 deletions

11
lib/gl/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "gl"
version = "0.1.0"
authors = ["Nerijus Arlauskas <nercury@gmail.com>"]
[build-dependencies]
gl_generator = "0.9"
gl_generator_profiling_struct = "0.1"
[features]
debug = []

25
lib/gl/build.rs Normal file
View file

@ -0,0 +1,25 @@
extern crate gl_generator;
extern crate gl_generator_profiling_struct;
use gl_generator::{Api, Fallbacks, Profile, Registry};
use gl_generator_profiling_struct::ProfilingStructGenerator;
use std::env;
use std::fs::File;
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let mut file_gl = File::create(&Path::new(&out_dir).join("bindings.rs")).unwrap();
let registry = Registry::new(
Api::Gl,
(4, 5),
Profile::Core,
Fallbacks::All,
["GL_NV_command_list"],
);
registry
.write_bindings(ProfilingStructGenerator, &mut file_gl)
.unwrap();
}

33
lib/gl/src/lib.rs Normal file
View file

@ -0,0 +1,33 @@
mod bindings {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
use std::ops::Deref;
use std::rc::Rc;
pub use crate::bindings::Gl as InnerGl;
pub use crate::bindings::*;
#[derive(Clone)]
pub struct Gl {
inner: Rc<bindings::Gl>,
}
impl Gl {
pub fn load_with<F>(loadfn: F) -> Gl
where
F: FnMut(&'static str) -> *const types::GLvoid,
{
Gl {
inner: Rc::new(bindings::Gl::load_with(loadfn)),
}
}
}
impl Deref for Gl {
type Target = bindings::Gl;
fn deref(&self) -> &bindings::Gl {
&self.inner
}
}