fix display region area for DX

This commit is contained in:
David Rose 2003-08-15 23:55:05 +00:00
parent 9153d8fe8f
commit 677aaa7a93
5 changed files with 32 additions and 13 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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");

View File

@ -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
}