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 #include <vlGraphics/LineIterator.hpp>
00038
00039 namespace vl
00040 {
00041
00042
00043
00058 class DrawArrays: public DrawCall
00059 {
00060 VL_INSTRUMENT_CLASS(vl::DrawArrays, DrawCall)
00061
00062 public:
00063 DrawArrays(): mStart(0), mCount(0)
00064 {
00065 VL_DEBUG_SET_OBJECT_NAME()
00066 mType = PT_TRIANGLES;
00067 mInstances = 1;
00068 }
00069
00070 DrawArrays(EPrimitiveType primitive, int start, int count, int instances=1)
00071 : mStart(start), mCount(count)
00072 {
00073 VL_DEBUG_SET_OBJECT_NAME()
00074 mInstances = instances;
00075 mType = primitive;
00076 }
00077
00078 DrawArrays& operator=(const DrawArrays& other)
00079 {
00080 super::operator=(other);
00081 mStart = other.mStart;
00082 mCount = other.mCount;
00083 mInstances = other.mInstances;
00084 return *this;
00085 }
00086
00087 virtual ref<DrawCall> clone() const
00088 {
00089 return new DrawArrays( primitiveType(), (int)start(), (int)count(), (int)instances() );
00090 }
00091
00092 virtual void deleteBufferObject() {}
00093 virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) {}
00094
00095 virtual void render(bool) const
00096 {
00097
00098 applyPatchParameters();
00099
00100 if ( instances() > 1 && (Has_GL_ARB_draw_instanced||Has_GL_EXT_draw_instanced) )
00101 VL_glDrawArraysInstanced( primitiveType(), (int)start(), (int)count(), (int)instances() );
00102 else
00103 glDrawArrays( primitiveType(), (int)start(), (int)count() );
00104
00105 #ifndef NDEBUG
00106 unsigned int glerr = glGetError();
00107 if (glerr != GL_NO_ERROR)
00108 {
00109 String msg( getGLErrorString(glerr) );
00110 Log::error( Say("glGetError() [%s:%n]: %s\n") << __FILE__ << __LINE__ << msg );
00111 Log::warning( "- If you are using geometry instancing in conjunction with display lists you will have to disable one of them.\n" );
00112 Log::warning( "- If you are using OpenGL ES you must NOT use GL_QUADS, GL_QUAD_STRIP and GL_POLYGON primitive types.\n" );
00113 VL_TRAP()
00114 }
00115 #endif
00116 }
00117
00119 void setStart(int start) { mStart = start; }
00120
00122 int start() const { return mStart; }
00123
00125 void setCount(int count) { mCount = count; }
00126
00128 int count() const { return mCount; }
00129
00131 void setInstances(int instances) { mInstances = instances; }
00132
00134 int instances() const { return mInstances; }
00135
00136 TriangleIterator triangleIterator() const
00137 {
00138 ref<TriangleIteratorDirect> tid = new TriangleIteratorDirect( primitiveType() );
00139 tid->initialize(mStart, mStart+mCount);
00140 return TriangleIterator(tid.get());
00141 }
00142
00143 LineIterator lineIterator() const
00144 {
00145 ref<LineIteratorDirect> lid = new LineIteratorDirect( primitiveType() );
00146 lid->initialize(mStart, mStart+mCount);
00147 return LineIterator(lid.get());
00148 }
00149
00150 IndexIterator indexIterator() const
00151 {
00152 ref<IndexIteratorDrawArrays> iida = new IndexIteratorDrawArrays;
00153 iida->initialize( mStart, mCount );
00154 IndexIterator iit;
00155 iit.initialize( iida.get() );
00156 return iit;
00157 }
00158
00159 protected:
00160 int mStart;
00161 int mCount;
00162 int mInstances;
00163 };
00164
00165 }
00166
00167 #endif
00168