diff --git a/src/app/app.cpp b/src/app/app.cpp index 2a14689b..c69dd786 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -36,6 +36,7 @@ #include "common/system/system.h" +#include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/opengl33/glutil.h" @@ -115,7 +116,8 @@ CApplication::CApplication(CSystemUtils* systemUtils) m_configFile(std::make_unique()), m_input(std::make_unique()), m_pathManager(std::make_unique(systemUtils)), - m_modManager(std::make_unique(this, m_pathManager.get())) + m_modManager(std::make_unique(this, m_pathManager.get())), + m_deviceConfig(std::make_unique()) { m_exitCode = 0; m_active = false; @@ -427,8 +429,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) std::getline(resolution, w, 'x'); std::getline(resolution, h, 'x'); - m_deviceConfig.size.x = atoi(w.c_str()); - m_deviceConfig.size.y = atoi(h.c_str()); + m_deviceConfig->size.x = atoi(w.c_str()); + m_deviceConfig->size.y = atoi(h.c_str()); m_resolutionOverride = true; break; } @@ -615,7 +617,7 @@ bool CApplication::Create() { if (it->x == w && it->y == h) { - m_deviceConfig.size = *it; + m_deviceConfig->size = *it; break; } } @@ -623,7 +625,7 @@ bool CApplication::Create() if ( GetConfigFile().GetIntProperty("Setup", "Fullscreen", iValue) && !m_resolutionOverride ) { - m_deviceConfig.fullScreen = (iValue == 1); + m_deviceConfig->fullScreen = (iValue == 1); } if (! CreateVideoSurface()) @@ -673,14 +675,14 @@ bool CApplication::Create() graphics = value; } - m_device = Gfx::CreateDevice(m_deviceConfig, graphics.c_str()); + m_device = Gfx::CreateDevice(*m_deviceConfig, graphics.c_str()); if (m_device == nullptr) { GetLogger()->Error("Unknown graphics device: %s\n", graphics.c_str()); GetLogger()->Info("Changing to default device\n"); m_systemUtils->SystemDialog(SystemDialogType::ERROR_MSG, "Graphics initialization error", "You have selected invalid graphics device with -graphics switch. Game will use default OpenGL device instead."); - m_device = Gfx::CreateDevice(m_deviceConfig, "opengl"); + m_device = Gfx::CreateDevice(*m_deviceConfig, "opengl"); } } //else @@ -747,23 +749,23 @@ bool CApplication::CreateVideoSurface() { Uint32 videoFlags = SDL_WINDOW_OPENGL; - if (m_deviceConfig.fullScreen) + if (m_deviceConfig->fullScreen) videoFlags |= SDL_WINDOW_FULLSCREEN; - if (m_deviceConfig.resizeable) + if (m_deviceConfig->resizeable) videoFlags |= SDL_WINDOW_RESIZABLE; // Set OpenGL attributes - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, m_deviceConfig.redSize); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, m_deviceConfig.greenSize); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, m_deviceConfig.blueSize); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, m_deviceConfig.alphaSize); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, m_deviceConfig->redSize); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, m_deviceConfig->greenSize); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, m_deviceConfig->blueSize); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, m_deviceConfig->alphaSize); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_deviceConfig.depthSize); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_deviceConfig.stencilSize); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_deviceConfig->depthSize); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_deviceConfig->stencilSize); - if (m_deviceConfig.doubleBuf) + if (m_deviceConfig->doubleBuf) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); std::string value; @@ -848,12 +850,12 @@ bool CApplication::CreateVideoSurface() /* If hardware acceleration specifically requested, this will force the hw accel and fail with error if not available */ - if (m_deviceConfig.hardwareAccel) + if (m_deviceConfig->hardwareAccel) SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); m_private->window = SDL_CreateWindow(m_windowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - m_deviceConfig.size.x, m_deviceConfig.size.y, + m_deviceConfig->size.x, m_deviceConfig->size.y, videoFlags); m_private->glcontext = SDL_GL_CreateContext(m_private->window); @@ -900,15 +902,15 @@ void CApplication::TryToSetVSync() bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) { - m_deviceConfig = newConfig; + *m_deviceConfig = newConfig; // TODO: Somehow this doesn't work for maximized windows (at least on Ubuntu) - SDL_SetWindowSize(m_private->window, m_deviceConfig.size.x, m_deviceConfig.size.y); - SDL_SetWindowFullscreen(m_private->window, m_deviceConfig.fullScreen ? SDL_WINDOW_FULLSCREEN : 0); + SDL_SetWindowSize(m_private->window, m_deviceConfig->size.x, m_deviceConfig->size.y); + SDL_SetWindowFullscreen(m_private->window, m_deviceConfig->fullScreen ? SDL_WINDOW_FULLSCREEN : 0); TryToSetVSync(); - m_device->ConfigChanged(m_deviceConfig); + m_device->ConfigChanged(*m_deviceConfig); m_eventQueue->AddEvent(Event(EVENT_RESOLUTION_CHANGED)); @@ -1238,10 +1240,10 @@ Event CApplication::ProcessSystemEvent() { if (m_private->currentEvent.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - Gfx::DeviceConfig newConfig = m_deviceConfig; + Gfx::DeviceConfig newConfig = *m_deviceConfig; newConfig.size.x = m_private->currentEvent.window.data1; newConfig.size.y = m_private->currentEvent.window.data2; - if (newConfig.size != m_deviceConfig.size) + if (newConfig.size != m_deviceConfig->size) ChangeVideoConfig(newConfig); } @@ -1496,7 +1498,7 @@ void CApplication::Render() CProfiler::StopPerformanceCounter(PCNT_RENDER_ALL); CProfiler::StartPerformanceCounter(PCNT_SWAP_BUFFERS); - if (m_deviceConfig.doubleBuf) + if (m_deviceConfig->doubleBuf) SDL_GL_SwapWindow(m_private->window); CProfiler::StopPerformanceCounter(PCNT_SWAP_BUFFERS); } @@ -1648,9 +1650,9 @@ long long CApplication::GetRealRelTime() const return m_realRelTime; } -Gfx::DeviceConfig CApplication::GetVideoConfig() const +const Gfx::DeviceConfig& CApplication::GetVideoConfig() const { - return m_deviceConfig; + return *m_deviceConfig; } std::vector CApplication::GetVideoResolutionList(int display) const diff --git a/src/app/app.h b/src/app/app.h index 7c712a22..79bf174f 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -29,8 +29,6 @@ #include "common/singleton.h" #include "common/system/system.h" -#include "graphics/core/device.h" - #include "level/level_category.h" #include @@ -51,6 +49,7 @@ class CSystemUtils; namespace Gfx { +class CDevice; class CEngine; struct DeviceConfig; } @@ -188,7 +187,7 @@ public: std::vector GetVideoResolutionList(int display = 0) const; //! Returns the current video mode - Gfx::DeviceConfig GetVideoConfig() const; + const Gfx::DeviceConfig& GetVideoConfig() const; //! Change the video mode to given mode bool ChangeVideoConfig(const Gfx::DeviceConfig &newConfig); @@ -348,7 +347,7 @@ protected: std::string m_errorMessage; //! Current configuration of OpenGL display device - Gfx::DeviceConfig m_deviceConfig; + std::unique_ptr m_deviceConfig; //! Text set as window title std::string m_windowTitle; diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 20ba8d4a..11a6be17 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -25,6 +25,7 @@ #include "common/config_file.h" #include "common/logger.h" +#include "graphics/core/device.h" #include "graphics/engine/camera.h" #include "graphics/engine/engine.h" diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index c547d249..270fc3fe 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -58,6 +58,7 @@ struct VertexCol; struct Vertex3D; enum class CullFace : unsigned char; +enum class PrimitiveType : unsigned char; enum class TransparencyMode : unsigned char; /** @@ -142,21 +143,6 @@ enum class FillMode : unsigned char POLY }; -/** - * \enum PrimitiveType - * \brief Type of primitive to render - */ -enum class PrimitiveType : unsigned char -{ - POINTS, - LINES, - LINE_STRIP, - LINE_LOOP, - TRIANGLES, - TRIANGLE_STRIP, - TRIANGLE_FAN -}; - /** * \enum FrustumPlane * \brief Planes of frustum space diff --git a/src/graphics/core/renderers.h b/src/graphics/core/renderers.h index 91f55600..5e5ffffa 100644 --- a/src/graphics/core/renderers.h +++ b/src/graphics/core/renderers.h @@ -34,10 +34,24 @@ namespace Gfx class CVertexBuffer; enum class CullFace : unsigned char; -enum class PrimitiveType : unsigned char; enum class TransparencyMode : unsigned char; struct Texture; +/** + * \enum PrimitiveType + * \brief Type of primitive to render + */ +enum class PrimitiveType : unsigned char +{ + POINTS, + LINES, + LINE_STRIP, + LINE_LOOP, + TRIANGLES, + TRIANGLE_STRIP, + TRIANGLE_FAN, +}; + struct ShadowParam { glm::mat4 matrix; diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h index 0a074a94..71f067b1 100644 --- a/src/graphics/core/texture.h +++ b/src/graphics/core/texture.h @@ -39,18 +39,18 @@ namespace Gfx * \enum TexImgFormat * \brief Format of image data */ -enum TexImgFormat +enum class TexImgFormat : unsigned char { //! Try to determine automatically (may not work) - TEX_IMG_AUTO, + AUTO, //! RGB triplet, 3 bytes - TEX_IMG_RGB, + RGB, //! BGR triplet, 3 bytes - TEX_IMG_BGR, + BGR, //! RGBA triplet, 4 bytes - TEX_IMG_RGBA, + RGBA, //! BGRA triplet, 4 bytes - TEX_IMG_BGRA + BGRA, }; /** @@ -157,7 +157,7 @@ struct TextureCreateParams //! Whether to generate mipmaps bool mipmap = false; //! Format of source image data - TexImgFormat format = TEX_IMG_RGB; + TexImgFormat format = TexImgFormat::RGB; //! General texture filtering mode TexFilter filter = TEX_FILTER_NEAREST; //! Pad the image to nearest power of 2 dimensions diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 6d08f644..6c8140fe 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -20,7 +20,6 @@ #include "graphics/engine/cloud.h" -#include "graphics/core/device.h" #include "graphics/core/material.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -111,8 +110,7 @@ void CCloud::Draw() float fogStart = deep*0.15f; float fogEnd = deep*0.24f; - CDevice* device = m_engine->GetDevice(); - auto renderer = device->GetObjectRenderer(); + auto renderer = m_engine->GetObjectRenderer(); renderer->Begin(); auto fogColor = m_engine->GetFogColor(m_engine->GetRankView()); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index effac2eb..bc637242 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -276,10 +276,10 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_shadowColor = 0.5f; - m_defaultTexParams.format = TEX_IMG_AUTO; + m_defaultTexParams.format = TexImgFormat::AUTO; m_defaultTexParams.filter = TEX_FILTER_BILINEAR; - m_terrainTexParams.format = TEX_IMG_AUTO; + m_terrainTexParams.format = TexImgFormat::AUTO; m_terrainTexParams.filter = TEX_FILTER_BILINEAR; // Compute bias matrix for shadow mapping @@ -307,6 +307,16 @@ CDevice* CEngine::GetDevice() return m_device; } +CUIRenderer* CEngine::GetUIRenderer() +{ + return m_device->GetUIRenderer(); +} + +CObjectRenderer* CEngine::GetObjectRenderer() +{ + return m_device->GetObjectRenderer(); +} + COldModelManager* CEngine::GetModelManager() { return m_modelManager.get(); @@ -408,7 +418,7 @@ bool CEngine::Create() Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); TextureCreateParams params; - params.format = TEX_IMG_AUTO; + params.format = TexImgFormat::AUTO; params.filter = TEX_FILTER_NEAREST; params.mipmap = false; m_miceTexture = LoadTexture("textures/interface/mouse.png", params); @@ -3168,7 +3178,7 @@ void CEngine::Capture3DScene() TextureCreateParams params; params.filter = TEX_FILTER_BILINEAR; - params.format = TEX_IMG_RGBA; + params.format = TexImgFormat::RGBA; params.mipmap = false; m_capturedWorldTexture = m_device->CreateTexture(&image, params); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 767c6c68..45e60049 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -56,6 +56,8 @@ namespace Gfx { class CDevice; +class CUIRenderer; +class CObjectRenderer; class COldModelManager; class CLightManager; class CText; @@ -436,6 +438,10 @@ public: void SetDevice(CDevice* device); //! Returns the current device CDevice* GetDevice(); + //! Returns the UI renderer + CUIRenderer* GetUIRenderer(); + //! Returns the object renderer + CObjectRenderer* GetObjectRenderer(); //! Returns the text rendering engine CText* GetText(); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 397999d2..021a6609 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -29,6 +29,7 @@ #include "common/resources/resourcemanager.h" +#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -178,7 +179,7 @@ public: { if (m_quads.empty()) return; - auto renderer = m_engine.GetDevice()->GetUIRenderer(); + auto renderer = m_engine.GetUIRenderer(); renderer->SetTexture(Texture{ m_texID }); renderer->SetTransparency(m_transparency); @@ -1363,7 +1364,7 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) Texture tex; tex.id = texture.id; - m_device->UpdateTexture(tex, texture.charPos, &imageData, TEX_IMG_RGBA); + m_device->UpdateTexture(tex, texture.charPos, &imageData, TexImgFormat::RGBA); imageData.surface = nullptr; @@ -1401,7 +1402,7 @@ FontTexture CText::CreateFontTexture(const glm::ivec2& tileSize) data.surface = textureSurface; TextureCreateParams createParams; - createParams.format = TEX_IMG_RGBA; + createParams.format = TexImgFormat::RGBA; createParams.filter = TEX_FILTER_NEAREST; createParams.mipmap = false; diff --git a/src/graphics/opengl33/glutil.cpp b/src/graphics/opengl33/glutil.cpp index 5bca1541..0a7b33ea 100644 --- a/src/graphics/opengl33/glutil.cpp +++ b/src/graphics/opengl33/glutil.cpp @@ -19,6 +19,8 @@ #include "graphics/opengl33/glutil.h" +#include "graphics/core/renderers.h" + #include "graphics/opengl33/gl33_device.h" #include "common/image.h" @@ -489,7 +491,24 @@ GLint LinkProgram(const std::vector& shaders) return program; } -std::unique_ptr GetGLFrameBufferPixels(const glm::ivec2& size) + +class CGLFrameBufferPixels : public CFrameBufferPixels +{ +public: + CGLFrameBufferPixels(std::size_t size) + : m_pixels(std::make_unique(size)) + {} + + void* GetPixelsData() override + { + return static_cast(m_pixels.get()); + } + +private: + std::unique_ptr m_pixels; +}; + +std::unique_ptr GetGLFrameBufferPixels(const glm::ivec2& size) { auto pixels = std::make_unique(4 * size.x * size.y); @@ -511,27 +530,27 @@ PreparedTextureData PrepareTextureData(ImageData* imageData, TexImgFormat format texData.sourceFormat = 0; - if (format == TEX_IMG_RGB) + if (format == TexImgFormat::RGB) { texData.sourceFormat = GL_RGB; texData.alpha = false; } - else if (format == TEX_IMG_BGR) + else if (format == TexImgFormat::BGR) { texData.sourceFormat = GL_BGR; texData.alpha = false; } - else if (format == TEX_IMG_RGBA) + else if (format == TexImgFormat::RGBA) { texData.sourceFormat = GL_RGBA; texData.alpha = true; } - else if (format == TEX_IMG_BGRA) + else if (format == TexImgFormat::BGRA) { texData.sourceFormat = GL_BGRA; texData.alpha = true; } - else if (format == TEX_IMG_AUTO) + else if (format == TexImgFormat::AUTO) { if (imageData->surface->format->BytesPerPixel == 4) { diff --git a/src/graphics/opengl33/glutil.h b/src/graphics/opengl33/glutil.h index 920f355f..67930867 100644 --- a/src/graphics/opengl33/glutil.h +++ b/src/graphics/opengl33/glutil.h @@ -22,8 +22,6 @@ // config.h must be included first #include "common/config.h" -#include "graphics/core/device.h" - #include #include @@ -33,11 +31,20 @@ struct SDL_Surface; +class CImage; +struct ImageData; // Graphics module namespace namespace Gfx { +class CDevice; +class CFrameBufferPixels; +struct DeviceConfig; +enum class PrimitiveType : unsigned char; +enum class Type : unsigned char; +enum class TexImgFormat : unsigned char; + bool InitializeGLEW(); //! Creates OpenGL device @@ -94,22 +101,6 @@ struct PreparedTextureData PreparedTextureData PrepareTextureData(ImageData* imageData, TexImgFormat format); -class CGLFrameBufferPixels : public CFrameBufferPixels -{ -public: - CGLFrameBufferPixels(std::size_t size) - : m_pixels(std::make_unique(size)) - {} - - void* GetPixelsData() override - { - return static_cast(m_pixels.get()); - } - -private: - std::unique_ptr m_pixels; -}; - -std::unique_ptr GetGLFrameBufferPixels(const glm::ivec2& size); +std::unique_ptr GetGLFrameBufferPixels(const glm::ivec2& size); } // namespace Gfx diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 0f188d51..430fc14d 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -23,10 +23,9 @@ #include "common/event.h" #include "common/restext.h" -#include "graphics/engine/engine.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" +#include "graphics/engine/engine.h" namespace Ui @@ -144,8 +143,6 @@ void CButton::Draw() glm::vec2 pos, dim, uv1, uv2; float dp; - auto device = m_engine->GetDevice(); - if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( m_state & STATE_WARNING ) // shading yellow-black? @@ -172,7 +169,7 @@ void CButton::Draw() (m_state & STATE_CARD ) == 0 && (m_state & STATE_SIMPLY) == 0 ) { - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button2.png"); diff --git a/src/ui/controls/check.cpp b/src/ui/controls/check.cpp index b4ffbc73..0161a433 100644 --- a/src/ui/controls/check.cpp +++ b/src/ui/controls/check.cpp @@ -23,7 +23,6 @@ #include "common/event.h" #include "common/restext.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -96,8 +95,7 @@ void CCheck::Draw() float zoomExt, zoomInt; int icon; - auto device = m_engine->GetDevice(); - auto renderer = device->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( (m_state & STATE_VISIBLE) == 0 ) return; diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index c70d8bf5..2e3f3fe9 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -23,7 +23,6 @@ #include "common/event.h" #include "common/restext.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -136,7 +135,7 @@ void CColor::Draw() DrawShadow(m_pos, m_dim); } - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button1.png"); renderer->SetTexture(texture); diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index 469bae51..1e497fca 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -456,7 +456,7 @@ void CControl::Draw() auto texture = m_engine->LoadTexture("textures/interface/button1.png"); - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); renderer->SetTransparency(Gfx::TransparencyMode::NONE); renderer->SetTexture(texture); @@ -613,7 +613,7 @@ void CControl::DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::v { glm::vec2 p1, p2, p3, p4; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); p1.x = pos.x; p1.y = pos.y; @@ -684,7 +684,7 @@ void CControl::DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::v glm::vec2 corner = cor; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); p1.x = pos.x; p1.y = pos.y; @@ -756,7 +756,7 @@ void CControl::DrawWarning(const glm::vec2& position, const glm::vec2& dimension glm::vec2 uv1, uv2; float dp; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); glm::vec2 pos = position; glm::vec2 dim = dimension; @@ -807,7 +807,7 @@ void CControl::DrawShadow(const glm::vec2& position, const glm::vec2& dimension, glm::vec2 uv1, uv2, corner; float dp; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); glm::vec2 pos = position; glm::vec2 dim = dimension; @@ -869,7 +869,7 @@ int CControl::SetButtonTextureForIcon(int icon) int buttonFile = (icon/64) + 1; auto texture = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString(buttonFile) + ".png"); - m_engine->GetDevice()->GetUIRenderer()->SetTexture(texture); + m_engine->GetUIRenderer()->SetTexture(texture); return iconIdx; } diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 35a7fcf9..aa8fa088 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -1182,16 +1182,16 @@ void CEdit::DrawImage(const glm::vec2& pos, std::string name, float width, glm::vec2 uv1, uv2, dim; float dp; - m_engine->GetDevice()->GetUIRenderer()->SetTransparency(Gfx::TransparencyMode::NONE); + m_engine->GetUIRenderer()->SetTransparency(Gfx::TransparencyMode::NONE); //m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); Gfx::TextureCreateParams params; - params.format = Gfx::TEX_IMG_AUTO; + params.format = Gfx::TexImgFormat::AUTO; params.filter = Gfx::TEX_FILTER_BILINEAR; params.padToNearestPowerOfTwo = true; Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params); - m_engine->GetDevice()->GetUIRenderer()->SetTexture(tex); + m_engine->GetUIRenderer()->SetTexture(tex); uv1.x = 0.0f; uv2.x = 1.0f; @@ -1225,7 +1225,7 @@ void CEdit::DrawBack(const glm::vec2& pos, const glm::vec2& dim) auto texture = m_engine->LoadTexture("textures/interface/button2.png"); - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); renderer->SetTexture(texture); renderer->SetTransparency(Gfx::TransparencyMode::NONE); @@ -1271,7 +1271,7 @@ void CEdit::DrawBack(const glm::vec2& pos, const glm::vec2& dim) void CEdit::DrawHorizontalGradient(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color1, Gfx::Color color2) { - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); renderer->SetTransparency(Gfx::TransparencyMode::NONE); glm::vec2 p1, p2; diff --git a/src/ui/controls/gauge.cpp b/src/ui/controls/gauge.cpp index 7d51bfe4..94c4cb36 100644 --- a/src/ui/controls/gauge.cpp +++ b/src/ui/controls/gauge.cpp @@ -22,7 +22,6 @@ #include "graphics/engine/engine.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -84,7 +83,7 @@ void CGauge::Draw() auto texture = m_engine->LoadTexture("textures/interface/button2.png"); - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); renderer->SetTexture(texture); renderer->SetTransparency(Gfx::TransparencyMode::NONE); diff --git a/src/ui/controls/group.cpp b/src/ui/controls/group.cpp index 7e5cf0cf..e175055d 100644 --- a/src/ui/controls/group.cpp +++ b/src/ui/controls/group.cpp @@ -23,7 +23,6 @@ #include "common/event.h" #include "common/restext.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -85,8 +84,6 @@ void CGroup::Draw() float dp; int icon; - auto device = m_engine->GetDevice(); - if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( m_state & STATE_SHADOW ) @@ -96,7 +93,7 @@ void CGroup::Draw() dp = 0.5f / 256.0f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( m_icon == 0 ) // hollow frame? { diff --git a/src/ui/controls/image.cpp b/src/ui/controls/image.cpp index 7f768815..eafde3c5 100644 --- a/src/ui/controls/image.cpp +++ b/src/ui/controls/image.cpp @@ -23,7 +23,6 @@ #include "common/event.h" #include "common/restext.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -95,7 +94,7 @@ void CImage::Draw() glm::vec2 uv1,uv2, corner, pos, dim; float dp; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( (m_state & STATE_VISIBLE) == 0 ) return; @@ -127,7 +126,7 @@ void CImage::Draw() if ( m_filename[0] != 0 ) // displays an image? { Gfx::TextureCreateParams params; - params.format = Gfx::TEX_IMG_AUTO; + params.format = Gfx::TexImgFormat::AUTO; params.filter = Gfx::TEX_FILTER_BILINEAR; params.padToNearestPowerOfTwo = true; Gfx::Texture tex = m_engine->LoadTexture(m_filename, params); diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index 3dd87ea8..8a1823d4 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -23,7 +23,6 @@ #include "common/global.h" #include "common/stringutils.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -138,7 +137,7 @@ void CKey::Draw() if (m_state & STATE_SHADOW) DrawShadow(m_pos, m_dim); - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button1.png"); renderer->SetTexture(texture); diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 82acd19f..f44d03ea 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -20,7 +20,6 @@ #include "ui/controls/list.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" #include "graphics/engine/engine.h" @@ -367,7 +366,7 @@ void CList::Draw() dp = 0.5f / 256.0f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if (m_icon != -1) { diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 11fbce07..c8a45cba 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -22,7 +22,6 @@ #include "common/image.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -337,7 +336,7 @@ void CMap::Draw() glm::vec2 uv1, uv2; int i; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( (m_state & STATE_VISIBLE) == 0 ) return; @@ -508,7 +507,7 @@ void CMap::DrawFocus(const glm::vec2& position, float dir, ObjectType type, MapC uv2.x = 126.0f/256.0f; uv2.y = 255.0f/256.0f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button2.png"); renderer->SetTransparency(Gfx::TransparencyMode::WHITE); @@ -563,7 +562,7 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map dim.x = 2.0f/128.0f*0.75f; dim.y = 2.0f/128.0f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( bOut ) // outside the map? { @@ -835,7 +834,7 @@ void CMap::DrawObjectIcon(const glm::vec2& pos, const glm::vec2& dim, MapColor c dp = 0.5f/256.0f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button3.png"); renderer->SetTransparency(Gfx::TransparencyMode::NONE); @@ -984,7 +983,7 @@ void CMap::DrawHighlight(const glm::vec2& position) dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f; dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button2.png"); renderer->SetTransparency(Gfx::TransparencyMode::BLACK); @@ -1003,7 +1002,7 @@ void CMap::DrawHighlight(const glm::vec2& position) void CMap::DrawTriangle(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& uv1, const glm::vec2& uv2) { - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto vertices = renderer->BeginPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 3); @@ -1019,7 +1018,7 @@ void CMap::DrawTriangle(const glm::vec2& p1, const glm::vec2& p2, const glm::vec void CMap::DrawPenta(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& p4, const glm::vec2& p5, const glm::vec2& uv1, const glm::vec2& uv2) { - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto vertices = renderer->BeginPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 5); vertices[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } }; @@ -1056,7 +1055,7 @@ void CMap::DrawVertex(const glm::vec2& uv1, const glm::vec2& uv2, float zoom) m_mapDim.x = p2.x-p1.x; m_mapDim.y = p2.y-p1.y; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto vertices = renderer->BeginPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4); vertices[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; @@ -1125,7 +1124,7 @@ void CMap::UpdateTerrain() } } - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); m_engine->DeleteTexture("interface/map.png"); m_engine->LoadTexture("textures/interface/map.png", &img); diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 1cd6f141..f22ee7dd 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -22,7 +22,6 @@ #include "common/event.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -309,8 +308,6 @@ void CScroll::Draw() float hButton; int icon, n, i; - auto device = m_engine->GetDevice(); - hButton = m_buttonUp?m_dim.x/0.75f:0.0f; // Draws the bottom. @@ -365,8 +362,7 @@ void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon) glm::vec2 uv1, uv2; float ex, dp; - auto device = m_engine->GetDevice(); - auto renderer = device->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( icon == 0 ) { diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 2c1c2006..8583a2a4 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -22,7 +22,6 @@ #include "common/event.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -119,7 +118,7 @@ void CShortcut::Draw() zoom = 1.0f; } - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto texture = m_engine->LoadTexture("textures/interface/button3.png"); renderer->SetTexture(texture); @@ -260,7 +259,7 @@ void CShortcut::DrawVertex(int icon, float zoom) u2 -= dp; v2 -= dp; - auto renderer = m_engine->GetDevice()->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); auto vertices = renderer->BeginPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4); vertices[0] = { { p1.x, p1.y }, { u1, v2 } }; diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 39fd0586..bdf67fae 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -23,7 +23,6 @@ #include "common/event.h" #include "common/stringutils.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -375,8 +374,6 @@ void CSlider::Draw() int icon; float h; - auto device = m_engine->GetDevice(); - if ( (m_state & STATE_VISIBLE) == 0 ) return; if (m_buttonLeft != nullptr) @@ -492,8 +489,7 @@ void CSlider::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon) glm::vec2 uv1, uv2, corner; float ex, dp; - auto device = m_engine->GetDevice(); - auto renderer = device->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); if ( icon == 0 ) { diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index db77af83..c42e4d11 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -38,7 +38,6 @@ #include "ui/controls/slider.h" #include "ui/controls/target.h" -#include "graphics/core/device.h" #include "graphics/core/renderers.h" #include "graphics/core/transparency.h" @@ -824,8 +823,6 @@ void CWindow::Draw() { if ( (m_state & STATE_VISIBLE) == 0 ) return; - auto device = m_engine->GetDevice(); - if ( m_state & STATE_SHADOW ) { DrawShadow(m_pos, m_dim); @@ -909,8 +906,7 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension, glm::vec2 pos = position; glm::vec2 dim = dimension; - auto device = m_engine->GetDevice(); - auto renderer = device->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); dp = 0.5f/256.0f; @@ -1300,8 +1296,7 @@ void CWindow::DrawHach(const glm::vec2& pos, const glm::vec2& dim) float dp, max, ndim; bool bStop; - auto device = m_engine->GetDevice(); - auto renderer = device->GetUIRenderer(); + auto renderer = m_engine->GetUIRenderer(); dp = 0.5f/256.0f; auto texture = m_engine->LoadTexture("textures/interface/button2.png"); diff --git a/src/ui/screen/screen_setup_display.cpp b/src/ui/screen/screen_setup_display.cpp index 44d463c4..4c186f5a 100644 --- a/src/ui/screen/screen_setup_display.cpp +++ b/src/ui/screen/screen_setup_display.cpp @@ -27,6 +27,7 @@ #include "common/settings.h" #include "common/stringutils.h" +#include "graphics/core/device.h" #include "graphics/engine/camera.h" #include "graphics/engine/engine.h" diff --git a/src/ui/screen/screen_setup_graphics.cpp b/src/ui/screen/screen_setup_graphics.cpp index e26746eb..9cb8e9d9 100644 --- a/src/ui/screen/screen_setup_graphics.cpp +++ b/src/ui/screen/screen_setup_graphics.cpp @@ -27,6 +27,7 @@ #include "common/settings.h" #include "common/stringutils.h" +#include "graphics/core/device.h" #include "graphics/engine/camera.h" #include "graphics/engine/engine.h"