1 /* $Id: s_pixeltex.c,v 1.11 2002/10/24 23:57:24 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This file implements both the GL_SGIX_pixel_texture and
30 * GL_SIGS_pixel_texture extensions. Luckily, they pretty much
31 * overlap in functionality so we use the same state variables
32 * and execution code for both.
40 #include "s_context.h"
41 #include "s_pixeltex.h"
42 #include "s_texture.h"
46 * Convert RGBA values into strq texture coordinates.
49 pixeltexgen(GLcontext
*ctx
, GLuint n
, const GLchan rgba
[][4],
50 GLfloat texcoord
[][4])
52 if (ctx
->Pixel
.FragmentRgbSource
== GL_CURRENT_RASTER_COLOR
) {
54 for (i
= 0; i
< n
; i
++) {
55 texcoord
[i
][0] = ctx
->Current
.RasterColor
[RCOMP
];
56 texcoord
[i
][1] = ctx
->Current
.RasterColor
[GCOMP
];
57 texcoord
[i
][2] = ctx
->Current
.RasterColor
[BCOMP
];
62 ASSERT(ctx
->Pixel
.FragmentRgbSource
== GL_PIXEL_GROUP_COLOR_SGIS
);
63 for (i
= 0; i
< n
; i
++) {
64 texcoord
[i
][0] = CHAN_TO_FLOAT(rgba
[i
][RCOMP
]);
65 texcoord
[i
][1] = CHAN_TO_FLOAT(rgba
[i
][GCOMP
]);
66 texcoord
[i
][2] = CHAN_TO_FLOAT(rgba
[i
][BCOMP
]);
70 if (ctx
->Pixel
.FragmentAlphaSource
== GL_CURRENT_RASTER_COLOR
) {
72 for (i
= 0; i
< n
; i
++) {
73 texcoord
[i
][3] = ctx
->Current
.RasterColor
[ACOMP
];
78 ASSERT(ctx
->Pixel
.FragmentAlphaSource
== GL_PIXEL_GROUP_COLOR_SGIS
);
79 for (i
= 0; i
< n
; i
++) {
80 texcoord
[i
][3] = CHAN_TO_FLOAT(rgba
[i
][ACOMP
]);
88 * Used by glDraw/CopyPixels: the incoming image colors are treated
89 * as texture coordinates. Use those coords to texture the image.
90 * This is for GL_SGIS_pixel_texture / GL_SGIX_pixel_texture.
93 _swrast_pixel_texture(GLcontext
*ctx
, struct sw_span
*span
)
97 ASSERT(!(span
->arrayMask
& SPAN_TEXTURE
));
98 span
->arrayMask
|= SPAN_TEXTURE
;
100 /* convert colors into texture coordinates */
101 pixeltexgen( ctx
, span
->end
,
102 (const GLchan (*)[4]) span
->array
->rgba
,
103 span
->array
->texcoords
[0] );
105 /* copy the new texture units for all enabled units */
106 for (unit
= 1; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
107 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
108 MEMCPY( span
->array
->texcoords
[unit
], span
->array
->texcoords
[0],
109 span
->end
* 4 * sizeof(GLfloat
) );
113 /* apply texture mapping */
114 _swrast_texture_span( ctx
, span
);
116 /* this is a work-around to be fixed by initializing again span */
117 span
->arrayMask
&= ~SPAN_TEXTURE
;