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 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
43 GLchan data
[MAX_WIDTH
][4];
44 struct gl_buffer_object
*bufferSave
;
46 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
47 /* no readbuffer - OK */
51 if (width
> MAX_WIDTH
)
54 RENDER_START( swrast
, ctx
);
56 /* read the data from framebuffer */
57 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
58 width
, x
, y
, CHAN_TYPE
, data
);
60 RENDER_FINISH(swrast
,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 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
78 GLchan data
[MAX_WIDTH
][4];
79 struct gl_buffer_object
*bufferSave
;
81 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
82 /* no readbuffer - OK */
86 if (width
> MAX_WIDTH
)
89 RENDER_START( swrast
, ctx
);
91 /* read the data from framebuffer */
92 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
93 width
, x
, y
, CHAN_TYPE
, data
);
95 RENDER_FINISH(swrast
,ctx
);
97 /* save PBO binding */
98 bufferSave
= ctx
->Unpack
.BufferObj
;
99 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
101 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
103 /* restore PBO binding */
104 ctx
->Unpack
.BufferObj
= bufferSave
;
109 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
110 GLenum internalFormat
,
111 GLint x
, GLint y
, GLsizei width
)
113 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
114 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
115 struct gl_buffer_object
*bufferSave
;
117 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
118 /* no readbuffer - OK */
122 RENDER_START( swrast
, ctx
);
124 /* read the data from framebuffer */
125 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
126 width
, x
, y
, CHAN_TYPE
, rgba
);
128 RENDER_FINISH( swrast
, ctx
);
130 /* save PBO binding */
131 bufferSave
= ctx
->Unpack
.BufferObj
;
132 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
134 /* store as convolution filter */
135 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
136 GL_RGBA
, CHAN_TYPE
, rgba
);
138 /* restore PBO binding */
139 ctx
->Unpack
.BufferObj
= bufferSave
;
144 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
145 GLenum internalFormat
,
146 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
148 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
149 struct gl_pixelstore_attrib packSave
;
150 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
152 struct gl_buffer_object
*bufferSave
;
154 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
155 /* no readbuffer - OK */
159 RENDER_START(swrast
,ctx
);
161 /* read pixels from framebuffer */
162 for (i
= 0; i
< height
; i
++) {
163 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
164 width
, x
, y
+ i
, CHAN_TYPE
, rgba
[i
] );
167 RENDER_FINISH(swrast
,ctx
);
170 * HACK: save & restore context state so we can store this as a
171 * convolution filter via the GL api. Doesn't call any callbacks
172 * hanging off ctx->Unpack statechanges.
175 packSave
= ctx
->Unpack
; /* save pixel packing params */
177 ctx
->Unpack
.Alignment
= 1;
178 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
179 ctx
->Unpack
.SkipPixels
= 0;
180 ctx
->Unpack
.SkipRows
= 0;
181 ctx
->Unpack
.ImageHeight
= 0;
182 ctx
->Unpack
.SkipImages
= 0;
183 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
184 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
185 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
186 ctx
->NewState
|= _NEW_PACKUNPACK
;
188 /* save PBO binding */
189 bufferSave
= ctx
->Unpack
.BufferObj
;
190 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
192 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
193 GL_RGBA
, CHAN_TYPE
, rgba
);
195 /* restore PBO binding */
196 ctx
->Unpack
.BufferObj
= bufferSave
;
198 ctx
->Unpack
= packSave
; /* restore pixel packing params */
199 ctx
->NewState
|= _NEW_PACKUNPACK
;