[MESA]
[reactos.git] / reactos / dll / opengl / mesa / src / mesa / tnl / t_vb_texmat.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2006 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 <keith@tungstengraphics.com>
26 */
27
28
29 #include "main/glheader.h"
30 #include "main/colormac.h"
31 #include "main/macros.h"
32 #include "main/imports.h"
33 #include "main/mtypes.h"
34
35 #include "math/m_xform.h"
36
37 #include "t_context.h"
38 #include "t_pipeline.h"
39
40 /* Is there any real benefit seperating texmat from texgen? It means
41 * we need two lots of intermediate storage. Any changes to
42 * _NEW_TEXTURE will invalidate both sets -- it's only on changes to
43 * *only* _NEW_TEXTURE_MATRIX that texgen survives but texmat doesn't.
44 *
45 * However, the seperation of this code from the complex texgen stuff
46 * is very appealing.
47 */
48 struct texmat_stage_data {
49 GLvector4f texcoord;
50 };
51
52 #define TEXMAT_STAGE_DATA(stage) ((struct texmat_stage_data *)stage->privatePtr)
53
54
55
56 static GLboolean run_texmat_stage( struct gl_context *ctx,
57 struct tnl_pipeline_stage *stage )
58 {
59 struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
60 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
61
62 if (!ctx->Texture._TexMatEnabled)
63 return GL_TRUE;
64
65 /* ENABLE_TEXMAT implies that the texture matrix is not the
66 * identity, so we don't have to check that here.
67 */
68 if (ctx->Texture._TexMatEnabled) {
69 (void) TransformRaw( &store->texcoord,
70 ctx->TextureMatrixStack.Top,
71 VB->AttribPtr[_TNL_ATTRIB_TEX]);
72
73 VB->AttribPtr[VERT_ATTRIB_TEX] = &store->texcoord;
74 }
75
76 return GL_TRUE;
77 }
78
79
80 /* Called the first time stage->run() is invoked.
81 */
82 static GLboolean alloc_texmat_data( struct gl_context *ctx,
83 struct tnl_pipeline_stage *stage )
84 {
85 struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
86 struct texmat_stage_data *store;
87
88 stage->privatePtr = CALLOC(sizeof(*store));
89 store = TEXMAT_STAGE_DATA(stage);
90 if (!store)
91 return GL_FALSE;
92
93 _mesa_vector4f_alloc( &store->texcoord, 0, VB->Size, 32 );
94
95 return GL_TRUE;
96 }
97
98
99 static void free_texmat_data( struct tnl_pipeline_stage *stage )
100 {
101 struct texmat_stage_data *store = TEXMAT_STAGE_DATA(stage);
102
103 if (store) {
104 if (store->texcoord.data)
105 _mesa_vector4f_free( &store->texcoord );
106 FREE( store );
107 stage->privatePtr = NULL;
108 }
109 }
110
111
112
113 const struct tnl_pipeline_stage _tnl_texture_transform_stage =
114 {
115 "texture transform", /* name */
116 NULL, /* private data */
117 alloc_texmat_data,
118 free_texmat_data, /* destructor */
119 NULL,
120 run_texmat_stage,
121 };