Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TriangleStripBuilder: Moved to new source files; began transition to …
…an abstract class
- Loading branch information
1 parent
5ed0205
commit ad702a3
Showing
5 changed files
with
282 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "render/trianglestripbuilder.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** @file render/trianglestripbuilder.h Triangle Strip Geometry Builder. | ||
* | ||
* @authors Copyright © 2011-2013 Daniel Swanson <danij@dengine.net> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#ifndef DENG_RENDER_TRIANGLE_STRIP_BUILDER | ||
#define DENG_RENDER_TRIANGLE_STRIP_BUILDER | ||
|
||
#include <QVarLengthArray> /// @todo Remove me | ||
|
||
#include <de/libdeng2.h> | ||
#include <de/Vector> | ||
|
||
#include "render/rendpoly.h" /// @todo Remove me | ||
|
||
namespace de { | ||
|
||
/** | ||
* Abstract interface for a component that can be interpreted as an "edge" | ||
* geometry. | ||
*/ | ||
class IEdge | ||
{ | ||
public: | ||
class IIntercept | ||
{ | ||
public: | ||
virtual ~IIntercept() {} | ||
|
||
virtual bool operator < (IIntercept const &other) const { | ||
return distance() < other.distance(); | ||
} | ||
|
||
virtual coord_t distance() const = 0; | ||
|
||
virtual Vector3d origin() const = 0; | ||
}; | ||
|
||
public: | ||
virtual ~IEdge() {} | ||
|
||
virtual bool isValid() const = 0; | ||
|
||
virtual IIntercept const &from() const = 0; | ||
|
||
virtual IIntercept const &to() const = 0; | ||
|
||
virtual Vector2f const &materialOrigin() const = 0; | ||
}; | ||
|
||
typedef QVarLengthArray<rvertex_t, 24> PositionBuffer; | ||
typedef QVarLengthArray<rtexcoord_t, 24> TexCoordBuffer; | ||
|
||
/** | ||
* Abstract triangle strip geometry builder. | ||
* | ||
* Encapsulates the logic of constructing triangle strip geometries. | ||
* | ||
* @ingroup render | ||
* | ||
* @todo Separate the backing store with an external allocator mechanism. | ||
* (Geometry should not be owned by the builder.) | ||
* @todo Support custom vertex types/do not depend on rvertex_t (etc...). | ||
* (Once implemented move this component to libgui.) | ||
* @todo Support building strips by adding single vertices. | ||
*/ | ||
class TriangleStripBuilder | ||
{ | ||
public: | ||
/** | ||
* Construct a new triangle strip builder. | ||
* | ||
* @param buildTexCoords @c true= construct texture coordinates also. | ||
*/ | ||
TriangleStripBuilder(bool buildTexCoords = false); | ||
|
||
/** | ||
* Begin construction of a new triangle strip geometry. Any existing unclaimed | ||
* geometry is discarded. | ||
* | ||
* Vertex layout: | ||
* 1--3 2--0 | ||
* | | or | | if @a direction @c =Anticlockwise | ||
* 0--2 3--1 | ||
* | ||
* @param direction Initial vertex winding direction. | ||
* | ||
* @param reserveElements Initial number of vertex elements to reserve. If the | ||
* user knows in advance roughly how many elements are required for the geometry | ||
* this number may be reserved from the outset, thereby improving performance | ||
* by minimizing dynamic memory allocations. If the estimate is off the only | ||
* side effect is reduced performance. | ||
*/ | ||
void begin(ClockDirection direction, int reserveElements = 0); | ||
|
||
/** | ||
* Submit an edge geometry to be added to the current triangle strip geometry. | ||
* | ||
* @param edge Edge geometry to add. | ||
* | ||
* @return Reference to this trangle strip builder. | ||
*/ | ||
TriangleStripBuilder &operator << (IEdge &edge); | ||
|
||
/** | ||
* Returns the total number of vertex elements in the current strip geometry. | ||
* If no strip is currently being built @c 0 is returned. | ||
*/ | ||
int numElements() const; | ||
|
||
/** | ||
* Take ownership of the last built strip of geometry. | ||
* | ||
* @param positions The address of the buffer containing the vertex position | ||
* values is written here. | ||
* @param texcoords The address of the buffer containing the texture coord | ||
* values is written here. Can be @c 0. | ||
* | ||
* @return Total number of vertex elements in the geometry (for convenience). | ||
*/ | ||
int take(PositionBuffer **positions, TexCoordBuffer **texcoords = 0); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace de | ||
|
||
#endif // DENG_RENDER_TRIANGLE_STRIP_BUILDER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.