Pioneer
Material.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _MATERIAL_H
5 #define _MATERIAL_H
6 /*
7  * Materials are used to apply an appropriate shader and other rendering parameters.
8  * Users request materials from the renderer by filling a MaterialDescriptor structure,
9  * and calling Renderer::CreateMaterial.
10  * Users are responsible for deleting a material they have requested. This is because materials
11  * are rarely shareable.
12  * Material::Apply is called by renderer before drawing, and Unapply after drawing (to restore state).
13  * For the OGL renderer, a Material is always accompanied by a Program.
14  */
15 #include "Color.h"
16 #include "matrix4x4.h"
17 #include "RefCounted.h"
18 
19 namespace Graphics {
20 
21  class Texture;
22  class RendererOGL;
23 
24  // Shorthand for unique effects
25  // The other descriptor parameters may or may not have effect,
26  // depends on the effect
27  enum EffectType {
46  };
47 
48  // XXX : there must be a better place to put this
50  HAS_ATMOSPHERE = 1 << 0,
51  HAS_ECLIPSES = 1 << 1,
52  HAS_HEAT_GRADIENT = 1 << 2
53  };
54 
55  // Renderer creates a material that best matches these requirements.
56  // EffectType may override some of the other flags.
58  public:
61  bool alphaTest;
62  bool glowMap;
63  bool ambientMap;
64  bool lighting;
65  bool normalMap;
67  bool usePatterns; //pattern/color system
69  bool instanced;
70  Sint32 textures; //texture count
71  Uint32 dirLights; //set by RendererOGL if lighting == true
72  Uint32 quality; // see: Graphics::MaterialQuality
73  Uint32 numShadows; //use by GeoSphere/GasGiant for eclipse
74 
75  friend bool operator==(const MaterialDescriptor &a, const MaterialDescriptor &b);
76  };
77 
78  /*
79  * A generic material with some generic parameters.
80  */
81  class Material : public RefCounted {
82  public:
83  Material();
84  virtual ~Material() {}
85 
94 
98  int shininess; //specular power 0-128
99 
100  virtual void Apply() {}
101  virtual void Unapply() {}
102  virtual bool IsProgramLoaded() const = 0;
103 
104  virtual void SetCommonUniforms(const matrix4x4f &mv, const matrix4x4f &proj) = 0;
105 
106  void *specialParameter0; //this can be whatever. Bit of a hack.
107 
108  //XXX may not be necessary. Used by newmodel to check if a material uses patterns
109  const MaterialDescriptor &GetDescriptor() const { return m_descriptor; }
110 
111  protected:
113 
114  private:
115  friend class RendererOGL;
116  };
117 
118 } // namespace Graphics
119 
120 #endif
Definition: Material.h:57
bool alphaTest
Definition: Material.h:61
bool lighting
Definition: Material.h:64
bool normalMap
Definition: Material.h:65
bool specularMap
Definition: Material.h:66
Uint32 numShadows
Definition: Material.h:73
Sint32 textures
Definition: Material.h:70
friend bool operator==(const MaterialDescriptor &a, const MaterialDescriptor &b)
Definition: Material.cpp:43
Uint32 quality
Definition: Material.h:72
bool instanced
Definition: Material.h:69
bool usePatterns
Definition: Material.h:67
EffectType effect
Definition: Material.h:60
Uint32 dirLights
Definition: Material.h:71
MaterialDescriptor()
Definition: Material.cpp:25
bool vertexColors
Definition: Material.h:68
bool glowMap
Definition: Material.h:62
bool ambientMap
Definition: Material.h:63
Definition: Material.h:81
Texture * heatGradient
Definition: Material.h:93
Color emissive
Definition: Material.h:97
Texture * texture0
Definition: Material.h:86
Texture * texture3
Definition: Material.h:89
Texture * texture5
Definition: Material.h:91
virtual void Apply()
Definition: Material.h:100
Texture * texture4
Definition: Material.h:90
virtual void Unapply()
Definition: Material.h:101
void * specialParameter0
Definition: Material.h:106
Texture * texture1
Definition: Material.h:87
Color diffuse
Definition: Material.h:95
Texture * texture2
Definition: Material.h:88
MaterialDescriptor m_descriptor
Definition: Material.h:112
virtual bool IsProgramLoaded() const =0
Texture * texture6
Definition: Material.h:92
virtual ~Material()
Definition: Material.h:84
virtual void SetCommonUniforms(const matrix4x4f &mv, const matrix4x4f &proj)=0
Color specular
Definition: Material.h:96
const MaterialDescriptor & GetDescriptor() const
Definition: Material.h:109
Material()
Definition: Material.cpp:8
int shininess
Definition: Material.h:98
Definition: RendererGL.h:45
Definition: Texture.h:106
Definition: RefCounted.h:11
Definition: Background.h:13
EffectType
Definition: Material.h:27
@ EFFECT_BILLBOARD
Definition: Material.h:45
@ EFFECT_GEOSPHERE_SKY
Definition: Material.h:36
@ EFFECT_GASSPHERE_TERRAIN
Definition: Material.h:38
@ EFFECT_SKYBOX
Definition: Material.h:41
@ EFFECT_SHIELD
Definition: Material.h:40
@ EFFECT_BILLBOARD_ATLAS
Definition: Material.h:44
@ EFFECT_GEN_GASGIANT_TEXTURE
Definition: Material.h:43
@ EFFECT_GEOSPHERE_TERRAIN
Definition: Material.h:33
@ EFFECT_GEOSPHERE_TERRAIN_WITH_LAVA
Definition: Material.h:34
@ EFFECT_GEOSPHERE_STAR
Definition: Material.h:37
@ EFFECT_GEOSPHERE_TERRAIN_WITH_WATER
Definition: Material.h:35
@ EFFECT_STARFIELD
Definition: Material.h:31
@ EFFECT_UI
Definition: Material.h:30
@ EFFECT_FRESNEL_SPHERE
Definition: Material.h:39
@ EFFECT_SPHEREIMPOSTOR
Definition: Material.h:42
@ EFFECT_VTXCOLOR
Definition: Material.h:29
@ EFFECT_DEFAULT
Definition: Material.h:28
@ EFFECT_PLANETRING
Definition: Material.h:32
MaterialQuality
Definition: Material.h:49
@ HAS_HEAT_GRADIENT
Definition: Material.h:52
@ HAS_ATMOSPHERE
Definition: Material.h:50
@ HAS_ECLIPSES
Definition: Material.h:51
Definition: Color.h:66