Permalink
Browse files

Simplify VertexArray

  • Loading branch information...
Dgame committed May 16, 2015
1 parent 7c3626f commit 222771e0b9fa7212f96fde46280a17a9c2f940f4
@@ -153,6 +153,14 @@ final:
}
}
/**
* Clear all Vertices but preserve the storage and capacity
*/
void clear() nothrow {
_vertices.length = 0;
_vertices.assumeSafeAppend();
}
/**
* Stores a Vertex
*/
@@ -15,6 +15,15 @@ import Dgame.Window.Window;
public:
/**
* A VertrexArray is a simple way to handle a performant textured shape.
* It provides a simple API and maintains the necessary properties.
* It is similar to a trimmed-down version of Shape, but does not contain possible unnecessary content.
*
* See: Shape, Vertex
*
* Author: Randy Schuett (rswhite4@googlemail.com)
*/
class VertexArray : Drawable {
private:
Vertex[] _vertices;
@@ -23,16 +32,19 @@ private:
protected:
@nogc
override void draw(ref const Window wnd) nothrow {
wnd.draw(Geometry.TriangleStrip, _texture, _vertices);
wnd.draw(this.geometry, _texture, _vertices);
}
public:
Geometry geometry;
final:
/**
* CTor
*/
@nogc
this(ref Texture texture) pure nothrow {
this(Geometry geometry, ref Texture texture) pure nothrow {
this.geometry = geometry;
this.setTexture(texture);
}
@@ -53,59 +65,18 @@ final:
}
/**
* Clear all Vertices but preserve the storage and capacity
* Reserve (additional) space for the internal Vertex array
*/
void clear() nothrow {
_vertices.length = 0;
_vertices.assumeSafeAppend();
void reserve(size_t size) pure nothrow {
_vertices.reserve(size);
}
/**
* Appends four Vertices arounds the given position with the given texture coordinates
*/
void append()(auto ref const Vector2f position) pure nothrow {
this.append(position, Rect(0, 0, _texture.width, _texture.height));
}
/**
* Appends four Vertices arounds the given position with the given texture coordinates
* Clear all Vertices but preserve the storage and capacity
*/
void append()(auto ref const Vector2f position, auto ref const Rect texRect) pure nothrow {
immutable float tx = float(texRect.x) / _texture.width;
immutable float ty = float(texRect.y) / _texture.height;
immutable float tw = float(texRect.width) / _texture.width;
immutable float th = float(texRect.height) / _texture.height;
immutable float tx_tw = tx + tw;
immutable float ty_th = ty + th;
immutable float cx_tw = position.x + texRect.width;
immutable float cy_th = position.y + texRect.height;
_vertices.reserve(4);
_vertices ~= Vertex(
position,
Vector2f(tx, ty),
Color4f.White
);
_vertices ~= Vertex(
Vector2f(cx_tw, position.y),
Vector2f(tx_tw, ty),
Color4f.White
);
_vertices ~= Vertex(
Vector2f(position.x, cy_th),
Vector2f(tx, ty_th),
Color4f.White
);
_vertices ~= Vertex(
Vector2f(cx_tw, cy_th),
Vector2f(tx_tw, ty_th),
Color4f.White
);
void clear() nothrow {
_vertices.length = 0;
_vertices.assumeSafeAppend();
}
/**
@@ -70,6 +70,11 @@ <h1>Dgame.Graphic.Shape</h1>
</big></dt>
<dd>CTor for circles<br><br>
</dd>
<dt><big><a name="Shape.clear"></a>final nothrow void <u>clear</u>();
</big></dt>
<dd>Clear all Vertices but preserve the storage and capacity<br><br>
</dd>
<dt><big><a name="Shape.append"></a>pure nothrow void <u>append</u>()(auto ref const Vertex <i>vertex</i>);
</big></dt>
@@ -5,6 +5,62 @@
<h1>Dgame.Graphic.VertexArray</h1>
<!-- Generated by Ddoc from ..\Graphic\VertexArray.d -->
<br><br>
<dl><dt><big><a name="VertexArray"></a>class <u>VertexArray</u>: <u>Dgame.Graphic.Drawable.Drawable</u>;
</big></dt>
<dd>A VertrexArray is a simple way to handle a performant textured shape.
It provides a simple API and maintains the necessary properties.
It is similar to a trimmed-down version of Shape, but does not contain possible unnecessary content.
<br><br>
<b>See:</b><br>
Shape, Vertex
<br><br>
<b>Author:</b><br>
Randy Schuett (rswhite4@googlemail.com)<br><br>
<dl><dt><big><a name="VertexArray.this"></a>final pure nothrow @nogc this(Geometry <i>geometry</i>, ref Texture <i>texture</i>);
</big></dt>
<dd>CTor<br><br>
</dd>
<dt><big><a name="VertexArray.setTexture"></a>final pure nothrow @nogc void <u>setTexture</u>(ref Texture <i>texture</i>);
</big></dt>
<dd>Set or reset a Texture<br><br>
</dd>
<dt><big><a name="VertexArray.getTexture"></a>final inout pure nothrow @nogc inout(Texture)* <u>getTexture</u>();
</big></dt>
<dd>Returns the current texture or <b>null</b><br><br>
</dd>
<dt><big><a name="VertexArray.reserve"></a>final pure nothrow void <u>reserve</u>(size_t <i>size</i>);
</big></dt>
<dd>Reserve (additional) space for the internal Vertex array<br><br>
</dd>
<dt><big><a name="VertexArray.clear"></a>final nothrow void <u>clear</u>();
</big></dt>
<dd>Clear all Vertices but preserve the storage and capacity<br><br>
</dd>
<dt><big><a name="VertexArray.append"></a>pure nothrow void <u>append</u>()(auto ref const Vertex <i>vertex</i>);
</big></dt>
<dd>Stores a Vertex<br><br>
</dd>
<dt><big><a name="VertexArray.opIndex"></a>final inout pure nothrow @nogc ref inout(Vertex) <u>opIndex</u>(size_t <i>index</i>);
</big></dt>
<dd>Returns all Vertices<br><br>
</dd>
<dt><big><a name="VertexArray.length"></a>final const pure nothrow @nogc @property size_t <u>length</u>();
</big></dt>
<dd>Returns the current amount of stored Vertices<br><br>
</dd>
</dl>
</dd>
</dl>
<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>

0 comments on commit 222771e

Please sign in to comment.