use NULL lambda array for pixel texture
[mesa.git] / src / mesa / swrast / s_pixeltex.c
1 /* $Id: s_pixeltex.c,v 1.7 2002/04/04 16:53:59 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28 /*
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.
33 */
34
35
36 #include "glheader.h"
37 #include "colormac.h"
38 #include "mem.h"
39
40 #include "s_context.h"
41 #include "s_pixeltex.h"
42 #include "s_texture.h"
43
44
45 /*
46 * Convert RGBA values into strq texture coordinates.
47 */
48 static void
49 pixeltexgen(GLcontext *ctx, GLuint n, const GLchan rgba[][4],
50 GLfloat texcoord[][4])
51 {
52 if (ctx->Pixel.FragmentRgbSource == GL_CURRENT_RASTER_COLOR) {
53 GLuint i;
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];
58 }
59 }
60 else {
61 GLuint i;
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]);
67 }
68 }
69
70 if (ctx->Pixel.FragmentAlphaSource == GL_CURRENT_RASTER_COLOR) {
71 GLuint i;
72 for (i = 0; i < n; i++) {
73 texcoord[i][3] = ctx->Current.RasterColor[ACOMP];
74 }
75 }
76 else {
77 GLuint i;
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]);
81 }
82 }
83 }
84
85
86
87 /*
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.
91 */
92 void
93 _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span)
94 {
95 if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) {
96 /* multitexture! */
97 GLchan primary_rgba[MAX_WIDTH][4];
98 GLuint unit;
99
100 MEMCPY(primary_rgba, span->color.rgba, 4 * span->end * sizeof(GLchan));
101
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],
109 NULL, /* lambda */
110 (CONST GLchan (*)[4]) primary_rgba,
111 span->color.rgba);
112 }
113 }
114 }
115 else {
116 /* single texture, unit 0 */
117 ASSERT(ctx->Texture._ReallyEnabled & TEXTURE0_ANY);
118 pixeltexgen(ctx, span->end,
119 (const GLchan (*)[4]) span->color.rgba,
120 span->texcoords[0]);
121 _swrast_texture_fragments(ctx, 0, span->end,
122 span->texcoords[0],
123 NULL, /* lambda */
124 (CONST GLchan (*)[4]) span->color.rgba,
125 (GLchan (*)[4]) span->color.rgba);
126 }
127 }