[DEV] add the basic compositing on image
This commit is contained in:
parent
b9bedb8b36
commit
8b8f48b654
2
external/etk
vendored
2
external/etk
vendored
@ -1 +1 @@
|
||||
Subproject commit 28ffa0fb754b2e9cdba86bf9d4bbfc35770fe70b
|
||||
Subproject commit fb13e03dc913ccd56c27aef4c780e68e3b384b84
|
166
sources/ewol/compositing/Area.cpp
Normal file
166
sources/ewol/compositing/Area.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <tinyXML/tinyxml.h>
|
||||
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/compositing/Area.h>
|
||||
#include <ewol/config.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ewol::Area"
|
||||
|
||||
ewol::Area::Area(ivec2 size) :
|
||||
m_position(0.0, 0.0, 0.0),
|
||||
m_color(draw::color::white),
|
||||
m_GLprogram(NULL),
|
||||
m_GLPosition(-1),
|
||||
m_GLMatrix(-1),
|
||||
m_GLColor(-1),
|
||||
m_GLtexture(-1),
|
||||
m_GLtexID(-1),
|
||||
m_resource(NULL)
|
||||
{
|
||||
ewol::resource::Keep(m_resource);
|
||||
m_resource->SetImageSize(size);
|
||||
m_resource->Flush();
|
||||
LoadProgram();
|
||||
}
|
||||
|
||||
ewol::Area::~Area(void)
|
||||
{
|
||||
if (NULL != m_resource) {
|
||||
ewol::resource::Release(m_resource);
|
||||
m_resource = NULL;
|
||||
}
|
||||
ewol::resource::Release(m_GLprogram);
|
||||
}
|
||||
|
||||
void ewol::Area::LoadProgram(void)
|
||||
{
|
||||
etk::UString tmpString("DATA:textured3D.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->GetAttribute("EW_color");
|
||||
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
|
||||
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
|
||||
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::Area::Draw(void)
|
||||
{
|
||||
if (m_coord.Size()<=0) {
|
||||
//EWOL_WARNING("Nothink to draw...");
|
||||
return;
|
||||
}
|
||||
if (m_resource == NULL) {
|
||||
// this is a normale case ... the user can choice to have no image ...
|
||||
return;
|
||||
}
|
||||
if (m_GLprogram==NULL) {
|
||||
EWOL_ERROR("No shader ...");
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 tmpMatrix = ewol::openGL::GetMatrix()*m_matrixApply;
|
||||
m_GLprogram->Use();
|
||||
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
|
||||
// TextureID
|
||||
m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId());
|
||||
// position :
|
||||
m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z,unused*/, &m_coord[0], 4*sizeof(btScalar));
|
||||
// Texture :
|
||||
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]);
|
||||
// color :
|
||||
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
|
||||
// Request the draw od the elements :
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
|
||||
m_GLprogram->UnUse();
|
||||
}
|
||||
|
||||
void ewol::Area::Clear(void)
|
||||
{
|
||||
// call upper class
|
||||
ewol::Compositing::Clear();
|
||||
// Reset Buffer :
|
||||
m_coord.Clear();
|
||||
m_coordTex.Clear();
|
||||
m_coordColor.Clear();
|
||||
// Reset temporal variables :
|
||||
m_position = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
|
||||
vec3 ewol::Area::GetPos(void)
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
|
||||
void ewol::Area::SetPos(vec3 pos)
|
||||
{
|
||||
m_position = pos;
|
||||
}
|
||||
|
||||
|
||||
void ewol::Area::SetRelPos(vec3 pos)
|
||||
{
|
||||
m_position += pos;
|
||||
}
|
||||
|
||||
|
||||
void ewol::Area::Print(ivec2 size)
|
||||
{
|
||||
vec3 point(0,0,0);
|
||||
vec2 tex(0,1);
|
||||
|
||||
point.setX(m_position.x());
|
||||
point.setY(m_position.y());
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
|
||||
|
||||
tex.setValue(1,1);
|
||||
point.setX(m_position.x() + size.x());
|
||||
point.setY(m_position.y());
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
|
||||
|
||||
tex.setValue(1,0);
|
||||
point.setX(m_position.x() + size.x());
|
||||
point.setY(m_position.y() + size.y());
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
|
||||
tex.setValue(0,0);
|
||||
point.setX(m_position.x());
|
||||
point.setY(m_position.y() + size.y());
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
|
||||
tex.setValue(0,1);
|
||||
point.setX(m_position.x());
|
||||
point.setY(m_position.y());
|
||||
m_coord.PushBack(point);
|
||||
m_coordTex.PushBack(tex);
|
||||
m_coordColor.PushBack(m_color);
|
||||
}
|
||||
|
||||
|
87
sources/ewol/compositing/Area.h
Normal file
87
sources/ewol/compositing/Area.h
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_COMPOSITING_AREA_H__
|
||||
#define __EWOL_COMPOSITING_AREA_H__
|
||||
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/compositing/Compositing.h>
|
||||
#include <ewol/renderer/ResourceManager.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
class Area : public ewol::Compositing
|
||||
{
|
||||
private:
|
||||
vec3 m_position; //!< The current position to draw
|
||||
draw::Color m_color; //!< The text foreground color
|
||||
private:
|
||||
ewol::Program* m_GLprogram; //!< pointer on the opengl display program
|
||||
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
|
||||
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
|
||||
int32_t m_GLColor; //!< openGL id on the element (color buffer)
|
||||
int32_t m_GLtexture; //!< openGL id on the element (Texture position)
|
||||
int32_t m_GLtexID; //!< openGL id on the element (texture ID)
|
||||
private:
|
||||
ewol::Texture* m_resource; //!< texture resources
|
||||
etk::Vector<vec3 > m_coord; //!< internal coord of the object
|
||||
etk::Vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
|
||||
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
|
||||
private:
|
||||
/**
|
||||
* @brief Load the openGL program and get all the ID needed
|
||||
*/
|
||||
void LoadProgram(void);
|
||||
public:
|
||||
/**
|
||||
* @brief generic constructor
|
||||
* @param[in] imageName Name of the file that might be loaded
|
||||
*/
|
||||
Area(ivec2 size);
|
||||
/**
|
||||
* @brief generic destructor
|
||||
*/
|
||||
~Area(void);
|
||||
public:
|
||||
/**
|
||||
* @brief Draw All the refistered text in the current element on openGL
|
||||
*/
|
||||
void Draw(void);
|
||||
/**
|
||||
* @brief Clear alll tre registered element in the current element
|
||||
*/
|
||||
void Clear(void);
|
||||
/**
|
||||
* @brief Get the current display position (sometime needed in the gui control)
|
||||
* @return the current position.
|
||||
*/
|
||||
vec3 GetPos(void);
|
||||
/**
|
||||
* @brief Set position for the next text writen
|
||||
* @param[in] pos Position of the text (in 3D)
|
||||
*/
|
||||
void SetPos(vec3 pos);
|
||||
/**
|
||||
* @brief Set relative position for the next text writen
|
||||
* @param[in] pos ofset apply of the text (in 3D)
|
||||
*/
|
||||
void SetRelPos(vec3 pos);
|
||||
/**
|
||||
* @brief Add a compleate of the image to display with the requested size
|
||||
* @param[in] size Size of the output image
|
||||
*/
|
||||
void Print(ivec2 size);
|
||||
|
||||
draw::Image& Get(void) { return m_resource->Get(); };
|
||||
void Flush(void) { m_resource->Flush(); };
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,27 +18,26 @@ namespace ewol
|
||||
class Image : public ewol::Compositing
|
||||
{
|
||||
private:
|
||||
vec3 m_position; //!< The current position to draw
|
||||
vec3 m_clippingPosStart; //!< Clipping start position
|
||||
vec3 m_clippingPosStop; //!< Clipping stop position
|
||||
bool m_clippingEnable; //!< true if the clipping must be activated
|
||||
private:
|
||||
vec3 m_position; //!< The current position to draw
|
||||
vec3 m_clippingPosStart; //!< Clipping start position
|
||||
vec3 m_clippingPosStop; //!< Clipping stop position
|
||||
bool m_clippingEnable; //!< true if the clipping must be activated
|
||||
draw::Color m_color; //!< The text foreground color
|
||||
vec3 m_axes; //!< Rotation axes (instant)
|
||||
float m_angle; //!< Angle to set at the axes
|
||||
private:
|
||||
draw::Color m_color; //!< The text foreground color
|
||||
vec3 m_axes; //!< Rotation axes (instant)
|
||||
float m_angle; //!< Angle to set at the axes
|
||||
ewol::Program* m_GLprogram; //!< pointer on the opengl display program
|
||||
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
|
||||
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
|
||||
int32_t m_GLColor; //!< openGL id on the element (color buffer)
|
||||
int32_t m_GLtexture; //!< openGL id on the element (Texture position)
|
||||
int32_t m_GLtexID; //!< openGL id on the element (texture ID)
|
||||
private:
|
||||
ewol::Program* m_GLprogram; //!< pointer on the opengl display program
|
||||
int32_t m_GLPosition; //!< openGL id on the element (vertex buffer)
|
||||
int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix)
|
||||
int32_t m_GLColor; //!< openGL id on the element (color buffer)
|
||||
int32_t m_GLtexture; //!< openGL id on the element (Texture position)
|
||||
int32_t m_GLtexID; //!< openGL id on the element (texture ID)
|
||||
private:
|
||||
ewol::TextureFile* m_resource; //!< texture resources
|
||||
etk::Vector<vec3 > m_coord; //!< internal coord of the object
|
||||
etk::Vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
|
||||
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
|
||||
ewol::TextureFile* m_resource; //!< texture resources
|
||||
etk::Vector<vec3 > m_coord; //!< internal coord of the object
|
||||
etk::Vector<vec2 > m_coordTex; //!< internal texture coordinate for every point
|
||||
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
|
||||
private:
|
||||
/**
|
||||
* @brief Load the openGL program and get all the ID needed
|
||||
|
@ -57,32 +57,31 @@ void ewol::Texture::UpdateContext(void)
|
||||
if (false == m_loaded) {
|
||||
// Request a new texture at OpenGl :
|
||||
glGenTextures(1, &m_texId);
|
||||
// TODO : check error ???
|
||||
glBindTexture(GL_TEXTURE_2D, m_texId);
|
||||
// TODO : Check error ???
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
//--- mode nearest
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
//--- Mode linear
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
EWOL_INFO("TEXTURE: Add [" << m_uniqueId << "]=" << m_data.GetSize() << " OGl_Id=" <<m_texId);
|
||||
glTexImage2D(GL_TEXTURE_2D, // Target
|
||||
0, // Level
|
||||
GL_RGBA, // Format internal
|
||||
m_data.GetWidth(),
|
||||
m_data.GetHeight(),
|
||||
0, // Border
|
||||
GL_RGBA, // format
|
||||
GL_UNSIGNED_BYTE, // type
|
||||
m_data.GetTextureDataPointer() );
|
||||
// now the data is loaded
|
||||
m_loaded = true;
|
||||
} else {
|
||||
EWOL_TODO("UPDATE Texture ...");
|
||||
}
|
||||
// in all case we set the texture properties :
|
||||
// TODO : check error ???
|
||||
glBindTexture(GL_TEXTURE_2D, m_texId);
|
||||
// TODO : Check error ???
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
//--- mode nearest
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
//--- Mode linear
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
EWOL_INFO("TEXTURE: Add [" << m_uniqueId << "]=" << m_data.GetSize() << " OGl_Id=" <<m_texId);
|
||||
glTexImage2D(GL_TEXTURE_2D, // Target
|
||||
0, // Level
|
||||
GL_RGBA, // Format internal
|
||||
m_data.GetWidth(),
|
||||
m_data.GetHeight(),
|
||||
0, // Border
|
||||
GL_RGBA, // format
|
||||
GL_UNSIGNED_BYTE, // type
|
||||
m_data.GetTextureDataPointer() );
|
||||
// now the data is loaded
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -376,7 +376,7 @@ namespace ewol {
|
||||
// -- Drawing : All drawing must be done in 2 separate buffer 1 for the current display and 1 for the working...
|
||||
// ----------------------------------------------------------------------------------------------------------------
|
||||
protected:
|
||||
bool m_needRegenerateDisplay; //!< the display might be done the next regeneration
|
||||
bool m_needRegenerateDisplay; //!< the display might be done the next regeneration
|
||||
/**
|
||||
* @brief The widget mark itself that it need to regenerate the nest time.
|
||||
*/
|
||||
|
@ -46,7 +46,8 @@ FILE_LIST+= ewol/compositing/Compositing.cpp \
|
||||
ewol/compositing/Image.cpp \
|
||||
ewol/compositing/Sprite.cpp \
|
||||
ewol/compositing/Mesh.cpp \
|
||||
ewol/compositing/Shaper.cpp
|
||||
ewol/compositing/Shaper.cpp \
|
||||
ewol/compositing/Area.cpp
|
||||
|
||||
|
||||
# all widgets
|
||||
|
Loading…
x
Reference in New Issue
Block a user