From be029b9103476d1eb573cf9b14cd8d210caa4250 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 24 Apr 2016 16:26:40 +0200 Subject: [PATCH] [DEV] butter interface on the texture push --- data/textured3D2.frag | 2 +- data/texturedNoMaterial.frag | 2 +- data/texturedNoMaterial.vert | 6 +++--- ewol/resource/Texture.cpp | 40 +++++++++++++++++++++++++++++------- ewol/widget/Image.cpp | 11 ++++++++-- ewol/widget/Image.h | 2 ++ 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/data/textured3D2.frag b/data/textured3D2.frag index 7ac89bc1..f37bf8ee 100644 --- a/data/textured3D2.frag +++ b/data/textured3D2.frag @@ -51,5 +51,5 @@ void main(void) { specularLight = EW_directionalLight.specularColor * EW_material.specularFactor; } vec4 light = ambientLight + diffuseLight + specularLight; - gl_FragColor = tmpElementColor * light; + gl_FragColor = tmpElementColor;// * light; } diff --git a/data/texturedNoMaterial.frag b/data/texturedNoMaterial.frag index eef476af..b6c6e2a7 100644 --- a/data/texturedNoMaterial.frag +++ b/data/texturedNoMaterial.frag @@ -3,7 +3,7 @@ precision mediump float; precision mediump int; #endif -// Input : +// Input: uniform sampler2D EW_texID; varying vec2 f_texcoord; diff --git a/data/texturedNoMaterial.vert b/data/texturedNoMaterial.vert index a757e9c9..6ce4ff3c 100644 --- a/data/texturedNoMaterial.vert +++ b/data/texturedNoMaterial.vert @@ -2,17 +2,17 @@ precision mediump float; precision mediump int; #endif -// Input : +// Input: attribute vec3 EW_coord3d; attribute vec2 EW_texture2d; uniform mat4 EW_MatrixTransformation; uniform mat4 EW_MatrixPosition; -// output : +// output: varying vec2 f_texcoord; void main(void) { - gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0); // set texture output coord f_texcoord = EW_texture2d; + gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0); } diff --git a/ewol/resource/Texture.cpp b/ewol/resource/Texture.cpp index 835377a2..6b256aa1 100644 --- a/ewol/resource/Texture.cpp +++ b/ewol/resource/Texture.cpp @@ -48,7 +48,7 @@ ewol::resource::Texture::~Texture() { removeContext(); } -//#include +#include bool ewol::resource::Texture::updateContext() { EWOL_INFO("updateContext [START]"); @@ -57,7 +57,7 @@ bool ewol::resource::Texture::updateContext() { //Lock error ==> try later ... return false; } - if (false == m_loaded) { + if (m_loaded == false) { // Request a new texture at openGl : glGenTextures(1, &m_texId); } @@ -74,16 +74,42 @@ bool ewol::resource::Texture::updateContext() { //--- Mode linear glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + int32_t typeObject = GL_RGBA; + int32_t sizeObject = GL_UNSIGNED_BYTE; + switch (m_data.getType()) { + case egami::colorType::RGBA8: + typeObject = GL_RGBA; + sizeObject = GL_UNSIGNED_BYTE; + break; + case egami::colorType::RGB8: + typeObject = GL_RGB; + sizeObject = GL_UNSIGNED_BYTE; + break; + case egami::colorType::RGBAf: + typeObject = GL_RGBA; + sizeObject = GL_FLOAT; + break; + case egami::colorType::RGBf: + typeObject = GL_RGBA; + sizeObject = GL_FLOAT; + break; + case egami::colorType::unsignedInt16: + case egami::colorType::unsignedInt32: + case egami::colorType::float32: + case egami::colorType::float64: + EWOL_ERROR("Not manage the type " << m_data.getType() << " for texture"); + break; + } EWOL_INFO("TEXTURE: add [" << getId() << "]=" << m_data.getSize() << " OGl_Id=" << m_texId << " type=" << m_data.getType()); - //egami::storeBMP("~/bbb_image.bmp", m_data); + egami::store(m_data, std::string("~/texture_") + etk::to_string(getId()) + ".bmp"); glTexImage2D(GL_TEXTURE_2D, // Target 0, // Level - GL_RGBA, // Format internal + typeObject, // Format internal m_data.getWidth(), m_data.getHeight(), 0, // Border - GL_RGBA, // format - GL_UNSIGNED_BYTE, // type + typeObject, // format + sizeObject, // type m_data.getTextureDataPointer() ); // now the data is loaded m_loaded = true; @@ -93,7 +119,7 @@ bool ewol::resource::Texture::updateContext() { void ewol::resource::Texture::removeContext() { std::unique_lock lock(m_mutex); - if (true == m_loaded) { + if (m_loaded == true) { // Request remove texture ... EWOL_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId); glDeleteTextures(1, &m_texId); diff --git a/ewol/widget/Image.cpp b/ewol/widget/Image.cpp index 39d31cbd..31072f2a 100644 --- a/ewol/widget/Image.cpp +++ b/ewol/widget/Image.cpp @@ -22,6 +22,7 @@ ewol::widget::Image::Image() : propertyPosStop(this, "part-stop", vec2(1.0f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 1.0f), "Start display position in the image", &ewol::widget::Image::onChangePropertyGlobalSize), propertyDistanceFieldMode(this, "distance-field", false, "Distance field mode", &ewol::widget::Image::onChangePropertyDistanceFieldMode), propertySmooth(this, "smooth", true, "Smooth display of the image", &ewol::widget::Image::onChangePropertySmooth), + propertyUseThemeColor(this, "use-theme-color", false, "use the theme color to display images", &ewol::widget::Image::onChangePropertyUseThemeColor), m_colorProperty(nullptr), m_colorId(-1) { addObjectType("ewol::widget::Image"); @@ -52,8 +53,10 @@ void ewol::widget::Image::onRegenerateDisplay() { } // remove data of the previous composition : m_compositing.clear(); - if (m_colorProperty != nullptr) { - m_compositing.setColor(m_colorProperty->get(m_colorId)); + if (*propertyUseThemeColor == true) { + if (m_colorProperty != nullptr) { + m_compositing.setColor(m_colorProperty->get(m_colorId)); + } } // calculate the new position and size : vec2 imageBoder = propertyBorder->getPixel(); @@ -213,3 +216,7 @@ void ewol::widget::Image::onChangePropertyDistanceFieldMode() { markToRedraw(); } +void ewol::widget::Image::onChangePropertyUseThemeColor() { + markToRedraw(); +} + diff --git a/ewol/widget/Image.h b/ewol/widget/Image.h index 29433259..4ea39190 100644 --- a/ewol/widget/Image.h +++ b/ewol/widget/Image.h @@ -35,6 +35,7 @@ namespace ewol { eproperty::Range propertyPosStop; //!< position in the image to start the sisplay (when we want not to display all the image) eproperty::Value propertyDistanceFieldMode; //!< to have a parameter eproperty::Value propertySmooth; //!< display is done in the pixed approximation if false + eproperty::Value propertyUseThemeColor; //!< Use the themo color management ("{ewol}THEME:COLOR:Image.json") default false protected: ewol::compositing::Image m_compositing; //!< compositing element of the image. std::shared_ptr m_colorProperty; //!< theme color property @@ -71,6 +72,7 @@ namespace ewol { virtual void onChangePropertyGlobalSize(); virtual void onChangePropertySmooth(); virtual void onChangePropertyDistanceFieldMode(); + virtual void onChangePropertyUseThemeColor(); }; }; };