Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
DrawCall.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 DrawCommand_INCLUDE_ONCE
33 #define DrawCommand_INCLUDE_ONCE
34 
35 #include <vlGraphics/Array.hpp>
39 
40 namespace vl
41 {
42  //------------------------------------------------------------------------------
43  // DrawCall
44  //------------------------------------------------------------------------------
90  class DrawCall: public Object
91  {
92  VL_INSTRUMENT_ABSTRACT_CLASS(vl::DrawCalls, Object)
93 
94  public:
97 
99  DrawCall& operator=(const DrawCall& other)
100  {
101  mType = other.mType;
102  mEnabled = other.mEnabled;
103  return *this;
104  }
105 
107  void setPrimitiveType(EPrimitiveType type) { mType = type; }
108 
110  EPrimitiveType primitiveType() const { return mType; }
111 
113  virtual void render(bool use_bo = true) const = 0;
114 
116  virtual ref<DrawCall> clone() const = 0;
117 
120 
122  virtual void deleteBufferObject() = 0;
123 
125  void setEnabled(bool enable) { mEnabled = enable; }
126 
128  bool isEnabled() const { return mEnabled; }
129 
134  virtual TriangleIterator triangleIterator() const = 0;
135 
139  virtual IndexIterator indexIterator() const = 0;
140 
143  {
144  u32 count = 0;
145  for( IndexIterator it = indexIterator(); it.hasNext(); it.next() )
146  ++count;
147  return count;
148  }
149 
152  {
153  u32 count = 0;
154  for( TriangleIterator it = triangleIterator(); it.hasNext(); it.next() )
155  ++count;
156  return count;
157  }
158 
160  virtual int instances() const { return 1; }
161 
163  virtual bool primitiveRestartEnabled() const { return false; }
164 
166  virtual unsigned int primitiveRestartIndex() { return 0; }
167 
169  void setPatchParameter(PatchParameter* patch_param) { mPatchParameter = patch_param; }
170 
173 
175  const PatchParameter* patchParameter() const { return mPatchParameter.get(); }
176 
177  protected:
178  void applyPatchParameters() const
179  {
180  if (mType == PT_PATCHES && mPatchParameter)
181  mPatchParameter->apply();
182 
183  if (mPatchParameter && mType != PT_PATCHES)
184  {
185  vl::Log::warning("PatchParameter used with non PT_PATCHES draw call!\n");
186  }
187  else
188  if (!mPatchParameter && mType == PT_PATCHES)
189  {
190  vl::Log::warning("No PatchParameter supplied while using PT_PATCHES draw call!\n");
191  }
192  }
193 
194  protected:
197  bool mEnabled;
198  };
199 }
200 
201 #endif
const PatchParameter * patchParameter() const
The PatchParameter attached to a DrawCall to be used when using primitive-type PT_PATCHES.
Definition: DrawCall.hpp:175
bool hasNext()
Returns false if the iterator has reached the end of the triangle list.
virtual bool primitiveRestartEnabled() const
Returns whether the primitive-restart functionality is enabled or not.
Definition: DrawCall.hpp:163
void setPrimitiveType(EPrimitiveType type)
Sets the draw call&#39;s primitive type.
Definition: DrawCall.hpp:107
virtual void deleteBufferObject()=0
Deletes the index buffer&#39;s BufferObject.
ref< PatchParameter > mPatchParameter
Definition: DrawCall.hpp:195
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
virtual void render(bool use_bo=true) const =0
Executes the draw call.
u32 countTriangles() const
Counts the number of virtual triangles of a DrawCall., i.e.
Definition: DrawCall.hpp:151
bool isEnabled() const
True if the draw call is enabled.
Definition: DrawCall.hpp:128
virtual ref< DrawCall > clone() const =0
Returns a clone of the draw call.
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode)=0
Updates the index buffer&#39;s BufferObject if marked as dirty.
EPrimitiveType
Visualization Library main namespace.
void applyPatchParameters() const
Definition: DrawCall.hpp:178
DrawCall()
Constructor.
Definition: DrawCall.hpp:96
PatchParameter * patchParameter()
The PatchParameter attached to a DrawCall to be used when using primitive-type PT_PATCHES.
Definition: DrawCall.hpp:172
The base class for all the reference counted objects.
Definition: Object.hpp:158
virtual TriangleIterator triangleIterator() const =0
Returns a TriangleIterator used to iterate through the triangles of a DrawCall.
unsigned int u32
32 bits unsigned integer
Definition: std_types.hpp:51
EPrimitiveType mType
Definition: DrawCall.hpp:196
Iterator used to extract the indices of every single triangle of a DrawCall regardless of the primiti...
virtual int instances() const
Returns the number of instances for this set of primitives.
Definition: DrawCall.hpp:160
EBufferObjectUpdateMode
u32 countIndices() const
Counts the number of virtual indices of a DrawCall., i.e.
Definition: DrawCall.hpp:142
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:145
The base class of DrawArrays, DrawElements, MultiDrawElements and DrawRangeElements.
Definition: DrawCall.hpp:90
DrawCall & operator=(const DrawCall &other)
Assignment operator.
Definition: DrawCall.hpp:99
virtual IndexIterator indexIterator() const =0
Returns a IndexIterator used to iterate through the virtual indices of a DrawCall.
void setEnabled(bool enable)
Enables/disables the draw call.
Definition: DrawCall.hpp:125
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
virtual unsigned int primitiveRestartIndex()
Returns the primitive restart index used by the draw call or 0 if primitive restart is not supported...
Definition: DrawCall.hpp:166
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
void setPatchParameter(PatchParameter *patch_param)
Attach a PatchParameter to a DrawCall to be used when using primitive-type PT_PATCHES.
Definition: DrawCall.hpp:169
Wrapper of glPatchParameter(), specifies the parameters for patch primitives, used by vl::DrawCall::s...