-
Notifications
You must be signed in to change notification settings - Fork 13
Read and use resolution.xml #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,10 @@ | |
| #include <locale> | ||
| #include <regex> | ||
|
|
||
| #include <GLFW/glfw3.h> | ||
|
|
||
| #include "src/common/platform.h" | ||
| #include "src/common/exception.h" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was only used for the monitor function, so it could be removed as well |
||
| #include "src/common/types.h" | ||
| #include "src/common/crc32.h" | ||
| #include "src/common/strutil.h" | ||
|
|
@@ -135,4 +138,4 @@ std::string getUserDataDirectory() { | |
| return userData; | ||
| } | ||
|
|
||
| } | ||
| } // End of namespace Common | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,11 @@ | |
|
|
||
| #include <CLI/CLI.hpp> | ||
|
|
||
| #include <src/graphics/fontman.h> | ||
| #include "src/configuration.h" | ||
| #include "src/graphics/gfxman.h" | ||
| #include "src/graphics/text.h" | ||
|
|
||
| #include "src/common/crc32.h" | ||
| #include "src/common/threadpool.h" | ||
| #include "src/common/strutil.h" | ||
|
|
@@ -38,6 +43,7 @@ | |
| #include "src/platform/keyconversion.h" | ||
| #include "src/platform/gamepadconversion.h" | ||
| #include "src/platform/gamepadman.h" | ||
| #include "src/platform/platform.h" | ||
|
|
||
| #include "src/graphics/fontman.h" | ||
| #include "src/graphics/text.h" | ||
|
|
@@ -270,6 +276,23 @@ void Game::init() { | |
|
|
||
| _engine->init(); | ||
| }); | ||
|
|
||
| // set window resolution and fullscreen mode | ||
| Configuration & config = _engine->getConfiguration(); | ||
|
|
||
| if (config.resolution.width == 0 || config.resolution.height == 0) { | ||
| Platform::VideoMode videoMode = _platform.getPrimaryMonitorVideoMode(); | ||
| config.resolution.width = videoMode.width; | ||
| config.resolution.height = videoMode.height; | ||
| config.resolution.fullscreen = true; | ||
| } | ||
|
|
||
| _window->setFullscreen(config.resolution.fullscreen); | ||
| _window->setSize(config.resolution.width, config.resolution.height); | ||
| spdlog::error("Window size: {} x {}", _window->getSize().x, _window->getSize().y); | ||
| spdlog::error("Content scale: {} x {}", _window->getContentScale().x, _window->getContentScale().y); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self - remove these log messages as well |
||
| GfxMan.setScreenSize(config.resolution.width, config.resolution.height); | ||
| GfxMan.setContentScale(_window->getContentScale()); | ||
| } | ||
|
|
||
| void Game::start() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| */ | ||
|
|
||
| #include <glm/gtc/type_ptr.hpp> | ||
| #include <algorithm> | ||
|
|
||
| #include "src/common/exception.h" | ||
|
|
||
|
|
@@ -29,8 +30,10 @@ namespace Graphics::OpenGL { | |
| Framebuffer::Framebuffer(const std::string &label) { | ||
| glGenFramebuffers(1, &_id); | ||
|
|
||
| if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | ||
| throw CreateException("Failed to initialize framebuffer"); | ||
| const GLenum framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); | ||
|
|
||
| if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE) | ||
| throw CreateException("Failed to initialize framebuffer: {}", framebufferStatus); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why you split up the framebuffer status?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was not specifically splitting, I was just outputting the error code in the exception message. I'll revert this change - it doesn't have to be here. |
||
|
|
||
| bind(); | ||
| if (GLAD_GL_KHR_debug && !label.empty()) | ||
|
|
@@ -64,8 +67,10 @@ void Framebuffer::attachRenderBuffer(const Renderbuffer &renderbuffer, GLenum at | |
| renderbuffer._id | ||
| ); | ||
|
|
||
| if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) | ||
| throw CreateException("Failed to attach renderbuffer tot exture"); | ||
| const GLenum framebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); | ||
|
|
||
| if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE) | ||
| throw CreateException("Failed to render buffer to texture: {}", framebufferStatus); | ||
| } | ||
|
|
||
| void Framebuffer::clear() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ | |
| #include "src/common/strutil.h" | ||
| #include "src/common/readfile.h" | ||
|
|
||
| #include "src/platform/window.h" | ||
|
|
||
| #include "src/awe/resman.h" | ||
| #include "src/awe/objfile.h" | ||
| #include "src/awe/hg.h" | ||
|
|
@@ -51,6 +53,7 @@ | |
| #include "src/graphics/shaderconverter.h" | ||
| #include "src/graphics/skeleton.h" | ||
| #include "src/graphics/images/surface.h" | ||
| #include "src/graphics/renderer.h" | ||
| #include "src/graphics/opengl/renderer.h" | ||
| #include "src/graphics/opengl/opengl.h" | ||
| #include "src/graphics/opengl/vbo.h" | ||
|
|
@@ -64,6 +67,7 @@ static void *loadProcAddress(const char *name) { | |
| } | ||
|
|
||
| Renderer::Renderer(Platform::Window &window, const std::string &shaderDirectory) : | ||
| Graphics::Renderer(window.getSize()), | ||
| _window(window), | ||
| _shaderDirectory(shaderDirectory) { | ||
| _window.makeCurrent(); | ||
|
|
@@ -194,27 +198,35 @@ Renderer::Renderer(Platform::Window &window, const std::string &shaderDirectory) | |
| // | ||
| rebuildShaders(); | ||
|
|
||
| // Get width and height of the default framebuffer | ||
| unsigned int width, height; | ||
| window.getSize(width, height); | ||
| setRenderPlane(_window.getSize()); | ||
|
|
||
| // Check for errors | ||
| assert(glGetError() == GL_NO_ERROR); | ||
| } | ||
|
|
||
| void Renderer::setRenderPlane(unsigned int width, unsigned int height) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to SetViewportSize |
||
| setRenderPlane(glm::vec2(width, height)); | ||
| } | ||
|
|
||
| void Renderer::setRenderPlane(const glm::vec2 size) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to SetViewportSize |
||
| Graphics::Renderer::setRenderPlane(size); | ||
|
|
||
| // Initialize deferred shading | ||
| // | ||
| _depthTexture = std::make_unique<Texture>(_loadingTasks, width, height, kRGBA16F, "depth_buffer"); | ||
| _normalTexture = std::make_unique<Texture>(_loadingTasks, width, height, kRGBA16F, "normal_buffer"); | ||
| _depthstencilBuffer = std::make_unique<Renderbuffer>(width, height, GL_DEPTH24_STENCIL8, | ||
| _depthTexture = std::make_unique<Texture>(_loadingTasks, size.x, size.y, kRGBA16F, "depth_buffer"); | ||
| _normalTexture = std::make_unique<Texture>(_loadingTasks, size.x, size.y, kRGBA16F, "normal_buffer"); | ||
| _depthstencilBuffer = std::make_unique<Renderbuffer>(size.x, size.y, GL_DEPTH24_STENCIL8, | ||
| "depthstencil_renderbuffer"); | ||
|
|
||
| _deferredBuffer = std::make_unique<Framebuffer>("Deferred Buffer"); | ||
| _deferredBuffer->setClearColor({0.0f, 0.0f, 0.0f, 0.0f}); | ||
| _deferredBuffer->bind(); | ||
|
|
||
| _deferredBuffer->attachRenderBuffer(*_depthstencilBuffer, GL_DEPTH_STENCIL_ATTACHMENT); | ||
|
|
||
| _deferredBuffer->attachTexture(*_depthTexture, GL_COLOR_ATTACHMENT0); | ||
| _deferredBuffer->attachTexture(*_normalTexture, GL_COLOR_ATTACHMENT1); | ||
|
|
||
| _lightBufferTexture = std::make_unique<Texture>(_loadingTasks, width, height, kRGBA16F, "light_buffer"); | ||
| _lightBufferTexture = std::make_unique<Texture>(_loadingTasks, size.x, size.y, kRGBA16F, "light_buffer"); | ||
|
|
||
| _lightBuffer = std::make_unique<Framebuffer>("Light Buffer"); | ||
| _lightBuffer->setClearColor({0.0f, 0.0f, 0.0f, 0.0f}); | ||
|
|
@@ -241,11 +253,18 @@ Renderer::Renderer(Platform::Window &window, const std::string &shaderDirectory) | |
|
|
||
| // Initialize ImGui | ||
| ImGui_ImplOpenGL3_Init(); | ||
| glViewport(0, 0, size.x, size.y); | ||
|
|
||
| // Check for errors | ||
| assert(glGetError() == GL_NO_ERROR); | ||
| } | ||
|
|
||
| void Renderer::setContentScale(glm::vec2 scale) { | ||
| Graphics::Renderer::setContentScale(scale); | ||
| glm::vec2 scaledResolution = _viewportSize * _contentScale; | ||
| glViewport(0, 0, scaledResolution.x, scaledResolution.y); | ||
| } | ||
|
|
||
| Renderer::~Renderer() { | ||
| ImGui_ImplOpenGL3_Shutdown(); | ||
| } | ||
|
|
@@ -297,8 +316,6 @@ void Renderer::drawWorld(const std::string &stage) { | |
| const auto &defaultShader = getProgram("standardmaterial", stage, 0); | ||
| static const glm::mat4 mirrorZ = glm::scale(glm::vec3(1, 1, -1)); | ||
|
|
||
| const auto screenResolution = glm::vec2(1920, 1080); | ||
|
|
||
| bool wireframe = false; | ||
| Material::CullMode cullMode = Material::kNone; | ||
|
|
||
|
|
@@ -329,7 +346,7 @@ void Renderer::drawWorld(const std::string &stage) { | |
| const std::optional<GLint> skinningMatrices = currentShader->getUniformLocation("GPU_skinning_matrices"); | ||
|
|
||
| if (screenRes) | ||
| currentShader->setUniform2f(*screenRes, screenResolution); | ||
| currentShader->setUniform2f(*screenRes, _viewportSize); | ||
|
|
||
| GLuint textureSlotShader = 0; | ||
| if (lightBuffer) { | ||
|
|
@@ -580,7 +597,7 @@ void Renderer::drawLights() { | |
|
|
||
| const auto cameraLightPositionView = _view * mirrorZ * light->getTransform()[3]; | ||
|
|
||
| pointlightProgram->setUniform2f(screenResIndex, glm::vec2(1920, 1080)); | ||
| pointlightProgram->setUniform2f(screenResIndex, _viewportSize); | ||
| pointlightProgram->setUniformMatrix4f(localToClipIndex, vp * mirrorZ * light->getTransform()); | ||
| pointlightProgram->setUniformMatrix4f(clipToViewIndex, clipToView); | ||
| pointlightProgram->setUniform3f(lightPositionIndex, cameraLightPositionView); | ||
|
|
@@ -605,7 +622,7 @@ void Renderer::drawLights() { | |
| } | ||
|
|
||
| void Renderer::drawGUI() { | ||
| glm::mat4 vp = glm::ortho(0.0f, 1920.0f, 0.0f, 1080.0f, -1000.0f, 1000.0f); | ||
| glm::mat4 vp = glm::ortho(0.0f, _viewportSize.x, 0.0f, _viewportSize.y, -1000.0f, 1000.0f); | ||
|
|
||
| pushDebug("Draw GUI"); | ||
|
|
||
|
|
@@ -621,14 +638,14 @@ void Renderer::drawGUI() { | |
| for (const auto &element: _guiElements) { | ||
| glm::mat4 m = glm::translate(glm::vec3( | ||
| element->getAbsolutePosition() + | ||
| element->getRelativePosition() * glm::vec2(1920.0, 1080.0), | ||
| element->getRelativePosition() * _viewportSize, | ||
| 0.0f | ||
| )); | ||
| std::static_pointer_cast<Graphics::OpenGL::VAO>(element->getVertexAttributes())->bind(); | ||
|
|
||
| for (const auto &part: element->getParts()) { | ||
| glm::mat4 m2 = m * | ||
| glm::scale(glm::vec3(part.absoluteSize + part.relativeSize * glm::vec2(1920, 1080), 1.0f)) * | ||
| glm::scale(glm::vec3(part.absoluteSize + part.relativeSize * _viewportSize, 1.0f)) * | ||
| glm::translate(glm::vec3(part.position, 1.0f)); | ||
| std::static_pointer_cast<Graphics::OpenGL::VBO>(part.indices)->bind(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,9 @@ class Renderer : public Graphics::Renderer { | |
| void drawFrame() override; | ||
|
|
||
| bool isLoading() const override; | ||
| void setRenderPlane(unsigned int width, unsigned int height) override; | ||
| void setRenderPlane(glm::vec2 size) override; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename also these methods to setRenderPlane |
||
| void setContentScale(glm::vec2 scale) override; | ||
|
|
||
| TexturePtr createTexture( | ||
| TextureType type, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,14 @@ | |
| #ifndef AWE_CONTEXT_H | ||
| #define AWE_CONTEXT_H | ||
|
|
||
| #include <glm/vec2.hpp> | ||
|
|
||
| namespace Platform { | ||
|
|
||
| class Context { | ||
| public: | ||
| virtual void getSize(unsigned int &width, unsigned int &height) = 0; | ||
| virtual glm::vec2 getSize() = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this method? I would prefer having the context interface to be designed in a minimal and concise way and if necessary convert it somewhere else to float |
||
| }; | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include should not appear outside the platform library