[DEV] change resource property

This commit is contained in:
Edouard DUPIN 2013-09-06 21:51:24 +02:00
parent 0d4cd4749b
commit a131e75b28
32 changed files with 666 additions and 520 deletions

2
external/ege vendored

@ -1 +1 @@
Subproject commit 274ad28f95c936d4fbc1e3843c14668b71be2024
Subproject commit 48099a92bb36496f1b2399bc8793b08fd7438748

View File

@ -45,7 +45,7 @@ ewol::Material::Material(void) :
ewol::Material::~Material(void)
{
if(NULL!=m_texture0) {
ewol::resource::Release(m_texture0);
ewol::TextureFile::Release(m_texture0);
}
}
@ -65,8 +65,8 @@ void ewol::Material::SetTexture0(const etk::UString& _filename)
ivec2 tmpSize(256, 256);
// prevent overloard error :
ewol::TextureFile* tmpCopy = m_texture0;
m_texture0 = NULL;
if (false == ewol::resource::Keep(_filename, m_texture0, tmpSize)) {
m_texture0 = ewol::TextureFile::Keep(_filename, tmpSize);
if (NULL == m_texture0 ) {
EWOL_ERROR("Can not load specific texture : " << _filename);
// retreave previous texture:
m_texture0 = tmpCopy;
@ -74,7 +74,7 @@ void ewol::Material::SetTexture0(const etk::UString& _filename)
}
if (NULL != tmpCopy) {
// really release previous texture. In case of same texture loading, then we did not have reload it .. just increase and decrease index...
ewol::resource::Release(tmpCopy);
ewol::TextureFile::Release(tmpCopy);
}
}

View File

@ -23,7 +23,7 @@ ewol::Area::Area(const ivec2& _size) :
m_GLtexID(-1),
m_resource(NULL)
{
ewol::resource::Keep(m_resource);
m_resource = ewol::Texture::Keep();
m_resource->SetImageSize(_size);
m_resource->Flush();
LoadProgram();
@ -31,19 +31,16 @@ ewol::Area::Area(const ivec2& _size) :
ewol::Area::~Area(void)
{
if (NULL != m_resource) {
ewol::resource::Release(m_resource);
m_resource = NULL;
}
ewol::resource::Release(m_GLprogram);
ewol::Texture::Release(m_resource);
ewol::Program::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_GLprogram = ewol::Program::Keep("DATA:textured3D.prog");
if (NULL != m_GLprogram) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");

View File

@ -288,10 +288,7 @@ void ewol::Drawing::ResetCount(void)
void ewol::Drawing::UnLoadProgram(void)
{
if (NULL!=m_GLprogram) {
ewol::resource::Release(m_GLprogram);
m_GLprogram = NULL;
}
ewol::Program::Release(m_GLprogram);
}
void ewol::Drawing::LoadProgram(void)
@ -299,9 +296,9 @@ void ewol::Drawing::LoadProgram(void)
// remove previous loading ... in case
UnLoadProgram();
// oad the new ...
etk::UString tmpString("DATA:color3.prog");
m_GLprogram = ewol::Program::Keep("DATA:color3.prog");
// get the shader resource :
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
if (NULL != m_GLprogram ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");

View File

@ -33,19 +33,16 @@ ewol::Image::Image(const etk::UString& _imageName) :
ewol::Image::~Image(void)
{
if (NULL != m_resource) {
ewol::resource::Release(m_resource);
m_resource = NULL;
}
ewol::resource::Release(m_GLprogram);
ewol::TextureFile::Release(m_resource);
ewol::Program::Release(m_GLprogram);
}
void ewol::Image::LoadProgram(void)
{
etk::UString tmpString("DATA:textured3D.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLprogram = ewol::Program::Keep("DATA:textured3D.prog");
if (NULL!=m_GLprogram) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
@ -238,15 +235,13 @@ void ewol::Image::SetSource(const etk::UString& _newFile, const vec2& _size)
{
Clear();
// remove old one
if (NULL != m_resource) {
ewol::resource::Release(m_resource);
m_resource = NULL;
}
ewol::TextureFile::Release(m_resource);
ivec2 tmpSize(_size.x(),_size.y());
// note that no image can be loaded...
if (_newFile != "") {
// link to new One
if (false == ewol::resource::Keep(_newFile, m_resource, tmpSize)) {
m_resource = ewol::TextureFile::Keep(_newFile, tmpSize);
if (NULL == m_resource) {
EWOL_ERROR("Can not get Image resource");
}
}

View File

@ -50,18 +50,9 @@ ewol::Shaper::~Shaper(void)
void ewol::Shaper::UnLoadProgram(void)
{
if (NULL != m_GLprogram) {
ewol::resource::Release(m_GLprogram);
m_GLprogram = NULL;
}
if (NULL != m_resourceTexture) {
ewol::resource::Release(m_resourceTexture);
m_resourceTexture = NULL;
}
if (NULL != m_config) {
ewol::resource::Release(m_config);
m_config = NULL;
}
ewol::Program::Release(m_GLprogram);
ewol::TextureFile::Release(m_resourceTexture);
ewol::ConfigFile::Release(m_config);
}
void ewol::Shaper::LoadProgram(void)
@ -70,7 +61,8 @@ void ewol::Shaper::LoadProgram(void)
EWOL_DEBUG("no Shaper set for loading resources ...");
return;
}
if (true == ewol::resource::Keep(m_name, m_config) ) {
m_config = ewol::ConfigFile::Keep(m_name);
if (NULL != m_config) {
m_confIdPaddingX = m_config->Request("PaddingX");
m_confIdPaddingY = m_config->Request("PaddingY");
m_confIdChangeTime = m_config->Request("ChangeTime");
@ -85,7 +77,8 @@ void ewol::Shaper::LoadProgram(void)
EWOL_DEBUG("Shaper try load shader : " << tmpFilename << " with base : " << basicShaderFile);
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpFilename, m_GLprogram) ) {
m_GLprogram = ewol::Program::Keep(tmpFilename);
if (NULL !=m_GLprogram) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
// Widget property ==> for the Vertex shader
@ -104,9 +97,7 @@ void ewol::Shaper::LoadProgram(void)
if (basicImageFile != "") {
tmpFilename = file.GetRelativeFolder() + basicImageFile;
ivec2 size(64,64);
if (true == ewol::resource::Keep(tmpFilename, m_resourceTexture, size) ) {
// nothing else to do ...
}
m_resourceTexture = ewol::TextureFile::Keep(tmpFilename, size);
}
}
}

View File

@ -47,20 +47,16 @@ ewol::Text::Text(const etk::UString& _fontName, int32_t _fontSize) :
ewol::Text::~Text(void)
{
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
ewol::resource::Release(m_GLprogram);
ewol::TexturedFont::Release(m_font);
ewol::Program::Release(m_GLprogram);
}
void ewol::Text::LoadProgram(void)
{
etk::UString tmpString("DATA:text.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLprogram = ewol::Program::Keep("DATA:text.prog");
if (NULL != m_GLprogram ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
@ -315,10 +311,7 @@ void ewol::Text::SetFont(etk::UString _fontName, int32_t _fontSize)
{
Clear();
// remove old one
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
ewol::TexturedFont * previousFont = m_font;
if (_fontSize <= 0) {
_fontSize = ewol::GetContext().GetFontDefault().GetSize();
}
@ -328,8 +321,12 @@ void ewol::Text::SetFont(etk::UString _fontName, int32_t _fontSize)
_fontName += ":";
_fontName += _fontSize;
// link to new One
if (false == ewol::resource::Keep(_fontName, m_font)) {
m_font = ewol::TexturedFont::Keep(_fontName);
if (NULL == m_font) {
EWOL_ERROR("Can not get font resource");
m_font = previousFont;
} else {
ewol::TexturedFont::Release(previousFont);
}
}

View File

@ -14,14 +14,13 @@
#define __class__ "Colored3DObject"
ewol::Colored3DObject::Colored3DObject(etk::UString _genName) :
ewol::Resource(_genName),
ewol::Colored3DObject::Colored3DObject(void) :
m_GLprogram(NULL)
{
etk::UString tmpString("DATA:simple3D.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLprogram = ewol::Program::Keep("DATA:simple3D.prog");
if (NULL != m_GLprogram ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLColor = m_GLprogram->GetUniform("EW_color");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
@ -31,7 +30,7 @@ ewol::Colored3DObject::Colored3DObject(etk::UString _genName) :
ewol::Colored3DObject::~Colored3DObject(void)
{
// remove dynamics dependencies :
ewol::resource::Release(m_GLprogram);
ewol::Program::Release(m_GLprogram);
}
@ -159,3 +158,28 @@ void ewol::Colored3DObject::DrawLine(etk::Vector<vec3>& _vertices,
ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST);
}
}
ewol::Colored3DObject* ewol::Colored3DObject::Keep(void)
{
EWOL_VERBOSE("KEEP : direct Colored3DObject");
// need to crate a new one ...
ewol::Colored3DObject* object = new ewol::Colored3DObject();
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : Colored3DObject ");
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::Colored3DObject::Release(ewol::Colored3DObject*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -21,12 +21,13 @@ namespace ewol
{
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
public:
Colored3DObject(etk::UString _genName);
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
protected:
Colored3DObject(void);
virtual ~Colored3DObject(void);
public:
virtual const char* GetType(void) { return "ewol::Colored3DObject"; };
virtual void Draw(etk::Vector<vec3>& _vertices,
const etk::Color<float>& _color,
@ -42,7 +43,18 @@ namespace ewol
mat4& _transformationMatrix,
bool _updateDepthBuffer=true,
bool _depthtest=true);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::Colored3DObject* Keep(void);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::Colored3DObject*& _object);
};
};

View File

@ -9,6 +9,7 @@
#include <etk/os/FSNode.h>
#include <ewol/debug.h>
#include <ewol/resources/ConfigFile.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "ConfigFile"
@ -26,10 +27,10 @@ void ewol::SimpleConfigElement::Parse(const etk::UString& value)
ewol::ConfigFile::ConfigFile(const etk::UString& filename):
ewol::Resource(filename)
ewol::ConfigFile::ConfigFile(const etk::UString& _filename):
ewol::Resource(_filename)
{
EWOL_DEBUG("SFP : load \"" << filename << "\"");
EWOL_DEBUG("SFP : load \"" << _filename << "\"");
Reload();
}
@ -132,17 +133,17 @@ void ewol::ConfigFile::Reload(void)
}
int32_t ewol::ConfigFile::Request(etk::UString paramName)
int32_t ewol::ConfigFile::Request(const etk::UString& _paramName)
{
// check if the parameters existed :
for (int32_t iii=0; iii<m_list.Size(); iii++){
if (NULL != m_list[iii]) {
if (m_list[iii]->m_paramName == paramName) {
if (m_list[iii]->m_paramName == _paramName) {
return iii;
}
}
}
ewol::SimpleConfigElement* tmpElement = new ewol::SimpleConfigElement(paramName);
ewol::SimpleConfigElement* tmpElement = new ewol::SimpleConfigElement(_paramName);
if (NULL == tmpElement) {
EWOL_DEBUG("error while allocation");
} else {
@ -151,3 +152,33 @@ int32_t ewol::ConfigFile::Request(etk::UString paramName)
return m_list.Size()-1;
}
ewol::ConfigFile* ewol::ConfigFile::Keep(const etk::UString& _filename)
{
EWOL_INFO("KEEP : SimpleConfig : file : \"" << _filename << "\"");
ewol::ConfigFile* object = static_cast<ewol::ConfigFile*>(GetManager().LocalKeep(_filename));
if (NULL != object) {
return object;
}
// this element create a new one every time ....
object = new ewol::ConfigFile(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Mesh.obj??");
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::ConfigFile::Release(ewol::ConfigFile*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -24,8 +24,8 @@ namespace ewol
int32_t m_valueInt;
float m_valuefloat;
public:
SimpleConfigElement(const etk::UString& name) :
m_paramName(name),
SimpleConfigElement(const etk::UString& _name) :
m_paramName(_name),
m_value(""),
m_valueInt(0),
m_valuefloat(0.0) { };
@ -41,17 +41,31 @@ namespace ewol
private:
etk::Vector<ewol::SimpleConfigElement*> m_list;
etk::UString m_errorString;
public:
ConfigFile(const etk::UString& filename);
protected:
ConfigFile(const etk::UString& _filename);
virtual ~ConfigFile(void);
public:
const char* GetType(void) { return "ewol::SimpleConfigFile"; };
void Reload(void);
int32_t Request(etk::UString paramName);
int32_t Request(const etk::UString& _paramName);
int32_t GetInteger(int32_t id) { if (id<0) { return 0; } return m_list[id]->GetInteger(); };
float GetFloat(int32_t id) { if (id<0) { return 0; } return m_list[id]->GetFloat(); };
etk::UString& GetString(int32_t id) { if (id<0) { return m_errorString; } return m_list[id]->GetString(); };
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the configuration file.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::ConfigFile* Keep(const etk::UString& _filename);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::ConfigFile*& _object);
};
};

View File

@ -16,6 +16,7 @@
#include <ewol/resources/Texture.h>
#include <ewol/resources/FontFreeType.h>
#include <ewol/resources/font/FontBase.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
@ -359,3 +360,29 @@ void ewol::FontFreeType::Display(void)
ewol::FontBase* ewol::FontFreeType::Keep(const etk::UString& _filename)
{
EWOL_VERBOSE("KEEP : Font : file : \"" << _filename << "\"");
ewol::FontBase* object = static_cast<ewol::FontBase*>(GetManager().LocalKeep(_filename));
if (NULL != object) {
return object;
}
// need to crate a new one ...
object = new ewol::FontFreeType(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::FontFreeType::Release(ewol::FontBase*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -28,9 +28,10 @@ namespace ewol
FT_Face m_fftFace;
bool m_init;
void Display(void);
public:
protected:
FontFreeType(const etk::UString& _fontName);
~FontFreeType(void);
public:
bool GetGlyphProperty(int32_t _fontSize,
ewol::GlyphProperty& _property);
@ -46,6 +47,19 @@ namespace ewol
int32_t GetHeight(int32_t _fontSize);
void GenerateKerning(int32_t _fontSize, etk::Vector<ewol::GlyphProperty>& _listGlyph);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the base font.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::FontBase* Keep(const etk::UString& _filename);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::FontBase*& _object);
};
void FreeTypeInit(void);
void FreeTypeUnInit(void);

View File

@ -34,3 +34,92 @@ ewol::TextureFile::TextureFile(etk::UString _genName, const etk::UString& _tmpfi
Flush();
}
#ifdef __TARGET_OS__Android
/**
* @brief get the next power 2 if the input
* @param[in] _value Value that we want the next power of 2
* @return result value
*/
static int32_t nextP2(int32_t _value)
{
int32_t val=1;
for (int32_t iii=1; iii<31; iii++) {
if (_value <= val) {
return val;
}
val *=2;
}
EWOL_CRITICAL("impossible CASE.... request P2 of " << _value);
return val;
}
#endif
ewol::TextureFile* ewol::TextureFile::Keep(const etk::UString& _filename, ivec2 _size)
{
EWOL_INFO("KEEP : TextureFile : file : " << _filename << " basic size=" << _size);
if (_filename == "") {
ewol::TextureFile* object = new ewol::TextureFile("");
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??");
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
if (_size.x()==0) {
_size.setX(-1);
//EWOL_ERROR("Error Request the image size.x() =0 ???");
}
if (_size.y()==0) {
_size.setY(-1);
//EWOL_ERROR("Error Request the image size.y() =0 ???");
}
etk::UString TmpFilename = _filename;
if (false == _filename.EndWith(".svg") ) {
_size = ivec2(-1,-1);
}
#ifdef __TARGET_OS__MacOs
EWOL_ERROR("TODO : Remove this strange hack");
_size = ivec2(64,64);
#endif
if (_size.x()>0 && _size.y()>0) {
EWOL_VERBOSE(" ==> specific size : " << _size);
#ifdef __TARGET_OS__Android
_size.setValue(nextP2(_size.x()), nextP2(_size.y()));
#endif
TmpFilename += ":";
TmpFilename += _size.x();
TmpFilename += "x";
TmpFilename += _size.y();
}
EWOL_INFO("KEEP : TextureFile : file : \"" << TmpFilename << "\" new size=" << _size);
ewol::TextureFile* object = static_cast<ewol::TextureFile*>(GetManager().LocalKeep(TmpFilename));
if (NULL != object) {
return object;
}
EWOL_INFO(" ==> create new one...");
// 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 NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::TextureFile::Release(ewol::TextureFile*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -21,12 +21,27 @@ namespace ewol
{
private:
vec2 m_realImageSize;
public:
private:
TextureFile(const etk::UString& _genName);
TextureFile(etk::UString _genName, const etk::UString& _fileName, const ivec2& _size);
~TextureFile(void) { };
public:
virtual const char* GetType(void) { return "ewol::TextureFile"; };
const vec2& GetRealSize(void) { return m_realImageSize; };
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the image file.
* @param[in] _requested size of the image (usefull when loading .svg to automatic rescale)
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::TextureFile* Keep(const etk::UString& _filename, ivec2 _size=ivec2(-1,-1));
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::TextureFile*& _object);
};
};

View File

@ -32,8 +32,8 @@ ewol::Mesh::Mesh(const etk::UString& _fileName, const etk::UString& _shaderName)
m_light.SetSpecularColor(vec4(0.0,0.0,0.0,1));
//EWOL_DEBUG(m_name << " " << m_light);
if (true == ewol::resource::Keep(_shaderName, m_GLprogram) ) {
m_GLprogram = ewol::Program::Keep(_shaderName);
if (NULL != m_GLprogram ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLNormal = m_GLprogram->GetAttribute("EW_normal");
@ -44,7 +44,7 @@ ewol::Mesh::Mesh(const etk::UString& _fileName, const etk::UString& _shaderName)
m_light.Link(m_GLprogram, "EW_directionalLight");
}
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
ewol::resource::Keep("w-fff", m_verticesVBO);
m_verticesVBO = ewol::VirtualBufferObject::Keep(4);
// load the curent file :
etk::UString tmpName = _fileName.ToLower();
@ -68,8 +68,8 @@ ewol::Mesh::Mesh(const etk::UString& _fileName, const etk::UString& _shaderName)
ewol::Mesh::~Mesh(void)
{
// remove dynamics dependencies :
ewol::resource::Release(m_GLprogram);
ewol::resource::Release(m_verticesVBO);
ewol::Program::Release(m_GLprogram);
ewol::VirtualBufferObject::Release(m_verticesVBO);
if (m_functionFreeShape!=NULL) {
m_functionFreeShape(m_pointerShape);
m_pointerShape = NULL;
@ -1011,3 +1011,32 @@ void ewol::Mesh::SetShape(void* _shape)
}
m_pointerShape=_shape;
};
ewol::Mesh* ewol::Mesh::Keep(const etk::UString& _meshName)
{
ewol::Mesh* object = static_cast<ewol::Mesh*>(GetManager().LocalKeep(_meshName));
if (NULL != object) {
return object;
}
object = new ewol::Mesh(_meshName);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Mesh??" << _meshName);
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::Mesh::Release(ewol::Mesh*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -107,9 +107,10 @@ namespace ewol
etk::Vector<ewol::PhysicsShape*> m_physics; //!< collision shape module ... (independent of bullet lib)
protected:
ewol::VirtualBufferObject* m_verticesVBO;
public:
private:
Mesh(const etk::UString& _fileName, const etk::UString& _shaderName="DATA:textured3D2.prog");
virtual ~Mesh(void);
public:
virtual const char* GetType(void) { return "ewol::Mesh"; };
virtual void Draw(mat4& positionMatrix);
void GenerateVBO(void);
@ -143,6 +144,19 @@ namespace ewol
void (*m_functionFreeShape)(void* _pointer);
public:
void SetFreeShapeFunction(void (*_functionFreeShape)(void* _pointer)) { m_functionFreeShape = _functionFreeShape; };
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the ewol mesh file.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::Mesh* Keep(const etk::UString& _meshname);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::Mesh*& _object);
};
};

View File

@ -36,15 +36,16 @@ ewol::Program::Program(const etk::UString& filename) :
etk::UString tmpFilename = m_name;
// remove extention ...
tmpFilename.Remove(tmpFilename.Size()-4, 4);
ewol::Shader* tmpShader = NULL;
if (false == ewol::resource::Keep(tmpFilename+"vert", tmpShader)) {
ewol::Shader* tmpShader = ewol::Shader::Keep(tmpFilename+"vert");
if (NULL==tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
return;
} else {
EWOL_DEBUG("Add shader on program : "<< tmpFilename << "vert");
m_shaderList.PushBack(tmpShader);
}
if (false == ewol::resource::Keep(tmpFilename+"frag", tmpShader)) {
tmpShader = ewol::Shader::Keep(tmpFilename+"frag");
if (NULL==tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
return;
} else {
@ -52,7 +53,6 @@ ewol::Program::Program(const etk::UString& filename) :
m_shaderList.PushBack(tmpShader);
}
} else {
etk::UString fileExtention = file.FileGetExtention();
if (fileExtention != "prog") {
EWOL_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
@ -80,8 +80,8 @@ ewol::Program::Program(const etk::UString& filename) :
}
// get it with relative position :
etk::UString tmpFilename = file.GetRelativeFolder() + tmpData;
ewol::Shader* tmpShader = NULL;
if (false == ewol::resource::Keep(tmpFilename, tmpShader)) {
ewol::Shader* tmpShader = ewol::Shader::Keep(tmpFilename);
if (NULL==tmpShader) {
EWOL_CRITICAL("Error while getting a specific shader filename : " << tmpFilename);
} else {
EWOL_DEBUG("Add shader on program : "<< tmpFilename);
@ -99,7 +99,7 @@ ewol::Program::Program(const etk::UString& filename) :
ewol::Program::~Program(void)
{
for (int32_t iii=0; iii<m_shaderList.Size(); iii++) {
ewol::resource::Release(m_shaderList[iii]);
ewol::Shader::Release(m_shaderList[iii]);
m_shaderList[iii] = 0;
}
m_shaderList.Clear();
@ -801,3 +801,31 @@ void ewol::Program::UnUse(void)
}
ewol::Program* ewol::Program::Keep(const etk::UString& _filename)
{
EWOL_VERBOSE("KEEP : Program : file : \"" << _filename << "\"");
ewol::Program* object = static_cast<ewol::Program*>(GetManager().LocalKeep(_filename));
if (NULL != object) {
return object;
}
// need to crate a new one ...
object = new ewol::Program(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::Program::Release(ewol::Program*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -54,7 +54,7 @@ namespace ewol
etk::Vector<ewol::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
bool m_hasTexture; //!< A texture has been set to the current shader
bool m_hasTexture1; //!< A texture has been set to the current shader
public:
protected:
/**
* @brief Contructor of an opengl Program.
* @param[in] filename Standard file name format. see @ref etk::FSNode
@ -64,6 +64,7 @@ namespace ewol
* @brief Destructor, remove the current Program.
*/
virtual ~Program(void);
public:
/**
* @brief Generic function that get the resouces name of his type.
* @return The define char of his name.
@ -267,6 +268,19 @@ namespace ewol
* @note this is really usefull when we tested the new themes or shader developpements.
*/
void Reload(void);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the openGL program.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::Program* Keep(const etk::UString& _filename);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::Program*& _object);
};
};

View File

@ -0,0 +1,45 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/resources/Resource.h>
#include <ewol/resources/ResourceManager.h>
#include <ewol/ewol.h>
#include <ewol/renderer/openGL.h>
#include <ewol/renderer/eContext.h>
// Specific for the resource :
uint32_t ewol::Resource::m_valBase=0;
void ewol::Resource::UpdateContext(void)
{
EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)");
}
void ewol::Resource::RemoveContext(void)
{
EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)");
}
void ewol::Resource::RemoveContextToLate(void)
{
EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)");
}
void ewol::Resource::Reload(void)
{
EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)");
}
ewol::ResourceManager ewol::Resource::GetManager(void)
{
return ewol::GetContext().GetResourcesManager();
}

View File

@ -18,6 +18,7 @@
namespace ewol
{
class ResourceManager;
// class resources is pure virtual
class Resource {
/*
@ -26,7 +27,7 @@ namespace ewol
void operator delete(void* elementPointer);
*/
private:
static uint32_t valBase;
static uint32_t m_valBase;
protected:
etk::UString m_name;
uint32_t m_counter;
@ -38,22 +39,22 @@ namespace ewol
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1)
{
m_uniqueId = valBase;
valBase++;
m_uniqueId = m_valBase;
m_valBase++;
};
Resource(const etk::UString& filename) :
m_name(filename),
Resource(const etk::UString& _filename) :
m_name(_filename),
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1)
{
m_uniqueId = valBase;
valBase++;
m_uniqueId = m_valBase;
m_valBase++;
};
virtual ~Resource(void) { };
virtual bool HasName(const etk::UString& fileName)
virtual bool HasName(const etk::UString& _fileName)
{
EWOL_VERBOSE("G : check : " << fileName << " ?= " << m_name << " = " << (fileName==m_name) );
return fileName==m_name;
EWOL_VERBOSE("G : check : " << _fileName << " ?= " << m_name << " = " << (_fileName==m_name) );
return _fileName==m_name;
};
virtual etk::UString GetName(void) { return m_name; };
void Increment(void) { m_counter++; };
@ -62,10 +63,12 @@ namespace ewol
uint32_t GetUID(void) { return m_uniqueId; };
uint8_t GetResourceLevel(void) { return m_resourceLevel; };
virtual const char* GetType(void) { return "unknow"; };
virtual void UpdateContext(void) { EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)"); };
virtual void RemoveContext(void) { EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)"); };
virtual void RemoveContextToLate(void) { EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)"); };
virtual void Reload(void) { EWOL_DEBUG("Not Set for : [" << m_uniqueId << "]" << m_name << " loaded " << m_counter << " time(s)"); };
virtual void UpdateContext(void);
virtual void RemoveContext(void);
virtual void RemoveContextToLate(void);
virtual void Reload(void);
static ewol::ResourceManager& GetManager(void);
};
};

View File

@ -15,10 +15,6 @@
#include <ewol/renderer/eContext.h>
// Specific for the resource :
uint32_t ewol::Resource::valBase=0;
ewol::ResourceManager::ResourceManager(void) :
m_contextHasBeenRemoved(true)
@ -96,19 +92,19 @@ void ewol::ResourceManager::ReLoadResources(void)
EWOL_INFO("------------- Resources -------------");
}
void ewol::ResourceManager::Update(ewol::Resource* object)
void ewol::ResourceManager::Update(ewol::Resource* _object)
{
// chek if not added before
for (int32_t iii=0; iii<m_resourceListToUpdate.Size(); iii++) {
if (m_resourceListToUpdate[iii] != NULL) {
if (m_resourceListToUpdate[iii] == object) {
if (m_resourceListToUpdate[iii] == _object) {
// just prevent some double add ...
return;
}
}
}
// add it ...
m_resourceListToUpdate.PushBack(object);
m_resourceListToUpdate.PushBack(_object);
}
// Specific to load or update the data in the openGl context ==> system use only
@ -165,12 +161,12 @@ void ewol::ResourceManager::ContextHasBeenDestroyed(void)
// internal generic keeper ...
ewol::Resource* ewol::ResourceManager::LocalKeep(const etk::UString& filename)
ewol::Resource* ewol::ResourceManager::LocalKeep(const etk::UString& _filename)
{
EWOL_VERBOSE("KEEP (DEFAULT) : file : \"" << filename << "\"");
EWOL_VERBOSE("KEEP (DEFAULT) : file : \"" << _filename << "\"");
for (int32_t iii=0; iii<m_resourceList.Size(); iii++) {
if (m_resourceList[iii] != NULL) {
if(m_resourceList[iii]->HasName(filename)) {
if(m_resourceList[iii]->HasName(_filename)) {
m_resourceList[iii]->Increment();
return m_resourceList[iii];
}
@ -181,257 +177,35 @@ ewol::Resource* ewol::ResourceManager::LocalKeep(const etk::UString& filename)
}
// internal generic keeper ...
void ewol::ResourceManager::LocalAdd(ewol::Resource* object)
void ewol::ResourceManager::LocalAdd(ewol::Resource* _object)
{
//Add ... find empty slot
for (int32_t iii=0; iii<m_resourceList.Size(); iii++) {
if (m_resourceList[iii] == NULL) {
m_resourceList[iii] = object;
m_resourceList[iii] = _object;
return;
}
}
// add at the end if no slot is free
m_resourceList.PushBack(object);
m_resourceList.PushBack(_object);
}
// return the type of the resource ...
bool ewol::resource::Keep(const etk::UString& filename, ewol::TexturedFont*& object)
void ewol::ResourceManager::Release(ewol::Resource*& _object)
{
EWOL_VERBOSE("KEEP : TexturedFont : file : \"" << filename << "\"");
object = static_cast<ewol::TexturedFont*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != object) {
return true;
}
// need to crate a new one ...
object = new ewol::TexturedFont(filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << filename);
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(object);
return true;
}
bool ewol::resource::Keep(const etk::UString& filename, ewol::FontBase*& object)
{
EWOL_VERBOSE("KEEP : Font : file : \"" << filename << "\"");
object = static_cast<ewol::FontBase*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != object) {
return true;
}
// need to crate a new one ...
object = new ewol::FontFreeType(filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << filename);
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(object);
return true;
}
bool ewol::resource::Keep(const etk::UString& filename, ewol::Program*& object)
{
EWOL_VERBOSE("KEEP : Program : file : \"" << filename << "\"");
object = static_cast<ewol::Program*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != object) {
return true;
}
// need to crate a new one ...
object = new ewol::Program(filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << filename);
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(object);
return true;
}
bool ewol::resource::Keep(const etk::UString& filename, ewol::Shader*& object)
{
EWOL_VERBOSE("KEEP : Simpleshader : file : \"" << filename << "\"");
object = static_cast<ewol::Shader*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != object) {
return true;
}
// need to crate a new one ...
object = new ewol::Shader(filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << filename);
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(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;
}
ewol::GetContext().GetResourcesManager().LocalAdd(object);
return true;
}
bool ewol::resource::Keep(ewol::Colored3DObject*& _object)
{
EWOL_VERBOSE("KEEP : direct Colored3DObject");
etk::UString filename = "?metaObject?Colored3DObject";
_object = static_cast<ewol::Colored3DObject*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != _object) {
return true;
}
// need to crate a new one ...
_object = new ewol::Colored3DObject(filename);
if (NULL == _object) {
EWOL_ERROR("allocation error of a resource : Colored3DObject ");
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(_object);
return true;
}
#ifdef __TARGET_OS__Android
/**
* @brief get the next power 2 if the input
* @param[in] _value Value that we want the next power of 2
* @return result value
*/
static int32_t nextP2(int32_t _value)
{
int32_t val=1;
for (int32_t iii=1; iii<31; iii++) {
if (_value <= val) {
return val;
}
val *=2;
}
EWOL_CRITICAL("impossible CASE.... request P2 of " << _value);
return val;
}
#endif
bool ewol::resource::Keep(const etk::UString& _filename, ewol::TextureFile*& _object, ivec2 _size)
{
EWOL_INFO("KEEP : TextureFile : file : " << _filename << " basic size=" << _size);
if (_filename == "") {
_object = new ewol::TextureFile("");
if (NULL == _object) {
EWOL_ERROR("allocation error of a resource : ??TEX??");
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(_object);
return true;
}
if (_size.x()==0) {
_size.setX(-1);
//EWOL_ERROR("Error Request the image size.x() =0 ???");
}
if (_size.y()==0) {
_size.setY(-1);
//EWOL_ERROR("Error Request the image size.y() =0 ???");
}
etk::UString TmpFilename = _filename;
if (false == _filename.EndWith(".svg") ) {
_size = ivec2(-1,-1);
}
#ifdef __TARGET_OS__MacOs
EWOL_ERROR("TODO : Remove this strange hack");
_size = ivec2(64,64);
#endif
if (_size.x()>0 && _size.y()>0) {
EWOL_VERBOSE(" ==> specific size : " << _size);
#ifdef __TARGET_OS__Android
_size.setValue(nextP2(_size.x()), nextP2(_size.y()));
#endif
TmpFilename += ":";
TmpFilename += _size.x();
TmpFilename += "x";
TmpFilename += _size.y();
}
EWOL_INFO("KEEP : TextureFile : file : \"" << TmpFilename << "\" new size=" << _size);
_object = static_cast<ewol::TextureFile*>(ewol::GetContext().GetResourcesManager().LocalKeep(TmpFilename));
if (NULL != _object) {
return true;
}
EWOL_INFO(" ==> create new one...");
// 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;
}
ewol::GetContext().GetResourcesManager().LocalAdd(_object);
return true;
}
bool ewol::resource::Keep(const etk::UString& _meshName, ewol::Mesh*& _object)
{
_object = static_cast<ewol::Mesh*>(ewol::GetContext().GetResourcesManager().LocalKeep(_meshName));
if (NULL != _object) {
return true;
}
_object = new ewol::Mesh(_meshName);
if (NULL == _object) {
EWOL_ERROR("allocation error of a resource : ??Mesh??" << _meshName);
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(_object);
return true;
}
bool ewol::resource::Keep(const etk::UString& _accesMode, ewol::VirtualBufferObject*& _object)
{
// this element create a new one every time ....
_object = new ewol::VirtualBufferObject(_accesMode);
if (NULL == _object) {
EWOL_ERROR("allocation error of a resource : ??VBO??");
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(_object);
return true;
}
bool ewol::resource::Keep(const etk::UString& filename, ewol::ConfigFile*& object)
{
EWOL_INFO("KEEP : SimpleConfig : file : \"" << filename << "\"");
object = static_cast<ewol::ConfigFile*>(ewol::GetContext().GetResourcesManager().LocalKeep(filename));
if (NULL != object) {
return true;
}
// this element create a new one every time ....
object = new ewol::ConfigFile(filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??Mesh.obj??");
return false;
}
ewol::GetContext().GetResourcesManager().LocalAdd(object);
return true;
}
void ewol::ResourceManager::Release(ewol::Resource*& object)
{
if (NULL == object) {
EWOL_ERROR("Try to remove a resource that have null pointer ...");
return;
}
for (int32_t iii=0; iii<m_resourceListToUpdate.Size(); iii++) {
if (m_resourceListToUpdate[iii] == object) {
if (m_resourceListToUpdate[iii] == _object) {
m_resourceListToUpdate[iii] = NULL;
//l_resourceListToUpdate.Erase(iii);
}
}
EWOL_VERBOSE("RELEASE (default) : file : \"" << object->GetName() << "\"");
EWOL_VERBOSE("RELEASE (default) : file : \"" << _object->GetName() << "\"");
for (int32_t iii=m_resourceList.Size()-1; iii>=0; iii--) {
if (m_resourceList[iii] != NULL) {
if(m_resourceList[iii] == object) {
if(m_resourceList[iii] == _object) {
if (true == m_resourceList[iii]->Decrement()) {
// delete element
delete(m_resourceList[iii]);
@ -439,79 +213,12 @@ void ewol::ResourceManager::Release(ewol::Resource*& object)
m_resourceList[iii] = NULL;
}
// insidiously remove the pointer for the caller ...
object = NULL;
_object = NULL;
return;
}
}
}
EWOL_ERROR("Can not find the resources in the list : " << (int64_t)object);
EWOL_ERROR("Can not find the resources in the list : " << (int64_t)_object);
// insidiously remove the pointer for the caller ...
object = NULL;
}
void ewol::resource::Release(ewol::TexturedFont*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::FontBase*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Program*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Shader*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Texture*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::TextureFile*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
//EWOL_INFO("RELEASE : TextureFile : nb=" << object2->GetCounter());
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Mesh*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::ConfigFile*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::Colored3DObject*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
}
void ewol::resource::Release(ewol::VirtualBufferObject*& object)
{
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
ewol::GetContext().GetResourcesManager().Release(object2);
object = NULL;
_object = NULL;
}

View File

@ -55,9 +55,9 @@ namespace ewol
void ReLoadResources(void);
/**
* @brief Call by the system to send all the needed data on the graphic card chen they change ...
* @param[in] object The resources that might be updated
* @param[in] _object The resources that might be updated
*/
void Update(ewol::Resource* object);
void Update(ewol::Resource* _object);
/**
* @brief Call by the system chen the openGL Context has been unexpectially removed ==> This reload all the texture, VBO and other ....
*/
@ -68,69 +68,14 @@ namespace ewol
void ContextHasBeenDestroyed(void);
public:
// internal API to extent eResources in extern Soft
ewol::Resource* LocalKeep(const etk::UString& filename);
void LocalAdd(ewol::Resource* object);
ewol::Resource* LocalKeep(const etk::UString& _filename);
void LocalAdd(ewol::Resource* _object);
public:
/**
* @brief Release a resources and free it if the Last release is call.
* @param[in,out] object element to realease ==> is return at NULL value.
* @param[in,out] _object element to realease ==> is return at NULL value.
*/
void Release(ewol::Resource*& object);
};
namespace resource
{
/**
* @brief Load the specify resources type
* @param[in] filename The filename of the resources
* @param[in,out] object The resources that might be instanciate.
* @return true if the resource has been loaded corectly.
* @return false An error occured ...
* @note when you call the Keep function, you must call the Realease function ==> otherwise the resources will never be freed
* @note The resources with the same name are loaded only one time, a counter prevent multiple loading...
*/
bool Keep(const etk::UString& filename, ewol::TexturedFont*& object);
bool Keep(const etk::UString& filename, ewol::FontBase*& object);
bool Keep(const etk::UString& filename, ewol::Program*& object);
bool Keep(const etk::UString& filename, ewol::Shader*& object);
bool Keep(ewol::Texture*& object); // no name needed here ...
bool Keep(const etk::UString& filename, ewol::TextureFile*& object, ivec2 size=ivec2(-1,-1));
bool Keep(const etk::UString& accesMode, ewol::VirtualBufferObject*& object);
bool Keep(const etk::UString& meshName, ewol::Mesh*& object);
bool Keep(const etk::UString& filename, ewol::ConfigFile*& object);
bool Keep(ewol::Colored3DObject*& object);
// must became :
/*
ewol::Font* KeepFont(const etk::UString& _filename);
ewol::Program* KeepProgram(const etk::UString& _filename);
ewol::Shader* KeepShader(const etk::UString& _filename);
ewol::Texture* KeepTexture(void);
ewol::Texture* KeepTexture(const etk::UString& _filename, const ivec2& size=ivec2(-1,-1));
void AddTextureResourceCreator(pf* _plop, const etk::UString& _ext);
ewol::Audio* KeepAudio(const etk::UString& _filename, bool _inRam=false);
void AddAudioResourceCreator(pf* _plop, const etk::UString& _ext);
ewol::VirtualBufferObject* KeepVBO(const etk::UString& _accesMode);
ewol::Mesh* KeepMesh(const etk::UString& _filename);
ewol::ConfigFile* KeepConfigFile(const etk::UString& _filename);
ewol::Colored3DObject* Keep3DObject(void);
void Release(ewol::Resource*& object);
*/
/**
* @brief Release a resources and free it if the Last release is call.
* @param[in,out] object element to realease ==> is return at NULL value.
*/
void Release(ewol::Resource*& object);
void Release(ewol::TexturedFont*& object);
void Release(ewol::FontBase*& object);
void Release(ewol::Program*& object);
void Release(ewol::Shader*& object);
void Release(ewol::Texture*& object);
void Release(ewol::TextureFile*& object);
void Release(ewol::VirtualBufferObject*& object);
void Release(ewol::Mesh*& object);
void Release(ewol::ConfigFile*& object);
void Release(ewol::Colored3DObject*& object);
void Release(ewol::Resource*& _object);
};
};

View File

@ -10,7 +10,7 @@
#include <etk/os/FSNode.h>
#include <ewol/debug.h>
#include <ewol/resources/Shader.h>
#include <ewol/resources/ResourceManager.h>
#undef __class__
#define __class__ "Shader"
@ -159,3 +159,29 @@ void ewol::Shader::Reload(void)
ewol::Shader* ewol::Shader::Keep(const etk::UString& _filename)
{
EWOL_VERBOSE("KEEP : Simpleshader : file : \"" << _filename << "\"");
ewol::Shader* object = static_cast<ewol::Shader*>(GetManager().LocalKeep(_filename));
if (NULL != object) {
return object;
}
// need to crate a new one ...
object = new ewol::Shader(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::Shader::Release(ewol::Shader*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -26,7 +26,7 @@ namespace ewol
char* m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
GLuint m_shader; //!< Opengl id of this element
GLenum m_type; //!< Type of the current shader(vertex/fragment)
public:
protected:
/**
* @brief Contructor of an opengl Shader
* @param[in] filename Standard file name format. see @ref etk::FSNode
@ -36,6 +36,7 @@ namespace ewol
* @brief Destructor, remove the current Shader
*/
virtual ~Shader(void);
public:
/**
* @brief Generic function that get the resouces name of his type.
* @return The define char of his name.
@ -68,6 +69,19 @@ namespace ewol
* @note this is really usefull when we tested the new themes or shader developpements.
*/
void Reload(void);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the openGL Shader.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::Shader* Keep(const etk::UString& _filename);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::Shader*& _object);
};
};

View File

@ -35,9 +35,15 @@ static int32_t nextP2(int32_t _value)
}
ewol::Texture::Texture(const etk::UString& _filename) :
ewol::Resource(_filename)
{
m_loaded = false;
m_texId = 0;
m_endPointSize.setValue(1.0,1.0);
}
ewol::Texture::Texture(etk::UString _tmpName) :
Resource(_tmpName)
ewol::Texture::Texture(void)
{
m_loaded = false;
m_texId = 0;
@ -105,7 +111,7 @@ void ewol::Texture::RemoveContextToLate(void)
void ewol::Texture::Flush(void)
{
// request to the manager to be call at the next update ...
ewol::GetContext().GetResourcesManager().Update(this);
GetManager().Update(this);
}
@ -115,3 +121,24 @@ void ewol::Texture::SetImageSize(ivec2 _newSize)
m_data.Resize(_newSize);
}
ewol::Texture* ewol::Texture::Keep(void)
{
// this element create a new one every time ....
ewol::Texture* object = new ewol::Texture();
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??TEX??");
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::Texture::Release(ewol::Texture*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -36,9 +36,11 @@ namespace ewol {
GLuint GetId(void) { return m_texId; };
vec2 GetUsableSize(void) { return m_endPointSize; };
// Public API:
public:
Texture(etk::UString tmpName);
protected:
Texture(const etk::UString& _filename);
Texture(void);
~Texture(void);
public:
virtual const char* GetType(void) { return "ewol::Texture"; };
// you must set the size here, because it will be set in multiple of pow(2)
void SetImageSize(ivec2 newSize);
@ -46,6 +48,18 @@ namespace ewol {
inline egami::Image& Get(void) { return m_data; };
// Flush the data to send it at the OpenGl system
void Flush(void);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::Texture* Keep(void);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::Texture*& _object);
};
};

View File

@ -14,6 +14,7 @@
#include <ewol/resources/font/FontBase.h>
#include <ewol/resources/TexturedFont.h>
#include <ewol/resources/FontFreeType.h>
etk::CCout& ewol::operator <<(etk::CCout& _os, const ewol::font::mode_te& _obj)
@ -213,7 +214,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
continue;
}
EWOL_INFO("Load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" ==> size=" << m_size);
ewol::resource::Keep(m_fileName[iiiFontId], m_font[iiiFontId]);
m_font[iiiFontId] = ewol::FontFreeType::Keep(m_fileName[iiiFontId]);
if (NULL == m_font[iiiFontId]) {
return;
}
@ -323,10 +324,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
ewol::TexturedFont::~TexturedFont(void)
{
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
if (NULL!= m_font[iiiFontId]) {
ewol::resource::Release(m_font[iiiFontId]);
m_font[iiiFontId] = NULL;
}
ewol::FontFreeType::Release(m_font[iiiFontId]);
}
}
@ -377,3 +375,32 @@ ewol::GlyphProperty* ewol::TexturedFont::GetGlyphPointer(const uniChar_t& _charc
//EWOL_ERROR(" m_bearing=" << m_listElement[_displayMode][index].m_bearing);
return &((m_listElement[_displayMode])[index]);
}
ewol::TexturedFont* ewol::TexturedFont::Keep(const etk::UString& _filename)
{
EWOL_VERBOSE("KEEP : TexturedFont : file : \"" << _filename << "\"");
ewol::TexturedFont* object = static_cast<ewol::TexturedFont*>(GetManager().LocalKeep(_filename));
if (NULL != object) {
return object;
}
// need to crate a new one ...
object = new ewol::TexturedFont(_filename);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : " << _filename);
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::TexturedFont::Release(ewol::TexturedFont*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -43,9 +43,10 @@ namespace ewol
// for the texture generation :
ivec2 m_lastGlyphPos[4];
int32_t m_lastRawHeigh[4];
public:
protected:
TexturedFont(etk::UString fontName);
~TexturedFont(void);
public:
virtual bool HasName(const etk::UString& fileName);
const char* GetType(void) { return "ewol::TexturedFont"; };
int32_t getFontSize(void) { return m_size; };
@ -81,6 +82,19 @@ namespace ewol
* @return the best mode we have in stock.
*/
ewol::font::mode_te GetWrappingMode(ewol::font::mode_te source) { return m_modeWraping[source]; };
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _filename Name of the texture font.
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::TexturedFont* Keep(const etk::UString& _filename);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::TexturedFont*& _object);
};

View File

@ -15,16 +15,16 @@
#undef __class__
#define __class__ "VirtualBufferObject"
ewol::VirtualBufferObject::VirtualBufferObject(const etk::UString& accesMode):
ewol::Resource(),
ewol::VirtualBufferObject::VirtualBufferObject(int32_t _number) :
m_exist(false)
{
m_nbVBO = etk_avg(1, _number, NB_VBO_MAX);
for (int32_t iii=0; iii<NB_VBO_MAX; iii++) {
m_vbo[iii]=0;
m_vboUsed[iii]=false;
}
m_resourceLevel = 3;
EWOL_DEBUG("OGL : load VBO mode=\"" << accesMode << "\"");
EWOL_DEBUG("OGL : load VBO count=\"" << _number << "\"");
}
@ -44,10 +44,10 @@ void ewol::VirtualBufferObject::UpdateContext(void)
{
if (false==m_exist) {
// Allocate and assign a Vertex Array Object to our handle
glGenBuffers(NB_VBO_MAX, m_vbo);
glGenBuffers(m_nbVBO, m_vbo);
}
m_exist = true;
for (int32_t iii=0; iii<NB_VBO_MAX; iii++) {
for (int32_t iii=0; iii<m_nbVBO; iii++) {
EWOL_INFO("VBO : Add [" << m_uniqueId << "]=" << m_buffer[iii].Size() << "*sizeof(float) OGl_Id=" << m_vbo[iii]);
if (true == m_vboUsed[iii]) {
// select the buffer to set data inside it ...
@ -68,7 +68,7 @@ void ewol::VirtualBufferObject::RemoveContext(void)
<< "/" << m_vbo[1]
<< "/" << m_vbo[2]
<< "/" << m_vbo[3]);
glDeleteBuffers(NB_VBO_MAX, m_vbo);
glDeleteBuffers(m_nbVBO, m_vbo);
m_exist = false;
for (int32_t iii=0; iii<NB_VBO_MAX; iii++) {
m_vbo[iii] = 0;
@ -140,3 +140,26 @@ int32_t ewol::VirtualBufferObject::SizeOnBufferVec2(int32_t id)
return m_buffer[id].Size()/2;
}
ewol::VirtualBufferObject* ewol::VirtualBufferObject::Keep(int32_t _number)
{
// this element create a new one every time ....
ewol::VirtualBufferObject* object = new ewol::VirtualBufferObject(_number);
if (NULL == object) {
EWOL_ERROR("allocation error of a resource : ??VBO??");
return NULL;
}
GetManager().LocalAdd(object);
return object;
}
void ewol::VirtualBufferObject::Release(ewol::VirtualBufferObject*& _object)
{
if (NULL == _object) {
return;
}
ewol::Resource* object2 = static_cast<ewol::Resource*>(_object);
GetManager().Release(object2);
_object = NULL;
}

View File

@ -15,7 +15,7 @@
#include <ewol/resources/Resource.h>
#include <ewol/renderer/openGL.h>
#define NB_VBO_MAX (4)
#define NB_VBO_MAX (20)
namespace ewol
{
@ -25,20 +25,22 @@ namespace ewol
class VirtualBufferObject : public ewol::Resource
{
private :
bool m_exist; //!< This data is availlable in the Graphic card
GLuint m_vbo[NB_VBO_MAX]; //!< OpenGl ID of this VBO
bool m_vboUsed[NB_VBO_MAX]; //!< true if the VBO is allocated or used ...
int32_t m_nbVBO;
bool m_exist; //!< This data is availlable in the Graphic card
GLuint m_vbo[NB_VBO_MAX]; //!< OpenGl ID of this VBO
bool m_vboUsed[NB_VBO_MAX]; //!< true if the VBO is allocated or used ...
etk::Vector<float> m_buffer[NB_VBO_MAX]; //!< data that is availlable in the VBO system ...
public:
protected:
/**
* @brief Constructor of this VBO.
* @param[in] accesMode Acces mode : ???
*/
VirtualBufferObject(const etk::UString& accesMode);
VirtualBufferObject(int32_t _number);
/**
* @brief Destructor of this VBO.
*/
virtual ~VirtualBufferObject(void);
public:
/**
* @brief Generic function that get the resouces name of his type.
* @return The define char of his name.
@ -96,6 +98,19 @@ namespace ewol
* @note this is really usefull when we tested the new themes or shader developpements.
*/
void Reload(void);
public:
/**
* @brief Keep the resource pointer.
* @note Never free this pointer by your own...
* @param[in] _number Number of VBO needed
* @return pointer on the resource or NULL if an error occured.
*/
static ewol::VirtualBufferObject* Keep(int32_t _number);
/**
* @brief Release the keeped resources
* @param[in,out] reference on the object pointer
*/
static void Release(ewol::VirtualBufferObject*& _object);
};
};
#endif

View File

@ -31,7 +31,8 @@ widget::Mesh::Mesh(const etk::UString& filename) :
// Limit event at 1:
SetMouseLimit(1);
if (filename!="") {
if (false==ewol::resource::Keep(m_meshName, m_object)) {
m_object = ewol::Mesh::Keep(m_meshName);
if (NULL == m_object) {
EWOL_ERROR("Can not load the resource : \"" << m_meshName << "\"");
}
}
@ -40,10 +41,7 @@ widget::Mesh::Mesh(const etk::UString& filename) :
widget::Mesh::~Mesh(void)
{
if (NULL != m_object) {
ewol::resource::Release(m_object);
m_object = NULL;
}
ewol::Mesh::Release(m_object);
}
void widget::Mesh::OnDraw(void)
{
@ -102,14 +100,14 @@ bool widget::Mesh::OnEventInput(const ewol::EventInput& _event)
return false;
}
void widget::Mesh::SetFile(const etk::UString& filename)
void widget::Mesh::SetFile(const etk::UString& _filename)
{
if (filename!="") {
if (NULL != m_object) {
ewol::resource::Release(m_object);
m_object = NULL;
}
if (false==ewol::resource::Keep(m_meshName, m_object)) {
if( _filename!=""
&& m_meshName != _filename ) {
ewol::Mesh::Release(m_object);
m_meshName = _filename;
m_object = ewol::Mesh::Keep(m_meshName);
if (NULL == m_object) {
EWOL_ERROR("Can not load the resource : \"" << m_meshName << "\"");
}
}