From 677aaa7a93f5324082bf7c462a3aa0f0248197d5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 15 Aug 2003 23:55:05 +0000 Subject: [PATCH] fix display region area for DX --- panda/src/display/displayRegion.I | 2 ++ panda/src/display/displayRegion.cxx | 19 ++++++++++++++++++- panda/src/display/displayRegion.h | 3 +++ panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx | 12 ++++-------- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 9 +++++---- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/panda/src/display/displayRegion.I b/panda/src/display/displayRegion.I index cb11cfd6f2..0ba8414d09 100644 --- a/panda/src/display/displayRegion.I +++ b/panda/src/display/displayRegion.I @@ -40,6 +40,8 @@ do_compute_pixels(int x_size, int y_size) { _pr = int((_r * x_size) + 0.5); _pb = int((_b * y_size) + 0.5); _pt = int((_t * y_size) + 0.5); + _pbi = int(((1.0f - _b) * y_size) + 0.5); + _pti = int(((1.0f - _t) * y_size) + 0.5); } diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 979aa61585..1ea6206af3 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -68,7 +68,7 @@ DisplayRegion(GraphicsLayer *layer, const float l, DisplayRegion:: DisplayRegion(int xsize, int ysize) : _l(0.), _r(1.), _b(0.), _t(1.), - _pl(0), _pr(xsize), _pb(0), _pt(ysize), + _pl(0), _pr(xsize), _pb(0), _pt(ysize), _pbi(ysize), _pti(0), _layer((GraphicsLayer *)NULL), _camera_node((Camera *)NULL), _active(true) @@ -386,6 +386,23 @@ get_region_pixels(int &xo, int &yo, int &w, int &h) const { h = _pt - _pb; } +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::get_region_pixels_i +// Access: Published +// Description: Similar to get_region_pixels(), but returns the upper +// left corner, and the pixel numbers are numbered from +// the top-left corner down, in the DirectX way of +// things. +//////////////////////////////////////////////////////////////////// +void DisplayRegion:: +get_region_pixels_i(int &xo, int &yo, int &w, int &h) const { + MutexHolder holder(_lock); + xo = _pl; + yo = _pti; + w = _pr - _pl; + h = _pbi - _pti; +} + //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::get_pixel_width // Access: Published diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index bc804bc869..b87c5b1aed 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -77,6 +77,7 @@ PUBLISHED: void compute_pixels(int x_size, int y_size); void get_pixels(int &pl, int &pr, int &pb, int &pt) const; void get_region_pixels(int &xo, int &yo, int &w, int &h) const; + void get_region_pixels_i(int &xo, int &yo, int &w, int &h) const; int get_pixel_width() const; int get_pixel_height() const; @@ -97,6 +98,8 @@ private: int _pr; int _pb; int _pt; + int _pbi; + int _pti; GraphicsLayer *_layer; NodePath _camera; diff --git a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx index 6979f94ff3..9f05480133 100644 --- a/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx +++ b/panda/src/dxgsg7/dxGraphicsStateGuardian7.cxx @@ -761,19 +761,15 @@ prepare_display_region() { } else if (_current_display_region != _actual_display_region) { _actual_display_region = _current_display_region; - int l, b, w, h; - _actual_display_region->get_region_pixels(l, b, w, h); + int l, u, w, h; + _actual_display_region->get_region_pixels_i(l, u, w, h); // Create the viewport - D3DVIEWPORT7 vp = { - l, b, - w, h, - 0.0f, 1.0f - }; + D3DVIEWPORT7 vp = { l, u, w, h, 0.0f, 1.0f }; HRESULT hr = _pScrn->pD3DDevice->SetViewport(&vp); if (FAILED(hr)) { dxgsg7_cat.error() - << "SetViewport(" << l << ", " << b << ", " << w << ", " << h + << "SetViewport(" << l << ", " << u << ", " << w << ", " << h << ") failed : result = " << ConvD3DErrorToString(hr) << endl; throw_event("panda3d-render-error"); diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 36f4da0e96..0614bc38e8 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -990,17 +990,18 @@ prepare_display_region() { } else if (_current_display_region != _actual_display_region) { _actual_display_region = _current_display_region; - int l, b, w, h; - _actual_display_region->get_region_pixels(l, b, w, h); + int l, u, w, h; + _actual_display_region->get_region_pixels_i(l, u, w, h); // Create the viewport - D3DVIEWPORT8 vp = {l,b,w,h,0.0f,1.0f}; + D3DVIEWPORT8 vp = { l, u, w, h, 0.0f, 1.0f }; HRESULT hr = _pD3DDevice->SetViewport( &vp ); if (FAILED(hr)) { dxgsg8_cat.error() - << "SetViewport(" << l << ", " << b << ", " << w << ", " << h + << "SetViewport(" << l << ", " << u << ", " << w << ", " << h << ") failed" << D3DERRORSTRING(hr); throw_event("panda3d-render-error"); + nassertv(false); } // Note: for DX9, also change scissor clipping state here }