2017-05-30 154 views
0

我想縮放從AcquireNextFrame創建的紋理。 這裏是我的代碼:directX 11 scale texture2D

if (gRealTexture == nullptr) { 
     D3D11_TEXTURE2D_DESC description; 
     texture2D->GetDesc(&description); 
     description.BindFlags = 0; 
     description.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; 
     description.Usage = D3D11_USAGE_STAGING; 
     description.MiscFlags = 0; 
     hr = gDevice->CreateTexture2D(&description, NULL, &gRealTexture); 
     if (FAILED(hr)) { 
      if (gRealTexture) { 
       gRealTexture->Release(); 
       gRealTexture = nullptr; 
      } 
      return NULL; 
     } 
    } 

    gImmediateContext->CopyResource(gRealTexture, texture2D); 
    D3D11_MAPPED_SUBRESOURCE mapped; 
    hr = gImmediateContext->Map(gRealTexture, 0, D3D11_MAP_READ_WRITE, 0, &mapped); 
    if (FAILED(hr)) { 
     gRealTexture->Release(); 
     gRealTexture = NULL; 
     return NULL; 
    } 
    unsigned char *source = static_cast<unsigned char *>(mapped.pData); //Here I get the pixel buffer data 

問題是,它是在全高清分辨率(1920×1080)。我想降低分辨率(例如1280x720),因爲我需要通過網絡發送source。我並不需要全高清圖像。

在獲取像素緩衝區之前,是否可以使用DirectX輕鬆實現?

感謝

回答

0

創建一個較小的分辨率的紋理,採用了全屏四(但收縮到新的大小)呈現texture2d較小質感。確保雙線性過濾打開。

然後複製並映射較小的紋理。 CopyResource需要相同的尺寸。

一些資源:

DX11 Helper Library
Render To Texture

DX11 Post Processing blur

模糊的設置是一樣的,我說什麼,而不是隻使用一個模糊着色器你用一個簡單的紋理着色器。

+0

請你可以告訴我一些代碼嗎?我只需要創建一個新的紋理,然後我複製這個之前的?使用CopyResource? – DevAndroid

+0

我創建了第二個紋理,我把這個描述:但是複製映射失敗: D3D11_TEXTURE2D_DESC描述; \t \t \t texture2D-> GetDesc(&description); \t \t \t description.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; \t \t \t description.CPUAccessFlags = 0; \t \t \t description.Usage = D3D11_USAGE_DEFAULT; \t \t \t description.MiscFlags = 0; \t \t \t description.Width = 1280; \t \t \t description.Height = 720; \t \t \t hr = gDevice-> CreateTexture2D(&description,NULL,&gScaledTexture); – DevAndroid

+0

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476106(v=vs.85).aspx –