Skip to content

Commit

Permalink
[SofaFramework] Isolate OpenGL code into a single module (Sofa.GL) (s…
Browse files Browse the repository at this point in the history
…ofa-framework#1649)

* new module, move files, setup cmake

* make the module compile

* make SofaFramework compiling

* split Transformation (w/ and wo ogl)

* move DrawToolGL in gl, move DrawTool in helper, make sofacore independent of Sofa.GL

* add compat mechanism

* move Trackball to helper::visual (as it has no opengl code), and add compat from helper::gl

* Make SofaOpenGLVisual (and others) compiling

* Make SofaGuiQt (and others) compiling

* add Sofa.GL test

* clean compat

* add Color compat

* Add Sofa.GL dep to SofaEulerianFluid

* add last compat header (seems unused, but in case of)

* change ref to InvertibleFVM

* Fix cmake config with no opengl and win include dir

* Make Sofa.GL a real package (i.e able to do find_package() and stuff)

* use only drawtool for Visual3DText, remove gl dependency

* remove macro SOFA_NO_OPENGL and use Sofa.GL package mechanism

* add Sofa.GL dependency to OpenCL

* remove SOFA_NO_OPENGL use in Sofa codebase (i.e no in the plugins)

* Change message to ref the PR number for more info

* Add dep to sofa.gl for OptiTrackNatNet

* IDE: add Sofa.GL in the SofaFramework folder

* replace _API keyword (with SOFA_GL_API)

* Revert "Merge remote-tracking branch 'origin/fix_cmake_win_noopengl_png' into isolate_gl"

This reverts commit 8828228, reversing
changes made to 81885a0.

* [CImgPlugin] CLEAN dependencies in CMakeLists

* [CImgPlugin] FIX Zlib dependency

* [CImgPlugin] CLEAN link to release deps only

* Fix image with GL

* fix merge...

* Update CMakeLists.txt

* Update VisualParams.h

Co-authored-by: Guillaume Paran <guillaume.paran@sofa-framework.org>
  • Loading branch information
fredroy and guparan authored Jan 6, 2021
1 parent 6b4ef54 commit c8e99f3
Show file tree
Hide file tree
Showing 113 changed files with 1,947 additions and 1,058 deletions.
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)

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

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

0 comments on commit c8e99f3

Please sign in to comment.