1
0
Fork 0
forked from wry/wry

render: implement a vulkan renderer

This commit is contained in:
Julian Orth 2024-02-03 15:19:20 +01:00
parent 4ba8550da8
commit cf332e8436
66 changed files with 4287 additions and 239 deletions

View file

@ -263,6 +263,7 @@ impl EglDisplay {
width: buf.width,
height: buf.height,
external_only: format.external_only,
format: buf.format,
}))
}
}

View file

@ -1,8 +1,11 @@
use {
crate::gfx_apis::gl::egl::{
display::EglDisplay,
sys::{EGLImageKHR, EGL_FALSE},
PROCS,
crate::{
format::Format,
gfx_apis::gl::egl::{
display::EglDisplay,
sys::{EGLImageKHR, EGL_FALSE},
PROCS,
},
},
std::rc::Rc,
};
@ -13,6 +16,7 @@ pub struct EglImage {
pub width: i32,
pub height: i32,
pub external_only: bool,
pub format: &'static Format,
}
impl Drop for EglImage {

View file

@ -11,7 +11,7 @@ use {
};
pub struct GlFrameBuffer {
pub _rb: Option<Rc<GlRenderBuffer>>,
pub rb: Rc<GlRenderBuffer>,
pub _tex: Option<Rc<GlTexture>>,
pub ctx: Rc<EglContext>,
pub width: i32,

View file

@ -56,7 +56,7 @@ impl GlRenderBuffer {
let status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
let fb = GlFrameBuffer {
_rb: Some(self.clone()),
rb: self.clone(),
_tex: None,
ctx: self.ctx.clone(),
fbo,

View file

@ -23,6 +23,7 @@ pub struct GlTexture {
pub width: i32,
pub height: i32,
pub external_only: bool,
pub format: &'static Format,
}
pub fn image_target(external_only: bool) -> GLenum {
@ -58,6 +59,7 @@ impl GlTexture {
width: img.width,
height: img.height,
external_only: img.external_only,
format: img.format,
})
}
@ -101,6 +103,7 @@ impl GlTexture {
width,
height,
external_only: false,
format,
})
}
}

View file

@ -14,13 +14,10 @@ use {
renderer::{framebuffer::Framebuffer, image::Image},
GfxGlState, RenderError, Texture,
},
video::{
dmabuf::DmaBuf,
drm::{Drm, NodeType},
gbm::GbmDevice,
},
video::{dmabuf::DmaBuf, drm::Drm, gbm::GbmDevice},
},
ahash::AHashMap,
jay_config::video::GfxApi,
std::{
cell::{Cell, RefCell},
ffi::CString,
@ -82,14 +79,10 @@ impl GlRenderContext {
}
pub(in crate::gfx_apis::gl) fn from_drm_device(drm: &Drm) -> Result<Self, RenderError> {
let nodes = drm.get_nodes()?;
let node = match nodes
.get(&NodeType::Render)
.or_else(|| nodes.get(&NodeType::Primary))
{
None => return Err(RenderError::NoRenderNode),
Some(path) => Rc::new(path.to_owned()),
};
let node = drm
.get_render_node()?
.ok_or(RenderError::NoRenderNode)
.map(Rc::new)?;
let dpy = EglDisplay::create(drm)?;
if !dpy.formats.contains_key(&XRGB8888.drm) {
return Err(RenderError::XRGB888);
@ -226,6 +219,7 @@ impl GfxContext for GlRenderContext {
fn shmem_texture(
self: Rc<Self>,
_old: Option<Rc<dyn GfxTexture>>,
data: &[Cell<u8>],
format: &'static Format,
width: i32,
@ -241,4 +235,8 @@ impl GfxContext for GlRenderContext {
fn gbm(&self) -> &GbmDevice {
&self.gbm
}
fn gfx_api(&self) -> GfxApi {
GfxApi::OpenGl
}
}

View file

@ -1,7 +1,7 @@
use {
crate::{
format::Format,
gfx_api::{GfxApiOpt, GfxFramebuffer},
gfx_api::{GfxApiOpt, GfxError, GfxFramebuffer},
gfx_apis::gl::{
gl::{
frame_buffer::GlFrameBuffer,
@ -114,7 +114,12 @@ impl GfxFramebuffer for Framebuffer {
height: i32,
format: &Format,
shm: &[Cell<u8>],
) {
self.copy_to_shm(x, y, width, height, format, shm)
) -> Result<(), GfxError> {
self.copy_to_shm(x, y, width, height, format, shm);
Ok(())
}
fn format(&self) -> &'static Format {
self.gl.rb.img.format
}
}

View file

@ -1,10 +1,12 @@
use {
crate::{
gfx_api::GfxTexture,
gfx_apis::gl::{gl::texture::GlTexture, renderer::context::GlRenderContext},
format::Format,
gfx_api::{GfxError, GfxTexture},
gfx_apis::gl::{gl::texture::GlTexture, renderer::context::GlRenderContext, RenderError},
},
std::{
any::Any,
cell::Cell,
fmt::{Debug, Formatter},
rc::Rc,
},
@ -39,4 +41,21 @@ impl GfxTexture for Texture {
fn as_any(&self) -> &dyn Any {
self
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
fn read_pixels(
self: Rc<Self>,
_x: i32,
_y: i32,
_width: i32,
_height: i32,
_stride: i32,
_format: &Format,
_shm: &[Cell<u8>],
) -> Result<(), GfxError> {
Err(RenderError::UnsupportedOperation.into())
}
}