1 /// Implements RenderBundle. This module is exclusive to raylib-d, see #20 and #21. 2 module isodi.future.render_bundle; 3 4 import raylib; 5 6 import isodi.tests; 7 import isodi.position; 8 import isodi.camera : Camera; 9 10 import isodi.raylib.model; 11 import isodi.raylib.display; 12 import isodi.raylib.camera; 13 14 import isodi.future.resource; 15 16 17 @safe: 18 19 20 class RenderBundle : AdvancedDrawableResource { 21 22 /// Position this bundle should be drawn at. 23 Position position; 24 25 /// Resources to be drawn as a part of this render bundle. 26 DrawableResource[] resources; 27 28 this() { } 29 30 this(Position position) { 31 32 this.position = position; 33 34 } 35 36 override void drawOffset(ref Camera camera, Position offset) @trusted { 37 38 import isodi.raylib.internal; 39 40 rlPushMatrix(); 41 scope (exit) rlPopMatrix(); 42 43 const outputPosition = position.sum(offset); 44 45 // Move to the appropriate position 46 rlTranslatef(outputPosition.toTuple3(100, CellPoint.center).expand); 47 48 foreach (resource; resources) { 49 50 rlPushMatrix(); 51 scope (exit) rlPopMatrix(); 52 53 if (auto advancedResource = cast(AdvancedDrawableResource) resource) { 54 55 advancedResource.drawOffset(camera, outputPosition); 56 57 } 58 59 else resource.draw(camera); 60 61 } 62 63 } 64 65 } 66 67 mixin DisplayTest!((display) { 68 69 import isodi.future.model; 70 71 auto bundle1 = new RenderBundle(position(0, 0)); 72 auto bundle2 = new RenderBundle(position(1, 2, Height(0.2))); 73 74 class RotatingResource : DrawableResource { 75 76 void draw(ref Camera camera) @trusted { 77 78 DrawGrid(10, 100); 79 80 camera.applyBillboard(); 81 rlScalef(1, -1, 1); 82 83 auto textWidth = MeasureText("This is a test", 20); 84 DrawText("This is a test", -textWidth/2, 0, 20, Colors.BLACK); 85 86 } 87 88 } 89 90 bundle2.resources ~= [ 91 92 cast(DrawableResource) new RotatingResource(), 93 new OldModel(display, "wraith-white"), 94 95 ]; 96 97 auto rldisplay = cast(RaylibDisplay) display; 98 rldisplay.addAnchor({ 99 100 bundle2.draw(display.camera); 101 102 }).position = bundle2.position; 103 104 });