blob: 0abe8cc35dd94d39f81ec6643c2d9c917f25dc6a [file] [log] [blame]
Keith Whitwellcab974c2000-12-26 05:09:27 +00001/*
2 * Mesa 3-D graphics library
Michal Krola2ea6062006-02-13 11:23:36 +00003 * Version: 6.5
Keith Whitwellcab974c2000-12-26 05:09:27 +00004 *
Michal Krola2ea6062006-02-13 11:23:36 +00005 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
Keith Whitwellcab974c2000-12-26 05:09:27 +00006 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
Gareth Hughes22144ab2001-03-12 00:48:37 +000024 * Authors:
Brian Paul05a4b372002-10-29 20:28:36 +000025 * Keith Whitwell <keith@tungstengraphics.com>
Keith Whitwellcab974c2000-12-26 05:09:27 +000026 */
27
28
Brian Paulbbd28712008-09-18 12:26:54 -060029#include "main/glheader.h"
30#include "main/colormac.h"
31#include "main/context.h"
32#include "main/macros.h"
33#include "main/imports.h"
34#include "main/mtypes.h"
Keith Whitwellcab974c2000-12-26 05:09:27 +000035
36#include "math/m_xform.h"
37
38#include "t_context.h"
39#include "t_pipeline.h"
40
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
Gareth Hughes22144ab2001-03-12 00:48:37 +000044 * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't.
Keith Whitwellcab974c2000-12-26 05:09:27 +000045 *
46 * However, the seperation of this code from the complex texgen stuff
47 * is very appealing.
48 */
49struct texmat_stage_data {
Brian Paul610d5992003-01-14 04:55:45 +000050 GLvector4f texcoord[MAX_TEXTURE_COORD_UNITS];
Keith Whitwellcab974c2000-12-26 05:09:27 +000051};
52
Brian Paulb51b0a82001-03-07 05:06:11 +000053#define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
Keith Whitwellcab974c2000-12-26 05:09:27 +000054
Keith Whitwellcab974c2000-12-26 05:09:27 +000055
Keith Whitwellcab974c2000-12-26 05:09:27 +000056
Gareth Hughes22144ab2001-03-12 00:48:37 +000057static GLboolean run_texmat_stage( GLcontext *ctx,
Keith Whitwellae0eaf92003-11-24 15:23:18 +000058 struct tnl_pipeline_stage *stage )
Keith Whitwellcab974c2000-12-26 05:09:27 +000059{
60 struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
Gareth Hughes22144ab2001-03-12 00:48:37 +000061 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
Keith Whitwellcab974c2000-12-26 05:09:27 +000062 GLuint i;
63
Briana328e462006-12-13 14:58:13 -070064 if (!ctx->Texture._TexMatEnabled || ctx->VertexProgram._Current)
Keith Whitwell6f973f32005-04-22 12:51:19 +000065 return GL_TRUE;
66
Keith Whitwellcab974c2000-12-26 05:09:27 +000067 /* ENABLE_TEXMAT implies that the texture matrix is not the
68 * identity, so we don't have to check that here.
69 */
Keith Whitwell6f973f32005-04-22 12:51:19 +000070 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) {
Keith Whitwelled39a432001-03-29 21:16:25 +000071 if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i)) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000072 (void) TransformRaw( &store->texcoord[i],
73 ctx->TextureMatrixStack[i].Top,
Brian Paul62e1fae2006-06-14 04:05:17 +000074 VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]);
Keith Whitwellcab974c2000-12-26 05:09:27 +000075
Brian Paul62e1fae2006-06-14 04:05:17 +000076 VB->TexCoordPtr[i] =
77 VB->AttribPtr[VERT_ATTRIB_TEX0+i] = &store->texcoord[i];
Keith Whitwellcab974c2000-12-26 05:09:27 +000078 }
Keith Whitwell6f973f32005-04-22 12:51:19 +000079 }
80
Keith Whitwellcab974c2000-12-26 05:09:27 +000081 return GL_TRUE;
82}
83
84
85/* Called the first time stage->run() is invoked.
86 */
Gareth Hughes22144ab2001-03-12 00:48:37 +000087static GLboolean alloc_texmat_data( GLcontext *ctx,
Keith Whitwellae0eaf92003-11-24 15:23:18 +000088 struct tnl_pipeline_stage *stage )
Keith Whitwellcab974c2000-12-26 05:09:27 +000089{
Gareth Hughes22144ab2001-03-12 00:48:37 +000090 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
Keith Whitwellcab974c2000-12-26 05:09:27 +000091 struct texmat_stage_data *store;
92 GLuint i;
93
Brian Paulb51b0a82001-03-07 05:06:11 +000094 stage->privatePtr = CALLOC(sizeof(*store));
Keith Whitwellcab974c2000-12-26 05:09:27 +000095 store = TEXMAT_STAGE_DATA(stage);
96 if (!store)
97 return GL_FALSE;
98
Brian Paul92f97852003-05-01 22:44:02 +000099 for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++)
Brian Paul08836342001-03-03 20:33:27 +0000100 _mesa_vector4f_alloc( &store->texcoord[i], 0, VB->Size, 32 );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000101
Keith Whitwell6f973f32005-04-22 12:51:19 +0000102 return GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000103}
104
105
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000106static void free_texmat_data( struct tnl_pipeline_stage *stage )
Keith Whitwellcab974c2000-12-26 05:09:27 +0000107{
108 struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
109 GLuint i;
110
111 if (store) {
Brian Paul610d5992003-01-14 04:55:45 +0000112 for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +0000113 if (store->texcoord[i].data)
Brian Paul08836342001-03-03 20:33:27 +0000114 _mesa_vector4f_free( &store->texcoord[i] );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000115 FREE( store );
Keith Whitwellb97e4782005-02-10 10:57:22 +0000116 stage->privatePtr = NULL;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000117 }
118}
Keith Whitwellcab974c2000-12-26 05:09:27 +0000119
120
Gareth Hughes22144ab2001-03-12 00:48:37 +0000121
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000122const struct tnl_pipeline_stage _tnl_texture_transform_stage =
Gareth Hughes22144ab2001-03-12 00:48:37 +0000123{
Brian Paul86b84272001-12-14 02:50:01 +0000124 "texture transform", /* name */
Brian Paul86b84272001-12-14 02:50:01 +0000125 NULL, /* private data */
Keith Whitwell6f973f32005-04-22 12:51:19 +0000126 alloc_texmat_data,
Brian Paul86b84272001-12-14 02:50:01 +0000127 free_texmat_data, /* destructor */
Keith Whitwell6f973f32005-04-22 12:51:19 +0000128 NULL,
129 run_texmat_stage,
Keith Whitwellcab974c2000-12-26 05:09:27 +0000130};