Subversion Repositories shark

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 pj 1
/* $Id: t_vb_texmat.c,v 1.1 2003-02-28 11:48:08 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 *
26
 * Authors:
27
 *    Keith Whitwell <keith@tungstengraphics.com>
28
 */
29
 
30
 
31
#include "glheader.h"
32
#include "colormac.h"
33
#include "context.h"
34
#include "macros.h"
35
#include "imports.h"
36
#include "mmath.h"
37
#include "mtypes.h"
38
 
39
#include "math/m_xform.h"
40
 
41
#include "t_context.h"
42
#include "t_pipeline.h"
43
 
44
/* Is there any real benefit seperating texmat from texgen?  It means
45
 * we need two lots of intermediate storage.  Any changes to
46
 * _NEW_TEXTURE will invalidate both sets -- it's only on changes to
47
 * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't.
48
 *
49
 * However, the seperation of this code from the complex texgen stuff
50
 * is very appealing.
51
 */
52
struct texmat_stage_data {
53
   GLvector4f texcoord[MAX_TEXTURE_UNITS];
54
};
55
 
56
#define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
57
 
58
static void check_texmat( GLcontext *ctx, struct gl_pipeline_stage *stage )
59
{
60
   GLuint i;
61
   stage->active = 0;
62
 
63
   if (ctx->Texture._TexMatEnabled && !ctx->VertexProgram.Enabled) {
64
      GLuint flags = 0;
65
 
66
      for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
67
         if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i))
68
            flags |= VERT_BIT_TEX(i);
69
 
70
      stage->active = 1;
71
      stage->inputs = flags;
72
      stage->outputs = flags;
73
   }
74
}
75
 
76
static GLboolean run_texmat_stage( GLcontext *ctx,
77
                                   struct gl_pipeline_stage *stage )
78
{
79
   struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
80
   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
81
   GLuint i;
82
 
83
   /* ENABLE_TEXMAT implies that the texture matrix is not the
84
    * identity, so we don't have to check that here.
85
    */
86
   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
87
      if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i)) {
88
         if (stage->changed_inputs & VERT_BIT_TEX(i))
89
            (void) TransformRaw( &store->texcoord[i],
90
                                 ctx->TextureMatrixStack[i].Top,
91
                                 VB->TexCoordPtr[i]);
92
 
93
         VB->TexCoordPtr[i] = &store->texcoord[i];
94
      }
95
   return GL_TRUE;
96
}
97
 
98
 
99
/* Called the first time stage->run() is invoked.
100
 */
101
static GLboolean alloc_texmat_data( GLcontext *ctx,
102
                                    struct gl_pipeline_stage *stage )
103
{
104
   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
105
   struct texmat_stage_data *store;
106
   GLuint i;
107
 
108
   stage->privatePtr = CALLOC(sizeof(*store));
109
   store = TEXMAT_STAGE_DATA(stage);
110
   if (!store)
111
      return GL_FALSE;
112
 
113
   for (i = 0 ; i < ctx->Const.MaxTextureUnits ; i++)
114
      _mesa_vector4f_alloc( &store->texcoord[i], 0, VB->Size, 32 );
115
 
116
   /* Now run the stage.
117
    */
118
   stage->run = run_texmat_stage;
119
   return stage->run( ctx, stage );
120
}
121
 
122
 
123
static void free_texmat_data( struct gl_pipeline_stage *stage )
124
{
125
   struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
126
   GLuint i;
127
 
128
   if (store) {
129
      for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
130
         if (store->texcoord[i].data)
131
            _mesa_vector4f_free( &store->texcoord[i] );
132
      FREE( store );
133
      stage->privatePtr = 0;
134
   }
135
}
136
 
137
 
138
 
139
const struct gl_pipeline_stage _tnl_texture_transform_stage =
140
{
141
   "texture transform",                 /* name */
142
   _NEW_TEXTURE|_NEW_TEXTURE_MATRIX,    /* check_state */
143
   _NEW_TEXTURE|_NEW_TEXTURE_MATRIX,    /* run_state */
144
   GL_FALSE,                            /* active? */
145
   0,                                   /* inputs */
146
   0,                                   /* outputs */
147
   0,                                   /* changed_inputs */
148
   NULL,                                /* private data */
149
   free_texmat_data,                    /* destructor */
150
   check_texmat,                        /* check */
151
   alloc_texmat_data,                   /* run -- initially set to init */
152
};