mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
Add stencil support.
This commit is contained in:
parent
20d6d877e1
commit
3760491ac6
@ -20,22 +20,23 @@
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DrawableRegion::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DrawableRegion::
|
||||
DrawableRegion() :
|
||||
DrawableRegion() :
|
||||
_screenshot_buffer_type(RenderBuffer::T_front),
|
||||
_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)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DrawableRegion::Copy Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE DrawableRegion::
|
||||
DrawableRegion(const DrawableRegion ©) :
|
||||
@ -43,14 +44,15 @@ DrawableRegion(const DrawableRegion ©) :
|
||||
_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)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: DrawableRegion::Copy Assignment Operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void DrawableRegion::
|
||||
operator = (const DrawableRegion ©) {
|
||||
@ -59,6 +61,7 @@ operator = (const DrawableRegion ©) {
|
||||
_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 ©) {
|
||||
_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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -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;
|
||||
@ -70,14 +76,16 @@ protected:
|
||||
private:
|
||||
// This data needs to be cycled.
|
||||
enum Flags {
|
||||
F_clear_color_active = 0x0001,
|
||||
F_clear_depth_active = 0x0002,
|
||||
F_clear_all = 0x0003, // = all of the above
|
||||
F_clear_color_active = 0x0001,
|
||||
F_clear_depth_active = 0x0002,
|
||||
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"
|
||||
|
@ -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:
|
||||
@ -241,7 +242,7 @@ clear_render_textures() {
|
||||
// * RTP_aux_rgba_2
|
||||
// * RTP_aux_rgba_3
|
||||
//
|
||||
// If you do not specify a bitplane to attach the
|
||||
// If you do not specify a bitplane to attach the
|
||||
// texture to, this routine will use a default based
|
||||
// on the texture's format:
|
||||
//
|
||||
@ -254,7 +255,7 @@ clear_render_textures() {
|
||||
// For example, if you pass in an F_rgba texture and
|
||||
// order that it be attached to RTP_depth, it will turn
|
||||
// into an F_depth_component texture.
|
||||
//
|
||||
//
|
||||
// Also see make_texture_buffer(), which is a
|
||||
// higher-level interface for preparing
|
||||
// render-to-a-texture mode.
|
||||
@ -268,7 +269,7 @@ add_render_texture(Texture *tex, RenderTextureMode mode,
|
||||
MutexHolder holder(_lock);
|
||||
|
||||
throw_event("render-texture-targets-changed");
|
||||
|
||||
|
||||
// Create texture if necessary.
|
||||
if (tex == (Texture *)NULL) {
|
||||
tex = new Texture(get_name());
|
||||
@ -288,7 +289,7 @@ add_render_texture(Texture *tex, RenderTextureMode mode,
|
||||
plane = RTP_color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set the texture's format to match the bitplane.
|
||||
// (And validate the bitplane, while we're at it).
|
||||
|
||||
@ -602,12 +603,12 @@ create_texture_card_vdata(int x, int y)
|
||||
vertex.add_data3f(Vertexf::rfu(-1.0f, 0.0f, -1.0f));
|
||||
vertex.add_data3f(Vertexf::rfu( 1.0f, 0.0f, 1.0f));
|
||||
vertex.add_data3f(Vertexf::rfu( 1.0f, 0.0f, -1.0f));
|
||||
|
||||
|
||||
texcoord.add_data2f( 0.0f, yhi);
|
||||
texcoord.add_data2f( 0.0f, 0.0f);
|
||||
texcoord.add_data2f( xhi, yhi);
|
||||
texcoord.add_data2f( xhi, 0.0f);
|
||||
|
||||
|
||||
normal.add_data3f(LVector3f::back());
|
||||
normal.add_data3f(LVector3f::back());
|
||||
normal.add_data3f(LVector3f::back());
|
||||
@ -738,8 +739,8 @@ make_texture_buffer(const string &name, int x_size, int y_size,
|
||||
FrameBufferProperties::FM_multisample |
|
||||
FrameBufferProperties::FM_hardware |
|
||||
FrameBufferProperties::FM_software;
|
||||
props.set_frame_buffer_mode(props.get_frame_buffer_mode() & (~clear));
|
||||
|
||||
props.set_frame_buffer_mode(props.get_frame_buffer_mode() & (~clear));
|
||||
|
||||
GraphicsOutput *buffer = get_gsg()->get_engine()->
|
||||
make_output(get_gsg()->get_pipe(),
|
||||
name, get_sort()-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);
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user