Skip to content

Commit

Permalink
Subclass GLX (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored Nov 20, 2024
1 parent 71ba9dd commit d8ea37a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
7 changes: 5 additions & 2 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# F3D Testing
function(f3d_test)

cmake_parse_arguments(F3D_TEST "TONE_MAPPING;LONG_TIMEOUT;INTERACTION;INTERACTION_CONFIGURE;NO_BASELINE;NO_RENDER;NO_OUTPUT;WILL_FAIL;NO_DATA_FORCE_RENDER" "NAME;CONFIG;RESOLUTION;THRESHOLD;REGEXP;REGEXP_FAIL;HDRI;RENDERING_BACKEND" "DATA;DEPENDS;ARGS" ${ARGN})
cmake_parse_arguments(F3D_TEST "TONE_MAPPING;LONG_TIMEOUT;INTERACTION;INTERACTION_CONFIGURE;NO_BASELINE;NO_RENDER;NO_OUTPUT;WILL_FAIL;NO_DATA_FORCE_RENDER" "NAME;CONFIG;RESOLUTION;THRESHOLD;REGEXP;REGEXP_FAIL;HDRI;RENDERING_BACKEND" "DATA;DEPENDS;ENV;ARGS" ${ARGN})

if(F3D_TEST_CONFIG)
list(APPEND F3D_TEST_ARGS "--config=${F3D_TEST_CONFIG}")
Expand Down Expand Up @@ -118,6 +118,7 @@ function(f3d_test)
set_tests_properties(f3d::${F3D_TEST_NAME} PROPERTIES FIXTURES_REQUIRED "${_depends_fixtures}")
endif()

set(f3d_test_env_vars ${F3D_TEST_ENV})
list(APPEND f3d_test_env_vars "CTEST_F3D_PROGRESS_BAR=1")
if (F3D_TEST_NO_DATA_FORCE_RENDER)
list(APPEND f3d_test_env_vars "CTEST_F3D_NO_DATA_FORCE_RENDER=1")
Expand Down Expand Up @@ -1029,7 +1030,9 @@ if(UNIX AND NOT APPLE AND VTK_VERSION VERSION_GREATER_EQUAL 9.3.20240914 AND F3D

if(F3D_TESTING_ENABLE_GLX_TESTS)
f3d_test(NAME TestRenderingBackendGLX DATA cow.vtp RENDERING_BACKEND glx)
f3d_test(NAME TestRenderingBackendGLXCheckClass DATA cow.vtp RENDERING_BACKEND glx ARGS --verbose REGEXP "vtkXOpenGLRenderWindow" NO_BASELINE)
f3d_test(NAME TestRenderingBackendGLXNoDisplay DATA cow.vtp RENDERING_BACKEND glx ENV "DISPLAY=:7" REGEXP "Cannot create a window" NO_BASELINE)
f3d_test(NAME TestRenderingBackendGLXCheckClass DATA cow.vtp RENDERING_BACKEND glx ARGS --verbose REGEXP "vtkF3DGLXRenderWindow" NO_BASELINE)
f3d_test(NAME TestRenderingBackendLinuxAutoCheckClass DATA cow.vtp ARGS --verbose REGEXP "vtkF3DGLXRenderWindow" NO_BASELINE)
endif()

f3d_test(NAME TestRenderingBackendWGLFailure DATA cow.vtp RENDERING_BACKEND wgl REGEXP "Cannot use a WGL context on this platform" NO_BASELINE)
Expand Down
5 changes: 0 additions & 5 deletions library/src/context.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
#include <vtkRenderingOpenGLConfigure.h>
#include <vtkVersion.h>

#if defined(VTK_USE_X) && VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
#include <vtkglad/include/glad/glx.h>
#endif

#if defined(VTK_OPENGL_HAS_EGL) && VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
#include <vtkglad/include/glad/egl.h>
#endif
Expand Down Expand Up @@ -49,7 +45,6 @@ context::function context::getSymbol(const std::string& lib, const std::string&
context::function context::glx()
{
#if defined(VTK_USE_X) && VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
gladLoaderLoadGLX(nullptr, 0); // Load core glx functions.
return getSymbol("GLX", "glXGetProcAddress");
#else
throw loading_exception("Cannot use a GLX context on this platform");
Expand Down
23 changes: 17 additions & 6 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <vtksys/SystemTools.hxx>

#ifdef VTK_USE_X
#include <vtkXOpenGLRenderWindow.h>
#include <vtkF3DGLXRenderWindow.h>
#endif

#ifdef _WIN32
Expand Down Expand Up @@ -72,7 +72,15 @@ class window_impl::internals
#ifdef _WIN32
return vtkSmartPointer<vtkF3DWGLRenderWindow>::New();
#else
// XXX: At the moment, rely on VTK logic for Linux and macOS
#if defined(VTK_USE_X)
// try GLX
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkF3DGLXRenderWindow>::New();
if (renWin)
{
return renWin;
}
#endif
// XXX: At the moment, fallback on VTK logic
// It will change in the future when other subclasses are implemented
return vtkSmartPointer<vtkRenderWindow>::New();
#endif
Expand Down Expand Up @@ -119,8 +127,8 @@ window_impl::window_impl(const options& options, const std::optional<Type>& type
}
else if (type == Type::GLX)
{
#if defined(VTK_USE_X) && VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
this->Internals->RenWin = vtkSmartPointer<vtkXOpenGLRenderWindow>::New();
#if defined(VTK_USE_X)
this->Internals->RenWin = vtkSmartPointer<vtkF3DGLXRenderWindow>::New();
#else
throw engine::no_window_exception("Window type is GLX but VTK GLX support is not enabled");
#endif
Expand All @@ -136,7 +144,10 @@ window_impl::window_impl(const options& options, const std::optional<Type>& type
this->Internals->RenWin = internals::AutoBackendWindow();
}

assert(this->Internals->RenWin != nullptr);
if (this->Internals->RenWin == nullptr)
{
throw engine::no_window_exception("Cannot create a window");
}

#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
vtkOpenGLRenderWindow* oglRenWin = vtkOpenGLRenderWindow::SafeDownCast(this->Internals->RenWin);
Expand Down Expand Up @@ -185,7 +196,7 @@ window_impl::Type window_impl::getType()
}

#ifdef VTK_USE_X
if (this->Internals->RenWin->IsA("vtkXOpenGLRenderWindow"))
if (this->Internals->RenWin->IsA("vtkF3DGLXRenderWindow"))
{
return Type::GLX;
}
Expand Down
6 changes: 6 additions & 0 deletions vtkext/private/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ if(WIN32)
list(APPEND classes vtkF3DWin32OutputWindow vtkF3DWGLRenderWindow)
endif()

# In theory the test should be `if (VTK_USE_X)` but this variable is
# only exported starting from VTK 9.4
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
list(APPEND classes vtkF3DGLXRenderWindow)
endif()

if(ANDROID)
list(APPEND classes vtkF3DAndroidLogOutputWindow)
endif()
Expand Down
38 changes: 38 additions & 0 deletions vtkext/private/module/vtkF3DGLXRenderWindow.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <vtkObjectFactory.h>
#include <vtkVersion.h>

#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
#include <vtk_glad.h>
#include <vtkglad/include/glad/glx.h>
#else
#include <vtk_glew.h>
#endif

#include "vtkF3DGLXRenderWindow.h"

#include <X11/Xlib.h>

//------------------------------------------------------------------------------
vtkF3DGLXRenderWindow::vtkF3DGLXRenderWindow() = default;

//------------------------------------------------------------------------------
vtkF3DGLXRenderWindow::~vtkF3DGLXRenderWindow() = default;

//------------------------------------------------------------------------------
vtkF3DGLXRenderWindow* vtkF3DGLXRenderWindow::New()
{
// Check if the X display is available
Display* dpy = XOpenDisplay(nullptr);
if (dpy == nullptr)
{
return nullptr;
}
XCloseDisplay(dpy);

#if VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 3, 20240914)
// Load core glx functions
gladLoaderLoadGLX(nullptr, 0);
#endif

VTK_STANDARD_NEW_BODY(vtkF3DGLXRenderWindow);
}
25 changes: 25 additions & 0 deletions vtkext/private/module/vtkF3DGLXRenderWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @class vtkF3DGLXRenderWindow
* @brief GLX context render window
*/

#ifndef vtkF3DGLXRenderWindow_h
#define vtkF3DGLXRenderWindow_h

#include "vtkXOpenGLRenderWindow.h"

class vtkF3DGLXRenderWindow : public vtkXOpenGLRenderWindow
{
public:
static vtkF3DGLXRenderWindow* New();
vtkTypeMacro(vtkF3DGLXRenderWindow, vtkXOpenGLRenderWindow);

protected:
vtkF3DGLXRenderWindow();
~vtkF3DGLXRenderWindow() override;

private:
vtkF3DGLXRenderWindow(const vtkF3DGLXRenderWindow&) = delete;
void operator=(const vtkF3DGLXRenderWindow&) = delete;
};
#endif // vtkF3DGLXRenderWindow_h

0 comments on commit d8ea37a

Please sign in to comment.