2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "math/m_xform.h"
38 #include "t_context.h"
39 #include "t_pipeline.h"
41 /* Is there any real benefit seperating texmat from texgen? It means
42 * we need two lots of intermediate storage. Any changes to
43 * _NEW_TEXTURE will invalidate both sets -- it's only on changes to
44 * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't.
46 * However, the seperation of this code from the complex texgen stuff
49 struct texmat_stage_data
{
50 GLvector4f texcoord
[MAX_TEXTURE_COORD_UNITS
];
53 #define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
55 static void check_texmat( GLcontext
*ctx
, struct tnl_pipeline_stage
*stage
)
60 if (ctx
->Texture
._TexMatEnabled
&& !ctx
->VertexProgram
.Enabled
) {
63 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
64 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
))
65 flags
|= _TNL_BIT_TEX(i
);
68 stage
->inputs
= flags
;
69 stage
->outputs
= flags
;
73 static GLboolean
run_texmat_stage( GLcontext
*ctx
,
74 struct tnl_pipeline_stage
*stage
)
76 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
77 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
80 /* ENABLE_TEXMAT implies that the texture matrix is not the
81 * identity, so we don't have to check that here.
83 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
84 if (ctx
->Texture
._TexMatEnabled
& ENABLE_TEXMAT(i
)) {
85 if (stage
->changed_inputs
& _TNL_BIT_TEX(i
))
86 (void) TransformRaw( &store
->texcoord
[i
],
87 ctx
->TextureMatrixStack
[i
].Top
,
90 VB
->TexCoordPtr
[i
] = &store
->texcoord
[i
];
96 /* Called the first time stage->run() is invoked.
98 static GLboolean
alloc_texmat_data( GLcontext
*ctx
,
99 struct tnl_pipeline_stage
*stage
)
101 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
102 struct texmat_stage_data
*store
;
105 stage
->privatePtr
= CALLOC(sizeof(*store
));
106 store
= TEXMAT_STAGE_DATA(stage
);
110 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
111 _mesa_vector4f_alloc( &store
->texcoord
[i
], 0, VB
->Size
, 32 );
113 /* Now run the stage.
115 stage
->run
= run_texmat_stage
;
116 return stage
->run( ctx
, stage
);
120 static void free_texmat_data( struct tnl_pipeline_stage
*stage
)
122 struct texmat_stage_data
*store
= TEXMAT_STAGE_DATA(stage
);
126 for (i
= 0; i
< MAX_TEXTURE_COORD_UNITS
; i
++)
127 if (store
->texcoord
[i
].data
)
128 _mesa_vector4f_free( &store
->texcoord
[i
] );
130 stage
->privatePtr
= 0;
136 const struct tnl_pipeline_stage _tnl_texture_transform_stage
=
138 "texture transform", /* name */
139 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* check_state */
140 _NEW_TEXTURE
|_NEW_TEXTURE_MATRIX
, /* run_state */
141 GL_FALSE
, /* active? */
144 0, /* changed_inputs */
145 NULL
, /* private data */
146 free_texmat_data
, /* destructor */
147 check_texmat
, /* check */
148 alloc_texmat_data
, /* run -- initially set to init */