diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 56bafdc126..e91141dd1b 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -112,7 +112,7 @@ static void CountDPs(DWORD nVerts,DWORD nTris) { cVertcount+=nVerts; cTricount+=nTris; - if(_pCurDeviceTexture==pLastTexture) { + if(_pCurDeviceTexture==pLastTexture) { cDP_noTexChangeCount++; } else pLastTexture = _pCurDeviceTexture; } @@ -152,7 +152,7 @@ Colorf_to_D3DCOLOR(const Colorf &cColorf) { fld DWORD PTR [ecx+4] ;grn fmul ST(0),ST(1) - fistp tempcolorval + fistp tempcolorval mov ebx,tempcolorval shl ebx, 8 or eax,ebx @@ -249,15 +249,15 @@ read_pixel_shader(string &filename) { dxgsg_cat.error() << "Could not find shader file '"<< filename << "'\n"; return NULL; } - + UINT BytesRead,FileSize = GetFileSize(hFile, NULL); - + pShaderBytes = new BYTE[FileSize]; if (pShaderBytes==NULL) { dxgsg_cat.error() << "MemAlloc failed for shader file '"<< filename << "'\n"; goto exit_create_pshader; } - + ReadFile(hFile, (void*)pShaderBytes, FileSize, (LPDWORD)&BytesRead, NULL); assert(BytesRead==FileSize); } else { @@ -272,7 +272,7 @@ read_pixel_shader(string &filename) { if ( FindFileHandle == INVALID_HANDLE_VALUE ) { dxgsg_cat.error() << "Could not find shader file '"<< filename << "'\n"; return NULL; - } + } FindClose(FindFileHandle); hr = D3DXAssembleShaderFromFile(filename.c_str(),D3DXASM_DEBUG,NULL,&pD3DXBuf_CompiledShader,&pD3DXBuf_CompilationErrors); @@ -287,13 +287,13 @@ read_pixel_shader(string &filename) { #endif } - hr = scrn.pD3DDevice->CreatePixelShader((DWORD*) ((pD3DXBuf_CompiledShader!=NULL) ? pD3DXBuf_CompiledShader->GetBufferPointer() : pShaderBytes), + hr = scrn.pD3DDevice->CreatePixelShader((DWORD*) ((pD3DXBuf_CompiledShader!=NULL) ? pD3DXBuf_CompiledShader->GetBufferPointer() : pShaderBytes), &hShader); if (FAILED(hr)) { dxgsg_cat.error() << "CreatePixelShader failed for '"<< filename << "' " << D3DERRORSTRING(hr); hShader=NULL; } - + assert(hShader!=NULL); // NULL is invalid I hope #ifdef _DEBUG @@ -328,7 +328,7 @@ read_vertex_shader(string &filename) { D3DVSD_STREAM(0), D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3 ), // input register v0 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR ), // input Register v5 - // D3DVSD_CONST(0,1),*(DWORD*)&c[0],*(DWORD*)&c[1],*(DWORD*)&c[2],*(DWORD*)&c[3], + // D3DVSD_CONST(0,1),*(DWORD*)&c[0],*(DWORD*)&c[1],*(DWORD*)&c[2],*(DWORD*)&c[3], }; memcpy(ShaderDeclHeader,Predefined_DeclArray,sizeof(Predefined_DeclArray)); @@ -345,15 +345,15 @@ read_vertex_shader(string &filename) { dxgsg_cat.error() << "Could not find shader file '"<< filename << "'\n"; return NULL; } - + UINT BytesRead,FileSize = GetFileSize(hFile, NULL); - + pShaderBytes = new BYTE[FileSize]; if (pShaderBytes==NULL) { dxgsg_cat.error() << "MemAlloc failed for shader file '"<< filename << "'\n"; goto exit_create_vshader; } - + ReadFile(hFile, (void*)pShaderBytes, FileSize, (LPDWORD)&BytesRead, NULL); assert(BytesRead==FileSize); } else { @@ -368,7 +368,7 @@ read_vertex_shader(string &filename) { if ( FindFileHandle == INVALID_HANDLE_VALUE ) { dxgsg_cat.error() << "Could not find shader file '"<< filename << "'\n"; return NULL; - } + } FindClose(FindFileHandle); hr = D3DXAssembleShaderFromFile(filename.c_str(),D3DXASM_DEBUG,&pD3DXBuf_Constants,&pD3DXBuf_CompiledShader,&pD3DXBuf_CompilationErrors); @@ -395,13 +395,13 @@ read_vertex_shader(string &filename) { UINT UsageFlags = (scrn.bCanUseHWVertexShaders ? 0x0 : D3DUSAGE_SOFTWAREPROCESSING); hr = scrn.pD3DDevice->CreateVertexShader((DWORD*)ShaderDeclHeader, - (DWORD*) ((pD3DXBuf_CompiledShader!=NULL) ? pD3DXBuf_CompiledShader->GetBufferPointer() : pShaderBytes), + (DWORD*) ((pD3DXBuf_CompiledShader!=NULL) ? pD3DXBuf_CompiledShader->GetBufferPointer() : pShaderBytes), &hShader, UsageFlags); if (FAILED(hr)) { dxgsg_cat.error() << "CreateVertexShader failed for '"<< filename << "' " << D3DERRORSTRING(hr); hShader=NULL; } - + assert(hShader!=NULL); // NULL is invalid I hope #ifdef _DEBUG @@ -463,7 +463,7 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { // _max_light_range = __D3DLIGHT_RANGE_MAX; - // non-dx obj values inited here should not change if resize is + // non-dx obj values inited here should not change if resize is // called and dx objects need to be recreated (otherwise they // belong in dx_init, with other renderstate @@ -499,7 +499,7 @@ DXGraphicsStateGuardian:: void DXGraphicsStateGuardian:: reset(void) { reset_panda_gsg(); - dxgsg_cat.error() << "DXGSG reset() not implemented properly yet!\n"; + dxgsg_cat.error() << "DXGSG reset() not implemented properly yet!\n"; // what else do we need to do? // delete all the objs too, right? // need to do a @@ -509,12 +509,12 @@ reset(void) { // setup up for re-calling dx_init(), this is not the final exit cleanup routine (see dx_cleanup) void DXGraphicsStateGuardian:: free_d3d_device(void) { - // dont want a full reset of gsg, just a state clear + // dont want a full reset of gsg, just a state clear set_state(RenderState::make_empty()); // want gsg to pass all state settings through _bDXisReady = false; - + if(scrn.pD3DDevice!=NULL) for(int i=0;iSetTexture(i,NULL); // d3d should release this stuff internally anyway, but whatever @@ -576,7 +576,7 @@ dx_init(HCURSOR hMouseCursor) { scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPING, true); _clipping_enabled = true; - // these both reflect d3d defaults + // these both reflect d3d defaults _color_writemask = 0xFFFFFFFF; _CurFVFType = 0x0; // guards SetVertexShader fmt @@ -587,7 +587,7 @@ dx_init(HCURSOR hMouseCursor) { // (not related to gouraud/flat shading) // scrn.pD3DDevice->SetRenderState(D3DRS_COLORVERTEX, true); - _depth_test_enabled = true; + _depth_test_enabled = true; scrn.pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, _depth_test_enabled); _pCurTexContext = NULL; @@ -597,7 +597,7 @@ dx_init(HCURSOR hMouseCursor) { _color_material_enabled = false; _normals_enabled = false; - + _depth_test_enabled = D3DZB_FALSE; scrn.pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); @@ -630,7 +630,7 @@ dx_init(HCURSOR hMouseCursor) { global_pD3DDevice = pDevice; #endif _pCurrentGeomContext = NULL; - _bDrawPrimDoSetupVertexBuffer = false; + _bDrawPrimDoSetupVertexBuffer = false; _last_testcooplevel_result = D3D_OK; @@ -695,7 +695,7 @@ dx_init(HCURSOR hMouseCursor) { dxgsg_cat.error() << "device is missing alpha blending capabilities, blending may not work correctly: SrcBlendCaps: 0x"<< (void*) scrn.d3dcaps.SrcBlendCaps << " DestBlendCaps: "<< (void*) scrn.d3dcaps.DestBlendCaps << endl; } -// just 'require' bilinear with mip nearest. +// just 'require' bilinear with mip nearest. #define REQUIRED_TEXFILTERCAPS (D3DPTFILTERCAPS_MAGFLINEAR | D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MINFLINEAR) if ((scrn.d3dcaps.TextureFilterCaps & REQUIRED_TEXFILTERCAPS)!=REQUIRED_TEXFILTERCAPS) { @@ -768,7 +768,7 @@ dx_init(HCURSOR hMouseCursor) { _current_fill_mode = RenderModeAttrib::M_filled; scrn.pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); - scrn.pD3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); // Use the diffuse vertex color. + scrn.pD3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); // Use the diffuse vertex color. /* Panda no longer requires us to specify the maximum number of @@ -777,12 +777,13 @@ dx_init(HCURSOR hMouseCursor) { limit or not. Until we override this function, there is no limit. - if(scrn.d3dcaps.MaxActiveLights==0) { + if(scrn.d3dcaps.MaxActiveLights==0) { // 0 indicates no limit on # of lights, but we use DXGSG_MAX_LIGHTS anyway for now init_lights(DXGSG_MAX_LIGHTS); } else { init_lights(min(DXGSG_MAX_LIGHTS,scrn.d3dcaps.MaxActiveLights)); - } */ + } + */ if(dx_auto_normalize_lighting) scrn.pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); @@ -824,7 +825,7 @@ dx_init(HCURSOR hMouseCursor) { scrn.pD3DDevice->SetRenderState(D3DRS_CULLMODE, dx_force_backface_culling); } else { dx_force_backface_culling=0; - if(dxgsg_cat.is_debug()) + if(dxgsg_cat.is_debug()) dxgsg_cat.debug() << "error, invalid value for dx-force-backface-culling\n"; } } @@ -910,7 +911,7 @@ dx_init(HCURSOR hMouseCursor) { CPT(RenderAttrib) dta = DepthTestAttrib::make(DepthTestAttrib::M_less); CPT(RenderAttrib) dwa = DepthWriteAttrib::make(DepthWriteAttrib::M_on); CPT(RenderAttrib) cfa = CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise); - + dta->issue(this); dwa->issue(this); cfa->issue(this); @@ -948,7 +949,7 @@ init_shader(ShaderType stype,DXShaderHandle &hShader,string *pFname) { HRESULT hr; char *sh_typename; - if(stype==VertexShader) + if(stype==VertexShader) sh_typename="Vertex"; else sh_typename="Pixel"; @@ -959,14 +960,14 @@ init_shader(ShaderType stype,DXShaderHandle &hShader,string *pFname) { if((hShader!=NULL)&&(!scrn.bIsDX81)) { // for dx8.0, need to release and recreate shaders after Reset() has been called - if(stype==VertexShader) + if(stype==VertexShader) hr = scrn.pD3DDevice->DeleteVertexShader(hShader); else hr = scrn.pD3DDevice->DeletePixelShader(hShader); if(FAILED(hr)) dxgsg_cat.error() << "Delete"<< sh_typename<<"Shader failed!" << D3DERRORSTRING(hr); hShader=NULL; } - + if(hShader==NULL) { // doing SetShader globally for testing purps. this really should be an object attribute // like current-texture is so it gets set and unset during traversal @@ -1007,7 +1008,7 @@ support_overlay_window(bool flag) { if (_overlay_windows_supported && !flag) { // Disable support for overlay windows. _overlay_windows_supported = false; - + if (dx_full_screen) { scrn.pddsPrimary->SetClipper(NULL); } @@ -1019,7 +1020,7 @@ support_overlay_window(bool flag) { if (dx_full_screen) { // Create a Clipper object to blt the whole screen. LPDIRECTDRAWCLIPPER Clipper; - + if (scrn.pDD->CreateClipper(0, &Clipper, NULL) == DD_OK) { Clipper->SetHWnd(0, scrn.hWnd); scrn.pddsPrimary->SetClipper(Clipper); @@ -1234,15 +1235,15 @@ report_texmgr_stats() { #endif { DDSCAPS2 ddsCaps; - + ZeroMemory(&ddsCaps,sizeof(ddsCaps)); - + ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; if(FAILED( hr = scrn.pD3DDevice->GetAvailableVidMem(&ddsCaps,&dwVidTotal,&dwVidFree))) { dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << D3DERRORSTRING(hr); exit(1); } - + ddsCaps.dwCaps = DDSCAPS_TEXTURE; if(FAILED( hr = scrn.pD3DDevice->GetAvailableVidMem(&ddsCaps,&dwTexTotal,&dwTexFree))) { dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << D3DERRORSTRING(hr); @@ -1297,7 +1298,7 @@ report_texmgr_stats() { char hitrate_str[20]; float fHitRate = (pRStats->NumUsedInVidMem * 100.0f) / pRStats->NumUsed; sprintf(hitrate_str,"%.1f",fHitRate); - + dxgsg_cat.spam() << "\n***** Stats for " << ResourceNameStrs[r] << " ********" << "\n HitRate:\t" << hitrate_str << "%" @@ -1326,7 +1327,7 @@ report_texmgr_stats() { dxgsg_cat.error() << "GetInfo(D3DVERTEXSTATS) failed : result = " << D3DERRORSTRING(hr); return; } else { - dxgsg_cat.spam() + dxgsg_cat.spam() << "\n***** Triangle Stats ********" << "\n NumRenderedTriangles:\t" << vtxstats.NumRenderedTriangles << "\n NumExtraClippingTriangles:\t" << vtxstats.NumExtraClippingTriangles << endl; @@ -1379,7 +1380,7 @@ typedef enum { _pCurrentGeomContext->_PrimInfo.push_back(dpInfo); \ _pCurrentGeomContext->_num_verts+=dpInfo.nVerts; \ _pCurrentGeomContext->_pEndofVertData+=numVertBytes; } - + INLINE void DXGraphicsStateGuardian:: transform_color(Colorf &InColor,D3DCOLOR &OutRGBAColor) { @@ -1421,7 +1422,7 @@ draw_prim_setup(const Geom *geom) { }} //////// - + // this stuff should eventually replace the iterators below PTA_Vertexf coords; PTA_ushort vindexes; @@ -1468,7 +1469,7 @@ draw_prim_setup(const Geom *geom) { _perVertex &= ~PER_COLOR; _perPrim &= ~PER_COLOR; _perComp &= ~PER_COLOR; - } + } } if (geom->get_binding(G_NORMAL) != G_OFF) { @@ -1507,7 +1508,7 @@ draw_prim_setup(const Geom *geom) { // Note on fogging: // the fogging expression should really be || (_fog_enabled && (_doFogType==PerVertexFog)) - // instead of just || (_fog_enabled), since GOURAUD shading should not be required for PerPixel + // instead of just || (_fog_enabled), since GOURAUD shading should not be required for PerPixel // fog, but the problem is some cards (Riva128,Matrox G200) emulate pixel fog with table fog // but dont force the shading mode to gouraud internally, so you end up with flat-shaded fog colors // (note, TNT does the right thing tho). So I guess we must do gouraud shading for all fog rendering for now @@ -1533,7 +1534,7 @@ draw_prim_inner_loop(int nVerts, const Geom *geom, ushort perFlags) { for(;nVerts > 0;nVerts--) { // coord info will always be _perVertex - GET_NEXT_VERTEX(NextVert); // need to optimize these + GET_NEXT_VERTEX(NextVert); // need to optimize these add_to_FVFBuf((void *)&NextVert, 3*sizeof(float)); if(perFlags==(ushort)TexCoordOnly) { @@ -1578,7 +1579,7 @@ draw_prim_inner_loop(int nVerts, const Geom *geom, ushort perFlags) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: draw_prim_inner_loop_coordtexonly(int nVerts, const Geom *geom) { - // assumes coord and texcoord data is per-vertex, + // assumes coord and texcoord data is per-vertex, // color is not per-vert/component (which would require fetching new vals in the vertex loop), // and no normal data. this should be common situation for animated character data // inc'ing local ptrs instead of member ones, seems to optimize better @@ -1606,7 +1607,7 @@ draw_prim_inner_loop_coordtexonly(int nVerts, const Geom *geom) { for(;nVerts>0;nVerts--) { if(bDoIndexedCoords) { memcpy(pLocalFvfBufPtr,(void*)&_coord_array[*pCurCoordIndex],3*sizeof(float)); - pCurCoordIndex++; + pCurCoordIndex++; } else { memcpy(pLocalFvfBufPtr,(void*)pCurCoord,3*sizeof(float)); pCurCoord++; @@ -1645,10 +1646,10 @@ draw_point(GeomPoint *geom, GeomContext *gc) { #ifdef GSG_VERBOSE dxgsg_cat.debug() << "draw_point()" << endl; #endif - + DO_PSTATS_STUFF(PStatTimer timer(_draw_primitive_pcollector)); DO_PSTATS_STUFF(_vertices_other_pcollector.add_level(geom->get_num_vertices())); - + // The DX Way int nPrims = geom->get_num_prims(); @@ -1685,7 +1686,7 @@ draw_point(GeomPoint *geom, GeomContext *gc) { // need to add code to handle fully indexed mode (and handle cases with index arrays of different lengths, // values (may only be possible to handle certain cases without reverting to old pipeline) - _perVertex = 0x0; + _perVertex = 0x0; _perPrim = 0; if (geom->get_binding(G_NORMAL) == G_PER_VERTEX) _perVertex |= PER_NORMAL; if (geom->get_binding(G_COLOR) == G_PER_VERTEX) _perVertex |= PER_COLOR; @@ -1705,7 +1706,7 @@ draw_point(GeomPoint *geom, GeomContext *gc) { } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_POINTLIST,nPrims); } - + _pCurFvfBufPtr = NULL; } @@ -1923,7 +1924,7 @@ draw_linestrip_base(Geom* geom, GeomContext *gc, bool bConnectEnds) { TestDrawPrimFailure(DrawPrim,hr,scrn.pD3DDevice,nVerts,0); } else { COPYVERTDATA_2_VERTEXBUFFER(D3DPT_LINESTRIP,nVerts); - } + } _pCurFvfBufPtr = NULL; } @@ -2036,7 +2037,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { float tex_right = geom->get_ur_uv()[0]; float tex_bottom = geom->get_ll_uv()[1]; float tex_top = geom->get_ur_uv()[1]; - + float half_width = 0.5f * tex_xsize * fabs(tex_right - tex_left); float half_height = 0.5f * tex_ysize * fabs(tex_top - tex_bottom); float scaled_width, scaled_height; @@ -2159,7 +2160,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // disabling dither for alpha particle-systems. // ATI sez: most applications ignore the fact that since alpha blended primitives - // combine the data in the frame buffer with the data in the current pixel, pixels + // combine the data in the frame buffer with the data in the current pixel, pixels // can be dithered multiple times and accentuate the dither pattern. This is particularly // true in particle systems which rely on the cumulative visual effect of many overlapping // alpha blended primitives. @@ -2181,8 +2182,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { D3DCOLOR CurColor; DWORD FVFType = D3DFVF_XYZ | (D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)) | D3DFVF_DIFFUSE; - DWORD vertex_size = sizeof(float) * 2 + sizeof(float) * 3 + sizeof(D3DCOLOR); - + DWORD vertex_size = sizeof(float) * 2 + sizeof(float) * 3 + sizeof(D3DCOLOR); + if (color_overall) { GET_NEXT_COLOR(); CurColor = _curD3Dcolor; @@ -2274,8 +2275,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // if flat shading, dont need to write color for middle vtx, just incr ptr if(bUseGouraudShadedColor) - *((DWORD *)_pCurFvfBufPtr) = (DWORD) CurColor; - _pCurFvfBufPtr += sizeof(D3DCOLOR); + *((DWORD *)_pCurFvfBufPtr) = (DWORD) CurColor; + _pCurFvfBufPtr += sizeof(D3DCOLOR); add_to_FVFBuf((void *)TexCrdSets[1], sizeof(float)*2); @@ -2284,7 +2285,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { add_to_FVFBuf((void *)ul.get_data(), 3*sizeof(float)); // if flat shading, dont need to write color for middle vtx, just incr ptr if(bUseGouraudShadedColor) - *((DWORD *)_pCurFvfBufPtr) = (DWORD) CurColor; + *((DWORD *)_pCurFvfBufPtr) = (DWORD) CurColor; _pCurFvfBufPtr += sizeof(D3DCOLOR); add_to_FVFBuf((void *)TexCrdSets[2], sizeof(float)*2); @@ -2307,7 +2308,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // cant do tristrip/fan since multiple quads arent connected // best we can do is indexed primitive, which sends 2 redundant indices instead of sending 2 redundant full verts HRESULT hr = scrn.pD3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, // start index in array - nVerts, numTris, + nVerts, numTris, _index_buf, D3DFMT_INDEX16, _pFvfBufBasePtr, vertex_size); TestDrawPrimFailure(DrawIndexedPrim,hr,scrn.pD3DDevice,QUADVERTLISTLEN*nPrims,numTris); @@ -2387,7 +2388,7 @@ draw_tri(GeomTri *geom, GeomContext *gc) { DO_PSTATS_STUFF(_vertices_tri_pcollector.add_level(geom->get_num_vertices())); #if 0 - if (_pCurTexContext!=NULL) { + if (_pCurTexContext!=NULL) { dxgsg_cat.spam() << "Cur active DX texture: " << _pCurTexContext->_tex->get_name() << "\n"; } #endif @@ -2410,7 +2411,7 @@ draw_tri(GeomTri *geom, GeomContext *gc) { geom->get_normals(norms,NormalBinding,nindexes); geom->get_colors(colors,ColorBinding,cindexes); geom->get_texcoords(texcoords,TexCoordBinding,tindexes); - + // this is the old geom setup, it reformats every vtx into an output array passed to d3d _perVertex = 0x0; @@ -2425,22 +2426,22 @@ draw_tri(GeomTri *geom, GeomContext *gc) { bool bPerPrimColor=(ColorBinding == G_PER_PRIM); if(bPerPrimColor) _perPrim = PER_COLOR; - else if(ColorBinding == G_PER_VERTEX) + else if(ColorBinding == G_PER_VERTEX) _perVertex = PER_COLOR; if(bUseTexCoordOnlyLoop) { - _perVertex |= PER_TEXCOORD; // TexCoords are either G_OFF or G_PER_VERTEX + _perVertex |= PER_TEXCOORD; // TexCoords are either G_OFF or G_PER_VERTEX } else { if(NormalBinding == G_PER_VERTEX) _perVertex |= PER_NORMAL; - else if(NormalBinding == G_PER_PRIM) + else if(NormalBinding == G_PER_PRIM) _perPrim |= PER_NORMAL; bPerPrimNormal=((_perPrim & PER_NORMAL)!=0); - if(TexCoordBinding == G_PER_VERTEX) + if(TexCoordBinding == G_PER_VERTEX) _perVertex |= PER_TEXCOORD; - } + } size_t vertex_size = draw_prim_setup(geom); @@ -2456,7 +2457,7 @@ draw_tri(GeomTri *geom, GeomContext *gc) { } if(bUseTexCoordOnlyLoop) { - draw_prim_inner_loop_coordtexonly(3, geom); + draw_prim_inner_loop_coordtexonly(3, geom); } else { if(bPerPrimNormal) p_normal = geom->get_next_normal(ni); // set primitive normal if there is one. @@ -2610,7 +2611,7 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { break; } - bPerPrimNormal=((_perPrim & PER_NORMAL)!=0); + bPerPrimNormal=((_perPrim & PER_NORMAL)!=0); if (TexCoordBinding == G_PER_VERTEX) _perVertex |= PER_TEXCOORD; @@ -2630,7 +2631,7 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { if(pLengthArr!=NULL) { nVerts = *(pLengthArr++); - } + } if(bPerPrimColor) { // remember color might be G_OVERALL too! GET_NEXT_COLOR(); @@ -2644,8 +2645,8 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { _pCurFvfBufPtr = _pFvfBufBasePtr; // _pCurFvfBufPtr changes, _pFvfBufBasePtr doesn't if(_perComp==0x0) { - if(bUseTexCoordOnlyLoop) { - draw_prim_inner_loop_coordtexonly(nVerts, geom); + if(bUseTexCoordOnlyLoop) { + draw_prim_inner_loop_coordtexonly(nVerts, geom); } else { if (bPerPrimNormal) p_normal = geom->get_next_normal(ni); // set primitive normal if there is one. @@ -2657,7 +2658,7 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { p_normal = geom->get_next_normal(ni); // set primitive normal if there is one. if(bIsTriList) { - // in flat shade mode, D3D strips color using the 1st vertex. + // in flat shade mode, D3D strips color using the 1st vertex. // (note: differs from OGL, which always uses last vtx for strips&fans // Store all but last 2 verts @@ -2666,7 +2667,7 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { // _perComp attribs should not be fetched for last 2 verts draw_prim_inner_loop(2, geom, _perVertex); } else { - // in flat shade mode, D3D fans color using the 2nd vertex. + // in flat shade mode, D3D fans color using the 2nd vertex. // (note: differs from OGL, which always uses last vtx for strips&fans // _perComp attribs should not be fetched for first & last verts, they will // be associated with middle n-2 verts @@ -2685,7 +2686,7 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { TestDrawPrimFailure(DrawPrim,hr,scrn.pD3DDevice,nVerts,numTris); } else { COPYVERTDATA_2_VERTEXBUFFER(trilisttype,nVerts); - } + } _pCurFvfBufPtr = NULL; } @@ -3071,7 +3072,7 @@ apply_texture(TextureContext *tc) { if (dirty) { // If the texture image has changed, or if its use of mipmaps has - // changed, we need to re-create the image. Ignore other types of + // changed, we need to re-create the image. Ignore other types of // changes, which arent significant for dx if((dirty & (Texture::DF_image | Texture::DF_mipmap)) != 0) { @@ -3082,13 +3083,13 @@ apply_texture(TextureContext *tc) { dxgsg_cat.warning() << "Texture " << *dtc->_texture << " has changed mipmap state.\n"; } - + dtc->DeleteTexture(); if (dtc->CreateTexture(scrn) == NULL) { // Oops, we can't re-create the texture for some reason. dxgsg_cat.error() << "Unable to re-create texture " << *dtc->_texture << endl; - + release_texture(dtc); enable_texturing(false); return; @@ -3395,7 +3396,7 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { TmpSurfYsize=RECT_YSIZE(minfo.rcMonitor); // set SrcCopyRect to client area of window in scrn coords - GetClientRect( scrn.hWnd, &SrcCopyRect); + GetClientRect( scrn.hWnd, &SrcCopyRect); ClientToScreen( scrn.hWnd, (POINT*)&SrcCopyRect.left ); ClientToScreen( scrn.hWnd, (POINT*)&SrcCopyRect.right ); } else { @@ -3406,15 +3407,15 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { SrcCopyRect.right=TmpSurfXsize; SrcCopyRect.bottom=TmpSurfYsize; } - + hr=scrn.pD3DDevice->CreateImageSurface(TmpSurfXsize,TmpSurfYsize,D3DFMT_A8R8G8B8,&pD3DSurf); if(FAILED(hr)) { dxgsg_cat.error() << "CreateImageSurface failed in copy_pixel_buffer()" << D3DERRORSTRING(hr); exit(1); } - + hr=scrn.pD3DDevice->GetFrontBuffer(pD3DSurf); - + if(hr==D3DERR_DEVICELOST) { // dont necessary want to exit in this case pD3DSurf->Release(); @@ -3644,9 +3645,9 @@ issue_transform(const TransformState *transform) { // so need to reset this vshader 'constant' every time view matrix changes HRESULT hr = scrn.pD3DDevice->SetVertexShaderConstant(VSHADER_XFORMMATRIX_CONSTANTREGNUMSTART, pMat, 4); #ifdef _DEBUG - if(FAILED(hr)) { + if(FAILED(hr)) { dxgsg_cat.error() << "SetVertexShader failed" << D3DERRORSTRING(hr); - exit(1); + exit(1); } #endif } @@ -3856,19 +3857,19 @@ bind_light(PointLight *light, int light_id) { alight.Diffuse = *(D3DCOLORVALUE *)(light->get_color().get_data()); alight.Ambient = black ; alight.Specular = *(D3DCOLORVALUE *)(light->get_specular_color().get_data()); - + // Position needs to specify x, y, z, and w // w == 1 implies non-infinite position alight.Position = *(D3DVECTOR *)pos.get_data(); - + alight.Range = __D3DLIGHT_RANGE_MAX; alight.Falloff = 1.0f; - + const LVecBase3f &att = light->get_attenuation(); alight.Attenuation0 = att[0]; alight.Attenuation1 = att[1]; alight.Attenuation2 = att[2]; - + HRESULT res = scrn.pD3DDevice->SetLight(light_id, &alight); } @@ -3900,16 +3901,16 @@ bind_light(DirectionalLight *light, int light_id) { alight.Diffuse = *(D3DCOLORVALUE *)(light->get_color().get_data()); alight.Ambient = black ; alight.Specular = *(D3DCOLORVALUE *)(light->get_specular_color().get_data()); - + alight.Direction = *(D3DVECTOR *)dir.get_data(); alight.Range = __D3DLIGHT_RANGE_MAX; alight.Falloff = 1.0f; - + alight.Attenuation0 = 1.0f; // constant alight.Attenuation1 = 0.0f; // linear alight.Attenuation2 = 0.0f; // quadratic - + HRESULT res = scrn.pD3DDevice->SetLight(light_id, &alight); } @@ -3937,32 +3938,32 @@ bind_light(Spotlight *light, int light_id) { D3DCOLORVALUE black; black.r = black.g = black.b = black.a = 0.0f; - + D3DLIGHT8 alight; ZeroMemory(&alight, sizeof(D3DLIGHT8)); - + alight.Type = D3DLIGHT_SPOT; alight.Ambient = black ; alight.Diffuse = *(D3DCOLORVALUE *)(light->get_color().get_data()); alight.Specular = *(D3DCOLORVALUE *)(light->get_specular_color().get_data()); - + alight.Position = *(D3DVECTOR *)pos.get_data(); - + alight.Direction = *(D3DVECTOR *)dir.get_data(); alight.Range = __D3DLIGHT_RANGE_MAX; alight.Falloff = 1.0f; alight.Theta = 0.0f; alight.Phi = lens->get_hfov(); - + const LVecBase3f &att = light->get_attenuation(); alight.Attenuation0 = att[0]; alight.Attenuation1 = att[1]; alight.Attenuation2 = att[2]; - + HRESULT res = scrn.pD3DDevice->SetLight(light_id, &alight); } - + //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::begin_frame // Access: Public, Virtual @@ -3998,8 +3999,6 @@ begin_frame() { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: end_frame() { - GraphicsStateGuardian::end_frame(); - HRESULT hr; if(_bShowFPSMeter) { @@ -4015,16 +4014,16 @@ end_frame() { // usually only want to call BeginText() & EndText() once/frame // to bracket all the text for a given cd3dfont obj - hr=_pStatMeterFont->BeginText(); + hr=_pStatMeterFont->BeginText(); if(SUCCEEDED(hr)) hr=_pStatMeterFont->DrawText(_fpsmeter_x_offset, _fpsmeter_y_offset, fontColor, fps_msg); if(SUCCEEDED(hr)) - hr=_pStatMeterFont->EndText(); + hr=_pStatMeterFont->EndText(); if(FAILED(hr)) _bShowFPSMeter=false; } - hr = scrn.pD3DDevice->EndScene(); + hr = scrn.pD3DDevice->EndScene(); // any GDI operations MUST occur after EndScene @@ -4093,7 +4092,7 @@ end_frame() { << "\n Avg Verts/frame:\t" << verts_per_frame << "\n Avg Tris/frame:\t" << tris_per_frame << "\n Avg DrawPrims/frm:\t" << DPs_per_frame - << "\n Avg Verts/DrawPrim:\t" << verts_per_DP + << "\n Avg Verts/DrawPrim:\t" << verts_per_DP << "\n Avg DrawPrims w/no Texture Change from prev DrawPrim/frm:\t" << DPs_notexchange_per_frame << "\n Avg Geoms/frm:\t" << Geoms_per_frame << "\n Avg DrawPrims/Geom:\t" << DrawPrims_per_Geom @@ -4109,7 +4108,7 @@ end_frame() { #if defined(DO_PSTATS)||defined(PRINT_RESOURCESTATS) #ifndef PRINT_RESOURCESTATS - if (_texmgrmem_total_pcollector.is_active()) + if (_texmgrmem_total_pcollector.is_active()) #endif { #define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval @@ -4122,6 +4121,8 @@ end_frame() { } } #endif + + GraphicsStateGuardian::end_frame(); } //////////////////////////////////////////////////////////////////// @@ -4291,7 +4292,7 @@ get_fog_mode_type(Fog::Mode m) const { switch (m) { case Fog::M_linear: return D3DFOG_LINEAR; - case Fog::M_exponential: + case Fog::M_exponential: return D3DFOG_EXP; case Fog::M_exponential_squared: return D3DFOG_EXP2; @@ -4323,7 +4324,7 @@ enable_lighting(bool enable) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: set_ambient_light(const Colorf &color) { - scrn.pD3DDevice->SetRenderState(D3DRS_AMBIENT, + scrn.pD3DDevice->SetRenderState(D3DRS_AMBIENT, Colorf_to_D3DCOLOR(color)); } @@ -4427,7 +4428,7 @@ set_blend_mode(ColorWriteAttrib::Mode color_write_mode, if((color_write_mode == ColorWriteAttrib::M_off) && !scrn.bCanDirectDisableColorWrites) { // need !scrn.bCanDirectDisableColorWrites guard because other issue_colorblend,issue_transp - // will come this way, and they should ignore the colorwriteattrib value since it's been + // will come this way, and they should ignore the colorwriteattrib value since it's been // handled separately in set_color_writemask enable_blend(true); call_dxBlendFunc(D3DBLEND_ZERO, D3DBLEND_ONE); @@ -4573,7 +4574,7 @@ dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled) { if(dxgsg_cat.is_spam()) { dxgsg_cat.spam() << "dx_cleanup called, bAtExitFnCalled=" << bAtExitFnCalled << ", bAtExitFnEverCalled=" << bAtExitFnEverCalled << endl; } - + bAtExitFnEverCalled = (bAtExitFnEverCalled || bAtExitFnCalled); // for now, I can't trust any of the ddraw/d3d releases during atexit(), @@ -4699,15 +4700,36 @@ HRESULT DXGraphicsStateGuardian::ReleaseAllDeviceObjects(void) { //////////////////////////////////////////////////////////////////// // Function: show_frame // Access: -// Description: Repaint primary buffer from back buffer +// Description: redraw primary buffer //////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian::show_frame(void) { +void DXGraphicsStateGuardian::show_frame(bool bNoNewFrameDrawn) { if(scrn.pD3DDevice==NULL) return; DO_PSTATS_STUFF(PStatTimer timer(_win->_swap_pcollector)); // this times just the flip, so it must go here in dxgsg, instead of wdxdisplay, which would time the whole frame HRESULT hr; + if(bNoNewFrameDrawn) { + // a new frame has not been rendered, we just want to display the last thing + // that was drawn into backbuf, if backbuf is valid + if(scrn.PresParams.SwapEffect==D3DSWAPEFFECT_DISCARD) { + // in DISCARD mode, old backbufs are not guaranteed to have valid pixels, + // so we cant copy back->front here. just give up. + return; + } else if(scrn.PresParams.SwapEffect==D3DSWAPEFFECT_FLIP) { + /* bugbug: here we should use CopyRects here to copy backbuf to front (except in + the case of frames 1 and 2 where we have no valid data in the backbuffer yet, + for those cases give up and return). + not implemented yet since right now we always do discard mode for fullscrn Present() + for speed. + */ + return; + } + + // otherwise we have D3DSWAPEFFECT_COPY, so fall-thru to normal Present() + // may work ok as long as backbuf hasnt been touched + } + hr = scrn.pD3DDevice->Present((CONST RECT*)NULL,(CONST RECT*)NULL,(HWND)NULL,NULL); if(FAILED(hr)) { if(hr == D3DERR_DEVICELOST) { @@ -4729,7 +4751,7 @@ HRESULT DXGraphicsStateGuardian::reset_d3d_device(D3DPRESENT_PARAMETERS *pPresPa ReleaseAllDeviceObjects(); if(!dx_full_screen) { - // for windowed make sure out format matches the desktop fmt, in case the + // for windowed make sure out format matches the desktop fmt, in case the // desktop mode has been changed scrn.pD3D8->GetAdapterDisplayMode(scrn.CardIDNum, &scrn.DisplayMode); @@ -4748,7 +4770,7 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { HRESULT hr = scrn.pD3DDevice->TestCooperativeLevel(); if(SUCCEEDED(hr)) { - assert(SUCCEEDED(_last_testcooplevel_result)); + assert(SUCCEEDED(_last_testcooplevel_result)); return true; } @@ -4766,7 +4788,7 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { _win->reactivate_window(); //must reactivate window before you can restore surfaces (otherwise you are in WRONGVIDEOMODE, and DDraw RestoreAllSurfaces fails) hr = scrn.pD3DDevice->TestCooperativeLevel(); if(FAILED(hr)) { - // internal chk, shouldnt fail + // internal chk, shouldnt fail dxgsg_cat.error() << "TestCooperativeLevel following Reset() failed, hr = " << D3DERRORSTRING(hr); exit(1); } @@ -4796,7 +4818,7 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { // This means that mode changes had taken place, surfaces // were lost but still we are in the original mode, so we // simply restore all surfaces and keep going. - + if(dxgsg_cat.is_debug()) { if(dx_full_screen) dxgsg_cat.debug() << "Lost access to DDRAW exclusive mode, waiting to regain it...\n"; @@ -4806,7 +4828,7 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { } else if(hr==D3DERR_DEVICENOTRESET) { // need to call Reset() - // do I want to do it here, or do + // do I want to do it here, or do HRESULT hr=scrn.pD3DDevice->Reset(&scrn.PresParams); if(FAILED(hr)) { dxgsg_cat.error() << "CheckCooperativeLevel Reset() failed, hr = " << D3DERRORSTRING(hr); @@ -4828,11 +4850,11 @@ bool DXGraphicsStateGuardian::CheckCooperativeLevel(bool bDoReactivateWindow) { if(dxgsg_cat.is_debug()) dxgsg_cat.debug() << "regained exclusive mode, refilling surfs...\n"; } - + if(bDoReactivateWindow) _win->reactivate_window(); //must reactivate window before you can restore surfaces (otherwise you are in WRONGVIDEOMODE, and DDraw RestoreAllSurfaces fails) - RestoreAllVideoSurfaces(); + RestoreAllVideoSurfaces(); _bDXisReady = TRUE; @@ -5068,7 +5090,7 @@ HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddW } // Create a surface for the cursor - if( FAILED( hr = pd3dDevice->CreateImageSurface( dwWidth, dwHeightDest, + if( FAILED( hr = pd3dDevice->CreateImageSurface( dwWidth, dwHeightDest, D3DFMT_A8R8G8B8, &pCursorBitmap ) ) ) { goto End; } @@ -5091,7 +5113,7 @@ HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddW goto End; } hgdiobjOld = SelectObject(hdcMask, iconinfo.hbmMask); - GetDIBits(hdcMask, iconinfo.hbmMask, 0, dwHeightSrc, + GetDIBits(hdcMask, iconinfo.hbmMask, 0, dwHeightSrc, pcrArrayMask, &bmi, DIB_RGB_COLORS); SelectObject(hdcMask, hgdiobjOld); @@ -5105,7 +5127,7 @@ HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddW goto End; } SelectObject(hdcColor, iconinfo.hbmColor); - GetDIBits(hdcColor, iconinfo.hbmColor, 0, dwHeightDest, + GetDIBits(hdcColor, iconinfo.hbmColor, 0, dwHeightDest, pcrArrayColor, &bmi, DIB_RGB_COLORS); } @@ -5132,8 +5154,8 @@ HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddW else pBitmap[dwWidth*y + x] = 0x00000000; - // It may be helpful to make the D3D cursor look slightly - // different from the Windows cursor so you can distinguish + // It may be helpful to make the D3D cursor look slightly + // different from the Windows cursor so you can distinguish // between the two when developing/testing code. When // bAddWatermark is TRUE, the following code adds some // small grey "D3D" characters to the upper-left corner of @@ -5157,7 +5179,7 @@ HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddW pCursorBitmap->UnlockRect(); // Set the device cursor - if( FAILED( hr = pd3dDevice->SetCursorProperties( iconinfo.xHotspot, + if( FAILED( hr = pd3dDevice->SetCursorProperties( iconinfo.xHotspot, iconinfo.yHotspot, pCursorBitmap ) ) ) { goto End; @@ -5204,8 +5226,8 @@ typedef struct { } POS_TEX_VERTEX; // define junk vars so symbols are included in dbginfo -POS_TEX_VERTEX junk11; -POS_COLOR_TEX_VERTEX junk22; +POS_TEX_VERTEX junk11; +POS_COLOR_TEX_VERTEX junk22; POS_NORM_COLOR_TEX_VERTEX junk33; #endif diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index a455c4caf6..83f05c730a 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -180,7 +180,7 @@ protected: DXTextureContext *_pCurTexContext; bool _bTransformIssued; // decaling needs to tell when a transform has been issued - D3DMATRIX _SavedTransform; + D3DMATRIX _SavedTransform; RenderBuffer::Type _cur_read_pixel_buffer; // source for copy_pixel_buffer operation @@ -197,7 +197,7 @@ protected: INLINE void enable_multisample_alpha_one(bool val); INLINE void enable_multisample_alpha_mask(bool val); INLINE void enable_multisample(bool val); -*/ +*/ INLINE void enable_color_material(bool val); INLINE void enable_fog(bool val); @@ -263,7 +263,7 @@ protected: PTA_Normalf _norms; PTA_Colorf _colors; PTA_ushort _cindexes,_nindexes; -*/ +*/ Colorf _lmodel_ambient; float _material_ambient; @@ -278,10 +278,10 @@ protected: } DxgsgFogType; DxgsgFogType _doFogType; bool _fog_enabled; -/* +/* TODO: cache fog state float _fog_start,_fog_end,_fog_density,float _fog_color; -*/ +*/ float _alpha_func_refval; // d3d stores UINT, panda stores this as float. we store float D3DCMPFUNC _alpha_func; @@ -352,11 +352,11 @@ public: #define DO_REACTIVATE_WINDOW true bool CheckCooperativeLevel(bool bDoReactivateWindow = false); - void show_frame(); + void show_frame(bool bNoNewFrameDrawn = false); void dx_init(HCURSOR hMouseCursor); void support_overlay_window(bool flag); - + private: static TypeHandle _type_handle; }; diff --git a/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx b/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx index 0eb35974d0..641dd4c7b8 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx +++ b/panda/src/wdxdisplay8/wdxGraphicsWindow8.cxx @@ -74,7 +74,7 @@ LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam,LPARAM lparam) // imperfect method to ID NVid? could also scan desc str, but that isnt fullproof either #define IS_NVIDIA(DDDEVICEID) ((DDDEVICEID.VendorId==0x10DE) || (DDDEVICEID.VendorId==0x12D2)) -#define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002) +#define IS_ATI(DDDEVICEID) (DDDEVICEID.VendorId==0x1002) #define IS_MATROX(DDDEVICEID) (DDDEVICEID.VendorId==0x102B) // because we dont have access to ModifierButtons, as a hack just synchronize state of these @@ -101,7 +101,7 @@ static DWORD BitDepth_2_DDBDMask(DWORD iBitDepth) { typedef enum {DBGLEV_FATAL,DBGLEV_ERROR,DBGLEV_WARNING,DBGLEV_INFO,DBGLEV_DEBUG,DBGLEV_SPAM } DebugLevels; - + void PrintDBGStr(DebugLevels level,HRESULT hr,const char *msgstr) { ostream *pstrm; static ostream dbg_strms[DBGLEV_SPAM+1]={wdxdisplay_cat.fatal,wdxdisplay_cat.error, @@ -122,13 +122,13 @@ void PrintErrorMessage(DWORD msgID) { msgID=GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL,msgID, + NULL,msgID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language (LPTSTR) &pMessageBuffer, // the weird ptrptr->ptr cast is intentional, see FORMAT_MESSAGE_ALLOCATE_BUFFER 1024, NULL); MessageBox(GetDesktopWindow(),pMessageBuffer,_T(ERRORBOX_TITLE),MB_OK); wdxdisplay_cat.fatal() << "System error msg: " << pMessageBuffer << endl; - LocalFree( pMessageBuffer ); + LocalFree( pMessageBuffer ); } //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) @@ -197,7 +197,7 @@ void wdxGraphicsWindow::DestroyMe(bool bAtExitFnCalled) { ReleaseDC(scrn.hWnd,scrn._hdc); // _hdc = NULL; } -*/ +*/ if(scrn.hWnd!=NULL) { DestroyWindow(scrn.hWnd); @@ -318,7 +318,9 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; BeginPaint(hwnd, &ps); - show_frame(); + if(DX_IS_READY) { + _dxgsg->show_frame(true); // 'true' since just want to show the last rendered backbuf, if any + } EndPaint(hwnd, &ps); return 0; } @@ -388,7 +390,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { set_cursor_visibility(true); break; } - + case WM_IME_NOTIFY: if (wparam == IMN_SETOPENSTATUS) { HIMC hIMC = ImmGetContext(hwnd); @@ -400,7 +402,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { ImmReleaseContext(hwnd, hIMC); } break; - + case WM_IME_STARTCOMPOSITION: // In case we're running fullscreen mode, we have to turn on // explicit DX support for overlay windows now, so we'll be able @@ -408,44 +410,44 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _dxgsg->support_overlay_window(true); _ime_active = true; break; - + case WM_IME_ENDCOMPOSITION: // Turn off the support for overlay windows, since we're done // with the IME window for now and it just slows things down. _dxgsg->support_overlay_window(false); _ime_active = false; break; - + case WM_IME_COMPOSITION: if (lparam & GCS_RESULTSTR) { if (!_input_devices.empty()) { HIMC hIMC = ImmGetContext(hwnd); nassertr(hIMC != 0, 0); - + static const int max_ime_result = 128; static char ime_result[max_ime_result]; - + if (_ime_composition_w) { // Since ImmGetCompositionStringA() doesn't seem to work // for Win2000 (it always returns question mark // characters), we have to use ImmGetCompositionStringW() // on this OS. This is actually the easier of the two // functions to use. - + DWORD result_size = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, ime_result, max_ime_result); - + // Add this string into the text buffer of the application. - + // ImmGetCompositionStringW() returns a string, but it's // filled in with wstring data: every two characters defines a // 16-bit unicode char. The docs aren't clear on the // endianness of this. I guess it's safe to assume all Win32 // machines are little-endian. for (DWORD i = 0; i < result_size; i += 2) { - int result = - ((int)(unsigned char)ime_result[i + 1] << 8) | + int result = + ((int)(unsigned char)ime_result[i + 1] << 8) | (unsigned char)ime_result[i]; _input_devices[0].keystroke(result); } @@ -456,13 +458,13 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { DWORD result_size = ImmGetCompositionStringA(hIMC, GCS_RESULTSTR, ime_result, max_ime_result); - + // ImmGetCompositionStringA() returns an encoded ANSI // string, which we now have to map to wide-character // Unicode. static const int max_wide_result = 128; static wchar_t wide_result[max_wide_result]; - + int wide_size = MultiByteToWideChar(CP_ACP, 0, ime_result, result_size, @@ -474,13 +476,13 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _input_devices[0].keystroke(wide_result[i]); } } - + ImmReleaseContext(hwnd, hIMC); } return 0; } break; - + case WM_CHAR: // Ignore WM_CHAR messages if we have the IME open, since // everything will come in through WM_IME_COMPOSITION. (It's @@ -491,7 +493,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _input_devices[0].keystroke(wparam); } break; - + case WM_SYSKEYDOWN: { // Alt and F10 are sent as WM_SYSKEYDOWN instead of WM_KEYDOWN // want to use defwindproc on Alt syskey so std windows cmd Alt-F4 works, etc @@ -508,33 +510,33 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { case WM_SYSCOMMAND: if(wparam==SC_KEYMENU) { - // if Alt is released (alone w/o other keys), defwindproc will send + // if Alt is released (alone w/o other keys), defwindproc will send // this command, which will 'activate' the title bar menu (we have none) // and give focus to it. we dont want this to happen, so kill this msg return 0; } break; - + case WM_KEYDOWN: { POINT point; - + GetCursorPos(&point); ScreenToClient(hwnd, &point); handle_keypress(lookup_key(wparam), point.x, point.y); - + // Handle Cntrl-V paste from clipboard. Is there a better way // to detect this hotkey? - if ((wparam=='V') && (GetKeyState(VK_CONTROL) < 0) && + if ((wparam=='V') && (GetKeyState(VK_CONTROL) < 0) && !_input_devices.empty()) { HGLOBAL hglb; char *lptstr; - + if (!IsClipboardFormatAvailable(CF_TEXT)) return 0; - + if (!OpenClipboard(NULL)) return 0; - + // Maybe we should support CF_UNICODETEXT if it is available // too? hglb = GetClipboardData(CF_TEXT); @@ -552,19 +554,19 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } break; } - + case WM_SYSKEYUP: case WM_KEYUP: handle_keyrelease(lookup_key(wparam)); break; - + case WM_LBUTTONDOWN: button = 0; case WM_MBUTTONDOWN: if(button < 0) button = 1; case WM_RBUTTONDOWN: - if(!DX_IS_READY) + if(!DX_IS_READY) break; if(button < 0) @@ -581,7 +583,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if(button < 0) button = 1; case WM_RBUTTONUP: - if(!DX_IS_READY) + if(!DX_IS_READY) break; if(button < 0) @@ -589,13 +591,13 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { ReleaseCapture(); #if 0 SET_MOUSE_COORD(x,LOWORD(lparam)); - SET_MOUSE_COORD(y,HIWORD(lparam)); + SET_MOUSE_COORD(y,HIWORD(lparam)); #endif handle_keyrelease(MouseButton::button(button)); return 0; case WM_SETCURSOR: - // Turn off any GDI window cursor + // Turn off any GDI window cursor // dx8 cursor not working yet if(_use_dx8_cursor && _props._fullscreen) { @@ -659,7 +661,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { #ifdef _DEBUG wdxdisplay_cat.spam() << "WM_EXITSIZEMOVE received" << endl; #endif - + if(_WindowAdjustingType==Resizing) { bool bSucceeded=handle_windowed_resize(hwnd,true); @@ -756,7 +758,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // user is using, since we may miss some here for(int i=0;iPresParams.BackBufferWidth << "," + wdxdisplay_cat.info() << "reset of original size (" <PresParams.BackBufferWidth << "," << pScrn->PresParams.BackBufferHeight << ") succeeded\n"; } } else { @@ -903,7 +905,7 @@ bool wdxGraphicsWindow::reset_device_resize_window(UINT new_xsize, UINT new_ysiz // Description: //////////////////////////////////////////////////////////////////// bool wdxGraphicsWindow::handle_windowed_resize(HWND hWnd,bool bDoDxReset) { - // handles windowed, non-fullscreen resizing + // handles windowed, non-fullscreen resizing GdiFlush(); assert(!_props._fullscreen); @@ -941,7 +943,7 @@ bool wdxGraphicsWindow::handle_windowed_resize(HWND hWnd,bool bDoDxReset) { do { // change _props xsize,ysize (need to do this here in case _dxgsg==NULL) resized(xsize,ysize); - + if((_dxgsg!=NULL)&& bDoDxReset) { bResizeSucceeded=reset_device_resize_window(xsize,ysize); // create the new resized rendertargets if(!bResizeSucceeded) { @@ -958,19 +960,19 @@ bool wdxGraphicsWindow::handle_windowed_resize(HWND hWnd,bool bDoDxReset) { } } } while(!bResizeSucceeded); -*/ +*/ // change _props xsize,ysize (need to do this here in case _dxgsg==NULL) // reset_device_resize will call it again, this is OK resized(xsize,ysize); - + if((_dxgsg!=NULL)&& bDoDxReset) { bResizeSucceeded=reset_device_resize_window(xsize,ysize); // create the new resized rendertargets if(!bResizeSucceeded) { - if(wdxdisplay_cat.is_debug()) + if(wdxdisplay_cat.is_debug()) wdxdisplay_cat.debug() << "windowed_resize to size: (" << xsize << "," << ysize << ") failed due to out-of-memory\n"; } else { - if(wdxdisplay_cat.is_debug()) + if(wdxdisplay_cat.is_debug()) wdxdisplay_cat.debug() << "windowed_resize to origin: (" << _props._xorg << "," << _props._yorg << "), size: (" << _props._xsize << "," << _props._ysize << ")\n"; } } @@ -1034,12 +1036,12 @@ void wdxGraphicsWindow::deactivate_window(void) { // currently this should only be called from CheckCoopLvl to return from Alt-tab void wdxGraphicsWindow::reactivate_window(void) { - if((!_window_active)||(_active_minimized_fullscreen)) { - + if((!_window_active)||(_active_minimized_fullscreen)) { + // first see if dx cooperative level is OK for reactivation // if(!_dxgsg->CheckCooperativeLevel()) // return; - + if(_PandaPausedTimer!=NULL) { KillTimer(_dxgsg->scrn.hWnd,_PandaPausedTimer); _PandaPausedTimer = NULL; @@ -1057,12 +1059,12 @@ void wdxGraphicsWindow::reactivate_window(void) { // need to call dx_init and ResourceManagerDiscardBytes since D3D Reset() was called init_resized_window(); - + // move window to top of zorder // if(_props._fullscreen) // SetWindowPos(_DisplayDataArray[0].hWnd, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOOWNERZORDER); GdiFlush(); - } + } if(_props._fullscreen) { throw_event("PandaRestarted"); // right now this is used to signal python event handler to re-enable audio @@ -1085,7 +1087,7 @@ wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe) : GraphicsWindow(pipe) // Access: // Description: //////////////////////////////////////////////////////////////////// -wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe, const GraphicsWindow::Properties& props) +wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe, const GraphicsWindow::Properties& props) : GraphicsWindow(pipe, props) { _ime_open = false; _pParentWindowGroup=NULL; @@ -1094,11 +1096,11 @@ wdxGraphicsWindow::wdxGraphicsWindow(GraphicsPipe* pipe, const GraphicsWindow::P bool supports_color_cursors(D3DADAPTER_IDENTIFIER8 &DevID) { // TODO: add more cards as more testing is done - if(IS_NVIDIA(DevID)) { + if(IS_NVIDIA(DevID)) { // all nvidia seem to support 256 color return true; } else if(IS_ATI(DevID)) { - // radeons seem to be in the 5100 range and support color, assume anything in 6000 or above + // radeons seem to be in the 5100 range and support color, assume anything in 6000 or above // is newer than radeon and supports 256 color if(((DevID.DeviceId>=0x5100) && (DevID.DeviceId<=0x5200)) || (DevID.DeviceId>=0x6000)) @@ -1127,7 +1129,7 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { HINSTANCE hProgramInstance = GetModuleHandle(NULL); WNDCLASS wc; static bool wc_registered = false; - _hParentWindow = NULL; + _hParentWindow = NULL; _bLoadedCustomCursor=false; // Clear before filling in window structure! @@ -1136,7 +1138,7 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { wc.lpfnWndProc = (WNDPROC) static_window_proc; wc.hInstance = hProgramInstance; - // all this must be moved to dx_init, since we need to create DX surface + // all this must be moved to dx_init, since we need to create DX surface string windows_icon_filename = get_icon_filename().to_os_specific(); @@ -1160,35 +1162,35 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { if(!windows_color_cursor_filename.empty()) { // card support for full color non-black/white GDI cursors varies greatly. if the cursor is not supported, - // it is rendered in software by GDI, which causes a flickering effect (because it's not synced + // it is rendered in software by GDI, which causes a flickering effect (because it's not synced // with flip?). GDI transparently masks the lack of HW support so there is no easy way for app to detect // if HW cursor support exists. alternatives are to tie cursor motion to frame rate using DDraw blts - // or overlays (this is done automatically by DX8 runtime mouse cursor support), or to have separate thread draw cursor + // or overlays (this is done automatically by DX8 runtime mouse cursor support), or to have separate thread draw cursor // (sync issues?). instead we do mono cursor unless card is known to support 256 color cursors bool bSupportsColorCursor=true; - - #if 0 + + #if 0 // remove this check for now, since dx8 should emulate color cursors /* if any card doesnt support color, dont load it*/ for(int w=0;w<_windows.size();w++) bSupportsColorCursor &= supports_color_cursors(_windows[w]->_dxgsg->scrn.DXDeviceID); #endif - + if(bSupportsColorCursor) { DWORD load_flags = LR_LOADFROMFILE; - + if(dx_full_screen) { // I think cursors should use LR_CREATEDIBSECTION since they should not be mapped to the device palette (in the case of 256-color cursors) // since they are not going to be used on the desktop load_flags |= LR_CREATEDIBSECTION; } - + // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) // if icon is more than 8bpp - // loads a .cur fmt file. + // loads a .cur fmt file. _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_color_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags ); - + if(_hMouseCursor==NULL) { wdxdisplay_cat.warning() << "windows color cursor filename '" << windows_color_cursor_filename << "' not found!!\n"; goto try_mono_cursor; @@ -1204,28 +1206,28 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { if(!_bLoadedCustomCursor) { string windows_mono_cursor_filename = get_mono_cursor_filename().to_os_specific(); - + if(!windows_mono_cursor_filename.empty()) { // Note: LoadImage seems to cause win2k internal heap corruption (outputdbgstr warnings) // if icon is more than 8bpp - + DWORD load_flags = LR_LOADFROMFILE; - + if(dx_full_screen) { // I think cursors should use LR_CREATEDIBSECTION since they should not be mapped to the device palette (in the case of 256-color cursors) // since they are not going to be used on the desktop load_flags |= LR_CREATEDIBSECTION; } - // loads a .cur fmt file. + // loads a .cur fmt file. _hMouseCursor = (HCURSOR) LoadImage(NULL, windows_mono_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags); - + if(_hMouseCursor==NULL) { wdxdisplay_cat.warning() << "windows mono cursor filename '" << windows_mono_cursor_filename << "' not found!!\n"; } else _bLoadedCustomCursor=true; } } - if(!_bLoadedCustomCursor) + if(!_bLoadedCustomCursor) _hMouseCursor = LoadCursor(NULL, DEFAULT_CURSOR); // need both a mouse and no-mouse class in case we have mixed fullscrn/windowed @@ -1233,12 +1235,12 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { if (!wc_registered) { // We only need to register the window class once per session. - wc.hCursor = _hMouseCursor; // for windowed mode use the GDI cursor. + wc.hCursor = _hMouseCursor; // for windowed mode use the GDI cursor. // bugbug: for fullscreen do we need to do a SetWindowLongNULL wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = WDX_WINDOWCLASSNAME; - + if(!RegisterClass(&wc)) { wdxdisplay_cat.error() << "could not register window class " << WDX_WINDOWCLASSNAME << endl; } @@ -1247,9 +1249,9 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { wc.hCursor = CreateNullCursor(hProgramInstance); if(wc.hCursor==NULL) wdxdisplay_cat.error() << "failed to create NULL cursor, error=" << GetLastError() << endl; - + wc.lpszClassName = WDX_WINDOWCLASSNAME_NOCURSOR; - + if(!RegisterClass(&wc)) { wdxdisplay_cat.error() << "could not register window class " << WDX_WINDOWCLASSNAME_NOCURSOR << endl; } @@ -1292,12 +1294,12 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { RECT win_rect; SetRect(&win_rect, props->_xorg, props->_yorg, props->_xorg + props->_xsize, props->_yorg + props->_ysize); - + if(props->_border) final_window_style |= WS_OVERLAPPEDWINDOW; // should we just use WS_THICKFRAME instead? - + AdjustWindowRect(&win_rect, final_window_style, false); //compute window size based on desired client area size - + // make sure origin is on screen if(win_rect.left < 0) { win_rect.right -= win_rect.left; win_rect.left = 0; @@ -1319,7 +1321,7 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { exit(1); } - // BUGBUG: this sets window posns based on desktop arrangement of monitors (that is what GetMonInfo is for). + // BUGBUG: this sets window posns based on desktop arrangement of monitors (that is what GetMonInfo is for). // need to move to chancfg stuff instead (i.e. use the properties x/yorg's) when that is ready HWND hWin = CreateWindow(pWindowClassName, props->_title.c_str(), final_window_style, xleft,ytop,xsize,ysize, @@ -1365,7 +1367,7 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { _hParentWindow = CreateWindow(WDX_WINDOWCLASSNAME, props->_title.c_str(), - window_style, + window_style, win_rect.left, win_rect.top, win_rect.right-win_rect.left,win_rect.bottom-win_rect.top, NULL, NULL, hProgramInstance, 0); _windows[0]->set_window_handle(_hParentWindow); @@ -1386,7 +1388,7 @@ void wdxGraphicsWindowGroup::CreateWindows(void) { // probably only need to do this for devnum 0 HDC hdc = GetDC(pWDXWin->_dxgsg_>scrn.hWnd); pWDXWin->_dxgsg->Set_HDC(hdc); -*/ +*/ } // now we can stop using the global_wdxwinptr crutch since windows are created @@ -1441,12 +1443,34 @@ void wdxGraphicsWindow::config_window(wdxGraphicsWindowGroup *pParentGroup) { // However, this function doesn't work for Win98; on this OS, we // have to use ImmGetCompositionStringA() instead, which returns an // encoded string in shift-jis (which we then have to decode). - + // For now, this is user-configurable, to allow testing of this code // on both OS's. After we verify that truth of the above claim, we // should base this decision on GetVersionEx() or maybe // VerifyVersionInfo(). + _ime_composition_w = ime_composition_w; + + // need to re-evaluate above in light of this, it seems that + // ImmGetCompositionStringW should work on both: + // The Input Method Editor and Unicode Windows 98/Me, Windows + // NT/2000/XP: Windows supports a Unicode interface for the + // IME, in addition to the ANSI interface originally supported. + // Windows 98/Me supports all the Unicode functions except + // ImmIsUIMessage. Also, all the messages in Windows 98/Me are + // ANSI based. Since Windows 98/Me does not support Unicode + // messages, applications can use ImmGetCompositionString to + // receive Unicode characters from a Unicode based IME on + // Windows 98/Me. There are two issues involved with Unicode + // handling and the IME. One is that the Unicode versions of + // IME routines return the size of a buffer in bytes rather + // than 16-bit Unicode characters,and the other is the IME + // normally returns Unicode characters (rather than DBCS) in + // the WM_CHAR and WM_IME_CHAR messages. Use RegisterClassW + // to cause the WM_CHAR and WM_IME_CHAR messages to return + // Unicode characters in the wParam parameter rather than DBCS + // characters. This is only available under Windows NT; it is + // stubbed out in Windows 95/98/Me. } void wdxGraphicsWindow::finish_window_setup(void) { @@ -1460,59 +1484,10 @@ void wdxGraphicsWindow::finish_window_setup(void) { SetWindowPos(hWin, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE); // call twice to override STARTUPINFO value, which may be set to hidden initially (by emacs for instance) ShowWindow(hWin, SW_SHOWNORMAL); - ShowWindow(hWin, SW_SHOWNORMAL); + ShowWindow(hWin, SW_SHOWNORMAL); // UpdateWindow( _mwindow ); } - -#if 0 -HRESULT CALLBACK EnumDevicesCallback(LPSTR pDeviceDescription, LPSTR pDeviceName, - LPD3DDEVICEDESC7 pD3DDeviceDesc,LPVOID pContext) { - D3DDEVICEDESC7 *pd3ddevs = (D3DDEVICEDESC7 *)pContext; -#ifdef _DEBUG - wdxdisplay_cat.spam() << "Enumerating Device " << pDeviceName << " : " << pDeviceDescription << endl; -#endif - -#define REGHALIDX 0 -#define TNLHALIDX 1 - - // only saves hal and tnl devs, not sw rasts - - if(IsEqualGUID(pD3DDeviceDesc->deviceGUID,IID_IDirect3DHALDevice)) { - CopyMemory(&pd3ddevs[REGHALIDX],pD3DDeviceDesc,sizeof(D3DDEVICEDESC7)); - } else if(IsEqualGUID(pD3DDeviceDesc->deviceGUID,IID_IDirect3DTnLHalDevice)) { - CopyMemory(&pd3ddevs[TNLHALIDX],pD3DDeviceDesc,sizeof(D3DDEVICEDESC7)); - } - return DDENUMRET_OK; -} - -#define MAX_DISPLAY_MODES 100 // probably dont need this much, since i already screen for width&hgt -typedef struct { - DWORD maxWidth,maxHeight; - DWORD supportedBitDepths; // uses DDBD_* flags - LPDDSURFACEDESC2 pDDSD_Arr; - DWORD cNumSurfDescs; -} DisplayModeInfo; - -HRESULT WINAPI EnumDisplayModesCallBack(LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID lpContext) { - DisplayModeInfo *pDMI = (DisplayModeInfo *) lpContext; - - // ddsd_search should assure this is true - assert((lpDDSurfaceDesc->dwWidth == pDMI->maxWidth) && (lpDDSurfaceDesc->dwHeight == pDMI->maxHeight)); - - // ignore refresh rates under 60Hz (and special values of 0 & 1) - if((lpDDSurfaceDesc->dwRefreshRate>1) && (lpDDSurfaceDesc->dwRefreshRate<60)) - return DDENUMRET_OK; - - assert(pDMI->cNumSurfDescs < MAX_DISPLAY_MODES); - memcpy(&(pDMI->pDDSD_Arr[pDMI->cNumSurfDescs]), lpDDSurfaceDesc, sizeof(DDSURFACEDESC2) ); - pDMI->cNumSurfDescs++; - pDMI->supportedBitDepths |= BitDepth_2_DDBDMask(lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount); - - return DDENUMRET_OK; -} -#endif - // this handles external programmatic requests for resizing (usually fullscrn resize) bool wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { bool bResizeSucceeded=false; @@ -1522,7 +1497,7 @@ bool wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { wdxdisplay_cat.debug() << "redundant resize() called, returning\n"; return true; } - + if(!_props._fullscreen) { if(wdxdisplay_cat.is_debug()) wdxdisplay_cat.debug() << "resize("<scrn.hWnd, NULL, win_rect.left,win_rect.top, RECT_XSIZE(win_rect), RECT_YSIZE(win_rect), SWP_NOZORDER | SWP_NOSENDCHANGING); - // WM_ERASEBKGND will be ignored, because _WindowAdjustingType!=NotAdjusting because + // WM_ERASEBKGND will be ignored, because _WindowAdjustingType!=NotAdjusting because // we dont want to redraw as user is manually resizing window, so need to force explicit // background clear for the programmatic resize fn call _WindowAdjustingType=NotAdjusting; - + //window_proc(_mwindow, WM_ERASEBKGND,(WPARAM)_hdc,0x0); // this doesnt seem to be working in toontown resize, so I put ddraw blackblt in handle_windowed_resize instead return handle_windowed_resize(_dxgsg->scrn.hWnd,true); } - + assert(IS_VALID_PTR(_dxgsg)); - + if(wdxdisplay_cat.is_info()) wdxdisplay_cat.info() << "fullscrn resize("<SetDXReady(false); - + bool bCouldntFindValidZBuf; D3DFORMAT pixFmt; bool bNeedZBuffer = (_dxgsg->scrn.PresParams.EnableAutoDepthStencil!=false); @@ -1572,12 +1547,12 @@ bool wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { wdxdisplay_cat.error() << "resize() failed: cant resize low vidmem device #" << _dxgsg->scrn.CardIDNum << " to non 640x480!\n"; goto Error_Return; } - + search_for_valid_displaymode(xsize,ysize,bNeedZBuffer,bNeedStencilBuffer, &_dxgsg->scrn.SupportedScreenDepthsMask, &bCouldntFindValidZBuf, &pixFmt); - + if(pixFmt==D3DFMT_UNKNOWN) { wdxdisplay_cat.error() << "resize() failed: " << (bCouldntFindValidZBuf ? "Couldnt find valid zbuffer format to go with FullScreen mode" : "No supported FullScreen modes") @@ -1590,14 +1565,14 @@ bool wdxGraphicsWindow::resize(unsigned int xsize,unsigned int ysize) { _dxgsg->scrn.DisplayMode.Width=xsize; _dxgsg->scrn.DisplayMode.Height=ysize; _dxgsg->scrn.DisplayMode.Format = pixFmt; - _dxgsg->scrn.DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT; + _dxgsg->scrn.DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT; _dxgsg->scrn.PresParams.BackBufferFormat = pixFmt; // make reset_device_resize use presparams or displaymode?? - + // resized(xsize,ysize); not needed? - + bResizeSucceeded=reset_device_resize_window(xsize,ysize); - + if(!bResizeSucceeded) { wdxdisplay_cat.error() << "resize() failed with OUT-OF-MEMORY error!\n"; @@ -1627,7 +1602,7 @@ UINT wdxGraphicsWindow:: verify_window_sizes(UINT numsizes,UINT *dimen) { // unfortunately this only works AFTER you make the window initially, // so its really mostly useful for resizes only - assert(IS_VALID_PTR(_dxgsg)); + assert(IS_VALID_PTR(_dxgsg)); UINT num_valid_modes=0; @@ -1663,7 +1638,7 @@ verify_window_sizes(UINT numsizes,UINT *dimen) { } BOOL WINAPI DX7_DriverEnumCallback( GUID* pGUID, TCHAR* strDesc,TCHAR* strName,VOID *argptr, HMONITOR hm) { -// #define PRNT(XX) ((XX!=NULL) ? XX : "NULL") +// #define PRNT(XX) ((XX!=NULL) ? XX : "NULL") // cout << "strDesc: "<< PRNT(strDesc) << " strName: "<< PRNT(strName)<push_back(CurCardID); return DDENUMRET_OK; } - + void wdxGraphicsWindowGroup:: find_all_card_memavails(void) { if(g_pCardIDVec!=NULL) // we've already got the info @@ -1762,7 +1737,7 @@ find_all_card_memavails(void) { (*g_pCardIDVec)[i].DeviceID = pDX7DeviceID->dwDeviceId; (*g_pCardIDVec)[i].VendorID = pDX7DeviceID->dwVendorId; - + // Get Current VidMem avail. Note this is only an estimate, when we switch to fullscreen // mode from desktop, more vidmem will be available (typically 1.2 meg). I dont want // to switch to fullscreen more than once due to the annoying monitor flicker, so try @@ -1777,15 +1752,15 @@ find_all_card_memavails(void) { // goto skip_device; exit(1); // probably want to exit, since it may be my fault } - + pDD->Release(); // release DD obj, since this is all we needed it for if(!dx_do_vidmemsize_check) { // still calling the DD stuff to get deviceID, etc. is this necessary? (*g_pCardIDVec)[i].MaxAvailVidMem = UNKNOWN_VIDMEM_SIZE; - (*g_pCardIDVec)[i].bIsLowVidMemCard = false; + (*g_pCardIDVec)[i].bIsLowVidMemCard = false; continue; - } + } if(dwVidMemTotal==0) // unreliable driver dwVidMemTotal=UNKNOWN_VIDMEM_SIZE; @@ -1797,7 +1772,7 @@ find_all_card_memavails(void) { count++; dwVidMemTotal = (1 << count); } - + // after SetDisplayMode, GetAvailVidMem totalmem seems to go down by 1.2 meg (contradicting above // comment and what I think would be correct behavior (shouldnt FS mode release the desktop vidmem?), // so this is the true value @@ -1812,7 +1787,7 @@ find_all_card_memavails(void) { #define LOWVIDMEMTHRESHOLD 5000000 // 4MB cards should fall below this #define CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD 1000000 // if # is > 1MB, card is lying and I cant tell what it is - + // assume buggy drivers (this means you, FireGL2) may return zero (or small amts) for dwVidMemTotal, so ignore value if its < CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD (*g_pCardIDVec)[i].bIsLowVidMemCard = ((dwVidMemTotal>CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD) && (dwVidMemTotal< LOWVIDMEMTHRESHOLD)); } @@ -1824,10 +1799,10 @@ find_all_card_memavails(void) { void wdxGraphicsWindow:: check_for_color_cursor_support(void) { // card support for non-black/white GDI cursors varies greatly. if the cursor is not supported, - // it is rendered in software by GDI, which causes a flickering effect (because it's not synced + // it is rendered in software by GDI, which causes a flickering effect (because it's not synced // with flip?). GDI transparently masks what's happening so there is no easy way for app to detect // if HW cursor support exists. alternatives are to tie cursor motion to frame rate using DDraw blts - // or overlays, or to have separate thread draw cursor (sync issues?). instead we do mono cursor + // or overlays, or to have separate thread draw cursor (sync issues?). instead we do mono cursor // unless card is known to support 256 color cursors string windows_color_cursor_filename = get_color_cursor_filename().to_os_specific(); @@ -1836,11 +1811,11 @@ check_for_color_cursor_support(void) { bool bSupportsColorCursor=false; - if(IS_NVIDIA(_DXDeviceID)) { + if(IS_NVIDIA(_DXDeviceID)) { // all nvidia seem to support 256 color bSupportsColorCursor=true; } else if(IS_ATI(_DXDeviceID)) { - // radeons seem to be in the 5100 range and support color, assume anything in 6000 or above + // radeons seem to be in the 5100 range and support color, assume anything in 6000 or above // is newer than radeon and supports 256 color if(((_DXDeviceID.dwDeviceId>=0x5100) && (_DXDeviceID.dwDeviceId<=0x5200)) || (_DXDeviceID.dwDeviceId>=0x6000)) @@ -1864,7 +1839,7 @@ check_for_color_cursor_support(void) { load_flags |= LR_CREATEDIBSECTION; } - // loads a .cur fmt file. + // loads a .cur fmt file. HCURSOR hNewMouseCursor = (HCURSOR) LoadImage(NULL, windows_color_cursor_filename.c_str(), IMAGE_CURSOR, 0, 0, load_flags ); if(hNewMouseCursor==NULL) { @@ -1885,8 +1860,8 @@ check_for_color_cursor_support(void) { int D3DFMT_to_DepthBits(D3DFORMAT fmt) { switch(fmt) { case D3DFMT_D16: return 16; - case D3DFMT_D24X8: - case D3DFMT_D24X4S4: + case D3DFMT_D24X8: + case D3DFMT_D24X4S4: case D3DFMT_D24S8: return 24; case D3DFMT_D32: return 32; case D3DFMT_D15S1: return 15; @@ -1903,7 +1878,7 @@ bool wdxGraphicsWindow::FindBestDepthFormat(DXScreenData &Display,D3DDISPLAYMODE static D3DFORMAT StencilPrefList[NUM_TEST_ZFMTS]={D3DFMT_D24S8,D3DFMT_D24X4S4,D3DFMT_D15S1}; // do not use Display.DisplayMode since that is probably not set yet, use TestDisplayMode instead - + // int want_color_bits = _props._want_color_bits; // int want_depth_bits = _props._want_depth_bits; should we pay attn to these so panda user can select bitdepth? @@ -1913,7 +1888,7 @@ bool wdxGraphicsWindow::FindBestDepthFormat(DXScreenData &Display,D3DDISPLAYMODE // nvidia likes zbuf depth to match rendertarget depth bool bOnlySelect16bpp= (dx_force_16bpp_zbuffer || bForce16bpp || (IS_NVIDIA(Display.DXDeviceID) && IS_16BPP_DISPLAY_FORMAT(TestDisplayMode.Format))); - + for(int i=0;iscrn.pD3D8->GetAdapterModeCount(_dxgsg->scrn.CardIDNum); - D3DDISPLAYMODE BestDispMode; + D3DDISPLAYMODE BestDispMode; ZeroMemory(&BestDispMode,sizeof(BestDispMode)); *pCouldntFindAnyValidZBuf=false; @@ -1977,7 +1952,7 @@ void wdxGraphicsWindow::search_for_valid_displaymode(UINT RequestedXsize,UINT Re hr = _dxgsg->scrn.pD3D8->EnumAdapterModes(_dxgsg->scrn.CardIDNum,i,&dispmode); if(FAILED(hr)) { wdxdisplay_cat.error() << "EnumAdapterDisplayMode failed for device #"<<_dxgsg->scrn.CardIDNum<< D3DERRORSTRING(hr); - exit(1); + exit(1); } if((dispmode.Width!=RequestedXsize) || (dispmode.Height!=RequestedYsize)) @@ -1998,7 +1973,7 @@ void wdxGraphicsWindow::search_for_valid_displaymode(UINT RequestedXsize,UINT Re continue; else { wdxdisplay_cat.error() << "CheckDeviceFormat failed for device #" <<_dxgsg->scrn.CardIDNum << D3DERRORSTRING(hr); - exit(1); + exit(1); } } @@ -2008,14 +1983,14 @@ void wdxGraphicsWindow::search_for_valid_displaymode(UINT RequestedXsize,UINT Re // if we have a valid memavail value, try to determine if we have enough space if(_dxgsg->scrn.MaxAvailVidMem!=UNKNOWN_VIDMEM_SIZE) { // assume user is testing fullscreen, not windowed, so use the dwTotal value - // see if 3 scrnbufs (front/back/z)at 16bpp at xsize*ysize will fit with a few + // see if 3 scrnbufs (front/back/z)at 16bpp at xsize*ysize will fit with a few // extra megs for texmem // 8MB Rage Pro says it has 6.8 megs Total free and will run at 1024x768, so // formula makes it so that is OK #define REQD_TEXMEM 1800000 - + float bytes_per_pixel = (bIs16bppRenderTgt ? 2 : 4); assert(_props._mask & W_DOUBLE); @@ -2029,7 +2004,7 @@ void wdxGraphicsWindow::search_for_valid_displaymode(UINT RequestedXsize,UINT Re if(RendTgtMinMemReqmt>_dxgsg->scrn.MaxAvailVidMem) { if(wdxdisplay_cat.is_debug()) - wdxdisplay_cat.debug() << "not enough VidMem for render tgt, skipping display fmt " << D3DFormatStr(dispmode.Format) + wdxdisplay_cat.debug() << "not enough VidMem for render tgt, skipping display fmt " << D3DFormatStr(dispmode.Format) << " (" << (int)RendTgtMinMemReqmt << " > " << _dxgsg->scrn.MaxAvailVidMem << ")\n"; continue; } @@ -2094,11 +2069,11 @@ void wdxGraphicsWindow::search_for_valid_displaymode(UINT RequestedXsize,UINT Re } // note: this chooses 32bpp, which may not be preferred over 16 for memory & speed reasons on some older cards in particular - if(*pSupportedScreenDepthsMask & X8R8G8B8_FLAG) + if(*pSupportedScreenDepthsMask & X8R8G8B8_FLAG) *pSuggestedPixFmt = D3DFMT_X8R8G8B8; - else if(*pSupportedScreenDepthsMask & R8G8B8_FLAG) + else if(*pSupportedScreenDepthsMask & R8G8B8_FLAG) *pSuggestedPixFmt = D3DFMT_R8G8B8; - else if(*pSupportedScreenDepthsMask & R5G6B5_FLAG) + else if(*pSupportedScreenDepthsMask & R5G6B5_FLAG) *pSuggestedPixFmt = D3DFMT_R5G6B5; else if(*pSupportedScreenDepthsMask & X1R5G5B5_FLAG) *pSuggestedPixFmt = D3DFMT_X1R5G5B5; @@ -2133,8 +2108,8 @@ bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevIn } //search_for_valid_displaymode needs these to be set - memcpy(&_dxgsg->scrn.d3dcaps,&d3dcaps,sizeof(D3DCAPS8)); - _dxgsg->scrn.CardIDNum=pDevInfo->cardID; + memcpy(&_dxgsg->scrn.d3dcaps,&d3dcaps,sizeof(D3DCAPS8)); + _dxgsg->scrn.CardIDNum=pDevInfo->cardID; _dxgsg->scrn.MaxAvailVidMem = UNKNOWN_VIDMEM_SIZE; _dxgsg->scrn.bIsLowVidMemCard = false; @@ -2164,7 +2139,7 @@ bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevIn _dxgsg->scrn.MaxAvailVidMem = (*g_pCardIDVec)[IDnum].MaxAvailVidMem; _dxgsg->scrn.bIsLowVidMemCard = (*g_pCardIDVec)[IDnum].bIsLowVidMemCard; } else wdxdisplay_cat.error() << "Error: couldnt find a CardID match in DX7 info, assuming card is not a lowmem card\n"; - } + } if((bWantStencil) && (d3dcaps.StencilCaps==0x0)) { wdxdisplay_cat.fatal() << "Stencil ability requested, but device #" << pDevInfo->cardID << " (" << _dxgsg->scrn.DXDeviceID.Description<<"), has no stencil capability!\n"; @@ -2178,7 +2153,7 @@ bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevIn _dxgsg->scrn.bCanUseHWVertexShaders = (d3dcaps.VertexShaderVersion >= D3DVS_VERSION(1,0)); _dxgsg->scrn.bCanUsePixelShaders = (d3dcaps.PixelShaderVersion >= D3DPS_VERSION(1,0)); - bool bNeedZBuffer = ((!(d3dcaps.RasterCaps & D3DPRASTERCAPS_ZBUFFERLESSHSR )) + bool bNeedZBuffer = ((!(d3dcaps.RasterCaps & D3DPRASTERCAPS_ZBUFFERLESSHSR )) && (_props._mask & W_DEPTH)); _dxgsg->scrn.PresParams.EnableAutoDepthStencil=bNeedZBuffer; @@ -2187,18 +2162,18 @@ bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevIn if(_props._fullscreen) { _props._xorg = _props._yorg = 0; - + bool bCouldntFindValidZBuf; if(!_dxgsg->scrn.bIsLowVidMemCard) { search_for_valid_displaymode(dwRenderWidth,dwRenderHeight,bNeedZBuffer,bWantStencil, &_dxgsg->scrn.SupportedScreenDepthsMask, &bCouldntFindValidZBuf, &pixFmt); - + // note I'm not saving refresh rate, will just use adapter default at given res for now - + if(pixFmt==D3DFMT_UNKNOWN) { - wdxdisplay_cat.fatal() + wdxdisplay_cat.fatal() << (bCouldntFindValidZBuf ? "Couldnt find valid zbuffer format to go with FullScreen mode" : "No supported FullScreen modes") << " at " << dwRenderWidth << "x" << dwRenderHeight << " for device #" << _dxgsg->scrn.CardIDNum <scrn.SupportedScreenDepthsMask & R5G6B5_FLAG) pixFmt = D3DFMT_R5G6B5; else if(_dxgsg->scrn.SupportedScreenDepthsMask & X1R5G5B5_FLAG) pixFmt = D3DFMT_X1R5G5B5; else { - wdxdisplay_cat.fatal() << "Low Memory VidCard has no supported FullScreen 16bpp resolutions at "<< dwRenderWidth << "x" << dwRenderHeight + wdxdisplay_cat.fatal() << "Low Memory VidCard has no supported FullScreen 16bpp resolutions at "<< dwRenderWidth << "x" << dwRenderHeight << " for device #" << pDevInfo->cardID << " (" << _dxgsg->scrn.DXDeviceID.Description <<"), skipping device...\n"; return false; } - + if(wdxdisplay_cat.is_info()) wdxdisplay_cat.info() << "Available VidMem (" << _dxgsg->scrn.MaxAvailVidMem << ") is under " << LOWVIDMEMTHRESHOLD <<", using 640x480 16bpp rendertargets to save tex vidmem.\n"; } @@ -2243,11 +2218,11 @@ bool wdxGraphicsWindow::search_for_device(LPDIRECT3D8 pD3D8,DXDeviceInfo *pDevIn } pixFmt = dispmode.Format; } - + _dxgsg->scrn.DisplayMode.Width=dwRenderWidth; _dxgsg->scrn.DisplayMode.Height=dwRenderHeight; _dxgsg->scrn.DisplayMode.Format = pixFmt; - _dxgsg->scrn.DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT; + _dxgsg->scrn.DisplayMode.RefreshRate = D3DPRESENT_RATE_DEFAULT; _dxgsg->scrn.hMon=pDevInfo->hMon; return true; } @@ -2270,11 +2245,11 @@ SetCoopLevelsAndDisplayModes(void) { wdxdisplay_cat.fatal() << "SetCooperativeLevel failed" << ConvD3DErrorToString(hr) << endl; exit(1); } - return; + return; } - + DWORD SCL_FLAGS = SCL_FPUFlag | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT; - + if(_windows.size()>1) { SCL_FLAGS |= DDSCL_SETDEVICEWINDOW; } @@ -2285,7 +2260,7 @@ SetCoopLevelsAndDisplayModes(void) { // need to set focus/device windows for multimon // focus window is primary monitor that will receive keybd input // all ddraw objs need to have same focus window - if(_windows.size()>1) { + if(_windows.size()>1) { if(FAILED(hr = pScrn->pDD->SetCooperativeLevel(_hParentWindow, DDSCL_SETFOCUSWINDOW))) { wdxdisplay_cat.fatal() << "SetCooperativeLevel SetFocusWindow failed on device 0: hr = " << ConvD3DErrorToString(hr) << endl; exit(1); @@ -2300,13 +2275,13 @@ SetCoopLevelsAndDisplayModes(void) { exit(1); } } - + if(FAILED(hr = pScrn->pDD->TestCooperativeLevel())) { wdxdisplay_cat.fatal() << "TestCooperativeLevel failed for device #"<< devnum<<": hr = " << ConvD3DErrorToString(hr) << endl; wdxdisplay_cat.fatal() << "Full screen app failed to get exclusive mode on init, exiting..\n"; exit(1); } - + // note: its important we call SetDisplayMode on all cards before creating surfaces on any of them // let driver choose default refresh rate (hopefully its >=60Hz) if(FAILED( hr = pScrn->pDD->SetDisplayMode( pScrn->dwRenderWidth, pScrn->dwRenderHeight, @@ -2314,12 +2289,12 @@ SetCoopLevelsAndDisplayModes(void) { wdxdisplay_cat.fatal() << "SetDisplayMode failed to set ("<dwRenderWidth<<"x"<dwRenderHeight<<"x"<dwFullScreenBitDepth<<") on device #"<< pScrn->CardIDNum<<": hr = " << ConvD3DErrorToString(hr) << endl; exit(1); } - + if(wdxdisplay_cat.is_debug()) { - DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd34); + DX_DECLARE_CLEAN(DDSURFACEDESC2,ddsd34); pScrn->pDD->GetDisplayMode(&ddsd34); wdxdisplay_cat.debug() << "set displaymode to " << ddsd34.dwWidth << "x" << ddsd34.dwHeight << " at "<< ddsd34.ddpfPixelFormat.dwRGBBitCount << "bpp, " << ddsd34.dwRefreshRate<< "Hz\n"; - + /* #ifdef _DEBUG if(FAILED(hr = (*Disply).pDD->GetAvailableVidMem(&ddsGAVMCaps,&dwVidMemTotal,&dwVidMemFree))) { @@ -2355,7 +2330,7 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { wdxdisplay_cat.info() << "no zbuffer requested, skipping zbuffer creation\n"; } #endif - + pPresParams->BackBufferFormat = Display.DisplayMode.Format; // dont need dest alpha, so just use adapter format if(dx_sync_video && !(pD3DCaps->Caps & D3DCAPS_READ_SCANLINE)) { @@ -2375,7 +2350,7 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { wdxdisplay_cat.error() << "device #"<BackBufferFormat) << endl; goto Fallback_to_16bpp_buffers; } - + if(Display.PresParams.EnableAutoDepthStencil) { if(!FindBestDepthFormat(Display,Display.DisplayMode,&Display.PresParams.AutoDepthStencilFormat,bWantStencil,false)) { wdxdisplay_cat.error() << "FindBestDepthFormat failed in CreateScreenBuffers for device #"<Windowed = !_props._fullscreen; - + if(dx_multisample_antialiasing_level>1) { // need to check both rendertarget and zbuffer fmts hr = pD3D8->CheckDeviceMultiSampleType(Display.CardIDNum, D3DDEVTYPE_HAL, Display.DisplayMode.Format, _props._fullscreen, D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level)); if(FAILED(hr)) { wdxdisplay_cat.fatal() << "device #"<CheckDeviceMultiSampleType(Display.CardIDNum, D3DDEVTYPE_HAL, Display.PresParams.AutoDepthStencilFormat, _props._fullscreen, D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level)); if(FAILED(hr)) { wdxdisplay_cat.fatal() << "device #"<MultiSampleType = D3DMULTISAMPLE_TYPE(dx_multisample_antialiasing_level); - + if(wdxdisplay_cat.is_info()) wdxdisplay_cat.info() << "device #"<BackBufferWidth = Display.DisplayMode.Width; pPresParams->BackBufferHeight = Display.DisplayMode.Height; DWORD dwBehaviorFlags=0x0; - + if(_dxgsg->scrn.bIsTNLDevice) { dwBehaviorFlags|=D3DCREATE_HARDWARE_VERTEXPROCESSING; // note: we could create a pure device in this case if I eliminated the GetRenderState calls in dxgsg - + // also, no software vertex processing available since I specify D3DCREATE_HARDWARE_VERTEXPROCESSING - // and not D3DCREATE_MIXED_VERTEXPROCESSING + // and not D3DCREATE_MIXED_VERTEXPROCESSING } else { dwBehaviorFlags|=D3DCREATE_SOFTWARE_VERTEXPROCESSING; } - + if(dx_preserve_fpu_state) dwBehaviorFlags|=D3DCREATE_FPU_PRESERVE; @@ -2440,7 +2415,7 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { #if 0 /* this is incorrect, we dont need rendertarget to hold alpha to do normal alpha blending, since blending is usually just based on source alpha. so for now its OK to pick rendertargets with same format as display - + // assume app requires alpha-blending // will fullscrn alphablend work with DISCARD anyway even if this cap is not set? I dont see it being set by latest drivers // for any card. need to test both dx8.0 and dx8.1, it may be that dx8.1 works even if cap is not set, but 8.0 doesnt @@ -2452,23 +2427,25 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { exit(1); } } -*/ +*/ #endif #ifdef _DEBUG if(pPresParams->MultiSampleType != D3DMULTISAMPLE_NONE) assert(pPresParams->SwapEffect == D3DSWAPEFFECT_DISCARD); // only valid effect for multisample #endif + + ClearToBlack(GetDesktopWindow(),_props); - hr = pD3D8->CreateDevice(Display.CardIDNum, D3DDEVTYPE_HAL, _pParentWindowGroup->_hParentWindow, + hr = pD3D8->CreateDevice(Display.CardIDNum, D3DDEVTYPE_HAL, _pParentWindowGroup->_hParentWindow, dwBehaviorFlags, pPresParams, &Display.pD3DDevice); if(FAILED(hr)) { wdxdisplay_cat.fatal() << "D3D CreateDevice failed for device #" << Display.CardIDNum << ", " << D3DERRORSTRING(hr); if(hr == D3DERR_OUTOFVIDEOMEMORY) - goto Fallback_to_16bpp_buffers; + goto Fallback_to_16bpp_buffers; } - + SetRect(&view_rect, 0, 0, dwRenderWidth, dwRenderHeight); } // end create full screen buffers @@ -2480,7 +2457,7 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { } D3DDISPLAYMODE dispmode; - hr = Display.pD3D8->GetAdapterDisplayMode(Display.CardIDNum, &dispmode); + hr = Display.pD3D8->GetAdapterDisplayMode(Display.CardIDNum, &dispmode); if(FAILED(hr)) { wdxdisplay_cat.fatal() << "GetAdapterDisplayMode failed" << D3DERRORSTRING(hr); @@ -2504,9 +2481,9 @@ CreateScreenBuffersAndDevice(DXScreenData &Display) { pPresParams->SwapEffect = D3DSWAPEFFECT_DISCARD; } - assert((dwRenderWidth==pPresParams->BackBufferWidth)&&(dwRenderHeight==pPresParams->BackBufferHeight)); + assert((dwRenderWidth==pPresParams->BackBufferWidth)&&(dwRenderHeight==pPresParams->BackBufferHeight)); - hr = pD3D8->CreateDevice(Display.CardIDNum, D3DDEVTYPE_HAL, _pParentWindowGroup->_hParentWindow, + hr = pD3D8->CreateDevice(Display.CardIDNum, D3DDEVTYPE_HAL, _pParentWindowGroup->_hParentWindow, dwBehaviorFlags, pPresParams, &Display.pD3DDevice); if(FAILED(hr)) { @@ -2556,7 +2533,7 @@ Fallback_to_16bpp_buffers: } } -// assumes CreateDevice or Device->Reset() has just been called, +// assumes CreateDevice or Device->Reset() has just been called, // and the new size is specified in _dxgsg->scrn.PresParams void wdxGraphicsWindow::init_resized_window(void) { DXScreenData *pDisplay=&_dxgsg->scrn; @@ -2583,7 +2560,7 @@ void wdxGraphicsWindow::init_resized_window(void) { _props._yorg = client_rect.top; #ifdef _DEBUG - // try to make sure GDI and DX agree on window client area size + // try to make sure GDI and DX agree on window client area size // but client rect will not include any offscreen areas, so dont // do check if window was bigger than screen (there are other bad // cases too, like when window is positioned partly offscreen, @@ -2594,7 +2571,7 @@ void wdxGraphicsWindow::init_resized_window(void) { if((_props._xsizescrn.pD3DDevice)); @@ -2705,6 +2682,7 @@ void wdxGraphicsWindow::setup_colormap(void) { RealizePalette(_hdc); } +/* dont need to override the defaults (which just go to gsg->begin_frame()) //////////////////////////////////////////////////////////////////// // Function: begin_frame // Access: @@ -2713,10 +2691,6 @@ void wdxGraphicsWindow::begin_frame(void) { GraphicsWindow::begin_frame(); } -void wdxGraphicsWindow::show_frame(void) { - _dxgsg->show_frame(); -} - //////////////////////////////////////////////////////////////////// // Function: end_frame // Access: @@ -2725,6 +2699,7 @@ void wdxGraphicsWindow::show_frame(void) { void wdxGraphicsWindow::end_frame(void) { GraphicsWindow::end_frame(); } +*/ //////////////////////////////////////////////////////////////////// // Function: handle_window_move @@ -2965,7 +2940,7 @@ get_depth_bitwidth(void) { // instead store the depth used at creation time // DX_DECLARE_CLEAN(DDSURFACEDESC2, ddsd); -// _dxgsg->_zbuf->GetSurfaceDesc(&ddsd); +// _dxgsg->_zbuf->GetSurfaceDesc(&ddsd); // return ddsd.ddpfPixelFormat.dwRGBBitCount; } @@ -2985,7 +2960,7 @@ static bool bCursorShadowOn,bMouseVanish; void set_global_parameters(void) { // turn off mousetrails and cursor shadow and mouse cursor vanish - // cursor shadow causes cursor blink and reduced frame rate due to lack of driver support for + // cursor shadow causes cursor blink and reduced frame rate due to lack of driver support for // cursor alpha blending // this is a win2k/xp only param, could use GetVersionEx to do it just for win2k, @@ -3057,6 +3032,7 @@ void wdxGraphicsWindowGroup::initWindowGroup(void) { UINT num_windows=_windows.size(); #define D3D8_NAME "d3d8.dll" + #define D3DCREATE8 "Direct3DCreate8" _hD3D8_DLL = LoadLibrary(D3D8_NAME); if(_hD3D8_DLL == 0) { @@ -3078,21 +3054,21 @@ void wdxGraphicsWindowGroup::initWindowGroup(void) { wdxdisplay_cat.fatal() << "system has only "<< numMonitors << " monitors attached, couldn't find enough devices to meet multi window reqmt of " << num_windows << endl; exit(1); } - } + } - // Do all DX7 stuff first -// find_all_card_memavails(); + // Do all DX7 stuff first + // find_all_card_memavails(); LPDIRECT3D8 pD3D8; typedef LPDIRECT3D8 (WINAPI *Direct3DCreate8_ProcPtr)(UINT SDKVersion); - + // dont want to statically link to possibly non-existent d3d8 dll, so must call D3DCr8 indirectly - Direct3DCreate8_ProcPtr D3DCreate8_Ptr = - (Direct3DCreate8_ProcPtr) GetProcAddress(_hD3D8_DLL, "Direct3DCreate8" ); + Direct3DCreate8_ProcPtr D3DCreate8_Ptr = + (Direct3DCreate8_ProcPtr) GetProcAddress(_hD3D8_DLL, D3DCREATE8); if(D3DCreate8_Ptr == NULL) { - wdxdisplay_cat.fatal() << "GetProcAddress for D3DCreate8 failed!" << endl; + wdxdisplay_cat.fatal() << "GetProcAddress for "<< D3DCREATE8 << "failed!" << endl; exit(1); } @@ -3117,7 +3093,7 @@ void wdxGraphicsWindowGroup::initWindowGroup(void) { } if(pD3D8==NULL) { - wdxdisplay_cat.fatal() << "Direct3DCreate8 failed!\n"; + wdxdisplay_cat.fatal() << D3DCREATE8 << " failed!\n"; exit(1); } @@ -3139,9 +3115,9 @@ void wdxGraphicsWindowGroup::initWindowGroup(void) { wdxdisplay_cat.info() << "D3D8 Adapter[" << i << "]: " << adapter_info.Description << ", Driver: " << adapter_info.Driver << ", DriverVersion: (" - << HIWORD(DrvVer->HighPart) << "." << LOWORD(DrvVer->HighPart) << "." - << HIWORD(DrvVer->LowPart) << "." << LOWORD(DrvVer->LowPart) << ")\nVendorID: 0x" - << (void*) adapter_info.VendorId << " DeviceID: 0x" << (void*) adapter_info.DeviceId + << HIWORD(DrvVer->HighPart) << "." << LOWORD(DrvVer->HighPart) << "." + << HIWORD(DrvVer->LowPart) << "." << LOWORD(DrvVer->LowPart) << ")\nVendorID: 0x" + << (void*) adapter_info.VendorId << " DeviceID: 0x" << (void*) adapter_info.DeviceId << " SubsysID: 0x" << (void*) adapter_info.SubSysId << " Revision: 0x" << (void*) adapter_info.Revision << endl; @@ -3201,13 +3177,13 @@ void wdxGraphicsWindowGroup::initWindowGroup(void) { for(UINT i=0;i<_windows.size();i++) { D3DADAPTER_IDENTIFIER8 adapter_info; pD3D8->GetAdapterIdentifier(_windows[i]->_dxgsg->scrn.CardIDNum,D3DENUM_NO_WHQL_LEVEL,&adapter_info); - wdxdisplay_cat.info() << "D3D8 Adapter[" << i << "]: " << adapter_info.Description + wdxdisplay_cat.info() << "D3D8 Adapter[" << i << "]: " << adapter_info.Description << ", MaxAvailVideoMem: " << _windows[i]->_dxgsg->scrn.MaxAvailVidMem << ", IsLowVidMemCard: " << (_windows[i]->_dxgsg->scrn.bIsLowVidMemCard ? "true" : "false") << endl; } } - CreateWindows(); // creates win32 windows (need to do this before Setting coopLvls and display modes, + CreateWindows(); // creates win32 windows (need to do this before Setting coopLvls and display modes, // but after we have all the monitor handles needed by CreateWindow() // SetCoopLevelsAndDisplayModes(); diff --git a/panda/src/wdxdisplay8/wdxGraphicsWindow8.h b/panda/src/wdxdisplay8/wdxGraphicsWindow8.h index acfad23a54..087cf05171 100644 --- a/panda/src/wdxdisplay8/wdxGraphicsWindow8.h +++ b/panda/src/wdxdisplay8/wdxGraphicsWindow8.h @@ -34,6 +34,8 @@ class wdxGraphicsWindowGroup; const int WDXWIN_CONFIGURE = 4; const int WDXWIN_EVENT = 8; +//#define FIND_CARD_MEMAVAILS + typedef HRESULT (WINAPI * LPDIRECTDRAWCREATEEX)(GUID FAR * lpGuid, LPVOID *lplpDD, REFIID iid,IUnknown FAR *pUnkOuter); typedef struct { @@ -54,6 +56,7 @@ class EXPCL_PANDADX wdxGraphicsWindow : public GraphicsWindow { friend class DXGraphicsStateGuardian; friend class DXTextureContext; friend class wdxGraphicsWindowGroup; + friend class DInput8Info; public: wdxGraphicsWindow(GraphicsPipe* pipe); @@ -63,7 +66,6 @@ public: wdxGraphicsWindow(GraphicsPipe* pipe,const GraphicsWindow::Properties& props,wdxGraphicsWindowGroup *pParentGroup); virtual ~wdxGraphicsWindow(void); - virtual void end_frame( void ); virtual TypeHandle get_gsg_type() const; static GraphicsWindow* make_wdxGraphicsWindow(const FactoryParams ¶ms); @@ -76,11 +78,14 @@ public: void handle_window_move( int x, int y ); void handle_mouse_motion( int x, int y ); void handle_mouse_exit(void); - void handle_keypress( ButtonHandle key, int x, int y ); - void handle_keyrelease( ButtonHandle key); + void handle_keypress(ButtonHandle key, int x, int y ); + void handle_keyrelease(ButtonHandle key); void dx_setup(); - virtual void begin_frame( void ); - void show_frame(); + +// dont need to override these now? +// virtual void begin_frame( void ); +// virtual void end_frame( void ); + virtual bool resize(unsigned int xsize,unsigned int ysize); virtual unsigned int verify_window_sizes(unsigned int numsizes,unsigned int *dimen); virtual int get_depth_bitwidth(void); @@ -104,7 +109,7 @@ public: UINT_PTR _PandaPausedTimer; DXGraphicsStateGuardian *_dxgsg; void CreateScreenBuffersAndDevice(DXScreenData &Display); - + private: wdxGraphicsWindowGroup *_pParentWindowGroup; HDC _hdc; @@ -146,7 +151,7 @@ class EXPCL_PANDADX wdxGraphicsWindowGroup { // group of windows are all created at the same time friend class wdxGraphicsWindow; -PUBLISHED: +PUBLISHED: wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&); wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&,const GraphicsWindow::Properties&); wdxGraphicsWindowGroup(GraphicsPipe *,const GraphicsWindow::Properties&,const GraphicsWindow::Properties&, @@ -167,7 +172,7 @@ public: pvector _windows; DXDeviceInfoVec *_pDeviceInfoVec; // only used during init to store valid devices HWND _hParentWindow; - HWND _hOldForegroundWindow; + HWND _hOldForegroundWindow; HCURSOR _hMouseCursor; bool _bLoadedCustomCursor; bool _bClosingAllWindows; @@ -175,6 +180,7 @@ public: DWORD _numMonitors,_numAdapters; LPDIRECT3D8 _pD3D8; HINSTANCE _hD3D8_DLL; + DInput8Info *_pDInputInfo; DXDeviceInfoVec _DeviceInfoVec; };