~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/swrast/s_masking.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Mesa 3-D graphics library
3
 
 * Version:  6.3
 
3
 * Version:  6.5.2
4
4
 *
5
 
 * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
 
5
 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6
6
 *
7
7
 * Permission is hereby granted, free of charge, to any person obtaining a
8
8
 * copy of this software and associated documentation files (the "Software"),
29
29
 
30
30
 
31
31
#include "glheader.h"
32
 
#include "enums.h"
33
32
#include "macros.h"
34
33
 
35
34
#include "s_context.h"
37
36
#include "s_span.h"
38
37
 
39
38
 
40
 
 
 
39
/**
 
40
 * Apply the color mask to a span of rgba values.
 
41
 */
41
42
void
42
43
_swrast_mask_rgba_span(GLcontext *ctx, struct gl_renderbuffer *rb,
43
 
                       const struct sw_span *span, GLchan rgba[][4])
 
44
                       SWspan *span)
44
45
{
45
 
   GLchan dest[MAX_WIDTH][4];
46
 
#if CHAN_BITS == 8
47
 
   GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
48
 
   GLuint dstMask = ~srcMask;
49
 
   GLuint *rgba32 = (GLuint *) rgba;
50
 
   GLuint *dest32 = (GLuint *) dest;
51
 
#else
52
 
   const GLboolean rMask = ctx->Color.ColorMask[RCOMP];
53
 
   const GLboolean gMask = ctx->Color.ColorMask[GCOMP];
54
 
   const GLboolean bMask = ctx->Color.ColorMask[BCOMP];
55
 
   const GLboolean aMask = ctx->Color.ColorMask[ACOMP];
56
 
#endif
57
46
   const GLuint n = span->end;
58
 
   GLuint i;
 
47
   void *rbPixels;
59
48
 
60
49
   ASSERT(n < MAX_WIDTH);
61
50
   ASSERT(span->arrayMask & SPAN_RGBA);
62
 
 
63
 
   if (span->arrayMask & SPAN_XY) {
64
 
      _swrast_get_values(ctx, rb, n, span->array->x, span->array->y,
65
 
                         dest, 4 * sizeof(GLchan));
 
51
   ASSERT(rb->DataType == span->array->ChanType);
 
52
 
 
53
   rbPixels = _swrast_get_dest_rgba(ctx, rb, span);
 
54
 
 
55
   /*
 
56
    * Do component masking.
 
57
    * Note that we're not using span->array->mask[] here.  We could...
 
58
    */
 
59
   if (span->array->ChanType == GL_UNSIGNED_BYTE) {
 
60
      /* treat 4xGLubyte as 1xGLuint */
 
61
      const GLuint srcMask = *((GLuint *) ctx->Color.ColorMask);
 
62
      const GLuint dstMask = ~srcMask;
 
63
      const GLuint *dst = (const GLuint *) rbPixels;
 
64
      GLuint *src = (GLuint *) span->array->color.sz1.rgba;
 
65
      GLuint i;
 
66
      for (i = 0; i < n; i++) {
 
67
         src[i] = (src[i] & srcMask) | (dst[i] & dstMask);
 
68
      }
 
69
   }
 
70
   else if (span->array->ChanType == GL_UNSIGNED_SHORT) {
 
71
      /* 2-byte components */
 
72
      /* XXX try to use 64-bit arithmetic someday */
 
73
      const GLushort rMask = ctx->Color.ColorMask[RCOMP] ? 0xffff : 0x0;
 
74
      const GLushort gMask = ctx->Color.ColorMask[GCOMP] ? 0xffff : 0x0;
 
75
      const GLushort bMask = ctx->Color.ColorMask[BCOMP] ? 0xffff : 0x0;
 
76
      const GLushort aMask = ctx->Color.ColorMask[ACOMP] ? 0xffff : 0x0;
 
77
      const GLushort (*dst)[4] = (const GLushort (*)[4]) rbPixels;
 
78
      GLushort (*src)[4] = span->array->color.sz2.rgba;
 
79
      GLuint i;
 
80
      for (i = 0; i < n; i++) {
 
81
         src[i][RCOMP] = (src[i][RCOMP] & rMask) | (dst[i][RCOMP] & ~rMask);
 
82
         src[i][GCOMP] = (src[i][GCOMP] & gMask) | (dst[i][GCOMP] & ~gMask);
 
83
         src[i][BCOMP] = (src[i][BCOMP] & bMask) | (dst[i][BCOMP] & ~bMask);
 
84
         src[i][ACOMP] = (src[i][ACOMP] & aMask) | (dst[i][ACOMP] & ~aMask);
 
85
      }
66
86
   }
67
87
   else {
68
 
      _swrast_read_rgba_span(ctx, rb, n, span->x, span->y, dest);
69
 
   }
70
 
 
71
 
#if CHAN_BITS == 8
72
 
   for (i = 0; i < n; i++) {
73
 
      rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
74
 
   }
75
 
#else
76
 
   for (i = 0; i < n; i++) {
77
 
      if (!rMask)  rgba[i][RCOMP] = dest[i][RCOMP];
78
 
      if (!gMask)  rgba[i][GCOMP] = dest[i][GCOMP];
79
 
      if (!bMask)  rgba[i][BCOMP] = dest[i][BCOMP];
80
 
      if (!aMask)  rgba[i][ACOMP] = dest[i][ACOMP];
81
 
   }
82
 
#endif
 
88
      /* 4-byte components */
 
89
      const GLuint rMask = ctx->Color.ColorMask[RCOMP] ? ~0x0 : 0x0;
 
90
      const GLuint gMask = ctx->Color.ColorMask[GCOMP] ? ~0x0 : 0x0;
 
91
      const GLuint bMask = ctx->Color.ColorMask[BCOMP] ? ~0x0 : 0x0;
 
92
      const GLuint aMask = ctx->Color.ColorMask[ACOMP] ? ~0x0 : 0x0;
 
93
      const GLuint (*dst)[4] = (const GLuint (*)[4]) rbPixels;
 
94
      GLuint (*src)[4] = (GLuint (*)[4]) span->array->color.sz4.rgba;
 
95
      GLuint i;
 
96
      for (i = 0; i < n; i++) {
 
97
         src[i][RCOMP] = (src[i][RCOMP] & rMask) | (dst[i][RCOMP] & ~rMask);
 
98
         src[i][GCOMP] = (src[i][GCOMP] & gMask) | (dst[i][GCOMP] & ~gMask);
 
99
         src[i][BCOMP] = (src[i][BCOMP] & bMask) | (dst[i][BCOMP] & ~bMask);
 
100
         src[i][ACOMP] = (src[i][ACOMP] & aMask) | (dst[i][ACOMP] & ~aMask);
 
101
      }
 
102
   }
83
103
}
84
104
 
85
105
 
86
 
/*
87
 
 * Apply glColorMask to a span of RGBA pixels.
 
106
/**
 
107
 * Apply the index mask to a span of color index values.
88
108
 */
89
109
void
90
 
_swrast_mask_rgba_array(GLcontext *ctx, struct gl_renderbuffer *rb,
91
 
                        GLuint n, GLint x, GLint y, GLchan rgba[][4])
92
 
{
93
 
   GLchan dest[MAX_WIDTH][4];
94
 
   GLuint i;
95
 
 
96
 
#if CHAN_BITS == 8
97
 
 
98
 
   GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
99
 
   GLuint dstMask = ~srcMask;
100
 
   GLuint *rgba32 = (GLuint *) rgba;
101
 
   GLuint *dest32 = (GLuint *) dest;
102
 
 
103
 
   _swrast_read_rgba_span( ctx, rb, n, x, y, dest );
104
 
   for (i = 0; i < n; i++) {
105
 
      rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
106
 
   }
107
 
 
108
 
#else
109
 
 
110
 
   const GLint rMask = ctx->Color.ColorMask[RCOMP];
111
 
   const GLint gMask = ctx->Color.ColorMask[GCOMP];
112
 
   const GLint bMask = ctx->Color.ColorMask[BCOMP];
113
 
   const GLint aMask = ctx->Color.ColorMask[ACOMP];
114
 
 
115
 
   _swrast_read_rgba_span( ctx, rb, n, x, y, dest );
116
 
   for (i = 0; i < n; i++) {
117
 
      if (!rMask)  rgba[i][RCOMP] = dest[i][RCOMP];
118
 
      if (!gMask)  rgba[i][GCOMP] = dest[i][GCOMP];
119
 
      if (!bMask)  rgba[i][BCOMP] = dest[i][BCOMP];
120
 
      if (!aMask)  rgba[i][ACOMP] = dest[i][ACOMP];
121
 
   }
122
 
 
123
 
#endif
124
 
}
125
 
 
126
 
 
127
 
 
128
 
void
129
110
_swrast_mask_ci_span(GLcontext *ctx, struct gl_renderbuffer *rb,
130
 
                     const struct sw_span *span, GLuint index[])
 
111
                     SWspan *span)
131
112
{
132
113
   const GLuint srcMask = ctx->Color.IndexMask;
133
114
   const GLuint dstMask = ~srcMask;
 
115
   GLuint *index = span->array->index;
134
116
   GLuint dest[MAX_WIDTH];
135
117
   GLuint i;
136
118
 
150
132
      index[i] = (index[i] & srcMask) | (dest[i] & dstMask);
151
133
   }
152
134
}
153
 
 
154
 
 
155
 
/*
156
 
 * Apply glIndexMask to an array of CI pixels.
157
 
 */
158
 
void
159
 
_swrast_mask_ci_array(GLcontext *ctx, struct gl_renderbuffer *rb,
160
 
                      GLuint n, GLint x, GLint y, GLuint index[])
161
 
{
162
 
   const GLuint srcMask = ctx->Color.IndexMask;
163
 
   const GLuint dstMask = ~srcMask;
164
 
   GLuint dest[MAX_WIDTH];
165
 
   GLuint i;
166
 
 
167
 
   _swrast_read_index_span(ctx, rb, n, x, y, dest);
168
 
 
169
 
   for (i=0;i<n;i++) {
170
 
      index[i] = (index[i] & srcMask) | (dest[i] & dstMask);
171
 
   }
172
 
}