Jump to content

  • Log In with Google      Sign In   
  • Create Account


BlackJoker

Member Since 28 Feb 2013
Offline Last Active Mar 02 2014 09:42 AM
-----

Topics I've Started

SwapChain resize questions

18 January 2014 - 10:57 AM

I have few questions regarding swapchain resizing:

 

First question:

I made resizing just like in MSDN article, but seems it works not fully correct.

After resizing back of my model begin to be visible from front. You can look this at screenshots

Attached File  before_res.png   429.61KB   0 downloads

Attached File  after_res.png   472.24KB   0 downloads

Attached File  result.png   266.16KB   0 downloads

 

first screenshot  - before resizing

second - after

third - how it displays in another angle.

 

Looks like stencil operation not working. Here is the code of my swapchain resizing:

void D3D11::ResizeSwapChain()
{
	if (swapChain)
	{
		DeinitializeD2D11();
		RECT rc;
		GetClientRect(hwnd, &rc);
		UINT width = rc.right - rc.left;
		UINT height = rc.bottom - rc.top;

		d3d11_DeviceContext->OMSetRenderTargets(0, 0, 0);

		// Release all outstanding references to the swap chain's buffers.
		d3d11_RenderTargetView->Release();

		HRESULT hr;
		// Preserve the existing buffer count and format.
		// Automatically choose the width and height to match the client rect for HWNDs.
		hr = swapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);


		// Perform error handling here!

		// Get buffer and create a render-target-view.
		ID3D11Texture2D* pBuffer;
		hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),
			(void**)&pBuffer);
		// Perform error handling here!

		hr = d3d11_Device->CreateRenderTargetView(pBuffer, NULL,
			&d3d11_RenderTargetView);
		// Perform error handling here!
		pBuffer->Release();

		d3d11_DeviceContext->OMSetRenderTargets(1, &d3d11_RenderTargetView, NULL);

		// Set up the viewport.
		D3D11_VIEWPORT viewPort;

		viewPort.Width = (float)width;
		viewPort.Height = (float)height;
		viewPort.MinDepth = 0.0f;
		viewPort.MaxDepth = 1.0f;
		viewPort.TopLeftX = 0.0f;
		viewPort.TopLeftY = 0.0f;
		d3d11_DeviceContext->RSSetViewports(1, &viewPort);

		InitializeD2D11();
	}
}

And second question:

 

if I created swapchain with 2 or more buffers, is this code correct in this case or I need do some changes to correctly resize all buffers?


Prevent WPF window redrawduring resizing

29 December 2013 - 03:33 PM

I have the following situation:

 

I use my WPF window in C++/CLI project of my game engine based on DirectX 11.

 

And my problem is when I resize a window, it always show a window background for a few milliseconds.

 I want to get rid of this behavior and don`t let window to redraw itself during resizing.

 

Does anyone faced such issue?

How I can do this in WPF window?

 

 

I tried to use SetClassLongPtr() for this puprose, but I dont know which parameters I should pass to make what i want.


D3D11 Rendering in other thread, window in Main thread

26 December 2013 - 04:53 PM

I have an issue I want to solve:

 

When I move/drag/resize a window, my message pump get stuck and window content is not updated (well known problem with DefWIndowProc). I want to create another thread and make rendering there, but I don`t know how to correctly do that, because if I start rendering loop in other thread, messages seems not to reach window or something like that.

 

Here is some code. I use C++/CLI mixed mode and WPF window:

 

This is main. Here I start my engine



[STAThreadAttribute]
int main()
{
	try
	{

		ManagedEngine^ managed = gcnew ManagedEngine();
		managed->InitializeSystem();
		ThreadStart^ threadDelegate = gcnew ThreadStart(managed, &ManagedEngine::StartEngine);
		Thread^ newThread = gcnew Thread(threadDelegate);
		newThread->Start();
		//managed->StartEngine();
		managed->Stop();

	}
	catch (Exception^ exception)
	{
		Console::WriteLine(exception->Message + exception->StackTrace + exception->TargetSite);
	}
}

In initializeSystem() I do initialization of D3D, Camera, DirectInput

 

Rendering thread is in method Run()



void Engine::Run()
{
	MSG msg;
	bool done, result;

	//////Инициализируем структуру MSG
	ZeroMemory(&msg, sizeof(MSG));

	//Создаём цикл, который будет работать до тех пор пока не получит
	//сообщение завершения работы от окна или от пользователя
	done = false;
	int counter = 0;
	while(!done)
	{
		Console::WriteLine("Зашёл в цикл рендеринга");
		//Обрабатываем сообщения Windows
		if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		
		//Если пришло сообщение закрыть приложение, тогда выходим
		if (msg.message == WM_QUIT)
		{
			done = true;
		}
		else
		{
			//Иначе обрабатываем кадр
			result = Frame();
			Console::WriteLine(counter);
			if (!result)
			{
				done = true;
			}
			counter++;
		}
	}
}

I did my engine structure almost exactly as in rastertek lessons if you see them.

 

So, As I understand the main my problem is that I have message pump run in another thread, but window is main thread, so messages cant be read. That lead window to get stuck in that time when rendering goes well.

 

Now I want to understand how to organize thread to leave message pump outside (in main thread), but listen this messages inside second thread.

Correct me if I'm wrong, please. I need your help!


Rendering freezing when drag/resize Window

26 December 2013 - 06:43 AM

I am using mixed mode C++/CLI in my game engine to create WPF window, in which DX is rendering.

 

Everything work fine except one thing - when I move or resize window, rendering freeze until mouse button will released.

I don`t know how to resolve this issue.

For now I even made a hook and attach WndProc to WPF window. I see that there are some messages in WndProc when I press mouse button and then everything hangs until mouse button will be released.

I thinks this is related with Win32 itself, but I don`t know how to hack this.

 

Does anyone now how to solve this issue and make DX always render even if I move or resize window?

 

By the wasy, In native WPF, when I resize or move window, there is no rendering issues like on attached image.

 

 

How did they do this? and how to do that in my engine???


How to make tile texture

22 December 2013 - 06:39 AM

Hello,

 

I want to make some textures to be tile instead of stretches on whole mesh.

 

Could you please answer how to implement such feature in DirectX 11?


PARTNERS