Material.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_MATERIAL_INCLUDED
34 #define H_DC_MATERIAL_INCLUDED
35 
36 
37 #include <Dynacoe/Backends/Renderer/Renderer.h>
38 #include <Dynacoe/Modules/Assets.h>
39 #include <Dynacoe/Util/RefBank.h>
40 namespace Dynacoe {
41 class Camera;
44 class Material {
45  public:
46  Material(const Material &);
47  Material();
48  ~Material();
49 
50 
51  Material & operator=(const Material &);
52 
55  struct State {
56  State();
57 
61 
65 
69 
73 
77 
80  float shininess;
81 
85  float userData[32];
86 
87  bool operator==(const State & other);
88  };
89 
93 
94 
98  enum class CoreProgram {
99  Basic,
100  Lighting
101  };
102 
103  enum class TextureSlot {
104  Color,
105  Normal,
106  Shiny,
107  };
108 
111  void SetProgram(CoreProgram);
112 
115  void SetProgram(ProgramID);
116 
128  void AddTexture(TextureSlot, AssetID image);
129  void AddTexture(uint32_t, AssetID image);
130 
131 
143 
146  void NextTextureFrame();
147 
148  // Prepares a static state with attributes of the material
149  void PopulateState(StaticState * target);
150 
151  std::string Info();
152  private:
153 
154  ProgramID GetProgramID(CoreProgram);
155  Entity::ID framebufferID;
156  RenderBufferID buffer;
157  ProgramID type;
158 
159 
160  std::vector<std::pair<int, int>> texturesRaw;
161  std::vector<std::pair<int, AssetID>> texturesSrc;
162  int textureFrameCount;
163  State previousState;
164 };
165 }
166 
167 
168 #endif
A standard object representing an RGBA color.
Definition: Color.h:47
void NextTextureFrame()
Iterates all textures to the next texture frame.
Default material. No lighting. The color is determined by the Ambient color.
float specularAmount
The amount of specular light that should be allowed.
Definition: Material.h:72
Definition: AssetID.h:37
Interprets the texture as an RGBA texture.
void SetProgram(CoreProgram)
Alters the rendering method to a built-in rendering program.
CoreProgram
The shader type alters how the attributes of the Material are interpreted.
Definition: Material.h:98
State state
Public state of the Material.
Definition: Material.h:92
The viewport object.
Definition: Camera.h:56
float userData[32]
Data that depends on the drawing mode. In implementations that support shaders, this can be used as y...
Definition: Material.h:85
Interprets the texture as a normal map. Each 4-pixel component is interpreted as a normal vector...
void SetFramebufferSource(Camera &)
Sets the given camera as the source framebuffer.
Assets are referred to by an AssetID. The AssetID uniquely refers to an Asset stored within memory...
Definition: AssetID.h:42
Color specular
The specular color of the material.
Definition: Material.h:68
Defines how an AspectMesh is visualized.
Definition: Material.h:44
Color diffuse
The diffuse color of the material.
Definition: Material.h:64
float shininess
The amount of reflected specular light.
Definition: Material.h:80
void AddTexture(TextureSlot, AssetID image)
Adds a texture to be drawn.
TextureSlot
Definition: Material.h:103
THe editable state of the Material.
Definition: Material.h:55
Color ambient
The ambient color of the material.
Definition: Material.h:60
Uniquely identifies an Entity.
Definition: Entity.h:67
Lighting material. The lighting shader is guaranteed to follow and Phong-like shading model...
Interprets the texture as a shiny map. Each red component of each 4-pixel is interpreted as a shiny v...
float diffuseAmount
The amount of diffuse light that should be allowed.
Definition: Material.h:76