CMSC23740 Common Code Library
Support code for CS23740 programming projects
Loading...
Searching...
No Matches
cs237::Window Class Referenceabstract

abstract base class for simple GLFW windows used to view buffers, etc. More...

#include <window.hpp>

Collaboration diagram for cs237::Window:

Classes

struct  DepthStencilBuffer
 information about the optional depth/stencil buffers for the window More...
 
struct  FrameData
 A container for the per-frame rendering state. More...
 
struct  SwapChain
 the collected information about the swap-chain for a window More...
 
struct  SwapChainDetails
 information about swap-chain support More...
 

Public Member Functions

virtual ~Window ()
 destructor: it destroys the underlying GLFW window
 
void initialize ()
 
Applicationapp ()
 return the application pointer
 
vk::Device device () const
 return the logical device for this window
 
vk::Queue graphicsQ () const
 the graphics queue
 
vk::Queue presentationQ () const
 the presentation queue
 
vk::Queue computeQ () const
 the compute queue
 
void refresh ()
 
void hide ()
 Hide the window.
 
void show ()
 Show the window (a no-op if it is already visible)
 
virtual void draw ()=0
 
virtual void reshape (int wid, int ht)
 
virtual void iconify (bool iconified)
 method invoked on Iconify events.
 
bool windowShouldClose ()
 get the value of the "close" flag for the window
 
virtual void key (int key, int scancode, int action, int mods)
 
virtual void cursorPos (double xpos, double ypos)
 
virtual void cursorEnter (bool entered)
 
virtual void mouseButton (int button, int action, int mods)
 
virtual void scroll (double xoffset, double yoffset)
 
void enableKeyEvent (bool enable)
 
void setCursorMode (int mode)
 
void enableCursorPosEvent (bool enable)
 
void enableCursorEnterEvent (bool enable)
 
void enableMouseButtonEvent (bool enable)
 
void enableScrollEvent (bool enable)
 
int width () const
 the width of the window
 
int height () const
 the height of the window
 

Protected Member Functions

 Window (Application *app, CreateWindowInfo const &info)
 the Window base-class constructor
 
virtual void _init ()
 subclasses can override this method to handle any additional initialization that needs to be run after the window object is constructed.
 
SwapChainDetails _getSwapChainDetails ()
 Get the swap-chain details for a physical device.
 
void _createSwapChain (bool depth, bool stencil)
 Create the swap chain for this window; this initializes the _swap instance variable.
 
void _recreateSwapChain ()
 Recreate the swap chain for this window; this redefines the _swap instance variable and is used when some aspect of the presentation surface changes.
 
virtual FrameData_allocFrameData (Window *w)
 virtual function for allocating a FrameData object. Subclasses of the Window class can define a subclass of FrameData and then override this method to allocate the subclass objects.
 
FrameData_currentFrame ()
 get a pointer to the current per-frame rendering state
 
FrameData_prevFrame ()
 get a pointer to the previous per-frame rendering state
 
FrameData_nextFrame ()
 get a pointer to the next per-frame rendering state
 
void _advanceFrame ()
 advance the current frame
 
vk::Result _acquireNextImage ()
 acquire the next image from the swap chain. This method has the side effect of setting the index of the current frame to the index of the swap-chain image that we are using.
 
void _initAttachments (std::vector< vk::AttachmentDescription > &descs, std::vector< vk::AttachmentReference > &refs)
 initialize the attachment descriptors and references for the color and optional depth/stencil-buffer
 
uint32_t _graphicsQIdx () const
 the graphics queue-family index
 
uint32_t _presentationQIdx () const
 the presentation queue
 
uint32_t _computeQIdx () const
 the compute queue index
 
vk::Viewport _getViewport (bool oglView=false)
 get the natural viewport for the window
 
vk::Rect2D _getScissorsRect ()
 get the scissors rectangle for this window
 
void _setViewportCmd (vk::CommandBuffer cmdBuf, bool oglView=false)
 add a command to set the viewport and scissor to the whole window
 
void _setViewportCmd (vk::CommandBuffer cmdBuf, int32_t x, int32_t y, int32_t wid, int32_t ht)
 add a viewport command to the command buffer; this also sets the scissor rectangle.
 
vk::DeviceMemory _allocImageMemory (vk::Image img, vk::MemoryPropertyFlags props)
 A helper function for allocating and binding device memory for an image.
 
vk::ImageView _createImageView (vk::Image img, vk::Format fmt, vk::ImageAspectFlags aspectFlags)
 A helper function for creating a Vulkan image view object for an image.
 
void _transitionImageLayout (vk::Image img, vk::Format fmt, vk::ImageLayout oldLayout, vk::ImageLayout newLayout)
 A helper function for changing the layout of an image.
 

Protected Attributes

Application_app
 the owning application
 
GLFWwindow * _win
 the underlying window
 
int _wid
 
int _ht
 window dimensions
 
bool _isVis
 true when the window is visible
 
bool _keyEnabled
 true when the Key callback is enabled
 
bool _cursorPosEnabled
 true when the CursorPos callback is enabled
 
bool _cursorEnterEnabled
 true when the CursorEnter callback is enabled
 
bool _mouseButtonEnabled
 true when the MouseButton callback is enabled
 
bool _scrollEnabled
 true when the Scroll callback is enabled
 
vk::SurfaceKHR _surf
 the Vulkan surface to render to
 
SwapChain _swap
 buffer-swapping information
 
FrameData_frames [kMaxFrames]
 the per-frame rendering state
 
uint32_t _curFrameIdx
 index into _frames array for current frame data
 

Detailed Description

abstract base class for simple GLFW windows used to view buffers, etc.

Constructor & Destructor Documentation

◆ ~Window()

virtual cs237::Window::~Window ( )
virtual

destructor: it destroys the underlying GLFW window

◆ Window()

cs237::Window::Window ( Application * app,
CreateWindowInfo const & info )
protected

the Window base-class constructor

Parameters
appthe owning application
infoinformation for creating the window, such as size and title

Member Function Documentation

◆ _acquireNextImage()

vk::Result cs237::Window::_acquireNextImage ( )
protected

acquire the next image from the swap chain. This method has the side effect of setting the index of the current frame to the index of the swap-chain image that we are using.

Returns
the status of the request; Result::eSuccess for success

◆ _advanceFrame()

void cs237::Window::_advanceFrame ( )
inlineprotected

advance the current frame

◆ _allocFrameData()

virtual FrameData * cs237::Window::_allocFrameData ( Window * w)
protectedvirtual

virtual function for allocating a FrameData object. Subclasses of the Window class can define a subclass of FrameData and then override this method to allocate the subclass objects.

◆ _allocImageMemory()

vk::DeviceMemory cs237::Window::_allocImageMemory ( vk::Image img,
vk::MemoryPropertyFlags props )
inlineprotected

A helper function for allocating and binding device memory for an image.

Parameters
imgthe image to allocate memory for
propsrequred memory properties
Returns
the device memory that has been bound to the image

◆ _computeQIdx()

uint32_t cs237::Window::_computeQIdx ( ) const
inlineprotected

the compute queue index

This method is a wrapper to allow subclasses access to this information

◆ _createImageView()

vk::ImageView cs237::Window::_createImageView ( vk::Image img,
vk::Format fmt,
vk::ImageAspectFlags aspectFlags )
inlineprotected

A helper function for creating a Vulkan image view object for an image.

Parameters
imgthe image on which the view is created
fmtthe format and type used to interpret image texels
aspectFlagsa bitmask specifying which aspect(s) of the image are included in the view.
Returns
the image view

◆ _createSwapChain()

void cs237::Window::_createSwapChain ( bool depth,
bool stencil )
protected

Create the swap chain for this window; this initializes the _swap instance variable.

Parameters
depthset to true if requesting depth-buffer support
stencilset to true if requesting stencil-buffer support

◆ _currentFrame()

FrameData * cs237::Window::_currentFrame ( )
inlineprotected

get a pointer to the current per-frame rendering state

◆ _getScissorsRect()

vk::Rect2D cs237::Window::_getScissorsRect ( )
inlineprotected

get the scissors rectangle for this window

Returns
a rectangle that covers the extent of the window

◆ _getSwapChainDetails()

SwapChainDetails cs237::Window::_getSwapChainDetails ( )
protected

Get the swap-chain details for a physical device.

◆ _getViewport()

vk::Viewport cs237::Window::_getViewport ( bool oglView = false)
inlineprotected

get the natural viewport for the window

Parameters
oglViewif true then use the OpenGL convention where Y = 0 maps to the bottom of the screen and Y increases going up.
Returns
a viewport that covers the extent of the window

◆ _graphicsQIdx()

uint32_t cs237::Window::_graphicsQIdx ( ) const
inlineprotected

the graphics queue-family index

This method is a wrapper to allow subclasses access to this information

◆ _init()

virtual void cs237::Window::_init ( )
protectedvirtual

subclasses can override this method to handle any additional initialization that needs to be run after the window object is constructed.

◆ _initAttachments()

void cs237::Window::_initAttachments ( std::vector< vk::AttachmentDescription > & descs,
std::vector< vk::AttachmentReference > & refs )
protected

initialize the attachment descriptors and references for the color and optional depth/stencil-buffer

Parameters
[out]descsvector that will contain the attachment descriptors
[out]refsvector that will contain the attachment references

◆ _nextFrame()

FrameData * cs237::Window::_nextFrame ( )
inlineprotected

get a pointer to the next per-frame rendering state

◆ _presentationQIdx()

uint32_t cs237::Window::_presentationQIdx ( ) const
inlineprotected

the presentation queue

This method is a wrapper to allow subclasses access to this information

◆ _prevFrame()

FrameData * cs237::Window::_prevFrame ( )
inlineprotected

get a pointer to the previous per-frame rendering state

◆ _recreateSwapChain()

void cs237::Window::_recreateSwapChain ( )
protected

Recreate the swap chain for this window; this redefines the _swap instance variable and is used when some aspect of the presentation surface changes.

◆ _setViewportCmd() [1/2]

void cs237::Window::_setViewportCmd ( vk::CommandBuffer cmdBuf,
bool oglView = false )
inlineprotected

add a command to set the viewport and scissor to the whole window

Parameters
cmdBufthe command buffer
oglViewif true then use the OpenGL convention where Y = 0 maps to the bottom of the screen and Y increases going up.

Vulkan follows the Direct3D convention of using a right-handed NDC space, which means that Y = 0 maps to the top of the screen, instead of the bottom (as in OpenGL). pass true as the second argument to use the OpenGL convention.

◆ _setViewportCmd() [2/2]

void cs237::Window::_setViewportCmd ( vk::CommandBuffer cmdBuf,
int32_t x,
int32_t y,
int32_t wid,
int32_t ht )
protected

add a viewport command to the command buffer; this also sets the scissor rectangle.

Parameters
cmdBufthe command buffer
xspecifies the Y coordinate of the upper-left corner
yspecifies the X coordinate of the upper-left corner
widspecifies the width of the viewport
htspecifies the height of the viewport

To use the OpenGL convention of the Y axis pointing up, specify the OpenGL Y coordinate and a negative height.

◆ _transitionImageLayout()

void cs237::Window::_transitionImageLayout ( vk::Image img,
vk::Format fmt,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout )
inlineprotected

A helper function for changing the layout of an image.

Parameters
imgthe image to change
fmtthe image's format
oldLayoutthe current layout of img
newLayoutthe new layout of img

◆ app()

Application * cs237::Window::app ( )
inline

return the application pointer

◆ computeQ()

vk::Queue cs237::Window::computeQ ( ) const
inline

the compute queue

◆ cursorEnter()

virtual void cs237::Window::cursorEnter ( bool entered)
virtual

◆ cursorPos()

virtual void cs237::Window::cursorPos ( double xpos,
double ypos )
virtual

◆ device()

vk::Device cs237::Window::device ( ) const
inline

return the logical device for this window

◆ draw()

virtual void cs237::Window::draw ( )
pure virtual

virtual draw method provided by derived classes to draw the contents of the window. It is called by Refresh.

◆ enableCursorEnterEvent()

void cs237::Window::enableCursorEnterEvent ( bool enable)

◆ enableCursorPosEvent()

void cs237::Window::enableCursorPosEvent ( bool enable)

◆ enableKeyEvent()

void cs237::Window::enableKeyEvent ( bool enable)

{ enable/disable handling of events

◆ enableMouseButtonEvent()

void cs237::Window::enableMouseButtonEvent ( bool enable)

◆ enableScrollEvent()

void cs237::Window::enableScrollEvent ( bool enable)

◆ graphicsQ()

vk::Queue cs237::Window::graphicsQ ( ) const
inline

the graphics queue

◆ height()

int cs237::Window::height ( ) const
inline

the height of the window

◆ hide()

void cs237::Window::hide ( )
inline

Hide the window.

◆ iconify()

virtual void cs237::Window::iconify ( bool iconified)
virtual

method invoked on Iconify events.

◆ initialize()

void cs237::Window::initialize ( )

method for completing the initialization of a window. This function allocates the per-frame data array and also invokes the virtual _init method to handle and sub-class specific initialization that was not handled in the constructor.

◆ key()

virtual void cs237::Window::key ( int key,
int scancode,
int action,
int mods )
virtual

{ Input handling methods; override these in the derived window classes to do something useful.

◆ mouseButton()

virtual void cs237::Window::mouseButton ( int button,
int action,
int mods )
virtual

◆ presentationQ()

vk::Queue cs237::Window::presentationQ ( ) const
inline

the presentation queue

◆ refresh()

void cs237::Window::refresh ( )
inline

Refresh the contents of the window. This method is also invoked on Refresh events.

◆ reshape()

virtual void cs237::Window::reshape ( int wid,
int ht )
virtual

method invoked on Reshape events.

Parameters
widspecifies the width of the viewport
htspecifies the height of the viewport

This method takes care of updating the cached size of the window and recreating the swap chain. Other updates, including allocating new framebuffers should be handled by overriding this method in the subclass.

◆ scroll()

virtual void cs237::Window::scroll ( double xoffset,
double yoffset )
virtual

◆ setCursorMode()

void cs237::Window::setCursorMode ( int mode)

◆ show()

void cs237::Window::show ( )
inline

Show the window (a no-op if it is already visible)

◆ width()

int cs237::Window::width ( ) const
inline

the width of the window

◆ windowShouldClose()

bool cs237::Window::windowShouldClose ( )
inline

get the value of the "close" flag for the window

Member Data Documentation

◆ _app

Application* cs237::Window::_app
protected

the owning application

◆ _curFrameIdx

uint32_t cs237::Window::_curFrameIdx
protected

index into _frames array for current frame data

◆ _cursorEnterEnabled

bool cs237::Window::_cursorEnterEnabled
protected

true when the CursorEnter callback is enabled

◆ _cursorPosEnabled

bool cs237::Window::_cursorPosEnabled
protected

true when the CursorPos callback is enabled

◆ _frames

FrameData* cs237::Window::_frames[kMaxFrames]
protected

the per-frame rendering state

◆ _ht

int cs237::Window::_ht
protected

window dimensions

◆ _isVis

bool cs237::Window::_isVis
protected

true when the window is visible

◆ _keyEnabled

bool cs237::Window::_keyEnabled
protected

true when the Key callback is enabled

◆ _mouseButtonEnabled

bool cs237::Window::_mouseButtonEnabled
protected

true when the MouseButton callback is enabled

◆ _scrollEnabled

bool cs237::Window::_scrollEnabled
protected

true when the Scroll callback is enabled

◆ _surf

vk::SurfaceKHR cs237::Window::_surf
protected

the Vulkan surface to render to

◆ _swap

SwapChain cs237::Window::_swap
protected

buffer-swapping information

◆ _wid

int cs237::Window::_wid
protected

◆ _win

GLFWwindow* cs237::Window::_win
protected

the underlying window


The documentation for this class was generated from the following file: