summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/threaded/ThreadedWindow.cpp
blob: bab324fffd25c3f57ff1f9d9f508ce268713c6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "UnityPrefix.h"
#include "Runtime/GfxDevice/threaded/ThreadedWindow.h"
#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h"
#include "Runtime/Graphics/RenderTexture.h"
#include "Runtime/Misc/QualitySettings.h"


#if UNITY_WIN && UNITY_EDITOR

int	ThreadedWindow::ms_CurrentFSAALevel = 0;

ThreadedWindow::ThreadedWindow(HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias )
:	GfxDeviceWindow(window, width, height, depthFormat, antiAlias)
{
	m_ClientWindow = new ClientDeviceWindow;
	m_FSAALevel = antiAlias;
	m_Reshaped = false;

	// Creating the actual window calls Reshape on the base class
	// Threaded window should be kept in the same state
	GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias);
}

ThreadedWindow::~ThreadedWindow()
{
	GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
	device.WindowDestroy(m_ClientWindow);
	m_ClientWindow = NULL;
}

bool ThreadedWindow::Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias )
{
	if(!GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias))
		return false;

	GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
	device.WindowReshape(m_ClientWindow, width, height, depthFormat, antiAlias);
	m_Reshaped = true;
	return true;
}

void ThreadedWindow::SetAsActiveWindow ()
{
	GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
	device.SetActiveWindow(m_ClientWindow);
	OnActivateWindow();
}

bool ThreadedWindow::BeginRendering()
{
	if (GfxDeviceWindow::BeginRendering())
	{
		GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
		device.BeginRendering(m_ClientWindow);
		OnActivateWindow();
		return true;
	}
	else
	{
		return false;
	}
}

bool ThreadedWindow::EndRendering( bool presentContent )
{
	if(GfxDeviceWindow::EndRendering(presentContent))
	{
		GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
		device.EndRendering(m_ClientWindow, presentContent);
		if (m_Reshaped)
		{
			GfxDeviceRenderer renderer = device.GetRenderer();
			// We need to complete rendering on WM_PAINT after window was resized
			// otherwise contents will look stretched in DirectX mode
			if (renderer == kGfxRendererD3D9 || renderer == kGfxRendererD3D11)
				device.FinishRendering();
			m_Reshaped = false;
		}
		return true;
	}
	else
	{
		return false;
	}
}

void ThreadedWindow::OnActivateWindow()
{
	GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice();
	device.SetActiveRenderTexture(NULL);
	device.SetCurrentWindowSize(m_Width, m_Height);
	device.SetInvertProjectionMatrix(false);
	ms_CurrentFSAALevel = m_FSAALevel;

}

#endif