2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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.
30 #include "s_context.h"
37 _swrast_CopyColorTable( GLcontext
*ctx
,
38 GLenum target
, GLenum internalformat
,
39 GLint x
, GLint y
, GLsizei width
)
41 GLchan data
[MAX_WIDTH
][4];
42 struct gl_buffer_object
*bufferSave
;
44 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
45 /* no readbuffer - OK */
49 /* Select buffer to read from */
50 _swrast_use_read_buffer(ctx
);
52 if (width
> MAX_WIDTH
)
55 /* read the data from framebuffer */
56 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
59 /* Restore reading from draw buffer (the default) */
60 _swrast_use_draw_buffer(ctx
);
62 /* save PBO binding */
63 bufferSave
= ctx
->Unpack
.BufferObj
;
64 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
66 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
68 /* restore PBO binding */
69 ctx
->Unpack
.BufferObj
= bufferSave
;
74 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
75 GLint x
, GLint y
, GLsizei width
)
77 GLchan data
[MAX_WIDTH
][4];
78 struct gl_buffer_object
*bufferSave
;
80 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
81 /* no readbuffer - OK */
85 /* Select buffer to read from */
86 _swrast_use_read_buffer(ctx
);
88 if (width
> MAX_WIDTH
)
91 /* read the data from framebuffer */
92 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
95 /* Restore reading from draw buffer (the default) */
96 _swrast_use_draw_buffer(ctx
);
98 /* save PBO binding */
99 bufferSave
= ctx
->Unpack
.BufferObj
;
100 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
102 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
104 /* restore PBO binding */
105 ctx
->Unpack
.BufferObj
= bufferSave
;
110 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
111 GLenum internalFormat
,
112 GLint x
, GLint y
, GLsizei width
)
114 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
115 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
116 struct gl_buffer_object
*bufferSave
;
118 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
119 /* no readbuffer - OK */
123 /* Select buffer to read from */
124 _swrast_use_read_buffer(ctx
);
126 RENDER_START( swrast
, ctx
);
128 /* read the data from framebuffer */
129 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
130 width
, x
, y
, (GLchan (*)[4]) rgba
);
132 RENDER_FINISH( swrast
, ctx
);
134 /* Restore reading from draw buffer (the default) */
135 _swrast_use_draw_buffer(ctx
);
137 /* save PBO binding */
138 bufferSave
= ctx
->Unpack
.BufferObj
;
139 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
141 /* store as convolution filter */
142 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
143 GL_RGBA
, CHAN_TYPE
, rgba
);
145 /* restore PBO binding */
146 ctx
->Unpack
.BufferObj
= bufferSave
;
151 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
152 GLenum internalFormat
,
153 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
155 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
156 struct gl_pixelstore_attrib packSave
;
157 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
159 struct gl_buffer_object
*bufferSave
;
161 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
162 /* no readbuffer - OK */
166 /* Select buffer to read from */
167 _swrast_use_read_buffer(ctx
);
169 RENDER_START(swrast
,ctx
);
171 /* read pixels from framebuffer */
172 for (i
= 0; i
< height
; i
++) {
173 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
174 width
, x
, y
+ i
, (GLchan (*)[4]) rgba
[i
] );
177 RENDER_FINISH(swrast
,ctx
);
179 /* Restore reading from draw buffer (the default) */
180 _swrast_use_draw_buffer(ctx
);
183 * HACK: save & restore context state so we can store this as a
184 * convolution filter via the GL api. Doesn't call any callbacks
185 * hanging off ctx->Unpack statechanges.
188 packSave
= ctx
->Unpack
; /* save pixel packing params */
190 ctx
->Unpack
.Alignment
= 1;
191 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
192 ctx
->Unpack
.SkipPixels
= 0;
193 ctx
->Unpack
.SkipRows
= 0;
194 ctx
->Unpack
.ImageHeight
= 0;
195 ctx
->Unpack
.SkipImages
= 0;
196 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
197 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
198 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
199 ctx
->NewState
|= _NEW_PACKUNPACK
;
201 /* save PBO binding */
202 bufferSave
= ctx
->Unpack
.BufferObj
;
203 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
205 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
206 GL_RGBA
, CHAN_TYPE
, rgba
);
208 /* restore PBO binding */
209 ctx
->Unpack
.BufferObj
= bufferSave
;
211 ctx
->Unpack
= packSave
; /* restore pixel packing params */
212 ctx
->NewState
|= _NEW_PACKUNPACK
;