&& !(ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled))
return GL_FALSE;
+ /* Vertex buffer object tests */
+ if (ctx->Array.ElementArrayBufferObj->Name) {
+ GLuint indexBytes;
+
+ /* use indices in the buffer object */
+ if (!ctx->Array.ElementArrayBufferObj->Data) {
+ _mesa_warning(ctx, "DrawElements with empty vertex elements buffer!");
+ return GL_FALSE;
+ }
+
+ /* make sure count doesn't go outside buffer bounds */
+ if (type == GL_UNSIGNED_INT) {
+ indexBytes = count * sizeof(GLuint);
+ }
+ else if (type == GL_UNSIGNED_BYTE) {
+ indexBytes = count * sizeof(GLubyte);
+ }
+ else {
+ ASSERT(type == GL_UNSIGNED_SHORT);
+ indexBytes = count * sizeof(GLushort);
+ }
+
+ if ((GLubyte *) indices + indexBytes >
+ ctx->Array.ElementArrayBufferObj->Data +
+ ctx->Array.ElementArrayBufferObj->Size) {
+ _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
+ return GL_FALSE;
+ }
+
+ /* Actual address is the sum of pointers. Indices may be used below. */
+ if (ctx->Const.CheckArrayBounds) {
+ indices = (const GLvoid *)
+ ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data,
+ (const GLubyte *) indices);
+ }
+ }
+
if (ctx->Const.CheckArrayBounds) {
/* find max array index */
GLuint max = 0;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->Array.ElementArrayBufferObj->Name) {
- /* use indices in the buffer object */
- ASSERT(ctx->Array.ElementArrayBufferObj->Data);
- indices = (const GLvoid **) ctx->Array.ElementArrayBufferObj->Data;
- }
-
for (i = 0; i < primcount; i++) {
if (count[i] > 0) {
(ctx->Exec->DrawElements)(mode, count[i], type, indices[i]);
for ( i = 0 ; i < primcount ; i++ ) {
if ( count[i] > 0 ) {
- (ctx->Exec->DrawArrays)( *(GLenum *) ((char *) mode + (i * modestride)),
- first[i], count[i] );
+ GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+ (ctx->Exec->DrawArrays)( m, first[i], count[i] );
}
}
}
for ( i = 0 ; i < primcount ; i++ ) {
if ( count[i] > 0 ) {
- (ctx->Exec->DrawElements)( *(GLenum *) ((char *) mode + (i * modestride)),
- count[i], type, indices[i] );
+ GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
+ (ctx->Exec->DrawElements)( m, count[i], type, indices[i] );
}
}
}
"DrawRangeElements with empty vertex elements buffer!");
return;
}
- indices = (GLvoid *) ctx->Array.ElementArrayBufferObj->Data;
+ /* actual address is the sum of pointers */
+ indices = (const GLvoid *)
+ ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data,
+ (const GLubyte *) indices);
}
/* Check arguments, etc.
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(NULL, "_tnl_DrawElements %d\n", count);
- if (ctx->Array.ElementArrayBufferObj->Name) {
- /* use indices in the buffer object */
- if (!ctx->Array.ElementArrayBufferObj->Data) {
- _mesa_warning(ctx, "DrawElements with empty vertex elements buffer!");
- return;
- }
- indices = (const GLvoid *) ctx->Array.ElementArrayBufferObj->Data;
- }
-
- /* Check arguments, etc.
- */
+ /* Check arguments, etc. */
if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
return;
+ if (ctx->Array.ElementArrayBufferObj->Name) {
+ /* actual address is the sum of pointers */
+ indices = (const GLvoid *)
+ ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data,
+ (const GLubyte *) indices);
+ }
+
ui_indices = (GLuint *)_ac_import_elements( ctx, GL_UNSIGNED_INT,
count, type, indices );