当前位置: 首页>>代码示例>>C++>>正文


C++ ComPtr::Map方法代码示例

本文整理汇总了C++中microsoft::wrl::ComPtr::Map方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::Map方法的具体用法?C++ ComPtr::Map怎么用?C++ ComPtr::Map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在microsoft::wrl::ComPtr的用法示例。


在下文中一共展示了ComPtr::Map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

	Microsoft::WRL::ComPtr<ID3D12Resource> Renderer::UploadIndexData(void *data, long dataSize)
	{
		WaitForGpu();

		// Command list allocators can only be reset when the associated 
		// command lists have finished execution on the GPU; apps should use 
		// fences to determine GPU execution progress.
		ThrowIfFailed(_commandAllocators[_frameIndex]->Reset());

		// However, when ExecuteCommandList() is called on a particular command 
		// list, that command list can then be reset at any time and must be before 
		// re-recording.
		ThrowIfFailed(_commandList->Reset(_commandAllocators[_frameIndex].Get(), NULL));

		Microsoft::WRL::ComPtr<ID3D12Resource> indexBuffer;
		Microsoft::WRL::ComPtr<ID3D12Resource> indexBufferUpload;

		ThrowIfFailed(_device->CreateCommittedResource(
			&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
			D3D12_HEAP_FLAG_NONE,
			&CD3DX12_RESOURCE_DESC::Buffer(dataSize),
			D3D12_RESOURCE_STATE_COPY_DEST,
			nullptr,
			IID_PPV_ARGS(&indexBuffer)));

		ThrowIfFailed(_device->CreateCommittedResource(
			&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
			D3D12_HEAP_FLAG_NONE,
			&CD3DX12_RESOURCE_DESC::Buffer(dataSize),
			D3D12_RESOURCE_STATE_GENERIC_READ,
			nullptr,
			IID_PPV_ARGS(&indexBufferUpload)));

		// Copy data to the intermediate upload heap and then schedule a copy 
		// from the upload heap to the vertex buffer.
		UINT8* pIndexDataBegin;
		ThrowIfFailed(indexBufferUpload->Map(0, &CD3DX12_RANGE(0, dataSize), reinterpret_cast<void**>(&pIndexDataBegin)));
		memcpy(pIndexDataBegin, data, dataSize);
		indexBufferUpload->Unmap(0, nullptr);

		_commandList->CopyBufferRegion(indexBuffer.Get(), 0, indexBufferUpload.Get(), 0, dataSize);
		_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(indexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_INDEX_BUFFER));

		// Close the command list and execute it to begin the vertex buffer copy into
		// the default heap.
		ThrowIfFailed(_commandList->Close());
		ID3D12CommandList* ppCommandLists[] = { _commandList.Get() };
		_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

		WaitForGpu();

		return indexBuffer;
	}
开发者ID:Slin,项目名称:leapBoxing,代码行数:53,代码来源:LBRenderer.cpp

示例2: glBufferSubData

void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
    if( g_pD3DDevice == 0 )
    {
        LOGInfo( LOGTag, "Trying to buffer data before d3d is initialized!\n" );
        return;
    }

    int buffer = -1;

    if( target == GL_ARRAY_BUFFER )
        buffer = g_ActiveBufferObject_Array;
    else if( target == GL_ELEMENT_ARRAY_BUFFER )
        buffer = g_ActiveBufferObject_ElementArray;

    if( buffer == -1 )
    {
        LOGInfo( LOGTag, "glBufferSubData() buffer not found!\n" );
        return;
    }

    assert( g_D3DBufferObjects[buffer].m_InUse == true );

    if( g_D3DBufferObjects[buffer].m_Buffer == 0 )
    {
        LOGInfo( LOGTag, "glBufferSubData() buffer not allocated!\n" );
        return;
    }

    // set the buffer data:
    if( data != 0 )
    {
        D3D11_MAPPED_SUBRESOURCE mappedResource;

        // Lock the vertex buffer so it can be written to.
        HRESULT result = g_pD3DContext->Map( g_D3DBufferObjects[buffer].m_Buffer.Get(), 0,
                                             D3D11_MAP_WRITE_DISCARD, 0, &mappedResource );
        if( FAILED(result) )
            return;

        // Get a pointer to the data in the vertex buffer.
        void* verticesPtr = (void*)((int*)mappedResource.pData + offset);

        // Copy the data into the vertex buffer.
        memcpy( verticesPtr, (void*)data, size );

        // Unlock the vertex buffer.
        g_pD3DContext->Unmap( g_D3DBufferObjects[buffer].m_Buffer.Get(), 0 );
    }
}
开发者ID:pmeneguzzi,项目名称:MyFramework,代码行数:50,代码来源:DXWrapper.cpp

示例3: glBufferData

void glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
{
    if( g_pD3DDevice == 0 )
    {
        LOGInfo( LOGTag, "Trying to initialize a buffer before d3d is initialized!\n" );
        return;
    }

    int buffer = -1;

    if( target == GL_ARRAY_BUFFER )
        buffer = g_ActiveBufferObject_Array;
    else if( target == GL_ELEMENT_ARRAY_BUFFER )
        buffer = g_ActiveBufferObject_ElementArray;

    if( buffer == -1 )
        return;

    assert( g_D3DBufferObjects[buffer].m_InUse == true );

    if( g_D3DBufferObjects[buffer].m_Buffer == 0 )
    {
        D3D11_BUFFER_DESC BufferDesc;

        // TODO: handle usage
        BufferDesc.Usage = D3D11_USAGE_DYNAMIC;
        BufferDesc.ByteWidth = size;
        if( target == GL_ARRAY_BUFFER )
            BufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
        else if( target == GL_ELEMENT_ARRAY_BUFFER )
            BufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;    
        BufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
        BufferDesc.MiscFlags = 0;
        BufferDesc.StructureByteStride = 0;

        // Now create the vertex buffer.
        HRESULT result = g_pD3DDevice->CreateBuffer( &BufferDesc, 0, &g_D3DBufferObjects[buffer].m_Buffer );
        if( FAILED(result) )
            return;
    }

    // set the buffer data:
    if( data != 0 )
    {
        D3D11_MAPPED_SUBRESOURCE mappedResource;

        // Lock the vertex buffer so it can be written to.
        HRESULT result = g_pD3DContext->Map( g_D3DBufferObjects[buffer].m_Buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource );
        if( FAILED(result) )
            return;

        // Get a pointer to the data in the vertex buffer.
        void* verticesPtr = (void*)mappedResource.pData;

        // Copy the data into the vertex buffer.
        memcpy( verticesPtr, (void*)data, size );

        // Unlock the vertex buffer.
        g_pD3DContext->Unmap( g_D3DBufferObjects[buffer].m_Buffer.Get(), 0 );
    }
}
开发者ID:pmeneguzzi,项目名称:MyFramework,代码行数:61,代码来源:DXWrapper.cpp


注:本文中的microsoft::wrl::ComPtr::Map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。