03c65db70ba9c40ada5fa5239dd1125419997df8
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.
56 accum_mad(struct pipe_context
*pipe
, GLfloat scale
, GLfloat bias
,
57 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
58 struct pipe_surface
*acc_ps
)
63 accBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
65 (void) pipe
->region_map(pipe
, acc_ps
->region
);
67 acc_ps
->get_tile(acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
69 for (i
= 0; i
< 4 * width
* height
; i
++) {
70 GLfloat val
= accBuf
[i
] * scale
+ bias
;
71 accBuf
[i
] = CLAMP(val
, 0.0, 1.0);
74 acc_ps
->put_tile(acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
78 pipe
->region_unmap(pipe
, acc_ps
->region
);
83 accum_accum(struct pipe_context
*pipe
, GLfloat value
,
84 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
85 struct pipe_surface
*acc_ps
,
86 struct pipe_surface
*color_ps
)
88 ubyte
*colorMap
, *accMap
;
89 GLfloat
*colorBuf
, *accBuf
;
92 colorBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
93 accBuf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
95 colorMap
= pipe
->region_map(pipe
, color_ps
->region
);
96 accMap
= pipe
->region_map(pipe
, acc_ps
->region
);
98 color_ps
->get_tile(color_ps
, xpos
, ypos
, width
, height
, colorBuf
);
99 acc_ps
->get_tile(acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
101 for (i
= 0; i
< 4 * width
* height
; i
++) {
102 GLfloat val
= accBuf
[i
] + colorBuf
[i
] * value
;
103 accBuf
[i
] = CLAMP(val
, 0.0, 1.0);
106 acc_ps
->put_tile(acc_ps
, xpos
, ypos
, width
, height
, accBuf
);
108 _mesa_free(colorBuf
);
111 pipe
->region_unmap(pipe
, color_ps
->region
);
112 pipe
->region_unmap(pipe
, acc_ps
->region
);
117 accum_load(struct pipe_context
*pipe
, GLfloat value
,
118 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
119 struct pipe_surface
*acc_ps
,
120 struct pipe_surface
*color_ps
)
125 buf
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
127 (void) pipe
->region_map(pipe
, color_ps
->region
);
128 (void) pipe
->region_map(pipe
, acc_ps
->region
);
130 color_ps
->get_tile(color_ps
, xpos
, ypos
, width
, height
, buf
);
132 for (i
= 0; i
< 4 * width
* height
; i
++) {
133 GLfloat val
= buf
[i
] * value
;
134 buf
[i
] = CLAMP(val
, 0.0, 1.0);
137 acc_ps
->put_tile(acc_ps
, xpos
, ypos
, width
, height
, buf
);
141 pipe
->region_unmap(pipe
, color_ps
->region
);
142 pipe
->region_unmap(pipe
, acc_ps
->region
);
147 accum_return(GLcontext
*ctx
, GLfloat value
,
148 GLint xpos
, GLint ypos
, GLint width
, GLint height
,
149 struct pipe_surface
*acc_ps
,
150 struct pipe_surface
*color_ps
)
152 struct pipe_context
*pipe
= ctx
->st
->pipe
;
153 const GLboolean writeR
= ctx
->Color
.ColorMask
[0];
154 const GLboolean writeG
= ctx
->Color
.ColorMask
[1];
155 const GLboolean writeB
= ctx
->Color
.ColorMask
[2];
156 const GLboolean writeA
= ctx
->Color
.ColorMask
[3];
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 acc_ps
->get_tile(acc_ps
, xpos
, ypos
, width
, height
, buf
);
167 for (i
= 0; i
< width
* height
; i
++) {
169 GLfloat r
= buf
[i
* 4 + 0] * value
;
170 buf
[i
* 4 + 0] = CLAMP(r
, 0.0, 1.0);
173 GLfloat g
= buf
[i
* 4 + 1] * value
;
174 buf
[i
* 4 + 1] = CLAMP(g
, 0.0, 1.0);
177 GLfloat b
= buf
[i
* 4 + 2] * value
;
178 buf
[i
* 4 + 2] = CLAMP(b
, 0.0, 1.0);
181 GLfloat a
= buf
[i
* 4 + 3] * value
;
182 buf
[i
* 4 + 3] = CLAMP(a
, 0.0, 1.0);
186 color_ps
->put_tile(color_ps
, xpos
, ypos
, width
, height
, buf
);
190 pipe
->region_unmap(pipe
, color_ps
->region
);
191 pipe
->region_unmap(pipe
, acc_ps
->region
);
196 st_Accum(GLcontext
*ctx
, GLenum op
, GLfloat value
)
198 struct st_context
*st
= ctx
->st
;
199 struct pipe_context
*pipe
= st
->pipe
;
200 struct st_renderbuffer
*acc_strb
201 = st_renderbuffer(ctx
->DrawBuffer
->Attachment
[BUFFER_ACCUM
].Renderbuffer
);
202 struct st_renderbuffer
*color_strb
203 = st_renderbuffer(ctx
->ReadBuffer
->_ColorReadBuffer
);
204 struct pipe_surface
*acc_ps
= acc_strb
->surface
;
205 struct pipe_surface
*color_ps
= color_strb
->surface
;
207 const GLint xpos
= ctx
->DrawBuffer
->_Xmin
;
208 const GLint ypos
= ctx
->DrawBuffer
->_Ymin
;
209 const GLint width
= ctx
->DrawBuffer
->_Xmax
- xpos
;
210 const GLint height
= ctx
->DrawBuffer
->_Ymax
- ypos
;
215 accum_mad(pipe
, 1.0, value
, xpos
, ypos
, width
, height
, acc_ps
);
220 accum_mad(pipe
, value
, 0.0, xpos
, ypos
, width
, height
, acc_ps
);
225 accum_accum(pipe
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
229 accum_load(pipe
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
232 accum_return(ctx
, value
, xpos
, ypos
, width
, height
, acc_ps
, color_ps
);
241 void st_init_accum_functions(struct dd_function_table
*functions
)
243 functions
->Accum
= st_Accum
;