Panda3D
store_pixel.h
1 // Filename: store_pixel.h
2 // Created by: drose (12May08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 /* Definition of a function to store a pixel in the framebuffer, using
16  user-specified color blending. */
17 
18 /* This file generates lots of "template" variations, using #define
19  and #include, similar to the way ztriangle.h works. */
20 
21 static void
22 FNAME(store_pixel) (ZBuffer *zb, PIXEL &result, int r, int g, int b, int a) {
23  unsigned int fr = PIXEL_R(result);
24  unsigned int fg = PIXEL_G(result);
25  unsigned int fb = PIXEL_B(result);
26  unsigned int fa = PIXEL_A(result);
27 
28  r = STORE_PIXEL_0(fr, ((unsigned int)r * OP_A(fr, r) >> 16) + ((unsigned int)fr * OP_B(fr, r) >> 16));
29  g = STORE_PIXEL_1(fg, ((unsigned int)g * OP_A(fg, g) >> 16) + ((unsigned int)fg * OP_B(fg, g) >> 16));
30  b = STORE_PIXEL_2(fg, ((unsigned int)b * OP_A(fb, b) >> 16) + ((unsigned int)fb * OP_B(fb, b) >> 16));
31  a = STORE_PIXEL_3(fg, ((unsigned int)a * OP_A(fa, a) >> 16) + ((unsigned int)fa * OP_B(fa, a) >> 16));
32  result = RGBA_TO_PIXEL(r, g, b, a);
33 }
34 
35 #ifdef FNAME_S
36 /* sRGB variant. */
37 
38 static void
39 FNAME_S(store_pixel) (ZBuffer *zb, PIXEL &result, int r, int g, int b, int a) {
40  unsigned int fr = PIXEL_SR(result);
41  unsigned int fg = PIXEL_SG(result);
42  unsigned int fb = PIXEL_SB(result);
43  unsigned int fa = PIXEL_A(result);
44 
45  r = STORE_PIXEL_0(fr, ((unsigned int)r * OP_A(fr, r) >> 16) + ((unsigned int)fr * OP_B(fr, r) >> 16));
46  g = STORE_PIXEL_1(fg, ((unsigned int)g * OP_A(fg, g) >> 16) + ((unsigned int)fg * OP_B(fg, g) >> 16));
47  b = STORE_PIXEL_2(fg, ((unsigned int)b * OP_A(fb, b) >> 16) + ((unsigned int)fb * OP_B(fb, b) >> 16));
48  a = STORE_PIXEL_3(fg, ((unsigned int)a * OP_A(fa, a) >> 16) + ((unsigned int)fa * OP_B(fa, a) >> 16));
49  result = SRGBA_TO_PIXEL(r, g, b, a);
50 }
51 
52 #undef FNAME_S
53 #endif
54 
55 #undef FNAME
56 #undef OP_A
57 #undef OP_B
58 #undef STORE_PIXEL_0
59 #undef STORE_PIXEL_1
60 #undef STORE_PIXEL_2
61 #undef STORE_PIXEL_3