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