[DEV] update lock

This commit is contained in:
Edouard DUPIN 2015-09-02 21:11:02 +02:00
parent d9ed0d196c
commit 1b8ec043cc
12 changed files with 157 additions and 78 deletions

View File

@ -21,7 +21,7 @@ gale::resource::Manager::Manager() :
}
gale::resource::Manager::~Manager() {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
bool hasError = false;
if (m_resourceListToUpdate.size()!=0) {
GALE_ERROR("Must not have anymore resources to update !!!");
@ -38,7 +38,7 @@ gale::resource::Manager::~Manager() {
}
void gale::resource::Manager::unInit() {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
display();
m_resourceListToUpdate.clear();
// remove all resources ...
@ -59,7 +59,7 @@ void gale::resource::Manager::unInit() {
void gale::resource::Manager::display() {
GALE_INFO("Resources loaded : ");
// remove all resources ...
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource != nullptr) {
@ -75,7 +75,7 @@ void gale::resource::Manager::display() {
void gale::resource::Manager::reLoadResources() {
GALE_INFO("------------- Resources re-loaded -------------");
// remove all resources ...
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_resourceList.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
GALE_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
@ -97,7 +97,7 @@ void gale::resource::Manager::reLoadResources() {
void gale::resource::Manager::update(const std::shared_ptr<gale::Resource>& _object) {
// chek if not added before
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceListToUpdate) {
if ( it != nullptr
&& it == _object) {
@ -111,44 +111,63 @@ void gale::resource::Manager::update(const std::shared_ptr<gale::Resource>& _obj
// Specific to load or update the data in the openGl context == > system use only
void gale::resource::Manager::updateContext() {
std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Check the number of call this ... GALE_INFO("update open-gl context ... ");
if (m_contextHasBeenRemoved == true) {
// need to update all ...
m_contextHasBeenRemoved = false;
if (m_resourceList.size() != 0) {
std::list<std::weak_ptr<gale::Resource>> resourceList;
{
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// Clean the update list
m_resourceListToUpdate.clear();
resourceList = m_resourceList;
}
if (resourceList.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
GALE_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (auto &it : m_resourceList) {
for (auto &it : resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock();
if( tmpRessource != nullptr
&& jjj == tmpRessource->getResourceLevel()) {
//GALE_DEBUG("Update context named : " << l_resourceList[iii]->getName());
tmpRessource->updateContext();
if (tmpRessource->updateContext() == false) {
// Lock error ==> postponned
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_resourceListToUpdate.push_back(tmpRessource);
}
}
}
}
}
} else {
if (m_resourceListToUpdate.size() != 0) {
std::vector<std::shared_ptr<gale::Resource>> resourceListToUpdate;
{
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
resourceListToUpdate = m_resourceListToUpdate;
// Clean the update list
m_resourceListToUpdate.clear();
}
if (resourceListToUpdate.size() != 0) {
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
GALE_INFO(" updateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
for (auto &it : m_resourceListToUpdate) {
for (auto &it : resourceListToUpdate) {
if ( it != nullptr
&& jjj == it->getResourceLevel()) {
it->updateContext();
if (it->updateContext() == false) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// Lock error ==> postponned
m_resourceListToUpdate.push_back(it);
}
}
}
}
}
}
// Clean the update list
m_resourceListToUpdate.clear();
}
// in this case, it is really too late ...
void gale::resource::Manager::contextHasBeenDestroyed() {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock();
if (tmpRessource != nullptr) {
@ -161,7 +180,7 @@ void gale::resource::Manager::contextHasBeenDestroyed() {
// internal generic keeper ...
std::shared_ptr<gale::Resource> gale::resource::Manager::localKeep(const std::string& _filename) {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::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();
@ -176,7 +195,7 @@ 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) {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
//Add ... find empty slot
for (auto &it : m_resourceList) {
std::shared_ptr<gale::Resource> tmpRessource = it.lock();
@ -191,7 +210,7 @@ void gale::resource::Manager::localAdd(const std::shared_ptr<gale::Resource>& _o
// in case of error ...
void gale::resource::Manager::cleanInternalRemoved() {
std11::unique_lock<std11::mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
//GALE_INFO("remove object in Manager");
updateContext();
for (auto it(m_resourceList.begin()); it!=m_resourceList.end(); ++it) {

View File

@ -22,7 +22,7 @@ namespace gale {
std::list<std::weak_ptr<gale::Resource>> m_resourceList;
std::vector<std::shared_ptr<gale::Resource>> m_resourceListToUpdate;
bool m_contextHasBeenRemoved;
std11::mutex m_mutex;
std11::recursive_mutex m_mutex;
public:
/**
* @brief initialize the internal variable

View File

@ -141,13 +141,19 @@ void gale::resource::Program::checkGlError(const char* _op, int32_t _localLine,
if (isPresent == true) {
GALE_ERROR(" in program name : " << m_name);
GALE_ERROR(" program OpenGL ID =" << m_program);
GALE_ERROR(" List IO :");
GALE_ERROR(" List Uniform:");
int32_t id = 0;
for (auto &it : m_elementList) {
if (id == _idElem) {
GALE_ERROR(" * name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " attribute=" << it.m_isAttribute << " is linked=" << it.m_isLinked);
} else {
GALE_ERROR(" name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " attribute=" << it.m_isAttribute << " is linked=" << it.m_isLinked);
if (it.m_isAttribute == false) {
GALE_ERROR(" " << (id==_idElem?"*":" ") << " name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " is linked=" << it.m_isLinked);
}
id++;
}
GALE_ERROR(" List Attribute:");
id = 0;
for (auto &it : m_elementList) {
if (it.m_isAttribute == true) {
GALE_ERROR(" " << (id==_idElem?"*":" ") << " name :" << it.m_name << " OpenGL ID=" << it.m_elementId << " is linked=" << it.m_isLinked);
}
id++;
}
@ -180,18 +186,22 @@ int32_t gale::resource::Program::getAttribute(std::string _elementName) {
progAttributeElement tmp;
tmp.m_name = _elementName;
tmp.m_isAttribute = true;
if (m_exist == true) {
if (gale::openGL::hasContext() == false) {
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this()));
tmp.m_elementId = -1;
tmp.m_isLinked = false;
} else if (m_exist == true) {
tmp.m_elementId = gale::openGL::program::getAttributeLocation(m_program, tmp.m_name);
tmp.m_isLinked = true;
if (tmp.m_elementId<0) {
GALE_WARNING(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
GALE_WARNING(" {" << m_program << "}[" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
tmp.m_isLinked = false;
} else {
GALE_INFO(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
GALE_INFO(" {" << m_program << "}[" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
}
} else {
// program is not loaded ==> just local reister ...
tmp.m_elementId = gale::openGL::program::getUniformLocation(m_program, tmp.m_name);
tmp.m_elementId = -1;
tmp.m_isLinked = false;
}
m_elementList.push_back(tmp);
@ -209,26 +219,34 @@ int32_t gale::resource::Program::getUniform(std::string _elementName) {
progAttributeElement tmp;
tmp.m_name = _elementName;
tmp.m_isAttribute = false;
if (m_exist == true) {
if (gale::openGL::hasContext() == false) {
getManager().update(std::dynamic_pointer_cast<gale::Resource>(shared_from_this()));
tmp.m_elementId = -1;
tmp.m_isLinked = false;
} else if (m_exist == true) {
tmp.m_elementId = gale::openGL::program::getUniformLocation(m_program, tmp.m_name);
tmp.m_isLinked = true;
if (tmp.m_elementId<0) {
GALE_WARNING(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
GALE_WARNING(" {" << m_program << "}[" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
tmp.m_isLinked = false;
} else {
GALE_INFO(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
GALE_INFO(" {" << m_program << "}[" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
}
} else {
// program is not loaded ==> just local reister ...
tmp.m_elementId = gale::openGL::program::getUniformLocation(m_program, tmp.m_name);
tmp.m_elementId = -1;
tmp.m_isLinked = false;
}
m_elementList.push_back(tmp);
return m_elementList.size()-1;
}
void gale::resource::Program::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
bool gale::resource::Program::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex, std11::defer_lock);
if (lock.try_lock() == false) {
//Lock error ==> try later ...
return false;
}
if (m_exist == true) {
// Do nothing == > too dangerous ...
} else {
@ -236,7 +254,7 @@ void gale::resource::Program::updateContext() {
GALE_INFO("Create the Program ... \"" << m_name << "\"");
m_program = gale::openGL::program::create();
if (m_program < 0) {
return;
return true;
}
// first attach vertex shader, and after fragment shader
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
@ -256,9 +274,8 @@ void gale::resource::Program::updateContext() {
if (gale::openGL::program::compile(m_program) == false) {
GALE_ERROR("Could not compile \"PROGRAM\": \"" << m_name << "\"");
gale::openGL::program::remove(m_program);
return;
return true;
}
m_exist = true;
// now get the old attribute requested priviously ...
size_t iii = 0;
for(auto &it : m_elementList) {
@ -266,24 +283,27 @@ void gale::resource::Program::updateContext() {
it.m_elementId = gale::openGL::program::getAttributeLocation(m_program, it.m_name);
it.m_isLinked = true;
if (it.m_elementId<0) {
GALE_WARNING(" [" << iii << "] openGL::getAttributeLocation(\"" << it.m_name << "\") = " << it.m_elementId);
GALE_WARNING(" {" << m_program << "}[" << iii << "] openGL::getAttributeLocation(\"" << it.m_name << "\") = " << it.m_elementId);
it.m_isLinked = false;
} else {
GALE_DEBUG(" [" << iii << "] openGL::getAttributeLocation(\"" << it.m_name << "\") = " << it.m_elementId);
GALE_DEBUG(" {" << m_program << "}[" << iii << "] openGL::getAttributeLocation(\"" << it.m_name << "\") = " << it.m_elementId);
}
} else {
it.m_elementId = gale::openGL::program::getUniformLocation(m_program, it.m_name);
it.m_isLinked = true;
if (it.m_elementId < 0) {
GALE_WARNING(" [" << iii << "] openGL::getUniformLocation(\"" << it.m_name << "\") = " << it.m_elementId);
GALE_WARNING(" {" << m_program << "}[" << iii << "] openGL::getUniformLocation(\"" << it.m_name << "\") = " << it.m_elementId);
it.m_isLinked = false;
} else {
GALE_DEBUG(" [" << iii << "] openGL::getUniformLocation(\"" << it.m_name << "\") = " << it.m_elementId);
GALE_DEBUG(" {" << m_program << "}[" << iii << "] openGL::getUniformLocation(\"" << it.m_name << "\") = " << it.m_elementId);
}
}
iii++;
}
// It will existed only when all is updated...
m_exist = true;
}
return true;
}
void gale::resource::Program::removeContext() {
@ -350,7 +370,8 @@ void gale::resource::Program::sendAttribute(int32_t _idElem,
int32_t _nbElement,
const void* _pointer,
int32_t _jumpBetweenSample) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if ( _idElem < 0
@ -378,7 +399,8 @@ void gale::resource::Program::sendAttributePointer(int32_t _idElem,
int32_t _index,
int32_t _jumpBetweenSample,
int32_t _offset) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -415,7 +437,8 @@ void gale::resource::Program::sendAttributePointer(int32_t _idElem,
//////////////////////////////////////////////////////////////////////////////////////////////
void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -440,7 +463,8 @@ void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix
//////////////////////////////////////////////////////////////////////////////////////////////
void gale::resource::Program::uniform1f(int32_t _idElem, float _value1) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -454,7 +478,8 @@ void gale::resource::Program::uniform1f(int32_t _idElem, float _value1) {
checkGlError("glUniform1f", __LINE__, _idElem);
}
void gale::resource::Program::uniform2f(int32_t _idElem, float _value1, float _value2) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -468,7 +493,8 @@ void gale::resource::Program::uniform2f(int32_t _idElem, float _value1, float _
checkGlError("glUniform2f", __LINE__, _idElem);
}
void gale::resource::Program::uniform3f(int32_t _idElem, float _value1, float _value2, float _value3) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -482,7 +508,8 @@ void gale::resource::Program::uniform3f(int32_t _idElem, float _value1, float _v
checkGlError("glUniform3f", __LINE__, _idElem);
}
void gale::resource::Program::uniform4f(int32_t _idElem, float _value1, float _value2, float _value3, float _value4) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -499,7 +526,8 @@ void gale::resource::Program::uniform4f(int32_t _idElem, float _value1, float _v
//////////////////////////////////////////////////////////////////////////////////////////////
void gale::resource::Program::uniform1i(int32_t _idElem, int32_t _value1) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -513,7 +541,8 @@ void gale::resource::Program::uniform1i(int32_t _idElem, int32_t _value1) {
checkGlError("glUniform1i", __LINE__, _idElem);
}
void gale::resource::Program::uniform2i(int32_t _idElem, int32_t _value1, int32_t _value2) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -527,7 +556,8 @@ void gale::resource::Program::uniform2i(int32_t _idElem, int32_t _value1, int32_
checkGlError("glUniform2i", __LINE__, _idElem);
}
void gale::resource::Program::uniform3i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -541,7 +571,8 @@ void gale::resource::Program::uniform3i(int32_t _idElem, int32_t _value1, int32_
checkGlError("glUniform3i", __LINE__, _idElem);
}
void gale::resource::Program::uniform4i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3, int32_t _value4) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -559,7 +590,8 @@ void gale::resource::Program::uniform4i(int32_t _idElem, int32_t _value1, int32_
//////////////////////////////////////////////////////////////////////////////////////////////
void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -581,7 +613,8 @@ void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform1fv", __LINE__, _idElem);
}
void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -603,7 +636,8 @@ void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform2fv", __LINE__, _idElem);
}
void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -626,7 +660,8 @@ void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform3fv", __LINE__, _idElem);
}
void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -652,7 +687,8 @@ void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
//////////////////////////////////////////////////////////////////////////////////////////////
void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -674,7 +710,8 @@ void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform1iv", __LINE__, _idElem);
}
void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -696,7 +733,8 @@ void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform2iv", __LINE__, _idElem);
}
void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -718,7 +756,8 @@ void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, co
checkGlError("glUniform3iv", __LINE__, _idElem);
}
void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -759,7 +798,8 @@ void gale::resource::Program::use() {
void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenGlID) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -784,7 +824,8 @@ void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenG
}
void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenGlID) {
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
@ -811,7 +852,8 @@ void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenG
void gale::resource::Program::unUse() {
//GALE_WARNING("Will use program : " << m_program);
if (0 == m_program) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_exist == false) {
return;
}
#if 0

View File

@ -289,7 +289,7 @@ namespace gale {
/**
* @brief This load/reload the data in the opengl context, needed when removed previously.
*/
void updateContext();
bool updateContext();
/**
* @brief remove the data from the opengl context.
*/

View File

@ -68,8 +68,9 @@ bool gale::Resource::isTypeCompatible(const std::string& _type) {
}
void gale::Resource::updateContext() {
bool gale::Resource::updateContext() {
GALE_DEBUG("Not set for : [" << getId() << "]" << getName() << " loaded " << shared_from_this().use_count() << " time(s)");
return true;
}
void gale::Resource::removeContext() {

View File

@ -189,8 +189,10 @@ namespace gale {
/**
* @brief Call when need to send data on the harware (openGL)
* @note This is done asynchronously with the create of the Resource.
* @return true The context is updated
* @return false The context is not updated
*/
virtual void updateContext();
virtual bool updateContext();
/**
* @brief The current OpenGl context is removing ==> remove yout own system data
*/

View File

@ -51,21 +51,25 @@ gale::resource::Shader::~Shader() {
m_exist = false;
}
void gale::resource::Shader::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
bool gale::resource::Shader::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex, std11::defer_lock);
if (lock.try_lock() == false) {
//Lock error ==> try later ...
return false;
}
if (m_exist == true) {
// Do nothing == > too dangerous ...
} else {
// create the Shader
if (m_fileData.size() == 0) {
m_shader = -1;
return;
return true;
}
GALE_INFO("Create Shader : '" << m_name << "'");
m_shader = gale::openGL::shader::create(m_type);
if (m_shader < 0) {
GALE_CRITICAL(" can not load shader");
return;
return true;
} else {
GALE_INFO("Compile shader with GLID=" << m_shader);
bool ret = gale::openGL::shader::compile(m_shader, m_fileData);
@ -75,11 +79,12 @@ void gale::resource::Shader::updateContext() {
tmpShaderType = "VERTEX SHADER";
}
GALE_CRITICAL("Could not compile \"" << tmpShaderType << "\" name='" << m_name << "'");
return;
return true;
}
}
m_exist = true;
}
return true;
}
void gale::resource::Shader::removeContext() {

View File

@ -56,7 +56,7 @@ namespace gale {
/**
* @brief This load/reload the data in the opengl context, needed when removed previously.
*/
void updateContext();
bool updateContext();
/**
* @brief remove the data from the opengl context.
*/

View File

@ -56,8 +56,12 @@ gale::resource::Texture::~Texture() {
removeContext();
}
void gale::resource::Texture::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
bool gale::resource::Texture::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex, std11::defer_lock);
if (lock.try_lock() == false) {
//Lock error ==> try later ...
return false;
}
if (false == m_loaded) {
// Request a new texture at openGl :
glGenTextures(1, &m_texId);
@ -86,6 +90,7 @@ void gale::resource::Texture::updateContext() {
&((*m_data)[0]) );
// now the data is loaded
m_loaded = true;
return true;
}
void gale::resource::Texture::removeContext() {

View File

@ -33,7 +33,7 @@ namespace gale {
bool m_loaded; //!< internal state of the openGl system.
// Gale internal API:
public:
virtual void updateContext();
virtual bool updateContext();
virtual void removeContext();
virtual void removeContextToLate();
// middleware interface:

View File

@ -38,8 +38,12 @@ void gale::resource::VirtualBufferObject::retreiveData() {
GALE_ERROR("TODO ... ");
}
void gale::resource::VirtualBufferObject::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
bool gale::resource::VirtualBufferObject::updateContext() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex, std11::defer_lock);
if (lock.try_lock() == false) {
//Lock error ==> try later ...
return false;
}
if (false == m_exist) {
// Allocate and assign a Vertex Array Object to our handle
gale::openGL::genBuffers(m_vbo);
@ -57,6 +61,7 @@ void gale::resource::VirtualBufferObject::updateContext() {
}
// un-bind it to permet to have no erreor in the next display ...
gale::openGL::unbindBuffer();
return true;
}
void gale::resource::VirtualBufferObject::removeContext() {

View File

@ -107,7 +107,7 @@ namespace gale {
/**
* @brief This load/reload the data in the opengl context, needed when removed previously.
*/
void updateContext();
bool updateContext();
/**
* @brief remove the data from the opengl context.
*/