Skip to content

Commit

Permalink
Fix OpenGL renderer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 8, 2024
1 parent f2743b5 commit 61ddefb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
31 changes: 11 additions & 20 deletions source/opengl/test/src/opengl_renderer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

#include "tactile/opengl/opengl_renderer.hpp"

#include <SDL2/SDL.h>
#include <gtest/gtest.h>
#include <imgui.h>

#include "tactile/base/container/maybe.hpp"
#include "tactile/core/platform/sdl_context.hpp"
#include "tactile/core/platform/window.hpp"
#include "tactile/core/ui/imgui_context.hpp"
#include "tactile/opengl/opengl_renderer_plugin.hpp"
#include "tactile/runtime/runtime.hpp"

namespace tactile {

Expand All @@ -18,28 +14,23 @@ class OpenGLRendererTest : public testing::Test
protected:
void SetUp() override
{
mSDL.emplace();

if (auto window = Window::create(SDL_WINDOW_OPENGL)) {
mWindow.emplace(std::move(*window));
}
else {
FAIL() << "Could not initialize OpenGL renderer";
}
mPlugin.load(mRuntime);
}

mImGuiContext.reset(ImGui::CreateContext());
void TearDown() override
{
mPlugin.unload(mRuntime);
}

Maybe<SDLContext> mSDL {};
Maybe<Window> mWindow {};
ui::UniqueImGuiContext mImGuiContext {};
Runtime mRuntime {};
OpenGLRendererPlugin mPlugin {};
};

/// \trace tactile::OpenGLRenderer::load_texture
TEST_F(OpenGLRendererTest, LoadTexture)
{
auto renderer = OpenGLRenderer::make(&mWindow.value(), mImGuiContext.get());
ASSERT_TRUE(renderer.has_value());
auto* renderer = dynamic_cast<OpenGLRenderer*>(mRuntime.get_renderer());
ASSERT_NE(renderer, nullptr);

EXPECT_EQ(renderer->load_texture("assets/images/dummy.png"), TextureID {1});
EXPECT_FALSE(renderer->load_texture("a/b/c.png").has_value());
Expand Down
41 changes: 10 additions & 31 deletions source/opengl/test/src/opengl_texture_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

#include "tactile/opengl/opengl_texture.hpp"

#include <utility> // move

#include <SDL2/SDL.h>
#include <gtest/gtest.h>
#include <imgui.h>

#include "tactile/base/container/maybe.hpp"
#include "tactile/core/platform/sdl_context.hpp"
#include "tactile/core/platform/window.hpp"
#include "tactile/core/ui/imgui_context.hpp"
#include "tactile/opengl/opengl_renderer.hpp"
#include "tactile/opengl/opengl_renderer_plugin.hpp"
#include "tactile/runtime/runtime.hpp"

namespace tactile {

Expand All @@ -21,30 +14,16 @@ class OpenGLTextureTest : public testing::Test
protected:
void SetUp() override
{
mSDL.emplace();

if (auto window = Window::create(SDL_WINDOW_OPENGL)) {
mWindow.emplace(std::move(*window));
}
else {
FAIL();
}

mImGuiCtx.reset(ImGui::CreateContext());

if (auto renderer =
OpenGLRenderer::make(&mWindow.value(), mImGuiCtx.get())) {
mRenderer.emplace(std::move(*renderer));
}
else {
FAIL() << "Could not initialize OpenGL renderer";
}
mPlugin.load(mRuntime);
}

void TearDown() override
{
mPlugin.unload(mRuntime);
}

Maybe<SDLContext> mSDL {};
Maybe<Window> mWindow {};
ui::UniqueImGuiContext mImGuiCtx {};
Maybe<OpenGLRenderer> mRenderer {};
Runtime mRuntime {};
OpenGLRendererPlugin mPlugin {};
};

/// \trace tactile::OpenGLTexture::load
Expand Down
3 changes: 3 additions & 0 deletions source/runtime/inc/tactile/runtime/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class TACTILE_RUNTIME_API Runtime final
[[nodiscard]]
auto get_window() -> IWindow*;

[[nodiscard]]
auto get_renderer() -> IRenderer*;

[[nodiscard]]
auto get_imgui_context() -> ImGuiContext*;

Expand Down
5 changes: 5 additions & 0 deletions source/runtime/src/tactile/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ auto Runtime::get_window() -> IWindow*
return mData->window.has_value() ? &mData->window.value() : nullptr;
}

auto Runtime::get_renderer() -> IRenderer*
{
return mData->renderer;
}

auto Runtime::get_imgui_context() -> ImGuiContext*
{
return mData->imgui_context.get();
Expand Down

0 comments on commit 61ddefb

Please sign in to comment.