summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-05-06 12:37:10 -0600
committerBrian Paul <brianp@vmware.com>2009-05-06 12:38:35 -0600
commitbb1fb2a5444c6b7d83ccb47949f60ed9fb4f0f93 (patch)
treefedbed4d6694a1a7960663ed32e9fc4b429e9c7e /src
parent88af3f8783452dcf50a9e2e82076f52b2044f643 (diff)
mesa: code consolidation in glDraw[Range]Elements() validation
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/api_validate.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index dfe754dee5..ad150eea80 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -30,6 +30,26 @@
#include "state.h"
+
+/**
+ * \return number of bytes in array [count] of type.
+ */
+static GLsizei
+index_bytes(GLenum type, GLsizei count)
+{
+ if (type == GL_UNSIGNED_INT) {
+ return count * sizeof(GLuint);
+ }
+ else if (type == GL_UNSIGNED_BYTE) {
+ return count * sizeof(GLubyte);
+ }
+ else {
+ ASSERT(type == GL_UNSIGNED_SHORT);
+ return count * sizeof(GLushort);
+ }
+}
+
+
/**
* Find the max index in the given element/index buffer
*/
@@ -146,7 +166,6 @@ _mesa_validate_DrawElements(GLcontext *ctx,
/* Vertex buffer object tests */
if (ctx->Array.ElementArrayBufferObj->Name) {
/* use indices in the buffer object */
- GLuint indexBytes;
if (!ctx->Array.ElementArrayBufferObj->Size) {
_mesa_warning(ctx,
@@ -154,19 +173,8 @@ _mesa_validate_DrawElements(GLcontext *ctx,
return GL_FALSE;
}
- 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);
- }
-
/* make sure count doesn't go outside buffer bounds */
- if (indexBytes > (GLuint) ctx->Array.ElementArrayBufferObj->Size) {
+ if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
_mesa_warning(ctx, "glDrawElements index out of buffer bounds");
return GL_FALSE;
}
@@ -236,21 +244,9 @@ _mesa_validate_DrawRangeElements(GLcontext *ctx, GLenum mode,
/* Vertex buffer object tests */
if (ctx->Array.ElementArrayBufferObj->Name) {
/* use indices in the buffer object */
- GLuint indexBytes;
-
- 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);
- }
/* make sure count doesn't go outside buffer bounds */
- if (indexBytes > ctx->Array.ElementArrayBufferObj->Size) {
+ if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
_mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
return GL_FALSE;
}