summaryrefslogtreecommitdiff
path: root/src/mesa/vbo
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2006-10-30 16:44:13 +0000
committerKeith Whitwell <keith@tungstengraphics.com>2006-10-30 16:44:13 +0000
commit99efde461d3b8615863bdb7308e05289e0db0422 (patch)
tree95b9e3f4f612957a93547892f3559cfaa44dccb7 /src/mesa/vbo
parentefef291dc71eb57f90785a26957f4b3e01733156 (diff)
better handling of current attributes. Trivial dlist and varray tests work
Diffstat (limited to 'src/mesa/vbo')
-rw-r--r--src/mesa/vbo/vbo_context.c144
-rw-r--r--src/mesa/vbo/vbo_context.h7
-rw-r--r--src/mesa/vbo/vbo_exec.c117
-rw-r--r--src/mesa/vbo/vbo_exec.h4
-rw-r--r--src/mesa/vbo/vbo_exec_array.c15
-rw-r--r--src/mesa/vbo/vbo_exec_draw.c38
-rw-r--r--src/mesa/vbo/vbo_save_draw.c28
7 files changed, 214 insertions, 139 deletions
diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c
index 5f28e6b0e0..29dfe09d99 100644
--- a/src/mesa/vbo/vbo_context.c
+++ b/src/mesa/vbo/vbo_context.c
@@ -40,6 +40,123 @@ extern void _tnl_draw_prims( GLcontext *ctx,
GLuint min_index,
GLuint max_index );
+
+
+#define NR_LEGACY_ATTRIBS 16
+#define NR_GENERIC_ATTRIBS 16
+#define NR_MAT_ATTRIBS 12
+
+static void init_legacy_currval(GLcontext *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct gl_client_array *arrays = vbo->legacy_currval;
+ GLuint i;
+
+ memset(arrays, 0, sizeof(*arrays) * NR_LEGACY_ATTRIBS);
+
+ /* Set up a constant (StrideB == 0) array for each current
+ * attribute:
+ */
+ for (i = 0; i < NR_LEGACY_ATTRIBS; i++) {
+ struct gl_client_array *cl = &arrays[i];
+
+ switch (i) {
+ case VBO_ATTRIB_EDGEFLAG:
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Ptr = (const void *)&ctx->Current.EdgeFlag;
+ break;
+ case VBO_ATTRIB_INDEX:
+ cl->Type = GL_FLOAT;
+ cl->Ptr = (const void *)&ctx->Current.Index;
+ break;
+ default:
+ cl->Type = GL_FLOAT;
+ cl->Ptr = (const void *)ctx->Current.Attrib[i];
+ break;
+ }
+
+ /* This will have to be determined at runtime:
+ */
+ cl->Size = 1;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Enabled = 1;
+ cl->BufferObj = ctx->Array.NullBufferObj;
+ }
+}
+
+
+static void init_generic_currval(GLcontext *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct gl_client_array *arrays = vbo->generic_currval;
+ GLuint i;
+
+ memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
+
+ for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
+ struct gl_client_array *cl = &arrays[i];
+
+ /* This will have to be determined at runtime:
+ */
+ cl->Size = 1;
+
+ cl->Type = GL_FLOAT;
+ cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Enabled = 1;
+ cl->BufferObj = ctx->Array.NullBufferObj;
+ }
+}
+
+
+static void init_mat_currval(GLcontext *ctx)
+{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct gl_client_array *arrays = vbo->mat_currval;
+ GLuint i;
+
+ memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
+
+ /* Set up a constant (StrideB == 0) array for each current
+ * attribute:
+ */
+ for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
+ struct gl_client_array *cl = &arrays[i];
+
+ /* Size is fixed for the material attributes, for others will
+ * be determined at runtime:
+ */
+ switch (i - VERT_ATTRIB_GENERIC0) {
+ case MAT_ATTRIB_FRONT_SHININESS:
+ case MAT_ATTRIB_BACK_SHININESS:
+ cl->Size = 1;
+ break;
+ case MAT_ATTRIB_FRONT_INDEXES:
+ case MAT_ATTRIB_BACK_INDEXES:
+ cl->Size = 3;
+ break;
+ default:
+ cl->Size = 4;
+ break;
+ }
+
+ if (i < MAT_ATTRIB_MAX)
+ cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
+ else
+ cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
+
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Enabled = 1;
+ cl->BufferObj = ctx->Array.NullBufferObj;
+ }
+}
+
+
+
GLboolean _vbo_CreateContext( GLcontext *ctx )
{
struct vbo_context *vbo = CALLOC_STRUCT(vbo_context);
@@ -60,6 +177,32 @@ GLboolean _vbo_CreateContext( GLcontext *ctx )
vbo_exec_init( ctx );
vbo_save_init( ctx );
+
+ init_legacy_currval( ctx );
+ init_generic_currval( ctx );
+ init_mat_currval( ctx );
+
+ /* Build mappings from VERT_ATTRIB -> VBO_ATTRIB depending on type
+ * of vertex program active.
+ */
+ {
+ GLuint i;
+
+ /* When no vertex program, pull in the material attributes in
+ * the 16..32 generic range.
+ */
+ for (i = 0; i < 16; i++)
+ vbo->map_vp_none[i] = i;
+ for (i = 0; i < 12; i++)
+ vbo->map_vp_none[16+i] = VBO_ATTRIB_MAT_FRONT_AMBIENT + i;
+ for (i = 0; i < 4; i++)
+ vbo->map_vp_none[28+i] = i;
+
+ for (i = 0; i < VERT_ATTRIB_MAX; i++)
+ vbo->map_vp_arb[i] = i;
+ }
+
+
/* By default:
*/
vbo->draw_prims = _tnl_draw_prims;
@@ -82,5 +225,4 @@ void _vbo_DestroyContext( GLcontext *ctx )
FREE(vbo_context(ctx));
ctx->swtnl_im = NULL;
-
}
diff --git a/src/mesa/vbo/vbo_context.h b/src/mesa/vbo/vbo_context.h
index 6b0f14d70e..a20bfbd518 100644
--- a/src/mesa/vbo/vbo_context.h
+++ b/src/mesa/vbo/vbo_context.h
@@ -60,6 +60,13 @@ void _vbo_DestroyContext( GLcontext *ctx );
struct vbo_context {
+ struct gl_client_array legacy_currval[16];
+ struct gl_client_array generic_currval[16];
+ struct gl_client_array mat_currval[16];
+
+ GLuint map_vp_none[32];
+ GLuint map_vp_arb[32];
+
struct vbo_exec_context exec;
struct vbo_save_context save;
diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c
index 4499803b8c..270e5201d3 100644
--- a/src/mesa/vbo/vbo_exec.c
+++ b/src/mesa/vbo/vbo_exec.c
@@ -38,119 +38,6 @@
#include "vbo_context.h"
-#define NR_LEGACY_ATTRIBS 16
-#define NR_GENERIC_ATTRIBS 16
-#define NR_MAT_ATTRIBS 12
-
-static void init_legacy_currval(GLcontext *ctx)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- struct gl_client_array *arrays = exec->legacy_currval;
- GLuint i;
-
- memset(arrays, 0, sizeof(*arrays) * NR_LEGACY_ATTRIBS);
-
- /* Set up a constant (StrideB == 0) array for each current
- * attribute:
- */
- for (i = 0; i < NR_LEGACY_ATTRIBS; i++) {
- struct gl_client_array *cl = &arrays[i];
-
- switch (i) {
- case VBO_ATTRIB_EDGEFLAG:
- cl->Type = GL_UNSIGNED_BYTE;
- cl->Ptr = (const void *)&ctx->Current.EdgeFlag;
- break;
- case VBO_ATTRIB_INDEX:
- cl->Type = GL_FLOAT;
- cl->Ptr = (const void *)&ctx->Current.Index;
- break;
- default:
- cl->Type = GL_FLOAT;
- cl->Ptr = (const void *)ctx->Current.Attrib[i];
- break;
- }
-
- /* This will have to be determined at runtime:
- */
- cl->Size = 1;
- cl->Stride = 0;
- cl->StrideB = 0;
- cl->Enabled = 1;
- cl->BufferObj = ctx->Array.NullBufferObj;
- }
-}
-
-
-static void init_generic_currval(GLcontext *ctx)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- struct gl_client_array *arrays = exec->generic_currval;
- GLuint i;
-
- memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
-
- for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
- struct gl_client_array *cl = &arrays[i];
-
- /* This will have to be determined at runtime:
- */
- cl->Size = 1;
-
- cl->Type = GL_FLOAT;
- cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
- cl->Stride = 0;
- cl->StrideB = 0;
- cl->Enabled = 1;
- cl->BufferObj = ctx->Array.NullBufferObj;
- }
-}
-
-
-static void init_mat_currval(GLcontext *ctx)
-{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- struct gl_client_array *arrays = exec->mat_currval;
- GLuint i;
-
- memset(arrays, 0, sizeof(*arrays) * NR_GENERIC_ATTRIBS);
-
- /* Set up a constant (StrideB == 0) array for each current
- * attribute:
- */
- for (i = 0; i < NR_GENERIC_ATTRIBS; i++) {
- struct gl_client_array *cl = &arrays[i];
-
- /* Size is fixed for the material attributes, for others will
- * be determined at runtime:
- */
- switch (i - VERT_ATTRIB_GENERIC0) {
- case MAT_ATTRIB_FRONT_SHININESS:
- case MAT_ATTRIB_BACK_SHININESS:
- cl->Size = 1;
- break;
- case MAT_ATTRIB_FRONT_INDEXES:
- case MAT_ATTRIB_BACK_INDEXES:
- cl->Size = 3;
- break;
- default:
- cl->Size = 4;
- break;
- }
-
- if (i < MAT_ATTRIB_MAX)
- cl->Ptr = (const void *)ctx->Light.Material.Attrib[i];
- else
- cl->Ptr = (const void *)ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + i];
-
- cl->Type = GL_FLOAT;
- cl->Stride = 0;
- cl->StrideB = 0;
- cl->Enabled = 1;
- cl->BufferObj = ctx->Array.NullBufferObj;
- }
-}
-
void vbo_exec_init( GLcontext *ctx )
{
@@ -167,10 +54,6 @@ void vbo_exec_init( GLcontext *ctx )
vbo_exec_vtx_init( exec );
vbo_exec_array_init( exec );
- init_legacy_currval( ctx );
- init_generic_currval( ctx );
- init_mat_currval( ctx );
-
ctx->Driver.NeedFlush = 0;
ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END;
ctx->Driver.FlushVertices = vbo_exec_FlushVertices;
diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h
index 4542d2807c..72855d267e 100644
--- a/src/mesa/vbo/vbo_exec.h
+++ b/src/mesa/vbo/vbo_exec.h
@@ -75,10 +75,6 @@ struct vbo_exec_context
GLcontext *ctx;
GLvertexformat vtxfmt;
- struct gl_client_array legacy_currval[16];
- struct gl_client_array generic_currval[16];
- struct gl_client_array mat_currval[16];
-
struct {
struct gl_buffer_object *bufferobj;
GLubyte *buffer_map;
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index 5cfa7a01a9..b3650e2697 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -107,7 +107,8 @@ static void bind_array_obj( GLcontext *ctx )
static void recalculate_input_bindings( GLcontext *ctx )
{
- struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
const struct gl_client_array **inputs = &exec->array.inputs[0];
GLuint i;
@@ -126,11 +127,11 @@ static void recalculate_input_bindings( GLcontext *ctx )
if (exec->array.legacy_array[i]->Enabled)
inputs[i] = exec->array.legacy_array[i];
else
- inputs[i] = &exec->legacy_currval[i];
+ inputs[i] = &vbo->legacy_currval[i];
}
for (i = 0; i < MAT_ATTRIB_MAX; i++) {
- inputs[VERT_ATTRIB_GENERIC0 + i] = &exec->mat_currval[i];
+ inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->mat_currval[i];
}
break;
case VP_NV:
@@ -144,7 +145,7 @@ static void recalculate_input_bindings( GLcontext *ctx )
else if (exec->array.legacy_array[i]->Enabled)
inputs[i] = exec->array.legacy_array[i];
else
- inputs[i] = &exec->legacy_currval[i];
+ inputs[i] = &vbo->legacy_currval[i];
}
break;
case VP_ARB:
@@ -160,21 +161,21 @@ static void recalculate_input_bindings( GLcontext *ctx )
else if (exec->array.legacy_array[0]->Enabled)
inputs[0] = exec->array.legacy_array[0];
else
- inputs[0] = &exec->legacy_currval[0];
+ inputs[0] = &vbo->legacy_currval[0];
for (i = 1; i <= VERT_ATTRIB_TEX7; i++) {
if (exec->array.legacy_array[i]->Enabled)
inputs[i] = exec->array.legacy_array[i];
else
- inputs[i] = &exec->legacy_currval[i];
+ inputs[i] = &vbo->legacy_currval[i];
}
for (i = 0; i < 16; i++) {
if (exec->array.generic_array[0]->Enabled)
inputs[VERT_ATTRIB_GENERIC0 + i] = exec->array.generic_array[i];
else
- inputs[VERT_ATTRIB_GENERIC0 + i] = &exec->generic_currval[i];
+ inputs[VERT_ATTRIB_GENERIC0 + i] = &vbo->generic_currval[i];
}
break;
}
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index f665c64c7a..c1898aea49 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -132,25 +132,49 @@ static GLuint vbo_copy_vertices( struct vbo_exec_context *exec )
}
+
/* TODO: populate these as the vertex is defined:
*/
-static void vbo_exec_bind_arrays( struct vbo_exec_context *exec )
+static void vbo_exec_bind_arrays( GLcontext *ctx )
{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_exec_context *exec = &vbo->exec;
struct gl_client_array *arrays = exec->vtx.arrays;
GLuint count = exec->vtx.vert_count;
GLubyte *data = exec->vtx.buffer_map;
+ const GLuint *map;
GLuint attr;
- memcpy(arrays, exec->legacy_currval, 16 * sizeof(arrays[0]));
- memcpy(arrays + 16, exec->mat_currval, 16 * sizeof(arrays[0]));
+ /* Install the default (ie Current) attributes first, then overlay
+ * all active ones.
+ */
+ switch (get_program_mode(exec->ctx)) {
+ case VP_NONE:
+ memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
+ memcpy(arrays + 16, vbo->mat_currval, 16 * sizeof(arrays[0]));
+ map = vbo->map_vp_none;
+ break;
+ case VP_NV:
+ case VP_ARB:
+ /* The aliasing of attributes for NV vertex programs has already
+ * occurred. NV vertex programs cannot access material values,
+ * nor attributes greater than VERT_ATTRIB_TEX7.
+ */
+ memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
+ memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+ map = vbo->map_vp_arb;
+ break;
+ }
/* Make all active attributes (including edgeflag) available as
* arrays of floats.
*/
- for (attr = 0; attr < VBO_ATTRIB_MAX ; attr++) {
- if (exec->vtx.attrsz[attr]) {
+ for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) {
+ GLuint src = map[attr];
+
+ if (exec->vtx.attrsz[src]) {
arrays[attr].Ptr = (void *)data;
- arrays[attr].Size = exec->vtx.attrsz[attr];
+ arrays[attr].Size = exec->vtx.attrsz[src];
arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
arrays[attr].Type = GL_FLOAT;
@@ -181,7 +205,7 @@ void vbo_exec_vtx_flush( struct vbo_exec_context *exec )
if (exec->vtx.copied.nr != exec->vtx.vert_count) {
GLcontext *ctx = exec->ctx;
- vbo_exec_bind_arrays( exec );
+ vbo_exec_bind_arrays( ctx );
vbo_context(ctx)->draw_prims( ctx,
exec->vtx.inputs,
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 44e0171233..18c770a41c 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -95,14 +95,36 @@ static void _playback_copy_to_current( GLcontext *ctx,
/* Treat the vertex storage as a VBO, define vertex arrays pointing
* into it:
*/
-static void vbo_bind_vertex_list( struct vbo_save_context *save,
+static void vbo_bind_vertex_list( GLcontext *ctx,
const struct vbo_save_vertex_list *node )
{
+ struct vbo_context *vbo = vbo_context(ctx);
+ struct vbo_save_context *save = &vbo->save;
struct gl_client_array *arrays = save->arrays;
GLuint data = node->buffer_offset;
+ const GLuint *map;
GLuint attr;
- memset(arrays, 0, VBO_ATTRIB_MAX * sizeof(arrays[0]));
+ /* Install the default (ie Current) attributes first, then overlay
+ * all active ones.
+ */
+ switch (get_program_mode(ctx)) {
+ case VP_NONE:
+ memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
+ memcpy(arrays + 16, vbo->mat_currval, 16 * sizeof(arrays[0]));
+ map = vbo->map_vp_none;
+ break;
+ case VP_NV:
+ case VP_ARB:
+ /* The aliasing of attributes for NV vertex programs has already
+ * occurred. NV vertex programs cannot access material values,
+ * nor attributes greater than VERT_ATTRIB_TEX7.
+ */
+ memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
+ memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+ map = vbo->map_vp_arb;
+ break;
+ }
for (attr = 0; attr <= VBO_ATTRIB_INDEX; attr++) {
if (node->attrsz[attr]) {
@@ -185,7 +207,7 @@ void vbo_save_playback_vertex_list( GLcontext *ctx, void *data )
return;
}
- vbo_bind_vertex_list( save, node );
+ vbo_bind_vertex_list( ctx, node );
vbo_context(ctx)->draw_prims( ctx,
save->inputs,