Runtime generate sse/sse2 code for some vertex programs. Experimental
[mesa.git] / src / mesa / swrast / s_pixeltex.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 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
25
26 /*
27 * This file implements both the GL_SGIX_pixel_texture and
28 * GL_SIGS_pixel_texture extensions. Luckily, they pretty much
29 * overlap in functionality so we use the same state variables
30 * and execution code for both.
31 */
32
33
34 #include "glheader.h"
35 #include "colormac.h"
36 #include "imports.h"
37
38 #include "s_context.h"
39 #include "s_pixeltex.h"
40 #include "s_texture.h"
41
42
43 /*
44 * Convert RGBA values into strq texture coordinates.
45 */
46 static void
47 pixeltexgen(GLcontext *ctx, GLuint n, const GLchan rgba[][4],
48 GLfloat texcoord[][4])
49 {
50 if (ctx->Pixel.FragmentRgbSource == GL_CURRENT_RASTER_COLOR) {
51 GLuint i;
52 for (i = 0; i < n; i++) {
53 texcoord[i][0] = ctx->Current.RasterColor[RCOMP];
54 texcoord[i][1] = ctx->Current.RasterColor[GCOMP];
55 texcoord[i][2] = ctx->Current.RasterColor[BCOMP];
56 }
57 }
58 else {
59 GLuint i;
60 ASSERT(ctx->Pixel.FragmentRgbSource == GL_PIXEL_GROUP_COLOR_SGIS);
61 for (i = 0; i < n; i++) {
62 texcoord[i][0] = CHAN_TO_FLOAT(rgba[i][RCOMP]);
63 texcoord[i][1] = CHAN_TO_FLOAT(rgba[i][GCOMP]);
64 texcoord[i][2] = CHAN_TO_FLOAT(rgba[i][BCOMP]);
65 }
66 }
67
68 if (ctx->Pixel.FragmentAlphaSource == GL_CURRENT_RASTER_COLOR) {
69 GLuint i;
70 for (i = 0; i < n; i++) {
71 texcoord[i][3] = ctx->Current.RasterColor[ACOMP];
72 }
73 }
74 else {
75 GLuint i;
76 ASSERT(ctx->Pixel.FragmentAlphaSource == GL_PIXEL_GROUP_COLOR_SGIS);
77 for (i = 0; i < n; i++) {
78 texcoord[i][3] = CHAN_TO_FLOAT(rgba[i][ACOMP]);
79 }
80 }
81 }
82
83
84
85 /*
86 * Used by glDraw/CopyPixels: the incoming image colors are treated
87 * as texture coordinates. Use those coords to texture the image.
88 * This is for GL_SGIS_pixel_texture / GL_SGIX_pixel_texture.
89 */
90 void
91 _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span)
92 {
93 GLuint unit;
94
95 ASSERT(!(span->arrayMask & SPAN_TEXTURE));
96 span->arrayMask |= SPAN_TEXTURE;
97 span->interpMask &= ~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 }