| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.1 |
| 4 |
* |
| 5 |
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved. |
| 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 |
* |
| 24 |
* Authors: |
| 25 |
* Keith Whitwell <[email protected]> |
| 26 |
*/ |
| 27 |
|
| 28 |
|
| 29 |
#include "glheader.h" |
| 30 |
#include "colormac.h" |
| 31 |
#include "context.h" |
| 32 |
#include "macros.h" |
| 33 |
#include "imports.h" |
| 34 |
#include "mtypes.h" |
| 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 |
| 44 |
* *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't. |
| 45 |
* |
| 46 |
* However, the seperation of this code from the complex texgen stuff |
| 47 |
* is very appealing. |
| 48 |
*/ |
| 49 |
struct texmat_stage_data { |
| 50 |
GLvector4f texcoord[MAX_TEXTURE_COORD_UNITS]; |
| 51 |
}; |
| 52 |
|
| 53 |
#define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr) |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
static GLboolean run_texmat_stage( GLcontext *ctx, |
| 58 |
struct tnl_pipeline_stage *stage ) |
| 59 |
{ |
| 60 |
struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage); |
| 61 |
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 62 |
GLuint i; |
| 63 |
|
| 64 |
if (!ctx->Texture._TexMatEnabled || ctx->VertexProgram._Enabled) |
| 65 |
return GL_TRUE; |
| 66 |
|
| 67 |
/* ENABLE_TEXMAT implies that the texture matrix is not the |
| 68 |
* identity, so we don't have to check that here. |
| 69 |
*/ |
| 70 |
for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) { |
| 71 |
if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i)) { |
| 72 |
(void) TransformRaw( &store->texcoord[i], |
| 73 |
ctx->TextureMatrixStack[i].Top, |
| 74 |
VB->TexCoordPtr[i]); |
| 75 |
|
| 76 |
VB->AttribPtr[VERT_ATTRIB_TEX0+i] = |
| 77 |
VB->TexCoordPtr[i] = &store->texcoord[i]; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return GL_TRUE; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
/* Called the first time stage->run() is invoked. |
| 86 |
*/ |
| 87 |
static GLboolean alloc_texmat_data( GLcontext *ctx, |
| 88 |
struct tnl_pipeline_stage *stage ) |
| 89 |
{ |
| 90 |
struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
| 91 |
struct texmat_stage_data *store; |
| 92 |
GLuint i; |
| 93 |
|
| 94 |
stage->privatePtr = CALLOC(sizeof(*store)); |
| 95 |
store = TEXMAT_STAGE_DATA(stage); |
| 96 |
if (!store) |
| 97 |
return GL_FALSE; |
| 98 |
|
| 99 |
for (i = 0 ; i < ctx->Const.MaxTextureCoordUnits ; i++) |
| 100 |
_mesa_vector4f_alloc( &store->texcoord[i], 0, VB->Size, 32 ); |
| 101 |
|
| 102 |
return GL_TRUE; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
static void free_texmat_data( struct tnl_pipeline_stage *stage ) |
| 107 |
{ |
| 108 |
struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage); |
| 109 |
GLuint i; |
| 110 |
|
| 111 |
if (store) { |
| 112 |
for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) |
| 113 |
if (store->texcoord[i].data) |
| 114 |
_mesa_vector4f_free( &store->texcoord[i] ); |
| 115 |
FREE( store ); |
| 116 |
stage->privatePtr = NULL; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
const struct tnl_pipeline_stage _tnl_texture_transform_stage = |
| 123 |
{ |
| 124 |
"texture transform", /* name */ |
| 125 |
NULL, /* private data */ |
| 126 |
alloc_texmat_data, |
| 127 |
free_texmat_data, /* destructor */ |
| 128 |
NULL, |
| 129 |
run_texmat_stage, |
| 130 |
}; |