shader work on PC for OObject textured and colored

This commit is contained in:
Edouard DUPIN 2012-08-28 18:16:09 +02:00
parent fd86f42454
commit 68a53a7068
32 changed files with 574 additions and 439 deletions

@ -1 +1 @@
Subproject commit 63cab9e476494878fa3e946734334e2522816a6e
Subproject commit 80585116ed17a8ead625d229e40ecef37783c7bb

View File

@ -36,8 +36,16 @@ namespace ewol
protected:
etk::UString m_name;
uint32_t m_counter;
uint32_t m_uniqueId;
public:
Resource(etk::UString& filename) : m_name(filename), m_counter(1) { };
Resource(etk::UString& filename) :
m_name(filename),
m_counter(1)
{
static uint32_t valBase=0;
m_uniqueId = valBase;
valBase++;
};
virtual ~Resource(void) { };
virtual bool HasName(etk::UString& fileName)
{
@ -48,6 +56,10 @@ namespace ewol
void Increment(void) { m_counter++; };
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
virtual const char* GetType(void) { return "unknow"; };
virtual void UpdateContext(void) { };
virtual void RemoveContext(void) { };
virtual void RemoveContextToLate(void) { };
uint32_t GetUID(void) { return m_uniqueId; };
};
};

View File

@ -29,7 +29,8 @@
#include <ewol/font/FontFreeType.h>
static etk::Vector<ewol::Resource*> l_resourceList;
static etk::Vector<ewol::Resource*> l_resourceListToUpdate;
static bool l_contextHasBeenRemoved = true;
void ewol::resource::Init(void)
{
@ -38,14 +39,18 @@ void ewol::resource::Init(void)
if (l_resourceList.Size() != 0) {
EWOL_CRITICAL("Start with a resource manager Not empty, number of resources loaded : " << l_resourceList.Size());
}
l_resourceListToUpdate.Clear();
l_resourceList.Clear();
l_contextHasBeenRemoved = true;
}
void ewol::resource::UnInit(void)
{
// remove textured font ...
l_resourceListToUpdate.Clear();
// remove all resources ...
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
if (l_resourceList[iii] != NULL) {
EWOL_WARNING("Find a resource that is not removed : [" << l_resourceList[iii]->GetUID() << "]");
delete(l_resourceList[iii]);
l_resourceList[iii] = NULL;
}
@ -53,6 +58,60 @@ void ewol::resource::UnInit(void)
l_resourceList.Clear();
}
void ewol::resource::Update(ewol::Resource* object)
{
// chek if not added before
for (int32_t iii=0; iii<l_resourceListToUpdate.Size(); iii++) {
if (l_resourceListToUpdate[iii] != NULL) {
if (l_resourceListToUpdate[iii] == object) {
// just prevent some double add ...
return;
}
}
}
// add it ...
l_resourceListToUpdate.PushBack(object);
}
// Specific to load or update the data in the openGl context ==> system use only
void ewol::resource::UpdateContext(void)
{
if (true == l_contextHasBeenRemoved) {
// need to update all ...
l_contextHasBeenRemoved = false;
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
if (l_resourceList[iii] != NULL) {
l_resourceList[iii]->UpdateContext();
}
}
}else {
for (int32_t iii=0; iii<l_resourceListToUpdate.Size(); iii++) {
if (l_resourceListToUpdate[iii] != NULL) {
l_resourceListToUpdate[iii]->UpdateContext();
}
}
}
// Clean the update list
l_resourceListToUpdate.Clear();
}
// in this case, it is really too late ...
void ewol::resource::ContextHasBeenDestroyed(void)
{
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
if (l_resourceList[iii] != NULL) {
l_resourceList[iii]->RemoveContextToLate();
}
}
// no context preent ...
l_contextHasBeenRemoved = true;
}
// internal generic keeper ...
static ewol::Resource* LocalKeep(etk::UString& filename)
{
@ -72,13 +131,14 @@ static ewol::Resource* LocalKeep(etk::UString& filename)
// internal generic keeper ...
static void LocalAdd(ewol::Resource* object)
{
EWOL_VERBOSE("Add ... find empty slot");
//Add ... find empty slot
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
if (l_resourceList[iii] == NULL) {
l_resourceList[iii] = object;
return;
}
}
// add at the end if no slot is free
l_resourceList.PushBack(object);
}
@ -154,6 +214,42 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
return true;
}
bool ewol::resource::Keep(ewol::Texture*& object)
{
// this element create a new one every time ....
object = new ewol::Texture("");
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??");
return false;
}
LocalAdd(object);
return true;
}
bool ewol::resource::Keep(etk::UString& filename, ewol::TextureFile*& object, Vector2D<int32_t> size)
{
etk::UString TmpFilename = filename;
TmpFilename += ":";
TmpFilename += size.x;
TmpFilename += "x";
TmpFilename += size.y;
EWOL_VERBOSE("KEEP : TectureFile : file : \"" << TmpFilename << "\"");
object = static_cast<ewol::TextureFile*>(LocalKeep(TmpFilename));
if (NULL != object) {
return true;
}
// need to crate a new one ...
object = new ewol::TextureFile(TmpFilename, filename, size);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << filename);
return false;
}
LocalAdd(object);
return true;
}
void ewol::resource::Release(ewol::Resource*& object)
{
@ -161,6 +257,12 @@ void ewol::resource::Release(ewol::Resource*& object)
EWOL_ERROR("Try to remove a resource that have null pointer ...");
return;
}
for (int32_t iii=0; iii<l_resourceListToUpdate.Size(); iii++) {
if (l_resourceListToUpdate[iii] == object) {
l_resourceListToUpdate[iii] = NULL;
l_resourceListToUpdate.Erase(iii);
}
}
EWOL_VERBOSE("RELEASE (default) : file : \"" << object->GetName() << "\"");
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
if (l_resourceList[iii] != NULL) {
@ -202,6 +304,18 @@ void ewol::resource::Release(ewol::Program*& object)
object = NULL;
}
void ewol::resource::Release(ewol::Shader*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Texture*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::TextureFile*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
Release(object2);

View File

@ -32,6 +32,8 @@
#include <ewol/openGL/Program.h>
#include <ewol/font/Font.h>
#include <ewol/font/TexturedFont.h>
#include <ewol/texture/Texture.h>
#include <ewol/texture/TextureFile.h>
namespace ewol
{
@ -39,17 +41,26 @@ namespace ewol
void Init(void);
void UnInit(void);
void Update(ewol::Resource* object);
// Specific to load or update the data in the openGl context ==> system use only
void UpdateContext(void);
void ContextHasBeenDestroyed(void);
// return the type of the resource ...
bool Keep(etk::UString& filename, ewol::TexturedFont*& object);
bool Keep(etk::UString& filename, ewol::Font*& object);
bool Keep(etk::UString& filename, ewol::Program*& object);
bool Keep(etk::UString& filename, ewol::Shader*& object);
bool Keep(ewol::Texture*& object); // no name needed here ...
bool Keep(etk::UString& filename, ewol::TextureFile*& object, Vector2D<int32_t> size);
void Release(ewol::Resource*& object);
void Release(ewol::TexturedFont*& object);
void Release(ewol::Font*& object);
void Release(ewol::Program*& object);
void Release(ewol::Shader*& object);
void Release(ewol::Texture*& object);
void Release(ewol::TextureFile*& object);
}
};

View File

@ -57,7 +57,7 @@ static int32_t simpleSQRT(int32_t value)
ewol::TexturedFont::TexturedFont(etk::UString fontName) :
ewol::Resource(fontName),
ewol::Texture(fontName),
m_font(NULL),
m_lastGlyphPos(0,0),
m_lastRawHeigh(0)
@ -80,6 +80,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
}
m_name = fontName.Extract(0, (tmpPos - tmpData));
m_size = tmpSize;
//EWOL_CRITICAL("Load FONT name : \"" << m_name << "\" ==> size=" << m_size);
ewol::resource::Keep(m_name, m_font);
if (NULL == m_font) {
@ -99,9 +100,6 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
iii = 0x9F;
}
}
// get the pointer on the image :
draw::Image& myImage = m_texture.Get();
/* this is a bad code for now ... */
// ==> determine the texture Size
@ -124,10 +122,10 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
int32_t textureHeight = nextP2(nbLine*glyphMaxHeight);
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
// resize must be done on the texture ...
m_texture.SetImageSize(Vector2D<int32_t>(textureWidth,textureHeight));
SetImageSize(Vector2D<int32_t>(textureWidth,textureHeight));
// now we can acces directly on the image
myImage.SetFillColor(draw::Color(0xFFFFFF00));
myImage.Clear();
m_data.SetFillColor(draw::Color(0xFFFFFF00));
m_data.Clear();
m_height = m_font->GetHeight(m_size);
@ -138,7 +136,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
/*
// check internal property:
// enought in the texture :
//if (myImage.GetWidth() < m_lastGlyphPos.x + m_listElement[iii].property.m_sizeTexture.x
//if (m_data.GetWidth() < m_lastGlyphPos.x + m_listElement[iii].property.m_sizeTexture.x
// resize if needed ...
// line size :
@ -154,7 +152,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
CurrentLineHigh = 0;
}
// draw the glyph
m_font->DrawGlyph(myImage, m_size, glyphPosition, m_listElement[iii].property);
m_font->DrawGlyph(m_data, m_size, glyphPosition, m_listElement[iii].property);
// set video position
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight;
@ -184,16 +182,16 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
for(int32_t jjj=0; jjj < textureHeight;jjj++) {
for(int32_t iii=0; iii < textureWidth; iii++){
tlpppp = myImage.Get(Vector2D<int32_t>(iii, jjj) );
tlpppp = m_data.Get(Vector2D<int32_t>(iii, jjj) );
// set only alpha :
tlpppp.a = etk_min( tlpppp.a+0x60, 0xFF);
// real set of color
myImage.Set(Vector2D<int32_t>(iii, jjj), tlpppp );
m_data.Set(Vector2D<int32_t>(iii, jjj), tlpppp );
}
}
#endif
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
m_texture.Flush();
Flush();
// initilize the texture ...
// TODO : Do a better methode that not initialize with a stupid language ... like now ...

View File

@ -33,7 +33,7 @@
namespace ewol
{
class TexturedFont : public ewol::Resource {
class TexturedFont : public ewol::Texture {
typedef struct {
GlyphProperty property;
@ -44,7 +44,6 @@ namespace ewol
int32_t m_size;
int32_t m_height;
ewol::Font* m_font;
ewol::Texture m_texture;
etk::Vector<freeTypeFontElement_ts> m_listElement;
// for the texture generation :
Vector2D<int32_t> m_lastGlyphPos;
@ -68,7 +67,6 @@ namespace ewol
// TODO : Remove this element, it is stupid ...
int32_t GetHeight(void) { return m_height; };
int32_t GetFontSize(void) { return m_size; };
ewol::Texture& GetTex(void) { return m_texture; };
};

View File

@ -35,6 +35,14 @@ ewol::OObject2DColored::OObject2DColored(void)
{
m_triElement = 0;
SetColor(1.0, 1.0, 1.0, 1.0);
etk::UString tmpString("color.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
//m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
}
}
@ -42,6 +50,7 @@ ewol::OObject2DColored::~OObject2DColored(void)
{
m_coord.Clear();
m_coordColor.Clear();
ewol::resource::Release(m_GLprogram);
}
@ -50,6 +59,37 @@ void ewol::OObject2DColored::Draw(void)
if (m_coord.Size()<=0) {
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
#if 1
glPushMatrix();
glScalef(m_scaling.x, m_scaling.y, 1.0);
m_GLprogram->Use();
// position :
glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL
2, // number of elements per vertex, here (x,y)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
&m_coord[0]); // Pointer on the buffer
glEnableVertexAttribArray(m_GLPosition);
// color :
glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL
4, // number of elements per vertex, here (r,g,b,a)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
&m_coordColor[0]); // Pointer on the buffer
glEnableVertexAttribArray(m_GLColor);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
glPopMatrix();
#else
glPushMatrix();
// Enable Pointers
glEnableClientState( GL_VERTEX_ARRAY );
@ -60,7 +100,7 @@ void ewol::OObject2DColored::Draw(void)
// Set the vertex pointer to our vertex data
glVertexPointer(2, GL_FLOAT, 0, &m_coord[0] );
//glColorPointer(4, oglTypeFloat_t, 0, &m_coordColor[0] );
glColorPointer(4, GL_UNSIGNED_BYTE, 0, &m_coordColor[0] );
glColorPointer(4, GL_FLOAT, 0, &m_coordColor[0] );
// Render : draw all of the triangles at once
glDrawArrays( GL_TRIANGLES, 0, m_coord.Size());
//glDrawElements( GL_TRIANGLES, 0, m_coord.Size());
@ -70,6 +110,7 @@ void ewol::OObject2DColored::Draw(void)
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
glPopMatrix();
#endif
}
@ -300,14 +341,15 @@ void ewol::OObject2DColored::GenerateTriangle(void)
void ewol::OObject2DColored::SetColor(draw::Color color)
{
draw::Colorf colorf = color;
if (m_triElement < 1) {
m_color[0] = color;
m_color[0] = colorf;
}
if (m_triElement < 2) {
m_color[1] = color;
m_color[1] = colorf;
}
if (m_triElement < 3) {
m_color[2] = color;
m_color[2] = colorf;
}
}
@ -392,7 +434,12 @@ void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float
void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h)
{
ResetCount();
/*
x += 3;
y += 3;
w -= 6;
h -= 6;
*/
/* Bitmap position
* xA xB
* yC *------*

View File

@ -26,6 +26,7 @@
#define __EWOL_O_OBJECT_2D_COLORED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DColored :public ewol::OObject
@ -36,11 +37,15 @@ namespace ewol {
public:
virtual void Draw(void);
protected:
ewol::Program* m_GLprogram;
GLint m_GLPosition;
GLint m_GLMatrix;
GLint m_GLColor;
etk::Vector<Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<draw::Color> m_coordColor; //!< internal color of the different point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
//etk::Vector<linkCoord_ts> m_linkCoord; //!< internal link between point to generate triangle
int32_t m_triElement;
draw::Color m_color[3];
draw::Colorf m_color[3];
Vector2D<float> m_triangle[3];
void GenerateTriangle(void);
void ResetCount(void);

View File

@ -99,8 +99,12 @@ void ewol::OObject2DTextColored::Draw(void)
//EWOL_WARNING("Nothink to draw...");
return;
}
if (m_font == NULL) {
EWOL_WARNING("no font...");
return;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_font->GetTex().GetId());
glBindTexture(GL_TEXTURE_2D, m_font->GetId());
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays

View File

@ -23,8 +23,7 @@
*/
#include <ewol/oObject/2DTextured.h>
#include <ewol/texture/Texture.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/ResourceManager.h>
#include <ewol/openGL/openGL.h>
#undef __class__
@ -34,15 +33,28 @@
ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, float sizeX, float sizeY)
{
EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\"");
m_resource = ewol::textureManager::ImageKeep(textureName, Vector2D<int32_t>(sizeX,sizeY));
if (false == ewol::resource::Keep(textureName, m_resource, Vector2D<int32_t>(sizeX,sizeY)) ) {
EWOL_CRITICAL("can not get a resource Texture");
}
etk::UString tmpString("textured.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
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");
}
}
ewol::OObject2DTextured::~OObject2DTextured(void)
{
if (NULL != m_resource) {
ewol::textureManager::ImageRelease(m_resource);
ewol::resource::Release(m_resource);
}
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject2DTextured::Draw(void)
@ -54,6 +66,52 @@ void ewol::OObject2DTextured::Draw(void)
EWOL_WARNING("Texture does not exist ...");
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
#if 1
glColor4f(1.0, 1.0, 1.0, 1.0);
m_GLprogram->Use();
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_resource->GetId());
// TextureID
glUniform1i(m_GLtexID, /*GL_TEXTURE*/0);
// position :
glVertexAttribPointer(m_GLPosition, // attribute ID of OpenGL
2, // number of elements per vertex, here (x,y)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
&m_coord[0]); // Pointer on the buffer
glEnableVertexAttribArray(m_GLPosition);
// Texture :
glVertexAttribPointer(m_GLtexture, // attribute ID of OpenGL
2, // number of elements per vertex, here (u,v)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
&m_coordTex[0]); // Pointer on the buffer
glEnableVertexAttribArray(m_GLtexture);
// color :
glVertexAttribPointer(m_GLColor, // attribute ID of OpenGL
4, // number of elements per vertex, here (r,g,b,a)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
&m_coordColor[0]); // Pointer on the buffer
glEnableVertexAttribArray(m_GLColor);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
glDisable(GL_TEXTURE_2D);
m_GLprogram->UnUse();
#else
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
//EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId));
@ -70,6 +128,7 @@ void ewol::OObject2DTextured::Draw(void)
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
glDisable(GL_TEXTURE_2D);
#endif
}
void ewol::OObject2DTextured::Clear(void)
@ -86,6 +145,12 @@ void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, draw
void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, float texX, float texY, float texSX, float texSY, draw::Color tmpColor)
{
/*
x += 3;
y += 3;
w -= 6;
h -= 6;
*/
//EWOL_DEBUG("Add rectangle : ...");
Vector2D<float> point;
texCoord_ts tex;

View File

@ -26,7 +26,7 @@
#define __EWOL_O_OBJECT_2D_TEXTURED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/texture/Texture.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DTextured :public ewol::OObject
@ -40,7 +40,13 @@ namespace ewol {
void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0, draw::Color tmpColor=draw::color::white);
void Rectangle(float x, float y, float w, float h, draw::Color tmpColor);
protected:
ewol::Texture* m_resource; //!< texture resources
ewol::Program* m_GLprogram;
GLint m_GLPosition;
GLint m_GLMatrix;
GLint m_GLColor;
GLint m_GLtexture;
GLint m_GLtexID;
ewol::TextureFile* m_resource; //!< texture resources
etk::Vector<Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Color> m_coordColor; //!< internal color of the different point

View File

@ -23,8 +23,7 @@
*/
#include <ewol/oObject/Sprite.h>
#include <ewol/texture/Texture.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/ResourceManager.h>
#include <ewol/openGL/openGL.h>
#include <math.h>
@ -36,14 +35,16 @@ ewol::Sprite::Sprite(etk::UString spriteName, float sizeX, float sizeY)
{
m_name = spriteName;
EWOL_VERBOSE("Create Sprite : \"" << m_name << "\"");
m_resource = ewol::textureManager::ImageKeep(m_name, Vector2D<int32_t>(sizeX,sizeY));
if (false == ewol::resource::Keep(m_name, m_resource, Vector2D<int32_t>(sizeX,sizeY)) ) {
EWOL_CRITICAL("can not get a resource Texture");
}
}
ewol::Sprite::~Sprite(void)
{
if (NULL != m_resource) {
ewol::textureManager::ImageRelease(m_resource);
ewol::resource::Release(m_resource);
}
}

View File

@ -26,7 +26,7 @@
#define __EWOL_O_OBJECT_SPRITE_H__
#include <ewol/oObject/OObject.h>
#include <ewol/texture/Texture.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class Sprite :public ewol::OObject
@ -44,7 +44,7 @@ namespace ewol {
void Element(Vector3D<float> pos, float size, float angle, draw::Color tmpColor);
bool HasName(etk::UString& name) { return name == m_name; };
protected:
ewol::Texture* m_resource; //!< texture resources
ewol::TextureFile* m_resource; //!< texture resources
etk::Vector<Vector3D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Color> m_coordColor; //!< internal color of the different point

View File

@ -131,4 +131,55 @@ bool ewol::Program::CreateAndLink(void)
return true;
}
// TODO : Set it dynamic to prevent reload system error ...
GLint ewol::Program::GetAttribute(etk::UString& tmpElement)
{
GLint elem = glGetAttribLocation(m_program, tmpElement.c_str());
if (elem<0) {
checkGlError("glGetAttribLocation");
EWOL_INFO("glGetAttribLocation(\"" << tmpElement << "\") = " << elem);
}
return elem;
}
GLint ewol::Program::GetAttribute(const char* tmpElement)
{
GLint elem = glGetAttribLocation(m_program, tmpElement);
if (elem<0) {
checkGlError("glGetAttribLocation");
EWOL_INFO("glGetAttribLocation(\"" << tmpElement << "\") = " << elem);
}
return elem;
}
GLint ewol::Program::GetUniform(etk::UString& tmpElement)
{
GLint elem = glGetUniformLocation(m_program, tmpElement.c_str());
if (elem<0) {
checkGlError("glGetUniformLocation");
EWOL_INFO("glGetUniformLocation(\"" << tmpElement << "\") = " << elem);
}
return elem;
}
GLint ewol::Program::GetUniform(const char* tmpElement)
{
GLint elem = glGetUniformLocation(m_program, tmpElement);
if (elem<0) {
checkGlError("glGetUniformLocation");
EWOL_INFO("glGetUniformLocation(\"" << tmpElement << "\") = " << elem);
}
return elem;
}
void ewol::Program::Use(void)
{
glUseProgram(m_program);
checkGlError("glUseProgram");
}
void ewol::Program::UnUse(void)
{
glUseProgram(0);
checkGlError("glUseProgram");
}

View File

@ -44,6 +44,12 @@ namespace ewol
const char* GetType(void) { return "ewol::Program"; };
GLuint GetGL_ID(void) { return m_program; };
bool CreateAndLink(void);
GLint GetAttribute(etk::UString& tmpElement);
GLint GetAttribute(const char* tmpElement);
GLint GetUniform(etk::UString& tmpElement);
GLint GetUniform(const char* tmpElement);
void Use(void);
void UnUse(void);
};
};

View File

@ -26,14 +26,14 @@
#include <ewol/openGL/openGL.h>
void glOrthoEwol(GLfloat left,
void glOrthoMatrix(GLfloat left,
GLfloat right,
GLfloat bottom,
GLfloat top,
GLfloat nearVal,
GLfloat farVal)
GLfloat farVal,
GLfloat* myMatrix)
{
GLfloat myMatrix[4*4];
int iii;
for(iii=0; iii<4*4 ; iii++) {
myMatrix[iii] = 0;
@ -52,12 +52,127 @@ void glOrthoEwol(GLfloat left,
myMatrix[14] = -1*(farVal + nearVal) / (farVal - nearVal);
#endif
myMatrix[15] = 1;
glLoadMatrixf(myMatrix);
}
void glOrthoEwol(GLfloat left,
GLfloat right,
GLfloat bottom,
GLfloat top,
GLfloat nearVal,
GLfloat farVal)
{
GLfloat myMatrix[4*4];
glOrthoMatrix(left, right, bottom, top, nearVal, farVal, myMatrix);
glLoadMatrixf(myMatrix);
}
ewol::OglMatrix::OglMatrix(float left, float right, float bottom, float top, float nearVal, float farVal)
{
Generate(left, right, bottom, top, nearVal, farVal);
}
void ewol::OglMatrix::Generate(float left, float right, float bottom, float top, float nearVal, float farVal)
{
int iii;
for(iii=0; iii<4*4 ; iii++) {
m_Matrix[iii] = 0;
}
m_Matrix[0] = 2.0 / (right - left);
m_Matrix[5] = 2.0 / (top - bottom);
m_Matrix[10] = -2.0 / (farVal - nearVal);
m_Matrix[3] = -1*(right + left) / (right - left);
m_Matrix[7] = -1*(top + bottom) / (top - bottom);
m_Matrix[11] = -1*(farVal + nearVal) / (farVal - nearVal);
m_Matrix[15] = 1;
}
ewol::OglMatrix::~OglMatrix()
{
}
//http://www.siteduzero.com/tutoriel-3-5003-les-matrices.html
static void MultiplyMatrix(float* inOut, float* mult)
{
// output Matrix
float matrixOut[4*4];
for(int32_t jjj=0; jjj<4 ; jjj++) {
float* tmpLeft = inOut + jjj*4;
for(int32_t iii=0; iii<4 ; iii++) {
float* tmpUpper = mult+iii;
float* tmpLeft2 = tmpLeft;
float tmpElement = 0;
for(int32_t kkk=0; kkk<4 ; kkk++) {
tmpElement += *tmpUpper * *tmpLeft2;
tmpUpper += 4;
tmpLeft2++;
}
matrixOut[jjj*4+iii] = tmpElement;
}
}
// set it at the output
for(int32_t iii=0; iii<4*4 ; iii++) {
inOut[iii] = matrixOut[iii];
}
}
void ewol::OglMatrix::Translate(float x, float y, float z)
{
float matrix[4*4];
for(int32_t iii=0; iii<4*4 ; iii++) {
matrix[iii] = 0;
}
// set identity :
matrix[0] = 1;
matrix[5] = 1;
matrix[10] = 1;
matrix[15] = 1;
// set translation :
matrix[3] = x;
matrix[7] = y;
matrix[11] = y;
// generate output :
MultiplyMatrix(m_Matrix, matrix);
}
void ewol::OglMatrix::Scale(float x, float y, float z)
{
float matrix[4*4];
for(int32_t iii=0; iii<4*4 ; iii++) {
matrix[iii] = 0;
}
// set identity :
matrix[0] = 1;
matrix[5] = 1;
matrix[10] = 1;
matrix[15] = 1;
// set scale :
matrix[0] = x;
matrix[5] = y;
matrix[10] = z;
// generate output :
MultiplyMatrix(m_Matrix, matrix);
}
void ewol::OglMatrix::rotate(float x, float y, float z, float angle)
{
float matrix[4*4];
for(int32_t iii=0; iii<4*4 ; iii++) {
matrix[iii] = 0;
}
// set identity :
matrix[0] = 1;
matrix[5] = 1;
matrix[10] = 1;
matrix[15] = 1;
// TODO ...
// generate output :
MultiplyMatrix(m_Matrix, matrix);
}
static void printGLString(const char *name, GLenum s)
{
const char *v = (const char *) glGetString(s);
@ -119,12 +234,9 @@ void TEST_renderFrame(void)
}
glClearColor(grey, grey, grey, 1.0f);
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if (NULL != l_program) {
glUseProgram(l_program->GetGL_ID());
checkGlError("glUseProgram");
}
l_program->Use();
glVertexAttribPointer( gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, gTriangleVertices);
glEnableVertexAttribArray(gvPositionHandle);
glDrawArrays(GL_TRIANGLES, 0, 3);
l_program->UnUse();
}

View File

@ -52,6 +52,19 @@ extern "C" {
void glOrthoEwol(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearVal, GLfloat farVal);
namespace ewol {
class OglMatrix{
public :
float m_Matrix[4*4];
OglMatrix(float left, float right, float bottom, float top, float nearVal, float farVal);
~OglMatrix();
void Generate(float left, float right, float bottom, float top, float nearVal, float farVal);
void Translate(float x=0.0, float y=0.0, float z=0.0);
void Scale(float x=1.0, float y=1.0, float z=1.0);
void rotate(float x, float y, float z, float angle=0.0);
};
};
bool TESTsetupGraphics(int w, int h);
void TEST_renderFrame(void);

View File

@ -30,7 +30,7 @@
#include <etk/MessageFifo.h>
#include <ewol/os/eSystem.h>
#include <ewol/os/gui.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/ResourceManager.h>
#include <ewol/eObject/EObject.h>
#include <ewol/eObject/EObjectManager.h>
#include <ewol/widget/WidgetManager.h>
@ -243,7 +243,7 @@ void eSystem::Init(void)
ewol::EObjectManager::Init();
ewol::EObjectMessageMultiCast::Init();
l_managementInput.Reset();
ewol::textureManager::Init();
ewol::resource::Init();
ewol::widgetManager::Init();
ewol::font::Init();
ewol::shortCut::Init();
@ -270,7 +270,7 @@ void eSystem::UnInit(void)
ewol::font::UnInit();
ewol::EObjectMessageMultiCast::UnInit();
ewol::EObjectManager::UnInit();
ewol::textureManager::UnInit();
ewol::resource::UnInit();
l_managementInput.Reset();
l_msgSystem.Clean();
}
@ -526,7 +526,7 @@ bool eSystem::Draw(bool displayEveryTime)
// FPS display system
l_FpsSystem.Tic();
if (true == isGlobalSystemInit) {
/*
#if 1
// process the events
ewolProcessEvents();
// call all the widget that neded to do something periodicly
@ -544,13 +544,14 @@ bool eSystem::Draw(bool displayEveryTime)
// check if the regenerate is needed ...
if( true == ewol::widgetManager::IsDrawingNeeded()
|| true == displayEveryTime) {
ewol::textureManager::UpdateContext();
ewol::resource::UpdateContext();
l_FpsSystem.IncrementCounter();
tmpWindows->SysDraw();
}
}
*/
#else
TEST_renderFrame();
#endif
glFlush();
}
// FPS display system
@ -587,7 +588,7 @@ void eSystem::ResetIOEvent(void)
*/
void eSystem::OpenGlContextDestroy(void)
{
ewol::textureManager::OpenGlContextHasBeenDestroyed();
ewol::resource::ContextHasBeenDestroyed();
}

View File

@ -30,7 +30,7 @@
#include <ewol/widget/WidgetManager.h>
#include <ewol/os/gui.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/ResourceManager.h>
#include <ewol/os/eSystem.h>
#include <unistd.h>

View File

@ -25,7 +25,6 @@
#include <ewol/texture/Texture.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/openGL/openGL.h>
#include <ewol/ewol.h>
@ -51,11 +50,9 @@ static int32_t nextP2(int32_t value)
ewol::Texture::Texture(void)
ewol::Texture::Texture(etk::UString tmpName) :
Resource(tmpName)
{
// add it to the texture manager
m_uniqueId = ewol::textureManager::Add(this);
m_loaded = false;
m_texId = 0;
m_endPointSize.x = 1.0;
@ -64,10 +61,7 @@ ewol::Texture::Texture(void)
ewol::Texture::~Texture(void)
{
// unregister from the texture manager
ewol::textureManager::Rm(this);
RemoveContext();
}
@ -125,7 +119,7 @@ void ewol::Texture::RemoveContextToLate(void)
void ewol::Texture::Flush(void)
{
// request to the manager to be call at the next update ...
ewol::textureManager::Update(this);
ewol::resource::Update(this);
}
@ -137,90 +131,3 @@ void ewol::Texture::SetImageSize(Vector2D<int32_t> newSize)
}
/*
#include <ewol/texture/TextureBMP.h>
#include <ewol/texture/TextureSVG.h>
#include <ewol/texture/TexturePNG.h>
*/
/**
* @brief Load a specific file texture
* @note : dimention must be a power of 2, otherwise, the display can be wrong... For the SVG, the texture automaticly generate the power of 2 dimention ...
* @param[in] fileName File that might be open
* @param[in] requestedWidth Requested size of the file we desire (if we can not resize it, we load it whit his normal size)
* @return The Internal ID of the texture, or -1 if an error occured ...
*/
// TODO : Load non square texture ...
// TODO : Check the size to regenerate the texture if the size change
#if 0
int32_t ewol::texture::Load(etk::UString tmpfileName, int32_t requestedWidth)
{
int32_t outTextureID = -1;
if (l_listLoadedTexture.Size()!=0) {
for (int32_t iii=0; iii<l_listLoadedTexture.Size(); iii++) {
if (NULL != l_listLoadedTexture[iii]) {
if (l_listLoadedTexture[iii]->m_filename == tmpfileName) {
l_listLoadedTexture[iii]->m_nbTimeLoaded++;
// this prevent the removing of the texture while the cycle is not ended ...
l_listLoadedTexture[iii]->m_destroy = false;
return iii;
}
}
}
}
etk::File fileName(tmpfileName, etk::FILE_TYPE_DATA);
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
// get the upper paw2 ot the size requested...
requestedWidth = nextP2(requestedWidth);
etk::UString fileExtention = fileName.GetExtention();
if (fileExtention == "bmp") {
// create the bitmap texture
ewol::texture::TextureBMP * myBitmap = new ewol::texture::TextureBMP(fileName);
// draw bitmap properties
//myBitmap->Display();
// check if all is OK
if (myBitmap->LoadOK() == true) {
if (myBitmap->Width() != nextP2(myBitmap->Width()) ) {
EWOL_ERROR("Texture has not the good dimention power of 2 : Width=" << myBitmap->Width() << "px ==> maybe not drawable ...");
}
if (myBitmap->Width() != myBitmap->Height()) {
EWOL_ERROR("Texture can not have Width=" << myBitmap->Width() << "px different of height=" << myBitmap->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap->Width(), myBitmap->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap->Data(), myBitmap->DataSize(), tmpfileName);
}
// removet the bitmap handle
delete (myBitmap);
} else if (fileExtention == "svg") {
/*if (requestedWidth < 32) {
requestedWidth = 32;
}*/
// create the bitmap texture
ewol::texture::TextureSVG * mySvg = new ewol::texture::TextureSVG(fileName, requestedWidth, requestedWidth);
// draw bitmap properties
//mySvg->Display();
// check if all is OK
if (mySvg->LoadOK() == true) {
if (mySvg->Width() != mySvg->Height()) {
EWOL_ERROR("Texture can not have Width=" << mySvg->Width() << "px different of height=" << mySvg->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, mySvg->Width(), mySvg->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, mySvg->Data(), mySvg->DataSize(), tmpfileName);
}
// removet the bitmap handle
delete (mySvg);
} else if (fileExtention == "png") {
EWOL_ERROR("Extention not supported now, but soon " << fileName );
} else {
EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp / .svg / .png");
}
}
return outTextureID;
}
#endif

View File

@ -29,11 +29,11 @@
#include <ewol/Debug.h>
#include <draw/Image.h>
#include <ewol/openGL/openGL.h>
#include <ewol/Resource.h>
namespace ewol {
class Texture {
private:
uint32_t m_uniqueId;
class Texture : public ewol::Resource {
protected:
// openGl Context propoerties :
draw::Image m_data;
// OpenGl textureID :
@ -53,7 +53,7 @@ namespace ewol {
Vector2D<float> GetUsableSize(void) { return m_endPointSize; };
// Public API:
public:
Texture(void);
Texture(etk::UString tmpName);
~Texture(void);
// you must set the size here, because it will be set in multiple of pow(2)
void SetImageSize(Vector2D<int32_t> newSize);

View File

@ -22,7 +22,7 @@
*******************************************************************************
*/
#include <ewol/texture/TextureManager.h>
#include <ewol/ResourceManager.h>
#include <ewol/texture/TextureFile.h>
#include <ewol/texture/Texture.h>
@ -32,42 +32,37 @@
//#include <ewol/texture/TexturePNG.h>
ewol::TextureFile::TextureFile(etk::UString tmpfileName, Vector2D<int32_t> size) :
m_counter(1),
m_fileName(tmpfileName)
ewol::TextureFile::TextureFile(etk::UString genName, etk::UString tmpfileName, Vector2D<int32_t> size) :
Texture(genName)
{
// load data
etk::File fileName(tmpfileName, etk::FILE_TYPE_DATA);
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
// get the upper paw2 ot the size requested...
if (size.x>0 && size.y>0) {
m_texture.SetImageSize(size);
SetImageSize(size);
}
etk::UString fileExtention = fileName.GetExtention();
if (fileExtention == "bmp") {
// generate the texture
ewol::imageBMP::GenerateImage(fileName, m_texture.Get());
ewol::imageBMP::GenerateImage(fileName, m_data);
} else if (fileExtention == "svg") {
svg::Parser m_element(fileName);
if (false == m_element.IsLoadOk()) {
EWOL_ERROR("Error To load SVG file " << fileName.GetCompleateName() );
} else {
m_element.GenerateAnImage(size, m_texture.Get());
// generate the texture
m_element.GenerateAnImage(size, m_data);
}
} else if (fileExtention == "png") {
EWOL_ERROR("Extention not supported now, but soon " << fileName );
} else {
EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp / .svg / .png");
}
m_texture.Flush();
Flush();
}
}
ewol::TextureFile::~TextureFile(void)
{
}

View File

@ -28,22 +28,15 @@
#include <etk/UString.h>
#include <draw/Image.h>
#include <ewol/texture/Texture.h>
#include <ewol/Resource.h>
namespace ewol
{
class TextureFile
class TextureFile : public ewol::Texture
{
private:
uint32_t m_counter;
ewol::Texture m_texture;
etk::UString m_fileName;
public:
TextureFile(etk::UString fileName, Vector2D<int32_t> size);
~TextureFile(void);
bool HasName(etk::UString& fileName) { return fileName==m_fileName; };
void Increment(void) { m_counter++; };
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
ewol::Texture& Get(void) { return m_texture; };
TextureFile(etk::UString genName, etk::UString fileName, Vector2D<int32_t> size);
~TextureFile(void) { };
};
};

View File

@ -1,202 +0,0 @@
/**
*******************************************************************************
* @file ewol/texture/textureManager.cpp
* @brief ewol Texture manager system (Sources)
* @author Edouard DUPIN
* @date 21/08/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <etk/File.h>
#include <etk/Vector.h>
#include <ewol/texture/TextureManager.h>
#include <ewol/texture/TextureFile.h>
static etk::Vector<ewol::Texture*> l_textureList;
static etk::Vector<ewol::Texture*> l_textureListToUpdate;
static uint32_t l_uniqueIdTexture = 0;
static bool l_contextHasBeenRemoved = true;
void ewol::textureManager::Init(void)
{
// nothing to do in théory then, we clean the buffers :
// NOTE : If we do domething here, then the system does not work corectly
l_textureList.Clear();
l_textureListToUpdate.Clear();
l_uniqueIdTexture = 0;
l_contextHasBeenRemoved = true;
}
void ewol::textureManager::UnInit(void)
{
l_textureListToUpdate.Clear();
for (int32_t iii=0; iii<l_textureList.Size(); iii++) {
if (l_textureList[iii] != NULL) {
l_textureList[iii]->RemoveContext();
}
}
}
// note : Return the UniqueID ...
uint32_t ewol::textureManager::Add(ewol::Texture *object)
{
if (object==NULL) {
EWOL_CRITICAL("try to add a texture with NULL pointer ...");
return 0;
}
for (int32_t iii=0; iii<l_textureList.Size(); iii++) {
if (l_textureList[iii] != NULL) {
if (l_textureList[iii] == object) {
EWOL_CRITICAL("try to add a texture a second time ...");
return 0;
}
}
}
l_uniqueIdTexture ++;
// add it in the list
l_textureList.PushBack(object);
// add it to be regenerated at the next update :
l_textureListToUpdate.PushBack(object);
// return his ID ...
return l_uniqueIdTexture;
}
void ewol::textureManager::Rm(ewol::Texture *object)
{
if (object==NULL) {
EWOL_CRITICAL("try to remove a texture with NULL pointer ...");
return;
}
for (int32_t iii=l_textureListToUpdate.Size()-1; iii>=0; iii--) {
if (l_textureListToUpdate[iii] != NULL) {
if (l_textureListToUpdate[iii] == object) {
// we find the texture :
l_textureListToUpdate.Erase(iii);
}
}
}
for (int32_t iii=l_textureList.Size()-1; iii>=0; iii--) {
if (l_textureList[iii] != NULL) {
if (l_textureList[iii] == object) {
// we find the texture :
l_textureList.Erase(iii);
return;
}
}
}
EWOL_CRITICAL("Try to remove a texture that is not present in the texture pool");
}
void ewol::textureManager::Update(ewol::Texture *object)
{
// chek if not added before
for (int32_t iii=0; iii<l_textureListToUpdate.Size(); iii++) {
if (l_textureListToUpdate[iii] != NULL) {
if (l_textureListToUpdate[iii] == object) {
// just prevent some double add ...
return;
}
}
}
// add it ...
l_textureListToUpdate.PushBack(object);
}
// Specific to load or update the data in the openGl context ==> system use only
void ewol::textureManager::UpdateContext(void)
{
if (true == l_contextHasBeenRemoved) {
// need to update all ...
l_contextHasBeenRemoved = false;
for (int32_t iii=0; iii<l_textureList.Size(); iii++) {
if (l_textureList[iii] != NULL) {
l_textureList[iii]->UpdateContext();
}
}
}else {
for (int32_t iii=0; iii<l_textureListToUpdate.Size(); iii++) {
if (l_textureListToUpdate[iii] != NULL) {
l_textureListToUpdate[iii]->UpdateContext();
}
}
}
// Clean the update list
l_textureListToUpdate.Clear();
}
void ewol::textureManager::OpenGlContextHasBeenDestroyed(void)
{
for (int32_t iii=0; iii<l_textureList.Size(); iii++) {
if (l_textureList[iii] != NULL) {
l_textureList[iii]->UpdateContext();
}
}
// no context preent ...
l_contextHasBeenRemoved = true;
}
static etk::Vector<ewol::TextureFile *> l_imageList;
// this permit to keep a specific texture and prevent the multiple loading of this one ...
ewol::Texture* ewol::textureManager::ImageKeep(etk::UString fileName, Vector2D<int32_t> size)
{
for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) {
if (l_imageList[iii] != NULL) {
if( l_imageList[iii]->HasName(fileName)
&& l_imageList[iii]->Get().Get().GetWidth() == size.x
&& l_imageList[iii]->Get().Get().GetHeight() == size.y) {
l_imageList[iii]->Increment();
return &l_imageList[iii]->Get();
}
}
}
ewol::TextureFile* tmpResources = new ewol::TextureFile(fileName, size);
if (NULL == tmpResources) {
EWOL_ERROR("allocation error of a resource Image : " << fileName);
return NULL;
}
l_imageList.PushBack(tmpResources);
return &tmpResources->Get();
}
void ewol::textureManager::ImageRelease(ewol::Texture*& object)
{
for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) {
if (l_imageList[iii] != NULL) {
if(&l_imageList[iii]->Get() == object) {
if (true == l_imageList[iii]->Decrement()) {
// delete element
delete(l_imageList[iii]);
// remove element from the list :
l_imageList.Erase(iii);
}
// insidiously remove the pointer for the caller ...
object = NULL;
return;
}
}
}
}

View File

@ -1,51 +0,0 @@
/**
*******************************************************************************
* @file ewol/texture/textureManager.h
* @brief ewol Texture manager system (header)
* @author Edouard DUPIN
* @date 21/08/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EWOL_TEXTURE_MANAGER_H__
#define __EWOL_TEXTURE_MANAGER_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <etk/File.h>
#include <ewol/texture/Texture.h>
namespace ewol
{
namespace textureManager {
void Init(void);
void UnInit(void);
uint32_t Add(ewol::Texture *object); // note : Return the UniqueID ...
void Rm(ewol::Texture *object);
void Update(ewol::Texture *object);
// Specific to load or update the data in the openGl context ==> system use only
void UpdateContext(void);
void OpenGlContextHasBeenDestroyed(void);
// this permit to keep a specific texture and prevent the multiple loading of this one ...
ewol::Texture* ImageKeep(etk::UString fileName, Vector2D<int32_t> size);
void ImageRelease(ewol::Texture*& object);
};
};
#endif

View File

@ -34,7 +34,6 @@ FILE_LIST+= ewol/oObject/OObject.cpp \
# texture management
FILE_LIST+= ewol/texture/Texture.cpp \
ewol/texture/TextureFile.cpp \
ewol/texture/TextureManager.cpp \
ewol/texture/TextureBMP.cpp \
ewol/texture/TexturePNG.cpp \
ewol/texture/TextureSVG.cpp

5
share/color.frag Normal file
View File

@ -0,0 +1,5 @@
varying vec4 f_color;
void main(void) {
gl_FragColor = f_color;
}

2
share/color.prog Normal file
View File

@ -0,0 +1,2 @@
color.vert
color.frag

14
share/color.vert Normal file
View File

@ -0,0 +1,14 @@
// Input :
attribute vec2 EW_coord2d;
attribute vec4 EW_color;
uniform mat4 EW_MatrixTransformation;
// output :
varying vec4 f_color;
void main(void) {
//gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0);
//gl_Position = vec4(EW_coord2d, 0.0, 1.0);
f_color = EW_color;
}

9
share/textured.frag Normal file
View File

@ -0,0 +1,9 @@
// Input :
uniform sampler2D EW_texID;
varying vec2 f_texcoord;
varying vec4 f_color;
void main(void) {
gl_FragColor = texture2D(EW_texID, f_texcoord);// * f_color;
}

2
share/textured.prog Normal file
View File

@ -0,0 +1,2 @@
textured.vert
textured.frag

18
share/textured.vert Normal file
View File

@ -0,0 +1,18 @@
// Input :
attribute vec2 EW_coord2d;
attribute vec2 EW_texture2d;
attribute vec4 EW_color;
uniform mat4 EW_MatrixTransformation;
// output :
varying vec4 f_color;
varying vec2 f_texcoord;
void main(void) {
//gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0);
// set texture output coord
f_texcoord = EW_texture2d;
// set output color :
f_color = EW_color;
}