1 /**
2  * Copyright:       Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved
3  * Authors:         $(Gabriel Gheorghe)
4  * License:         $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007)
5  * Source:          $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/framework/primitive/impl.d)
6  * Documentation:
7  * Coverage:
8 **/
9 module liberty.framework.primitive.impl;
10 
11 import liberty.logger.impl;
12 import liberty.model.impl;
13 import liberty.scene.entity;
14 import liberty.graphics.shader.impl;
15 
16 /**
17  *
18 **/
19 abstract class Primitive : Entity {
20   private {
21     Shader shader;
22   }
23 
24   /**
25    *
26   **/
27   this(string id) {
28     super(id);
29 
30     shader = Shader
31       .getOrCreate("Primitive", (shader) {
32         shader
33           .addGlobalRenderMethod((program) {
34             program.loadUniform("uSkyColor", scene.world.getExpHeightFogColor);
35           })
36           .addPerEntityRenderMethod((program) {
37             program.loadUniform("uUseFakeLighting", model.fakeLightingEnabled);
38           });
39       });
40 
41     shader.registerEntity(this);
42     scene.shaderMap[shader.id] = shader;
43   }
44 }
45 
46 /**
47  *
48 **/
49 abstract class UniquePrimitive : Primitive {
50   private static bool hasInstance;
51   /**
52    *
53   **/
54   this(string id) {
55     if (this.hasInstance) {
56       Logger.error(
57         "Cannot have multiple instances", 
58         typeof(this).stringof
59       );
60     }
61     super(id);
62     this.hasInstance = true;
63   }
64 }