Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 pj 1
/* $Id: s_pixeltex.c,v 1.1 2003-02-28 11:49:42 pj 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 "imports.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 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.
91
 */
92
void
93
_swrast_pixel_texture(GLcontext *ctx, struct sw_span *span)
94
{
95
   GLuint unit;
96
 
97
   ASSERT(!(span->arrayMask & SPAN_TEXTURE));
98
   span->arrayMask |= SPAN_TEXTURE;
99
 
100
   /* convert colors into texture coordinates */
101
   pixeltexgen( ctx, span->end,
102
                (const GLchan (*)[4]) span->array->rgba,
103
                span->array->texcoords[0] );
104
 
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) );
110
      }
111
   }
112
 
113
   /* apply texture mapping */
114
   _swrast_texture_span( ctx, span );
115
 
116
   /* this is a work-around to be fixed by initializing again span */
117
   span->arrayMask &= ~SPAN_TEXTURE;
118
}