Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
DrawArrays.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef DrawArrays_INCLUDE_DEFINE
33 #define DrawArrays_INCLUDE_DEFINE
34 
35 #include <vlGraphics/DrawCall.hpp>
37 
38 namespace vl
39 {
40  //------------------------------------------------------------------------------
41  // DrawArrays
42  //------------------------------------------------------------------------------
57  class DrawArrays: public DrawCall
58  {
60 
61  public:
63  {
64  VL_DEBUG_SET_OBJECT_NAME()
66  mInstances = 1;
67  }
68 
69  DrawArrays(EPrimitiveType primitive, int start, int count, int instances=1)
70  : mStart(start), mCount(count)
71  {
72  VL_DEBUG_SET_OBJECT_NAME()
74  mType = primitive;
75  }
76 
78  {
79  super::operator=(other);
80  mStart = other.mStart;
81  mCount = other.mCount;
82  mInstances = other.mInstances;
83  return *this;
84  }
85 
86  virtual ref<DrawCall> clone() const
87  {
88  return new DrawArrays( primitiveType(), (int)start(), (int)count(), (int)instances() );
89  }
90 
91  virtual void deleteBufferObject() {}
93 
94  virtual void render(bool) const
95  {
96  VL_CHECK_OGL()
97 
98  // apply patch parameters if any and if using PT_PATCHES
100 
101  if ( instances() > 1 && (Has_GL_ARB_draw_instanced||Has_GL_EXT_draw_instanced) )
102  VL_glDrawArraysInstanced( primitiveType(), (int)start(), (int)count(), (int)instances() );
103  else
104  glDrawArrays( primitiveType(), (int)start(), (int)count() );
105 
106  #ifndef NDEBUG
107  unsigned int glerr = glGetError();
108  if (glerr != GL_NO_ERROR)
109  {
110  String msg( getGLErrorString(glerr) );
111  Log::error( Say("glGetError() [%s:%n]: %s\n") << __FILE__ << __LINE__ << msg );
112  Log::warning( "- If you are using geometry instancing in conjunction with display lists you will have to disable one of them.\n" );
113  Log::warning( "- If you are using OpenGL ES you must NOT use GL_QUADS, GL_QUAD_STRIP and GL_POLYGON primitive types.\n" );
114  VL_TRAP()
115  }
116  #endif
117  }
118 
120  void setStart(int start) { mStart = start; }
121 
123  int start() const { return mStart; }
124 
126  void setCount(int count) { mCount = count; }
127 
129  int count() const { return mCount; }
130 
133 
135  int instances() const { return mInstances; }
136 
138  {
140  tid->initialize(mStart, mStart+mCount);
141  return TriangleIterator(tid.get());
142  }
143 
145  {
147  iida->initialize( mStart, mCount );
148  IndexIterator iit;
149  iit.initialize( iida.get() );
150  return iit;
151  }
152 
153  protected:
154  int mStart;
155  int mCount;
157  };
158 
159 }
160 
161 #endif
162 
const T * get() const
Definition: Object.hpp:128
A simple String formatting class.
Definition: Say.hpp:124
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
Definition: Log.cpp:155
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
DrawArrays & operator=(const DrawArrays &other)
Definition: DrawArrays.hpp:77
DrawArrays(EPrimitiveType primitive, int start, int count, int instances=1)
Definition: DrawArrays.hpp:69
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
Definition: Log.cpp:165
For internal use only.
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
EPrimitiveType
virtual void deleteBufferObject()
Deletes the index buffer&#39;s BufferObject.
Definition: DrawArrays.hpp:91
Visualization Library main namespace.
void initialize(IndexIteratorAbstract *iterator)
void applyPatchParameters() const
Definition: DrawCall.hpp:178
void setStart(int start)
sets the starting vertex for the rendering.
Definition: DrawArrays.hpp:120
void setCount(int count)
sets the number of vertices to be rendered.
Definition: DrawArrays.hpp:126
#define VL_TRAP()
Definition: checks.hpp:70
virtual void render(bool) const
Executes the draw call.
Definition: DrawArrays.hpp:94
int count() const
returns the number of vertices to be rendered.
Definition: DrawArrays.hpp:129
Index iterator operating used by DrawArrays.
EPrimitiveType mType
Definition: DrawCall.hpp:196
Iterator used to extract the indices of every single triangle of a DrawCall regardless of the primiti...
EBufferObjectUpdateMode
IndexIterator indexIterator() const
Returns a IndexIterator used to iterate through the virtual indices of a DrawCall.
Definition: DrawArrays.hpp:144
VLGRAPHICS_EXPORT const char * getGLErrorString(int err)
Returns a readable string corresponding to the given OpenGL error code as returned by glGetError() ...
Definition: OpenGL.cpp:591
#define VL_CHECK_OGL()
Definition: OpenGL.hpp:156
The base class of DrawArrays, DrawElements, MultiDrawElements and DrawRangeElements.
Definition: DrawCall.hpp:90
virtual ref< DrawCall > clone() const
Returns a clone of the draw call.
Definition: DrawArrays.hpp:86
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
int start() const
returns the starting vertex for the rendering.
Definition: DrawArrays.hpp:123
void setInstances(int instances)
Sets the number of instances for this set of primitives.
Definition: DrawArrays.hpp:132
int instances() const
Returns the number of instances for this set of primitives.
Definition: DrawArrays.hpp:135
Wraps a IndexIteratorAbstract to iterate over the indices of a DrawCall.
EPrimitiveType primitiveType() const
Returns the draw call&#39;s primitive type.
Definition: DrawCall.hpp:110
Wraps the OpenGL function glDrawArrays().
Definition: DrawArrays.hpp:57
TriangleIterator triangleIterator() const
Returns a TriangleIterator used to iterate through the triangles of a DrawCall.
Definition: DrawArrays.hpp:137
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode)
Updates the index buffer&#39;s BufferObject if marked as dirty.
Definition: DrawArrays.hpp:92