Refactored code for glClear - added aux bitplane clears

This commit is contained in:
Josh Yelon 2008-02-21 19:55:40 +00:00
parent 7bb510a3ef
commit b98c5f0bf5
18 changed files with 319 additions and 329 deletions

View File

@ -25,12 +25,13 @@
INLINE DrawableRegion:: INLINE DrawableRegion::
DrawableRegion() : DrawableRegion() :
_screenshot_buffer_type(RenderBuffer::T_front), _screenshot_buffer_type(RenderBuffer::T_front),
_draw_buffer_type(RenderBuffer::T_back), _draw_buffer_type(RenderBuffer::T_back)
_flags(0),
_clear_color(0.0f, 0.0f, 0.0f, 0.0f),
_clear_depth(1.0f),
_clear_stencil(0)
{ {
for (int i=0; i<RTP_COUNT; i++) {
_clear_active[i] = false;
_clear_value[i] = Colorf(0.0f, 0.0f, 0.0f, 0.0f);
}
_clear_value[RTP_depth] = Colorf(1.0f,1.0f,1.0f,1.0f);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -41,12 +42,12 @@ DrawableRegion() :
INLINE DrawableRegion:: INLINE DrawableRegion::
DrawableRegion(const DrawableRegion &copy) : DrawableRegion(const DrawableRegion &copy) :
_screenshot_buffer_type(copy._screenshot_buffer_type), _screenshot_buffer_type(copy._screenshot_buffer_type),
_draw_buffer_type(copy._draw_buffer_type), _draw_buffer_type(copy._draw_buffer_type)
_flags(copy._flags),
_clear_color(copy._clear_color),
_clear_depth(copy._clear_depth),
_clear_stencil(copy._clear_stencil)
{ {
for (int i=0; i<RTP_COUNT; i++) {
_clear_active[i] = copy._clear_active[i];
_clear_value[i] = copy._clear_value[i];
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -58,10 +59,10 @@ INLINE void DrawableRegion::
operator = (const DrawableRegion &copy) { operator = (const DrawableRegion &copy) {
_screenshot_buffer_type = copy._screenshot_buffer_type; _screenshot_buffer_type = copy._screenshot_buffer_type;
_draw_buffer_type = copy._draw_buffer_type; _draw_buffer_type = copy._draw_buffer_type;
_flags = copy._flags; for (int i=0; i<RTP_COUNT; i++) {
_clear_color = copy._clear_color; _clear_active[i] = copy._clear_active[i];
_clear_depth = copy._clear_depth; _clear_value[i] = copy._clear_value[i];
_clear_stencil = copy._clear_stencil; }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -72,10 +73,10 @@ operator = (const DrawableRegion &copy) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
copy_clear_settings(const DrawableRegion &copy) { copy_clear_settings(const DrawableRegion &copy) {
_flags = (_flags & ~F_clear_all) | (copy._flags & F_clear_all); for (int i=0; i<RTP_COUNT; i++) {
_clear_color = copy._clear_color; _clear_active[i] = copy._clear_active[i];
_clear_depth = copy._clear_depth; _clear_value[i] = copy._clear_value[i];
_clear_stencil = copy._clear_stencil; }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -89,11 +90,7 @@ copy_clear_settings(const DrawableRegion &copy) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_color_active(bool clear_color_active) { set_clear_color_active(bool clear_color_active) {
if (clear_color_active) { _clear_active[RTP_color] = clear_color_active;
_flags |= F_clear_color_active;
} else {
_flags &= ~F_clear_color_active;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -105,7 +102,7 @@ set_clear_color_active(bool clear_color_active) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion:: INLINE bool DrawableRegion::
get_clear_color_active() const { get_clear_color_active() const {
return ((_flags & F_clear_color_active) != 0); return _clear_active[RTP_color];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -119,11 +116,7 @@ get_clear_color_active() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_depth_active(bool clear_depth_active) { set_clear_depth_active(bool clear_depth_active) {
if (clear_depth_active) { _clear_active[RTP_depth] = clear_depth_active;
_flags |= F_clear_depth_active;
} else {
_flags &= ~F_clear_depth_active;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -135,7 +128,7 @@ set_clear_depth_active(bool clear_depth_active) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion:: INLINE bool DrawableRegion::
get_clear_depth_active() const { get_clear_depth_active() const {
return ((_flags & F_clear_depth_active) != 0); return _clear_active[RTP_depth];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -149,11 +142,7 @@ get_clear_depth_active() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_stencil_active(bool clear_stencil_active) { set_clear_stencil_active(bool clear_stencil_active) {
if (clear_stencil_active) { _clear_active[RTP_stencil] = clear_stencil_active;
_flags |= F_clear_stencil_active;
} else {
_flags &= ~F_clear_stencil_active;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -165,7 +154,29 @@ set_clear_stencil_active(bool clear_stencil_active) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion:: INLINE bool DrawableRegion::
get_clear_stencil_active() const { get_clear_stencil_active() const {
return ((_flags & F_clear_stencil_active) != 0); return _clear_active[RTP_stencil];
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_active
// Access: Published
// Description: Sets the clear-active flag for any bitplane.
////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion::
set_clear_active(int id, bool clear_active) {
nassertv((id >= 0)&&(id < RTP_COUNT));
_clear_active[id] = clear_active;
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::get_clear_active
// Access: Published
// Description: Gets the clear-active flag for any bitplane.
////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion::
get_clear_active(int id) const {
nassertr((id >= 0)&&(id < RTP_COUNT), false);
return _clear_active[id];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -179,7 +190,7 @@ get_clear_stencil_active() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_color(const Colorf &color) { set_clear_color(const Colorf &color) {
_clear_color = color; _clear_value[RTP_color] = color;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -193,7 +204,7 @@ set_clear_color(const Colorf &color) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE const Colorf &DrawableRegion:: INLINE const Colorf &DrawableRegion::
get_clear_color() const { get_clear_color() const {
return _clear_color; return _clear_value[RTP_color];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -207,7 +218,7 @@ get_clear_color() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_depth(float depth) { set_clear_depth(float depth) {
_clear_depth = depth; _clear_value[RTP_depth] = Colorf(depth,depth,depth,depth);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -221,7 +232,7 @@ set_clear_depth(float depth) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE float DrawableRegion:: INLINE float DrawableRegion::
get_clear_depth() const { get_clear_depth() const {
return _clear_depth; return _clear_value[RTP_depth][0];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_stencil // Function: DrawableRegion::set_clear_stencil
@ -234,7 +245,7 @@ get_clear_depth() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
set_clear_stencil(const unsigned int stencil) { set_clear_stencil(const unsigned int stencil) {
_clear_stencil = stencil; _clear_value[RTP_stencil] = Colorf(stencil,stencil,stencil,stencil);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -248,7 +259,30 @@ set_clear_stencil(const unsigned int stencil) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE unsigned int DrawableRegion:: INLINE unsigned int DrawableRegion::
get_clear_stencil() const { get_clear_stencil() const {
return _clear_stencil; return (int)(_clear_value[RTP_stencil][0]);
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::set_clear_value
// Access: Published
// Description: Sets the clear value for any bitplane.
////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion::
set_clear_value(int id, const Colorf &color) {
nassertv((id >= 0) && (id < RTP_COUNT));
_clear_value[id] = color;
}
////////////////////////////////////////////////////////////////////
// Function: DrawableRegion::get_clear_value
// Access: Published
// Description: Returns the clear value for any bitplane.
////////////////////////////////////////////////////////////////////
INLINE const Colorf &DrawableRegion::
get_clear_value(int id) const {
static Colorf blank(0.5,0.5,0.5,0.0);
nassertr((id >= 0) && (id < RTP_COUNT), blank);
return _clear_value[id];
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -259,9 +293,9 @@ get_clear_stencil() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void DrawableRegion:: INLINE void DrawableRegion::
disable_clears() { disable_clears() {
set_clear_color_active(false); for (int i=0; i<RTP_COUNT; i++) {
set_clear_depth_active(false); _clear_active[i] = false;
set_clear_stencil_active(false); }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -274,7 +308,10 @@ disable_clears() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool DrawableRegion:: INLINE bool DrawableRegion::
is_any_clear_active() const { is_any_clear_active() const {
return (_flags & F_clear_all) != 0; for (int i=0; i<RTP_COUNT; i++) {
if (_clear_active[i]) return true;
}
return false;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -44,6 +44,29 @@ public:
INLINE void copy_clear_settings(const DrawableRegion &copy); INLINE void copy_clear_settings(const DrawableRegion &copy);
PUBLISHED: PUBLISHED:
// It seems awkward to have this type, and also
// RenderBuffer::Type. However, the fact that RenderBuffer::Type
// is a bitmask makes it awfully awkward to work with.
enum RenderTexturePlane {
RTP_stencil=0,
RTP_depth_stencil=1,
RTP_depth=1,
RTP_color,
RTP_aux_rgba_0,
RTP_aux_rgba_1,
RTP_aux_rgba_2,
RTP_aux_rgba_3,
RTP_aux_hrgba_0,
RTP_aux_hrgba_1,
RTP_aux_hrgba_2,
RTP_aux_hrgba_3,
RTP_aux_float_0,
RTP_aux_float_1,
RTP_aux_float_2,
RTP_aux_float_3,
RTP_COUNT
};
INLINE void set_clear_color_active(bool clear_color_active); INLINE void set_clear_color_active(bool clear_color_active);
INLINE bool get_clear_color_active() const; INLINE bool get_clear_color_active() const;
@ -62,6 +85,12 @@ PUBLISHED:
INLINE void set_clear_stencil(unsigned int stencil); INLINE void set_clear_stencil(unsigned int stencil);
INLINE unsigned int get_clear_stencil() const; INLINE unsigned int get_clear_stencil() const;
INLINE void set_clear_active(int n, bool clear_aux_active);
INLINE bool get_clear_active(int n) const;
INLINE void set_clear_value(int n, const Colorf &color);
INLINE const Colorf &get_clear_value(int n) const;
INLINE void disable_clears(); INLINE void disable_clears();
INLINE bool is_any_clear_active() const; INLINE bool is_any_clear_active() const;
@ -75,20 +104,10 @@ protected:
int _draw_buffer_type; int _draw_buffer_type;
private: private:
// This data needs to be cycled. bool _clear_active[RTP_COUNT];
enum Flags { Colorf _clear_value[RTP_COUNT];
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" #include "drawableRegion.I"

View File

@ -289,6 +289,7 @@ set_accum_bits(int n) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void FrameBufferProperties:: INLINE void FrameBufferProperties::
set_aux_rgba(int n) { set_aux_rgba(int n) {
nassertv(n < 4);
_property[FBP_aux_rgba] = n; _property[FBP_aux_rgba] = n;
_specified[FBP_aux_rgba] = true; _specified[FBP_aux_rgba] = true;
} }
@ -300,6 +301,7 @@ set_aux_rgba(int n) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void FrameBufferProperties:: INLINE void FrameBufferProperties::
set_aux_hrgba(int n) { set_aux_hrgba(int n) {
nassertv(n < 4);
_property[FBP_aux_hrgba] = n; _property[FBP_aux_hrgba] = n;
_specified[FBP_aux_hrgba] = true; _specified[FBP_aux_hrgba] = true;
} }
@ -311,6 +313,7 @@ set_aux_hrgba(int n) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void FrameBufferProperties:: INLINE void FrameBufferProperties::
set_aux_float(int n) { set_aux_float(int n) {
nassertv(n < 4);
_property[FBP_aux_float] = n; _property[FBP_aux_float] = n;
_specified[FBP_aux_float] = true; _specified[FBP_aux_float] = true;
} }

View File

@ -251,11 +251,32 @@ output(ostream &out) const {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: FrameBufferProperties::get_aux_mask
// Access: Published
// Description: Converts the aux bitplanes of the
// framebuffer into a RenderBuffer::Type.
////////////////////////////////////////////////////////////////////
int FrameBufferProperties::
get_aux_mask() const {
int mask = 0;
for (int i=0; i<_property[FBP_aux_rgba]; i++) {
mask |= (RenderBuffer::T_aux_rgba_0 << i);
}
for (int i=0; i<_property[FBP_aux_hrgba]; i++) {
mask |= (RenderBuffer::T_aux_hrgba_0 << i);
}
for (int i=0; i<_property[FBP_aux_float]; i++) {
mask |= (RenderBuffer::T_aux_float_0 << i);
}
return mask;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: FrameBufferProperties::get_buffer_mask // Function: FrameBufferProperties::get_buffer_mask
// Access: Private // Access: Private
// Description: Converts the framebuffer properties into // Description: Converts the non-aux bitplanes of the
// a RenderBuffer::Type. // framebuffer into a RenderBuffer::Type.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int FrameBufferProperties:: int FrameBufferProperties::
get_buffer_mask() const { get_buffer_mask() const {
@ -272,16 +293,6 @@ get_buffer_mask() const {
if (_property[FBP_stencil_bits] > 0) { if (_property[FBP_stencil_bits] > 0) {
mask |= RenderBuffer::T_stencil; mask |= RenderBuffer::T_stencil;
} }
for (int aux_rgba=0; aux_rgba < _property[FBP_aux_rgba]; ++aux_rgba) {
mask |= (RenderBuffer::T_aux_rgba_0 << aux_rgba);
}
for (int aux_hrgba=0; aux_hrgba < _property[FBP_aux_hrgba]; ++aux_hrgba) {
mask |= (RenderBuffer::T_aux_hrgba_0 << aux_hrgba);
}
for (int aux_float=0; aux_float < _property[FBP_aux_float]; ++aux_float) {
mask |= (RenderBuffer::T_aux_float_0 << aux_float);
}
return mask; return mask;
} }

View File

@ -118,6 +118,7 @@ PUBLISHED:
int get_quality(const FrameBufferProperties &reqs) const; int get_quality(const FrameBufferProperties &reqs) const;
bool is_any_specified() const; bool is_any_specified() const;
bool is_basic() const; bool is_basic() const;
int get_aux_mask() const;
int get_buffer_mask() const; int get_buffer_mask() const;
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const; bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const;
}; };

View File

@ -83,28 +83,6 @@ PUBLISHED:
RTM_triggered_copy_ram, RTM_triggered_copy_ram,
}; };
// It seems awkward to have this type, and also
// RenderBuffer::Type. However, the fact that RenderBuffer::Type
// is a bitmask makes it awfully awkward to work with.
enum RenderTexturePlane {
RTP_depth_stencil=1,
RTP_depth=1,
RTP_color,
RTP_aux_rgba_0,
RTP_aux_rgba_1,
RTP_aux_rgba_2,
RTP_aux_rgba_3,
RTP_aux_hrgba_0,
RTP_aux_hrgba_1,
RTP_aux_hrgba_2,
RTP_aux_hrgba_3,
RTP_aux_float_0,
RTP_aux_float_1,
RTP_aux_float_2,
RTP_aux_float_3,
RTP_COUNT
};
// There are many reasons to call begin_frame/end_frame. // There are many reasons to call begin_frame/end_frame.
enum FrameMode { enum FrameMode {
FM_render, // We are rendering a frame. FM_render, // We are rendering a frame.

View File

@ -747,23 +747,3 @@ set_current_properties(const FrameBufferProperties *prop) {
_current_properties = prop; _current_properties = prop;
} }
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::set_stencil_clear_value
// Access: Public
// Description: Set current stencil clear value.
////////////////////////////////////////////////////////////////////
INLINE void GraphicsStateGuardian::
set_stencil_clear_value(unsigned int stencil_clear_value) {
_stencil_clear_value = stencil_clear_value;
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::get_stencil_clear_value
// Access: Public
// Description: Get current stencil clear value.
////////////////////////////////////////////////////////////////////
INLINE unsigned int GraphicsStateGuardian::
get_stencil_clear_value() {
return _stencil_clear_value;
}

View File

@ -333,10 +333,6 @@ reset() {
_scene_setup = _scene_null; _scene_setup = _scene_null;
_color_write_mask = ColorWriteAttrib::C_all; _color_write_mask = ColorWriteAttrib::C_all;
_color_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f);
_depth_clear_value = 1.0f;
_stencil_clear_value = 0;
_accum_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f);
_has_scene_graph_color = false; _has_scene_graph_color = false;
_transform_stale = true; _transform_stale = true;
@ -389,6 +385,21 @@ set_state_and_transform(const RenderState *state,
const TransformState *trans) { const TransformState *trans) {
} }
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::clear
// Access: Public
// Description: Clears the framebuffer within the current
// DisplayRegion, according to the flags indicated by
// the given DrawableRegion object.
//
// This does not set the DisplayRegion first. You
// should call prepare_display_region() to specify the
// region you wish the clear operation to apply to.
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
clear(DrawableRegion *clearable) {
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::get_render_buffer // Function: GraphicsStateGuardian::get_render_buffer
// Access: Public // Access: Public
@ -731,63 +742,6 @@ compute_distance_to(const LPoint3f &point) const {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::set_color_clear_value
// Access: Public
// Description: Sets the color that the next do_clear() command will set
// the color buffer to
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
set_color_clear_value(const Colorf& value) {
_color_clear_value = value;
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::set_depth_clear_value
// Access: Public
// Description: Sets the depth that the next do_clear() command will set
// the depth buffer to
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
set_depth_clear_value(const float value) {
_depth_clear_value = value;
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::clear
// Access: Public
// Description: Clears the framebuffer within the current
// DisplayRegion, according to the flags indicated by
// the given DrawableRegion object.
//
// This does not set the DisplayRegion first. You
// should call prepare_display_region() to specify the
// region you wish the clear operation to apply to.
////////////////////////////////////////////////////////////////////
void GraphicsStateGuardian::
clear(DrawableRegion *clearable) {
PStatTimer timer(_clear_pcollector);
int clear_buffer_type = 0;
if (clearable->get_clear_color_active()) {
clear_buffer_type |= clearable->get_draw_buffer_type();
set_color_clear_value(clearable->get_clear_color());
}
if (clearable->get_clear_depth_active()) {
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,
*_current_properties));
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GraphicsStateGuardian::fetch_specified_value // Function: GraphicsStateGuardian::fetch_specified_value
// Access: Public // Access: Public

View File

@ -189,11 +189,7 @@ public:
virtual float compute_distance_to(const LPoint3f &point) const; virtual float compute_distance_to(const LPoint3f &point) const;
virtual void set_color_clear_value(const Colorf &value); virtual void clear(DrawableRegion *clearable);
virtual void set_depth_clear_value(const float value);
virtual void do_clear(const RenderBuffer &buffer)=0;
void clear(DrawableRegion *clearable);
const LMatrix4f *fetch_specified_value(Shader::ShaderMatSpec &spec, int altered); const LMatrix4f *fetch_specified_value(Shader::ShaderMatSpec &spec, int altered);
const LMatrix4f *fetch_specified_part(Shader::ShaderMatInput input, InternalName *name, LMatrix4f &t); const LMatrix4f *fetch_specified_part(Shader::ShaderMatInput input, InternalName *name, LMatrix4f &t);
@ -263,9 +259,6 @@ public:
virtual void bind_light(Spotlight *light_obj, const NodePath &light, virtual void bind_light(Spotlight *light_obj, const NodePath &light,
int light_id); int light_id);
INLINE void set_stencil_clear_value(unsigned int stencil_clear_value);
INLINE unsigned int get_stencil_clear_value();
static void create_gamma_table (float gamma, unsigned short *red_table, unsigned short *green_table, unsigned short *blue_table); static void create_gamma_table (float gamma, unsigned short *red_table, unsigned short *green_table, unsigned short *blue_table);
#ifdef DO_PSTATS #ifdef DO_PSTATS
@ -320,10 +313,6 @@ protected:
const GeomVertexDataPipelineReader *_data_reader; const GeomVertexDataPipelineReader *_data_reader;
unsigned int _color_write_mask; unsigned int _color_write_mask;
Colorf _color_clear_value;
float _depth_clear_value;
unsigned int _stencil_clear_value;
Colorf _accum_clear_value;
CPT(DisplayRegion) _current_display_region; CPT(DisplayRegion) _current_display_region;
Lens::StereoChannel _current_stereo_channel; Lens::StereoChannel _current_stereo_channel;

View File

@ -103,7 +103,6 @@ DXGraphicsStateGuardian8(GraphicsPipe *pipe) :
_d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f; _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f;
_cur_read_pixel_buffer = RenderBuffer::T_front; _cur_read_pixel_buffer = RenderBuffer::T_front;
set_color_clear_value(_color_clear_value);
// DirectX drivers seem to consistently invert the texture when // DirectX drivers seem to consistently invert the texture when
// they copy framebuffer-to-texture. Ok. // they copy framebuffer-to-texture. Ok.
@ -485,17 +484,6 @@ make_geom_munger(const RenderState *state, Thread *current_thread) {
return GeomMunger::register_munger(munger, current_thread); return GeomMunger::register_munger(munger, current_thread);
} }
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::set_color_clear_value
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8::
set_color_clear_value(const Colorf& value) {
_color_clear_value = value;
_d3dcolor_clear_value = Colorf_to_D3DCOLOR(value);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::do_clear // Function: DXGraphicsStateGuardian8::do_clear
// Access: Public, Virtual // Access: Public, Virtual
@ -503,24 +491,26 @@ set_color_clear_value(const Colorf& value) {
// colors. // colors.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8:: void DXGraphicsStateGuardian8::
do_clear(const RenderBuffer &buffer) { clear(DrawableRegion *clearable) {
nassertv(buffer._gsg == this);
int buffer_type = buffer._buffer_type;
DWORD main_flags = 0; DWORD main_flags = 0;
DWORD aux_flags = 0; DWORD aux_flags = 0;
D3DCOLOR color_clear_value = Colorf_to_D3DCOLOR(clearable->get_clear_color());
float depth_clear_value = clearable->get_clear_depth();
DWORD stencil_clear_value = (DWORD)(clearable->get_clear_stencil());
//set appropriate flags //set appropriate flags
if (buffer_type & RenderBuffer::T_color) { if (clearable->get_clear_color_active()) {
main_flags |= D3DCLEAR_TARGET; main_flags |= D3DCLEAR_TARGET;
} }
if (buffer_type & RenderBuffer::T_depth) { if (clearable->get_clear_depth_active()) {
aux_flags |= D3DCLEAR_ZBUFFER; aux_flags |= D3DCLEAR_ZBUFFER;
nassertv(_screen->_presentation_params.EnableAutoDepthStencil); nassertv(_screen->_presentation_params.EnableAutoDepthStencil);
} }
if (buffer_type & RenderBuffer::T_stencil) { if (clearable->get_clear_stencil_active()) {
// clear only if there is a stencil buffer // clear only if there is a stencil buffer
if (_screen->_presentation_params.EnableAutoDepthStencil && if (_screen->_presentation_params.EnableAutoDepthStencil &&
IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) { IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) {
@ -529,20 +519,20 @@ do_clear(const RenderBuffer &buffer) {
} }
if ((main_flags | aux_flags) != 0) { if ((main_flags | aux_flags) != 0) {
HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, _d3dcolor_clear_value, HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) { if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) {
// Maybe there's a problem with the one or more of the auxiliary // Maybe there's a problem with the one or more of the auxiliary
// buffers. // buffers.
hr = _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, _d3dcolor_clear_value, hr = _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (!FAILED(hr)) { if (!FAILED(hr)) {
// Yep, it worked without them. That's a problem. Which buffer // Yep, it worked without them. That's a problem. Which buffer
// poses the problem? // poses the problem?
if (buffer_type & RenderBuffer::T_depth) { if (clearable->get_clear_depth_active()) {
aux_flags |= D3DCLEAR_ZBUFFER; aux_flags |= D3DCLEAR_ZBUFFER;
HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, _d3dcolor_clear_value, HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (FAILED(hr2)) { if (FAILED(hr2)) {
dxgsg8_cat.error() dxgsg8_cat.error()
<< "Unable to clear depth buffer; removing.\n"; << "Unable to clear depth buffer; removing.\n";
@ -550,10 +540,10 @@ do_clear(const RenderBuffer &buffer) {
((FrameBufferProperties *)_current_properties)->set_depth_bits(0); ((FrameBufferProperties *)_current_properties)->set_depth_bits(0);
} }
} }
if (buffer_type & RenderBuffer::T_stencil) { if (clearable->get_clear_stencil_active()) {
aux_flags |= D3DCLEAR_STENCIL; aux_flags |= D3DCLEAR_STENCIL;
HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, _d3dcolor_clear_value, HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, color_clear_value,
_stencil_clear_value, (DWORD)_stencil_clear_value); stencil_clear_value, stencil_clear_value);
if (FAILED(hr2)) { if (FAILED(hr2)) {
dxgsg8_cat.error() dxgsg8_cat.error()
<< "Unable to clear stencil buffer; removing.\n"; << "Unable to clear stencil buffer; removing.\n";

View File

@ -68,9 +68,7 @@ public:
virtual PT(GeomMunger) make_geom_munger(const RenderState *state, virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
Thread *current_thread); Thread *current_thread);
virtual void set_color_clear_value(const Colorf &value); virtual void clear(DrawableRegion *region);
virtual void do_clear(const RenderBuffer &buffer);
virtual void prepare_display_region(DisplayRegionPipelineReader *dr, virtual void prepare_display_region(DisplayRegionPipelineReader *dr,
Lens::StereoChannel stereo_channel); Lens::StereoChannel stereo_channel);
@ -226,8 +224,6 @@ protected:
RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation
bool _auto_rescale_normal; bool _auto_rescale_normal;
D3DCOLOR _d3dcolor_clear_value;
float _material_ambient; float _material_ambient;
float _material_diffuse; float _material_diffuse;
float _material_specular; float _material_specular;

View File

@ -121,7 +121,6 @@ DXGraphicsStateGuardian9(GraphicsPipe *pipe) :
_d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f; _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f;
_cur_read_pixel_buffer = RenderBuffer::T_front; _cur_read_pixel_buffer = RenderBuffer::T_front;
set_color_clear_value(_color_clear_value);
// DirectX drivers seem to consistently invert the texture when // DirectX drivers seem to consistently invert the texture when
// they copy framebuffer-to-texture. Ok. // they copy framebuffer-to-texture. Ok.
@ -767,43 +766,34 @@ make_geom_munger(const RenderState *state, Thread *current_thread) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::set_color_clear_value // Function: DXGraphicsStateGuardian9::clear
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian9::
set_color_clear_value(const Colorf& value) {
_color_clear_value = value;
_d3dcolor_clear_value = Colorf_to_D3DCOLOR(value);
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian9::do_clear
// Access: Public, Virtual // Access: Public, Virtual
// Description: Clears all of the indicated buffers to their assigned // Description: Clears all of the indicated buffers to their assigned
// colors. // colors.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian9:: void DXGraphicsStateGuardian9::
do_clear(const RenderBuffer &buffer) { clear(DrawableRegion *clearable) {
nassertv(buffer._gsg == this);
int buffer_type = buffer._buffer_type;
DWORD main_flags = 0; DWORD main_flags = 0;
DWORD aux_flags = 0; DWORD aux_flags = 0;
D3DCOLOR color_clear_value = Colorf_to_D3DCOLOR(clearable->get_clear_color());
float depth_clear_value = clearable->get_clear_depth();
DWORD stencil_clear_value = (DWORD)(clearable->get_clear_stencil());
DBG_S dxgsg9_cat.debug ( ) << "DXGraphicsStateGuardian9::do_clear\n"; DBG_E DBG_S dxgsg9_cat.debug ( ) << "DXGraphicsStateGuardian9::do_clear\n"; DBG_E
//set appropriate flags //set appropriate flags
if (buffer_type & RenderBuffer::T_color) { if (clearable->get_clear_color_active()) {
main_flags |= D3DCLEAR_TARGET; main_flags |= D3DCLEAR_TARGET;
} }
if (buffer_type & RenderBuffer::T_depth) { if (clearable->get_clear_depth_active()) {
aux_flags |= D3DCLEAR_ZBUFFER; aux_flags |= D3DCLEAR_ZBUFFER;
nassertv(_screen->_presentation_params.EnableAutoDepthStencil); nassertv(_screen->_presentation_params.EnableAutoDepthStencil);
} }
if (buffer_type & RenderBuffer::T_stencil) { if (clearable->get_clear_stencil_active()) {
// clear only if there is a stencil buffer // clear only if there is a stencil buffer
if (_screen->_presentation_params.EnableAutoDepthStencil && if (_screen->_presentation_params.EnableAutoDepthStencil &&
IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) { IS_STENCIL_FORMAT(_screen->_presentation_params.AutoDepthStencilFormat)) {
@ -811,7 +801,7 @@ do_clear(const RenderBuffer &buffer) {
// DEBUG // DEBUG
if (false) { if (false) {
dxgsg9_cat.debug ( ) << "STENCIL CLEAR " << _stencil_clear_value << "\n"; dxgsg9_cat.debug ( ) << "STENCIL CLEAR " << stencil_clear_value << "\n";
} }
} }
} }
@ -821,20 +811,20 @@ do_clear(const RenderBuffer &buffer) {
DBG_S dxgsg9_cat.debug ( ) << "ccccc DXGraphicsStateGuardian9::really do_clear\n"; DBG_E DBG_S dxgsg9_cat.debug ( ) << "ccccc DXGraphicsStateGuardian9::really do_clear\n"; DBG_E
DBG_S dxgsg9_cat.debug ( ) << "clear flags: main " << main_flags << " aux :" << aux_flags << "\n"; DBG_E DBG_S dxgsg9_cat.debug ( ) << "clear flags: main " << main_flags << " aux :" << aux_flags << "\n"; DBG_E
HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, _d3dcolor_clear_value, HRESULT hr = _d3d_device->Clear(0, NULL, main_flags | aux_flags, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) { if (FAILED(hr) && main_flags == D3DCLEAR_TARGET && aux_flags != 0) {
// Maybe there's a problem with the one or more of the auxiliary // Maybe there's a problem with the one or more of the auxiliary
// buffers. // buffers.
hr = _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, _d3dcolor_clear_value, hr = _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (!FAILED(hr)) { if (!FAILED(hr)) {
// Yep, it worked without them. That's a problem. Which buffer // Yep, it worked without them. That's a problem. Which buffer
// poses the problem? // poses the problem?
if (buffer_type & RenderBuffer::T_depth) { if (clearable->get_clear_depth_active()) {
aux_flags |= D3DCLEAR_ZBUFFER; aux_flags |= D3DCLEAR_ZBUFFER;
HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, _d3dcolor_clear_value, HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, color_clear_value,
_depth_clear_value, (DWORD)_stencil_clear_value); depth_clear_value, stencil_clear_value);
if (FAILED(hr2)) { if (FAILED(hr2)) {
dxgsg9_cat.error() dxgsg9_cat.error()
<< "Unable to clear depth buffer; removing.\n"; << "Unable to clear depth buffer; removing.\n";
@ -842,10 +832,10 @@ do_clear(const RenderBuffer &buffer) {
((FrameBufferProperties *)_current_properties)->set_depth_bits(0); ((FrameBufferProperties *)_current_properties)->set_depth_bits(0);
} }
} }
if (buffer_type & RenderBuffer::T_stencil) { if (clearable->get_clear_stencil_active()) {
aux_flags |= D3DCLEAR_STENCIL; aux_flags |= D3DCLEAR_STENCIL;
HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, _d3dcolor_clear_value, HRESULT hr2 = _d3d_device->Clear(0, NULL, D3DCLEAR_STENCIL, color_clear_value,
_stencil_clear_value, (DWORD)_stencil_clear_value); stencil_clear_value, stencil_clear_value);
if (FAILED(hr2)) { if (FAILED(hr2)) {
dxgsg9_cat.error() dxgsg9_cat.error()
<< "Unable to clear stencil buffer; removing.\n"; << "Unable to clear stencil buffer; removing.\n";

View File

@ -108,9 +108,7 @@ public:
virtual PT(GeomMunger) make_geom_munger(const RenderState *state, virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
Thread *current_thread); Thread *current_thread);
virtual void set_color_clear_value(const Colorf &value); virtual void clear(DrawableRegion *clearable);
virtual void do_clear(const RenderBuffer &buffer);
virtual void prepare_display_region(DisplayRegionPipelineReader *dr, virtual void prepare_display_region(DisplayRegionPipelineReader *dr,
Lens::StereoChannel stereo_channel); Lens::StereoChannel stereo_channel);
@ -280,8 +278,6 @@ protected:
RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation
bool _auto_rescale_normal; bool _auto_rescale_normal;
D3DCOLOR _d3dcolor_clear_value;
float _material_ambient; float _material_ambient;
float _material_diffuse; float _material_diffuse;
float _material_specular; float _material_specular;

View File

@ -1224,45 +1224,89 @@ reset() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::do_clear // Function: GraphicsStateGuardian::clear
// Access: Public, Virtual // Access: Public
// Description: Clears all of the indicated buffers to their assigned // Description: Clears the framebuffer within the current
// colors. // DisplayRegion, according to the flags indicated by
// the given DrawableRegion object.
//
// This does not set the DisplayRegion first. You
// should call prepare_display_region() to specify the
// region you wish the clear operation to apply to.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void CLP(GraphicsStateGuardian):: void CLP(GraphicsStateGuardian)::
do_clear(const RenderBuffer &buffer) { clear(DrawableRegion *clearable) {
nassertv(buffer._gsg == this); PStatTimer timer(_clear_pcollector);
int buffer_type = buffer._buffer_type;
GLbitfield mask = 0; if ((!clearable->get_clear_color_active())&&
(!clearable->get_clear_depth_active())&&
(!clearable->get_clear_stencil_active())) {
return;
}
set_state_and_transform(RenderState::make_empty(), _internal_transform); set_state_and_transform(RenderState::make_empty(), _internal_transform);
if (buffer_type & RenderBuffer::T_color) { int mask = 0;
GLP(ClearColor)(_color_clear_value[0],
_color_clear_value[1], for (int i=0; i<_current_properties->get_aux_rgba(); i++) {
_color_clear_value[2], int layerid = GraphicsOutput::RTP_aux_rgba_0 + i;
_color_clear_value[3]); int layerbit = RenderBuffer::T_aux_rgba_0 << i;
mask |= GL_COLOR_BUFFER_BIT; if (clearable->get_clear_active(layerid)) {
set_draw_buffer(buffer); Colorf v = clearable->get_clear_value(layerid);
GLP(ClearColor)(v[0],v[1],v[2],v[3]);
set_draw_buffer(layerbit);
GLP(Clear)(GL_COLOR_BUFFER_BIT);
}
}
for (int i=0; i<_current_properties->get_aux_hrgba(); i++) {
int layerid = GraphicsOutput::RTP_aux_hrgba_0 + i;
int layerbit = RenderBuffer::T_aux_hrgba_0 << i;
if (clearable->get_clear_active(layerid)) {
Colorf v = clearable->get_clear_value(layerid);
GLP(ClearColor)(v[0],v[1],v[2],v[3]);
set_draw_buffer(layerbit);
GLP(Clear)(GL_COLOR_BUFFER_BIT);
}
}
for (int i=0; i<_current_properties->get_aux_float(); i++) {
int layerid = GraphicsOutput::RTP_aux_float_0 + i;
int layerbit = RenderBuffer::T_aux_float_0 << i;
if (clearable->get_clear_active(layerid)) {
Colorf v = clearable->get_clear_value(layerid);
GLP(ClearColor)(v[0],v[1],v[2],v[3]);
set_draw_buffer(layerbit);
GLP(Clear)(GL_COLOR_BUFFER_BIT);
}
} }
if (buffer_type & RenderBuffer::T_depth) { if (clearable->get_clear_color_active()) {
GLP(ClearDepth)(_depth_clear_value); Colorf v = clearable->get_clear_color();
GLP(ClearColor)(v[0],v[1],v[2],v[3]);
mask |= GL_COLOR_BUFFER_BIT;
set_draw_buffer(clearable->get_draw_buffer_type());
}
if (clearable->get_clear_depth_active()) {
GLP(ClearDepth)(clearable->get_clear_depth());
mask |= GL_DEPTH_BUFFER_BIT; mask |= GL_DEPTH_BUFFER_BIT;
} }
if (buffer_type & RenderBuffer::T_stencil) { if (clearable->get_clear_stencil_active()) {
GLP(ClearStencil)(_stencil_clear_value); GLP(ClearStencil)(clearable->get_clear_stencil());
mask |= GL_STENCIL_BUFFER_BIT; mask |= GL_STENCIL_BUFFER_BIT;
} }
if (buffer_type & RenderBuffer::T_accum) { GLP(Clear)(mask);
GLP(ClearAccum)(_accum_clear_value[0],
_accum_clear_value[1], // In the past, it was possible to set the draw buffer
_accum_clear_value[2], // once in prepare_display_region and then forget about it.
_accum_clear_value[3]); // Now, with aux layers, it is necessary to occasionally
mask |= GL_ACCUM_BUFFER_BIT; // change the draw buffer. In time, I think there will need
} // to be a draw buffer attrib. Until then, this little hack
// to put things back the way they were after
// prepare_display_region will bdo.
set_draw_buffer(_draw_buffer_type);
if (GLCAT.is_spam()) { if (GLCAT.is_spam()) {
GLCAT.spam() << "glClear("; GLCAT.spam() << "glClear(";
@ -1281,7 +1325,6 @@ do_clear(const RenderBuffer &buffer) {
GLCAT.spam(false) << ")" << endl; GLCAT.spam(false) << ")" << endl;
} }
GLP(Clear)(mask);
report_my_gl_errors(); report_my_gl_errors();
} }
@ -1306,8 +1349,10 @@ prepare_display_region(DisplayRegionPipelineReader *dr,
GLsizei width = GLsizei(w); GLsizei width = GLsizei(w);
GLsizei height = GLsizei(h); GLsizei height = GLsizei(h);
set_draw_buffer(get_render_buffer(dr->get_object()->get_draw_buffer_type(), _draw_buffer_type = dr->get_object()->get_draw_buffer_type() & _current_properties->get_buffer_mask() & _stereo_buffer_mask;
*_current_properties)); _draw_buffer_type |= _current_properties->get_aux_mask();
set_draw_buffer(_draw_buffer_type);
enable_scissor(true); enable_scissor(true);
GLP(Scissor)(x, y, width, height); GLP(Scissor)(x, y, width, height);
GLP(Viewport)(x, y, width, height); GLP(Viewport)(x, y, width, height);
@ -3276,7 +3321,7 @@ void CLP(GraphicsStateGuardian)::
framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr,
const RenderBuffer &rb) { const RenderBuffer &rb) {
nassertv(tex != NULL && dr != NULL); nassertv(tex != NULL && dr != NULL);
set_read_buffer(rb); set_read_buffer(rb._buffer_type);
int xo, yo, w, h; int xo, yo, w, h;
dr->get_region_pixels(xo, yo, w, h); dr->get_region_pixels(xo, yo, w, h);
@ -3363,7 +3408,7 @@ bool CLP(GraphicsStateGuardian)::
framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr,
const RenderBuffer &rb) { const RenderBuffer &rb) {
nassertr(tex != NULL && dr != NULL, false); nassertr(tex != NULL && dr != NULL, false);
set_read_buffer(rb); set_read_buffer(rb._buffer_type);
GLP(PixelStorei)(GL_PACK_ALIGNMENT, 1); GLP(PixelStorei)(GL_PACK_ALIGNMENT, 1);
// Bug fix for RE, RE2, and VTX - need to disable texturing in order // Bug fix for RE, RE2, and VTX - need to disable texturing in order
@ -4556,30 +4601,43 @@ get_extension_func(const char *, const char *) {
// Access: Protected // Access: Protected
// Description: Sets up the GLP(DrawBuffer) to render into the buffer // Description: Sets up the GLP(DrawBuffer) to render into the buffer
// indicated by the RenderBuffer object. This only sets // indicated by the RenderBuffer object. This only sets
// up the color bits; it does not affect the depth, // up the color and aux bits; it does not affect the depth,
// stencil, accum layers. // stencil, accum layers.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void CLP(GraphicsStateGuardian):: void CLP(GraphicsStateGuardian)::
set_draw_buffer(const RenderBuffer &rb) { set_draw_buffer(int rbtype) {
if (_current_fbo) { if (_current_fbo) {
GLuint buffers[16]; GLuint buffers[16];
int nbuffers=0; int nbuffers=0;
if (rb._buffer_type & RenderBuffer::T_front) { if (rbtype & RenderBuffer::T_color) {
nbuffers += 1; buffers[nbuffers++] = GL_COLOR_ATTACHMENT0_EXT;
} }
nbuffers += _current_properties->get_aux_rgba(); int index = 1;
nbuffers += _current_properties->get_aux_hrgba(); for (int i=0; i<_current_properties->get_aux_rgba(); i++) {
nbuffers += _current_properties->get_aux_float(); if (rbtype & (RenderBuffer::T_aux_rgba_0 << i)) {
for (int i=0; i<nbuffers; i++) { buffers[nbuffers++] = GL_COLOR_ATTACHMENT0_EXT + index;
buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i; }
index += 1;
}
for (int i=0; i<_current_properties->get_aux_hrgba(); i++) {
if (rbtype & (RenderBuffer::T_aux_hrgba_0 << i)) {
buffers[nbuffers++] = GL_COLOR_ATTACHMENT0_EXT + index;
}
index += 1;
}
for (int i=0; i<_current_properties->get_aux_float(); i++) {
if (rbtype & (RenderBuffer::T_aux_float_0 << i)) {
buffers[nbuffers++] = GL_COLOR_ATTACHMENT0_EXT + index;
}
index += 1;
} }
_glDrawBuffers(nbuffers, buffers); _glDrawBuffers(nbuffers, buffers);
} else { } else {
switch (rb._buffer_type & RenderBuffer::T_color) { switch (rbtype & RenderBuffer::T_color) {
case RenderBuffer::T_front: case RenderBuffer::T_front:
GLP(DrawBuffer)(GL_FRONT); GLP(DrawBuffer)(GL_FRONT);
break; break;
@ -4641,26 +4699,26 @@ set_draw_buffer(const RenderBuffer &rb) {
// stencil, accum layers. // stencil, accum layers.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void CLP(GraphicsStateGuardian):: void CLP(GraphicsStateGuardian)::
set_read_buffer(const RenderBuffer &rb) { set_read_buffer(int rbtype) {
if (_current_fbo) { if (_current_fbo) {
GLuint buffer = GL_COLOR_ATTACHMENT0_EXT; GLuint buffer = GL_COLOR_ATTACHMENT0_EXT;
int index = 1; int index = 1;
for (int i=0; i<_current_properties->get_aux_rgba(); i++) { for (int i=0; i<_current_properties->get_aux_rgba(); i++) {
if (rb._buffer_type & (RenderBuffer::T_aux_rgba_0 << i)) { if (rbtype & (RenderBuffer::T_aux_rgba_0 << i)) {
buffer = GL_COLOR_ATTACHMENT0_EXT + index; buffer = GL_COLOR_ATTACHMENT0_EXT + index;
} }
index += 1; index += 1;
} }
for (int i=0; i<_current_properties->get_aux_hrgba(); i++) { for (int i=0; i<_current_properties->get_aux_hrgba(); i++) {
if (rb._buffer_type & (RenderBuffer::T_aux_hrgba_0 << i)) { if (rbtype & (RenderBuffer::T_aux_hrgba_0 << i)) {
buffer = GL_COLOR_ATTACHMENT0_EXT + index; buffer = GL_COLOR_ATTACHMENT0_EXT + index;
} }
index += 1; index += 1;
} }
for (int i=0; i<_current_properties->get_aux_float(); i++) { for (int i=0; i<_current_properties->get_aux_float(); i++) {
if (rb._buffer_type & (RenderBuffer::T_aux_float_0 << i)) { if (rbtype & (RenderBuffer::T_aux_float_0 << i)) {
buffer = GL_COLOR_ATTACHMENT0_EXT + index; buffer = GL_COLOR_ATTACHMENT0_EXT + index;
} }
index += 1; index += 1;
@ -4669,7 +4727,7 @@ set_read_buffer(const RenderBuffer &rb) {
} else { } else {
switch (rb._buffer_type & RenderBuffer::T_color) { switch (rbtype & RenderBuffer::T_color) {
case RenderBuffer::T_front: case RenderBuffer::T_front:
GLP(ReadBuffer)(GL_FRONT); GLP(ReadBuffer)(GL_FRONT);
break; break;

View File

@ -116,8 +116,6 @@ public:
virtual void reset(); virtual void reset();
virtual void do_clear(const RenderBuffer &buffer);
virtual void prepare_display_region(DisplayRegionPipelineReader *dr, virtual void prepare_display_region(DisplayRegionPipelineReader *dr,
Lens::StereoChannel stereo_channel); Lens::StereoChannel stereo_channel);
virtual CPT(TransformState) calc_projection_mat(const Lens *lens); virtual CPT(TransformState) calc_projection_mat(const Lens *lens);
@ -185,6 +183,8 @@ public:
virtual PT(GeomMunger) make_geom_munger(const RenderState *state, virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
Thread *current_thread); Thread *current_thread);
virtual void clear(DrawableRegion *region);
virtual void framebuffer_copy_to_texture virtual void framebuffer_copy_to_texture
(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb); (Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb);
virtual bool framebuffer_copy_to_ram virtual bool framebuffer_copy_to_ram
@ -293,8 +293,8 @@ protected:
INLINE GLenum get_light_id(int index) const; INLINE GLenum get_light_id(int index) const;
INLINE GLenum get_clip_plane_id(int index) const; INLINE GLenum get_clip_plane_id(int index) const;
void set_draw_buffer(const RenderBuffer &rb); void set_draw_buffer(int rbtype);
void set_read_buffer(const RenderBuffer &rb); void set_read_buffer(int rbtype);
static GLenum get_numeric_type(Geom::NumericType numeric_type); static GLenum get_numeric_type(Geom::NumericType numeric_type);
GLenum get_texture_target(Texture::TextureType texture_type) const; GLenum get_texture_target(Texture::TextureType texture_type) const;
@ -375,6 +375,7 @@ protected:
int _viewport_width; int _viewport_width;
int _viewport_height; int _viewport_height;
int _draw_buffer_type;
bool _auto_antialias_mode; bool _auto_antialias_mode;
RenderModeAttrib::Mode _render_mode; RenderModeAttrib::Mode _render_mode;
float _point_size; float _point_size;

View File

@ -17,16 +17,6 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: WebcamVideo::get_name
// Access: Published
// Description: Returns the camera's name / description.
////////////////////////////////////////////////////////////////////
INLINE const string &WebcamVideo::
get_name() const {
return _name;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WebcamVideo::get_size_x // Function: WebcamVideo::get_size_x
// Access: Published // Access: Published

View File

@ -34,7 +34,6 @@ PUBLISHED:
static int get_num_options(); static int get_num_options();
static PT(WebcamVideo) get_option(int n); static PT(WebcamVideo) get_option(int n);
INLINE const string &get_name() const;
INLINE int get_size_x() const; INLINE int get_size_x() const;
INLINE int get_size_y() const; INLINE int get_size_y() const;
INLINE int get_fps() const; INLINE int get_fps() const;
@ -44,9 +43,7 @@ PUBLISHED:
public: public:
static void find_all_webcams(); static void find_all_webcams();
protected: protected:
string _name;
int _size_x; int _size_x;
int _size_y; int _size_y;
int _fps; int _fps;

View File

@ -329,14 +329,14 @@ add_device(WebcamVideoList &list, IMoniker *pMoniker, AM_MEDIA_TYPE *media) {
PT(WebcamVideoDS) wc = new WebcamVideoDS; PT(WebcamVideoDS) wc = new WebcamVideoDS;
ostringstream name; ostringstream name;
name << "DirectShow: " << get_moniker_name(pMoniker) << " @ " << media_x(media) << " x " << media_y(media) << " FPS:" << media_fps(media); name << "DirectShow: " << get_moniker_name(pMoniker) << " @ " << media_x(media) << " x " << media_y(media) << " FPS:" << media_fps(media);
wc->_name = name.str(); wc->set_name(name.str());
wc->_size_x = media_x(media); wc->_size_x = media_x(media);
wc->_size_y = media_y(media); wc->_size_y = media_y(media);
wc->_fps = media_fps(media); wc->_fps = media_fps(media);
wc->_moniker = pMoniker; wc->_moniker = pMoniker;
wc->_media = media; wc->_media = media;
list.push_back(wc); list.push_back(wc);
cerr << "Added device: " << wc->_name << "\n"; cerr << "Added device: " << wc->get_name() << "\n";
} }