Simplify oddly redundant StencilAttrib implementation.

Also add RenderState::compare_mask().
This commit is contained in:
rdb 2014-12-03 22:44:07 +01:00
parent 15b88283b2
commit 0473fa7ead
15 changed files with 370 additions and 865 deletions

View File

@ -43,7 +43,6 @@
windowHandle.I windowHandle.h \ windowHandle.I windowHandle.h \
windowProperties.I windowProperties.h \ windowProperties.I windowProperties.h \
renderBuffer.h \ renderBuffer.h \
stencilRenderStates.h \
stereoDisplayRegion.I stereoDisplayRegion.h \ stereoDisplayRegion.I stereoDisplayRegion.h \
displaySearchParameters.h \ displaySearchParameters.h \
displayInformation.h \ displayInformation.h \
@ -80,7 +79,6 @@
parasiteBuffer.cxx \ parasiteBuffer.cxx \
windowHandle.cxx \ windowHandle.cxx \
windowProperties.cxx \ windowProperties.cxx \
stencilRenderStates.cxx \
stereoDisplayRegion.cxx \ stereoDisplayRegion.cxx \
subprocessWindow.cxx \ subprocessWindow.cxx \
touchInfo.cxx touchInfo.cxx
@ -118,7 +116,6 @@
windowHandle.I windowHandle.h \ windowHandle.I windowHandle.h \
windowProperties.I windowProperties.h \ windowProperties.I windowProperties.h \
renderBuffer.h \ renderBuffer.h \
stencilRenderStates.h \
stereoDisplayRegion.I stereoDisplayRegion.h \ stereoDisplayRegion.I stereoDisplayRegion.h \
subprocessWindow.h subprocessWindow.I \ subprocessWindow.h subprocessWindow.I \
subprocessWindowBuffer.h subprocessWindowBuffer.I \ subprocessWindowBuffer.h subprocessWindowBuffer.I \

View File

@ -258,8 +258,6 @@ GraphicsStateGuardian(CoordinateSystem internal_coordinate_system,
// it is rendered. // it is rendered.
_runtime_color_scale = false; _runtime_color_scale = false;
_stencil_render_states = 0;
// The default is no shader support. // The default is no shader support.
_auto_detect_shader_model = SM_00; _auto_detect_shader_model = SM_00;
_shader_model = SM_00; _shader_model = SM_00;
@ -279,11 +277,6 @@ GraphicsStateGuardian::
~GraphicsStateGuardian() { ~GraphicsStateGuardian() {
remove_gsg(this); remove_gsg(this);
if (_stencil_render_states) {
delete _stencil_render_states;
_stencil_render_states = 0;
}
if (_shader_generator) { if (_shader_generator) {
delete _shader_generator; delete _shader_generator;
_shader_generator = 0; _shader_generator = 0;
@ -1988,12 +1981,6 @@ reset() {
_last_max_stage_index = 0; _last_max_stage_index = 0;
_is_valid = true; _is_valid = true;
if (_stencil_render_states) {
delete _stencil_render_states;
_stencil_render_states = 0;
}
_stencil_render_states = new StencilRenderStates(this);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -45,7 +45,6 @@
#include "texture.h" #include "texture.h"
#include "occlusionQueryContext.h" #include "occlusionQueryContext.h"
#include "timerQueryContext.h" #include "timerQueryContext.h"
#include "stencilRenderStates.h"
#include "loader.h" #include "loader.h"
#include "shaderAttrib.h" #include "shaderAttrib.h"
#include "texGenAttrib.h" #include "texGenAttrib.h"
@ -532,8 +531,6 @@ protected:
int _stereo_buffer_mask; int _stereo_buffer_mask;
StencilRenderStates *_stencil_render_states;
int _auto_detect_shader_model; int _auto_detect_shader_model;
int _shader_model; int _shader_model;

View File

@ -12,7 +12,6 @@
#include "nativeWindowHandle.cxx" #include "nativeWindowHandle.cxx"
#include "parasiteBuffer.cxx" #include "parasiteBuffer.cxx"
#include "standardMunger.cxx" #include "standardMunger.cxx"
#include "stencilRenderStates.cxx"
#include "touchInfo.cxx" #include "touchInfo.cxx"
#include "stereoDisplayRegion.cxx" #include "stereoDisplayRegion.cxx"
#include "subprocessWindow.cxx" #include "subprocessWindow.cxx"

View File

@ -1,111 +0,0 @@
// Filename: stencilRenderStates.cxx
// Created by: aignacio (17May06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#include "graphicsStateGuardian.h"
#include "stencilRenderStates.h"
////////////////////////////////////////////////////////////////////
// Function: StencilRenderStates::Constructor
// Description: Constructor. All data is set to the default.
////////////////////////////////////////////////////////////////////
StencilRenderStates::
StencilRenderStates (GraphicsStateGuardian *gsg) {
int index;
// clear all
for (index = 0; index < SRS_total; index++) {
_stencil_render_state_array [index] = 0;
_stencil_function_array [index] = 0;
}
// set default render states
set_stencil_render_state (false, SRS_reference, 0);
set_stencil_render_state (false, SRS_read_mask, ~0);
set_stencil_render_state (false, SRS_write_mask, ~0);
set_stencil_render_state (false, SRS_front_enable, 0);
set_stencil_render_state (false, SRS_front_comparison_function, SCF_always);
set_stencil_render_state (false, SRS_front_stencil_fail_operation, SO_keep);
set_stencil_render_state (false, SRS_front_stencil_pass_z_fail_operation, SO_keep);
set_stencil_render_state (false, SRS_front_stencil_pass_z_pass_operation, SO_keep);
set_stencil_render_state (false, SRS_back_enable, 0);
set_stencil_render_state (false, SRS_back_comparison_function, SCF_always);
set_stencil_render_state (false, SRS_back_stencil_fail_operation, SO_keep);
set_stencil_render_state (false, SRS_back_stencil_pass_z_fail_operation, SO_keep);
set_stencil_render_state (false, SRS_back_stencil_pass_z_pass_operation, SO_keep);
_gsg = gsg;
}
////////////////////////////////////////////////////////////////////
// Function: StencilRenderStates::Destructor
// Description:
////////////////////////////////////////////////////////////////////
StencilRenderStates::
~StencilRenderStates (void) {
}
////////////////////////////////////////////////////////////////////
// Function: StencilRenderStates::set_stencil_render_state
// Description: Sets the current render state for the specified
// stencil render state. The execute_function
// parameter can be used to defer the actual setting
// of the render state at the API level. This is
// useful for the OpenGL API where certain render
// states are not independent/atomic (i.e.
// glStencilFunc and glStencilOp).
////////////////////////////////////////////////////////////////////
void StencilRenderStates::
set_stencil_render_state (bool execute_function, StencilRenderStates::StencilRenderState stencil_render_state, StencilType value) {
// DEBUG
if (false) {
printf ("SRS %d %d %d \n", execute_function, stencil_render_state, value);
}
_stencil_render_state_array [stencil_render_state] = value;
if (execute_function) {
StencilFunction stencil_function;
stencil_function = _stencil_function_array [stencil_render_state];
if (stencil_function) {
stencil_function (stencil_render_state, this);
}
}
}
////////////////////////////////////////////////////////////////////
// Function: StencilRenderStates::get_stencil_render_state
// Description: Gets the current render state for the specified
// stencil render state.
////////////////////////////////////////////////////////////////////
StencilType StencilRenderStates::
get_stencil_render_state (StencilRenderStates::StencilRenderState stencil_render_state) {
return _stencil_render_state_array [stencil_render_state];
}
////////////////////////////////////////////////////////////////////
// Function: StencilRenderStates::set_stencil_function
// Description: Registers an API specific callback for setting a
// specified stencil render state.
////////////////////////////////////////////////////////////////////
void StencilRenderStates::
set_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilFunction stencil_function) {
_stencil_function_array [stencil_render_state] = stencil_function;
}

View File

@ -1,101 +0,0 @@
// Filename: stencilRenderStates.h
// Created by: aignacio (17May06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef STENCILRENDERSTATES_H
#define STENCILRENDERSTATES_H
class GraphicsStateGuardian;
typedef unsigned int StencilType;
////////////////////////////////////////////////////////////////////
// Class : StencilRenderStates
// Description : An abstract cross-platform class for setting stencil
// buffer render states. Each gsg needs to create its
// own low-level API specific functions on how to set
// each render state. The "set_stencil_render_state"
// function can be used in an immediate-mode fashion.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_DISPLAY StencilRenderStates {
PUBLISHED:
enum StencilRenderState
{
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,
SRS_clear,
SRS_clear_value,
SRS_total,
SRS_first = 0,
};
enum StencilComparisonFunction
{
SCF_never,
SCF_less_than,
SCF_equal,
SCF_less_than_or_equal,
SCF_greater_than,
SCF_not_equal,
SCF_greater_than_or_equal,
SCF_always,
};
enum StencilOperation
{
SO_keep,
SO_zero,
SO_replace,
SO_increment,
SO_decrement,
SO_invert,
SO_increment_saturate,
SO_decrement_saturate,
};
public:
typedef void (*StencilFunction) (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states);
StencilRenderStates (GraphicsStateGuardian *gsg);
~StencilRenderStates (void);
void set_stencil_render_state (bool execute_function, StencilRenderStates::StencilRenderState stencil_render_state, StencilType value);
StencilType get_stencil_render_state (StencilRenderStates::StencilRenderState stencil_render_state);
void set_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilFunction stencil_function);
GraphicsStateGuardian *_gsg;
private:
StencilType _stencil_render_state_array [SRS_total];
StencilFunction _stencil_function_array [SRS_total];
};
#endif

View File

@ -2074,9 +2074,6 @@ reset() {
PRINT_REFCNT(dxgsg8, _d3d_device); PRINT_REFCNT(dxgsg8, _d3d_device);
void dx_set_stencil_functions (StencilRenderStates *stencil_render_states);
dx_set_stencil_functions (_stencil_render_states);
// Now that the GSG has been initialized, make it available for // Now that the GSG has been initialized, make it available for
// optimizations. // optimizations.
add_gsg(this); add_gsg(this);
@ -4310,9 +4307,7 @@ draw_indexed_primitive_up(D3DPRIMITIVETYPE primitive_type,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// DX stencil code section // DX stencil code section
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
static int dx_stencil_comparison_function_array[] = {
static int dx_stencil_comparison_function_array [ ] =
{
D3DCMP_NEVER, D3DCMP_NEVER,
D3DCMP_LESS, D3DCMP_LESS,
D3DCMP_EQUAL, D3DCMP_EQUAL,
@ -4323,8 +4318,7 @@ static int dx_stencil_comparison_function_array [ ] =
D3DCMP_ALWAYS, D3DCMP_ALWAYS,
}; };
static int dx_stencil_operation_array [ ] = static int dx_stencil_operation_array[] = {
{
D3DSTENCILOP_KEEP, D3DSTENCILOP_KEEP,
D3DSTENCILOP_ZERO, D3DSTENCILOP_ZERO,
D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE,
@ -4336,84 +4330,6 @@ static int dx_stencil_operation_array [ ] =
D3DSTENCILOP_DECRSAT, D3DSTENCILOP_DECRSAT,
}; };
void dx_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
StencilType render_state_value;
DXGraphicsStateGuardian8 *gsg;
LPDIRECT3DDEVICE8 device;
gsg = (DXGraphicsStateGuardian8 *) stencil_render_states -> _gsg;
device = gsg->get_d3d_device();
render_state_value = stencil_render_states -> get_stencil_render_state (stencil_render_state);
if (dxgsg8_cat.is_debug()) {
dxgsg8_cat.debug()
<< "SRS: " << StencilAttrib::stencil_render_state_name_array [stencil_render_state] << ", " << render_state_value << "\n";
}
switch (stencil_render_state)
{
case StencilRenderStates::SRS_front_enable:
device->SetRenderState (D3DRS_STENCILENABLE, render_state_value);
break;
case StencilRenderStates::SRS_back_enable:
// not supported in DX8
break;
case StencilRenderStates::SRS_front_comparison_function:
device->SetRenderState (D3DRS_STENCILFUNC, dx_stencil_comparison_function_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_fail_operation:
device->SetRenderState (D3DRS_STENCILFAIL, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_pass_z_fail_operation:
device->SetRenderState (D3DRS_STENCILZFAIL, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_pass_z_pass_operation:
device->SetRenderState (D3DRS_STENCILPASS, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_reference:
device->SetRenderState (D3DRS_STENCILREF, render_state_value);
break;
case StencilRenderStates::SRS_read_mask:
device->SetRenderState (D3DRS_STENCILMASK, render_state_value);
break;
case StencilRenderStates::SRS_write_mask:
device->SetRenderState (D3DRS_STENCILWRITEMASK, render_state_value);
break;
case StencilRenderStates::SRS_back_comparison_function:
// not supported in DX8
break;
case StencilRenderStates::SRS_back_stencil_fail_operation:
// not supported in DX8
break;
case StencilRenderStates::SRS_back_stencil_pass_z_fail_operation:
// not supported in DX8
break;
case StencilRenderStates::SRS_back_stencil_pass_z_pass_operation:
// not supported in DX8
break;
default:
break;
}
}
void dx_set_stencil_functions (StencilRenderStates *stencil_render_states) {
if (stencil_render_states) {
StencilRenderStates::StencilRenderState stencil_render_state;
for (stencil_render_state = StencilRenderStates::SRS_first; stencil_render_state < StencilRenderStates::SRS_total; stencil_render_state = (StencilRenderStates::StencilRenderState) ((int) stencil_render_state + 1)) {
stencil_render_states -> set_stencil_function (stencil_render_state, dx_stencil_function);
}
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::do_issue_stencil // Function: DXGraphicsStateGuardian8::do_issue_stencil
// Access: Protected // Access: Protected
@ -4421,48 +4337,56 @@ void dx_set_stencil_functions (StencilRenderStates *stencil_render_states) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8:: void DXGraphicsStateGuardian8::
do_issue_stencil() { do_issue_stencil() {
if (!_supports_stencil) { if (!_supports_stencil) {
return; return;
} }
StencilRenderStates *stencil_render_states; const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib(StencilAttrib::get_class_slot()));
const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib_def(StencilAttrib::get_class_slot()));
stencil_render_states = this -> _stencil_render_states;
if (stencil && stencil_render_states) {
if (dxgsg8_cat.is_debug()) { if (stencil != (const StencilAttrib *)NULL) {
// DEBUG
if (false) {
dxgsg8_cat.debug() << "STENCIL STATE CHANGE\n"; dxgsg8_cat.debug() << "STENCIL STATE CHANGE\n";
dxgsg8_cat.debug() << "\n" dxgsg8_cat.debug() << "\n"
<< "SRS_front_enable " << stencil -> get_render_state (StencilAttrib::SRS_front_enable) << "\n" << "SRS_front_comparison_function " << stencil->get_render_state(StencilAttrib::SRS_front_comparison_function) << "\n"
<< "SRS_front_comparison_function " << stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function) << "\n" << "SRS_front_stencil_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation) << "\n"
<< "SRS_front_stencil_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation) << "\n" << "SRS_front_stencil_pass_z_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n"
<< "SRS_front_stencil_pass_z_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n" << "SRS_front_stencil_pass_z_pass_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n"
<< "SRS_front_stencil_pass_z_pass_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n" << "SRS_reference " << stencil->get_render_state(StencilAttrib::SRS_reference) << "\n"
<< "SRS_reference " << stencil -> get_render_state (StencilAttrib::SRS_reference) << "\n" << "SRS_read_mask " << stencil->get_render_state(StencilAttrib::SRS_read_mask) << "\n"
<< "SRS_read_mask " << stencil -> get_render_state (StencilAttrib::SRS_read_mask) << "\n" << "SRS_write_mask " << stencil->get_render_state(StencilAttrib::SRS_write_mask) << "\n";
<< "SRS_write_mask " << stencil -> get_render_state (StencilAttrib::SRS_write_mask) << "\n";
} }
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, stencil -> get_render_state (StencilAttrib::SRS_front_enable)); unsigned int front_compare;
if (stencil -> get_render_state (StencilAttrib::SRS_front_enable)) { front_compare = stencil->get_render_state(StencilAttrib::SRS_front_comparison_function);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_comparison_function, stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function)); if (front_compare != RenderAttrib::M_none) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation)); set_render_state(D3DRS_STENCILENABLE, TRUE);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation)); set_render_state(D3DRS_STENCILFUNC, dx_stencil_comparison_function_array[front_compare]);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_pass_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation)); set_render_state(D3DRS_STENCILFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation)]);
set_render_state(D3DRS_STENCILZFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation)]);
set_render_state(D3DRS_STENCILPASS, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation)]);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_reference, stencil -> get_render_state (StencilAttrib::SRS_reference)); set_render_state(D3DRS_STENCILREF, stencil->get_render_state(StencilAttrib::SRS_reference));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_read_mask, stencil -> get_render_state (StencilAttrib::SRS_read_mask)); set_render_state(D3DRS_STENCILMASK, stencil->get_render_state(StencilAttrib::SRS_read_mask));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_write_mask, stencil -> get_render_state (StencilAttrib::SRS_write_mask)); set_render_state(D3DRS_STENCILWRITEMASK, stencil->get_render_state(StencilAttrib::SRS_write_mask));
} } else {
} set_render_state(D3DRS_STENCILENABLE, FALSE);
else {
if (dxgsg8_cat.is_debug()) {
dxgsg8_cat.debug() << "STENCIL STATE CHANGE TO OFF \n";
} }
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, 0); if (stencil->get_render_state(StencilAttrib::SRS_clear)) {
_d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, 0, 0.0f, stencil->get_render_state(StencilAttrib::SRS_clear_value));
}
} else {
// DEBUG
if (false) {
dxgsg8_cat.debug() << "STENCIL STATE CHANGE TO OFF\n";
}
set_render_state(D3DRS_STENCILENABLE, FALSE);
} }
} }

View File

@ -2769,9 +2769,6 @@ reset() {
PRINT_REFCNT(dxgsg9, _d3d_device); PRINT_REFCNT(dxgsg9, _d3d_device);
void dx_set_stencil_functions (StencilRenderStates *stencil_render_states);
dx_set_stencil_functions (_stencil_render_states);
// Now that the GSG has been initialized, make it available for // Now that the GSG has been initialized, make it available for
// optimizations. // optimizations.
add_gsg(this); add_gsg(this);
@ -5261,9 +5258,7 @@ check_dx_allocation (HRESULT result, int allocation_size, int attempts)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// DX stencil code section // DX stencil code section
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
static int dx_stencil_comparison_function_array[] = {
static int dx_stencil_comparison_function_array [ ] =
{
D3DCMP_NEVER, D3DCMP_NEVER,
D3DCMP_LESS, D3DCMP_LESS,
D3DCMP_EQUAL, D3DCMP_EQUAL,
@ -5274,8 +5269,7 @@ static int dx_stencil_comparison_function_array [ ] =
D3DCMP_ALWAYS, D3DCMP_ALWAYS,
}; };
static int dx_stencil_operation_array [ ] = static int dx_stencil_operation_array[] = {
{
D3DSTENCILOP_KEEP, D3DSTENCILOP_KEEP,
D3DSTENCILOP_ZERO, D3DSTENCILOP_ZERO,
D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE,
@ -5287,93 +5281,6 @@ static int dx_stencil_operation_array [ ] =
D3DSTENCILOP_DECRSAT, D3DSTENCILOP_DECRSAT,
}; };
void dx_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
StencilType render_state_value;
DXGraphicsStateGuardian9 *gsg;
gsg = (DXGraphicsStateGuardian9 *) stencil_render_states -> _gsg;
render_state_value = stencil_render_states -> get_stencil_render_state (stencil_render_state);
// DEBUG
if (false) {
dxgsg9_cat.debug()
<< "SRS: " << StencilAttrib::stencil_render_state_name_array [stencil_render_state] << ", " << render_state_value << "\n";
}
switch (stencil_render_state)
{
case StencilRenderStates::SRS_front_enable:
gsg -> set_render_state (D3DRS_STENCILENABLE, render_state_value);
break;
case StencilRenderStates::SRS_back_enable:
if (gsg -> get_supports_two_sided_stencil()) {
gsg -> set_render_state (D3DRS_TWOSIDEDSTENCILMODE, render_state_value);
}
break;
case StencilRenderStates::SRS_front_comparison_function:
gsg -> set_render_state (D3DRS_STENCILFUNC, dx_stencil_comparison_function_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_fail_operation:
gsg -> set_render_state (D3DRS_STENCILFAIL, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_pass_z_fail_operation:
gsg -> set_render_state (D3DRS_STENCILZFAIL, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_front_stencil_pass_z_pass_operation:
gsg -> set_render_state (D3DRS_STENCILPASS, dx_stencil_operation_array [render_state_value]);
break;
case StencilRenderStates::SRS_reference:
gsg -> set_render_state (D3DRS_STENCILREF, render_state_value);
break;
case StencilRenderStates::SRS_read_mask:
gsg -> set_render_state (D3DRS_STENCILMASK, render_state_value);
break;
case StencilRenderStates::SRS_write_mask:
gsg -> set_render_state (D3DRS_STENCILWRITEMASK, render_state_value);
break;
case StencilRenderStates::SRS_back_comparison_function:
if (gsg -> get_supports_two_sided_stencil()) {
gsg -> set_render_state (D3DRS_CCW_STENCILFUNC, dx_stencil_comparison_function_array [render_state_value]);
}
break;
case StencilRenderStates::SRS_back_stencil_fail_operation:
if (gsg -> get_supports_two_sided_stencil()) {
gsg -> set_render_state (D3DRS_CCW_STENCILFAIL, dx_stencil_operation_array [render_state_value]);
}
break;
case StencilRenderStates::SRS_back_stencil_pass_z_fail_operation:
if (gsg -> get_supports_two_sided_stencil()) {
gsg -> set_render_state (D3DRS_CCW_STENCILZFAIL, dx_stencil_operation_array [render_state_value]);
}
break;
case StencilRenderStates::SRS_back_stencil_pass_z_pass_operation:
if (gsg -> get_supports_two_sided_stencil()) {
gsg -> set_render_state (D3DRS_CCW_STENCILPASS, dx_stencil_operation_array [render_state_value]);
}
break;
default:
break;
}
}
void dx_set_stencil_functions (StencilRenderStates *stencil_render_states) {
if (stencil_render_states) {
StencilRenderStates::StencilRenderState stencil_render_state;
for (stencil_render_state = StencilRenderStates::SRS_first; stencil_render_state < StencilRenderStates::SRS_total; stencil_render_state = (StencilRenderStates::StencilRenderState) ((int) stencil_render_state + 1)) {
stencil_render_states -> set_stencil_function (stencil_render_state, dx_stencil_function);
}
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::do_issue_stencil // Function: DXGraphicsStateGuardian9::do_issue_stencil
// Access: Protected // Access: Protected
@ -5385,70 +5292,84 @@ do_issue_stencil() {
return; return;
} }
StencilRenderStates *stencil_render_states; const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib(StencilAttrib::get_class_slot()));
const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib_def(StencilAttrib::get_class_slot()));
stencil_render_states = this -> _stencil_render_states;
if (stencil && stencil_render_states) {
if (stencil != (const StencilAttrib *)NULL) {
// DEBUG // DEBUG
if (false) { if (false) {
dxgsg9_cat.debug() << "STENCIL STATE CHANGE\n"; dxgsg9_cat.debug() << "STENCIL STATE CHANGE\n";
dxgsg9_cat.debug() << "\n" dxgsg9_cat.debug() << "\n"
<< "SRS_front_enable " << stencil -> get_render_state (StencilAttrib::SRS_front_enable) << "\n" << "SRS_front_comparison_function " << stencil->get_render_state(StencilAttrib::SRS_front_comparison_function) << "\n"
<< "SRS_back_enable " << stencil -> get_render_state (StencilAttrib::SRS_back_enable) << "\n" << "SRS_front_stencil_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation) << "\n"
<< "SRS_front_comparison_function " << stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function) << "\n" << "SRS_front_stencil_pass_z_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n"
<< "SRS_front_stencil_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation) << "\n" << "SRS_front_stencil_pass_z_pass_operation " << stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n"
<< "SRS_front_stencil_pass_z_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n" << "SRS_reference " << stencil->get_render_state(StencilAttrib::SRS_reference) << "\n"
<< "SRS_front_stencil_pass_z_pass_operation " << stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n" << "SRS_read_mask " << stencil->get_render_state(StencilAttrib::SRS_read_mask) << "\n"
<< "SRS_reference " << stencil -> get_render_state (StencilAttrib::SRS_reference) << "\n" << "SRS_write_mask " << stencil->get_render_state(StencilAttrib::SRS_write_mask) << "\n"
<< "SRS_read_mask " << stencil -> get_render_state (StencilAttrib::SRS_read_mask) << "\n" << "SRS_back_comparison_function " << stencil->get_render_state(StencilAttrib::SRS_back_comparison_function) << "\n"
<< "SRS_write_mask " << stencil -> get_render_state (StencilAttrib::SRS_write_mask) << "\n" << "SRS_back_stencil_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_back_stencil_fail_operation) << "\n"
<< "SRS_back_comparison_function " << stencil -> get_render_state (StencilAttrib::SRS_back_comparison_function) << "\n" << "SRS_back_stencil_pass_z_fail_operation " << stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation) << "\n"
<< "SRS_back_stencil_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_back_stencil_fail_operation) << "\n" << "SRS_back_stencil_pass_z_pass_operation " << stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation) << "\n";
<< "SRS_back_stencil_pass_z_fail_operation " << stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_fail_operation) << "\n"
<< "SRS_back_stencil_pass_z_pass_operation " << stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_pass_operation) << "\n";
} }
bool on; bool on = false;
on = false; unsigned int front_compare;
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, stencil -> get_render_state (StencilAttrib::SRS_front_enable)); front_compare = stencil->get_render_state(StencilAttrib::SRS_front_comparison_function);
if (stencil -> get_render_state (StencilAttrib::SRS_front_enable)) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_comparison_function, stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function)); if (front_compare != RenderAttrib::M_none) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation)); set_render_state(D3DRS_STENCILENABLE, TRUE);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation)); set_render_state(D3DRS_STENCILFUNC, dx_stencil_comparison_function_array[front_compare]);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_pass_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation)); set_render_state(D3DRS_STENCILFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation)]);
set_render_state(D3DRS_STENCILZFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation)]);
set_render_state(D3DRS_STENCILPASS, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation)]);
on = true; on = true;
} else {
set_render_state(D3DRS_STENCILENABLE, FALSE);
} }
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_enable, stencil -> get_render_state (StencilAttrib::SRS_back_enable)); if (_supports_two_sided_stencil) {
if (stencil -> get_render_state (StencilAttrib::SRS_back_enable)) { unsigned int back_compare;
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_comparison_function, stencil -> get_render_state (StencilAttrib::SRS_back_comparison_function)); back_compare = stencil->get_render_state(StencilAttrib::SRS_back_comparison_function);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_fail_operation));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_pass_z_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_fail_operation)); if (back_compare != RenderAttrib::M_none) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_pass_z_pass_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_pass_operation)); set_render_state(D3DRS_TWOSIDEDSTENCILMODE, TRUE);
set_render_state(D3DRS_CCW_STENCILFUNC, dx_stencil_comparison_function_array[back_compare]);
set_render_state(D3DRS_CCW_STENCILFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_back_stencil_fail_operation)]);
set_render_state(D3DRS_CCW_STENCILZFAIL, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation)]);
set_render_state(D3DRS_CCW_STENCILPASS, dx_stencil_operation_array[
stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation)]);
on = true; on = true;
} else {
set_render_state(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
}
} }
if (on) { if (on) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_reference, stencil -> get_render_state (StencilAttrib::SRS_reference)); set_render_state(D3DRS_STENCILREF, stencil->get_render_state(StencilAttrib::SRS_reference));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_read_mask, stencil -> get_render_state (StencilAttrib::SRS_read_mask)); set_render_state(D3DRS_STENCILMASK, stencil->get_render_state(StencilAttrib::SRS_read_mask));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_write_mask, stencil -> get_render_state (StencilAttrib::SRS_write_mask)); set_render_state(D3DRS_STENCILWRITEMASK, stencil->get_render_state(StencilAttrib::SRS_write_mask));
} }
if (stencil -> get_render_state (StencilAttrib::SRS_clear)) { if (stencil->get_render_state(StencilAttrib::SRS_clear)) {
_d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, 0, 0.0f, stencil -> get_render_state (StencilAttrib::SRS_clear_value)); _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, 0, 0.0f, stencil->get_render_state(StencilAttrib::SRS_clear_value));
} }
}
else {
} else {
// DEBUG // DEBUG
if (false) { if (false) {
dxgsg9_cat.debug() << "STENCIL STATE CHANGE TO OFF \n"; dxgsg9_cat.debug() << "STENCIL STATE CHANGE TO OFF\n";
} }
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, 0); set_render_state(D3DRS_STENCILENABLE, FALSE);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_enable, 0); if (_supports_two_sided_stencil) {
set_render_state(D3DRS_TWOSIDEDSTENCILMODE, FALSE);
}
} }
} }

View File

@ -337,11 +337,6 @@ CLP(GraphicsStateGuardian)::
} }
close_gsg(); close_gsg();
if (_stencil_render_states) {
delete _stencil_render_states;
_stencil_render_states = 0;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -2103,9 +2098,6 @@ reset() {
report_my_gl_errors(); report_my_gl_errors();
void gl_set_stencil_functions (StencilRenderStates *stencil_render_states);
gl_set_stencil_functions(_stencil_render_states);
#if defined(HAVE_CG) && !defined(OPENGLES) #if defined(HAVE_CG) && !defined(OPENGLES)
typedef struct { typedef struct {
@ -11511,18 +11503,7 @@ bind_fbo(GLuint fbo) {
// GL stencil code section // GL stencil code section
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
static int gl_stencil_comparison_function_array [ ] = { static int gl_stencil_operations_array[] = {
GL_NEVER,
GL_LESS,
GL_EQUAL,
GL_LEQUAL,
GL_GREATER,
GL_NOTEQUAL,
GL_GEQUAL,
GL_ALWAYS,
};
static int gl_stencil_operations_array [ ] = {
GL_KEEP, GL_KEEP,
GL_ZERO, GL_ZERO,
GL_REPLACE, GL_REPLACE,
@ -11539,144 +11520,6 @@ static int gl_stencil_operations_array [ ] = {
GL_DECR, GL_DECR,
}; };
void __glActiveStencilFace (GraphicsStateGuardian *gsg, GLenum face) {
CLP(GraphicsStateGuardian) *glgsg;
glgsg = (CLP(GraphicsStateGuardian) *) gsg;
if (gsg -> get_supports_two_sided_stencil ( ) &&
glgsg -> _glActiveStencilFaceEXT) {
if (face == GL_FRONT) {
// glActiveStencilFaceEXT (GL_FRONT);
glgsg -> _glActiveStencilFaceEXT (GL_FRONT);
}
else {
// glActiveStencilFaceEXT (GL_BACK);
glgsg -> _glActiveStencilFaceEXT (GL_BACK);
}
}
}
void gl_front_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
__glActiveStencilFace (stencil_render_states -> _gsg, GL_FRONT);
glStencilFunc
(
gl_stencil_comparison_function_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_front_comparison_function)],
stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_reference),
stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_read_mask)
);
}
void gl_front_stencil_operation (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
__glActiveStencilFace (stencil_render_states -> _gsg, GL_FRONT);
glStencilOp
(
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_front_stencil_fail_operation)],
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_front_stencil_pass_z_fail_operation)],
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_front_stencil_pass_z_pass_operation)]
);
}
void gl_back_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
bool supports_two_sided_stencil;
supports_two_sided_stencil = stencil_render_states -> _gsg -> get_supports_two_sided_stencil ( );
if (supports_two_sided_stencil) {
__glActiveStencilFace (stencil_render_states -> _gsg, GL_BACK);
glStencilFunc
(
gl_stencil_comparison_function_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_back_comparison_function)],
stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_reference),
stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_read_mask)
);
}
}
void gl_back_stencil_operation (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
bool supports_two_sided_stencil;
supports_two_sided_stencil = stencil_render_states -> _gsg -> get_supports_two_sided_stencil ( );
if (supports_two_sided_stencil) {
__glActiveStencilFace (stencil_render_states -> _gsg, GL_BACK);
glStencilOp
(
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_back_stencil_fail_operation)],
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_back_stencil_pass_z_fail_operation)],
gl_stencil_operations_array [stencil_render_states -> get_stencil_render_state (StencilRenderStates::SRS_back_stencil_pass_z_pass_operation)]
);
}
}
void gl_front_back_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
gl_front_stencil_function (stencil_render_state, stencil_render_states);
gl_back_stencil_function (stencil_render_state, stencil_render_states);
}
void gl_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilRenderStates *stencil_render_states) {
StencilType render_state_value;
bool supports_two_sided_stencil;
supports_two_sided_stencil = stencil_render_states -> _gsg -> get_supports_two_sided_stencil ( );
render_state_value = stencil_render_states -> get_stencil_render_state (stencil_render_state);
switch (stencil_render_state) {
case StencilRenderStates::SRS_front_enable:
if (render_state_value) {
glEnable (GL_STENCIL_TEST);
}
else {
glDisable (GL_STENCIL_TEST);
}
break;
#ifndef OPENGLES
case StencilRenderStates::SRS_back_enable:
if (supports_two_sided_stencil) {
if (render_state_value) {
glEnable (GL_STENCIL_TEST_TWO_SIDE_EXT);
}
else {
glDisable (GL_STENCIL_TEST_TWO_SIDE_EXT);
}
}
break;
#endif
case StencilRenderStates::SRS_write_mask:
glStencilMask (render_state_value);
break;
default:
break;
}
}
void gl_set_stencil_functions (StencilRenderStates *stencil_render_states) {
if (stencil_render_states) {
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_front_enable, gl_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_back_enable, gl_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_front_comparison_function, gl_front_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_front_stencil_fail_operation, gl_front_stencil_operation);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_front_stencil_pass_z_fail_operation, gl_front_stencil_operation);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_front_stencil_pass_z_pass_operation, gl_front_stencil_operation);
// GL seems to support different read masks and/or reference values for front and back, but DX does not.
// This needs to be cross-platform so do it the DX way by setting the same read mask and reference for both front and back.
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_reference, gl_front_back_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_read_mask, gl_front_back_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_write_mask, gl_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_back_comparison_function, gl_back_stencil_function);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_back_stencil_fail_operation, gl_back_stencil_operation);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_back_stencil_pass_z_fail_operation, gl_back_stencil_operation);
stencil_render_states -> set_stencil_function (StencilRenderStates::SRS_back_stencil_pass_z_pass_operation, gl_back_stencil_operation);
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::do_issue_stencil // Function: GLGraphicsStateGuardian::do_issue_stencil
// Access: Protected // Access: Protected
@ -11688,72 +11531,84 @@ do_issue_stencil() {
return; return;
} }
const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib_def(StencilAttrib::get_class_slot())); const StencilAttrib *stencil = DCAST(StencilAttrib, _target_rs->get_attrib(StencilAttrib::get_class_slot()));
StencilRenderStates *stencil_render_states;
stencil_render_states = this -> _stencil_render_states;
if (stencil && stencil_render_states) {
if (stencil != (const StencilAttrib *)NULL) {
// DEBUG // DEBUG
if (false) { if (false) {
GLCAT.debug() << "STENCIL STATE CHANGE\n"; GLCAT.debug() << "STENCIL STATE CHANGE\n";
GLCAT.debug() << "\n" GLCAT.debug() << "\n"
<< "SRS_front_enable " << (int)stencil -> get_render_state (StencilAttrib::SRS_front_enable) << "\n" << "SRS_front_comparison_function " << (int)stencil->get_render_state(StencilAttrib::SRS_front_comparison_function) << "\n"
<< "SRS_back_enable " << (int)stencil -> get_render_state (StencilAttrib::SRS_back_enable) << "\n" << "SRS_front_stencil_fail_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation) << "\n"
<< "SRS_front_comparison_function " << (int)stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function) << "\n" << "SRS_front_stencil_pass_z_fail_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n"
<< "SRS_front_stencil_fail_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation) << "\n" << "SRS_front_stencil_pass_z_pass_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n"
<< "SRS_front_stencil_pass_z_fail_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation) << "\n" << "SRS_reference " << (int)stencil->get_render_state(StencilAttrib::SRS_reference) << "\n"
<< "SRS_front_stencil_pass_z_pass_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation) << "\n" << "SRS_read_mask " << (int)stencil->get_render_state(StencilAttrib::SRS_read_mask) << "\n"
<< "SRS_reference " << (int)stencil -> get_render_state (StencilAttrib::SRS_reference) << "\n" << "SRS_write_mask " << (int)stencil->get_render_state(StencilAttrib::SRS_write_mask) << "\n"
<< "SRS_read_mask " << (int)stencil -> get_render_state (StencilAttrib::SRS_read_mask) << "\n" << "SRS_back_comparison_function " << (int)stencil->get_render_state(StencilAttrib::SRS_back_comparison_function) << "\n"
<< "SRS_write_mask " << (int)stencil -> get_render_state (StencilAttrib::SRS_write_mask) << "\n" << "SRS_back_stencil_fail_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_back_stencil_fail_operation) << "\n"
<< "SRS_back_comparison_function " << (int)stencil -> get_render_state (StencilAttrib::SRS_back_comparison_function) << "\n" << "SRS_back_stencil_pass_z_fail_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation) << "\n"
<< "SRS_back_stencil_fail_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_back_stencil_fail_operation) << "\n" << "SRS_back_stencil_pass_z_pass_operation " << (int)stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation) << "\n";
<< "SRS_back_stencil_pass_z_fail_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_fail_operation) << "\n"
<< "SRS_back_stencil_pass_z_pass_operation " << (int)stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_pass_operation) << "\n";
} }
{ if (_supports_two_sided_stencil) {
bool on; //TODO: add support for OpenGL 2.0-style glStencilFuncSeparate.
unsigned int back_compare;
back_compare = stencil->get_render_state(StencilAttrib::SRS_back_comparison_function);
on = false; if (back_compare != RenderAttrib::M_none) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, stencil -> get_render_state (StencilAttrib::SRS_front_enable)); glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
if (stencil -> get_render_state (StencilAttrib::SRS_front_enable)) { _glActiveStencilFaceEXT(GL_BACK);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_comparison_function, stencil -> get_render_state (StencilAttrib::SRS_front_comparison_function));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_fail_operation)); glStencilFunc(
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_fail_operation)); PANDA_TO_GL_COMPAREFUNC(back_compare),
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_stencil_pass_z_pass_operation, stencil -> get_render_state (StencilAttrib::SRS_front_stencil_pass_z_pass_operation)); stencil->get_render_state(StencilAttrib::SRS_reference),
on = true; stencil->get_render_state(StencilAttrib::SRS_read_mask));
glStencilOp(
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_back_stencil_fail_operation)],
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_fail_operation)],
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_back_stencil_pass_z_pass_operation)]
);
glStencilMask(stencil->get_render_state(StencilAttrib::SRS_write_mask));
} else {
glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
} }
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_enable, stencil -> get_render_state (StencilAttrib::SRS_back_enable)); _glActiveStencilFaceEXT(GL_FRONT);
if (stencil -> get_render_state (StencilAttrib::SRS_back_enable)) {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_comparison_function, stencil -> get_render_state (StencilAttrib::SRS_back_comparison_function));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_fail_operation));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_pass_z_fail_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_fail_operation));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_stencil_pass_z_pass_operation, stencil -> get_render_state (StencilAttrib::SRS_back_stencil_pass_z_pass_operation));
on = true;
} }
if (on) { unsigned int front_compare;
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_reference, stencil -> get_render_state (StencilAttrib::SRS_reference)); front_compare = stencil->get_render_state(StencilAttrib::SRS_front_comparison_function);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_read_mask, stencil -> get_render_state (StencilAttrib::SRS_read_mask));
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_write_mask, stencil -> get_render_state (StencilAttrib::SRS_write_mask)); if (front_compare != RenderAttrib::M_none) {
} glEnable(GL_STENCIL_TEST);
glStencilFunc(
PANDA_TO_GL_COMPAREFUNC(front_compare),
stencil->get_render_state(StencilAttrib::SRS_reference),
stencil->get_render_state(StencilAttrib::SRS_read_mask));
glStencilOp(
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_front_stencil_fail_operation)],
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_fail_operation)],
gl_stencil_operations_array[stencil->get_render_state(StencilAttrib::SRS_front_stencil_pass_z_pass_operation)]
);
glStencilMask(stencil->get_render_state(StencilAttrib::SRS_write_mask));
} else {
glDisable(GL_STENCIL_TEST);
} }
if (stencil -> get_render_state (StencilAttrib::SRS_clear)) { if (stencil->get_render_state(StencilAttrib::SRS_clear)) {
GLbitfield mask = 0;
// clear stencil buffer // clear stencil buffer
glClearStencil(stencil -> get_render_state (StencilAttrib::SRS_clear_value)); glClearStencil(stencil->get_render_state(StencilAttrib::SRS_clear_value));
mask |= GL_STENCIL_BUFFER_BIT; glClear(GL_STENCIL_BUFFER_BIT);
glClear(mask);
} }
} else {
glDisable(GL_STENCIL_TEST);
if (_supports_two_sided_stencil) {
glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
} }
else {
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_front_enable, 0);
stencil_render_states -> set_stencil_render_state (true, StencilRenderStates::SRS_back_enable, 0);
} }
} }

View File

@ -230,6 +230,31 @@ compare_sort(const RenderState &other) const {
return 0; return 0;
} }
////////////////////////////////////////////////////////////////////
// Function: RenderState::compare_mask
// Access: Published
// Description: This version of compare_to takes a slot mask that
// indicates which attributes to include in the
// comparison. Unlike compare_to, this method
// compares the attributes by pointer.
////////////////////////////////////////////////////////////////////
int RenderState::
compare_mask(const RenderState &other, SlotMask compare_mask) const {
SlotMask mask = (_filled_slots | other._filled_slots) & compare_mask;
int slot = mask.get_lowest_on_bit();
while (slot >= 0) {
const RenderAttrib *a = _attributes[slot]._attrib;
const RenderAttrib *b = other._attributes[slot]._attrib;
if (a != b) {
return a < b ? -1 : 1;
}
mask.clear_bit(slot);
slot = mask.get_lowest_on_bit();
}
return 0;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: RenderState::cull_callback // Function: RenderState::cull_callback
// Access: Published // Access: Published

View File

@ -67,6 +67,7 @@ public:
PUBLISHED: PUBLISHED:
int compare_to(const RenderState &other) const; int compare_to(const RenderState &other) const;
int compare_sort(const RenderState &other) const; int compare_sort(const RenderState &other) const;
int compare_mask(const RenderState &other, SlotMask compare_mask) const;
INLINE size_t get_hash() const; INLINE size_t get_hash() const;
INLINE bool is_empty() const; INLINE bool is_empty() const;

View File

@ -18,6 +18,6 @@
// Description: Returns render state. // Description: Returns render state.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE unsigned int StencilAttrib:: INLINE unsigned int StencilAttrib::
get_render_state(unsigned int render_state_identifier) const { get_render_state(StencilRenderState render_state_identifier) const {
return _stencil_render_states [render_state_identifier]; return _stencil_render_states[(int)render_state_identifier];
} }

View File

@ -24,11 +24,8 @@ TypeHandle StencilAttrib::_type_handle;
int StencilAttrib::_attrib_slot; int StencilAttrib::_attrib_slot;
const char *StencilAttrib:: const char *StencilAttrib::
stencil_render_state_name_array [StencilAttrib::SRS_total] = stencil_render_state_name_array[StencilAttrib::SRS_total] =
{ {
"SRS_front_enable",
"SRS_back_enable",
"SRS_front_comparison_function", "SRS_front_comparison_function",
"SRS_front_stencil_fail_operation", "SRS_front_stencil_fail_operation",
"SRS_front_stencil_pass_z_fail_operation", "SRS_front_stencil_pass_z_fail_operation",
@ -55,11 +52,7 @@ stencil_render_state_name_array [StencilAttrib::SRS_total] =
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
StencilAttrib:: StencilAttrib::
StencilAttrib() { StencilAttrib() {
_stencil_render_states [SRS_front_comparison_function] = M_none;
_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_fail_operation] = SO_keep;
_stencil_render_states [SRS_front_stencil_pass_z_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_front_stencil_pass_z_pass_operation] = SO_keep;
@ -68,7 +61,7 @@ StencilAttrib() {
_stencil_render_states [SRS_read_mask] = ~0; _stencil_render_states [SRS_read_mask] = ~0;
_stencil_render_states [SRS_write_mask] = ~0; _stencil_render_states [SRS_write_mask] = ~0;
_stencil_render_states [SRS_back_comparison_function] = SCF_always; _stencil_render_states [SRS_back_comparison_function] = M_none;
_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep; _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_fail_operation] = SO_keep;
_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep; _stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
@ -84,10 +77,8 @@ StencilAttrib() {
// turned off. // turned off.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib:: CPT(RenderAttrib) StencilAttrib::
make_off() make_off() {
{
StencilAttrib *attrib = new StencilAttrib; StencilAttrib *attrib = new StencilAttrib;
return return_new(attrib); return return_new(attrib);
} }
@ -110,19 +101,20 @@ make_default() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib:: CPT(RenderAttrib) StencilAttrib::
make( make(
unsigned int front_enable, bool front_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask) unsigned int write_mask)
{ {
StencilAttrib *attrib = new StencilAttrib; StencilAttrib *attrib = new StencilAttrib;
attrib->_stencil_render_states [SRS_front_enable] = front_enable; if (!front_enable) {
attrib->_stencil_render_states [SRS_back_enable] = 0; front_comparison_function = M_none;
}
attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
@ -133,7 +125,7 @@ make(
attrib->_stencil_render_states [SRS_read_mask] = read_mask; attrib->_stencil_render_states [SRS_read_mask] = read_mask;
attrib->_stencil_render_states [SRS_write_mask] = write_mask; attrib->_stencil_render_states [SRS_write_mask] = write_mask;
attrib->_stencil_render_states [SRS_back_comparison_function] = SCF_always; attrib->_stencil_render_states [SRS_back_comparison_function] = M_none;
attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
@ -148,24 +140,29 @@ make(
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib:: CPT(RenderAttrib) StencilAttrib::
make_2_sided( make_2_sided(
unsigned int front_enable, bool front_enable,
unsigned int back_enable, bool back_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int back_comparison_function, PandaCompareFunc back_comparison_function,
unsigned int back_stencil_fail_operation, StencilOperation back_stencil_fail_operation,
unsigned int back_stencil_pass_z_fail_operation, StencilOperation back_stencil_pass_z_fail_operation,
unsigned int back_stencil_pass_z_pass_operation) StencilOperation back_stencil_pass_z_pass_operation)
{ {
StencilAttrib *attrib = new StencilAttrib; StencilAttrib *attrib = new StencilAttrib;
attrib->_stencil_render_states [SRS_front_enable] = front_enable; if (!front_enable) {
attrib->_stencil_render_states [SRS_back_enable] = back_enable; front_comparison_function = M_none;
}
if (!back_enable) {
back_comparison_function = M_none;
}
attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
@ -191,21 +188,22 @@ make_2_sided(
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib:: CPT(RenderAttrib) StencilAttrib::
make_with_clear( make_with_clear(
unsigned int front_enable, bool front_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int clear, bool clear,
unsigned int clear_value) unsigned int clear_value)
{ {
StencilAttrib *attrib = new StencilAttrib; StencilAttrib *attrib = new StencilAttrib;
attrib->_stencil_render_states [SRS_front_enable] = front_enable; if (!front_enable) {
attrib->_stencil_render_states [SRS_back_enable] = 0; front_comparison_function = M_none;
}
attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
@ -216,7 +214,7 @@ make_with_clear(
attrib->_stencil_render_states [SRS_read_mask] = read_mask; attrib->_stencil_render_states [SRS_read_mask] = read_mask;
attrib->_stencil_render_states [SRS_write_mask] = write_mask; attrib->_stencil_render_states [SRS_write_mask] = write_mask;
attrib->_stencil_render_states [SRS_back_comparison_function] = SCF_always; attrib->_stencil_render_states [SRS_back_comparison_function] = M_none;
attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_fail_operation] = SO_keep;
attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_pass_z_fail_operation] = SO_keep;
attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep; attrib->_stencil_render_states [SRS_back_stencil_pass_z_pass_operation] = SO_keep;
@ -234,26 +232,31 @@ make_with_clear(
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
CPT(RenderAttrib) StencilAttrib:: CPT(RenderAttrib) StencilAttrib::
make_2_sided_with_clear( make_2_sided_with_clear(
unsigned int front_enable, bool front_enable,
unsigned int back_enable, bool back_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int back_comparison_function, PandaCompareFunc back_comparison_function,
unsigned int back_stencil_fail_operation, StencilOperation back_stencil_fail_operation,
unsigned int back_stencil_pass_z_fail_operation, StencilOperation back_stencil_pass_z_fail_operation,
unsigned int back_stencil_pass_z_pass_operation, StencilOperation back_stencil_pass_z_pass_operation,
unsigned int clear, bool clear,
unsigned int clear_value) unsigned int clear_value)
{ {
StencilAttrib *attrib = new StencilAttrib; StencilAttrib *attrib = new StencilAttrib;
attrib->_stencil_render_states [SRS_front_enable] = front_enable; if (!front_enable) {
attrib->_stencil_render_states [SRS_back_enable] = back_enable; front_comparison_function = M_none;
}
if (!back_enable) {
back_comparison_function = M_none;
}
attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function; attrib->_stencil_render_states [SRS_front_comparison_function] = front_comparison_function;
attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation; attrib->_stencil_render_states [SRS_front_stencil_fail_operation] = stencil_fail_operation;
@ -316,9 +319,9 @@ compare_to_impl(const RenderAttrib *other) const {
int index; int index;
int compare_result = 0; int compare_result = 0;
for (index = 0; index < SRS_total; index++) { for (index = 0; index < SRS_total; ++index) {
a = (int) sa -> _stencil_render_states [index]; a = (int) sa -> _stencil_render_states[index];
b = (int) _stencil_render_states [index]; b = (int) _stencil_render_states[index];
compare_result = (a - b); compare_result = (a - b);
if (compare_result) { if (compare_result) {
break; break;
@ -368,9 +371,8 @@ void StencilAttrib::
write_datagram(BamWriter *manager, Datagram &dg) { write_datagram(BamWriter *manager, Datagram &dg) {
RenderAttrib::write_datagram(manager, dg); RenderAttrib::write_datagram(manager, dg);
int index; for (int index = 0; index < SRS_total; ++index) {
for (index = 0; index < SRS_total; index++) { dg.add_uint32(_stencil_render_states[index]);
dg.add_int32(_stencil_render_states [index]);
} }
} }
@ -405,8 +407,29 @@ void StencilAttrib::
fillin(DatagramIterator &scan, BamReader *manager) { fillin(DatagramIterator &scan, BamReader *manager) {
RenderAttrib::fillin(scan, manager); RenderAttrib::fillin(scan, manager);
int index; if (manager->get_file_minor_ver() < 35) {
for (index = 0; index < SRS_total; index++) { unsigned int front_enable, back_enable;
_stencil_render_states [index] = scan.get_int32(); front_enable = scan.get_int32();
back_enable = scan.get_int32();
for (int index = 0; index < SRS_total; ++index) {
_stencil_render_states[index] = scan.get_int32();
}
if (front_enable) {
_stencil_render_states[SRS_front_comparison_function]++;
} else {
_stencil_render_states[SRS_front_comparison_function] = M_none;
}
if (back_enable) {
_stencil_render_states[SRS_back_comparison_function]++;
} else {
_stencil_render_states[SRS_back_comparison_function] = M_none;
}
} else {
for (int index = 0; index < SRS_total; ++index) {
_stencil_render_states[index] = scan.get_uint32();
}
} }
} }

View File

@ -35,13 +35,8 @@ private:
StencilAttrib(); StencilAttrib();
PUBLISHED: PUBLISHED:
// enums are duplicated here from class StencilRenderStates for use in Python // enums are duplicated here from class StencilRenderStates for use in Python
enum StencilRenderState enum StencilRenderState {
{
SRS_front_enable,
SRS_back_enable,
SRS_front_comparison_function, SRS_front_comparison_function,
SRS_front_stencil_fail_operation, SRS_front_stencil_fail_operation,
SRS_front_stencil_pass_z_fail_operation, SRS_front_stencil_pass_z_fail_operation,
@ -60,24 +55,21 @@ PUBLISHED:
SRS_clear_value, SRS_clear_value,
SRS_total, SRS_total,
SRS_first = 0,
}; };
enum StencilComparisonFunction // Exists purely for backward compatibility.
{ enum StencilComparisonFunction {
SCF_never, SCF_never = M_never,
SCF_less_than, SCF_less_than = M_less,
SCF_equal, SCF_equal = M_equal,
SCF_less_than_or_equal, SCF_less_than_or_equal = M_less_equal,
SCF_greater_than, SCF_greater_than = M_greater,
SCF_not_equal, SCF_not_equal = M_not_equal,
SCF_greater_than_or_equal, SCF_greater_than_or_equal = M_greater_equal,
SCF_always, SCF_always = M_always,
}; };
enum StencilOperation enum StencilOperation {
{
SO_keep, SO_keep,
SO_zero, SO_zero,
SO_replace, SO_replace,
@ -88,69 +80,64 @@ PUBLISHED:
SO_decrement_saturate, SO_decrement_saturate,
}; };
enum StencilMask
{
SM_default = ~0,
};
static CPT(RenderAttrib) make_off(); static CPT(RenderAttrib) make_off();
static CPT(RenderAttrib) make_default(); static CPT(RenderAttrib) make_default();
static CPT(RenderAttrib) make( static CPT(RenderAttrib) make(
unsigned int front_enable, bool front_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask); unsigned int write_mask);
static CPT(RenderAttrib) make_2_sided( static CPT(RenderAttrib) make_2_sided(
unsigned int front_enable, bool front_enable,
unsigned int back_enable, bool back_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int back_comparison_function, PandaCompareFunc back_comparison_function,
unsigned int back_stencil_fail_operation, StencilOperation back_stencil_fail_operation,
unsigned int back_stencil_pass_z_fail_operation, StencilOperation back_stencil_pass_z_fail_operation,
unsigned int back_stencil_pass_z_pass_operation); StencilOperation back_stencil_pass_z_pass_operation);
static CPT(RenderAttrib) make_with_clear( static CPT(RenderAttrib) make_with_clear(
unsigned int front_enable, bool front_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int clear, bool clear,
unsigned int clear_value); unsigned int clear_value);
static CPT(RenderAttrib) make_2_sided_with_clear( static CPT(RenderAttrib) make_2_sided_with_clear(
unsigned int front_enable, bool front_enable,
unsigned int back_enable, bool back_enable,
unsigned int front_comparison_function, PandaCompareFunc front_comparison_function,
unsigned int stencil_fail_operation, StencilOperation stencil_fail_operation,
unsigned int stencil_pass_z_fail_operation, StencilOperation stencil_pass_z_fail_operation,
unsigned int front_stencil_pass_z_pass_operation, StencilOperation front_stencil_pass_z_pass_operation,
unsigned int reference, unsigned int reference,
unsigned int read_mask, unsigned int read_mask,
unsigned int write_mask, unsigned int write_mask,
unsigned int back_comparison_function, PandaCompareFunc back_comparison_function,
unsigned int back_stencil_fail_operation, StencilOperation back_stencil_fail_operation,
unsigned int back_stencil_pass_z_fail_operation, StencilOperation back_stencil_pass_z_fail_operation,
unsigned int back_stencil_pass_z_pass_operation, StencilOperation back_stencil_pass_z_pass_operation,
unsigned int clear, bool clear,
unsigned int clear_value); unsigned int clear_value);
INLINE unsigned int get_render_state (unsigned int render_state_identifier) const; INLINE unsigned int get_render_state(StencilRenderState render_state_identifier) const;
public: public:
static const char *stencil_render_state_name_array [SRS_total]; static const char *stencil_render_state_name_array [SRS_total];

View File

@ -33,7 +33,7 @@ static const unsigned short _bam_major_ver = 6;
// Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData. // Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData.
static const unsigned short _bam_first_minor_ver = 14; static const unsigned short _bam_first_minor_ver = 14;
static const unsigned short _bam_minor_ver = 34; static const unsigned short _bam_minor_ver = 35;
// Bumped to minor version 14 on 12/19/07 to change default ColorAttrib. // Bumped to minor version 14 on 12/19/07 to change default ColorAttrib.
// Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort. // Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort.
// Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level. // Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level.
@ -55,5 +55,6 @@ static const unsigned short _bam_minor_ver = 34;
// Bumped to minor version 32 on 6/11/12 to add Texture::_has_read_mipmaps. // Bumped to minor version 32 on 6/11/12 to add Texture::_has_read_mipmaps.
// Bumped to minor version 33 on 8/17/13 to add UvScrollNode::_w_speed. // Bumped to minor version 33 on 8/17/13 to add UvScrollNode::_w_speed.
// Bumped to minor version 34 on 9/16/14 to add ScissorAttrib::_off. // Bumped to minor version 34 on 9/16/14 to add ScissorAttrib::_off.
// Bumped to minor version 35 on 12/3/14 to change StencilAttrib.
#endif #endif