1 /* $Id: s_pixeltex.c,v 1.7 2002/04/04 16:53:59 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 byglDraw/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
)
95 if (ctx
->Texture
._ReallyEnabled
& ~TEXTURE0_ANY
) {
97 GLchan primary_rgba
[MAX_WIDTH
][4];
100 MEMCPY(primary_rgba
, span
->color
.rgba
, 4 * span
->end
* sizeof(GLchan
));
102 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
103 if (ctx
->Texture
.Unit
[unit
]._ReallyEnabled
) {
104 pixeltexgen(ctx
, span
->end
,
105 (const GLchan (*)[4]) span
->color
.rgba
,
106 span
->texcoords
[unit
]);
107 _swrast_texture_fragments(ctx
, unit
, span
->end
,
108 span
->texcoords
[unit
],
110 (CONST
GLchan (*)[4]) primary_rgba
,
116 /* single texture, unit 0 */
117 ASSERT(ctx
->Texture
._ReallyEnabled
& TEXTURE0_ANY
);
118 pixeltexgen(ctx
, span
->end
,
119 (const GLchan (*)[4]) span
->color
.rgba
,
121 _swrast_texture_fragments(ctx
, 0, span
->end
,
124 (CONST
GLchan (*)[4]) span
->color
.rgba
,
125 (GLchan (*)[4]) span
->color
.rgba
);