1 // Written in the D programming language.
2 /++
3  + Authors: KanzakiKino
4  + Copyright: KanzakiKino 2018
5  + License: LGPL-3.0
6 ++/
7 module g4d.element.shape.rect;
8 import g4d.element.shape.regular,
9        g4d.gl.buffer,
10        g4d.shader.base;
11 import gl3n.linalg;
12 
13 /// An element of rectangle.
14 class RectElement : RegularNgonElement!4
15 {
16     protected ArrayBuffer _uv;
17 
18     ///
19     this ()
20     {
21         super();
22     }
23 
24     ///
25     override void clear ()
26     {
27         super.clear();
28         _uv = new ArrayBuffer( new float[N*2] );
29     }
30 
31     /// UV can be specified.
32     void resize ( vec2 sz, vec2 uv = vec2(1f,1f) )
33     {
34         auto halfW = sz.x/2;
35         auto halfH = sz.y/2;
36 
37         _pos.overwrite([
38             -halfW,  halfH, 0, 1,
39              halfW,  halfH, 0, 1,
40              halfW, -halfH, 0, 1,
41             -halfW, -halfH, 0, 1,
42         ]);
43         _uv.overwrite([
44             0f,0f, uv.x,0f, uv.x,uv.y, 0f,uv.y,
45         ]);
46     }
47 
48     ///
49     override void draw ( Shader s )
50     {
51         if ( s.textureSupport ) {
52             s.uploadUvBuffer( _uv );
53         }
54         super.draw(s);
55     }
56 }