From b3a36f7378ea0f299cfa36c81de42e00adb7292d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Mon, 26 Jun 2017 20:11:17 +0200 Subject: Isolate irrlicht references and use a singleton (#6041) * Add Device3D class which will contain IrrlichtDevice interface move getSupportedVideoDrivers to Device3D Add Device3D singleton & use it in various places Rename Device3D to Rendering engine & add helper functions to various device pointers More singleton work RenderingEngine owns draw_load_screen move draw functions to RenderingEngine Reduce IrrlichtDevice exposure and guienvironment RenderingEngine: Expose get_timer_time() to remove device from guiEngine Make irrlichtdevice & scene manager less exposed * Code style fixes * Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly * enum paralax => enum parallax --- src/shader.cpp | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/shader.cpp') diff --git a/src/shader.cpp b/src/shader.cpp index 5ff8c910b..6e89d75ad 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include "client/renderingengine.h" #include "EShaderTypes.h" #include "log.h" #include "gamedef.h" @@ -177,7 +178,7 @@ class ShaderCallback : public video::IShaderConstantSetCallBack std::vector m_setters; public: - ShaderCallback(const std::vector &factories) + ShaderCallback(const std::vector &factories) { for (u32 i = 0; i < factories.size(); ++i) m_setters.push_back(factories[i]->create()); @@ -260,7 +261,7 @@ public: class ShaderSource : public IWritableShaderSource { public: - ShaderSource(IrrlichtDevice *device); + ShaderSource(); ~ShaderSource(); /* @@ -309,8 +310,6 @@ private: // The id of the thread that is allowed to use irrlicht directly std::thread::id m_main_thread; - // The irrlicht device - IrrlichtDevice *m_device; // Cache of source shaders // This should be only accessed from the main thread @@ -332,18 +331,17 @@ private: std::vector m_callbacks; }; -IWritableShaderSource* createShaderSource(IrrlichtDevice *device) +IWritableShaderSource *createShaderSource() { - return new ShaderSource(device); + return new ShaderSource(); } /* Generate shader given the shader name. */ ShaderInfo generate_shader(const std::string &name, - u8 material_type, u8 drawtype, - IrrlichtDevice *device, std::vector &callbacks, - const std::vector &setter_factories, + u8 material_type, u8 drawtype, std::vector &callbacks, + const std::vector &setter_factories, SourceShaderCache *sourcecache); /* @@ -354,11 +352,8 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache, std::string &vertex_program, std::string &pixel_program, std::string &geometry_program, bool &is_highlevel); -ShaderSource::ShaderSource(IrrlichtDevice *device): - m_device(device) +ShaderSource::ShaderSource() { - assert(m_device); // Pre-condition - m_main_thread = std::this_thread::get_id(); // Add a dummy ShaderInfo as the first index, named "" @@ -453,7 +448,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name, } ShaderInfo info = generate_shader(name, material_type, drawtype, - m_device, m_callbacks, m_setter_factories, &m_sourcecache); + m_callbacks, m_setter_factories, &m_sourcecache); /* Add shader to caches (add dummy shaders too) @@ -518,7 +513,7 @@ void ShaderSource::rebuildShaders() ShaderInfo *info = &m_shaderinfo_cache[i]; if(info->name != ""){ *info = generate_shader(info->name, info->material_type, - info->drawtype, m_device, m_callbacks, + info->drawtype, m_callbacks, m_setter_factories, &m_sourcecache); } } @@ -526,8 +521,8 @@ void ShaderSource::rebuildShaders() ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtype, - IrrlichtDevice *device, std::vector &callbacks, - const std::vector &setter_factories, + std::vector &callbacks, + const std::vector &setter_factories, SourceShaderCache *sourcecache) { ShaderInfo shaderinfo; @@ -535,7 +530,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp shaderinfo.material_type = material_type; shaderinfo.drawtype = drawtype; shaderinfo.material = video::EMT_SOLID; - switch(material_type){ + switch (material_type) { case TILE_MATERIAL_BASIC: shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; break; @@ -553,15 +548,16 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp break; case TILE_MATERIAL_WAVING_PLANTS: shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; - break; + break; + default: + break; } bool enable_shaders = g_settings->getBool("enable_shaders"); if (!enable_shaders) return shaderinfo; - video::IVideoDriver* driver = device->getVideoDriver(); - sanity_check(driver); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices(); if(!gpu){ -- cgit v1.2.3