summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/gl/program.h2
-rw-r--r--test/test-render.cpp72
-rw-r--r--ui/window.h7
3 files changed, 77 insertions, 4 deletions
diff --git a/gfx/gl/program.h b/gfx/gl/program.h
index 711a26d..f14b0f3 100644
--- a/gfx/gl/program.h
+++ b/gfx/gl/program.h
@@ -7,6 +7,7 @@
class Location;
+using ProgramRef = glRef<GLuint, &glCreateProgram, &glDeleteProgram>;
class Program {
public:
template<typename... S> Program(const S &... srcs)
@@ -40,7 +41,6 @@ public:
protected:
void use() const;
- using ProgramRef = glRef<GLuint, &__glewCreateProgram, &__glewDeleteProgram>;
void linkAndValidate() const;
ProgramRef m_program;
};
diff --git a/test/test-render.cpp b/test/test-render.cpp
index f2f658f..590f8b3 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -47,6 +47,78 @@ public:
};
BOOST_GLOBAL_FIXTURE(ApplicationBase);
+
+#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN
+static void
+CreateProgramTest()
+{
+ ProgramRef p;
+ BOOST_REQUIRE(p);
+}
+BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1)
+{
+ BOOST_REQUIRE(!glCreateProgram); // Init not called yet
+ {
+ SDL_WindowPtr window {TEST_WINDOW_PARAMS};
+ BOOST_REQUIRE(window);
+ BOOST_REQUIRE(!glCreateProgram);
+ BOOST_REQUIRE_NE(glewInit(), GLEW_OK); // No context yet
+ {
+ SDL_GLContextPtr context {window};
+ BOOST_REQUIRE(context);
+ BOOST_REQUIRE(!glCreateProgram);
+ BOOST_REQUIRE_EQUAL(glewInit(), GLEW_OK);
+ BOOST_REQUIRE(glCreateProgram);
+ CreateProgramTest();
+ } // Context destroyed
+ BOOST_REQUIRE(glCreateProgram); // Functions still set
+ BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context
+ {
+ SDL_GLContextPtr context {window};
+ BOOST_REQUIRE(context);
+ CreateProgramTest();
+ }
+ }
+ {
+ SDL_WindowPtr window {TEST_WINDOW_PARAMS};
+ BOOST_REQUIRE(window);
+ SDL_GLContextPtr context {window};
+ BOOST_REQUIRE(context);
+ CreateProgramTest();
+ }
+}
+
+BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour2)
+{
+ SDL_WindowPtr window1 {TEST_WINDOW_PARAMS};
+ BOOST_REQUIRE(window1);
+ {
+ SDL_WindowPtr window2 {TEST_WINDOW_PARAMS};
+ BOOST_REQUIRE(window2);
+ SDL_GLContextPtr context {window2};
+ BOOST_REQUIRE(context);
+ CreateProgramTest();
+ }
+ BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with no context
+}
+
+BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour3)
+{
+ std::optional<SDL_WindowPtr> window1 {std::in_place, TEST_WINDOW_PARAMS};
+ std::optional<SDL_WindowPtr> window2 {std::in_place, TEST_WINDOW_PARAMS};
+ BOOST_REQUIRE(window1);
+ BOOST_REQUIRE(window1.value());
+ SDL_GLContextPtr context {window1.value()};
+ BOOST_REQUIRE(context);
+ CreateProgramTest();
+ window1.reset();
+ BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get fails with context's window gone
+ window1.emplace(TEST_WINDOW_PARAMS);
+ BOOST_REQUIRE(window1);
+ BOOST_REQUIRE(window1.value());
+ BOOST_REQUIRE_THROW({ ProgramRef p; }, std::exception); // Get still fails with context's window gone
+}
+
BOOST_FIXTURE_TEST_SUITE(w, TestRenderWindow);
BOOST_AUTO_TEST_CASE(basic)
diff --git a/ui/window.h b/ui/window.h
index 6f8ad82..cb0118a 100644
--- a/ui/window.h
+++ b/ui/window.h
@@ -10,6 +10,10 @@
#include <special_members.hpp>
#include <string>
+using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
+using GL_Context = std::remove_pointer_t<SDL_GLContext>;
+using SDL_GLContextPtr = wrapped_ptrt<GL_Context, SDL_GL_CreateContext, SDL_GL_DeleteContext>;
+
class Window {
public:
Window(size_t width, size_t height, const std::string & title, Uint32 flags);
@@ -31,9 +35,6 @@ protected:
GlewInitHelper();
};
- using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
- using GL_Context = std::remove_pointer_t<SDL_GLContext>;
- using SDL_GLContextPtr = wrapped_ptrt<GL_Context, SDL_GL_CreateContext, SDL_GL_DeleteContext>;
const glm::ivec2 size;
SDL_WindowPtr m_window;
SDL_GLContextPtr glContext;