switch to using driFillInModes fix depthbuffer = 0
[mesa.git] / src / mesa / swrast / s_imaging.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
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 /* KW: Moved these here to remove knowledge of swrast from core mesa.
26 * Should probably pull the entire software implementation of these
27 * extensions into either swrast or a sister module.
28 */
29
30 #include "s_context.h"
31 #include "s_span.h"
32 #include "colortab.h"
33 #include "convolve.h"
34
35
36 void
37 _swrast_CopyColorTable( GLcontext *ctx,
38 GLenum target, GLenum internalformat,
39 GLint x, GLint y, GLsizei width)
40 {
41 GLchan data[MAX_WIDTH][4];
42
43 /* Select buffer to read from */
44 _swrast_use_read_buffer(ctx);
45
46 if (width > MAX_WIDTH)
47 width = MAX_WIDTH;
48
49 /* read the data from framebuffer */
50 _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
51
52 /* Restore reading from draw buffer (the default) */
53 _swrast_use_draw_buffer(ctx);
54
55 _mesa_ColorTable(target, internalformat, width, GL_RGBA, CHAN_TYPE, data);
56 }
57
58
59 void
60 _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start,
61 GLint x, GLint y, GLsizei width)
62 {
63 GLchan data[MAX_WIDTH][4];
64
65 /* Select buffer to read from */
66 _swrast_use_read_buffer(ctx);
67
68 if (width > MAX_WIDTH)
69 width = MAX_WIDTH;
70
71 /* read the data from framebuffer */
72 _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y, data );
73
74 /* Restore reading from draw buffer (the default) */
75 _swrast_use_draw_buffer(ctx);
76
77 _mesa_ColorSubTable(target, start, width, GL_RGBA, CHAN_TYPE, data);
78 }
79
80
81 void
82 _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target,
83 GLenum internalFormat,
84 GLint x, GLint y, GLsizei width)
85 {
86 SWcontext *swrast = SWRAST_CONTEXT(ctx);
87 GLchan rgba[MAX_CONVOLUTION_WIDTH][4];
88
89 /* Select buffer to read from */
90 _swrast_use_read_buffer(ctx);
91
92 RENDER_START( swrast, ctx );
93
94 /* read the data from framebuffer */
95 _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y,
96 (GLchan (*)[4]) rgba );
97
98 RENDER_FINISH( swrast, ctx );
99
100 /* Restore reading from draw buffer (the default) */
101 _swrast_use_draw_buffer(ctx);
102
103 /* store as convolution filter */
104 _mesa_ConvolutionFilter1D(target, internalFormat, width,
105 GL_RGBA, CHAN_TYPE, rgba);
106 }
107
108
109 void
110 _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target,
111 GLenum internalFormat,
112 GLint x, GLint y, GLsizei width, GLsizei height)
113 {
114 SWcontext *swrast = SWRAST_CONTEXT(ctx);
115 struct gl_pixelstore_attrib packSave;
116 GLchan rgba[MAX_CONVOLUTION_HEIGHT][MAX_CONVOLUTION_WIDTH][4];
117 GLint i;
118
119 /* Select buffer to read from */
120 _swrast_use_read_buffer(ctx);
121
122 RENDER_START(swrast,ctx);
123
124 /* read pixels from framebuffer */
125 for (i = 0; i < height; i++) {
126 _swrast_read_rgba_span( ctx, ctx->ReadBuffer, width, x, y + i,
127 (GLchan (*)[4]) rgba[i] );
128 }
129
130 RENDER_FINISH(swrast,ctx);
131
132 /* Restore reading from draw buffer (the default) */
133 _swrast_use_draw_buffer(ctx);
134
135 /*
136 * HACK: save & restore context state so we can store this as a
137 * convolution filter via the GL api. Doesn't call any callbacks
138 * hanging off ctx->Unpack statechanges.
139 */
140
141 packSave = ctx->Unpack; /* save pixel packing params */
142
143 ctx->Unpack.Alignment = 1;
144 ctx->Unpack.RowLength = MAX_CONVOLUTION_WIDTH;
145 ctx->Unpack.SkipPixels = 0;
146 ctx->Unpack.SkipRows = 0;
147 ctx->Unpack.ImageHeight = 0;
148 ctx->Unpack.SkipImages = 0;
149 ctx->Unpack.SwapBytes = GL_FALSE;
150 ctx->Unpack.LsbFirst = GL_FALSE;
151 ctx->Unpack.BufferObj = ctx->Array.NullBufferObj;
152 ctx->NewState |= _NEW_PACKUNPACK;
153
154 _mesa_ConvolutionFilter2D(target, internalFormat, width, height,
155 GL_RGBA, CHAN_TYPE, rgba);
156
157 ctx->Unpack = packSave; /* restore pixel packing params */
158 ctx->NewState |= _NEW_PACKUNPACK;
159 }