[DEV] integrate the new interface of URI and file
This commit is contained in:
parent
9f5104bedc
commit
9fc1003fbb
@ -10,7 +10,7 @@
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <etk/tool.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
#include <ethread/Mutex.hpp>
|
||||
|
||||
@ -26,6 +26,9 @@
|
||||
#include <echrono/Time.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
#include <etk/Allocator.hpp>
|
||||
#include <etk/uri/provider/ProviderFile.hpp>
|
||||
#include <etk/theme/theme.hpp>
|
||||
|
||||
ETK_DECLARE_TYPE(gale::Context);
|
||||
|
||||
/**
|
||||
@ -165,18 +168,19 @@ void gale::Context::setArchiveDir(int _mode, const char* _str, const char* _appl
|
||||
switch(_mode) {
|
||||
case 0:
|
||||
GALE_DEBUG("Directory APK : path=" << _str);
|
||||
etk::setBaseFolderData(_str, _applName);
|
||||
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(_str));
|
||||
break;
|
||||
case 1:
|
||||
GALE_DEBUG("Directory mode=FILE path=" << _str);
|
||||
etk::setBaseFolderDataUser(_str);
|
||||
etk::uri::provider::add("USER_DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(_str));
|
||||
break;
|
||||
case 2:
|
||||
GALE_DEBUG("Directory mode=CACHE path=" << _str);
|
||||
etk::setBaseFolderCache(_str);
|
||||
etk::uri::provider::add("CACHE", ememory::makeShared<etk::uri::provider::ProviderFile>(_str));
|
||||
break;
|
||||
case 3:
|
||||
GALE_DEBUG("Directory mode=EXTERNAL_CACHE path=" << _str);
|
||||
etk::uri::provider::add("EXTERNAL_CACHE", ememory::makeShared<etk::uri::provider::ProviderFile>(_str));
|
||||
break;
|
||||
default:
|
||||
GALE_DEBUG("Directory mode=???? path=" << _str);
|
||||
@ -216,13 +220,10 @@ namespace gale {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
gale::Context::Context(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
m_application(_application),
|
||||
m_simulationActive(false),
|
||||
m_simulationFile("gale.gsim"),
|
||||
m_simulationUri(etk::Path("gale.gsim")),
|
||||
//m_objectManager(*this),
|
||||
m_previousDisplayTime(),
|
||||
// TODO : m_input(*this),
|
||||
@ -253,12 +254,13 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
|
||||
// By default we set 2 themes (1 color and 1 shape ...) :
|
||||
etk::theme::setNameDefault("GUI", "shape/square/");
|
||||
etk::theme::setNameDefault("COLOR", "color/black/");
|
||||
|
||||
// parse the debug level:
|
||||
for(int32_t iii=0; iii<m_commandLine.size(); ++iii) {
|
||||
if (m_commandLine.get(iii) == "--gale-fps") {
|
||||
m_displayFps=true;
|
||||
} else if (etk::start_with(m_commandLine.get(iii), "--gale-simulation-file=") == true) {
|
||||
m_simulationFile.setName(etk::String(m_commandLine.get(iii).begin()+23, m_commandLine.get(iii).end()) );
|
||||
m_simulationUri = etk::Path(etk::String(m_commandLine.get(iii).begin()+23, m_commandLine.get(iii).end()) );
|
||||
} else if (m_commandLine.get(iii) == "--gale-simulation-record") {
|
||||
m_simulationActive = true;
|
||||
} else if (etk::start_with(m_commandLine.get(iii), "--gale-backend=") == true) {
|
||||
@ -330,13 +332,17 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha
|
||||
// request the init of the application in the main context of openGL ...
|
||||
if (m_simulationActive == true) {
|
||||
// in simulation case:
|
||||
if (m_simulationFile.fileOpenWrite() == false) {
|
||||
GALE_CRITICAL("Can not create Simulation file : " << m_simulationFile);
|
||||
m_simulationFile = etk::uri::get(m_simulationUri);
|
||||
if (m_simulationFile == null) {
|
||||
GALE_CRITICAL("Can not create Simulation file : " << m_simulationUri);
|
||||
}
|
||||
if (m_simulationFile->open(etk::io::OpenMode::Write) == false) {
|
||||
GALE_CRITICAL("Can not create Simulation file : " << m_simulationUri);
|
||||
m_simulationActive = false;
|
||||
} else {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":INIT");
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":INIT");
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
}
|
||||
#if defined(__GALE_ANDROID_ORIENTATION_LANDSCAPE__)
|
||||
@ -411,14 +417,14 @@ gale::Context::~Context() {
|
||||
GALE_INFO(" == > Gale system Un-Init (END)");
|
||||
if (m_simulationActive == true) {
|
||||
// in simulation case:
|
||||
m_simulationFile.fileClose();
|
||||
m_simulationFile->close();
|
||||
}
|
||||
}
|
||||
|
||||
void gale::Context::requestUpdateSize() {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":RECALCULATE_SIZE\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":RECALCULATE_SIZE\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([](gale::Context& _context){
|
||||
@ -434,10 +440,10 @@ void gale::Context::OS_Resize(const vec2& _size) {
|
||||
// TODO : Better in the thread ... ==> but generate some init error ...
|
||||
gale::Dimension::setPixelWindowsSize(_size);
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":RESIZE:");
|
||||
m_simulationFile.filePuts(etk::toString(_size));
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":RESIZE:");
|
||||
m_simulationFile->puts(etk::toString(_size));
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([_size](gale::Context& _context){
|
||||
@ -487,16 +493,16 @@ void gale::Context::OS_SetInput(enum gale::key::type _type,
|
||||
int32_t _pointerID,
|
||||
const vec2& _pos) {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":INPUT:");
|
||||
m_simulationFile.filePuts(etk::toString(_type));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(_status));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(_pointerID));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(_pos));
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":INPUT:");
|
||||
m_simulationFile->puts(etk::toString(_type));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(_status));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(_pointerID));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(_pos));
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([_type, _status, _pointerID, _pos](gale::Context& _context){
|
||||
@ -524,16 +530,16 @@ void gale::Context::OS_setKeyboard(const gale::key::Special& _special,
|
||||
}
|
||||
}
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":KEYBOARD:");
|
||||
m_simulationFile.filePuts(etk::toString(_special));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(_type));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(_state));
|
||||
m_simulationFile.filePuts(":");
|
||||
m_simulationFile.filePuts(etk::toString(uint64_t(_char)));
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":KEYBOARD:");
|
||||
m_simulationFile->puts(etk::toString(_special));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(_type));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(_state));
|
||||
m_simulationFile->puts(":");
|
||||
m_simulationFile->puts(etk::toString(uint64_t(_char)));
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([_special, _type, _state, _char](gale::Context& _context){
|
||||
@ -550,8 +556,8 @@ void gale::Context::OS_setKeyboard(const gale::key::Special& _special,
|
||||
|
||||
void gale::Context::OS_Hide() {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":VIEW:false\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":VIEW:false\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([](gale::Context& _context){
|
||||
@ -571,8 +577,8 @@ void gale::Context::OS_Hide() {
|
||||
|
||||
void gale::Context::OS_Show() {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":VIEW:true\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":VIEW:true\n");
|
||||
}
|
||||
m_msgSystem.post([](gale::Context& _context){
|
||||
/*
|
||||
@ -592,10 +598,10 @@ void gale::Context::OS_Show() {
|
||||
|
||||
void gale::Context::OS_ClipBoardArrive(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":CLIPBOARD_ARRIVE:");
|
||||
m_simulationFile.filePuts(etk::toString(_clipboardID));
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":CLIPBOARD_ARRIVE:");
|
||||
m_simulationFile->puts(etk::toString(_clipboardID));
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_msgSystem.post([_clipboardID](gale::Context& _context){
|
||||
@ -617,10 +623,10 @@ void gale::Context::clipBoardSet(enum gale::context::clipBoard::clipboardListe _
|
||||
|
||||
bool gale::Context::OS_Draw(bool _displayEveryTime) {
|
||||
if (m_simulationActive == true) {
|
||||
m_simulationFile.filePuts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile.filePuts(":DRAW:");
|
||||
m_simulationFile.filePuts(etk::toString(_displayEveryTime));
|
||||
m_simulationFile.filePuts("\n");
|
||||
m_simulationFile->puts(etk::toString(echrono::Steady::now()));
|
||||
m_simulationFile->puts(":DRAW:");
|
||||
m_simulationFile->puts(etk::toString(_displayEveryTime));
|
||||
m_simulationFile->puts("\n");
|
||||
}
|
||||
{
|
||||
static int32_t countMemeCheck = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <etk/os/Fifo.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
@ -73,7 +73,8 @@ namespace gale {
|
||||
protected:
|
||||
// simulation area:
|
||||
bool m_simulationActive;
|
||||
etk::FSNode m_simulationFile;
|
||||
etk::Uri m_simulationUri;
|
||||
ememory::SharedPtr<etk::io::Interface> m_simulationFile;
|
||||
private:
|
||||
echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case...
|
||||
etk::Fifo<etk::Function<void(gale::Context& _context)> > m_msgSystem;
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
@ -75,15 +75,17 @@ class SimulationInterface : public gale::Context {
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
m_simulationFile = etk::uri::get(m_simulationUri);
|
||||
// Try to open the file of simulation:
|
||||
if (m_simulationFile.fileOpenRead() == false) {
|
||||
if ( m_simulationFile == null
|
||||
|| m_simulationFile->open(etk::io::OpenMode::Read) == false) {
|
||||
GALE_ERROR("can not open the simulation file");
|
||||
return -1;
|
||||
}
|
||||
etk::String action;
|
||||
// main cycle
|
||||
while(m_run == true) {
|
||||
bool lineIsOk = m_simulationFile.fileGets(action);
|
||||
bool lineIsOk = m_simulationFile->gets(action);
|
||||
if (lineIsOk == false) {
|
||||
// reach end of simulation file;
|
||||
return 0;
|
||||
@ -156,7 +158,7 @@ class SimulationInterface : public gale::Context {
|
||||
GALE_ERROR("unknow event : '" << localAction << "'");
|
||||
}
|
||||
}
|
||||
m_simulationFile.fileClose();
|
||||
m_simulationFile->close();
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
|
@ -18,7 +18,7 @@ extern "C" {
|
||||
#include <errno.h>
|
||||
}
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
|
||||
#ifndef GALE_VERSION
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/resource/Program.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
@ -27,48 +27,47 @@ gale::resource::Program::Program() :
|
||||
m_resourceLevel = 1;
|
||||
}
|
||||
|
||||
void gale::resource::Program::init(const etk::String& _filename) {
|
||||
gale::Resource::init(_filename);
|
||||
void gale::resource::Program::init(const etk::Uri& _uri) {
|
||||
gale::Resource::init(_uri.get());
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
GALE_DEBUG("OGL : load PROGRAM '" << m_name << "'");
|
||||
GALE_DEBUG("OGL : load PROGRAM '" << _uri << "'");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
etk::FSNode file(m_name);
|
||||
if (file.exist() == false) {
|
||||
GALE_DEBUG("File does not Exist : \"" << file << "\" == > automatic load of framment and shader with same names... ");
|
||||
etk::String tmpFilename = m_name;
|
||||
// remove extention ...
|
||||
tmpFilename.erase(tmpFilename.size()-4, 4);
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert");
|
||||
if (etk::uri::exist(_uri) == false) {
|
||||
GALE_DEBUG("File does not Exist : \"" << _uri << "\" == > automatic load of framment and shader with same names... ");
|
||||
etk::Uri tmpUri = _uri;
|
||||
tmpUri.setPath(_uri.getPath().getExtentionRemoved() + ".vert");
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
return;
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename << "vert");
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri << "vert");
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
tmpShader = gale::resource::Shader::create(tmpFilename+"frag");
|
||||
tmpUri.setPath(_uri.getPath().getExtentionRemoved() + ".frag");
|
||||
tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
return;
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename << "frag");
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri << "frag");
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
} else {
|
||||
etk::String fileExtention = file.fileGetExtention();
|
||||
if (fileExtention != "prog") {
|
||||
GALE_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
|
||||
if (_uri.getPath().getExtention() != "prog") {
|
||||
GALE_ERROR("File does not have extention \".prog\" for program but : \"" << _uri.getPath() << "\"");
|
||||
return;
|
||||
}
|
||||
if (file.fileOpenRead() == false) {
|
||||
GALE_ERROR("Can not open the file : \"" << file << "\"");
|
||||
auto fileIO = etk::uri::get(_uri);
|
||||
if ( fileIO == null
|
||||
|| fileIO->open(etk::io::OpenMode::Read) == false) {
|
||||
GALE_ERROR("Can not open the file : \"" << _uri << "\"");
|
||||
return;
|
||||
}
|
||||
#define MAX_LINE_SIZE (2048)
|
||||
char tmpData[MAX_LINE_SIZE];
|
||||
while (file.fileGets(tmpData, MAX_LINE_SIZE) != null) {
|
||||
int32_t len = strlen(tmpData);
|
||||
etk::String tmpData;
|
||||
while (fileIO->gets(tmpData) != false) {
|
||||
int32_t len = tmpData.size();
|
||||
if( tmpData[len-1] == '\n'
|
||||
|| tmpData[len-1] == '\r') {
|
||||
tmpData[len-1] = '\0';
|
||||
@ -82,18 +81,18 @@ void gale::resource::Program::init(const etk::String& _filename) {
|
||||
continue;
|
||||
}
|
||||
// get it with relative position:
|
||||
etk::String tmpFilename = file.getRelativeFolder() + tmpData;
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename);
|
||||
etk::Uri tmpUri = _uri;
|
||||
tmpUri.setPath(_uri.getPath().getParent() / tmpData);
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename);
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri);
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
|
||||
}
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
fileIO->close();
|
||||
}
|
||||
if (gale::openGL::hasContext() == true) {
|
||||
updateContext();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <gale/resource/Shader.hpp>
|
||||
#include <gale/resource/VirtualBufferObject.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace gale {
|
||||
namespace resource {
|
||||
@ -57,10 +58,10 @@ namespace gale {
|
||||
protected:
|
||||
/**
|
||||
* @brief Contructor of an opengl Program.
|
||||
* @param[in] filename Standard file name format. see @ref etk::FSNode
|
||||
* @param[in] _uri Uri of the file
|
||||
*/
|
||||
Program();
|
||||
void init(const etk::String& _filename);
|
||||
void init(const etk::Uri& _uri);
|
||||
public:
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Program);
|
||||
/**
|
||||
|
@ -32,6 +32,11 @@ void gale::Resource::init(const etk::String& _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
void gale::Resource::init(const etk::Uri& _uri) {
|
||||
m_resourceHasBeenInit=true;
|
||||
m_name = _uri.get();
|
||||
}
|
||||
|
||||
const char * const gale::Resource::getType() {
|
||||
if (m_listType.size() == 0) {
|
||||
return "gale::Resource";
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <ethread/MutexRecursive.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
|
||||
#define MAX_RESOURCE_LEVEL (5)
|
||||
@ -32,7 +33,7 @@
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(const etk::String& _name, GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
ememory::SharedPtr<gale::Resource> resource2; \
|
||||
if (_name != "" && _name != "---") { \
|
||||
if (_name.isEmpty() == false && _name != "---") { \
|
||||
resource2 = getManager().localKeep(_name); \
|
||||
} \
|
||||
if (resource2 != null) { \
|
||||
@ -56,6 +57,35 @@
|
||||
return resource; \
|
||||
}
|
||||
|
||||
#define DECLARE_RESOURCE_URI_FACTORY(className) \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(const etk::Uri& _uri, GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
ememory::SharedPtr<gale::Resource> resource2; \
|
||||
etk::String name = _uri.get(); \
|
||||
if (name.isEmpty() == false && name != "---") { \
|
||||
resource2 = getManager().localKeep(name); \
|
||||
} \
|
||||
if (resource2 != null) { \
|
||||
resource = ememory::dynamicPointerCast<className>(resource2); \
|
||||
if (resource == null) { \
|
||||
GALE_CRITICAL("Request resource file : '" << name << "' With the wrong type (dynamic cast error)"); \
|
||||
return null; \
|
||||
} \
|
||||
return resource; \
|
||||
} \
|
||||
resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
|
||||
if (resource == null) { \
|
||||
GALE_ERROR("allocation error of a resource : " << name); \
|
||||
return null; \
|
||||
} \
|
||||
resource->init(_uri, etk::forward<GALE_TYPE>(_all)... ); \
|
||||
if (resource->resourceHasBeenCorectlyInit() == false) { \
|
||||
GALE_CRITICAL("resource Is not correctly init : " << #className ); \
|
||||
} \
|
||||
getManager().localAdd(resource); \
|
||||
return resource; \
|
||||
}
|
||||
|
||||
#define DECLARE_RESOURCE_SINGLE_FACTORY(className,uniqueName) \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
@ -107,10 +137,13 @@ namespace gale {
|
||||
/**
|
||||
* @brief Initialisation of the class and previous classes.
|
||||
* @param[in] _name Name of the resource.
|
||||
* @param[in] _uri Uri of the resource.
|
||||
*/
|
||||
void init();
|
||||
//! @previous
|
||||
void init(const etk::String& _name);
|
||||
//! @previous
|
||||
void init(const etk::Uri& _uri);
|
||||
public:
|
||||
//! geenric destructor
|
||||
virtual ~Resource() {
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/resource/Shader.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
@ -25,18 +25,18 @@ gale::resource::Shader::Shader() :
|
||||
m_resourceLevel = 0;
|
||||
}
|
||||
|
||||
void gale::resource::Shader::init(const etk::String& _filename) {
|
||||
void gale::resource::Shader::init(const etk::Uri& _uri) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
gale::Resource::init(_filename);
|
||||
GALE_DEBUG("OGL : load SHADER '" << _filename << "'");
|
||||
gale::Resource::init(_uri.get());
|
||||
GALE_DEBUG("OGL : load SHADER '" << _uri << "'");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
if (etk::end_with(m_name, ".frag") == true) {
|
||||
if (_uri.getPath().getExtention() == "frag") {
|
||||
m_type = gale::openGL::shader::type::fragment;
|
||||
} else if (etk::end_with(m_name, ".vert") == true) {
|
||||
} else if (_uri.getPath().getExtention() == "vert") {
|
||||
m_type = gale::openGL::shader::type::vertex;
|
||||
} else {
|
||||
GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\"");
|
||||
GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << _uri << "\"");
|
||||
return;
|
||||
}
|
||||
reload();
|
||||
@ -101,27 +101,13 @@ void gale::resource::Shader::removeContextToLate() {
|
||||
|
||||
void gale::resource::Shader::reload() {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.exist()) {
|
||||
GALE_CRITICAL("File does not Exist : '" << file << "' : '" << file.getFileSystemName() << "'");
|
||||
etk::Uri uri = m_name;
|
||||
if (etk::uri::exist(uri)) {
|
||||
GALE_CRITICAL("File does not Exist : '" << uri << "' : path='" << uri.getPath() << "'");
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t fileSize = file.fileSize();
|
||||
if (0 == fileSize) {
|
||||
GALE_CRITICAL("This file is empty : " << file);
|
||||
return;
|
||||
}
|
||||
if (false == file.fileOpenRead()) {
|
||||
GALE_CRITICAL("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
m_fileData = file.fileReadAllString();
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
|
||||
etk::uri::readAll(uri, m_fileData);
|
||||
// now change the OGL context ...
|
||||
|
||||
if (gale::openGL::hasContext() == true) {
|
||||
GALE_DEBUG("OGL : load SHADER '" << m_name << "' ==> call update context (direct)");
|
||||
removeContext();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/resource/Resource.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace gale {
|
||||
namespace resource {
|
||||
@ -28,7 +29,7 @@ namespace gale {
|
||||
*/
|
||||
Shader();
|
||||
public:
|
||||
void init(const etk::String& _filename);
|
||||
void init(const etk::Uri& _uri);
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Shader);
|
||||
/**
|
||||
* @brief Destructor, remove the current Shader
|
||||
|
Loading…
x
Reference in New Issue
Block a user