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

View File

@ -42,7 +42,7 @@ void gale::Thread::start() {
#if defined(__TARGET_OS__Android)
pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this);
#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) {
GALE_ERROR("Can not create thread ...");
return;

View File

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

View File

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

View File

@ -16,7 +16,7 @@
#include <gale/context/commandLine.h>
// TODO : #include <gale/context/InputManager.h>
#include <gale/context/Fps.h>
#include <memory>
#include <ememory/memory.h>
#include <gale/orientation.h>
#include <gale/context/clipBoard.h>
#include <ethread/tools.h>
@ -26,9 +26,9 @@
namespace gale {
class Context/* : private gale::object::RemoveEvent */{
private:
std::shared_ptr<gale::Application> m_application; //!< Application handle
ememory::SharedPtr<gale::Application> m_application; //!< Application handle
public:
std::shared_ptr<gale::Application> getApplication() {
ememory::SharedPtr<gale::Application> getApplication() {
return m_application;
}
private:
@ -184,12 +184,12 @@ namespace gale {
* @param source the widget where the event came from
* @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
* @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
*/

View File

@ -34,7 +34,7 @@ void gale::context::InputManager::setDpi(int32_t newDPI) {
}
bool gale::context::InputManager::localEventInput(enum gale::key::type _type,
std::shared_ptr<gale::Application> _destApplication,
ememory::SharedPtr<gale::Application> _destApplication,
int32_t _IdInput,
enum gale::key::status _status,
vec2 _pos) {
@ -104,13 +104,13 @@ gale::context::InputManager::~InputManager() {
}
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) {
if (_type == gale::key::typeFinger) {
int32_t lastMinimum = 0;
for(int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
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 (iii != _realInputId) {
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
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 :
if (_type == gale::key::typeMouse && _pointerID == 0) {
// 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 :
std::shared_ptr<gale::Application> tmpApplication;
ememory::SharedPtr<gale::Application> tmpApplication;
if (m_grabApplication.lock() != nullptr) {
// grab all events ...
tmpApplication = m_grabApplication.lock();
@ -282,7 +282,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
}
// get the curent time ...
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) {
EVENT_DEBUG("GUI : Input ID=" << _pointerID
@ -319,7 +319,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
eventTable[_pointerID].lastTimeEvent = currentTime;
// set the element inside ...
eventTable[_pointerID].isInside = true;
std::shared_ptr<gale::Application> tmpApplication = m_grabApplication.lock();
ememory::SharedPtr<gale::Application> tmpApplication = m_grabApplication.lock();
// get destination Application :
if(nullptr != tmpWindows) {
if ( tmpApplication != nullptr
@ -362,7 +362,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
// revove the Application ...
eventTable[_pointerID].curentApplicationEvent.reset();
} else {
std::shared_ptr<gale::Application> tmpApplication = eventTable[_pointerID].curentApplicationEvent.lock();
ememory::SharedPtr<gale::Application> tmpApplication = eventTable[_pointerID].curentApplicationEvent.lock();
// generate UP Event
EVENT_DEBUG("GUI : Input ID=" << _pointerID
<< " == >" << eventTable[_pointerID].destinationInputId

View File

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

View File

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

View File

@ -15,8 +15,8 @@ namespace gale {
namespace resource {
class Manager{
private:
std::list<std::weak_ptr<gale::Resource>> m_resourceList;
std::vector<std::shared_ptr<gale::Resource>> m_resourceListToUpdate;
std::list<ememory::WeakPtr<gale::Resource>> m_resourceList;
std::vector<ememory::SharedPtr<gale::Resource>> m_resourceListToUpdate;
bool m_contextHasBeenRemoved;
std::recursive_mutex m_mutex;
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 ...
* @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 ....
*/
@ -57,8 +57,8 @@ namespace gale {
void contextHasBeenDestroyed();
public:
// internal API to extent eResources in extern Soft
std::shared_ptr<gale::Resource> localKeep(const std::string& _filename);
void localAdd(const std::shared_ptr<gale::Resource>& _object);
ememory::SharedPtr<gale::Resource> localKeep(const std::string& _filename);
void localAdd(const ememory::SharedPtr<gale::Resource>& _object);
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 ..."
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... ");
std::string tmpFilename = m_name;
// remove extention ...
tmpFilename.erase(tmpFilename.size()-4, 4);
std::shared_ptr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert");
if (nullptr == tmpShader) {
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert");
if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
return;
} else {
@ -46,7 +46,7 @@ void gale::resource::Program::init(const std::string& _filename) {
m_shaderList.push_back(tmpShader);
}
tmpShader = gale::resource::Shader::create(tmpFilename+"frag");
if (nullptr == tmpShader) {
if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
return;
} 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 << "\"");
return;
}
if (false == file.fileOpenRead()) {
if (file.fileOpenRead() == false) {
GALE_ERROR("Can not open the file : \"" << file << "\"");
return;
}
@ -81,8 +81,8 @@ void gale::resource::Program::init(const std::string& _filename) {
}
// get it with relative position :
std::string tmpFilename = file.getRelativeFolder() + tmpData;
std::shared_ptr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename);
if (nullptr == tmpShader) {
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename);
if (tmpShader == nullptr) {
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
} else {
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) {
updateContext();
} 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_isAttribute = true;
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_isLinked = false;
} else if (m_exist == true) {
@ -215,7 +215,7 @@ int32_t gale::resource::Program::getUniform(std::string _elementName) {
tmp.m_name = _elementName;
tmp.m_isAttribute = 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_isLinked = false;
} else if (m_exist == true) {
@ -253,14 +253,14 @@ bool gale::resource::Program::updateContext() {
}
// first attach vertex shader, and after fragment shader
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) {
gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
}
}
}
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) {
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() {
/* TODO : ...
etk::file file(m_name, etk::FILE_TYPE_DATA);
if (false == file.Exist()) {
if (file.Exist() == false) {
GALE_ERROR("File does not Exist : \"" << file << "\"");
return;
}
int32_t fileSize = file.size();
if (0 == fileSize) {
if (fileSize == 0) {
GALE_ERROR("This file is empty : " << file);
return;
}
if (false == file.fOpenRead()) {
if (file.fOpenRead() == false) {
GALE_ERROR("Can not open the file : " << file);
return;
}
// remove previous data ...
if (nullptr != m_fileData) {
if (m_fileData != nullptr) {
delete[] m_fileData;
m_fileData = 0;
}
// allocate data
m_fileData = new char[fileSize+5];
if (nullptr == m_fileData) {
if (m_fileData == nullptr) {
GALE_ERROR("Error Memory allocation size=" << fileSize);
return;
}
@ -390,7 +390,7 @@ void gale::resource::Program::sendAttribute(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 _jumpBetweenSample,
int32_t _offset) {
@ -589,18 +589,19 @@ void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -612,18 +613,19 @@ void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -635,18 +637,19 @@ void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -659,18 +662,19 @@ void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -686,18 +690,19 @@ void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -709,18 +714,19 @@ void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -732,18 +738,19 @@ void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -755,18 +762,19 @@ void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
if (m_exist == false) {
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) << "]");
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
if (0 == _nbElement) {
if (_nbElement == 0) {
GALE_ERROR("No element to send at open GL ...");
return;
}
if (nullptr == _value) {
if (_value == nullptr) {
GALE_ERROR("nullptr Input pointer to send at open GL ...");
return;
}
@ -797,10 +805,11 @@ void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenG
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
#if 0
@ -823,10 +832,11 @@ void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenG
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) {
return;
}
if (false == m_elementList[_idElem].m_isLinked) {
if (m_elementList[_idElem].m_isLinked == false) {
return;
}
#if 0
@ -852,7 +862,7 @@ void gale::resource::Program::unUse() {
return;
}
#if 0
if (true == m_hasTexture) {
if (m_hasTexture == true) {
gale::openGL::disable(GL_TEXTURE_2D);
//checkGlError("glDisable", __LINE__);
m_hasTexture = false;

View File

@ -49,7 +49,7 @@ namespace gale {
private :
bool m_exist; //!< the file existed
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
bool m_hasTexture; //!< 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,
int32_t _jumpBetweenSample=0);
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 _jumpBetweenSample=0,
int32_t _offset=0);

View File

@ -67,20 +67,20 @@ bool gale::Resource::isTypeCompatible(const std::string& _type) {
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;
}
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() {
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() {
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() {

View File

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

View File

@ -57,12 +57,12 @@ namespace gale {
private:
// 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.
enum dataType m_dataType; //!< Type of the image.
enum color m_dataColorSpace; //!< Color space of the image.
public:
void setTexture(const std::shared_ptr<std::vector<char>>& _data,
void setTexture(const ememory::SharedPtr<std::vector<char>>& _data,
const ivec2& _size,
enum gale::resource::Texture::dataType _dataType,
enum gale::resource::Texture::color _dataColorSpace);

View File

@ -86,7 +86,7 @@ void gale::resource::VirtualBufferObject::reload() {
void gale::resource::VirtualBufferObject::flush() {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
// 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) {
@ -103,7 +103,7 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3&
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);
if ((size_t)_elementID*3 > m_buffer[_id].size()) {
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]);
}
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);
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);
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());
}
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);
if ((size_t)_elementID*2 > m_buffer[_id].size()) {
return vec2(0,0);

View File

@ -42,7 +42,7 @@ namespace gale {
* @brief get the real openGL ID.
* @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];
};
/**
@ -59,27 +59,27 @@ namespace gale {
* @param[in] _id VBO Element
* @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.
* @param[in] _id VBO Element
* @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 :
* @param[in] _id Id of the buffer requested.
* @param[in] _data Direct data that might be set.
*/
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 :
* @param[in] _id Id of the buffer requested.
* @param[in] _data Direct data that might be set.
*/
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 :
* @param[in] _id Id of the buffer requested.

View File

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