mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
color mask
This commit is contained in:
parent
ef44e25157
commit
e4709607c3
@ -25,10 +25,10 @@ FNAME(store_pixel) (ZBuffer *zb, PIXEL &result, int r, int g, int b, int a) {
|
|||||||
unsigned int fb = PIXEL_B(result);
|
unsigned int fb = PIXEL_B(result);
|
||||||
unsigned int fa = PIXEL_A(result);
|
unsigned int fa = PIXEL_A(result);
|
||||||
|
|
||||||
r = STORE_PIX_CLAMP(((unsigned int)r * OP_A(fr, r) >> 16) + ((unsigned int)fr * OP_B(fr, r) >> 16));
|
r = STORE_PIXEL_0(fr, ((unsigned int)r * OP_A(fr, r) >> 16) + ((unsigned int)fr * OP_B(fr, r) >> 16));
|
||||||
g = STORE_PIX_CLAMP(((unsigned int)g * OP_A(fg, g) >> 16) + ((unsigned int)fg * OP_B(fg, g) >> 16));
|
g = STORE_PIXEL_1(fg, ((unsigned int)g * OP_A(fg, g) >> 16) + ((unsigned int)fg * OP_B(fg, g) >> 16));
|
||||||
b = STORE_PIX_CLAMP(((unsigned int)b * OP_A(fb, b) >> 16) + ((unsigned int)fb * OP_B(fb, b) >> 16));
|
b = STORE_PIXEL_2(fg, ((unsigned int)b * OP_A(fb, b) >> 16) + ((unsigned int)fb * OP_B(fb, b) >> 16));
|
||||||
a = STORE_PIX_CLAMP(((unsigned int)a * OP_A(fa, a) >> 16) + ((unsigned int)fa * OP_B(fa, a) >> 16));
|
a = STORE_PIXEL_3(fg, ((unsigned int)a * OP_A(fa, a) >> 16) + ((unsigned int)fa * OP_B(fa, a) >> 16));
|
||||||
result = RGBA_TO_PIXEL(r, g, b, a);
|
result = RGBA_TO_PIXEL(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,3 +36,7 @@ FNAME(store_pixel) (ZBuffer *zb, PIXEL &result, int r, int g, int b, int a) {
|
|||||||
#undef FNAME
|
#undef FNAME
|
||||||
#undef OP_A
|
#undef OP_A
|
||||||
#undef OP_B
|
#undef OP_B
|
||||||
|
#undef STORE_PIXEL_0
|
||||||
|
#undef STORE_PIXEL_1
|
||||||
|
#undef STORE_PIXEL_2
|
||||||
|
#undef STORE_PIXEL_3
|
||||||
|
@ -34,8 +34,17 @@ CodeTable = {
|
|||||||
'mcalpha' : '0xffff - zb->blend_a',
|
'mcalpha' : '0xffff - zb->blend_a',
|
||||||
}
|
}
|
||||||
|
|
||||||
def getFname(op_a, op_b):
|
|
||||||
return 'store_pixel_%s_%s' % (op_a, op_b)
|
bitnames = 'rgba'
|
||||||
|
|
||||||
|
def getFname(op_a, op_b, mask):
|
||||||
|
maskname = ''
|
||||||
|
for b in range(4):
|
||||||
|
if (mask & (1 << b)):
|
||||||
|
maskname += bitnames[b]
|
||||||
|
else:
|
||||||
|
maskname += '0'
|
||||||
|
return 'store_pixel_%s_%s_%s' % (op_a, op_b, maskname)
|
||||||
|
|
||||||
# We write the code that actually instantiates the various
|
# We write the code that actually instantiates the various
|
||||||
# pixel-storing functions to store_pixel_code.h.
|
# pixel-storing functions to store_pixel_code.h.
|
||||||
@ -51,16 +60,22 @@ print >> table, ''
|
|||||||
|
|
||||||
for op_a in Operands:
|
for op_a in Operands:
|
||||||
for op_b in Operands:
|
for op_b in Operands:
|
||||||
fname = getFname(op_a, op_b)
|
for mask in range(0, 16):
|
||||||
print >> code, '#define FNAME(name) %s' % (fname)
|
fname = getFname(op_a, op_b, mask)
|
||||||
print >> code, '#define OP_A(f, i) ((unsigned int)(%s))' % (CodeTable[op_a])
|
print >> code, '#define FNAME(name) %s' % (fname)
|
||||||
print >> code, '#define OP_B(f, i) ((unsigned int)(%s))' % (CodeTable[op_eb])
|
print >> code, '#define OP_A(f, i) ((unsigned int)(%s))' % (CodeTable[op_a])
|
||||||
print >> code, '#include "store_pixel.h"'
|
print >> code, '#define OP_B(f, i) ((unsigned int)(%s))' % (CodeTable[op_b])
|
||||||
print >> code, ''
|
for b in range(0, 4):
|
||||||
|
if (mask & (1 << b)):
|
||||||
|
print >> code, "#define STORE_PIXEL_%s(fr, r) STORE_PIX_CLAMP(r)" % (b)
|
||||||
|
else:
|
||||||
|
print >> code, "#define STORE_PIXEL_%s(fr, r) (fr)" % (b)
|
||||||
|
print >> code, '#include "store_pixel.h"'
|
||||||
|
print >> code, ''
|
||||||
|
|
||||||
|
|
||||||
# Now, generate the table of function pointers.
|
# Now, generate the table of function pointers.
|
||||||
arraySize = '[%s][%s]' % (len(Operands), len(Operands))
|
arraySize = '[%s][%s][16]' % (len(Operands), len(Operands))
|
||||||
|
|
||||||
print >> table, 'extern const ZB_storePixelFunc store_pixel_funcs%s;' % (arraySize)
|
print >> table, 'extern const ZB_storePixelFunc store_pixel_funcs%s;' % (arraySize)
|
||||||
print >> code, 'const ZB_storePixelFunc store_pixel_funcs%s = {' % (arraySize)
|
print >> code, 'const ZB_storePixelFunc store_pixel_funcs%s = {' % (arraySize)
|
||||||
@ -68,8 +83,11 @@ print >> code, 'const ZB_storePixelFunc store_pixel_funcs%s = {' % (arraySize)
|
|||||||
for op_a in Operands:
|
for op_a in Operands:
|
||||||
print >> code, ' {'
|
print >> code, ' {'
|
||||||
for op_b in Operands:
|
for op_b in Operands:
|
||||||
fname = getFname(op_a, op_b)
|
print >> code, ' {'
|
||||||
print >> code, ' %s,' % (fname)
|
for mask in range(0, 16):
|
||||||
|
fname = getFname(op_a, op_b, mask)
|
||||||
|
print >> code, ' %s,' % (fname)
|
||||||
|
print >> code, ' },'
|
||||||
print >> code, ' },'
|
print >> code, ' },'
|
||||||
print >> code, '};'
|
print >> code, '};'
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
|||||||
/* This file is generated code--do not edit. See store_pixel.py. */
|
/* This file is generated code--do not edit. See store_pixel.py. */
|
||||||
|
|
||||||
extern const ZB_storePixelFunc store_pixel_funcs[14][14];
|
extern const ZB_storePixelFunc store_pixel_funcs[14][14][16];
|
||||||
|
@ -822,11 +822,30 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int color_write_state = 0; // cstore
|
int color_write_state = 0; // cstore
|
||||||
|
|
||||||
|
const ColorWriteAttrib *target_color_write = DCAST(ColorWriteAttrib, _target_rs->get_attrib_def(ColorWriteAttrib::get_class_slot()));
|
||||||
|
unsigned int color_channels =
|
||||||
|
target_color_write->get_channels() & _color_write_mask;
|
||||||
|
if (color_channels != ColorWriteAttrib::C_all) {
|
||||||
|
// Implement a color mask.
|
||||||
|
int op_a = get_color_blend_op(ColorBlendAttrib::O_one);
|
||||||
|
int op_b = get_color_blend_op(ColorBlendAttrib::O_zero);
|
||||||
|
_c->zb->store_pix_func = store_pixel_funcs[op_a][op_b][color_channels];
|
||||||
|
color_write_state = 2; // cgeneral
|
||||||
|
}
|
||||||
|
|
||||||
const TransparencyAttrib *target_transparency = DCAST(TransparencyAttrib, _target_rs->get_attrib_def(TransparencyAttrib::get_class_slot()));
|
const TransparencyAttrib *target_transparency = DCAST(TransparencyAttrib, _target_rs->get_attrib_def(TransparencyAttrib::get_class_slot()));
|
||||||
switch (target_transparency->get_mode()) {
|
switch (target_transparency->get_mode()) {
|
||||||
case TransparencyAttrib::M_alpha:
|
case TransparencyAttrib::M_alpha:
|
||||||
case TransparencyAttrib::M_dual:
|
case TransparencyAttrib::M_dual:
|
||||||
color_write_state = 1; // cblend
|
color_write_state = 1; // cblend
|
||||||
|
if (color_channels != ColorWriteAttrib::C_all) {
|
||||||
|
// Implement a color mask, with alpha blending.
|
||||||
|
int op_a = get_color_blend_op(ColorBlendAttrib::O_incoming_alpha);
|
||||||
|
int op_b = get_color_blend_op(ColorBlendAttrib::O_one_minus_incoming_alpha);
|
||||||
|
_c->zb->store_pix_func = store_pixel_funcs[op_a][op_b][color_channels];
|
||||||
|
color_write_state = 2; // cgeneral
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -839,7 +858,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
|
|||||||
// the transparency set.
|
// the transparency set.
|
||||||
int op_a = get_color_blend_op(target_color_blend->get_operand_a());
|
int op_a = get_color_blend_op(target_color_blend->get_operand_a());
|
||||||
int op_b = get_color_blend_op(target_color_blend->get_operand_b());
|
int op_b = get_color_blend_op(target_color_blend->get_operand_b());
|
||||||
_c->zb->store_pix_func = store_pixel_funcs[op_a][op_b];
|
_c->zb->store_pix_func = store_pixel_funcs[op_a][op_b][color_channels];
|
||||||
Colorf c = target_color_blend->get_color();
|
Colorf c = target_color_blend->get_color();
|
||||||
_c->zb->blend_r = (int)(c[0] * ZB_POINT_RED_MAX);
|
_c->zb->blend_r = (int)(c[0] * ZB_POINT_RED_MAX);
|
||||||
_c->zb->blend_g = (int)(c[1] * ZB_POINT_GREEN_MAX);
|
_c->zb->blend_g = (int)(c[1] * ZB_POINT_GREEN_MAX);
|
||||||
@ -849,9 +868,6 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
|
|||||||
color_write_state = 2; // cgeneral
|
color_write_state = 2; // cgeneral
|
||||||
}
|
}
|
||||||
|
|
||||||
const ColorWriteAttrib *target_color_write = DCAST(ColorWriteAttrib, _target_rs->get_attrib_def(ColorWriteAttrib::get_class_slot()));
|
|
||||||
unsigned int color_channels =
|
|
||||||
target_color_write->get_channels() & _color_write_mask;
|
|
||||||
if (color_channels == ColorWriteAttrib::C_off) {
|
if (color_channels == ColorWriteAttrib::C_off) {
|
||||||
color_write_state = 3; // coff
|
color_write_state = 3; // coff
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user