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 142 143 144 145
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef UNITDRAWER_STATE_H
#define UNITDRAWER_STATE_H
#include <array>
#include "System/type2.h"
struct float4;
class CUnitDrawer;
class CCamera;
struct ISkyLight;
namespace Shader {
struct IProgramObject;
}
enum {
DRAWER_STATE_FFP = 0, // fixed-function path
DRAWER_STATE_SSP = 1, // standard-shader path (ARB/GLSL)
DRAWER_STATE_SEL = 2, // selected path
DRAWER_STATE_CNT = 3,
};
struct IUnitDrawerState {
public:
static IUnitDrawerState* GetInstance(bool haveARB, bool haveGLSL);
static void FreeInstance(IUnitDrawerState* state) { delete state; }
static void PushTransform(const CCamera* cam);
static void PopTransform();
static float4 GetTeamColor(int team, float alpha);
IUnitDrawerState() { modelShaders.fill(nullptr); }
virtual ~IUnitDrawerState() {}
virtual bool Init(const CUnitDrawer*) { return false; }
virtual void Kill() {}
virtual bool CanEnable(const CUnitDrawer*) const { return false; }
virtual bool CanDrawAlpha() const { return false; }
virtual bool CanDrawDeferred() const { return false; }
virtual void Enable(const CUnitDrawer*, bool, bool) = 0;
virtual void Disable(const CUnitDrawer*, bool) = 0;
virtual void EnableTextures() const = 0;
virtual void DisableTextures() const = 0;
virtual void EnableShaders(const CUnitDrawer*) {}
virtual void DisableShaders(const CUnitDrawer*) {}
virtual void UpdateCurrentShaderSky(const CUnitDrawer*, const ISkyLight*) const {}
virtual void SetTeamColor(int team, const float2 alpha) const = 0;
virtual void SetNanoColor(const float4& color) const {}
void SetActiveShader(unsigned int shadowed, unsigned int deferred) {
// shadowed=1 --> shader 1 (deferred=0) or 3 (deferred=1)
// shadowed=0 --> shader 0 (deferred=0) or 2 (deferred=1)
modelShaders[MODEL_SHADER_ACTIVE] = modelShaders[shadowed + deferred * 2];
}
enum ModelShaderProgram {
MODEL_SHADER_NOSHADOW_STANDARD = 0, ///< model shader (V+F) without self-shadowing
MODEL_SHADER_SHADOWED_STANDARD = 1, ///< model shader (V+F) with self-shadowing
MODEL_SHADER_NOSHADOW_DEFERRED = 2, ///< deferred version of MODEL_SHADER_NOSHADOW (GLSL-only)
MODEL_SHADER_SHADOWED_DEFERRED = 3, ///< deferred version of MODEL_SHADER_SHADOW (GLSL-only)
MODEL_SHADER_ACTIVE = 4, ///< currently active model shader
MODEL_SHADER_COUNT = 5,
};
protected:
// shared ARB and GLSL state managers
void EnableCommon(const CUnitDrawer*, bool);
void DisableCommon(const CUnitDrawer*, bool);
void EnableTexturesCommon() const;
void DisableTexturesCommon() const;
protected:
std::array<Shader::IProgramObject*, MODEL_SHADER_COUNT> modelShaders;
};
struct UnitDrawerStateFFP: public IUnitDrawerState {
public:
bool CanEnable(const CUnitDrawer*) const override;
void Enable(const CUnitDrawer*, bool, bool) override;
void Disable(const CUnitDrawer*, bool) override;
void EnableTextures() const override;
void DisableTextures() const override;
void SetTeamColor(int team, const float2 alpha) const override;
void SetNanoColor(const float4& color) const override;
};
struct UnitDrawerStateARB: public IUnitDrawerState {
public:
bool Init(const CUnitDrawer*) override;
void Kill() override;
bool CanEnable(const CUnitDrawer*) const override;
void Enable(const CUnitDrawer*, bool, bool) override;
void Disable(const CUnitDrawer*, bool) override;
void EnableTextures() const override;
void DisableTextures() const override;
void EnableShaders(const CUnitDrawer*) override;
void DisableShaders(const CUnitDrawer*) override;
void SetNanoColor(const float4& color) const override;
void SetTeamColor(int team, const float2 alpha) const override;
};
struct UnitDrawerStateGLSL: public IUnitDrawerState {
public:
bool Init(const CUnitDrawer*) override;
void Kill() override;
bool CanEnable(const CUnitDrawer*) const override;
bool CanDrawAlpha() const override { return true; }
bool CanDrawDeferred() const override { return true; }
void Enable(const CUnitDrawer*, bool, bool) override;
void Disable(const CUnitDrawer*, bool) override;
void EnableTextures() const override;
void DisableTextures() const override;
void EnableShaders(const CUnitDrawer*) override;
void DisableShaders(const CUnitDrawer*) override;
void UpdateCurrentShaderSky(const CUnitDrawer*, const ISkyLight*) const override;
void SetTeamColor(int team, const float2 alpha) const override;
void SetNanoColor(const float4& color) const override;
};
#endif
|