Panda3D
 All Classes Functions Variables Enumerations
stencilRenderStates.cxx
00001 // Filename: stencilRenderStates.cxx
00002 // Created by:  aignacio (17May06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "graphicsStateGuardian.h"
00016 #include "stencilRenderStates.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: StencilRenderStates::Constructor
00020 //  Description: Constructor.  All data is set to the default.
00021 ////////////////////////////////////////////////////////////////////
00022 StencilRenderStates::
00023 StencilRenderStates (GraphicsStateGuardian *gsg) {
00024 
00025   int index;
00026 
00027   // clear all
00028   for (index = 0; index < SRS_total; index++) {
00029     _stencil_render_state_array [index] = 0;
00030     _stencil_function_array [index] = 0;
00031   }
00032 
00033   // set default render states
00034   set_stencil_render_state (false, SRS_reference, 0);
00035 
00036   set_stencil_render_state (false, SRS_read_mask, ~0);
00037   set_stencil_render_state (false, SRS_write_mask, ~0);
00038 
00039   set_stencil_render_state (false, SRS_front_enable, 0);
00040   set_stencil_render_state (false, SRS_front_comparison_function, SCF_always);
00041   set_stencil_render_state (false, SRS_front_stencil_fail_operation, SO_keep);
00042   set_stencil_render_state (false, SRS_front_stencil_pass_z_fail_operation, SO_keep);
00043   set_stencil_render_state (false, SRS_front_stencil_pass_z_pass_operation, SO_keep);
00044 
00045   set_stencil_render_state (false, SRS_back_enable, 0);
00046   set_stencil_render_state (false, SRS_back_comparison_function, SCF_always);
00047   set_stencil_render_state (false, SRS_back_stencil_fail_operation, SO_keep);
00048   set_stencil_render_state (false, SRS_back_stencil_pass_z_fail_operation, SO_keep);
00049   set_stencil_render_state (false, SRS_back_stencil_pass_z_pass_operation, SO_keep);
00050 
00051   _gsg = gsg;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: StencilRenderStates::Destructor
00056 //  Description:
00057 ////////////////////////////////////////////////////////////////////
00058 StencilRenderStates::
00059 ~StencilRenderStates (void) {
00060 
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: StencilRenderStates::set_stencil_render_state
00065 //  Description: Sets the current render state for the specified
00066 //               stencil render state. The execute_function
00067 //               parameter can be used to defer the actual setting
00068 //               of the render state at the API level.  This is
00069 //               useful for the OpenGL API where certain render
00070 //               states are not independent/atomic (i.e.
00071 //               glStencilFunc and glStencilOp).
00072 ////////////////////////////////////////////////////////////////////
00073 void StencilRenderStates::
00074 set_stencil_render_state (bool execute_function, StencilRenderStates::StencilRenderState stencil_render_state, StencilType value) {
00075 
00076   // DEBUG
00077   if (false) {
00078     printf ("SRS %d %d %d \n", execute_function, stencil_render_state, value);
00079   }
00080 
00081   _stencil_render_state_array [stencil_render_state] = value;
00082 
00083   if (execute_function) {
00084     StencilFunction stencil_function;
00085 
00086     stencil_function = _stencil_function_array [stencil_render_state];
00087     if (stencil_function) {
00088       stencil_function (stencil_render_state, this);
00089     }
00090   }
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: StencilRenderStates::get_stencil_render_state
00095 //  Description: Gets the current render state for the specified
00096 //               stencil render state.
00097 ////////////////////////////////////////////////////////////////////
00098 StencilType StencilRenderStates::
00099 get_stencil_render_state (StencilRenderStates::StencilRenderState stencil_render_state) {
00100   return _stencil_render_state_array [stencil_render_state];
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: StencilRenderStates::set_stencil_function
00105 //  Description: Registers an API specific callback for setting a
00106 //               specified stencil render state.
00107 ////////////////////////////////////////////////////////////////////
00108 void StencilRenderStates::
00109 set_stencil_function (StencilRenderStates::StencilRenderState stencil_render_state, StencilFunction stencil_function) {
00110   _stencil_function_array [stencil_render_state] = stencil_function;
00111 }
 All Classes Functions Variables Enumerations