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 "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 if (width
> MAX_WIDTH
)
52 /* read the data from framebuffer */
53 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
56 /* save PBO binding */
57 bufferSave
= ctx
->Unpack
.BufferObj
;
58 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
60 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, CHAN_TYPE
, data
);
62 /* restore PBO binding */
63 ctx
->Unpack
.BufferObj
= bufferSave
;
68 _swrast_CopyColorSubTable( GLcontext
*ctx
,GLenum target
, GLsizei start
,
69 GLint x
, GLint y
, GLsizei width
)
71 GLchan data
[MAX_WIDTH
][4];
72 struct gl_buffer_object
*bufferSave
;
74 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
75 /* no readbuffer - OK */
79 if (width
> MAX_WIDTH
)
82 /* read the data from framebuffer */
83 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
86 /* save PBO binding */
87 bufferSave
= ctx
->Unpack
.BufferObj
;
88 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
90 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, CHAN_TYPE
, data
);
92 /* restore PBO binding */
93 ctx
->Unpack
.BufferObj
= bufferSave
;
98 _swrast_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
99 GLenum internalFormat
,
100 GLint x
, GLint y
, GLsizei width
)
102 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
103 GLchan rgba
[MAX_CONVOLUTION_WIDTH
][4];
104 struct gl_buffer_object
*bufferSave
;
106 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
107 /* no readbuffer - OK */
111 RENDER_START( swrast
, ctx
);
113 /* read the data from framebuffer */
114 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
115 width
, x
, y
, (GLchan (*)[4]) rgba
);
117 RENDER_FINISH( swrast
, ctx
);
119 /* save PBO binding */
120 bufferSave
= ctx
->Unpack
.BufferObj
;
121 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
123 /* store as convolution filter */
124 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
125 GL_RGBA
, CHAN_TYPE
, rgba
);
127 /* restore PBO binding */
128 ctx
->Unpack
.BufferObj
= bufferSave
;
133 _swrast_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
134 GLenum internalFormat
,
135 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
137 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
138 struct gl_pixelstore_attrib packSave
;
139 GLchan rgba
[MAX_CONVOLUTION_HEIGHT
][MAX_CONVOLUTION_WIDTH
][4];
141 struct gl_buffer_object
*bufferSave
;
143 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
144 /* no readbuffer - OK */
148 RENDER_START(swrast
,ctx
);
150 /* read pixels from framebuffer */
151 for (i
= 0; i
< height
; i
++) {
152 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
153 width
, x
, y
+ i
, (GLchan (*)[4]) rgba
[i
] );
156 RENDER_FINISH(swrast
,ctx
);
159 * HACK: save & restore context state so we can store this as a
160 * convolution filter via the GL api. Doesn't call any callbacks
161 * hanging off ctx->Unpack statechanges.
164 packSave
= ctx
->Unpack
; /* save pixel packing params */
166 ctx
->Unpack
.Alignment
= 1;
167 ctx
->Unpack
.RowLength
= MAX_CONVOLUTION_WIDTH
;
168 ctx
->Unpack
.SkipPixels
= 0;
169 ctx
->Unpack
.SkipRows
= 0;
170 ctx
->Unpack
.ImageHeight
= 0;
171 ctx
->Unpack
.SkipImages
= 0;
172 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
173 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
174 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
175 ctx
->NewState
|= _NEW_PACKUNPACK
;
177 /* save PBO binding */
178 bufferSave
= ctx
->Unpack
.BufferObj
;
179 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
181 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
182 GL_RGBA
, CHAN_TYPE
, rgba
);
184 /* restore PBO binding */
185 ctx
->Unpack
.BufferObj
= bufferSave
;
187 ctx
->Unpack
= packSave
; /* restore pixel packing params */
188 ctx
->NewState
|= _NEW_PACKUNPACK
;