本文整理汇总了C++中TRefCountPtr::GetInitReference方法的典型用法代码示例。如果您正苦于以下问题:C++ TRefCountPtr::GetInitReference方法的具体用法?C++ TRefCountPtr::GetInitReference怎么用?C++ TRefCountPtr::GetInitReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TRefCountPtr
的用法示例。
在下文中一共展示了TRefCountPtr::GetInitReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: D3D9PreProcessShader
/** Preprocesses a shader without performing compilation, and dump it out for debugging*/
void D3D9PreProcessShader(
const TCHAR* strFilename,
const FString& strShaderFile,
vector<D3DXMACRO>& Defines,
const FD3DIncludeEnvironment& Environment,
const TCHAR* strShaderPath
)
{
TRefCountPtr<ID3DXBuffer> ShaderCode;
TRefCountPtr<ID3DXBuffer> ErrorText;
FTCHARToANSI AnsiShaderFile(strShaderFile.c_str());
FD3DIncludeEnvironment IncludeEnvironment(Environment);
HRESULT ret = D3DXPreprocessShader( (ANSICHAR*)AnsiShaderFile,
strShaderFile.size(),
&Defines.at(0),
&IncludeEnvironment,
ShaderCode.GetInitReference(),
ErrorText.GetInitReference()
);
if( FAILED(ret) )
{
debugf(NAME_Warning, TEXT("Preprocess failed for shader %s: %s"), strFilename, ANSI_TO_TCHAR(ErrorText->GetBufferPointer()));
}
else
{
TCHAR Tmp[MAX_SPRINTF];
appSprintf(Tmp, TEXT("%s%s.pre"), strShaderPath, strFilename);
appSaveStringToFile(ANSI_TO_TCHAR(ShaderCode->GetBufferPointer()), Tmp);
}
}
示例2: IsViewportFullscreen
void FSlateD3DRenderer::Private_CreateViewport( TSharedRef<SWindow> InWindow, const FVector2D &WindowSize )
{
TSharedRef< FGenericWindow > NativeWindow = InWindow->GetNativeWindow().ToSharedRef();
bool bFullscreen = IsViewportFullscreen( *InWindow );
bool bWindowed = true;//@todo implement fullscreen: !bFullscreen;
DXGI_SWAP_CHAIN_DESC SwapChainDesc;
FMemory::Memzero(&SwapChainDesc, sizeof(SwapChainDesc) );
SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Width = FMath::TruncToInt(WindowSize.X);
SwapChainDesc.BufferDesc.Height = FMath::TruncToInt(WindowSize.Y);
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.OutputWindow = (HWND)NativeWindow->GetOSWindowHandle();
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.Windowed = bWindowed;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
TRefCountPtr<IDXGIDevice> DXGIDevice;
HRESULT Hr = GD3DDevice->QueryInterface( __uuidof(IDXGIDevice), (void**)DXGIDevice.GetInitReference() );
check( SUCCEEDED(Hr) );
TRefCountPtr<IDXGIAdapter> DXGIAdapter;
Hr = DXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)DXGIAdapter.GetInitReference() );
check( SUCCEEDED(Hr) );
TRefCountPtr<IDXGIFactory> DXGIFactory;
DXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void **)DXGIFactory.GetInitReference() );
check( SUCCEEDED(Hr) );
FSlateD3DViewport Viewport;
Hr = DXGIFactory->CreateSwapChain(DXGIDevice.GetReference(), &SwapChainDesc, Viewport.D3DSwapChain.GetInitReference() );
check( SUCCEEDED(Hr) );
Hr = DXGIFactory->MakeWindowAssociation((HWND)NativeWindow->GetOSWindowHandle(),DXGI_MWA_NO_ALT_ENTER);
check(SUCCEEDED(Hr));
uint32 Width = FMath::TruncToInt(WindowSize.X);
uint32 Height = FMath::TruncToInt(WindowSize.Y);
Viewport.ViewportInfo.MaxDepth = 1.0f;
Viewport.ViewportInfo.MinDepth = 0.0f;
Viewport.ViewportInfo.Width = Width;
Viewport.ViewportInfo.Height = Height;
Viewport.ViewportInfo.TopLeftX = 0;
Viewport.ViewportInfo.TopLeftY = 0;
CreateBackBufferResources( Viewport.D3DSwapChain, Viewport.BackBufferTexture, Viewport.RenderTargetView );
Viewport.ProjectionMatrix = CreateProjectionMatrixD3D( Width, Height );
WindowToViewportMap.Add( &InWindow.Get(), Viewport );
}
示例3: SetGraphicsAdapter
void FOculusRiftPlugin::SetGraphicsAdapter(const ovrGraphicsLuid& luid)
{
TRefCountPtr<IDXGIFactory> DXGIFactory;
if(SUCCEEDED(CreateDXGIFactory(__uuidof(IDXGIFactory), (void**) DXGIFactory.GetInitReference())))
{
for(int32 adapterIndex = 0;; adapterIndex++)
{
TRefCountPtr<IDXGIAdapter> DXGIAdapter;
DXGI_ADAPTER_DESC DXGIAdapterDesc;
if( FAILED(DXGIFactory->EnumAdapters(adapterIndex, DXGIAdapter.GetInitReference())) ||
FAILED(DXGIAdapter->GetDesc(&DXGIAdapterDesc)) )
{
break;
}
if(!FMemory::Memcmp(&luid, &DXGIAdapterDesc.AdapterLuid, sizeof(LUID)))
{
// Remember this adapterIndex so we use the right adapter, even when we startup without HMD connected
GConfig->SetInt(TEXT("Oculus.Settings"), TEXT("GraphicsAdapter"), adapterIndex, GEngineIni);
break;
}
}
}
}
示例4: SUCCEEDED
void FSlateD3DRenderer::CreateBackBufferResources( TRefCountPtr<IDXGISwapChain>& InSwapChain, TRefCountPtr<ID3D11Texture2D>& OutBackBuffer, TRefCountPtr<ID3D11RenderTargetView>& OutRTV )
{
InSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), (void**)OutBackBuffer.GetInitReference() );
D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
RTVDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
RTVDesc.Texture2D.MipSlice = 0;
HRESULT Hr = GD3DDevice->CreateRenderTargetView( OutBackBuffer, &RTVDesc, OutRTV.GetInitReference() );
check( SUCCEEDED(Hr) );
}
示例5:
FDynamicRHI* FD3D12DynamicRHIModule::CreateRHI()
{
TRefCountPtr<IDXGIFactory4> DXGIFactory;
SafeCreateDXGIFactory(DXGIFactory.GetInitReference());
check(DXGIFactory);
return new FD3D12DynamicRHI(DXGIFactory, ChosenAdapter);
}
示例6: sizeof
FD3D11Viewport::FD3D11Viewport(FD3D11DynamicRHI* InD3DRHI,HWND InWindowHandle,uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen, EPixelFormat InPreferredPixelFormat):
D3DRHI(InD3DRHI),
LastFlipTime(0),
LastFrameComplete(0),
LastCompleteTime(0),
SyncCounter(0),
bSyncedLastFrame(false),
WindowHandle(InWindowHandle),
MaximumFrameLatency(3),
SizeX(InSizeX),
SizeY(InSizeY),
bIsFullscreen(bInIsFullscreen),
PixelFormat(InPreferredPixelFormat),
bIsValid(true),
FrameSyncEvent(InD3DRHI)
{
check(IsInGameThread());
D3DRHI->Viewports.Add(this);
// Ensure that the D3D device has been created.
D3DRHI->InitD3DDevice();
// Create a backbuffer/swapchain for each viewport
TRefCountPtr<IDXGIDevice> DXGIDevice;
VERIFYD3D11RESULT(D3DRHI->GetDevice()->QueryInterface( IID_IDXGIDevice, (void**)DXGIDevice.GetInitReference() ));
// Create the swapchain.
DXGI_SWAP_CHAIN_DESC SwapChainDesc;
FMemory::Memzero( &SwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC) );
SwapChainDesc.BufferDesc = SetupDXGI_MODE_DESC();
// MSAA Sample count
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
// 1:single buffering, 2:double buffering, 3:triple buffering
SwapChainDesc.BufferCount = 1;
SwapChainDesc.OutputWindow = WindowHandle;
SwapChainDesc.Windowed = !bIsFullscreen;
// DXGI_SWAP_EFFECT_DISCARD / DXGI_SWAP_EFFECT_SEQUENTIAL
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
VERIFYD3D11RESULT(D3DRHI->GetFactory()->CreateSwapChain(DXGIDevice,&SwapChainDesc,SwapChain.GetInitReference()));
// Set the DXGI message hook to not change the window behind our back.
D3DRHI->GetFactory()->MakeWindowAssociation(WindowHandle,DXGI_MWA_NO_WINDOW_CHANGES);
// Create a RHI surface to represent the viewport's back buffer.
BackBuffer = GetSwapChainSurface(D3DRHI, PixelFormat, SwapChain);
// Tell the window to redraw when they can.
// @todo: For Slate viewports, it doesn't make sense to post WM_PAINT messages (we swallow those.)
::PostMessage( WindowHandle, WM_PAINT, 0, 0 );
BeginInitResource(&FrameSyncEvent);
}
示例7: GetSwapChainSurface
/**
* Creates a FD3D11Surface to represent a swap chain's back buffer.
*/
FD3D11Texture2D* GetSwapChainSurface(FD3D11DynamicRHI* D3DRHI,IDXGISwapChain* SwapChain)
{
// Grab the back buffer
TRefCountPtr<ID3D11Texture2D> BackBufferResource;
VERIFYD3D11RESULT_EX(SwapChain->GetBuffer(0,IID_ID3D11Texture2D,(void**)BackBufferResource.GetInitReference()), D3DRHI->GetDevice());
// create the render target view
TRefCountPtr<ID3D11RenderTargetView> BackBufferRenderTargetView;
D3D11_RENDER_TARGET_VIEW_DESC RTVDesc;
RTVDesc.Format = DXGI_FORMAT_UNKNOWN;
RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
RTVDesc.Texture2D.MipSlice = 0;
VERIFYD3D11RESULT(D3DRHI->GetDevice()->CreateRenderTargetView(BackBufferResource,&RTVDesc,BackBufferRenderTargetView.GetInitReference()));
D3D11_TEXTURE2D_DESC TextureDesc;
BackBufferResource->GetDesc(&TextureDesc);
TArray<TRefCountPtr<ID3D11RenderTargetView> > RenderTargetViews;
RenderTargetViews.Add(BackBufferRenderTargetView);
// create a shader resource view to allow using the backbuffer as a texture
TRefCountPtr<ID3D11ShaderResourceView> BackBufferShaderResourceView;
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
SRVDesc.Format = DXGI_FORMAT_UNKNOWN;
SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MostDetailedMip = 0;
SRVDesc.Texture2D.MipLevels = 1;
VERIFYD3D11RESULT(D3DRHI->GetDevice()->CreateShaderResourceView(BackBufferResource,&SRVDesc,BackBufferShaderResourceView.GetInitReference()));
FD3D11Texture2D* NewTexture = new FD3D11Texture2D(
D3DRHI,
BackBufferResource,
BackBufferShaderResourceView,
false,
1,
RenderTargetViews,
NULL,
TextureDesc.Width,
TextureDesc.Height,
1,
1,
1,
PF_A2B10G10R10,
false,
false,
false
);
D3D11TextureAllocated2D(*NewTexture);
NewTexture->DoNoDeferDelete();
return NewTexture;
}
示例8: sizeof
FIndexBufferRHIRef FD3D11DynamicRHI::RHICreateIndexBuffer(uint32 Stride,uint32 Size,uint32 InUsage, FRHIResourceCreateInfo& CreateInfo)
{
// Explicitly check that the size is nonzero before allowing CreateIndexBuffer to opaquely fail.
check(Size > 0);
// Describe the index buffer.
D3D11_BUFFER_DESC Desc;
ZeroMemory( &Desc, sizeof( D3D11_BUFFER_DESC ) );
Desc.ByteWidth = Size;
Desc.Usage = (InUsage & BUF_AnyDynamic) ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
Desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
Desc.CPUAccessFlags = (InUsage & BUF_AnyDynamic) ? D3D11_CPU_ACCESS_WRITE : 0;
Desc.MiscFlags = 0;
if (InUsage & BUF_UnorderedAccess)
{
Desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
}
if(InUsage & BUF_DrawIndirect)
{
Desc.MiscFlags |= D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
}
if (InUsage & BUF_ShaderResource)
{
Desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
}
// If a resource array was provided for the resource, create the resource pre-populated
D3D11_SUBRESOURCE_DATA InitData;
D3D11_SUBRESOURCE_DATA* pInitData = NULL;
if(CreateInfo.ResourceArray)
{
check(Size == CreateInfo.ResourceArray->GetResourceDataSize());
InitData.pSysMem = CreateInfo.ResourceArray->GetResourceData();
InitData.SysMemPitch = Size;
InitData.SysMemSlicePitch = 0;
pInitData = &InitData;
}
TRefCountPtr<ID3D11Buffer> IndexBufferResource;
VERIFYD3D11RESULT(Direct3DDevice->CreateBuffer(&Desc,pInitData,IndexBufferResource.GetInitReference()));
UpdateBufferStats(IndexBufferResource, true);
if(CreateInfo.ResourceArray)
{
// Discard the resource array's contents.
CreateInfo.ResourceArray->Discard();
}
return new FD3D11IndexBuffer(IndexBufferResource, Stride, Size, InUsage);
}
示例9: if
FUnorderedAccessViewRHIRef FD3D12DynamicRHI::RHICreateUnorderedAccessView(FStructuredBufferRHIParamRef StructuredBufferRHI, bool bUseUAVCounter, bool bAppendBuffer)
{
FD3D12StructuredBuffer* StructuredBuffer = FD3D12DynamicRHI::ResourceCast(StructuredBufferRHI);
const D3D12_RESOURCE_DESC& BufferDesc = StructuredBuffer->Resource->GetDesc();
const uint32 BufferUsage = StructuredBuffer->GetUsage();
const bool bByteAccessBuffer = (BufferUsage & BUF_ByteAddressBuffer) != 0;
const bool bStructuredBuffer = !bByteAccessBuffer;
check(bByteAccessBuffer != bStructuredBuffer); // You can't have a structured buffer that allows raw views
D3D12_UNORDERED_ACCESS_VIEW_DESC UAVDesc ={};
UAVDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
UAVDesc.Format = DXGI_FORMAT_UNKNOWN;
uint32 EffectiveStride = StructuredBuffer->GetStride();
if (bByteAccessBuffer)
{
UAVDesc.Format = DXGI_FORMAT_R32_TYPELESS;
EffectiveStride = 4;
}
else if (BufferUsage & BUF_DrawIndirect)
{
UAVDesc.Format = DXGI_FORMAT_R32_UINT;
EffectiveStride = 4;
}
UAVDesc.Buffer.FirstElement = StructuredBuffer->ResourceLocation->GetOffset() / EffectiveStride;
UAVDesc.Buffer.NumElements = StructuredBuffer->ResourceLocation->GetEffectiveBufferSize() / EffectiveStride;
UAVDesc.Buffer.StructureByteStride = bStructuredBuffer ? EffectiveStride : 0;
UAVDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
UAVDesc.Buffer.CounterOffsetInBytes = 0;
const bool bNeedsCounterResource = bAppendBuffer | bUseUAVCounter;
TRefCountPtr<FD3D12Resource> CounterResource;
if (bNeedsCounterResource)
{
GetRHIDevice()->GetResourceHelper().CreateBuffer(D3D12_HEAP_TYPE_DEFAULT, 4, CounterResource.GetInitReference(), D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
}
if (bByteAccessBuffer)
{
UAVDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW;
}
return new FD3D12UnorderedAccessView(GetRHIDevice(), &UAVDesc, StructuredBuffer->ResourceLocation, CounterResource);
}
示例10:
int32 FD3DGPUProfiler::RecordEventTimestamp(ID3D11Device* Direct3DDevice, ID3D11DeviceContext* Direct3DDeviceIMContext)
{
check(CurrentGPUProfile);
D3D11_QUERY_DESC TimestampQueryDesc;
TimestampQueryDesc.Query = D3D11_QUERY_TIMESTAMP;
TimestampQueryDesc.MiscFlags = 0;
TRefCountPtr<ID3D11Query> TimestampQuery;
VERIFYD3D11RESULT(Direct3DDevice->CreateQuery(&TimestampQueryDesc,TimestampQuery.GetInitReference()));
Direct3DDeviceIMContext->End(TimestampQuery);
return CurrentGPUProfile->EventTimestampQueries.Add(TimestampQuery);
}
示例11: CountAdapterOutputs
static uint32 CountAdapterOutputs(TRefCountPtr<IDXGIAdapter>& Adapter)
{
uint32 OutputCount = 0;
for(;;)
{
TRefCountPtr<IDXGIOutput> Output;
HRESULT hr = Adapter->EnumOutputs(OutputCount, Output.GetInitReference());
if(FAILED(hr))
{
break;
}
++OutputCount;
}
return OutputCount;
}
示例12:
/**
* Initializes the static variables, if necessary.
*/
void FD3D11BufferedGPUTiming::PlatformStaticInitialize(void* UserData)
{
// Are the static variables initialized?
check( !GAreGlobalsInitialized );
// Get the GPU timestamp frequency.
GTimingFrequency = 0;
TRefCountPtr<ID3D11Query> FreqQuery;
FD3D11DynamicRHI* D3DRHI = (FD3D11DynamicRHI*)UserData;
ID3D11DeviceContext *D3D11DeviceContext = D3DRHI->GetDeviceContext();
HRESULT D3DResult;
D3D11_QUERY_DESC QueryDesc;
QueryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
QueryDesc.MiscFlags = 0;
D3DResult = D3DRHI->GetDevice()->CreateQuery(&QueryDesc, FreqQuery.GetInitReference() );
if ( D3DResult == S_OK )
{
D3D11DeviceContext->Begin(FreqQuery);
D3D11DeviceContext->End(FreqQuery);
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT FreqQueryData;
D3DResult = D3D11DeviceContext->GetData(FreqQuery,&FreqQueryData,sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT),0);
double StartTime = FPlatformTime::Seconds();
while ( D3DResult == S_FALSE && (FPlatformTime::Seconds() - StartTime) < 0.1 )
{
FPlatformProcess::Sleep( 0.005f );
D3DResult = D3D11DeviceContext->GetData(FreqQuery,&FreqQueryData,sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT),0);
}
if(D3DResult == S_OK)
{
GTimingFrequency = FreqQueryData.Frequency;
checkSlow(!FreqQueryData.Disjoint);
}
}
FreqQuery = NULL;
}
示例13: IsCompositionEnabled
bool FD3D11Viewport::Present(bool bLockToVsync)
{
bool bNativelyPresented = true;
#if D3D11_WITH_DWMAPI
// We can't call Present if !bIsValid, as it waits a window message to be processed, but the main thread may not be pumping the message handler.
if(bIsValid)
{
// Check if the viewport's swap chain has been invalidated by DXGI.
BOOL bSwapChainFullscreenState;
TRefCountPtr<IDXGIOutput> SwapChainOutput;
VERIFYD3D11RESULT(SwapChain->GetFullscreenState(&bSwapChainFullscreenState,SwapChainOutput.GetInitReference()));
// Can't compare BOOL with bool...
if ( (!!bSwapChainFullscreenState) != bIsFullscreen )
{
bIsValid = false;
// Minimize the window.
// use SW_FORCEMINIMIZE if the messaging thread is likely to be blocked for a sizeable period.
// SW_FORCEMINIMIZE also prevents the minimize animation from playing.
::ShowWindow(WindowHandle,SW_MINIMIZE);
}
}
// When desktop composition is enabled, locking to vsync via the Present
// call is unreliable. Instead, communicate with the desktop window manager
// directly to enable vsync.
const bool bSyncWithDWM = bLockToVsync && !bIsFullscreen && RHIConsoleVariables::bSyncWithDWM && IsCompositionEnabled();
if (bSyncWithDWM)
{
PresentWithVsyncDWM();
}
else
#endif //D3D11_WITH_DWMAPI
{
// Present the back buffer to the viewport window.
bNativelyPresented = PresentChecked(bLockToVsync ? RHIConsoleVariables::SyncInterval : 0);
}
return bNativelyPresented;
}
示例14: if
FRenderQueryRHIRef FD3D11DynamicRHI::RHICreateRenderQuery(ERenderQueryType QueryType)
{
TRefCountPtr<ID3D11Query> Query;
D3D11_QUERY_DESC Desc;
if(QueryType == RQT_Occlusion)
{
Desc.Query = D3D11_QUERY_OCCLUSION;
}
else if(QueryType == RQT_AbsoluteTime)
{
Desc.Query = D3D11_QUERY_TIMESTAMP;
}
else
{
check(0);
}
Desc.MiscFlags = 0;
VERIFYD3D11RESULT(Direct3DDevice->CreateQuery(&Desc,Query.GetInitReference()));
return new FD3D11OcclusionQuery(Query, QueryType);
}
示例15: sizeof
/** Merges a set of D3DXMeshes. */
static void MergeD3DXMeshes(
IDirect3DDevice9* Device,
TRefCountPtr<ID3DXMesh>& OutMesh,TArray<int32>& OutBaseFaceIndex,const TArray<ID3DXMesh*>& Meshes)
{
TArray<D3DVERTEXELEMENT9> VertexElements;
GetD3D9MeshVertexDeclarations(VertexElements);
// Count the number of faces and vertices in the input meshes.
int32 NumFaces = 0;
int32 NumVertices = 0;
for(int32 MeshIndex = 0;MeshIndex < Meshes.Num();MeshIndex++)
{
NumFaces += Meshes[MeshIndex]->GetNumFaces();
NumVertices += Meshes[MeshIndex]->GetNumVertices();
}
// Create mesh for source data
VERIFYD3D9RESULT(D3DXCreateMesh(
NumFaces,
NumVertices,
D3DXMESH_SYSTEMMEM,
(D3DVERTEXELEMENT9*)VertexElements.GetData(),
Device,
OutMesh.GetInitReference()
) );
// Fill D3DXMesh
FUtilVertex* ResultVertices;
uint16* ResultIndices;
::DWORD * ResultAttributes;
OutMesh->LockVertexBuffer(0,(LPVOID*)&ResultVertices);
OutMesh->LockIndexBuffer(0,(LPVOID*)&ResultIndices);
OutMesh->LockAttributeBuffer(0, &ResultAttributes);
int32 BaseVertexIndex = 0;
int32 BaseFaceIndex = 0;
for(int32 MeshIndex = 0;MeshIndex < Meshes.Num();MeshIndex++)
{
ID3DXMesh* Mesh = Meshes[MeshIndex];
FUtilVertex* Vertices;
uint16* Indices;
::DWORD * Attributes;
Mesh->LockVertexBuffer(0,(LPVOID*)&Vertices);
Mesh->LockIndexBuffer(0,(LPVOID*)&Indices);
Mesh->LockAttributeBuffer(0, &Attributes);
for(uint32 FaceIndex = 0;FaceIndex < Mesh->GetNumFaces();FaceIndex++)
{
for(uint32 VertexIndex = 0;VertexIndex < 3;VertexIndex++)
{
*ResultIndices++ = BaseVertexIndex + *Indices++;
}
}
OutBaseFaceIndex.Add(BaseFaceIndex);
BaseFaceIndex += Mesh->GetNumFaces();
FMemory::Memcpy(ResultVertices,Vertices,Mesh->GetNumVertices() * sizeof(FUtilVertex));
ResultVertices += Mesh->GetNumVertices();
BaseVertexIndex += Mesh->GetNumVertices();
FMemory::Memcpy(ResultAttributes,Attributes,Mesh->GetNumFaces() * sizeof(uint32));
ResultAttributes += Mesh->GetNumFaces();
Mesh->UnlockIndexBuffer();
Mesh->UnlockVertexBuffer();
Mesh->UnlockAttributeBuffer();
}
OutMesh->UnlockIndexBuffer();
OutMesh->UnlockVertexBuffer();
OutMesh->UnlockAttributeBuffer();
}