Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Michal Krol | a2ea606 | 2006-02-13 11:23:36 +0000 | [diff] [blame] | 3 | * Version: 6.5 |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 4 | * |
Michal Krol | a2ea606 | 2006-02-13 11:23:36 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 6 | * |
| 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 Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 24 | * Authors: |
Brian Paul | 05a4b37 | 2002-10-29 20:28:36 +0000 | [diff] [blame] | 25 | * Keith Whitwell <keith@tungstengraphics.com> |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | |
Brian Paul | bbd2871 | 2008-09-18 12:26:54 -0600 | [diff] [blame] | 29 | #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 Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 35 | |
| 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 Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 44 | * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't. |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 45 | * |
| 46 | * However, the seperation of this code from the complex texgen stuff |
| 47 | * is very appealing. |
| 48 | */ |
| 49 | struct texmat_stage_data { |
Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 50 | GLvector4f texcoord[MAX_TEXTURE_COORD_UNITS]; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 53 | #define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 54 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 55 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 56 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 57 | static GLboolean run_texmat_stage( GLcontext *ctx, |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 58 | struct tnl_pipeline_stage *stage ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 59 | { |
| 60 | struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage); |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 61 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 62 | GLuint i; |
| 63 | |
Brian | a328e46 | 2006-12-13 14:58:13 -0700 | [diff] [blame] | 64 | if (!ctx->Texture._TexMatEnabled || ctx->VertexProgram._Current) |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 65 | return GL_TRUE; |
| 66 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 67 | /* ENABLE_TEXMAT implies that the texture matrix is not the |
| 68 | * identity, so we don't have to check that here. |
| 69 | */ |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 70 | for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) { |
Keith Whitwell | ed39a43 | 2001-03-29 21:16:25 +0000 | [diff] [blame] | 71 | if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i)) { |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 72 | (void) TransformRaw( &store->texcoord[i], |
| 73 | ctx->TextureMatrixStack[i].Top, |
Brian Paul | 62e1fae | 2006-06-14 04:05:17 +0000 | [diff] [blame] | 74 | VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 75 | |
Brian Paul | 62e1fae | 2006-06-14 04:05:17 +0000 | [diff] [blame] | 76 | VB->TexCoordPtr[i] = |
| 77 | VB->AttribPtr[VERT_ATTRIB_TEX0+i] = &store->texcoord[i]; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 78 | } |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 81 | return GL_TRUE; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /* Called the first time stage->run() is invoked. |
| 86 | */ |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 87 | static GLboolean alloc_texmat_data( GLcontext *ctx, |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 88 | struct tnl_pipeline_stage *stage ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 89 | { |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 90 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 91 | struct texmat_stage_data *store; |
| 92 | GLuint i; |
| 93 | |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 94 | stage->privatePtr = CALLOC(sizeof(*store)); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 95 | store = TEXMAT_STAGE_DATA(stage); |
| 96 | if (!store) |
| 97 | return GL_FALSE; |
| 98 | |
Brian Paul | 92f9785 | 2003-05-01 22:44:02 +0000 | [diff] [blame] | 99 | for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 100 | _mesa_vector4f_alloc( &store->texcoord[i], 0, VB->Size, 32 ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 101 | |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 102 | return GL_TRUE; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 106 | static void free_texmat_data( struct tnl_pipeline_stage *stage ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 107 | { |
| 108 | struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage); |
| 109 | GLuint i; |
| 110 | |
| 111 | if (store) { |
Brian Paul | 610d599 | 2003-01-14 04:55:45 +0000 | [diff] [blame] | 112 | for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 113 | if (store->texcoord[i].data) |
Brian Paul | 0883634 | 2001-03-03 20:33:27 +0000 | [diff] [blame] | 114 | _mesa_vector4f_free( &store->texcoord[i] ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 115 | FREE( store ); |
Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame] | 116 | stage->privatePtr = NULL; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 119 | |
| 120 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 121 | |
Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 122 | const struct tnl_pipeline_stage _tnl_texture_transform_stage = |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 123 | { |
Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 124 | "texture transform", /* name */ |
Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 125 | NULL, /* private data */ |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 126 | alloc_texmat_data, |
Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 127 | free_texmat_data, /* destructor */ |
Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 128 | NULL, |
| 129 | run_texmat_stage, |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 130 | }; |