primBuilder.h

Engine/source/gfx/primBuilder.h

More...

Namespaces:

namespace

Primitive Builder.

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _PRIMBUILDER_H_
25#define _PRIMBUILDER_H_
26
27#include "gfx/gfxVertexBuffer.h"
28
29//**************************************************************************
30//
31//**************************************************************************
32
33/// Primitive Builder.
34///
35/// A simple interface to put together lines and polygons
36/// quickly and easily - OpenGL style. This is basically
37/// a convenient way to fill a vertex buffer, then draw it.
38///
39/// There are two ways to use it. You can use the begin()
40/// and end() calls to have it draw immediately after calling
41/// end(). This is the "OpenGL" or "immediate" style of usage.
42///
43/// The other way to use this is to use the beginToBuffer()
44/// and endToBuffer() calls, which let you store the
45/// results of your intermediate calls for later use.
46/// This is much more efficient than using the immediate style.
47///
48namespace PrimBuild
49{
50   extern const ColorI _colWhite;
51
52   void beginToBuffer( GFXPrimitiveType type, U32 maxVerts );
53   GFXVertexBuffer *endToBuffer( U32 &outNumPrims );
54
55   void begin( GFXPrimitiveType type, U32 maxVerts );
56   void end( bool useGenericShaders = true );
57
58   void vertex2f( F32 x, F32 y );
59   void vertex3f( F32 x, F32 y, F32 z );
60
61   void vertex2fv( const F32 *data );
62   inline void vertex2fv( const Point2F &pnt ) { vertex2fv( (F32 *) &pnt ); };
63   inline void vertex2fv( const Point2F *pnt ) { vertex2fv( (F32 *) pnt ); };
64
65   void vertex3fv( const F32 *data );
66   inline void vertex3fv( const Point3F &pnt ) { vertex3fv( (F32 *) &pnt ); };
67   inline void vertex3fv( const Point3F *pnt ) { vertex3fv( (F32 *) pnt ); };
68
69   inline void vertex2i( S32 x, S32 y ) { vertex2f((F32)x, (F32)y); }
70   inline void vertex3i( S32 x, S32 y, S32 z ) { vertex3f((F32)x, (F32)y, (F32)z); }
71
72   void color( const ColorI & );
73   void color( const LinearColorF & );
74   void color3i( U8 red, U8 green, U8 blue );
75   void color4i( U8 red, U8 green, U8 blue, U8 alpha );
76   void color3f( F32 red, F32 green, F32 blue );
77   void color4f( F32 red, F32 green, F32 blue, F32 alpha );
78
79   inline void colorWhite() { color( _colWhite ); }
80
81   void texCoord2f( F32 x, F32 y );
82
83   void shutdown();
84}
85
86#endif
87