[Mesa-dev] [PATCH 03/12] mesa: Use an early return to unindent most of vbo_exec_Begin/End().
Eric Anholt
eric at anholt.net
Fri Jan 18 14:30:38 PST 2013
---
src/mesa/vbo/vbo_exec_api.c | 109 +++++++++++++++++++++----------------------
1 file changed, 54 insertions(+), 55 deletions(-)
diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
index 657c9aa..42eb953 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -789,54 +789,53 @@ vbo_exec_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
static void GLAPIENTRY vbo_exec_Begin( GLenum mode )
{
GET_CURRENT_CONTEXT( ctx );
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ int i;
- if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- int i;
-
- if (!_mesa_valid_prim_mode(ctx, mode, "glBegin")) {
- return;
- }
+ if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glBegin");
+ return;
+ }
- vbo_draw_method(vbo_context(ctx), DRAW_BEGIN_END);
+ if (!_mesa_valid_prim_mode(ctx, mode, "glBegin")) {
+ return;
+ }
- if (ctx->Driver.PrepareExecBegin)
- ctx->Driver.PrepareExecBegin(ctx);
+ vbo_draw_method(vbo_context(ctx), DRAW_BEGIN_END);
- if (ctx->NewState) {
- _mesa_update_state( ctx );
+ if (ctx->Driver.PrepareExecBegin)
+ ctx->Driver.PrepareExecBegin(ctx);
- CALL_Begin(ctx->Exec, (mode));
- return;
- }
+ if (ctx->NewState) {
+ _mesa_update_state( ctx );
- if (!_mesa_valid_to_render(ctx, "glBegin")) {
- return;
- }
+ CALL_Begin(ctx->Exec, (mode));
+ return;
+ }
- /* Heuristic: attempt to isolate attributes occuring outside
- * begin/end pairs.
- */
- if (exec->vtx.vertex_size && !exec->vtx.attrsz[0])
- vbo_exec_FlushVertices_internal(exec, GL_FALSE);
-
- i = exec->vtx.prim_count++;
- exec->vtx.prim[i].mode = mode;
- exec->vtx.prim[i].begin = 1;
- exec->vtx.prim[i].end = 0;
- exec->vtx.prim[i].indexed = 0;
- exec->vtx.prim[i].weak = 0;
- exec->vtx.prim[i].pad = 0;
- exec->vtx.prim[i].start = exec->vtx.vert_count;
- exec->vtx.prim[i].count = 0;
- exec->vtx.prim[i].num_instances = 1;
- exec->vtx.prim[i].base_instance = 0;
-
- ctx->Driver.CurrentExecPrimitive = mode;
+ if (!_mesa_valid_to_render(ctx, "glBegin")) {
+ return;
}
- else
- _mesa_error( ctx, GL_INVALID_OPERATION, "glBegin" );
-
+
+ /* Heuristic: attempt to isolate attributes occuring outside
+ * begin/end pairs.
+ */
+ if (exec->vtx.vertex_size && !exec->vtx.attrsz[0])
+ vbo_exec_FlushVertices_internal(exec, GL_FALSE);
+
+ i = exec->vtx.prim_count++;
+ exec->vtx.prim[i].mode = mode;
+ exec->vtx.prim[i].begin = 1;
+ exec->vtx.prim[i].end = 0;
+ exec->vtx.prim[i].indexed = 0;
+ exec->vtx.prim[i].weak = 0;
+ exec->vtx.prim[i].pad = 0;
+ exec->vtx.prim[i].start = exec->vtx.vert_count;
+ exec->vtx.prim[i].count = 0;
+ exec->vtx.prim[i].num_instances = 1;
+ exec->vtx.prim[i].base_instance = 0;
+
+ ctx->Driver.CurrentExecPrimitive = mode;
}
@@ -846,26 +845,26 @@ static void GLAPIENTRY vbo_exec_Begin( GLenum mode )
static void GLAPIENTRY vbo_exec_End( void )
{
GET_CURRENT_CONTEXT( ctx );
+ struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glEnd");
+ return;
+ }
- if (exec->vtx.prim_count > 0) {
- /* close off current primitive */
- int idx = exec->vtx.vert_count;
- int i = exec->vtx.prim_count - 1;
+ if (exec->vtx.prim_count > 0) {
+ /* close off current primitive */
+ int idx = exec->vtx.vert_count;
+ int i = exec->vtx.prim_count - 1;
- exec->vtx.prim[i].end = 1;
- exec->vtx.prim[i].count = idx - exec->vtx.prim[i].start;
- }
+ exec->vtx.prim[i].end = 1;
+ exec->vtx.prim[i].count = idx - exec->vtx.prim[i].start;
+ }
- ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
+ ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
- if (exec->vtx.prim_count == VBO_MAX_PRIM)
- vbo_exec_vtx_flush( exec, GL_FALSE );
- }
- else
- _mesa_error( ctx, GL_INVALID_OPERATION, "glEnd" );
+ if (exec->vtx.prim_count == VBO_MAX_PRIM)
+ vbo_exec_vtx_flush( exec, GL_FALSE );
if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
_mesa_flush(ctx);
--
1.7.10.4
More information about the mesa-dev
mailing list