[DEV] add VBO for openGL (not tested) and set code to reload shaders

This commit is contained in:
Edouard DUPIN 2012-10-10 18:09:54 +02:00
parent e3a379dd62
commit a70c2055b9
12 changed files with 454 additions and 254 deletions

View File

@ -29,20 +29,33 @@
#include <etk/UString.h>
#include <ewol/Debug.h>
#define MAX_RESOURCE_LEVEL (5)
namespace ewol
{
// class resources is pure virtual
class Resource {
private:
static uint32_t valBase;
protected:
etk::UString m_name;
uint32_t m_counter;
uint32_t m_uniqueId;
uint8_t m_resourceLevel;
public:
Resource(void) :
m_name(""),
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1)
{
m_uniqueId = valBase;
valBase++;
};
Resource(etk::UString& filename) :
m_name(filename),
m_counter(1)
m_counter(1),
m_resourceLevel(MAX_RESOURCE_LEVEL-1)
{
static uint32_t valBase=0;
m_uniqueId = valBase;
valBase++;
};
@ -57,11 +70,12 @@ namespace ewol
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
int32_t GetCounter(void) { return m_counter; };
virtual const char* GetType(void) { return "unknow"; };
virtual void UpdateContext(void) { };
virtual void RemoveContext(void) { };
virtual void RemoveContextToLate(void) { };
virtual void Reload(void) {};
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)"); };
uint32_t GetUID(void) { return m_uniqueId; };
uint8_t GetResourceLevel(void) { return m_resourceLevel; };
};
};

View File

@ -28,6 +28,11 @@
#include <ewol/ResourceManager.h>
#include <ewol/font/FontFreeType.h>
// Specific for the resource :
uint32_t ewol::Resource::valBase=0;
static etk::Vector<ewol::Resource*> l_resourceList;
static etk::Vector<ewol::Resource*> l_resourceListToUpdate;
static bool l_contextHasBeenRemoved = true;
@ -86,14 +91,16 @@ void ReLoadResources(void)
{
EWOL_INFO("------------- Resources re-loaded -------------");
// remove all resources ...
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
if (l_resourceList[iii] != NULL) {
const char * mode = "keep same";
if (etk::UString(l_resourceList[iii]->GetType()) == "ewol::Program") {
mode = "Reload ...";
l_resourceList[iii]->Reload();
if (l_resourceList.Size() != 0) {
for (int32_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
if( l_resourceList[iii] != NULL
&& jjj==l_resourceList[iii]->GetResourceLevel()) {
l_resourceList[iii]->Reload();
EWOL_INFO(" [" << l_resourceList[iii]->GetUID() << "]="<< l_resourceList[iii]->GetType());
}
}
EWOL_INFO(" [" << l_resourceList[iii]->GetUID() << "]="<< l_resourceList[iii]->GetType() << " ==> " << mode);
}
}
EWOL_INFO("------------- Resources -------------");
@ -120,15 +127,27 @@ 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();
if (l_resourceList.Size() != 0) {
for (int32_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" UpdateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
if( l_resourceList[iii] != NULL
&& jjj==l_resourceList[iii]->GetResourceLevel()) {
l_resourceList[iii]->UpdateContext();
}
}
}
}
}else {
for (int32_t iii=0; iii<l_resourceListToUpdate.Size(); iii++) {
if (l_resourceListToUpdate[iii] != NULL) {
l_resourceListToUpdate[iii]->UpdateContext();
if (l_resourceListToUpdate.Size() != 0) {
for (int32_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
EWOL_INFO(" UpdateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (int32_t iii=0; iii<l_resourceListToUpdate.Size(); iii++) {
if( l_resourceListToUpdate[iii] != NULL
&& jjj==l_resourceList[iii]->GetResourceLevel()) {
l_resourceListToUpdate[iii]->UpdateContext();
}
}
}
}
}
@ -311,6 +330,18 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::TextureFile*& object, Ve
}
bool ewol::resource::Keep(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;
}
LocalAdd(object);
return true;
}
void ewol::resource::Release(ewol::Resource*& object)
{
@ -393,4 +424,5 @@ void ewol::resource::Release(ewol::TextureFile*& object)
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
Release(object2);
object = NULL;
}
}

View File

@ -30,6 +30,7 @@
#include <ewol/Resource.h>
#include <ewol/openGL/Shader.h>
#include <ewol/openGL/Program.h>
#include <ewol/openGL/VirtualBufferObject.h>
#include <ewol/font/Font.h>
#include <ewol/font/TexturedFont.h>
#include <ewol/font/DistantFieldFont.h>
@ -61,6 +62,7 @@ namespace ewol
#endif
bool Keep(ewol::Texture*& object); // no name needed here ...
bool Keep(etk::UString& filename, ewol::TextureFile*& object, Vector2D<int32_t> size);
bool Keep(etk::UString& accesMode, ewol::VirtualBufferObject*& object);
void Release(ewol::Resource*& object);
void Release(ewol::TexturedFont*& object);
@ -72,6 +74,7 @@ namespace ewol
#endif
void Release(ewol::Texture*& object);
void Release(ewol::TextureFile*& object);
void Release(ewol::VirtualBufferObject*& object);
}
};

View File

@ -34,9 +34,11 @@
ewol::Program::Program(etk::UString& filename) :
ewol::Resource(filename),
m_exist(false),
m_program(0),
m_hasTexture(false)
{
m_resourceLevel = 1;
EWOL_DEBUG("OGL : load PROGRAM \"" << filename << "\"");
// load data from file "all the time ..."
@ -81,7 +83,7 @@ ewol::Program::Program(etk::UString& filename) :
// close the file:
file.fClose();
CreateAndLink();
UpdateContext();
}
@ -93,20 +95,11 @@ ewol::Program::~Program(void)
m_shaderList[iii] = 0;
}
m_shaderList.Clear();
if (0!=m_program) {
glDeleteProgram(m_program);
m_program = 0;
}
RemoveContext();
m_elementList.Clear();
m_hasTexture = false;
}
void ewol::Program::Reload(void)
{
// TODO ...
}
static void checkGlError(const char* op, int32_t localLine)
{
for (GLint error = glGetError(); error; error = glGetError()) {
@ -117,38 +110,6 @@ static void checkGlError(const char* op, int32_t localLine)
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
bool ewol::Program::CreateAndLink(void)
{
EWOL_INFO("Create the Program ...");
m_program = glCreateProgram();
if (0 == m_program) {
EWOL_ERROR("program creation return error ...");
return false;
}
for (int32_t iii=0; iii<m_shaderList.Size(); iii++) {
if (NULL != m_shaderList[iii]) {
glAttachShader(m_program, m_shaderList[iii]->GetGL_ID());
checkGlError("glAttachShader", __LINE__);
}
}
glLinkProgram(m_program);
checkGlError("glLinkProgram", __LINE__);
GLint linkStatus = GL_FALSE;
glGetProgramiv(m_program, GL_LINK_STATUS, &linkStatus);
checkGlError("glGetProgramiv", __LINE__);
if (linkStatus != GL_TRUE) {
GLint bufLength = 0;
l_bufferDisplayError[0] = '\0';
glGetProgramInfoLog(m_program, LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
EWOL_ERROR("Could not compile \"PROGRAM\": " << l_bufferDisplayError);
glDeleteProgram(m_program);
checkGlError("glDeleteProgram", __LINE__);
m_program = 0;
return false;
}
return true;
}
int32_t ewol::Program::GetAttribute(etk::UString tmpElement)
{
@ -171,6 +132,128 @@ int32_t ewol::Program::GetAttribute(etk::UString tmpElement)
return m_elementList.Size()-1;
}
void ewol::Program::UpdateContext(void)
{
if (true==m_exist) {
// Do nothing ==> too dangerous ...
} else {
// create the Shader
EWOL_INFO("Create the Program ...");
m_program = glCreateProgram();
if (0 == m_program) {
EWOL_ERROR("program creation return error ...");
return;
}
for (int32_t iii=0; iii<m_shaderList.Size(); iii++) {
if (NULL != m_shaderList[iii]) {
glAttachShader(m_program, m_shaderList[iii]->GetGL_ID());
checkGlError("glAttachShader", __LINE__);
}
}
glLinkProgram(m_program);
checkGlError("glLinkProgram", __LINE__);
GLint linkStatus = GL_FALSE;
glGetProgramiv(m_program, GL_LINK_STATUS, &linkStatus);
checkGlError("glGetProgramiv", __LINE__);
if (linkStatus != GL_TRUE) {
GLint bufLength = 0;
l_bufferDisplayError[0] = '\0';
glGetProgramInfoLog(m_program, LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
EWOL_ERROR("Could not compile \"PROGRAM\": " << l_bufferDisplayError);
glDeleteProgram(m_program);
checkGlError("glDeleteProgram", __LINE__);
m_program = 0;
return;
}
m_exist = true;
// now get the old attribute requested priviously ...
for(int32_t iii=0; iii<m_elementList.Size(); iii++) {
m_elementList[iii].m_elementId = glGetAttribLocation(m_program, m_elementList[iii].m_name.c_str());
if (m_elementList[iii].m_elementId<0) {
checkGlError("glGetAttribLocation", __LINE__);
EWOL_INFO("glGetAttribLocation(\"" << m_elementList[iii].m_name << "\") = " << m_elementList[iii].m_elementId);
}
}
}
}
void ewol::Program::RemoveContext(void)
{
if (true==m_exist) {
glDeleteProgram(m_program);
m_program = 0;
m_exist = false;
for(int32_t iii=0; iii<m_elementList.Size(); iii++) {
m_elementList[iii].m_elementId=0;
}
}
}
void ewol::Program::RemoveContextToLate(void)
{
m_exist = false;
m_program = 0;
}
void ewol::Program::Reload(void)
{
/* TODO : ...
etk::File file(m_name, etk::FILE_TYPE_DATA);
if (false == file.Exist()) {
EWOL_ERROR("File does not Exist : \"" << file << "\"");
return;
}
int32_t fileSize = file.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << file);
return;
}
if (false == file.fOpenRead()) {
EWOL_ERROR("Can not open the file : " << file);
return;
}
// Remove previous data ...
if (NULL != m_fileData) {
delete[] m_fileData;
m_fileData = 0;
}
// allocate data
m_fileData = new char[fileSize+5];
if (NULL == m_fileData) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
// load data from the file :
file.fRead(m_fileData, 1, fileSize);
// close the file:
file.fClose();
*/
// now change the OGL context ...
RemoveContext();
UpdateContext();
}
int32_t ewol::Program::GetUniform(etk::UString tmpElement)
{
// check if it exist previously :

View File

@ -44,6 +44,7 @@
class Program : public ewol::Resource
{
private :
bool m_exist;
GLuint m_program;
etk::Vector<ewol::Shader*> m_shaderList;
etk::Vector<ewol::progAttributeElement> m_elementList;
@ -52,8 +53,6 @@
Program(etk::UString& filename);
virtual ~Program(void);
const char* GetType(void) { return "ewol::Program"; };
virtual void Reload(void);
bool CreateAndLink(void);
int32_t GetAttribute(etk::UString tmpElement);
void SendAttribute(int32_t idElem, int32_t nbElement, void* pointer, int32_t jumpBetweenSample=0);
int32_t GetUniform(etk::UString tmpElement);
@ -83,6 +82,10 @@
void Use(void);
void SetTexture0(int32_t idElem, GLint textureOpenGlID);
void UnUse(void);
void UpdateContext(void);
void RemoveContext(void);
void RemoveContextToLate(void);
void Reload(void);
};
};
#endif

View File

@ -33,10 +33,12 @@
ewol::Shader::Shader(etk::UString& filename):
ewol::Resource(filename),
m_exist(false),
m_fileData(NULL),
m_shader(0),
m_type(0)
{
m_resourceLevel = 0;
EWOL_DEBUG("OGL : load SHADER \"" << filename << "\"");
// load data from file "all the time ..."
@ -55,30 +57,7 @@ ewol::Shader::Shader(etk::UString& filename):
EWOL_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << fileExtention << "\"");
return;
}
int32_t fileSize = file.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << file);
return;
}
if (false == file.fOpenRead()) {
EWOL_ERROR("Can not open the file : " << file);
return;
}
// allocate data
m_fileData = new char[fileSize+5];
if (NULL == m_fileData) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
// load data from the file :
file.fRead(m_fileData, 1, fileSize);
// close the file:
file.fClose();
CompileAndSendShader();
Reload();
}
@ -92,6 +71,7 @@ ewol::Shader::~Shader(void)
glDeleteShader(m_shader);
m_shader = 0;
}
m_exist = false;
}
@ -104,36 +84,96 @@ static void checkGlError(const char* op)
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
bool ewol::Shader::CompileAndSendShader(void)
void ewol::Shader::UpdateContext(void)
{
if (NULL == m_fileData) {
m_shader = 0;
return false;
}
m_shader = glCreateShader(m_type);
if (!m_shader) {
EWOL_ERROR("glCreateShader return error ...");
checkGlError("glCreateShader");
return false;
if (true==m_exist) {
// Do nothing ==> too dangerous ...
} else {
glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL);
glCompileShader(m_shader);
GLint compiled = 0;
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
if (!compiled) {
GLint infoLen = 0;
l_bufferDisplayError[0] = '\0';
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
if (m_type == GL_VERTEX_SHADER){
tmpShaderType = "GL_VERTEX_SHADER";
}
EWOL_ERROR("Could not compile \"" << tmpShaderType << "\": " << l_bufferDisplayError);
return false;
// create the Shader
if (NULL == m_fileData) {
m_shader = 0;
return;
}
m_shader = glCreateShader(m_type);
if (!m_shader) {
EWOL_ERROR("glCreateShader return error ...");
checkGlError("glCreateShader");
return;
} else {
glShaderSource(m_shader, 1, (const char**)&m_fileData, NULL);
glCompileShader(m_shader);
GLint compiled = 0;
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled);
if (!compiled) {
GLint infoLen = 0;
l_bufferDisplayError[0] = '\0';
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
if (m_type == GL_VERTEX_SHADER){
tmpShaderType = "GL_VERTEX_SHADER";
}
EWOL_ERROR("Could not compile \"" << tmpShaderType << "\": " << l_bufferDisplayError);
return;
}
}
m_exist = true;
}
return true;
}
void ewol::Shader::RemoveContext(void)
{
if (true==m_exist) {
glDeleteShader(m_shader);
m_exist = false;
m_shader = 0;
}
}
void ewol::Shader::RemoveContextToLate(void)
{
m_exist = false;
m_shader = 0;
}
void ewol::Shader::Reload(void)
{
etk::File file(m_name, etk::FILE_TYPE_DATA);
if (false == file.Exist()) {
EWOL_ERROR("File does not Exist : \"" << file << "\"");
return;
}
int32_t fileSize = file.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << file);
return;
}
if (false == file.fOpenRead()) {
EWOL_ERROR("Can not open the file : " << file);
return;
}
// Remove previous data ...
if (NULL != m_fileData) {
delete[] m_fileData;
m_fileData = 0;
}
// allocate data
m_fileData = new char[fileSize+5];
if (NULL == m_fileData) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
// load data from the file :
file.fRead(m_fileData, 1, fileSize);
// close the file:
file.fClose();
// now change the OGL context ...
RemoveContext();
UpdateContext();
}
#endif

View File

@ -35,6 +35,7 @@
class Shader : public ewol::Resource
{
private :
bool m_exist;
char* m_fileData;
GLuint m_shader;
GLenum m_type;
@ -44,7 +45,10 @@
const char* GetType(void) { return "ewol::Shader"; };
GLuint GetGL_ID(void) { return m_shader; };
GLenum GetShaderType(void) { return m_type; };
bool CompileAndSendShader(void);
void UpdateContext(void);
void RemoveContext(void);
void RemoveContextToLate(void);
void Reload(void);
};
};
#endif

View File

@ -0,0 +1,102 @@
/**
*******************************************************************************
* @file ewol/openGL/VirtualBufferObject.cpp
* @brief ewol openGl virtualBufferObject system (Sources)
* @author Edouard DUPIN
* @date 10/10/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 <etk/File.h>
#include <ewol/Debug.h>
#include <ewol/openGL/VirtualBufferObject.h>
ewol::VirtualBufferObject::VirtualBufferObject(etk::UString& accesMode):
ewol::Resource(),
m_exist(false),
m_vbo(0)
{
m_resourceLevel = 3;
EWOL_DEBUG("OGL : load VBO mode\"" << accesMode << "\"");
// load data from file "all the time ..."
/*
glGenBuffers(1, &m_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
*/
}
ewol::VirtualBufferObject::~VirtualBufferObject(void)
{
RemoveContext();
}
void ewol::VirtualBufferObject::RetreiveData(void)
{
EWOL_ERROR("TODO ... ");
}
void ewol::VirtualBufferObject::UpdateContext(void)
{
if (true==m_exist) {
// update the data
if (m_buffer.Size()<=0) {
RemoveContext();
} else {
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer.Size(), &m_buffer[0], GL_STATIC_DRAW);
}
} else {
// create the Buffer
if (m_buffer.Size()>0) {
glGenBuffers(1, &m_vbo);
m_exist = true;
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*m_buffer.Size(), &m_buffer[0], GL_STATIC_DRAW);
}
// Note we did not create the buffer when no data is needed
}
}
void ewol::VirtualBufferObject::RemoveContext(void)
{
if (true==m_exist) {
glDeleteBuffers(1, &m_vbo);
m_exist = false;
m_vbo = 0;
}
}
void ewol::VirtualBufferObject::RemoveContextToLate(void)
{
m_exist = false;
m_vbo = 0;
}
void ewol::VirtualBufferObject::Reload(void)
{
RemoveContext();
UpdateContext();
}

View File

@ -0,0 +1,56 @@
/**
*******************************************************************************
* @file ewol/openGL/VirtualBufferObject.h
* @brief ewol openGl virtualBufferObject system (header)
* @author Edouard DUPIN
* @date 10/10/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 __OPEN_GL__VIRTUAL_BUFFER_OBJECT_H__
#define __OPEN_GL__VIRTUAL_BUFFER_OBJECT_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/Resource.h>
#include <ewol/openGL/openGL.h>
namespace ewol
{
class VirtualBufferObject : public ewol::Resource
{
private :
bool m_exist;
GLuint m_vbo;
public:
// data that is availlable in the VBO system ...
etk::Vector<float> m_buffer;
public:
VirtualBufferObject(etk::UString& accesMode);
virtual ~VirtualBufferObject(void);
const char* GetType(void) { return "ewol::VirtualBufferObject"; };
GLuint GetGL_ID(void) { return m_vbo; };
etk::Vector<float>& GetRefByffer(void) { return m_buffer; };
void RetreiveData(void);
void UpdateContext(void);
void RemoveContext(void);
void RemoveContextToLate(void);
void Reload(void);
};
};
#endif

View File

@ -1,94 +0,0 @@
/**
*******************************************************************************
* @file ewol/theme/Theme.cpp
* @brief basic ewol Theme basic class (Sources)
* @author Edouard DUPIN
* @date 23/11/2011
* @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 <tinyXML/tinyxml.h>
#include <ewol/theme/Theme.h>
#include <ewol/Debug.h>
#undef __class__
#define __class__ "theme"
void ewol::theme::Load(etk::File & localFile)
{
if (localFile.HasExtention() == false) {
EWOL_ERROR("can not load theme with file, has no extention : " << localFile);
return;
}
if (localFile.GetExtention() != "eol") {
EWOL_ERROR("can not load theme with file, has not extention .eol : " << localFile);
return;
}
if (false == localFile.Exist()) {
EWOL_ERROR("File does not Exist ... " << localFile);
return;
} else {
TiXmlDocument XmlDocument;
// open the curent File
if (false == localFile.Exist()) {
EWOL_ERROR("File Does not exist : " << localFile);
return;
}
int32_t fileSize = localFile.Size();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << localFile);
return;
}
if (false == localFile.fOpenRead()) {
EWOL_ERROR("Can not open the file : " << localFile);
return;
}
// allocate data
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
// load data from the file :
localFile.fRead(fileBuffer, 1, fileSize);
// close the file:
localFile.fClose();
// load the XML from the memory
XmlDocument.Parse((const char*)fileBuffer, 0, TIXML_ENCODING_UTF8);
TiXmlElement* root = XmlDocument.FirstChildElement( "ewolTheme" );
if (NULL == root ) {
EWOL_ERROR("(l ?) main node not find: \"ewolTheme\" in \"" << localFile << "\"");
return;
} else {
for(TiXmlNode * pNode=root->FirstChild(); NULL!=pNode; pNode = pNode->NextSibling()) {
if (pNode->Type()==TiXmlNode::TINYXML_COMMENT) {
continue;
}
EWOL_TODO("default theme loading");
//EWOL_ERROR("(l " << pNode->Row() << ") node not suported : \"" << nodeValue <<"\" must be [???,???]");
}
}
if (NULL != fileBuffer) {
delete[] fileBuffer;
}
}
}

View File

@ -1,41 +0,0 @@
/**
*******************************************************************************
* @file ewol/theme/Theme.h
* @brief basic ewol Theme basic class (Header)
* @author Edouard DUPIN
* @date 23/11/2011
* @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_EOL_THEME_H__
#define __EWOL_EOL_THEME_H__
#include <etk/Types.h>
#include <etk/UString.h>
#include <etk/File.h>
namespace ewol {
namespace theme {
void Load(etk::File & localFile);
};
};
#endif

View File

@ -8,7 +8,8 @@ FILE_LIST = ewol/ewol.cpp \
FILE_LIST+= ewol/openGL/openGL.cpp \
ewol/openGL/Shader.cpp \
ewol/openGL/Program.cpp
ewol/openGL/Program.cpp \
ewol/openGL/VirtualBufferObject.cpp
# Gui interface
@ -79,9 +80,6 @@ FILE_LIST+= ewol/widget/Widget.cpp \
ewol/widget/meta/Parameter.cpp \
ewol/widget/meta/ParameterList.cpp
# Theme parsing ...
FILE_LIST+= ewol/theme/Theme.cpp
# Audio system
FILE_LIST+= ewol/audio/audio.cpp \
ewol/audio/decWav.cpp