Some refactors to reduce extensive recompilation cascades

Renamed AlphaMode::OPAQUE to AlphaMode::NONE due to clash with preprocessor define
Moved Gfx::EngineTriangle to a separate file
dev
Tomasz Kapuściński 2022-02-26 02:39:13 +01:00
parent e839f0dec7
commit baa616050a
42 changed files with 174 additions and 98 deletions

View File

@ -95,6 +95,7 @@ add_library(colobotbase STATIC
graphics/core/material.h
graphics/core/texture.h
graphics/core/transparency.h
graphics/core/triangle.h
graphics/core/type.cpp
graphics/core/type.h
graphics/core/renderers.h

View File

@ -26,7 +26,6 @@
#include "graphics/core/color.h"
#include "graphics/core/texture.h"
#include "graphics/core/transparency.h"
#include "graphics/core/vertex.h"
#include <glm/glm.hpp>
@ -59,6 +58,7 @@ struct VertexCol;
struct Vertex3D;
enum class CullFace : unsigned char;
enum class TransparencyMode : unsigned char;
/**
* \struct DeviceConfig

View File

@ -65,7 +65,7 @@ struct Material
//! Normal map
std::string normalTexture = "";
//! Alpha mode
AlphaMode alphaMode = AlphaMode::OPAQUE;
AlphaMode alphaMode = AlphaMode::NONE;
//! Alpha threshold
float alphaThreshold = 0.0;
// Cull face

View File

@ -24,7 +24,6 @@
#pragma once
#include "graphics/core/transparency.h"
#include "graphics/core/vertex.h"
#include <glm/glm.hpp>
@ -36,6 +35,7 @@ namespace Gfx
class CVertexBuffer;
enum class CullFace : unsigned char;
enum class PrimitiveType : unsigned char;
enum class TransparencyMode : unsigned char;
struct Texture;
struct ShadowParam

View File

@ -40,7 +40,7 @@ enum class TransparencyMode : unsigned char
//! Alpha transparency mode
enum class AlphaMode : unsigned char
{
OPAQUE, // opaque material
NONE, // opaque material
MASK, // alpha scissor with threshold
BLEND, // alpha blending
};

View File

@ -0,0 +1,46 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/core/triangle.h
* \brief Triangle struct
*/
#pragma once
#include "graphics/core/material.h"
#include "graphics/core/vertex.h"
// Graphics module namespace
namespace Gfx
{
/**
* \struct EngineTriangle
* \brief A triangle drawn by the graphics engine
*/
struct EngineTriangle
{
//! Triangle vertices
Vertex3D triangle[3];
//! Triangle material
Material material;
};
} // namespace Gfx

View File

@ -25,6 +25,8 @@
#include "common/event.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
@ -582,7 +584,7 @@ void CCamera::FlushOver()
{
m_overType = CAM_OVER_EFFECT_NULL;
m_overColorBase = Color(0.0f, 0.0f, 0.0f, 0.0f); // black
m_engine->SetOverColor(); // nothing
m_engine->SetOverColor(Color(), TransparencyMode::BLACK); // nothing
}
void CCamera::SetOverBaseColor(Color color)

View File

@ -37,6 +37,7 @@ struct Event;
namespace Gfx
{
enum class TransparencyMode : unsigned char;
/**
\enum CameraType

View File

@ -22,6 +22,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h"

View File

@ -34,7 +34,9 @@
#include "graphics/core/device.h"
#include "graphics/core/framebuffer.h"
#include "graphics/core/material.h"
#include "graphics/core/renderers.h"
#include "graphics/core/triangle.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
@ -70,6 +72,56 @@ using TimeUtils::TimeUnit;
namespace Gfx
{
/**
* \struct EngineBaseObjDataTier
* \brief Tier 3 of object tree (data)
*/
struct EngineBaseObjDataTier
{
EngineTriangleType type = EngineTriangleType::TRIANGLES;
Material material = {};
std::vector<Vertex3D> vertices;
CVertexBuffer* buffer = nullptr;
bool updateStaticBuffer = false;
Texture albedoTexture;
Texture emissiveTexture;
Texture materialTexture;
Texture normalTexture;
Texture detailTexture;
glm::vec2 uvOffset = { 0.0f, 0.0f };
glm::vec2 uvScale = { 1.0f, 1.0f };
};
/**
* \struct BaseEngineObject
* \brief Base (template) object - geometry for engine objects
*
* This is also the tier 1 of base object tree.
*/
struct EngineBaseObject
{
//! If true, base object is valid in objects vector
bool used = false;
//! Number of triangles
int totalTriangles = 0;
//! Bounding box min (origin 0,0,0 always included)
glm::vec3 bboxMin{ 0, 0, 0 };
//! bounding box max (origin 0,0,0 always included)
glm::vec3 bboxMax{ 0, 0, 0 };
//! A bounding sphere that contains all the vertices in this EngineBaseObject
Math::Sphere boundingSphere;
//! Next tier
std::vector<EngineBaseObjDataTier> next;
inline void LoadDefault()
{
*this = EngineBaseObject();
}
};
/**
* \struct EngineMouse
* \brief Information about mouse cursor
@ -237,7 +289,6 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
Math::LoadTranslationMatrix(temp2, glm::vec3(1.0f, 1.0f, 1.0f));
m_shadowBias = temp1 * temp2;
m_lastState = -1;
m_statisticTriangle = 0;
m_fps = 0.0f;
m_firstGroundSpot = false;
@ -2592,9 +2643,6 @@ void CEngine::Render()
return;
m_statisticTriangle = 0;
m_lastState = -1;
m_lastColor = Color(-1.0f);
m_lastMaterial = Material();
m_lightMan->UpdateLights();
@ -2824,7 +2872,7 @@ void CEngine::Draw3DScene()
continue;
}
if (data.material.alphaMode != AlphaMode::OPAQUE)
if (data.material.alphaMode != AlphaMode::NONE)
{
objectRenderer->SetAlphaScissor(data.material.alphaThreshold);
}
@ -3450,7 +3498,6 @@ void CEngine::DrawInterface()
// Force new state to disable lighting
m_interfaceMode = true;
m_lastState = -1;
// Draw the entire interface
Ui::CInterface* interface = CRobotMain::GetInstancePointer()->GetInterface();
@ -3460,7 +3507,6 @@ void CEngine::DrawInterface()
}
m_interfaceMode = false;
m_lastState = -1;
if (!m_screenshotMode && m_renderInterface)
{

View File

@ -28,7 +28,6 @@
#include "common/system/system.h"
#include "graphics/core/color.h"
#include "graphics/core/material.h"
#include "graphics/core/texture.h"
#include "graphics/core/renderers.h"
#include "graphics/core/vertex.h"
@ -69,9 +68,14 @@ class CTerrain;
class CPyroManager;
class CModelMesh;
class CVertexBuffer;
struct EngineBaseObjDataTier;
struct EngineBaseObject;
struct EngineTriangle;
struct Material;
struct ModelShadowSpot;
struct ModelTriangle;
enum class TransparencyMode : unsigned char;
/**
* \enum EngineTriangleType
@ -85,18 +89,6 @@ enum class EngineTriangleType
SURFACE = 2
};
/**
* \struct EngineTriangle
* \brief A triangle drawn by the graphics engine
*/
struct EngineTriangle
{
//! Triangle vertices
Vertex3D triangle[3];
//! Triangle material
Material material;
};
/**
\enum EngineObjectType
\brief Class of graphics engine object */
@ -118,57 +110,6 @@ enum EngineObjectType
ENG_OBJTYPE_METAL = 6
};
/**
* \struct EngineBaseObjDataTier
* \brief Tier 3 of object tree (data)
*/
struct EngineBaseObjDataTier
{
EngineTriangleType type = EngineTriangleType::TRIANGLES;
Material material = {};
std::vector<Vertex3D> vertices;
CVertexBuffer* buffer = nullptr;
bool updateStaticBuffer = false;
Texture albedoTexture;
Texture emissiveTexture;
Texture materialTexture;
Texture normalTexture;
Texture detailTexture;
glm::vec2 uvOffset = { 0.0f, 0.0f };
glm::vec2 uvScale = { 1.0f, 1.0f };
};
/**
* \struct BaseEngineObject
* \brief Base (template) object - geometry for engine objects
*
* This is also the tier 1 of base object tree.
*/
struct EngineBaseObject
{
//! If true, base object is valid in objects vector
bool used = false;
//! Number of triangles
int totalTriangles = 0;
//! Bounding box min (origin 0,0,0 always included)
glm::vec3 bboxMin{ 0, 0, 0 };
//! bounding box max (origin 0,0,0 always included)
glm::vec3 bboxMax{ 0, 0, 0 };
//! A bounding sphere that contains all the vertices in this EngineBaseObject
Math::Sphere boundingSphere;
//! Next tier
std::vector<EngineBaseObjDataTier> next;
inline void LoadDefault()
{
*this = EngineBaseObject();
}
};
/**
* \struct EngineObject
* \brief Object drawn by the graphics engine
@ -875,7 +816,7 @@ public:
//! Specifies whether to draw the foreground
void SetOverFront(bool front);
//! Sets the foreground overlay color
void SetOverColor(const Color& color = Color(), TransparencyMode mode = TransparencyMode::BLACK);
void SetOverColor(const Color& color, TransparencyMode mode);
//@{
//! Management of the particle density
@ -1335,15 +1276,6 @@ protected:
//! Type of mouse cursor
EngineMouseType m_mouseType;
//! Last engine render state (-1 at the beginning of frame)
int m_lastState;
//! Last color set with render state
Color m_lastColor;
//! Last texture names for 2 used texture stages
std::string m_lastTexture[2];
//! Last material
Material m_lastMaterial;
//! True when drawing 2D UI
bool m_interfaceMode;

View File

@ -24,6 +24,7 @@
#include "common/logger.h"
#include "graphics/core/device.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/terrain.h"

View File

@ -26,6 +26,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/triangle.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h"
@ -73,7 +74,7 @@ static bool IsAlien(ObjectType type)
}
CParticle::CParticle(CEngine* engine)
: m_engine(engine)
: m_engine(engine), m_triangle(MAXPARTICULE)
{
std::fill_n(m_frameUpdate, SH_MAX, true);
}

View File

@ -31,6 +31,7 @@
#include "sound/sound_type.h"
#include <vector>
class CRobotMain;
class CObject;
@ -42,6 +43,7 @@ namespace Gfx
{
class CParticleRenderer;
struct EngineTriangle;
const short MAXPARTICULE = 500;
const short MAXPARTITYPE = 6;
@ -344,7 +346,7 @@ protected:
CParticleRenderer* m_renderer = nullptr;
Particle m_particle[MAXPARTICULE*MAXPARTITYPE];
EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0
std::vector<EngineTriangle> m_triangle; // triangle if PartiType == 0
Track m_track[MAXTRACK];
int m_wheelTraceTotal = 0;
int m_wheelTraceIndex = 0;

View File

@ -24,6 +24,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -24,6 +24,8 @@
#include "common/logger.h"
#include "graphics/core/triangle.h"
#include "graphics/engine/lightman.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/terrain.h"

View File

@ -17,7 +17,6 @@
* along with this program. If not, see http://gnu.org/licenses
*/
#include "graphics/engine/terrain.h"
#include "app/app.h"
@ -25,6 +24,8 @@
#include "common/image.h"
#include "common/logger.h"
#include "graphics/core/triangle.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/water.h"

View File

@ -30,6 +30,7 @@
#include "common/resources/resourcemanager.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -25,6 +25,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h"

View File

@ -402,7 +402,7 @@ CModelMesh ModelInput::ReadTextMesh(std::istream& stream)
bool doubleSided = ReadLineString(stream, "dbl_side") == std::string("Y");
t.material.cullFace = doubleSided ? CullFace::NONE : CullFace::BACK;
if (t.material.alphaMode != AlphaMode::OPAQUE)
if (t.material.alphaMode != AlphaMode::NONE)
t.material.alphaThreshold = 0.5f;
mesh.AddTriangle(t);
@ -647,7 +647,7 @@ void ModelInput::ConvertFromOldRenderState(ModelTriangle& triangle, int state)
triangle.material.alphaThreshold = 0.5f;
}
else
triangle.material.alphaMode = AlphaMode::OPAQUE;
triangle.material.alphaMode = AlphaMode::NONE;
if ((state & static_cast<int>(ModelRenderState::Part1)) != 0)
triangle.material.tag = "tracker_right";
@ -891,11 +891,11 @@ Math::Sphere ModelInput::ParseCameraCollisionSphere(const std::string& text)
AlphaMode ModelInput::ParseTransparentMode(const std::string& text)
{
if (text == "none")
return AlphaMode::OPAQUE;
return AlphaMode::NONE;
else if (text == "alpha")
return AlphaMode::MASK;
else
return AlphaMode::OPAQUE;
return AlphaMode::NONE;
}
std::string ModelInput::ParseSpecialMark(const std::string& text)

View File

@ -27,6 +27,8 @@
#include "common/make_unique.h"
#include "graphics/core/light.h"
#include "graphics/core/material.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -26,8 +26,6 @@
#include "graphics/core/device.h"
#include "graphics/core/material.h"
#include "graphics/opengl/glframebuffer.h"
#include "graphics/opengl/glutil.h"
@ -43,6 +41,9 @@
namespace Gfx
{
enum class CullFace : unsigned char;
enum class TransparencyMode : unsigned char;
//! Struct for dynamic buffers
struct DynamicBuffer
{
@ -196,9 +197,9 @@ private:
//! Depth mask
bool m_depthMask = true;
//! Cull face mode
CullFace m_cullFace = CullFace::NONE;
CullFace m_cullFace = {};
//! Transparency mode
TransparencyMode m_transparency = TransparencyMode::NONE;
TransparencyMode m_transparency = {};
};
} // namespace Gfx

View File

@ -22,6 +22,8 @@
#include "graphics/opengl/gl33device.h"
#include "graphics/opengl/glutil.h"
#include "graphics/core/material.h"
#include "graphics/core/transparency.h"
#include "graphics/core/vertex.h"
#include "common/logger.h"

View File

@ -3,6 +3,8 @@
#include "graphics/opengl/gl33device.h"
#include "graphics/opengl/glutil.h"
#include "graphics/core/material.h"
#include "graphics/core/transparency.h"
#include "graphics/core/vertex.h"
#include "common/logger.h"

View File

@ -3,6 +3,8 @@
#include "graphics/opengl/gl33device.h"
#include "graphics/opengl/glutil.h"
#include "graphics/core/material.h"
#include "graphics/core/transparency.h"
#include "graphics/core/vertex.h"
#include "common/logger.h"

View File

@ -37,6 +37,8 @@
#include "common/resources/outputstream.h"
#include "common/resources/resourcemanager.h"
#include "graphics/core/material.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
#include "graphics/engine/engine.h"
@ -446,7 +448,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_engine->SetBackground("");
m_engine->SetBackForce(false);
m_engine->SetForegroundName("");
m_engine->SetOverColor();
m_engine->SetOverColor(Gfx::Color(), Gfx::TransparencyMode::BLACK);
m_engine->DeleteGroundMark(0);
SetSpeed(1.0f);
m_terrain->SetWind(glm::vec3(0.0f, 0.0f, 0.0f));

View File

@ -26,6 +26,7 @@
#include "graphics/engine/engine.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
namespace Ui

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/text.h"

View File

@ -25,6 +25,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -29,6 +29,7 @@
#include "level/robotmain.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "math/func.h"

View File

@ -32,6 +32,8 @@
#include "common/resources/outputstream.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "level/parser/parser.h"

View File

@ -21,8 +21,10 @@
#include "ui/controls/gauge.h"
#include "graphics/engine/engine.h"
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
namespace Ui

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "math/func.h"

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "sound/sound.h"

View File

@ -24,6 +24,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "ui/controls/button.h"

View File

@ -24,6 +24,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"

View File

@ -25,6 +25,8 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include "graphics/engine/engine.h"
#include "graphics/engine/text.h"

View File

@ -40,6 +40,7 @@
#include "graphics/core/device.h"
#include "graphics/core/renderers.h"
#include "graphics/core/transparency.h"
#include <algorithm>

View File

@ -61,6 +61,8 @@
#include "ui/screen/screen_setup_sound.h"
#include "ui/screen/screen_welcome.h"
#include "graphics/core/transparency.h"
namespace Ui
{

View File

@ -23,6 +23,8 @@
#include "common/stringutils.h"
#include "graphics/core/material.h"
#include "graphics/engine/engine.h"
#include "level/robotmain.h"