From 465fe59dfbd60ffa22610958420c24a835712d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 16 Jun 2021 02:33:15 +0200 Subject: [PATCH] Added Renderers Added UI Renderer Added OpenGL 3.3 UI Renderer Reimplemented most of UI drawing functionality to use UI Renderer TODO: fix OpenGL errors --- src/CMakeLists.txt | 3 + src/graphics/core/device.h | 5 + src/graphics/core/renderers.h | 69 +++++++ src/graphics/engine/engine.cpp | 104 +++++++---- src/graphics/engine/engine.h | 4 + src/graphics/engine/text.cpp | 48 +++-- src/graphics/opengl/gl33device.cpp | 23 ++- src/graphics/opengl/gl33device.h | 8 + src/graphics/opengl/gl33renderers.cpp | 195 ++++++++++++++++++++ src/graphics/opengl/gl33renderers.h | 77 ++++++++ src/graphics/opengl/shaders/gl33/ui_fs.glsl | 36 ++++ src/graphics/opengl/shaders/gl33/ui_vs.glsl | 41 ++++ src/ui/controls/button.cpp | 7 +- src/ui/controls/check.cpp | 7 +- src/ui/controls/color.cpp | 27 +-- src/ui/controls/control.cpp | 142 +++++++------- src/ui/controls/edit.cpp | 19 +- src/ui/controls/gauge.cpp | 2 +- src/ui/controls/group.cpp | 77 ++++---- src/ui/controls/image.cpp | 4 +- src/ui/controls/key.cpp | 2 +- src/ui/controls/list.cpp | 10 +- src/ui/controls/map.cpp | 77 ++++---- src/ui/controls/scroll.cpp | 15 +- src/ui/controls/shortcut.cpp | 20 +- src/ui/controls/slider.cpp | 16 +- src/ui/controls/window.cpp | 55 ++++-- 27 files changed, 828 insertions(+), 265 deletions(-) create mode 100644 src/graphics/core/renderers.h create mode 100644 src/graphics/opengl/gl33renderers.cpp create mode 100644 src/graphics/opengl/gl33renderers.h create mode 100644 src/graphics/opengl/shaders/gl33/ui_fs.glsl create mode 100644 src/graphics/opengl/shaders/gl33/ui_vs.glsl diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be9f41ea..fd5eebd6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,6 +98,7 @@ add_library(colobotbase STATIC graphics/core/texture.h graphics/core/type.cpp graphics/core/type.h + graphics/core/renderers.h graphics/core/vertex.h graphics/engine/camera.cpp graphics/engine/camera.h @@ -144,6 +145,8 @@ add_library(colobotbase STATIC graphics/model/model_triangle.h graphics/opengl/gl33device.cpp graphics/opengl/gl33device.h + graphics/opengl/gl33renderers.cpp + graphics/opengl/gl33renderers.h graphics/opengl/glframebuffer.cpp graphics/opengl/glframebuffer.h graphics/opengl/glutil.cpp diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 6bfa8218..7047593c 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -49,6 +49,7 @@ namespace Gfx { class CFramebuffer; +class CUIRenderer; struct FramebufferParams; struct Light; struct Material; @@ -374,6 +375,8 @@ public: //! Sets current rendering mode virtual void SetRenderMode(RenderMode mode) = 0; + //! Returns UI renderer + virtual CUIRenderer* GetUIRenderer() = 0; //! Sets the transform matrix of given type virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0; @@ -424,6 +427,8 @@ public: Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; //! Renders primitive composed of vertices with solid color virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; + //! Renders primitive using UI renderer + virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) = 0; //! Renders primitives composed of lists of vertices with single texture virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices, diff --git a/src/graphics/core/renderers.h b/src/graphics/core/renderers.h new file mode 100644 index 00000000..9e7c8580 --- /dev/null +++ b/src/graphics/core/renderers.h @@ -0,0 +1,69 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + + /** + * \file graphics/core/renderers.h + * \brief Abstract classes representing renderers + */ + +#pragma once + +#include "graphics/core/vertex.h" + +#include + +// Graphics module namespace +namespace Gfx +{ + +enum PrimitiveType; +struct Texture; + +/** + * \class CRenderer + * \brief Common abstract interface for renderers + */ +class CRenderer +{ +public: + virtual ~CRenderer() { } + + //! Flush buffered content + virtual void Flush() = 0; +}; + +/** + * \class CRenderer + * \brief Abstract interface for UI renderers + */ +class CUIRenderer : public CRenderer +{ +public: + virtual ~CUIRenderer() { } + + //! Sets ortographic projection with given parameters + virtual void SetProjection(float left, float right, float bottom, float top) = 0; + //! Sets texture, setting texture 0 means using white texture + virtual void SetTexture(const Texture& texture) = 0; + + //! Draws primitive + virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) = 0; +}; + +} // namespace Gfx diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index c146d767..a085aba6 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -36,6 +36,7 @@ #include "graphics/core/device.h" #include "graphics/core/framebuffer.h" +#include "graphics/core/renderers.h" #include "graphics/engine/camera.h" #include "graphics/engine/cloud.h" @@ -356,6 +357,10 @@ bool CEngine::Create() m_matWorldInterface.LoadIdentity(); m_matViewInterface.LoadIdentity(); + auto renderer = m_device->GetUIRenderer(); + renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f); + m_device->SetRenderMode(RENDER_MODE_INTERFACE); + Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); TextureCreateParams params; @@ -1971,6 +1976,8 @@ void CEngine::SetState(int state, const Color& color) if (state == m_lastState && color == m_lastColor) return; + m_device->GetUIRenderer()->Flush(); + m_lastState = state; m_lastColor = color; @@ -3631,20 +3638,21 @@ void CEngine::DrawCaptured3DScene() m_device->SetRenderState(RENDER_STATE_BLENDING, false); m_device->SetRenderState(RENDER_STATE_CULLING, false); - Vertex vertices[4]; + Vertex2D vertices[4]; - vertices[0] = Vertex(Math::Vector(-1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 0.0f)); - vertices[1] = Vertex(Math::Vector(1.0f, -1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 0.0f)); - vertices[2] = Vertex(Math::Vector(-1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(0.0f, 1.0f)); - vertices[3] = Vertex(Math::Vector(1.0f, 1.0f, 0.0f), Math::Vector(0.0f, 1.0f, 0.0f), Math::Point(1.0f, 1.0f)); + vertices[0] = { { 0.0f, 0.0f }, { 0.0f, 0.0f } }; + vertices[1] = { { 1.0f, 0.0f }, { 1.0f, 0.0f } }; + vertices[2] = { { 0.0f, 1.0f }, { 0.0f, 1.0f } }; + vertices[3] = { { 1.0f, 1.0f }, { 1.0f, 1.0f } }; m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); - m_device->SetTexture(TEXTURE_PRIMARY, m_capturedWorldTexture); - m_device->SetTextureEnabled(TEXTURE_PRIMARY, true); - m_device->SetTextureEnabled(TEXTURE_SECONDARY, false); + auto renderer = m_device->GetUIRenderer(); - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); + renderer->SetTexture(m_capturedWorldTexture); + renderer->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, 4, vertices); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); } void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& transform, const Gfx::Color& color) @@ -4859,23 +4867,20 @@ void CEngine::DrawBackgroundImage() v2 -= margin_v; } - SetTexture(m_backgroundTex); - SetState(ENG_RSTATE_OPAQUE_TEXTURE | ENG_RSTATE_WRAP); + SetUITexture(m_backgroundTex); - m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); - - Vertex vertex[4] = + Vertex2D vertices[4] = { - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) + { { p1.x, p1.y }, { u1, v2 } }, + { { p1.x, p2.y }, { u1, v1 } }, + { { p2.x, p1.y }, { u2, v2 } }, + { { p2.x, p2.y }, { u2, v1 } } }; - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); AddStatisticTriangle(2); + + m_device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } void CEngine::DrawPlanet() @@ -5079,6 +5084,8 @@ void CEngine::DrawMouse() m_device->SetMaterial(material); m_device->SetTexture(0, m_miceTexture); + SetUITexture(m_miceTexture); + Math::Point mousePos = CInput::GetInstancePointer()->GetMousePos(); Math::IntPoint pos(mousePos.x * m_size.x, m_size.y - mousePos.y * m_size.y); pos.x -= MOUSE_TYPES.at(m_mouseType).hotPoint.x; @@ -5119,18 +5126,18 @@ void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon) u2 -= dp; v2 -= dp; - Math::Vector normal(0.0f, 0.0f, -1.0f); - - Vertex vertex[4] = + Vertex2D vertex[4] = { - Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v2)), - Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v1)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v2)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v1)) + { { p1.x, p2.y }, { u1, v2 } }, + { { p1.x, p1.y }, { u1, v1 } }, + { { p2.x, p2.y }, { u2, v2 } }, + { { p2.x, p1.y }, { u2, v1 } } }; m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); } void CEngine::DrawStats() @@ -5145,17 +5152,18 @@ void CEngine::DrawStats() Math::Point pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height); SetState(ENG_RSTATE_TCOLOR_ALPHA); + SetUITexture(Texture{}); - Gfx::Color black(0.0f, 0.0f, 0.0f, 0.75f); + glm::u8vec4 black = { 0, 0, 0, 192 }; Math::Point margin = Math::Point(5.f / m_size.x, 5.f / m_size.y); - VertexCol vertex[4] = + Vertex2D vertex[4] = { - VertexCol(Math::Vector(pos.x - margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y, 0.0f), black), - VertexCol(Math::Vector(pos.x - margin.x, pos.y + height + margin.y, 0.0f), black), - VertexCol(Math::Vector(pos.x + width + margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y, 0.0f), black), - VertexCol(Math::Vector(pos.x + width + margin.x, pos.y + height + margin.y, 0.0f), black) + { { pos.x - margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y }, {}, black }, + { { pos.x - margin.x, pos.y + height + margin.y }, {}, black }, + { { pos.x + width + margin.x, pos.y - (TOTAL_LINES + 1) * height - margin.y }, {}, black }, + { { pos.x + width + margin.x, pos.y + height + margin.y }, {}, black } }; m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); @@ -5233,6 +5241,8 @@ void CEngine::DrawStats() std::stringstream str; str << std::fixed << std::setprecision(2) << m_statisticPos.x << "; " << m_statisticPos.z; drawStatsLine( "Position", str.str(), ""); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); } void CEngine::DrawTimer() @@ -5241,6 +5251,8 @@ void CEngine::DrawTimer() Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COMMON, 15.0f)); m_text->DrawText(m_timerText, FONT_COMMON, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); } void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector& triangles) @@ -5525,6 +5537,11 @@ void CEngine::SetInterfaceCoordinates() m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); + + auto renderer = m_device->GetUIRenderer(); + renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); } void CEngine::EnablePauseBlur() @@ -5555,6 +5572,25 @@ void CEngine::SetWindowCoordinates() m_device->SetTransform(TRANSFORM_VIEW, matViewWindow); m_device->SetTransform(TRANSFORM_PROJECTION, matProjWindow); m_device->SetTransform(TRANSFORM_WORLD, matWorldWindow); + + auto renderer = m_device->GetUIRenderer(); + renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f); + + m_device->SetRenderMode(RENDER_MODE_INTERFACE); +} + +void CEngine::SetUITexture(const std::string& name) +{ + auto texture = LoadTexture(name); + + SetUITexture(texture); +} + +void CEngine::SetUITexture(const Texture& texture) +{ + auto renderer = m_device->GetUIRenderer(); + + renderer->SetTexture(texture); } } // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index aee24f34..b67124ac 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1189,6 +1189,10 @@ public: void EnablePauseBlur(); void DisablePauseBlur(); + void SetUITexture(const std::string& name); + void SetUITexture(const Texture& texture); + + //! Reloads all textures /** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/ void ReloadAllTextures(); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index fef37333..b8fad690 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -29,6 +29,8 @@ #include "common/resources/resourcemanager.h" +#include "graphics/core/renderers.h" + #include "graphics/engine/engine.h" #include "math/func.h" @@ -113,7 +115,7 @@ public: /// Add a quad to be rendered. /// This may trigger a call to Flush() if necessary. - void Add(Vertex vertices[4], unsigned int texID, EngineRenderState renderState, Color color) + void Add(Vertex2D vertices[4], unsigned int texID, EngineRenderState renderState, Color color) { if (texID != m_texID || renderState != m_renderState || color != m_color) { @@ -132,6 +134,7 @@ public: m_engine.SetState(m_renderState); m_engine.GetDevice()->SetTexture(0, m_texID); + m_engine.SetUITexture(Texture{ m_texID }); assert(m_firsts.size() == m_counts.size()); if (m_firsts.size() < m_quads.size()) @@ -148,16 +151,24 @@ public: } } - const Vertex* vertices = m_quads.front().vertices; - m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(), - m_counts.data(), static_cast(m_quads.size()), m_color); + for (const auto& quad : m_quads) + { + m_engine.GetDevice()->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad.vertices, 4); + } + + m_engine.GetDevice()->GetUIRenderer()->Flush(); + m_engine.GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); + + //const Vertex* vertices = m_quads.front().vertices; + //m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(), + // m_counts.data(), static_cast(m_quads.size()), m_color); m_engine.AddStatisticTriangle(static_cast(m_quads.size() * 2)); m_quads.clear(); } private: CEngine& m_engine; - struct Quad { Vertex vertices[4]; }; + struct Quad { Vertex2D vertices[4]; }; std::vector m_quads; std::vector m_firsts; std::vector m_counts; @@ -1026,8 +1037,6 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I Math::IntPoint p1(pos.x, pos.y - height); Math::IntPoint p2(pos.x + width, pos.y); - Math::Vector n(0.0f, 0.0f, -1.0f); // normal - // For whatever reason ch.c1 is a SIGNED char, we need to fix that unsigned char icon = static_cast(ch.c1); @@ -1047,12 +1056,14 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I uv2.x -= dp; uv2.y -= dp; - Vertex quad[4] = + glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 }; + + Vertex2D quad[4] = { - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv2.y)), - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv1.y)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv2.y)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv1.y)) + { { p1.x, p2.y }, { uv1.x, uv2.y }, col }, + { { p1.x, p1.y }, { uv1.x, uv1.y }, col }, + { { p2.x, p2.y }, { uv2.x, uv2.y }, col }, + { { p2.x, p1.y }, { uv2.x, uv1.y }, col } }; m_quadBatch->Add(quad, texID, ENG_RSTATE_TTEXTURE_WHITE, color); @@ -1083,14 +1094,15 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::I static_cast(tex.charPos.y + halfPixelMargin) / FONT_TEXTURE_SIZE.y); Math::Point texCoord2(static_cast(tex.charPos.x + tex.charSize.x - halfPixelMargin) / FONT_TEXTURE_SIZE.x, static_cast(tex.charPos.y + tex.charSize.y - halfPixelMargin) / FONT_TEXTURE_SIZE.y); - Math::Vector n(0.0f, 0.0f, -1.0f); // normal - Vertex quad[4] = + glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 }; + + Vertex2D quad[4] = { - Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(texCoord1.x, texCoord2.y)), - Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(texCoord1.x, texCoord1.y)), - Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(texCoord2.x, texCoord2.y)), - Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(texCoord2.x, texCoord1.y)) + { { p1.x, p2.y }, { texCoord1.x, texCoord2.y }, col }, + { { p1.x, p1.y }, { texCoord1.x, texCoord1.y }, col }, + { { p2.x, p2.y }, { texCoord2.x, texCoord2.y }, col }, + { { p2.x, p1.y }, { texCoord2.x, texCoord1.y }, col } }; m_quadBatch->Add(quad, tex.id, ENG_RSTATE_TEXT, color); diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index bd26d35b..82f79eb1 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -31,6 +31,7 @@ #include "graphics/engine/engine.h" #include "graphics/opengl/glframebuffer.h" +#include "graphics/opengl/gl33renderers.h" #include "math/geometry.h" @@ -40,6 +41,8 @@ #include +#include + // Graphics module namespace namespace Gfx @@ -511,6 +514,8 @@ bool CGL33Device::Create() glUniform1f(uni.alphaReference, 1.0f); } + m_uiRenderer = std::make_unique(); + SetRenderMode(RENDER_MODE_NORMAL); // create default framebuffer object @@ -570,6 +575,8 @@ void CGL33Device::Destroy() m_currentTextures.clear(); m_texturesEnabled.clear(); m_textureStageParams.clear(); + + m_uiRenderer = nullptr; } void CGL33Device::ConfigChanged(const DeviceConfig& newConfig) @@ -615,6 +622,8 @@ void CGL33Device::Clear() void CGL33Device::SetRenderMode(RenderMode mode) { + m_uiRenderer->Flush(); + switch (mode) { case RENDER_MODE_NORMAL: @@ -641,6 +650,11 @@ void CGL33Device::SetRenderMode(RenderMode mode) UpdateTextureState(2); } +CUIRenderer* CGL33Device::GetUIRenderer() +{ + return m_uiRenderer.get(); +} + void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix) { if (type == TRANSFORM_WORLD) @@ -1170,6 +1184,11 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, i glDrawArrays(TranslateGfxPrimitive(type), 0, vertexCount); } +void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) +{ + m_uiRenderer->DrawPrimitive(type, vertexCount, vertices); +} + void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color) { @@ -1834,16 +1853,12 @@ void CGL33Device::UpdateLights() inline void CGL33Device::BindVBO(GLuint vbo) { - if (m_currentVBO == vbo) return; - glBindBuffer(GL_ARRAY_BUFFER, vbo); m_currentVBO = vbo; } inline void CGL33Device::BindVAO(GLuint vao) { - if (m_currentVAO == vao) return; - glBindVertexArray(vao); m_currentVAO = vao; } diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index 5fcd4e2a..bbd05a01 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -57,6 +57,8 @@ struct DynamicBuffer unsigned int offset = 0; }; +class CGL33UIRenderer; + /** \class CGL33Device \brief Implementation of CDevice interface in OpenGL 3.3 @@ -90,6 +92,7 @@ public: void Clear() override; void SetRenderMode(RenderMode mode) override; + CUIRenderer* GetUIRenderer() override; void SetTransform(TransformType type, const Math::Matrix &matrix) override; @@ -121,6 +124,8 @@ public: Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) override; + virtual void DrawPrimitive(PrimitiveType type, const Vertex2D* vertices, int vertexCount) override; + virtual void DrawPrimitives(PrimitiveType type, const Vertex *vertices, int first[], int count[], int drawCount, Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; @@ -314,6 +319,9 @@ private: UniformLocations m_uniforms[3]; //! Uniform locations for current mode UniformLocations* m_uni = nullptr; + + //! Interface renderer + std::unique_ptr m_uiRenderer; }; } // namespace Gfx diff --git a/src/graphics/opengl/gl33renderers.cpp b/src/graphics/opengl/gl33renderers.cpp new file mode 100644 index 00000000..f61bbde9 --- /dev/null +++ b/src/graphics/opengl/gl33renderers.cpp @@ -0,0 +1,195 @@ +#include "graphics/opengl/gl33renderers.h" + +#include "graphics/opengl/glutil.h" + +#include "graphics/core/vertex.h" + +#include "common/logger.h" + +#include + +#include + +namespace Gfx +{ + +CGL33UIRenderer::CGL33UIRenderer() +{ + GLint shaders[2]; + + shaders[0] = LoadShader(GL_VERTEX_SHADER, "shaders/gl33/ui_vs.glsl"); + if (shaders[0] == 0) + { + GetLogger()->Error("Cound not create vertex shader from file 'ui_vs.glsl'\n"); + return; + } + + shaders[1] = LoadShader(GL_FRAGMENT_SHADER, "shaders/gl33/ui_fs.glsl"); + if (shaders[1] == 0) + { + GetLogger()->Error("Cound not create fragment shader from file 'ui_fs.glsl'\n"); + return; + } + + m_program = LinkProgram(2, shaders); + if (m_program == 0) + { + GetLogger()->Error("Cound not link shader program for normal rendering\n"); + return; + } + + glDeleteShader(shaders[0]); + glDeleteShader(shaders[1]); + + glUseProgram(m_program); + + m_projectionMatrix = glGetUniformLocation(m_program, "uni_ProjectionMatrix"); + auto matrix = glm::ortho(0.0f, +1.0f, 0.0f, +1.0f); + glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix)); + + // Set texture unit to 8th + auto texture = glGetUniformLocation(m_program, "uni_Texture"); + glUniform1i(texture, 8); + + // Generic buffer + glGenBuffers(1, &m_bufferVBO); + glBindBuffer(GL_COPY_WRITE_BUFFER, m_bufferVBO); + glBufferData(GL_COPY_WRITE_BUFFER, m_bufferCapacity, nullptr, GL_STREAM_DRAW); + + glGenVertexArrays(1, &m_bufferVAO); + glBindVertexArray(m_bufferVAO); + + // White texture + glActiveTexture(GL_TEXTURE0); + glGenTextures(1, &m_whiteTexture); + glBindTexture(GL_TEXTURE_2D, m_whiteTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE); + + glUseProgram(0); +} + +CGL33UIRenderer::~CGL33UIRenderer() +{ + glDeleteProgram(m_program); + glDeleteTextures(1, &m_whiteTexture); + + glDeleteBuffers(1, &m_bufferVBO); + glDeleteVertexArrays(1, &m_bufferVAO); +} + +void CGL33UIRenderer::SetProjection(float left, float right, float bottom, float top) +{ + Flush(); + + glUseProgram(m_program); + + auto matrix = glm::ortho(left, right, bottom, top); + + glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix)); + + glUseProgram(0); +} + +void CGL33UIRenderer::SetTexture(const Texture& texture) +{ + if (m_currentTexture == texture.id) return; + + Flush(); + + glActiveTexture(GL_TEXTURE8); + + m_currentTexture = texture.id; + + if (m_currentTexture == 0) + glBindTexture(GL_TEXTURE_2D, m_whiteTexture); + else + glBindTexture(GL_TEXTURE_2D, m_currentTexture); +} + +void CGL33UIRenderer::DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) +{ + // If too much data would be buffered, flush + size_t totalSize = (m_buffer.size() + count) * sizeof(Vertex2D); + + if (totalSize > m_bufferCapacity) + Flush(); + + // Buffer data + GLint first = m_buffer.size(); + + m_buffer.insert(m_buffer.end(), vertices, vertices + count); + m_types.push_back(TranslateGfxPrimitive(type)); + m_firsts.push_back(first); + m_counts.push_back(count); +} + +void CGL33UIRenderer::Flush() +{ + if (m_types.empty()) return; + + glUseProgram(m_program); + + // Increase buffer size if necessary + size_t size = m_buffer.size() * sizeof(Vertex2D); + + if (m_bufferCapacity < size) + m_bufferCapacity = size; + + // Send new vertices to GPU + glBindBuffer(GL_ARRAY_BUFFER, m_bufferVBO); + glBufferData(GL_ARRAY_BUFFER, m_bufferCapacity, nullptr, GL_STREAM_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, size, m_buffer.data()); + + // Respecify vertex attributes + glBindVertexArray(m_bufferVAO); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), + reinterpret_cast(offsetof(Vertex2D, position))); + + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), + reinterpret_cast(offsetof(Vertex2D, uv))); + + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex2D), + reinterpret_cast(offsetof(Vertex2D, color))); + + // Draw primitives by grouping by type + for (size_t i = 0; i < m_types.size(); i++) + { + //glDrawArrays(m_types[i], m_firsts[i], m_counts[i]); + + //* + size_t count = 1; + + for (; i + count < m_types.size(); count++) + { + if (m_types[i] != m_types[i + count]) + break; + } + + glMultiDrawArrays(m_types[i], &m_firsts[i], &m_counts[i], count); + + i += count; + // */ + } + + // Clear buffers + m_buffer.clear(); + m_types.clear(); + m_firsts.clear(); + m_counts.clear(); + + glUseProgram(0); +} + +} // namespace Gfx diff --git a/src/graphics/opengl/gl33renderers.h b/src/graphics/opengl/gl33renderers.h new file mode 100644 index 00000000..2ab940db --- /dev/null +++ b/src/graphics/opengl/gl33renderers.h @@ -0,0 +1,77 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + + /** + * \file graphics/opengl/gl33renderers.h + * \brief OpenGL 3.3 renderers + */ + +#pragma once + +#include "graphics/core/renderers.h" + +#include + +#include +#include + +// Graphics module namespace +namespace Gfx +{ + +class CGL33UIRenderer : public CUIRenderer +{ +public: + CGL33UIRenderer(); + virtual ~CGL33UIRenderer(); + + virtual void SetProjection(float left, float right, float bottom, float top) override; + virtual void SetTexture(const Texture& texture) override; + + virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) override; + + virtual void Flush() override; + +private: + // location of uni_ProjectionMatrix uniform + GLint m_projectionMatrix = -1; + + // Vertex buffer object + GLuint m_bufferVBO = 0; + // Vertex array object + GLuint m_bufferVAO = 0; + // VBO capacity + GLsizei m_bufferCapacity = 4 * 1024; + + // Buffered vertex data + std::vector m_buffer; + std::vector m_types; + std::vector m_firsts; + std::vector m_counts; + + // Shader program + GLuint m_program = 0; + + // 1x1 white texture + GLuint m_whiteTexture = 0; + // Currently bound texture + GLuint m_currentTexture = 0; +}; + +} // namespace Gfx diff --git a/src/graphics/opengl/shaders/gl33/ui_fs.glsl b/src/graphics/opengl/shaders/gl33/ui_fs.glsl new file mode 100644 index 00000000..b40b01bb --- /dev/null +++ b/src/graphics/opengl/shaders/gl33/ui_fs.glsl @@ -0,0 +1,36 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +// FRAGMENT SHADER - UI RENDERER +#version 330 core + +uniform sampler2D uni_Texture; + +in VertexData +{ + vec4 Color; + vec2 TexCoord; +} data; + +out vec4 out_FragColor; + +void main() +{ + out_FragColor = data.Color * texture(uni_Texture, data.TexCoord); +} diff --git a/src/graphics/opengl/shaders/gl33/ui_vs.glsl b/src/graphics/opengl/shaders/gl33/ui_vs.glsl new file mode 100644 index 00000000..8629eaae --- /dev/null +++ b/src/graphics/opengl/shaders/gl33/ui_vs.glsl @@ -0,0 +1,41 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +// VERTEX SHADER - UI RENDERER +#version 330 core + +uniform mat4 uni_ProjectionMatrix; + +layout(location = 0) in vec4 in_VertexCoord; +layout(location = 1) in vec2 in_TexCoord; +layout(location = 2) in vec4 in_Color; + +out VertexData +{ + vec4 Color; + vec2 TexCoord; +} data; + +void main() +{ + gl_Position = uni_ProjectionMatrix * in_VertexCoord; + + data.Color = in_Color; + data.TexCoord = in_TexCoord; +} diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index 86f0591b..52f9571f 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -24,6 +24,7 @@ #include "common/restext.h" #include "graphics/engine/engine.h" +#include "graphics/core/device.h" namespace Ui @@ -141,6 +142,8 @@ void CButton::Draw() Math::Point 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? @@ -167,8 +170,8 @@ void CButton::Draw() (m_state & STATE_CARD ) == 0 && (m_state & STATE_SIMPLY) == 0 ) { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetUITexture("textures/interface/button2.png"); dp = 0.5f / 256.0f; @@ -199,6 +202,8 @@ void CButton::Draw() pos.x = m_pos.x + m_dim.x - 5.0f / 640.0f - 3.0f / 640.0f; DrawIcon(pos, dim, uv1, uv2, 0.0f); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } diff --git a/src/ui/controls/check.cpp b/src/ui/controls/check.cpp index 2fc7dafe..4d6afd31 100644 --- a/src/ui/controls/check.cpp +++ b/src/ui/controls/check.cpp @@ -23,6 +23,7 @@ #include "common/event.h" #include "common/restext.h" +#include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/engine/text.h" @@ -92,6 +93,8 @@ void CCheck::Draw() float zoomExt, zoomInt; int icon; + auto device = m_engine->GetDevice(); + if ( (m_state & STATE_VISIBLE) == 0 ) return; iDim = m_dim; @@ -102,8 +105,8 @@ void CCheck::Draw() DrawShadow(m_pos, m_dim); } - m_engine->SetTexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetUITexture("textures/interface/button1.png"); zoomExt = 1.00f; zoomInt = 0.95f; @@ -146,6 +149,8 @@ void CCheck::Draw() } } + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); + m_dim = iDim; // Draw the name. diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index 8c7f7929..05fd4b07 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -124,10 +124,9 @@ bool CColor::EventProcess(const Event &event) // Draw the button. void CColor::Draw() { - Gfx::CDevice* device; - Gfx::VertexCol vertex[4]; // 2 triangles - Gfx::Color color; - Math::Point p1, p2; + Gfx::Vertex2D vertex[4]; // 2 triangles + Gfx::Color color; + Math::Point p1, p2; if ( (m_state & STATE_VISIBLE) == 0 ) return; @@ -136,7 +135,7 @@ void CColor::Draw() DrawShadow(m_pos, m_dim); } - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); CControl::Draw(); @@ -147,19 +146,23 @@ void CColor::Draw() color = GetColor(); - m_engine->SetTexture(""); // no texture + glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 }; + + m_engine->SetUITexture(Gfx::Texture{0}); // no texture m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); - vertex[0] = Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color); - vertex[1] = Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color); - vertex[2] = Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color); - vertex[3] = Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color); + auto device = m_engine->GetDevice(); + + vertex[0] = { { p1.x, p1.y }, {}, col }; + vertex[1] = { { p1.x, p2.y }, {}, col }; + vertex[2] = { { p2.x, p1.y }, {}, col }; + vertex[3] = { { p2.x, p2.y }, {}, col }; - device = m_engine->GetDevice(); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); -} + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); +} void CColor::SetRepeat(bool bRepeat) { diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index cb97d5db..fadf3a91 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -453,8 +453,9 @@ void CControl::Draw() if ( (m_state & STATE_VISIBLE) == 0 ) return; - m_engine->SetTexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetUITexture("textures/interface/button1.png"); + auto device = m_engine->GetDevice(); zoomExt = 1.00f; zoomInt = 0.95f; @@ -507,7 +508,7 @@ void CControl::Draw() if ( m_state & STATE_OKAY ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); icon = 3; // yellow with green point pressed } @@ -555,6 +556,8 @@ void CControl::Draw() m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0); } } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draw the vertex array. @@ -606,26 +609,22 @@ void CControl::DrawPart(int icon, float zoom, float ex) void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, float ex) { - Gfx::CDevice* device; - Gfx::Vertex vertex[8]; // 6 triangles - Math::Point p1, p2, p3, p4; - Math::Vector n; + Gfx::Vertex2D vertex[8]; // 6 triangles + glm::vec2 p1, p2, p3, p4; - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); p1.x = pos.x; p1.y = pos.y; p2.x = pos.x + dim.x; p2.y = pos.y + dim.y; - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - if ( ex == 0.0f ) // one piece? { - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv2.y)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv1.y)); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); - vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x,uv1.y)); + vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; + vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; + vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; + vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -637,14 +636,14 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: p3.x = p1.x + ex*dim.y / (uv2.y - uv1.y); p4.x = p2.x - ex*dim.y / (uv2.y - uv1.y); - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y)); - vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p1.y, 0.0f), n, Math::Point(uv1.x+ex,uv2.y)); - vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p2.y, 0.0f), n, Math::Point(uv1.x+ex,uv1.y)); - vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p1.y, 0.0f), n, Math::Point(uv2.x-ex,uv2.y)); - vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p2.y, 0.0f), n, Math::Point(uv2.x-ex,uv1.y)); - vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y)); - vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y)); + vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; + vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; + vertex[2] = { { p3.x, p1.y }, { uv1.x+ex,uv2.y } }; + vertex[3] = { { p3.x, p2.y }, { uv1.x+ex,uv1.y } }; + vertex[4] = { { p4.x, p1.y }, { uv2.x-ex,uv2.y } }; + vertex[5] = { { p4.x, p2.y }, { uv2.x-ex,uv1.y } }; + vertex[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; + vertex[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8); m_engine->AddStatisticTriangle(6); @@ -654,19 +653,21 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: p3.y = p1.y + ex*dim.x / (uv2.x - uv1.x); p4.y = p2.y - ex*dim.x / (uv2.x - uv1.x); - vertex[0] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y )); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y )); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex)); - vertex[3] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex)); - vertex[4] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex)); - vertex[5] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex)); - vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y )); - vertex[7] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y )); + vertex[0] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; + vertex[1] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; + vertex[2] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; + vertex[3] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } }; + vertex[4] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } }; + vertex[5] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } }; + vertex[6] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; + vertex[7] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8); m_engine->AddStatisticTriangle(6); } } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draws a rectangular icon made up of 9 pieces. @@ -674,20 +675,16 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, Math::Point corner, float ex) { - Gfx::CDevice* device; - Gfx::Vertex vertex[8]; // 6 triangles - Math::Point p1, p2, p3, p4; - Math::Vector n; + Gfx::Vertex2D vertices[8]; // 6 triangles + glm::vec2 p1, p2, p3, p4; - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); p1.x = pos.x; p1.y = pos.y; p2.x = pos.x + dim.x; p2.y = pos.y + dim.y; - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - if ( corner.x > dim.x / 2.0f ) corner.x = dim.x / 2.0f; if ( corner.y > dim.y / 2.0f ) corner.y = dim.y / 2.0f; @@ -701,40 +698,45 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: p4.y = p2.y - corner.y; // Bottom horizontal band. - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x, uv2.y )); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex)); - vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p1.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y )); - vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y - ex)); - vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p1.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y )); - vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p3.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y - ex)); - vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x, uv2.y )); - vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex)); - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8); + vertices[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; + vertices[1] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } }; + vertices[2] = { { p3.x, p1.y }, { uv1.x + ex, uv2.y } }; + vertices[3] = { { p3.x, p3.y }, { uv1.x + ex, uv2.y - ex } }; + vertices[4] = { { p4.x, p1.y }, { uv2.x - ex, uv2.y } }; + vertices[5] = { { p4.x, p3.y }, { uv2.x - ex, uv2.y - ex } }; + vertices[6] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; + vertices[7] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8); m_engine->AddStatisticTriangle(6); // Central horizontal band. - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p3.y, 0.0f), n, Math::Point(uv1.x, uv2.y - ex)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex)); - vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv1.x + ex, uv2.y - ex)); - vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p4.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y + ex)); - vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p3.y, 0.0f), n, Math::Point(uv2.x - ex, uv2.y - ex)); - vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y + ex)); - vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p3.y, 0.0f), n, Math::Point(uv2.x, uv2.y - ex)); - vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex)); - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8); + vertices[0] = { { p1.x, p3.y }, { uv1.x, uv2.y - ex } }; + vertices[1] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } }; + vertices[2] = { { p3.x, p3.y }, { uv1.x + ex, uv2.y - ex } }; + vertices[3] = { { p3.x, p4.y }, { uv1.x + ex, uv1.y + ex } }; + vertices[4] = { { p4.x, p3.y }, { uv2.x - ex, uv2.y - ex } }; + vertices[5] = { { p4.x, p4.y }, { uv2.x - ex, uv1.y + ex } }; + vertices[6] = { { p2.x, p3.y }, { uv2.x, uv2.y - ex } }; + vertices[7] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } }; + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8); m_engine->AddStatisticTriangle(6); // Top horizontal band. - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p4.y, 0.0f), n, Math::Point(uv1.x, uv1.y + ex)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x, uv1.y )); - vertex[2] = Gfx::Vertex(Math::Vector(p3.x, p4.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y + ex)); - vertex[3] = Gfx::Vertex(Math::Vector(p3.x, p2.y, 0.0f), n, Math::Point(uv1.x + ex, uv1.y )); - vertex[4] = Gfx::Vertex(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y + ex)); - vertex[5] = Gfx::Vertex(Math::Vector(p4.x, p2.y, 0.0f), n, Math::Point(uv2.x - ex, uv1.y )); - vertex[6] = Gfx::Vertex(Math::Vector(p2.x, p4.y, 0.0f), n, Math::Point(uv2.x, uv1.y + ex)); - vertex[7] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x, uv1.y )); - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 8); + vertices[0] = { { p1.x, p4.y }, { uv1.x, uv1.y + ex } }; + vertices[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; + vertices[2] = { { p3.x, p4.y }, { uv1.x + ex, uv1.y + ex } }; + vertices[3] = { { p3.x, p2.y }, { uv1.x + ex, uv1.y } }; + vertices[4] = { { p4.x, p4.y }, { uv2.x - ex, uv1.y + ex } }; + vertices[5] = { { p4.x, p2.y }, { uv2.x - ex, uv1.y } }; + vertices[6] = { { p2.x, p4.y }, { uv2.x, uv1.y + ex } }; + vertices[7] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; + + device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8); m_engine->AddStatisticTriangle(6); + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draw round the hatch of a button. @@ -746,8 +748,9 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim) dp = 0.5f / 256.0f; - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetUITexture("textures/interface/button2.png"); + auto device = m_engine->GetDevice(); uv1.x = 64.0f / 256.0f; uv1.y = 208.0f / 256.0f; @@ -779,6 +782,8 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim) pos.x += dim.x; DrawIcon(pos, dim, uv1, uv2); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draw the shade under a button. @@ -790,8 +795,9 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep) dp = 0.5f/256.0f; - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE); + m_engine->SetUITexture("textures/interface/button2.png"); + auto device = m_engine->GetDevice(); pos.x += deep * 0.010f * 0.75f; pos.y -= deep * 0.015f; @@ -812,6 +818,8 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep) corner.y = 10.0f / 480.0f; DrawIcon(pos, dim, uv1, uv2, corner, 6.0f / 256.0f); + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } @@ -841,7 +849,9 @@ int CControl::SetButtonTextureForIcon(int icon) { int iconIdx = icon%64; int buttonFile = (icon/64) + 1; - m_engine->SetTexture("textures/interface/button" + StrUtils::ToString(buttonFile) + ".png"); + + m_engine->SetUITexture("textures/interface/button" + StrUtils::ToString(buttonFile) + ".png"); + return iconIdx; } diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 570bd518..6c132079 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -1155,6 +1155,8 @@ void CEdit::Draw() { m_scroll->Draw(); } + + m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draw an image part. @@ -1182,7 +1184,7 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width, params.padToNearestPowerOfTwo = true; Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params); - m_engine->SetTexture(tex); + m_engine->SetUITexture(tex); uv1.x = 0.0f; uv2.x = 1.0f; @@ -1214,7 +1216,7 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim) if ( m_bGeneric ) return; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( m_bMulti ) @@ -1267,12 +1269,15 @@ void CEdit::DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color p2.x = pos.x + dim.x; p2.y = pos.y + dim.y; - Gfx::VertexCol quad[] = + glm::u8vec4 col1 = { color1.r * 255, color1.g * 255, color1.b * 255, color1.a * 255 }; + glm::u8vec4 col2 = { color2.r * 255, color2.g * 255, color2.b * 255, color2.a * 255 }; + + Gfx::Vertex2D quad[] = { - Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color1), - Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color1), - Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color2), - Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color2) + { { p1.x, p1.y }, {}, col1 }, + { { p1.x, p2.y }, {}, col1 }, + { { p2.x, p1.y }, {}, col2 }, + { { p2.x, p2.y }, {}, col2 } }; m_engine->GetDevice()->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); diff --git a/src/ui/controls/gauge.cpp b/src/ui/controls/gauge.cpp index 545fcfa7..02c30f44 100644 --- a/src/ui/controls/gauge.cpp +++ b/src/ui/controls/gauge.cpp @@ -78,7 +78,7 @@ void CGauge::Draw() if ( (m_state & STATE_VISIBLE) == 0 ) return; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); dp = 0.5f/256.0f; diff --git a/src/ui/controls/group.cpp b/src/ui/controls/group.cpp index d303c118..f1b864c4 100644 --- a/src/ui/controls/group.cpp +++ b/src/ui/controls/group.cpp @@ -23,6 +23,7 @@ #include "common/event.h" #include "common/restext.h" +#include "graphics/core/device.h" #include "graphics/engine/engine.h" @@ -79,6 +80,8 @@ void CGroup::Draw() float dp; int icon; + auto device = m_engine->GetDevice(); + if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( m_state & STATE_SHADOW ) @@ -90,8 +93,9 @@ void CGroup::Draw() if ( m_icon == 0 ) // hollow frame? { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + uv1.x = 160.0f / 256.0f; uv1.y = 192.0f / 256.0f; // u-v texture uv2.x = 192.0f / 256.0f; @@ -106,8 +110,9 @@ void CGroup::Draw() } if ( m_icon == 1 ) // orange solid opaque? { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetUITexture("textures/interface/button2.png"); + uv1.x = 104.0f / 256.0f; uv1.y = 48.0f / 256.0f; uv2.x = 112.0f / 256.0f; @@ -120,8 +125,9 @@ void CGroup::Draw() } if ( m_icon == 2 ) // orange degrade -> transparent? { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); + m_engine->SetUITexture("textures/interface/button2.png"); + uv1.x = 112.0f / 256.0f; uv1.y = 48.0f / 256.0f; uv2.x = 120.0f / 256.0f; @@ -134,8 +140,9 @@ void CGroup::Draw() } if ( m_icon == 3 ) // transparent gradient -> gray? { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); + m_engine->SetUITexture("textures/interface/button2.png"); + uv1.x = 120.0f / 256.0f; uv1.y = 48.0f / 256.0f; uv2.x = 128.0f / 256.0f; @@ -148,8 +155,9 @@ void CGroup::Draw() } if ( m_icon == 4 ) // degrade blue corner? { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); + m_engine->SetUITexture("textures/interface/button2.png"); + uv1.x = 192.0f / 256.0f; uv1.y = 128.0f / 256.0f; uv2.x = 224.0f / 256.0f; @@ -162,8 +170,9 @@ void CGroup::Draw() } if ( m_icon == 5 ) // degrade orange corner? { - m_engine->SetTexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); + m_engine->SetUITexture("textures/interface/button2.png"); + uv1.x = 224.0f / 256.0f; uv1.y = 128.0f / 256.0f; uv2.x = 256.0f / 256.0f; @@ -176,8 +185,9 @@ void CGroup::Draw() } if ( m_icon == 6 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + uv1.x = 0.0f / 256.0f; // brown transparent uv1.y = 75.0f / 256.0f; uv2.x = 64.0f / 256.0f; @@ -192,8 +202,9 @@ void CGroup::Draw() } if ( m_icon == 7 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + uv1.x = 64.0f / 256.0f; uv1.y = 0.0f / 256.0f; uv2.x = 96.0f / 256.0f; @@ -206,8 +217,9 @@ void CGroup::Draw() } if ( m_icon == 8 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + uv1.x = 64.0f / 256.0f; // green transparent uv1.y = 160.0f / 256.0f; uv2.x = 160.0f / 256.0f; @@ -220,8 +232,9 @@ void CGroup::Draw() } if ( m_icon == 9 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + uv1.x = 64.0f / 256.0f; // red transparent uv1.y = 176.0f/256.0f; uv2.x = 160.0f/256.0f; @@ -234,8 +247,9 @@ void CGroup::Draw() } if ( m_icon == 10 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + uv1.x = 64.0f / 256.0f; // blue transparent uv1.y = 192.0f / 256.0f; uv2.x = 160.0f / 256.0f; @@ -248,7 +262,7 @@ void CGroup::Draw() } if ( m_icon == 11 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f / 256.0f; // yellow transparent uv1.y = 224.0f / 256.0f; @@ -265,7 +279,7 @@ void CGroup::Draw() dim.x = m_dim.x / 2.0f; dim.y = m_dim.y / 2.0f; - m_engine->SetTexture("textures/interface/mouse.png"); + m_engine->SetUITexture("textures/interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/300.0f; pos.y = m_pos.y+m_dim.y/300.0f+dim.y; @@ -304,7 +318,7 @@ void CGroup::Draw() } if ( m_icon == 13 ) // corner upper / left? { - m_engine->SetTexture("textures/interface/mouse.png"); + m_engine->SetUITexture("textures/interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -325,7 +339,7 @@ void CGroup::Draw() } if ( m_icon == 14 ) // corner upper / right? { - m_engine->SetTexture("textures/interface/mouse.png"); + m_engine->SetUITexture("textures/interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -346,7 +360,7 @@ void CGroup::Draw() } if ( m_icon == 15 ) // corner lower / left? { - m_engine->SetTexture("textures/interface/mouse.png"); + m_engine->SetUITexture("textures/interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -367,7 +381,7 @@ void CGroup::Draw() } if ( m_icon == 16 ) // corner lower / left? { - m_engine->SetTexture("textures/interface/mouse.png"); + m_engine->SetUITexture("textures/interface/mouse.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); pos.x = m_pos.x-m_dim.x/150.0f; pos.y = m_pos.y+m_dim.y/150.0f; @@ -388,7 +402,7 @@ void CGroup::Draw() } if ( m_icon == 17 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f / 256.0f; // blue frame uv1.y = 75.0f / 256.0f; @@ -404,7 +418,7 @@ void CGroup::Draw() } if ( m_icon == 18 ) // arrow> for SatCom? { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 0.0f / 256.0f; // > uv1.y = 192.0f / 256.0f; @@ -418,7 +432,7 @@ void CGroup::Draw() } if ( m_icon == 19 ) // SatCom symbol? { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 224.0f / 256.0f; // SatCom symbol uv1.y = 224.0f / 256.0f; @@ -432,7 +446,7 @@ void CGroup::Draw() } if ( m_icon == 20 ) // solid blue background? { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 224.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -446,7 +460,7 @@ void CGroup::Draw() } if ( m_icon == 21 ) // stand-by symbol? { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 160.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -460,7 +474,7 @@ void CGroup::Draw() } if ( m_icon == 22 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // opaque yellow uv1.y = 224.0f / 256.0f; @@ -477,7 +491,7 @@ void CGroup::Draw() if ( m_icon == 23 ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // yellow uv1.y = 192.0f / 256.0f; @@ -493,7 +507,7 @@ void CGroup::Draw() } if ( m_icon == 24 ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 80.0f / 256.0f; // orange uv1.y = 192.0f / 256.0f; @@ -509,7 +523,7 @@ void CGroup::Draw() } if ( m_icon == 25 ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; // orange uv1.y = 208.0f / 256.0f; @@ -525,7 +539,7 @@ void CGroup::Draw() } if ( m_icon == 26 ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 80.0f / 256.0f; // red uv1.y = 208.0f / 256.0f; @@ -541,7 +555,7 @@ void CGroup::Draw() } if ( m_icon == 27 ) { - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f / 256.0f; uv1.y = 0.0f / 256.0f; @@ -558,8 +572,7 @@ void CGroup::Draw() { pos = m_pos; dim = m_dim; - - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f / 256.0f; uv1.y = 32.0f / 256.0f; @@ -571,7 +584,7 @@ void CGroup::Draw() uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); pos.x += 8.0f / 640.0f; pos.y += 8.0f / 480.0f; @@ -633,6 +646,8 @@ void CGroup::Draw() uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } diff --git a/src/ui/controls/image.cpp b/src/ui/controls/image.cpp index bb610042..3e630c8e 100644 --- a/src/ui/controls/image.cpp +++ b/src/ui/controls/image.cpp @@ -102,7 +102,7 @@ void CImage::Draw() if ( m_icon == 0 ) // hollow frame? { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 160.0f / 256.0f; uv1.y = 192.0f / 256.0f; // u-v texture @@ -124,7 +124,7 @@ void CImage::Draw() params.filter = Gfx::TEX_FILTER_BILINEAR; params.padToNearestPowerOfTwo = true; Gfx::Texture tex = m_engine->LoadTexture(m_filename, params); - m_engine->SetTexture(tex); + m_engine->SetUITexture(tex); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); pos = m_pos; dim = m_dim; diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index 03dab6ac..977c0c28 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -135,7 +135,7 @@ void CKey::Draw() DrawShadow(m_pos, m_dim); - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); float zoomExt = 1.00f; diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 59a02176..df3d1a19 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -370,7 +370,7 @@ void CList::Draw() if (m_icon == 0) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f / 256.0f; @@ -380,7 +380,7 @@ void CList::Draw() } else { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 132.0f / 256.0f; @@ -416,7 +416,7 @@ void CList::Draw() dim.y *= 0.4f; pos.y -= dim.y; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw uv1.x = 120.0f / 256.0f; uv1.y = 64.0f / 256.0f; @@ -491,7 +491,7 @@ void CList::Draw() if (m_items[i + m_firstLine].check) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f / 256.0f; uv1.y = 0.0f / 256.0f; @@ -516,7 +516,7 @@ void CList::Draw() } else { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw if ( i + m_firstLine == m_selectLine ) { diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index 9d9ebb48..883e44e4 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -344,7 +344,7 @@ void CMap::Draw() if (m_fixImage.empty()) // drawing of the relief? { - m_engine->SetTexture("textures/interface/map.png"); + m_engine->SetUITexture("textures/interface/map.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.5f + (m_offset.x - (m_half / m_zoom)) / (m_half * 2.0f); uv1.y = 0.5f - (m_offset.y + (m_half / m_zoom)) / (m_half * 2.0f); @@ -355,7 +355,7 @@ void CMap::Draw() else // still image? { m_engine->LoadTexture(m_fixImage); - m_engine->SetTexture(m_fixImage); + m_engine->SetUITexture(m_fixImage); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f; uv1.y = 0.0f; @@ -493,7 +493,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color uv2.x = 126.0f/256.0f; uv2.y = 255.0f/256.0f; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); bEnding = false; @@ -553,7 +553,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo return; // flashes } - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); if ( bUp ) { @@ -696,7 +696,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo { if ( bSelect ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( m_bToy ) { @@ -722,7 +722,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo { if ( m_bRadar ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 64.5f/256.0f; // blue triangle uv1.y = 240.5f/256.0f; @@ -742,7 +742,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo if ( color == MAPCOLOR_WAYPOINTb ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 192.5f/256.0f; // blue cross uv1.y = 240.5f/256.0f; @@ -752,7 +752,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTr ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 208.5f/256.0f; // red cross uv1.y = 240.5f/256.0f; @@ -762,7 +762,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTg ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 224.5f/256.0f; // green cross uv1.y = 240.5f/256.0f; @@ -772,7 +772,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTy ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 240.5f/256.0f; // yellow cross uv1.y = 240.5f/256.0f; @@ -782,7 +782,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo } if ( color == MAPCOLOR_WAYPOINTv ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 192.5f/256.0f; // violet cross uv1.y = 224.5f/256.0f; @@ -803,7 +803,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, dp = 0.5f/256.0f; - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); if ( color == MAPCOLOR_MOVE ) { @@ -907,7 +907,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, case OBJECT_MOBILEit: case OBJECT_MOBILErp: case OBJECT_MOBILEst: - m_engine->SetTexture("textures/interface/button4.png"); break; + m_engine->SetUITexture("textures/interface/button4.png"); break; default: ; // button3.png } @@ -942,7 +942,7 @@ void CMap::DrawHighlight(Math::Point pos) dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f; dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 160.5f/256.0f; // hilite uv1.y = 224.5f/256.0f; @@ -957,17 +957,13 @@ void CMap::DrawHighlight(Math::Point pos) void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2) { - Gfx::CDevice* device; - Gfx::VertexTex2 vertex[3]; // 1 triangle - Math::Vector n; + Gfx::Vertex2D vertex[3]; // 1 triangle - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - - vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv1.y)); - vertex[1] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv2.y)); - vertex[2] = Gfx::VertexTex2(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); + vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } }; + vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } }; + vertex[2] = { { p3.x, p3.y }, { uv2.x, uv2.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLES, vertex, 3); m_engine->AddStatisticTriangle(1); @@ -977,19 +973,15 @@ void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Po void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2) { - Gfx::CDevice* device; - Gfx::VertexTex2 vertex[5]; // 1 pentagon - Math::Vector n; + Gfx::Vertex2D vertex[5]; // 1 pentagon - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - - vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv1.y)); - vertex[1] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv2.y)); - vertex[2] = Gfx::VertexTex2(Math::Vector(p5.x, p5.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); - vertex[3] = Gfx::VertexTex2(Math::Vector(p3.x, p3.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); - vertex[4] = Gfx::VertexTex2(Math::Vector(p4.x, p4.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); + vertex[0] = { { p1.x, p1.y }, { uv1.x, uv1.y } }; + vertex[1] = { { p2.x, p2.y }, { uv1.x, uv2.y } }; + vertex[2] = { { p5.x, p5.y }, { uv2.x, uv2.y } }; + vertex[3] = { { p3.x, p3.y }, { uv2.x, uv2.y } }; + vertex[4] = { { p4.x, p4.y }, { uv2.x, uv2.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 5); m_engine->AddStatisticTriangle(3); @@ -999,12 +991,10 @@ void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) { - Gfx::CDevice* device; - Gfx::VertexTex2 vertex[4]; // 2 triangles + Gfx::Vertex2D vertex[4]; // 2 triangles Math::Point p1, p2, c; - Math::Vector n; - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); p1.x = m_pos.x; p1.y = m_pos.y; @@ -1024,12 +1014,10 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) m_mapDim.x = p2.x-p1.x; m_mapDim.y = p2.y-p1.y; - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - - vertex[0] = Gfx::VertexTex2(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(uv1.x,uv2.y)); - vertex[1] = Gfx::VertexTex2(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(uv1.x,uv1.y)); - vertex[2] = Gfx::VertexTex2(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(uv2.x,uv2.y)); - vertex[3] = Gfx::VertexTex2(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(uv2.x,uv1.y)); + vertex[0] = { { p1.x, p1.y }, { uv1.x, uv2.y } }; + vertex[1] = { { p1.x, p2.y }, { uv1.x, uv1.y } }; + vertex[2] = { { p2.x, p1.y }, { uv2.x, uv2.y } }; + vertex[3] = { { p2.x, p2.y }, { uv2.x, uv1.y } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); @@ -1094,6 +1082,7 @@ void CMap::UpdateTerrain() m_engine->DeleteTexture("interface/map.png"); m_engine->LoadTexture("textures/interface/map.png", &img); + m_engine->SetUITexture("textures/interface/map.png"); } // Updates the field in the map. diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 2dbf39b1..2bb42f47 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -23,6 +23,7 @@ #include "common/event.h" #include "common/make_unique.h" +#include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "ui/controls/button.h" @@ -306,6 +307,8 @@ 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. @@ -351,6 +354,8 @@ void CScroll::Draw() { m_buttonDown->Draw(); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draws a rectangle. @@ -360,9 +365,11 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) Math::Point uv1, uv2; float ex, dp; + auto device = m_engine->GetDevice(); + if ( icon == 0 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; @@ -372,7 +379,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; @@ -382,7 +389,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 2 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; // blue rectangle uv1.y = 0.0f/256.0f; @@ -392,7 +399,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 104.0f/256.0f; // blue line - uv1.y = 32.0f/256.0f; diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 0864db1b..eb2c9d90 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -115,7 +115,7 @@ void CShortcut::Draw() zoom = 1.0f; } - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); if ( icon != -1 ) { @@ -216,19 +216,19 @@ void CShortcut::Draw() DrawIcon(m_pos, m_dim, uv1, uv2); } + + m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draw the vertex array. void CShortcut::DrawVertex(int icon, float zoom) { - Gfx::CDevice* device; - Gfx::Vertex vertex[4]; // 2 triangles + Gfx::Vertex2D vertex[4]; // 2 triangles Math::Point p1, p2, c; - Math::Vector n; float u1, u2, v1, v2, dp; - device = m_engine->GetDevice(); + auto device = m_engine->GetDevice(); p1.x = m_pos.x; p1.y = m_pos.y; @@ -255,12 +255,10 @@ void CShortcut::DrawVertex(int icon, float zoom) u2 -= dp; v2 -= dp; - n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - - vertex[0] = Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)); - vertex[1] = Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)); - vertex[2] = Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)); - vertex[3] = Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)); + vertex[0] = { { p1.x, p1.y }, { u1, v2 } }; + vertex[1] = { { p1.x, p2.y }, { u1, v1 } }; + vertex[2] = { { p2.x, p1.y }, { u2, v2 } }; + vertex[3] = { { p2.x, p2.y }, { u2, v1 } }; device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_engine->AddStatisticTriangle(2); diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 3ae1109e..69ea8c6b 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -23,6 +23,7 @@ #include "common/event.h" #include "common/stringutils.h" +#include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/engine/text.h" @@ -371,6 +372,8 @@ void CSlider::Draw() int icon; float h; + auto device = m_engine->GetDevice(); + if ( (m_state & STATE_VISIBLE) == 0 ) return; if (m_buttonLeft != nullptr) @@ -472,6 +475,8 @@ void CSlider::Draw() m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); } } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } std::string CSlider::GetLabel() @@ -486,9 +491,12 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) Math::Point uv1, uv2, corner; float ex, dp; + auto device = m_engine->GetDevice(); + auto renderer = device->GetUIRenderer(); + if ( icon == 0 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // yellow rectangle uv1.y = 32.0f/256.0f; @@ -500,7 +508,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // gray rectangle uv1.y = 32.0f/256.0f; @@ -512,7 +520,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 224.0f/256.0f; // cursor uv1.y = 32.0f/256.0f; @@ -535,6 +543,8 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2, corner, ex); + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index bcf76ce4..2d0f6631 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -38,6 +38,8 @@ #include "ui/controls/slider.h" #include "ui/controls/target.h" +#include "graphics/core/device.h" + #include @@ -816,6 +818,8 @@ 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); @@ -862,6 +866,8 @@ void CWindow::Draw() DrawHach(pos, dim); // right hatch } + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); + pos.x = m_pos.x+width/2.0f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f; m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0); @@ -886,6 +892,8 @@ void CWindow::Draw() { control->Draw(); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draws a rectangle. @@ -896,11 +904,13 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) float dp; int i; + auto device = m_engine->GetDevice(); + dp = 0.5f/256.0f; if ( icon == 0 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 64.0f/256.0f; // dark blue transparent uv1.y = 64.0f/256.0f; @@ -916,7 +926,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 1 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // white tooltip uv1.y = 0.0f/256.0f; @@ -930,7 +940,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 2 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // yellow uv1.y = 16.0f/256.0f; @@ -944,7 +954,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 3 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper uv1.y = 64.0f/256.0f; @@ -963,7 +973,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x += 100.0f/640.0f; dim.y += 60.0f/480.0f; - m_engine->SetTexture("textures/objects/human.png"); + m_engine->SetUITexture("textures/object/human.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 140.0f/256.0f; uv1.y = 32.0f/256.0f; @@ -980,7 +990,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y += 0.0f/480.0f; - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); uv1.x = 192.0f/256.0f; uv1.y = 32.0f/256.0f; @@ -999,7 +1009,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y -= 20.0f/480.0f; - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; uv1.y = 0.0f/256.0f; @@ -1035,7 +1045,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) dim.x -= 20.0f/640.0f; dim.y -= 20.0f/480.0f; - m_engine->SetTexture("textures/interface/button3.png"); + m_engine->SetUITexture("textures/interface/button3.png"); uv1.x = 0.0f/256.0f; uv1.y = 224.0f/256.0f; uv2.x = 32.0f/256.0f; @@ -1046,7 +1056,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) uv2.y -= dp; DrawIcon(pos, dim, uv1, uv2); // dark blue background - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); uv1.x = 224.0f/256.0f; uv1.y = 224.0f/256.0f; uv2.x = 249.0f/256.0f; @@ -1118,7 +1128,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 5 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent green uv1.y = 160.0f/256.0f; @@ -1132,7 +1142,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 6 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent red uv1.y = 176.0f/256.0f; @@ -1146,7 +1156,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 7 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent blue uv1.y = 192.0f/256.0f; @@ -1160,7 +1170,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 8 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 0.0f/256.0f; // opaque orange uv1.y = 0.0f/256.0f; @@ -1176,7 +1186,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 9 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 32.0f/256.0f; // opaque gray uv1.y = 32.0f/256.0f; @@ -1196,7 +1206,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 11 ) { - m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); uv1.x = 64.0f/256.0f; // transparent yellow uv1.y = 224.0f/256.0f; @@ -1210,7 +1220,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 12 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 128.0f/256.0f; // dirty opaque gray uv1.y = 128.0f/256.0f; @@ -1226,7 +1236,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 13 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 192.0f/256.0f; // dirty opaque blue uv1.y = 128.0f/256.0f; @@ -1242,7 +1252,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) } else if ( icon == 14 ) { - m_engine->SetTexture("textures/interface/button1.png"); + m_engine->SetUITexture("textures/interface/button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 160.0f/256.0f; // dirty opaque red uv1.y = 128.0f/256.0f; @@ -1256,6 +1266,8 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) corner.y = 6.0f/480.0f; DrawIcon(pos, dim, uv1, uv2, corner, 5.0f/256.0f); } + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } // Draws hatching. @@ -1266,9 +1278,10 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim) float dp, max, ndim; bool bStop; - dp = 0.5f/256.0f; + auto device = m_engine->GetDevice(); - m_engine->SetTexture("textures/interface/button2.png"); + dp = 0.5f/256.0f; + m_engine->SetUITexture("textures/interface/button2.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); uv1.x = 64.0f/256.0f; // hatching uv1.y = 208.0f/256.0f; @@ -1299,6 +1312,8 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim) ppos.x += ddim.x; } while ( !bStop ); + + device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE); } void CWindow::SetFocus(CControl* focusControl)