15 #include <vsg/app/WindowTraits.h>
16 #include <vsg/core/ref_ptr.h>
17 #include <vsg/ui/UIEvent.h>
18 #include <vsg/vk/CommandBuffer.h>
19 #include <vsg/vk/CommandPool.h>
20 #include <vsg/vk/DeviceMemory.h>
21 #include <vsg/vk/Framebuffer.h>
22 #include <vsg/vk/Semaphore.h>
39 virtual const char* instanceExtensionSurfaceName()
const = 0;
41 virtual bool valid()
const {
return false; }
43 virtual bool visible()
const {
return valid(); }
59 virtual void resize() {}
62 const ref_ptr<WindowTraits> traits()
const {
return _traits; }
64 const VkExtent2D& extent2D()
const {
return _extent2D; }
66 vec4& clearColor() {
return _clearColor; }
67 const vec4& clearColor()
const {
return _clearColor; }
69 VkSurfaceFormatKHR surfaceFormat();
71 VkFormat depthFormat();
73 VkSampleCountFlagBits framebufferSamples()
const {
return _framebufferSamples; }
75 void setInstance(ref_ptr<Instance> instance);
76 ref_ptr<Instance> getInstance() {
return _instance; }
77 ref_ptr<Instance> getOrCreateInstance();
79 void setSurface(ref_ptr<Surface> surface);
80 ref_ptr<Surface> getSurface() {
return _surface; }
81 ref_ptr<Surface> getOrCreateSurface();
83 void setPhysicalDevice(ref_ptr<PhysicalDevice> physicalDevice);
84 ref_ptr<PhysicalDevice> getPhysicalDevice() {
return _physicalDevice; }
85 ref_ptr<PhysicalDevice> getOrCreatePhysicalDevice();
87 void setDevice(ref_ptr<Device> device);
88 ref_ptr<Device> getDevice() {
return _device; }
89 ref_ptr<Device> getOrCreateDevice();
91 void setRenderPass(ref_ptr<RenderPass> renderPass);
92 ref_ptr<RenderPass> getRenderPass() {
return _renderPass; }
93 ref_ptr<RenderPass> getOrCreateRenderPass();
95 ref_ptr<Swapchain> getSwapchain() {
return _swapchain; }
96 ref_ptr<Swapchain> getOrCreateSwapchain();
98 ref_ptr<Image> getDepthImage() {
return _depthImage; }
99 ref_ptr<Image> getOrCreateDepthImage();
101 ref_ptr<ImageView> getDepthImageView() {
return _depthImageView; }
102 ref_ptr<ImageView> getOrCreateDepthImageView();
104 size_t numFrames()
const {
return _frames.size(); }
106 ref_ptr<ImageView> imageView(
size_t i) {
return _frames[i].imageView; }
107 const ref_ptr<ImageView> imageView(
size_t i)
const {
return _frames[i].imageView; }
109 ref_ptr<Framebuffer> framebuffer(
size_t i) {
return _frames[i].framebuffer; }
110 const ref_ptr<Framebuffer> framebuffer(
size_t i)
const {
return _frames[i].framebuffer; }
116 size_t imageIndex(
size_t relativeFrameIndex = 0)
const {
return relativeFrameIndex < _indices.size() ? _indices[relativeFrameIndex] : _indices.size(); }
118 bool debugLayersEnabled()
const {
return _traits->debugLayer; }
127 using Frames = std::vector<Frame>;
129 Frame& frame(
size_t i) {
return _frames[i]; }
130 Frames& frames() {
return _frames; }
133 Window(ref_ptr<WindowTraits> traits);
137 virtual void _initSurface() = 0;
139 void _initInstance();
140 void _initPhysicalDevice();
142 void _initRenderPass();
143 void _initSwapchain();
145 virtual void clear();
146 void share(ref_ptr<Device> device);
147 void buildSwapchain();
149 ref_ptr<WindowTraits> _traits;
151 VkExtent2D _extent2D;
153 VkSurfaceFormatKHR _imageFormat;
154 VkFormat _depthFormat;
156 VkSampleCountFlagBits _framebufferSamples;
158 ref_ptr<Instance> _instance;
159 ref_ptr<PhysicalDevice> _physicalDevice;
160 ref_ptr<Device> _device;
161 ref_ptr<Surface> _surface;
162 ref_ptr<Swapchain> _swapchain;
163 ref_ptr<RenderPass> _renderPass;
165 ref_ptr<Image> _depthImage;
166 ref_ptr<ImageView> _depthImageView;
169 ref_ptr<Image> _multisampleImage;
170 ref_ptr<ImageView> _multisampleImageView;
173 ref_ptr<Image> _multisampleDepthImage;
174 ref_ptr<ImageView> _multisampleDepthImageView;
176 ref_ptr<Semaphore> _availableSemaphore;
179 std::vector<size_t> _indices;
183 using Windows = std::vector<ref_ptr<Window>>;
VkResult acquireNextImage(uint64_t timeout=std::numeric_limits< uint64_t >::max())
call vkAquireNextImageKHR to find the next imageIndex of the swapchain images/framebuffers
virtual void releaseWindow()
Definition: Window.h:47
static ref_ptr< Window > create(vsg::ref_ptr< WindowTraits > traits)
static Window::create(traits) method creates a platform specific Window instance based on specified w...
size_t imageIndex(size_t relativeFrameIndex=0) const
get the image index for specified relative frame index, a 0 value is the current frame being rendered...
Definition: Window.h:116
virtual bool pollEvents(UIEvents &events)
get the list of events since the last pollEvents() call by splicing bufferEvents with polled windowin...
virtual void releaseConnection()
Definition: Window.h:51
UIEvents bufferedEvents
events buffered since the last pollEvents.
Definition: Window.h:54