Class GLFWRenderModuleWindow
- Direct Known Subclasses:
VulkanGLFWRenderModuleWindow
Handles the parts of window management that are the same whichever graphics API is being driven: initialising GLFW, opening the window, wiring up input, and tearing it all down. Subclasses supply the API-specific pieces — which window hints to set, and how to check that a usable driver is present.
Closing the window stops the engine, so the window's lifetime is effectively the program's.
This will be changed in a future build, as to allow no-window and multi-window setups.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe window's height, kept current by GLFW's framebuffer size callback.protected booleanWhether the window has been initialized.protected intThe window's width, kept current by GLFW's framebuffer size callback.protected longFields inherited from class RenderModuleWindow
logger, mainModuleEngine, renderModuleKeyboardInput, renderModuleMouseInput, shouldClose, title -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGLFWRenderModuleWindow(MainModuleEngine mainModuleEngine, String title, Logger logger) Creates a GLFW window. -
Method Summary
Modifier and TypeMethodDescriptionvoidclean()Destroys the window and releases its platform resources.abstract booleanReturns whether a driver for the subclass's graphics API is present.intReturns the window's height.intgetWidth()Returns the window's width.longReturns the underlying GLFW window handle.voidinit()Opens the window and creates its input objects.booleanReturns whether the window has been initializedvoidloop()Advances the window by one frame, sampling input and handling a close request.voidAsks the window to close at the next opportunity.protected abstract voidApplies the GLFW window hints the subclass's graphics API requires.booleanReturns whether the window has been asked to close.protected abstract voidFails with a message naming the graphics API that could not be found.Methods inherited from class RenderModuleWindow
getKeyboardInput, getMouseInput, pollEvents, resetInput
-
Field Details
-
windowHandle
-
width
protected int widthThe window's width, kept current by GLFW's framebuffer size callback. -
height
protected int heightThe window's height, kept current by GLFW's framebuffer size callback. -
initialized
protected boolean initializedWhether the window has been initialized.
-
-
Constructor Details
-
GLFWRenderModuleWindow
Creates a GLFW window.Nothing is opened until
init()is called.- Parameters:
mainModuleEngine- the engine this window belongs totitle- the window's title bar textlogger- the logger to write window diagnostics to
-
-
Method Details
-
init
public void init()Description copied from class:RenderModuleWindowOpens the window and creates its input objects.- Specified by:
initin classRenderModuleWindow
-
loop
public void loop()Description copied from class:RenderModuleWindowAdvances the window by one frame, sampling input and handling a close request.- Specified by:
loopin classRenderModuleWindow
-
getHeight
public int getHeight()Description copied from class:RenderModuleWindowReturns the window's height.- Specified by:
getHeightin classRenderModuleWindow- Returns:
- the current height in pixels
-
getWidth
public int getWidth()Description copied from class:RenderModuleWindowReturns the window's width.- Specified by:
getWidthin classRenderModuleWindow- Returns:
- the current width in pixels
-
isInitialized
public boolean isInitialized()Description copied from class:RenderModuleWindowReturns whether the window has been initialized- Specified by:
isInitializedin classRenderModuleWindow- Returns:
trueif the window is initialized.
-
setShouldClose
public void setShouldClose()Description copied from class:RenderModuleWindowAsks the window to close at the next opportunity.- Overrides:
setShouldClosein classRenderModuleWindow
-
shouldClose
public boolean shouldClose()Description copied from class:RenderModuleWindowReturns whether the window has been asked to close.- Overrides:
shouldClosein classRenderModuleWindow- Returns:
trueonce a close has been requested, by this class or by the user
-
clean
public void clean()Description copied from class:RenderModuleWindowDestroys the window and releases its platform resources.- Specified by:
cleanin classRenderModuleWindow
-
doesDriverExist
public abstract boolean doesDriverExist()Returns whether a driver for the subclass's graphics API is present.Checked during
init(), before the window is created, so that an unusable environment is reported before any resource is acquired.- Returns:
trueif the graphics API can be used on this machine
-
throwDriverNotFoundException
protected abstract void throwDriverNotFoundException()Fails with a message naming the graphics API that could not be found.Called when
doesDriverExist()returnsfalse; implementations are expected to throw rather than return. -
setWindowHints
protected abstract void setWindowHints()Applies the GLFW window hints the subclass's graphics API requires.Called before the window is created. A Vulkan implementation, for example, sets
GLFW_CLIENT_APItoGLFW_NO_APIso GLFW does not create an OpenGL context. -
getWindowHandle
public long getWindowHandle()Returns the underlying GLFW window handle.Needed to create a rendering surface against this window.
- Returns:
- the GLFW window handle, or
0beforeinit()
-