Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2f2b04e
Initial support for movement controlled by keys
robertosfield May 5, 2023
61fc0c1
Merge branch 'master' into TrackballKeys
robertosfield May 5, 2023
22f9087
Fixed cppecheck reported issue
robertosfield May 8, 2023
bd2586d
Improve documentation of plane-matrix multiplication
timoore May 8, 2023
f02eba6
Merge pull request #804 from timoore/mat4-docs
robertosfield May 8, 2023
9cb5372
Adopted std::map<> for speedig up deletion
robertosfield May 9, 2023
e7c7c82
Fixed cppcheck reported issue
robertosfield May 10, 2023
1fcd535
Merge pull request #806 from vsg-dev/AllocatorMapBlocks
robertosfield May 10, 2023
3bfc0c8
Added setting of the overrideMask to make sure the UpdateGraphicsPipe…
robertosfield May 12, 2023
e775af7
Added check to make sure context is only used if it matches the view …
robertosfield May 12, 2023
81f62bf
Merge branch 'master' into TrackballKeys
robertosfield May 12, 2023
6be18aa
Implemented turn left/right.
robertosfield May 12, 2023
e70e557
[FIXED] vkCreateRenderPass2KHR support
May 13, 2023
8b13906
[ADDED] renderPass to RenderGraph
May 13, 2023
eeee9a4
[FIXED] depthResolveAttachment to use LOAD_OP_DONT_CARE
May 13, 2023
149ea0f
[FIXED] -Wunused-but-set-variable warnings
May 13, 2023
4cc75f3
[FIXED] accidentally added includes
May 13, 2023
a043ecc
Experiment with tracking holding keyboard keys
robertosfield May 13, 2023
2b7caa6
Merge pull request #809 from siystar/warnings
robertosfield May 13, 2023
3a85183
Refacrtord to avoid access of resources that are unneccessary.
robertosfield May 13, 2023
6fb0fd4
Merge pull request #812 from siystar/loadop
robertosfield May 13, 2023
c87b4cc
Merge pull request #813 from siystar/createrenderpass2
robertosfield May 13, 2023
53d9a63
Merge branch 'renderpass' of https://github.com/siystar/VulkanSceneGr…
robertosfield May 14, 2023
634a10c
Moved the renderPassInfo.renderPass assignment to avoid setting it mu…
robertosfield May 14, 2023
b8a0ec7
Merge branch 'master' into TrackballKeys
robertosfield May 14, 2023
06d78b5
Added experimental update of camera position using key controls.
robertosfield May 14, 2023
eecadee
Moved keyboard state tracking into decidated Keyboard class
robertosfield May 15, 2023
e5dfd87
Improved support for handling keyboard focus
robertosfield May 15, 2023
30b5535
Added look up/down and forwrd/back support with 'w', 's', 'i' and 'o'…
robertosfield May 15, 2023
364a798
Test build of WM_SETFOCUS & WM_KILLFOCUS
robertosfield May 16, 2023
907e247
Added FocusInEvent and FocusOutEvent for tracking when a window gain/…
robertosfield May 16, 2023
5f7b64f
Added FocusInEvent/FocusOutEvent suppprt to Xcb_Window and Win32_Window.
robertosfield May 16, 2023
d7755f1
Added use of FocusInEvent/FocusOutEvent to Trackball
robertosfield May 16, 2023
e21f726
Moved Keyboard class into into own header
robertosfield May 16, 2023
cdf26b8
Ran clang-format
robertosfield May 16, 2023
788225a
Added { } to fix build
robertosfield May 16, 2023
20f7b54
Added user controllable keys for controlling motion
robertosfield May 16, 2023
16a1751
Resutrctured the keyboard movement implementation
robertosfield May 16, 2023
ecd23ae
Ran clang-format
robertosfield May 17, 2023
68fe636
Added bool method to vec/plane/quat class to make it easier to test i…
robertosfield May 17, 2023
b30c90d
Added inertial effect to Trackball keyboard controls.
robertosfield May 17, 2023
f08409d
Added roll with q and e keys
robertosfield May 17, 2023
8b4dee7
Ran clang-format
robertosfield May 17, 2023
47f1b62
Fixed typos
robertosfield May 17, 2023
0267c32
Merge branch 'master' into TrackballKeys
robertosfield May 17, 2023
dc3668d
Merge pull request #816 from vsg-dev/TrackballKeys
robertosfield May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ if (VSG_SUPPORTS_ShaderCompiler)

if (Git_FOUND)

set(glslang_URL "https://github.com/vsg-dev/glslang.git" CACHE STRING "URL of the glslang git repositiory")
set(glslang_branch "VSG-1.0.x" CACHE STRING "branch/tag of the glslang git repositiory")
set(glslang_URL "https://github.com/vsg-dev/glslang.git" CACHE STRING "URL of the glslang git repository")
set(glslang_branch "VSG-1.0.x" CACHE STRING "branch/tag of the glslang git repository")

execute_process(COMMAND ${GIT_EXECUTABLE} clone --depth 1 --branch ${glslang_branch} ${glslang_URL}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
1 change: 1 addition & 0 deletions cmake/cppcheck-suppression-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ returnTempReference:*/include/vsg/core/Inherit.h
// suppress inappropriate warning of variableScope
variableScope:*/include/vsg/utils/SharedObjects.h
variableScope:*/src/vsg/utils/SharedObjects.cpp
variableScope:*/src/vsg/app/CompileManager.cpp

// suppress really stupid warning of pointerLessThanZero
pointerLessThanZero:*/src/vsg/app/Viewer.cpp
1 change: 1 addition & 0 deletions include/vsg/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/ui/CollectEvents.h>
#include <vsg/ui/FrameStamp.h>
#include <vsg/ui/KeyEvent.h>
#include <vsg/ui/Keyboard.h>
#include <vsg/ui/PlayEvents.h>
#include <vsg/ui/PointerEvent.h>
#include <vsg/ui/PrintEvents.h>
Expand Down
5 changes: 4 additions & 1 deletion include/vsg/app/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace vsg
ref_ptr<Framebuffer> framebuffer;
ref_ptr<Window> window;

/// RenderPass to use passed to the vkCmdBeginRenderPass, either obtained from which of the framebuffer or window are active
/// RenderPass to use passed to the vkCmdBeginRenderPass, if renderPass is set it takes precedence, if not then either obtained from which of the framebuffer or window are active
RenderPass* getRenderPass();

/// Get the Exten2D of the attached Framebuffer or Window.
Expand All @@ -50,6 +50,9 @@ namespace vsg
/// ReandingArea settings for VkRenderPassBeginInfo.renderArea passed to the vkCmdBeginRenderPass, usually maps the ViewportState's scissor
VkRect2D renderArea;

/// RenderPass to use passed to the vkCmdBeginRenderPass in place of the framebuffer's or window's renderPass. renderPass must be compatible with the render pass used to create the window or framebuffer.
ref_ptr<RenderPass> renderPass;

/// Buffer clearing settings for vkRrenderPassInfo.clearValueCount & vkRenderPassInfo.pClearValues passed to the vkCmdBeginRenderPass
using ClearValues = std::vector<VkClearValue>;
ClearValues clearValues; // initialize window colour and depth/stencil
Expand Down
47 changes: 44 additions & 3 deletions include/vsg/app/Trackball.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/app/Camera.h>
#include <vsg/app/EllipsoidModel.h>
#include <vsg/maths/transform.h>
#include <vsg/ui/ApplicationEvent.h>
#include <vsg/ui/KeyEvent.h>
#include <vsg/ui/Keyboard.h>
#include <vsg/ui/PointerEvent.h>
#include <vsg/ui/ScrollWheelEvent.h>
#include <vsg/ui/TouchEvent.h>
Expand All @@ -37,6 +36,9 @@ namespace vsg
dvec3 tbc(PointerEvent& event);

void apply(KeyPressEvent& keyPress) override;
void apply(KeyReleaseEvent& keyRelease) override;
void apply(FocusInEvent& focusIn) override;
void apply(FocusOutEvent& focusOut) override;
void apply(ButtonPressEvent& buttonPress) override;
void apply(ButtonReleaseEvent& buttonRelease) override;
void apply(MoveEvent& moveEvent) override;
Expand Down Expand Up @@ -81,6 +83,42 @@ namespace vsg
/// container that maps key symbol bindings with the Viewpoint that should move the LookAt to when pressed.
std::map<KeySymbol, Viewpoint> keyViewpointMap;

/// Key that turns the view left around the eye points
KeySymbol turnLeftKey = KEY_a;

/// Key that turns the view right around the eye points
KeySymbol turnRightKey = KEY_d;

/// Key that pitches up the view around the eye point
KeySymbol pitchUpKey = KEY_w;

/// Key that pitches down the view around the eye point
KeySymbol pitchDownKey = KEY_s;

/// Key that rools the view anti-clockwise/left
KeySymbol rollLeftKey = KEY_q;

/// Key that rolls the view clockwise/right
KeySymbol rollRightKey = KEY_e;

/// Key that moves the view forward
KeySymbol moveForwardKey = KEY_o;

/// Key that moves the view backwards
KeySymbol moveBackwardKey = KEY_i;

/// Key that moves the view left
KeySymbol moveLeftKey = KEY_Left;

/// Key that moves the view right
KeySymbol moveRightKey = KEY_Right;

/// Key that moves the view upward
KeySymbol moveUpKey = KEY_Up;

/// Key that moves the view downard
KeySymbol moveDownKey = KEY_Down;

/// Button mask value used to enable panning of the view, defaults to left mouse button
ButtonMask rotateButtonMask = BUTTON_MASK_1;

Expand All @@ -104,7 +142,8 @@ namespace vsg
ref_ptr<LookAt> _lookAt;
ref_ptr<EllipsoidModel> _ellipsoidModel;

bool _hasFocus = false;
bool _hasKeyboardFocus = false;
bool _hasPointerFocus = false;
bool _lastPointerEventWithinRenderArea = false;

enum UpdateMode
Expand All @@ -131,6 +170,8 @@ namespace vsg
ref_ptr<LookAt> _endLookAt;
std::map<uint32_t, ref_ptr<TouchEvent>> _previousTouches;

ref_ptr<Keyboard> _keyboard;

double _animationDuration = 0.0;
};
VSG_type_name(vsg::Trackball);
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/app/WindowResizeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace vsg
class VSG_DECLSPEC UpdateGraphicsPipelines : public vsg::Inherit<vsg::Visitor, UpdateGraphicsPipelines>
{
public:
UpdateGraphicsPipelines();

vsg::ref_ptr<vsg::Context> context;
std::set<std::pair<const vsg::Object*, uint32_t>> visited;

Expand Down
9 changes: 7 additions & 2 deletions include/vsg/core/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ namespace vsg
Allocator* parent = nullptr;
std::string name;
size_t blockSize = 0;
std::list<std::unique_ptr<MemoryBlock>> memoryBlocks;
std::map<void*, std::unique_ptr<MemoryBlock>> memoryBlocks;
MemoryBlock* latestMemoryBlock = nullptr;

MemoryBlocks(Allocator* in_parent, const std::string& in_name, size_t in_blockSize);
virtual ~MemoryBlocks();

void* allocate(std::size_t size);
bool deallocate(void* ptr, std::size_t size);

size_t deleteEmptyMemoryBlocks();
size_t totalAvailableSize() const;
size_t totalReservedSize() const;
Expand All @@ -114,6 +116,9 @@ namespace vsg

mutable std::mutex mutex;

double allocationTime = 0.0;
double deallocationTime = 0.0;

protected:
// if you are assigning a custom allocator you must retain the old allocator to manage the memory it allocated and needs to delete
std::unique_ptr<Allocator> nestedAllocator;
Expand All @@ -135,7 +140,7 @@ namespace vsg

allocator_affinity_nodes() = default;
template<class U>
constexpr allocator_affinity_nodes(const allocator_affinity_nodes<U>&) noexcept {}
explicit constexpr allocator_affinity_nodes(const allocator_affinity_nodes<U>&) noexcept {}

value_type* allocate(std::size_t n)
{
Expand Down
4 changes: 4 additions & 0 deletions include/vsg/core/ConstVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace vsg
class ExposeWindowEvent;
class ConfigureWindowEvent;
class CloseWindowEvent;
class FocusInEvent;
class FocusOutEvent;
class KeyEvent;
class KeyPressEvent;
class KeyReleaseEvent;
Expand Down Expand Up @@ -356,6 +358,8 @@ namespace vsg
virtual void apply(const ExposeWindowEvent&);
virtual void apply(const ConfigureWindowEvent&);
virtual void apply(const CloseWindowEvent&);
virtual void apply(const FocusInEvent&);
virtual void apply(const FocusOutEvent&);
virtual void apply(const KeyEvent&);
virtual void apply(const KeyPressEvent&);
virtual void apply(const KeyReleaseEvent&);
Expand Down
4 changes: 4 additions & 0 deletions include/vsg/core/Visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace vsg
class ExposeWindowEvent;
class ConfigureWindowEvent;
class CloseWindowEvent;
class FocusInEvent;
class FocusOutEvent;
class KeyEvent;
class KeyPressEvent;
class KeyReleaseEvent;
Expand Down Expand Up @@ -356,6 +358,8 @@ namespace vsg
virtual void apply(ExposeWindowEvent&);
virtual void apply(ConfigureWindowEvent&);
virtual void apply(CloseWindowEvent&);
virtual void apply(FocusInEvent&);
virtual void apply(FocusOutEvent&);
virtual void apply(KeyEvent&);
virtual void apply(KeyPressEvent&);
virtual void apply(KeyReleaseEvent&);
Expand Down
2 changes: 1 addition & 1 deletion include/vsg/io/mem_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace vsg
{

/// Input stream that enables reading from a read only block of memory
/// Like std::string_view the memory referenced by the mem_stream has been kept in memory for the duration of the mem_stream existance.
/// Like std::string_view the memory referenced by the mem_stream has been kept in memory for the duration of the mem_stream existence.
class VSG_DECLSPEC mem_stream : public std::istream
{
public:
Expand Down
5 changes: 3 additions & 2 deletions include/vsg/maths/mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ namespace vsg
lhs[0] * rhs[3][0] + lhs[1] * rhs[3][1] + lhs[2] * rhs[3][2] + lhs[3] * rhs[3][3]);
}

/* Left multiplication of a plane and a matrix. This can be used directly to transform a plane
from a coordinate system's local coordinates to world coordinates. */
/* Left multiplication of a plane and a matrix. If the matrix is the inverse of the
local-to-world transform i.e., the world-to-local transform, then this can be used directly
to transform a plane from a coordinate system's local coordinates to world coordinates. */
template<typename T, typename R>
t_plane<T> operator*(const t_plane<T>& lhs, const t_mat4<R>& rhs)
{
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/maths/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace vsg

bool valid() const { return n.x != 0.0 && n.y != 0.0 && n.z != 0.0; }

explicit operator bool() const noexcept { return valid(); }

T* data() { return value; }
const T* data() const { return value; }
};
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/maths/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace vsg
z = axis.z * sinhalfangle * inversenorm;
w = coshalfangle;
}

explicit operator bool() const noexcept { return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0 || value[3] != 0.0; }
};

using quat = t_quat<float>; /// float quaternion
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/maths/vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ namespace vsg
}
return *this;
}

explicit operator bool() const noexcept { return value[0] != 0.0 || value[1] != 0.0; }
};

using vec2 = t_vec2<float>; // float 2D vector
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/maths/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ namespace vsg
}
return *this;
}

explicit operator bool() const noexcept { return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0; }
};

using vec3 = t_vec3<float>; // float 3D vector
Expand Down
2 changes: 2 additions & 0 deletions include/vsg/maths/vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ namespace vsg
}
return *this;
}

explicit operator bool() const noexcept { return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0 || value[3] != 0.0; }
};

using vec4 = t_vec4<float>; // float 4D vector
Expand Down
49 changes: 49 additions & 0 deletions include/vsg/ui/Keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

/* <editor-fold desc="MIT License">

Copyright(c) 2023 Robert Osfield

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

</editor-fold> */

#include <vsg/ui/ApplicationEvent.h>
#include <vsg/ui/KeyEvent.h>

namespace vsg
{

/// Keyboard tracks keyboard events to maintain the key pressed state and how long the key has been hel for
class VSG_DECLSPEC Keyboard : public Inherit<Visitor, Keyboard>
{
public:
void apply(KeyPressEvent& keyPress) override;
void apply(KeyReleaseEvent& keyRelease) override;
void apply(FocusInEvent& focusIn) override;
void apply(FocusOutEvent& focusOut) override;

struct KeyHistory
{
vsg::time_point timeOfFirstKeyPress = {};
vsg::time_point timeOfLastKeyPress = {};
vsg::time_point timeOfKeyRelease = {};
bool handled = false;
};

std::map<KeySymbol, KeyHistory> keyState;

/// return true if key is currently pressed
bool pressed(KeySymbol key, bool ignore_handled_keys = true);

/// return a pair of times, the first is the time, in seconds, since the key was first pressed and the second is the time, in secnds, since it was released.
/// if the key hasn't been pressed then then first value will be < 0.0, if the key is still pressed then the second value will be 0.0.
std::pair<double, double> times(KeySymbol key, bool ignore_handled_keys = true);
};
VSG_type_name(vsg::Keyboard);

} // namespace vsg
22 changes: 22 additions & 0 deletions include/vsg/ui/WindowEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,26 @@ namespace vsg
};
VSG_type_name(vsg::CloseWindowEvent);

/// FocusInEvent represents a window aquiring focus event.
class FocusInEvent : public Inherit<WindowEvent, FocusInEvent>
{
public:
FocusInEvent() {}

FocusInEvent(Window* in_window, time_point in_time) :
Inherit(in_window, in_time) {}
};
VSG_type_name(vsg::FocusInEvent);

/// FocusOutEvent represents a window loosing focus event.
class FocusOutEvent : public Inherit<WindowEvent, FocusOutEvent>
{
public:
FocusOutEvent() {}

FocusOutEvent(Window* in_window, time_point in_time) :
Inherit(in_window, in_time) {}
};
VSG_type_name(vsg::FocusOutEvent);

} // namespace vsg
5 changes: 5 additions & 0 deletions include/vsg/vk/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace vsg
const Extensions* getExtensions() const { return _extensions.get(); }

/// get the address of specified function using vkGetDeviceProcAddr
/// for core commands beyond the apiVersion specified in vsg::Instance creation, vkGetDeviceProcAddr may return a non-nullptr function pointer, though the function pointer must not be called.
/// for extension commands, vkGetDeviceProcAddr will always return nullptr if the extension is not enabled in vsg::Device creation.
template<typename T>
bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
{
Expand All @@ -68,6 +70,9 @@ namespace vsg
return (procAddress);
}

/// device-level core functionality can be used if both VkInstance and VkPhysicalDevice support the Vulkan version that provides it.
bool supportsApiVersion(uint32_t version) const;

protected:
virtual ~Device();

Expand Down
3 changes: 3 additions & 0 deletions include/vsg/vk/PhysicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace vsg
/// Call vkEnumerateDeviceExtensionProperties to enumerate extension properties.
std::vector<VkExtensionProperties> enumerateDeviceExtensionProperties(const char* pLayerName = nullptr);

/// return true if the extension is supported by physicalDevice
bool supportsDeviceExtension(const char* extensionName);

protected:
// use Instance::getDevice(..) to create PhysicalDevice
PhysicalDevice(Instance* instance, VkPhysicalDevice device);
Expand Down
1 change: 1 addition & 0 deletions src/vsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ set(SOURCES
ui/ShiftEventTime.cpp
ui/PlayEvents.cpp
ui/PrintEvents.cpp
ui/Keyboard.cpp

vk/CommandBuffer.cpp
vk/CommandPool.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/vsg/app/CompileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ CompileResult CompileManager::compile(ref_ptr<Object> object, ContextSelectionFu
catch (...)
{
vsg::debug("CompileManager::compile() exception caught");
result.message = "Exception occured during compilation.";
result.message = "Exception occurred during compilation.";
result.result = VK_ERROR_UNKNOWN;
}

Expand Down
Loading