bool ShaderProgram::upload_to(RenderContext const & context) const { if ( !program_ || dirty_) { std::list<scm::gl::shader_ptr> shaders; ResourceFactory factory; for (auto const& s : stages_) { auto source = factory.resolve_substitutions(s.source, substitutions_); shaders.push_back(context.render_device->create_shader(s.type, source)); } if (interleaved_stream_capture_.empty()) { program_ = context.render_device->create_program(shaders); } else { scm::gl::interleaved_stream_capture capture_array (interleaved_stream_capture_.front()); for (auto const& k : interleaved_stream_capture_) capture_array(k); program_ = context.render_device->create_program( shaders, capture_array, in_rasterization_discard_); } dirty_ = false; if (!program_) { Logger::LOG_WARNING << "Failed to create shaders!" << std::endl; return false; } } return true; }
void ResourceManager::LoadResource( const std::string & resource ) { if( ResourceIsLoaded( resource ) ) return; ResourceFactory * rf = ResourceFactory::Instance( ); m_Resources[resource] = rf->LoadResource( resource ); }
FullscreenPassDescription& FullscreenPassDescription::source(std::string const& source) { #ifndef GUACAMOLE_RUNTIME_PROGRAM_COMPILATION ResourceFactory factory; fragment_shader_ = factory.prepare_shader(source, "FullscreenPass shader"); #else fragment_shader_ = source; Resources::resolve_includes(fragment_shader_); #endif fragment_shader_is_file_name_ = false; recompile_shaders_ = true; return *this; }
void LowQualitySplattingSubRenderer::_load_shaders() { //create stages only with one thread! if(!shaders_loaded_) { #ifndef GUACAMOLE_RUNTIME_PROGRAM_COMPILATION #error "This works only with GUACAMOLE_RUNTIME_PROGRAM_COMPILATION enabled" #endif ResourceFactory factory; shader_stages_.clear(); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_VERTEX_SHADER, factory.read_shader_file("resources/shaders/plod/one_pass_splatting/one_pass_low_quality.vert"))); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_GEOMETRY_SHADER, factory.read_shader_file("resources/shaders/plod/one_pass_splatting/one_pass_low_quality.geom"))); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_FRAGMENT_SHADER, factory.read_shader_file("resources/shaders/plod/one_pass_splatting/one_pass_low_quality.frag"))); shaders_loaded_ = true; } }
SPointsRenderer::SPointsRenderer() : initialized_(false) { ResourceFactory factory; // create final shader description program_stages_.push_back(ShaderProgramStage( scm::gl::STAGE_VERTEX_SHADER, factory.read_shader_file("resources/shaders/forward_point_rendering.vert"))); program_stages_.push_back(ShaderProgramStage( scm::gl::STAGE_FRAGMENT_SHADER, factory.read_shader_file("resources/shaders/forward_point_rendering.frag"))); }
void LogToLinSubRenderer::_load_shaders() { //create stages only with one thread! if(!shaders_loaded_) { #ifndef GUACAMOLE_RUNTIME_PROGRAM_COMPILATION #error "This works only with GUACAMOLE_RUNTIME_PROGRAM_COMPILATION enabled" #endif ResourceFactory factory; shader_stages_.clear(); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_VERTEX_SHADER, factory.read_shader_file("resources/shaders/plod/p00_log_to_lin_conversion.vert"))); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_FRAGMENT_SHADER, factory.read_shader_file("resources/shaders/plod/p00_log_to_lin_conversion.frag"))); shaders_loaded_ = true; } }
void HoleFillingSubRenderer::_load_shaders() { //create stages only with one thread! if(!shaders_loaded_) { #ifndef GUACAMOLE_RUNTIME_PROGRAM_COMPILATION #error "This works only with GUACAMOLE_RUNTIME_PROGRAM_COMPILATION enabled" #endif ResourceFactory factory; shader_stages_.clear(); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_VERTEX_SHADER, factory.read_shader_file("resources/shaders/plod/linked_list_splatting/p03_fill_holes.vert")) ); shader_stages_.push_back(ShaderProgramStage(scm::gl::STAGE_FRAGMENT_SHADER, factory.read_shader_file("resources/shaders/plod/linked_list_splatting/p03_fill_holes.frag")) ); shaders_loaded_ = true; } }
// ---------------------------------------------------------------------------------------------- // this function must *always* return a valid Resource, even for 'missing' resources. Resource* ResourceManager::LoadAsync(const WCHAR* filename, Resource* def) { AutoSync sync(&m_criticalSection); // CRITICAL SECTION - ENTIRE FUNCTION Resource * res = NULL; // check cache, use if already there. if(NULL == res) { auto it = m_loaded.find(filename); if(it != m_loaded.end() ) res = it->second; } // check pending, use if already there. if(NULL == res) { auto it = m_pending.find(filename); if(it != m_pending.end() ) res = it->second; } // create new info and add it to pending list to be loaded. if(NULL == res) { ResourceFactory * factory = GetFactory(filename); if (!factory) { return NULL; } res = factory->CreateResource(def); m_pending[filename] = res; BOOL success = SetEvent(m_EventHandle); #ifdef NDEBUG UNREFERENCED_VARIABLE(success); #endif assert(success); } assert(res); res->AddRef(); return res; }
// ---------------------------------------------------------------------------------------------- Resource* ResourceManager::LoadImmediate(const WCHAR* filename, Resource* def) { AutoSync sync(&m_criticalSection); // CRITICAL SECTION - ENTIRE FUNCTION Resource * res = NULL; // check cache, use if already there. if(NULL == res) { auto it = m_loaded.find(filename); if(it != m_loaded.end() ) res = it->second; } // check pending, use if already there. if(NULL == res) { auto it = m_pending.find(filename); if(it != m_pending.end() ) res = it->second; } // create new info and add load it immediatelly. if(NULL == res) { ResourceFactory * factory = GetFactory(filename); res = factory->CreateResource(def); bool loaded = LoadResource(res, filename); if(!loaded) { Logger::Log(OutputMessageType::Error, L"failed to load %s\n",filename); SAFE_DELETE(res); return NULL; } else { m_loaded[filename] = res; } } res->AddRef(); return res; }
// loading/unloading // ---------------------------------------------------------------------------------------------- // Loads a file and turns it into a runtime resource bool ResourceManager::LoadResource(Resource * res, const WCHAR* filename) { bool ok = false; // try to create resource if (!FileUtils::Exists(filename)) { Logger::Log(OutputMessageType::Error, L"Failed to load file, '%ls' -- does not exist\n", filename); return false; } PerfTimer timer; timer.Start(); // get factory associated with 'filename' ResourceFactory * factory = GetFactory(filename); if (!factory) { return false; } ok = factory->LoadResource(res, filename); if (ok) { res->SetReady(); timer.Stop(); Logger::Log(OutputMessageType::Debug, L"%d ms Loaded %ls\n", timer.ElapsedMilliseconds(), FileUtils::Name(filename)); } else { timer.Stop(); Logger::Log(OutputMessageType::Error, L"%d ms failed to load %ls\n", timer.ElapsedMilliseconds(), filename); } return ok; }
int main(int argc, char **argv) { // print version info if(argc == 2) { string param(argv[1]); if(param == "--version" || param == "-v") { cout << "Version information:" << endl; cout << "Graphics Application Revision: " << ERP_GIT_VERSION << endl; cout << "BOINC Revision: " << SVN_VERSION << endl; exit(0); } } // enable BOINC diagnostics // TODO: we might want to optimize this for glibc- and mingw-based stacktraces! boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS); #ifdef __APPLE__ setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData)); #endif // choose application to be build/used GraphicsEngineFactory::Applications scienceApplication; #ifdef SCIENCE_APP scienceApplication = GraphicsEngineFactory::SCIENCE_APP; #else scienceApplication = GraphicsEngineFactory::EinsteinS5R3; #endif // prepare main objects WindowManager window; ResourceFactory factory; AbstractGraphicsEngine *graphics = GraphicsEngineFactory::createInstance( GraphicsEngineFactory::Starsphere, scienceApplication); if(!graphics) { cerr << "Requested graphics engine could not be found/instantiated!" << endl; exit(1); } // initialize window manager if(!window.initialize()) { cerr << "Window manager could not be initialized!" << endl; delete graphics; exit(1); } // create font and icon resource instances const Resource *fontResource = factory.createInstance("FontSansSerif"); const Resource *iconResource = factory.createInstance("AppIconBMP"); if(fontResource == NULL) { cerr << "Font resource could not be loaded!" << endl; delete graphics; exit(1); } if(fontResource->data()->size() <= 0) { cerr << "Font resource could not be loaded!" << endl; delete graphics; delete fontResource; exit(1); } if(iconResource != NULL && iconResource->data()->size() > 0) { window.setWindowIcon(&iconResource->data()->at(0), iconResource->data()->size()); delete iconResource; } else { cerr << "Icon resource could not be loaded! Continuing anyway..." << endl; } window.setWindowCaption("Einstein@Home"); // register starsphere as event observer window.registerEventObserver(graphics); // pepare rendering graphics->initialize(window.windowWidth(), window.windowHeight(), fontResource); graphics->refreshBOINCInformation(); // check optional command line parameters if(argc == 2) { string param(argv[1]); if(param == "--fullscreen") { // set non-interactive mode (must do this first on Apple) window.setScreensaverMode(true); } if(param == "--fullscreen" || param == "--demo") { // switch to fullscreen (on windoze: after init!) window.toggleFullscreen(); #ifdef __APPLE__ SetMacSSLevel(); #endif } } // enter main event loop window.eventLoop(); // clean up end exit window.unregisterEventObserver(graphics); delete graphics; delete fontResource; exit(0); }
void init(int argc, char** argv) { static scm::shared_ptr<scm::core> scm_core(new scm::core(argc, argv)); #ifdef GUACAMOLE_GLFW3 if (!glfwInit()) { Logger::LOG_ERROR << "Failed to initialize GLFW!" << std::endl; } else { Logger::LOG_DEBUG << "Succeed to initialize GLFW!" << std::endl; } #endif scm::gl::sampler_state_desc sampler_state(scm::gl::FILTER_MIN_MAG_LINEAR, scm::gl::WRAP_CLAMP_TO_EDGE, scm::gl::WRAP_CLAMP_TO_EDGE); gua::TextureDatabase::instance()->add("gua_loading_texture", std::make_shared<Texture2D>(gua::make_loading_image(), 1, sampler_state)); gua::TextureDatabase::instance()->add("gua_default_texture", std::make_shared<Texture2D>(gua::make_default_image(), 1, sampler_state)); gua::TextureDatabase::instance()->add("gua_noise_texture", std::make_shared<Texture2D>(gua::make_noise_image(), 1, sampler_state)); TriMeshLoader mesh_loader; #ifdef GUACAMOLE_RUNTIME_PROGRAM_COMPILATION ResourceFactory factory; auto light_sphere_obj = factory.read_plain_file("resources/geometry/gua_light_sphere.obj"); auto light_cone_obj = factory.read_plain_file("resources/geometry/gua_light_cone.obj"); GeometryDatabase::instance()->add( "gua_light_sphere_proxy", std::shared_ptr<GeometryResource>( static_cast<GeometryResource*>(mesh_loader.load_from_buffer(light_sphere_obj.c_str(), light_sphere_obj.size(), false)[0]))); GeometryDatabase::instance()->add( "gua_light_cone_proxy", std::shared_ptr<GeometryResource>( static_cast<GeometryResource*>(mesh_loader.load_from_buffer(light_cone_obj.c_str(), light_cone_obj.size(), false)[0]))); #else GeometryDatabase::instance()->add( "gua_light_sphere_proxy", std::shared_ptr<GeometryResource>( static_cast<GeometryResource*>(mesh_loader.load_from_buffer( Resources::lookup_string(Resources::geometry_gua_light_sphere_obj).c_str(), Resources::geometry_gua_light_sphere_obj.size(), false)[0]))); GeometryDatabase::instance()->add( "gua_light_cone_proxy", std::shared_ptr<GeometryResource>( static_cast<GeometryResource*>(mesh_loader.load_from_buffer( Resources::lookup_string(Resources::geometry_gua_light_cone_obj).c_str(), Resources::geometry_gua_light_cone_obj.size(), false)[0]))); #endif PBSMaterialFactory::create_material(PBSMaterialFactory::ALL); Logger::LOG_DEBUG << "Guacamole initialization finished." << std::endl; }