diff --git a/SofaKernel/SofaFramework/CMakeLists.txt b/SofaKernel/SofaFramework/CMakeLists.txt index 14c5b39470a..939fd4ccc09 100644 --- a/SofaKernel/SofaFramework/CMakeLists.txt +++ b/SofaKernel/SofaFramework/CMakeLists.txt @@ -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) diff --git a/SofaKernel/modules/Sofa.GL/CMakeLists.txt b/SofaKernel/modules/Sofa.GL/CMakeLists.txt new file mode 100644 index 00000000000..f673ddfde90 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/CMakeLists.txt @@ -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 "$") + +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() diff --git a/SofaKernel/modules/Sofa.GL/README.md b/SofaKernel/modules/Sofa.GL/README.md new file mode 100644 index 00000000000..e383ba802fb --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/README.md @@ -0,0 +1 @@ +# Sofa.GL \ No newline at end of file diff --git a/SofaKernel/modules/Sofa.GL/Sofa.GLConfig.cmake.in b/SofaKernel/modules/Sofa.GL/Sofa.GLConfig.cmake.in new file mode 100644 index 00000000000..58e8afc8a70 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/Sofa.GLConfig.cmake.in @@ -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@) diff --git a/SofaKernel/modules/Sofa.GL/Sofa.GL_test/CMakeLists.txt b/SofaKernel/modules/Sofa.GL/Sofa.GL_test/CMakeLists.txt new file mode 100644 index 00000000000..aa9d63b1f31 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/Sofa.GL_test/CMakeLists.txt @@ -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) diff --git a/SofaKernel/modules/SofaHelper/SofaHelper_test/gl/GLSLShader_test.cpp b/SofaKernel/modules/Sofa.GL/Sofa.GL_test/src/GLSLShader_test.cpp similarity index 100% rename from SofaKernel/modules/SofaHelper/SofaHelper_test/gl/GLSLShader_test.cpp rename to SofaKernel/modules/Sofa.GL/Sofa.GL_test/src/GLSLShader_test.cpp diff --git a/SofaKernel/modules/SofaHelper/SofaHelper_test/gl/test.cppglsl b/SofaKernel/modules/Sofa.GL/Sofa.GL_test/src/test.cppglsl similarity index 100% rename from SofaKernel/modules/SofaHelper/SofaHelper_test/gl/test.cppglsl rename to SofaKernel/modules/Sofa.GL/Sofa.GL_test/src/test.cppglsl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.cpp similarity index 98% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.cpp index 271456c8efe..f0659b58620 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.cpp @@ -19,22 +19,16 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include -#include +#include #include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { static const int quadricDiscretisation = 16; @@ -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 diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.h similarity index 92% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.h index 9fcf9191a4e..e81187a088a 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Axis.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Axis.h @@ -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 #include -#include -#include +#include +#include #include -#include - -namespace sofa -{ - -namespace helper -{ +#include -namespace gl +namespace sofa::gl { -class SOFA_HELPER_API Axis +class SOFA_GL_API Axis { public: typedef sofa::defaulttype::Vector3 Vector3; @@ -95,12 +85,4 @@ class SOFA_HELPER_API Axis }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapes.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapes.h similarity index 93% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapes.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapes.h index 939ec931481..c4bff102900 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapes.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapes.h @@ -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 +#pragma once +#include #include -#include +#include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { static GLUquadricObj* quadric = gluNewQuadric(); @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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 diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.cpp similarity index 80% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.cpp index c46618875a8..d45426659cb 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.cpp @@ -21,24 +21,14 @@ ******************************************************************************/ #define SOFA_HELPER_GL_BASICSHAPESGL_CPP -#include +#include -namespace sofa +namespace sofa::gl { -namespace helper -{ - -namespace gl -{ - -template class SOFA_HELPER_API BasicShapesGL_Sphere >; -template class SOFA_HELPER_API BasicShapesGL_Sphere >; -template class SOFA_HELPER_API BasicShapesGL_FakeSphere >; -template class SOFA_HELPER_API BasicShapesGL_FakeSphere >; - -} //gl -} //helper -} //sofa - +template class SOFA_GL_API BasicShapesGL_Sphere >; +template class SOFA_GL_API BasicShapesGL_Sphere >; +template class SOFA_GL_API BasicShapesGL_FakeSphere >; +template class SOFA_GL_API BasicShapesGL_FakeSphere >; +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.h similarity index 87% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.h index 0a48a29b1ef..7a0f6d96c81 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.h @@ -19,25 +19,15 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_BASICSHAPESGL_H -#define SOFA_HELPER_GL_BASICSHAPESGL_H - -#ifndef SOFA_NO_OPENGL - -#include +#pragma once +#include #include #include -#include +#include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { class BasicShapesGL @@ -127,18 +117,10 @@ class BasicShapesGL_FakeSphere : public BasicShapesGL }; #if !defined(SOFA_HELPER_GL_BASICSHAPESGL_CPP) -extern template class SOFA_HELPER_API BasicShapesGL_Sphere >; -extern template class SOFA_HELPER_API BasicShapesGL_Sphere >; -extern template class SOFA_HELPER_API BasicShapesGL_FakeSphere >; -extern template class SOFA_HELPER_API BasicShapesGL_FakeSphere >; +extern template class SOFA_GL_API BasicShapesGL_Sphere >; +extern template class SOFA_GL_API BasicShapesGL_Sphere >; +extern template class SOFA_GL_API BasicShapesGL_FakeSphere >; +extern template class SOFA_GL_API BasicShapesGL_FakeSphere >; #endif // !defined(SOFA_HELPER_GL_BASICSHAPESGL_CPP) -} //gl - -} //helper - -} //sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif // SOFA_HELPER_GL_BASICSHAPESGL_H +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.inl b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.inl similarity index 95% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.inl rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.inl index 42bb7755d5b..50e043b49df 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/BasicShapesGL.inl +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/BasicShapesGL.inl @@ -19,20 +19,12 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_BASICSHAPESGL_INL -#define SOFA_HELPER_GL_BASICSHAPESGL_INL +#pragma once +#include +#include +#include -#include -#include -#include - -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { template @@ -151,7 +143,7 @@ template void BasicShapesGL_Sphere::internalDraw(const GLBuffers &buffer, const VertexType& center, const float& radius) { glPushMatrix(); - helper::gl::glTranslate(center[0], center[1], center[2]); + gl::glTranslate(center[0], center[1], center[2]); glScalef(radius, radius, radius); glDrawElements(GL_QUADS, GLsizei(buffer.indicesSize), GL_UNSIGNED_INT, nullptr); @@ -260,13 +252,13 @@ void BasicShapesGL_FakeSphere::init() { if (!b_isInit) { - if (!sofa::helper::gl::GLSLShader::InitGLSL()) + if (!sofa::gl::GLSLShader::InitGLSL()) { msg_info("BasicShapesGL") << "InitGLSL failed" ; return; } - std::string vertexShaderContent = sofa::helper::gl::generateSphereVS; - std::string fragmentShaderContent = sofa::helper::gl::generateSphereFS; + std::string vertexShaderContent = sofa::gl::generateSphereVS; + std::string fragmentShaderContent = sofa::gl::generateSphereFS; m_shader = new GLSLShader(); m_shader->SetVertexShaderFromString(vertexShaderContent); @@ -479,11 +471,4 @@ void BasicShapesGL_FakeSphere::draw(const helper::vector } -} // namespace gl - -} // namespace helper - -} // namespace sofa - - -#endif // SOFA_HELPER_GL_BASICSHAPESGL_INL +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.cpp similarity index 94% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.cpp index d3f18d32ff8..991f35f777e 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.cpp @@ -19,7 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include @@ -28,13 +28,7 @@ #include // sprintf and friends #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { Capture::Capture() @@ -61,7 +55,7 @@ bool Capture::saveScreen(const std::string& filename, int compression_level) { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); - img->init(viewport[2], viewport[3], 1, 1, io::Image::UNORM8, io::Image::RGB); + img->init(viewport[2], viewport[3], 1, 1, helper::io::Image::UNORM8, helper::io::Image::RGB); glReadBuffer(GL_FRONT); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, img->getPixels()); @@ -133,9 +127,4 @@ bool Capture::saveScreen(int compression_level) return saveScreen(findFilename(), compression_level); } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.h similarity index 86% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.h index 680beb133b6..b4464efcf99 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Capture.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Capture.h @@ -19,25 +19,15 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_CAPTURE_H -#define SOFA_HELPER_GL_CAPTURE_H - -#ifndef SOFA_NO_OPENGL - -#include +#pragma once +#include #include -#include - -namespace sofa -{ - -namespace helper -{ +#include -namespace gl +namespace sofa::gl { -class SOFA_HELPER_API Capture +class SOFA_GL_API Capture { protected: std::string prefix; @@ -59,12 +49,4 @@ class SOFA_HELPER_API Capture bool saveScreen(int compression_level = -1); }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.cpp similarity index 94% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.cpp index 2495ab43eea..b399dde21a0 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.cpp @@ -19,19 +19,13 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include -#include +#include +#include #include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { using sofa::helper::types::RGBAColor ; @@ -60,9 +54,4 @@ void Color::getHSVA( float* rgba, float h, float s, float v, float a ) } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.h similarity index 82% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.h index c55cfc494a7..f7cbb5c050e 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Color.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Color.h @@ -19,33 +19,16 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_COLOR_H -#define SOFA_HELPER_GL_COLOR_H +#pragma once +#include -#ifndef SOFA_NO_OPENGL - -#include +#include /// Forward declaration -namespace sofa { - namespace helper { - namespace types { - class RGBAColor; - } - } -} - - -namespace sofa +namespace sofa::gl { -namespace helper -{ - -namespace gl -{ - -class SOFA_HELPER_API Color +class SOFA_GL_API Color { public: static void set(const sofa::helper::types::RGBAColor& color) ; @@ -58,12 +41,4 @@ class SOFA_HELPER_API Color ~Color(); }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.cpp similarity index 98% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.cpp index 23785b9e704..b930f6c14bc 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.cpp @@ -19,20 +19,14 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { static const int quadricDiscretisation = 16; @@ -253,9 +247,4 @@ void Cylinder::draw(const double *mat, SReal len) a->draw(); } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.h similarity index 90% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.h index a15943f4cd7..b07cc578078 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Cylinder.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Cylinder.h @@ -19,31 +19,21 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_CYLINDER_H -#define SOFA_HELPER_GL_CYLINDER_H - -#ifndef SOFA_NO_OPENGL - +#pragma once #include #include -#include -#include +#include +#include -#include +#include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { -class SOFA_HELPER_API Cylinder +class SOFA_GL_API Cylinder { public: typedef sofa::defaulttype::Vector3 Vector3; @@ -88,12 +78,4 @@ class SOFA_HELPER_API Cylinder static void clear() { CylinderMap.clear(); } // need to be called when display list has been created in another opengl context }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.cpp similarity index 97% rename from SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.cpp index 6a9e7bb44af..82beb2fc324 100644 --- a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.cpp @@ -21,41 +21,26 @@ ******************************************************************************/ #define SOFA_HELPER_GL_DRAWTOOLGL_CPP -#include - -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include #include -namespace sofa +namespace sofa::gl { -namespace helper -{ - -namespace gl -{ +template class SOFA_GL_API BasicShapesGL_Sphere< sofa::defaulttype::Vector3 >; +template class SOFA_GL_API BasicShapesGL_FakeSphere< sofa::defaulttype::Vector3 >; -template class SOFA_CORE_API BasicShapesGL_Sphere< sofa::defaulttype::Vector3 >; -template class SOFA_CORE_API BasicShapesGL_FakeSphere< sofa::defaulttype::Vector3 >; - -} // namespace gl - -} // namespace helper - -namespace core -{ - -namespace visual -{ using namespace sofa::defaulttype; -using namespace sofa::helper::gl; +using sofa::helper::types::RGBAColor; DrawToolGL::DrawToolGL() { @@ -451,12 +436,12 @@ void DrawToolGL::drawTriangleFan(const std::vector &points, void DrawToolGL::drawFrame(const Vector3& position, const Quaternion &orientation, const Vec<3,float> &size) { setPolygonMode(0,false); - helper::gl::Axis::draw(position, orientation, size); + gl::Axis::draw(position, orientation, size); } void DrawToolGL::drawFrame(const Vector3& position, const Quaternion &orientation, const Vec<3,float> &size, const RGBAColor &color) { setPolygonMode(0,false); - helper::gl::Axis::draw(position, orientation, size, color, color, color); + gl::Axis::draw(position, orientation, size, color, color, color); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1134,7 +1119,7 @@ void DrawToolGL::drawScaledHexahedra(const std::vector &points, const R void DrawToolGL::drawSphere( const Vector3 &p, float radius) { glPushMatrix(); - helper::gl::drawSphere(p, radius, 32, 16); + gl::drawSphere(p, radius, 32, 16); glPopMatrix(); } @@ -1142,7 +1127,7 @@ void DrawToolGL::drawSphere(const Vector3 &p, float radius, const RGBAColor &col { setMaterial(color); glPushMatrix(); - helper::gl::drawSphere(p, radius, 32, 16); + gl::drawSphere(p, radius, 32, 16); glPopMatrix(); resetMaterial(color); } @@ -1150,7 +1135,7 @@ void DrawToolGL::drawSphere(const Vector3 &p, float radius, const RGBAColor &col void DrawToolGL::drawEllipsoid(const Vector3 &p, const Vector3 &radii) { glPushMatrix(); - helper::gl::drawEllipsoid(p, (float)radii[0], (float)radii[1], (float)radii[2], 32, 16); + gl::drawEllipsoid(p, (float)radii[0], (float)radii[1], (float)radii[2], 32, 16); glPopMatrix(); } @@ -1277,8 +1262,8 @@ void DrawToolGL::resetMaterial() ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void DrawToolGL::clear() { - helper::gl::Axis::clear(); - helper::gl::Cylinder::clear(); + gl::Axis::clear(); + gl::Cylinder::clear(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1343,7 +1328,7 @@ void DrawToolGL::writeOverlayText( int x, int y, unsigned fontSize, const RGBACo glScalef( scale, scale, scale ); - helper::gl::GlText::textureDraw_Overlay(text); + gl::GlText::textureDraw_Overlay(text); glPopAttrib(); // GL_ENABLE_BIT glPopAttrib(); // GL_LIGHTING_BIT @@ -1401,14 +1386,14 @@ void DrawToolGL::draw3DText(const Vector3 &p, float scale, const RGBAColor &colo { glColor4fv(color.array()); - sofa::helper::gl::GlText::draw(text, p, (double)scale); + sofa::gl::GlText::draw(text, p, (double)scale); } void DrawToolGL::draw3DText_Indices(const std::vector &positions, float scale, const RGBAColor &color) { glColor4f(color[0], color[1], color[2], color[3]); - sofa::helper::gl::GlText::textureDraw_Indices(positions, scale); + sofa::gl::GlText::textureDraw_Indices(positions, scale); } void DrawToolGL::saveLastState() @@ -1430,8 +1415,4 @@ void DrawToolGL::readPixels(int x, int y, int w, int h, float* rgb, float* z) glReadPixels(x, y, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, z); } -} // namespace visual - -} // namespace core - -} // namespace sofa +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.h similarity index 96% rename from SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.h index 91780864462..548b6cbbfd8 100644 --- a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawToolGL.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/DrawToolGL.h @@ -19,26 +19,19 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#pragma once - -#ifndef SOFA_CORE_VISUAL_DRAWTOOLGL_H -#define SOFA_CORE_VISUAL_DRAWTOOLGL_H +#include #include #include -#include - -namespace sofa -{ - -namespace core -{ +#include -namespace visual +namespace sofa::gl { -class SOFA_CORE_API DrawToolGL : public DrawTool +class SOFA_GL_API DrawToolGL : public helper::visual::DrawTool { public: @@ -208,8 +201,8 @@ class SOFA_CORE_API DrawToolGL : public DrawTool int mPolygonMode; //0: no cull, 1 front (CULL_CLOCKWISE), 2 back (CULL_ANTICLOCKWISE) bool mWireFrameEnabled; - helper::gl::BasicShapesGL_Sphere m_sphereUtil; - helper::gl::BasicShapesGL_FakeSphere m_fakeSphereUtil; + gl::BasicShapesGL_Sphere m_sphereUtil; + gl::BasicShapesGL_FakeSphere m_fakeSphereUtil; // utility functions, defining primitives virtual void internalDrawPoint(const Vector3 &p, const RGBAColor &c); @@ -251,10 +244,4 @@ class SOFA_CORE_API DrawToolGL : public DrawTool bool getWireFrameEnabled() {return mWireFrameEnabled;} }; -}//namespace visual - -}//namespace core - -}//namespace sofa - -#endif // SOFA_CORE_VISUAL_DRAWTOOLGL_H +}//namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.cpp similarity index 98% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.cpp index 5f697a71918..34ef48e9420 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.cpp @@ -20,16 +20,10 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include -#include +#include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { FrameBufferObject::FrameBufferObject(bool depthTexture, bool enableDepth, bool enableColor, bool enableMipMap, GLint defaultWindowFramebuffer) @@ -320,8 +314,4 @@ void FrameBufferObject::initColorBuffer() } -} //namespace gl - -} //namespace helper - -} //namespace sofa +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.h similarity index 90% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.h index bed31a87d82..da502cce9e7 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/FrameBufferObject.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/FrameBufferObject.h @@ -19,24 +19,16 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef FRAMEBUFFEROBJECT_H_ -#define FRAMEBUFFEROBJECT_H_ +#pragma once +#include -#include +#include -#include -#include - - -namespace sofa -{ -namespace helper -{ -namespace gl +namespace sofa::gl { -struct SOFA_HELPER_API fboParameters +struct SOFA_GL_API fboParameters { GLint depthInternalformat; // GL_DEPTHCOMPONENT16 GL_DEPTHCOMPONENT24... GLint colorInternalformat; // GL_RGB8, GL_RGB16... @@ -52,7 +44,7 @@ struct SOFA_HELPER_API fboParameters } }; -class SOFA_HELPER_API FrameBufferObject +class SOFA_GL_API FrameBufferObject { private: GLint m_defaultWindowFramebufferID; @@ -97,11 +89,4 @@ class SOFA_HELPER_API FrameBufferObject void initColorBuffer(); }; -} //gl - -} //helper - -} //sofa - - -#endif /* FRAMEBUFFEROBJECT_H_ */ +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.cpp similarity index 97% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.cpp index 5d57283608f..f909dc5da62 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.cpp @@ -19,7 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include @@ -29,16 +29,10 @@ #include -namespace sofa +namespace sofa::gl { -namespace helper -{ - -namespace gl -{ - -class GLSLFileListener : public FileEventListener +class GLSLFileListener : public helper::system::FileEventListener { public: /// This attribute is not owning the pointer. @@ -102,7 +96,7 @@ GLSLShader::GLSLShader() geometry_vertices_out = -1; #endif header = ""; - m_filelistener = std::shared_ptr(new GLSLFileListener(this)) ; + m_filelistener = std::shared_ptr(new GLSLFileListener(this)) ; } GLSLShader::~GLSLShader() @@ -110,7 +104,7 @@ GLSLShader::~GLSLShader() // BUGFIX: if the GL context is gone, this can crash the application on exit -- Jeremie A. //Release(); if(m_filelistener){ - FileMonitor::removeListener(m_filelistener.get()); + helper::system::FileMonitor::removeListener(m_filelistener.get()); } } @@ -131,7 +125,7 @@ void GLSLShader::SetShaderFileName(GLint target, const std::string& filename) if (filename.empty()) { if(m_filelistener && !m_hShaderContents[target].filename.empty()) - FileMonitor::removeFileListener(m_hShaderContents[target].filename, m_filelistener.get()) ; + helper::system::FileMonitor::removeFileListener(m_hShaderContents[target].filename, m_filelistener.get()) ; m_hShaderContents.erase(target); }else{ ShaderContents sc; @@ -139,7 +133,7 @@ void GLSLShader::SetShaderFileName(GLint target, const std::string& filename) sc.text = LoadTextFile(filename); m_hShaderContents[target] = sc; if(m_filelistener) - FileMonitor::addFile(filename, m_filelistener.get()) ; + helper::system::FileMonitor::addFile(filename, m_filelistener.get()) ; } } @@ -505,8 +499,4 @@ void GLSLShader::Release() } } -} // namespace gl - -} // namespace helper - -} // namespace sofa +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.h similarity index 92% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.h index 181aa049045..c2928167640 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/GLSLShader.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/GLSLShader.h @@ -19,64 +19,28 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_GLSLSHADER_H -#define SOFA_HELPER_GL_GLSLSHADER_H - -#include - - -/// Forward declaration. -namespace sofa { - namespace helper { - namespace system { - class FileEventListener ; - } - } -} - - - -#include -#include - -#include -#include +#pragma once +#include #include -#include -#include -#include -#include - #include -using sofa::helper::system::FileEventListener ; -using sofa::helper::system::FileMonitor ; - -#include +#include +#include -////////////////////////////// FORWARD DEFINITION ////////////////////////////////////////////////// -namespace sofa { - namespace helper { - namespace gl { - class GLSLShader ; - } - } +/// Forward declaration. +namespace sofa::gl +{ + class GLSLShader ; } -MSG_REGISTER_CLASS(sofa::helper::gl::GLSLShader, "GLSLShader") +MSG_REGISTER_CLASS(sofa::gl::GLSLShader, "GLSLShader") ////////////////////////////////////// DEFINITION ////////////////////////////////////////////////// -namespace sofa -{ - -namespace helper +namespace sofa::gl { -namespace gl -{ - -class SOFA_HELPER_API GLSLShader +class SOFA_GL_API GLSLShader { public: @@ -284,11 +248,4 @@ class SOFA_HELPER_API GLSLShader std::shared_ptr m_filelistener ; }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - - -#endif /* SOFA_HELPER_GL_GLSLSHADER_H */ +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/RAII.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/RAII.h similarity index 89% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/RAII.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/RAII.h index c067232624d..888350ce147 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/RAII.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/RAII.h @@ -19,24 +19,14 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_RAII_H -#define SOFA_HELPER_GL_RAII_H - -#ifndef SOFA_NO_OPENGL - -#include -#include +#pragma once +#include +#include /* Opengl Resource Acquisition Is Initialisation */ /* with this tool, we know at any moment what is the state of the openGL machine */ -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { template @@ -82,12 +72,4 @@ struct Disable }; }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.cpp similarity index 89% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.cpp index 197f8b71d5b..18e54e5af37 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.cpp @@ -20,17 +20,13 @@ * Contact information: contact@sofa-framework.org * ******************************************************************************/ #include -#include +#include #include #include -namespace sofa +namespace sofa::gl { -namespace helper -{ -namespace gl -{ -static unsigned int targetTable[io::Image::COUNT_OF_TEXTURE_TYPES] = +static unsigned int targetTable[helper::io::Image::COUNT_OF_TEXTURE_TYPES] = { GL_TEXTURE_2D, #if defined(GL_VERSION_1_2) @@ -43,7 +39,7 @@ static unsigned int targetTable[io::Image::COUNT_OF_TEXTURE_TYPES] = #endif }; -static unsigned int typeTable[io::Image::COUNT_OF_DATA_TYPES] = +static unsigned int typeTable[helper::io::Image::COUNT_OF_DATA_TYPES] = { GL_UNSIGNED_BYTE, // UNORM8 GL_UNSIGNED_SHORT, // UNORM16 @@ -57,7 +53,7 @@ static unsigned int typeTable[io::Image::COUNT_OF_DATA_TYPES] = GL_UNSIGNED_BYTE // UCOMPRESSED }; -static unsigned int formatTable[io::Image::COUNT_OF_CHANNEL_FORMATS] = +static unsigned int formatTable[helper::io::Image::COUNT_OF_CHANNEL_FORMATS] = { GL_LUMINANCE, // L GL_LUMINANCE_ALPHA, // LA @@ -75,7 +71,7 @@ static unsigned int formatTable[io::Image::COUNT_OF_CHANNEL_FORMATS] = #endif }; -static unsigned int internalFormatTable[io::Image::COUNT_OF_DATA_TYPES][io::Image::COUNT_OF_CHANNEL_FORMATS] = +static unsigned int internalFormatTable[helper::io::Image::COUNT_OF_DATA_TYPES][helper::io::Image::COUNT_OF_CHANNEL_FORMATS] = { // UNORM8 { @@ -179,7 +175,7 @@ static unsigned int internalFormatTable[io::Image::COUNT_OF_DATA_TYPES][io::Imag } }; -static unsigned int internalFormatTableSRGB[io::Image::COUNT_OF_DATA_TYPES][io::Image::COUNT_OF_CHANNEL_FORMATS] = +static unsigned int internalFormatTableSRGB[helper::io::Image::COUNT_OF_DATA_TYPES][helper::io::Image::COUNT_OF_CHANNEL_FORMATS] = { #if defined(GL_EXT_texture_sRGB) // UNORM8 @@ -225,7 +221,7 @@ static bool isPowerOfTwo(unsigned a) void Texture::update() { - io::Image::TextureType textureType = image->getTextureType(); + helper::io::Image::TextureType textureType = image->getTextureType(); target = targetTable[textureType]; unsigned format = formatTable[image->getChannelFormat()]; unsigned type = typeTable[image->getDataType()]; @@ -258,9 +254,9 @@ void Texture::update() glPixelStorei(GL_PACK_ALIGNMENT,1); switch (textureType) { - case io::Image::TEXTURE_2D: + case helper::io::Image::TEXTURE_2D: #if defined(GLEW_VERSION_1_3) - if (image->getDataType() == io::Image::UCOMPRESSED) + if (image->getDataType() == helper::io::Image::UCOMPRESSED) for (unsigned i = 0; i < mipmaps; i++) glCompressedTexImage2D(target, i, internalFormat, image->getWidth(i), image->getHeight(i), 0, image->getMipmapSize(i), image->getMipmapPixels(i)); @@ -271,10 +267,10 @@ void Texture::update() format, type, image->getMipmapPixels(i)); break; - case io::Image::TEXTURE_3D: + case helper::io::Image::TEXTURE_3D: #if defined(GLEW_VERSION_1_2) #if defined(GLEW_VERSION_1_3) - if (image->getDataType() == io::Image::UCOMPRESSED) + if (image->getDataType() == helper::io::Image::UCOMPRESSED) for (unsigned i = 0; i < mipmaps; i++) glCompressedTexImage3D(target, i, internalFormat, image->getWidth(i), image->getHeight(i), image->getDepth(i), 0, image->getMipmapSize(i), image->getMipmapPixels(i)); @@ -286,9 +282,9 @@ void Texture::update() #endif break; - case io::Image::TEXTURE_CUBE: + case helper::io::Image::TEXTURE_CUBE: #if defined(GLEW_VERSION_1_3) - if (image->getDataType() == io::Image::UCOMPRESSED) + if (image->getDataType() == helper::io::Image::UCOMPRESSED) for (unsigned j = 0; j < 6; j++) for (unsigned i = 0; i < mipmaps; i++) glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, i, internalFormat, @@ -311,7 +307,7 @@ void Texture::update() void Texture::init() { - io::Image::TextureType textureType = image->getTextureType(); + helper::io::Image::TextureType textureType = image->getTextureType(); target = GL_TEXTURE_2D; // Default value in case the format is not supported. // Check OpenGL support. @@ -331,11 +327,11 @@ void Texture::init() switch (textureType) { - case io::Image::TEXTURE_INVALID: + case helper::io::Image::TEXTURE_INVALID: msg_error("Texture") << "invalid texture type."; return; - case io::Image::TEXTURE_3D: + case helper::io::Image::TEXTURE_3D: #if defined(GLEW_VERSION_1_2) if (!GLEW_VERSION_1_2) #endif @@ -345,7 +341,7 @@ void Texture::init() } break; - case io::Image::TEXTURE_CUBE: + case helper::io::Image::TEXTURE_CUBE: #if defined(GLEW_VERSION_1_3) if (!GLEW_VERSION_1_3) #endif @@ -360,8 +356,8 @@ void Texture::init() switch (image->getDataType()) { - case io::Image::UINT32: - if (image->getChannelFormat() <= io::Image::LA) + case helper::io::Image::UINT32: + if (image->getChannelFormat() <= helper::io::Image::LA) { #if defined(GLEW_EXT_texture_integer) if (!GLEW_EXT_texture_integer) @@ -381,7 +377,7 @@ void Texture::init() } break; - case io::Image::HALF: + case helper::io::Image::HALF: #if defined(GLEW_VERSION_3_0) if (!GLEW_VERSION_3_0) #endif @@ -391,8 +387,8 @@ void Texture::init() } /* Pass through (no break!) */ [[fallthrough]]; - case io::Image::FLOAT: - if (image->getChannelFormat() <= io::Image::LA) + case helper::io::Image::FLOAT: + if (image->getChannelFormat() <= helper::io::Image::LA) { #if defined(GLEW_ARB_texture_float) if (!GLEW_ARB_texture_float) @@ -412,11 +408,11 @@ void Texture::init() } break; - case io::Image::UCOMPRESSED: + case helper::io::Image::UCOMPRESSED: switch (image->getChannelFormat()) { - case io::Image::L: - case io::Image::LA: + case helper::io::Image::L: + case helper::io::Image::LA: #if defined(GLEW_EXT_texture_compression_latc) if (!GLEW_EXT_texture_compression_latc) #endif @@ -426,8 +422,8 @@ void Texture::init() } break; - case io::Image::R: - case io::Image::RG: + case helper::io::Image::R: + case helper::io::Image::RG: #if defined(GLEW_VERSION_3_0) if (!GLEW_VERSION_3_0) #endif @@ -437,8 +433,8 @@ void Texture::init() } break; - case io::Image::RGB: - case io::Image::RGBA: + case helper::io::Image::RGB: + case helper::io::Image::RGBA: #if defined(GLEW_EXT_texture_compression_s3tc) if (!GLEW_EXT_texture_compression_s3tc) #endif @@ -490,7 +486,7 @@ void Texture::init() glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } - if (repeat && textureType != io::Image::TEXTURE_CUBE) + if (repeat && textureType != helper::io::Image::TEXTURE_CUBE) { glTexParameteri( target, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( target, GL_TEXTURE_WRAP_T, GL_REPEAT ); @@ -509,7 +505,7 @@ void Texture::init() #if defined(GLEW_ARB_seamless_cube_map) // This is a global state so probably should be moved to a more appropriate location. - if (textureType == io::Image::TEXTURE_CUBE) + if (textureType == helper::io::Image::TEXTURE_CUBE) if (GLEW_ARB_seamless_cube_map) glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); #endif @@ -535,7 +531,7 @@ void Texture::unbind(void) glBindTexture(target, 0); } -io::Image* Texture::getImage(void) +helper::io::Image* Texture::getImage(void) { return image; } @@ -545,6 +541,5 @@ Texture::~Texture(void) if (id) glDeleteTextures(1, &id); delete image; image=nullptr; } -} // namespace gl -} // namespace helper -} // namespace sofa + +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.h similarity index 84% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.h index 7a6e0e9de21..eb5902c856e 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Texture.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/Texture.h @@ -19,28 +19,18 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_TEXTURE_H -#define SOFA_HELPER_GL_TEXTURE_H - -#ifndef SOFA_NO_OPENGL - -#include -#include +#pragma once +#include +#include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { -class SOFA_HELPER_API Texture +class SOFA_GL_API Texture { private: - io::Image *image; + helper::io::Image *image; GLuint id, target; bool repeat, linearInterpolation, generateMipmaps, srgbColorspace; float minLod, maxLod; @@ -52,13 +42,13 @@ class SOFA_HELPER_API Texture { } - Texture (io::Image *img, bool repeat = true, bool linearInterpolation = true, bool generateMipmaps = true, + Texture (helper::io::Image *img, bool repeat = true, bool linearInterpolation = true, bool generateMipmaps = true, bool srgbColorspace = false, float minLod = -1000, float maxLod = 1000) :image(img),id(0),repeat(repeat), linearInterpolation(linearInterpolation), generateMipmaps(generateMipmaps), srgbColorspace(srgbColorspace), minLod(minLod), maxLod(maxLod) {} - io::Image* getImage(void); + helper::io::Image* getImage(void); GLuint getTarget() const { return target; } void bind(void); void unbind(void); @@ -73,12 +63,4 @@ class SOFA_HELPER_API Texture Texture operator=(const Texture& ) { return Texture(); } }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.cpp new file mode 100644 index 00000000000..a7e213da378 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.cpp @@ -0,0 +1,83 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include +#include +#include + +namespace sofa::gl +{ + +// -------------------------------------------------------------------------------------- +// --- Constructor +// -------------------------------------------------------------------------------------- +TransformationGL::TransformationGL() + : Transformation() +{ + +} + + +// -------------------------------------------------------------------------------------- +// --- Destructor +// -------------------------------------------------------------------------------------- +TransformationGL::~TransformationGL() +{ +} + + +// -------------------------------------------------------------------------------------- +// --- Apply the transformation +// -------------------------------------------------------------------------------------- +void TransformationGL::Apply() +{ + gl::glTranslate(translation[0], translation[1], translation[2]); + gl::glMultMatrix((SReal *)rotation); + gl::glScale(scale[0], scale[1], scale[2]); +} + + +// -------------------------------------------------------------------------------------- +// --- First center the object, then apply the transformation (to align with the corresponding texture) +// -------------------------------------------------------------------------------------- +void TransformationGL::ApplyWithCentring() +{ + Apply(); + + gl::glTranslate(-objectCenter[0], -objectCenter[1], -objectCenter[2]); +} + + +// -------------------------------------------------------------------------------------- +// --- Apply the inverse transformation +// -------------------------------------------------------------------------------------- +void TransformationGL::ApplyInverse() +{ + SReal iRotation[4][4]; + + InvertTransRotMatrix(rotation, iRotation); + + gl::glScale((SReal)1.0 / scale[0], (SReal)1.0 / scale[1], (SReal)1.0 / scale[2]); + gl::glMultMatrix((SReal *)rotation); + gl::glTranslate(-translation[0], -translation[1], -translation[2]); +} + +} // namespace sofa::gl diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.h new file mode 100644 index 00000000000..fab90833465 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/TransformationGL.h @@ -0,0 +1,42 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#include + +namespace sofa::gl +{ + +class SOFA_GL_API TransformationGL : public helper::visual::Transformation +{ +public: + TransformationGL(); + virtual ~TransformationGL(); + + void Apply() override; + void ApplyWithCentring() override; + void ApplyInverse() override; + +}; + +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.cpp similarity index 96% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.cpp index 3a3b24e2417..26d07054bf1 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.cpp @@ -19,7 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include @@ -32,13 +32,7 @@ using sofa::helper::system::FileSystem; #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { VideoRecorderFFMPEG::VideoRecorderFFMPEG() @@ -101,7 +95,7 @@ bool VideoRecorderFFMPEG::init(const std::string& ffmpeg_exec_filepath, const st #ifdef WIN32 extension = ".exe"; #endif - m_ffmpegExecPath = Utils::getExecutablePath() + "/ffmpeg" + extension; + m_ffmpegExecPath = helper::Utils::getExecutablePath() + "/ffmpeg" + extension; if(!FileSystem::isFile(m_ffmpegExecPath)) { // Fallback to a relative FFMPEG (may be in system or exposed in PATH) @@ -219,9 +213,4 @@ std::string VideoRecorderFFMPEG::findFilename(const unsigned int framerate, cons return filename; } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.h similarity index 86% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.h index 23bbd2772fe..cae5c266795 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/VideoRecorderFFMPEG.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/VideoRecorderFFMPEG.h @@ -19,28 +19,18 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_VIDEORECORDER_FFMPEG_H -#define SOFA_HELPER_GL_VIDEORECORDER_FFMPEG_H - -#ifndef SOFA_NO_OPENGL - -#include -#include +#pragma once +#include +#include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { -class SOFA_HELPER_API VideoRecorderFFMPEG +class SOFA_GL_API VideoRecorderFFMPEG { protected: @@ -82,12 +72,4 @@ class SOFA_HELPER_API VideoRecorderFFMPEG }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif //SOFA_HELPER_GL_VIDEORECORDER_FFMPEG_H +} // namespace sofa::gl diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/config.h.in b/SofaKernel/modules/Sofa.GL/src/sofa/gl/config.h.in new file mode 100644 index 00000000000..a2d7bd70216 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/config.h.in @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#define SOFA_GL_VERSION @PROJECT_VERSION@ + +#ifdef SOFA_BUILD_SOFA_GL +# define SOFA_TARGET @PROJECT_NAME@ +# define SOFA_GL_API SOFA_EXPORT_DYNAMIC_LIBRARY +#else +# define SOFA_GL_API SOFA_IMPORT_DYNAMIC_LIBRARY +#endif diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.cpp similarity index 93% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.cpp index c695622dc1d..d6681bae4cd 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.cpp @@ -21,20 +21,16 @@ ******************************************************************************/ #include "gl.h" -#ifndef SOFA_NO_OPENGL - -SOFA_HELPER_API const char* GetGlExtensionsList() +SOFA_GL_API const char* GetGlExtensionsList() { return reinterpret_cast(glGetString(GL_EXTENSIONS)); } -SOFA_HELPER_API bool CanUseGlExtension(const std::string& ext) +SOFA_GL_API bool CanUseGlExtension(const std::string& ext) { const char * extensions = GetGlExtensionsList(); if( extensions && std::string(extensions).find( ext ) != std::string::npos ) return true; return false; } - -#endif diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.h new file mode 100644 index 00000000000..f66b2ebd001 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/gl.h @@ -0,0 +1,31 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + + +#include +#include + +extern SOFA_GL_API const char* GetGlExtensionsList(); + +extern SOFA_GL_API bool CanUseGlExtension(const std::string& ext); diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.cpp similarity index 94% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.cpp index 413654faacc..beb7fcebbef 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.cpp @@ -19,22 +19,16 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { using namespace sofa::defaulttype; using std::string; -SOFA_HELPER_API const std::string GlText::ASCII_TEXTURE_PATH("textures/texture_ascii_smooth.png"); -SOFA_HELPER_API sofa::helper::io::Image *GlText::s_asciiImage = nullptr; -SOFA_HELPER_API sofa::helper::gl::Texture* GlText::s_asciiTexture = nullptr; +SOFA_GL_API const std::string GlText::ASCII_TEXTURE_PATH("textures/texture_ascii_smooth.png"); +SOFA_GL_API sofa::helper::io::Image *GlText::s_asciiImage = nullptr; +SOFA_GL_API sofa::gl::Texture* GlText::s_asciiTexture = nullptr; void GlText::initTexture() { @@ -44,7 +38,7 @@ void GlText::initTexture() } if (s_asciiTexture == nullptr && s_asciiImage != nullptr) { - s_asciiTexture = new sofa::helper::gl::Texture(s_asciiImage, false, true, false ); + s_asciiTexture = new sofa::gl::Texture(s_asciiImage, false, true, false ); } } @@ -277,8 +271,4 @@ void GlText::textureDraw_Indices(const helper::vector& pos -} // namespace gl - -} // namespace helper - -} // namespace sofa +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.h similarity index 89% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.h index 9a8b5bb8460..6118a5c3f88 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.h @@ -19,11 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_TEXT_H -#define SOFA_HELPER_GL_TEXT_H - -#ifndef SOFA_NO_OPENGL - +#pragma once #include #include #include @@ -31,20 +27,14 @@ #include #include -#include -#include +#include +#include #include -#include - -#include - -namespace sofa -{ +#include -namespace helper -{ +#include -namespace gl +namespace sofa::gl { @@ -53,7 +43,7 @@ namespace gl * in 2D (screen) or in 3D (world coordinates) */ -class SOFA_HELPER_API GlText +class SOFA_GL_API GlText { public: typedef sofa::helper::fixed_array Vector3; @@ -103,19 +93,11 @@ class SOFA_HELPER_API GlText static const std::string ASCII_TEXTURE_PATH; static sofa::helper::io::Image *s_asciiImage; - static sofa::helper::gl::Texture* s_asciiTexture; + static sofa::gl::Texture* s_asciiTexture; double scale; std::string text; defaulttype::Vector3 position; }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.inl b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.inl similarity index 94% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.inl rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.inl index 704eef72a33..bc8ca382b12 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glText.inl +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glText.inl @@ -19,26 +19,16 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_GLTEXT_INL -#define SOFA_HELPER_GL_GLTEXT_INL +#pragma once +#include -#ifndef SOFA_NO_OPENGL - -#include - -#include +#include #include #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { template @@ -152,12 +142,4 @@ void GlText::draw(const T& text, const defaulttype::Vector3& position, const dou glEnable(GL_LIGHTING); } -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.cpp similarity index 98% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.cpp rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.cpp index 6f4df516e00..9fea8d44e83 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.cpp +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.cpp @@ -35,13 +35,7 @@ extern "C" Display * glXGetCurrentDisplayEXT (void); #endif -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { #if __APPLE__ diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.h similarity index 93% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.h index a6513fef20e..3c48c13d9e5 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/glfont.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glfont.h @@ -19,20 +19,10 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_GLFONT_H -#define SOFA_HELPER_GL_GLFONT_H - -#ifndef SOFA_NO_OPENGL - +#pragma once #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { SOFA_HELPER_API void glfntInit(void); diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/glu.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glu.h similarity index 93% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/system/glu.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/glu.h index 9895f065857..97d28638acc 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/glu.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/glu.h @@ -19,16 +19,10 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_SYSTEM_GLU_H -#define SOFA_HELPER_SYSTEM_GLU_H +#pragma once -#if !defined(SOFA_NO_OPENGL) #if defined (__APPLE__) #include #else #include #endif -#endif - - -#endif /* SOFA_NO_OPENGL */ diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.cpp b/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.cpp new file mode 100644 index 00000000000..3e196fc83e8 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.cpp @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include + +#include +#include + +namespace sofa::gl +{ + +static bool s_initialized = false; +static bool s_cleanedUp = false; + +SOFA_GL_API void init() +{ + if (!s_initialized) + { + sofa::defaulttype::init(); + s_initialized = true; + } +} + +SOFA_GL_API bool isInitialized() +{ + return s_initialized; +} + +SOFA_GL_API void cleanup() +{ + if (!s_cleanedUp) + { + sofa::defaulttype::cleanup(); + s_cleanedUp = true; + } +} + +SOFA_GL_API bool isCleanedUp() +{ + return s_cleanedUp; +} + +// Detect missing cleanup() call. +static const struct CleanupCheck +{ + CleanupCheck() {} + ~CleanupCheck() + { + if (gl::isInitialized() && !gl::isCleanedUp()) + helper::printLibraryNotCleanedUpWarning("Sofa.GL", "sofa::gl::cleanup()"); + } +} check; + +} // namespace sofa::gl diff --git a/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.h new file mode 100644 index 00000000000..b95a2403c37 --- /dev/null +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/initSofa.GL.h @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +namespace sofa::gl +{ +/// @brief Initialize the Sofa.GL library, as well as its dependencies: +/// SofaDefaultType, SofaHelper. +SOFA_GL_API void init(); + +/// @brief Return true if and only if the Sofa.GL library has been initialized. +SOFA_GL_API bool isInitialized(); + +/// @brief Clean up the resources used by the Sofa.GL library, as well as its +/// dependencies: SofaDefaultType, SofaHelper. +SOFA_GL_API void cleanup(); + +/// @brief Return true if and only if the Sofa.GL library has been cleaned +/// up. +SOFA_GL_API bool isCleanedUp(); + +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/shaders/generateSphere.cppglsl b/SofaKernel/modules/Sofa.GL/src/sofa/gl/shaders/generateSphere.cppglsl similarity index 96% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/shaders/generateSphere.cppglsl rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/shaders/generateSphere.cppglsl index 32815712e39..01d0990b9d4 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/shaders/generateSphere.cppglsl +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/shaders/generateSphere.cppglsl @@ -1,10 +1,4 @@ -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { const std::string generateSphereVS = R"SHADER_DELIM( @@ -92,8 +86,4 @@ void main() } )SHADER_DELIM"; -} //gl - -} //helper - -} //sofa \ No newline at end of file +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/template.h b/SofaKernel/modules/Sofa.GL/src/sofa/gl/template.h similarity index 95% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/template.h rename to SofaKernel/modules/Sofa.GL/src/sofa/gl/template.h index f52bcd0f424..9e9850f918d 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/template.h +++ b/SofaKernel/modules/Sofa.GL/src/sofa/gl/template.h @@ -19,21 +19,11 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_TEMPLATE_H -#define SOFA_HELPER_GL_TEMPLATE_H +#pragma once +#include +#include -#ifndef SOFA_NO_OPENGL - -#include -#include - -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::gl { template @@ -318,12 +308,4 @@ inline void glMultMatrix(const double* p) glMultMatrixd(p); } -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif /* SOFA_NO_OPENGL */ - -#endif +} // namespace sofa::gl diff --git a/SofaKernel/modules/SofaCore/CMakeLists.txt b/SofaKernel/modules/SofaCore/CMakeLists.txt index eb3ea432c9d..48c5412381f 100644 --- a/SofaKernel/modules/SofaCore/CMakeLists.txt +++ b/SofaKernel/modules/SofaCore/CMakeLists.txt @@ -142,7 +142,6 @@ set(HEADER_FILES ${SRC_ROOT}/topology/TopologyElementHandler.h ${SRC_ROOT}/topology/TopologyHandler.h ${SRC_ROOT}/visual/DisplayFlags.h - ${SRC_ROOT}/visual/DrawTool.h ${SRC_ROOT}/visual/Shader.h ${SRC_ROOT}/visual/VisualLoop.h ${SRC_ROOT}/visual/VisualManager.h @@ -255,11 +254,6 @@ set(SOURCE_FILES ${SRC_ROOT}/logging/PerComponentLoggingMessageHandler.cpp ) -if(NOT SOFA_NO_OPENGL) - list(APPEND HEADER_FILES ${SRC_ROOT}/visual/DrawToolGL.h) - list(APPEND SOURCE_FILES ${SRC_ROOT}/visual/DrawToolGL.cpp) -endif() - add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC SofaHelper SofaDefaultType) diff --git a/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.cpp b/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.cpp index 308fdedf4e6..55019267a23 100644 --- a/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.cpp +++ b/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.cpp @@ -41,7 +41,7 @@ VisualParams::VisualParams() , m_cameraType(PERSPECTIVE_TYPE) , m_pass(Std) , m_drawTool(nullptr) - , m_boundFrameBuffer(nullptr) + //, m_boundFrameBuffer(nullptr) , m_x (ConstVecCoordId::position()) , m_v (ConstVecDerivId::velocity()) , m_supportedAPIs(0) diff --git a/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.h b/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.h index e8a4e7c0481..42692cf90ea 100644 --- a/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.h +++ b/SofaKernel/modules/SofaCore/src/sofa/core/visual/VisualParams.h @@ -24,30 +24,12 @@ #define SOFA_CORE_VISUAL_VISUALPARAMS_H #include -#include +#include +#include #include -#include - - -namespace sofa -{ - -namespace helper -{ -namespace gl -{ -class FrameBufferObject; -} // namespace gl -} // namespace helper - -namespace core +namespace sofa::core::visual { -namespace visual -{ - -class DrawTool; - /// The enumeration used to describe potentially supported graphics API. enum { @@ -135,11 +117,8 @@ class SOFA_CORE_API VisualParams : public ExecParams const Pass& pass() const { return m_pass; } Pass& pass() { return m_pass; } - DrawTool*& drawTool() { return m_drawTool; } - DrawTool*& drawTool() const { return m_drawTool; } - - helper::gl::FrameBufferObject*& frameBufferObject() { return m_boundFrameBuffer; } - helper::gl::FrameBufferObject*& frameBufferObject() const { return m_boundFrameBuffer; } + helper::visual::DrawTool*& drawTool() { return m_drawTool; } + helper::visual::DrawTool*& drawTool() const { return m_drawTool; } DisplayFlags& displayFlags() { return m_displayFlags; } const DisplayFlags& displayFlags() const { return m_displayFlags; } @@ -159,10 +138,18 @@ class SOFA_CORE_API VisualParams : public ExecParams /// Get the projection matrix used to draw the scene. This OpenGL matrix defines the camera coordinate system with respect to the viewport, including perspective if any. void getProjectionMatrix( double m[16] ) const { for(unsigned i=0; i<16; i++) m[i] = m_projectionMatrix[i]; } - /// @todo clarify what this is with respect to ModelView and Perspective matrices - sofa::helper::gl::Transformation& sceneTransform() { return m_sceneTransform; } - const sofa::helper::gl::Transformation& sceneTransform() const { return m_sceneTransform; } + /// set those deprecations as error ASAP + [[deprecated("sceneTransform in DrawTool is removed from VisualParam, use with the ModelView and Perspective Matrices instead.")]] + helper::visual::Transformation& sceneTransform() { return m_sceneTransform; } + + [[deprecated("sceneTransform in DrawTool is removed from VisualParam, use with the ModelView and Perspective Matrices instead.")]] + const helper::visual::Transformation& sceneTransform() const { return m_sceneTransform; } + + //[[deprecated("frameBufferObject in DrawTool is removed from VisualParam, use your rendering API instead.")]] + //helper::gl::FrameBufferObject*& frameBufferObject() { return m_boundFrameBuffer; } + //[[deprecated("frameBufferObject in DrawTool is removed from VisualParam, use your rendering API instead.")]] + //helper::gl::FrameBufferObject*& frameBufferObject() const { return m_boundFrameBuffer; } bool isSupported(unsigned int api) const { @@ -179,15 +166,15 @@ class SOFA_CORE_API VisualParams : public ExecParams protected: sofa::defaulttype::BoundingBox m_sceneBoundingBox; - helper::gl::Transformation m_sceneTransform; + helper::visual::Transformation m_sceneTransform; Viewport m_viewport; SReal m_zNear; SReal m_zFar; CameraType m_cameraType; Pass m_pass; DisplayFlags m_displayFlags; - mutable DrawTool* m_drawTool; - mutable helper::gl::FrameBufferObject* m_boundFrameBuffer; + mutable helper::visual::DrawTool* m_drawTool; + //mutable helper::gl::FrameBufferObject* m_boundFrameBuffer; /// Ids of position vector ConstMultiVecCoordId m_x; /// Ids of velocity vector @@ -199,8 +186,7 @@ class SOFA_CORE_API VisualParams : public ExecParams SReal m_projectionMatrix[16]; ///< projection matrix. }; -} // namespace visual -} // namespace core -} // namespace sofa +} // namespace sofa::core::visual + #endif // SOFA_CORE_VISUAL_VISUALPARAMS_H diff --git a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/AngularSpringForceField.cpp b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/AngularSpringForceField.cpp index e1deb12638e..bd308fbf73b 100644 --- a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/AngularSpringForceField.cpp +++ b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/AngularSpringForceField.cpp @@ -22,7 +22,6 @@ #define SOFA_COMPONENT_FORCEFIELD_ANGULARSPRINGFORCEFIELD_CPP #include -#include #include namespace sofa::component::forcefield diff --git a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialRestShapeSpringsForceField.cpp b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialRestShapeSpringsForceField.cpp index fec73cf60df..1698528d9fa 100644 --- a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialRestShapeSpringsForceField.cpp +++ b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialRestShapeSpringsForceField.cpp @@ -26,7 +26,6 @@ #include "PolynomialRestShapeSpringsForceField.inl" -#include #include namespace sofa::component::forcefield diff --git a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialSpringsForceField.cpp b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialSpringsForceField.cpp index 6e901a52f03..583e8780b16 100644 --- a/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialSpringsForceField.cpp +++ b/SofaKernel/modules/SofaDeformable/src/SofaDeformable/PolynomialSpringsForceField.cpp @@ -26,7 +26,6 @@ #include "PolynomialSpringsForceField.inl" -#include #include namespace sofa::component::interactionforcefield diff --git a/SofaKernel/modules/SofaHelper/CMakeLists.txt b/SofaKernel/modules/SofaHelper/CMakeLists.txt index 54af2a00e65..69a0de8bf7b 100644 --- a/SofaKernel/modules/SofaHelper/CMakeLists.txt +++ b/SofaKernel/modules/SofaHelper/CMakeLists.txt @@ -15,11 +15,6 @@ if(SOFAHELPER_HAVE_BOOST_SYSTEM else() sofa_set_01(SOFAHELPER_HAVE_BOOST VALUE FALSE BOTH_SCOPES) endif() -# OpenGL (gl, glu) + GLEW -if(NOT SOFA_NO_OPENGL) - sofa_find_package(OpenGL REQUIRED BOTH_SCOPES) - sofa_find_package(GLEW BOTH_SCOPES) -endif() # GTest if(SOFA_BUILD_TESTS OR SOFA_BUILD_RELEASE_PACKAGE) sofa_find_package(GTest CONFIG BOTH_SCOPES) @@ -79,8 +74,6 @@ set(HEADER_FILES ${SRC_ROOT}/fixed_array.h ${SRC_ROOT}/fixed_array_algorithms.h ${SRC_ROOT}/hash.h - ${SRC_ROOT}/gl/Trackball.h - ${SRC_ROOT}/gl/Transformation.h ${SRC_ROOT}/init.h ${SRC_ROOT}/integer_id.h ${SRC_ROOT}/io/BaseFileAccess.h @@ -120,8 +113,6 @@ set(HEADER_FILES ${SRC_ROOT}/system/config.h ${SRC_ROOT}/system/console.h ${SRC_ROOT}/system/console_internal.h - ${SRC_ROOT}/system/gl.h - ${SRC_ROOT}/system/glu.h ${SRC_ROOT}/system/thread/CTime.h ${SRC_ROOT}/system/thread/CircularQueue.h ${SRC_ROOT}/system/thread/CircularQueue.inl @@ -157,6 +148,9 @@ set(HEADER_FILES ${SRC_ROOT}/logging/DefaultStyleMessageFormatter.h ${SRC_ROOT}/logging/ExceptionMessageHandler.h ${SRC_ROOT}/messaging/FileMessage.h + ${SRC_ROOT}/visual/Transformation.h + ${SRC_ROOT}/visual/DrawTool.h + ${SRC_ROOT}/visual/Trackball.h ) set(SOURCE_FILES ${SRC_ROOT}/AdvancedTimer.cpp @@ -181,8 +175,6 @@ set(SOURCE_FILES ${SRC_ROOT}/UnitTest.cpp ${SRC_ROOT}/Utils.cpp ${SRC_ROOT}/decompose.cpp - ${SRC_ROOT}/gl/Trackball.cpp - ${SRC_ROOT}/gl/Transformation.cpp ${SRC_ROOT}/init.cpp ${SRC_ROOT}/io/BaseFileAccess.cpp ${SRC_ROOT}/io/FileAccess.cpp @@ -233,6 +225,8 @@ set(SOURCE_FILES ${SRC_ROOT}/logging/RoutingMessageHandler.cpp ${SRC_ROOT}/logging/ExceptionMessageHandler.cpp ${SRC_ROOT}/messaging/FileMessage.cpp + ${SRC_ROOT}/visual/Transformation.cpp + ${SRC_ROOT}/visual/Trackball.cpp ) if(CMAKE_SYSTEM_NAME STREQUAL Linux) list(APPEND SOURCE_FILES ${SRC_ROOT}/system/FileMonitor_linux.cpp) @@ -261,52 +255,30 @@ if(Boost_FILESYSTEM_FOUND) list(APPEND HEADER_FILES ${SRC_ROOT}/system/FileRepository.h) list(APPEND SOURCE_FILES ${SRC_ROOT}/system/FileRepository.cpp) endif() -set(SHADER_FILES "") -if(NOT SOFA_NO_OPENGL) - list(APPEND HEADER_FILES - ${SRC_ROOT}/gl/Capture.h - ${SRC_ROOT}/gl/Color.h - ${SRC_ROOT}/gl/RAII.h - ${SRC_ROOT}/gl/template.h - ${SRC_ROOT}/system/gl.h - ${SRC_ROOT}/system/glu.h - ${SRC_ROOT}/gl/Axis.h - ${SRC_ROOT}/gl/BasicShapes.h - ${SRC_ROOT}/gl/BasicShapesGL.h - ${SRC_ROOT}/gl/BasicShapesGL.inl - ${SRC_ROOT}/gl/Cylinder.h - ${SRC_ROOT}/gl/Texture.h - ${SRC_ROOT}/gl/Trackball.h - ${SRC_ROOT}/gl/Transformation.h - ${SRC_ROOT}/gl/VideoRecorderFFMPEG.h - ${SRC_ROOT}/gl/glText.h - ${SRC_ROOT}/gl/glText.inl - ) - list(APPEND SOURCE_FILES - ${SRC_ROOT}/gl/Axis.cpp - ${SRC_ROOT}/gl/BasicShapesGL.cpp - ${SRC_ROOT}/gl/Cylinder.cpp - ${SRC_ROOT}/gl/glText.cpp - ${SRC_ROOT}/gl/Capture.cpp - ${SRC_ROOT}/gl/Texture.cpp - ${SRC_ROOT}/gl/VideoRecorderFFMPEG.cpp - ${SRC_ROOT}/gl/Color.cpp - ${SRC_ROOT}/system/gl.cpp + +# Compatibility files +set (COMPATSRC_ROOT "compat/") +set (COMPAT_HEADER_FILES + ${COMPATSRC_ROOT}/sofa/core/visual/DrawTool.h + ${COMPATSRC_ROOT}/sofa/core/visual/DrawToolGL.h + ${COMPATSRC_ROOT}/sofa/helper/system/gl.h + ${COMPATSRC_ROOT}/sofa/helper/system/glu.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Trackball.h + ${COMPATSRC_ROOT}/sofa/helper/gl/template.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Texture.h + ${COMPATSRC_ROOT}/sofa/helper/gl/FrameBufferObject.h + ${COMPATSRC_ROOT}/sofa/helper/gl/GLSLShader.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Transformation.h + ${COMPATSRC_ROOT}/sofa/helper/gl/RAII.h + ${COMPATSRC_ROOT}/sofa/helper/gl/BasicShapes.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Capture.h + ${COMPATSRC_ROOT}/sofa/helper/gl/VideoRecorderFFMPEG.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Axis.h + ${COMPATSRC_ROOT}/sofa/helper/gl/glText.h + ${COMPATSRC_ROOT}/sofa/helper/gl/glText.inl + ${COMPATSRC_ROOT}/sofa/helper/gl/Color.h + ${COMPATSRC_ROOT}/sofa/helper/gl/Cylinder.h ) - if(GLEW_FOUND) - list(APPEND HEADER_FILES - ${SRC_ROOT}/gl/FrameBufferObject.h - ${SRC_ROOT}/gl/GLSLShader.h - ) - list(APPEND SOURCE_FILES - ${SRC_ROOT}/gl/FrameBufferObject.cpp - ${SRC_ROOT}/gl/GLSLShader.cpp - ) - list(APPEND SHADER_FILES - ${SRC_ROOT}/gl/shaders/generateSphere.cppglsl - ) - endif() -endif() # Create build and install versions of etc/sofa.ini: # - In build dir, sofa.ini contains absolute paths to distant (in source) share/ and examples/ dirs @@ -320,11 +292,14 @@ configure_file("etc/sofa.ini.in" "${CMAKE_BINARY_DIR}/etc/installedSofa.ini") install(FILES "${CMAKE_BINARY_DIR}/etc/installedSofa.ini" DESTINATION etc RENAME sofa.ini COMPONENT applications) # LIBRARY -add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SHADER_FILES} ${SOURCE_FILES}) +add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${COMPAT_HEADER_FILES}) target_include_directories(${PROJECT_NAME} PUBLIC "$") target_include_directories(${PROJECT_NAME} PUBLIC "$") target_include_directories(${PROJECT_NAME} PUBLIC "$") target_include_directories(${PROJECT_NAME} PUBLIC "$") +target_include_directories(${PROJECT_NAME} PUBLIC "$") +source_group("compat" FILES ${COMPAT_HEADER_FILES} ) + if(CMAKE_SYSTEM_NAME STREQUAL Windows) target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$") endif() @@ -369,29 +344,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) target_link_libraries(${PROJECT_NAME} PRIVATE Shlwapi) endif() -# OpenGL (gl, glu) + GLEW -if(NOT SOFA_NO_OPENGL) - 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() -endif() - # Boost if(Boost_FOUND) target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost Boost::system Boost::filesystem Boost::program_options) diff --git a/SofaKernel/modules/SofaHelper/SofaHelper_test/CMakeLists.txt b/SofaKernel/modules/SofaHelper/SofaHelper_test/CMakeLists.txt index 1fb7a4b0a3f..4550794465e 100644 --- a/SofaKernel/modules/SofaHelper/SofaHelper_test/CMakeLists.txt +++ b/SofaKernel/modules/SofaHelper/SofaHelper_test/CMakeLists.txt @@ -22,12 +22,6 @@ set(SOURCE_FILES testing/TestMessageHandler_test.cpp ) -if(NOT SOFA_NO_OPENGL) - list(APPEND SOURCE_FILES - gl/GLSLShader_test.cpp - ) -endif() - add_subdirectory(system/TestPlugin) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawTool.h b/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawTool.h new file mode 100644 index 00000000000..90aa3afb00d --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawTool.h @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/helper/visual/DrawTool.h") + +namespace sofa::core::visual +{ + using DrawTool = sofa::helper::visual::DrawTool; + +} // namespace sofa::core::visual diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawToolGL.h b/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawToolGL.h new file mode 100644 index 00000000000..8422260f355 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/core/visual/DrawToolGL.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + + +#if __has_include() +#include +#define GL_DRAWTOOLGL_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/DrawToolGL.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_DRAWTOOLGL_ENABLE_WRAPPER + +namespace sofa::core::visual +{ + using DrawToolGL = sofa::gl::DrawToolGL; + +} // namespace sofa::core::visual + +#endif // GL_DRAWTOOLGL_ENABLE_WRAPPER + +#undef GL_DRAWTOOLGL_ENABLE_WRAPPER + diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Axis.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Axis.h new file mode 100644 index 00000000000..f1cb26e1a53 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Axis.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_AXIS_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/Axis.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_AXIS_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using Axis = sofa::gl::Axis; + +} // namespace sofa::helper::gl + +#endif // GL_AXIS_ENABLE_WRAPPER + +#undef GL_AXIS_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/BasicShapes.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/BasicShapes.h new file mode 100644 index 00000000000..b5399132111 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/BasicShapes.h @@ -0,0 +1,98 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_BASICSHAPES_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/BasicShapes.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_BASICSHAPES_ENABLE_WRAPPER +#include + +namespace sofa::helper::gl +{ +template +void drawCone(const V& p1, const V& p2, const float& radius1, const float& radius2, const int subd = 8) +{ + sofa::gl::drawCone(p1, p2, radius1, radius2, subd); +} + + +template +void drawCylinder(const V& p1, const V& p2, const float& rad, const int subd = 8) +{ + sofa::gl::drawCylinder(p1, p2, rad, subd); +} + + +template +void drawArrow(const V& p1, const V& p2, const float& rad, const int subd = 8) +{ + sofa::gl::drawArrow(p1, p2, rad, subd); +} + + +template +void drawSphere(const V& center, const float& rad, const int subd1 = 8, const int subd2 = 8) +{ + sofa::gl::drawSphere(center, rad, subd1, subd2); +} + +template +void drawEllipsoid(const V& center, const float& radx, const float& rady, const float& radz, const int subd1 = 8, const int subd2 = 8) +{ + sofa::gl::drawEllipsoid(center, radx, rady, subd1, subd2); +} + +template +void drawWireSphere(const V& center, const float& rad, const int subd1 = 8, const int subd2 = 8) +{ + sofa::gl::drawWireSphere(center, rad, subd1, subd2); +} + +template +void drawTorus(const float* coordinateMatrix, const float& bodyRad = 0.0, const float& rad = 1.0, const int precision = 20, + const V& color = sofa::helper::fixed_array(255, 215, 180)) +{ + sofa::gl::drawTorus(coordinateMatrix, bodyRad, rad, precision, color); +} + +template +void drawEmptyParallelepiped(const V& vert1, const V& vert2, const V& vert3, const V& vert4, const V& vecFromFaceToOppositeFace, const float& rad = 1.0, const int precision = 8, + const V& color = sofa::helper::fixed_array(255, 0, 0)) +{ + sofa::gl::drawEmptyParallelepiped(vert1, vert2, vert3, vert4, vecFromFaceToOppositeFace, rad, precision, color); +} + +} // namespace sofa::helper::gl + +#endif // GL_BASICSHAPES_ENABLE_WRAPPER + +#undef GL_BASICSHAPES_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Capture.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Capture.h new file mode 100644 index 00000000000..b2856d41f4b --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Capture.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_CAPTURE_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/Capture.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_CAPTURE_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using Capture = sofa::gl::Capture; + +} // namespace sofa::helper::gl + +#endif // GL_CAPTURE_ENABLE_WRAPPER + +#undef GL_CAPTURE_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Color.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Color.h new file mode 100644 index 00000000000..85fdd22b3d5 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Color.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_COLOR_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/Color.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_COLOR_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using Color = sofa::gl::Color; + +} // namespace sofa::helper::gl + +#endif // GL_COLOR_ENABLE_WRAPPER + +#undef GL_COLOR_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Cylinder.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Cylinder.h new file mode 100644 index 00000000000..8b836da3d71 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Cylinder.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_CYLINDER_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/Cylinder.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_CYLINDER_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using Cylinder = sofa::gl::Cylinder; + +} // namespace sofa::helper::gl + +#endif // GL_CYLINDER_ENABLE_WRAPPER + +#undef GL_CYLINDER_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/FrameBufferObject.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/FrameBufferObject.h new file mode 100644 index 00000000000..e9890b12ef0 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/FrameBufferObject.h @@ -0,0 +1,47 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_FRAMEBUFFER_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/FrameBufferObject.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_FRAMEBUFFER_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using fboParameters = sofa::gl::fboParameters; + using FrameBufferObject = sofa::gl::FrameBufferObject; + +} // namespace sofa::helper::gl + +#endif // GL_FRAMEBUFFER_ENABLE_WRAPPER + +#undef GL_FRAMEBUFFER_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/GLSLShader.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/GLSLShader.h new file mode 100644 index 00000000000..78c69afe4f4 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/GLSLShader.h @@ -0,0 +1,44 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_GLSLSHADER_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/GLSLShader.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_GLSLSHADER_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using GLSLShader = sofa::gl::GLSLShader; + +} // namespace sofa::helper::gl + +#endif // GL_AXIS_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/RAII.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/RAII.h new file mode 100644 index 00000000000..37bc68a68a4 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/RAII.h @@ -0,0 +1,51 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/RAII.h") +#define GL_RAII_ENABLE_WRAPPER + +#else +#error "OpenGL headers have been moved to Sofa.GL; you will need to link against your library if you need OpenGL, and include instead of this one." +#endif + +#ifdef GL_RAII_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + template + using Enable = sofa::gl::Enable; + + template + using Disable = sofa::gl::Disable; + + +} // namespace sofa::helper::gl + +#endif // GL_RAII_ENABLE_WRAPPER + +#undef GL_RAII_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Texture.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Texture.h new file mode 100644 index 00000000000..6aab3b191ad --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Texture.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_TEXTURE_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/Texture.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_TEXTURE_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using Texture = sofa::gl::Texture; + +} // namespace sofa::helper::gl + +#endif // GL_TEXTURE_ENABLE_WRAPPER + +#undef GL_TEXTURE_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Trackball.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Trackball.h new file mode 100644 index 00000000000..698788778b0 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Trackball.h @@ -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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/helper/visual/Trackball.h") + +namespace sofa::helper::gl +{ + using Trackball = sofa::helper::visual::Trackball; + +} // namespace sofa::helper::gl + diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Transformation.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Transformation.h new file mode 100644 index 00000000000..255db5eb6aa --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/Transformation.h @@ -0,0 +1,34 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/helper/visual/Transformation.h") + +SOFA_PRAGMA_WARNING("Transformation has been stripped of its OpenGL code, use sofa::gl::TransformationGL if you need its OpenGL implementation.") + +namespace sofa::helper::gl +{ + using Transformation = sofa::helper::visual::Transformation; + +} // namespace sofa::helper::gl diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/VideoRecorderFFMPEG.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/VideoRecorderFFMPEG.h new file mode 100644 index 00000000000..d7ee6d9f19d --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/VideoRecorderFFMPEG.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_VIDEORECORDERFFMPEG_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/VideoRecorderFFMPEG.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_VIDEORECORDERFFMPEG_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using VideoRecorderFFMPEG = sofa::gl::VideoRecorderFFMPEG; + +} // namespace sofa::helper::gl + +#endif // GL_VIDEORECORDERFFMPEG_ENABLE_WRAPPER + +#undef GL_VIDEORECORDERFFMPEG_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.h new file mode 100644 index 00000000000..6998f543144 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.h @@ -0,0 +1,44 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +#if __has_include() +#include +#define GL_GLTEXT_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/glText.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_GLTEXT_ENABLE_WRAPPER + +namespace sofa::helper::gl +{ + using GlText = sofa::gl::GlText; + +} // namespace sofa::helper::gl + +#endif // GL_GLTEXT_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.inl b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.inl new file mode 100644 index 00000000000..99f20c0c426 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/glText.inl @@ -0,0 +1,34 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include + +#if __has_include() +#include + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/glText.inl") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/template.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/template.h new file mode 100644 index 00000000000..80372826e5a --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/gl/template.h @@ -0,0 +1,322 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#if __has_include() +#include +#define GL_TEMPLATE_ENABLE_WRAPPER + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/template.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL. Therefore you will need to link against Sofa.GL if you need OpenGL (PR1649), and include instead of this one." +#endif + +#ifdef GL_TEMPLATE_ENABLE_WRAPPER +namespace sofa::helper::gl +{ + +template +inline void glVertexNv(const float* /*p*/) +{ +} + +template<> +inline void glVertexNv<3>(const float* p) +{ + sofa::gl::glVertexNv<3>(p); +} + +template<> +inline void glVertexNv<2>(const float* p) +{ + sofa::gl::glVertexNv<2>(p); +} + +template<> +inline void glVertexNv<1>(const float* p) +{ + sofa::gl::glVertexNv<1>(p); +} + +template +inline void glVertexNv(const double* p) +{ + sofa::gl::glVertexNv(p); +} + +template<> +inline void glVertexNv<2>(const double* p) +{ + sofa::gl::glVertexNv<2>(p); +} + +template<> +inline void glVertexNv<1>(const double* p) +{ + sofa::gl::glVertexNv<1>(p); +} + +template +inline void glVertexT(const Coord& c) +{ + sofa::gl::glVertexT(c); +} + +template<> +inline void glVertexT(const double& c) +{ + sofa::gl::glVertexT(c); +} + +template<> +inline void glVertexT(const float& c) +{ + sofa::gl::glVertexT(c); +} + + +//////////////////////////////////////// + +template +inline void glTexCoordNv(const float* /*p*/) +{ +} + +template<> +inline void glTexCoordNv<3>(const float* p) +{ + sofa::gl::glTexCoordNv<3>(p); +} + +template<> +inline void glTexCoordNv<2>(const float* p) +{ + sofa::gl::glTexCoordNv<2>(p); +} + +template<> +inline void glTexCoordNv<1>(const float* p) +{ + sofa::gl::glTexCoordNv<1>(p); +} + +template +inline void glTexCoordNv(const double* p) +{ + sofa::gl::glTexCoordNv(p); +} + +template<> +inline void glTexCoordNv<2>(const double* p) +{ + sofa::gl::glTexCoordNv<2>(p); +} + +template<> +inline void glTexCoordNv<1>(const double* p) +{ + sofa::gl::glTexCoordNv<1>(p); +} + +template +inline void glTexCoordT(const Coord& c) +{ + sofa::gl::glTexCoordT(c); +} + +template<> +inline void glTexCoordT(const double& c) +{ + sofa::gl::glTexCoordT(c); +} + +template<> +inline void glTexCoordT(const float& c) +{ + sofa::gl::glTexCoordT(c); +} + + + +/////////////////////////////////////// + +template +inline void glNormalNv(const float* p) +{ + sofa::gl::glNormalNv(p); +} + +template<> +inline void glNormalNv<2>(const float* p) +{ + sofa::gl::glNormalNv<2>(p); +} + +template<> +inline void glNormalNv<1>(const float* p) +{ + sofa::gl::glNormalNv<1>(p); +} + +template +inline void glNormalNv(const double* p) +{ + sofa::gl::glNormalNv(p); +} + +template<> +inline void glNormalNv<2>(const double* p) +{ + sofa::gl::glNormalNv<2>(p); +} + +template<> +inline void glNormalNv<1>(const double* p) +{ + sofa::gl::glNormalNv<1>(p); +} + +template +inline void glNormalT(const Coord& c) +{ + sofa::gl::glNormalNv(c.ptr()); +} + +template<> +inline void glNormalT(const double& c) +{ + sofa::gl::glNormalT(c); +} + +template<> +inline void glNormalT(const float& c) +{ + sofa::gl::glNormalT(c); +} +//////// +inline void glTranslate(const float& c1, const float& c2, const float& c3) +{ + sofa::gl::glTranslate(c1, c2, c3); +} + +inline void glTranslate(const double& c1, const double& c2, const double& c3) +{ + sofa::gl::glTranslate(c1, c2, c3); +} + +template +inline void glTranslateNv(const float* p) +{ + sofa::gl::glTranslateNv(p); +} + +template<> +inline void glTranslateNv<2>(const float* p) +{ + sofa::gl::glTranslateNv<2>(p); +} + +template<> +inline void glTranslateNv<1>(const float* p) +{ + sofa::gl::glTranslateNv<1>(p); +} + +template +inline void glTranslateNv(const double* p) +{ + sofa::gl::glTranslateNv(p); +} + +template<> +inline void glTranslateNv<2>(const double* p) +{ + sofa::gl::glTranslateNv<2>(p); +} + +template<> +inline void glTranslateNv<1>(const double* p) +{ + sofa::gl::glTranslateNv<1>(p); +} + +template +inline void glTranslateT(const Coord& c) +{ + sofa::gl::glTranslateT(c); +} + +template<> +inline void glTranslateT(const double& c) +{ + sofa::gl::glTranslateT(c); +} + +template<> +inline void glTranslateT(const float& c) +{ + sofa::gl::glTranslateT(c); +} + + +//////////// + + + + +inline void glScale(const float& c1, const float& c2, const float& c3) +{ + sofa::gl::glScale(c1, c2, c3); +} + +inline void glScale(const double& c1, const double& c2, const double& c3) +{ + sofa::gl::glScale(c1, c2, c3); +} + +inline void glRotate(const GLfloat &value, const float& c1, const float& c2, const float& c3) +{ + sofa::gl::glRotate(value, c1, c2, c3); +} + +inline void glRotate(const GLdouble &value, const double& c1, const double& c2, const double& c3) +{ + sofa::gl::glRotate(value, c1, c2, c3); +} + +inline void glMultMatrix(const float* p) +{ + sofa::gl::glMultMatrix(p); +} + +inline void glMultMatrix(const double* p) +{ + sofa::gl::glMultMatrix(p); +} + +} + +#endif // GL_TEMPLATE_ENABLE_WRAPPER + +#undef GL_TEMPLATE_ENABLE_WRAPPER diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/system/gl.h similarity index 85% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.h rename to SofaKernel/modules/SofaHelper/compat/sofa/helper/system/gl.h index 0e96d6be1cf..91b3a0ea294 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/gl.h +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/system/gl.h @@ -19,21 +19,14 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_SYSTEM_GL_H -#define SOFA_HELPER_SYSTEM_GL_H - +#pragma once #include -#ifndef SOFA_NO_OPENGL - -#include - -# include - -extern SOFA_HELPER_API const char* GetGlExtensionsList(); - -extern SOFA_HELPER_API bool CanUseGlExtension(const std::string& ext); +#if __has_include() +#include -#endif // SOFA_NO_OPENGL +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/gl.h") -#endif +#else +#error "OpenGL headers have been moved to Sofa.GL; you will need to link against your library if you need OpenGL, and include instead of this one." +#endif \ No newline at end of file diff --git a/SofaKernel/modules/SofaHelper/compat/sofa/helper/system/glu.h b/SofaKernel/modules/SofaHelper/compat/sofa/helper/system/glu.h new file mode 100644 index 00000000000..1f229766395 --- /dev/null +++ b/SofaKernel/modules/SofaHelper/compat/sofa/helper/system/glu.h @@ -0,0 +1,32 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once +#include + +#if __has_include() +#include + +SOFA_DEPRECATED_HEADER(v21.06, "sofa/gl/glu.h") + +#else +#error "OpenGL headers have been moved to Sofa.GL; you will need to link against your library if you need OpenGL, and include instead of this one." +#endif \ No newline at end of file diff --git a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawTool.h b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/DrawTool.h similarity index 98% rename from SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawTool.h rename to SofaKernel/modules/SofaHelper/src/sofa/helper/visual/DrawTool.h index 093693a42fd..b18a15a3378 100644 --- a/SofaKernel/modules/SofaCore/src/sofa/core/visual/DrawTool.h +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/DrawTool.h @@ -19,19 +19,14 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_DRAWTOOL_H -#define SOFA_HELPER_GL_DRAWTOOL_H +#pragma once #include #include #include -namespace sofa -{ -namespace core -{ -namespace visual +namespace sofa::helper::visual { /** @@ -43,7 +38,7 @@ namespace visual * */ -class SOFA_CORE_API DrawTool +class DrawTool { public: @@ -590,10 +585,4 @@ class SOFA_CORE_API DrawTool }; -} // namespace visual - -} // namespace core - -} // namespace sofa - -#endif //SOFA_CORE_VISUAL_DRAWTOOL_H +} // namespace sofa::helper::visual diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.cpp b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.cpp similarity index 97% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.cpp rename to SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.cpp index ba186eb2db1..98f2ec3aaab 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.cpp +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.cpp @@ -68,16 +68,10 @@ * June 1998 */ -#include +#include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::helper::visual { using namespace sofa::defaulttype; @@ -202,9 +196,4 @@ static double tb_project_to_sphere(double r, double x, double y) return z; } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::helper::visual diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.h b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.h similarity index 96% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.h rename to SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.h index 2e97613bf9f..6a5e162aa76 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Trackball.h +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Trackball.h @@ -69,20 +69,12 @@ * first paramater. */ -#ifndef SOFA_HELPER_GL_TRACKBALL_H -#define SOFA_HELPER_GL_TRACKBALL_H - +#pragma once #include #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::helper::visual { class SOFA_HELPER_API Trackball @@ -112,10 +104,4 @@ class SOFA_HELPER_API Trackball sofa::defaulttype::Quaternion _quat; }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif +} // namespace sofa::helper::visual diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.cpp b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.cpp similarity index 72% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.cpp rename to SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.cpp index c0bea014876..deeb4b4afdd 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.cpp +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.cpp @@ -19,17 +19,9 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include -#include -#include +#include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::helper::visual { // -------------------------------------------------------------------------------------- @@ -94,49 +86,6 @@ Transformation& Transformation::operator=(const Transformation& transform) } -// -------------------------------------------------------------------------------------- -// --- Apply the transformation -// -------------------------------------------------------------------------------------- -void Transformation::Apply() -{ -#ifndef SOFA_NO_OPENGL - helper::gl::glTranslate(translation[0], translation[1], translation[2]); - helper::gl::glMultMatrix((SReal *)rotation); - helper::gl::glScale(scale[0], scale[1], scale[2]); -#endif /* SOFA_NO_OPENGL */ -} - - -// -------------------------------------------------------------------------------------- -// --- First center the object, then apply the transformation (to align with the corresponding texture) -// -------------------------------------------------------------------------------------- -void Transformation::ApplyWithCentring() -{ - Apply(); - -#ifndef SOFA_NO_OPENGL - helper::gl::glTranslate(-objectCenter[0], -objectCenter[1], -objectCenter[2]); -#endif /* SOFA_NO_OPENGL */ -} - - -// -------------------------------------------------------------------------------------- -// --- Apply the inverse transformation -// -------------------------------------------------------------------------------------- -void Transformation::ApplyInverse() -{ - SReal iRotation[4][4]; - - InvertTransRotMatrix(rotation, iRotation); - -#ifndef SOFA_NO_OPENGL - helper::gl::glScale((SReal)1.0 / scale[0], (SReal)1.0 / scale[1], (SReal)1.0 / scale[2]); - helper::gl::glMultMatrix((SReal *)rotation); - helper::gl::glTranslate(-translation[0], -translation[1], -translation[2]); -#endif /* SOFA_NO_OPENGL */ -} - - //---------------------------------------------------------------------------- //--- Inversion for 4x4 matrix only containing rotations and translations //--- Transpose rotation matrix and mutiple by -1 translation row @@ -183,9 +132,4 @@ void Transformation::InvertTransRotMatrix(SReal sMatrix[4][4], InvertTransRotMatrix(dMatrix); } -} // namespace gl - -} // namespace helper - -} // namespace sofa - +} // namespace sofa::helper::visual diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.h b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.h similarity index 86% rename from SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.h rename to SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.h index 0cf0c8f8921..962e914ffc3 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/gl/Transformation.h +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/visual/Transformation.h @@ -19,18 +19,10 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_HELPER_GL_TRANSFORMATION_H -#define SOFA_HELPER_GL_TRANSFORMATION_H - +#pragma once #include -namespace sofa -{ - -namespace helper -{ - -namespace gl +namespace sofa::helper::visual { class SOFA_HELPER_API Transformation @@ -42,14 +34,15 @@ class SOFA_HELPER_API Transformation SReal objectCenter[3]; public: - Transformation(); // constructor - ~Transformation(); // destructor + Transformation(); + virtual ~Transformation(); Transformation(const Transformation & other); + Transformation& operator=(const Transformation& transform); - void Apply(); - void ApplyWithCentring(); - void ApplyInverse(); + virtual void Apply() {}; + virtual void ApplyWithCentring() {}; + virtual void ApplyInverse() {}; template Vector operator*(Vector v) const @@ -64,16 +57,10 @@ class SOFA_HELPER_API Transformation return r; } -private: +protected: void InvertTransRotMatrix(SReal matrix[4][4]); void InvertTransRotMatrix(SReal sMatrix[4][4], SReal dMatrix[4][4]); }; -} // namespace gl - -} // namespace helper - -} // namespace sofa - -#endif // __TRANSFORMATION_H__ +} // namespace sofa::helper::visual diff --git a/applications/plugins/InvertibleFVM/ExternalProjectConfig.cmake.in b/applications/plugins/InvertibleFVM/ExternalProjectConfig.cmake.in index 12d4d8936ab..f8928ed5806 100644 --- a/applications/plugins/InvertibleFVM/ExternalProjectConfig.cmake.in +++ b/applications/plugins/InvertibleFVM/ExternalProjectConfig.cmake.in @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.2) include(ExternalProject) ExternalProject_Add(InvertibleFVM GIT_REPOSITORY https://github.com/sofa-framework/InvertibleFVM - GIT_TAG origin/master + GIT_TAG origin/follow_sofa_pr1649 SOURCE_DIR "${CMAKE_SOURCE_DIR}/applications/plugins/InvertibleFVM" BINARY_DIR "" CONFIGURE_COMMAND "" diff --git a/applications/plugins/OptiTrackNatNet/CMakeLists.txt b/applications/plugins/OptiTrackNatNet/CMakeLists.txt index 279d02161c8..de0e46c3209 100644 --- a/applications/plugins/OptiTrackNatNet/CMakeLists.txt +++ b/applications/plugins/OptiTrackNatNet/CMakeLists.txt @@ -15,11 +15,12 @@ set(SOURCE_FILES ) find_package(SofaGeneral REQUIRED) +find_package(Sofa.GL REQUIRED) find_package(Boost QUIET COMPONENTS system regex date_time REQUIRED) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_OPTITRACKNATNET") -target_link_libraries(${PROJECT_NAME} SofaCore SofaSimulationCommon SofaUserInteraction) +target_link_libraries(${PROJECT_NAME} SofaCore SofaSimulationCommon SofaUserInteraction Sofa.GL) target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES}) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") diff --git a/applications/plugins/SofaDistanceGrid/CMakeLists.txt b/applications/plugins/SofaDistanceGrid/CMakeLists.txt index 4cb28f89767..aaa1cccfb8c 100644 --- a/applications/plugins/SofaDistanceGrid/CMakeLists.txt +++ b/applications/plugins/SofaDistanceGrid/CMakeLists.txt @@ -57,10 +57,11 @@ sofa_find_package(MiniFlowVR QUIET) find_package(SofaMeshCollision REQUIRED) find_package(SofaUserInteraction REQUIRED) find_package(SofaMiscCollision REQUIRED) +find_package(Sofa.GL REQUIRED) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC SofaMeshCollision SofaMiscCollision) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaUserInteraction) +target_link_libraries(${PROJECT_NAME} PUBLIC SofaUserInteraction Sofa.GL) if(MiniFlowVR_FOUND) target_link_libraries(${PROJECT_NAME} PRIVATE miniFlowVR) # Private because not exported in API diff --git a/applications/plugins/SofaDistanceGrid/SofaDistanceGridConfig.cmake.in b/applications/plugins/SofaDistanceGrid/SofaDistanceGridConfig.cmake.in index 24ee372c4c7..38b029a8fa5 100644 --- a/applications/plugins/SofaDistanceGrid/SofaDistanceGridConfig.cmake.in +++ b/applications/plugins/SofaDistanceGrid/SofaDistanceGridConfig.cmake.in @@ -7,6 +7,7 @@ find_package(SofaFramework QUIET REQUIRED) find_package(SofaMeshCollision QUIET REQUIRED) find_package(SofaUserInteraction QUIET REQUIRED) find_package(SofaMiscCollision QUIET REQUIRED) +find_package(Sofa.GL QUIET REQUIRED) set(SOFADISTANCEGRID_HAVE_MINIFLOWVR @SOFADISTANCEGRID_HAVE_MINIFLOWVR@) diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/DistanceGrid.cpp b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/DistanceGrid.cpp index 2cafb3657b1..875263f97fe 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/DistanceGrid.cpp +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/DistanceGrid.cpp @@ -23,8 +23,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp index 9f3ce4041de..897f691c9f4 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/collision/DistanceGridCollisionModel.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl index 8141032c1b6..013f5feb004 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl @@ -26,7 +26,7 @@ #include #include "DistanceGridForceField.h" #include -#include +#include #include #include diff --git a/applications/plugins/SofaEulerianFluid/CMakeLists.txt b/applications/plugins/SofaEulerianFluid/CMakeLists.txt index b3555fc3b68..8a422706d58 100644 --- a/applications/plugins/SofaEulerianFluid/CMakeLists.txt +++ b/applications/plugins/SofaEulerianFluid/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.12) project(SofaEulerianFluid VERSION 1.0) +find_package(SofaFramework REQUIRED) +find_package(Sofa.GL REQUIRED) + set(HEADER_FILES Fluid2D.h Fluid3D.h @@ -23,7 +26,7 @@ set(EXTRA_FILES ) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) -target_link_libraries(${PROJECT_NAME} SofaCore) +target_link_libraries(${PROJECT_NAME} SofaCore Sofa.GL) # # ## Install rules for the library and headers; CMake package configurations files diff --git a/applications/plugins/SofaEulerianFluid/SofaEulerianFluidConfig.cmake.in b/applications/plugins/SofaEulerianFluid/SofaEulerianFluidConfig.cmake.in index b78650f5c78..d53c1627315 100644 --- a/applications/plugins/SofaEulerianFluid/SofaEulerianFluidConfig.cmake.in +++ b/applications/plugins/SofaEulerianFluid/SofaEulerianFluidConfig.cmake.in @@ -1,9 +1,10 @@ -# CMake package configuration file for the SofaMiscCollision plugin +# CMake package configuration file for the SofaEulerianFluid plugin @PACKAGE_GUARD@ @PACKAGE_INIT@ find_package(SofaFramework REQUIRED) +find_package(Sofa.GL REQUIRED) if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/applications/plugins/SofaMiscCollision/src/SofaMiscCollision/TetrahedronModel.cpp b/applications/plugins/SofaMiscCollision/src/SofaMiscCollision/TetrahedronModel.cpp index c3657d3ebeb..3c9263d5d38 100644 --- a/applications/plugins/SofaMiscCollision/src/SofaMiscCollision/TetrahedronModel.cpp +++ b/applications/plugins/SofaMiscCollision/src/SofaMiscCollision/TetrahedronModel.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/applications/plugins/SofaOpenCL/CMakeLists.txt b/applications/plugins/SofaOpenCL/CMakeLists.txt index ff1582cd92d..02dda178d0e 100644 --- a/applications/plugins/SofaOpenCL/CMakeLists.txt +++ b/applications/plugins/SofaOpenCL/CMakeLists.txt @@ -7,6 +7,7 @@ find_package(OpenCL REQUIRED) find_package(SofaGeneralObjectInteraction REQUIRED) find_package(SofaGeneralDeformable REQUIRED) find_package(SofaUserInteraction REQUIRED) +find_package(Sofa.GL REQUIRED) sofa_find_package(SofaSphFluid QUIET) set(HEADER_FILES @@ -105,7 +106,7 @@ add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${OTHER_FILES add_definitions("-DSOFA_SRC_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/../../..\"") add_definitions("-DSOFA_BUILD_GPU_OPENCL") -target_link_libraries(${PROJECT_NAME} ${OPENCL_LIBRARIES} SofaHelper SofaEngine SofaUserInteraction csparse SofaGeneralObjectInteraction SofaGeneralDeformable) # taucs taucs_mt system-taucs) +target_link_libraries(${PROJECT_NAME} ${OPENCL_LIBRARIES} SofaHelper SofaEngine SofaUserInteraction csparse SofaGeneralObjectInteraction SofaGeneralDeformable Sofa.GL) # taucs taucs_mt system-taucs) if(SofaSphFluid_FOUND) target_link_libraries(${PROJECT_NAME} SofaSphFluid) # taucs taucs_mt system-taucs) endif() diff --git a/applications/plugins/image/CMakeLists.txt b/applications/plugins/image/CMakeLists.txt index 6b7e2ac1df0..9139effef21 100644 --- a/applications/plugins/image/CMakeLists.txt +++ b/applications/plugins/image/CMakeLists.txt @@ -3,8 +3,8 @@ project(image VERSION 0.1) find_package(SofaBase REQUIRED) find_package(SofaGeneralVisual REQUIRED) +find_package(Sofa.GL REQUIRED) -sofa_find_package(OpenGL QUIET) sofa_find_package(SofaGui QUIET) sofa_find_package(CImgPlugin REQUIRED) sofa_find_package(Newmat REQUIRED) @@ -41,6 +41,8 @@ set(SOURCE_FILES MeshToImageEngine.cpp TransferFunction.cpp VoronoiToMeshEngine.cpp + DepthMapToMeshEngine.cpp + ImageViewer.cpp initImage.cpp ) set(HEADER_FILES @@ -68,20 +70,13 @@ set(HEADER_FILES TransferFunction.h VectorVis.h VoronoiToMeshEngine.h + DepthMapToMeshEngine.h + ImageViewer.h ) set(README_FILES image.txt ) - -if(OpenGL_FOUND) - list(APPEND SOURCE_FILES DepthMapToMeshEngine.cpp) - list(APPEND HEADER_FILES DepthMapToMeshEngine.h) -else() - message(STATUS "image: could not find OpenGL library, won't build the DepthMapToMeshEngine") -endif() - - if(SofaPython_FOUND) set(PYTHON_FILES python/SofaImage/API.py @@ -94,10 +89,7 @@ if(SofaPython_FOUND) sofa_install_pythonscripts(PLUGIN_NAME ${PROJECT_NAME} PYTHONSCRIPTS_SOURCE_DIR "python") endif() -if(NOT ${SOFA_NO_OPENGL}) - list(APPEND HEADER_FILES ImageViewer.h) - list(APPEND SOURCE_FILES ImageViewer.cpp) - +if(Sofa.GL_FOUND) if(FREENECT_FOUND) list(APPEND HEADER_FILES Kinect.h) list(APPEND SOURCE_FILES Kinect.cpp) @@ -125,7 +117,7 @@ endif() add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${README_FILES} ${PYTHON_FILES}) target_compile_definitions(${PROJECT_NAME} PRIVATE "-DSOFA_BUILD_IMAGE") -target_link_libraries(${PROJECT_NAME} SofaCore SofaBase SofaGeneralVisual CImgPlugin) +target_link_libraries(${PROJECT_NAME} SofaCore SofaBase Sofa.GL SofaGeneralVisual CImgPlugin) target_link_libraries(${PROJECT_NAME} DiffusionSolver) target_link_libraries(${PROJECT_NAME} newmat) diff --git a/modules/SofaGeneralAnimationLoop/src/SofaGeneralAnimationLoop/MechanicalMatrixMapper.inl b/modules/SofaGeneralAnimationLoop/src/SofaGeneralAnimationLoop/MechanicalMatrixMapper.inl index ab110714fd8..7009be18561 100644 --- a/modules/SofaGeneralAnimationLoop/src/SofaGeneralAnimationLoop/MechanicalMatrixMapper.inl +++ b/modules/SofaGeneralAnimationLoop/src/SofaGeneralAnimationLoop/MechanicalMatrixMapper.inl @@ -23,7 +23,6 @@ #include "MechanicalMatrixMapper.h" #include -#include #include // accumulate jacobian diff --git a/modules/SofaGeneralDeformable/src/SofaGeneralDeformable/VectorSpringForceField.inl b/modules/SofaGeneralDeformable/src/SofaGeneralDeformable/VectorSpringForceField.inl index 136ebe00151..e75ab01f47e 100644 --- a/modules/SofaGeneralDeformable/src/SofaGeneralDeformable/VectorSpringForceField.inl +++ b/modules/SofaGeneralDeformable/src/SofaGeneralDeformable/VectorSpringForceField.inl @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/modules/SofaGeneralEngine/CMakeLists.txt b/modules/SofaGeneralEngine/CMakeLists.txt index fd1ae820e7f..68ef0e31186 100644 --- a/modules/SofaGeneralEngine/CMakeLists.txt +++ b/modules/SofaGeneralEngine/CMakeLists.txt @@ -111,8 +111,6 @@ list(APPEND HEADER_FILES ${SOFAGENERALENGINE_SRC}/SubsetTopology.inl ${SOFAGENERALENGINE_SRC}/SumEngine.h ${SOFAGENERALENGINE_SRC}/SumEngine.inl - ${SOFAGENERALENGINE_SRC}/TextureInterpolation.h - ${SOFAGENERALENGINE_SRC}/TextureInterpolation.inl ${SOFAGENERALENGINE_SRC}/TransformEngine.h ${SOFAGENERALENGINE_SRC}/TransformEngine.inl ${SOFAGENERALENGINE_SRC}/TransformMatrixEngine.h @@ -177,7 +175,6 @@ list(APPEND SOURCE_FILES ${SOFAGENERALENGINE_SRC}/Spiral.cpp ${SOFAGENERALENGINE_SRC}/SubsetTopology.cpp ${SOFAGENERALENGINE_SRC}/SumEngine.cpp - ${SOFAGENERALENGINE_SRC}/TextureInterpolation.cpp ${SOFAGENERALENGINE_SRC}/TransformEngine.cpp ${SOFAGENERALENGINE_SRC}/TransformMatrixEngine.cpp ${SOFAGENERALENGINE_SRC}/TransformPosition.cpp @@ -188,9 +185,26 @@ list(APPEND SOURCE_FILES find_package(SofaMeshCollision REQUIRED) find_package(SofaGeneralMeshCollision REQUIRED) +sofa_find_package(Sofa.GL QUIET) + +if(Sofa.GL_FOUND) + list(APPEND HEADER_FILES + ${SOFAGENERALENGINE_SRC}/TextureInterpolation.h + ${SOFAGENERALENGINE_SRC}/TextureInterpolation.inl + ) + list(APPEND SOURCE_FILES + ${SOFAGENERALENGINE_SRC}/TextureInterpolation.cpp + ) +endif() + + add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaMeshCollision SofaGeneralMeshCollision) +target_link_libraries(${PROJECT_NAME} PUBLIC SofaMeshCollision SofaGeneralMeshCollision) + +if(Sofa.GL_FOUND) + target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.GL) # Needs OpenGL for TextureInterpolation +endif() if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # Silence attribute warnings (for example, ignored already defined external template) diff --git a/modules/SofaGeneralEngine/SofaGeneralEngineConfig.cmake.in b/modules/SofaGeneralEngine/SofaGeneralEngineConfig.cmake.in index 391f51b48f5..5a5fcd4a777 100644 --- a/modules/SofaGeneralEngine/SofaGeneralEngineConfig.cmake.in +++ b/modules/SofaGeneralEngine/SofaGeneralEngineConfig.cmake.in @@ -3,9 +3,15 @@ @PACKAGE_GUARD@ @PACKAGE_INIT@ +set(SOFAGENERALENGINE_HAVE_SOFA.GL @SOFAGENERALENGINE_HAVE_SOFA.GL@) + find_package(SofaMeshCollision QUIET REQUIRED) find_package(SofaGeneralMeshCollision QUIET REQUIRED) +if(SOFAGENERALENGINE_HAVE_SOFA.GL) + find_package(Sofa.GL QUIET REQUIRED) +endif() + if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") endif() diff --git a/modules/SofaGeneralEngine/src/SofaGeneralEngine/TextureInterpolation.inl b/modules/SofaGeneralEngine/src/SofaGeneralEngine/TextureInterpolation.inl index d0393b3697a..83199077a3f 100644 --- a/modules/SofaGeneralEngine/src/SofaGeneralEngine/TextureInterpolation.inl +++ b/modules/SofaGeneralEngine/src/SofaGeneralEngine/TextureInterpolation.inl @@ -22,9 +22,9 @@ #pragma once #include #include -#include #include #include +#include namespace sofa::component::engine { @@ -242,7 +242,6 @@ void TextureInterpolation::standardLinearInterpolation() template void TextureInterpolation::draw(const core::visual::VisualParams* vparams ) { -#ifndef SOFA_NO_OPENGL // to force update. getX() must have call to endEdit() _outputCoord.getValue(); @@ -310,7 +309,6 @@ void TextureInterpolation::draw(const core::visual::VisualParams* vpa } } -#endif /* SOFA_NO_OPENGL */ } diff --git a/modules/SofaGeneralSimpleFem/src/SofaGeneralSimpleFem/BeamFEMForceField.inl b/modules/SofaGeneralSimpleFem/src/SofaGeneralSimpleFem/BeamFEMForceField.inl index f0405ddfbb2..87013eff02c 100644 --- a/modules/SofaGeneralSimpleFem/src/SofaGeneralSimpleFem/BeamFEMForceField.inl +++ b/modules/SofaGeneralSimpleFem/src/SofaGeneralSimpleFem/BeamFEMForceField.inl @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/modules/SofaGeneralVisual/CMakeLists.txt b/modules/SofaGeneralVisual/CMakeLists.txt index 4503174d9c4..89614166bd3 100644 --- a/modules/SofaGeneralVisual/CMakeLists.txt +++ b/modules/SofaGeneralVisual/CMakeLists.txt @@ -8,18 +8,13 @@ set(SOFAGENERALVISUAL_SRC "src/${PROJECT_NAME}") set(HEADER_FILES ${SOFAGENERALVISUAL_SRC}/config.h.in ${SOFAGENERALVISUAL_SRC}/initSofaGeneralVisual.h - ) - -set(SOURCE_FILES - ${SOFAGENERALVISUAL_SRC}/initSofaGeneralVisual.cpp - ) - -list(APPEND HEADER_FILES ${SOFAGENERALVISUAL_SRC}/RecordedCamera.h ${SOFAGENERALVISUAL_SRC}/VisualTransform.h ${SOFAGENERALVISUAL_SRC}/Visual3DText.h ) -list(APPEND SOURCE_FILES + +set(SOURCE_FILES + ${SOFAGENERALVISUAL_SRC}/initSofaGeneralVisual.cpp ${SOFAGENERALVISUAL_SRC}/RecordedCamera.cpp ${SOFAGENERALVISUAL_SRC}/VisualTransform.cpp ${SOFAGENERALVISUAL_SRC}/Visual3DText.cpp diff --git a/modules/SofaGeneralVisual/SofaGeneralVisualConfig.cmake.in b/modules/SofaGeneralVisual/SofaGeneralVisualConfig.cmake.in index cb715e6af5d..2c3891d84d1 100644 --- a/modules/SofaGeneralVisual/SofaGeneralVisualConfig.cmake.in +++ b/modules/SofaGeneralVisual/SofaGeneralVisualConfig.cmake.in @@ -3,8 +3,14 @@ @PACKAGE_GUARD@ @PACKAGE_INIT@ +set(SOFAGENERALVISUAL_HAVE_SOFA.GL @SOFAGENERALVISUAL_HAVE_SOFA.GL@) + find_package(SofaBase QUIET REQUIRED) +if(SOFAGENERALVISUAL_HAVE_SOFA.GL) + find_package(Sofa.GL QUIET REQUIRED) +endif() + if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") endif() diff --git a/modules/SofaGeneralVisual/src/SofaGeneralVisual/Visual3DText.cpp b/modules/SofaGeneralVisual/src/SofaGeneralVisual/Visual3DText.cpp index 8abe5bbb6a0..9b8dc079ad8 100644 --- a/modules/SofaGeneralVisual/src/SofaGeneralVisual/Visual3DText.cpp +++ b/modules/SofaGeneralVisual/src/SofaGeneralVisual/Visual3DText.cpp @@ -25,7 +25,6 @@ #include #include #include -#include namespace sofa::component::visualmodel @@ -62,28 +61,21 @@ void Visual3DText::reinit() void Visual3DText::drawTransparent(const core::visual::VisualParams* vparams) { -#ifndef SOFA_NO_OPENGL if(!vparams->displayFlags().getShowVisualModels()) return; const defaulttype::Vec3f& pos = d_position.getValue(); float scale = d_scale.getValue(); const bool& depthTest = d_depthTest.getValue(); - if( !depthTest ) - { - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_DEPTH_TEST); - } + vparams->drawTool()->saveLastState(); - vparams->drawTool()->setLightingEnabled(true); + vparams->drawTool()->disableDepthTest(); + vparams->drawTool()->setLightingEnabled(true); vparams->drawTool()->draw3DText(pos,scale,d_color.getValue(),d_text.getValue().c_str()); - - if( !depthTest ) - glPopAttrib(); -#endif /* SOFA_NO_OPENGL */ + vparams->drawTool()->restoreLastState(); } } // namespace sofa::component::visualmodel diff --git a/modules/SofaGuiCommon/CMakeLists.txt b/modules/SofaGuiCommon/CMakeLists.txt index a703f8ddb00..fa61aaf4184 100644 --- a/modules/SofaGuiCommon/CMakeLists.txt +++ b/modules/SofaGuiCommon/CMakeLists.txt @@ -4,12 +4,12 @@ project(SofaGuiCommon) find_package(SofaBase REQUIRED) find_package(SofaUserInteraction REQUIRED) find_package(SofaGraphComponent REQUIRED) - +sofa_find_package(Sofa.GL) # ColourPickingVisitor set(SRC_ROOT src/sofa/gui) set(HEADER_FILES - ${SRC_ROOT}/config.h + ${SRC_ROOT}/config.h.in ${SRC_ROOT}/BaseGUI.h ${SRC_ROOT}/BaseViewer.h ${SRC_ROOT}/BatchGUI.h @@ -39,6 +39,9 @@ set(SOURCE_FILES add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES}) target_link_libraries(${PROJECT_NAME} PUBLIC SofaBase SofaGraphComponent SofaUserInteraction) +if(Sofa.GL_FOUND) + target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.GL) +endif() if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # Silence attribute warnings (for example, ignored already defined external template) diff --git a/modules/SofaGuiCommon/src/sofa/gui/ColourPickingVisitor.cpp b/modules/SofaGuiCommon/src/sofa/gui/ColourPickingVisitor.cpp index 8e1a3ebb48b..43befa320de 100644 --- a/modules/SofaGuiCommon/src/sofa/gui/ColourPickingVisitor.cpp +++ b/modules/SofaGuiCommon/src/sofa/gui/ColourPickingVisitor.cpp @@ -106,7 +106,7 @@ void ColourPickingVisitor::processCollisionModel(simulation::Node* node , core: void ColourPickingVisitor::processTriangleModel(simulation::Node * node, sofa::component::collision::TriangleCollisionModel * tmodel) { -#ifndef SOFA_NO_OPENGL +#ifdef SOFAGUICOMMON_HAVE_SOFA_GL using namespace sofa::core::collision; using namespace sofa::defaulttype; glDisable(GL_LIGHTING); @@ -162,12 +162,12 @@ void ColourPickingVisitor::processTriangleModel(simulation::Node * node, sofa::c default: assert(false); } vparams->drawTool()->drawTriangles(points,normals,colours); -#endif /* SOFA_NO_OPENGL */ +#endif // SOFAGUICOMMON_HAVE_SOFA_GL } void ColourPickingVisitor::processSphereModel(simulation::Node * node, sofa::component::collision::SphereCollisionModel * smodel) { -#ifndef SOFA_NO_OPENGL +#ifdef SOFAGUICOMMON_HAVE_SOFA_GL typedef Sphere::Coord Coord; if( method == ENCODE_RELATIVEPOSITION ) return; // we pick the center of the sphere. @@ -208,7 +208,7 @@ void ColourPickingVisitor::processSphereModel(simulation::Node * node, sofa::com glPopMatrix(); } -#endif /* SOFA_NO_OPENGL */ +#endif // SOFAGUICOMMON_HAVE_SOFA_GL } diff --git a/modules/SofaGuiCommon/src/sofa/gui/config.h b/modules/SofaGuiCommon/src/sofa/gui/config.h.in similarity index 92% rename from modules/SofaGuiCommon/src/sofa/gui/config.h rename to modules/SofaGuiCommon/src/sofa/gui/config.h.in index 21d693a02c3..b1109e68a5a 100644 --- a/modules/SofaGuiCommon/src/sofa/gui/config.h +++ b/modules/SofaGuiCommon/src/sofa/gui/config.h.in @@ -19,16 +19,17 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#ifndef SOFA_GUI_CONFIG_H -#define SOFA_GUI_CONFIG_H +#pragma once #include +#define SOFAGUICOMMON_HAVE_SOFA_GL @SOFAGUICOMMON_HAVE_SOFA.GL@ + +#define SOFAGUICOMMON_VERSION @PROJECT_VERSION@ + #ifdef SOFA_BUILD_SOFAGUICOMMON -# define SOFA_TARGET SofaGuiCommon +# define SOFA_TARGET @PROJECT_NAME@ # define SOFA_SOFAGUICOMMON_API SOFA_EXPORT_DYNAMIC_LIBRARY #else # define SOFA_SOFAGUICOMMON_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif - -#endif diff --git a/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.cpp b/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.cpp index 6778d85661a..1cb0327b9cb 100644 --- a/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.cpp +++ b/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.cpp @@ -21,6 +21,7 @@ ******************************************************************************/ #include +#include #include namespace sofa diff --git a/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.h b/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.h index 9bb918a9a71..7b21ba7f667 100644 --- a/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.h +++ b/modules/SofaGuiQt/src/sofa/gui/qt/viewer/OglModelPolicy.h @@ -27,6 +27,8 @@ #include #include +#include + namespace sofa { namespace gui @@ -40,7 +42,7 @@ class SOFA_SOFAGUIQT_API OglModelPolicy : public VisualModelPolicy { protected: sofa::core::ObjectFactory::ClassEntry::SPtr classVisualModel; - std::unique_ptr drawTool; + std::unique_ptr drawTool; public: void load() override; void unload() override; diff --git a/modules/SofaMiscMapping/src/SofaMiscMapping/DistanceMapping.inl b/modules/SofaMiscMapping/src/SofaMiscMapping/DistanceMapping.inl index 34e7f48e265..3828a70ad49 100644 --- a/modules/SofaMiscMapping/src/SofaMiscMapping/DistanceMapping.inl +++ b/modules/SofaMiscMapping/src/SofaMiscMapping/DistanceMapping.inl @@ -23,7 +23,6 @@ #include "DistanceMapping.h" #include -#include #include #include #include diff --git a/modules/SofaMiscMapping/src/SofaMiscMapping/SquareDistanceMapping.inl b/modules/SofaMiscMapping/src/SofaMiscMapping/SquareDistanceMapping.inl index 6814a9e99c4..66dd1ca2aec 100644 --- a/modules/SofaMiscMapping/src/SofaMiscMapping/SquareDistanceMapping.inl +++ b/modules/SofaMiscMapping/src/SofaMiscMapping/SquareDistanceMapping.inl @@ -23,7 +23,6 @@ #include "SquareDistanceMapping.h" #include -#include #include #include diff --git a/modules/SofaOpenglVisual/CMakeLists.txt b/modules/SofaOpenglVisual/CMakeLists.txt index 9238187a9a8..bae1b41416a 100644 --- a/modules/SofaOpenglVisual/CMakeLists.txt +++ b/modules/SofaOpenglVisual/CMakeLists.txt @@ -1,12 +1,13 @@ cmake_minimum_required(VERSION 3.12) project(SofaOpenglVisual LANGUAGES CXX) -if(SOFA_NO_OPENGL) - message(FATAL_ERROR "SOFA_NO_OPENGL flag prevents from using the SofaOpenglVisual plugin") -endif() - find_package(SofaBase REQUIRED) find_package(SofaSimulation REQUIRED) +find_package(Sofa.GL REQUIRED) + +if(NOT Sofa.GL_FOUND) + message(FATAL_ERROR "Sofa.GL not enabled, cannot build the SofaOpenglVisual plugin") +endif() set(HEADER_FILES src/SofaOpenglVisual/config.h @@ -83,7 +84,7 @@ set(EXTRA_FILES ) add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES}) -target_link_libraries(${PROJECT_NAME} PUBLIC SofaBaseVisual SofaSimulationCommon) +target_link_libraries(${PROJECT_NAME} PUBLIC SofaBaseVisual SofaSimulationCommon Sofa.GL) sofa_create_package_with_targets( PACKAGE_NAME ${PROJECT_NAME} diff --git a/modules/SofaOpenglVisual/SofaOpenglVisualConfig.cmake.in b/modules/SofaOpenglVisual/SofaOpenglVisualConfig.cmake.in index ea4b948d30f..1466377e623 100644 --- a/modules/SofaOpenglVisual/SofaOpenglVisualConfig.cmake.in +++ b/modules/SofaOpenglVisual/SofaOpenglVisualConfig.cmake.in @@ -4,6 +4,7 @@ find_package(SofaBase QUIET REQUIRED) find_package(SofaSimulation QUIET REQUIRED) +find_package(Sofa.GL QUIET REQUIRED) if(NOT TARGET @PROJECT_NAME@) include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglColorMap.h b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglColorMap.h index 5f3f8df7126..dcd55a98d5a 100644 --- a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglColorMap.h +++ b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglColorMap.h @@ -23,8 +23,6 @@ #define SOFA_COMPONENT_VISUALMODEL_OGLCOLORMAP_H #include "config.h" -#ifndef SOFA_NO_OPENGL - #include #include #include @@ -127,6 +125,4 @@ class SOFA_OPENGL_VISUAL_API OglColorMap : public sofa::core::visual::VisualMode } // namespace sofa -#endif /* SOFA_NO_OPENGL */ - #endif diff --git a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglGrid.cpp b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglGrid.cpp index 36d6a9a0f86..2ec9978e77c 100644 --- a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglGrid.cpp +++ b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglGrid.cpp @@ -127,7 +127,6 @@ void OglGrid::updateVisual() void OglGrid::drawVisual(const core::visual::VisualParams* vparams) { -#ifndef SOFA_NO_OPENGL if (!draw.getValue()) return; std::vector points; @@ -177,7 +176,6 @@ void OglGrid::drawVisual(const core::visual::VisualParams* vparams) vparams->drawTool()->drawLines(points, thickness.getValue(), color.getValue()); -#endif } } // namespace visualmodel diff --git a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglRenderingSRGB.cpp b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglRenderingSRGB.cpp index 3bbc2e65cde..3b407eb01b0 100644 --- a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglRenderingSRGB.cpp +++ b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglRenderingSRGB.cpp @@ -33,7 +33,6 @@ namespace component namespace visualmodel { -using namespace helper::gl; using namespace simulation; //Register RenderingSRGB in the Object Factory diff --git a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglSceneFrame.cpp b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglSceneFrame.cpp index d983ddd05fe..8999acb7e70 100644 --- a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglSceneFrame.cpp +++ b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglSceneFrame.cpp @@ -71,7 +71,6 @@ void OglSceneFrame::updateVisual() void OglSceneFrame::draw(const core::visual::VisualParams* vparams) { -#ifndef SOFA_NO_OPENGL if (!drawFrame.getValue()) return; glPushAttrib( GL_ALL_ATTRIB_BITS); @@ -288,7 +287,6 @@ void OglSceneFrame::draw(const core::visual::VisualParams* vparams) glPopAttrib(); glViewport(viewport[0],viewport[1],viewport[2],viewport[3]); -#endif } diff --git a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglViewport.cpp b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglViewport.cpp index f78636c529c..46594a7b033 100644 --- a/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglViewport.cpp +++ b/modules/SofaOpenglVisual/src/SofaOpenglVisual/OglViewport.cpp @@ -221,9 +221,6 @@ void OglViewport::postDrawScene(core::visual::VisualParams* vp) void OglViewport::renderToViewport(core::visual::VisualParams* vp) { const sofa::defaulttype::BoundingBox& sceneBBox = vp->sceneBBox(); - helper::gl::Transformation vp_sceneTransform = vp->sceneTransform(); -// double vp_zNear = vp->zNear(); -// double vp_zFar = vp->zFar(); const Viewport viewport = vp->viewport(); //Launch FBO process diff --git a/modules/SofaUserInteraction/src/SofaUserInteraction/MouseInteractor.inl b/modules/SofaUserInteraction/src/SofaUserInteraction/MouseInteractor.inl index cb81ad684b9..f01b8add02f 100644 --- a/modules/SofaUserInteraction/src/SofaUserInteraction/MouseInteractor.inl +++ b/modules/SofaUserInteraction/src/SofaUserInteraction/MouseInteractor.inl @@ -22,7 +22,6 @@ #pragma once #include #include -#include #include namespace sofa::component::collision