Support right & middle mouse dragging, set macOS frameTimer based on vsync refresh period
This commit is contained in:
parent
3941a5becd
commit
57e650b653
5 changed files with 49 additions and 8 deletions
|
|
@ -242,8 +242,8 @@ void VulkanExampleBase::nextFrame()
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||||
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||||
frameTimer = (float)tDiff / 100.0f; // SRS - Divide by 100 for macOS - perhaps shorter tDiff due to background rendering?
|
frameTimer = (float)tDiff * refreshPeriod; // SRS - Multiply by the display refresh period due to fixed vsync rendering on iOS and macOS
|
||||||
#else
|
#else
|
||||||
frameTimer = (float)tDiff / 1000.0f;
|
frameTimer = (float)tDiff / 1000.0f;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,7 @@ public:
|
||||||
int64_t lastTapTime = 0;
|
int64_t lastTapTime = 0;
|
||||||
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
#elif (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||||
void* view;
|
void* view;
|
||||||
|
double refreshPeriod = 1.0/60.0; // SRS - default refreshPeriod for 60 fps display
|
||||||
#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT)
|
#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT)
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
IDirectFB *dfb = nullptr;
|
IDirectFB *dfb = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,19 @@
|
||||||
#include "examples.h"
|
#include "examples.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void MVKExample::renderFrame() { // SRS - don't need to expose VulkanExampleBase::renderFrame() to DemoViewController
|
void MVKExample::renderFrame() { // SRS - don't need to expose VulkanExampleBase::renderFrame() to DemoViewController
|
||||||
_vulkanExample->renderFrame();
|
_vulkanExample->renderFrame();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void MVKExample::displayLinkOutputCb() { // SRS - expose VulkanExampleBase::displayLinkOutputCb() to DemoViewController
|
void MVKExample::displayLinkOutputCb() { // SRS - expose VulkanExampleBase::displayLinkOutputCb() to DemoViewController
|
||||||
_vulkanExample->displayLinkOutputCb();
|
_vulkanExample->displayLinkOutputCb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MVKExample::getRefreshPeriod(double refreshPeriod) { // SRS - get the actual refresh period of the display
|
||||||
|
_vulkanExample->refreshPeriod = refreshPeriod;
|
||||||
|
}
|
||||||
|
|
||||||
void MVKExample::windowWillResize(float x, float y) {
|
void MVKExample::windowWillResize(float x, float y) {
|
||||||
_vulkanExample->windowWillResize(x, y);
|
_vulkanExample->windowWillResize(x, y);
|
||||||
}
|
}
|
||||||
|
|
@ -85,14 +89,22 @@ void MVKExample::mouseUp(double x, double y) {
|
||||||
_vulkanExample->mouseButtons.left = false;
|
_vulkanExample->mouseButtons.left = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MVKExample::otherMouseDown() {
|
void MVKExample::rightMouseDown() {
|
||||||
_vulkanExample->mouseButtons.right = true;
|
_vulkanExample->mouseButtons.right = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MVKExample::otherMouseUp() {
|
void MVKExample::rightMouseUp() {
|
||||||
_vulkanExample->mouseButtons.right = false;
|
_vulkanExample->mouseButtons.right = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MVKExample::otherMouseDown() {
|
||||||
|
_vulkanExample->mouseButtons.middle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MVKExample::otherMouseUp() {
|
||||||
|
_vulkanExample->mouseButtons.middle = false;
|
||||||
|
}
|
||||||
|
|
||||||
void MVKExample::mouseDragged(double x, double y) {
|
void MVKExample::mouseDragged(double x, double y) {
|
||||||
_vulkanExample->mouseDragged(x, y);
|
_vulkanExample->mouseDragged(x, y);
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +121,7 @@ MVKExample::MVKExample(void* view) {
|
||||||
_vulkanExample = new VulkanExample();
|
_vulkanExample = new VulkanExample();
|
||||||
_vulkanExample->initVulkan();
|
_vulkanExample->initVulkan();
|
||||||
_vulkanExample->setupWindow(view);
|
_vulkanExample->setupWindow(view);
|
||||||
// _vulkanExample->initSwapchain(); // SRS - initSwapchain() is now part of VulkanExampleBase::prepare()
|
//_vulkanExample->initSwapchain(); // SRS - initSwapchain() is now part of VulkanExampleBase::prepare()
|
||||||
_vulkanExample->prepare();
|
_vulkanExample->prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class MVKExample {
|
||||||
public:
|
public:
|
||||||
//void renderFrame(); // SRS - don't need to expose VulkanExampleBase::renderFrame() to DemoViewController
|
//void renderFrame(); // SRS - don't need to expose VulkanExampleBase::renderFrame() to DemoViewController
|
||||||
void displayLinkOutputCb(); // SRS - expose VulkanExampleBase::displayLinkOutputCb() to DemoViewController
|
void displayLinkOutputCb(); // SRS - expose VulkanExampleBase::displayLinkOutputCb() to DemoViewController
|
||||||
|
void getRefreshPeriod(double refreshPeriod); // SRS - get the actual refresh period of the display
|
||||||
|
|
||||||
void windowWillResize(float x, float y); // SRS - expose window resize events to DemoViewController
|
void windowWillResize(float x, float y); // SRS - expose window resize events to DemoViewController
|
||||||
void windowDidResize();
|
void windowDidResize();
|
||||||
|
|
@ -25,6 +26,8 @@ public:
|
||||||
|
|
||||||
void mouseDown(double x, double y); // SRS - expose mouse events to DemoViewController
|
void mouseDown(double x, double y); // SRS - expose mouse events to DemoViewController
|
||||||
void mouseUp(double x, double y);
|
void mouseUp(double x, double y);
|
||||||
|
void rightMouseDown();
|
||||||
|
void rightMouseUp();
|
||||||
void otherMouseDown();
|
void otherMouseDown();
|
||||||
void otherMouseUp();
|
void otherMouseUp();
|
||||||
void mouseDragged(double x, double y);
|
void mouseDragged(double x, double y);
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,14 @@ MVKExample* _mvkExample;
|
||||||
CVDisplayLinkStart(_displayLink);
|
CVDisplayLinkStart(_displayLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SRS - Handle window resize events
|
// SRS - get the actual refresh period of the display
|
||||||
|
-(void) viewWillAppear {
|
||||||
|
[super viewWillAppear];
|
||||||
|
|
||||||
|
_mvkExample->getRefreshPeriod(CVDisplayLinkGetActualOutputVideoRefreshPeriod(_displayLink));
|
||||||
|
}
|
||||||
|
|
||||||
|
// SRS - Handle window resize events (FIXME: resizeable window not yet supported at init)
|
||||||
-(NSSize) windowWillResize:(NSWindow*) sender toSize:(NSSize)frameSize {
|
-(NSSize) windowWillResize:(NSWindow*) sender toSize:(NSSize)frameSize {
|
||||||
CVDisplayLinkStop(_displayLink);
|
CVDisplayLinkStop(_displayLink);
|
||||||
_mvkExample->windowWillResize(frameSize.width, frameSize.height);
|
_mvkExample->windowWillResize(frameSize.width, frameSize.height);
|
||||||
|
|
@ -118,6 +125,14 @@ MVKExample* _mvkExample;
|
||||||
_mvkExample->mouseUp(point.x, point.y);
|
_mvkExample->mouseUp(point.x, point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) rightMouseDown:(NSEvent*) theEvent {
|
||||||
|
_mvkExample->rightMouseDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) rightMouseUp:(NSEvent*) theEvent {
|
||||||
|
_mvkExample->rightMouseUp();
|
||||||
|
}
|
||||||
|
|
||||||
-(void) otherMouseDown:(NSEvent*) theEvent {
|
-(void) otherMouseDown:(NSEvent*) theEvent {
|
||||||
_mvkExample->otherMouseDown();
|
_mvkExample->otherMouseDown();
|
||||||
}
|
}
|
||||||
|
|
@ -131,6 +146,16 @@ MVKExample* _mvkExample;
|
||||||
_mvkExample->mouseDragged(point.x, point.y);
|
_mvkExample->mouseDragged(point.x, point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void) rightMouseDragged:(NSEvent*) theEvent {
|
||||||
|
auto point = [self getMouseLocalPoint:theEvent];
|
||||||
|
_mvkExample->mouseDragged(point.x, point.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) otherMouseDragged:(NSEvent*) theEvent {
|
||||||
|
auto point = [self getMouseLocalPoint:theEvent];
|
||||||
|
_mvkExample->mouseDragged(point.x, point.y);
|
||||||
|
}
|
||||||
|
|
||||||
-(void) mouseMoved:(NSEvent*) theEvent {
|
-(void) mouseMoved:(NSEvent*) theEvent {
|
||||||
auto point = [self getMouseLocalPoint:theEvent];
|
auto point = [self getMouseLocalPoint:theEvent];
|
||||||
_mvkExample->mouseDragged(point.x, point.y);
|
_mvkExample->mouseDragged(point.x, point.y);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue