32 #ifndef DrawElements_INCLUDE_ONCE 33 #define DrawElements_INCLUDE_ONCE 117 template <
class arr_type>
125 static const index_type primitive_restart_index = index_type(~0);
134 bool operator<(const Triangle<index_type>& b)
const 136 if (ABC[0] != b.ABC[0])
137 return ABC[0] < b.ABC[0];
139 if (ABC[1] != b.ABC[1])
140 return ABC[1] < b.ABC[1];
142 return ABC[2] < b.ABC[2];
147 { T tmp = ABC[0]; ABC[0] = ABC[1]; ABC[1] = ABC[2]; ABC[2] = tmp; }
149 { T tmp = ABC[0]; ABC[0] = ABC[1]; ABC[1] = ABC[2]; ABC[2] = tmp; }
157 VL_DEBUG_SET_OBJECT_NAME()
160 mIndexBuffer =
new arr_type;
170 super::operator=(other);
207 const arr_type*
indexBuffer()
const {
return mIndexBuffer.get(); }
212 indexBuffer()->updateBufferObject(mode);
217 indexBuffer()->bufferObject()->deleteBufferObject();
225 #if !defined(NDEBUG) && (defined(VL_OPENGL_ES1) || defined(GL_OPENGL_ES2)) 230 case PT_QUADS:
Log::error(
"vl::DrawElements does not support PT_QUADS under OpenGL ES!\n");
break;
232 case PT_POLYGON:
Log::error(
"vl::DrawElements does not support PT_POLYGON under OpenGL ES!\n");
break;
237 case PT_PATCHES:
Log::error(
"vl::DrawElements does not support PT_PATCHES under OpenGL ES!\n");
break;
243 if (indexBuffer()->glType() != GL_UNSIGNED_BYTE && indexBuffer()->glType() != GL_UNSIGNED_SHORT)
245 Log::error(
"vl::DrawElements only supports GL_UNSIGNED_BYTE and GL_UNSIGNED_SHORT under OpenGL ES!\n");
252 if ( !use_bo && !indexBuffer()->size() )
263 glPrimitiveRestartIndex(primitive_restart_index);
VL_CHECK_OGL();
268 const GLvoid* ptr = indexBuffer()->bufferObject()->ptr();
269 if (use_bo && indexBuffer()->bufferObject()->handle())
271 VL_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer()->bufferObject()->handle());
VL_CHECK_OGL()
276 VL_glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
VL_CHECK_OGL()
281 const char*ptr_end =
NULL;
285 ptr_end = (
char*)ptr +
sizeof(index_type)*(use_bo ? indexBuffer()->sizeBufferObject() : indexBuffer()->size());
288 ptr = (
char*)ptr + mOffset;
293 ptr = (
char*)ptr + mOffset;
296 ptr_end = (
char*)ptr +
sizeof(index_type)*mCount;
300 const GLsizei count = (GLsizei)((index_type*)ptr_end - (index_type*)ptr);
336 unsigned int glerr = glGetError();
337 if (glerr != GL_NO_ERROR)
340 Log::error(
Say(
"glGetError() [%s:%n]: %s\n") << __FILE__ << __LINE__ << msg );
341 Log::warning(
"- If you are using geometry instancing in conjunction with display lists you will have to disable one of them.\n" );
342 Log::warning(
"- If you are using OpenGL ES you must not use GL_QUADS, GL_QUAD_STRIP and GL_POLYGON primitive types.\n" );
383 VL_DEBUG_SET_OBJECT_NAME();
396 VL_DEBUG_SET_OBJECT_NAME();
409 VL_DEBUG_SET_OBJECT_NAME();
int baseVertex() const
Returns the currently used base vertex.
void setBaseVertex(int base_vertex)
If base_vertx is != 0 glDrawElementsBaseVertex/glDrawElementsInstancedBaseVertex will be used instead...
DrawElements & operator=(const DrawElements &other)
Assign operator.
A simple String formatting class.
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
TriangleIterator triangleIterator() const
Returns a TriangleIterator used to iterate through the triangles of a DrawCall.
Index iterator operating over DrawElements, DrawRangeElements and MultiDrawElements.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
virtual void render(bool use_bo) const
Executes the draw call.
ref< arr_type > mIndexBuffer
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setInstances(int instances)
Sets the number of instances for this set of primitives.
bool Has_Primitive_Instancing
int i32
32 bits signed integer
Wrapper for the OpenGL function glDrawElements().
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Visualization Library main namespace.
void initialize(IndexIteratorAbstract *iterator)
Base interface for all DrawElements* sub classes.
void applyPatchParameters() const
IndexIterator indexIterator() const
Returns a IndexIterator used to iterate through the virtual indices of a DrawCall.
i32 count() const
The number of indices to render, default is -1 which means 'till the end of the indexBuffer() from of...
arr_type::scalar_type index_type
unsigned int u32
32 bits unsigned integer
const arr_type * indexBuffer() const
The BufferObject containing the indices used to render.
DrawElementsUByte(EPrimitiveType primitive=PT_TRIANGLES, int instances=1)
Iterator used to extract the indices of every single triangle of a DrawCall regardless of the primiti...
virtual ref< DrawCall > clone() const
Returns a clone of this DrawCall.
bool mPrimitiveRestartEnabled
virtual void deleteBufferObject()
Deletes the index buffer's BufferObject.
arr_type * indexBuffer()
The BufferObject containing the indices used to render.
VLGRAPHICS_EXPORT const char * getGLErrorString(int err)
Returns a readable string corresponding to the given OpenGL error code as returned by glGetError() ...
int instances() const
Returns the number of instances for this set of primitives.
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
The base class of DrawArrays, DrawElements, MultiDrawElements and DrawRangeElements.
virtual bool primitiveRestartEnabled() const
Returns whether the primitive-restart functionality is enabled or not (requires OpenGL 3...
DrawElementsUInt(EPrimitiveType primitive=PT_TRIANGLES, int instances=1)
bool Has_Primitive_Restart
The ref<> class is used to reference-count an Object.
u32 offset() const
The offset in bytes from which the index buffer will be read.
Wraps a IndexIteratorAbstract to iterate over the indices of a DrawCall.
EPrimitiveType primitiveType() const
Returns the draw call's primitive type.
DrawElementsUShort(EPrimitiveType primitive=PT_TRIANGLES, int instances=1)
void setCount(i32 count)
The number of indices to render, default is -1 which means 'till the end of the indexBuffer() from of...
virtual void updateDirtyBufferObject(EBufferObjectUpdateMode mode)
Updates the index buffer's BufferObject if marked as dirty.
void setIndexBuffer(arr_type *index_buffer)
The BufferObject containing the indices used to render.
DrawElements(EPrimitiveType primitive=PT_TRIANGLES, int instances=1)
Constructor.
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 (requires OpenGL 3.1).
void setOffset(u32 offset)
The offset in bytes from which the index buffer will be read.