-
Notifications
You must be signed in to change notification settings - Fork 321
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
Changes from 1 commit
fee8613
a673df6
cc3a770
0b115cb
4307293
42ddfd7
be3d0c0
13cb482
a0e971c
8816356
4211608
898f896
3f2d4c7
a736ae9
92eea3a
7b5ab1f
299c6cd
79bbc9b
a3cfce7
32924bd
4d8d518
b1a71a8
43a0a91
e91ed50
eb08a81
b034046
40292b7
154acf8
fa9b9e3
b108dc0
f45b973
e70358d
66aba35
5ce7bd7
4d25774
1daa165
6ec30ba
2f931bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we define versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guparan just not to be forgotten for the update of |
||
|
||
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" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Sofa.GL |
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@) |
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 |
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 |
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 |
There was a problem hiding this comment.
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?