mesa/vbo: replace vbo_draw_method() with _mesa_set_drawing_arrays()

The arrays specified by ctx->Array._DrawArrays are used for all
vertex drawing via vbo_context::draw_prims().  Different arrays are
used for immediate mode, vertex arrays, display lists, etc.  Changing
from one to another requires updating derived/driver array state.

Before, we indirectly specifid the arrays with the gl_draw_method values.
Now we just directly specify the arrays instead.  This is simpler and
will allow a subsequent display list optimization.

In the future, it might make sense to get rid of ctx->Array._DrawArrays
entirely and just pass the arrays as another parameter to
vbo_context::draw_prims().

Reviewed-by: Mathias Fröhlich <mathias.froehlich@web.de>
This commit is contained in:
Brian Paul
2018-01-24 09:14:35 -07:00
parent d9894ede02
commit 0d044f7d61
8 changed files with 34 additions and 74 deletions

View File

@@ -433,20 +433,17 @@ bind_vertex_array(struct gl_context *ctx, GLuint id, bool no_error)
newObj->EverBound = GL_TRUE; newObj->EverBound = GL_TRUE;
} }
if (ctx->Array.DrawMethod == DRAW_ARRAYS) { /* The _DrawArrays pointer is pointing at the VAO being unbound and
/* The _DrawArrays pointer is pointing at the VAO being unbound and * that VAO may be in the process of being deleted. If it's not going
* that VAO may be in the process of being deleted. If it's not going * to be deleted, this will have no effect, because the pointer needs
* to be deleted, this will have no effect, because the pointer needs * to be updated by the VBO module anyway.
* to be updated by the VBO module anyway. *
* * Before the VBO module can update the pointer, we have to set it
* Before the VBO module can update the pointer, we have to set it * to NULL for drivers not to set up arrays which are not bound,
* to NULL for drivers not to set up arrays which are not bound, * or to prevent a crash if the VAO being unbound is going to be
* or to prevent a crash if the VAO being unbound is going to be * deleted.
* deleted. */
*/ _mesa_set_drawing_arrays(ctx, NULL);
ctx->Array._DrawArrays = NULL;
ctx->Array.DrawMethod = DRAW_NONE;
}
ctx->NewState |= _NEW_ARRAY; ctx->NewState |= _NEW_ARRAY;
_mesa_reference_vao(ctx, &ctx->Array.VAO, newObj); _mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);

View File

@@ -1538,9 +1538,8 @@ copy_array_attrib(struct gl_context *ctx,
/* skip ArrayBufferObj */ /* skip ArrayBufferObj */
/* skip IndexBufferObj */ /* skip IndexBufferObj */
/* Invalidate draw state. It will be updated during the next draw. */ /* Invalidate array state. It will be updated during the next draw. */
dest->DrawMethod = DRAW_NONE; _mesa_set_drawing_arrays(ctx, NULL);
dest->_DrawArrays = NULL;
} }
/** /**

View File

@@ -1603,19 +1603,6 @@ struct gl_vertex_array_object
}; };
/**
* Used to signal when transitioning from one kind of drawing method
* to another.
*/
typedef enum
{
DRAW_NONE, /**< Initial value only */
DRAW_BEGIN_END,
DRAW_DISPLAY_LIST,
DRAW_ARRAYS
} gl_draw_method;
/** /**
* Enum for the OpenGL APIs we know about and may support. * Enum for the OpenGL APIs we know about and may support.
* *
@@ -1666,9 +1653,6 @@ struct gl_array_attrib
GLuint RestartIndex; GLuint RestartIndex;
/*@}*/ /*@}*/
/** One of the DRAW_xxx flags, not consumed by drivers */
gl_draw_method DrawMethod;
/* GL_ARB_vertex_buffer_object */ /* GL_ARB_vertex_buffer_object */
struct gl_buffer_object *ArrayBufferObj; struct gl_buffer_object *ArrayBufferObj;

View File

@@ -78,6 +78,21 @@ _mesa_attr_zero_aliases_vertex(const struct gl_context *ctx)
return ctx->_AttribZeroAliasesVertex; return ctx->_AttribZeroAliasesVertex;
} }
/**
* This specifies the set of vertex arrays used by the driver for drawing.
*/
static inline void
_mesa_set_drawing_arrays(struct gl_context *ctx,
const struct gl_vertex_array **arrays)
{
if (ctx->Array._DrawArrays != arrays) {
ctx->Array._DrawArrays = arrays;
ctx->NewDriverState |= ctx->DriverFlags.NewArray;
}
}
extern void extern void
_mesa_update_array_format(struct gl_context *ctx, _mesa_update_array_format(struct gl_context *ctx,
struct gl_vertex_array_object *vao, struct gl_vertex_array_object *vao,

View File

@@ -770,7 +770,7 @@ vbo_exec_Begin(GLenum mode)
return; return;
} }
vbo_draw_method(vbo_context(ctx), DRAW_BEGIN_END); _mesa_set_drawing_arrays(ctx, exec->vtx.inputs);
if (ctx->NewState) { if (ctx->NewState) {
_mesa_update_state(ctx); _mesa_update_state(ctx);

View File

@@ -444,7 +444,7 @@ vbo_bind_arrays(struct gl_context *ctx)
struct vbo_context *vbo = vbo_context(ctx); struct vbo_context *vbo = vbo_context(ctx);
struct vbo_exec_context *exec = &vbo->exec; struct vbo_exec_context *exec = &vbo->exec;
vbo_draw_method(vbo, DRAW_ARRAYS); _mesa_set_drawing_arrays(ctx, vbo->exec.array.inputs);
if (exec->array.recalculate_inputs) { if (exec->array.recalculate_inputs) {
recalculate_input_bindings(ctx); recalculate_input_bindings(ctx);

View File

@@ -98,43 +98,6 @@ get_vp_mode( struct gl_context *ctx )
} }
/**
* This is called by glBegin, glDrawArrays and glDrawElements (and
* variations of those calls). When we transition from immediate mode
* drawing to array drawing we need to invalidate the array state.
*
* glBegin/End builds vertex arrays. Those arrays may look identical
* to glDrawArrays arrays except that the position of the elements may
* be different. For example, arrays of (position3v, normal3f) vs. arrays
* of (normal3f, position3f). So we need to make sure we notify drivers
* that arrays may be changing.
*/
static inline void
vbo_draw_method(struct vbo_context *vbo, gl_draw_method method)
{
struct gl_context *ctx = vbo->exec.ctx;
if (ctx->Array.DrawMethod != method) {
switch (method) {
case DRAW_ARRAYS:
ctx->Array._DrawArrays = vbo->exec.array.inputs;
break;
case DRAW_BEGIN_END:
ctx->Array._DrawArrays = vbo->exec.vtx.inputs;
break;
case DRAW_DISPLAY_LIST:
ctx->Array._DrawArrays = vbo->save.inputs;
break;
default:
unreachable("Bad VBO drawing method");
}
ctx->NewDriverState |= ctx->DriverFlags.NewArray;
ctx->Array.DrawMethod = method;
}
}
/** /**
* Return if format is integer. The immediate mode commands only emit floats * Return if format is integer. The immediate mode commands only emit floats
* for non-integer types, thus everything else is integer. * for non-integer types, thus everything else is integer.

View File

@@ -34,6 +34,7 @@
#include "main/macros.h" #include "main/macros.h"
#include "main/light.h" #include "main/light.h"
#include "main/state.h" #include "main/state.h"
#include "main/varray.h"
#include "util/bitscan.h" #include "util/bitscan.h"
#include "vbo_private.h" #include "vbo_private.h"
@@ -267,7 +268,8 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
{ {
const struct vbo_save_vertex_list *node = const struct vbo_save_vertex_list *node =
(const struct vbo_save_vertex_list *) data; (const struct vbo_save_vertex_list *) data;
struct vbo_save_context *save = &vbo_context(ctx)->save; struct vbo_context *vbo = vbo_context(ctx);
struct vbo_save_context *save = &vbo->save;
GLboolean remap_vertex_store = GL_FALSE; GLboolean remap_vertex_store = GL_FALSE;
if (save->vertex_store && save->vertex_store->buffer_map) { if (save->vertex_store && save->vertex_store->buffer_map) {
@@ -318,7 +320,7 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
bind_vertex_list(ctx, node); bind_vertex_list(ctx, node);
vbo_draw_method(vbo_context(ctx), DRAW_DISPLAY_LIST); _mesa_set_drawing_arrays(ctx, vbo->save.inputs);
/* Again... /* Again...
*/ */