summaryrefslogtreecommitdiff
path: root/xc/extras/Mesa/src/array_cache/ac_import.c
diff options
context:
space:
mode:
Diffstat (limited to 'xc/extras/Mesa/src/array_cache/ac_import.c')
-rw-r--r--xc/extras/Mesa/src/array_cache/ac_import.c191
1 files changed, 168 insertions, 23 deletions
diff --git a/xc/extras/Mesa/src/array_cache/ac_import.c b/xc/extras/Mesa/src/array_cache/ac_import.c
index 183527eaf..d68de5b03 100644
--- a/xc/extras/Mesa/src/array_cache/ac_import.c
+++ b/xc/extras/Mesa/src/array_cache/ac_import.c
@@ -1,9 +1,9 @@
/*
* Mesa 3-D graphics library
- * Version: 3.5
+ * Version: 4.1
*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2002 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"),
@@ -23,12 +23,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Keith Whitwell <keithw@valinux.com>
+ * Keith Whitwell <keith@tungstengraphics.com>
*/
#include "glheader.h"
#include "macros.h"
-#include "mem.h"
+#include "imports.h"
#include "mmath.h"
#include "mtypes.h"
@@ -58,9 +58,9 @@ static void reset_texcoord( GLcontext *ctx, GLuint unit )
else {
ac->Raw.TexCoord[unit] = ac->Fallback.TexCoord[unit];
- if (ctx->Current.Texcoord[unit][3] != 1.0)
+ if (ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3] != 1.0)
ac->Raw.TexCoord[unit].Size = 4;
- else if (ctx->Current.Texcoord[unit][2] != 0.0)
+ else if (ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2] != 0.0)
ac->Raw.TexCoord[unit].Size = 3;
else
ac->Raw.TexCoord[unit].Size = 2;
@@ -73,7 +73,8 @@ static void reset_texcoord( GLcontext *ctx, GLuint unit )
static void reset_vertex( GLcontext *ctx )
{
ACcontext *ac = AC_CONTEXT(ctx);
- ASSERT(ctx->Array.Vertex.Enabled);
+ ASSERT(ctx->Array.Vertex.Enabled
+ || (ctx->VertexProgram.Enabled && ctx->Array.VertexAttrib[0].Enabled));
ac->Raw.Vertex = ctx->Array.Vertex;
STRIDE_ARRAY(ac->Raw.Vertex, ac->start);
ac->IsCached.Vertex = GL_FALSE;
@@ -103,7 +104,7 @@ static void reset_color( GLcontext *ctx )
ACcontext *ac = AC_CONTEXT(ctx);
- if (ctx->Array._Enabled & _NEW_ARRAY_COLOR) {
+ if (ctx->Array._Enabled & _NEW_ARRAY_COLOR0) {
ac->Raw.Color = ctx->Array.Color;
STRIDE_ARRAY(ac->Raw.Color, ac->start);
}
@@ -111,7 +112,7 @@ static void reset_color( GLcontext *ctx )
ac->Raw.Color = ac->Fallback.Color;
ac->IsCached.Color = GL_FALSE;
- ac->NewArrayState &= ~_NEW_ARRAY_COLOR;
+ ac->NewArrayState &= ~_NEW_ARRAY_COLOR0;
}
@@ -119,7 +120,7 @@ static void reset_secondarycolor( GLcontext *ctx )
{
ACcontext *ac = AC_CONTEXT(ctx);
- if (ctx->Array._Enabled & _NEW_ARRAY_SECONDARYCOLOR) {
+ if (ctx->Array._Enabled & _NEW_ARRAY_COLOR1) {
ac->Raw.SecondaryColor = ctx->Array.SecondaryColor;
STRIDE_ARRAY(ac->Raw.SecondaryColor, ac->start);
}
@@ -127,7 +128,7 @@ static void reset_secondarycolor( GLcontext *ctx )
ac->Raw.SecondaryColor = ac->Fallback.SecondaryColor;
ac->IsCached.SecondaryColor = GL_FALSE;
- ac->NewArrayState &= ~_NEW_ARRAY_SECONDARYCOLOR;
+ ac->NewArrayState &= ~_NEW_ARRAY_COLOR1;
}
@@ -146,6 +147,7 @@ static void reset_index( GLcontext *ctx )
ac->NewArrayState &= ~_NEW_ARRAY_INDEX;
}
+
static void reset_fogcoord( GLcontext *ctx )
{
ACcontext *ac = AC_CONTEXT(ctx);
@@ -161,6 +163,7 @@ static void reset_fogcoord( GLcontext *ctx )
ac->NewArrayState &= ~_NEW_ARRAY_FOGCOORD;
}
+
static void reset_edgeflag( GLcontext *ctx )
{
ACcontext *ac = AC_CONTEXT(ctx);
@@ -177,7 +180,73 @@ static void reset_edgeflag( GLcontext *ctx )
}
+static void reset_attrib( GLcontext *ctx, GLuint index )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ GLboolean fallback = GL_FALSE;
+
+ /*
+ * The 16 NV vertex attribute arrays have top priority. If one of those
+ * is not enabled, look if a corresponding conventional array is enabled.
+ * If nothing else, use the fallback (ctx->Current.Attrib) values.
+ */
+ if (ctx->Array._Enabled & _NEW_ARRAY_ATTRIB(index)) {
+ ac->Raw.Attrib[index] = ctx->Array.VertexAttrib[index];
+ STRIDE_ARRAY(ac->Raw.Attrib[index], ac->start);
+ }
+ else if (ctx->Array._Enabled & (1 << index)) {
+ /* use conventional vertex array if possible */
+ if (index == VERT_ATTRIB_POS) {
+ ac->Raw.Attrib[index] = ctx->Array.Vertex;
+ }
+ else if (index == VERT_ATTRIB_NORMAL) {
+ ac->Raw.Attrib[index] = ctx->Array.Normal;
+ }
+ else if (index == VERT_ATTRIB_COLOR0) {
+ ac->Raw.Attrib[index] = ctx->Array.Color;
+ }
+ else if (index == VERT_ATTRIB_COLOR1) {
+ ac->Raw.Attrib[index] = ctx->Array.SecondaryColor;
+ }
+ else if (index == VERT_ATTRIB_FOG) {
+ ac->Raw.Attrib[index] = ctx->Array.FogCoord;
+ }
+ else if (index >= VERT_ATTRIB_TEX0 && index <= VERT_ATTRIB_TEX7) {
+ GLuint unit = index - VERT_ATTRIB_TEX0;
+ ASSERT(unit < MAX_TEXTURE_UNITS);
+ ac->Raw.Attrib[index] = ctx->Array.TexCoord[unit];
+ }
+ else {
+ /* missing conventional array (vertex weight, for example) */
+ fallback = GL_TRUE;
+ }
+ if (!fallback)
+ STRIDE_ARRAY(ac->Raw.Attrib[index], ac->start);
+ }
+ else {
+ fallback = GL_TRUE;
+ }
+
+ if (fallback) {
+ /* fallback to ctx->Current.Attrib values */
+ ac->Raw.Attrib[index] = ac->Fallback.Attrib[index];
+
+ if (ctx->Current.Attrib[index][3] != 1.0)
+ ac->Raw.Attrib[index].Size = 4;
+ else if (ctx->Current.Attrib[index][2] != 0.0)
+ ac->Raw.Attrib[index].Size = 3;
+ else
+ ac->Raw.Attrib[index].Size = 2;
+ }
+
+ ac->IsCached.Attrib[index] = GL_FALSE;
+ ac->NewArrayState &= ~_NEW_ARRAY_ATTRIB(index);
+}
+
+/*
+ * Generic import function for color data
+ */
static void import( GLcontext *ctx,
GLenum type,
struct gl_client_array *to,
@@ -236,8 +305,12 @@ static void import( GLcontext *ctx,
-/* Functions to import array ranges with specified types and strides.
+/*
+ * Functions to import array ranges with specified types and strides.
+ * For example, if the vertex data is GLshort[2] and we want GLfloat[3]
+ * we'll use an import function to do the data conversion.
*/
+
static void import_texcoord( GLcontext *ctx, GLuint unit,
GLenum type, GLuint stride )
{
@@ -245,6 +318,8 @@ static void import_texcoord( GLcontext *ctx, GLuint unit,
struct gl_client_array *from = &ac->Raw.TexCoord[unit];
struct gl_client_array *to = &ac->Cache.TexCoord[unit];
+ ASSERT(unit < ctx->Const.MaxTextureUnits);
+
/* Limited choices at this stage:
*/
ASSERT(type == GL_FLOAT);
@@ -315,9 +390,6 @@ static void import_normal( GLcontext *ctx,
ac->IsCached.Normal = GL_TRUE;
}
-
-
-
static void import_color( GLcontext *ctx,
GLenum type, GLuint stride )
{
@@ -414,10 +486,42 @@ static void import_edgeflag( GLcontext *ctx,
ac->IsCached.EdgeFlag = GL_TRUE;
}
+static void import_attrib( GLcontext *ctx, GLuint index,
+ GLenum type, GLuint stride )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ struct gl_client_array *from = &ac->Raw.Attrib[index];
+ struct gl_client_array *to = &ac->Cache.Attrib[index];
+
+ ASSERT(index < VERT_ATTRIB_MAX);
+
+ /* Limited choices at this stage:
+ */
+ ASSERT(type == GL_FLOAT);
+ ASSERT(stride == 4*sizeof(GLfloat) || stride == 0);
+ ASSERT(ac->count - ac->start < ctx->Const.MaxArrayLockSize);
+
+ _math_trans_4f( (GLfloat (*)[4]) to->Ptr,
+ from->Ptr,
+ from->StrideB,
+ from->Type,
+ from->Size,
+ 0,
+ ac->count - ac->start);
+
+ to->Size = from->Size;
+ to->StrideB = 4 * sizeof(GLfloat);
+ to->Type = GL_FLOAT;
+ ac->IsCached.Attrib[index] = GL_TRUE;
+}
+
-/* Externals to request arrays with specific properties:
+/*
+ * Externals to request arrays with specific properties:
*/
+
+
struct gl_client_array *_ac_import_texcoord( GLcontext *ctx,
GLuint unit,
GLenum type,
@@ -428,6 +532,8 @@ struct gl_client_array *_ac_import_texcoord( GLcontext *ctx,
{
ACcontext *ac = AC_CONTEXT(ctx);
+ ASSERT(unit < ctx->Const.MaxTextureUnits);
+
/* Can we keep the existing version?
*/
if (ac->NewArrayState & _NEW_ARRAY_TEXCOORD(unit))
@@ -532,7 +638,7 @@ struct gl_client_array *_ac_import_color( GLcontext *ctx,
/* Can we keep the existing version?
*/
- if (ac->NewArrayState & _NEW_ARRAY_COLOR)
+ if (ac->NewArrayState & _NEW_ARRAY_COLOR0)
reset_color( ctx );
/* Is the request impossible?
@@ -600,7 +706,7 @@ struct gl_client_array *_ac_import_secondarycolor( GLcontext *ctx,
/* Can we keep the existing version?
*/
- if (ac->NewArrayState & _NEW_ARRAY_SECONDARYCOLOR)
+ if (ac->NewArrayState & _NEW_ARRAY_COLOR1)
reset_secondarycolor( ctx );
/* Is the request impossible?
@@ -655,9 +761,6 @@ struct gl_client_array *_ac_import_fogcoord( GLcontext *ctx,
}
}
-
-
-
struct gl_client_array *_ac_import_edgeflag( GLcontext *ctx,
GLenum type,
GLuint reqstride,
@@ -688,8 +791,50 @@ struct gl_client_array *_ac_import_edgeflag( GLcontext *ctx,
}
}
+/* GL_NV_vertex_program */
+struct gl_client_array *_ac_import_attrib( GLcontext *ctx,
+ GLuint index,
+ GLenum type,
+ GLuint reqstride,
+ GLuint reqsize,
+ GLboolean reqwriteable,
+ GLboolean *writeable )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+
+ ASSERT(index < VERT_ATTRIB_MAX);
+
+ /* Can we keep the existing version?
+ */
+ if (ac->NewArrayState & _NEW_ARRAY_ATTRIB(index)) {
+ reset_attrib( ctx, index );
+ }
+ else if (ac->NewArrayState & (1 << index)) {
+ /* Also need to check conventional attributes */
+ reset_attrib( ctx, index );
+ }
+ /* Is the request impossible?
+ */
+ if (reqsize != 0 && ac->Raw.Attrib[index].Size > (GLint) reqsize)
+ return NULL;
+ /* Do we need to pull in a copy of the client data:
+ */
+ if (ac->Raw.Attrib[index].Type != type ||
+ (reqstride != 0 && ac->Raw.Attrib[index].StrideB != (GLint)reqstride) ||
+ reqwriteable)
+ {
+ if (!ac->IsCached.Attrib[index])
+ import_attrib(ctx, index, type, reqstride );
+ *writeable = GL_TRUE;
+ return &ac->Cache.Attrib[index];
+ }
+ else {
+ *writeable = GL_FALSE;
+ return &ac->Raw.Attrib[index];
+ }
+}
/* Clients must call this function to validate state and set bounds
@@ -722,8 +867,8 @@ void _ac_import_range( GLcontext *ctx, GLuint start, GLuint count )
-/* Additional convienence function for importing a the element list
- * for drawelements, drawrangeelements:
+/* Additional convienence function for importing the element list
+ * for glDrawElements() and glDrawRangeElements().
*/
CONST void *
_ac_import_elements( GLcontext *ctx,