Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef DrawArrays_INCLUDE_DEFINE
00033 #define DrawArrays_INCLUDE_DEFINE
00034
00035 #include <vlGraphics/DrawCall.hpp>
00036 #include <vlGraphics/TriangleIterator.hpp>
00037
00038 namespace vl
00039 {
00040
00041
00042
00057 class DrawArrays: public DrawCall
00058 {
00059 VL_INSTRUMENT_CLASS(vl::DrawArrays, DrawCall)
00060
00061 public:
00062 DrawArrays(): mStart(0), mCount(0)
00063 {
00064 VL_DEBUG_SET_OBJECT_NAME()
00065 mType = PT_TRIANGLES;
00066 mInstances = 1;
00067 }
00068
00069 DrawArrays(EPrimitiveType primitive, int start, int count, int instances=1)
00070 : mStart(start), mCount(count)
00071 {
00072 VL_DEBUG_SET_OBJECT_NAME()
00073 mInstances = instances;
00074 mType = primitive;
00075 }
00076
00077 DrawArrays& operator=(const DrawArrays& other)
00078 {
00079 super::operator=(other);
00080 mStart = other.mStart;
00081 mCount = other.mCount;
00082 mInstances = other.mInstances;
00083 return *this;
00084 }
00085
00086 virtual ref<DrawCall> clone() const
00087 {
00088 return new DrawArrays( primitiveType(), (int)start(), (int)count(), (int)instances() );
00089 }
00090
00091 virtual void deleteBufferObject() {}
00092 virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) {}
00093
00094 virtual void render(bool) const
00095 {
00096
00097 applyPatchParameters();
00098
00099 if ( instances() > 1 && (Has_GL_ARB_draw_instanced||Has_GL_EXT_draw_instanced) )
00100 VL_glDrawArraysInstanced( primitiveType(), (int)start(), (int)count(), (int)instances() );
00101 else
00102 glDrawArrays( primitiveType(), (int)start(), (int)count() );
00103
00104 #ifndef NDEBUG
00105 unsigned int glerr = glGetError();
00106 if (glerr != GL_NO_ERROR)
00107 {
00108 String msg( getGLErrorString(glerr) );
00109 Log::error( Say("glGetError() [%s:%n]: %s\n") << __FILE__ << __LINE__ << msg );
00110 Log::warning( "- If you are using geometry instancing in conjunction with display lists you will have to disable one of them.\n" );
00111 Log::warning( "- If you are using OpenGL ES you must NOT use GL_QUADS, GL_QUAD_STRIP and GL_POLYGON primitive types.\n" );
00112 VL_TRAP()
00113 }
00114 #endif
00115 }
00116
00118 void setStart(int start) { mStart = start; }
00119
00121 int start() const { return mStart; }
00122
00124 void setCount(int count) { mCount = count; }
00125
00127 int count() const { return mCount; }
00128
00130 void setInstances(int instances) { mInstances = instances; }
00131
00133 int instances() const { return mInstances; }
00134
00135 TriangleIterator triangleIterator() const
00136 {
00137 ref<TriangleIteratorDirect> tid = new TriangleIteratorDirect( primitiveType() );
00138 tid->initialize(mStart, mStart+mCount);
00139 return TriangleIterator(tid.get());
00140 }
00141
00142 IndexIterator indexIterator() const
00143 {
00144 ref<IndexIteratorDrawArrays> iida = new IndexIteratorDrawArrays;
00145 iida->initialize( mStart, mCount );
00146 IndexIterator iit;
00147 iit.initialize( iida.get() );
00148 return iit;
00149 }
00150
00151 protected:
00152 int mStart;
00153 int mCount;
00154 int mInstances;
00155 };
00156
00157 }
00158
00159 #endif
00160