add some real UI
This commit is contained in:
parent
16ea643f90
commit
7b22551bee
39
src/lib.rs
39
src/lib.rs
|
|
@ -17,6 +17,23 @@ mod trace;
|
|||
|
||||
const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct SphericalPosition {
|
||||
pub yaw: f32,
|
||||
pub pitch: f32,
|
||||
pub distance: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct RedrawArgs {
|
||||
pub camera_position: SphericalPosition,
|
||||
pub light_position: SphericalPosition,
|
||||
pub light_radius: f32,
|
||||
pub light_spread: f32,
|
||||
}
|
||||
|
||||
pub struct Gpu {
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
|
|
@ -88,11 +105,11 @@ impl Core {
|
|||
}
|
||||
}
|
||||
|
||||
fn render(&self, output: &wgpu::Texture) {
|
||||
fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) {
|
||||
let camera = OrbitalCamera {
|
||||
position_yaw: PI / 4.,
|
||||
position_pitch: 0.5f32.sqrt().atan(),
|
||||
distance: 3.0,
|
||||
position_yaw: args.camera_position.yaw,
|
||||
position_pitch: args.camera_position.pitch,
|
||||
distance: args.camera_position.distance,
|
||||
};
|
||||
let aspect = {
|
||||
let size = output.size();
|
||||
|
|
@ -134,11 +151,11 @@ impl Core {
|
|||
self.pipeline.render(&mut pass, [&self.tripod]);
|
||||
|
||||
let source = Source {
|
||||
position_yaw: 0.0,
|
||||
position_pitch: PI / 3.,
|
||||
distance: 1.0,
|
||||
radius: 0.125,
|
||||
spread: 0.125,
|
||||
position_yaw: args.light_position.yaw,
|
||||
position_pitch: args.light_position.pitch,
|
||||
distance: args.light_position.distance,
|
||||
radius: args.light_radius,
|
||||
spread: args.light_spread,
|
||||
};
|
||||
|
||||
let contour: Vec<Vertex> = loop_list(source.contour(17))
|
||||
|
|
@ -227,9 +244,9 @@ impl Core {
|
|||
/// Redraws the entire surface.
|
||||
///
|
||||
/// [`Self::configure`] must be called at least once before this.
|
||||
pub fn redraw(&mut self) {
|
||||
pub fn redraw(&mut self, args: &RedrawArgs) {
|
||||
let output = self.surface.get_current_texture().unwrap();
|
||||
self.render(&output.texture);
|
||||
self.render(&output.texture, args);
|
||||
output.present();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
src/main.rs
19
src/main.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::{f32::consts::PI, sync::Arc};
|
||||
|
||||
use glam::uvec2;
|
||||
use photon_light::{Core, init_gpu_inner};
|
||||
use photon_light::{Core, RedrawArgs, SphericalPosition, init_gpu_inner};
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
|
|
@ -37,7 +37,20 @@ impl MainWindow {
|
|||
WindowEvent::Resized(physical_size) => self
|
||||
.core
|
||||
.configure(uvec2(physical_size.width, physical_size.height)),
|
||||
WindowEvent::RedrawRequested => self.core.redraw(),
|
||||
WindowEvent::RedrawRequested => self.core.redraw(&RedrawArgs {
|
||||
camera_position: SphericalPosition {
|
||||
yaw: PI / 4.,
|
||||
pitch: 0.5f32.sqrt().atan(),
|
||||
distance: 3.0,
|
||||
},
|
||||
light_position: SphericalPosition {
|
||||
yaw: 0.0,
|
||||
pitch: PI / 3.,
|
||||
distance: 1.0,
|
||||
},
|
||||
light_radius: 0.125,
|
||||
light_spread: 0.125,
|
||||
}),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace ffi {
|
|||
extern "C" Core* rt4_viewport_create(xcb_connection_t* connection, std::uint32_t window);
|
||||
extern "C" void rt4_viewport_destroy(Core* viewport);
|
||||
extern "C" void rt4_viewport_configure(Core* viewport, std::uint32_t width, std::uint32_t height);
|
||||
extern "C" void rt4_viewport_redraw(Core* viewport);
|
||||
extern "C" void rt4_viewport_redraw(Core* viewport, const RedrawArgs* args);
|
||||
} // namespace ffi
|
||||
|
||||
BoxCore::BoxCore(BoxCore&& b)
|
||||
|
|
@ -52,6 +52,6 @@ void MutCore::configure(std::uint32_t width, std::uint32_t height) const {
|
|||
rt4_viewport_configure(use(), width, height);
|
||||
}
|
||||
|
||||
void MutCore::redraw() const {
|
||||
rt4_viewport_redraw(use());
|
||||
void MutCore::redraw(const RedrawArgs& args) const {
|
||||
rt4_viewport_redraw(use(), &args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,23 @@ struct xcb_connection_t;
|
|||
|
||||
namespace ffi {
|
||||
struct Core;
|
||||
}
|
||||
|
||||
struct SphericalPosition {
|
||||
float yaw;
|
||||
float pitch;
|
||||
float distance;
|
||||
};
|
||||
|
||||
struct RedrawArgs {
|
||||
SphericalPosition camera_position;
|
||||
SphericalPosition light_position;
|
||||
float light_radius;
|
||||
float light_spread;
|
||||
};
|
||||
} // namespace ffi
|
||||
|
||||
using ffi::RedrawArgs;
|
||||
using ffi::SphericalPosition;
|
||||
|
||||
class MutCore {
|
||||
friend class BoxCore;
|
||||
|
|
@ -15,7 +31,7 @@ public:
|
|||
explicit operator bool() const { return ptr; }
|
||||
|
||||
void configure(std::uint32_t width, std::uint32_t height) const;
|
||||
void redraw() const;
|
||||
void redraw(const RedrawArgs& args) const;
|
||||
|
||||
private:
|
||||
ffi::Core* ptr = nullptr;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::{ffi::c_void, num::NonZero, ptr::NonNull};
|
||||
|
||||
use glam::uvec2;
|
||||
use photon_light::{Core, init_gpu_inner};
|
||||
use photon_light::{Core, RedrawArgs, init_gpu_inner};
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
||||
|
||||
unsafe fn create_viewport(
|
||||
|
|
@ -40,6 +40,6 @@ unsafe extern "C" fn rt4_viewport_configure(viewport: &mut Core, width: u32, hei
|
|||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe extern "C" fn rt4_viewport_redraw(viewport: &mut Core) {
|
||||
viewport.redraw();
|
||||
unsafe extern "C" fn rt4_viewport_redraw(viewport: &mut Core, args: &RedrawArgs) {
|
||||
viewport.redraw(args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,30 @@ PhotonLight::PhotonLight(QWidget* parent)
|
|||
: QMainWindow(parent),
|
||||
m_ui(new Ui::MainWindow) {
|
||||
m_ui->setupUi(this);
|
||||
emit updateView();
|
||||
}
|
||||
|
||||
PhotonLight::~PhotonLight() = default;
|
||||
|
||||
float deg_to_rad(float val) {
|
||||
return val * float(M_PI / 180);
|
||||
}
|
||||
|
||||
void PhotonLight::updateView() {
|
||||
m_ui->viewport->setView(RedrawArgs{
|
||||
.camera_position = SphericalPosition{
|
||||
.yaw = deg_to_rad(m_ui->cameraYaw->value()),
|
||||
.pitch = deg_to_rad(m_ui->cameraPitch->value()),
|
||||
.distance = 3.0,
|
||||
},
|
||||
.light_position = SphericalPosition{
|
||||
.yaw = deg_to_rad(m_ui->lightYaw->value()),
|
||||
.pitch = deg_to_rad(m_ui->lightPitch->value()),
|
||||
.distance = 1.0,
|
||||
},
|
||||
.light_radius = 0.125,
|
||||
.light_spread = 0.125,
|
||||
});
|
||||
}
|
||||
|
||||
#include "moc_main_window.cpp"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ public:
|
|||
explicit PhotonLight(QWidget* parent = nullptr);
|
||||
~PhotonLight() override;
|
||||
|
||||
public slots:
|
||||
void updateView();
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1220</width>
|
||||
<height>823</height>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="Viewport" name="widget" native="true"/>
|
||||
<widget class="Viewport" name="viewport" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
@ -25,12 +25,159 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1220</width>
|
||||
<width>800</width>
|
||||
<height>38</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QDockWidget" name="dockWidget">
|
||||
<property name="features">
|
||||
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
|
||||
</property>
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Camera</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Yaw</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="cameraYaw">
|
||||
<property name="minimum">
|
||||
<number>-180</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>45</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Pitch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="cameraPitch">
|
||||
<property name="minimum">
|
||||
<number>-90</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>90</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>35</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Light</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Yaw</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="lightYaw">
|
||||
<property name="minimum">
|
||||
<number>-180</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>180</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Pitch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="lightPitch">
|
||||
<property name="minimum">
|
||||
<number>-90</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>90</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>60</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>385</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
@ -41,5 +188,73 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>cameraYaw</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>688</x>
|
||||
<y>159</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>403</x>
|
||||
<y>362</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>cameraPitch</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>688</x>
|
||||
<y>215</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>403</x>
|
||||
<y>362</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>lightYaw</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>688</x>
|
||||
<y>319</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>403</x>
|
||||
<y>362</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>lightPitch</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>688</x>
|
||||
<y>375</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>403</x>
|
||||
<y>362</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>updateView()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ Viewport::Viewport(QWidget* parent, Qt::WindowFlags f)
|
|||
|
||||
Viewport::~Viewport() = default;
|
||||
|
||||
void Viewport::setView(RedrawArgs new_args) {
|
||||
args = new_args;
|
||||
update();
|
||||
}
|
||||
|
||||
QPaintEngine* Viewport::paintEngine() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -32,7 +37,7 @@ bool Viewport::event(QEvent* event) {
|
|||
void Viewport::paintEvent(QPaintEvent* event) {
|
||||
if (!core)
|
||||
recreate();
|
||||
core->redraw();
|
||||
core->redraw(args);
|
||||
}
|
||||
|
||||
void Viewport::resizeEvent(QResizeEvent* event) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ public:
|
|||
~Viewport() override;
|
||||
QPaintEngine* paintEngine() const override;
|
||||
|
||||
void setView(RedrawArgs new_args);
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event) override;
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
|
@ -19,6 +21,7 @@ protected:
|
|||
|
||||
private:
|
||||
BoxCore core;
|
||||
RedrawArgs args = {};
|
||||
|
||||
void recreate();
|
||||
void updateSize();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user