Beispiel #1
16
Texture2D::Texture2D( Device& _Device, ID3D11Texture2D& _Texture, const IPixelFormatDescriptor& _Format )
	: Component( _Device )
	, m_Format( _Format )
	, m_bIsDepthStencil( false )
	, m_bIsCubeMap( false )
	, m_pCachedDepthStencilView( NULL )
{
	D3D11_TEXTURE2D_DESC	Desc;
	_Texture.GetDesc( &Desc );

	m_Width = Desc.Width;
	m_Height = Desc.Height;
	m_ArraySize = Desc.ArraySize;
	m_MipLevelsCount = Desc.MipLevels;

	for ( int ShaderStageIndex=0; ShaderStageIndex < 6; ShaderStageIndex++ )
		m_LastAssignedSlots[ShaderStageIndex] = -1;
	m_LastAssignedSlotsUAV = -1;

	m_pTexture = &_Texture;
}
Beispiel #2
0
HRESULT CreateDirect3DContext(HWND wndHandle){
	// create a struct to hold information about the swap chain
	DXGI_SWAP_CHAIN_DESC scd;

	// clear out the struct for use
	ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

	// fill the swap chain description struct
	scd.BufferCount = 1;									// one back buffer
	scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;		// use 32-bit color
	scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;		// how swap chain is to be used
	scd.OutputWindow = wndHandle;							// the window to be used
	scd.SampleDesc.Count = 1;								// how many multisamples
	scd.Windowed = TRUE;									// windowed/full-screen mode

	// create a device, device context and swap chain using the information in the scd struct
	hr = D3D11CreateDeviceAndSwapChain(
		NULL,
		D3D_DRIVER_TYPE_HARDWARE,
		NULL,
		D3D11_CREATE_DEVICE_DEBUG,	//ny
		NULL,
		NULL,
		D3D11_SDK_VERSION,
		&scd,
		&gSwapChain,
		&gDevice,
		NULL,
		&gDeviceContext);

	if (SUCCEEDED(hr))
	{
		// get the address of the back buffer
		ID3D11Texture2D* pBackBuffer = nullptr;
		gSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

		// use the back buffer address to create the render target
		gDevice->CreateRenderTargetView(pBackBuffer, NULL, &gBackbufferRTV);
		pBackBuffer->Release();
	}
	return hr;
}
Beispiel #3
0
void App::Resize()
{
	if(!(devContext && swapChain && dev))
		return;
	// Release old render target
	if(renderTarget)
		renderTarget->Release();
	renderTarget = 0;

	swapChain->ResizeBuffers(1, winWidth, winHeight, DXGI_FORMAT_R16G16B16A16_FLOAT, 0);
	ID3D11Texture2D* bbuf;
	swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&bbuf));
	HR(dev->CreateRenderTargetView(bbuf, 0, &renderTarget));
	bbuf->Release();
	
	devContext->OMSetRenderTargets(1, &renderTarget, NULL);

	for(auto it=viewports.begin();it != viewports.end(); it++)
		it->SetVPSize(winWidth, winHeight);
}
HRESULT WINAPI DXGIPresent(IDXGISwapChain * sc, UINT b, UINT c) {

    DxgiFrameGrabber *dxgiFrameGrabber = DxgiFrameGrabber::getInstance();

    Logger *logger = dxgiFrameGrabber->m_logger;

    DXGI_SWAP_CHAIN_DESC desc;
    sc->GetDesc(&desc);
    logger->reportLogDebug(L"d3d10 Buffers count: %u, Output hwnd: %u, %s", desc.BufferCount, desc.OutputWindow, desc.Windowed ? "windowed" : "fullscreen");

    if (!desc.Windowed) {
        if (dxgiDevice == DxgiDeviceUnknown || dxgiDevice == DxgiDeviceD3D10 ) {

            ID3D10Texture2D *pBackBuffer;
            HRESULT hr = sc->GetBuffer(0, IID_ID3D10Texture2D, reinterpret_cast<LPVOID*> (&pBackBuffer));

            if (hr == S_OK) {
                if (dxgiDevice == DxgiDeviceUnknown) dxgiDevice = DxgiDeviceD3D10;
                D3D10Grab(pBackBuffer);
                pBackBuffer->Release();
            } else {
                if (dxgiDevice != DxgiDeviceUnknown)
                    logger->reportLogError(L"couldn't get d3d10 buffer. returned 0x%x", hr);
            }
        }
        if (dxgiDevice == DxgiDeviceUnknown || dxgiDevice == DxgiDeviceD3D11 ) {
            ID3D11Texture2D *pBackBuffer;
            HRESULT hr = sc->GetBuffer(0, IID_ID3D11Texture2D, reinterpret_cast<LPVOID*> (&pBackBuffer));
            if(hr == S_OK) {
                if (dxgiDevice == DxgiDeviceUnknown) dxgiDevice = DxgiDeviceD3D11;
                D3D11Grab(pBackBuffer);
                pBackBuffer->Release();
            } else {
                logger->reportLogError(L"couldn't get d3d11 buffer. returned 0x%x", hr);
            }
        }
    }

    DXGISCPresentFunc originalFunc = reinterpret_cast<DXGISCPresentFunc>(dxgiFrameGrabber->m_dxgiPresentProxyFuncVFTable->getOriginalFunc());
    return originalFunc(sc,b,c);
}
void RenderSystem::v_Init()
{
	HRESULT hr;

	/////////////////////////Create buffer desc///////////////////////
	DXGI_MODE_DESC bufferDesc;
	ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
	bufferDesc.Width                   = m_ScreenWidth;
	bufferDesc.Height                  = m_ScreenHeight;
	bufferDesc.RefreshRate.Numerator   = 60;
	bufferDesc.RefreshRate.Denominator = 1;
	bufferDesc.Format                  = DXGI_FORMAT_R8G8B8A8_UNORM;
	bufferDesc.ScanlineOrdering        = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	bufferDesc.Scaling                 = DXGI_MODE_SCALING_UNSPECIFIED;

	//////////////////Create swapChain Desc////////////////////////////
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
	swapChainDesc.BufferDesc         = bufferDesc;
	swapChainDesc.SampleDesc.Count   = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage        = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount        = 1;
	swapChainDesc.OutputWindow       = GetHwnd();
	swapChainDesc.Windowed           = TRUE;
	swapChainDesc.SwapEffect         = DXGI_SWAP_EFFECT_DISCARD;

	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE,
		NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, 
		&swapChainDesc, &m_pSwapChain, &m_pD3D11Device,
		NULL, &m_pD3D11DeviceContext);

	//Create the rendertargetView, which buffer is a texture
	ID3D11Texture2D *pBackBuffer;
	hr = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer);
	hr = m_pD3D11Device->CreateRenderTargetView(pBackBuffer, NULL, &m_pRenderTargetView);
	//DebugHR(hr);
	pBackBuffer->Release();


}
Beispiel #6
0
void Resize(int height, int width)
{
	if (g_pSwapChain)
	{
		g_pImmediateContext->OMSetRenderTargets(0, 0, 0);

		// Освобождаем задний буффер
		g_pRenderTargetView->Release();

		HRESULT hr;
		// Меняем размер буффера
		// Ширина и высота выбираются автоматически из HWND
		hr = g_pSwapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

		// Создаём задний буффер
		ID3D11Texture2D* pBuffer;
		hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),
			(void**)&pBuffer);

		hr = g_pd3dDevice->CreateRenderTargetView(pBuffer, NULL,
			&g_pRenderTargetView);
		pBuffer->Release();

		g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, NULL);

		g_width = width;           // получаем ширину
		g_height = height;   // и высоту окна

		// Настройка вьюпорта
		D3D11_VIEWPORT vp;
		vp.Width = g_width;
		vp.Height = g_height;
		vp.MinDepth = .0f;
		vp.MaxDepth = 1.0f;
		vp.TopLeftX = 0;
		vp.TopLeftY = 0;
		g_pImmediateContext->RSSetViewports(1, &vp);

		InitGUIBuffers();
	}
}
void Window::Resize()
{
	HRESULT result;

	RECT clientRect;
	GetClientRect(_handle, &clientRect);

	if (_swapChain)
		_swapChain->Release();
	if (_depthStencilView)
		_depthStencilView->Release();
	if (_renderTargetView)
		_renderTargetView->Release();

	//Swap chain

	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	swapChainDesc = Utils::CreateSwapChainDescription(clientRect.right, clientRect.bottom, _handle);
	result = Utils::CreateSwapChain(_d3dDevice, &swapChainDesc, &_swapChain);

	//Render target view

	ID3D11Texture2D* backBuffer;
	_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer));
	_d3dDevice->CreateRenderTargetView(backBuffer, NULL, &_renderTargetView);
	backBuffer->Release();

	//Depth stencil

	D3D11_TEXTURE2D_DESC depthStencilDesc;
	depthStencilDesc = Utils::CreateDepthStencilDescription(clientRect.right, clientRect.bottom);
	result = Utils::CreateDepthStencilView(_d3dDevice, &depthStencilDesc, &_depthStencilView);

	//Set depth and stencil views

	_d3dDeviceContext->OMSetRenderTargets(1, &_renderTargetView, _depthStencilView);

	//Set viewport

	Utils::SetViewport(_d3dDeviceContext, (float)clientRect.right, (float)clientRect.bottom);
}
void DxSprite::BeginBatch(ID3D11ShaderResourceView * texSRV)
{
    assert( Initialized );

    BatchTexSRV = texSRV;
    BatchTexSRV->AddRef( );

    ID3D11Resource * resource = 0;
    BatchTexSRV->GetResource(&resource);
    ID3D11Texture2D * tex = reinterpret_cast<ID3D11Texture2D*>(resource);

    D3D11_TEXTURE2D_DESC texDesc;
    tex->GetDesc(&texDesc);

    SAFE_RELEASE(resource)

    TexWidth  = texDesc.Width; 
    TexHeight = texDesc.Height;

    SpriteList.clear( );
}
void MT_Texture::Clean()
{
	for (int i = m_textures.size() - 1; i >= 0; i--)
	{
		ID3D11Texture2D* texture = m_textures[i];
		m_textures.pop_back();
		texture->Release();
		texture = 0;
	}

	for (int i = m_shaderResourceViews.size() - 1; i >= 0; i--)
	{
		ID3D11ShaderResourceView* shaderResourceView = m_shaderResourceViews[i];
		m_shaderResourceViews.pop_back();
		shaderResourceView->Release();
		shaderResourceView = 0;
	}

	if (m_samplerState) m_samplerState->Release();
	m_samplerState = 0;
}
Beispiel #10
0
HRESULT Device3D::CreateTargetView()
{
	HRESULT hr = S_OK;

	// Create a render target view
	ID3D11Texture2D* pBackBuffer;
	hr = mSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID*)&pBackBuffer );
	if( FAILED(hr) )
		return hr;

	// create shader unordered access view on back buffer for compute shader to write into texture
	hr = mDevice->CreateUnorderedAccessView( pBackBuffer, NULL, &mBackbufferUAV );

	SAFE_RELEASE(mRenderTargetView);
	hr = mDevice->CreateRenderTargetView( pBackBuffer, NULL, &mRenderTargetView );
	pBackBuffer->Release();
	if( FAILED(hr) )
		return hr;

	return hr;
}
void D3D11CanvasWindowGraphics::CreateSwapChainResources()
{
	ID3D11Device* pDevice = m_driver->GetD3D11Device();

	// Get back buffer RTV

	ID3D11Texture2D* texture = NULL;
	CHECK_HR(m_swapChain->GetBuffer(0, IID_PPV_ARGS(&texture)));

	D3D11_TEXTURE2D_DESC t2dd;
	texture->GetDesc(&t2dd);

	CHECK_HR(pDevice->CreateRenderTargetView(texture, NULL, m_backBufferRTV.Receive()));

	SafeRelease(texture);

	// Create Direct2D render target

	m_d2dTarget = D2DTarget::Create(m_driver->GetD2DFactory(),
		pDevice, m_driver->GetD3D10Device(), t2dd.Width, t2dd.Height);
}
Beispiel #12
0
bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int level)
{
	// TODO: Somehow implement this (D3DX11 doesn't support dumping individual LODs)
	static bool warn_once = true;
	if (level && warn_once)
	{
		WARN_LOG(VIDEO, "Dumping individual LOD not supported by D3D11 backend!");
		warn_once = false;
		return false;
	}

	ID3D11Texture2D* pNewTexture = nullptr;
	ID3D11Texture2D* pSurface = texture->GetTex();
	D3D11_TEXTURE2D_DESC desc;
	pSurface->GetDesc(&desc);

	desc.BindFlags = 0;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
	desc.Usage = D3D11_USAGE_STAGING;

	HRESULT hr = D3D::device->CreateTexture2D(&desc, nullptr, &pNewTexture);

	bool saved_png = false;

	if (SUCCEEDED(hr) && pNewTexture)
	{
		D3D::context->CopyResource(pNewTexture, pSurface);

		D3D11_MAPPED_SUBRESOURCE map;
		hr = D3D::context->Map(pNewTexture, 0, D3D11_MAP_READ_WRITE, 0, &map);
		if (SUCCEEDED(hr))
		{
			saved_png = TextureToPng((u8*)map.pData, map.RowPitch, filename, desc.Width, desc.Height);
			D3D::context->Unmap(pNewTexture, 0);
		}
		SAFE_RELEASE(pNewTexture);
	}

	return saved_png;
}
void DX11SpriteBatch::BeginBatch(ID3D11ShaderResourceView* texSRV)
{
	RJE_ASSERT(mInitialized);

	mBatchTexSRV = texSRV;
	mBatchTexSRV->AddRef();

	// Get the size of the texture
	ID3D11Resource* resource = nullptr;
	mBatchTexSRV->GetResource(&resource);
	ID3D11Texture2D* tex = reinterpret_cast<ID3D11Texture2D*>(resource);

	D3D11_TEXTURE2D_DESC texDesc;
	tex->GetDesc(&texDesc);

	RJE_SAFE_RELEASE(resource);

	mTexWidth  = texDesc.Width; 
	mTexHeight = texDesc.Height;

	mSpriteList.clear();
}
Beispiel #14
0
void D3DBase::resetViewport(float width, float height)
{
	if (m_swapChain)
	{
		m_deviceContext->OMSetRenderTargets(0, 0, 0);        
        m_renderTargetView.ReleaseAndGetAddressOf();
		
		HRESULT hr = m_swapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);

		// Add error handling

		// Get buffer and create a render target view
		ID3D11Texture2D* pBuffer;
		hr = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**) &pBuffer);

		hr = m_device->CreateRenderTargetView(pBuffer, NULL, m_renderTargetView.ReleaseAndGetAddressOf());

		pBuffer->Release();

        m_deviceContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), NULL);
        // setBackBufferRenderTarget();
		
		// Setup projection matrix
		float fov = (float) D3DX_PI / 4.0f;
		float aspectRatio = width / height;
		D3DXMatrixPerspectiveFovLH(&m_projectionMatrix, fov, aspectRatio, 1.0f, 1000.0f);
		
		// Setup the viewport
		D3D11_VIEWPORT viewport;
		viewport.Width = width;
		viewport.Height = height;
		viewport.MinDepth = 0.0f;
		viewport.MaxDepth = 1.0f;
		viewport.TopLeftX = 0;
		viewport.TopLeftY = 0;

		m_deviceContext->RSSetViewports(1, &viewport);
	}	
}
Beispiel #15
0
void RenderSystem::createFrameBuffer()
{
  releaseFrameBuffer();

  ID3D11Texture2D* backBuffer;
  if (SUCCEEDED(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&backBuffer)))
  {
    VALIDATE(m_device->CreateRenderTargetView(backBuffer, NULL, &m_backBufferRTV));
    backBuffer->Release();
  }

  DXGI_SWAP_CHAIN_DESC sd;
  m_swapChain->GetDesc(&sd);

  D3D11_TEXTURE2D_DESC desc;
  ::ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
  desc.ArraySize = 1;
  desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
  desc.Format = DXGI_FORMAT_R24G8_TYPELESS;
  desc.Width = sd.BufferDesc.Width;
  desc.Height = sd.BufferDesc.Height;
  desc.MipLevels = sd.SampleDesc.Count > 0 ? 1 : 0;
  desc.SampleDesc = sd.SampleDesc;
  desc.Usage = D3D11_USAGE_DEFAULT;

  if (SUCCEEDED(m_device->CreateTexture2D(&desc, NULL, &m_depthBuffer)))
  {
    D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
    ::ZeroMemory(&descDSV, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
    descDSV.ViewDimension = sd.SampleDesc.Count > 0 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;
    descDSV.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;

    VALIDATE(m_device->CreateDepthStencilView(m_depthBuffer, &descDSV, &m_backBufferDSV));
  }

  m_stateCache->setRenderTargets(1, &m_backBufferRTV, m_backBufferDSV);

  setViewport((float)sd.BufferDesc.Width, (float)sd.BufferDesc.Height);
}
Beispiel #16
0
// Gets or lazily creates the default texture
ID3D11ShaderResourceView* EffectDeviceResources::GetDefaultTexture()
{
	return DemandCreate(mDefaultTexture, mMutex, [&](ID3D11ShaderResourceView** pResult) -> HRESULT
	{
		static const uint32_t s_pixel = 0xffffffff;

		D3D11_SUBRESOURCE_DATA initData = { &s_pixel, sizeof(uint32_t), 0 };

		D3D11_TEXTURE2D_DESC desc;
		memset(&desc, 0, sizeof(desc));
		desc.Width = desc.Height = desc.MipLevels = desc.ArraySize = 1;
		desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		desc.SampleDesc.Count = 1;
		desc.Usage = D3D11_USAGE_IMMUTABLE;
		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

		ID3D11Texture2D* tex = nullptr;
		HRESULT hr = mDevice->CreateTexture2D(&desc, &initData, &tex);

		if (SUCCEEDED(hr))
		{
			SetDebugObjectName(tex, "DirectXTK:Effect");

			D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
			memset(&SRVDesc, 0, sizeof(SRVDesc));
			SRVDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
			SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
			SRVDesc.Texture2D.MipLevels = 1;

			hr = mDevice->CreateShaderResourceView(tex, &SRVDesc, pResult);
			if (SUCCEEDED(hr))
				SetDebugObjectName(*pResult, "DirectXTK:Effect");

			tex->Release();
		}

		return hr;
	});
}
void idRenderTexture::CreateFromImages( idImage *colorImage, idImage *depthStencilImage ) {
	ID3D11Texture2D* albedoImage;
	HRESULT hr;
	if(colorImage == NULL) {
		// Create a render target view
		hr = render.GetSwapChain()->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&albedoImage );
		if( FAILED( hr ) ) {
			Sys_Error("CreateFromImages: Failed to get backbuffer\n");
		}
	}
	else {
		albedoImage = colorImage->GetTextureHandle();
	}

	hr = render.GetDevice()->CreateRenderTargetView( albedoImage, NULL, &pRenderTargetView );
	if( FAILED( hr ) ) {
		Sys_Error("CreateFromImages: Failed to create render target view\n");
	}

	if(colorImage == NULL) {
		albedoImage->Release();
	}

	if(depthStencilImage != NULL)
	{
		D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
		ZeroMemory( &descDSV, sizeof(descDSV) );
		descDSV.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
		descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
		descDSV.Texture2D.MipSlice = 0;
		hr = render.GetDevice()->CreateDepthStencilView( depthStencilImage->GetTextureHandle(), &descDSV, &pDepthStencilView );
		if( FAILED( hr ) )
			Sys_Error("Failed to create depth image");
	}
	else {
		pDepthStencilView = NULL;
	}
}
Beispiel #18
0
Bitmap::Bitmap(ID3D11Device* device, WCHAR* textureFilename, std::string name) : RenderObject(name)
{
	m_vertexBuffer = 0;
	m_indexBuffer = 0;
	m_Texture = 0;

	bool result;

	m_previousPosX = -1;
	m_previousPosY = -1;

	result = InitializeBuffers(device);
	if(!result)
	{
		throw std::exception("Could not initialize Bitmap Buffers");
	}

	result = LoadTexture(device, textureFilename);
	if(!result)
	{
		std::stringstream ss;
		ss << "Could not Load Bitmap Texture: " << textureFilename;
		throw std::exception(ss.str().c_str());
	}
	
	ID3D11Texture2D* res;

	m_Texture->GetTexture()->GetResource((ID3D11Resource**)&res);

	D3D11_TEXTURE2D_DESC desc;

	res->GetDesc(&desc);

	m_bitmapWidth = desc.Width;
	m_bitmapHeight = desc.Height;

	shared = false;
}
// テクスチャロード
int LoadTexture( TCHAR *szFileName, TEX_PICTURE *pTexPic )
{
    HRESULT						hr;
	D3DX11_IMAGE_INFO			ImageInfo;
	D3DX11_IMAGE_LOAD_INFO		liLoadInfo;
	ID3D11Texture2D				*pTexture;
	int							nTexWidth, nTexHeight;

	// 画像情報取得
	hr = D3DX11GetImageInfoFromFile( szFileName, NULL, &ImageInfo, NULL );
    if ( FAILED( hr ) ) {
        return hr;
    }
	nTexWidth  = ( int )pow( 2.0, floor( log( ( double )ImageInfo.Width )  / log( 2.0 ) + 1.01 ) );
	if ( ( nTexWidth  / 2 ) == ImageInfo.Width  ) nTexWidth  /= 2;
	nTexHeight = ( int )pow( 2.0, floor( log( ( double )ImageInfo.Height ) / log( 2.0 ) + 1.01 ) );
	if ( ( nTexHeight / 2 ) == ImageInfo.Height ) nTexHeight /= 2;

	// ロード
	ZeroMemory( &liLoadInfo, sizeof( D3DX11_IMAGE_LOAD_INFO ) );
	liLoadInfo.Width = nTexWidth;
	liLoadInfo.Height = nTexHeight;
	liLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	liLoadInfo.Format = ImageInfo.Format;

	hr = D3DX11CreateShaderResourceViewFromFile( g_pd3dDevice, szFileName, &liLoadInfo, NULL, &( pTexPic->pSRViewTexture ), NULL );
    if ( FAILED( hr ) ) {
        return hr;
    }
	pTexPic->pSRViewTexture->GetResource( ( ID3D11Resource ** )&( pTexture ) );
	pTexture->GetDesc( &( pTexPic->tdDesc ) );
	pTexture->Release();

	pTexPic->nWidth = ImageInfo.Width;
	pTexPic->nHeight = ImageInfo.Height;

	return S_OK;
}
Beispiel #20
0
ID3D11Texture2D* DesktopDuplication::acquireNextFrame(DXGI_OUTDUPL_FRAME_INFO& frameInfoOut)
{
	IDXGIResource* frameResource;
	hr = outputDuplication->AcquireNextFrame(acquireTimeout, &frameInfoOut, &frameResource);

	if (hr != S_OK)
	{
		reinitialize(); // Second chance to recover adapter failure.
		std::cout << "Next frame acquisition failed: " << hr << ". Reinitializing DXGI subsystems..." << std::endl;
		CHECKED(hr, outputDuplication->AcquireNextFrame(acquireTimeout, &frameInfoOut, &frameResource));
	}

	ID3D11Texture2D* frameTex;
	CHECKED(hr, frameResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(&frameTex)));
	frameResource->Release();

	ID3D11Texture2D* frameStagingTex = copyToStaging(frameTex);
	frameTex->Release();

	CHECKED(hr, outputDuplication->ReleaseFrame());

	return frameStagingTex;
}
Beispiel #21
0
	ID3D11RenderTargetView * DX11::CreateRenderTarget (IDXGISwapChain1 * chain)
	{
		ID3D11RenderTargetView * view = nullptr;

		ID3D11Texture2D * pBackBuffer;
		D3D11_RENDER_TARGET_VIEW_DESC render_target_view_desc = {};
		render_target_view_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		render_target_view_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
		chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
		HRESULT hr = m_pd3dDevice->CreateRenderTargetView(pBackBuffer, &render_target_view_desc, &view);
		if (!SUCCEEDED(hr))
		{
			Assert(view);
			TRACE_MSG(LL_ERROR, CTX_BB | CTX_GFX | CTX_INIT, "DX11 device CreateRenderTargetView failed, hresult=0x%x", hr);
			pBackBuffer->Release();
			return nullptr;
		}

		m_pd3dDeviceContext->OMSetRenderTargets(1, &view, NULL);
		pBackBuffer->Release();
		TRACE_MSG(LL_VERBOSE, CTX_BB | CTX_GFX | CTX_INIT, "Created render target @ 0x%x for chain @ 0x%x", view, chain);
		return view;
	}
Beispiel #22
0
void RenderTarget::CreateViewport(ID3D11Texture2D& texture, D3D11_VIEWPORT* viewport) {
    // Set the viewport
    D3D11_TEXTURE2D_DESC textureDesc;
    texture.GetDesc(&textureDesc);
    ZeroMemory(viewport, sizeof(D3D11_VIEWPORT));

    viewport->TopLeftX = 0;
    viewport->TopLeftY = 0;
    viewport->Width = float(textureDesc.Width);
    viewport->Height = float(textureDesc.Height);
    // TODO: make sure these are the same as the values for the zbuffer
    viewport->MinDepth = 0.0f;
    viewport->MaxDepth = 1.0f;
}
Beispiel #23
0
// Default creation routine for making the back/stencil buffers
//-----------------------------------------------------------------------------
CPUTResult CPUT_DX11::CreateContext()
{
    HRESULT hr;
    CPUTResult result;
    RECT rc;
    HWND hWnd = mpWindow->GetHWnd();

    GetClientRect( hWnd, &rc );
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;

    // Create a render target view
    ID3D11Texture2D *pBackBuffer = NULL;
    hr = mpSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
    ASSERT( SUCCEEDED(hr), _L("Failed getting back buffer.") );

    hr = mpD3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &mpBackBufferRTV );
    pBackBuffer->Release();
    ASSERT( SUCCEEDED(hr), _L("Failed creating render target view.") );
    CPUTSetDebugName( mpBackBufferRTV, _L("BackBufferView") );

    // create depth/stencil buffer
    result = CreateAndBindDepthBuffer(width, height);
    ASSERT( SUCCEEDED(hr), _L("Failed creating and binding depth buffer.") );

    // Setup the viewport
    D3D11_VIEWPORT vp;
    vp.Width = (FLOAT)width;
    vp.Height = (FLOAT)height;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    mpContext->RSSetViewports( 1, &vp );

    return CPUT_SUCCESS;
}
Beispiel #24
0
    bool Init(ovrSession session, int sizeW, int sizeH)
    {
        Session = session;

        ovrTextureSwapChainDesc desc = {};
        desc.Type = ovrTexture_2D;
        desc.ArraySize = 1;
        desc.Format = OVR_FORMAT_R8G8B8A8_UNORM_SRGB;
        desc.Width = sizeW;
        desc.Height = sizeH;
        desc.MipLevels = 1;
        desc.SampleCount = 1;
        desc.MiscFlags = ovrTextureMisc_DX_Typeless;
        desc.StaticImage = ovrFalse;
        desc.BindFlags = ovrTextureBind_DX_RenderTarget;

        ovrResult result = ovr_CreateTextureSwapChainDX(session, DIRECTX.Device, &desc, &TextureChain);
        if (!OVR_SUCCESS(result))
            return false;

        int textureCount = 0;
        ovr_GetTextureSwapChainLength(Session, TextureChain, &textureCount);
        VALIDATE(textureCount == TextureCount, "TextureCount mismatch.");

        for (int i = 0; i < TextureCount; ++i)
        {
            ID3D11Texture2D* tex = nullptr;
            ovr_GetTextureSwapChainBufferDX(Session, TextureChain, i, IID_PPV_ARGS(&tex));
            D3D11_RENDER_TARGET_VIEW_DESC rtvd = {};
            rtvd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
            rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
            DIRECTX.Device->CreateRenderTargetView(tex, &rtvd, &TexRtv[i]);
            tex->Release();
        }

        return true;
    }
Beispiel #25
0
bool D3DRenderer::CreateRenderTargetView()
{
	HRESULT result;
	ID3D11Texture2D* backBufferPtr;

	//Attach the back buffer to the swap chain
	result = this->m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
	if (FAILED(result))
	{
		return false;
	}

	//Create the target view
	result = this->m_device->CreateRenderTargetView(backBufferPtr, NULL, &this->m_renderTargetView);
	if (FAILED(result))
	{
		return false;
	}

	backBufferPtr->Release();
	backBufferPtr = 0;

	return true;
}
void DxTexture::InitialiseCubeMap(ID3D11Device* device)
{
    const std::string filePath = m_texture.Path() + ".dds";
    if (!boost::filesystem::exists(filePath))
    {
        Logger::LogError("DirectX: " + filePath + " doesn't exist");
    }

    D3DX11_IMAGE_LOAD_INFO loadInfo;
    loadInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;

    ID3D11Texture2D* texture = nullptr;
    SetDebugName(texture, filePath + "_texture");

    if (FAILED(D3DX11CreateTextureFromFile(device, filePath.c_str(),
                                           &loadInfo, 0, (ID3D11Resource**)&texture, 0)))
    {
        Logger::LogError("DirectX: Failed to create texture " + filePath);
    }

    D3D11_TEXTURE2D_DESC textureDesc;
    texture->GetDesc(&textureDesc);

    D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc;
    viewDesc.Format = textureDesc.Format;
    viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
    viewDesc.TextureCube.MipLevels = textureDesc.MipLevels;
    viewDesc.TextureCube.MostDetailedMip = 0;

    if (FAILED(device->CreateShaderResourceView(texture, &viewDesc, &m_view)))
    {
        Logger::LogError("DirectX: Failed to resource view " + filePath);
    }

    texture->Release();
}
    void CCoherentViewListener::CreateShaderResourceViewForDX11Texture()
    {
        if ( gEnv->pRenderer->GetRenderType() != eRT_DX11 || m_pTexture == NULL )
        {
            return;
        }

        ID3D11Texture2D* pTexture = static_cast<ID3D11Texture2D*>( m_pTexture );

        ID3D11Device* pDevice = static_cast<ID3D11Device*>( gD3DDevice );
        ID3D11DeviceContext* pContext = NULL;
        pDevice->GetImmediateContext( &pContext );

        D3D11_TEXTURE2D_DESC texDesc;
        pTexture->GetDesc( &texDesc );

        D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
        srvDesc.Format = texDesc.Format;
        srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
        srvDesc.Texture2D.MipLevels = texDesc.MipLevels;
        srvDesc.Texture2D.MostDetailedMip = 0;

        pDevice->CreateShaderResourceView( pTexture, &srvDesc, &m_pTextureSRV );
    }
ModelDefinition *ModelFactory::create2D_Model(ID3D11ShaderResourceView *p_Texture)
{
	ModelDefinition *model = new ModelDefinition();
	ID3D11Resource *resource;
	ID3D11Texture2D *texture;
	D3D11_TEXTURE2D_DESC textureDesc;

	p_Texture->GetResource(&resource);
	resource->QueryInterface(&texture);
	texture->GetDesc(&textureDesc);
	Vector2 halfSize(textureDesc.Width * 0.5f, textureDesc.Height * 0.5f);
	SAFE_RELEASE(texture);
	SAFE_RELEASE(resource);
	create2D_VertexBuffer(model, halfSize);

	model->diffuseTexture.push_back(make_pair(std::string("Text"), p_Texture));
	model->materialSets.resize(1);
	model->materialSets[0].first = "default";
	model->materialSets[0].second.push_back(ModelDefinition::Material(0, 6, 0));
	model->is2D = true;
	model->isAnimated = false;

	return model;
}
void myD3D11DeviceContext::readTexture(ID3D11Texture2D *inputTexture, Bitmap &result)
{
    ID3D11Texture2D *captureTexture;

    D3D11_TEXTURE2D_DESC renderDesc;
    inputTexture->GetDesc(&renderDesc);

    renderDesc.MipLevels = 1;
    renderDesc.ArraySize = 1;
    renderDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    renderDesc.SampleDesc.Count = 1;
    renderDesc.SampleDesc.Quality = 0;
    renderDesc.BindFlags = 0;
    renderDesc.MiscFlags = 0;
    renderDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
    renderDesc.Usage = D3D11_USAGE_STAGING;
    assets->device->base->CreateTexture2D(&renderDesc, nullptr, &captureTexture);

    assets->context->base->CopyResource(captureTexture, inputTexture);

    result.allocate(renderDesc.Width, renderDesc.Height);

    D3D11_MAPPED_SUBRESOURCE resource;
    UINT subresource = D3D11CalcSubresource(0, 0, 0);
    HRESULT hr = assets->context->base->Map(captureTexture, subresource, D3D11_MAP_READ, 0, &resource);
    const BYTE *data = (BYTE *)resource.pData;

    for (UINT y = 0; y < renderDesc.Height; y++)
    {
        memcpy(&result(0U, y), data + resource.RowPitch * y, renderDesc.Width * sizeof(ml::vec4uc));
    }

    assets->context->base->Unmap(captureTexture, subresource);

    captureTexture->Release();
}
Beispiel #30
0
	void SetTarget(ID3D11Texture2D* pTarget)
	{
		if (pTarget == this->pTarget)
		{
			return;
		}
		else
		{
			this->pTarget = pTarget;
		}

		D3D11_TEXTURE2D_DESC texDesc;
		pTarget->GetDesc(&texDesc);
		
		sizeX = texDesc.Width; sizeY = texDesc.Height;

		pRenderTargetView = nullptr;
		D3D11_RENDER_TARGET_VIEW_DESC desc;
		ZeroMemory(&desc, sizeof(desc));
		desc.Format = texDesc.Format;
		desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
		desc.Texture2D.MipSlice = 1;
		HRESULT hr = pDevice->CreateRenderTargetView(pTarget,&desc , &pRenderTargetView);
		if (FAILED(hr))
		{
			throw std::exception("CreateRenderTargetView failed.");
		}

		ID3D11RenderTargetView* targets[] = 
		{
			pRenderTargetView
		};
		GetImmediateContext()->OMSetRenderTargets(1,targets, nullptr);

		D3D11_VIEWPORT vps[] = {
			{ 0,0,texDesc.Width,texDesc.Height,0,1 }
		};		
		GetImmediateContext()->RSSetViewports(1, vps);

		float const clearColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
		GetImmediateContext()->ClearRenderTargetView(pRenderTargetView, clearColor);
	}