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
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion SofaKernel/SofaFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ 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})
add_subdirectory(../modules/${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET})
if(SOFA_BUILD_TESTS)
Expand Down
106 changes: 106 additions & 0 deletions SofaKernel/modules/Sofa.GL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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}/VideoRecorderFFMPEG.h
${SOFAGLSRC_ROOT}/glText.h
${SOFAGLSRC_ROOT}/glText.inl
${SOFAGLSRC_ROOT}/TransformationGL.h
${SOFAGLSRC_ROOT}/DrawToolGL.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}/TransformationGL.cpp
${SOFAGLSRC_ROOT}/DrawToolGL.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()

# own include dir, the macro does not handle "independent" package for SofaFramework-style include
# i.e NOT the name of package first (sofa/gl is wanted, instead of Sofa.GL/)
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/${PROJECT_NAME}>")

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${Sofa_VERSION}
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
RELOCATABLE "SofaFramework"
)

set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER SofaFramework)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(SOFAGL_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(SOFAGL_BUILD_TESTS)
enable_testing()
add_subdirectory(${PROJECT_NAME}_test)
endif()
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
19 changes: 19 additions & 0 deletions SofaKernel/modules/Sofa.GL/Sofa.GLConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CMake package configuration file for the @PROJECT_NAME@ module

@PACKAGE_GUARD@
@PACKAGE_INIT@

set(SOFA.GL_HAVE_GLEW @SOFA.GL_HAVE_GLEW@)

find_package(SofaFramework QUIET REQUIRED) # SofaHelper SofaDefaulttype
find_package(OpenGL QUIET REQUIRED)

if(SOFA.GL_HAVE_GLEW)
find_package(GLEW QUIET REQUIRED)
endif()

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

check_required_components(@PROJECT_NAME@)
12 changes: 12 additions & 0 deletions SofaKernel/modules/Sofa.GL/Sofa.GL_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.12)

project(Sofa.GL_test)

set(SOURCE_FILES
src/GLSLShader_test.cpp
)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain Sofa.GL)

add_test(NAME Sofa.GL_test COMMAND Sofa.GL_test)
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/helper/gl/Axis.h>
#include <sofa/gl/Axis.h>

#include <sofa/helper/system/gl.h>
#include <sofa/gl/gl.h>

#include <cassert>
#include <algorithm>
#include <iostream>


namespace sofa
{

namespace helper
{

namespace gl
namespace sofa::gl
{

static const int quadricDiscretisation = 16;
Expand Down Expand Up @@ -394,9 +388,4 @@ void Axis::draw(const Vector3& p1, const Vector3& p2, const double& r1, const do

}

} // namespace gl

} // namespace helper

} // namespace sofa

} // namespace sofa::gl
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,21 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef SOFA_HELPER_GL_AXIS_H
#define SOFA_HELPER_GL_AXIS_H

#ifndef SOFA_NO_OPENGL

#pragma once
#include <sofa/defaulttype/Vec.h>
#include <sofa/defaulttype/Quat.h>

#include <sofa/helper/system/gl.h>
#include <sofa/helper/system/glu.h>
#include <sofa/gl/gl.h>
#include <sofa/gl/glu.h>

#include <map>

#include <sofa/helper/config.h>

namespace sofa
{

namespace helper
{
#include <sofa/gl/config.h>

namespace gl
namespace sofa::gl
{

class SOFA_HELPER_API Axis
class SOFA_GL_API Axis
{
public:
typedef sofa::defaulttype::Vector3 Vector3;
Expand Down Expand Up @@ -95,12 +85,4 @@ class SOFA_HELPER_API Axis

};

} // namespace gl

} // namespace helper

} // namespace sofa

#endif /* SOFA_NO_OPENGL */

#endif
} // namespace sofa::gl
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,13 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef SOFA_HELPER_GL_BASICSHAPES_H
#define SOFA_HELPER_GL_BASICSHAPES_H

#ifndef SOFA_NO_OPENGL

#include <sofa/helper/gl/template.h>
#pragma once
#include <sofa/gl/template.h>
#include <sofa/helper/fixed_array.h>
#include <sofa/helper/system/glu.h>
#include <sofa/gl/glu.h>
#include <cmath>

namespace sofa
{

namespace helper
{

namespace gl
namespace sofa::gl
{

static GLUquadricObj* quadric = gluNewQuadric();
Expand Down Expand Up @@ -71,15 +61,15 @@ void drawCone(const V& p1, const V& p2, const float& radius1, const float& radiu
/* construct normal */
tmp = p*ct+q*st;
/* set the normal for the two subseqent points */
helper::gl::glNormalT(tmp);
gl::glNormalT(tmp);
/* point on disk 1 */
V w(p1);
w += tmp*radius1;
helper::gl::glVertexT(w);
gl::glVertexT(w);
/* point on disk 2 */
w=p2;
w += tmp*radius2;
helper::gl::glVertexT(w);
gl::glVertexT(w);
}
glEnd();
}
Expand Down Expand Up @@ -108,7 +98,7 @@ void drawSphere(const V& center, const float& rad, const int subd1=8, const int
gluQuadricOrientation(quadric, GLU_OUTSIDE);
gluQuadricNormals(quadric, GLU_SMOOTH);
glPushMatrix();
helper::gl::glTranslateT( center );
gl::glTranslateT( center );
gluSphere(quadric,rad,subd1,subd2);
glPopMatrix();
}
Expand All @@ -120,8 +110,8 @@ void drawEllipsoid(const V& center, const float& radx, const float& rady, const
gluQuadricOrientation(quadric, GLU_OUTSIDE);
gluQuadricNormals(quadric, GLU_SMOOTH);
glPushMatrix();
helper::gl::glTranslateT(center);
helper::gl::glScale(radx,rady,radz);
gl::glTranslateT(center);
gl::glScale(radx,rady,radz);
gluSphere(quadric, 1.0, subd1, subd2);
glPopMatrix();
}
Expand All @@ -132,7 +122,7 @@ void drawWireSphere(const V& center, const float& rad, const int subd1=8, const
gluQuadricDrawStyle(quadric, GLU_LINE);
gluQuadricOrientation(quadric, GLU_OUTSIDE);
glPushMatrix();
helper::gl::glTranslateT( center );
gl::glTranslateT( center );
gluSphere(quadric,rad,subd1,subd2);
glPopMatrix();
}
Expand Down Expand Up @@ -226,10 +216,4 @@ void drawEmptyParallelepiped(const V& vert1, const V& vert2, const V& vert3, con
glPopMatrix();
}

} //gl
} //helper
} //sofa

#endif /* SOFA_NO_OPENGL */

#endif
} // namespace sofa::gl
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@
******************************************************************************/
#define SOFA_HELPER_GL_BASICSHAPESGL_CPP

#include <sofa/helper/gl/BasicShapesGL.inl>
#include <sofa/gl/BasicShapesGL.inl>

namespace sofa
namespace sofa::gl
{

namespace helper
{

namespace gl
{

template class SOFA_HELPER_API BasicShapesGL_Sphere<helper::fixed_array< float, 3 > >;
template class SOFA_HELPER_API BasicShapesGL_Sphere<helper::fixed_array< double, 3 > >;
template class SOFA_HELPER_API BasicShapesGL_FakeSphere<helper::fixed_array< float, 3 > >;
template class SOFA_HELPER_API BasicShapesGL_FakeSphere<helper::fixed_array< double, 3 > >;

} //gl
} //helper
} //sofa

template class SOFA_GL_API BasicShapesGL_Sphere<helper::fixed_array< float, 3 > >;
template class SOFA_GL_API BasicShapesGL_Sphere<helper::fixed_array< double, 3 > >;
template class SOFA_GL_API BasicShapesGL_FakeSphere<helper::fixed_array< float, 3 > >;
template class SOFA_GL_API BasicShapesGL_FakeSphere<helper::fixed_array< double, 3 > >;

} // namespace sofa::gl
Loading