support red-blue stereo in dx8/9

This commit is contained in:
David Rose 2006-02-17 21:15:01 +00:00
parent 808cca4c3f
commit 82c0011f87
4 changed files with 47 additions and 51 deletions

View File

@ -558,16 +558,12 @@ do_clear(const RenderBuffer &buffer) {
// scissor region and viewport)
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8::
prepare_display_region() {
if (_current_display_region == (DisplayRegion*)0L) {
dxgsg8_cat.error()
<< "Invalid NULL display region in prepare_display_region()\n";
} else if (_current_display_region != _actual_display_region) {
_actual_display_region = _current_display_region;
prepare_display_region(DisplayRegion *dr, Lens::StereoChannel stereo_channel) {
nassertv(dr != (DisplayRegion *)NULL);
GraphicsStateGuardian::prepare_display_region(dr, stereo_channel);
int l, u, w, h;
_actual_display_region->get_region_pixels_i(l, u, w, h);
_current_display_region->get_region_pixels_i(l, u, w, h);
// Create the viewport
D3DVIEWPORT8 vp = { l, u, w, h, 0.0f, 1.0f };
@ -593,6 +589,9 @@ prepare_display_region() {
}
}
// Note: for DX9, also change scissor clipping state here
if (_screen->_can_direct_disable_color_writes) {
_d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, _color_write_mask);
}
}
@ -609,7 +608,7 @@ prepare_display_region() {
// false if it is not.
////////////////////////////////////////////////////////////////////
bool DXGraphicsStateGuardian8::
prepare_lens(Lens::StereoChannel stereo_channel) {
prepare_lens() {
if (_current_lens == (Lens *)NULL) {
return false;
}
@ -619,7 +618,7 @@ prepare_lens(Lens::StereoChannel stereo_channel) {
}
// Start with the projection matrix from the lens.
const LMatrix4f &lens_mat = _current_lens->get_projection_mat(stereo_channel);
const LMatrix4f &lens_mat = _current_lens->get_projection_mat(_current_stereo_channel);
// The projection matrix must always be left-handed Y-up internally,
// to match DirectX's convention, even if our coordinate system of
@ -1715,9 +1714,6 @@ reset() {
_d3d_device->SetRenderState(D3DRS_CLIPPING, true);
// these both reflect d3d defaults
_color_writemask = 0xFFFFFFFF;
_d3d_device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
_d3d_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
@ -2788,7 +2784,9 @@ do_issue_blending() {
// all the other blending-related stuff doesn't matter. If the
// device doesn't support color-write, we use blending tricks
// to effectively disable color write.
if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) {
unsigned int color_channels =
_target._color_write->get_channels() & _color_write_mask;
if (color_channels == ColorWriteAttrib::C_off) {
if (_target._color_write != _state._color_write) {
if (_screen->_can_direct_disable_color_writes) {
_d3d_device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
@ -2803,7 +2801,7 @@ do_issue_blending() {
} else {
if (_target._color_write != _state._color_write) {
if (_screen->_can_direct_disable_color_writes) {
_d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, _target._color_write->get_channels());
_d3d_device->SetRenderState(D3DRS_COLORWRITEENABLE, color_channels);
}
}
}

View File

@ -66,8 +66,8 @@ public:
virtual void do_clear(const RenderBuffer &buffer);
virtual void prepare_display_region();
virtual bool prepare_lens(Lens::StereoChannel stereo_channel);
virtual void prepare_display_region(DisplayRegion *dr, Lens::StereoChannel stereo_channel);
virtual bool prepare_lens();
virtual bool begin_frame();
virtual bool begin_scene();
@ -201,7 +201,6 @@ protected:
bool _auto_rescale_normal;
D3DCOLOR _d3dcolor_clear_value;
UINT _color_writemask;
float _material_ambient;
float _material_diffuse;
@ -222,7 +221,6 @@ protected:
LMatrix4f _projection_mat;
CPT(DisplayRegion) _actual_display_region;
const DXVertexBufferContext8 *_active_vbuffer;
const DXIndexBufferContext8 *_active_ibuffer;

View File

@ -804,7 +804,10 @@ prepare_display_region(DisplayRegion *dr, Lens::StereoChannel stereo_channel) {
nassertv(false);
}
}
// Note: for DX9, also change scissor clipping state here
if (_screen->_can_direct_disable_color_writes) {
set_render_state(D3DRS_COLORWRITEENABLE, _color_write_mask);
}
}
////////////////////////////////////////////////////////////////////
@ -2560,9 +2563,6 @@ reset() {
set_render_state(D3DRS_CLIPPING, true);
// these both reflect d3d defaults
_color_writemask = 0xFFFFFFFF;
set_render_state(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
set_render_state(D3DRS_ZWRITEENABLE, TRUE);
@ -3682,7 +3682,9 @@ do_issue_blending() {
// all the other blending-related stuff doesn't matter. If the
// device doesn't support color-write, we use blending tricks
// to effectively disable color write.
if (_target._color_write->get_channels() == ColorWriteAttrib::C_off) {
unsigned int color_channels =
_target._color_write->get_channels() & _color_write_mask;
if (color_channels == ColorWriteAttrib::C_off) {
if (_target._color_write != _state._color_write) {
if (_screen->_can_direct_disable_color_writes) {
set_render_state(D3DRS_ALPHABLENDENABLE, FALSE);
@ -3697,7 +3699,7 @@ do_issue_blending() {
} else {
if (_target._color_write != _state._color_write) {
if (_screen->_can_direct_disable_color_writes) {
set_render_state(D3DRS_COLORWRITEENABLE, _target._color_write->get_channels());
set_render_state(D3DRS_COLORWRITEENABLE, color_channels);
}
}
}

View File

@ -258,7 +258,6 @@ protected:
bool _auto_rescale_normal;
D3DCOLOR _d3dcolor_clear_value;
UINT _color_writemask;
float _material_ambient;
float _material_diffuse;
@ -286,7 +285,6 @@ protected:
PT(ShaderExpansion) _texture_binding_shader_expansion;
CLP(ShaderContext) *_texture_binding_shader_context;
CPT(DisplayRegion) _actual_display_region;
const DXVertexBufferContext9 *_active_vbuffer;
const DXIndexBufferContext9 *_active_ibuffer;