1 /* $Id: t_vb_texmat.c,v 1.12 2003/03/01 01:50:28 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "math/m_xform.h"
40 #include "t_context.h"
41 #include "t_pipeline.h"
43 /* Is there any real benefit seperating texmat from texgen? It means
44 * we need two lots of intermediate storage. Any changes to
45 * _NEW_TEXTURE will invalidate both sets -- it's only on changes to
46 * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't.
48 * However, the seperation of this code from the complex texgen stuff
51 struct texmat_stage_data
{
52 GLvector4f texcoord
[MAX_TEXTURE_COORD_UNITS
];
55 #define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
57 static void check_texmat( GLcontext
*ctx
, struct gl_pipeline_stage
*stage
)
62 if (ctx
->Texture
._TexMatEnabled
&& !ctx
->VertexProgram
.Enabled
) {
65 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
66 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
))
67 flags
|= VERT_BIT_TEX(i
);
70 stage
->inputs
= flags
;
71 stage
->outputs
= flags
;
75 static GLboolean
run_texmat_stage( GLcontext
*ctx
,
76 struct gl_pipeline_stage
*stage
)
78 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
79 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
82 /* ENABLE_TEXMAT implies that the texture matrix is not the
83 * identity, so we don't have to check that here.
85 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
86 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
)) {
87 if (stage
->changed_inputs
& VERT_BIT_TEX(i
))
88 (void) TransformRaw( &store
->texcoord
[i
],
89 ctx
->TextureMatrixStack
[i
].Top
,
92 VB
->TexCoordPtr
[i
] = &store
->texcoord
[i
];
98 /* Called the first time stage->run() is invoked.
100 static GLboolean
alloc_texmat_data( GLcontext
*ctx
,
101 struct gl_pipeline_stage
*stage
)
103 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
104 struct texmat_stage_data
*store
;
107 stage
->privatePtr
= CALLOC(sizeof(*store
));
108 store
= TEXMAT_STAGE_DATA(stage
);
112 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
113 _mesa_vector4f_alloc( &store
->texcoord
[i
], 0, VB
->Size
, 32 );
115 /* Now run the stage.
117 stage
->run
= run_texmat_stage
;
118 return stage
->run( ctx
, stage
);
122 static void free_texmat_data( struct gl_pipeline_stage
*stage
)
124 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
128 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
129 if (store
->texcoord
[i
].data
)
130 _mesa_vector4f_free( &store
->texcoord
[i
] );
132 stage
->privatePtr
= 0;
138 const struct gl_pipeline_stage _tnl_texture_transform_stage
=
140 "texture transform", /* name */
141 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* check_state */
142 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* run_state */
143 GL_FALSE
, /* active? */
146 0, /* changed_inputs */
147 NULL
, /* private data */
148 free_texmat_data
, /* destructor */
149 check_texmat
, /* check */
150 alloc_texmat_data
, /* run -- initially set to init */