1 /* $Id: t_vb_texmat.c,v 1.9 2002/10/24 23:57:25 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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 <keithw@valinux.com>
39 #include "math/m_xform.h"
41 #include "t_context.h"
42 #include "t_pipeline.h"
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.
49 * However, the seperation of this code from the complex texgen stuff
52 struct texmat_stage_data
{
53 GLvector4f texcoord
[MAX_TEXTURE_UNITS
];
56 #define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
58 static void check_texmat( GLcontext
*ctx
, struct gl_pipeline_stage
*stage
)
63 if (ctx
->Texture
._TexMatEnabled
&& !ctx
->VertexProgram
.Enabled
) {
66 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
67 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
))
68 flags
|= VERT_BIT_TEX(i
);
71 stage
->inputs
= flags
;
72 stage
->outputs
= flags
;
76 static GLboolean
run_texmat_stage( GLcontext
*ctx
,
77 struct gl_pipeline_stage
*stage
)
79 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
80 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
83 /* ENABLE_TEXMAT implies that the texture matrix is not the
84 * identity, so we don't have to check that here.
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
,
93 VB
->TexCoordPtr
[i
] = &store
->texcoord
[i
];
99 /* Called the first time stage->run() is invoked.
101 static GLboolean
alloc_texmat_data( GLcontext
*ctx
,
102 struct gl_pipeline_stage
*stage
)
104 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
105 struct texmat_stage_data
*store
;
108 stage
->privatePtr
= CALLOC(sizeof(*store
));
109 store
= TEXMAT_STAGE_DATA(stage
);
113 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
114 _mesa_vector4f_alloc( &store
->texcoord
[i
], 0, VB
->Size
, 32 );
116 /* Now run the stage.
118 stage
->run
= run_texmat_stage
;
119 return stage
->run( ctx
, stage
);
123 static void free_texmat_data( struct gl_pipeline_stage
*stage
)
125 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
129 for (i
= 0 ; i
< MAX_TEXTURE_UNITS
; i
++)
130 if (store
->texcoord
[i
].data
)
131 _mesa_vector4f_free( &store
->texcoord
[i
] );
133 stage
->privatePtr
= 0;
139 const struct gl_pipeline_stage _tnl_texture_transform_stage
=
141 "texture transform", /* name */
142 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* check_state */
143 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* run_state */
144 GL_FALSE
, /* active? */
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 */