primBuilder.h 3.4 KB

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