Removed all dependency on interface rendering mode

dev
Tomasz Kapuściński 2021-07-03 13:21:23 +02:00
parent 465fe59dfb
commit 16200bbeac
17 changed files with 39 additions and 68 deletions

View File

@ -378,6 +378,9 @@ public:
//! Returns UI renderer //! Returns UI renderer
virtual CUIRenderer* GetUIRenderer() = 0; virtual CUIRenderer* GetUIRenderer() = 0;
//! Restores device rendering mode
virtual void Restore() = 0;
//! Sets the transform matrix of given type //! Sets the transform matrix of given type
virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0; virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0;

View File

@ -359,7 +359,6 @@ bool CEngine::Create()
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f); renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
@ -3651,8 +3650,6 @@ void CEngine::DrawCaptured3DScene()
renderer->SetTexture(m_capturedWorldTexture); renderer->SetTexture(m_capturedWorldTexture);
renderer->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, 4, vertices); renderer->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, 4, vertices);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& transform, const Gfx::Color& color) void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix& transform, const Gfx::Color& color)
@ -4114,7 +4111,7 @@ void CEngine::DrawObject(const EngineBaseObjDataTier& p4)
void CEngine::DrawInterface() void CEngine::DrawInterface()
{ {
m_device->SetRenderMode(RENDER_MODE_INTERFACE); m_device->SetRenderMode(RENDER_MODE_NORMAL);
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
m_device->SetRenderState(RENDER_STATE_LIGHTING, false); m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
@ -4219,7 +4216,7 @@ void CEngine::DrawInterface()
m_device->SetRenderState(RENDER_STATE_LIGHTING, false); m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
m_device->SetRenderState(RENDER_STATE_FOG, false); m_device->SetRenderState(RENDER_STATE_FOG, false);
m_device->SetRenderMode(RENDER_MODE_INTERFACE); m_device->SetRenderMode(RENDER_MODE_NORMAL);
SetInterfaceCoordinates(); SetInterfaceCoordinates();
} }
@ -4750,7 +4747,7 @@ void CEngine::DrawShadowSpots()
void CEngine::DrawBackground() void CEngine::DrawBackground()
{ {
m_device->SetRenderMode(RENDER_MODE_INTERFACE); m_device->SetRenderMode(RENDER_MODE_NORMAL);
if (m_cloud->GetLevel() != 0.0f) // clouds ? if (m_cloud->GetLevel() != 0.0f) // clouds ?
{ {
@ -4879,8 +4876,6 @@ void CEngine::DrawBackgroundImage()
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4);
AddStatisticTriangle(2); AddStatisticTriangle(2);
m_device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
void CEngine::DrawPlanet() void CEngine::DrawPlanet()
@ -4927,7 +4922,7 @@ void CEngine::DrawForegroundImage()
SetTexture(m_foregroundTex); SetTexture(m_foregroundTex);
SetState(ENG_RSTATE_CLAMP | ENG_RSTATE_TTEXTURE_BLACK); SetState(ENG_RSTATE_CLAMP | ENG_RSTATE_TTEXTURE_BLACK);
m_device->SetRenderMode(RENDER_MODE_INTERFACE); m_device->SetRenderMode(RENDER_MODE_NORMAL);
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
@ -4935,8 +4930,6 @@ void CEngine::DrawForegroundImage()
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
AddStatisticTriangle(2); AddStatisticTriangle(2);
m_device->SetRenderMode(RENDER_MODE_NORMAL);
} }
void CEngine::DrawOverColor() void CEngine::DrawOverColor()
@ -4955,7 +4948,7 @@ void CEngine::DrawOverColor()
Color(0.0f, 0.0f, 0.0f, 0.0f) Color(0.0f, 0.0f, 0.0f, 0.0f)
}; };
m_device->SetRenderMode(RENDER_MODE_INTERFACE); m_device->SetRenderMode(RENDER_MODE_NORMAL);
SetState(m_overMode); SetState(m_overMode);
@ -5136,8 +5129,6 @@ void CEngine::DrawMouseSprite(Math::IntPoint pos, Math::IntPoint size, int icon)
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
AddStatisticTriangle(2); AddStatisticTriangle(2);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::DrawStats() void CEngine::DrawStats()
@ -5241,8 +5232,6 @@ void CEngine::DrawStats()
std::stringstream str; std::stringstream str;
str << std::fixed << std::setprecision(2) << m_statisticPos.x << "; " << m_statisticPos.z; str << std::fixed << std::setprecision(2) << m_statisticPos.x << "; " << m_statisticPos.z;
drawStatsLine( "Position", str.str(), ""); drawStatsLine( "Position", str.str(), "");
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::DrawTimer() void CEngine::DrawTimer()
@ -5251,8 +5240,6 @@ void CEngine::DrawTimer()
Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COMMON, 15.0f)); Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COMMON, 15.0f));
m_text->DrawText(m_timerText, FONT_COMMON, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); m_text->DrawText(m_timerText, FONT_COMMON, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector<Gfx::ModelTriangle>& triangles) void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector<Gfx::ModelTriangle>& triangles)
@ -5540,8 +5527,6 @@ void CEngine::SetInterfaceCoordinates()
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f); renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::EnablePauseBlur() void CEngine::EnablePauseBlur()
@ -5575,8 +5560,6 @@ void CEngine::SetWindowCoordinates()
auto renderer = m_device->GetUIRenderer(); auto renderer = m_device->GetUIRenderer();
renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f); renderer->SetProjection(0.0f, m_size.x, m_size.y, 0.0f);
m_device->SetRenderMode(RENDER_MODE_INTERFACE);
} }
void CEngine::SetUITexture(const std::string& name) void CEngine::SetUITexture(const std::string& name)

View File

@ -157,7 +157,6 @@ public:
} }
m_engine.GetDevice()->GetUIRenderer()->Flush(); m_engine.GetDevice()->GetUIRenderer()->Flush();
m_engine.GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
//const Vertex* vertices = m_quads.front().vertices; //const Vertex* vertices = m_quads.front().vertices;
//m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(), //m_engine.GetDevice()->DrawPrimitives(PRIMITIVE_TRIANGLE_STRIP, vertices, m_firsts.data(),

View File

@ -514,7 +514,7 @@ bool CGL33Device::Create()
glUniform1f(uni.alphaReference, 1.0f); glUniform1f(uni.alphaReference, 1.0f);
} }
m_uiRenderer = std::make_unique<CGL33UIRenderer>(); m_uiRenderer = std::make_unique<CGL33UIRenderer>(this);
SetRenderMode(RENDER_MODE_NORMAL); SetRenderMode(RENDER_MODE_NORMAL);
@ -609,6 +609,8 @@ void CGL33Device::BeginScene()
void CGL33Device::EndScene() void CGL33Device::EndScene()
{ {
m_uiRenderer->Flush();
#ifdef DEV_BUILD #ifdef DEV_BUILD
CheckGLErrors(); CheckGLErrors();
#endif #endif
@ -655,6 +657,22 @@ CUIRenderer* CGL33Device::GetUIRenderer()
return m_uiRenderer.get(); return m_uiRenderer.get();
} }
void CGL33Device::Restore()
{
switch (m_mode)
{
case 0:
glUseProgram(m_normalProgram);
break;
case 1:
glUseProgram(m_interfaceProgram);
break;
case 2:
glUseProgram(m_shadowProgram);
break;
}
}
void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix) void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
{ {
if (type == TRANSFORM_WORLD) if (type == TRANSFORM_WORLD)

View File

@ -94,6 +94,8 @@ public:
void SetRenderMode(RenderMode mode) override; void SetRenderMode(RenderMode mode) override;
CUIRenderer* GetUIRenderer() override; CUIRenderer* GetUIRenderer() override;
void Restore() override;
void SetTransform(TransformType type, const Math::Matrix &matrix) override; void SetTransform(TransformType type, const Math::Matrix &matrix) override;
void SetMaterial(const Material &material) override; void SetMaterial(const Material &material) override;

View File

@ -1,5 +1,6 @@
#include "graphics/opengl/gl33renderers.h" #include "graphics/opengl/gl33renderers.h"
#include "graphics/opengl/gl33device.h"
#include "graphics/opengl/glutil.h" #include "graphics/opengl/glutil.h"
#include "graphics/core/vertex.h" #include "graphics/core/vertex.h"
@ -13,7 +14,8 @@
namespace Gfx namespace Gfx
{ {
CGL33UIRenderer::CGL33UIRenderer() CGL33UIRenderer::CGL33UIRenderer(CGL33Device* device)
: m_device(device)
{ {
GLint shaders[2]; GLint shaders[2];
@ -95,7 +97,7 @@ void CGL33UIRenderer::SetProjection(float left, float right, float bottom, float
glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix)); glUniformMatrix4fv(m_projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
glUseProgram(0); m_device->Restore();
} }
void CGL33UIRenderer::SetTexture(const Texture& texture) void CGL33UIRenderer::SetTexture(const Texture& texture)
@ -166,9 +168,6 @@ void CGL33UIRenderer::Flush()
// Draw primitives by grouping by type // Draw primitives by grouping by type
for (size_t i = 0; i < m_types.size(); i++) for (size_t i = 0; i < m_types.size(); i++)
{ {
//glDrawArrays(m_types[i], m_firsts[i], m_counts[i]);
//*
size_t count = 1; size_t count = 1;
for (; i + count < m_types.size(); count++) for (; i + count < m_types.size(); count++)
@ -180,7 +179,6 @@ void CGL33UIRenderer::Flush()
glMultiDrawArrays(m_types[i], &m_firsts[i], &m_counts[i], count); glMultiDrawArrays(m_types[i], &m_firsts[i], &m_counts[i], count);
i += count; i += count;
// */
} }
// Clear buffers // Clear buffers
@ -189,7 +187,7 @@ void CGL33UIRenderer::Flush()
m_firsts.clear(); m_firsts.clear();
m_counts.clear(); m_counts.clear();
glUseProgram(0); m_device->Restore();
} }
} // namespace Gfx } // namespace Gfx

View File

@ -35,10 +35,12 @@
namespace Gfx namespace Gfx
{ {
class CGL33Device;
class CGL33UIRenderer : public CUIRenderer class CGL33UIRenderer : public CUIRenderer
{ {
public: public:
CGL33UIRenderer(); CGL33UIRenderer(CGL33Device* device);
virtual ~CGL33UIRenderer(); virtual ~CGL33UIRenderer();
virtual void SetProjection(float left, float right, float bottom, float top) override; virtual void SetProjection(float left, float right, float bottom, float top) override;
@ -49,6 +51,8 @@ public:
virtual void Flush() override; virtual void Flush() override;
private: private:
CGL33Device* const m_device;
// location of uni_ProjectionMatrix uniform // location of uni_ProjectionMatrix uniform
GLint m_projectionMatrix = -1; GLint m_projectionMatrix = -1;

View File

@ -202,8 +202,6 @@ void CButton::Draw()
pos.x = m_pos.x + m_dim.x - 5.0f / 640.0f - 3.0f / 640.0f; pos.x = m_pos.x + m_dim.x - 5.0f / 640.0f - 3.0f / 640.0f;
DrawIcon(pos, dim, uv1, uv2, 0.0f); DrawIcon(pos, dim, uv1, uv2, 0.0f);
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }

View File

@ -149,8 +149,6 @@ void CCheck::Draw()
} }
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
m_dim = iDim; m_dim = iDim;
// Draw the name. // Draw the name.

View File

@ -160,8 +160,6 @@ void CColor::Draw()
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
m_engine->AddStatisticTriangle(2); m_engine->AddStatisticTriangle(2);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
void CColor::SetRepeat(bool bRepeat) void CColor::SetRepeat(bool bRepeat)

View File

@ -556,8 +556,6 @@ void CControl::Draw()
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0); m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0);
} }
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draw the vertex array. // Draw the vertex array.
@ -666,8 +664,6 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
m_engine->AddStatisticTriangle(6); m_engine->AddStatisticTriangle(6);
} }
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draws a rectangular icon made up of 9 pieces. // Draws a rectangular icon made up of 9 pieces.
@ -735,8 +731,6 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math:
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8); device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 8);
m_engine->AddStatisticTriangle(6); m_engine->AddStatisticTriangle(6);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draw round the hatch of a button. // Draw round the hatch of a button.
@ -782,8 +776,6 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim)
pos.x += dim.x; pos.x += dim.x;
DrawIcon(pos, dim, uv1, uv2); DrawIcon(pos, dim, uv1, uv2);
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draw the shade under a button. // Draw the shade under a button.
@ -818,8 +810,6 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep)
corner.y = 10.0f / 480.0f; corner.y = 10.0f / 480.0f;
DrawIcon(pos, dim, uv1, uv2, corner, 6.0f / 256.0f); DrawIcon(pos, dim, uv1, uv2, corner, 6.0f / 256.0f);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }

View File

@ -1155,8 +1155,6 @@ void CEdit::Draw()
{ {
m_scroll->Draw(); m_scroll->Draw();
} }
m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draw an image part. // Draw an image part.

View File

@ -646,8 +646,6 @@ void CGroup::Draw()
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); DrawIcon(pos, dim, uv1, uv2);
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }

View File

@ -354,8 +354,6 @@ void CScroll::Draw()
{ {
m_buttonDown->Draw(); m_buttonDown->Draw();
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draws a rectangle. // Draws a rectangle.

View File

@ -216,8 +216,6 @@ void CShortcut::Draw()
DrawIcon(m_pos, m_dim, uv1, uv2); DrawIcon(m_pos, m_dim, uv1, uv2);
} }
m_engine->GetDevice()->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draw the vertex array. // Draw the vertex array.

View File

@ -475,8 +475,6 @@ void CSlider::Draw()
m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0); m_engine->GetText()->DrawText(text, m_fontType, m_fontSize, pos, dim.x, Gfx::TEXT_ALIGN_RIGHT, 0);
} }
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
std::string CSlider::GetLabel() std::string CSlider::GetLabel()
@ -543,8 +541,6 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
uv2.y -= dp; uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2, corner, ex); DrawIcon(pos, dim, uv1, uv2, corner, ex);
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }

View File

@ -866,8 +866,6 @@ void CWindow::Draw()
DrawHach(pos, dim); // right hatch DrawHach(pos, dim); // right hatch
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
pos.x = m_pos.x+width/2.0f; pos.x = m_pos.x+width/2.0f;
pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f; pos.y = m_pos.y+m_dim.y-0.01f-h*1.10f;
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0); m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, width, Gfx::TEXT_ALIGN_CENTER, 0);
@ -892,8 +890,6 @@ void CWindow::Draw()
{ {
control->Draw(); control->Draw();
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draws a rectangle. // Draws a rectangle.
@ -1266,8 +1262,6 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
corner.y = 6.0f/480.0f; corner.y = 6.0f/480.0f;
DrawIcon(pos, dim, uv1, uv2, corner, 5.0f/256.0f); DrawIcon(pos, dim, uv1, uv2, corner, 5.0f/256.0f);
} }
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
// Draws hatching. // Draws hatching.
@ -1312,8 +1306,6 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim)
ppos.x += ddim.x; ppos.x += ddim.x;
} }
while ( !bStop ); while ( !bStop );
device->SetRenderMode(Gfx::RENDER_MODE_INTERFACE);
} }
void CWindow::SetFocus(CControl* focusControl) void CWindow::SetFocus(CControl* focusControl)