libobs/graphics: Add NV12 texture support

This commit is contained in:
jp9000
2019-02-07 17:00:46 -08:00
parent b64d7d71d0
commit 93fc61fa82
8 changed files with 237 additions and 8 deletions
+37 -4
View File
@@ -80,7 +80,7 @@ void gs_texture_2d::InitTexture(const uint8_t **data)
td.Height = height;
td.MipLevels = genMipmaps ? 0 : levels;
td.ArraySize = type == GS_TEXTURE_CUBE ? 6 : 1;
td.Format = dxgiFormat;
td.Format = nv12 ? DXGI_FORMAT_NV12 : dxgiFormat;
td.BindFlags = D3D11_BIND_SHADER_RESOURCE;
td.SampleDesc.Count = 1;
td.CPUAccessFlags = isDynamic ? D3D11_CPU_ACCESS_WRITE : 0;
@@ -182,7 +182,12 @@ void gs_texture_2d::InitRenderTargets()
{
HRESULT hr;
if (type == GS_TEXTURE_2D) {
hr = device->device->CreateRenderTargetView(texture, NULL,
D3D11_RENDER_TARGET_VIEW_DESC rtv;
rtv.Format = dxgiFormat;
rtv.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
rtv.Texture2D.MipSlice = 0;
hr = device->device->CreateRenderTargetView(texture, &rtv,
renderTarget[0].Assign());
if (FAILED(hr))
throw HRError("Failed to create render target view",
@@ -210,7 +215,7 @@ void gs_texture_2d::InitRenderTargets()
gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t width,
uint32_t height, gs_color_format colorFormat, uint32_t levels,
const uint8_t **data, uint32_t flags_, gs_texture_type type,
bool gdiCompatible)
bool gdiCompatible, bool nv12_)
: gs_texture (device, gs_type::gs_texture_2d, type, levels,
colorFormat),
width (width),
@@ -222,7 +227,8 @@ gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t width,
isDynamic ((flags_ & GS_DYNAMIC) != 0),
isShared ((flags_ & SHARED_FLAGS) != 0),
genMipmaps ((flags_ & GS_BUILD_MIPMAPS) != 0),
sharedHandle (GS_INVALID_HANDLE)
sharedHandle (GS_INVALID_HANDLE),
nv12 (nv12_)
{
InitTexture(data);
InitResourceView();
@@ -231,6 +237,33 @@ gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t width,
InitRenderTargets();
}
gs_texture_2d::gs_texture_2d(gs_device_t *device, ID3D11Texture2D *nv12tex,
uint32_t flags_)
: gs_texture (device, gs_type::gs_texture_2d, GS_TEXTURE_2D),
isRenderTarget ((flags_ & GS_RENDER_TARGET) != 0),
isDynamic ((flags_ & GS_DYNAMIC) != 0),
isShared ((flags_ & SHARED_FLAGS) != 0),
genMipmaps ((flags_ & GS_BUILD_MIPMAPS) != 0),
nv12 (true)
{
texture = nv12tex;
texture->GetDesc(&td);
this->type = GS_TEXTURE_2D;
this->format = GS_R8G8;
this->flags = flags_;
this->levels = 1;
this->device = device;
this->chroma = true;
this->width = td.Width / 2;
this->height = td.Height / 2;
this->dxgiFormat = DXGI_FORMAT_R8G8_UNORM;
InitResourceView();
if (isRenderTarget)
InitRenderTargets();
}
gs_texture_2d::gs_texture_2d(gs_device_t *device, uint32_t handle)
: gs_texture (device, gs_type::gs_texture_2d,
GS_TEXTURE_2D),