1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef FEATUREDRAWER_H_
#define FEATUREDRAWER_H_
#include <vector>
#include <array>
#include "Game/Camera.h"
#include "Rendering/Models/ModelRenderContainer.h"
#include "System/creg/creg_cond.h"
#include "System/EventClient.h"
class CFeature;
namespace GL {
struct GeometryBuffer;
}
class CFeatureDrawer: public CEventClient
{
public:
CFeatureDrawer(): CEventClient("[CFeatureDrawer]", 313373, false) {}
static void InitStatic();
static void KillStatic(bool reload);
void Init();
void Kill();
void ConfigNotify(const std::string& key, const std::string& value);
void UpdateDrawQuad(CFeature* feature);
void Update() override;
void Draw();
void DrawOpaquePass(bool deferredPass);
void DrawShadowPass();
void DrawAlphaPass(bool aboveWater);
static void SetFeatureLuaTrans(const CFeature* feature, bool lodCall);
static void SetFeatureDefTrans(const CFeature* feature, bool lodCall);
static void DrawFeatureLuaTrans(const CFeature* feature, bool lodCall, bool noLuaCall);
static void DrawFeatureDefTrans(const CFeature*, bool lodCall, bool noLuaCall);
/// LuaOpenGL::Feature{Raw}: draw a single feature with full state setup
void PushIndividualState(const CFeature* feature, bool deferredPass);
void PopIndividualState(const CFeature* feature, bool deferredPass);
void DrawIndividualDefTrans(const CFeature* feature, bool noLuaCall);
void DrawIndividualLuaTrans(const CFeature* feature, bool noLuaCall);
void SetDrawForwardPass(bool b) { drawForward = b; }
void SetDrawDeferredPass(bool b) { drawDeferred = b; }
public:
// CEventClient interface
bool WantsEvent(const std::string& eventName) override {
return (eventName == "RenderFeatureCreated" || eventName == "RenderFeatureDestroyed" || eventName == "FeatureMoved");
}
bool GetFullRead() const override { return true; }
int GetReadAllyTeam() const override { return AllAccessTeam; }
void RenderFeatureCreated(const CFeature* feature) override;
void RenderFeatureDestroyed(const CFeature* feature) override;
void FeatureMoved(const CFeature* feature, const float3& oldpos) override;
public:
const GL::GeometryBuffer* GetGeometryBuffer() const { return geomBuffer; }
GL::GeometryBuffer* GetGeometryBuffer() { return geomBuffer; }
bool DrawForward() const { return drawForward; }
bool DrawDeferred() const { return drawDeferred; }
private:
static void UpdateDrawPos(CFeature* f);
void DrawOpaqueFeatures(int modelType);
void DrawAlphaFeatures(int modelType);
void DrawAlphaFeature(CFeature* f, bool ffpMat);
void DrawFarFeatures();
bool CanDrawFeature(const CFeature*) const;
static void DrawFeatureModel(const CFeature* feature, bool noLuaCall);
void FlagVisibleFeatures(
const CCamera*,
bool drawShadowPass,
bool drawReflection,
bool drawRefraction,
bool drawFar
);
void GetVisibleFeatures(CCamera*, int, bool drawFar);
private:
int drawQuadsX;
int drawQuadsY;
float farDist;
float featureDrawDistance;
float featureFadeDistance;
bool drawForward;
bool drawDeferred;
// we need these because alpha- and shadow-pass both
// reuse Draw{Opaque}Feature{s} which sets team color
bool inAlphaPass;
bool inShadowPass;
private:
friend class CFeatureQuadDrawer;
struct RdrContProxy {
const ModelRenderContainer<CFeature>& GetRenderer(unsigned int i) const { return rendererTypes[i]; }
ModelRenderContainer<CFeature>& GetRenderer(unsigned int i) { return rendererTypes[i]; }
unsigned int GetLastDrawFrame() const { return lastDrawFrame; }
void SetLastDrawFrame(unsigned int f) { lastDrawFrame = f; }
private:
std::array<ModelRenderContainer<CFeature>, MODELTYPE_OTHER> rendererTypes;
// frame on which this proxy's owner quad last
// received a DrawQuad call (i.e. was in view)
// during *any* pass
unsigned int lastDrawFrame = 0;
};
std::vector<RdrContProxy> modelRenderers;
std::array< std::vector<int>, CCamera::CAMTYPE_ENVMAP> camVisibleQuads;
std::array<unsigned int, CCamera::CAMTYPE_ENVMAP> camVisDrawFrames;
std::vector<CFeature*> unsortedFeatures;
GL::GeometryBuffer* geomBuffer;
};
extern CFeatureDrawer* featureDrawer;
#endif /* FEATUREDRAWER_H_ */
|