Skip to content
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

[SofaFramework] Isolate OpenGL code into a single module (Sofa.GL) #1649

Merged
merged 38 commits into from
Jan 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fee8613
new module, move files, setup cmake
fredroy Dec 3, 2020
a673df6
make the module compile
fredroy Dec 3, 2020
cc3a770
make SofaFramework compiling
fredroy Dec 3, 2020
0b115cb
split Transformation (w/ and wo ogl)
fredroy Dec 4, 2020
4307293
move DrawToolGL in gl, move DrawTool in helper, make sofacore indepen…
fredroy Dec 4, 2020
42ddfd7
add compat mechanism
fredroy Dec 4, 2020
be3d0c0
move Trackball to helper::visual (as it has no opengl code), and add …
fredroy Dec 4, 2020
13cb482
Make SofaOpenGLVisual (and others) compiling
fredroy Dec 4, 2020
a0e971c
Make SofaGuiQt (and others) compiling
fredroy Dec 4, 2020
8816356
add Sofa.GL test
fredroy Dec 4, 2020
4211608
clean compat
fredroy Dec 4, 2020
898f896
add Color compat
fredroy Dec 4, 2020
3f2d4c7
Add Sofa.GL dep to SofaEulerianFluid
fredroy Dec 4, 2020
a736ae9
add last compat header (seems unused, but in case of)
fredroy Dec 4, 2020
92eea3a
change ref to InvertibleFVM
fredroy Dec 4, 2020
7b5ab1f
Fix cmake config with no opengl and win include dir
fredroy Dec 5, 2020
299c6cd
Make Sofa.GL a real package (i.e able to do find_package() and stuff)
fredroy Dec 7, 2020
79bbc9b
use only drawtool for Visual3DText, remove gl dependency
fredroy Dec 7, 2020
a3cfce7
remove macro SOFA_NO_OPENGL and use Sofa.GL package mechanism
fredroy Dec 7, 2020
32924bd
add Sofa.GL dependency to OpenCL
fredroy Dec 7, 2020
4d8d518
remove SOFA_NO_OPENGL use in Sofa codebase (i.e no in the plugins)
fredroy Dec 7, 2020
b1a71a8
Change message to ref the PR number for more info
fredroy Dec 7, 2020
43a0a91
Add dep to sofa.gl for OptiTrackNatNet
fredroy Dec 7, 2020
e91ed50
IDE: add Sofa.GL in the SofaFramework folder
fredroy Dec 8, 2020
eb08a81
replace _API keyword (with SOFA_GL_API)
fredroy Dec 9, 2020
b034046
Revert "Merge remote-tracking branch 'origin/fix_cmake_win_noopengl_p…
fredroy Dec 14, 2020
40292b7
[CImgPlugin] CLEAN dependencies in CMakeLists
guparan Dec 7, 2020
154acf8
[CImgPlugin] FIX Zlib dependency
guparan Dec 7, 2020
fa9b9e3
[CImgPlugin] CLEAN link to release deps only
guparan Dec 8, 2020
b108dc0
Fix image with GL
fredroy Dec 14, 2020
f45b973
Merge branch 'master' into isolate_gl
fredroy Dec 15, 2020
e70358d
Merge branch 'master' into isolate_gl
fredroy Dec 23, 2020
66aba35
fix merge...
fredroy Dec 23, 2020
5ce7bd7
Merge branch 'master' into isolate_gl
fredroy Dec 28, 2020
4d25774
Update CMakeLists.txt
fredroy Jan 6, 2021
1daa165
Update VisualParams.h
fredroy Jan 6, 2021
6ec30ba
Merge branch 'master' into isolate_gl
fredroy Jan 6, 2021
2f931bd
Merge branch 'master' into isolate_gl
fredroy Jan 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
new module, move files, setup cmake
  • Loading branch information
fredroy committed Dec 14, 2020
commit fee861365cbb3d16072becd48a4dd38c022c7c28
7 changes: 6 additions & 1 deletion SofaKernel/SofaFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -35,8 +35,13 @@ sofa_set_01(SOFA_WITH_DEPRECATED_COMPONENTS_ VALUE ${SOFA_WITH_DEPRECATED_COMPON
sofa_set_01(SOFA_NO_UPDATE_BBOX_ VALUE ${SOFA_NO_UPDATE_BBOX}) # build_option_bbox.h.in

# Package install include directory
set(SOFAFRAMEWORK_TARGETS SofaCore SofaDefaultType SofaHelper SofaSimulationCore)
set(SOFAFRAMEWORK_TARGETS SofaCore SofaDefaultType SofaHelper SofaSimulationCore )
if(NOT SOFA_NO_OPENGL)
list(APPEND SOFAFRAMEWORK_TARGETS Sofa.GL)
endif()

foreach(TARGET ${SOFAFRAMEWORK_TARGETS})
message("Adding ${TARGET}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this for debugging purposes?

add_subdirectory(../modules/${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET})
if(SOFA_BUILD_TESTS)
target_compile_options(${TARGET} PUBLIC "-DFRAMEWORK_TEST_RESOURCES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/resources/tests\"")
93 changes: 93 additions & 0 deletions SofaKernel/modules/Sofa.GL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.12)
project(Sofa.GL LANGUAGES CXX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we define versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package version follows Sofa's version; you can see that this is set in the macro with (... PACKAGE_VERSION ${Sofa_VERSION}... )


set(SOFAGLSRC_ROOT "src/sofa/gl")

sofa_find_package(OpenGL REQUIRED BOTH_SCOPES)
sofa_find_package(GLEW BOTH_SCOPES)

set(HEADER_FILES
${SOFAGLSRC_ROOT}/config.h.in
${SOFAGLSRC_ROOT}/initSofa.GL.h
${SOFAGLSRC_ROOT}/gl.h
${SOFAGLSRC_ROOT}/glu.h
${SOFAGLSRC_ROOT}/Capture.h
${SOFAGLSRC_ROOT}/Color.h
${SOFAGLSRC_ROOT}/RAII.h
${SOFAGLSRC_ROOT}/template.h
${SOFAGLSRC_ROOT}/Axis.h
${SOFAGLSRC_ROOT}/BasicShapes.h
${SOFAGLSRC_ROOT}/BasicShapesGL.h
${SOFAGLSRC_ROOT}/BasicShapesGL.inl
${SOFAGLSRC_ROOT}/Cylinder.h
${SOFAGLSRC_ROOT}/Texture.h
${SOFAGLSRC_ROOT}/Trackball.h
${SOFAGLSRC_ROOT}/Transformation.h
${SOFAGLSRC_ROOT}/VideoRecorderFFMPEG.h
${SOFAGLSRC_ROOT}/glText.h
${SOFAGLSRC_ROOT}/glText.inl
${SOFAGLSRC_ROOT}/Trackball.h
${SOFAGLSRC_ROOT}/Transformation.h
)

set(SOURCE_FILES
${SOFAGLSRC_ROOT}/initSofa.GL.cpp
${SOFAGLSRC_ROOT}/Axis.cpp
${SOFAGLSRC_ROOT}/BasicShapesGL.cpp
${SOFAGLSRC_ROOT}/Cylinder.cpp
${SOFAGLSRC_ROOT}/glText.cpp
${SOFAGLSRC_ROOT}/Capture.cpp
${SOFAGLSRC_ROOT}/Texture.cpp
${SOFAGLSRC_ROOT}/VideoRecorderFFMPEG.cpp
${SOFAGLSRC_ROOT}/Color.cpp
${SOFAGLSRC_ROOT}/gl.cpp
${SOFAGLSRC_ROOT}/Trackball.cpp
${SOFAGLSRC_ROOT}/Transformation.cpp
)

if(GLEW_FOUND)
list(APPEND HEADER_FILES
${SOFAGLSRC_ROOT}/FrameBufferObject.h
${SOFAGLSRC_ROOT}/GLSLShader.h
)
list(APPEND SOURCE_FILES
${SOFAGLSRC_ROOT}/FrameBufferObject.cpp
${SOFAGLSRC_ROOT}/GLSLShader.cpp
)
list(APPEND SHADER_FILES
${SOFAGLSRC_ROOT}/shaders/generateSphere.cppglsl
)
endif()

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper SofaDefaultType)

target_compile_definitions(${PROJECT_NAME} PRIVATE SOFA_BUILD_SOFA_GL) # To remove once sofa_add_targets_to_package remove the dot in the generated definition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guparan just not to be forgotten for the update of sofa_add_targets_to_package


if(TARGET OpenGL::GL AND TARGET OpenGL::GLU) # Imported targets defined since CMake 3.8
target_link_libraries(${PROJECT_NAME} PUBLIC OpenGL::GL OpenGL::GLU)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENGL_LIBRARIES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${OPENGL_INCLUDE_DIR})
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Linux AND SOFA_BUILD_RELEASE_PACKAGE AND OPENGL_GLU_FOUND)
# Add GLU to Linux binaries
sofa_install_libraries(PATHS ${OPENGL_glu_LIBRARY})
endif()

if(GLEW_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC GLEW::GLEW)
if (SOFA_BUILD_RELEASE_PACKAGE OR CMAKE_SYSTEM_NAME STREQUAL Windows)
sofa_install_libraries(TARGETS GLEW::GLEW)
endif()
else()
message("OpenGL advanced functions (e.g shaders, FBO) are disabled.")
endif()

sofa_add_targets_to_package(
PACKAGE_NAME SofaFramework
PACKAGE_VERSION ${Sofa_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "SofaFramework"
)
1 change: 1 addition & 0 deletions SofaKernel/modules/Sofa.GL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Sofa.GL
12 changes: 12 additions & 0 deletions SofaKernel/modules/Sofa.GL/Sofa.GLConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CMake package configuration file for the @PROJECT_NAME@ module

@PACKAGE_GUARD@
@PACKAGE_INIT@

find_package(SofaFramework QUIET REQUIRED)

if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
endif()

check_required_components(@PROJECT_NAME@)
33 changes: 33 additions & 0 deletions SofaKernel/modules/Sofa.GL/src/sofa/gl/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/config.h>

#define SOFAGENERALDEFORMABLE_VERSION @PROJECT_VERSION@

#ifdef SOFA_BUILD_SOFA_GL
# define SOFA_TARGET @PROJECT_NAME@
# define SOFA_SOFA_GL_API SOFA_EXPORT_DYNAMIC_LIBRARY
#else
# define SOFA_SOFA_GL_API SOFA_IMPORT_DYNAMIC_LIBRARY
#endif
File renamed without changes.
72 changes: 72 additions & 0 deletions SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/gl/initSofa.GL.h

#include <sofa/defaulttype/init.h>
#include <sofa/helper/init.h>

namespace sofa::gl
{

static bool s_initialized = false;
static bool s_cleanedUp = false;

SOFA_SOFA_GL_API void init()
{
if (!s_initialized)
{
sofa::defaulttype::init();
s_initialized = true;
}
}

SOFA_SOFA_GL_API bool isInitialized()
{
return s_initialized;
}

SOFA_SOFA_GL_API void cleanup()
{
if (!s_cleanedUp)
{
sofa::defaulttype::cleanup();
s_cleanedUp = true;
}
}

SOFA_SOFA_GL_API bool isCleanedUp()
{
return s_cleanedUp;
}

// Detect missing cleanup() call.
static const struct CleanupCheck
{
CleanupCheck() {}
~CleanupCheck()
{
if (core::isInitialized() && !core::isCleanedUp())
helper::printLibraryNotCleanedUpWarning("Sofa.GL", "sofa::gl::cleanup()");
}
} check;

} // namespace sofa::gl
43 changes: 43 additions & 0 deletions SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <sofa/gl/config.h>

namespace sofa::gl
{
/// @brief Initialize the Sofa.GL library, as well as its dependencies:
/// SofaDefaultType, SofaHelper.
SOFA_SOFA_GL_API void init();

/// @brief Return true if and only if the Sofa.GL library has been initialized.
SOFA_SOFA_GL_API bool isInitialized();

/// @brief Clean up the resources used by the Sofa.GL library, as well as its
/// dependencies: SofaDefaultType, SofaHelper.
SOFA_SOFA_GL_API void cleanup();

/// @brief Return true if and only if the Sofa.GL library has been cleaned
/// up.
SOFA_SOFA_GL_API bool isCleanedUp();

} // namespace sofa::gl
Loading