]> git.localhorst.tv Git - blank.git/blobdiff - src/graphics/viewport.cpp
allow disabling vsync to fail
[blank.git] / src / graphics / viewport.cpp
index c46ef28c76fa91bbc6da470615319f69ad75bc73..0fe24085739db91a49385b635028497f2c358e6f 100644 (file)
@@ -3,7 +3,7 @@
 #include "SkyBox.hpp"
 #include "Viewport.hpp"
 
-#include "../app/init.hpp"
+#include "../app/error.hpp"
 #include "../geometry/const.hpp"
 
 #include <GL/glew.h>
@@ -94,6 +94,7 @@ Viewport::Viewport()
 : cam()
 , canv()
 , cursor(1.0f)
+, cam_offset(0.0f)
 , chunk_prog()
 , entity_prog()
 , sky_prog()
@@ -102,9 +103,14 @@ Viewport::Viewport()
        glClearColor(0.0, 0.0, 0.0, 1.0);
 }
 
-void Viewport::VSync(bool b) noexcept {
+void Viewport::VSync(bool b) {
        if (SDL_GL_SetSwapInterval(b) != 0) {
-               throw SDLError("SDL_GL_SetSwapInterval");
+               if (b) {
+                       throw SDLError("SDL_GL_SetSwapInterval(1)");
+               } else {
+                       // allow failure, because this usually means there's no vsync
+                       // support at all, i.e. "it's off"
+               }
        }
 }
 
@@ -263,9 +269,7 @@ BlendedSprite &Viewport::SpriteProgram() noexcept {
 
 
 void Viewport::WorldPosition(const glm::mat4 &t) noexcept {
-       const glm::vec3 offset(0.0f, 0.0f, 0.0f);
-       //const glm::vec3 offset(0.0f, 0.0f, -5.0f);
-       cam.View(glm::translate(glm::inverse(t), glm::vec3(t * glm::vec4(offset, 0.0f))));
+       cam.View(glm::translate(glm::inverse(t), glm::vec3(t * glm::vec4(cam_offset, 0.0f))));
        ChunkProgram().SetView(cam.View());
        sky_prog.Activate();
        SkyBoxProgram().SetView(cam.View());