2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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 "main/glheader.h"
31 #include "main/colortab.h"
32 #include "main/convolve.h"
33 #include "s_context.h"
38 _swrast_CopyColorTable( GLcontext
*ctx
,
39 GLenum target
, GLenum internalformat
,
40 GLint x
, GLint y
, GLsizei width
)
42 GLchan data
[MAX_WIDTH
][4];
43 struct gl_buffer_object
*bufferSave
;
45 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
46 /* no readbuffer - OK */
50 if (width
> MAX_WIDTH
)
53 swrast_render_start(ctx
);
55 /* read the data from framebuffer */
56 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
57 width
, x
, y
, CHAN_TYPE
, data
);
59 swrast_render_finish(ctx
);
61 /* save PBO binding */
62 bufferSave
= ctx
->Unpack
.BufferObj
;
63 ctx
->Unpack
.BufferObj
= ctx
->Shared
->NullBufferObj
;
65 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
67 /* restore PBO binding */
68 ctx
->Unpack
.BufferObj
= bufferSave
;
73 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
74 GLint x
, GLint y
, GLsizei width
)
76 GLchan data
[MAX_WIDTH
][4];
77 struct gl_buffer_object
*bufferSave
;
79 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
80 /* no readbuffer - OK */
84 if (width
> MAX_WIDTH
)
87 swrast_render_start(ctx
);
89 /* read the data from framebuffer */
90 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
91 width
, x
, y
, CHAN_TYPE
, data
);
93 swrast_render_finish(ctx
);
95 /* save PBO binding */
96 bufferSave
= ctx
->Unpack
.BufferObj
;
97 ctx
->Unpack
.BufferObj
= ctx
->Shared
->NullBufferObj
;
99 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
101 /* restore PBO binding */
102 ctx
->Unpack
.BufferObj
= bufferSave
;
107 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
108 GLenum internalFormat
,
109 GLint x
, GLint y
, GLsizei width
)
111 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
112 struct gl_buffer_object
*bufferSave
;
114 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
115 /* no readbuffer - OK */
119 swrast_render_start(ctx
);
121 /* read the data from framebuffer */
122 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
123 width
, x
, y
, CHAN_TYPE
, rgba
);
125 swrast_render_finish(ctx
);
127 /* save PBO binding */
128 bufferSave
= ctx
->Unpack
.BufferObj
;
129 ctx
->Unpack
.BufferObj
= ctx
->Shared
->NullBufferObj
;
131 /* store as convolution filter */
132 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
133 GL_RGBA
, CHAN_TYPE
, rgba
);
135 /* restore PBO binding */
136 ctx
->Unpack
.BufferObj
= bufferSave
;
141 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
142 GLenum internalFormat
,
143 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
145 struct gl_pixelstore_attrib packSave
;
146 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
148 struct gl_buffer_object
*bufferSave
;
150 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
151 /* no readbuffer - OK */
155 swrast_render_start(ctx
);
157 /* read pixels from framebuffer */
158 for (i
= 0; i
< height
; i
++) {
159 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
160 width
, x
, y
+ i
, CHAN_TYPE
, rgba
[i
] );
163 swrast_render_finish(ctx
);
166 * HACK: save & restore context state so we can store this as a
167 * convolution filter via the GL api. Doesn't call any callbacks
168 * hanging off ctx->Unpack statechanges.
171 packSave
= ctx
->Unpack
; /* save pixel packing params */
173 ctx
->Unpack
.Alignment
= 1;
174 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
175 ctx
->Unpack
.SkipPixels
= 0;
176 ctx
->Unpack
.SkipRows
= 0;
177 ctx
->Unpack
.ImageHeight
= 0;
178 ctx
->Unpack
.SkipImages
= 0;
179 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
180 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
181 ctx
->Unpack
.BufferObj
= ctx
->Shared
->NullBufferObj
;
182 ctx
->NewState
|= _NEW_PACKUNPACK
;
184 /* save PBO binding */
185 bufferSave
= ctx
->Unpack
.BufferObj
;
186 ctx
->Unpack
.BufferObj
= ctx
->Shared
->NullBufferObj
;
188 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
189 GL_RGBA
, CHAN_TYPE
, rgba
);
191 /* restore PBO binding */
192 ctx
->Unpack
.BufferObj
= bufferSave
;
194 ctx
->Unpack
= packSave
; /* restore pixel packing params */
195 ctx
->NewState
|= _NEW_PACKUNPACK
;