openxr: support changing overlay opacity

This commit is contained in:
galister
2024-02-17 11:06:26 +01:00
parent 12003fdddd
commit d42c0ef670
7 changed files with 21 additions and 14 deletions

View File

@@ -100,10 +100,6 @@ or alternatively add the following to `Cargo.toml` to only do basic optimization
opt-level = 1 opt-level = 1
``` ```
## OpenXR: Overlay opacity
Translucent overlays are not supported on OpenXR yet.
## Scroll wheel doesn't work ## Scroll wheel doesn't work
This seems to be an issue specific to Electron apps (Discord, Element, Slack, Spotify) on Wayland. Scrolling will work when using these in your web browser. This seems to be an issue specific to Electron apps (Discord, Element, Slack, Spotify) on Wayland. Scrolling will work when using these in your web browser.

View File

@@ -4,8 +4,8 @@ use anyhow::bail;
use ovr_overlay::{ use ovr_overlay::{
input::{ActionHandle, ActionSetHandle, ActiveActionSet, InputManager, InputValueHandle}, input::{ActionHandle, ActionSetHandle, ActiveActionSet, InputManager, InputValueHandle},
sys::{ sys::{
k_unMaxTrackedDeviceCount, ETrackedControllerRole, ETrackedDeviceClass, ETrackedControllerRole, ETrackedDeviceClass, ETrackedDeviceProperty,
ETrackedDeviceProperty, ETrackingUniverseOrigin, ETrackingUniverseOrigin,
}, },
system::SystemManager, system::SystemManager,
TrackedDeviceIndex, TrackedDeviceIndex,

View File

@@ -135,10 +135,11 @@ impl LinePool {
if let Some(inner) = line.maybe_line.take() { if let Some(inner) = line.maybe_line.take() {
let quad = xr::CompositionLayerQuad::new() let quad = xr::CompositionLayerQuad::new()
.pose(inner.pose) .pose(inner.pose)
.sub_image( .sub_image(line.swapchain.acquire_present_release(
line.swapchain command_buffer,
.acquire_present_release(command_buffer, inner.view), inner.view,
) 1.0,
))
.eye_visibility(xr::EyeVisibility::BOTH) .eye_visibility(xr::EyeVisibility::BOTH)
.layer_flags(xr::CompositionLayerFlags::CORRECT_CHROMATIC_ABERRATION) .layer_flags(xr::CompositionLayerFlags::CORRECT_CHROMATIC_ABERRATION)
.space(&xr.stage) .space(&xr.stage)

View File

@@ -50,7 +50,7 @@ impl OverlayData<OpenXrOverlayData> {
srd srd
}); });
let sub_image = data.acquire_present_release(command_buffer, my_view); let sub_image = data.acquire_present_release(command_buffer, my_view, self.state.alpha);
let posef = helpers::transform_to_posef(&self.state.transform); let posef = helpers::transform_to_posef(&self.state.transform);
let aspect_ratio = extent[1] as f32 / extent[0] as f32; let aspect_ratio = extent[1] as f32 / extent[0] as f32;

View File

@@ -87,6 +87,7 @@ impl SwapchainRenderData {
&mut self, &mut self,
command_buffer: &mut WlxCommandBuffer, command_buffer: &mut WlxCommandBuffer,
view: Arc<ImageView>, view: Arc<ImageView>,
alpha: f32,
) -> xr::SwapchainSubImage<xr::Vulkan> { ) -> xr::SwapchainSubImage<xr::Vulkan> {
let idx = self.swapchain.acquire_image().unwrap() as usize; let idx = self.swapchain.acquire_image().unwrap() as usize;
self.swapchain.wait_image(xr::Duration::INFINITE).unwrap(); self.swapchain.wait_image(xr::Duration::INFINITE).unwrap();
@@ -95,14 +96,18 @@ impl SwapchainRenderData {
command_buffer.begin_rendering(render_target.clone()); command_buffer.begin_rendering(render_target.clone());
let target_extent = render_target.image().extent(); let target_extent = render_target.image().extent();
let set = self
let set0 = self
.pipeline .pipeline
.uniform_sampler(0, view.clone(), Filter::Linear); .uniform_sampler(0, view.clone(), Filter::Linear);
let set1 = self.pipeline.uniform_buffer(1, vec![alpha]);
let pass = self.pipeline.create_pass( let pass = self.pipeline.create_pass(
[target_extent[0] as _, target_extent[1] as _], [target_extent[0] as _, target_extent[1] as _],
command_buffer.graphics.quad_verts.clone(), command_buffer.graphics.quad_verts.clone(),
command_buffer.graphics.quad_indices.clone(), command_buffer.graphics.quad_indices.clone(),
vec![set], vec![set0, set1],
); );
command_buffer.run_ref(&pass); command_buffer.run_ref(&pass);
command_buffer.end_rendering(); command_buffer.end_rendering();

View File

@@ -13,7 +13,7 @@ use serde::Deserialize;
use crate::{ use crate::{
backend::{ backend::{
common::{OverlayContainer, OverlaySelector, TaskType}, common::{OverlaySelector, TaskType},
input::PointerMode, input::PointerMode,
overlay::{OverlayData, OverlayState, RelativeTo}, overlay::{OverlayData, OverlayState, RelativeTo},
}, },

View File

@@ -92,6 +92,10 @@ pub mod frag_srgb {
layout (location = 0) out vec4 out_color; layout (location = 0) out vec4 out_color;
layout (set = 0, binding = 0) uniform sampler2D in_texture; layout (set = 0, binding = 0) uniform sampler2D in_texture;
layout (set = 1, binding = 0) uniform AlphaBlock {
uniform float alpha;
};
void main() void main()
{ {
@@ -102,6 +106,7 @@ pub mod frag_srgb {
vec4 lower = out_color/vec4(12.92); vec4 lower = out_color/vec4(12.92);
out_color = mix(higher, lower, cutoff); out_color = mix(higher, lower, cutoff);
out_color.a = alpha;
} }
", ",
} }