This commit is contained in:
David Rose 2005-06-01 20:44:23 +00:00
parent 7a33e8ddb1
commit 1e13cf99ac
3 changed files with 136 additions and 160 deletions

View File

@ -68,14 +68,13 @@
TypeHandle DXGraphicsStateGuardian8::_type_handle; TypeHandle DXGraphicsStateGuardian8::_type_handle;
static D3DMATRIX matIdentity; D3DMATRIX DXGraphicsStateGuardian8::_d3d_ident_mat;
#define __D3DLIGHT_RANGE_MAX ((float)sqrt(FLT_MAX)) //for some reason this is missing in dx8 hdrs #define __D3DLIGHT_RANGE_MAX ((float)sqrt(FLT_MAX)) //for some reason this is missing in dx8 hdrs
#define MY_D3DRGBA(r, g, b, a) ((D3DCOLOR) D3DCOLOR_COLORVALUE(r, g, b, a)) #define MY_D3DRGBA(r, g, b, a) ((D3DCOLOR) D3DCOLOR_COLORVALUE(r, g, b, a))
static bool tex_stats_retrieval_impossible = false;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::Constructor // Function: DXGraphicsStateGuardian8::Constructor
// Access: Public // Access: Public
@ -92,16 +91,16 @@ DXGraphicsStateGuardian8(const FrameBufferProperties &properties) :
_transform_stale = false; _transform_stale = false;
_vertex_blending_enabled = false; _vertex_blending_enabled = false;
_overlay_windows_supported = false; _overlay_windows_supported = false;
_tex_stats_retrieval_impossible = false;
_active_vbuffer = NULL; _active_vbuffer = NULL;
_active_ibuffer = NULL; _active_ibuffer = NULL;
// non-dx obj values inited here should not change if resize is // This is a static member, but we initialize it here in the
// called and dx objects need to be recreated (otherwise they // constructor anyway. It won't hurt if it gets repeatedly
// belong in dx_init, with other renderstate // initalized.
ZeroMemory(&_d3d_ident_mat, sizeof(D3DMATRIX));
ZeroMemory(&matIdentity, sizeof(D3DMATRIX)); _d3d_ident_mat._11 = _d3d_ident_mat._22 = _d3d_ident_mat._33 = _d3d_ident_mat._44 = 1.0f;
matIdentity._11 = matIdentity._22 = matIdentity._33 = matIdentity._44 = 1.0f;
_cur_read_pixel_buffer = RenderBuffer::T_front; _cur_read_pixel_buffer = RenderBuffer::T_front;
set_color_clear_value(_color_clear_value); set_color_clear_value(_color_clear_value);
@ -204,55 +203,55 @@ apply_texture(int i, TextureContext *tc) {
} }
Texture *tex = tc->_texture; Texture *tex = tc->_texture;
Texture::WrapMode wrapU, wrapV; Texture::WrapMode wrap_u, wrap_v;
wrapU = tex->get_wrap_u(); wrap_u = tex->get_wrap_u();
wrapV = tex->get_wrap_v(); wrap_v = tex->get_wrap_v();
_pD3DDevice->SetTextureStageState(i, D3DTSS_ADDRESSU, get_texture_wrap_mode(wrapU)); _pD3DDevice->SetTextureStageState(i, D3DTSS_ADDRESSU, get_texture_wrap_mode(wrap_u));
_pD3DDevice->SetTextureStageState(i, D3DTSS_ADDRESSV, get_texture_wrap_mode(wrapV)); _pD3DDevice->SetTextureStageState(i, D3DTSS_ADDRESSV, get_texture_wrap_mode(wrap_v));
uint aniso_degree = tex->get_anisotropic_degree(); uint aniso_degree = tex->get_anisotropic_degree();
Texture::FilterType ft = tex->get_magfilter(); Texture::FilterType ft = tex->get_magfilter();
_pD3DDevice->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, aniso_degree); _pD3DDevice->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, aniso_degree);
D3DTEXTUREFILTERTYPE newMagFilter; D3DTEXTUREFILTERTYPE new_mag_filter;
if (aniso_degree <= 1) { if (aniso_degree <= 1) {
newMagFilter = ((ft != Texture::FT_nearest) ? D3DTEXF_LINEAR : D3DTEXF_POINT); new_mag_filter = ((ft != Texture::FT_nearest) ? D3DTEXF_LINEAR : D3DTEXF_POINT);
} else { } else {
newMagFilter = D3DTEXF_ANISOTROPIC; new_mag_filter = D3DTEXF_ANISOTROPIC;
} }
_pD3DDevice->SetTextureStageState(i, D3DTSS_MAGFILTER, newMagFilter); _pD3DDevice->SetTextureStageState(i, D3DTSS_MAGFILTER, new_mag_filter);
// map Panda composite min+mip filter types to d3d's separate min & mip filter types // map Panda composite min+mip filter types to d3d's separate min & mip filter types
D3DTEXTUREFILTERTYPE newMinFilter = get_d3d_min_type(tex->get_minfilter()); D3DTEXTUREFILTERTYPE new_min_filter = get_d3d_min_type(tex->get_minfilter());
D3DTEXTUREFILTERTYPE newMipFilter = get_d3d_mip_type(tex->get_minfilter()); D3DTEXTUREFILTERTYPE new_mip_filter = get_d3d_mip_type(tex->get_minfilter());
if (!tex->might_have_ram_image()) { if (!tex->might_have_ram_image()) {
// If the texture is completely dynamic, don't try to issue // If the texture is completely dynamic, don't try to issue
// mipmaps--pandadx doesn't support auto-generated mipmaps at this // mipmaps--pandadx doesn't support auto-generated mipmaps at this
// point. // point.
newMipFilter = D3DTEXF_NONE; new_mip_filter = D3DTEXF_NONE;
} }
#ifndef NDEBUG #ifndef NDEBUG
// sanity check // sanity check
if ((!dtc->has_mipmaps()) && (newMipFilter != D3DTEXF_NONE)) { if ((!dtc->has_mipmaps()) && (new_mip_filter != D3DTEXF_NONE)) {
dxgsg8_cat.error() dxgsg8_cat.error()
<< "Trying to set mipmap filtering for texture with no generated mipmaps!! texname[" << "Trying to set mipmap filtering for texture with no generated mipmaps!! texname["
<< tex->get_name() << "], filter(" << tex->get_name() << "], filter("
<< tex->get_minfilter() << ")\n"; << tex->get_minfilter() << ")\n";
newMipFilter = D3DTEXF_NONE; new_mip_filter = D3DTEXF_NONE;
} }
#endif #endif
if (aniso_degree >= 2) { if (aniso_degree >= 2) {
newMinFilter = D3DTEXF_ANISOTROPIC; new_min_filter = D3DTEXF_ANISOTROPIC;
} }
_pD3DDevice->SetTextureStageState(i, D3DTSS_MINFILTER, newMinFilter); _pD3DDevice->SetTextureStageState(i, D3DTSS_MINFILTER, new_min_filter);
_pD3DDevice->SetTextureStageState(i, D3DTSS_MIPFILTER, newMipFilter); _pD3DDevice->SetTextureStageState(i, D3DTSS_MIPFILTER, new_mip_filter);
_pD3DDevice->SetTexture(i, dtc->get_d3d_texture()); _pD3DDevice->SetTexture(i, dtc->get_d3d_texture());
} }
@ -265,8 +264,8 @@ apply_texture(int i, TextureContext *tc) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8:: void DXGraphicsStateGuardian8::
release_texture(TextureContext *tc) { release_texture(TextureContext *tc) {
DXTextureContext8 *gtc = DCAST(DXTextureContext8, tc); DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
delete gtc; delete dtc;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -715,7 +714,6 @@ end_scene() {
HRESULT hr = _pD3DDevice->EndScene(); HRESULT hr = _pD3DDevice->EndScene();
if (FAILED(hr)) { if (FAILED(hr)) {
if (hr == D3DERR_DEVICELOST) { if (hr == D3DERR_DEVICELOST) {
if (dxgsg8_cat.is_debug()) { if (dxgsg8_cat.is_debug()) {
dxgsg8_cat.debug() dxgsg8_cat.debug()
@ -745,11 +743,11 @@ end_frame() {
#if defined(DO_PSTATS) #if defined(DO_PSTATS)
if (_texmgrmem_total_pcollector.is_active()) { if (_texmgrmem_total_pcollector.is_active()) {
#define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval #define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval
static DWORD LastTickCount = 0; static DWORD last_tick_count = 0;
DWORD CurTickCount = GetTickCount(); DWORD cur_tick_count = GetTickCount();
if (CurTickCount-LastTickCount > TICKS_PER_GETTEXINFO) { if (cur_tick_count - last_tick_count > TICKS_PER_GETTEXINFO) {
LastTickCount = CurTickCount; last_tick_count = cur_tick_count;
report_texmgr_stats(); report_texmgr_stats();
} }
} }
@ -851,7 +849,7 @@ begin_draw_primitives(const qpGeom *geom, const qpGeomMunger *munger,
// these vertices, but that turns out to be a bigger hammer than // these vertices, but that turns out to be a bigger hammer than
// we want: that also prevents lighting calculations and user clip // we want: that also prevents lighting calculations and user clip
// planes. // planes.
_pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity); _pD3DDevice->SetTransform(D3DTS_WORLD, &_d3d_ident_mat);
static const LMatrix4f rescale_mat static const LMatrix4f rescale_mat
(1, 0, 0, 0, (1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0,
@ -1323,17 +1321,17 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, const
} }
DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc); DXTextureContext8 *dtc = DCAST(DXTextureContext8, tc);
IDirect3DSurface8 *pTexSurfaceLev0, *pCurRenderTarget; IDirect3DSurface8 *tex_level_0, *render_target;
hr = dtc->get_d3d_texture()->GetSurfaceLevel(0, &pTexSurfaceLev0); hr = dtc->get_d3d_texture()->GetSurfaceLevel(0, &tex_level_0);
if (FAILED(hr)) { if (FAILED(hr)) {
dxgsg8_cat.error() << "GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr); dxgsg8_cat.error() << "GetSurfaceLev failed in copy_texture" << D3DERRORSTRING(hr);
return; return;
} }
hr = _pD3DDevice->GetRenderTarget(&pCurRenderTarget); hr = _pD3DDevice->GetRenderTarget(&render_target);
if (FAILED(hr)) { if (FAILED(hr)) {
dxgsg8_cat.error() << "GetRenderTgt failed in copy_texture" << D3DERRORSTRING(hr); dxgsg8_cat.error() << "GetRenderTgt failed in copy_texture" << D3DERRORSTRING(hr);
SAFE_RELEASE(pTexSurfaceLev0); SAFE_RELEASE(tex_level_0);
return; return;
} }
@ -1345,14 +1343,14 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, const
SrcRect.bottom = yo+h; SrcRect.bottom = yo+h;
// now copy from fb to tex // now copy from fb to tex
hr = _pD3DDevice->CopyRects(pCurRenderTarget, &SrcRect, 1, pTexSurfaceLev0, 0); hr = _pD3DDevice->CopyRects(render_target, &SrcRect, 1, tex_level_0, 0);
if (FAILED(hr)) { if (FAILED(hr)) {
dxgsg8_cat.error() dxgsg8_cat.error()
<< "CopyRects failed in copy_texture" << D3DERRORSTRING(hr); << "CopyRects failed in copy_texture" << D3DERRORSTRING(hr);
} }
SAFE_RELEASE(pCurRenderTarget); SAFE_RELEASE(render_target);
SAFE_RELEASE(pTexSurfaceLev0); SAFE_RELEASE(tex_level_0);
} }
@ -1370,7 +1368,7 @@ bool DXGraphicsStateGuardian8::
framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) { framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const RenderBuffer &rb) {
set_read_buffer(rb); set_read_buffer(rb);
RECT SrcCopyRect; RECT rect;
nassertr(tex != NULL && dr != NULL, false); nassertr(tex != NULL && dr != NULL, false);
int xo, yo, w, h; int xo, yo, w, h;
@ -1378,29 +1376,32 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb); tex->setup_2d_texture(w, h, Texture::T_unsigned_byte, Texture::F_rgb);
SrcCopyRect.top = yo; rect.top = yo;
SrcCopyRect.left = xo; rect.left = xo;
SrcCopyRect.right = xo + w; rect.right = xo + w;
SrcCopyRect.bottom = yo + h; rect.bottom = yo + h;
IDirect3DSurface8 *pD3DSurf; IDirect3DSurface8 *framebuffer;
HRESULT hr; HRESULT hr;
if (_cur_read_pixel_buffer & RenderBuffer::T_back) { if (_cur_read_pixel_buffer & RenderBuffer::T_back) {
hr = _pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pD3DSurf); hr = _pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &framebuffer);
if (FAILED(hr)) { if (FAILED(hr)) {
dxgsg8_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr); dxgsg8_cat.error() << "GetBackBuffer failed" << D3DERRORSTRING(hr);
return false; return false;
} }
// note if you try to grab the backbuffer and full-screen anti-aliasing is on, // note if you try to grab the backbuffer and full-screen
// the backbuffer might be larger than the window size. for screenshots its safer to get the front buffer. // anti-aliasing is on, the backbuffer might be larger than the
// window size. for screenshots its safer to get the front
// buffer.
} else if (_cur_read_pixel_buffer & RenderBuffer::T_front) { } else if (_cur_read_pixel_buffer & RenderBuffer::T_front) {
// must create a A8R8G8B8 sysmem surface for GetFrontBuffer to copy to // must create a A8R8G8B8 sysmem surface for GetFrontBuffer to
// copy to
DWORD TmpSurfXsize, TmpSurfYsize; DWORD temp_x_size, temp_y_size;
if (_pScrn->PresParams.Windowed) { if (_pScrn->PresParams.Windowed) {
// GetFrontBuffer retrieves the entire desktop for a monitor, so // GetFrontBuffer retrieves the entire desktop for a monitor, so
@ -1410,30 +1411,30 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
minfo.cbSize = sizeof(MONITORINFO); minfo.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor GetMonitorInfo(_pScrn->hMon, &minfo); // have to use GetMonitorInfo, since this gsg may not be for primary monitor
TmpSurfXsize = RECT_XSIZE(minfo.rcMonitor); temp_x_size = RECT_XSIZE(minfo.rcMonitor);
TmpSurfYsize = RECT_YSIZE(minfo.rcMonitor); temp_y_size = RECT_YSIZE(minfo.rcMonitor);
// set SrcCopyRect to client area of window in scrn coords // set rect to client area of window in scrn coords
ClientToScreen(_pScrn->hWnd, (POINT*)&SrcCopyRect.left); ClientToScreen(_pScrn->hWnd, (POINT*)&rect.left);
ClientToScreen(_pScrn->hWnd, (POINT*)&SrcCopyRect.right); ClientToScreen(_pScrn->hWnd, (POINT*)&rect.right);
} else { } else {
RECT WindRect; RECT wind_rect;
GetWindowRect(_pScrn->hWnd, &WindRect); GetWindowRect(_pScrn->hWnd, &wind_rect);
TmpSurfXsize = RECT_XSIZE(WindRect); temp_x_size = RECT_XSIZE(wind_rect);
TmpSurfYsize = RECT_YSIZE(WindRect); temp_y_size = RECT_YSIZE(wind_rect);
} }
hr = _pD3DDevice->CreateImageSurface(TmpSurfXsize, TmpSurfYsize, D3DFMT_A8R8G8B8, &pD3DSurf); hr = _pD3DDevice->CreateImageSurface(temp_x_size, temp_y_size, D3DFMT_A8R8G8B8, &framebuffer);
if (FAILED(hr)) { if (FAILED(hr)) {
dxgsg8_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr); dxgsg8_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr);
return false; return false;
} }
hr = _pD3DDevice->GetFrontBuffer(pD3DSurf); hr = _pD3DDevice->GetFrontBuffer(framebuffer);
if (hr == D3DERR_DEVICELOST) { if (hr == D3DERR_DEVICELOST) {
pD3DSurf->Release(); framebuffer->Release();
dxgsg8_cat.error() << "copy_pixel_buffer failed: device lost\n"; dxgsg8_cat.error() << "copy_pixel_buffer failed: device lost\n";
return false; return false;
} }
@ -1443,9 +1444,9 @@ framebuffer_copy_to_ram(Texture *tex, int z, const DisplayRegion *dr, const Rend
return false; return false;
} }
DXTextureContext8::d3d_surface_to_texture(SrcCopyRect, pD3DSurf, tex); DXTextureContext8::d3d_surface_to_texture(rect, framebuffer, tex);
RELEASE(pD3DSurf, dxgsg8, "pD3DSurf", RELEASE_ONCE); RELEASE(framebuffer, dxgsg8, "framebuffer", RELEASE_ONCE);
nassertr(tex->has_ram_image(), false); nassertr(tex->has_ram_image(), false);
return true; return true;
@ -1481,36 +1482,36 @@ reset() {
assert(_pScrn->pD3D8 != NULL); assert(_pScrn->pD3D8 != NULL);
assert(_pD3DDevice != NULL); assert(_pD3DDevice != NULL);
D3DCAPS8 d3dCaps; D3DCAPS8 d3d_caps;
_pD3DDevice->GetDeviceCaps(&d3dCaps); _pD3DDevice->GetDeviceCaps(&d3d_caps);
if (dxgsg8_cat.is_debug()) { if (dxgsg8_cat.is_debug()) {
dxgsg8_cat.debug() dxgsg8_cat.debug()
<< "\nHwTransformAndLight = " << ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0) << "\nHwTransformAndLight = " << ((d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)
<< "\nMaxTextureWidth = " << d3dCaps.MaxTextureWidth << "\nMaxTextureWidth = " << d3d_caps.MaxTextureWidth
<< "\nMaxTextureHeight = " << d3dCaps.MaxTextureHeight << "\nMaxTextureHeight = " << d3d_caps.MaxTextureHeight
<< "\nMaxVolumeExtent = " << d3dCaps.MaxVolumeExtent << "\nMaxVolumeExtent = " << d3d_caps.MaxVolumeExtent
<< "\nMaxTextureAspectRatio = " << d3dCaps.MaxTextureAspectRatio << "\nMaxTextureAspectRatio = " << d3d_caps.MaxTextureAspectRatio
<< "\nTexCoordCount = " << (d3dCaps.FVFCaps & D3DFVFCAPS_TEXCOORDCOUNTMASK) << "\nTexCoordCount = " << (d3d_caps.FVFCaps & D3DFVFCAPS_TEXCOORDCOUNTMASK)
<< "\nMaxTextureBlendStages = " << d3dCaps.MaxTextureBlendStages << "\nMaxTextureBlendStages = " << d3d_caps.MaxTextureBlendStages
<< "\nMaxSimultaneousTextures = " << d3dCaps.MaxSimultaneousTextures << "\nMaxSimultaneousTextures = " << d3d_caps.MaxSimultaneousTextures
<< "\nMaxActiveLights = " << d3dCaps.MaxActiveLights << "\nMaxActiveLights = " << d3d_caps.MaxActiveLights
<< "\nMaxUserClipPlanes = " << d3dCaps.MaxUserClipPlanes << "\nMaxUserClipPlanes = " << d3d_caps.MaxUserClipPlanes
<< "\nMaxVertexBlendMatrices = " << d3dCaps.MaxVertexBlendMatrices << "\nMaxVertexBlendMatrices = " << d3d_caps.MaxVertexBlendMatrices
<< "\nMaxVertexBlendMatrixIndex = " << d3dCaps.MaxVertexBlendMatrixIndex << "\nMaxVertexBlendMatrixIndex = " << d3d_caps.MaxVertexBlendMatrixIndex
<< "\nMaxPointSize = " << d3dCaps.MaxPointSize << "\nMaxPointSize = " << d3d_caps.MaxPointSize
<< "\nMaxPrimitiveCount = " << d3dCaps.MaxPrimitiveCount << "\nMaxPrimitiveCount = " << d3d_caps.MaxPrimitiveCount
<< "\nMaxVertexIndex = " << d3dCaps.MaxVertexIndex << "\nMaxVertexIndex = " << d3d_caps.MaxVertexIndex
<< "\nMaxStreams = " << d3dCaps.MaxStreams << "\nMaxStreams = " << d3d_caps.MaxStreams
<< "\nMaxStreamStride = " << d3dCaps.MaxStreamStride << "\nMaxStreamStride = " << d3d_caps.MaxStreamStride
<< "\n"; << "\n";
} }
_max_texture_stages = d3dCaps.MaxSimultaneousTextures; _max_texture_stages = d3d_caps.MaxSimultaneousTextures;
_max_lights = d3dCaps.MaxActiveLights; _max_lights = d3d_caps.MaxActiveLights;
_max_clip_planes = d3dCaps.MaxUserClipPlanes; _max_clip_planes = d3d_caps.MaxUserClipPlanes;
_max_vertex_transforms = d3dCaps.MaxVertexBlendMatrices; _max_vertex_transforms = d3d_caps.MaxVertexBlendMatrices;
_max_vertex_transform_indices = d3dCaps.MaxVertexBlendMatrixIndex; _max_vertex_transform_indices = d3d_caps.MaxVertexBlendMatrixIndex;
ZeroMemory(&_lmodel_ambient, sizeof(Colorf)); ZeroMemory(&_lmodel_ambient, sizeof(Colorf));
_pD3DDevice->SetRenderState(D3DRS_AMBIENT, 0x0); _pD3DDevice->SetRenderState(D3DRS_AMBIENT, 0x0);
@ -1522,7 +1523,7 @@ reset() {
// these both reflect d3d defaults // these both reflect d3d defaults
_color_writemask = 0xFFFFFFFF; _color_writemask = 0xFFFFFFFF;
_CurFVFType = 0x0; // guards SetVertexShader fmt _CurFVFType = 0x0;
_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); _pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
@ -1573,15 +1574,18 @@ reset() {
_pScrn->d3dcaps.MaxTextureHeight = 256; _pScrn->d3dcaps.MaxTextureHeight = 256;
if (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) { if (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) {
// watch out for drivers that emulate per-pixel fog with per-vertex fog (Riva128, Matrox Millen G200) // Watch out for drivers that emulate per-pixel fog with
// some of these require gouraud-shading to be set to work, as if you were using vertex fog // per-vertex fog (Riva128, Matrox Millen G200). Some of these
// require gouraud-shading to be set to work, as if you were using
// vertex fog
_doFogType = PerPixelFog; _doFogType = PerPixelFog;
} else { } else {
// every card is going to have vertex fog, since it's implemented in d3d runtime // every card is going to have vertex fog, since it's implemented
// in d3d runtime.
assert((_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0); assert((_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0);
// vtx fog may look crappy if you have large polygons in the foreground and they get clipped, // vertex fog may look crappy if you have large polygons in the
// so you may want to disable it // foreground and they get clipped, so you may want to disable it
if (dx_no_vertex_fog) { if (dx_no_vertex_fog) {
_doFogType = None; _doFogType = None;
@ -1589,14 +1593,15 @@ reset() {
_doFogType = PerVertexFog; _doFogType = PerVertexFog;
// range-based fog only works with vertex fog in dx7/8 // range-based fog only works with vertex fog in dx7/8
if (dx_use_rangebased_fog && (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)) if (dx_use_rangebased_fog && (_pScrn->d3dcaps.RasterCaps & D3DPRASTERCAPS_FOGRANGE)) {
_pD3DDevice->SetRenderState(D3DRS_RANGEFOGENABLE, true); _pD3DDevice->SetRenderState(D3DRS_RANGEFOGENABLE, true);
}
} }
} }
_pScrn->bCanDirectDisableColorWrites = ((_pScrn->d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0); _pScrn->bCanDirectDisableColorWrites = ((_pScrn->d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0);
// Lighting, let's turn it off by default // Lighting, let's turn it off initially.
_pD3DDevice->SetRenderState(D3DRS_LIGHTING, false); _pD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
// turn on dithering if the rendertarget is < 8bits/color channel // turn on dithering if the rendertarget is < 8bits/color channel
@ -1656,7 +1661,6 @@ reset() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian8:: void DXGraphicsStateGuardian8::
apply_fog(Fog *fog) { apply_fog(Fog *fog) {
if (_doFogType == None) if (_doFogType == None)
return; return;
@ -1728,8 +1732,9 @@ issue_alpha_test(const AlphaTestAttrib *attrib) {
AlphaTestAttrib::PandaCompareFunc mode = attrib->get_mode(); AlphaTestAttrib::PandaCompareFunc mode = attrib->get_mode();
if (mode == AlphaTestAttrib::M_none) { if (mode == AlphaTestAttrib::M_none) {
enable_alpha_test(false); enable_alpha_test(false);
} else { } else {
// AlphaTestAttrib::PandaCompareFunc == = D3DCMPFUNC // AlphaTestAttrib::PandaCompareFunc === D3DCMPFUNC
call_dxAlphaFunc((D3DCMPFUNC)mode, attrib->get_reference_alpha()); call_dxAlphaFunc((D3DCMPFUNC)mode, attrib->get_reference_alpha());
enable_alpha_test(true); enable_alpha_test(true);
} }
@ -2275,7 +2280,7 @@ do_issue_texture() {
// For some reason, "disabling" texture coordinate transforms // For some reason, "disabling" texture coordinate transforms
// doesn't seem to be sufficient. We'll load an identity matrix // doesn't seem to be sufficient. We'll load an identity matrix
// to underscore the point. // to underscore the point.
_pD3DDevice->SetTransform(get_tex_mat_sym(i), &matIdentity); _pD3DDevice->SetTransform(get_tex_mat_sym(i), &_d3d_ident_mat);
} }
} }
@ -2567,36 +2572,6 @@ set_read_buffer(const RenderBuffer &rb) {
return; return;
} }
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::get_smooth_state
// Access: Protected, Static
// Description: Returns a RenderState object that represents
// smooth, per-vertex shading.
////////////////////////////////////////////////////////////////////
CPT(RenderState) DXGraphicsStateGuardian8::
get_smooth_state() {
static CPT(RenderState) state;
if (state == (RenderState *)NULL) {
state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_smooth));
}
return state;
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::get_flat_state
// Access: Protected, Static
// Description: Returns a RenderState object that represents
// flat, per-primitive shading.
////////////////////////////////////////////////////////////////////
CPT(RenderState) DXGraphicsStateGuardian8::
get_flat_state() {
static CPT(RenderState) state;
if (state == (RenderState *)NULL) {
state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat));
}
return state;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian8::do_auto_rescale_normal // Function: DXGraphicsStateGuardian8::do_auto_rescale_normal
// Access: Protected // Access: Protected
@ -2736,7 +2711,7 @@ report_texmgr_stats() {
D3DDEVINFO_RESOURCEMANAGER all_resource_stats; D3DDEVINFO_RESOURCEMANAGER all_resource_stats;
ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER)); ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
if (!tex_stats_retrieval_impossible) { if (!_tex_stats_retrieval_impossible) {
hr = _pD3DDevice->GetInfo(D3DDEVINFOID_RESOURCEMANAGER, &all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER)); hr = _pD3DDevice->GetInfo(D3DDEVINFOID_RESOURCEMANAGER, &all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
if (hr != D3D_OK) { if (hr != D3D_OK) {
if (hr == S_FALSE) { if (hr == S_FALSE) {
@ -2747,7 +2722,7 @@ report_texmgr_stats() {
<< "texstats GetInfo() requires debug DX DLLs to be installed!!\n"; << "texstats GetInfo() requires debug DX DLLs to be installed!!\n";
} }
ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER)); ZeroMemory(&all_resource_stats, sizeof(D3DDEVINFO_RESOURCEMANAGER));
tex_stats_retrieval_impossible = true; _tex_stats_retrieval_impossible = true;
} }
} else { } else {
dxgsg8_cat.error() << "GetInfo(RESOURCEMANAGER) failed to get tex stats: result = " << D3DERRORSTRING(hr); dxgsg8_cat.error() << "GetInfo(RESOURCEMANAGER) failed to get tex stats: result = " << D3DERRORSTRING(hr);

View File

@ -133,15 +133,12 @@ protected:
virtual void set_blend_mode(); virtual void set_blend_mode();
void free_nondx_resources(); // free local internal buffers void free_nondx_resources();
void free_d3d_device(void); void free_d3d_device(void);
void set_draw_buffer(const RenderBuffer &rb); void set_draw_buffer(const RenderBuffer &rb);
void set_read_buffer(const RenderBuffer &rb); void set_read_buffer(const RenderBuffer &rb);
static CPT(RenderState) get_smooth_state();
static CPT(RenderState) get_flat_state();
void do_auto_rescale_normal(); void do_auto_rescale_normal();
protected: protected:
@ -171,7 +168,8 @@ protected:
void set_texture_blend_mode(int i, const TextureStage *stage); void set_texture_blend_mode(int i, const TextureStage *stage);
void dx_cleanup(); void dx_cleanup();
HRESULT reset_d3d_device(D3DPRESENT_PARAMETERS *pPresParams, DXScreenData **pScrn=NULL); HRESULT reset_d3d_device(D3DPRESENT_PARAMETERS *pPresParams,
DXScreenData **pScrn = NULL);
bool check_cooperative_level(); bool check_cooperative_level();
@ -247,6 +245,9 @@ protected:
const DXIndexBufferContext8 *_active_ibuffer; const DXIndexBufferContext8 *_active_ibuffer;
bool _overlay_windows_supported; bool _overlay_windows_supported;
bool _tex_stats_retrieval_impossible;
static D3DMATRIX _d3d_ident_mat;
public: public:
virtual TypeHandle get_type() const { virtual TypeHandle get_type() const {

View File

@ -185,28 +185,28 @@ typedef enum {
#define RECT_XSIZE(REC) (REC.right-REC.left) #define RECT_XSIZE(REC) (REC.right-REC.left)
#define RECT_YSIZE(REC) (REC.bottom-REC.top) #define RECT_YSIZE(REC) (REC.bottom-REC.top)
typedef struct { struct DXScreenData {
LPDIRECT3DDEVICE8 pD3DDevice; LPDIRECT3DDEVICE8 pD3DDevice;
IDirect3DSwapChain8 *pSwapChain; IDirect3DSwapChain8 *pSwapChain;
LPDIRECT3D8 pD3D8; // copied from DXGraphicsPipe8 for convenience LPDIRECT3D8 pD3D8; // copied from DXGraphicsPipe8 for convenience
HWND hWnd; HWND hWnd;
HMONITOR hMon; HMONITOR hMon;
DWORD MaxAvailVidMem; DWORD MaxAvailVidMem;
ushort CardIDNum; // adapter ID ushort CardIDNum; // adapter ID
ushort depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly ushort depth_buffer_bitdepth; //GetSurfaceDesc is not reliable so must store this explicitly
bool bCanDirectDisableColorWrites; // if true, dont need blending for this bool bCanDirectDisableColorWrites; // if true, dont need blending for this
bool bIsLowVidMemCard; bool bIsLowVidMemCard;
bool bIsTNLDevice; bool bIsTNLDevice;
bool bCanUseHWVertexShaders; bool bCanUseHWVertexShaders;
bool bCanUsePixelShaders; bool bCanUsePixelShaders;
bool bIsDX81; bool bIsDX81;
UINT SupportedScreenDepthsMask; UINT SupportedScreenDepthsMask;
UINT SupportedTexFmtsMask; UINT SupportedTexFmtsMask;
D3DCAPS8 d3dcaps; D3DCAPS8 d3dcaps;
D3DDISPLAYMODE DisplayMode; D3DDISPLAYMODE DisplayMode;
D3DPRESENT_PARAMETERS PresParams; // not redundant with DisplayMode since width/height must be 0 for windowed mode D3DPRESENT_PARAMETERS PresParams; // not redundant with DisplayMode since width/height must be 0 for windowed mode
D3DADAPTER_IDENTIFIER8 DXDeviceID; D3DADAPTER_IDENTIFIER8 DXDeviceID;
} DXScreenData; };
//utility stuff //utility stuff