| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "iimage.h" |
| 4 |
#include "ideclmanager.h" |
| 5 |
#include "imodule.h" |
| 6 |
#include "ifilesystem.h" |
| 7 |
#include <sigc++/signal.h> |
| 8 |
|
| 9 |
#include "math/Vector3.h" |
| 10 |
#include "math/Vector4.h" |
| 11 |
|
| 12 |
#include <ostream> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "Texture.h" |
| 16 |
#include "ishaderlayer.h" |
| 17 |
#include "ishaderexpression.h" |
| 18 |
|
| 19 |
class Image; |
| 20 |
|
| 21 |
/** |
| 22 |
* \brief Interface for a material shader. |
| 23 |
* |
| 24 |
* A material shader consists of global parameters, an editor image, and zero |
| 25 |
* or more shader layers (including diffusemap, bumpmap and specularmap |
| 26 |
* textures which are handled specially). |
| 27 |
* |
| 28 |
* Most material shaders are defined in .mtr files within the mod asset tree, |
| 29 |
* but there are also internal materials generated for Radiant-specific |
| 30 |
* internal OpenGL shaders, such as those used to render wireframes. |
| 31 |
*/ |
| 32 |
class Material |
| 33 |
{ |
| 34 |
public: |
| 35 |
|
| 36 |
enum CullType |
| 37 |
{ |
| 38 |
CULL_BACK, // default backside culling, for materials without special flags |
| 39 |
CULL_FRONT, // "backSided" |
| 40 |
CULL_NONE, // "twoSided" |
| 41 |
}; |
| 42 |
|
| 43 |
// Global material flags |
| 44 |
enum Flags |
| 45 |
{ |
| 46 |
FLAG_NOSHADOWS = 1 << 0, // noShadows |
| 47 |
FLAG_NOSELFSHADOW = 1 << 1, // noSelfShadow |
| 48 |
FLAG_FORCESHADOWS = 1 << 2, // forceShadows |
| 49 |
FLAG_NOOVERLAYS = 1 << 3, // noOverlays |
| 50 |
FLAG_FORCEOVERLAYS = 1 << 4, // forceOverlays |
| 51 |
FLAG_TRANSLUCENT = 1 << 5, // translucent |
| 52 |
FLAG_FORCEOPAQUE = 1 << 6, // forceOpaque |
| 53 |
FLAG_NOFOG = 1 << 7, // noFog |
| 54 |
FLAG_NOPORTALFOG = 1 << 8, // noPortalFog |
| 55 |
FLAG_UNSMOOTHEDTANGENTS = 1 << 9, // unsmoothedTangents |
| 56 |
FLAG_MIRROR = 1 << 10, // mirror |
| 57 |
FLAG_POLYGONOFFSET = 1 << 11, // has polygonOffset |
| 58 |
FLAG_ISLIGHTGEMSURF = 1 << 12, // is used by the TDM lightgem |
| 59 |
FLAG_HAS_SORT_DEFINED = 1 << 13, // whether a sort value has been defined |
| 60 |
}; |
| 61 |
|
| 62 |
// Parser flags, used to give some hints to the material editor GUI |
| 63 |
// about what the material sources looked like |
| 64 |
enum ParseFlags |
| 65 |
{ |
| 66 |
PF_HasSortDefined = 1 << 0, // has a "sort" keyword in its definition |
| 67 |
PF_HasAmbientRimColour = 1 << 1, // has an "ambientRimColor" keyword in its definition |
| 68 |
PF_HasSpectrum = 1 << 2, // has a "spectrum" keyword in its definition |
| 69 |
PF_HasDecalInfo = 1 << 3, // has a "decalinfo" keyword in its definition |
| 70 |
PF_HasDecalMacro = 1 << 4, // has a "DECAL_MACRO" keyword in its definition |
| 71 |
PF_HasTwoSidedDecalMacro = 1 << 5, // has a "TWOSIDED_DECAL_MACRO" keyword in its definition |
| 72 |
PF_HasParticleMacro = 1 << 6, // has a "PARTICLE_MACRO" keyword in its definition |
| 73 |
PF_HasGlassMacro = 1 << 7, // has a "GLASS_MACRO" keyword in its definition |
| 74 |
}; |
| 75 |
|
| 76 |
// Surface Flags |
| 77 |
enum SurfaceFlags |
| 78 |
{ |
| 79 |
SURF_SOLID = 1 << 0, |
| 80 |
SURF_OPAQUE = 1 << 1, |
| 81 |
SURF_WATER = 1 << 2, |
| 82 |
SURF_PLAYERCLIP = 1 << 3, |
| 83 |
SURF_MONSTERCLIP = 1 << 4, |
| 84 |
SURF_MOVEABLECLIP = 1 << 5, |
| 85 |
SURF_IKCLIP = 1 << 6, |
| 86 |
SURF_BLOOD = 1 << 7, |
| 87 |
SURF_TRIGGER = 1 << 8, |
| 88 |
SURF_AASSOLID = 1 << 9, |
| 89 |
SURF_AASOBSTACLE = 1 << 10, |
| 90 |
SURF_FLASHLIGHT_TRIGGER = 1 << 11, |
| 91 |
SURF_NONSOLID = 1 << 12, |
| 92 |
SURF_NULLNORMAL = 1 << 13, |
| 93 |
SURF_AREAPORTAL = 1 << 14, |
| 94 |
SURF_NOCARVE = 1 << 15, |
| 95 |
SURF_DISCRETE = 1 << 16, |
| 96 |
SURF_NOFRAGMENT = 1 << 17, |
| 97 |
SURF_SLICK = 1 << 18, |
| 98 |
SURF_COLLISION = 1 << 19, |
| 99 |
SURF_NOIMPACT = 1 << 20, |
| 100 |
SURF_NODAMAGE = 1 << 21, |
| 101 |
SURF_LADDER = 1 << 22, |
| 102 |
SURF_NOSTEPS = 1 << 23, |
| 103 |
SURF_GUISURF = 1 << 24, // has guisurf in its material def |
| 104 |
SURF_ENTITYGUI = 1 << 25, // guisurf entity |
| 105 |
SURF_ENTITYGUI2 = 1 << 26, // guisurf entity2 |
| 106 |
SURF_ENTITYGUI3 = 1 << 27, // guisurf entity3 |
| 107 |
}; |
| 108 |
|
| 109 |
// Surface Type (plastic, stone, etc.) |
| 110 |
enum SurfaceType |
| 111 |
{ |
| 112 |
SURFTYPE_DEFAULT, |
| 113 |
SURFTYPE_METAL, |
| 114 |
SURFTYPE_STONE, |
| 115 |
SURFTYPE_FLESH, |
| 116 |
SURFTYPE_WOOD, |
| 117 |
SURFTYPE_CARDBOARD, |
| 118 |
SURFTYPE_LIQUID, |
| 119 |
SURFTYPE_GLASS, |
| 120 |
SURFTYPE_PLASTIC, |
| 121 |
SURFTYPE_RICOCHET, |
| 122 |
SURFTYPE_AASOBSTACLE, |
| 123 |
SURFTYPE_10, |
| 124 |
SURFTYPE_11, |
| 125 |
SURFTYPE_12, |
| 126 |
SURFTYPE_13, |
| 127 |
SURFTYPE_14, |
| 128 |
SURFTYPE_15 |
| 129 |
}; |
| 130 |
|
| 131 |
/** |
| 132 |
* \brief |
| 133 |
* Requested sort position from material declaration (e.g. "sort decal"). |
| 134 |
* The actual sort order of a material is stored as a floating point number, |
| 135 |
* these enumerations represent some regularly used shortcuts in material decls. |
| 136 |
* The values of this enum have been modeled after the ones found in the D3 SDK. |
| 137 |
*/ |
| 138 |
enum SortRequest |
| 139 |
{ |
| 140 |
SORT_SUBVIEW = -3, // mirrors, viewscreens, etc |
| 141 |
SORT_GUI = -2, // guis |
| 142 |
SORT_BAD = -1, |
| 143 |
SORT_OPAQUE, // opaque |
| 144 |
SORT_PORTAL_SKY, |
| 145 |
SORT_DECAL, // scorch marks, etc. |
| 146 |
SORT_FAR, |
| 147 |
SORT_MEDIUM, // normal translucent |
| 148 |
SORT_CLOSE, |
| 149 |
SORT_ALMOST_NEAREST, // gun smoke puffs |
| 150 |
SORT_NEAREST, // screen blood blobs |
| 151 |
SORT_AFTER_FOG = 90, // TDM-specific |
| 152 |
SORT_POST_PROCESS = 100 // after a screen copy to texture |
| 153 |
}; |
| 154 |
|
| 155 |
// Deform Type |
| 156 |
enum DeformType |
| 157 |
{ |
| 158 |
DEFORM_NONE, |
| 159 |
DEFORM_SPRITE, |
| 160 |
DEFORM_TUBE, |
| 161 |
DEFORM_FLARE, |
| 162 |
DEFORM_EXPAND, |
| 163 |
DEFORM_MOVE, |
| 164 |
DEFORM_TURBULENT, |
| 165 |
DEFORM_EYEBALL, |
| 166 |
DEFORM_PARTICLE, |
| 167 |
DEFORM_PARTICLE2, |
| 168 |
}; |
| 169 |
|
| 170 |
struct DecalInfo |
| 171 |
{ |
| 172 |
int stayMilliSeconds; |
| 173 |
int fadeMilliSeconds; |
| 174 |
Vector4 startColour; |
| 175 |
Vector4 endColour; |
| 176 |
|
| 177 |
DecalInfo() : |
| 178 |
stayMilliSeconds(0), |
| 179 |
fadeMilliSeconds(0), |
| 180 |
startColour(0,0,0,0), |
| 181 |
endColour(0,0,0,0) |
| 182 |
{} |
| 183 |
}; |
| 184 |
|
| 185 |
enum Coverage |
| 186 |
{ |
| 187 |
MC_UNDETERMINED, |
| 188 |
MC_OPAQUE, // completely fills the triangle, will have black drawn on fillDepthBuffer |
| 189 |
MC_PERFORATED, // may have alpha tested holes |
| 190 |
MC_TRANSLUCENT // blended with background |
| 191 |
}; |
| 192 |
|
| 193 |
// TDM 2.11 frob stage keyword |
| 194 |
enum class FrobStageType |
| 195 |
{ |
| 196 |
Default, // no frobstage keyword in this material |
| 197 |
Diffuse, // frobstage_diffuse has been declared: frobstage_diffuse 0.25 0.50 |
| 198 |
Texture, // frobstage_texture textures/some/thing 0.15 0.40 |
| 199 |
NoFrobStage, // frobstage_none |
| 200 |
}; |
| 201 |
|
| 202 |
virtual ~Material() {} |
| 203 |
|
| 204 |
/// Return the editor image texture for this shader. |
| 205 |
virtual TexturePtr getEditorImage() = 0; |
| 206 |
|
| 207 |
/// Return true if the editor image is no tex for this shader. |
| 208 |
virtual bool isEditorImageNoTex() = 0; |
| 209 |
|
| 210 |
// Returns the expression defining the editor image of this material, as passed to qer_editorimage statement, |
| 211 |
// or an empty string if this keyword was not used at all in this declaration. |
| 212 |
virtual shaders::IMapExpression::Ptr getEditorImageExpression() = 0; |
| 213 |
|
| 214 |
// Set the editor image path of this material |
| 215 |
virtual void setEditorImageExpressionFromString(const std::string& editorImagePath) = 0; |
| 216 |
|
| 217 |
/// Get the string name of this material |
| 218 |
virtual std::string getName() const = 0; |
| 219 |
|
| 220 |
virtual bool IsInUse() const = 0; |
| 221 |
virtual void SetInUse(bool bInUse) = 0; |
| 222 |
|
| 223 |
/// Return true if this is an internal material not corresponding to a .mtr |
| 224 |
virtual bool IsDefault() const = 0; |
| 225 |
|
| 226 |
/// get shader file name (ie the file where this one is defined) |
| 227 |
virtual const char* getShaderFileName() const = 0; |
| 228 |
|
| 229 |
// Set the mtr file name to define where this material should be saved to |
| 230 |
// This will throw an exception if the given path (absolute or relative) |
| 231 |
// is not located within the current mod file tree (VFS) |
| 232 |
virtual void setShaderFileName(const std::string& fullPath) = 0; |
| 233 |
|
| 234 |
// Returns the VFS info structure of the file this shader is defined in |
| 235 |
virtual const vfs::FileInfo& getShaderFileInfo() const = 0; |
| 236 |
|
| 237 |
/** |
| 238 |
* \brief Return the requested sort position of this material. |
| 239 |
*/ |
| 240 |
virtual float getSortRequest() const = 0; |
| 241 |
|
| 242 |
// Set the sort value for this material, see the SortRequest enum for predefined values |
| 243 |
virtual void setSortRequest(float sortRequest) = 0; |
| 244 |
|
| 245 |
// Resets the sort request to the default value |
| 246 |
virtual void resetSortRequest() = 0; |
| 247 |
|
| 248 |
/// Return a polygon offset if one is defined. The default is 0. |
| 249 |
virtual float getPolygonOffset() const = 0; |
| 250 |
|
| 251 |
// Set the polygon offset of this material. Clear the FLAG_POLYGONOFFSET to disable the offset altogether. |
| 252 |
virtual void setPolygonOffset(float offset) = 0; |
| 253 |
|
| 254 |
/// Get the desired texture repeat behaviour. |
| 255 |
virtual ClampType getClampType() const = 0; |
| 256 |
|
| 257 |
// Set the clamp type for this material |
| 258 |
virtual void setClampType(ClampType type) = 0; |
| 259 |
|
| 260 |
/// Get the cull type (none, back, front) |
| 261 |
virtual CullType getCullType() const = 0; |
| 262 |
|
| 263 |
// Set the cull type |
| 264 |
virtual void setCullType(CullType type) = 0; |
| 265 |
|
| 266 |
/// Get the global material flags (translucent, noshadows, etc.) |
| 267 |
virtual int getMaterialFlags() const = 0; |
| 268 |
|
| 269 |
// Set the given material flag |
| 270 |
virtual void setMaterialFlag(Flags flag) = 0; |
| 271 |
|
| 272 |
// Clear the given material flags |
| 273 |
virtual void clearMaterialFlag(Flags flag) = 0; |
| 274 |
|
| 275 |
/// Surface flags (areaportal, nonsolid, etc.) |
| 276 |
virtual int getSurfaceFlags() const = 0; |
| 277 |
|
| 278 |
// Set the given surface flag |
| 279 |
virtual void setSurfaceFlag(Material::SurfaceFlags flag) = 0; |
| 280 |
|
| 281 |
// Clear the given surface flag |
| 282 |
virtual void clearSurfaceFlag(Material::SurfaceFlags flag) = 0; |
| 283 |
|
| 284 |
/// Surface Type (wood, stone, surfType15, ...) |
| 285 |
virtual SurfaceType getSurfaceType() const = 0; |
| 286 |
|
| 287 |
// Set the surface type of this material |
| 288 |
virtual void setSurfaceType(SurfaceType type) = 0; |
| 289 |
|
| 290 |
/// Get the deform type of this material |
| 291 |
virtual DeformType getDeformType() const = 0; |
| 292 |
|
| 293 |
// Returns the shader expression used to define the deform parameters (valid indices in [0..2]) |
| 294 |
virtual shaders::IShaderExpression::Ptr getDeformExpression(std::size_t index) = 0; |
| 295 |
|
| 296 |
// Used for Deform_Particle/Particle2 defines the name of the particle def |
| 297 |
virtual std::string getDeformDeclName() = 0; |
| 298 |
|
| 299 |
/// Returns the spectrum of this shader, 0 is the default value (even without keyword in the material) |
| 300 |
virtual int getSpectrum() const = 0; |
| 301 |
|
| 302 |
// Sets the spectrum of this material. |
| 303 |
virtual void setSpectrum(int spectrum) = 0; |
| 304 |
|
| 305 |
/// Retrieves the decal info structure of this material. |
| 306 |
virtual DecalInfo getDecalInfo() const = 0; |
| 307 |
|
| 308 |
// Sets the decal info structure on this material. |
| 309 |
// If the structure is not empty, it will enable the ParseFlag PF_HasDecalInfo, |
| 310 |
// an empty/defaulted decalInfo structure will clear the flag |
| 311 |
virtual void setDecalInfo(const DecalInfo& info) = 0; |
| 312 |
|
| 313 |
/// Returns the coverage type of this material, also needed by the map compiler. |
| 314 |
virtual Coverage getCoverage() const = 0; |
| 315 |
|
| 316 |
/** |
| 317 |
* Returns the raw shader definition block, as parsed by the material manager. |
| 318 |
* The definition is lacking the outermost curly braces. |
| 319 |
*/ |
| 320 |
virtual std::string getDefinition() = 0; |
| 321 |
|
| 322 |
/** Determine whether this is an ambient light shader, i.e. the |
| 323 |
* material def contains the global "ambientLight" keyword. |
| 324 |
*/ |
| 325 |
virtual bool isAmbientLight() const = 0; |
| 326 |
|
| 327 |
/** Determine whether this is an blend light shader, i.e. the |
| 328 |
* material def contains the global "blendLight" keyword. |
| 329 |
*/ |
| 330 |
virtual bool isBlendLight() const = 0; |
| 331 |
|
| 332 |
/** Determine whether this is an fog light shader, i.e. the |
| 333 |
* material def contains the global "fogLight" keyword. |
| 334 |
*/ |
| 335 |
virtual bool isFogLight() const = 0; |
| 336 |
|
| 337 |
/** Determine whether this is a cubic light shader, i.e. the |
| 338 |
* material def contains the global "cubicLight" keyword. |
| 339 |
*/ |
| 340 |
virtual bool isCubicLight() const = 0; |
| 341 |
|
| 342 |
virtual void setIsAmbientLight(bool newValue) = 0; |
| 343 |
virtual void setIsBlendLight(bool newValue) = 0; |
| 344 |
virtual void setIsFogLight(bool newValue) = 0; |
| 345 |
virtual void setIsCubicLight(bool newValue) = 0; |
| 346 |
|
| 347 |
/** |
| 348 |
* For light shaders: implicitly no-shadows lights (ambients, fogs, etc) |
| 349 |
* will never cast shadows but individual light entities can also override this value. |
| 350 |
*/ |
| 351 |
virtual bool lightCastsShadows() const = 0; |
| 352 |
|
| 353 |
// returns true if the material will generate shadows, not making a |
| 354 |
// distinction between global and no-self shadows |
| 355 |
virtual bool surfaceCastsShadow() const = 0; |
| 356 |
|
| 357 |
/** |
| 358 |
* returns true if the material will draw anything at all. Triggers, portals, |
| 359 |
* etc, will not have anything to draw. A not drawn surface can still castShadow, |
| 360 |
* which can be used to make a simplified shadow hull for a complex object set as noShadow. |
| 361 |
*/ |
| 362 |
virtual bool isDrawn() const = 0; |
| 363 |
|
| 364 |
/** |
| 365 |
* a discrete surface will never be merged with other surfaces by dmap, which is |
| 366 |
* necessary to prevent mutliple gui surfaces, mirrors, autosprites, and some other |
| 367 |
* special effects from being combined into a single surface |
| 368 |
* guis, merging sprites or other effects, mirrors and remote views are always discrete |
| 369 |
*/ |
| 370 |
virtual bool isDiscrete() const = 0; |
| 371 |
|
| 372 |
// Returns the number of layers in this material |
| 373 |
virtual std::size_t getNumLayers() = 0; |
| 374 |
|
| 375 |
// Returns the n-th layer of this material (0-based index) |
| 376 |
virtual IShaderLayer::Ptr getLayer(std::size_t index) = 0; |
| 377 |
|
| 378 |
/// Return the first material layer, if any |
| 379 |
virtual IShaderLayer* firstLayer() = 0; |
| 380 |
|
| 381 |
/** |
| 382 |
* \brief Visit all layers in this material using the given functor. |
| 383 |
* The functor can return false to abort the traversal, true will continue. |
| 384 |
* This includes all diffuse, bump, specular or blend layers. |
| 385 |
*/ |
| 386 |
virtual void foreachLayer(const std::function<bool(const IShaderLayer::Ptr&)>& functor) = 0; |
| 387 |
|
| 388 |
// Add a new (typed) layer to this material, returning the index of the new layer |
| 389 |
virtual std::size_t addLayer(IShaderLayer::Type type) = 0; |
| 390 |
|
| 391 |
// Removes the indexed layer from this material |
| 392 |
virtual void removeLayer(std::size_t index) = 0; |
| 393 |
|
| 394 |
// Duplicates the given layer and returns the index to the copied one |
| 395 |
virtual std::size_t duplicateLayer(std::size_t index) = 0; |
| 396 |
|
| 397 |
// Swaps the position of the two layers |
| 398 |
virtual void swapLayerPosition(std::size_t first, std::size_t second) = 0; |
| 399 |
|
| 400 |
// Returns the edit interface for the given shader layer. Calling this method |
| 401 |
// will immediately mark this Material as modified. |
| 402 |
virtual IEditableShaderLayer::Ptr getEditableLayer(std::size_t index) = 0; |
| 403 |
|
| 404 |
/// Return the light falloff texture, if this is a light shader |
| 405 |
virtual TexturePtr lightFalloffImage() = 0; |
| 406 |
|
| 407 |
// Return the expression of the light falloff map for use with this shader. |
| 408 |
virtual shaders::IMapExpression::Ptr getLightFalloffExpression() = 0; |
| 409 |
|
| 410 |
// Set the lightFallOff expression to define the image/cubemap to use |
| 411 |
virtual void setLightFalloffExpressionFromString(const std::string& expressionString) = 0; |
| 412 |
|
| 413 |
// Return the type of the light fall off image |
| 414 |
// (can be MapType::Map (lightFalloffImage or MapType::CameraCubeMap for lightFalloffCubeMap) |
| 415 |
virtual IShaderLayer::MapType getLightFalloffCubeMapType() = 0; |
| 416 |
|
| 417 |
// Set the type of the light fall off image |
| 418 |
// (can be MapType::Map (lightFalloffImage or MapType::CameraCubeMap for lightFalloffCubeMap) |
| 419 |
virtual void setLightFalloffCubeMapType(IShaderLayer::MapType type) = 0; |
| 420 |
|
| 421 |
// greebo: Returns the description as defined in the material |
| 422 |
virtual std::string getDescription() const = 0; |
| 423 |
|
| 424 |
// Set the description text of this material |
| 425 |
virtual void setDescription(const std::string& description) = 0; |
| 426 |
|
| 427 |
// Returns the frob stage type this material is using (defaults to FrobStageType::Default) |
| 428 |
virtual FrobStageType getFrobStageType() = 0; |
| 429 |
|
| 430 |
// Sets the frob stage type. Might assign a _white frob stage map expression (if empty). |
| 431 |
virtual void setFrobStageType(FrobStageType type) = 0; |
| 432 |
|
| 433 |
// When FrobStageType::Texture: defines the texture that has been declared using frobstage_texture |
| 434 |
virtual shaders::IMapExpression::Ptr getFrobStageMapExpression() = 0; |
| 435 |
|
| 436 |
// Sets the frob stage map expression (applicable to FrobStageType::Texture) |
| 437 |
virtual void setFrobStageMapExpressionFromString(const std::string& expr) = 0; |
| 438 |
|
| 439 |
// frobstage_diffuse and frobstage_texture accept two (r g b) or float expressions |
| 440 |
// Index is [0..1]. The first parameter is additive, second is multiplicative |
| 441 |
virtual Vector3 getFrobStageRgbParameter(std::size_t index) = 0; |
| 442 |
|
| 443 |
// Assigns the RGB components to the frob stage parameter with the given index => "(x y z)" |
| 444 |
virtual void setFrobStageRgbParameter(std::size_t index, const Vector3& value) = 0; |
| 445 |
|
| 446 |
// Assigns a single uniform value to the frob stage parameter with the given index => "x" |
| 447 |
virtual void setFrobStageParameter(std::size_t index, double value) = 0; |
| 448 |
|
| 449 |
/// Return TRUE if the shader is visible, FALSE if it is filtered or |
| 450 |
/// disabled in any other way. |
| 451 |
virtual bool isVisible() const = 0; |
| 452 |
|
| 453 |
/// Sets the visibility of this shader. |
| 454 |
virtual void setVisible(bool visible) = 0; |
| 455 |
|
| 456 |
// Returns the flags set by the material parser |
| 457 |
virtual int getParseFlags() const = 0; |
| 458 |
|
| 459 |
// Returns the argument string after the renderbump keyword, or an empty string if no statement is present |
| 460 |
virtual std::string getRenderBumpArguments() = 0; |
| 461 |
|
| 462 |
// Returns the argument string after the renderbumpflat keyword, or an empty string if no statement is present |
| 463 |
virtual std::string getRenderBumpFlatArguments() = 0; |
| 464 |
|
| 465 |
// The argument to the "guisurf" keyword, if not entity[2]3]. |
| 466 |
// In case entity[2]3] is set, the corresponding surface flags are enabled |
| 467 |
virtual const std::string& getGuiSurfArgument() = 0; |
| 468 |
|
| 469 |
// True if this mateiral has been altered from its original definition |
| 470 |
virtual bool isModified() = 0; |
| 471 |
|
| 472 |
// Roll back the changes made to this material |
| 473 |
virtual void revertModifications() = 0; |
| 474 |
|
| 475 |
// Reloads the textures used by this material from disk |
| 476 |
virtual void refreshImageMaps() = 0; |
| 477 |
|
| 478 |
struct ParseResult |
| 479 |
{ |
| 480 |
bool success; // whether the update was successful |
| 481 |
std::string parseError; // if success == false, this contains the error message |
| 482 |
}; |
| 483 |
|
| 484 |
// Attempts to redefine this material from the given source text, which is |
| 485 |
// just the block contents, exlcuding the outermost curly braces of the decl. |
| 486 |
// Returns true on success, returns false if the source text could not |
| 487 |
// be successfully parsed (e.g. due to malformed syntax). |
| 488 |
virtual ParseResult updateFromSourceText(const std::string& sourceText) = 0; |
| 489 |
|
| 490 |
// Signal emitted when this material is modified |
| 491 |
virtual sigc::signal<void>& sig_materialChanged() = 0; |
| 492 |
}; |
| 493 |
|
| 494 |
typedef std::shared_ptr<Material> MaterialPtr; |
| 495 |
|
| 496 |
/// Stream insertion of Material for debugging purposes. |
| 497 |
inline |
| 498 |
std::ostream& operator<< (std::ostream& os, const Material& shader) |
| 499 |
{ |
| 500 |
os << "Material(name=" << shader.getName() |
| 501 |
<< ", filename=" << shader.getShaderFileName() |
| 502 |
<< ")"; |
| 503 |
return os; |
| 504 |
} |
| 505 |
|
| 506 |
/// Debug stream insertion of possibly null material pointer |
| 507 |
inline std::ostream& operator<< (std::ostream& os, const Material* m) |
| 508 |
{ |
| 509 |
if (m) |
| 510 |
return os << *m; |
| 511 |
else |
| 512 |
return os << "[no material]"; |
| 513 |
} |
| 514 |
|
| 515 |
typedef std::function<void(const std::string&)> ShaderNameCallback; |
| 516 |
|
| 517 |
// Represents a table declaration in the .mtr files |
| 518 |
class ITableDefinition : |
| 519 |
public decl::IDeclaration |
| 520 |
{ |
| 521 |
public: |
| 522 |
using Ptr = std::shared_ptr<ITableDefinition>; |
| 523 |
|
| 524 |
virtual ~ITableDefinition() {} |
| 525 |
|
| 526 |
// Retrieve a value from this table, respecting the clamp and snap flags |
| 527 |
virtual float getValue(float index) = 0; |
| 528 |
}; |
| 529 |
|
| 530 |
constexpr const char* const MODULE_SHADERSYSTEM = "MaterialManager"; |
| 531 |
|
| 532 |
/** |
| 533 |
* \brief |
| 534 |
* Interface for the material manager. |
| 535 |
* |
| 536 |
* The material manager parses all of the MTR declarations and provides access |
| 537 |
* to Material objects representing the loaded materials. |
| 538 |
*/ |
| 539 |
class IMaterialManager |
| 540 |
: public RegisterableModule |
| 541 |
{ |
| 542 |
public: |
| 543 |
// NOTE: shader and texture names used must be full path. |
| 544 |
// Shaders usable as textures have prefix equal to getTexturePrefix() |
| 545 |
|
| 546 |
/** |
| 547 |
* \brief Return the shader with the given name. The default shader will be |
| 548 |
* returned if name is not found. |
| 549 |
* |
| 550 |
* \param name |
| 551 |
* The text name of the shader to load. |
| 552 |
* |
| 553 |
* \returns |
| 554 |
* MaterialPtr corresponding to the named shader object. |
| 555 |
*/ |
| 556 |
virtual MaterialPtr getMaterial(const std::string& name) = 0; |
| 557 |
|
| 558 |
/** |
| 559 |
* greebo: Returns true if the named material is existing, false otherwise. |
| 560 |
* In the latter case getMaterialForName() would return a default "shader not found". |
| 561 |
*/ |
| 562 |
virtual bool materialExists(const std::string& name) = 0; |
| 563 |
|
| 564 |
/** |
| 565 |
* A material can be modified if it has been declared in a physical file, |
| 566 |
* i.e. outside a PAK file. |
| 567 |
*/ |
| 568 |
virtual bool materialCanBeModified(const std::string& name) = 0; |
| 569 |
|
| 570 |
virtual void foreachShaderName(const ShaderNameCallback& callback) = 0; |
| 571 |
|
| 572 |
/** |
| 573 |
* Visit each material with the given function object. Replaces the legacy foreachShader(). |
| 574 |
*/ |
| 575 |
virtual void foreachMaterial(const std::function<void(const MaterialPtr&)>& func) = 0; |
| 576 |
|
| 577 |
// Set the callback to be invoked when the active shaders list has changed |
| 578 |
virtual sigc::signal<void> signal_activeShadersChanged() const = 0; |
| 579 |
|
| 580 |
// Is invoked when a new material is inserted into the resource tree, passing the name as argument |
| 581 |
virtual sigc::signal<void, const std::string&>& signal_materialCreated() = 0; |
| 582 |
|
| 583 |
// Is called when a material name is changed, passing the old and the new name as arguments |
| 584 |
virtual sigc::signal<void, const std::string&, const std::string&>& signal_materialRenamed() = 0; |
| 585 |
|
| 586 |
// Is emitted when a named material is removed from the library |
| 587 |
virtual sigc::signal<void, const std::string&>& signal_materialRemoved() = 0; |
| 588 |
|
| 589 |
/** |
| 590 |
* Enable or disable active shaders updates (for performance). |
| 591 |
*/ |
| 592 |
virtual void setActiveShaderUpdates(bool val) = 0; |
| 593 |
|
| 594 |
virtual const char* getTexturePrefix() const = 0; |
| 595 |
|
| 596 |
/** |
| 597 |
* \brief |
| 598 |
* Return the default texture to be used for lighting mode rendering if it |
| 599 |
* is not defined for a shader. |
| 600 |
* |
| 601 |
* \param type |
| 602 |
* The type of interaction layer whose default texture is required. |
| 603 |
*/ |
| 604 |
virtual TexturePtr getDefaultInteractionTexture(IShaderLayer::Type type) = 0; |
| 605 |
|
| 606 |
/** |
| 607 |
* greebo: This is a substitution for the "old" TexturesCache method |
| 608 |
* used to load an image from a file to graphics memory for arbitrary |
| 609 |
* use (e.g. the Overlay module). |
| 610 |
* |
| 611 |
* @param filename |
| 612 |
* The absolute filename. |
| 613 |
* |
| 614 |
* @param moduleNames |
| 615 |
* The space-separated list of image modules (default is "GDK"). |
| 616 |
*/ |
| 617 |
virtual TexturePtr loadTextureFromFile(const std::string& filename) = 0; |
| 618 |
|
| 619 |
/** |
| 620 |
* Creates a new shader expression for the given string. This can be used to create standalone |
| 621 |
* expression objects for unit testing purposes. |
| 622 |
*/ |
| 623 |
virtual shaders::IShaderExpression::Ptr createShaderExpressionFromString(const std::string& exprStr) = 0; |
| 624 |
|
| 625 |
// Creates a new material using the given name. In case the name is already in use, |
| 626 |
// a generated one will be assigned to the created material |
| 627 |
virtual MaterialPtr createEmptyMaterial(const std::string& name) = 0; |
| 628 |
|
| 629 |
// Creates a copy of the given material and returns the reference to it |
| 630 |
virtual MaterialPtr copyMaterial(const std::string& nameOfOriginal, const std::string& nameOfCopy) = 0; |
| 631 |
|
| 632 |
// Renames the material named oldName to newName, and returns true if the operation was successful. |
| 633 |
// If the new name is already in use, this returns false too. |
| 634 |
virtual bool renameMaterial(const std::string& oldName, const std::string& newName) = 0; |
| 635 |
|
| 636 |
// Removes the named material |
| 637 |
virtual void removeMaterial(const std::string& name) = 0; |
| 638 |
|
| 639 |
// Saves the named material to the file location as specified in its shaderfile info. |
| 640 |
// If the path is not writable or the material is not suitable for saving, this will throw an exception |
| 641 |
virtual void saveMaterial(const std::string& name) = 0; |
| 642 |
|
| 643 |
// Tries to find the named table, returns an empty reference if nothing found |
| 644 |
virtual ITableDefinition::Ptr getTable(const std::string& name) = 0; |
| 645 |
|
| 646 |
// Reload the textures used by the active shaders |
| 647 |
virtual void reloadImages() = 0; |
| 648 |
}; |
| 649 |
|
| 650 |
inline IMaterialManager& GlobalMaterialManager() |
| 651 |
{ |
| 652 |
static module::InstanceReference<IMaterialManager> _reference(MODULE_SHADERSYSTEM); |
| 653 |
return _reference; |
| 654 |
} |