summaryrefslogtreecommitdiff
path: root/src/mesa/array_cache/ac_context.c
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2000-12-26 15:14:04 +0000
committerKeith Whitwell <keith@tungstengraphics.com>2000-12-26 15:14:04 +0000
commit770169f230a197d969f64df76cfaee1f0e27874f (patch)
tree0cab3b1c582edb1ffcb2df2bb6443f6578ba87dd /src/mesa/array_cache/ac_context.c
parent9ef50d5826c92aa7c9dd19702f18b0dfec59f03c (diff)
The array cache.
Diffstat (limited to 'src/mesa/array_cache/ac_context.c')
-rw-r--r--src/mesa/array_cache/ac_context.c257
1 files changed, 257 insertions, 0 deletions
diff --git a/src/mesa/array_cache/ac_context.c b/src/mesa/array_cache/ac_context.c
new file mode 100644
index 0000000000..f3609ebe8c
--- /dev/null
+++ b/src/mesa/array_cache/ac_context.c
@@ -0,0 +1,257 @@
+/* $Id: ac_context.c,v 1.1 2000/12/26 15:14:04 keithw Exp $ */
+
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.5
+ *
+ * Copyright (C) 1999 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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Author:
+ * Keith Whitwell <keithw@valinux.com>
+ */
+
+#include "glheader.h"
+#include "macros.h"
+#include "mem.h"
+#include "mmath.h"
+#include "mtypes.h"
+
+#include "array_cache/ac_context.h"
+
+static void _ac_fallbacks_init( GLcontext *ctx )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ struct gl_client_array *cl;
+ GLuint i;
+
+ cl = &ac->Fallback.Normal;
+ cl->Size = 3;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) ctx->Current.Normal;
+ cl->Enabled = 1;
+
+ cl = &ac->Fallback.Color;
+ cl->Size = 4;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) ctx->Current.Color;
+ cl->Enabled = 1;
+
+ cl = &ac->Fallback.SecondaryColor;
+ cl->Size = 3;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) ctx->Current.SecondaryColor;
+ cl->Enabled = 1;
+
+ cl = &ac->Fallback.FogCoord;
+ cl->Size = 1;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) &ctx->Current.FogCoord;
+ cl->Enabled = 1;
+
+ cl = &ac->Fallback.Index;
+ cl->Size = 1;
+ cl->Type = GL_UNSIGNED_INT;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) &ctx->Current.Index;
+ cl->Enabled = 1;
+
+ for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
+ cl = &ac->Fallback.TexCoord[i];
+ cl->Size = 4;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) ctx->Current.Texcoord[i];
+ cl->Enabled = 1;
+ }
+
+ cl = &ac->Fallback.EdgeFlag;
+ cl->Size = 1;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = 0;
+ cl->Ptr = (void *) &ctx->Current.EdgeFlag;
+ cl->Enabled = 1;
+}
+
+
+static void _ac_cache_init( GLcontext *ctx )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ struct gl_client_array *cl;
+ GLuint size = ctx->Const.MaxArrayLockSize + MAX_CLIPPED_VERTICES;
+ GLuint i;
+
+ cl = &ac->Cache.Vertex;
+ cl->Size = 4;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 4 * sizeof(GLfloat);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ cl = &ac->Cache.Normal;
+ cl->Size = 3;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 3 * sizeof(GLfloat);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ cl = &ac->Cache.Color;
+ cl->Size = 4;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = 4 * sizeof(GLubyte);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ cl = &ac->Cache.SecondaryColor;
+ cl->Size = 3;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = 4 * sizeof(GLubyte);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ cl = &ac->Cache.FogCoord;
+ cl->Size = 1;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = sizeof(GLfloat);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ cl = &ac->Cache.Index;
+ cl->Size = 1;
+ cl->Type = GL_UNSIGNED_INT;
+ cl->Stride = 0;
+ cl->StrideB = sizeof(GLuint);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+
+ for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
+ cl = &ac->Cache.TexCoord[i];
+ cl->Size = 4;
+ cl->Type = GL_FLOAT;
+ cl->Stride = 0;
+ cl->StrideB = 4 * sizeof(GLfloat);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+ }
+
+ cl = &ac->Cache.EdgeFlag;
+ cl->Size = 1;
+ cl->Type = GL_UNSIGNED_BYTE;
+ cl->Stride = 0;
+ cl->StrideB = sizeof(GLubyte);
+ cl->Ptr = MALLOC( cl->StrideB * size );
+ cl->Enabled = 1;
+}
+
+
+/* This storage used to hold translated client data if type or stride
+ * need to be fixed.
+ */
+static void _ac_elts_init( GLcontext *ctx )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ GLuint size = 1000;
+
+ ac->Elts = (GLuint *)MALLOC( sizeof(GLuint) * size );
+ ac->elt_size = size;
+}
+
+static void _ac_current_init( GLcontext *ctx )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ GLuint i;
+
+ ac->Current.Color = &ac->Fallback.Color;
+ ac->Current.EdgeFlag = &ac->Fallback.EdgeFlag;
+ ac->Current.FogCoord = &ac->Fallback.FogCoord;
+ ac->Current.Index = &ac->Fallback.Index;
+ ac->Current.Normal = &ac->Fallback.Normal;
+ ac->Current.SecondaryColor = &ac->Fallback.SecondaryColor;
+ ac->Current.Vertex = &ctx->Array.Vertex;
+
+ ac->Writeable.Color = GL_FALSE;
+ ac->Writeable.EdgeFlag = GL_FALSE;
+ ac->Writeable.FogCoord = GL_FALSE;
+ ac->Writeable.Index = GL_FALSE;
+ ac->Writeable.Normal = GL_FALSE;
+ ac->Writeable.SecondaryColor = GL_FALSE;
+ ac->Writeable.Vertex = GL_FALSE;
+
+ for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
+ ac->Current.TexCoord[i] = &ac->Fallback.TexCoord[i];
+ ac->Writeable.TexCoord[i] = GL_FALSE;
+ }
+
+}
+
+GLboolean _ac_CreateContext( GLcontext *ctx )
+{
+ ctx->acache_context = CALLOC(sizeof(ACcontext));
+ if (ctx->acache_context) {
+ _ac_cache_init( ctx );
+ _ac_fallbacks_init( ctx );
+ _ac_current_init( ctx );
+ _ac_elts_init( ctx );
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+void _ac_DestroyContext( GLcontext *ctx )
+{
+ ACcontext *ac = AC_CONTEXT(ctx);
+ GLint i;
+
+ if (ac->Cache.Vertex.Ptr) FREE( ac->Cache.Vertex.Ptr );
+ if (ac->Cache.Normal.Ptr) FREE( ac->Cache.Normal.Ptr );
+ if (ac->Cache.Color.Ptr) FREE( ac->Cache.Color.Ptr );
+ if (ac->Cache.SecondaryColor.Ptr) FREE( ac->Cache.SecondaryColor.Ptr );
+ if (ac->Cache.EdgeFlag.Ptr) FREE( ac->Cache.EdgeFlag.Ptr );
+ if (ac->Cache.Index.Ptr) FREE( ac->Cache.Index.Ptr );
+ if (ac->Cache.FogCoord.Ptr) FREE( ac->Cache.FogCoord.Ptr );
+
+ for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
+ if (ac->Cache.TexCoord[i].Ptr)
+ FREE( ac->Cache.TexCoord[i].Ptr );
+ }
+
+ if (ac->Elts) FREE( ac->Elts );
+}
+
+void _ac_InvalidateState( GLcontext *ctx, GLuint new_state )
+{
+ AC_CONTEXT(ctx)->NewState |= new_state;
+ AC_CONTEXT(ctx)->NewArrayState |= ctx->Array.NewState;
+}