7a245b0ed6d56dfd17adb719dccf890cc844e411
1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "main/imports.h"
34 #include "main/image.h"
35 #include "main/macros.h"
37 #include "st_context.h"
39 #include "st_cb_accum.h"
40 #include "st_cb_fbo.h"
42 #include "st_format.h"
43 #include "pipe/p_context.h"
44 #include "pipe/p_defines.h"
48 * For hardware that supports deep color buffers, we could accelerate
49 * most/all the accum operations with blending/texturing.
50 * For now, just use the get/put_tile() functions and do things in software.
55 st_clear_accum_buffer(GLcontext
*ctx
, struct gl_renderbuffer
*rb
)
57 struct pipe_context
*pipe
= ctx
->st
->pipe
;
58 struct st_renderbuffer
*acc_strb
= st_renderbuffer(rb
);
59 struct pipe_surface
*acc_ps
= acc_strb
->surface
;
60 const GLint xpos
= ctx
->DrawBuffer
->_Xmin
;
61 const GLint ypos
= ctx
->DrawBuffer
->_Ymin
;
62 const GLint width
= ctx
->DrawBuffer
->_Xmax
- xpos
;
63 const GLint height
= ctx
->DrawBuffer
->_Ymax
- ypos
;
64 const GLfloat r
= ctx
->Accum
.ClearColor
[0];
65 const GLfloat g
= ctx
->Accum
.ClearColor
[1];
66 const GLfloat b
= ctx
->Accum
.ClearColor
[2];
67 const GLfloat a
= ctx
->Accum
.ClearColor
[3];
71 (void) pipe
->region_map(pipe
, acc_ps
->region
);
73 accBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
75 for (i
= 0; i
< width
* height
; i
++) {
76 accBuf
[i
* 4 + 0] = r
;
77 accBuf
[i
* 4 + 1] = g
;
78 accBuf
[i
* 4 + 2] = b
;
79 accBuf
[i
* 4 + 3] = a
;
82 pipe
->put_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
86 pipe
->region_unmap(pipe
, acc_ps
->region
);
93 accum_mad(struct pipe_context
*pipe
, GLfloat scale
, GLfloat bias
,
94 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
95 struct pipe_surface
*acc_ps
)
100 accBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
102 (void) pipe
->region_map(pipe
, acc_ps
->region
);
104 pipe
->get_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
106 for (i
= 0; i
< 4 * width
* height
; i
++) {
107 accBuf
[i
] = accBuf
[i
] * scale
+ bias
;
110 pipe
->put_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
114 pipe
->region_unmap(pipe
, acc_ps
->region
);
119 accum_accum(struct pipe_context
*pipe
, GLfloat value
,
120 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
121 struct pipe_surface
*acc_ps
,
122 struct pipe_surface
*color_ps
)
124 ubyte
*colorMap
, *accMap
;
125 GLfloat
*colorBuf
, *accBuf
;
128 colorBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
129 accBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
131 colorMap
= pipe
->region_map(pipe
, color_ps
->region
);
132 accMap
= pipe
->region_map(pipe
, acc_ps
->region
);
134 pipe
->get_tile_rgba(pipe
, color_ps
, xpos
, ypos
, width
, height
, colorBuf
);
135 pipe
->get_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
137 for (i
= 0; i
< 4 * width
* height
; i
++) {
138 accBuf
[i
] = accBuf
[i
] + colorBuf
[i
] * value
;
141 pipe
->put_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
146 pipe
->region_unmap(pipe
, color_ps
->region
);
147 pipe
->region_unmap(pipe
, acc_ps
->region
);
152 accum_load(struct pipe_context
*pipe
, GLfloat value
,
153 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
154 struct pipe_surface
*acc_ps
,
155 struct pipe_surface
*color_ps
)
160 buf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
162 (void) pipe
->region_map(pipe
, color_ps
->region
);
163 (void) pipe
->region_map(pipe
, acc_ps
->region
);
165 pipe
->get_tile_rgba(pipe
, color_ps
, xpos
, ypos
, width
, height
, buf
);
167 for (i
= 0; i
< 4 * width
* height
; i
++) {
168 buf
[i
] = buf
[i
] * value
;
171 pipe
->put_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, buf
);
175 pipe
->region_unmap(pipe
, color_ps
->region
);
176 pipe
->region_unmap(pipe
, acc_ps
->region
);
181 accum_return(GLcontext
*ctx
, GLfloat value
,
182 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
183 struct pipe_surface
*acc_ps
,
184 struct pipe_surface
*color_ps
)
186 struct pipe_context
*pipe
= ctx
->st
->pipe
;
187 const GLubyte
*colormask
= ctx
->Color
.ColorMask
;
188 GLfloat
*abuf
, *cbuf
= NULL
;
191 abuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
193 (void) pipe
->region_map(pipe
, color_ps
->region
);
194 (void) pipe
->region_map(pipe
, acc_ps
->region
);
196 pipe
->get_tile_rgba(pipe
, acc_ps
, xpos
, ypos
, width
, height
, abuf
);
198 if (!colormask
[0] || !colormask
[1] || !colormask
[2] || !colormask
[3]) {
199 cbuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
200 pipe
->get_tile_rgba(pipe
, color_ps
, xpos
, ypos
, width
, height
, cbuf
);
203 for (i
= 0; i
< width
* height
; i
++) {
204 for (ch
= 0; ch
< 4; ch
++) {
206 GLfloat val
= abuf
[i
* 4 + ch
] * value
;
207 abuf
[i
* 4 + ch
] = CLAMP(val
, 0.0, 1.0);
210 abuf
[i
* 4 + ch
] = cbuf
[i
* 4 + ch
];
215 pipe
->put_tile_rgba(pipe
, color_ps
, xpos
, ypos
, width
, height
, abuf
);
221 pipe
->region_unmap(pipe
, color_ps
->region
);
222 pipe
->region_unmap(pipe
, acc_ps
->region
);
227 st_Accum(GLcontext
*ctx
, GLenum op
, GLfloat value
)
229 struct st_context
*st
= ctx
->st
;
230 struct pipe_context
*pipe
= st
->pipe
;
231 struct st_renderbuffer
*acc_strb
232 = st_renderbuffer(ctx
->DrawBuffer
->Attachment
[BUFFER_ACCUM
].Renderbuffer
);
233 struct st_renderbuffer
*color_strb
234 = st_renderbuffer(ctx
->ReadBuffer
->_ColorReadBuffer
);
235 struct pipe_surface
*acc_ps
= acc_strb
->surface
;
236 struct pipe_surface
*color_ps
= color_strb
->surface
;
238 const GLint xpos
= ctx
->DrawBuffer
->_Xmin
;
239 const GLint ypos
= ctx
->DrawBuffer
->_Ymin
;
240 const GLint width
= ctx
->DrawBuffer
->_Xmax
- xpos
;
241 const GLint height
= ctx
->DrawBuffer
->_Ymax
- ypos
;
243 /* make sure color bufs aren't cached */
244 pipe
->flush(pipe
, 0);
249 accum_mad(pipe
, 1.0, value
, xpos
, ypos
, width
, height
, acc_ps
);
254 accum_mad(pipe
, value
, 0.0, xpos
, ypos
, width
, height
, acc_ps
);
259 accum_accum(pipe
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
263 accum_load(pipe
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
266 accum_return(ctx
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
275 void st_init_accum_functions(struct dd_function_table
*functions
)
277 functions
->Accum
= st_Accum
;