Skip to content

Commit

Permalink
Fix GLES implementation and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danyspin97 committed Dec 20, 2023
1 parent 5c9b165 commit f1e421e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 40 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ walkdir = "2.4.0"
dirs = "5.0.1"
serde_json = "1.0.108"
wayland-egl = "0.32.0"
wayland-backend = { version = "0.3.2", features = ["client_system"] }
glutin = { version = "0.31.1", default-features = false, features = ["egl"] }
gl_generator = "0.14.0"
khronos-egl = { version = "6.0.0", features = [ "static" ] }
Expand Down
9 changes: 5 additions & 4 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use flexi_logger::{Duplicate, FileSpec, Logger};
use hotwatch::{Event, Hotwatch};
use log::error;
use nix::unistd::fork;
use smithay_client_toolkit::reexports::client::{Proxy, QueueHandle};
use smithay_client_toolkit::reexports::client::Proxy;
use smithay_client_toolkit::reexports::{
calloop::{self, channel::Sender},
calloop_wayland_source::WaylandSource,
Expand Down Expand Up @@ -67,9 +67,10 @@ fn run(config: Config, xdg_dirs: BaseDirectories) -> Result<()> {

let conn = Connection::connect_to_env().unwrap();

let egl_display = egl
.get_display(conn.display().id().as_ptr() as *mut std::ffi::c_void)
.unwrap();
let egl_display = unsafe {
egl.get_display(conn.display().id().as_ptr() as *mut std::ffi::c_void)
.unwrap()
};
egl.initialize(egl_display).unwrap();

let (globals, event_queue) = registry_queue_init(&conn).unwrap();
Expand Down
33 changes: 10 additions & 23 deletions daemon/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{
ffi::{CStr, CString},
ops::Deref,
};
use std::ops::Deref;

use egl::API as egl;
use glutin::prelude::*;

pub mod gl {
#![allow(clippy::all)]
Expand Down Expand Up @@ -90,7 +86,7 @@ impl Renderer {
std::ptr::null(),
);
println!("{}", gl.GetError());
// gl.EnableVertexAttribArray(POS_ATTRIB as gl::types::GLuint);
gl.EnableVertexAttribArray(POS_ATTRIB as gl::types::GLuint);
println!("{}", gl.GetError());

gl.VertexAttribPointer(
Expand All @@ -102,7 +98,7 @@ impl Renderer {
(2 * std::mem::size_of::<f32>()) as *const () as *const _,
);
println!("vertexattrib tex {}", gl.GetError());
// gl.EnableVertexAttribArray(TEX_ATTRIB as gl::types::GLuint);
gl.EnableVertexAttribArray(TEX_ATTRIB as gl::types::GLuint);
println!("tex_attrib {}", gl.GetError());

Self {
Expand All @@ -119,7 +115,6 @@ impl Renderer {
self.gl.UseProgram(self.program);

self.gl.BindVertexArray(self.vao);
println!("vao: {}", self.vao);
println!("bindvertex {}", self.GetError());
self.gl.BindBuffer(gl::ARRAY_BUFFER, self.vbo);
println!("{}", self.GetError());
Expand Down Expand Up @@ -193,20 +188,13 @@ unsafe fn create_shader(
}
}

fn get_gl_string(gl: &gl::Gl, variant: gl::types::GLenum) -> Option<&'static CStr> {
unsafe {
let s = gl.GetString(variant);
(!s.is_null()).then(|| CStr::from_ptr(s.cast()))
}
}

#[rustfmt::skip]
static VERTEX_DATA: [f32; 24] = [
-1.0, -1.0, 0.0, 0.0,
-1.0, 1.0, 1.0, 0.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 0.0,
1.0, -1.0, 1.0, 0.0,
-1.0, -1.0, 0.0, 1.0,
-1.0, 1.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0,
1.0, 1.0, 1.0, 0.0,
1.0, -1.0, 1.0, 1.0,
-1.0, -1.0, 0.0, 1.0,
];

Expand All @@ -220,7 +208,7 @@ attribute vec2 texcoord;
varying vec2 v_texcoord;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
gl_Position = vec4(position, 1.0, 1.0);
v_texcoord = texcoord;
}
\0";
Expand Down Expand Up @@ -255,7 +243,6 @@ uniform sampler2D u_texture;
varying vec2 v_texcoord;
void main() {
// gl_FragColor = vec4(v_color, 1.0);
gl_FragColor = texture2D(u_texture, v_texcoord);;
gl_FragColor = texture2D(u_texture, v_texcoord);
}
\0";
16 changes: 3 additions & 13 deletions daemon/src/surface.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
use std::ffi::c_void;
use std::fs::OpenOptions;
use std::io::{BufWriter, Write};
use std::path::Path;
use std::path::PathBuf;
use std::ptr::{null, slice_from_raw_parts_mut};
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;

use color_eyre::eyre::{bail, ensure, Context};
use color_eyre::Result;
use egl::API as egl;
use glutin::api::egl::device::Device;
use glutin::api::egl::display::Display;
use glutin::config::{ConfigSurfaceTypes, ConfigTemplate, ConfigTemplateBuilder};
use glutin::context::{ContextApi, ContextAttributesBuilder};
use glutin::prelude::*;
use image::imageops::FilterType;
use image::{open, DynamicImage, ImageBuffer, Pixel, Rgba};
use log::{info, warn};
use nix::libc::MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED;
use smithay_client_toolkit::compositor::Region;
use smithay_client_toolkit::output::OutputInfo;
use smithay_client_toolkit::reexports::calloop::timer::{TimeoutAction, Timer};
use smithay_client_toolkit::reexports::calloop::LoopHandle;
use smithay_client_toolkit::reexports::client::protocol::wl_output::WlOutput;
use smithay_client_toolkit::reexports::client::protocol::{wl_shm, wl_surface};
use smithay_client_toolkit::reexports::client::protocol::wl_surface;
use smithay_client_toolkit::reexports::client::{Proxy, QueueHandle};
use smithay_client_toolkit::shell::wlr_layer::{Anchor, Layer, LayerSurface};
use smithay_client_toolkit::shm::slot::SlotPool;
use walkdir::WalkDir;
use wayland_egl::WlEglSurface;

use crate::wallpaper_info::Sorting;
use crate::render::{gl, Renderer};
use crate::wallpaper_info::Sorting;
use crate::wallpaper_info::WallpaperInfo;
use crate::wpaperd::Wpaperd;

Expand Down Expand Up @@ -435,6 +424,7 @@ impl Surface {
println!("{}", renderer.GetError());
renderer.Uniform1i(loc, 0);
println!("{}", renderer.GetError());
renderer.TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
// Wait for the previous commands to finish before reading from the framebuffer.
renderer.Finish();
renderer.draw();
Expand Down

0 comments on commit f1e421e

Please sign in to comment.