[DEV] update new ememory::SharedPtr

This commit is contained in:
Edouard DUPIN 2016-07-15 21:22:11 +02:00
parent be8aee1788
commit 8109039223
19 changed files with 151 additions and 141 deletions

View File

@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
#include <memory> #include <ememory/memory.h>
#include <etk/types.h> #include <etk/types.h>
#include <etk/math/Vector2D.h> #include <etk/math/Vector2D.h>
#include <gale/orientation.h> #include <gale/orientation.h>
@ -17,7 +17,7 @@
namespace gale { namespace gale {
class Context; class Context;
class Application : public std::enable_shared_from_this<gale::Application> { class Application : public ememory::EnableSharedFromThis<gale::Application> {
public: public:
Application(); Application();
virtual ~Application(); virtual ~Application();

View File

@ -42,7 +42,7 @@ void gale::Thread::start() {
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this); pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this);
#else #else
m_thread = std::make_shared<std::thread>(&gale::Thread::threadCall, this); m_thread = ememory::makeShared<std::thread>(&gale::Thread::threadCall, this);
if (m_thread == nullptr) { if (m_thread == nullptr) {
GALE_ERROR("Can not create thread ..."); GALE_ERROR("Can not create thread ...");
return; return;

View File

@ -32,7 +32,7 @@ namespace gale {
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
pthread_t m_thread; pthread_t m_thread;
#else #else
std::shared_ptr<std::thread> m_thread; ememory::SharedPtr<std::thread> m_thread;
#endif #endif
gale::Context* m_context; gale::Context* m_context;
public: public:

View File

@ -128,13 +128,13 @@ void gale::Context::unLockContext() {
} }
#if 0 #if 0
void gale::Context::inputEventTransfertWidget(std::shared_ptr<gale::Widget> _source, void gale::Context::inputEventTransfertWidget(ememory::SharedPtr<gale::Widget> _source,
std::shared_ptr<gale::Widget> _destination) { ememory::SharedPtr<gale::Widget> _destination) {
m_input.transfertEvent(_source, _destination); m_input.transfertEvent(_source, _destination);
} }
void gale::Context::inputEventGrabPointer(std::shared_ptr<gale::Widget> _widget) { void gale::Context::inputEventGrabPointer(ememory::SharedPtr<gale::Widget> _widget) {
m_input.grabPointer(_widget); m_input.grabPointer(_widget);
} }
@ -275,7 +275,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
m_simulationFile.filePuts("\n"); m_simulationFile.filePuts("\n");
} }
m_msgSystem.post([](gale::Context& _context){ m_msgSystem.post([](gale::Context& _context){
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl == nullptr) { if (appl == nullptr) {
return; return;
} }
@ -389,7 +389,7 @@ void gale::Context::OS_SetInput(enum gale::key::type _type,
m_simulationFile.filePuts("\n"); m_simulationFile.filePuts("\n");
} }
m_msgSystem.post([_type, _status, _pointerID, _pos](gale::Context& _context){ m_msgSystem.post([_type, _status, _pointerID, _pos](gale::Context& _context){
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl == nullptr) { if (appl == nullptr) {
return; return;
} }
@ -425,7 +425,7 @@ void gale::Context::OS_setKeyboard(const gale::key::Special& _special,
m_simulationFile.filePuts("\n"); m_simulationFile.filePuts("\n");
} }
m_msgSystem.post([_special, _type, _state, _char](gale::Context& _context){ m_msgSystem.post([_special, _type, _state, _char](gale::Context& _context){
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl == nullptr) { if (appl == nullptr) {
return; return;
} }
@ -443,7 +443,7 @@ void gale::Context::OS_Hide() {
} }
m_msgSystem.post([](gale::Context& _context){ m_msgSystem.post([](gale::Context& _context){
/* /*
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl == nullptr) { if (appl == nullptr) {
return; return;
} }
@ -463,7 +463,7 @@ void gale::Context::OS_Show() {
} }
m_msgSystem.post([](gale::Context& _context){ m_msgSystem.post([](gale::Context& _context){
/* /*
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl == nullptr) { if (appl == nullptr) {
return; return;
} }
@ -485,7 +485,7 @@ void gale::Context::OS_ClipBoardArrive(enum gale::context::clipBoard::clipboardL
m_simulationFile.filePuts("\n"); m_simulationFile.filePuts("\n");
} }
m_msgSystem.post([_clipboardID](gale::Context& _context){ m_msgSystem.post([_clipboardID](gale::Context& _context){
std::shared_ptr<gale::Application> appl = _context.getApplication(); ememory::SharedPtr<gale::Application> appl = _context.getApplication();
if (appl != nullptr) { if (appl != nullptr) {
appl->onClipboardEvent(_clipboardID); appl->onClipboardEvent(_clipboardID);
} }

View File

@ -16,7 +16,7 @@
#include <gale/context/commandLine.h> #include <gale/context/commandLine.h>
// TODO : #include <gale/context/InputManager.h> // TODO : #include <gale/context/InputManager.h>
#include <gale/context/Fps.h> #include <gale/context/Fps.h>
#include <memory> #include <ememory/memory.h>
#include <gale/orientation.h> #include <gale/orientation.h>
#include <gale/context/clipBoard.h> #include <gale/context/clipBoard.h>
#include <ethread/tools.h> #include <ethread/tools.h>
@ -26,9 +26,9 @@
namespace gale { namespace gale {
class Context/* : private gale::object::RemoveEvent */{ class Context/* : private gale::object::RemoveEvent */{
private: private:
std::shared_ptr<gale::Application> m_application; //!< Application handle ememory::SharedPtr<gale::Application> m_application; //!< Application handle
public: public:
std::shared_ptr<gale::Application> getApplication() { ememory::SharedPtr<gale::Application> getApplication() {
return m_application; return m_application;
} }
private: private:
@ -184,12 +184,12 @@ namespace gale {
* @param source the widget where the event came from * @param source the widget where the event came from
* @param destination the widget where the event mitgh be generated now * @param destination the widget where the event mitgh be generated now
*/ */
void inputEventTransfertWidget(std::shared_ptr<gale::Widget> _source, std::shared_ptr<gale::Widget> _destination); void inputEventTransfertWidget(ememory::SharedPtr<gale::Widget> _source, ememory::SharedPtr<gale::Widget> _destination);
/** /**
* @brief This fonction lock the pointer properties to move in relative instead of absolute * @brief This fonction lock the pointer properties to move in relative instead of absolute
* @param[in] widget The widget that lock the pointer events * @param[in] widget The widget that lock the pointer events
*/ */
void inputEventGrabPointer(std::shared_ptr<gale::Widget> _widget); void inputEventGrabPointer(ememory::SharedPtr<gale::Widget> _widget);
/** /**
* @brief This fonction un-lock the pointer properties to move in relative instead of absolute * @brief This fonction un-lock the pointer properties to move in relative instead of absolute
*/ */

View File

@ -34,7 +34,7 @@ void gale::context::InputManager::setDpi(int32_t newDPI) {
} }
bool gale::context::InputManager::localEventInput(enum gale::key::type _type, bool gale::context::InputManager::localEventInput(enum gale::key::type _type,
std::shared_ptr<gale::Application> _destApplication, ememory::SharedPtr<gale::Application> _destApplication,
int32_t _IdInput, int32_t _IdInput,
enum gale::key::status _status, enum gale::key::status _status,
vec2 _pos) { vec2 _pos) {
@ -104,13 +104,13 @@ gale::context::InputManager::~InputManager() {
} }
int32_t gale::context::InputManager::localGetDestinationId(enum gale::key::type _type, int32_t gale::context::InputManager::localGetDestinationId(enum gale::key::type _type,
std::shared_ptr<gale::Application> _destApplication, ememory::SharedPtr<gale::Application> _destApplication,
int32_t _realInputId) { int32_t _realInputId) {
if (_type == gale::key::typeFinger) { if (_type == gale::key::typeFinger) {
int32_t lastMinimum = 0; int32_t lastMinimum = 0;
for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) { for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
if (true == m_eventInputSaved[iii].isUsed) { if (true == m_eventInputSaved[iii].isUsed) {
std::shared_ptr<gale::Application> tmpApplication = m_eventInputSaved[iii].curentApplicationEvent.lock(); ememory::SharedPtr<gale::Application> tmpApplication = m_eventInputSaved[iii].curentApplicationEvent.lock();
if (tmpApplication == _destApplication) { if (tmpApplication == _destApplication) {
if (iii != _realInputId) { if (iii != _realInputId) {
lastMinimum = std::max(lastMinimum, m_eventInputSaved[iii].destinationInputId); lastMinimum = std::max(lastMinimum, m_eventInputSaved[iii].destinationInputId);
@ -146,12 +146,12 @@ void gale::context::InputManager::motion(enum gale::key::type _type,
// not manage input // not manage input
return; return;
} }
std::shared_ptr<gale::Application::Windows> tmpWindows = m_context.getWindows(); ememory::SharedPtr<gale::Application::Windows> tmpWindows = m_context.getWindows();
// special case for the mouse event 0 that represent the hover event of the system : // special case for the mouse event 0 that represent the hover event of the system :
if (_type == gale::key::typeMouse && _pointerID == 0) { if (_type == gale::key::typeMouse && _pointerID == 0) {
// this event is all time on the good Application ... and manage the enter and leave ... // this event is all time on the good Application ... and manage the enter and leave ...
// NOTE : the "layer Application" force us to get the Application at the specific position all the time : // NOTE : the "layer Application" force us to get the Application at the specific position all the time :
std::shared_ptr<gale::Application> tmpApplication; ememory::SharedPtr<gale::Application> tmpApplication;
if (m_grabApplication.lock() != nullptr) { if (m_grabApplication.lock() != nullptr) {
// grab all events ... // grab all events ...
tmpApplication = m_grabApplication.lock(); tmpApplication = m_grabApplication.lock();
@ -282,7 +282,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
} }
// get the curent time ... // get the curent time ...
int64_t currentTime = gale::getTime(); int64_t currentTime = gale::getTime();
std::shared_ptr<gale::Application::Windows> tmpWindows = m_context.getWindows(); ememory::SharedPtr<gale::Application::Windows> tmpWindows = m_context.getWindows();
if (true == _isDown) { if (true == _isDown) {
EVENT_DEBUG("GUI : Input ID=" << _pointerID EVENT_DEBUG("GUI : Input ID=" << _pointerID
@ -319,7 +319,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
eventTable[_pointerID].lastTimeEvent = currentTime; eventTable[_pointerID].lastTimeEvent = currentTime;
// set the element inside ... // set the element inside ...
eventTable[_pointerID].isInside = true; eventTable[_pointerID].isInside = true;
std::shared_ptr<gale::Application> tmpApplication = m_grabApplication.lock(); ememory::SharedPtr<gale::Application> tmpApplication = m_grabApplication.lock();
// get destination Application : // get destination Application :
if(nullptr != tmpWindows) { if(nullptr != tmpWindows) {
if ( tmpApplication != nullptr if ( tmpApplication != nullptr
@ -362,7 +362,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
// revove the Application ... // revove the Application ...
eventTable[_pointerID].curentApplicationEvent.reset(); eventTable[_pointerID].curentApplicationEvent.reset();
} else { } else {
std::shared_ptr<gale::Application> tmpApplication = eventTable[_pointerID].curentApplicationEvent.lock(); ememory::SharedPtr<gale::Application> tmpApplication = eventTable[_pointerID].curentApplicationEvent.lock();
// generate UP Event // generate UP Event
EVENT_DEBUG("GUI : Input ID=" << _pointerID EVENT_DEBUG("GUI : Input ID=" << _pointerID
<< " == >" << eventTable[_pointerID].destinationInputId << " == >" << eventTable[_pointerID].destinationInputId

View File

@ -19,7 +19,7 @@ namespace gale {
bool isUsed; bool isUsed;
int32_t destinationInputId; int32_t destinationInputId;
int64_t lastTimeEvent; int64_t lastTimeEvent;
std::weak_ptr<gale::Application> curentApplicationEvent; ememory::WeakPtr<gale::Application> curentApplicationEvent;
vec2 origin; vec2 origin;
vec2 size; vec2 size;
vec2 downStart; vec2 downStart;
@ -42,7 +42,7 @@ namespace gale {
class InputManager { class InputManager {
// special grab pointer mode : // special grab pointer mode :
private: private:
std::weak_ptr<gale::Application> m_grabApplication; //!< Application that grab the curent pointer. ememory::WeakPtr<gale::Application> m_grabApplication; //!< Application that grab the curent pointer.
private: private:
int32_t m_dpi; int32_t m_dpi;
InputLimit m_eventInputLimit; InputLimit m_eventInputLimit;
@ -62,7 +62,7 @@ namespace gale {
* @return true if event has been greped * @return true if event has been greped
*/ */
bool localEventInput(enum gale::key::type _type, bool localEventInput(enum gale::key::type _type,
std::shared_ptr<gale::Application> _destApplication, ememory::SharedPtr<gale::Application> _destApplication,
int32_t _IdInput, int32_t _IdInput,
enum gale::key::status _typeEvent, enum gale::key::status _typeEvent,
vec2 _pos); vec2 _pos);
@ -76,7 +76,7 @@ namespace gale {
* @return the gale input id * @return the gale input id
*/ */
int32_t localGetDestinationId(enum gale::key::type _type, int32_t localGetDestinationId(enum gale::key::type _type,
std::shared_ptr<gale::Application> _destApplication, ememory::SharedPtr<gale::Application> _destApplication,
int32_t _realInputId); int32_t _realInputId);
private: private:
gale::Context& m_context; gale::Context& m_context;

View File

@ -42,11 +42,11 @@ void gale::resource::Manager::unInit() {
// remove all resources ... // remove all resources ...
auto it(m_resourceList.begin()); auto it(m_resourceList.begin());
while(it != m_resourceList.end()) { while(it != m_resourceList.end()) {
std::shared_ptr<gale::Resource> tmpRessource = (*it).lock(); ememory::SharedPtr<gale::Resource> tmpRessource = (*it).lock();
if (tmpRessource != nullptr) { if (tmpRessource != nullptr) {
GALE_WARNING("Find a resource that is not removed : [" << tmpRessource->getId() << "]" GALE_WARNING("Find a resource that is not removed : [" << tmpRessource->getId() << "]"
<< "=\"" << tmpRessource->getName() << "\" " << "=\"" << tmpRessource->getName() << "\" "
<< tmpRessource.use_count() << " elements"); << tmpRessource.useCount() << " elements");
} }
m_resourceList.erase(it); m_resourceList.erase(it);
it = m_resourceList.begin(); it = m_resourceList.begin();
@ -59,12 +59,12 @@ void gale::resource::Manager::display() {
// remove all resources ... // remove all resources ...
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceList) { for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource != nullptr) { if (tmpRessource != nullptr) {
GALE_INFO(" [" << tmpRessource->getId() << "]" GALE_INFO(" [" << tmpRessource->getId() << "]"
<< tmpRessource->getType() << tmpRessource->getType()
<< "=\"" << tmpRessource->getName() << "\" " << "=\"" << tmpRessource->getName() << "\" "
<< tmpRessource.use_count() << " elements"); << tmpRessource.useCount() << " elements");
} }
} }
GALE_INFO("Resources ---"); GALE_INFO("Resources ---");
@ -78,7 +78,7 @@ void gale::resource::Manager::reLoadResources() {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) { for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
GALE_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1)); GALE_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (auto &it : m_resourceList) { for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if(tmpRessource != nullptr) { if(tmpRessource != nullptr) {
if (jjj == tmpRessource->getResourceLevel()) { if (jjj == tmpRessource->getResourceLevel()) {
tmpRessource->reload(); tmpRessource->reload();
@ -93,7 +93,7 @@ void gale::resource::Manager::reLoadResources() {
GALE_INFO("------------- Resources -------------"); GALE_INFO("------------- Resources -------------");
} }
void gale::resource::Manager::update(const std::shared_ptr<gale::Resource>& _object) { void gale::resource::Manager::update(const ememory::SharedPtr<gale::Resource>& _object) {
// chek if not added before // chek if not added before
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceListToUpdate) { for (auto &it : m_resourceListToUpdate) {
@ -113,7 +113,7 @@ void gale::resource::Manager::updateContext() {
if (m_contextHasBeenRemoved == true) { if (m_contextHasBeenRemoved == true) {
// need to update all ... // need to update all ...
m_contextHasBeenRemoved = false; m_contextHasBeenRemoved = false;
std::list<std::weak_ptr<gale::Resource>> resourceList; std::list<ememory::WeakPtr<gale::Resource>> resourceList;
{ {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
// Clean the update list // Clean the update list
@ -124,7 +124,7 @@ void gale::resource::Manager::updateContext() {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) { for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
GALE_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1)); GALE_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (auto &it : resourceList) { for (auto &it : resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if( tmpRessource != nullptr if( tmpRessource != nullptr
&& jjj == tmpRessource->getResourceLevel()) { && jjj == tmpRessource->getResourceLevel()) {
//GALE_DEBUG("Update context named : " << l_resourceList[iii]->getName()); //GALE_DEBUG("Update context named : " << l_resourceList[iii]->getName());
@ -138,7 +138,7 @@ void gale::resource::Manager::updateContext() {
} }
} }
} else { } else {
std::vector<std::shared_ptr<gale::Resource>> resourceListToUpdate; std::vector<ememory::SharedPtr<gale::Resource>> resourceListToUpdate;
{ {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
resourceListToUpdate = m_resourceListToUpdate; resourceListToUpdate = m_resourceListToUpdate;
@ -167,7 +167,7 @@ void gale::resource::Manager::updateContext() {
void gale::resource::Manager::contextHasBeenDestroyed() { void gale::resource::Manager::contextHasBeenDestroyed() {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceList) { for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource != nullptr) { if (tmpRessource != nullptr) {
tmpRessource->removeContextToLate(); tmpRessource->removeContextToLate();
} }
@ -177,11 +177,11 @@ void gale::resource::Manager::contextHasBeenDestroyed() {
} }
// internal generic keeper ... // internal generic keeper ...
std::shared_ptr<gale::Resource> gale::resource::Manager::localKeep(const std::string& _filename) { ememory::SharedPtr<gale::Resource> gale::resource::Manager::localKeep(const std::string& _filename) {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
GALE_VERBOSE("KEEP (DEFAULT) : file : '" << _filename << "' in " << m_resourceList.size() << " resources"); GALE_VERBOSE("KEEP (DEFAULT) : file : '" << _filename << "' in " << m_resourceList.size() << " resources");
for (auto &it : m_resourceList) { for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource != nullptr) { if (tmpRessource != nullptr) {
if (tmpRessource->getName() == _filename) { if (tmpRessource->getName() == _filename) {
return tmpRessource; return tmpRessource;
@ -192,11 +192,11 @@ std::shared_ptr<gale::Resource> gale::resource::Manager::localKeep(const std::st
} }
// internal generic keeper ... // internal generic keeper ...
void gale::resource::Manager::localAdd(const std::shared_ptr<gale::Resource>& _object) { void gale::resource::Manager::localAdd(const ememory::SharedPtr<gale::Resource>& _object) {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
//Add ... find empty slot //Add ... find empty slot
for (auto &it : m_resourceList) { for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock(); ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource == nullptr) { if (tmpRessource == nullptr) {
it = _object; it = _object;
return; return;

View File

@ -15,8 +15,8 @@ namespace gale {
namespace resource { namespace resource {
class Manager{ class Manager{
private: private:
std::list<std::weak_ptr<gale::Resource>> m_resourceList; std::list<ememory::WeakPtr<gale::Resource>> m_resourceList;
std::vector<std::shared_ptr<gale::Resource>> m_resourceListToUpdate; std::vector<ememory::SharedPtr<gale::Resource>> m_resourceListToUpdate;
bool m_contextHasBeenRemoved; bool m_contextHasBeenRemoved;
std::recursive_mutex m_mutex; std::recursive_mutex m_mutex;
public: public:
@ -46,7 +46,7 @@ namespace gale {
* @brief Call by the system to send all the needed data on the graphic card chen they change ... * @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(const std::shared_ptr<gale::Resource>& _object); void update(const ememory::SharedPtr<gale::Resource>& _object);
/** /**
* @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other .... * @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
*/ */
@ -57,8 +57,8 @@ namespace gale {
void contextHasBeenDestroyed(); void contextHasBeenDestroyed();
public: public:
// internal API to extent eResources in extern Soft // internal API to extent eResources in extern Soft
std::shared_ptr<gale::Resource> localKeep(const std::string& _filename); ememory::SharedPtr<gale::Resource> localKeep(const std::string& _filename);
void localAdd(const std::shared_ptr<gale::Resource>& _object); void localAdd(const ememory::SharedPtr<gale::Resource>& _object);
virtual void cleanInternalRemoved(); virtual void cleanInternalRemoved();
}; };
} }

View File

@ -32,13 +32,13 @@ void gale::resource::Program::init(const std::string& _filename) {
// load data from file "all the time ..." // load data from file "all the time ..."
etk::FSNode file(m_name); etk::FSNode file(m_name);
if (false == file.exist()) { if (file.exist() == false) {
GALE_INFO("File does not Exist : \"" << file << "\" == > automatic load of framment and shader with same names... "); GALE_INFO("File does not Exist : \"" << file << "\" == > automatic load of framment and shader with same names... ");
std::string tmpFilename = m_name; std::string tmpFilename = m_name;
// remove extention ... // remove extention ...
tmpFilename.erase(tmpFilename.size()-4, 4); tmpFilename.erase(tmpFilename.size()-4, 4);
std::shared_ptr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert"); ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert");
if (nullptr == tmpShader) { if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename); GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
return; return;
} else { } else {
@ -46,7 +46,7 @@ void gale::resource::Program::init(const std::string& _filename) {
m_shaderList.push_back(tmpShader); m_shaderList.push_back(tmpShader);
} }
tmpShader = gale::resource::Shader::create(tmpFilename+"frag"); tmpShader = gale::resource::Shader::create(tmpFilename+"frag");
if (nullptr == tmpShader) { if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename); GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
return; return;
} else { } else {
@ -59,7 +59,7 @@ void gale::resource::Program::init(const std::string& _filename) {
GALE_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\""); GALE_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
return; return;
} }
if (false == file.fileOpenRead()) { if (file.fileOpenRead() == false) {
GALE_ERROR("Can not open the file : \"" << file << "\""); GALE_ERROR("Can not open the file : \"" << file << "\"");
return; return;
} }
@ -81,8 +81,8 @@ void gale::resource::Program::init(const std::string& _filename) {
} }
// get it with relative position : // get it with relative position :
std::string tmpFilename = file.getRelativeFolder() + tmpData; std::string tmpFilename = file.getRelativeFolder() + tmpData;
std::shared_ptr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename); ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename);
if (nullptr == tmpShader) { if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename); GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
} else { } else {
GALE_DEBUG("Add shader on program : "<< tmpFilename); GALE_DEBUG("Add shader on program : "<< tmpFilename);
@ -96,7 +96,7 @@ void gale::resource::Program::init(const std::string& _filename) {
if (gale::openGL::hasContext() == true) { if (gale::openGL::hasContext() == true) {
updateContext(); updateContext();
} else { } else {
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
} }
} }
@ -182,7 +182,7 @@ int32_t gale::resource::Program::getAttribute(std::string _elementName) {
tmp.m_name = _elementName; tmp.m_name = _elementName;
tmp.m_isAttribute = true; tmp.m_isAttribute = true;
if (gale::openGL::hasContext() == false) { if (gale::openGL::hasContext() == false) {
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
tmp.m_elementId = -1; tmp.m_elementId = -1;
tmp.m_isLinked = false; tmp.m_isLinked = false;
} else if (m_exist == true) { } else if (m_exist == true) {
@ -215,7 +215,7 @@ int32_t gale::resource::Program::getUniform(std::string _elementName) {
tmp.m_name = _elementName; tmp.m_name = _elementName;
tmp.m_isAttribute = false; tmp.m_isAttribute = false;
if (gale::openGL::hasContext() == false) { if (gale::openGL::hasContext() == false) {
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
tmp.m_elementId = -1; tmp.m_elementId = -1;
tmp.m_isLinked = false; tmp.m_isLinked = false;
} else if (m_exist == true) { } else if (m_exist == true) {
@ -253,14 +253,14 @@ bool gale::resource::Program::updateContext() {
} }
// first attach vertex shader, and after fragment shader // first attach vertex shader, and after fragment shader
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (nullptr != m_shaderList[iii]) { if (m_shaderList[iii] != nullptr) {
if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::vertex) { if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::vertex) {
gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID()); gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
} }
} }
} }
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (nullptr != m_shaderList[iii]) { if (m_shaderList[iii] != nullptr) {
if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::fragment) { if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::fragment) {
gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID()); gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
} }
@ -323,28 +323,28 @@ void gale::resource::Program::removeContextToLate() {
void gale::resource::Program::reload() { void gale::resource::Program::reload() {
/* TODO : ... /* TODO : ...
etk::file file(m_name, etk::FILE_TYPE_DATA); etk::file file(m_name, etk::FILE_TYPE_DATA);
if (false == file.Exist()) { if (file.Exist() == false) {
GALE_ERROR("File does not Exist : \"" << file << "\""); GALE_ERROR("File does not Exist : \"" << file << "\"");
return; return;
} }
int32_t fileSize = file.size(); int32_t fileSize = file.size();
if (0 == fileSize) { if (fileSize == 0) {
GALE_ERROR("This file is empty : " << file); GALE_ERROR("This file is empty : " << file);
return; return;
} }
if (false == file.fOpenRead()) { if (file.fOpenRead() == false) {
GALE_ERROR("Can not open the file : " << file); GALE_ERROR("Can not open the file : " << file);
return; return;
} }
// remove previous data ... // remove previous data ...
if (nullptr != m_fileData) { if (m_fileData != nullptr) {
delete[] m_fileData; delete[] m_fileData;
m_fileData = 0; m_fileData = 0;
} }
// allocate data // allocate data
m_fileData = new char[fileSize+5]; m_fileData = new char[fileSize+5];
if (nullptr == m_fileData) { if (m_fileData == nullptr) {
GALE_ERROR("Error Memory allocation size=" << fileSize); GALE_ERROR("Error Memory allocation size=" << fileSize);
return; return;
} }
@ -390,7 +390,7 @@ void gale::resource::Program::sendAttribute(int32_t _idElem,
} }
void gale::resource::Program::sendAttributePointer(int32_t _idElem, void gale::resource::Program::sendAttributePointer(int32_t _idElem,
const std::shared_ptr<gale::resource::VirtualBufferObject>& _vbo, const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
int32_t _index, int32_t _index,
int32_t _jumpBetweenSample, int32_t _jumpBetweenSample,
int32_t _offset) { int32_t _offset) {
@ -589,18 +589,19 @@ void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -612,18 +613,19 @@ void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -635,18 +637,19 @@ void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -659,18 +662,19 @@ void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -686,18 +690,19 @@ void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -709,18 +714,19 @@ void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -732,18 +738,19 @@ void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -755,18 +762,19 @@ void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]"); GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
if (0 == _nbElement) { if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ..."); GALE_ERROR("No element to send at open GL ...");
return; return;
} }
if (nullptr == _value) { if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ..."); GALE_ERROR("nullptr Input pointer to send at open GL ...");
return; return;
} }
@ -797,10 +805,11 @@ void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenG
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
#if 0 #if 0
@ -823,10 +832,11 @@ void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenG
if (m_exist == false) { if (m_exist == false) {
return; return;
} }
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) { if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
return; return;
} }
if (false == m_elementList[_idElem].m_isLinked) { if (m_elementList[_idElem].m_isLinked == false) {
return; return;
} }
#if 0 #if 0
@ -852,7 +862,7 @@ void gale::resource::Program::unUse() {
return; return;
} }
#if 0 #if 0
if (true == m_hasTexture) { if (m_hasTexture == true) {
gale::openGL::disable(GL_TEXTURE_2D); gale::openGL::disable(GL_TEXTURE_2D);
//checkGlError("glDisable", __LINE__); //checkGlError("glDisable", __LINE__);
m_hasTexture = false; m_hasTexture = false;

View File

@ -49,7 +49,7 @@ namespace gale {
private : private :
bool m_exist; //!< the file existed bool m_exist; //!< the file existed
int64_t m_program; //!< openGL id of the current program int64_t m_program; //!< openGL id of the current program
std::vector<std::shared_ptr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded std::vector<ememory::SharedPtr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded
std::vector<gale::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user std::vector<gale::resource::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_hasTexture; //!< A texture has been set to the current shader
bool m_hasTexture1; //!< A texture has been set to the current shader bool m_hasTexture1; //!< A texture has been set to the current shader
@ -92,7 +92,7 @@ namespace gale {
const void* _pointer, const void* _pointer,
int32_t _jumpBetweenSample=0); int32_t _jumpBetweenSample=0);
void sendAttributePointer(int32_t _idElem, void sendAttributePointer(int32_t _idElem,
const std::shared_ptr<gale::resource::VirtualBufferObject>& _vbo, const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
int32_t _index, int32_t _index,
int32_t _jumpBetweenSample=0, int32_t _jumpBetweenSample=0,
int32_t _offset=0); int32_t _offset=0);

View File

@ -67,20 +67,20 @@ bool gale::Resource::isTypeCompatible(const std::string& _type) {
bool gale::Resource::updateContext() { bool gale::Resource::updateContext() {
GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << shared_from_this().use_count() << " time(s)"); GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << sharedFromThis().useCount() << " time(s)");
return true; return true;
} }
void gale::Resource::removeContext() { void gale::Resource::removeContext() {
GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << shared_from_this().use_count() << " time(s)"); GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << sharedFromThis().useCount() << " time(s)");
} }
void gale::Resource::removeContextToLate() { void gale::Resource::removeContextToLate() {
GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << shared_from_this().use_count() << " time(s)"); GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << sharedFromThis().useCount() << " time(s)");
} }
void gale::Resource::reload() { void gale::Resource::reload() {
GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << shared_from_this().use_count() << " time(s)"); GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << sharedFromThis().useCount() << " time(s)");
} }
gale::resource::Manager& gale::Resource::getManager() { gale::resource::Manager& gale::Resource::getManager() {

View File

@ -6,15 +6,15 @@
#pragma once #pragma once
#include <mutex> #include <mutex>
#include <memory> #include <ememory/memory.h>
#include <etk/types.h> #include <etk/types.h>
#include <gale/debug.h> #include <gale/debug.h>
#define MAX_RESOURCE_LEVEL (5) #define MAX_RESOURCE_LEVEL (5)
#define DECLARE_RESOURCE_FACTORY(className) \ #define DECLARE_RESOURCE_FACTORY(className) \
template<typename ... T> static std::shared_ptr<className> create( T&& ... all ) { \ template<typename ... T> static ememory::SharedPtr<className> create( T&& ... all ) { \
std::shared_ptr<className> resource(new className()); \ ememory::SharedPtr<className> resource(new className()); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("Factory resource error"); \ GALE_ERROR("Factory resource error"); \
return nullptr; \ return nullptr; \
@ -28,14 +28,14 @@
} }
#define DECLARE_RESOURCE_NAMED_FACTORY(className) \ #define DECLARE_RESOURCE_NAMED_FACTORY(className) \
template<typename ... T> static std::shared_ptr<className> create(const std::string& _name, T&& ... all ) { \ template<typename ... T> static ememory::SharedPtr<className> create(const std::string& _name, T&& ... all ) { \
std::shared_ptr<className> resource; \ ememory::SharedPtr<className> resource; \
std::shared_ptr<gale::Resource> resource2; \ ememory::SharedPtr<gale::Resource> resource2; \
if (_name != "" && _name != "---") { \ if (_name != "" && _name != "---") { \
resource2 = getManager().localKeep(_name); \ resource2 = getManager().localKeep(_name); \
} \ } \
if (resource2 != nullptr) { \ if (resource2 != nullptr) { \
resource = std::dynamic_pointer_cast<className>(resource2); \ resource = ememory::dynamicPointerCast<className>(resource2); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_CRITICAL("Request resource file : '" << _name << "' With the wrong type (dynamic cast error)"); \ GALE_CRITICAL("Request resource file : '" << _name << "' With the wrong type (dynamic cast error)"); \
return nullptr; \ return nullptr; \
@ -44,7 +44,7 @@
if (resource != nullptr) { \ if (resource != nullptr) { \
return resource; \ return resource; \
} \ } \
resource = std::shared_ptr<className>(new className()); \ resource = ememory::SharedPtr<className>(new className()); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("allocation error of a resource : " << _name); \ GALE_ERROR("allocation error of a resource : " << _name); \
return nullptr; \ return nullptr; \
@ -58,11 +58,11 @@
} }
#define DECLARE_RESOURCE_SINGLE_FACTORY(className,uniqueName) \ #define DECLARE_RESOURCE_SINGLE_FACTORY(className,uniqueName) \
template<typename ... T> static std::shared_ptr<className> create(T&& ... all ) { \ template<typename ... T> static ememory::SharedPtr<className> create(T&& ... all ) { \
std::shared_ptr<className> resource; \ ememory::SharedPtr<className> resource; \
std::shared_ptr<gale::Resource> resource2 = getManager().localKeep(uniqueName); \ ememory::SharedPtr<gale::Resource> resource2 = getManager().localKeep(uniqueName); \
if (resource2 != nullptr) { \ if (resource2 != nullptr) { \
resource = std::dynamic_pointer_cast<className>(resource2); \ resource = ememory::dynamicPointerCast<className>(resource2); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_CRITICAL("Request resource file : '" << uniqueName << "' With the wrong type (dynamic cast error)"); \ GALE_CRITICAL("Request resource file : '" << uniqueName << "' With the wrong type (dynamic cast error)"); \
return nullptr; \ return nullptr; \
@ -71,7 +71,7 @@
if (resource != nullptr) { \ if (resource != nullptr) { \
return resource; \ return resource; \
} \ } \
resource = std::shared_ptr<className>(new className()); \ resource = ememory::SharedPtr<className>(new className()); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("allocation error of a resource : " << uniqueName); \ GALE_ERROR("allocation error of a resource : " << uniqueName); \
return nullptr; \ return nullptr; \
@ -97,9 +97,9 @@ namespace gale {
* :** ConfigFile: simple widget configuration files * :** ConfigFile: simple widget configuration files
* :** ... * :** ...
*/ */
class Resource : public std::enable_shared_from_this<gale::Resource> { class Resource : public ememory::EnableSharedFromThis<gale::Resource> {
protected: protected:
std::recursive_mutex m_mutex; mutable std::recursive_mutex m_mutex;
protected: protected:
/** /**
* @brief generic protected contructor (use factory to create this class) * @brief generic protected contructor (use factory to create this class)

View File

@ -128,7 +128,7 @@ void gale::resource::Shader::reload() {
// TODO : Check this, this is a leek ==> in the GPU ... really bad ... // TODO : Check this, this is a leek ==> in the GPU ... really bad ...
m_exist = false; m_exist = false;
m_shader = 0; m_shader = 0;
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
} }
} }

View File

@ -106,10 +106,10 @@ void gale::resource::Texture::removeContextToLate() {
void gale::resource::Texture::flush() { void gale::resource::Texture::flush() {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
// request to the manager to be call at the next update ... // request to the manager to be call at the next update ...
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
} }
void gale::resource::Texture::setTexture(const std::shared_ptr<std::vector<char>>& _data, void gale::resource::Texture::setTexture(const ememory::SharedPtr<std::vector<char>>& _data,
const ivec2& _size, const ivec2& _size,
enum gale::resource::Texture::dataType _dataType, enum gale::resource::Texture::dataType _dataType,
enum gale::resource::Texture::color _dataColorSpace) { enum gale::resource::Texture::color _dataColorSpace) {

View File

@ -57,12 +57,12 @@ namespace gale {
private: private:
// Image propoerties: // Image propoerties:
std::shared_ptr<std::vector<char>> m_data; //!< pointer on the image data. ememory::SharedPtr<std::vector<char>> m_data; //!< pointer on the image data.
ivec2 m_size; //!< size of the image data. ivec2 m_size; //!< size of the image data.
enum dataType m_dataType; //!< Type of the image. enum dataType m_dataType; //!< Type of the image.
enum color m_dataColorSpace; //!< Color space of the image. enum color m_dataColorSpace; //!< Color space of the image.
public: public:
void setTexture(const std::shared_ptr<std::vector<char>>& _data, void setTexture(const ememory::SharedPtr<std::vector<char>>& _data,
const ivec2& _size, const ivec2& _size,
enum gale::resource::Texture::dataType _dataType, enum gale::resource::Texture::dataType _dataType,
enum gale::resource::Texture::color _dataColorSpace); enum gale::resource::Texture::color _dataColorSpace);

View File

@ -86,7 +86,7 @@ void gale::resource::VirtualBufferObject::reload() {
void gale::resource::VirtualBufferObject::flush() { void gale::resource::VirtualBufferObject::flush() {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
// request to the manager to be call at the next update ... // request to the manager to be call at the next update ...
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this())); getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
} }
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3& _data) { void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3& _data) {
@ -103,7 +103,7 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3&
m_buffer[_id].push_back(_data.z()); m_buffer[_id].push_back(_data.z());
} }
vec3 gale::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _elementID) { vec3 gale::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _elementID) const {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
if ((size_t)_elementID*3 > m_buffer[_id].size()) { if ((size_t)_elementID*3 > m_buffer[_id].size()) {
return vec3(0,0,0); return vec3(0,0,0);
@ -113,11 +113,11 @@ vec3 gale::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _
m_buffer[_id][3*_elementID+2]); m_buffer[_id][3*_elementID+2]);
} }
int32_t gale::resource::VirtualBufferObject::bufferSize(int32_t _id) { int32_t gale::resource::VirtualBufferObject::bufferSize(int32_t _id) const {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
return m_buffer[_id].size()/m_vboSizeDataOffset[_id]; return m_buffer[_id].size()/m_vboSizeDataOffset[_id];
} }
int32_t gale::resource::VirtualBufferObject::getElementSize(int32_t _id) { int32_t gale::resource::VirtualBufferObject::getElementSize(int32_t _id) const {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
return m_vboSizeDataOffset[_id]; return m_vboSizeDataOffset[_id];
} }
@ -135,7 +135,7 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec2&
m_buffer[_id].push_back(_data.y()); m_buffer[_id].push_back(_data.y());
} }
vec2 gale::resource::VirtualBufferObject::getOnBufferVec2(int32_t _id, int32_t _elementID) { vec2 gale::resource::VirtualBufferObject::getOnBufferVec2(int32_t _id, int32_t _elementID) const {
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::unique_lock<std::recursive_mutex> lock(m_mutex);
if ((size_t)_elementID*2 > m_buffer[_id].size()) { if ((size_t)_elementID*2 > m_buffer[_id].size()) {
return vec2(0,0); return vec2(0,0);

View File

@ -42,7 +42,7 @@ namespace gale {
* @brief get the real openGL ID. * @brief get the real openGL ID.
* @return the Ogl id reference of this VBO. * @return the Ogl id reference of this VBO.
*/ */
int64_t getGL_ID(int32_t _id) { int64_t getGL_ID(int32_t _id) const {
return m_vbo[_id]; return m_vbo[_id];
}; };
/** /**
@ -59,27 +59,27 @@ namespace gale {
* @param[in] _id VBO Element * @param[in] _id VBO Element
* @return Number of Float in the buffer. * @return Number of Float in the buffer.
*/ */
int32_t bufferSize(int32_t _id); int32_t bufferSize(int32_t _id) const;
/** /**
* @brief Get the offset between element. * @brief Get the offset between element.
* @param[in] _id VBO Element * @param[in] _id VBO Element
* @return Number of Float to jump between target. * @return Number of Float to jump between target.
*/ */
int32_t getElementSize(int32_t _id); int32_t getElementSize(int32_t _id) const;
/** /**
* @brief push data on a buffer with a custum type : * @brief push data on a buffer with a custum type :
* @param[in] _id Id of the buffer requested. * @param[in] _id Id of the buffer requested.
* @param[in] _data Direct data that might be set. * @param[in] _data Direct data that might be set.
*/ */
void pushOnBuffer(int32_t _id, const vec3& _data); void pushOnBuffer(int32_t _id, const vec3& _data);
vec3 getOnBufferVec3(int32_t _id, int32_t _elementID); vec3 getOnBufferVec3(int32_t _id, int32_t _elementID) const;
/** /**
* @brief push data on a buffer with a custum type : * @brief push data on a buffer with a custum type :
* @param[in] _id Id of the buffer requested. * @param[in] _id Id of the buffer requested.
* @param[in] _data Direct data that might be set. * @param[in] _data Direct data that might be set.
*/ */
void pushOnBuffer(int32_t _id, const vec2& _data); void pushOnBuffer(int32_t _id, const vec2& _data);
vec2 getOnBufferVec2(int32_t _id, int32_t _elementID); vec2 getOnBufferVec2(int32_t _id, int32_t _elementID) const;
/** /**
* @brief push data on a buffer with a custum type : * @brief push data on a buffer with a custum type :
* @param[in] _id Id of the buffer requested. * @param[in] _id Id of the buffer requested.

View File

@ -17,7 +17,7 @@
class MainApplication : public gale::Application { class MainApplication : public gale::Application {
private: private:
std::shared_ptr<gale::resource::Program> m_GLprogram; ememory::SharedPtr<gale::resource::Program> m_GLprogram;
int32_t m_GLPosition; int32_t m_GLPosition;
int32_t m_GLMatrix; int32_t m_GLMatrix;
int32_t m_GLColor; int32_t m_GLColor;