Initial working stencil.

This commit is contained in:
aignacio_sf 2006-05-24 00:13:04 +00:00
parent 1a8e40cb46
commit d57e768594
3 changed files with 101 additions and 37 deletions

View File

@ -26,26 +26,24 @@
INLINE StencilAttrib::
StencilAttrib() {
_stencil_render_states [SRS_clear_value] = 0;
_stencil_render_states [SRS_reference] = 0;
_stencil_render_states [SRS_read_mask] = ~0;
_stencil_render_states [SRS_write_mask] = ~0;
_stencil_render_states [SRS_front_enable] = 0;
_stencil_render_states [SRS_back_enable] = 0;
_stencil_render_states [SRS_front_comparison_function] = SCF_always;
_stencil_render_states [SRS_front_stencil_fail_operation] = SO_keep;
_stencil_render_states [SRS_front_stencil_pass_z_fail_operation] = SO_keep;
_stencil_render_states [SRS_front_stencil_pass_z_pass_operation] = SO_keep;
_stencil_render_states [SRS_back_enable] = 0;
_stencil_render_states [SRS_reference] = 0;
_stencil_render_states [SRS_read_mask] = ~0;
_stencil_render_states [SRS_write_mask] = ~0;
_stencil_render_states [SRS_back_comparison_function] = SCF_always;
_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
_default = true;
_pre = false;
}
////////////////////////////////////////////////////////////////////
@ -55,8 +53,13 @@ StencilAttrib() {
////////////////////////////////////////////////////////////////////
INLINE void StencilAttrib::
set_render_state(unsigned int render_state_identifier, unsigned int render_state) {
if (_pre) {
_stencil_render_states [render_state_identifier] = render_state;
_default = false;
}
else {
// ERROR: set_render_state can only be called with a pre_make StencilAttrib
printf ("ERROR: set_render_state can only be called with a StencilAttrib.make_begin\n");
}
}
////////////////////////////////////////////////////////////////////

View File

@ -27,10 +27,49 @@
TypeHandle StencilAttrib::_type_handle;
char *StencilAttrib::
stencil_render_state_name_array [StencilAttrib::SRS_total] =
{
"SRS_front_enable",
"SRS_back_enable",
"SRS_front_comparison_function",
"SRS_front_stencil_fail_operation",
"SRS_front_stencil_pass_z_fail_operation",
"SRS_front_stencil_pass_z_pass_operation",
"SRS_reference",
"SRS_read_mask",
"SRS_write_mask",
"SRS_back_comparison_function",
"SRS_back_stencil_fail_operation",
"SRS_back_stencil_pass_z_fail_operation",
"SRS_back_stencil_pass_z_pass_operation",
};
////////////////////////////////////////////////////////////////////
// Function: StencilAttrib::make_begin
// Access: Published, Static
// Description: Constructs a new default and writable StencilAttrib.
// set_render_state can be called.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib::
make_begin() {
StencilAttrib *attrib = new StencilAttrib;
attrib -> _pre = true;
CPT(RenderAttrib) pt_attrib = attrib;
return pt_attrib;
}
////////////////////////////////////////////////////////////////////
// Function: StencilAttrib::make
// Access: Published, Static
// Description: Constructs a new StencilAttrib object.
// Description: Constructs a new default read-only StencilAttrib.
// set_render_state can not be called on the created
// object.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib::
make() {
@ -38,6 +77,29 @@ make() {
return return_new(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: StencilAttrib::make_end
// Access: Published
// Description: Constructs a final read-only StencilAttrib object
// from an existing StencilAttrib.
////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib::
make_end() {
StencilAttrib *attrib = new StencilAttrib;
StencilAttrib *original_attrib;
original_attrib = this;
int index;
for (index = 0; index < SRS_total; index++) {
attrib -> _stencil_render_states [index] =
original_attrib -> _stencil_render_states [index];
}
return return_new(attrib);
}
////////////////////////////////////////////////////////////////////
// Function: StencilAttrib::output
// Access: Public, Virtual
@ -45,9 +107,12 @@ make() {
////////////////////////////////////////////////////////////////////
void StencilAttrib::
output(ostream &out) const {
int index;
for (index = 0; index < SRS_total; index++) {
out << "(" << index << "," << _stencil_render_states [index] << ")";
out
<< "(" << stencil_render_state_name_array [index]
<< ", " << _stencil_render_states [index] << ")";
}
}
@ -71,24 +136,18 @@ compare_to_impl(const RenderAttrib *other) const {
const StencilAttrib *sa;
DCAST_INTO_R(sa, other, 0);
int a;
int b;
int index;
int compare_result = 0;
// quick test to see if both are default states
// which should be the most common case
if (_default && (_default == sa -> _default)) {
}
else {
int index;
for (index = 0; index < SRS_total; index++) {
if (_stencil_render_states [index] - sa -> _stencil_render_states [index]) {
// ?????
compare_result = -(index + 1);
a = (int) sa -> _stencil_render_states [index];
b = (int) _stencil_render_states [index];
if (compare_result = (a - b)) {
break;
}
}
}
return compare_result;
}
@ -182,5 +241,4 @@ fillin(DatagramIterator &scan, BamReader *manager) {
for (index = 0; index < SRS_total; index++) {
_stencil_render_states [index] = scan.get_int32();
}
_default = false;
}

View File

@ -38,20 +38,18 @@ PUBLISHED:
// enums are duplicated here from class StencilRenderStates for use in Python
enum StencilRenderState
{
SRS_clear_value,
SRS_reference,
SRS_read_mask,
SRS_write_mask,
SRS_front_enable,
SRS_back_enable,
SRS_front_comparison_function,
SRS_front_stencil_fail_operation,
SRS_front_stencil_pass_z_fail_operation,
SRS_front_stencil_pass_z_pass_operation,
SRS_back_enable,
SRS_reference,
SRS_read_mask,
SRS_write_mask,
SRS_back_comparison_function,
SRS_back_stencil_fail_operation,
SRS_back_stencil_pass_z_fail_operation,
@ -86,11 +84,15 @@ PUBLISHED:
SO_decrement_saturate,
};
static CPT(RenderAttrib) make_begin();
static CPT(RenderAttrib) make();
CPT(RenderAttrib) make_end();
INLINE void set_render_state (unsigned int render_state_identifier, unsigned int render_state);
INLINE unsigned int get_render_state (unsigned int render_state_identifier) const;
public:
static char *stencil_render_state_name_array [SRS_total];
virtual void output(ostream &out) const;
virtual void store_into_slot(AttribSlots *slots) const;
@ -100,7 +102,8 @@ protected:
private:
unsigned int _stencil_render_states [SRS_total];
bool _default;
public:
bool _pre;
public:
static void register_with_read_factory();