32 #ifndef MultiDrawElements_INCLUDE_ONCE 33 #define MultiDrawElements_INCLUDE_ONCE 88 for(
size_t i=0; i<size; ++i)
150 template <
class arr_type>
158 static const index_type primitive_restart_index = index_type(~0);
164 VL_DEBUG_SET_OBJECT_NAME()
166 mIndexBuffer =
new arr_type;
172 super::operator=(other);
190 const arr_type*
indexBuffer()
const {
return mIndexBuffer.get(); }
195 indexBuffer()->updateBufferObject(mode);
200 indexBuffer()->bufferObject()->deleteBufferObject();
209 if ( !use_bo && !indexBuffer()->size() )
220 glPrimitiveRestartIndex(primitive_restart_index);
VL_CHECK_OGL();
223 const GLvoid **indices_ptr =
NULL;
224 if (use_bo && indexBuffer()->bufferObject()->handle())
226 VL_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer()->bufferObject()->handle());
VL_CHECK_OGL()
227 VL_CHECK(!mBufferObjectPointerVector.empty())
228 indices_ptr = (
const GLvoid**)&mBufferObjectPointerVector[0];
232 VL_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
234 indices_ptr = (
const GLvoid**)&mPointerVector[0];
247 vl::Log::error(
"MultiDrawElements::render(): glMultiDrawElementsBaseVertex() not supported!\n" 248 "OpenGL 3.1 or GL_ARB_draw_elements_base_vertex extension required.\n" 277 const std::vector<const index_type*>&
pointerVector()
const {
return mPointerVector; }
291 VL_CHECK( indexBuffer() && indexBuffer()->size() )
293 const index_type* ptr = (
const index_type*)indexBuffer()->bufferObject()->ptr();
296 mPointerVector[i] = ptr;
304 VL_CHECK( indexBuffer() && indexBuffer()->size() )
305 mBufferObjectPointerVector.resize( mPointerVector.size() );
306 const index_type* base_ptr = (
const index_type*)indexBuffer()->ptr();
308 for(
size_t i=0; i<mPointerVector.size(); ++i)
310 size_t offset = mPointerVector[i] - base_ptr;
311 mBufferObjectPointerVector[i] = (
const index_type*)0 + offset;
332 VL_DEBUG_SET_OBJECT_NAME();
345 VL_DEBUG_SET_OBJECT_NAME();
358 VL_DEBUG_SET_OBJECT_NAME();
362 template <
class arr_type>
Wrapper for the OpenGL function glMultiDrawElements().
MultiDrawElements(EPrimitiveType primitive=PT_TRIANGLES)
TriangleIterator triangleIterator() const
Returns a TriangleIterator used to iterate through the triangles of a DrawCall.
void finalizeSetup()
Calls computePointerVector(), computeBufferObjectPointerVector() and resizes the base vertex array to...
std::vector< GLint > & baseVertices()
Returns the list of base vertices, one for each primitive.
void setIndexBuffer(arr_type *index_buffer)
std::vector< const index_type * > & pointerVector()
The pointer vector used as 'indices' parameter of glMultiDrawElements when NOT using BufferObjects...
const std::vector< GLint > & baseVertices() const
Returns the list of base vertices, one for each primitive.
Index iterator operating over DrawElements, DrawRangeElements and MultiDrawElements.
std::vector< GLsizei > & countVector()
The count vector used as 'count' parameter of glMultiDrawElements.
const std::vector< GLsizei > & countVector() const
The count vector used as 'count' parameter of glMultiDrawElements.
MultiDrawElementsUByte(EPrimitiveType primitive=PT_TRIANGLES)
MultiDrawElementsUInt(EPrimitiveType primitive=PT_TRIANGLES)
Base interface for all MultiDrawElements* sub classes.
void setCountVector(const GLsizei *vcount, size_t size)
Sets the vector defining the length of each primitive and automatically computes the pointer vectors ...
std::vector< GLint > mBaseVertices
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
IndexIterator indexIterator() const
Returns a IndexIterator used to iterate through the virtual indices of a DrawCall.
std::vector< const index_type * > mBufferObjectPointerVector
MultiDrawElements & operator=(const MultiDrawElements &other)
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Visualization Library main namespace.
void initialize(IndexIteratorAbstract *iterator)
virtual bool primitiveRestartEnabled() const
Returns whether the primitive-restart functionality is enabled or not.
void applyPatchParameters() const
const std::vector< const index_type * > & pointerVector() const
The pointer vector used as 'indices' parameter of glMultiDrawElements when NOT using BufferObjects...
virtual void computePointerVector()=0
Computes the pointer vector to be used when BufferObjects are DISABLED.
std::vector< GLsizei > mCountVector
virtual void render(bool use_bo) const
Executes the draw call.
virtual void deleteBufferObject()
Deletes the index buffer's BufferObject.
virtual TriangleIterator triangleIterator() const =0
Returns a TriangleIterator used to iterate through the triangles of a DrawCall.
bool mPrimitiveRestartEnabled
std::vector< const index_type * > & bufferObjectPointerVector()
The pointer vector used as 'indices' parameter of glMultiDrawElements when using BufferObjects.
virtual ref< DrawCall > clone() const
Returns a clone of the draw call.
virtual void computeBufferObjectPointerVector()=0
Computes the pointer vector to be used when BufferObjects are ENABLED.
void setCountVector(const std::vector< GLsizei > &vcount)
Sets the vector defining the length of each primitive and automatically computes the pointer vectors ...
Iterator used to extract the indices of every single triangle of a DrawCall regardless of the primiti...
void computeBufferObjectPointerVector()
Computes bufferObjectPointerVector() based on the values contained in pointerVector().
virtual unsigned int primitiveRestartIndex()
Returns the primitive restart index used by the draw call or 0 if primitive restart is not supported...
void setPrimitiveRestartEnabled(bool enabled)
Enables the primitive-restart functionality.
MultiDrawElementsUShort(EPrimitiveType primitive=PT_TRIANGLES)
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
The base class of DrawArrays, DrawElements, MultiDrawElements and DrawRangeElements.
const std::vector< const index_type * > & bufferObjectPointerVector() const
The pointer vector used as 'indices' parameter of glMultiDrawElements when using BufferObjects.
const arr_type * indexBuffer() const
std::vector< const index_type * > mPointerVector
void computePointerVector()
Computes pointerVector() based on the values contained on countVector().
bool Has_Primitive_Restart
The ref<> class is used to reference-count an Object.
ref< arr_type > mIndexBuffer
Wraps a IndexIteratorAbstract to iterate over the indices of a DrawCall.
void setBaseVertices(const std::vector< GLint > &base_verts)
Returns the list of base vertices, one for each primitive.
EPrimitiveType primitiveType() const
Returns the draw call's primitive type.
arr_type::scalar_type index_type
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode mode)
Updates the index buffer's BufferObject if marked as dirty.