aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/vbo
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-02 14:47:58 +0000
committermarha <marha@users.sourceforge.net>2010-04-02 14:47:58 +0000
commit7933658107276f9d5491f8736a743cf8f8bbd5f2 (patch)
treef2893a761364e7abc9d934e9c5427e5cf5190c7a /mesalib/src/mesa/vbo
parent83fa9a9811e2c18cffd83a020757f7fb51ffddaa (diff)
downloadvcxsrv-7933658107276f9d5491f8736a743cf8f8bbd5f2.tar.gz
vcxsrv-7933658107276f9d5491f8736a743cf8f8bbd5f2.tar.bz2
vcxsrv-7933658107276f9d5491f8736a743cf8f8bbd5f2.zip
Updated to following packages:
mesa-7.8
Diffstat (limited to 'mesalib/src/mesa/vbo')
-rw-r--r--mesalib/src/mesa/vbo/vbo_context.c50
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec.c3
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_api.c44
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_array.c140
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_draw.c49
-rw-r--r--mesalib/src/mesa/vbo/vbo_exec_eval.c2
-rw-r--r--mesalib/src/mesa/vbo/vbo_rebase.c10
-rw-r--r--mesalib/src/mesa/vbo/vbo_save.c13
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_api.c30
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_draw.c2
-rw-r--r--mesalib/src/mesa/vbo/vbo_save_loopback.c17
-rw-r--r--mesalib/src/mesa/vbo/vbo_split.c4
-rw-r--r--mesalib/src/mesa/vbo/vbo_split_copy.c55
-rw-r--r--mesalib/src/mesa/vbo/vbo_split_inplace.c114
14 files changed, 274 insertions, 259 deletions
diff --git a/mesalib/src/mesa/vbo/vbo_context.c b/mesalib/src/mesa/vbo/vbo_context.c
index 75c32e0b9..e3be39a34 100644
--- a/mesalib/src/mesa/vbo/vbo_context.c
+++ b/mesalib/src/mesa/vbo/vbo_context.c
@@ -33,24 +33,13 @@
#include "vbo.h"
#include "vbo_context.h"
-#if 0
-/* Reach out and grab this to use as the default:
- */
-extern void _tnl_draw_prims( GLcontext *ctx,
- const struct gl_client_array *arrays[],
- const struct _mesa_prim *prims,
- GLuint nr_prims,
- const struct _mesa_index_buffer *ib,
- GLuint min_index,
- GLuint max_index );
-#endif
-
#define NR_LEGACY_ATTRIBS 16
#define NR_GENERIC_ATTRIBS 16
#define NR_MAT_ATTRIBS 12
+
static GLuint check_size( const GLfloat *attr )
{
if (attr[3] != 1.0) return 4;
@@ -59,6 +48,7 @@ static GLuint check_size( const GLfloat *attr )
return 1;
}
+
static void init_legacy_currval(GLcontext *ctx)
{
struct vbo_context *vbo = vbo_context(ctx);
@@ -158,23 +148,6 @@ static void init_mat_currval(GLcontext *ctx)
}
}
-#if 0
-
-static void vbo_exec_current_init( struct vbo_exec_context *exec )
-{
- GLcontext *ctx = exec->ctx;
- GLint i;
-
- /* setup the pointers for the typical 16 vertex attributes */
- for (i = 0; i < VBO_ATTRIB_FIRST_MATERIAL; i++)
- exec->vtx.current[i] = ctx->Current.Attrib[i];
-
- /* setup pointers for the 12 material attributes */
- for (i = 0; i < MAT_ATTRIB_MAX; i++)
- exec->vtx.current[VBO_ATTRIB_FIRST_MATERIAL + i] =
- ctx->Light.Material.Attrib[i];
-}
-#endif
GLboolean _vbo_CreateContext( GLcontext *ctx )
{
@@ -220,12 +193,6 @@ GLboolean _vbo_CreateContext( GLcontext *ctx )
}
- /* By default:
- */
-#if 0 /* dead - see vbo_set_draw_func() */
- vbo->draw_prims = _tnl_draw_prims;
-#endif
-
/* Hook our functions into exec and compile dispatch tables. These
* will pretty much be permanently installed, which means that the
* vtxfmt mechanism can be removed now.
@@ -240,6 +207,7 @@ GLboolean _vbo_CreateContext( GLcontext *ctx )
return GL_TRUE;
}
+
void _vbo_InvalidateState( GLcontext *ctx, GLuint new_state )
{
_ae_invalidate_state(ctx, new_state);
@@ -249,17 +217,25 @@ void _vbo_InvalidateState( GLcontext *ctx, GLuint new_state )
void _vbo_DestroyContext( GLcontext *ctx )
{
+ struct vbo_context *vbo = vbo_context(ctx);
+
if (ctx->aelt_context) {
_ae_destroy_context( ctx );
ctx->aelt_context = NULL;
}
- if (vbo_context(ctx)) {
+ if (vbo) {
+ GLuint i;
+
+ for (i = 0; i < VBO_ATTRIB_MAX; i++) {
+ _mesa_reference_buffer_object(ctx, &vbo->currval[i].BufferObj, NULL);
+ }
+
vbo_exec_destroy(ctx);
#if FEATURE_dlist
vbo_save_destroy(ctx);
#endif
- FREE(vbo_context(ctx));
+ FREE(vbo);
ctx->swtnl_im = NULL;
}
}
diff --git a/mesalib/src/mesa/vbo/vbo_exec.c b/mesalib/src/mesa/vbo/vbo_exec.c
index e168a89ea..a057befed 100644
--- a/mesalib/src/mesa/vbo/vbo_exec.c
+++ b/mesalib/src/mesa/vbo/vbo_exec.c
@@ -28,9 +28,6 @@
#include "main/api_arrayelt.h"
#include "main/glheader.h"
-#include "main/imports.h"
-#include "main/context.h"
-#include "main/macros.h"
#include "main/mtypes.h"
#include "main/vtxfmt.h"
diff --git a/mesalib/src/mesa/vbo/vbo_exec_api.c b/mesalib/src/mesa/vbo/vbo_exec_api.c
index f0a7eeadd..e40f5f9dc 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_api.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_api.c
@@ -41,7 +41,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/light.h"
#include "main/api_arrayelt.h"
#include "main/api_noop.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
#include "vbo_context.h"
@@ -126,8 +126,8 @@ void vbo_exec_vtx_wrap( struct vbo_exec_context *exec )
assert(exec->vtx.max_vert - exec->vtx.vert_count > exec->vtx.copied.nr);
for (i = 0 ; i < exec->vtx.copied.nr ; i++) {
- _mesa_memcpy( exec->vtx.buffer_ptr, data,
- exec->vtx.vertex_size * sizeof(GLfloat));
+ memcpy( exec->vtx.buffer_ptr, data,
+ exec->vtx.vertex_size * sizeof(GLfloat));
exec->vtx.buffer_ptr += exec->vtx.vertex_size;
data += exec->vtx.vertex_size;
exec->vtx.vert_count++;
@@ -414,13 +414,13 @@ static void GLAPIENTRY vbo_exec_EvalCoord1f( GLfloat u )
}
- _mesa_memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
- exec->vtx.vertex_size * sizeof(GLfloat));
+ memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
+ exec->vtx.vertex_size * sizeof(GLfloat));
vbo_exec_do_EvalCoord1f( exec, u );
- _mesa_memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
- exec->vtx.vertex_size * sizeof(GLfloat));
+ memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
+ exec->vtx.vertex_size * sizeof(GLfloat));
}
static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
@@ -444,13 +444,13 @@ static void GLAPIENTRY vbo_exec_EvalCoord2f( GLfloat u, GLfloat v )
vbo_exec_fixup_vertex( ctx, VBO_ATTRIB_NORMAL, 3 );
}
- _mesa_memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
- exec->vtx.vertex_size * sizeof(GLfloat));
+ memcpy( exec->vtx.copied.buffer, exec->vtx.vertex,
+ exec->vtx.vertex_size * sizeof(GLfloat));
vbo_exec_do_EvalCoord2f( exec, u, v );
- _mesa_memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
- exec->vtx.vertex_size * sizeof(GLfloat));
+ memcpy( exec->vtx.vertex, exec->vtx.copied.buffer,
+ exec->vtx.vertex_size * sizeof(GLfloat));
}
static void GLAPIENTRY vbo_exec_EvalCoord1fv( const GLfloat *u )
@@ -759,6 +759,7 @@ void vbo_use_buffer_objects(GLcontext *ctx)
}
/* Allocate a real buffer object now */
+ _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
}
@@ -780,7 +781,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
ctx->Shared->NullBufferObj);
ASSERT(!exec->vtx.buffer_map);
- exec->vtx.buffer_map = (GLfloat *)ALIGN_MALLOC(VBO_VERT_BUFFER_SIZE, 64);
+ exec->vtx.buffer_map = (GLfloat *)_mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
vbo_exec_vtxfmt_init( exec );
@@ -803,8 +804,19 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
{
struct gl_client_array *arrays = exec->vtx.arrays;
+ unsigned i;
+
memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+
+ for (i = 0; i < 16; ++i) {
+ arrays[i ].BufferObj = NULL;
+ arrays[i + 16].BufferObj = NULL;
+ _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj,
+ vbo->legacy_currval[i].BufferObj);
+ _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
+ vbo->generic_currval[i].BufferObj);
+ }
}
exec->vtx.vertex_size = 0;
@@ -823,7 +835,7 @@ void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
ASSERT(exec->vtx.bufferobj->Name == 0 ||
exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
if (exec->vtx.bufferobj->Name == 0) {
- ALIGN_FREE(exec->vtx.buffer_map);
+ _mesa_align_free(exec->vtx.buffer_map);
exec->vtx.buffer_map = NULL;
exec->vtx.buffer_ptr = NULL;
}
@@ -845,7 +857,7 @@ void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
void vbo_exec_BeginVertices( GLcontext *ctx )
{
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
- if (0) _mesa_printf("%s\n", __FUNCTION__);
+ if (0) printf("%s\n", __FUNCTION__);
vbo_exec_vtx_map( exec );
assert((exec->ctx->Driver.NeedFlush & FLUSH_UPDATE_CURRENT) == 0);
@@ -880,10 +892,10 @@ void vbo_exec_FlushVertices( GLcontext *ctx, GLuint flags )
assert(exec->flush_call_depth == 1);
#endif
- if (0) _mesa_printf("%s\n", __FUNCTION__);
+ if (0) printf("%s\n", __FUNCTION__);
if (exec->ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END) {
- if (0) _mesa_printf("%s - inside begin/end\n", __FUNCTION__);
+ if (0) printf("%s - inside begin/end\n", __FUNCTION__);
#ifdef DEBUG
exec->flush_call_depth--;
assert(exec->flush_call_depth == 0);
diff --git a/mesalib/src/mesa/vbo/vbo_exec_array.c b/mesalib/src/mesa/vbo/vbo_exec_array.c
index 6de8f059b..90474da7c 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_array.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_array.c
@@ -35,7 +35,6 @@
#include "main/bufferobj.h"
#include "main/enums.h"
#include "main/macros.h"
-#include "glapi/dispatch.h"
#include "vbo_context.h"
@@ -50,7 +49,7 @@ vbo_get_minmax_index(GLcontext *ctx,
GLuint *min_index, GLuint *max_index)
{
GLuint i;
- GLsizei count = prim->count;
+ GLuint count = prim->count;
const void *indices;
if (_mesa_is_bufferobj(ib->obj)) {
@@ -133,17 +132,17 @@ check_array_data(GLcontext *ctx, struct gl_client_array *array,
case GL_FLOAT:
{
GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
- GLuint k;
+ GLint k;
for (k = 0; k < array->Size; k++) {
if (IS_INF_OR_NAN(f[k]) ||
f[k] >= 1.0e20 || f[k] <= -1.0e10) {
- _mesa_printf("Bad array data:\n");
- _mesa_printf(" Element[%u].%u = %f\n", j, k, f[k]);
- _mesa_printf(" Array %u at %p\n", attrib, (void* ) array);
- _mesa_printf(" Type 0x%x, Size %d, Stride %d\n",
- array->Type, array->Size, array->Stride);
- _mesa_printf(" Address/offset %p in Buffer Object %u\n",
- array->Ptr, array->BufferObj->Name);
+ printf("Bad array data:\n");
+ printf(" Element[%u].%u = %f\n", j, k, f[k]);
+ printf(" Array %u at %p\n", attrib, (void* ) array);
+ printf(" Type 0x%x, Size %d, Stride %d\n",
+ array->Type, array->Size, array->Stride);
+ printf(" Address/offset %p in Buffer Object %u\n",
+ array->Ptr, array->BufferObj->Name);
f[k] = 1.0; /* XXX replace the bad value! */
}
/*assert(!IS_INF_OR_NAN(f[k]));*/
@@ -258,21 +257,21 @@ print_draw_arrays(GLcontext *ctx, struct vbo_exec_context *exec,
{
int i;
- _mesa_printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
- mode, start, count);
+ printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
+ mode, start, count);
for (i = 0; i < 32; i++) {
GLuint bufName = exec->array.inputs[i]->BufferObj->Name;
GLint stride = exec->array.inputs[i]->Stride;
- _mesa_printf("attr %2d: size %d stride %d enabled %d "
- "ptr %p Bufobj %u\n",
- i,
- exec->array.inputs[i]->Size,
- stride,
- /*exec->array.inputs[i]->Enabled,*/
- exec->array.legacy_array[i]->Enabled,
- exec->array.inputs[i]->Ptr,
- bufName);
+ printf("attr %2d: size %d stride %d enabled %d "
+ "ptr %p Bufobj %u\n",
+ i,
+ exec->array.inputs[i]->Size,
+ stride,
+ /*exec->array.inputs[i]->Enabled,*/
+ exec->array.legacy_array[i]->Enabled,
+ exec->array.inputs[i]->Ptr,
+ bufName);
if (bufName) {
struct gl_buffer_object *buf = _mesa_lookup_bufferobj(ctx, bufName);
@@ -285,9 +284,9 @@ print_draw_arrays(GLcontext *ctx, struct vbo_exec_context *exec,
int n = (count * stride) / 4;
if (n > 32)
n = 32;
- _mesa_printf(" Data at offset %d:\n", offset);
+ printf(" Data at offset %d:\n", offset);
for (i = 0; i < n; i++) {
- _mesa_printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
+ printf(" float[%d] = 0x%08x %f\n", i, k[i], f[i]);
}
ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, buf);
}
@@ -444,6 +443,13 @@ recalculate_input_bindings(GLcontext *ctx)
}
+/**
+ * Examine the enabled vertex arrays to set the exec->array.inputs[] values.
+ * These will point to the arrays to actually use for drawing. Some will
+ * be user-provided arrays, other will be zero-stride const-valued arrays.
+ * Note that this might set the _NEW_ARRAY dirty flag so state validation
+ * must be done after this call.
+ */
static void
bind_arrays(GLcontext *ctx)
{
@@ -485,9 +491,6 @@ vbo_exec_DrawArrays(GLenum mode, GLint start, GLsizei count)
FLUSH_CURRENT( ctx, 0 );
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
if (!_mesa_valid_to_render(ctx, "glDrawArrays")) {
return;
}
@@ -543,37 +546,37 @@ dump_element_buffer(GLcontext *ctx, GLenum type)
case GL_UNSIGNED_BYTE:
{
const GLubyte *us = (const GLubyte *) map;
- GLuint i;
+ GLint i;
for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size; i++) {
- _mesa_printf("%02x ", us[i]);
+ printf("%02x ", us[i]);
if (i % 32 == 31)
- _mesa_printf("\n");
+ printf("\n");
}
- _mesa_printf("\n");
+ printf("\n");
}
break;
case GL_UNSIGNED_SHORT:
{
const GLushort *us = (const GLushort *) map;
- GLuint i;
+ GLint i;
for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 2; i++) {
- _mesa_printf("%04x ", us[i]);
+ printf("%04x ", us[i]);
if (i % 16 == 15)
- _mesa_printf("\n");
+ printf("\n");
}
- _mesa_printf("\n");
+ printf("\n");
}
break;
case GL_UNSIGNED_INT:
{
const GLuint *us = (const GLuint *) map;
- GLuint i;
+ GLint i;
for (i = 0; i < ctx->Array.ElementArrayBufferObj->Size / 4; i++) {
- _mesa_printf("%08x ", us[i]);
+ printf("%08x ", us[i]);
if (i % 8 == 7)
- _mesa_printf("\n");
+ printf("\n");
}
- _mesa_printf("\n");
+ printf("\n");
}
break;
default:
@@ -601,18 +604,16 @@ vbo_validated_drawrangeelements(GLcontext *ctx, GLenum mode,
FLUSH_CURRENT( ctx, 0 );
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
if (!_mesa_valid_to_render(ctx, "glDraw[Range]Elements")) {
return;
}
+ bind_arrays( ctx );
+
+ /* check for dirty state again */
if (ctx->NewState)
_mesa_update_state( ctx );
- bind_arrays( ctx );
-
ib.count = count;
ib.type = type;
ib.obj = ctx->Array.ElementArrayBufferObj;
@@ -689,6 +690,16 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
* or we can read/write out of memory in several different places!
*/
+ /* Catch/fix some potential user errors */
+ if (type == GL_UNSIGNED_BYTE) {
+ start = MIN2(start, 0xff);
+ end = MIN2(end, 0xff);
+ }
+ else if (type == GL_UNSIGNED_SHORT) {
+ start = MIN2(start, 0xffff);
+ end = MIN2(end, 0xffff);
+ }
+
if (end >= ctx->Array.ArrayObj->_MaxElement) {
/* the max element is out of bounds of one or more enabled arrays */
warnCount++;
@@ -713,8 +724,7 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
#ifdef DEBUG
/* 'end' was out of bounds, but now let's check the actual array
- * indexes to see if any of them are out of bounds. If so, warn
- * and skip the draw to avoid potential segfault, etc.
+ * indexes to see if any of them are out of bounds.
*/
{
GLuint max = _mesa_max_buffer_index(ctx, count, type, indices,
@@ -731,7 +741,6 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
ctx->Array.ElementArrayBufferObj->Name,
ctx->Array.ElementArrayBufferObj->Size);
}
- return;
}
/* XXX we could also find the min index and compare to 'start'
* to see if start is correct. But it's more likely to get the
@@ -739,14 +748,18 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
*/
}
#endif
+
+ /* Set 'end' to the max possible legal value */
+ assert(ctx->Array.ArrayObj->_MaxElement >= 1);
+ end = ctx->Array.ArrayObj->_MaxElement - 1;
}
else if (0) {
- _mesa_printf("glDraw[Range]Elements{,BaseVertex}"
- "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
- "base %d\n",
- start, end, type, count,
- ctx->Array.ElementArrayBufferObj->Name,
- basevertex);
+ printf("glDraw[Range]Elements{,BaseVertex}"
+ "(start %u, end %u, type 0x%x, count %d) ElemBuf %u, "
+ "base %d\n",
+ start, end, type, count,
+ ctx->Array.ElementArrayBufferObj->Name,
+ basevertex);
}
#if 0
@@ -837,17 +850,11 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode,
FLUSH_CURRENT( ctx, 0 );
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
if (!_mesa_valid_to_render(ctx, "glMultiDrawElements")) {
return;
}
- if (ctx->NewState)
- _mesa_update_state( ctx );
-
- prim = _mesa_calloc(primcount * sizeof(*prim));
+ prim = calloc(1, primcount * sizeof(*prim));
if (prim == NULL) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glMultiDrawElements");
return;
@@ -858,6 +865,10 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode,
*/
bind_arrays( ctx );
+ /* check for dirty state again */
+ if (ctx->NewState)
+ _mesa_update_state( ctx );
+
switch (type) {
case GL_UNSIGNED_INT:
index_type_size = 4;
@@ -924,13 +935,13 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode,
vbo->draw_prims(ctx, exec->array.inputs, prim, primcount, &ib,
GL_FALSE, ~0, ~0);
} else {
+ /* render one prim at a time */
for (i = 0; i < primcount; i++) {
ib.count = count[i];
ib.type = type;
ib.obj = ctx->Array.ElementArrayBufferObj;
ib.ptr = indices[i];
-
prim[0].begin = 1;
prim[0].end = 1;
prim[0].weak = 0;
@@ -943,12 +954,13 @@ vbo_validated_multidrawelements(GLcontext *ctx, GLenum mode,
prim[0].basevertex = basevertex[i];
else
prim[0].basevertex = 0;
- }
- vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib,
- GL_FALSE, ~0, ~0);
+ vbo->draw_prims(ctx, exec->array.inputs, prim, 1, &ib,
+ GL_FALSE, ~0, ~0);
+ }
}
- _mesa_free(prim);
+
+ free(prim);
}
diff --git a/mesalib/src/mesa/vbo/vbo_exec_draw.c b/mesalib/src/mesa/vbo/vbo_exec_draw.c
index 4f4385601..045af46da 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_draw.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_draw.c
@@ -30,7 +30,6 @@
#include "main/context.h"
#include "main/enums.h"
#include "main/state.h"
-#include "main/macros.h"
#include "vbo_context.h"
@@ -44,22 +43,22 @@ vbo_exec_debug_verts( struct vbo_exec_context *exec )
GLuint count = exec->vtx.vert_count;
GLuint i;
- _mesa_printf("%s: %u vertices %d primitives, %d vertsize\n",
- __FUNCTION__,
- count,
- exec->vtx.prim_count,
- exec->vtx.vertex_size);
+ printf("%s: %u vertices %d primitives, %d vertsize\n",
+ __FUNCTION__,
+ count,
+ exec->vtx.prim_count,
+ exec->vtx.vertex_size);
for (i = 0 ; i < exec->vtx.prim_count ; i++) {
struct _mesa_prim *prim = &exec->vtx.prim[i];
- _mesa_printf(" prim %d: %s%s %d..%d %s %s\n",
- i,
- _mesa_lookup_prim_by_nr(prim->mode),
- prim->weak ? " (weak)" : "",
- prim->start,
- prim->start + prim->count,
- prim->begin ? "BEGIN" : "(wrap)",
- prim->end ? "END" : "(wrap)");
+ printf(" prim %d: %s%s %d..%d %s %s\n",
+ i,
+ _mesa_lookup_prim_by_nr(prim->mode),
+ prim->weak ? " (weak)" : "",
+ prim->start,
+ prim->start + prim->count,
+ prim->begin ? "BEGIN" : "(wrap)",
+ prim->end ? "END" : "(wrap)");
}
}
@@ -86,24 +85,24 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
case GL_LINES:
ovf = nr&1;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
return i;
case GL_TRIANGLES:
ovf = nr%3;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
return i;
case GL_QUADS:
ovf = nr&3;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
return i;
case GL_LINE_STRIP:
if (nr == 0) {
return 0;
}
else {
- _mesa_memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
return 1;
}
case GL_LINE_LOOP:
@@ -113,12 +112,12 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
return 0;
}
else if (nr == 1) {
- _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) );
+ memcpy( dst, src+0, sz * sizeof(GLfloat) );
return 1;
}
else {
- _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) );
- _mesa_memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst, src+0, sz * sizeof(GLfloat) );
+ memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
return 2;
}
case GL_TRIANGLE_STRIP:
@@ -140,7 +139,7 @@ vbo_copy_vertices( struct vbo_exec_context *exec )
break;
}
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
return i;
case PRIM_OUTSIDE_BEGIN_END:
return 0;
@@ -344,7 +343,7 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
}
if (0)
- _mesa_printf("map %d..\n", exec->vtx.buffer_used);
+ printf("map %d..\n", exec->vtx.buffer_used);
}
@@ -379,8 +378,8 @@ vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
}
if (0)
- _mesa_printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
- exec->vtx.vert_count);
+ printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
+ exec->vtx.vert_count);
vbo_context(ctx)->draw_prims( ctx,
exec->vtx.inputs,
diff --git a/mesalib/src/mesa/vbo/vbo_exec_eval.c b/mesalib/src/mesa/vbo/vbo_exec_eval.c
index a7846213d..23ad12608 100644
--- a/mesalib/src/mesa/vbo/vbo_exec_eval.c
+++ b/mesalib/src/mesa/vbo/vbo_exec_eval.c
@@ -29,7 +29,7 @@
#include "main/context.h"
#include "main/macros.h"
#include "math/m_eval.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
#include "vbo_exec.h"
diff --git a/mesalib/src/mesa/vbo/vbo_rebase.c b/mesalib/src/mesa/vbo/vbo_rebase.c
index 55a82ee36..ff7c7a6b0 100644
--- a/mesalib/src/mesa/vbo/vbo_rebase.c
+++ b/mesalib/src/mesa/vbo/vbo_rebase.c
@@ -124,7 +124,7 @@ void vbo_rebase_prims( GLcontext *ctx,
assert(min_index != 0);
if (0)
- _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
+ printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
/* XXX this path is disabled for now.
@@ -134,7 +134,7 @@ void vbo_rebase_prims( GLcontext *ctx,
/* If we can just tell the hardware or the TNL to interpret our
* indices with a different base, do so.
*/
- tmp_prims = (struct _mesa_prim *)_mesa_malloc(sizeof(*prim) * nr_prims);
+ tmp_prims = (struct _mesa_prim *)malloc(sizeof(*prim) * nr_prims);
for (i = 0; i < nr_prims; i++) {
tmp_prims[i] = prim[i];
@@ -187,7 +187,7 @@ void vbo_rebase_prims( GLcontext *ctx,
else {
/* Otherwise the primitives need adjustment.
*/
- tmp_prims = (struct _mesa_prim *)_mesa_malloc(sizeof(*prim) * nr_prims);
+ tmp_prims = (struct _mesa_prim *)malloc(sizeof(*prim) * nr_prims);
for (i = 0; i < nr_prims; i++) {
/* If this fails, it could indicate an application error:
@@ -229,10 +229,10 @@ void vbo_rebase_prims( GLcontext *ctx,
max_index - min_index );
if (tmp_indices)
- _mesa_free(tmp_indices);
+ free(tmp_indices);
if (tmp_prims)
- _mesa_free(tmp_prims);
+ free(tmp_prims);
}
diff --git a/mesalib/src/mesa/vbo/vbo_save.c b/mesalib/src/mesa/vbo/vbo_save.c
index 9757c3d9f..fd9a13027 100644
--- a/mesalib/src/mesa/vbo/vbo_save.c
+++ b/mesalib/src/mesa/vbo/vbo_save.c
@@ -28,8 +28,6 @@
#include "main/mtypes.h"
#include "main/bufferobj.h"
-#include "main/dlist.h"
-#include "main/vtxfmt.h"
#include "main/imports.h"
#include "vbo_context.h"
@@ -60,8 +58,19 @@ void vbo_save_init( GLcontext *ctx )
{
struct gl_client_array *arrays = save->arrays;
+ unsigned i;
+
memcpy(arrays, vbo->legacy_currval, 16 * sizeof(arrays[0]));
memcpy(arrays + 16, vbo->generic_currval, 16 * sizeof(arrays[0]));
+
+ for (i = 0; i < 16; ++i) {
+ arrays[i ].BufferObj = NULL;
+ arrays[i + 16].BufferObj = NULL;
+ _mesa_reference_buffer_object(ctx, &arrays[i ].BufferObj,
+ vbo->legacy_currval[i].BufferObj);
+ _mesa_reference_buffer_object(ctx, &arrays[i + 16].BufferObj,
+ vbo->generic_currval[i].BufferObj);
+ }
}
ctx->Driver.CurrentSavePrimitive = PRIM_UNKNOWN;
diff --git a/mesalib/src/mesa/vbo/vbo_save_api.c b/mesalib/src/mesa/vbo/vbo_save_api.c
index 3f86c68b2..a5d027982 100644
--- a/mesalib/src/mesa/vbo/vbo_save_api.c
+++ b/mesalib/src/mesa/vbo/vbo_save_api.c
@@ -78,7 +78,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "main/api_validate.h"
#include "main/api_arrayelt.h"
#include "main/vtxfmt.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
#include "vbo_context.h"
@@ -118,23 +118,23 @@ static GLuint _save_copy_vertices( GLcontext *ctx,
case GL_LINES:
ovf = nr&1;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
return i;
case GL_TRIANGLES:
ovf = nr%3;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
return i;
case GL_QUADS:
ovf = nr&3;
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
return i;
case GL_LINE_STRIP:
if (nr == 0)
return 0;
else {
- _mesa_memcpy( dst, src+(nr-1)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst, src+(nr-1)*sz, sz*sizeof(GLfloat) );
return 1;
}
case GL_LINE_LOOP:
@@ -143,11 +143,11 @@ static GLuint _save_copy_vertices( GLcontext *ctx,
if (nr == 0)
return 0;
else if (nr == 1) {
- _mesa_memcpy( dst, src+0, sz*sizeof(GLfloat) );
+ memcpy( dst, src+0, sz*sizeof(GLfloat) );
return 1;
} else {
- _mesa_memcpy( dst, src+0, sz*sizeof(GLfloat) );
- _mesa_memcpy( dst+sz, src+(nr-1)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst, src+0, sz*sizeof(GLfloat) );
+ memcpy( dst+sz, src+(nr-1)*sz, sz*sizeof(GLfloat) );
return 2;
}
case GL_TRIANGLE_STRIP:
@@ -158,7 +158,7 @@ static GLuint _save_copy_vertices( GLcontext *ctx,
default: ovf = 2 + (nr&1); break;
}
for (i = 0 ; i < ovf ; i++)
- _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
+ memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) );
return i;
default:
assert(0);
@@ -277,7 +277,7 @@ static void _save_compile_vertex_list( GLcontext *ctx )
/* Duplicate our template, increment refcounts to the storage structs:
*/
- _mesa_memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
+ memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz));
node->vertex_size = save->vertex_size;
node->buffer_offset = (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat);
node->count = save->vert_count;
@@ -441,7 +441,7 @@ static void _save_wrap_filled_vertex( GLcontext *ctx )
assert(save->max_vert - save->vert_count > save->copied.nr);
for (i = 0 ; i < save->copied.nr ; i++) {
- _mesa_memcpy( save->buffer_ptr, data, save->vertex_size * sizeof(GLfloat));
+ memcpy( save->buffer_ptr, data, save->vertex_size * sizeof(GLfloat));
data += save->vertex_size;
save->buffer_ptr += save->vertex_size;
save->vert_count++;
@@ -1185,10 +1185,10 @@ static void vbo_print_vertex_list( GLcontext *ctx, void *data )
GLuint i;
(void) ctx;
- _mesa_printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
- node->count,
- node->prim_count,
- node->vertex_size);
+ printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n",
+ node->count,
+ node->prim_count,
+ node->vertex_size);
for (i = 0 ; i < node->prim_count ; i++) {
struct _mesa_prim *prim = &node->prim[i];
diff --git a/mesalib/src/mesa/vbo/vbo_save_draw.c b/mesalib/src/mesa/vbo/vbo_save_draw.c
index d834fa1f2..a7cf29acd 100644
--- a/mesalib/src/mesa/vbo/vbo_save_draw.c
+++ b/mesalib/src/mesa/vbo/vbo_save_draw.c
@@ -243,7 +243,7 @@ void vbo_save_playback_vertex_list( GLcontext *ctx, void *data )
* includes operations such as glBegin or glDrawArrays.
*/
if (0)
- _mesa_printf("displaylist recursive begin");
+ printf("displaylist recursive begin");
vbo_save_loopback_vertex_list( ctx, node );
return;
diff --git a/mesalib/src/mesa/vbo/vbo_save_loopback.c b/mesalib/src/mesa/vbo/vbo_save_loopback.c
index b7a74e453..3f581ea02 100644
--- a/mesalib/src/mesa/vbo/vbo_save_loopback.c
+++ b/mesalib/src/mesa/vbo/vbo_save_loopback.c
@@ -29,9 +29,8 @@
#include "main/glheader.h"
#include "main/enums.h"
#include "main/imports.h"
-#include "main/macros.h"
#include "main/mtypes.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
#include "glapi/glapi.h"
#include "vbo_context.h"
@@ -79,7 +78,7 @@ struct loopback_attr {
};
/* Don't emit ends and begins on wrapped primitives. Don't replay
- * wrapped vertices. If we get here, it's probably because the the
+ * wrapped vertices. If we get here, it's probably because the
* precalculated wrapping is wrong.
*/
static void loopback_prim( GLcontext *ctx,
@@ -96,12 +95,12 @@ static void loopback_prim( GLcontext *ctx,
GLuint k;
if (0)
- _mesa_printf("loopback prim %s(%s,%s) verts %d..%d\n",
- _mesa_lookup_prim_by_nr(prim->mode),
- prim->begin ? "begin" : "..",
- prim->end ? "end" : "..",
- start,
- end);
+ printf("loopback prim %s(%s,%s) verts %d..%d\n",
+ _mesa_lookup_prim_by_nr(prim->mode),
+ prim->begin ? "begin" : "..",
+ prim->end ? "end" : "..",
+ start,
+ end);
if (prim->begin) {
CALL_Begin(GET_DISPATCH(), ( prim->mode ));
diff --git a/mesalib/src/mesa/vbo/vbo_split.c b/mesalib/src/mesa/vbo/vbo_split.c
index c445acca7..ce40cbbcc 100644
--- a/mesalib/src/mesa/vbo/vbo_split.c
+++ b/mesalib/src/mesa/vbo/vbo_split.c
@@ -108,12 +108,14 @@ void vbo_split_prims( GLcontext *ctx,
vbo_draw_func draw,
const struct split_limits *limits )
{
- GLuint max_basevertex = prim->basevertex;
+ GLint max_basevertex = prim->basevertex;
GLuint i;
for (i = 1; i < nr_prims; i++)
max_basevertex = MAX2(max_basevertex, prim[i].basevertex);
+ /* XXX max_basevertex is computed but not used, why? */
+
if (ib) {
if (limits->max_indices == 0) {
/* Could traverse the indices, re-emitting vertices in turn.
diff --git a/mesalib/src/mesa/vbo/vbo_split_copy.c b/mesalib/src/mesa/vbo/vbo_split_copy.c
index c45190b9d..2ec7d9b0f 100644
--- a/mesalib/src/mesa/vbo/vbo_split_copy.c
+++ b/mesalib/src/mesa/vbo/vbo_split_copy.c
@@ -34,7 +34,6 @@
#include "main/imports.h"
#include "main/image.h"
#include "main/macros.h"
-#include "main/enums.h"
#include "main/mtypes.h"
#include "vbo_split.h"
@@ -148,21 +147,21 @@ dump_draw_info(GLcontext *ctx,
{
GLuint i, j;
- _mesa_printf("VBO Draw:\n");
+ printf("VBO Draw:\n");
for (i = 0; i < nr_prims; i++) {
- _mesa_printf("Prim %u of %u\n", i, nr_prims);
- _mesa_printf(" Prim mode 0x%x\n", prims[i].mode);
- _mesa_printf(" IB: %p\n", (void*) ib);
+ printf("Prim %u of %u\n", i, nr_prims);
+ printf(" Prim mode 0x%x\n", prims[i].mode);
+ printf(" IB: %p\n", (void*) ib);
for (j = 0; j < VERT_ATTRIB_MAX; j++) {
- _mesa_printf(" array %d at %p:\n", j, (void*) arrays[j]);
- _mesa_printf(" enabled %d, ptr %p, size %d, type 0x%x, stride %d\n",
- arrays[j]->Enabled, arrays[j]->Ptr,
- arrays[j]->Size, arrays[j]->Type, arrays[j]->StrideB);
+ printf(" array %d at %p:\n", j, (void*) arrays[j]);
+ printf(" enabled %d, ptr %p, size %d, type 0x%x, stride %d\n",
+ arrays[j]->Enabled, arrays[j]->Ptr,
+ arrays[j]->Size, arrays[j]->Type, arrays[j]->StrideB);
if (0) {
GLint k = prims[i].start + prims[i].count - 1;
GLfloat *last = (GLfloat *) (arrays[j]->Ptr + arrays[j]->Stride * k);
- _mesa_printf(" last: %f %f %f\n",
- last[0], last[1], last[2]);
+ printf(" last: %f %f %f\n",
+ last[0], last[1], last[2]);
}
}
}
@@ -197,7 +196,7 @@ flush( struct copy_context *copy )
&copy->dstib,
GL_TRUE,
0,
- copy->dstbuf_nr );
+ copy->dstbuf_nr - 1 );
/* Reset all pointers:
*/
@@ -221,8 +220,6 @@ begin( struct copy_context *copy, GLenum mode, GLboolean begin_flag )
{
struct _mesa_prim *prim = &copy->dstprim[copy->dstprim_nr];
-/* _mesa_printf("begin %s (%d)\n", _mesa_lookup_prim_by_nr(mode), begin_flag); */
-
prim->mode = mode;
prim->begin = begin_flag;
}
@@ -238,7 +235,7 @@ elt(struct copy_context *copy, GLuint elt_idx)
GLuint elt = copy->srcelt[elt_idx];
GLuint slot = elt & (ELT_TABLE_SIZE-1);
-/* _mesa_printf("elt %d\n", elt); */
+/* printf("elt %d\n", elt); */
/* Look up the incoming element in the vertex cache. Re-emit if
* necessary.
@@ -247,7 +244,7 @@ elt(struct copy_context *copy, GLuint elt_idx)
GLubyte *csr = copy->dstptr;
GLuint i;
-/* _mesa_printf(" --> emit to dstelt %d\n", copy->dstbuf_nr); */
+/* printf(" --> emit to dstelt %d\n", copy->dstbuf_nr); */
for (i = 0; i < copy->nr_varying; i++) {
const struct gl_client_array *srcarray = copy->varying[i].array;
@@ -271,10 +268,10 @@ elt(struct copy_context *copy, GLuint elt_idx)
{
const GLuint *f = (const GLuint *)srcptr;
GLuint j;
- _mesa_printf(" varying %d: ", i);
+ printf(" varying %d: ", i);
for(j = 0; j < copy->varying[i].size / 4; j++)
- _mesa_printf("%x ", f[j]);
- _mesa_printf("\n");
+ printf("%x ", f[j]);
+ printf("\n");
}
}
@@ -287,9 +284,9 @@ elt(struct copy_context *copy, GLuint elt_idx)
copy->dstbuf_nr * copy->vertex_size));
}
/* else */
-/* _mesa_printf(" --> reuse vertex\n"); */
+/* printf(" --> reuse vertex\n"); */
-/* _mesa_printf(" --> emit %d\n", copy->vert_cache[slot].out); */
+/* printf(" --> emit %d\n", copy->vert_cache[slot].out); */
copy->dstelt[copy->dstelt_nr++] = copy->vert_cache[slot].out;
return check_flush(copy);
}
@@ -303,7 +300,7 @@ end( struct copy_context *copy, GLboolean end_flag )
{
struct _mesa_prim *prim = &copy->dstprim[copy->dstprim_nr];
-/* _mesa_printf("end (%d)\n", end_flag); */
+/* printf("end (%d)\n", end_flag); */
prim->end = end_flag;
prim->count = copy->dstelt_nr - prim->start;
@@ -469,7 +466,7 @@ replay_init( struct copy_context *copy )
switch (copy->ib->type) {
case GL_UNSIGNED_BYTE:
- copy->translated_elt_buf = _mesa_malloc(sizeof(GLuint) * copy->ib->count);
+ copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
copy->srcelt = copy->translated_elt_buf;
for (i = 0; i < copy->ib->count; i++)
@@ -477,7 +474,7 @@ replay_init( struct copy_context *copy )
break;
case GL_UNSIGNED_SHORT:
- copy->translated_elt_buf = _mesa_malloc(sizeof(GLuint) * copy->ib->count);
+ copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
copy->srcelt = copy->translated_elt_buf;
for (i = 0; i < copy->ib->count; i++)
@@ -503,7 +500,7 @@ replay_init( struct copy_context *copy )
*
* XXX: This should be a VBO!
*/
- copy->dstbuf = _mesa_malloc(copy->dstbuf_size * copy->vertex_size);
+ copy->dstbuf = malloc(copy->dstbuf_size * copy->vertex_size);
copy->dstptr = copy->dstbuf;
/* Setup new vertex arrays to point into the output buffer:
@@ -532,7 +529,7 @@ replay_init( struct copy_context *copy )
copy->ib->count * 2 + 3);
copy->dstelt_size = MIN2(copy->dstelt_size,
copy->limits->max_indices);
- copy->dstelt = _mesa_malloc(sizeof(GLuint) * copy->dstelt_size);
+ copy->dstelt = malloc(sizeof(GLuint) * copy->dstelt_size);
copy->dstelt_nr = 0;
/* Setup the new index buffer to point to the allocated element
@@ -556,9 +553,9 @@ replay_finish( struct copy_context *copy )
/* Free our vertex and index buffers:
*/
- _mesa_free(copy->translated_elt_buf);
- _mesa_free(copy->dstbuf);
- _mesa_free(copy->dstelt);
+ free(copy->translated_elt_buf);
+ free(copy->dstbuf);
+ free(copy->dstelt);
/* Unmap VBO's
*/
diff --git a/mesalib/src/mesa/vbo/vbo_split_inplace.c b/mesalib/src/mesa/vbo/vbo_split_inplace.c
index da84eaa6e..2fc866c57 100644
--- a/mesalib/src/mesa/vbo/vbo_split_inplace.c
+++ b/mesalib/src/mesa/vbo/vbo_split_inplace.c
@@ -30,12 +30,15 @@
#include "main/mtypes.h"
#include "main/macros.h"
#include "main/enums.h"
+#include "main/image.h"
#include "vbo_split.h"
#define MAX_PRIM 32
-/* Used for splitting without copying.
+/* Used for splitting without copying. No attempt is made to handle
+ * too large indexed vertex buffers: In general you need to copy to do
+ * that.
*/
struct split_context {
GLcontext *ctx;
@@ -48,6 +51,7 @@ struct split_context {
vbo_draw_func draw;
const struct split_limits *limits;
+ GLuint limit;
struct _mesa_prim dstprim[MAX_PRIM];
GLuint dstprim_nr;
@@ -58,38 +62,38 @@ struct split_context {
static void flush_vertex( struct split_context *split )
{
- GLuint min_index, max_index;
+ struct _mesa_index_buffer ib;
GLuint i;
if (!split->dstprim_nr)
return;
- min_index = split->dstprim[0].start;
- max_index = min_index + split->dstprim[0].count - 1;
+ if (split->ib) {
+ ib = *split->ib;
- for (i = 1; i < split->dstprim_nr; i++) {
- GLuint tmp_min = split->dstprim[i].start;
- GLuint tmp_max = tmp_min + split->dstprim[i].count - 1;
+ ib.count = split->max_index - split->min_index + 1;
+ ib.ptr = (const void *)((const char *)ib.ptr +
+ split->min_index * _mesa_sizeof_type(ib.type));
- if (tmp_min < min_index)
- min_index = tmp_min;
-
- if (tmp_max > max_index)
- max_index = tmp_max;
+ /* Rebase the primitives to save index buffer entries. */
+ for (i = 0; i < split->dstprim_nr; i++)
+ split->dstprim[i].start -= split->min_index;
}
- assert(max_index >= min_index);
+ assert(split->max_index >= split->min_index);
- split->draw( split->ctx,
- split->array,
- split->dstprim,
- split->dstprim_nr,
- NULL,
- GL_TRUE,
- min_index,
- max_index);
+ split->draw(split->ctx,
+ split->array,
+ split->dstprim,
+ split->dstprim_nr,
+ split->ib ? &ib : NULL,
+ !split->ib,
+ split->min_index,
+ split->max_index);
split->dstprim_nr = 0;
+ split->min_index = ~0;
+ split->max_index = 0;
}
@@ -106,62 +110,67 @@ static struct _mesa_prim *next_outprim( struct split_context *split )
}
}
-static int align(int value, int alignment)
+static void update_index_bounds(struct split_context *split,
+ const struct _mesa_prim *prim)
{
- return (value + alignment - 1) & ~(alignment - 1);
+ split->min_index = MIN2(split->min_index, prim->start);
+ split->max_index = MAX2(split->max_index, prim->start + prim->count - 1);
}
-
+/* Return the maximum amount of vertices that can be emitted for a
+ * primitive starting at 'prim->start', depending on the previous
+ * index bounds.
+ */
+static GLuint get_max_vertices(struct split_context *split,
+ const struct _mesa_prim *prim)
+{
+ if ((prim->start > split->min_index &&
+ prim->start - split->min_index >= split->limit) ||
+ (prim->start < split->max_index &&
+ split->max_index - prim->start >= split->limit))
+ /* "prim" starts too far away from the old range. */
+ return 0;
+
+ return MIN2(split->min_index, prim->start) + split->limit - prim->start;
+}
/* Break large primitives into smaller ones. If not possible, convert
* the primitive to indexed and pass to split_elts().
*/
static void split_prims( struct split_context *split)
{
- GLuint csr = 0;
GLuint i;
for (i = 0; i < split->nr_prims; i++) {
const struct _mesa_prim *prim = &split->prim[i];
GLuint first, incr;
GLboolean split_inplace = split_prim_inplace(prim->mode, &first, &incr);
- GLuint count;
-
- /* Always wrap on an even numbered vertex to avoid problems with
- * triangle strips.
- */
- GLuint available = align(split->limits->max_verts - csr - 1, 2);
- assert(split->limits->max_verts >= csr);
+ GLuint available = get_max_vertices(split, prim);
+ GLuint count = prim->count - (prim->count - first) % incr;
if (prim->count < first)
continue;
-
- count = prim->count - (prim->count - first) % incr;
-
- if ((available < count && !split_inplace) ||
+ if ((available < count && !split_inplace) ||
(available < first && split_inplace)) {
flush_vertex(split);
- csr = 0;
- available = align(split->limits->max_verts - csr - 1, 2);
+ available = get_max_vertices(split, prim);
}
if (available >= count) {
struct _mesa_prim *outprim = next_outprim(split);
+
*outprim = *prim;
- csr += prim->count;
- available = align(split->limits->max_verts - csr - 1, 2);
- }
+ update_index_bounds(split, outprim);
+ }
else if (split_inplace) {
GLuint j, nr;
-
for (j = 0 ; j < count ; ) {
GLuint remaining = count - j;
struct _mesa_prim *outprim = next_outprim(split);
nr = MIN2( available, remaining );
-
nr -= (nr - first) % incr;
outprim->mode = prim->mode;
@@ -169,21 +178,20 @@ static void split_prims( struct split_context *split)
outprim->end = (nr == remaining && prim->end);
outprim->start = prim->start + j;
outprim->count = nr;
-
+
+ update_index_bounds(split, outprim);
+
if (nr == remaining) {
/* Finished.
*/
- j += nr;
- csr += nr;
- available = align(split->limits->max_verts - csr - 1, 2);
+ j += nr;
}
else {
/* Wrapped the primitive:
*/
j += nr - (first - incr);
flush_vertex(split);
- csr = 0;
- available = align(split->limits->max_verts - csr - 1, 2);
+ available = get_max_vertices(split, prim);
}
}
}
@@ -260,10 +268,14 @@ void vbo_split_inplace( GLcontext *ctx,
split.prim = prim;
split.nr_prims = nr_prims;
split.ib = ib;
- split.min_index = min_index;
- split.max_index = max_index;
+
+ /* Empty interval, makes calculations simpler. */
+ split.min_index = ~0;
+ split.max_index = 0;
+
split.draw = draw;
split.limits = limits;
+ split.limit = ib ? limits->max_indices : limits->max_verts;
split_prims( &split );
}