Add stencil support.

This commit is contained in:
aignacio_sf 2006-05-23 23:41:08 +00:00
parent 20d6d877e1
commit 3760491ac6
4 changed files with 93 additions and 17 deletions

View File

@ -28,7 +28,8 @@ DrawableRegion() :
_draw_buffer_type(RenderBuffer::T_back),
_flags(0),
_clear_color(0.0f, 0.0f, 0.0f, 0.0f),
_clear_depth(1.0f)
_clear_depth(1.0f),
_clear_stencil(0)
{
}
@ -43,7 +44,8 @@ DrawableRegion(const DrawableRegion &copy) :
_draw_buffer_type(copy._draw_buffer_type),
_flags(copy._flags),
_clear_color(copy._clear_color),
_clear_depth(copy._clear_depth)
_clear_depth(copy._clear_depth),
_clear_stencil(copy._clear_stencil)
{
}
@ -59,6 +61,7 @@ operator = (const DrawableRegion &copy) {
_flags = copy._flags;
_clear_color = copy._clear_color;
_clear_depth = copy._clear_depth;
_clear_stencil = copy._clear_stencil;
}
////////////////////////////////////////////////////////////////////
@ -72,6 +75,7 @@ copy_clear_settings(const DrawableRegion &copy) {
_flags = (_flags & ~F_clear_all) | (copy._flags & F_clear_all);
_clear_color = copy._clear_color;
_clear_depth = copy._clear_depth;
_clear_stencil = copy._clear_stencil;
}
////////////////////////////////////////////////////////////////////
@ -134,6 +138,36 @@ get_clear_depth_active() const {
return ((_flags & F_clear_depth_active) != 0);
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_stencil_active
// Access: Published
// Description: Toggles the flag that indicates whether the stencil
// buffer should be cleared every frame. If this is
// true, the stencil buffer will be cleared to the value
// indicated by set_clear_stencil(); otherwise, it will be
// left alone.
////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion::
set_clear_stencil_active(bool clear_stencil_active) {
if (clear_stencil_active) {
_flags |= F_clear_stencil_active;
} else {
_flags &= ~F_clear_stencil_active;
}
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::get_clear_stencil_active
// Access: Published
// Description: Returns the current setting of the flag that
// indicates whether the color buffer should be cleared
// every frame. See set_clear_stencil_active().
////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion::
get_clear_stencil_active() const {
return ((_flags & F_clear_stencil_active) != 0);
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_color
// Access: Published
@ -189,6 +223,33 @@ INLINE float DrawableRegion::
get_clear_depth() const {
return _clear_depth;
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_stencil
// Access: Published
// Description: Sets the clear stencil to the indicated value. This is
// the value that will be used to clear the stencil buffer
// every frame, but only if get_clear_color_active()
// returns true. If get_clear_stencil_active() returns
// false, this is meaningless.
////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion::
set_clear_stencil(const unsigned int stencil) {
_clear_stencil = stencil;
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::get_clear_stencil
// Access: Published
// Description: Returns the current clear stencil value. This is
// the value that will be used to clear the stencil buffer
// every frame, but only if get_clear_stencil_active()
// returns true. If get_clear_stencil_active() returns
// false, this is meaningless.
////////////////////////////////////////////////////////////////////
INLINE unsigned int DrawableRegion::
get_clear_stencil() const {
return _clear_stencil;
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::disable_clears
@ -200,6 +261,7 @@ INLINE void DrawableRegion::
disable_clears() {
set_clear_color_active(false);
set_clear_depth_active(false);
set_clear_stencil_active(false);
}
////////////////////////////////////////////////////////////////////

View File

@ -49,12 +49,18 @@ PUBLISHED:
INLINE void set_clear_depth_active(bool clear_depth_active);
INLINE bool get_clear_depth_active() const;
INLINE void set_clear_stencil_active(bool clear_stencil_active);
INLINE bool get_clear_stencil_active() const;
INLINE void set_clear_color(const Colorf &color);
INLINE const Colorf &get_clear_color() const;
INLINE void set_clear_depth(float depth);
INLINE float get_clear_depth() const;
INLINE void set_clear_stencil(unsigned int stencil);
INLINE unsigned int get_clear_stencil() const;
INLINE void disable_clears();
INLINE bool is_any_clear_active() const;
@ -72,12 +78,14 @@ private:
enum Flags {
F_clear_color_active = 0x0001,
F_clear_depth_active = 0x0002,
F_clear_all = 0x0003, // = all of the above
F_clear_stencil_active = 0x0004,
F_clear_all = 0x0007, // = all of the above
};
int _flags;
Colorf _clear_color;
float _clear_depth;
unsigned int _clear_stencil;
};
#include "drawableRegion.I"

View File

@ -127,6 +127,7 @@ GraphicsOutput(GraphicsPipe *pipe,
// depth.
set_clear_color_active(true);
set_clear_depth_active(true);
set_clear_stencil_active(true);
switch (background_color.get_num_words()) {
case 1:
@ -815,6 +816,7 @@ make_cube_map(const string &name, int size, NodePath &camera_rig,
// each display region.
buffer->set_clear_color_active(false);
buffer->set_clear_depth_active(false);
buffer->set_clear_stencil_active(false);
PT(Lens) lens = new PerspectiveLens;
lens->set_fov(90.0f);

View File

@ -725,6 +725,10 @@ clear(DrawableRegion *clearable) {
clear_buffer_type |= RenderBuffer::T_depth;
set_depth_clear_value(clearable->get_clear_depth());
}
if (clearable->get_clear_stencil_active()) {
clear_buffer_type |= RenderBuffer::T_stencil;
set_stencil_clear_value(clearable->get_clear_stencil());
}
if (clear_buffer_type != 0) {
do_clear(get_render_buffer(clear_buffer_type,