1 module dlangui.graphics.scene.drawableobject;
2
3 import dlangui.core.config;
4 static if (ENABLE_OPENGL):
5 static if (BACKEND_GUI):
6
7 import dlangui.core.types;
8
9 /// Reference counted DrawableObject
10 alias DrawableObjectRef = Ref!DrawableObject;
11
12 /// base drawable object
13 class DrawableObject : RefCountedObject {
14
15 import dlangui.graphics.scene.node;
16
17 this() {
18 }
19 void draw(Node3d node, bool wireframe) {
20 /// override it
21 }
22 }
23
24 /// base drawable object with material
25 class MaterialDrawableObject : DrawableObject {
26 import dlangui.graphics.scene.node;
27 import dlangui.graphics.scene.material;
28 import dlangui.graphics.scene.light;
29
30 protected MaterialRef _material;
31 protected bool _autobindLights = true;
32 protected Lights _lights;
33
34 this() {
35 }
36
37 this(Material material) {
38 _material = material;
39 }
40
41 @property ref MaterialRef material() { return _material; }
42
43 @property bool autobindLights() { return _autobindLights; }
44 @property MaterialDrawableObject autobindLights(bool flg) { _autobindLights = flg; return this; }
45
46 MaterialDrawableObject bindLight(Light light) {
47 _lights.add(light);
48 return this;
49 }
50
51 MaterialDrawableObject unbindLight(Light light) {
52 _lights.remove(light);
53 return this;
54 }
55
56 protected static __gshared LightParams _lightParamsBuffer;
57 @property protected LightParams * lights(Node3d node) {
58 if (!node.scene)
59 return null;
60 if (!_autobindLights)
61 return null; // TODO: allow manually bound lights
62 if (_lights.empty) {
63 if (node.scene.boundLights.empty)
64 return null;
65 return node.scene.boundLightsPtr;
66 }
67 if (node.scene.boundLights.empty) {
68 _lightParamsBuffer.reset();
69 _lightParamsBuffer.add(_lights);
70 } else {
71 _lightParamsBuffer.reset(node.scene.boundLights);
72 _lightParamsBuffer.add(_lights);
73 }
74 return &_lightParamsBuffer;
75 }
76
77 override void draw(Node3d node, bool wireframe) {
78 /// override it
79 }
80 }