target os build

This commit is contained in:
tsuki 2024-09-11 01:31:41 +08:00
parent 6d6836a83f
commit b588115b7d
12 changed files with 280 additions and 64 deletions

View File

@ -158,10 +158,11 @@ impl AttaWithBuffer for AggFastPath {
let len = ebo.len() as i32;
attach.bind_data(&vbo, Some(&ebo), len, glow::STATIC_DRAW);
attach.bind_data(gl,&vbo, Some(&ebo), len, glow::STATIC_DRAW);
Ok(())
}
#[cfg(target_os = "macos")]
fn init(
&self,
gl: &glow::Context,
@ -197,6 +198,48 @@ impl AttaWithBuffer for AggFastPath {
(vao, vbo, Some(ebo), None)
}
}
#[cfg(not(target_os = "macos"))]
fn init(
&self,
gl: &glow::Context,
) -> (
NativeVertexArray,
NativeBuffer,
Option<NativeBuffer>,
Option<NativeTexture>,
) {
unsafe {
let vao = gl.create_vertex_array().unwrap();
let vbo = gl.create_buffer().unwrap();
gl.vertex_array_vertex_buffer(vao, 0, Some(vbo), 0, 40);
gl.enable_vertex_array_attrib(vao, 0);
gl.vertex_array_attrib_format_i32(vao, 0, 4, glow::FLOAT, 0);
gl.enable_vertex_array_attrib(vao, 1);
gl.vertex_array_attrib_format_i32(vao, 1, 3, glow::FLOAT, 12);
gl.enable_vertex_array_attrib(vao, 2);
gl.vertex_array_attrib_format_i32(vao, 2, 3, glow::FLOAT, 24);
gl.enable_vertex_array_attrib(vao, 3);
gl.vertex_array_attrib_format_i32(vao, 3, 3, glow::FLOAT, 36);
gl.vertex_array_attrib_binding_f32(vao, 0, 0);
gl.vertex_array_attrib_binding_f32(vao, 1, 0);
gl.vertex_array_attrib_binding_f32(vao, 2, 0);
gl.vertex_array_attrib_binding_f32(vao, 3, 0);
let ebo = gl.create_buffer().unwrap();
gl.vertex_array_element_buffer(vao, Some(ebo));
(vao, vbo, Some(ebo), None)
}
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy, Zeroable, Pod)]

View File

@ -54,6 +54,7 @@ impl ColorMap for LinearColormap {
program: &crate::components::Program,
) -> crate::errors::Result<()> {
use bytemuck::cast_slice;
#[cfg(target_os = "macos")]
unsafe {
if self.color_changed {
let texture = gl.create_texture().unwrap();
@ -92,6 +93,27 @@ impl ColorMap for LinearColormap {
}
}
#[cfg(not(target_os = "macos"))]
unsafe {
let texture = gl.create_named_texture(glow::TEXTURE_1D).unwrap();
gl.texture_parameter_i32(
texture,
glow::TEXTURE_MIN_FILTER,
glow::NEAREST as i32,
);
gl.texture_parameter_i32(
texture,
glow::TEXTURE_MAG_FILTER,
glow::NEAREST as i32,
);
// gl.tex_storage_1d(texture, 0, glow::RGBA, self.colors.len() as i32)
todo!("implement this");
}
Ok(())
}

View File

@ -310,10 +310,11 @@ impl AttaWithBuffer for Text {
&mut *self.font_manager.borrow_mut(),
&mut *self.cache.borrow_mut(),
)?;
attach.bind_data(&v.vertex(), None, v.len() as i32, glow::STATIC_DRAW);
attach.bind_data(gl,&v.vertex(), None, v.len() as i32, glow::STATIC_DRAW);
Ok(())
}
#[cfg(target_os = "macos")]
fn init(
&self,
gl: &glow::Context,
@ -337,6 +338,36 @@ impl AttaWithBuffer for Text {
gl.bind_vertex_array(None);
gl.bind_buffer(glow::ARRAY_BUFFER, None);
(vao, vbo, None, None)
}
}
// OpenGl 4.6
#[cfg(not(target_os = "macos"))]
fn init(
&self,
gl: &glow::Context,
) -> (
glow::NativeVertexArray,
glow::NativeBuffer,
Option<glow::NativeBuffer>,
Option<glow::NativeTexture>,
) {
unsafe {
let vao = gl.create_vertex_array().unwrap();
let vbo = gl.create_buffer().unwrap();
gl.vertex_array_vertex_buffer(vao, 0, Some(vbo), 0, 48);
gl.enable_vertex_array_attrib(vao, 0);
gl.vertex_array_attrib_format_i32(vao, 0, 4, glow::FLOAT, 0);
gl.enable_vertex_array_attrib(vao, 1);
gl.vertex_array_attrib_format_i32(vao, 0, 4, glow::FLOAT, 16);
gl.vertex_array_attrib_binding_f32(vao, 0, 0);
gl.vertex_array_attrib_binding_f32(vao, 1, 0);
(vao, vbo, None, None)
}
}

View File

@ -304,7 +304,7 @@ impl AttaWithBuffer for GeoQuadMesh {
0.0,
]);
}
attach.bind_data(&vertices, None, 4, glow::STATIC_DRAW);
attach.bind_data(gl,&vertices, None, 4, glow::STATIC_DRAW);
// Texture
unsafe {
@ -376,6 +376,7 @@ impl AttaWithBuffer for GeoQuadMesh {
}
}
#[cfg(target_os = "macos")]
fn init(
&self,
gl: &glow::Context,
@ -398,6 +399,65 @@ impl AttaWithBuffer for GeoQuadMesh {
gl.bind_vertex_array(None);
gl.bind_buffer(glow::ARRAY_BUFFER, None);
// Create Texture
let texture = gl.create_texture().unwrap();
gl.bind_texture(glow::TEXTURE_3D, Some(texture));
gl.tex_parameter_i32(
glow::TEXTURE_3D,
glow::TEXTURE_MIN_FILTER,
glow::NEAREST as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_3D,
glow::TEXTURE_MAG_FILTER,
glow::NEAREST as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_3D,
glow::TEXTURE_WRAP_S,
glow::CLAMP_TO_EDGE as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_3D,
glow::TEXTURE_WRAP_T,
glow::CLAMP_TO_EDGE as i32,
);
gl.tex_parameter_i32(
glow::TEXTURE_3D,
glow::TEXTURE_WRAP_R,
glow::CLAMP_TO_EDGE as i32,
);
(vao, vbo, None, Some(texture))
}
}
#[cfg(not(target_os = "macos"))]
fn init(
&self,
gl: &glow::Context,
) -> (
glow::NativeVertexArray,
glow::NativeBuffer,
Option<glow::NativeBuffer>,
Option<glow::NativeTexture>,
) {
unsafe {
let vao = gl.create_vertex_array().unwrap();
let vbo = gl.create_buffer().unwrap();
gl.vertex_array_vertex_buffer(vao, 0, Some(vbo), 0, 24);
gl.enable_vertex_array_attrib(vao, 0);
gl.vertex_array_attrib_format_i32(vao, 0, 3, glow::FLOAT, 0);
gl.enable_vertex_array_attrib(vao, 1);
gl.vertex_array_attrib_format_i32(vao, 1, 3, glow::FLOAT, 12);
gl.vertex_array_attrib_binding_f32(vao, 0, 0);
gl.vertex_array_attrib_binding_f32(vao, 1, 0);
// Create Texture
let texture = gl.create_texture().unwrap();
gl.bind_texture(glow::TEXTURE_3D, Some(texture));

View File

@ -204,18 +204,19 @@ impl AttaWithBuffer for PPI {
let last_range = *range.last().unwrap() as f32;
let data = &data.data.cast_to::<f32>();
for azi_idx in 0..azimuth_len {
for r_idx in 0..r_len {
let azi = *azimuth.get(azi_idx).unwrap() as f32;
let r = *range.get(r_idx).unwrap() as f32 / last_range;
let data = &data.data.cast_to::<f32>();
let dt = data.get([layer, azi_idx, r_idx]).unwrap();
vertices.extend([r, azi, ele, *dt]);
}
}
let len = vertices.len() as i32 / 4;
attach.bind_data(&vertices, None, len, glow::STATIC_DRAW);
attach.bind_data(gl,&vertices, None, len, glow::STATIC_DRAW);
Ok(())
}
_ => {
@ -223,6 +224,9 @@ impl AttaWithBuffer for PPI {
}
}
}
// OpenGl 4.1
#[cfg(target_os = "macos")]
fn init(
&self,
gl: &glow::Context,
@ -245,6 +249,33 @@ impl AttaWithBuffer for PPI {
(vao, vbo, None, None)
}
}
// OpenGl 4.6
#[cfg(not(target_os = "macos"))]
fn init(
&self,
gl: &glow::Context,
) -> (
NativeVertexArray,
NativeBuffer,
Option<NativeBuffer>,
Option<glow::NativeTexture>,
) {
unsafe {
let vao = gl.create_vertex_array().unwrap();
let vbo = gl.create_buffer().unwrap();
gl.vertex_array_vertex_buffer(vao, 0, Some(vbo), 0, 16);
gl.enable_vertex_array_attrib(vao, 0);
gl.vertex_array_attrib_format_i32(vao, 0, 4, glow::FLOAT, 0);
gl.vertex_array_attrib_binding_f32(vao, 0, 0);
(vao, vbo, None, None)
}
}
}
#[derive(Default, Clone, Debug)]

View File

@ -62,7 +62,7 @@ pub struct ViewPort<T: Resource = NativeRenderbuffer> {
impl<T: Resource> ViewPort<T> {
pub fn bind(&self, gl: &glow::Context) {
self.main_fbo.bind(glow::FRAMEBUFFER);
self.main_fbo.bind(gl,glow::FRAMEBUFFER);
unsafe {
gl.viewport(
0,
@ -110,12 +110,12 @@ impl ViewPort<NativeTexture> {
let main_rbo: RcGlRcResource<NativeTexture> = gl.create_resource_rc();
let main_depth_rbo: RcGlRcResource<NativeRenderbuffer> = gl.create_resource_rc();
main_fbo.bind(glow::FRAMEBUFFER);
main_fbo.bind(gl,glow::FRAMEBUFFER);
unsafe {
// Color Attachment
gl.active_texture(glow::TEXTURE0);
main_rbo.bind(glow::TEXTURE_2D);
main_rbo.bind(gl,glow::TEXTURE_2D);
gl.tex_image_2d(
glow::TEXTURE_2D,
0,
@ -149,7 +149,7 @@ impl ViewPort<NativeTexture> {
if depth {
// Depth Attachment
main_depth_rbo.bind(glow::RENDERBUFFER);
main_depth_rbo.bind(gl,glow::RENDERBUFFER);
gl.renderbuffer_storage(
glow::RENDERBUFFER,
glow::DEPTH_COMPONENT24,
@ -195,11 +195,11 @@ impl ViewPort<NativeRenderbuffer> {
let main_rbo: RcGlRcResource<NativeRenderbuffer> = gl.create_resource_rc();
let main_depth_rbo: RcGlRcResource<NativeRenderbuffer> = gl.create_resource_rc();
main_fbo.bind(glow::FRAMEBUFFER);
main_fbo.bind(gl,glow::FRAMEBUFFER);
unsafe {
// Color Attachment
main_rbo.bind(glow::RENDERBUFFER);
main_rbo.bind(gl,glow::RENDERBUFFER);
gl.renderbuffer_storage(glow::RENDERBUFFER, glow::RGBA8, RBO_WIDTH, RBO_HEIGHT);
gl.framebuffer_renderbuffer(
glow::FRAMEBUFFER,
@ -211,7 +211,7 @@ impl ViewPort<NativeRenderbuffer> {
if depth {
// Depth Attachment
main_depth_rbo.bind(glow::RENDERBUFFER);
main_depth_rbo.bind(gl,glow::RENDERBUFFER);
gl.renderbuffer_storage(
glow::RENDERBUFFER,
glow::DEPTH_COMPONENT24,

View File

@ -194,8 +194,10 @@ impl<'b, 'a: 'b> Module for GeoQuadMeshModule<'b, 'a> {
.set_config(&self.gl, &config.to_quad_config())?;
// Quad Draw
quad_attach.bind_self(self.geo_quad_mesh_program.program_ref());
quad_attach.bind_self(&self.gl,self.geo_quad_mesh_program.program_ref());
// Bind the texture
#[cfg(target_os = "macos")]
self.bind_attach_tex(quad_attach)?;
// Draw the quad

View File

@ -9,6 +9,7 @@ use crate::{
utils::resources::{ManagedResource, RcGlBuffer, RcGlVertexArray},
GL,
};
use cgmath::num_traits::cast;
use femtovg::{renderer::OpenGl, Canvas};
use glow::{HasContext, NativeBuffer, NativeTexture, NativeVertexArray};
use radarg_core::{config::Setting, Data};
@ -64,13 +65,21 @@ impl Attach {
}
}
fn bind_self(&self, program: &Program) {
self.vao.bind(glow::VERTEX_ARRAY);
self.vbo.bind(glow::ARRAY_BUFFER);
fn bind_self(&self,gl: &glow::Context, program: &Program) {
#[cfg(target_os = "macos")]
{
self.vao.bind(gl,glow::VERTEX_ARRAY);
self.vbo.bind(gl,glow::ARRAY_BUFFER);
if let Some(ebo) = self.ebo.as_ref() {
ebo.bind(glow::ELEMENT_ARRAY_BUFFER);
ebo.bind(gl,glow::ELEMENT_ARRAY_BUFFER);
}
}
#[cfg(not(target_os = "macos"))]
unsafe {
gl.bind_vertex_array(Some(self.vao.native()));
}
}
fn unbind_self(&self) {
self.vao.unbind(glow::VERTEX_ARRAY);
@ -80,24 +89,38 @@ impl Attach {
}
}
pub fn bind_data(&mut self, vbo: &Vec<f32>, ebo: Option<&Vec<u32>>, len: i32, usage: u32) {
pub fn bind_data(&mut self,gl:&glow::Context, vbo: &Vec<f32>, ebo: Option<&Vec<u32>>, len: i32, usage: u32) {
use bytemuck::cast_slice;
self.vbo.bind(glow::ARRAY_BUFFER);
#[cfg(target_os = "macos")]
{
self.vbo.bind(gl,glow::ARRAY_BUFFER);
unsafe {
self.gl
gl
.buffer_data_u8_slice(glow::ARRAY_BUFFER, cast_slice(&vbo), usage);
if let Some(ebo) = ebo {
self.gl.bind_buffer(
gl.bind_buffer(
glow::ELEMENT_ARRAY_BUFFER,
Some(self.ebo.as_ref().unwrap().native()),
);
self.gl
gl
.buffer_data_u8_slice(glow::ELEMENT_ARRAY_BUFFER, cast_slice(&ebo), usage);
self.gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, None);
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, None);
}
}
self.vbo.unbind(glow::ARRAY_BUFFER);
}
#[cfg(not(target_os = "macos"))]
{
unsafe {
gl.named_buffer_data_u8_slice(self.vbo.native(), cast_slice(&vbo), usage);
if let Some(ebo) = ebo {
gl.named_buffer_data_u8_slice(self.ebo.as_ref().unwrap().native(), cast_slice(ebo), usage);
}
}
}
self.len = len;
}

View File

@ -314,8 +314,11 @@ impl<'b, 'a: 'b> Module for PPIModule<'b, 'a> {
}
// PPI Draw
ppi_attach.bind_self(&self.ppi_program.program_ref());
ppi_attach.bind_self(&self.gl,&self.ppi_program.program_ref());
self.ppi_program.draw(&self.gl, ppi_attach.len())?;
#[cfg(target_os = "macos")]
ppi_attach.unbind_self();
// Unmount PPI Program
@ -343,7 +346,7 @@ impl<'b, 'a: 'b> Module for PPIModule<'b, 'a> {
// PPI Tick Draw
let attach = &mut cursor.line_attach;
attach.bind_self(self.line_program.program_ref());
attach.bind_self(&self.gl,self.line_program.program_ref());
self.line_program.draw(&self.gl, attach.len())?;
attach.unbind_self();
@ -358,7 +361,7 @@ impl<'b, 'a: 'b> Module for PPIModule<'b, 'a> {
self.text_program
.set_config(&self.gl, &config.to_font_config());
tick_attach.bind_self(self.text_program.program_ref());
tick_attach.bind_self(&self.gl,self.text_program.program_ref());
self.text_program.draw(&self.gl, tick_attach.len())?;
tick_attach.unbind_self();

View File

@ -17,7 +17,7 @@ pub type RcGlRcBuffer = RcGlRcResource<NativeBuffer>;
// pub type RcGlResource<'a, T> = Rc<GlResource<'a, T>>;
pub trait ManagedResource {
fn bind(&self, target: u32);
fn bind(&self, gl:&glow::Context, target: u32);
fn unbind(&self, target: u32);
}
#[derive(Debug, Clone)]
@ -305,8 +305,8 @@ impl Deref for GL {
}
impl<T: Resource> ManagedResource for RcGlResource<'_, T> {
fn bind(&self, target: u32) {
self.0.resource.bind(self.0.gl, target);
fn bind(&self,gl:&glow::Context, target: u32) {
self.0.resource.bind(gl, target);
}
fn unbind(&self, target: u32) {
@ -315,8 +315,8 @@ impl<T: Resource> ManagedResource for RcGlResource<'_, T> {
}
impl<T: Resource> ManagedResource for RcGlRcResource<T> {
fn bind(&self, target: u32) {
self.0.resource.bind(&self.0.gl, target);
fn bind(&self,gl:&glow::Context, target: u32) {
self.0.resource.bind(gl, target);
}
fn unbind(&self, target: u32) {

View File

@ -15,14 +15,14 @@ use components::app::AppModel;
use gi::{App as GI, Helper, GL};
use once_cell::{sync::Lazy as SafeLazy, unsync::Lazy as UnsafeLazy};
use relm4::RelmApp;
use surfman::declare_surfman;
// use surfman::declare_surfman;
use tracing::info;
use tracing_subscriber;
mod predefined;
mod widgets;
declare_surfman!();
// declare_surfman!();
const APP_ID: &str = "org.tsuki.radar_g";
static RUNTIME: SafeLazy<Runtime> =

View File

@ -127,9 +127,12 @@ impl ObjectImpl for Render {
}
impl WidgetImpl for Render {
fn realize(&self) {
self.parent_realize();
}
fn unrealize(&self) {
self.obj().make_current();
self.gi.borrow_mut().as_mut().unwrap().destroy();
@ -139,6 +142,14 @@ impl WidgetImpl for Render {
}
impl GLAreaImpl for Render {
fn create_context(&self) -> Option<gtk::gdk::GLContext> {
let context = self.parent_create_context();
context.as_ref().map(|ctx| {
});
context
}
fn resize(&self, width: i32, height: i32) {
{
let mut status = self.status.borrow_mut();
@ -173,21 +184,9 @@ impl GLAreaImpl for Render {
if let Some(gi) = gi.as_mut() {
let gl = &gi.context.gl;
unsafe {
let err = gl.get_error();
if err != glow::NO_ERROR {
panic!("GL Error: {:?}", err);
}
}
let mut operation = self.opeartion.borrow_mut();
let viewport = self.viewport.borrow();
operation.deal_io(&viewport.as_ref().unwrap(), &self.io.borrow());
unsafe {
let err = gl.get_error();
if err != glow::NO_ERROR {
panic!("GL Error: {:?}", err);
}
}
gi.render(
&mut *self.modules.borrow_mut(),
@ -213,6 +212,8 @@ impl Render {
info!("Creating canvas");
widget.make_current();
widget.attach_buffers();
info!("Debug enabled: {}", self.obj().context().unwrap().is_debug_enabled());
let (mut gi, viewport) = unsafe {
static LOAD_FN: fn(&str) -> *const std::ffi::c_void =
|s| epoxy::get_proc_addr(s) as *const _;
@ -316,16 +317,16 @@ fn gl_debug_output(
fn enable_opengl_debugging(ctx: &mut glow::Context) {
unsafe {
if ctx.supported_extensions().contains("GL_ARB_debug_output") {
unsafe {
ctx.enable(glow::DEBUG_OUTPUT);
ctx.enable(glow::DEBUG_OUTPUT_SYNCHRONOUS);
ctx.debug_message_callback(|source, _type, id, severity, message| {
println!(
"GL ARB Debug Message: Source: {:?}, ID: {}, Severity: {:?}, Message: {}",
source, id, severity, message
);
});
ctx.enable(glow::DEBUG_OUTPUT);
ctx.enable(glow::DEBUG_OUTPUT_SYNCHRONOUS);
}
} else {
info!("GL_ARB_debug_output not supported");
}