Partial refactor of UI rendering to improve performance and fix transparency issues

Disabled rendering via CDevice
dev
Tomasz Kapuściński 2022-02-03 18:40:58 +01:00
parent 0908e10ff6
commit 1a190b7f6f
32 changed files with 584 additions and 804 deletions

View File

@ -465,12 +465,6 @@ public:
//! Enables/disables the given texture stage //! Enables/disables the given texture stage
virtual void SetTextureEnabled(int index, bool enabled) = 0; virtual void SetTextureEnabled(int index, bool enabled) = 0;
//! Sets the params for texture stage with given index
virtual void SetTextureStageParams(int index, const TextureStageParams &params) = 0;
//! Sets only the texture wrap modes (for faster than thru stage params)
virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0;
//! Renders primitive composed of vertices with single texture //! Renders primitive composed of vertices with single texture
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0; Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
@ -508,12 +502,6 @@ public:
//! Sets the clear color //! Sets the clear color
virtual void SetClearColor(const Color &color) = 0; virtual void SetClearColor(const Color &color) = 0;
//! Sets the current cull mode
virtual void SetCullMode(CullMode mode) = 0;
//! Sets the current fill mode
virtual void SetFillMode(FillMode mode) = 0;
//! Copies content of framebuffer to texture //! Copies content of framebuffer to texture
virtual void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) = 0; virtual void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) = 0;

View File

@ -36,7 +36,7 @@ class CVertexBuffer;
enum class PrimitiveType : unsigned char; enum class PrimitiveType : unsigned char;
struct Texture; struct Texture;
enum class TransparencyMode enum class TransparencyMode : unsigned char
{ {
NONE, NONE,
ALPHA, ALPHA,
@ -59,9 +59,6 @@ class CRenderer
{ {
public: public:
virtual ~CRenderer() { } virtual ~CRenderer() { }
//! Flush buffered content
virtual void Flush() {}
}; };
/** /**
@ -79,9 +76,14 @@ public:
virtual void SetTexture(const Texture& texture) = 0; virtual void SetTexture(const Texture& texture) = 0;
//! Sets color //! Sets color
virtual void SetColor(const glm::vec4& color) = 0; virtual void SetColor(const glm::vec4& color) = 0;
//! Sets transparency mode
virtual void SetTransparency(TransparencyMode mode) = 0;
//! Draws primitive //! Draws primitive
virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) = 0; virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) = 0;
virtual Vertex2D* BeginPrimitive(PrimitiveType type, int count) = 0;
virtual bool EndPrimitive() = 0;
}; };
/** /**

View File

@ -135,7 +135,7 @@ CCamera::CCamera()
m_overType = CAM_OVER_EFFECT_NULL; m_overType = CAM_OVER_EFFECT_NULL;
m_overForce = 0.0f; m_overForce = 0.0f;
m_overTime = 0.0f; m_overTime = 0.0f;
m_overMode = 0; m_overMode = TransparencyMode::NONE;
m_overFadeIn = 0.0f; m_overFadeIn = 0.0f;
m_overFadeOut = 0.0f; m_overFadeOut = 0.0f;
@ -611,7 +611,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force)
if (m_overType == CAM_OVER_EFFECT_BLOOD) if (m_overType == CAM_OVER_EFFECT_BLOOD)
{ {
m_overColor = Color(0.8f, 0.1f, 0.1f); // red m_overColor = Color(0.8f, 0.1f, 0.1f); // red
m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overMode = TransparencyMode::BLACK;
m_overFadeIn = 0.4f; m_overFadeIn = 0.4f;
m_overFadeOut = 0.8f; m_overFadeOut = 0.8f;
@ -621,7 +621,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force)
if ( m_overType == CAM_OVER_EFFECT_FADEIN_WHITE ) if ( m_overType == CAM_OVER_EFFECT_FADEIN_WHITE )
{ {
m_overColor = Color(1.0f, 1.0f, 1.0f); // white m_overColor = Color(1.0f, 1.0f, 1.0f); // white
m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overMode = TransparencyMode::BLACK;
m_overFadeIn = 0.0f; m_overFadeIn = 0.0f;
m_overFadeOut = 20.0f; m_overFadeOut = 20.0f;
@ -631,7 +631,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force)
if ( m_overType == CAM_OVER_EFFECT_FADEOUT_WHITE ) if ( m_overType == CAM_OVER_EFFECT_FADEOUT_WHITE )
{ {
m_overColor = Color(1.0f, 1.0f, 1.0f); // white m_overColor = Color(1.0f, 1.0f, 1.0f); // white
m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overMode = TransparencyMode::BLACK;
m_overFadeIn = 6.0f; m_overFadeIn = 6.0f;
m_overFadeOut = 100000.0f; m_overFadeOut = 100000.0f;
@ -641,7 +641,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force)
if ( m_overType == CAM_OVER_EFFECT_FADEOUT_BLACK ) if ( m_overType == CAM_OVER_EFFECT_FADEOUT_BLACK )
{ {
m_overColor = m_engine->GetFogColor(1); // fog color underwater m_overColor = m_engine->GetFogColor(1); // fog color underwater
m_overMode = ENG_RSTATE_TTEXTURE_WHITE; m_overMode = TransparencyMode::WHITE;
m_overFadeIn = 4.0f; m_overFadeIn = 4.0f;
m_overFadeOut = 100000.0f; m_overFadeOut = 100000.0f;
@ -651,7 +651,7 @@ void CCamera::StartOver(CameraOverEffect effect, glm::vec3 pos, float force)
if ( m_overType == CAM_OVER_EFFECT_LIGHTNING ) if ( m_overType == CAM_OVER_EFFECT_LIGHTNING )
{ {
m_overColor = Color(0.9f, 1.0f, 1.0f); // white-cyan m_overColor = Color(0.9f, 1.0f, 1.0f); // white-cyan
m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overMode = TransparencyMode::BLACK;
m_overFadeIn = 0.0f; m_overFadeIn = 0.0f;
m_overFadeOut = 1.0f; m_overFadeOut = 1.0f;
@ -692,7 +692,7 @@ void CCamera::OverFrame(const Event &event)
intensity *= m_overForce; intensity *= m_overForce;
Color color; Color color;
if (m_overMode == ENG_RSTATE_TCOLOR_WHITE) if (m_overMode == TransparencyMode::WHITE)
{ {
color.r = 1.0f - (1.0f - m_overColor.r) * intensity; color.r = 1.0f - (1.0f - m_overColor.r) * intensity;
color.g = 1.0f - (1.0f - m_overColor.g) * intensity; color.g = 1.0f - (1.0f - m_overColor.g) * intensity;
@ -717,7 +717,7 @@ void CCamera::OverFrame(const Event &event)
intensity *= m_overForce; intensity *= m_overForce;
Color color; Color color;
if (m_overMode == ENG_RSTATE_TCOLOR_WHITE) if (m_overMode == TransparencyMode::WHITE)
{ {
color.r = 1.0f-(1.0f-m_overColor.r) * intensity; color.r = 1.0f-(1.0f-m_overColor.r) * intensity;
color.g = 1.0f-(1.0f-m_overColor.g) * intensity; color.g = 1.0f-(1.0f-m_overColor.g) * intensity;

View File

@ -389,7 +389,7 @@ protected:
float m_overTime; float m_overTime;
Color m_overColorBase; Color m_overColorBase;
Color m_overColor; Color m_overColor;
int m_overMode; TransparencyMode m_overMode;
float m_overFadeIn; float m_overFadeIn;
float m_overFadeOut; float m_overFadeOut;

View File

@ -83,17 +83,17 @@ struct EngineMouse
//! Shadow texture part //! Shadow texture part
int iconShadow; int iconShadow;
//! Mode to render 1st image in //! Mode to render 1st image in
EngineRenderState mode1; TransparencyMode mode1;
//! Mode to render 2nd image in //! Mode to render 2nd image in
EngineRenderState mode2; TransparencyMode mode2;
//! Hot point //! Hot point
glm::ivec2 hotPoint; glm::ivec2 hotPoint;
EngineMouse(int icon1 = -1, EngineMouse(int icon1 = -1,
int icon2 = -1, int icon2 = -1,
int iconShadow = -1, int iconShadow = -1,
EngineRenderState mode1 = ENG_RSTATE_NORMAL, TransparencyMode mode1 = TransparencyMode::NONE,
EngineRenderState mode2 = ENG_RSTATE_NORMAL, TransparencyMode mode2 = TransparencyMode::NONE,
glm::ivec2 hotPoint = { 0, 0 }) glm::ivec2 hotPoint = { 0, 0 })
: icon1(icon1) : icon1(icon1)
, icon2(icon2) , icon2(icon2)
@ -106,22 +106,22 @@ struct EngineMouse
constexpr glm::ivec2 MOUSE_SIZE(32, 32); constexpr glm::ivec2 MOUSE_SIZE(32, 32);
const std::map<EngineMouseType, EngineMouse> MOUSE_TYPES = { const std::map<EngineMouseType, EngineMouse> MOUSE_TYPES = {
{{ENG_MOUSE_NORM}, {EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, glm::ivec2( 1, 1))}}, {{ENG_MOUSE_NORM}, {EngineMouse( 0, 1, 32, TransparencyMode::WHITE, TransparencyMode::BLACK, glm::ivec2( 1, 1))}},
{{ENG_MOUSE_WAIT}, {EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, glm::ivec2( 8, 12))}}, {{ENG_MOUSE_WAIT}, {EngineMouse( 2, 3, 33, TransparencyMode::WHITE, TransparencyMode::BLACK, glm::ivec2( 8, 12))}},
{{ENG_MOUSE_HAND}, {EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, glm::ivec2( 7, 2))}}, {{ENG_MOUSE_HAND}, {EngineMouse( 4, 5, 34, TransparencyMode::WHITE, TransparencyMode::BLACK, glm::ivec2( 7, 2))}},
{{ENG_MOUSE_NO}, {EngineMouse( 6, 7, 35, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, glm::ivec2(10, 10))}}, {{ENG_MOUSE_NO}, {EngineMouse( 6, 7, 35, TransparencyMode::WHITE, TransparencyMode::BLACK, glm::ivec2(10, 10))}},
{{ENG_MOUSE_EDIT}, {EngineMouse( 8, 9, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 6, 10))}}, {{ENG_MOUSE_EDIT}, {EngineMouse( 8, 9, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 6, 10))}},
{{ENG_MOUSE_CROSS}, {EngineMouse(10, 11, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2(10, 10))}}, {{ENG_MOUSE_CROSS}, {EngineMouse(10, 11, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2(10, 10))}},
{{ENG_MOUSE_MOVEV}, {EngineMouse(12, 13, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 5, 11))}}, {{ENG_MOUSE_MOVEV}, {EngineMouse(12, 13, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 5, 11))}},
{{ENG_MOUSE_MOVEH}, {EngineMouse(14, 15, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2(11, 5))}}, {{ENG_MOUSE_MOVEH}, {EngineMouse(14, 15, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2(11, 5))}},
{{ENG_MOUSE_MOVED}, {EngineMouse(16, 17, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 9, 9))}}, {{ENG_MOUSE_MOVED}, {EngineMouse(16, 17, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 9, 9))}},
{{ENG_MOUSE_MOVEI}, {EngineMouse(18, 19, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 9, 9))}}, {{ENG_MOUSE_MOVEI}, {EngineMouse(18, 19, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 9, 9))}},
{{ENG_MOUSE_MOVE}, {EngineMouse(20, 21, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2(11, 11))}}, {{ENG_MOUSE_MOVE}, {EngineMouse(20, 21, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2(11, 11))}},
{{ENG_MOUSE_TARGET}, {EngineMouse(22, 23, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2(15, 15))}}, {{ENG_MOUSE_TARGET}, {EngineMouse(22, 23, -1, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2(15, 15))}},
{{ENG_MOUSE_SCROLLL}, {EngineMouse(24, 25, 43, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 2, 9))}}, {{ENG_MOUSE_SCROLLL}, {EngineMouse(24, 25, 43, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 2, 9))}},
{{ENG_MOUSE_SCROLLR}, {EngineMouse(26, 27, 44, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2(17, 9))}}, {{ENG_MOUSE_SCROLLR}, {EngineMouse(26, 27, 44, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2(17, 9))}},
{{ENG_MOUSE_SCROLLU}, {EngineMouse(28, 29, 45, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 9, 2))}}, {{ENG_MOUSE_SCROLLU}, {EngineMouse(28, 29, 45, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 9, 2))}},
{{ENG_MOUSE_SCROLLD}, {EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, glm::ivec2( 9, 17))}}, {{ENG_MOUSE_SCROLLD}, {EngineMouse(30, 31, 46, TransparencyMode::BLACK, TransparencyMode::WHITE, glm::ivec2( 9, 17))}},
}; };
CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
@ -181,7 +181,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
m_backgroundScale = false; m_backgroundScale = false;
m_overFront = true; m_overFront = true;
m_overColor = Color(); m_overColor = Color();
m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overMode = TransparencyMode::BLACK;
m_highlight = false; m_highlight = false;
std::fill_n(m_highlightRank, 100, -1); std::fill_n(m_highlightRank, 100, -1);
m_highlightTime = 0.0f; m_highlightTime = 0.0f;
@ -346,7 +346,6 @@ bool CEngine::Create()
} }
m_device->SetClearColor(Color(0.0f, 0.0f, 0.0f, 0.0f)); m_device->SetClearColor(Color(0.0f, 0.0f, 0.0f, 0.0f));
m_device->SetFillMode(FillMode::POLY);
SetFocus(m_focus); SetFocus(m_focus);
@ -1918,238 +1917,6 @@ bool CEngine::TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D)
void CEngine::SetState(int state, const Color& color)
{
if (state == m_lastState && color == m_lastColor)
return;
m_device->GetUIRenderer()->Flush();
m_device->GetUIRenderer()->SetColor({ color.r, color.g, color.b, color.a });
m_lastState = state;
m_lastColor = color;
if (state & ENG_RSTATE_TTEXTURE_BLACK) // transparent black texture?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
params.factor = color;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
else if (state & ENG_RSTATE_TTEXTURE_WHITE) // transparent white texture?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_ADD;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
params.factor = color.Inverse();
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
else if (state & ENG_RSTATE_TCOLOR_BLACK) // transparent black color?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR);
m_device->SetTextureEnabled(0, false);
}
else if (state & ENG_RSTATE_TCOLOR_WHITE) // transparent white color?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO);
m_device->SetTextureEnabled(0, false);
}
else if (state & ENG_RSTATE_TDIFFUSE) // diffuse color as transparent?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_DST_ALPHA);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_REPLACE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
else if (state & ENG_RSTATE_OPAQUE_TEXTURE) // opaque texture ?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, false);
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, TextureStageParams()); // default operation
}
else if (state & ENG_RSTATE_OPAQUE_COLOR) // opaque color ?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, false);
m_device->SetTextureEnabled(0, false);
}
else if (state & ENG_RSTATE_TEXT) // font rendering?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA);
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, TextureStageParams()); // default operation
}
else if (state & ENG_RSTATE_ALPHA) // image with alpha channel?
{
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA);
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, true);
m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.5f);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
params.alphaOperation = TEX_MIX_OPER_REPLACE;
params.alphaArg1 = TEX_MIX_ARG_TEXTURE;
params.factor = color;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
else if (state & ENG_RSTATE_TTEXTURE_ALPHA) // texture with alpha channel?
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, true);
m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.0f);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_INV_SRC_ALPHA);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_SRC_COLOR;
params.alphaOperation = TEX_MIX_OPER_MODULATE;
params.alphaArg1 = TEX_MIX_ARG_TEXTURE;
params.alphaArg2 = TEX_MIX_ARG_FACTOR;
params.factor = color;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
else if (state & ENG_RSTATE_TCOLOR_ALPHA)
{
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, true);
m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_INV_SRC_ALPHA);
m_device->SetTextureEnabled(0, false);
}
else // normal ?
{
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_BLENDING, false);
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true);
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
}
bool second = m_dirty;
// TODO: I'm pretty sure this is reversed and should be m_dirty instead of !m_dirty ~krzys_h
if ( !m_dirty && (state & ENG_RSTATE_SECOND) == 0 ) second = false;
if ((state & ENG_RSTATE_DUAL_BLACK) && second)
{
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(1, true);
m_device->SetTextureStageParams(1, params);
}
else if ((state & ENG_RSTATE_DUAL_WHITE) && second)
{
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_ADD;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR;
params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(1, true);
m_device->SetTextureStageParams(1, params);
}
else
{
m_device->SetTextureEnabled(1, false);
}
if (state & ENG_RSTATE_WRAP)
{
m_device->SetTextureStageWrap(0, TEX_WRAP_REPEAT, TEX_WRAP_REPEAT);
m_device->SetTextureStageWrap(1, TEX_WRAP_REPEAT, TEX_WRAP_REPEAT);
}
else if (state & ENG_RSTATE_CLAMP)
{
m_device->SetTextureStageWrap(0, TEX_WRAP_CLAMP, TEX_WRAP_CLAMP);
m_device->SetTextureStageWrap(1, TEX_WRAP_CLAMP, TEX_WRAP_CLAMP);
}
if (state & ENG_RSTATE_2FACE)
{
m_device->SetRenderState(RENDER_STATE_CULLING, false);
}
else
{
m_device->SetRenderState(RENDER_STATE_CULLING, true);
m_device->SetCullMode(CULL_CCW);
}
}
void CEngine::SetMaterial(const Material& mat) void CEngine::SetMaterial(const Material& mat)
{ {
m_lastMaterial = mat; m_lastMaterial = mat;
@ -2807,7 +2574,7 @@ void CEngine::SetOverFront(bool front)
m_overFront = front; m_overFront = front;
} }
void CEngine::SetOverColor(const Color& color, int mode) void CEngine::SetOverColor(const Color& color, TransparencyMode mode)
{ {
m_overColor = color; m_overColor = color;
m_overMode = mode; m_overMode = mode;
@ -3233,8 +3000,6 @@ void CEngine::Draw3DScene()
//m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); //m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
SetState(0);
Gfx::ShadowParam shadowParams[4]; Gfx::ShadowParam shadowParams[4];
for (int i = 0; i < m_shadowRegions; i++) for (int i = 0; i < m_shadowRegions; i++)
{ {
@ -3522,7 +3287,7 @@ void CEngine::Draw3DScene()
glm::mat4 worldMatrix = glm::mat4(1.0f); glm::mat4 worldMatrix = glm::mat4(1.0f);
m_device->SetTransform(TRANSFORM_WORLD, worldMatrix); m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
SetState(ENG_RSTATE_OPAQUE_COLOR); //SetState(ENG_RSTATE_OPAQUE_COLOR);
for (const auto& line : m_displayGoto) for (const auto& line : m_displayGoto)
{ {
@ -3661,14 +3426,7 @@ void CEngine::Capture3DScene()
void CEngine::DrawCaptured3DScene() void CEngine::DrawCaptured3DScene()
{ {
glm::mat4 identity = glm::mat4(1.0f); m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
m_device->SetTransform(TRANSFORM_PROJECTION, identity);
m_device->SetTransform(TRANSFORM_VIEW, identity);
m_device->SetTransform(TRANSFORM_WORLD, identity);
m_device->SetRenderState(RENDER_STATE_BLENDING, false);
m_device->SetRenderState(RENDER_STATE_CULLING, false);
Vertex2D vertices[4]; Vertex2D vertices[4];
@ -3677,11 +3435,10 @@ void CEngine::DrawCaptured3DScene()
vertices[2] = { { 0.0f, 1.0f }, { 0.0f, 1.0f } }; vertices[2] = { { 0.0f, 1.0f }, { 0.0f, 1.0f } };
vertices[3] = { { 1.0f, 1.0f }, { 1.0f, 1.0f } }; vertices[3] = { { 1.0f, 1.0f }, { 1.0f, 1.0f } };
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetTexture(m_capturedWorldTexture); renderer->SetTexture(m_capturedWorldTexture);
renderer->SetTransparency(TransparencyMode::NONE);
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertices); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertices);
} }
@ -3805,7 +3562,7 @@ void CEngine::RenderPendingDebugDraws()
m_device->SetTransform(TRANSFORM_WORLD, glm::mat4(1.0f)); m_device->SetTransform(TRANSFORM_WORLD, glm::mat4(1.0f));
SetState(ENG_RSTATE_OPAQUE_COLOR); //SetState(ENG_RSTATE_OPAQUE_COLOR);
m_device->DrawPrimitives(PrimitiveType::LINE_STRIP, m_device->DrawPrimitives(PrimitiveType::LINE_STRIP,
m_pendingDebugDraws.vertices.data(), m_pendingDebugDraws.vertices.data(),
@ -3975,10 +3732,6 @@ void CEngine::RenderShadowMap()
renderer->End(); renderer->End();
m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false);
m_device->SetRenderState(RENDER_STATE_CULLING, false);
m_device->SetCullMode(CULL_CW);
// restore default state // restore default state
m_device->SetViewport(0, 0, m_size.x, m_size.y); m_device->SetViewport(0, 0, m_size.x, m_size.y);
@ -4060,7 +3813,6 @@ void CEngine::DrawInterface()
// Force new state to disable lighting // Force new state to disable lighting
m_interfaceMode = true; m_interfaceMode = true;
m_lastState = -1; m_lastState = -1;
SetState(Gfx::ENG_RSTATE_NORMAL);
// Draw the entire interface // Draw the entire interface
Ui::CInterface* interface = CRobotMain::GetInstancePointer()->GetInterface(); Ui::CInterface* interface = CRobotMain::GetInstancePointer()->GetInterface();
@ -4071,7 +3823,6 @@ void CEngine::DrawInterface()
m_interfaceMode = false; m_interfaceMode = false;
m_lastState = -1; m_lastState = -1;
SetState(Gfx::ENG_RSTATE_NORMAL);
if (!m_screenshotMode && m_renderInterface) if (!m_screenshotMode && m_renderInterface)
{ {
@ -4688,7 +4439,7 @@ void CEngine::DrawShadowSpots()
if (lastIntensity != intensity) // intensity changed? if (lastIntensity != intensity) // intensity changed?
{ {
lastIntensity = intensity; lastIntensity = intensity;
SetState(ENG_RSTATE_TTEXTURE_WHITE, Color(intensity, intensity, intensity, intensity)); //SetState(ENG_RSTATE_TTEXTURE_WHITE, Color(intensity, intensity, intensity, intensity));
} }
m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4);
@ -4733,8 +4484,6 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
SetState(ENG_RSTATE_OPAQUE_COLOR);
auto renderer = m_device->GetObjectRenderer(); auto renderer = m_device->GetObjectRenderer();
renderer->Begin(); renderer->Begin();
renderer->SetProjectionMatrix(m_matProjInterface); renderer->SetProjectionMatrix(m_matProjInterface);
@ -4826,8 +4575,6 @@ void CEngine::DrawBackgroundImage()
v2 -= margin_v; v2 -= margin_v;
} }
SetUITexture(m_backgroundTex);
Vertex2D vertices[4] = Vertex2D vertices[4] =
{ {
{ { p1.x, p1.y }, { u1, v2 } }, { { p1.x, p1.y }, { u1, v2 } },
@ -4837,6 +4584,7 @@ void CEngine::DrawBackgroundImage()
}; };
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetTexture(m_backgroundTex);
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertices); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertices);
AddStatisticTriangle(2); AddStatisticTriangle(2);
} }
@ -4887,7 +4635,7 @@ void CEngine::DrawForegroundImage()
}; };
SetTexture(m_foregroundTex); SetTexture(m_foregroundTex);
SetState(ENG_RSTATE_CLAMP | ENG_RSTATE_TTEXTURE_BLACK); //SetState(ENG_RSTATE_TTEXTURE_BLACK);
m_device->Restore(); m_device->Restore();
@ -4901,8 +4649,8 @@ void CEngine::DrawForegroundImage()
void CEngine::DrawOverColor() void CEngine::DrawOverColor()
{ {
if ((m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) || if ((m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == TransparencyMode::BLACK) ||
(m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE)) (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == TransparencyMode::WHITE))
return; return;
glm::vec2 p1(0.0f, 0.0f); glm::vec2 p1(0.0f, 0.0f);
@ -4917,33 +4665,19 @@ void CEngine::DrawOverColor()
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
m_device->Restore(); auto renderer = m_device->GetUIRenderer();
renderer->SetTexture(Texture{});
renderer->SetTransparency(m_overMode);
SetState(m_overMode); Vertex2D vertex[4] =
auto renderer = m_device->GetObjectRenderer();
renderer->Begin();
renderer->SetProjectionMatrix(m_matProjInterface);
renderer->SetViewMatrix(m_matViewInterface);
renderer->SetModelMatrix(m_matWorldInterface);
renderer->SetLighting(false);
if (m_overMode == ENG_RSTATE_TCOLOR_BLACK)
renderer->SetTransparency(TransparencyMode::BLACK);
else if (m_overMode == ENG_RSTATE_TCOLOR_WHITE)
renderer->SetTransparency(TransparencyMode::WHITE);
Vertex3D vertex[4] =
{ {
{ glm::vec3(p1.x, p1.y, 0.0f), colors[1] }, { { p1.x, p1.y }, {}, colors[1] },
{ glm::vec3(p1.x, p2.y, 0.0f), colors[0] }, { { p1.x, p2.y }, {}, colors[0] },
{ glm::vec3(p2.x, p1.y, 0.0f), colors[1] }, { { p2.x, p1.y }, {}, colors[1] },
{ glm::vec3(p2.x, p2.y, 0.0f), colors[0] } { { p2.x, p2.y }, {}, colors[0] }
}; };
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex);
renderer->End();
AddStatisticTriangle(2); AddStatisticTriangle(2);
@ -4999,7 +4733,7 @@ void CEngine::DrawHighlight()
if (nbOut > 2) if (nbOut > 2)
return; return;
SetState(ENG_RSTATE_OPAQUE_COLOR); //SetState(ENG_RSTATE_OPAQUE_COLOR);
float d = 0.5f + sinf(m_highlightTime * 6.0f) * 0.5f; float d = 0.5f + sinf(m_highlightTime * 6.0f) * 0.5f;
d *= (p2.x - p1.x) * 0.1f; d *= (p2.x - p1.x) * 0.1f;
@ -5049,10 +4783,6 @@ void CEngine::DrawMouse()
SetWindowCoordinates(); SetWindowCoordinates();
m_device->SetTexture(0, m_miceTexture);
SetUITexture(m_miceTexture);
glm::vec2 mousePos = CInput::GetInstancePointer()->GetMousePos(); glm::vec2 mousePos = CInput::GetInstancePointer()->GetMousePos();
glm::ivec2 pos(mousePos.x * m_size.x, m_size.y - mousePos.y * m_size.y); glm::ivec2 pos(mousePos.x * m_size.x, m_size.y - mousePos.y * m_size.y);
pos.x -= MOUSE_TYPES.at(m_mouseType).hotPoint.x; pos.x -= MOUSE_TYPES.at(m_mouseType).hotPoint.x;
@ -5060,19 +4790,17 @@ void CEngine::DrawMouse()
glm::ivec2 shadowPos = { pos.x + 4, pos.y - 3 }; glm::ivec2 shadowPos = { pos.x + 4, pos.y - 3 };
SetState(ENG_RSTATE_TCOLOR_WHITE); auto renderer = m_device->GetUIRenderer();
DrawMouseSprite(shadowPos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).iconShadow); renderer->SetTexture(m_miceTexture);
SetState(MOUSE_TYPES.at(m_mouseType).mode1); DrawMouseSprite(shadowPos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).iconShadow, TransparencyMode::WHITE);
DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon1); DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon1, MOUSE_TYPES.at(m_mouseType).mode1);
DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon2, MOUSE_TYPES.at(m_mouseType).mode2);
SetState(MOUSE_TYPES.at(m_mouseType).mode2);
DrawMouseSprite(pos, MOUSE_SIZE, MOUSE_TYPES.at(m_mouseType).icon2);
SetInterfaceCoordinates(); SetInterfaceCoordinates();
} }
void CEngine::DrawMouseSprite(const glm::ivec2& pos, const glm::ivec2& size, int icon) void CEngine::DrawMouseSprite(const glm::ivec2& pos, const glm::ivec2& size, int icon, TransparencyMode mode)
{ {
if (icon == -1) if (icon == -1)
return; return;
@ -5100,6 +4828,7 @@ void CEngine::DrawMouseSprite(const glm::ivec2& pos, const glm::ivec2& size, int
}; };
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetTransparency(mode);
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex);
AddStatisticTriangle(2); AddStatisticTriangle(2);
} }
@ -5115,8 +4844,9 @@ void CEngine::DrawStats()
glm::vec2 pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height); glm::vec2 pos(0.05f * m_size.x/m_size.y, 0.05f + TOTAL_LINES * height);
SetState(ENG_RSTATE_TCOLOR_ALPHA); //SetState(ENG_RSTATE_TCOLOR_ALPHA);
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetTransparency(TransparencyMode::ALPHA);
renderer->SetTexture(Texture{}); renderer->SetTexture(Texture{});
glm::u8vec4 black = { 0, 0, 0, 192 }; glm::u8vec4 black = { 0, 0, 0, 192 };
@ -5133,7 +4863,7 @@ void CEngine::DrawStats()
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, vertex);
SetState(ENG_RSTATE_TEXT); renderer->SetTransparency(TransparencyMode::ALPHA);
auto drawStatsLine = [&](const std::string& name, const std::string& value, const std::string& value2) auto drawStatsLine = [&](const std::string& name, const std::string& value, const std::string& value2)
{ {
@ -5210,7 +4940,7 @@ void CEngine::DrawStats()
void CEngine::DrawTimer() void CEngine::DrawTimer()
{ {
SetState(ENG_RSTATE_TEXT); //SetState(ENG_RSTATE_TEXT);
glm::vec2 pos(0.98f, 0.98f-m_text->GetAscent(FONT_COMMON, 15.0f)); glm::vec2 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_text->DrawText(m_timerText, FONT_COMMON, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
@ -5529,18 +5259,4 @@ void CEngine::SetWindowCoordinates()
renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f); renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f);
} }
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 } // namespace Gfx

View File

@ -30,6 +30,7 @@
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "graphics/core/material.h" #include "graphics/core/material.h"
#include "graphics/core/texture.h" #include "graphics/core/texture.h"
#include "graphics/core/renderers.h"
#include "graphics/core/vertex.h" #include "graphics/core/vertex.h"
#include "math/sphere.h" #include "math/sphere.h"
@ -55,7 +56,6 @@ struct Event;
namespace Gfx namespace Gfx
{ {
class CDevice; class CDevice;
class COldModelManager; class COldModelManager;
class CLightManager; class CLightManager;
@ -90,10 +90,6 @@ enum EngineRenderState
ENG_RSTATE_TTEXTURE_WHITE = (1<<1), ENG_RSTATE_TTEXTURE_WHITE = (1<<1),
//! The transparent diffuse color //! The transparent diffuse color
ENG_RSTATE_TDIFFUSE = (1<<2), ENG_RSTATE_TDIFFUSE = (1<<2),
//! Texture wrap
ENG_RSTATE_WRAP = (1<<3),
//! Texture borders with solid color
ENG_RSTATE_CLAMP = (1<<4),
//! Light texture (ambient max) //! Light texture (ambient max)
ENG_RSTATE_LIGHT = (1<<5), ENG_RSTATE_LIGHT = (1<<5),
//! Double black texturing //! Double black texturing
@ -837,7 +833,7 @@ public:
/* *************** Mode setting *************** */ /* *************** Mode setting *************** */
//! Sets the current rendering state //! Sets the current rendering state
void SetState(int state, const Color& color = Color(1.0f, 1.0f, 1.0f, 1.0f)); //void SetState(int state, const Color& color = Color(1.0f, 1.0f, 1.0f, 1.0f));
//! Sets the current material //! Sets the current material
void SetMaterial(const Material& mat); void SetMaterial(const Material& mat);
@ -997,7 +993,7 @@ public:
//! Specifies whether to draw the foreground //! Specifies whether to draw the foreground
void SetOverFront(bool front); void SetOverFront(bool front);
//! Sets the foreground overlay color //! Sets the foreground overlay color
void SetOverColor(const Color& color = Color(), int mode = ENG_RSTATE_TCOLOR_BLACK); void SetOverColor(const Color& color = Color(), TransparencyMode mode = TransparencyMode::BLACK);
//@{ //@{
//! Management of the particle density //! Management of the particle density
@ -1171,9 +1167,6 @@ public:
void EnablePauseBlur(); void EnablePauseBlur();
void DisablePauseBlur(); void DisablePauseBlur();
void SetUITexture(const std::string& name);
void SetUITexture(const Texture& texture);
//! Reloads all textures //! Reloads all textures
/** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/ /** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
@ -1218,7 +1211,7 @@ protected:
//! Draws the mouse cursor //! Draws the mouse cursor
void DrawMouse(); void DrawMouse();
//! Draw part of mouse cursor sprite //! Draw part of mouse cursor sprite
void DrawMouseSprite(const glm::ivec2& pos, const glm::ivec2& size, int icon); void DrawMouseSprite(const glm::ivec2& pos, const glm::ivec2& size, int icon, TransparencyMode mode);
//! Draw statistic texts //! Draw statistic texts
void DrawStats(); void DrawStats();
//! Draw mission timer //! Draw mission timer
@ -1380,7 +1373,7 @@ protected:
Color m_backgroundCloudDown; Color m_backgroundCloudDown;
bool m_overFront; bool m_overFront;
Color m_overColor; Color m_overColor;
int m_overMode; TransparencyMode m_overMode;
std::string m_foregroundName; std::string m_foregroundName;
Texture m_foregroundTex; Texture m_foregroundTex;
bool m_drawWorld; bool m_drawWorld;

View File

@ -226,7 +226,7 @@ void CLightning::Draw()
device->SetTransform(TRANSFORM_WORLD, mat); device->SetTransform(TRANSFORM_WORLD, mat);
m_engine->SetTexture("textures/effect00.png"); m_engine->SetTexture("textures/effect00.png");
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK); //m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK);
glm::vec2 texInf; glm::vec2 texInf;
texInf.x = 64.5f/256.0f; texInf.x = 64.5f/256.0f;

View File

@ -635,7 +635,7 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank)
buffer.type = EngineTriangleType::SURFACE; buffer.type = EngineTriangleType::SURFACE;
buffer.state = ENG_RSTATE_WRAP; buffer.state = ENG_RSTATE_NORMAL;
buffer.state |= ENG_RSTATE_SECOND; buffer.state |= ENG_RSTATE_SECOND;
if (step == 1) if (step == 1)

View File

@ -115,13 +115,13 @@ public:
/// Add a quad to be rendered. /// Add a quad to be rendered.
/// This may trigger a call to Flush() if necessary. /// This may trigger a call to Flush() if necessary.
void Add(Vertex2D vertices[4], unsigned int texID, EngineRenderState renderState, Color color) void Add(Vertex2D vertices[4], unsigned int texID, TransparencyMode transparency, Color color)
{ {
if (texID != m_texID || renderState != m_renderState || color != m_color) if (texID != m_texID || transparency != m_transparency || color != m_color)
{ {
Flush(); Flush();
m_texID = texID; m_texID = texID;
m_renderState = renderState; m_transparency = transparency;
m_color = color; m_color = color;
} }
m_quads.emplace_back(Quad{{vertices[0], vertices[1], vertices[2], vertices[3]}}); m_quads.emplace_back(Quad{{vertices[0], vertices[1], vertices[2], vertices[3]}});
@ -132,9 +132,9 @@ public:
{ {
if (m_quads.empty()) return; if (m_quads.empty()) return;
m_engine.SetState(m_renderState); auto renderer = m_engine.GetDevice()->GetUIRenderer();
m_engine.GetDevice()->SetTexture(0, m_texID); renderer->SetTexture(Texture{ m_texID });
m_engine.SetUITexture(Texture{ m_texID }); renderer->SetTransparency(m_transparency);
assert(m_firsts.size() == m_counts.size()); assert(m_firsts.size() == m_counts.size());
if (m_firsts.size() < m_quads.size()) if (m_firsts.size() < m_quads.size())
@ -151,15 +151,11 @@ public:
} }
} }
auto renderer = m_engine.GetDevice()->GetUIRenderer();
for (const auto& quad : m_quads) for (const auto& quad : m_quads)
{ {
renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, quad.vertices); renderer->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, 4, quad.vertices);
} }
m_engine.GetDevice()->GetUIRenderer()->Flush();
//const Vertex* vertices = m_quads.front().vertices; //const Vertex* vertices = m_quads.front().vertices;
//m_engine.GetDevice()->DrawPrimitives(PrimitiveType::TRIANGLE_STRIP, vertices, m_firsts.data(), //m_engine.GetDevice()->DrawPrimitives(PrimitiveType::TRIANGLE_STRIP, vertices, m_firsts.data(),
// m_counts.data(), static_cast<int>(m_quads.size()), m_color); // m_counts.data(), static_cast<int>(m_quads.size()), m_color);
@ -176,7 +172,7 @@ private:
Color m_color; Color m_color;
unsigned int m_texID{}; unsigned int m_texID{};
EngineRenderState m_renderState{}; TransparencyMode m_transparency = TransparencyMode::NONE;
}; };
@ -1068,7 +1064,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, glm::iv
{ { p2.x, p1.y }, { uv2.x, uv1.y }, col } { { p2.x, p1.y }, { uv2.x, uv1.y }, col }
}; };
m_quadBatch->Add(quad, texID, ENG_RSTATE_TTEXTURE_WHITE, color); m_quadBatch->Add(quad, texID, TransparencyMode::WHITE, color);
pos.x += width; pos.x += width;
} }
@ -1107,7 +1103,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, glm::iv
{ { p2.x, p1.y }, { texCoord2.x, texCoord1.y }, col } { { p2.x, p1.y }, { texCoord2.x, texCoord1.y }, col }
}; };
m_quadBatch->Add(quad, tex.id, ENG_RSTATE_TEXT, color); m_quadBatch->Add(quad, tex.id, TransparencyMode::ALPHA, color);
pos.x += tex.charSize.x * width; pos.x += tex.charSize.x * width;
} }

View File

@ -373,8 +373,6 @@ void CGL33Device::BeginScene()
void CGL33Device::EndScene() void CGL33Device::EndScene()
{ {
m_uiRenderer->Flush();
#ifdef DEV_BUILD #ifdef DEV_BUILD
CheckGLErrors(); CheckGLErrors();
#endif #endif
@ -413,13 +411,7 @@ CShadowRenderer* CGL33Device::GetShadowRenderer()
void CGL33Device::Restore() void CGL33Device::Restore()
{ {
m_uiRenderer->Flush();
glUseProgram(m_normalProgram); glUseProgram(m_normalProgram);
//UpdateTextureState(0);
//UpdateTextureState(1);
//UpdateTextureState(2);
} }
void CGL33Device::SetTransform(TransformType type, const glm::mat4 &matrix) void CGL33Device::SetTransform(TransformType type, const glm::mat4 &matrix)
@ -678,8 +670,6 @@ void CGL33Device::SetTexture(int index, const Texture &texture)
m_currentTextures[index] = texture; // remember the new value m_currentTextures[index] = texture; // remember the new value
// Params need to be updated for the new bound texture
UpdateTextureParams(index);
UpdateTextureState(index); UpdateTextureState(index);
} }
@ -694,8 +684,6 @@ void CGL33Device::SetTexture(int index, unsigned int textureId)
m_currentTextures[index].id = textureId; m_currentTextures[index].id = textureId;
// Params need to be updated for the new bound texture
UpdateTextureParams(index);
UpdateTextureState(index); UpdateTextureState(index);
} }
@ -711,82 +699,10 @@ void CGL33Device::SetTextureEnabled(int index, bool enabled)
UpdateTextureState(index); UpdateTextureState(index);
} }
/**
Sets the texture parameters for the given texture stage.
If the given texture was not set (bound) yet, nothing happens.
The settings are remembered, even if texturing is disabled at the moment. */
void CGL33Device::SetTextureStageParams(int index, const TextureStageParams &params)
{
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
// Remember the settings
m_textureStageParams[index] = params;
UpdateTextureParams(index);
}
void CGL33Device::UpdateTextureParams(int index)
{
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
// Don't actually do anything if texture not set
if (! m_currentTextures[index].Valid())
return;
const TextureStageParams &params = m_textureStageParams[index];
glActiveTexture(GL_TEXTURE0 + index);
if (params.wrapS == TEX_WRAP_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
else if (params.wrapS == TEX_WRAP_CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
else if (params.wrapS == TEX_WRAP_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
else assert(false);
if (params.wrapT == TEX_WRAP_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
else if (params.wrapT == TEX_WRAP_CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
else if (params.wrapT == TEX_WRAP_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
else assert(false);
}
void CGL33Device::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT)
{
assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
// Remember the settings
m_textureStageParams[index].wrapS = wrapS;
m_textureStageParams[index].wrapT = wrapT;
// Don't actually do anything if texture not set
if (! m_currentTextures[index].Valid())
return;
glActiveTexture(GL_TEXTURE0 + index);
if (wrapS == TEX_WRAP_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
else if (wrapS == TEX_WRAP_CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
else if (wrapS == TEX_WRAP_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
else assert(false);
if (wrapT == TEX_WRAP_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
else if (wrapT == TEX_WRAP_CLAMP_TO_BORDER)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
else if (wrapT == TEX_WRAP_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
else assert(false);
}
void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color) void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount, Color color)
{ {
return;
unsigned int size = vertexCount * sizeof(Vertex); unsigned int size = vertexCount * sizeof(Vertex);
DynamicBuffer& buffer = m_dynamicBuffer; DynamicBuffer& buffer = m_dynamicBuffer;
@ -824,6 +740,8 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int
void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount)
{ {
return;
unsigned int size = vertexCount * sizeof(VertexCol); unsigned int size = vertexCount * sizeof(VertexCol);
DynamicBuffer& buffer = m_dynamicBuffer; DynamicBuffer& buffer = m_dynamicBuffer;
@ -860,6 +778,8 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, i
void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount) void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, int vertexCount)
{ {
return;
unsigned int size = vertexCount * sizeof(Vertex3D); unsigned int size = vertexCount * sizeof(Vertex3D);
DynamicBuffer& buffer = m_dynamicBuffer; DynamicBuffer& buffer = m_dynamicBuffer;
@ -900,6 +820,8 @@ void CGL33Device::DrawPrimitive(PrimitiveType type, const Vertex3D* vertices, in
void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices, void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
int first[], int count[], int drawCount, Color color) int first[], int count[], int drawCount, Color color)
{ {
return;
int vertexCount = 0; int vertexCount = 0;
for (int i = 0; i < drawCount; i++) for (int i = 0; i < drawCount; i++)
@ -948,6 +870,8 @@ void CGL33Device::DrawPrimitives(PrimitiveType type, const Vertex *vertices,
void CGL33Device::DrawPrimitives(PrimitiveType type, const VertexCol *vertices, void CGL33Device::DrawPrimitives(PrimitiveType type, const VertexCol *vertices,
int first[], int count[], int drawCount) int first[], int count[], int drawCount)
{ {
return;
int vertexCount = 0; int vertexCount = 0;
for (int i = 0; i < drawCount; i++) for (int i = 0; i < drawCount; i++)
@ -1068,23 +992,6 @@ void CGL33Device::SetClearColor(const Color &color)
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
} }
void CGL33Device::SetCullMode(CullMode mode)
{
// Cull clockwise back faces, so front face is the opposite
// (assuming GL_CULL_FACE is GL_BACK)
if (mode == CULL_CW ) glFrontFace(GL_CCW);
else if (mode == CULL_CCW) glFrontFace(GL_CW);
else assert(false);
}
void CGL33Device::SetFillMode(FillMode mode)
{
if (mode == FillMode::POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
else if (mode == FillMode::LINES) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else if (mode == FillMode::POLY) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
else assert(false);
}
void CGL33Device::CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) void CGL33Device::CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height)
{ {
if (texture.id == 0) return; if (texture.id == 0) return;

View File

@ -135,10 +135,6 @@ public:
void SetTexture(int index, unsigned int textureId) override; void SetTexture(int index, unsigned int textureId) override;
void SetTextureEnabled(int index, bool enabled) override; void SetTextureEnabled(int index, bool enabled) override;
void SetTextureStageParams(int index, const TextureStageParams &params) override;
void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT) override;
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount, virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) override; 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 VertexCol *vertices , int vertexCount) override;
@ -166,10 +162,6 @@ public:
void SetClearColor(const Color &color) override; void SetClearColor(const Color &color) override;
void SetCullMode(CullMode mode) override;
void SetFillMode(FillMode mode) override;
void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override; void CopyFramebufferToTexture(Texture& texture, int xOffset, int yOffset, int x, int y, int width, int height) override;
std::unique_ptr<CFrameBufferPixels> GetFrameBufferPixels() const override; std::unique_ptr<CFrameBufferPixels> GetFrameBufferPixels() const override;
@ -192,8 +184,6 @@ public:
bool IsFramebufferSupported() override; bool IsFramebufferSupported() override;
private: private:
//! Updates the texture params for given texture stage
void UpdateTextureParams(int index);
//! Updates texture state //! Updates texture state
inline void UpdateTextureState(int index); inline void UpdateTextureState(int index);

View File

@ -177,6 +177,10 @@ void CGL33ObjectRenderer::CGL33ObjectRenderer::Begin()
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW); // Colobot issue: faces are reversed
SetUVTransform({ 0.0f, 0.0f }, { 1.0f, 1.0f }); SetUVTransform({ 0.0f, 0.0f }, { 1.0f, 1.0f });
} }
@ -320,7 +324,6 @@ void CGL33ObjectRenderer::SetCullMode(bool enabled)
if (enabled) if (enabled)
{ {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
} }
else else
{ {

View File

@ -71,7 +71,7 @@ CGL33UIRenderer::CGL33UIRenderer(CGL33Device* device)
// Generic buffer // Generic buffer
glGenBuffers(1, &m_bufferVBO); glGenBuffers(1, &m_bufferVBO);
glBindBuffer(GL_COPY_WRITE_BUFFER, m_bufferVBO); glBindBuffer(GL_COPY_WRITE_BUFFER, m_bufferVBO);
glBufferData(GL_COPY_WRITE_BUFFER, m_bufferCapacity, nullptr, GL_STREAM_DRAW); glBufferData(GL_COPY_WRITE_BUFFER, m_bufferCapacity * sizeof(Vertex2D), nullptr, GL_STREAM_DRAW);
glGenVertexArrays(1, &m_bufferVAO); glGenVertexArrays(1, &m_bufferVAO);
glBindVertexArray(m_bufferVAO); glBindVertexArray(m_bufferVAO);
@ -106,8 +106,6 @@ CGL33UIRenderer::~CGL33UIRenderer()
void CGL33UIRenderer::SetProjection(float left, float right, float bottom, float top) void CGL33UIRenderer::SetProjection(float left, float right, float bottom, float top)
{ {
Flush();
m_uniforms.projectionMatrix = glm::ortho(left, right, bottom, top); m_uniforms.projectionMatrix = glm::ortho(left, right, bottom, top);
m_uniformsDirty = true; m_uniformsDirty = true;
} }
@ -116,8 +114,6 @@ void CGL33UIRenderer::SetTexture(const Texture& texture)
{ {
if (m_currentTexture == texture.id) return; if (m_currentTexture == texture.id) return;
Flush();
glActiveTexture(GL_TEXTURE8); glActiveTexture(GL_TEXTURE8);
m_currentTexture = texture.id; m_currentTexture = texture.id;
@ -130,88 +126,129 @@ void CGL33UIRenderer::SetTexture(const Texture& texture)
void CGL33UIRenderer::SetColor(const glm::vec4& color) void CGL33UIRenderer::SetColor(const glm::vec4& color)
{ {
Flush();
m_uniforms.color = color; m_uniforms.color = color;
m_uniformsDirty = true; m_uniformsDirty = true;
} }
void CGL33UIRenderer::DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) void CGL33UIRenderer::SetTransparency(TransparencyMode mode)
{ {
// If too much data would be buffered, flush switch (mode)
size_t totalSize = (m_buffer.size() + count) * sizeof(Vertex2D); {
case TransparencyMode::NONE:
if (totalSize > m_bufferCapacity) glDisable(GL_BLEND);
Flush(); break;
case TransparencyMode::ALPHA:
// Buffer data glEnable(GL_BLEND);
GLint first = m_buffer.size(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
m_buffer.insert(m_buffer.end(), vertices, vertices + count); break;
m_types.push_back(TranslateGfxPrimitive(type)); case TransparencyMode::BLACK:
m_firsts.push_back(first); glEnable(GL_BLEND);
m_counts.push_back(count); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
glBlendEquation(GL_FUNC_ADD);
break;
case TransparencyMode::WHITE:
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
glBlendEquation(GL_FUNC_ADD);
break;
}
} }
void CGL33UIRenderer::Flush() void CGL33UIRenderer::DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices)
{ {
if (m_types.empty()) return; auto ptr = BeginPrimitive(type, count);
UpdateUniforms(); std::copy_n(vertices, count, ptr);
EndPrimitive();
}
Vertex2D* CGL33UIRenderer::BeginPrimitive(PrimitiveType type, int count)
{
ClearGLErrors();
glBindVertexArray(m_bufferVAO);
glBindBuffer(GL_ARRAY_BUFFER, m_bufferVBO);
GLuint total = m_offset + count;
// Buffer full, orphan
if (total >= m_bufferCapacity)
{
glBufferData(GL_ARRAY_BUFFER, m_bufferCapacity * sizeof(Vertex2D), nullptr, GL_STREAM_DRAW);
m_offset = 0;
// Respecify vertex attributes
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, position)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, uv)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, color)));
}
auto ptr = glMapBufferRange(GL_ARRAY_BUFFER,
m_offset * sizeof(Vertex2D),
count * sizeof(Vertex2D),
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
m_mapped = true;
m_type = type;
m_count = count;
ClearGLErrors();
CheckGLErrors();
// Mapping failed, use backup buffer
if (ptr == nullptr)
{
m_backup = true;
m_buffer.resize(count);
return m_buffer.data();
}
else
{
return reinterpret_cast<Vertex2D*>(ptr);
}
}
bool CGL33UIRenderer::EndPrimitive()
{
if (!m_mapped) return false;
if (m_backup)
{
glBufferSubData(GL_ARRAY_BUFFER, m_offset * sizeof(Vertex2D), m_count * sizeof(Vertex2D), m_buffer.data());
}
else
{
glUnmapBuffer(GL_ARRAY_BUFFER);
}
glUseProgram(m_program); glUseProgram(m_program);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_uniformBuffer); glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_uniformBuffer);
// Increase buffer size if necessary UpdateUniforms();
size_t size = m_buffer.size() * sizeof(Vertex2D);
if (m_bufferCapacity < size) glDrawArrays(TranslateGfxPrimitive(m_type), m_offset, m_count);
m_bufferCapacity = size;
// Send new vertices to GPU m_offset += m_count;
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 m_mapped = false;
glBindVertexArray(m_bufferVAO); m_backup = false;
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, position)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, uv)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex2D),
reinterpret_cast<void*>(offsetof(Vertex2D, color)));
// Draw primitives by grouping by type
for (size_t i = 0; i < m_types.size(); 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();
m_device->Restore(); m_device->Restore();
return true;
} }
void CGL33UIRenderer::UpdateUniforms() void CGL33UIRenderer::UpdateUniforms()
@ -336,6 +373,7 @@ void CGL33TerrainRenderer::Begin()
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glFrontFace(GL_CW); // Colobot issue: faces are reversed
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -475,11 +513,6 @@ void CGL33TerrainRenderer::DrawObject(const glm::mat4& matrix, const CVertexBuff
glDrawArrays(TranslateGfxPrimitive(b->GetType()), 0, b->Size()); glDrawArrays(TranslateGfxPrimitive(b->GetType()), 0, b->Size());
} }
void CGL33TerrainRenderer::Flush()
{
}
CGL33ShadowRenderer::CGL33ShadowRenderer(CGL33Device* device) CGL33ShadowRenderer::CGL33ShadowRenderer(CGL33Device* device)
: m_device(device) : m_device(device)
{ {
@ -636,9 +669,4 @@ void CGL33ShadowRenderer::DrawObject(const CVertexBuffer* buffer, bool transpare
glDrawArrays(TranslateGfxPrimitive(b->GetType()), 0, b->Size()); glDrawArrays(TranslateGfxPrimitive(b->GetType()), 0, b->Size());
} }
void CGL33ShadowRenderer::Flush()
{
}
} // namespace Gfx } // namespace Gfx

View File

@ -46,10 +46,12 @@ public:
virtual void SetProjection(float left, float right, float bottom, float top) override; virtual void SetProjection(float left, float right, float bottom, float top) override;
virtual void SetTexture(const Texture& texture) override; virtual void SetTexture(const Texture& texture) override;
virtual void SetColor(const glm::vec4& color) override; virtual void SetColor(const glm::vec4& color) override;
virtual void SetTransparency(TransparencyMode mode) override;
virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) override; virtual void DrawPrimitive(PrimitiveType type, int count, const Vertex2D* vertices) override;
virtual void Flush() override; virtual Vertex2D* BeginPrimitive(PrimitiveType type, int count) override;
virtual bool EndPrimitive() override;
private: private:
void UpdateUniforms(); void UpdateUniforms();
@ -76,12 +78,16 @@ private:
GLuint m_bufferVAO = 0; GLuint m_bufferVAO = 0;
// VBO capacity // VBO capacity
GLsizei m_bufferCapacity = 4 * 1024; GLsizei m_bufferCapacity = 4 * 1024;
// Buffer mapping state
PrimitiveType m_type = {};
GLuint m_offset = 0;
GLuint m_count = 0;
bool m_mapped = false;
bool m_backup = false;
// Buffered vertex data // Buffered vertex data
std::vector<Vertex2D> m_buffer; std::vector<Vertex2D> m_buffer;
std::vector<GLenum> m_types;
std::vector<GLint> m_firsts;
std::vector<GLsizei> m_counts;
// Shader program // Shader program
GLuint m_program = 0; GLuint m_program = 0;
@ -127,8 +133,6 @@ public:
//! Draws terrain object //! Draws terrain object
virtual void DrawObject(const glm::mat4& matrix, const CVertexBuffer* buffer) override; virtual void DrawObject(const glm::mat4& matrix, const CVertexBuffer* buffer) override;
virtual void Flush() override;
private: private:
CGL33Device* const m_device; CGL33Device* const m_device;
@ -196,8 +200,6 @@ public:
//! Draws terrain object //! Draws terrain object
virtual void DrawObject(const CVertexBuffer* buffer, bool transparent) override; virtual void DrawObject(const CVertexBuffer* buffer, bool transparent) override;
virtual void Flush() override;
private: private:
CGL33Device* const m_device; CGL33Device* const m_device;

View File

@ -40,6 +40,6 @@ void main()
{ {
gl_Position = uni_Matrix * in_VertexCoord; gl_Position = uni_Matrix * in_VertexCoord;
data.Color = uni_Color * in_Color; data.Color = in_Color;
data.TexCoord = in_TexCoord; data.TexCoord = in_TexCoord;
} }

View File

@ -25,6 +25,7 @@
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
namespace Ui namespace Ui
@ -170,8 +171,12 @@ void CButton::Draw()
(m_state & STATE_CARD ) == 0 && (m_state & STATE_CARD ) == 0 &&
(m_state & STATE_SIMPLY) == 0 ) (m_state & STATE_SIMPLY) == 0 )
{ {
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetUITexture("textures/interface/button2.png");
auto texture = m_engine->LoadTexture("textures/interface/button2.png");
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
dp = 0.5f / 256.0f; dp = 0.5f / 256.0f;

View File

@ -24,6 +24,7 @@
#include "common/restext.h" #include "common/restext.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/engine/text.h" #include "graphics/engine/text.h"
@ -94,6 +95,7 @@ void CCheck::Draw()
int icon; int icon;
auto device = m_engine->GetDevice(); auto device = m_engine->GetDevice();
auto renderer = device->GetUIRenderer();
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
@ -105,8 +107,9 @@ void CCheck::Draw()
DrawShadow(m_pos, m_dim); DrawShadow(m_pos, m_dim);
} }
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
zoomExt = 1.00f; zoomExt = 1.00f;
zoomInt = 0.95f; zoomInt = 0.95f;
@ -140,7 +143,7 @@ void CCheck::Draw()
if ( (m_state & STATE_DEAD) == 0 ) if ( (m_state & STATE_DEAD) == 0 )
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
if ( m_state & STATE_CHECK ) if ( m_state & STATE_CHECK )
{ {

View File

@ -136,8 +136,11 @@ void CColor::Draw()
DrawShadow(m_pos, m_dim); DrawShadow(m_pos, m_dim);
} }
m_engine->SetUITexture("textures/interface/button1.png"); auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
auto texture = m_engine->LoadTexture("textures/interface/button1.png");
renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
CControl::Draw(); CControl::Draw();
p1.x = m_pos.x + (3.0f / 640.0f); p1.x = m_pos.x + (3.0f / 640.0f);
@ -149,16 +152,14 @@ void CColor::Draw()
glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 }; glm::u8vec4 col = { color.r * 255, color.g * 255, color.b * 255, color.a * 255 };
m_engine->SetUITexture(Gfx::Texture{0}); // no texture renderer->SetTexture(Gfx::Texture{0});
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
vertex[0] = { { p1.x, p1.y }, {}, col }; vertex[0] = { { p1.x, p1.y }, {}, col };
vertex[1] = { { p1.x, p2.y }, {}, col }; vertex[1] = { { p1.x, p2.y }, {}, col };
vertex[2] = { { p2.x, p1.y }, {}, col }; vertex[2] = { { p2.x, p1.y }, {}, col };
vertex[3] = { { p2.x, p2.y }, {}, col }; vertex[3] = { { p2.x, p2.y }, {}, col };
auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex); renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, vertex);
m_engine->AddStatisticTriangle(2); m_engine->AddStatisticTriangle(2);
} }

View File

@ -451,9 +451,11 @@ void CControl::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetUITexture("textures/interface/button1.png");
auto device = m_engine->GetDevice(); auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
zoomExt = 1.00f; zoomExt = 1.00f;
zoomInt = 0.95f; zoomInt = 0.95f;
@ -506,7 +508,8 @@ void CControl::Draw()
if ( m_state & STATE_OKAY ) if ( m_state & STATE_OKAY )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
renderer->SetTexture(texture);
icon = 3; // yellow with green point pressed icon = 3; // yellow with green point pressed
} }
@ -518,7 +521,8 @@ void CControl::Draw()
if ( m_state & STATE_DEAD ) return; if ( m_state & STATE_DEAD ) return;
icon = SetButtonTextureForIcon(m_icon); icon = SetButtonTextureForIcon(m_icon);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
//m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
if ( icon != -1 ) if ( icon != -1 )
{ {
DrawPart(icon, zoomInt, 0.0f); DrawPart(icon, zoomInt, 0.0f);
@ -740,14 +744,17 @@ void CControl::DrawWarning(const glm::vec2& position, const glm::vec2& dimension
glm::vec2 uv1, uv2; glm::vec2 uv1, uv2;
float dp; float dp;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
glm::vec2 pos = position; glm::vec2 pos = position;
glm::vec2 dim = dimension; glm::vec2 dim = dimension;
dp = 0.5f / 256.0f; dp = 0.5f / 256.0f;
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
auto device = m_engine->GetDevice(); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
uv1.x = 64.0f / 256.0f; uv1.x = 64.0f / 256.0f;
uv1.y = 208.0f / 256.0f; uv1.y = 208.0f / 256.0f;
@ -788,14 +795,17 @@ void CControl::DrawShadow(const glm::vec2& position, const glm::vec2& dimension,
glm::vec2 uv1, uv2, corner; glm::vec2 uv1, uv2, corner;
float dp; float dp;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
glm::vec2 pos = position; glm::vec2 pos = position;
glm::vec2 dim = dimension; glm::vec2 dim = dimension;
dp = 0.5f/256.0f; dp = 0.5f/256.0f;
m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png");
auto device = m_engine->GetDevice(); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
renderer->SetTexture(texture);
pos.x += deep * 0.010f * 0.75f; pos.x += deep * 0.010f * 0.75f;
pos.y -= deep * 0.015f; pos.y -= deep * 0.015f;
@ -846,7 +856,8 @@ int CControl::SetButtonTextureForIcon(int icon)
int iconIdx = icon%64; int iconIdx = icon%64;
int buttonFile = (icon/64) + 1; int buttonFile = (icon/64) + 1;
m_engine->SetUITexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png"); auto texture = m_engine->LoadTexture("textures/interface/button" + StrUtils::ToString<int>(buttonFile) + ".png");
m_engine->GetDevice()->GetUIRenderer()->SetTexture(texture);
return iconIdx; return iconIdx;
} }

View File

@ -1177,7 +1177,8 @@ void CEdit::DrawImage(const glm::vec2& pos, std::string name, float width,
glm::vec2 uv1, uv2, dim; glm::vec2 uv1, uv2, dim;
float dp; float dp;
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); m_engine->GetDevice()->GetUIRenderer()->SetTransparency(Gfx::TransparencyMode::NONE);
//m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
Gfx::TextureCreateParams params; Gfx::TextureCreateParams params;
params.format = Gfx::TEX_IMG_AUTO; params.format = Gfx::TEX_IMG_AUTO;
@ -1185,7 +1186,7 @@ void CEdit::DrawImage(const glm::vec2& pos, std::string name, float width,
params.padToNearestPowerOfTwo = true; params.padToNearestPowerOfTwo = true;
Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params); Gfx::Texture tex = m_engine->LoadTexture(PrepareImageFilename(name), params);
m_engine->SetUITexture(tex); m_engine->GetDevice()->GetUIRenderer()->SetTexture(tex);
uv1.x = 0.0f; uv1.x = 0.0f;
uv2.x = 1.0f; uv2.x = 1.0f;
@ -1217,8 +1218,11 @@ void CEdit::DrawBack(const glm::vec2& pos, const glm::vec2& dim)
if ( m_bGeneric ) return; if ( m_bGeneric ) return;
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
if ( m_bMulti ) if ( m_bMulti )
{ {
@ -1262,7 +1266,8 @@ 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) void CEdit::DrawHorizontalGradient(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color1, Gfx::Color color2)
{ {
m_engine->SetState(Gfx::ENG_RSTATE_OPAQUE_COLOR); auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
glm::vec2 p1, p2; glm::vec2 p1, p2;
p1.x = pos.x; p1.x = pos.x;
@ -1281,8 +1286,6 @@ void CEdit::DrawHorizontalGradient(const glm::vec2& pos, const glm::vec2& dim, G
{ { p2.x, p2.y }, {}, col2 } { { p2.x, p2.y }, {}, col2 }
}; };
auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, quad); renderer->DrawPrimitive(Gfx::PrimitiveType::TRIANGLE_STRIP, 4, quad);
m_engine->AddStatisticTriangle(2); m_engine->AddStatisticTriangle(2);
} }

View File

@ -21,6 +21,8 @@
#include "ui/controls/gauge.h" #include "ui/controls/gauge.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
namespace Ui namespace Ui
@ -78,8 +80,11 @@ void CGauge::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
auto renderer = m_engine->GetDevice()->GetUIRenderer();
renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
dp = 0.5f/256.0f; dp = 0.5f/256.0f;

View File

@ -24,6 +24,7 @@
#include "common/restext.h" #include "common/restext.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "math/func.h" #include "math/func.h"
@ -93,10 +94,13 @@ void CGroup::Draw()
dp = 0.5f / 256.0f; dp = 0.5f / 256.0f;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
if ( m_icon == 0 ) // hollow frame? if ( m_icon == 0 ) // hollow frame?
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 160.0f / 256.0f; uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture uv1.y = 192.0f / 256.0f; // u-v texture
@ -112,8 +116,9 @@ void CGroup::Draw()
} }
if ( m_icon == 1 ) // orange solid opaque? if ( m_icon == 1 ) // orange solid opaque?
{ {
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 104.0f / 256.0f; uv1.x = 104.0f / 256.0f;
uv1.y = 48.0f / 256.0f; uv1.y = 48.0f / 256.0f;
@ -127,8 +132,9 @@ void CGroup::Draw()
} }
if ( m_icon == 2 ) // orange degrade -> transparent? if ( m_icon == 2 ) // orange degrade -> transparent?
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 112.0f / 256.0f; uv1.x = 112.0f / 256.0f;
uv1.y = 48.0f / 256.0f; uv1.y = 48.0f / 256.0f;
@ -142,8 +148,9 @@ void CGroup::Draw()
} }
if ( m_icon == 3 ) // transparent gradient -> gray? if ( m_icon == 3 ) // transparent gradient -> gray?
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 120.0f / 256.0f; uv1.x = 120.0f / 256.0f;
uv1.y = 48.0f / 256.0f; uv1.y = 48.0f / 256.0f;
@ -157,8 +164,9 @@ void CGroup::Draw()
} }
if ( m_icon == 4 ) // degrade blue corner? if ( m_icon == 4 ) // degrade blue corner?
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 192.0f / 256.0f; uv1.x = 192.0f / 256.0f;
uv1.y = 128.0f / 256.0f; uv1.y = 128.0f / 256.0f;
@ -172,8 +180,9 @@ void CGroup::Draw()
} }
if ( m_icon == 5 ) // degrade orange corner? if ( m_icon == 5 ) // degrade orange corner?
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetUITexture("textures/interface/button2.png"); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 224.0f / 256.0f; uv1.x = 224.0f / 256.0f;
uv1.y = 128.0f / 256.0f; uv1.y = 128.0f / 256.0f;
@ -187,8 +196,9 @@ void CGroup::Draw()
} }
if ( m_icon == 6 ) if ( m_icon == 6 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 0.0f / 256.0f; // brown transparent uv1.x = 0.0f / 256.0f; // brown transparent
uv1.y = 75.0f / 256.0f; uv1.y = 75.0f / 256.0f;
@ -204,8 +214,9 @@ void CGroup::Draw()
} }
if ( m_icon == 7 ) if ( m_icon == 7 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f / 256.0f; uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f; uv1.y = 0.0f / 256.0f;
@ -219,8 +230,9 @@ void CGroup::Draw()
} }
if ( m_icon == 8 ) if ( m_icon == 8 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f / 256.0f; // green transparent uv1.x = 64.0f / 256.0f; // green transparent
uv1.y = 160.0f / 256.0f; uv1.y = 160.0f / 256.0f;
@ -234,8 +246,9 @@ void CGroup::Draw()
} }
if ( m_icon == 9 ) if ( m_icon == 9 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f / 256.0f; // red transparent uv1.x = 64.0f / 256.0f; // red transparent
uv1.y = 176.0f/256.0f; uv1.y = 176.0f/256.0f;
@ -249,8 +262,9 @@ void CGroup::Draw()
} }
if ( m_icon == 10 ) if ( m_icon == 10 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f / 256.0f; // blue transparent uv1.x = 64.0f / 256.0f; // blue transparent
uv1.y = 192.0f / 256.0f; uv1.y = 192.0f / 256.0f;
@ -264,8 +278,9 @@ void CGroup::Draw()
} }
if ( m_icon == 11 ) if ( m_icon == 11 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f / 256.0f; // yellow transparent uv1.x = 64.0f / 256.0f; // yellow transparent
uv1.y = 224.0f / 256.0f; uv1.y = 224.0f / 256.0f;
uv2.x = 160.0f / 256.0f; uv2.x = 160.0f / 256.0f;
@ -281,8 +296,9 @@ void CGroup::Draw()
dim.x = m_dim.x / 2.0f; dim.x = m_dim.x / 2.0f;
dim.y = m_dim.y / 2.0f; dim.y = m_dim.y / 2.0f;
m_engine->SetUITexture("textures/interface/mouse.png"); auto texture = m_engine->LoadTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x = m_pos.x-m_dim.x/300.0f; pos.x = m_pos.x-m_dim.x/300.0f;
pos.y = m_pos.y+m_dim.y/300.0f+dim.y; pos.y = m_pos.y+m_dim.y/300.0f+dim.y;
uv1.x = 0.5f / 256.0f; uv1.x = 0.5f / 256.0f;
@ -300,7 +316,7 @@ void CGroup::Draw()
Math::Swap(uv1.x, uv2.x); Math::Swap(uv1.x, uv2.x);
DrawIcon(pos, dim, uv1, uv2); // dl DrawIcon(pos, dim, uv1, uv2); // dl
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
pos.x = m_pos.x+m_dim.x/300.0f; pos.x = m_pos.x+m_dim.x/300.0f;
pos.y = m_pos.y-m_dim.y/300.0f+dim.y; pos.y = m_pos.y-m_dim.y/300.0f+dim.y;
uv1.x = 64.5f / 256.0f; uv1.x = 64.5f / 256.0f;
@ -320,8 +336,9 @@ void CGroup::Draw()
} }
if ( m_icon == 13 ) // corner upper / left? if ( m_icon == 13 ) // corner upper / left?
{ {
m_engine->SetUITexture("textures/interface/mouse.png"); auto texture = m_engine->LoadTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x = m_pos.x-m_dim.x/150.0f; pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f; pos.y = m_pos.y+m_dim.y/150.0f;
uv1.x = 128.5f / 256.0f; uv1.x = 128.5f / 256.0f;
@ -330,7 +347,7 @@ void CGroup::Draw()
uv2.y = 255.5f / 256.0f; uv2.y = 255.5f / 256.0f;
DrawIcon(pos, m_dim, uv1, uv2); DrawIcon(pos, m_dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
pos.x = m_pos.x+m_dim.x/150.0f; pos.x = m_pos.x+m_dim.x/150.0f;
pos.y = m_pos.y-m_dim.y/150.0f; pos.y = m_pos.y-m_dim.y/150.0f;
uv1.x = 192.5f / 256.0f; uv1.x = 192.5f / 256.0f;
@ -341,8 +358,9 @@ void CGroup::Draw()
} }
if ( m_icon == 14 ) // corner upper / right? if ( m_icon == 14 ) // corner upper / right?
{ {
m_engine->SetUITexture("textures/interface/mouse.png"); auto texture = m_engine->LoadTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x = m_pos.x-m_dim.x/150.0f; pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f; pos.y = m_pos.y+m_dim.y/150.0f;
uv2.x = 128.5f / 256.0f; uv2.x = 128.5f / 256.0f;
@ -351,7 +369,7 @@ void CGroup::Draw()
uv2.y = 255.5f / 256.0f; uv2.y = 255.5f / 256.0f;
DrawIcon(pos, m_dim, uv1, uv2); DrawIcon(pos, m_dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
pos.x = m_pos.x+m_dim.x/150.0f; pos.x = m_pos.x+m_dim.x/150.0f;
pos.y = m_pos.y-m_dim.y/150.0f; pos.y = m_pos.y-m_dim.y/150.0f;
uv2.x = 192.5f / 256.0f; uv2.x = 192.5f / 256.0f;
@ -362,8 +380,9 @@ void CGroup::Draw()
} }
if ( m_icon == 15 ) // corner lower / left? if ( m_icon == 15 ) // corner lower / left?
{ {
m_engine->SetUITexture("textures/interface/mouse.png"); auto texture = m_engine->LoadTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x = m_pos.x-m_dim.x/150.0f; pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f; pos.y = m_pos.y+m_dim.y/150.0f;
uv1.x = 128.5f / 256.0f; uv1.x = 128.5f / 256.0f;
@ -372,7 +391,7 @@ void CGroup::Draw()
uv1.y = 255.5f / 256.0f; uv1.y = 255.5f / 256.0f;
DrawIcon(pos, m_dim, uv1, uv2); DrawIcon(pos, m_dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
pos.x = m_pos.x+m_dim.x/150.0f; pos.x = m_pos.x+m_dim.x/150.0f;
pos.y = m_pos.y-m_dim.y/150.0f; pos.y = m_pos.y-m_dim.y/150.0f;
uv1.x = 192.5f / 256.0f; uv1.x = 192.5f / 256.0f;
@ -383,8 +402,9 @@ void CGroup::Draw()
} }
if ( m_icon == 16 ) // corner lower / left? if ( m_icon == 16 ) // corner lower / left?
{ {
m_engine->SetUITexture("textures/interface/mouse.png"); auto texture = m_engine->LoadTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x = m_pos.x-m_dim.x/150.0f; pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f; pos.y = m_pos.y+m_dim.y/150.0f;
uv2.x = 128.5f / 256.0f; uv2.x = 128.5f / 256.0f;
@ -393,7 +413,7 @@ void CGroup::Draw()
uv1.y = 255.5f / 256.0f; uv1.y = 255.5f / 256.0f;
DrawIcon(pos, m_dim, uv1, uv2); DrawIcon(pos, m_dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
pos.x = m_pos.x+m_dim.x/150.0f; pos.x = m_pos.x+m_dim.x/150.0f;
pos.y = m_pos.y-m_dim.y/150.0f; pos.y = m_pos.y-m_dim.y/150.0f;
uv2.x = 192.5f / 256.0f; uv2.x = 192.5f / 256.0f;
@ -404,8 +424,9 @@ void CGroup::Draw()
} }
if ( m_icon == 17 ) if ( m_icon == 17 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 0.0f / 256.0f; // blue frame uv1.x = 0.0f / 256.0f; // blue frame
uv1.y = 75.0f / 256.0f; uv1.y = 75.0f / 256.0f;
uv2.x = 64.0f / 256.0f; uv2.x = 64.0f / 256.0f;
@ -420,8 +441,9 @@ void CGroup::Draw()
} }
if ( m_icon == 18 ) // arrow> for SatCom? if ( m_icon == 18 ) // arrow> for SatCom?
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 0.0f / 256.0f; // > uv1.x = 0.0f / 256.0f; // >
uv1.y = 192.0f / 256.0f; uv1.y = 192.0f / 256.0f;
uv2.x = 32.0f / 256.0f; uv2.x = 32.0f / 256.0f;
@ -434,8 +456,9 @@ void CGroup::Draw()
} }
if ( m_icon == 19 ) // SatCom symbol? if ( m_icon == 19 ) // SatCom symbol?
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 224.0f / 256.0f; // SatCom symbol uv1.x = 224.0f / 256.0f; // SatCom symbol
uv1.y = 224.0f / 256.0f; uv1.y = 224.0f / 256.0f;
uv2.x = 256.0f / 256.0f; uv2.x = 256.0f / 256.0f;
@ -448,8 +471,9 @@ void CGroup::Draw()
} }
if ( m_icon == 20 ) // solid blue background? if ( m_icon == 20 ) // solid blue background?
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 224.0f / 256.0f; uv1.x = 224.0f / 256.0f;
uv1.y = 32.0f / 256.0f; uv1.y = 32.0f / 256.0f;
uv2.x = 256.0f / 256.0f; uv2.x = 256.0f / 256.0f;
@ -462,8 +486,9 @@ void CGroup::Draw()
} }
if ( m_icon == 21 ) // stand-by symbol? if ( m_icon == 21 ) // stand-by symbol?
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 160.0f / 256.0f; uv1.x = 160.0f / 256.0f;
uv1.y = 32.0f / 256.0f; uv1.y = 32.0f / 256.0f;
uv2.x = 192.0f / 256.0f; uv2.x = 192.0f / 256.0f;
@ -476,8 +501,9 @@ void CGroup::Draw()
} }
if ( m_icon == 22 ) if ( m_icon == 22 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f / 256.0f; // opaque yellow uv1.x = 64.0f / 256.0f; // opaque yellow
uv1.y = 224.0f / 256.0f; uv1.y = 224.0f / 256.0f;
uv2.x = 160.0f / 256.0f; uv2.x = 160.0f / 256.0f;
@ -493,8 +519,9 @@ void CGroup::Draw()
if ( m_icon == 23 ) if ( m_icon == 23 )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f / 256.0f; // yellow uv1.x = 64.0f / 256.0f; // yellow
uv1.y = 192.0f / 256.0f; uv1.y = 192.0f / 256.0f;
uv2.x = 80.0f / 256.0f; uv2.x = 80.0f / 256.0f;
@ -509,8 +536,9 @@ void CGroup::Draw()
} }
if ( m_icon == 24 ) if ( m_icon == 24 )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 80.0f / 256.0f; // orange uv1.x = 80.0f / 256.0f; // orange
uv1.y = 192.0f / 256.0f; uv1.y = 192.0f / 256.0f;
uv2.x = 96.0f / 256.0f; uv2.x = 96.0f / 256.0f;
@ -525,8 +553,9 @@ void CGroup::Draw()
} }
if ( m_icon == 25 ) if ( m_icon == 25 )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f / 256.0f; // orange uv1.x = 64.0f / 256.0f; // orange
uv1.y = 208.0f / 256.0f; uv1.y = 208.0f / 256.0f;
uv2.x = 80.0f / 256.0f; uv2.x = 80.0f / 256.0f;
@ -541,8 +570,9 @@ void CGroup::Draw()
} }
if ( m_icon == 26 ) if ( m_icon == 26 )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 80.0f / 256.0f; // red uv1.x = 80.0f / 256.0f; // red
uv1.y = 208.0f / 256.0f; uv1.y = 208.0f / 256.0f;
uv2.x = 96.0f / 256.0f; uv2.x = 96.0f / 256.0f;
@ -557,8 +587,9 @@ void CGroup::Draw()
} }
if ( m_icon == 27 ) if ( m_icon == 27 )
{ {
m_engine->SetUITexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 32.0f / 256.0f; uv1.x = 32.0f / 256.0f;
uv1.y = 0.0f / 256.0f; uv1.y = 0.0f / 256.0f;
uv2.x = 64.0f / 256.0f; uv2.x = 64.0f / 256.0f;
@ -572,10 +603,11 @@ void CGroup::Draw()
if ( m_icon >= 100 && m_icon <= 120 ) // building? if ( m_icon >= 100 && m_icon <= 120 ) // building?
{ {
auto texture = m_engine->LoadTexture("textures/interface/button2.png");
renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
pos = m_pos; pos = m_pos;
dim = m_dim; dim = m_dim;
m_engine->SetUITexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f / 256.0f; uv1.x = 32.0f / 256.0f;
uv1.y = 32.0f / 256.0f; uv1.y = 32.0f / 256.0f;
uv2.x = uv1.x+32.0f/256.0f; uv2.x = uv1.x+32.0f/256.0f;
@ -586,8 +618,9 @@ void CGroup::Draw()
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); DrawIcon(pos, dim, uv1, uv2);
m_engine->SetUITexture("textures/interface/button3.png"); texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
pos.x += 8.0f / 640.0f; pos.x += 8.0f / 640.0f;
pos.y += 8.0f / 480.0f; pos.y += 8.0f / 480.0f;
dim.x -= 16.0f / 640.0f; dim.x -= 16.0f / 640.0f;
@ -602,7 +635,7 @@ void CGroup::Draw()
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); DrawIcon(pos, dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
pos.x += 2.0f / 640.0f; pos.x += 2.0f / 640.0f;
pos.y += 2.0f / 480.0f; pos.y += 2.0f / 480.0f;
dim.x -= 4.0f / 640.0f; dim.x -= 4.0f / 640.0f;
@ -617,7 +650,7 @@ void CGroup::Draw()
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); DrawIcon(pos, dim, uv1, uv2);
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
pos.x += 8.0f / 640.0f; pos.x += 8.0f / 640.0f;
pos.y += 8.0f / 480.0f; pos.y += 8.0f / 480.0f;
dim.x -= 16.0f / 640.0f; dim.x -= 16.0f / 640.0f;

View File

@ -23,6 +23,8 @@
#include "common/event.h" #include "common/event.h"
#include "common/restext.h" #include "common/restext.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -91,6 +93,8 @@ void CImage::Draw()
glm::vec2 uv1,uv2, corner, pos, dim; glm::vec2 uv1,uv2, corner, pos, dim;
float dp; float dp;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
if ( (m_state & STATE_VISIBLE) == 0 ) return; if ( (m_state & STATE_VISIBLE) == 0 ) return;
if ( m_state & STATE_SHADOW ) if ( m_state & STATE_SHADOW )
@ -102,8 +106,9 @@ void CImage::Draw()
if ( m_icon == 0 ) // hollow frame? if ( m_icon == 0 ) // hollow frame?
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 160.0f / 256.0f; uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture uv1.y = 192.0f / 256.0f; // u-v texture
uv2.x = 192.0f / 256.0f; uv2.x = 192.0f / 256.0f;
@ -124,8 +129,8 @@ void CImage::Draw()
params.filter = Gfx::TEX_FILTER_BILINEAR; params.filter = Gfx::TEX_FILTER_BILINEAR;
params.padToNearestPowerOfTwo = true; params.padToNearestPowerOfTwo = true;
Gfx::Texture tex = m_engine->LoadTexture(m_filename, params); Gfx::Texture tex = m_engine->LoadTexture(m_filename, params);
m_engine->SetUITexture(tex); renderer->SetTexture(tex);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
pos = m_pos; pos = m_pos;
dim = m_dim; dim = m_dim;
pos.x += 5.0f / 640.0f; pos.x += 5.0f / 640.0f;

View File

@ -23,6 +23,8 @@
#include "common/global.h" #include "common/global.h"
#include "common/stringutils.h" #include "common/stringutils.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "sound/sound.h" #include "sound/sound.h"
@ -134,9 +136,11 @@ void CKey::Draw()
if (m_state & STATE_SHADOW) if (m_state & STATE_SHADOW)
DrawShadow(m_pos, m_dim); DrawShadow(m_pos, m_dim);
auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
float zoomExt = 1.00f; float zoomExt = 1.00f;
float zoomInt = 0.95f; float zoomInt = 0.95f;

View File

@ -22,6 +22,8 @@
#include "common/make_unique.h" #include "common/make_unique.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "math/func.h" #include "math/func.h"
@ -366,14 +368,17 @@ void CList::Draw()
dp = 0.5f / 256.0f; dp = 0.5f / 256.0f;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
if (m_icon != -1) if (m_icon != -1)
{ {
dim = m_dim; dim = m_dim;
if (m_icon == 0) if (m_icon == 0)
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f / 256.0f; uv1.x = 128.0f / 256.0f;
uv1.y = 64.0f / 256.0f; // u-v texture uv1.y = 64.0f / 256.0f; // u-v texture
@ -382,8 +387,9 @@ void CList::Draw()
} }
else else
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 132.0f / 256.0f; uv1.x = 132.0f / 256.0f;
uv1.y = 68.0f / 256.0f; // u-v texture uv1.y = 68.0f / 256.0f; // u-v texture
@ -418,8 +424,9 @@ void CList::Draw()
dim.y *= 0.4f; dim.y *= 0.4f;
pos.y -= dim.y; pos.y -= dim.y;
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 120.0f / 256.0f; uv1.x = 120.0f / 256.0f;
uv1.y = 64.0f / 256.0f; uv1.y = 64.0f / 256.0f;
uv2.x = 128.0f / 256.0f; uv2.x = 128.0f / 256.0f;
@ -493,8 +500,9 @@ void CList::Draw()
if (m_items[i + m_firstLine].check) if (m_items[i + m_firstLine].check)
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f / 256.0f; uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f; uv1.y = 0.0f / 256.0f;
uv2.x = 96.0f / 256.0f; uv2.x = 96.0f / 256.0f;
@ -505,7 +513,7 @@ void CList::Draw()
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); // square shape DrawIcon(pos, dim, uv1, uv2); // square shape
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 0.0f / 256.0f; // v uv1.x = 0.0f / 256.0f; // v
uv1.y = 64.0f / 256.0f; uv1.y = 64.0f / 256.0f;
uv2.x = 32.0f / 256.0f; uv2.x = 32.0f / 256.0f;
@ -518,8 +526,9 @@ void CList::Draw()
} }
else else
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
if ( i + m_firstLine == m_selectLine ) if ( i + m_firstLine == m_selectLine )
{ {
uv1.x =224.0f / 256.0f; // < uv1.x =224.0f / 256.0f; // <

View File

@ -335,6 +335,8 @@ void CMap::Draw()
glm::vec2 uv1, uv2; glm::vec2 uv1, uv2;
int i; int i;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
if ( (m_state & STATE_VISIBLE) == 0 ) if ( (m_state & STATE_VISIBLE) == 0 )
return; return;
@ -348,23 +350,28 @@ void CMap::Draw()
if (m_fixImage.empty()) // drawing of the relief? if (m_fixImage.empty()) // drawing of the relief?
{ {
m_engine->SetUITexture("textures/interface/map.png"); auto texture = m_engine->LoadTexture("textures/interface/map.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
uv1.x = 0.5f + (m_offset.x - (m_half / m_zoom)) / (m_half * 2.0f); 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); uv1.y = 0.5f - (m_offset.y + (m_half / m_zoom)) / (m_half * 2.0f);
uv2.x = 0.5f + (m_offset.x + (m_half / m_zoom)) / (m_half * 2.0f); uv2.x = 0.5f + (m_offset.x + (m_half / m_zoom)) / (m_half * 2.0f);
uv2.y = 0.5f - (m_offset.y - (m_half / m_zoom)) / (m_half * 2.0f); uv2.y = 0.5f - (m_offset.y - (m_half / m_zoom)) / (m_half * 2.0f);
DrawVertex(uv1, uv2, 0.97f); // drawing the map DrawVertex(uv1, uv2, 0.97f); // drawing the map
} }
else // still image? else // still image?
{ {
m_engine->LoadTexture(m_fixImage); auto texture = m_engine->LoadTexture(m_fixImage);
m_engine->SetUITexture(m_fixImage); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
uv1.x = 0.0f; uv1.x = 0.0f;
uv1.y = 0.0f; uv1.y = 0.0f;
uv2.x = 1.0f; uv2.x = 1.0f;
uv2.y = 1.0f; uv2.y = 1.0f;
DrawVertex(uv1, uv2, 0.97f); // drawing the map DrawVertex(uv1, uv2, 0.97f); // drawing the map
} }
@ -499,8 +506,11 @@ void CMap::DrawFocus(const glm::vec2& position, float dir, ObjectType type, MapC
uv2.x = 126.0f/256.0f; uv2.x = 126.0f/256.0f;
uv2.y = 255.0f/256.0f; uv2.y = 255.0f/256.0f;
m_engine->SetUITexture("textures/interface/button2.png"); auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
auto texture = m_engine->LoadTexture("textures/interface/button2.png");
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
renderer->SetTexture(texture);
bEnding = false; bEnding = false;
do do
@ -551,6 +561,8 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
dim.x = 2.0f/128.0f*0.75f; dim.x = 2.0f/128.0f*0.75f;
dim.y = 2.0f/128.0f; dim.y = 2.0f/128.0f;
auto renderer = m_engine->GetDevice()->GetUIRenderer();
if ( bOut ) // outside the map? if ( bOut ) // outside the map?
{ {
if ( color == MAPCOLOR_BBOX && !m_bRadar ) return; if ( color == MAPCOLOR_BBOX && !m_bRadar ) return;
@ -561,8 +573,10 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
return; // flashes return; // flashes
} }
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
if ( bUp ) if ( bUp )
{ {
uv1.x = 160.5f/256.0f; // yellow triangle ^ uv1.x = 160.5f/256.0f; // yellow triangle ^
@ -704,8 +718,10 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
{ {
if ( bSelect ) if ( bSelect )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
if ( m_bToy ) if ( m_bToy )
{ {
uv1.x = 164.5f/256.0f; // black pentagon uv1.x = 164.5f/256.0f; // black pentagon
@ -730,8 +746,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
{ {
if ( m_bRadar ) if ( m_bRadar )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
renderer->SetTexture(texture);
uv1.x = 64.5f/256.0f; // blue triangle uv1.x = 64.5f/256.0f; // blue triangle
uv1.y = 240.5f/256.0f; uv1.y = 240.5f/256.0f;
uv2.x = 79.0f/256.0f; uv2.x = 79.0f/256.0f;
@ -750,8 +767,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
if ( color == MAPCOLOR_WAYPOINTb ) if ( color == MAPCOLOR_WAYPOINTb )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 192.5f/256.0f; // blue cross uv1.x = 192.5f/256.0f; // blue cross
uv1.y = 240.5f/256.0f; uv1.y = 240.5f/256.0f;
uv2.x = 207.0f/256.0f; uv2.x = 207.0f/256.0f;
@ -760,8 +778,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
} }
if ( color == MAPCOLOR_WAYPOINTr ) if ( color == MAPCOLOR_WAYPOINTr )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 208.5f/256.0f; // red cross uv1.x = 208.5f/256.0f; // red cross
uv1.y = 240.5f/256.0f; uv1.y = 240.5f/256.0f;
uv2.x = 223.0f/256.0f; uv2.x = 223.0f/256.0f;
@ -770,8 +789,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
} }
if ( color == MAPCOLOR_WAYPOINTg ) if ( color == MAPCOLOR_WAYPOINTg )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 224.5f/256.0f; // green cross uv1.x = 224.5f/256.0f; // green cross
uv1.y = 240.5f/256.0f; uv1.y = 240.5f/256.0f;
uv2.x = 239.0f/256.0f; uv2.x = 239.0f/256.0f;
@ -780,8 +800,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
} }
if ( color == MAPCOLOR_WAYPOINTy ) if ( color == MAPCOLOR_WAYPOINTy )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 240.5f/256.0f; // yellow cross uv1.x = 240.5f/256.0f; // yellow cross
uv1.y = 240.5f/256.0f; uv1.y = 240.5f/256.0f;
uv2.x = 255.0f/256.0f; uv2.x = 255.0f/256.0f;
@ -790,8 +811,9 @@ void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, Map
} }
if ( color == MAPCOLOR_WAYPOINTv ) if ( color == MAPCOLOR_WAYPOINTv )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 192.5f/256.0f; // violet cross uv1.x = 192.5f/256.0f; // violet cross
uv1.y = 224.5f/256.0f; uv1.y = 224.5f/256.0f;
uv2.x = 207.0f/256.0f; uv2.x = 207.0f/256.0f;
@ -811,8 +833,12 @@ void CMap::DrawObjectIcon(const glm::vec2& pos, const glm::vec2& dim, MapColor c
dp = 0.5f/256.0f; dp = 0.5f/256.0f;
m_engine->SetUITexture("textures/interface/button3.png"); auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
auto texture = m_engine->LoadTexture("textures/interface/button3.png");
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
renderer->SetTexture(texture);
if ( color == MAPCOLOR_MOVE ) if ( color == MAPCOLOR_MOVE )
{ {
uv1.x = 160.0f/256.0f; // blue uv1.x = 160.0f/256.0f; // blue
@ -915,11 +941,15 @@ void CMap::DrawObjectIcon(const glm::vec2& pos, const glm::vec2& dim, MapColor c
case OBJECT_MOBILEit: case OBJECT_MOBILEit:
case OBJECT_MOBILErp: case OBJECT_MOBILErp:
case OBJECT_MOBILEst: case OBJECT_MOBILEst:
m_engine->SetUITexture("textures/interface/button4.png"); break; {
auto texture = m_engine->LoadTexture("textures/interface/button4.png");
renderer->SetTexture(texture);
break;
}
default: ; // button3.png default: ; // button3.png
} }
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = (32.0f/256.0f)*(icon%8); uv1.x = (32.0f/256.0f)*(icon%8);
uv1.y = (32.0f/256.0f)*(icon/8); uv1.y = (32.0f/256.0f)*(icon/8);
uv2.x = uv1.x+32.0f/256.0f; uv2.x = uv1.x+32.0f/256.0f;
@ -952,8 +982,12 @@ void CMap::DrawHighlight(const glm::vec2& position)
dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f; dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f;
dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f; dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f;
m_engine->SetUITexture("textures/interface/button2.png"); auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
auto texture = m_engine->LoadTexture("textures/interface/button2.png");
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
renderer->SetTexture(texture);
uv1.x = 160.5f/256.0f; // hilite uv1.x = 160.5f/256.0f; // hilite
uv1.y = 224.5f/256.0f; uv1.y = 224.5f/256.0f;
uv2.x = 175.0f/256.0f; uv2.x = 175.0f/256.0f;
@ -1090,9 +1124,13 @@ void CMap::UpdateTerrain()
} }
} }
auto renderer = m_engine->GetDevice()->GetUIRenderer();
m_engine->DeleteTexture("interface/map.png"); m_engine->DeleteTexture("interface/map.png");
m_engine->LoadTexture("textures/interface/map.png", &img); m_engine->LoadTexture("textures/interface/map.png", &img);
m_engine->SetUITexture("textures/interface/map.png");
auto texture = m_engine->LoadTexture("textures/interface/map.png");
renderer->SetTexture(texture);
} }
// Updates the field in the map. // Updates the field in the map.

View File

@ -24,6 +24,7 @@
#include "common/make_unique.h" #include "common/make_unique.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "ui/controls/button.h" #include "ui/controls/button.h"
@ -364,11 +365,13 @@ void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
float ex, dp; float ex, dp;
auto device = m_engine->GetDevice(); auto device = m_engine->GetDevice();
auto renderer = device->GetUIRenderer();
if ( icon == 0 ) if ( icon == 0 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 0.0f/256.0f; // yellow rectangle uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 32.0f/256.0f; uv2.x = 32.0f/256.0f;
@ -377,8 +380,9 @@ void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
} }
else if ( icon == 1 ) else if ( icon == 1 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f/256.0f; // gray rectangle uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -387,8 +391,9 @@ void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
} }
else if ( icon == 2 ) else if ( icon == 2 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f/256.0f; // blue rectangle uv1.x = 64.0f/256.0f; // blue rectangle
uv1.y = 0.0f/256.0f; uv1.y = 0.0f/256.0f;
uv2.x = 96.0f/256.0f; uv2.x = 96.0f/256.0f;
@ -397,8 +402,9 @@ void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
} }
else else
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 104.0f/256.0f; // blue line - uv1.x = 104.0f/256.0f; // blue line -
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 128.0f/256.0f; uv2.x = 128.0f/256.0f;

View File

@ -89,28 +89,28 @@ bool CShortcut::EventProcess(const Event &event)
void CShortcut::Draw() void CShortcut::Draw()
{ {
float zoom; float zoom;
int icon, mode; int icon;
icon = 0; icon = 0;
zoom = 0.8f; zoom = 0.8f;
mode = Gfx::ENG_RSTATE_TTEXTURE_WHITE; Gfx::TransparencyMode mode = Gfx::TransparencyMode::WHITE;
if ( m_state & STATE_HILIGHT ) if ( m_state & STATE_HILIGHT )
{ {
icon = 4; icon = 4;
zoom = 0.9f; zoom = 0.9f;
mode = Gfx::ENG_RSTATE_NORMAL; mode = Gfx::TransparencyMode::NONE;
} }
if ( m_state & STATE_CHECK ) if ( m_state & STATE_CHECK )
{ {
icon = 1; icon = 1;
zoom = 0.8f; zoom = 0.8f;
mode = Gfx::ENG_RSTATE_NORMAL; mode = Gfx::TransparencyMode::NONE;
} }
if ( m_state & STATE_PRESS ) if ( m_state & STATE_PRESS )
{ {
icon = 1; icon = 1;
zoom = 1.0f; zoom = 1.0f;
mode = Gfx::ENG_RSTATE_NORMAL; mode = Gfx::TransparencyMode::NONE;
} }
if ( m_icon == 128+6 || m_icon == 128+7 || m_icon == 58 ) // pause or film? if ( m_icon == 128+6 || m_icon == 128+7 || m_icon == 58 ) // pause or film?
{ {
@ -118,22 +118,25 @@ void CShortcut::Draw()
zoom = 1.0f; zoom = 1.0f;
} }
m_engine->SetUITexture("textures/interface/button3.png"); auto renderer = m_engine->GetDevice()->GetUIRenderer();
auto texture = m_engine->LoadTexture("textures/interface/button3.png");
renderer->SetTexture(texture);
if ( icon != -1 ) if ( icon != -1 )
{ {
m_engine->SetState(mode); renderer->SetTransparency(mode);
DrawVertex(icon, 0.95f); DrawVertex(icon, 0.95f);
} }
icon = SetButtonTextureForIcon(m_icon); icon = SetButtonTextureForIcon(m_icon);
if (m_icon == 58) if (m_icon == 58)
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
} }
else else
{ {
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
} }
DrawVertex(icon, zoom); DrawVertex(icon, zoom);
@ -142,8 +145,9 @@ void CShortcut::Draw()
glm::vec2 p1, p2, c, uv1, uv2; glm::vec2 p1, p2, c, uv1, uv2;
float dp; float dp;
m_engine->SetTexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
zoom = 0.9f+sinf(m_time*8.0f)*0.1f; zoom = 0.9f+sinf(m_time*8.0f)*0.1f;
@ -182,8 +186,9 @@ void CShortcut::Draw()
glm::vec2 uv1, uv2; glm::vec2 uv1, uv2;
float dp; float dp;
m_engine->SetTexture("textures/interface/button3.png"); auto texture = m_engine->LoadTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 160.0f/256.0f; uv1.x = 160.0f/256.0f;
uv1.y = 0.0f/256.0f; uv1.y = 0.0f/256.0f;
@ -203,8 +208,9 @@ void CShortcut::Draw()
glm::vec2 uv1, uv2; glm::vec2 uv1, uv2;
float dp; float dp;
m_engine->SetTexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 159.0f / 256.0f; uv1.x = 159.0f / 256.0f;
uv1.y = 240.0f / 256.0f; uv1.y = 240.0f / 256.0f;

View File

@ -24,6 +24,7 @@
#include "common/stringutils.h" #include "common/stringutils.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/engine/text.h" #include "graphics/engine/text.h"
@ -494,8 +495,9 @@ void CSlider::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
if ( icon == 0 ) if ( icon == 0 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 0.0f/256.0f; // yellow rectangle uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 32.0f/256.0f; uv2.x = 32.0f/256.0f;
@ -506,8 +508,9 @@ void CSlider::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
} }
else if ( icon == 1 ) else if ( icon == 1 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f/256.0f; // gray rectangle uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -518,8 +521,9 @@ void CSlider::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon)
} }
else else
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 224.0f/256.0f; // cursor uv1.x = 224.0f/256.0f; // cursor
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 256.0f/256.0f; uv2.x = 256.0f/256.0f;

View File

@ -39,6 +39,7 @@
#include "ui/controls/target.h" #include "ui/controls/target.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include <algorithm> #include <algorithm>
@ -906,13 +907,15 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
glm::vec2 dim = dimension; glm::vec2 dim = dimension;
auto device = m_engine->GetDevice(); auto device = m_engine->GetDevice();
auto renderer = device->GetUIRenderer();
dp = 0.5f/256.0f; dp = 0.5f/256.0f;
if ( icon == 0 ) if ( icon == 0 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 64.0f/256.0f; // dark blue transparent uv1.x = 64.0f/256.0f; // dark blue transparent
uv1.y = 64.0f/256.0f; uv1.y = 64.0f/256.0f;
uv2.x = 128.0f/256.0f; uv2.x = 128.0f/256.0f;
@ -927,8 +930,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 1 ) else if ( icon == 1 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f/256.0f; // white tooltip uv1.x = 128.0f/256.0f; // white tooltip
uv1.y = 0.0f/256.0f; uv1.y = 0.0f/256.0f;
uv2.x = 224.0f/256.0f; uv2.x = 224.0f/256.0f;
@ -941,8 +945,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 2 ) else if ( icon == 2 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f/256.0f; // yellow uv1.x = 128.0f/256.0f; // yellow
uv1.y = 16.0f/256.0f; uv1.y = 16.0f/256.0f;
uv2.x = 224.0f/256.0f; uv2.x = 224.0f/256.0f;
@ -955,8 +960,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 3 ) else if ( icon == 3 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper
uv1.y = 64.0f/256.0f; uv1.y = 64.0f/256.0f;
uv2.x = 64.0f/256.0f; uv2.x = 64.0f/256.0f;
@ -974,8 +980,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
dim.x += 100.0f/640.0f; dim.x += 100.0f/640.0f;
dim.y += 60.0f/480.0f; dim.y += 60.0f/480.0f;
m_engine->SetUITexture("textures/object/human.png"); auto texture = m_engine->LoadTexture("textures/interface/human.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 140.0f/256.0f; uv1.x = 140.0f/256.0f;
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 182.0f/256.0f; uv2.x = 182.0f/256.0f;
@ -991,8 +998,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
dim.x -= 20.0f/640.0f; dim.x -= 20.0f/640.0f;
dim.y += 0.0f/480.0f; dim.y += 0.0f/480.0f;
m_engine->SetUITexture("textures/interface/button2.png"); texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::WHITE);
uv1.x = 192.0f/256.0f; uv1.x = 192.0f/256.0f;
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 224.0f/256.0f; uv2.x = 224.0f/256.0f;
@ -1010,8 +1018,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
dim.x -= 20.0f/640.0f; dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f; dim.y -= 20.0f/480.0f;
m_engine->SetUITexture("textures/interface/button1.png"); texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f/256.0f; uv1.x = 64.0f/256.0f;
uv1.y = 0.0f/256.0f; uv1.y = 0.0f/256.0f;
uv2.x = 96.0f/256.0f; uv2.x = 96.0f/256.0f;
@ -1046,7 +1055,8 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
dim.x -= 20.0f/640.0f; dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f; dim.y -= 20.0f/480.0f;
m_engine->SetUITexture("textures/interface/button3.png"); texture = m_engine->LoadTexture("textures/interface/button3.png");
renderer->SetTexture(texture);
uv1.x = 0.0f/256.0f; uv1.x = 0.0f/256.0f;
uv1.y = 224.0f/256.0f; uv1.y = 224.0f/256.0f;
uv2.x = 32.0f/256.0f; uv2.x = 32.0f/256.0f;
@ -1057,7 +1067,8 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); // dark blue background DrawIcon(pos, dim, uv1, uv2); // dark blue background
m_engine->SetUITexture("textures/interface/button2.png"); texture = m_engine->LoadTexture("textures/interface/button2.png");
renderer->SetTexture(texture);
uv1.x = 224.0f/256.0f; uv1.x = 224.0f/256.0f;
uv1.y = 224.0f/256.0f; uv1.y = 224.0f/256.0f;
uv2.x = 249.0f/256.0f; uv2.x = 249.0f/256.0f;
@ -1129,8 +1140,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 5 ) else if ( icon == 5 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f/256.0f; // transparent green uv1.x = 64.0f/256.0f; // transparent green
uv1.y = 160.0f/256.0f; uv1.y = 160.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -1143,8 +1155,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 6 ) else if ( icon == 6 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f/256.0f; // transparent red uv1.x = 64.0f/256.0f; // transparent red
uv1.y = 176.0f/256.0f; uv1.y = 176.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -1157,8 +1170,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 7 ) else if ( icon == 7 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f/256.0f; // transparent blue uv1.x = 64.0f/256.0f; // transparent blue
uv1.y = 192.0f/256.0f; uv1.y = 192.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -1171,8 +1185,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 8 ) else if ( icon == 8 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 0.0f/256.0f; // opaque orange uv1.x = 0.0f/256.0f; // opaque orange
uv1.y = 0.0f/256.0f; uv1.y = 0.0f/256.0f;
uv2.x = 32.0f/256.0f; uv2.x = 32.0f/256.0f;
@ -1187,8 +1202,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 9 ) else if ( icon == 9 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 32.0f/256.0f; // opaque gray uv1.x = 32.0f/256.0f; // opaque gray
uv1.y = 32.0f/256.0f; uv1.y = 32.0f/256.0f;
uv2.x = 64.0f/256.0f; uv2.x = 64.0f/256.0f;
@ -1207,8 +1223,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 11 ) else if ( icon == 11 )
{ {
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::BLACK);
uv1.x = 64.0f/256.0f; // transparent yellow uv1.x = 64.0f/256.0f; // transparent yellow
uv1.y = 224.0f/256.0f; uv1.y = 224.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -1221,8 +1238,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 12 ) else if ( icon == 12 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 128.0f/256.0f; // dirty opaque gray uv1.x = 128.0f/256.0f; // dirty opaque gray
uv1.y = 128.0f/256.0f; uv1.y = 128.0f/256.0f;
uv2.x = 160.0f/256.0f; uv2.x = 160.0f/256.0f;
@ -1237,8 +1255,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 13 ) else if ( icon == 13 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 192.0f/256.0f; // dirty opaque blue uv1.x = 192.0f/256.0f; // dirty opaque blue
uv1.y = 128.0f/256.0f; uv1.y = 128.0f/256.0f;
uv2.x = 224.0f/256.0f; uv2.x = 224.0f/256.0f;
@ -1253,8 +1272,9 @@ void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension,
} }
else if ( icon == 14 ) else if ( icon == 14 )
{ {
m_engine->SetUITexture("textures/interface/button1.png"); auto texture = m_engine->LoadTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 160.0f/256.0f; // dirty opaque red uv1.x = 160.0f/256.0f; // dirty opaque red
uv1.y = 128.0f/256.0f; uv1.y = 128.0f/256.0f;
uv2.x = 192.0f/256.0f; uv2.x = 192.0f/256.0f;
@ -1278,10 +1298,12 @@ void CWindow::DrawHach(const glm::vec2& pos, const glm::vec2& dim)
bool bStop; bool bStop;
auto device = m_engine->GetDevice(); auto device = m_engine->GetDevice();
auto renderer = device->GetUIRenderer();
dp = 0.5f/256.0f; dp = 0.5f/256.0f;
m_engine->SetUITexture("textures/interface/button2.png"); auto texture = m_engine->LoadTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); renderer->SetTexture(texture);
renderer->SetTransparency(Gfx::TransparencyMode::NONE);
uv1.x = 64.0f/256.0f; // hatching uv1.x = 64.0f/256.0f; // hatching
uv1.y = 208.0f/256.0f; uv1.y = 208.0f/256.0f;
uv2.x = 145.0f/256.0f; uv2.x = 145.0f/256.0f;

View File

@ -156,7 +156,7 @@ void CMainUserInterface::ChangePhase(Phase phase)
{ {
m_main->GetCamera()->SetType(Gfx::CAM_TYPE_NULL); m_main->GetCamera()->SetType(Gfx::CAM_TYPE_NULL);
m_engine->SetOverFront(false); m_engine->SetOverFront(false);
m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok? m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::TransparencyMode::BLACK); // TODO: color ok?
m_phase = phase; // copy the info from CRobotMain m_phase = phase; // copy the info from CRobotMain

View File

@ -58,9 +58,9 @@ void CScreenWelcome::CreateInterface()
m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5); m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5);
if ( m_imageIndex == 0 ) if ( m_imageIndex == 0 )
m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::TransparencyMode::BLACK);
else else
m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::TransparencyMode::WHITE);
m_engine->SetOverFront(true); m_engine->SetOverFront(true);
SetBackground("textures/interface/intro"+StrUtils::ToString<int>(m_imageIndex+1)+".png", true); SetBackground("textures/interface/intro"+StrUtils::ToString<int>(m_imageIndex+1)+".png", true);
@ -96,11 +96,11 @@ bool CScreenWelcome::EventProcess(const Event &event)
if ( intensity > 1.0f ) intensity = 1.0f; if ( intensity > 1.0f ) intensity = 1.0f;
// white first, others -> black fading // white first, others -> black fading
int mode = Gfx::ENG_RSTATE_TCOLOR_WHITE; Gfx::TransparencyMode mode = Gfx::TransparencyMode::WHITE;
if ((m_imageIndex == 0) && (m_time < WELCOME_LENGTH/2.0f)) if ((m_imageIndex == 0) && (m_time < WELCOME_LENGTH/2.0f))
{ {
intensity = 1.0f - intensity; intensity = 1.0f - intensity;
mode = Gfx::ENG_RSTATE_TCOLOR_BLACK; mode = Gfx::TransparencyMode::BLACK;
} }
m_engine->SetOverColor(Gfx::Color(intensity, intensity, intensity, intensity), mode); m_engine->SetOverColor(Gfx::Color(intensity, intensity, intensity, intensity), mode);