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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef LUA_OBJECT_DRAWER_H
#define LUA_OBJECT_DRAWER_H
// for LuaObjType and LuaMatType
#include "Lua/LuaObjectMaterial.h"
#include "Rendering/GL/GeometryBuffer.h"
class CSolidObject;
class LuaMaterial;
class LuaMatBin;
class LuaMatShader;
//
// handles drawing of objects (units, features) with
// custom Lua-assigned materials (e.g. display lists,
// shaders, ...) during the various renderer passes
//
// note: custom materials can use standard shaders!
//
class LuaObjectDrawer {
public:
static bool InDrawPass() { return inDrawPass; }
static void DrawDeferredPass(LuaObjType objType);
static bool DrawSingleObjectCommon(const CSolidObject* obj, LuaObjType objType, bool applyTrans);
static bool DrawSingleObject(const CSolidObject* obj, LuaObjType objType);
static bool DrawSingleObjectNoTrans(const CSolidObject* obj, LuaObjType objType);
static void Update(bool init);
static void Init();
static void Kill();
static void SetObjectLOD(CSolidObject* obj, LuaObjType objType, unsigned int lodCount);
static bool AddObjectForLOD(CSolidObject* obj, LuaObjType objType, bool useAlphaMat, bool useShadowMat);
static bool AddOpaqueMaterialObject(CSolidObject* obj, LuaObjType objType);
static bool AddAlphaMaterialObject(CSolidObject* obj, LuaObjType objType);
static bool AddShadowMaterialObject(CSolidObject* obj, LuaObjType objType);
static void DrawOpaqueMaterialObjects(LuaObjType objType, bool deferredPass);
static void DrawAlphaMaterialObjects(LuaObjType objType, bool deferredPass);
static void DrawShadowMaterialObjects(LuaObjType objType, bool deferredPass);
public:
static void ReadLODScales(LuaObjType objType);
static void SetDrawPassGlobalLODFactor(LuaObjType objType);
static int GetBinObjTeam() { return binObjTeam; }
static float GetLODScale (int objType) { return (LODScale[objType] ); }
static float GetLODScaleShadow (int objType) { return (LODScale[objType] * LODScaleShadow [objType]); }
static float GetLODScaleReflection(int objType) { return (LODScale[objType] * LODScaleReflection[objType]); }
static float GetLODScaleRefraction(int objType) { return (LODScale[objType] * LODScaleRefraction[objType]); }
static float SetLODScale (int objType, float v) { return (LODScale [objType] = v); }
static float SetLODScaleShadow (int objType, float v) { return (LODScaleShadow [objType] = v); }
static float SetLODScaleReflection(int objType, float v) { return (LODScaleReflection[objType] = v); }
static float SetLODScaleRefraction(int objType, float v) { return (LODScaleRefraction[objType] = v); }
static LuaMatType GetDrawPassOpaqueMat();
static LuaMatType GetDrawPassAlphaMat();
static LuaMatType GetDrawPassShadowMat() { return LUAMAT_SHADOW; }
// shared by {Unit,Feature}Drawer
// note: the pointer MUST already be valid during
// FeatureDrawer's ctor, in CWorldDrawer::LoadPre)
static GL::GeometryBuffer* GetGeometryBuffer() { return geomBuffer; }
private:
static void DrawMaterialBins(LuaObjType objType, LuaMatType matType, bool deferredPass);
static void DrawMaterialBin(
const LuaMatBin* currBin,
const LuaMaterial* prevMat,
LuaObjType objType,
LuaMatType matType,
bool deferredPass,
bool alphaMatBin
);
static void DrawBinObject(
const CSolidObject* obj,
LuaObjType objType,
const LuaObjectLODMaterial* lodMat,
const LuaMaterial* luaMat,
bool deferredPass,
bool alphaMatBin,
bool applyTrans,
bool noLuaCall
);
private:
static GL::GeometryBuffer* geomBuffer;
// whether we are currently in DrawMaterialBins
static bool inDrawPass;
// whether alpha-material bins are being drawn
static bool inAlphaBin;
// whether we can execute DrawDeferredPass
static bool drawDeferredEnabled;
// whether deferred object drawing is allowed by user
static bool drawDeferredAllowed;
// whether the deferred feature pass clears the GB
static bool bufferClearAllowed;
// team of last object visited in DrawMaterialBin
// (needed because bins are not sorted by team and
// Lua shaders do not have any uniform caching yet)
static int binObjTeam;
static float LODScale[LUAOBJ_LAST];
static float LODScaleShadow[LUAOBJ_LAST];
static float LODScaleReflection[LUAOBJ_LAST];
static float LODScaleRefraction[LUAOBJ_LAST];
};
#endif
|