summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mesa/tnl/t_context.h17
-rw-r--r--src/mesa/tnl/t_imm_alloc.c91
-rw-r--r--src/mesa/tnl/t_imm_dlist.c48
-rw-r--r--src/mesa/tnl/t_imm_fixup.c30
4 files changed, 96 insertions, 90 deletions
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index 1647fec1287..d08da93abdb 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -1,4 +1,4 @@
-/* $Id: t_context.h,v 1.44 2003/01/14 04:55:47 brianp Exp $ */
+/* $Id: t_context.h,v 1.45 2003/03/28 01:39:04 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -143,9 +143,10 @@
/**
- * KW: Represents everything that can take place between a begin and
- * end, and can represent multiple begin/end pairs. Can be used to
- * losslessly encode this information in display lists.
+ * Stores everything that can take place between a glBegin and glEnd.
+ * Adjacent glBegin/glEnd pairs are stored back-to-back when there's no
+ * state changes between them.
+ * Used for immediate mode rendering and display lists.
*/
struct immediate
{
@@ -196,6 +197,9 @@ struct immediate
* of individual arrays as we did prior to Mesa 4.1.
*
* XXX may need to use 32-byte aligned allocation for this!!!
+ * XXX replace this with GLfloat *Attrib[VERT_ATTRIB_MAX] and allocate
+ * the attribute arrays as needed, so save memory. As is, we're using
+ * 256 bytes per vertex (16 attribs * 4 comps/attrib * 4 bytes/comp).
*/
GLfloat Attrib[VERT_ATTRIB_MAX][IMM_SIZE][4]; /* GL_NV_vertex_program */
@@ -219,6 +223,11 @@ struct vertex_arrays
GLvector4f TexCoord[MAX_TEXTURE_COORD_UNITS];
GLvector1ui Elt;
GLvector4f FogCoord;
+
+ /* These attributes don't alias with the conventional attributes.
+ * The GL_NV_vertex_program extension defines 16 extra sets of vertex
+ * arrays which have precedent over the conventional arrays when enabled.
+ */
GLvector4f Attribs[VERT_ATTRIB_MAX];
};
diff --git a/src/mesa/tnl/t_imm_alloc.c b/src/mesa/tnl/t_imm_alloc.c
index 7062cd4b9d0..4c1e8201beb 100644
--- a/src/mesa/tnl/t_imm_alloc.c
+++ b/src/mesa/tnl/t_imm_alloc.c
@@ -1,10 +1,10 @@
-/* $Id: t_imm_alloc.c,v 1.17 2002/10/29 20:29:01 brianp Exp $ */
+/* $Id: t_imm_alloc.c,v 1.18 2003/03/28 01:39:05 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 4.1
+ * Version: 5.1
*
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -36,57 +36,63 @@
static int id = 0; /* give each struct immediate a unique ID number */
-static struct immediate *real_alloc_immediate( GLcontext *ctx )
+
+static struct immediate *
+real_alloc_immediate( GLcontext *ctx )
{
- struct immediate *IM = ALIGN_CALLOC_STRUCT( immediate, 32 );
+ struct immediate *immed = ALIGN_CALLOC_STRUCT( immediate, 32 );
- if (!IM)
- return 0;
+ printf("Sizeof(struct immed) = %d\n", sizeof(struct immediate));
-/* memset(IM, 0, sizeof(*IM)); */
+ if (!immed)
+ return NULL;
- IM->id = id++;
- IM->ref_count = 0;
- IM->FlushElt = 0;
- IM->LastPrimitive = IMM_MAX_COPIED_VERTS;
- IM->Count = IMM_MAX_COPIED_VERTS;
- IM->Start = IMM_MAX_COPIED_VERTS;
- IM->Material = 0;
- IM->MaterialMask = 0;
- IM->MaxTextureUnits = ctx->Const.MaxTextureUnits;
- IM->TexSize = 0;
- IM->NormalLengthPtr = 0;
+ immed->id = id++;
+ immed->ref_count = 0;
+ immed->FlushElt = 0;
+ immed->LastPrimitive = IMM_MAX_COPIED_VERTS;
+ immed->Count = IMM_MAX_COPIED_VERTS;
+ immed->Start = IMM_MAX_COPIED_VERTS;
+ immed->Material = 0;
+ immed->MaterialMask = 0;
+ immed->MaxTextureUnits = ctx->Const.MaxTextureCoordUnits;
+ immed->TexSize = 0;
+ immed->NormalLengthPtr = 0;
- IM->CopyTexSize = 0;
- IM->CopyStart = IM->Start;
+ immed->CopyTexSize = 0;
+ immed->CopyStart = immed->Start;
- return IM;
+ return immed;
}
-static void real_free_immediate( struct immediate *IM )
+static void
+real_free_immediate( struct immediate *immed )
{
static int freed = 0;
- if (IM->Material) {
- FREE( IM->Material );
- FREE( IM->MaterialMask );
- IM->Material = 0;
- IM->MaterialMask = 0;
+ if (immed->Material) {
+ FREE( immed->Material );
+ FREE( immed->MaterialMask );
+ immed->Material = 0;
+ immed->MaterialMask = 0;
}
- if (IM->NormalLengthPtr)
- ALIGN_FREE( IM->NormalLengthPtr );
+ if (immed->NormalLengthPtr)
+ ALIGN_FREE( immed->NormalLengthPtr );
- ALIGN_FREE( IM );
+ ALIGN_FREE( immed );
freed++;
/* printf("outstanding %d\n", id - freed); */
}
-/* Cache a single allocated immediate struct.
+/**
+ * Return a pointer to a new 'struct immediate' object.
+ * We actually keep a spare/cached one to reduce malloc calls.
*/
-struct immediate *_tnl_alloc_immediate( GLcontext *ctx )
+struct immediate *
+_tnl_alloc_immediate( GLcontext *ctx )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct immediate *tmp = tnl->freed_immediate;
@@ -99,26 +105,29 @@ struct immediate *_tnl_alloc_immediate( GLcontext *ctx )
return real_alloc_immediate( ctx );
}
-/* May be called after tnl is destroyed.
+/**
+ * Free a 'struct immediate' object.
+ * May be called after tnl is destroyed.
*/
-void _tnl_free_immediate( GLcontext *ctx, struct immediate *IM )
+void
+_tnl_free_immediate( GLcontext *ctx, struct immediate *immed )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
- ASSERT(IM->ref_count == 0);
+ ASSERT(immed->ref_count == 0);
- if (IM->NormalLengthPtr) {
- ALIGN_FREE(IM->NormalLengthPtr);
- IM->NormalLengthPtr = NULL;
+ if (immed->NormalLengthPtr) {
+ ALIGN_FREE(immed->NormalLengthPtr);
+ immed->NormalLengthPtr = NULL;
}
if (!tnl) {
- real_free_immediate( IM );
+ real_free_immediate( immed );
}
else {
if (tnl->freed_immediate)
real_free_immediate( tnl->freed_immediate );
- tnl->freed_immediate = IM;
+ tnl->freed_immediate = immed;
}
}
diff --git a/src/mesa/tnl/t_imm_dlist.c b/src/mesa/tnl/t_imm_dlist.c
index a9ae72cee07..07dd86b334e 100644
--- a/src/mesa/tnl/t_imm_dlist.c
+++ b/src/mesa/tnl/t_imm_dlist.c
@@ -1,4 +1,4 @@
-/* $Id: t_imm_dlist.c,v 1.46 2003/03/01 01:50:26 brianp Exp $ */
+/* $Id: t_imm_dlist.c,v 1.47 2003/03/28 01:39:05 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -66,7 +66,8 @@ static void execute_compiled_cassette( GLcontext *ctx, void *data );
static void loopback_compiled_cassette( GLcontext *ctx, struct immediate *IM );
-static void build_normal_lengths( struct immediate *IM )
+static void
+build_normal_lengths( struct immediate *IM )
{
GLuint i;
GLfloat len;
@@ -93,7 +94,9 @@ static void build_normal_lengths( struct immediate *IM )
}
}
-static void fixup_normal_lengths( struct immediate *IM )
+
+static void
+fixup_normal_lengths( struct immediate *IM )
{
GLuint i;
GLfloat len = 1.0F; /* just to silence warnings */
@@ -147,6 +150,9 @@ _tnl_compile_cassette( GLcontext *ctx, struct immediate *IM )
_tnl_fixup_input( ctx, IM );
+ /* Allocate space for this structure in the display list currently
+ * being compiled.
+ */
node = (TNLvertexcassette *)
_mesa_alloc_instruction(ctx,
tnl->opcode_vertex_cassette,
@@ -202,7 +208,8 @@ _tnl_compile_cassette( GLcontext *ctx, struct immediate *IM )
}
-static void fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
+static void
+fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
@@ -240,7 +247,8 @@ static void fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
IM->LastPrimitive = IM->CopyStart;
}
}
- } else {
+ }
+ else {
GLuint i;
if (IM->BeginState & VERT_ERROR_0)
@@ -249,6 +257,7 @@ static void fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
if (IM->CopyStart == IM->Start &&
IM->Flag[IM->Start] & (VERT_BIT_END | VERT_BIT_END_VB))
{
+ /* nothing */
}
else
{
@@ -261,7 +270,7 @@ static void fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
ASSERT(IM->PrimitiveLength[IM->Start] > 0 ||
IM->Flag[IM->Start] & (VERT_BIT_END | VERT_BIT_END_VB));
- for (i = IM->Start ; i <= IM->Count ; i += IM->PrimitiveLength[i])
+ for (i = IM->Start ; i <= IM->Count ; i += IM->PrimitiveLength[i]) {
if (IM->Flag[i] & (VERT_BIT_END | VERT_BIT_END_VB)) {
IM->PrimitiveLength[IM->CopyStart] = i - IM->CopyStart;
if (IM->Flag[i] & VERT_BIT_END_VB) {
@@ -273,14 +282,17 @@ static void fixup_compiled_primitives( GLcontext *ctx, struct immediate *IM )
}
break;
}
+ }
}
}
}
+
/* Undo any changes potentially made to the immediate in the range
* IM->Start..IM->Count above.
*/
-static void restore_compiled_primitives( GLcontext *ctx, struct immediate *IM )
+static void
+restore_compiled_primitives( GLcontext *ctx, struct immediate *IM )
{
TNLcontext *tnl = TNL_CONTEXT(ctx);
IM->Primitive[IM->Start] = tnl->DlistPrimitive;
@@ -288,7 +300,6 @@ static void restore_compiled_primitives( GLcontext *ctx, struct immediate *IM )
}
-
static void
execute_compiled_cassette( GLcontext *ctx, void *data )
{
@@ -384,6 +395,7 @@ execute_compiled_cassette( GLcontext *ctx, void *data )
tnl->ReplayHardBeginEnd = 0;
}
+
static void
destroy_compiled_cassette( GLcontext *ctx, void *data )
{
@@ -419,6 +431,7 @@ print_compiled_cassette( GLcontext *ctx, void *data )
_tnl_print_cassette( node->IM );
}
+
void
_tnl_BeginCallList( GLcontext *ctx, GLuint list )
{
@@ -505,7 +518,12 @@ _tnl_dlist_init( GLcontext *ctx )
}
-static void emit_material( struct gl_material *src, GLuint bitmask )
+/**
+ * Call glMaterialfv for the attributes specified by bitmask, using the
+ * material colors in src.
+ */
+static void
+emit_material( const struct gl_material *src, GLuint bitmask )
{
if (bitmask & FRONT_EMISSION_BIT)
glMaterialfv( GL_FRONT, GL_EMISSION, src[0].Emission );
@@ -562,16 +580,14 @@ static void emit_material( struct gl_material *src, GLuint bitmask )
* begin/end), or (for tnl hardware) implement their own display list
* mechanism.
*/
-static void loopback_compiled_cassette( GLcontext *ctx, struct immediate *IM )
+static void
+loopback_compiled_cassette( GLcontext *ctx, struct immediate *IM )
{
- GLuint i;
- GLuint *flags = IM->Flag;
- GLuint orflag = IM->OrFlag;
- GLuint j;
+ const GLuint *flags = IM->Flag;
+ const GLuint orflag = IM->OrFlag;
void (GLAPIENTRY *vertex)( const GLfloat * );
void (GLAPIENTRY *texcoordfv[MAX_TEXTURE_COORD_UNITS])( GLenum, const GLfloat * );
- GLuint maxtex = 0;
- GLuint p, length, prim = 0;
+ GLuint i, j, p, length, prim = 0, maxtex = 0;
if (orflag & VERT_BITS_OBJ_234)
vertex = (void (GLAPIENTRY *)(const GLfloat *)) glVertex4fv;
diff --git a/src/mesa/tnl/t_imm_fixup.c b/src/mesa/tnl/t_imm_fixup.c
index 8cb263363e8..6e40db6b438 100644
--- a/src/mesa/tnl/t_imm_fixup.c
+++ b/src/mesa/tnl/t_imm_fixup.c
@@ -1,4 +1,4 @@
-/* $Id: t_imm_fixup.c,v 1.40 2003/03/01 01:50:27 brianp Exp $ */
+/* $Id: t_imm_fixup.c,v 1.41 2003/03/28 01:39:05 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -207,39 +207,11 @@ static void copy_from_current( GLcontext *ctx, struct immediate *IM,
if (MESA_VERBOSE&VERBOSE_IMMEDIATE)
_tnl_print_vert_flags("copy from current", copyMask);
-#if 0
- if (copyMask & VERT_BIT_NORMAL) {
- COPY_4V(IM->Attrib[VERT_ATTRIB_NORMAL][pos],
- ctx->Current.Attrib[VERT_ATTRIB_NORMAL]);
- }
-
- if (copyMask & VERT_BIT_COLOR0) {
- COPY_4FV( IM->Attrib[VERT_ATTRIB_COLOR0][pos],
- ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
- }
-
- if (copyMask & VERT_BIT_COLOR1)
- COPY_4FV( IM->Attrib[VERT_ATTRIB_COLOR1][pos],
- ctx->Current.Attrib[VERT_ATTRIB_COLOR1]);
-
- if (copyMask & VERT_BIT_FOG)
- IM->Attrib[VERT_ATTRIB_FOG][pos][0] = ctx->Current.Attrib[VERT_ATTRIB_FOG][0];
-
- if (copyMask & VERT_BITS_TEX_ANY) {
- GLuint i;
- for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++) {
- if (copyMask & VERT_BIT_TEX(i))
- COPY_4FV(IM->Attrib[VERT_ATTRIB_TEX0 + i][pos],
- ctx->Current.Attrib[VERT_ATTRIB_TEX0 + i]);
- }
- }
-#else
for (attrib = 0, attribBit = 1; attrib < 16; attrib++, attribBit <<= 1) {
if (copyMask & attribBit) {
COPY_4FV( IM->Attrib[attrib][pos], ctx->Current.Attrib[attrib]);
}
}
-#endif
if (copyMask & VERT_BIT_INDEX)
IM->Index[pos] = ctx->Current.Index;