1 /** 2 Copyright: Copyright (c) 2016-2017 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.graphics.batch2d; 7 8 import voxelman.container.buffer; 9 import voxelman.model.vertex; 10 import voxelman.math; 11 import voxelman.graphics; 12 13 alias ColoredVertex2d = VertexPosColor!(float, 2, ubyte, 4); 14 15 struct Batch2d 16 { 17 Buffer!ColoredVertex2d triBuffer; 18 Buffer!ColoredVertex2d lineBuffer; 19 Buffer!ColoredVertex2d pointBuffer; 20 21 void putRect(vec2 pos, vec2 size, Color4ub color, bool fill) 22 { 23 enum vec2 offset = vec2(0, 0);// 0.375 24 if (fill) { 25 triBuffer.put( 26 ColoredVertex2d(offset + pos, color), 27 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y), color), 28 ColoredVertex2d(offset + vec2(pos.x, pos.y + size.y), color), 29 ColoredVertex2d(offset + vec2(pos.x, pos.y + size.y), color), 30 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y), color), 31 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y + size.y), color)); 32 } else { 33 lineBuffer.put( 34 ColoredVertex2d(offset + pos, color), 35 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y), color), 36 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y), color), 37 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y + size.y), color), 38 ColoredVertex2d(offset + vec2(pos.x + size.x, pos.y + size.y), color), 39 ColoredVertex2d(offset + vec2(pos.x, pos.y + size.y), color), 40 ColoredVertex2d(offset + vec2(pos.x, pos.y + size.y), color), 41 ColoredVertex2d(offset + vec2(pos.x, pos.y - 1), color)); 42 } 43 } 44 45 void putLine(vec2 start, vec2 end, Color4ub color) 46 { 47 lineBuffer.put( 48 ColoredVertex2d(start, color), 49 ColoredVertex2d(end, color)); 50 } 51 52 void putPoint(vec2 pos, Color4ub color) 53 { 54 pointBuffer.put(ColoredVertex2d(pos, color)); 55 } 56 57 void reset() 58 { 59 triBuffer.clear(); 60 lineBuffer.clear(); 61 pointBuffer.clear(); 62 } 63 }