From b2f79b30117ea6f7a35e093819bdb297282363be Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 1 Apr 2019 21:59:56 +0200 Subject: [PATCH] [DEV] automatic selection of texture mode in shader --- ege/resource/Mesh.cpp | 43 +++++++++++++++++++++++++++++-------------- ege/resource/Mesh.hpp | 3 +-- lutin_ege.py | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index e73a263..0cd4dd8 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -34,6 +34,7 @@ ege::resource::Mesh::Mesh() : void ege::resource::Mesh::init(const etk::Uri& _fileName, const etk::Uri& _shaderName) { gale::Resource::init(_fileName.getString()); EGE_VERBOSE("Load a new mesh : '" << _fileName << "'"); + // ------------------------------------------------------------------------------------------------ // get the shader resource : m_GLPosition = 0; @@ -42,20 +43,7 @@ void ege::resource::Mesh::init(const etk::Uri& _fileName, const etk::Uri& _shade m_light.setAmbientColor(vec4(1.0f,1.0f,1.0f,1.0f)); // Global anbiant color of the scene m_light.setDiffuseColor(vec4(1.0f,1.0f,1.0f,1.0f)); // Color of the object m_light.setSpecularColor(vec4(0.0f,0.0f,0.0f,1.0f)); // Light color reflection - - EGE_VERBOSE(m_name << " " << m_light << " shader=" << _shaderName); - m_GLprogram = gale::resource::Program::create(_shaderName); - if (m_GLprogram != null) { - m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); - m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); - m_GLNormal = m_GLprogram->getAttribute("EW_normal"); - m_GLColor = m_GLprogram->getAttribute("EW_color"); - m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); - m_GLMatrixPosition = m_GLprogram->getUniform("EW_MatrixPosition"); - // Link material and Lights - m_GLMaterial.link(m_GLprogram, "EW_material"); - m_light.link(m_GLprogram, "EW_directionalLight"); - } + // ------------------------------------------------------------------------------------------------ // this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer m_verticesVBO = gale::resource::VirtualBufferObject::create(5); if (m_verticesVBO == null) { @@ -64,6 +52,7 @@ void ege::resource::Mesh::init(const etk::Uri& _fileName, const etk::Uri& _shade } // TO facilitate some debugs we add a name of the VBO: m_verticesVBO->setName("[VBO] of " + _fileName.getString()); + // ------------------------------------------------------------------------------------------------ // load the curent file : etk::String extention = etk::toLower(_fileName.getPath().getExtention()); // select the corect loader : @@ -81,6 +70,32 @@ void ege::resource::Mesh::init(const etk::Uri& _fileName, const etk::Uri& _shade } else { // nothing to do == > reqiest an enmpty mesh ==> user manage it ... } + // ------------------------------------------------------------------------------------------------ + etk::Uri shaderName = _shaderName; + if (shaderName.isEmpty() == true) { + shaderName = "DATA:///material3D.prog"; + for (auto &it: m_materials) { + if (it.second->haveTexture() == true) { + shaderName = "DATA:///material3DTextured.prog"; + break; + } + } + } + // ------------------------------------------------------------------------------------------------ + EGE_VERBOSE(m_name << " " << m_light << " shader=" << shaderName); + m_GLprogram = gale::resource::Program::create(shaderName); + if (m_GLprogram != null) { + m_GLPosition = m_GLprogram->getAttribute("EW_coord3d"); + m_GLtexture = m_GLprogram->getAttribute("EW_texture2d"); + m_GLNormal = m_GLprogram->getAttribute("EW_normal"); + m_GLColor = m_GLprogram->getAttribute("EW_color"); + m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation"); + m_GLMatrixPosition = m_GLprogram->getUniform("EW_MatrixPosition"); + // Link material and Lights + m_GLMaterial.link(m_GLprogram, "EW_material"); + m_light.link(m_GLprogram, "EW_directionalLight"); + } + // ------------------------------------------------------------------------------------------------ } diff --git a/ege/resource/Mesh.hpp b/ege/resource/Mesh.hpp index ca65f6b..1ab8fc7 100644 --- a/ege/resource/Mesh.hpp +++ b/ege/resource/Mesh.hpp @@ -119,8 +119,7 @@ namespace ege { protected: Mesh(); void init(const etk::Uri& _fileName="---", - //const etk::String& _shaderName="DATA:///textured3D2.prog" - const etk::Uri& _shaderName="DATA:///material3D.prog" + const etk::Uri& _shaderName=etk::Uri() //==> Shader is automatically selected (depending on the presence or ot of texture... ); public: virtual ~Mesh(); diff --git a/lutin_ege.py b/lutin_ege.py index e3cc836..ac8af35 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -77,7 +77,7 @@ def configure(target, my_module): 'ege/Ray.cpp', ]) my_module.copy_path('data/ParticuleMesh.*') - my_module.copy_path('data/material3D.*') + my_module.copy_path('data/material*') my_module.add_depend([ 'ewol', 'ephysics',