@@ -9003,15 +9003,18 @@ xbox::void_xt WINAPI xbox::EMUPATCH(D3DDevice_InsertCallback)
90039003 LOG_INCOMPLETE ();
90049004}
90059005
9006+ unsigned int MaxRectPatchVertexCount = 0 ;
9007+ std::map<uint32_t , D3DRECTPATCH_INFO> g_RectPatchInfoCache;
9008+ std::map<uint32_t , D3DTRIPATCH_INFO> g_TriPatchInfoCache;
90069009// ******************************************************************
90079010// * patch: D3DDevice_DrawRectPatch
90089011// ******************************************************************
90099012xbox::hresult_xt WINAPI xbox::EMUPATCH (D3DDevice_DrawRectPatch)
90109013(
90119014 uint_xt Handle,
9012- CONST float_xt * pNumSegs,
9013- CONST D3DRECTPATCH_INFO * pRectPatchInfo
9014- )
9015+ CONST float_xt* pNumSegs,
9016+ CONST D3DRECTPATCH_INFO* pRectPatchInfo
9017+ )
90159018{
90169019 LOG_FUNC_BEGIN
90179020 LOG_FUNC_ARG (Handle)
@@ -9020,10 +9023,26 @@ xbox::hresult_xt WINAPI xbox::EMUPATCH(D3DDevice_DrawRectPatch)
90209023 LOG_FUNC_END;
90219024
90229025 CxbxUpdateNativeD3DResources ();
9023-
9024- HRESULT hRet = g_pD3DDevice->DrawRectPatch ( Handle, pNumSegs, pRectPatchInfo );
9026+ // setup DrawContext in order to call VertexBufferConverter.Apply() to setup stream source and vertex buffer
9027+ CxbxDrawContext DrawContext = {};
9028+ DrawContext.XboxPrimitiveType = xbox::X_D3DPRIMITIVETYPE::X_D3DPT_QUADLIST;
9029+ D3DRECTPATCH_INFO tmpRectPatchInfo;
9030+ if (pRectPatchInfo != nullptr ) {
9031+ g_RectPatchInfoCache.insert (std::pair<uint32_t , D3DRECTPATCH_INFO>(Handle, *pRectPatchInfo));
9032+ }
9033+ else {
9034+ // d3d9 seems unhappy when pRectPatchInfo==nullptr
9035+ auto it = g_RectPatchInfoCache.find (Handle);
9036+ tmpRectPatchInfo = it->second ;
9037+ pRectPatchInfo = &tmpRectPatchInfo;
9038+ }
9039+ DrawContext.dwVertexCount = (pRectPatchInfo->StartVertexOffsetHeight + pRectPatchInfo->Height ) * pRectPatchInfo->Stride ;
9040+ // keep max. vertex count so we can use same vertex count in DrawContext which will result in using the same vertex buffer cache.
9041+ if (MaxRectPatchVertexCount < DrawContext.dwVertexCount )MaxRectPatchVertexCount = DrawContext.dwVertexCount ;
9042+ DrawContext.dwVertexCount = MaxRectPatchVertexCount;
9043+ VertexBufferConverter.Apply (&DrawContext);
9044+ HRESULT hRet = g_pD3DDevice->DrawRectPatch (Handle, pNumSegs, pRectPatchInfo);
90259045 DEBUG_D3DRESULT (hRet, " g_pD3DDevice->DrawRectPatch" );
9026-
90279046 return hRet;
90289047}
90299048
0 commit comments