/**
+ * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
+ * etc? The set of legal values depends on whether geometry shaders/programs
+ * are supported.
+ */
+GLboolean
+_mesa_valid_prim_mode(const struct gl_context *ctx, GLenum mode)
+{
+ if (ctx->Extensions.ARB_geometry_shader4 &&
+ mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ return GL_FALSE;
+ }
+ else if (mode > GL_POLYGON) {
+ return GL_FALSE;
+ }
+ else {
+ return GL_TRUE;
+ }
+}
+
+
+/**
* Error checking for glDrawElements(). Includes parameter checking
* and VBO bounds checking.
* \return GL_TRUE if OK to render, GL_FALSE if error found
return GL_FALSE;
}
- if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)" );
return GL_FALSE;
}
return GL_FALSE;
}
- if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glDrawRangeElements(mode)" );
return GL_FALSE;
}
return GL_FALSE;
}
- if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glDrawArrays(mode)" );
return GL_FALSE;
}
return GL_FALSE;
}
- if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glDrawArraysInstanced(mode=0x%x)", mode);
return GL_FALSE;
return GL_FALSE;
}
- if (mode > GL_TRIANGLE_STRIP_ADJACENCY_ARB) {
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glDrawElementsInstanced(mode = 0x%x)", mode);
return GL_FALSE;
#include "api_arrayelt.h"
#include "api_exec.h"
#include "api_loopback.h"
+#include "api_validate.h"
#if FEATURE_ATI_fragment_shader
#include "atifragshader.h"
#endif
Node *n;
GLboolean error = GL_FALSE;
- if ( /*mode < GL_POINTS || */ mode > GL_POLYGON) {
- _mesa_compile_error(ctx, GL_INVALID_ENUM, "Begin (mode)");
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
+ _mesa_compile_error(ctx, GL_INVALID_ENUM, "glBegin(mode)");
error = GL_TRUE;
}
else if (ctx->Driver.CurrentSavePrimitive == PRIM_UNKNOWN) {
#include "main/light.h"
#include "main/api_arrayelt.h"
#include "main/api_noop.h"
+#include "main/api_validate.h"
#include "main/dispatch.h"
#include "vbo_context.h"
#endif /* FEATURE_evaluators */
+
/**
* Called via glBegin.
*/
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
int i;
+ if (!_mesa_valid_prim_mode(ctx, mode)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBegin");
+ return;
+ }
+
if (ctx->NewState) {
_mesa_update_state( ctx );