From 11924e20918fa557a4c713bce2d1d68aa2ee2810 Mon Sep 17 00:00:00 2001
From: Ricardo Ortiz <ricardo.ortiz@kitware.com>
Date: Sun, 30 Aug 2015 20:14:21 -0400
Subject: [PATCH] Fix cyclic dependency between mesh and rendering.

---
 Core/CMakeLists.txt                           |  1 +
 Core/Color.cpp                                | 10 ---
 Core/Color.h                                  | 15 ++++-
 {Rendering => Core}/ConfigRendering.h         | 11 ----
 Core/CoreClass.h                              |  5 +-
 Core/Light.h                                  |  2 +-
 Core/RenderDetail.cpp                         | 65 ++++++++++++-------
 Core/RenderDetail.h                           |  9 +++
 Core/Scene.cpp                                | 12 ++--
 Core/SceneObject.h                            |  2 +-
 Core/StaticSceneObject.h                      |  2 +
 Core/ViewerBase.h                             |  1 -
 Examples/renderCube/main.cpp                  | 19 +++---
 Examples/vegaFem/main.cpp                     |  6 +-
 Mesh/CMakeLists.txt                           |  1 -
 Mesh/SurfaceMesh.cpp                          | 37 ++++++-----
 Mesh/SurfaceMesh.h                            |  7 --
 RenderDelegates/PlaneRenderDelegate.cpp       |  6 +-
 RenderDelegates/SurfaceTreeRenderDelegate.cpp |  8 +--
 Rendering/ConfigRendering.cpp                 |  2 +-
 Rendering/CustomRenderer.h                    |  2 +-
 Rendering/GLUtils.cpp                         |  2 +-
 Rendering/OpenGLRenderer.cpp                  | 36 +++++-----
 Rendering/OpenGLViewer.cpp                    |  8 +--
 Rendering/OpenGLViewer.h                      |  1 +
 Rendering/VAO.h                               |  2 +-
 Rendering/VBO.h                               |  2 +-
 VTKRendering/CMakeLists.txt                   |  1 +
 VTKRendering/VTKMeshRenderDelegate.cpp        |  7 +-
 VTKRendering/VTKViewer.cpp                    |  1 +
 30 files changed, 153 insertions(+), 130 deletions(-)
 rename {Rendering => Core}/ConfigRendering.h (95%)

diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index d8649d55f..3e081d48e 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -63,6 +63,7 @@ simmedtk_add_library(Core
 )
 
 target_link_libraries(Core
+
   PUBLIC
     GLEW::GLEW
     ${OPENGL_LIBRARY}
diff --git a/Core/Color.cpp b/Core/Color.cpp
index 20eb44fb1..1d1b05f88 100644
--- a/Core/Color.cpp
+++ b/Core/Color.cpp
@@ -82,16 +82,6 @@ Color &Color::operator=(const Color &p_color )
     return *this;
 }
 
-GLfloat *Color::toGLColor()
-{
-    return static_cast<GLfloat*>(rgba);
-}
-
-const GLfloat *Color::toGLColor() const
-{
-    return static_cast<const GLfloat*>(rgba);
-}
-
 void Color::setValue( float p_red, float p_green, float p_blue, float p_alpha )
 {
     rgba[0] = p_red;
diff --git a/Core/Color.h b/Core/Color.h
index 4b3035792..81b5ad848 100644
--- a/Core/Color.h
+++ b/Core/Color.h
@@ -43,9 +43,20 @@ struct Color
     float operator()(int p_i);
     /// \brief setting
     Color &operator=(const Color &p_color);
+
     /// \brief converts to gl color
-    GLfloat* toGLColor();
-    const GLfloat* toGLColor() const;
+    template<typename GLColorType>
+    GLColorType* toGLColor()
+    {
+        return static_cast<GLColorType*>(&rgba[0]);
+    }
+
+    template<typename GLColorType>
+    const GLColorType* toGLColor() const
+    {
+        return static_cast<const GLColorType*>(&rgba[0]);
+    }
+
     /// \brief set RGB color
     void setValue(float p_red, float p_green, float p_blue, float p_alpha);
 
diff --git a/Rendering/ConfigRendering.h b/Core/ConfigRendering.h
similarity index 95%
rename from Rendering/ConfigRendering.h
rename to Core/ConfigRendering.h
index 91d008765..303b584d1 100644
--- a/Rendering/ConfigRendering.h
+++ b/Core/ConfigRendering.h
@@ -24,17 +24,6 @@
 #ifndef SMCONFIGRENDERING_H
 #define SMCONFIGRENDERING_H
 
-#include <memory>
-#include <vector>
-
-// SimMedTK includes
-#include "Core/Config.h"
-#include "Core/Color.h"
-#include "Core/RenderDetail.h"
-
-
-class Shader;
-
 /// \brief this shows the Vertex Buffer Object Size
 ///It should be bigger than the total data of vertices and indices of the scene objects.
 ///the value is in bytes
diff --git a/Core/CoreClass.h b/Core/CoreClass.h
index 05e1338a5..eb02c3103 100644
--- a/Core/CoreClass.h
+++ b/Core/CoreClass.h
@@ -34,7 +34,8 @@
 #include "Core/Config.h"
 #include "Core/UnifiedId.h"
 #include "Core/EventHandler.h"
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
+#include "Core/RenderDetail.h"
 
 class SDK;
 class CoreClass;
@@ -244,10 +245,10 @@ protected:
     core::EventType,
     core::EventHandler::FunctionContainerType::iterator> eventIndexMap;
     std::shared_ptr<RenderDelegate> renderDelegate; ///!< Class that can render this class
+    std::shared_ptr<RenderDetail> renderDetail; ///< specifies visualization type
 
 private:
     std::shared_ptr<UnifiedId> uniqueId; ///< unique Id
-    std::shared_ptr<RenderDetail> renderDetail; ///< specifies visualization type
     core::ClassDrawOrder drawOrder; ///< draw order of the object
 };
 
diff --git a/Core/Light.h b/Core/Light.h
index 7401c4150..5bee154f0 100644
--- a/Core/Light.h
+++ b/Core/Light.h
@@ -31,7 +31,7 @@
 #include "Core/Config.h"
 #include "Core/CoreClass.h"
 #include "Core/Vector.h"
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 
 #define SMLIGHT_SPOTMAX 128
 
diff --git a/Core/RenderDetail.cpp b/Core/RenderDetail.cpp
index 541ea4790..510660c1f 100644
--- a/Core/RenderDetail.cpp
+++ b/Core/RenderDetail.cpp
@@ -18,50 +18,49 @@
 
 void RenderDetail::addShader(std::shared_ptr<UnifiedId> p_shaderID)
 {
-
     shaderEnable.push_back(true);
     shaders.push_back(p_shaderID);
 }
 void RenderDetail::addVAO(std::shared_ptr<UnifiedId> p_shaderID)
 {
-
     VAOs.push_back(p_shaderID);
     VAOEnable.push_back(true);
 }
 
 RenderDetail::RenderDetail()
 {
-  this->reset();
+    this->reset();
 }
 
 RenderDetail::RenderDetail(unsigned int type)
 {
-  this->reset();
-  normalLength = 1.0;
-  this->renderType = type;
+    this->reset();
+    normalLength = 1.0;
+    this->renderType = type;
 }
 
 void RenderDetail::reset()
 {
-  renderType = 0;
-  highLightColor.rgba[0] = 1.0f;
-  highLightColor.rgba[1] = 0.0f;
-  highLightColor.rgba[2] = 0.0f;
-  pointSize = 1;
-  lineSize = 1;
-  shadowColor.rgba[0] = 0.0f;
-  shadowColor.rgba[1] = 0.0f;
-  shadowColor.rgba[2] = 0.0f;
-  shadowColor.rgba[3] = 0.5f;
-  colorDiffuse = Color::colorWhite;
-  colorAmbient = Color::colorWhite;
-  colorSpecular = Color::colorWhite;
-  normalColor = Color::colorGreen;
-  wireFrameColor = Color::colorBlue;
-  shininess = 50.0;
-  debugDraw = false;
-  castShadow = true;
-  canGetShadow = true;
+    renderType = 0;
+    highLightColor.rgba[0] = 1.0f;
+    highLightColor.rgba[1] = 0.0f;
+    highLightColor.rgba[2] = 0.0f;
+    pointSize = 1;
+    lineSize = 1;
+    shadowColor.rgba[0] = 0.0f;
+    shadowColor.rgba[1] = 0.0f;
+    shadowColor.rgba[2] = 0.0f;
+    shadowColor.rgba[3] = 0.5f;
+    colorDiffuse = Color::colorWhite;
+    colorAmbient = Color::colorWhite;
+    colorSpecular = Color::colorWhite;
+    normalColor = Color::colorGreen;
+    wireFrameColor = Color::colorBlue;
+    shininess = 50.0;
+    debugDraw = false;
+    castShadow = true;
+    canGetShadow = true;
+    textureFilename = "";
 }
 
 void RenderDetail::setNormalLength(const float len)
@@ -188,3 +187,19 @@ const std::vector< bool >& RenderDetail::getVAOEnable() const
 {
     return this->VAOEnable;
 }
+void RenderDetail::setTextureFilename(const std::string& filename)
+{
+    this->textureFilename = filename;
+}
+const std::string &RenderDetail::getTextureFilename() const
+{
+    return this->textureFilename;
+}
+bool RenderDetail::renderTexture() const
+{
+    return !this->textureFilename.empty() && this->renderType & SIMMEDTK_RENDER_TEXTURE;
+}
+bool RenderDetail::renderNormals() const
+{
+    return  this->renderType & SIMMEDTK_RENDER_NORMALS;
+}
diff --git a/Core/RenderDetail.h b/Core/RenderDetail.h
index 156244840..3d27b67e9 100644
--- a/Core/RenderDetail.h
+++ b/Core/RenderDetail.h
@@ -19,6 +19,7 @@
 
 #include "Core/Config.h"
 #include "Core/Color.h"
+#include "Core/ConfigRendering.h"
 
 #include <memory>
 #include <vector>
@@ -155,6 +156,12 @@ public:
 
     void setWireframeColor(const Color wireColor);
 
+    void setTextureFilename(const std::string &filename);
+    const std::string &getTextureFilename() const;
+    bool renderTexture() const;
+
+    bool renderNormals() const;
+
 public:
     unsigned int renderType; // render type
     Color colorDiffuse; // diffuse color
@@ -172,6 +179,8 @@ public:
     float shininess; // specular shinness
     bool debugDraw; // debug draw enabled or not
     float normalLength; // length of rendered normals
+    std::string textureFilename; // file name for the texture attached
+
     std::vector<std::shared_ptr<UnifiedId>> shaders; // attached shaders
     std::vector<bool> shaderEnable; // enable/disable any attached shader
     std::vector<std::shared_ptr<UnifiedId>> VAOs; // stores  VAO IDs
diff --git a/Core/Scene.cpp b/Core/Scene.cpp
index a2b3f5a15..9fa60daa5 100644
--- a/Core/Scene.cpp
+++ b/Core/Scene.cpp
@@ -121,9 +121,9 @@ void Scene::initLights()
     for (auto light: lights)
     {
         glEnable(light->renderUsage);
-        glLightfv(light->renderUsage, GL_AMBIENT, light->lightColorAmbient.toGLColor());
-        glLightfv(light->renderUsage, GL_DIFFUSE, light->lightColorDiffuse.toGLColor());
-        glLightfv(light->renderUsage, GL_SPECULAR, light->lightColorSpecular.toGLColor());
+        glLightfv(light->renderUsage, GL_AMBIENT, light->lightColorAmbient.toGLColor<GLfloat>());
+        glLightfv(light->renderUsage, GL_DIFFUSE, light->lightColorDiffuse.toGLColor<GLfloat>());
+        glLightfv(light->renderUsage, GL_SPECULAR, light->lightColorSpecular.toGLColor<GLfloat>());
         glLightf(light->renderUsage, GL_SPOT_EXPONENT, light->spotExp * SMLIGHT_SPOTMAX);
         glLightf(light->renderUsage, GL_SPOT_CUTOFF, light->spotCutOffAngle);
         casted = light->lightPos.getPosition().cast<float>();
@@ -147,9 +147,9 @@ void Scene::refreshLights()
     for (auto light: lights)
     {
         glEnable(light->renderUsage);
-        glLightfv(light->renderUsage, GL_AMBIENT, light->lightColorAmbient.toGLColor());
-        glLightfv(light->renderUsage, GL_DIFFUSE, light->lightColorDiffuse.toGLColor());
-        glLightfv(light->renderUsage, GL_SPECULAR, light->lightColorSpecular.toGLColor());
+        glLightfv(light->renderUsage, GL_AMBIENT, light->lightColorAmbient.toGLColor<GLfloat>());
+        glLightfv(light->renderUsage, GL_DIFFUSE, light->lightColorDiffuse.toGLColor<GLfloat>());
+        glLightfv(light->renderUsage, GL_SPECULAR, light->lightColorSpecular.toGLColor<GLfloat>());
         glLightf(light->renderUsage, GL_SPOT_EXPONENT, light->spotExp * SMLIGHT_SPOTMAX);
         glLightf(light->renderUsage, GL_SPOT_CUTOFF, light->spotCutOffAngle);
         casted = light->lightPos.getPosition().cast<float>();
diff --git a/Core/SceneObject.h b/Core/SceneObject.h
index 247a7d352..9e3b4aa21 100644
--- a/Core/SceneObject.h
+++ b/Core/SceneObject.h
@@ -32,7 +32,7 @@
 #include "Core/Vector.h"
 #include "Core/Config.h"
 #include "Core/CoreClass.h"
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 #include "Rendering/CustomRenderer.h"
 
 //forward class declaration
diff --git a/Core/StaticSceneObject.h b/Core/StaticSceneObject.h
index fd88e0b32..69ad74802 100644
--- a/Core/StaticSceneObject.h
+++ b/Core/StaticSceneObject.h
@@ -32,6 +32,8 @@
 #include "Core/Model.h"
 #include "Mesh/SurfaceMesh.h"
 
+class ErrorLog;
+
 namespace core {
     class Event;
 }
diff --git a/Core/ViewerBase.h b/Core/ViewerBase.h
index c1c2364bd..4c2de0c6d 100644
--- a/Core/ViewerBase.h
+++ b/Core/ViewerBase.h
@@ -36,7 +36,6 @@
 class SDK;
 class OpenGLWindowStream;
 class MetalShader;
-class SceneTextureShader;
 class FrameBuffer;
 class Texture;
 
diff --git a/Examples/renderCube/main.cpp b/Examples/renderCube/main.cpp
index c1e0c754d..dccd0ef43 100644
--- a/Examples/renderCube/main.cpp
+++ b/Examples/renderCube/main.cpp
@@ -33,13 +33,14 @@
 #include "Core/SDK.h"
 #include "Rendering/TextureManager.h"
 #include "Geometry/MeshModel.h"
+#include "Core/Factory.h"
 
 int main()
 {
     initRenderDelegates();
     initVTKRendering();
     initIODelegates();
-    const bool useVTKRenderer = false;
+    const bool useVTKRenderer = true;
 
     std::shared_ptr<SDK> sdk;
     std::shared_ptr<Scene> scene1;
@@ -67,20 +68,22 @@ int main()
     //Create a new scene to work in
     scene1 = sdk->createScene();
 
-    //Create the camera controller
+    auto cubeModel = std::make_shared<MeshModel>();
+    cubeModel->load("models/cube.obj");
+    auto renderDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE);
+    renderDetail->setTextureFilename("textures/cube.jpg");
+    cubeModel->setRenderDetail(renderDetail);
+
     if(!useVTKRenderer)
     {
+        //Create the camera controller
         camCtl = std::make_shared<mstk::Examples::Common::wasdCameraController>();
         keyShutdown = std::make_shared<mstk::Examples::Common::KeyPressSDKShutdown>();
         pzrCamCtl = std::make_shared<mstk::Examples::Common::pzrMouseCameraController>();
+        TextureManager::addTexture("textures/cube.jpg", "cubetex");
+        std::static_pointer_cast<SurfaceMesh>(cubeModel->getMesh())->assignTexture("cubetex");
     }
-    auto cubeModel = std::make_shared<MeshModel>();
-    TextureManager::addTexture("textures/cube.jpg", "cubetex");
-    cubeModel->load("models/cube.obj");
-    std::static_pointer_cast<SurfaceMesh>(cubeModel->getMesh())->assignTexture("cubetex");
 
-    auto renderDetail = std::make_shared<RenderDetail>(SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE);
-    cubeModel->setRenderDetail(renderDetail);
 
     cube = std::make_shared<StaticSceneObject>();
 
diff --git a/Examples/vegaFem/main.cpp b/Examples/vegaFem/main.cpp
index 8e023f91e..372d8b890 100644
--- a/Examples/vegaFem/main.cpp
+++ b/Examples/vegaFem/main.cpp
@@ -99,7 +99,11 @@ int main()
     femObjRenderDetail->setVertexColor(maroon);
     femObjRenderDetail->setNormalLength(0.02);
 
-    femObject->getVolumetricMesh()->getRenderingMesh()->setRenderDetail(femObjRenderDetail);
+    auto renderingMesh = femObject->getVolumetricMesh()->getRenderingMesh();
+    if(renderingMesh)
+    {
+        renderingMesh->setRenderDetail(femObjRenderDetail);
+    }
 
     sdk->addSceneActor(femObject, femSimulator);
 
diff --git a/Mesh/CMakeLists.txt b/Mesh/CMakeLists.txt
index aa6db00be..ad589642e 100644
--- a/Mesh/CMakeLists.txt
+++ b/Mesh/CMakeLists.txt
@@ -11,7 +11,6 @@ simmedtk_add_library(Mesh
 target_link_libraries(Mesh
   PRIVATE
     Core
-    Rendering
   PUBLIC
     Assimp::Assimp
     VegaFEM::minivector
diff --git a/Mesh/SurfaceMesh.cpp b/Mesh/SurfaceMesh.cpp
index 85c61ba23..4bfb5a5ab 100644
--- a/Mesh/SurfaceMesh.cpp
+++ b/Mesh/SurfaceMesh.cpp
@@ -22,7 +22,8 @@
 //---------------------------------------------------------------------------
 
 #include "Mesh/SurfaceMesh.h"
-#include "Core/CollisionConfig.h"
+
+#include "Core/Factory.h"
 #include "Core/RenderDelegate.h"
 
 ///
@@ -210,10 +211,6 @@ void SurfaceMesh::checkTriangleOrientation()
         }
     }
 }
-const std::string& SurfaceMesh::getTextureFileName(const size_t i) const
-{
-    return TextureManager::getTexture(textures[i]->textureId)->textureFileName;
-}
 const std::vector< Eigen::Matrix< float, int(2), int(1) >, Eigen::aligned_allocator< Eigen::Matrix< float, int(2), int(1) > > >& SurfaceMesh::getTextureCoordinates() const
 {
     return this->textureCoord;
@@ -244,24 +241,30 @@ void SurfaceMesh::addTextureCoordinate(const float& x, const float& y)
 }
 void SurfaceMesh::assignTexture(const std::string& referenceName)
 {
-    int id;
-    TextureManager::findTextureId(referenceName,id);
-
-    if(id < 0)
-    {
-        std::cerr << "The texture " << referenceName
-            << " cant be attached because it has not been processed by the manager." << std::endl;
-        return;
-    }
-
+    // TODO: This test has to be done at the rendrer level!
+//     int id;
+//     TextureManager::findTextureId(referenceName,id);
+//
+//     if(id < 0)
+//     {
+//         std::cerr << "The texture " << referenceName
+//             << " cant be attached because it has not been processed by the manager." << std::endl;
+//         return;
+//     }
+//
     auto attachment = std::make_shared<TextureAttachment>();
+    attachment->textureId = -1;
     attachment->textureName = referenceName;
-    attachment->textureId = id;
     this->textures.push_back(attachment);
 }
 bool SurfaceMesh::isMeshTextured() const
 {
-    return !this->textures.empty();
+    if(!this->renderDetail)
+    {
+        return false;
+    }
+
+    return !this->renderDetail->getTextureFilename().empty();
 }
 void SurfaceMesh::setUseOBJTexture(bool use)
 {
diff --git a/Mesh/SurfaceMesh.h b/Mesh/SurfaceMesh.h
index f99bb72d5..290b825a9 100644
--- a/Mesh/SurfaceMesh.h
+++ b/Mesh/SurfaceMesh.h
@@ -26,8 +26,6 @@
 
 // SimMedTK includes
 #include "Core/BaseMesh.h"
-#include "Rendering/TextureManager.h"
-#include "Core/Factory.h"
 
 /// \brief this is the Surface Mesh class derived from generic Mesh class.
 class SurfaceMesh: public Core::BaseMesh
@@ -82,11 +80,6 @@ public:
     /// Texture handling
 
     struct TextureAttachment;
-    ///
-    /// \brief Returns the the name of ith texture.
-    ///
-    const std::string &getTextureFileName(const size_t i) const;
-
     ///
     /// \brief Returns the texture coordinates array.
     ///
diff --git a/RenderDelegates/PlaneRenderDelegate.cpp b/RenderDelegates/PlaneRenderDelegate.cpp
index f20a7e548..3320f3db3 100644
--- a/RenderDelegates/PlaneRenderDelegate.cpp
+++ b/RenderDelegates/PlaneRenderDelegate.cpp
@@ -41,9 +41,9 @@ void PlaneRenderDelegate::draw() const
 //         }
 //         glEnable(GL_LIGHTING);
 //
-//         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Color::colorGray.toGLColor());
-//         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Color::colorWhite.toGLColor());
-//         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Color::colorGray.toGLColor());
+//         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Color::colorGray.toGLColor<GLfloat>());
+//         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Color::colorWhite.toGLColor<GLfloat>());
+//         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Color::colorGray.toGLColor<GLfloat>());
 //
 //         glEnable(GL_BLEND);
 //         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
diff --git a/RenderDelegates/SurfaceTreeRenderDelegate.cpp b/RenderDelegates/SurfaceTreeRenderDelegate.cpp
index 7104ef44e..d1a7cce80 100644
--- a/RenderDelegates/SurfaceTreeRenderDelegate.cpp
+++ b/RenderDelegates/SurfaceTreeRenderDelegate.cpp
@@ -53,15 +53,15 @@ bool SurfaceTreeRenderDelegate::drawTree() const
     return false;
 
   core::Vec3d center;
-  glColor3fv(Color::colorGreen.toGLColor());
+  glColor3fv(Color::colorGreen.toGLColor<GLfloat>());
 
   glEnable(GL_LIGHTING);
   glPushAttrib(GL_LIGHTING_BIT);
-  glColor3fv(Color::colorGreen.toGLColor());
-  glColor3fv(Color::colorBlue.toGLColor());
+  glColor3fv(Color::colorGreen.toGLColor<GLfloat>());
+  glColor3fv(Color::colorBlue.toGLColor<GLfloat>());
 
   glPushMatrix();
-  glColor3fv(Color::colorPink.toGLColor());
+  glColor3fv(Color::colorPink.toGLColor<GLfloat>());
 
   geom->getRoot()->draw();
 
diff --git a/Rendering/ConfigRendering.cpp b/Rendering/ConfigRendering.cpp
index e53175a18..670394e13 100644
--- a/Rendering/ConfigRendering.cpp
+++ b/Rendering/ConfigRendering.cpp
@@ -21,5 +21,5 @@
 // Contact:
 //---------------------------------------------------------------------------
 
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 
diff --git a/Rendering/CustomRenderer.h b/Rendering/CustomRenderer.h
index 6a63cb070..d3452aae5 100644
--- a/Rendering/CustomRenderer.h
+++ b/Rendering/CustomRenderer.h
@@ -26,7 +26,7 @@
 
 
 // SimMedTK includes
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 #include "Core/Config.h"
 #include "Core/CoreClass.h"
 #include "Core/SceneObject.h"
diff --git a/Rendering/GLUtils.cpp b/Rendering/GLUtils.cpp
index f4cbe843a..49a280f39 100644
--- a/Rendering/GLUtils.cpp
+++ b/Rendering/GLUtils.cpp
@@ -111,7 +111,7 @@ void GLUtils::drawQuadOnScreen(Color p_color, float p_left,
     glLoadIdentity();
     glOrtho(0, 1.0, 0.0, 1, 0.1, 1.1);
     glBegin(GL_QUADS);
-    glColor4fv(p_color.toGLColor());
+    glColor4fv(p_color.toGLColor<GLfloat>());
     glVertex3d(p_left, p_bottom, -1.0);
     glVertex3d(p_right, p_bottom, -1.0);
     glVertex3d(p_right, p_top , -1.0);
diff --git a/Rendering/OpenGLRenderer.cpp b/Rendering/OpenGLRenderer.cpp
index c9b6c4700..421e56ecf 100644
--- a/Rendering/OpenGLRenderer.cpp
+++ b/Rendering/OpenGLRenderer.cpp
@@ -68,9 +68,9 @@ void OpenGLRenderer::drawLineMesh(std::shared_ptr<LineMesh> p_lineMesh, std::sha
 
     if (renderType & SIMMEDTK_RENDER_MATERIALCOLOR)
     {
-        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  renderDetail->getColorDiffuse().toGLColor());
-        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, renderDetail->getColorSpecular().toGLColor());
-        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, renderDetail->getColorAmbient().toGLColor());
+        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  renderDetail->getColorDiffuse().toGLColor<GLfloat>());
+        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, renderDetail->getColorSpecular().toGLColor<GLfloat>());
+        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, renderDetail->getColorAmbient().toGLColor<GLfloat>());
         glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, renderDetail->getShininess());
     }
 
@@ -139,7 +139,7 @@ void OpenGLRenderer::drawLineMesh(std::shared_ptr<LineMesh> p_lineMesh, std::sha
     if (renderType & SIMMEDTK_RENDER_HIGHLIGHTVERTICES)
     {
         glDisable(GL_LIGHTING);
-        glColor3fv(renderDetail->getHighLightColor().toGLColor());
+        glColor3fv(renderDetail->getHighLightColor().toGLColor<GLfloat>());
         glDrawArrays(GL_POINTS, 0, p_lineMesh->nbrVertices);
         glEnable(GL_LIGHTING);
     }
@@ -197,10 +197,10 @@ void OpenGLRenderer::drawSurfaceMeshTriangles(
 
     if (p_surfaceMesh->getRenderDetail()->getRenderType() & SIMMEDTK_RENDER_MATERIALCOLOR)
     {
-        const GLfloat * color = renderDetail->getColorDiffuse().toGLColor();
+        const GLfloat * color = renderDetail->getColorDiffuse().toGLColor<GLfloat>();
         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
-        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, renderDetail->getColorSpecular().toGLColor());
-        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, renderDetail->getColorAmbient().toGLColor());
+        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, renderDetail->getColorSpecular().toGLColor<GLfloat>());
+        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, renderDetail->getColorAmbient().toGLColor<GLfloat>());
         glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, renderDetail->getShininess());
     }
 
@@ -247,7 +247,7 @@ void OpenGLRenderer::drawSurfaceMeshTriangles(
     {
         glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
         glDisable(GL_LIGHTING);
-        glColor3fv(renderDetail->getVertexColor().toGLColor());
+        glColor3fv(renderDetail->getVertexColor().toGLColor<GLfloat>());
         glDrawElements(GL_TRIANGLES, p_surfaceMesh->getTriangles().size() * 3, GL_UNSIGNED_INT, p_surfaceMesh->getTriangles().data()->data());
 
         glEnable(GL_LIGHTING);
@@ -262,7 +262,7 @@ void OpenGLRenderer::drawSurfaceMeshTriangles(
         glPolygonOffset(1.0, 1.0);
         glDisable(GL_LIGHTING);
         glDisable(GL_TEXTURE_2D);
-        glColor4fv(renderDetail->getWireFrameColor().toGLColor());
+        glColor4fv(renderDetail->getWireFrameColor().toGLColor<GLfloat>());
 
         glDrawElements(GL_TRIANGLES, p_surfaceMesh->getTriangles().size() * 3, GL_UNSIGNED_INT, p_surfaceMesh->getTriangles().data()->data());
 
@@ -276,7 +276,7 @@ void OpenGLRenderer::drawSurfaceMeshTriangles(
     if (p_surfaceMesh->getRenderDetail()->getRenderType() & SIMMEDTK_RENDER_HIGHLIGHTVERTICES)
     {
         glDisable(GL_LIGHTING);
-        glColor3fv(renderDetail->getHighLightColor().toGLColor());
+        glColor3fv(renderDetail->getHighLightColor().toGLColor<GLfloat>());
         glDrawArrays(GL_POINTS, 0, p_surfaceMesh->getNumberOfVertices());
         glEnable(GL_LIGHTING);
     }
@@ -370,7 +370,7 @@ void OpenGLRenderer::draw(const Eigen::AlignedBox3d &aabb, Color p_color)
     glDisable(GL_TEXTURE_2D);
 
     glLineWidth(1.0);
-    glColor3fv(p_color.toGLColor());
+    glColor3fv(p_color.toGLColor<GLfloat>());
     glBegin(GL_LINES);
 
     auto const &min = aabb.min();
@@ -478,17 +478,17 @@ void OpenGLRenderer::drawAxes(const float length)
 
     Eigen::Vector3f origin(0, 0, 0);
 
-    glColor3fv(Color::colorRed.toGLColor());
+    glColor3fv(Color::colorRed.toGLColor<GLfloat>());
     glPushMatrix();
     drawArrow(origin, Eigen::Vector3f(length, 0, 0), headWidth);
     glPopMatrix();
 
-    glColor3fv(Color::colorGreen.toGLColor());
+    glColor3fv(Color::colorGreen.toGLColor<GLfloat>());
     glPushMatrix();
     drawArrow(origin, Eigen::Vector3f(0, length, 0), headWidth);
     glPopMatrix();
 
-    glColor3fv(Color::colorBlue.toGLColor());
+    glColor3fv(Color::colorBlue.toGLColor<GLfloat>());
     glPushMatrix();
     drawArrow(origin, Eigen::Vector3f(0, 0, length), headWidth);
     glPopMatrix();
@@ -502,21 +502,21 @@ void OpenGLRenderer::drawAxes(const Matrix33f &rotMat, const core::Vec3f &pos, c
 
     GLfloat headWidth = length / 12;
 
-    glColor3fv(Color::colorRed.toGLColor());
+    glColor3fv(Color::colorRed.toGLColor<GLfloat>());
     glPushMatrix();
     Eigen::Vector3f xVec(length, 0, 0);
     xVec = rotMat*xVec + pos;
     drawArrow(pos, xVec, headWidth);
     glPopMatrix();
 
-    glColor3fv(Color::colorGreen.toGLColor());
+    glColor3fv(Color::colorGreen.toGLColor<GLfloat>());
     glPushMatrix();
     Eigen::Vector3f yVec(0, length, 0);
     yVec = rotMat*yVec + pos;
     drawArrow(pos, yVec, headWidth);
     glPopMatrix();
 
-    glColor3fv(Color::colorBlue.toGLColor());
+    glColor3fv(Color::colorBlue.toGLColor<GLfloat>());
     glPushMatrix();
     Eigen::Vector3f zVec(0, 0, length);
     zVec = rotMat*zVec + pos;
@@ -549,7 +549,7 @@ void OpenGLRenderer::draw(Plane &p_plane, float p_scale, Color p_color)
 
     glDisable(GL_LIGHTING);
     glBegin(GL_QUADS);
-    glColor3fv(p_color.toGLColor());
+    glColor3fv(p_color.toGLColor<GLfloat>());
     tmp = rot*planePoints[0] + point;
     glVertex3dv(tmp.data());
     tmp = rot*planePoints[1] + point;
diff --git a/Rendering/OpenGLViewer.cpp b/Rendering/OpenGLViewer.cpp
index 1f0be3d3f..5bb0cf10f 100644
--- a/Rendering/OpenGLViewer.cpp
+++ b/Rendering/OpenGLViewer.cpp
@@ -325,10 +325,10 @@ void OpenGLViewer::renderToScreen(const RenderOperation &p_rop)
 /// \brief Set the color and other viewer defaults
 void OpenGLViewer::setToDefaults()
 {
-    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, defaultDiffuseColor.toGLColor());
-    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, defaultSpecularColor.toGLColor());
-    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, defaultAmbientColor.toGLColor());
-    glColor4fv(defaultDiffuseColor.toGLColor());
+    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, defaultDiffuseColor.toGLColor<GLfloat>());
+    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, defaultSpecularColor.toGLColor<GLfloat>());
+    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, defaultAmbientColor.toGLColor<GLfloat>());
+    glColor4fv(defaultDiffuseColor.toGLColor<GLfloat>());
 }
 
 /// \brief Called at the beginning of each frame by the module
diff --git a/Rendering/OpenGLViewer.h b/Rendering/OpenGLViewer.h
index 1885fc7cd..6629ce841 100644
--- a/Rendering/OpenGLViewer.h
+++ b/Rendering/OpenGLViewer.h
@@ -32,6 +32,7 @@
 
 //forward declaration
 class OpenGLWindowStream;
+class SceneTextureShader;
 
 /// \brief Handles all rendering routines.
 class OpenGLViewer : public ViewerBase
diff --git a/Rendering/VAO.h b/Rendering/VAO.h
index fafd0ae3c..5222062f3 100644
--- a/Rendering/VAO.h
+++ b/Rendering/VAO.h
@@ -33,7 +33,7 @@
 #include "Core/Config.h"
 #include "Core/CoreClass.h"
 #include "Core/Utils.h"
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 #include "Rendering/GLUtils.h"
 #include "Rendering/Shader.h"
 #include "Rendering/VBO.h"
diff --git a/Rendering/VBO.h b/Rendering/VBO.h
index b708c970d..2fc36bcdf 100644
--- a/Rendering/VBO.h
+++ b/Rendering/VBO.h
@@ -32,7 +32,7 @@
 #include "Core/Config.h"
 #include "Core/CoreClass.h"
 #include "Core/BaseMesh.h"
-#include "Rendering/ConfigRendering.h"
+#include "Core/ConfigRendering.h"
 #include "Rendering/GLUtils.h"
 #include "Core/Utils.h"
 #include "Core/Vector.h"
diff --git a/VTKRendering/CMakeLists.txt b/VTKRendering/CMakeLists.txt
index f108790d3..dbd270585 100644
--- a/VTKRendering/CMakeLists.txt
+++ b/VTKRendering/CMakeLists.txt
@@ -16,6 +16,7 @@ set(PRIVATE_LIBS
     PRIVATE
         Core
         Simulators)
+
 if(VTK_LIBRARIES)
     target_link_libraries(VTKRendering
     PUBLIC
diff --git a/VTKRendering/VTKMeshRenderDelegate.cpp b/VTKRendering/VTKMeshRenderDelegate.cpp
index 22053e590..8829334fa 100644
--- a/VTKRendering/VTKMeshRenderDelegate.cpp
+++ b/VTKRendering/VTKMeshRenderDelegate.cpp
@@ -113,10 +113,11 @@ void MeshRenderDelegate::initDraw()
     unstructuredMesh->SetCells(VTK_TRIANGLE,triangles.GetPointer());
 
     vtkSmartPointer<vtkTexture> texture;
-    if(mesh->isMeshTextured())
+    auto renderDetail = mesh->getRenderDetail();
+    if(renderDetail && renderDetail->renderTexture())
     {
         vtkNew<vtkJPEGReader> jpegReader;
-        jpegReader->SetFileName(mesh->getTextureFileName(0).c_str());
+        jpegReader->SetFileName(mesh->getRenderDetail()->getTextureFilename().c_str());
 
         texture = vtkTexture::New();
         texture->SetInputConnection(jpegReader->GetOutputPort());
@@ -135,7 +136,7 @@ void MeshRenderDelegate::initDraw()
     }
 
     dataSet = unstructuredMesh.GetPointer();
-    if (mesh->getRenderDetail()->renderType & SIMMEDTK_RENDER_NORMALS)
+    if (renderDetail && renderDetail->renderNormals())
     {
         vtkSmartPointer<vtkGeometryFilter> geometry = vtkGeometryFilter::New();
         geometry->SetInputData(unstructuredMesh.GetPointer());
diff --git a/VTKRendering/VTKViewer.cpp b/VTKRendering/VTKViewer.cpp
index 9c61e61d1..da0481e40 100644
--- a/VTKRendering/VTKViewer.cpp
+++ b/VTKRendering/VTKViewer.cpp
@@ -24,6 +24,7 @@
 #include "VTKRendering/VTKViewer.h"
 #include "VTKRendering/VTKRenderDelegate.h"
 #include "Core/MakeUnique.h"
+#include "Core/Factory.h"
 
 // VTK includes
 #include <vtkNew.h>
-- 
GitLab