2022-10-23 23:46:12 -04:00
|
|
|
/*
|
|
|
|
* Created by Brett Terpstra 6920201 on 22/10/22.
|
|
|
|
* Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef STEP_3_GRAPHICS_H
|
|
|
|
#define STEP_3_GRAPHICS_H
|
|
|
|
|
|
|
|
// includes required to open a window on the system and render with opengl.
|
|
|
|
// we are using the GLX extension to the X11 windowing system
|
|
|
|
// instead of using external libs like GLFW and GLAD.
|
|
|
|
// Wayland is not and will not be supported.
|
2022-10-31 00:51:51 -04:00
|
|
|
#include <config.h>
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
#ifndef USE_GLFW
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <GLES3/gl32.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#include "graphics/imgui/imgui_impl_x11.h"
|
|
|
|
#else
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
#include <graphics/gl/glad/gl.h>
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include "graphics/imgui/imgui_impl_glfw.h"
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
#endif
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-23 23:46:12 -04:00
|
|
|
#include <config.h>
|
|
|
|
#include <engine/util/std.h>
|
|
|
|
#include <functional>
|
|
|
|
#include <graphics/input.h>
|
2022-10-28 01:44:23 -04:00
|
|
|
#include "graphics/imgui/imgui_impl_opengl3.h"
|
2022-11-13 02:00:27 -05:00
|
|
|
#include "graphics/gl/gl.h"
|
|
|
|
#include "engine/raytracing.h"
|
2022-10-28 01:44:23 -04:00
|
|
|
#include <engine/image/image.h>
|
|
|
|
#include <engine/types.h>
|
2022-10-23 23:46:12 -04:00
|
|
|
|
|
|
|
namespace Raytracing {
|
2022-10-28 01:44:23 -04:00
|
|
|
|
|
|
|
void drawQuad();
|
|
|
|
void deleteQuad();
|
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
#ifdef USE_GLFW
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
class XWindow {
|
|
|
|
private:
|
|
|
|
GLFWwindow* window;
|
|
|
|
int m_displayWidth, m_displayHeight;
|
|
|
|
bool isCloseRequested = false;
|
2022-11-13 02:00:27 -05:00
|
|
|
long lastFrameTime;
|
|
|
|
PRECISION_TYPE delta;
|
|
|
|
PRECISION_TYPE frameTimeMs,frameTimeS;
|
|
|
|
PRECISION_TYPE fps;
|
2022-10-31 00:51:51 -04:00
|
|
|
public:
|
|
|
|
XWindow(int width, int height);
|
|
|
|
// runs X11 event processing and some GL commands used for window drawing
|
2022-11-13 02:00:27 -05:00
|
|
|
void beginUpdate();
|
|
|
|
void endUpdate();
|
|
|
|
|
|
|
|
[[nodiscard]] inline bool shouldWindowClose() const { return isCloseRequested; }
|
|
|
|
|
|
|
|
[[nodiscard]] inline PRECISION_TYPE getFrameTimeMillis() const {return frameTimeMs;}
|
|
|
|
[[nodiscard]] inline PRECISION_TYPE getFrameTimeSeconds() const {return frameTimeS;}
|
|
|
|
[[nodiscard]] inline PRECISION_TYPE getFPS() const {return fps;}
|
|
|
|
|
|
|
|
void setMouseGrabbed(bool grabbed);
|
|
|
|
bool isMouseGrabbed();
|
2022-11-15 16:23:37 -05:00
|
|
|
[[nodiscard]] inline int displayWidth() const {return m_displayWidth;}
|
|
|
|
[[nodiscard]] inline int displayHeight() const {return m_displayHeight;}
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
void closeWindow();
|
|
|
|
~XWindow();
|
|
|
|
};
|
2022-11-13 02:00:27 -05:00
|
|
|
|
2022-10-31 00:51:51 -04:00
|
|
|
#else
|
2022-10-23 23:46:12 -04:00
|
|
|
class XWindow {
|
|
|
|
private:
|
|
|
|
// X11 display itself
|
|
|
|
Display *display;
|
|
|
|
// the desktop window or root window
|
|
|
|
Window desktop;
|
|
|
|
// our window's GL attributes, using full RGBA, with a depth of 24. Double buffering on the window.
|
|
|
|
GLint OpenGLAttributes[5] { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
|
2022-10-28 01:44:23 -04:00
|
|
|
const int visual_attribs[23] = {
|
|
|
|
GLX_X_RENDERABLE , True,
|
|
|
|
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
|
|
|
|
GLX_RENDER_TYPE , GLX_RGBA_BIT,
|
|
|
|
GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
|
|
|
|
GLX_RED_SIZE , 8,
|
|
|
|
GLX_GREEN_SIZE , 8,
|
|
|
|
GLX_BLUE_SIZE , 8,
|
|
|
|
GLX_ALPHA_SIZE , 8,
|
|
|
|
GLX_DEPTH_SIZE , 24,
|
|
|
|
GLX_STENCIL_SIZE , 8,
|
|
|
|
GLX_DOUBLEBUFFER , True,
|
|
|
|
//GLX_SAMPLE_BUFFERS , 1,
|
|
|
|
//GLX_SAMPLES , 4,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
int glx_major, glx_minor, frameBufferCount;
|
|
|
|
GLXFBConfig* frameBufferConfig;
|
2022-10-23 23:46:12 -04:00
|
|
|
// X11 stuff we have to have
|
|
|
|
XVisualInfo *visualInfo;
|
|
|
|
Colormap colormap;
|
|
|
|
XSetWindowAttributes xSetWindowAttributes{};
|
|
|
|
// our window which we will use to draw on
|
|
|
|
Window window;
|
|
|
|
GLXContext glContext;
|
|
|
|
XWindowAttributes windowAttributes {};
|
|
|
|
// used for event handling, like pressing a button or moving the mouse.
|
|
|
|
XEvent events{};
|
|
|
|
int m_width, m_height;
|
|
|
|
int m_displayWidth, m_displayHeight;
|
|
|
|
bool isCloseRequested = false;
|
|
|
|
Atom wmDelete;
|
|
|
|
public:
|
|
|
|
XWindow(int width, int height);
|
|
|
|
// runs X11 event processing and some GL commands used for window drawing
|
|
|
|
void runUpdates(const std::function<void()>& drawFunction);
|
|
|
|
[[nodiscard]] inline bool shouldWindowClose() const{ return isCloseRequested; }
|
|
|
|
void closeWindow();
|
|
|
|
~XWindow();
|
|
|
|
};
|
2022-10-31 00:51:51 -04:00
|
|
|
#endif
|
2022-11-13 02:00:27 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The display renderer class handles all the major rendering events outside of window functions
|
|
|
|
* like ImGUI and GL stuff. These events include running ImGUI draw commands, pushing of current raycasting result to the gpu, and debug mode graphics.
|
|
|
|
*/
|
|
|
|
class DisplayRenderer {
|
|
|
|
private:
|
|
|
|
XWindow& m_window;
|
|
|
|
Texture& m_mainImage;
|
2022-11-15 16:23:37 -05:00
|
|
|
World& m_world;
|
2022-11-13 02:00:27 -05:00
|
|
|
Shader& m_imageShader;
|
|
|
|
Shader& m_worldShader;
|
|
|
|
Raycaster& m_raycaster;
|
|
|
|
Parser& m_parser;
|
|
|
|
VAO* m_spiderVAO;
|
|
|
|
VAO* m_houseVAO;
|
|
|
|
VAO* m_planeVAO;
|
|
|
|
Camera& m_camera;
|
|
|
|
public:
|
|
|
|
DisplayRenderer(XWindow& mWindow,
|
|
|
|
Texture& mMainImage,
|
2022-11-15 16:23:37 -05:00
|
|
|
World& world,
|
2022-11-13 02:00:27 -05:00
|
|
|
Shader& mImageShader,
|
|
|
|
Shader& mWorldShader,
|
|
|
|
Raycaster& mRaycaster,
|
|
|
|
Parser& mParser,
|
|
|
|
VAO* mSpiderVao,
|
|
|
|
VAO* mHouseVao,
|
|
|
|
VAO* mPlaneVao,
|
|
|
|
Camera& mCamera)
|
|
|
|
: m_window(mWindow), m_mainImage(mMainImage), m_imageShader(mImageShader), m_worldShader(mWorldShader), m_raycaster(mRaycaster),
|
2022-11-15 16:23:37 -05:00
|
|
|
m_parser(mParser), m_spiderVAO(mSpiderVao), m_houseVAO(mHouseVao), m_planeVAO(mPlaneVao), m_camera(mCamera), m_world(world) {}
|
2022-11-13 02:00:27 -05:00
|
|
|
void draw();
|
|
|
|
};
|
2022-10-23 23:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //STEP_3_GRAPHICS_H
|