mirror of
https://github.com/yawut/SDL.git
synced 2026-04-23 17:17:41 -05:00
WinRT: converted tabs to spaces in src/video/windowsrt/*
This commit is contained in:
parent
1fae2ee829
commit
c0cc3cec3f
|
|
@ -6,31 +6,31 @@
|
|||
|
||||
namespace DX
|
||||
{
|
||||
inline void ThrowIfFailed(HRESULT hr)
|
||||
{
|
||||
if (FAILED(hr))
|
||||
{
|
||||
// Set a breakpoint on this line to catch Win32 API errors.
|
||||
throw Platform::Exception::CreateException(hr);
|
||||
}
|
||||
}
|
||||
inline void ThrowIfFailed(HRESULT hr)
|
||||
{
|
||||
if (FAILED(hr))
|
||||
{
|
||||
// Set a breakpoint on this line to catch Win32 API errors.
|
||||
throw Platform::Exception::CreateException(hr);
|
||||
}
|
||||
}
|
||||
|
||||
// Function that reads from a binary file asynchronously.
|
||||
inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
|
||||
{
|
||||
using namespace Windows::Storage;
|
||||
using namespace Concurrency;
|
||||
|
||||
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
|
||||
|
||||
return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file)
|
||||
{
|
||||
return FileIO::ReadBufferAsync(file);
|
||||
}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^
|
||||
{
|
||||
auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
|
||||
Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
|
||||
return fileData;
|
||||
});
|
||||
}
|
||||
// Function that reads from a binary file asynchronously.
|
||||
inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
|
||||
{
|
||||
using namespace Windows::Storage;
|
||||
using namespace Concurrency;
|
||||
|
||||
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
|
||||
|
||||
return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file)
|
||||
{
|
||||
return FileIO::ReadBufferAsync(file);
|
||||
}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^
|
||||
{
|
||||
auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
|
||||
Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
|
||||
return fileData;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ using namespace Windows::Graphics::Display;
|
|||
using namespace concurrency;
|
||||
|
||||
SDL_WinRTApp::SDL_WinRTApp() :
|
||||
m_windowClosed(false),
|
||||
m_windowVisible(true),
|
||||
m_windowClosed(false),
|
||||
m_windowVisible(true),
|
||||
m_sdlWindowData(NULL),
|
||||
m_useRelativeMouseMode(false)
|
||||
{
|
||||
|
|
@ -51,52 +51,52 @@ SDL_WinRTApp::SDL_WinRTApp() :
|
|||
|
||||
void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
|
||||
{
|
||||
applicationView->Activated +=
|
||||
applicationView->Activated +=
|
||||
ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnActivated);
|
||||
|
||||
CoreApplication::Suspending +=
|
||||
CoreApplication::Suspending +=
|
||||
ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
|
||||
|
||||
CoreApplication::Resuming +=
|
||||
CoreApplication::Resuming +=
|
||||
ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
|
||||
|
||||
m_renderer = ref new SDL_winrtrenderer();
|
||||
m_renderer = ref new SDL_winrtrenderer();
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::SetWindow(CoreWindow^ window)
|
||||
{
|
||||
window->SizeChanged +=
|
||||
window->SizeChanged +=
|
||||
ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
|
||||
|
||||
window->VisibilityChanged +=
|
||||
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
|
||||
window->VisibilityChanged +=
|
||||
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
|
||||
|
||||
window->Closed +=
|
||||
window->Closed +=
|
||||
ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
|
||||
|
||||
window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
|
||||
window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
|
||||
|
||||
window->PointerPressed +=
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
|
||||
window->PointerPressed +=
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
|
||||
|
||||
window->PointerReleased +=
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
|
||||
|
||||
window->PointerMoved +=
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
|
||||
window->PointerMoved +=
|
||||
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
|
||||
|
||||
// Retrieves relative-only mouse movements:
|
||||
Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
|
||||
ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
|
||||
|
||||
window->KeyDown +=
|
||||
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
|
||||
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
|
||||
|
||||
window->KeyUp +=
|
||||
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
|
||||
window->KeyUp +=
|
||||
ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
|
||||
|
||||
|
||||
m_renderer->Initialize(CoreWindow::GetForCurrentThread());
|
||||
m_renderer->Initialize(CoreWindow::GetForCurrentThread());
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::Load(Platform::String^ entryPoint)
|
||||
|
|
@ -117,26 +117,26 @@ void SDL_WinRTApp::Run()
|
|||
|
||||
void SDL_WinRTApp::PumpEvents()
|
||||
{
|
||||
if (!m_windowClosed)
|
||||
{
|
||||
if (m_windowVisible)
|
||||
{
|
||||
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
|
||||
}
|
||||
}
|
||||
if (!m_windowClosed)
|
||||
{
|
||||
if (m_windowVisible)
|
||||
{
|
||||
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::UpdateWindowFramebuffer(SDL_Surface * surface, SDL_Rect * rects, int numrects)
|
||||
{
|
||||
if (!m_windowClosed && m_windowVisible)
|
||||
{
|
||||
m_renderer->Render(surface, rects, numrects);
|
||||
m_renderer->Present(); // This call is synchronized to the display frame rate.
|
||||
}
|
||||
{
|
||||
m_renderer->Render(surface, rects, numrects);
|
||||
m_renderer->Present(); // This call is synchronized to the display frame rate.
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::Uninitialize()
|
||||
|
|
@ -145,24 +145,24 @@ void SDL_WinRTApp::Uninitialize()
|
|||
|
||||
void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
|
||||
{
|
||||
m_renderer->UpdateForWindowSizeChange();
|
||||
m_renderer->UpdateForWindowSizeChange();
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
|
||||
{
|
||||
m_windowVisible = args->Visible;
|
||||
m_windowVisible = args->Visible;
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
|
||||
{
|
||||
m_windowClosed = true;
|
||||
m_windowClosed = true;
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
|
||||
{
|
||||
if (m_sdlWindowData)
|
||||
{
|
||||
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
|
|||
{
|
||||
if (m_sdlWindowData)
|
||||
{
|
||||
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -492,7 +492,7 @@ void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::C
|
|||
|
||||
void SDL_WinRTApp::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
|
||||
{
|
||||
CoreWindow::GetForCurrentThread()->Activate();
|
||||
CoreWindow::GetForCurrentThread()->Activate();
|
||||
}
|
||||
|
||||
static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event * event)
|
||||
|
|
@ -517,13 +517,13 @@ static int SDLCALL RemoveAppSuspendAndResumeEvents(void * userdata, SDL_Event *
|
|||
|
||||
void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
|
||||
{
|
||||
// Save app state asynchronously after requesting a deferral. Holding a deferral
|
||||
// indicates that the application is busy performing suspending operations. Be
|
||||
// aware that a deferral may not be held indefinitely. After about five seconds,
|
||||
// the app will be forced to exit.
|
||||
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
|
||||
create_task([this, deferral]()
|
||||
{
|
||||
// Save app state asynchronously after requesting a deferral. Holding a deferral
|
||||
// indicates that the application is busy performing suspending operations. Be
|
||||
// aware that a deferral may not be held indefinitely. After about five seconds,
|
||||
// the app will be forced to exit.
|
||||
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
|
||||
create_task([this, deferral]()
|
||||
{
|
||||
// Send a window-minimized event immediately to observers.
|
||||
// CoreDispatcher::ProcessEvents, which is the backbone on which
|
||||
// SDL_WinRTApp::PumpEvents is built, will not return to its caller
|
||||
|
|
@ -541,15 +541,15 @@ void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ a
|
|||
SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
||||
SDL_FilterEvents(RemoveAppSuspendAndResumeEvents, 0);
|
||||
}
|
||||
deferral->Complete();
|
||||
});
|
||||
deferral->Complete();
|
||||
});
|
||||
}
|
||||
|
||||
void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
|
||||
{
|
||||
// Restore any data or state that was unloaded on suspend. By default, data
|
||||
// and state are persisted when resuming from suspend. Note that this event
|
||||
// does not occur if the app was previously terminated.
|
||||
// Restore any data or state that was unloaded on suspend. By default, data
|
||||
// and state are persisted when resuming from suspend. Note that this event
|
||||
// does not occur if the app was previously terminated.
|
||||
if (m_sdlWindowData)
|
||||
{
|
||||
SDL_SendWindowEvent(m_sdlWindowData->sdlWindow, SDL_WINDOWEVENT_RESTORED, 0, 0); // TODO: see if SDL_WINDOWEVENT_SIZE_CHANGED should be getting triggered here (it is, currently)
|
||||
|
|
@ -619,6 +619,6 @@ __declspec(dllexport) int SDL_WinRT_RunApplication(SDL_WinRT_MainFunction mainFu
|
|||
{
|
||||
SDL_WinRT_main = mainFunction;
|
||||
auto direct3DApplicationSource = ref new Direct3DApplicationSource();
|
||||
CoreApplication::Run(direct3DApplicationSource);
|
||||
return 0;
|
||||
CoreApplication::Run(direct3DApplicationSource);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ using namespace Windows::UI::Core;
|
|||
ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
|
||||
{
|
||||
public:
|
||||
SDL_WinRTApp();
|
||||
|
||||
// IFrameworkView Methods.
|
||||
virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
|
||||
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void Load(Platform::String^ entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
SDL_WinRTApp();
|
||||
|
||||
// IFrameworkView Methods.
|
||||
virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
|
||||
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void Load(Platform::String^ entryPoint);
|
||||
virtual void Run();
|
||||
virtual void Uninitialize();
|
||||
|
||||
internal:
|
||||
// SDL-specific methods
|
||||
|
|
@ -32,25 +32,25 @@ internal:
|
|||
Windows::Foundation::Point TransformCursor(Windows::Foundation::Point rawPosition);
|
||||
|
||||
protected:
|
||||
// Event Handlers.
|
||||
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
|
||||
void OnLogicalDpiChanged(Platform::Object^ sender);
|
||||
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
|
||||
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
|
||||
void OnResuming(Platform::Object^ sender, Platform::Object^ args);
|
||||
void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
|
||||
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
|
||||
void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
// Event Handlers.
|
||||
void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
|
||||
void OnLogicalDpiChanged(Platform::Object^ sender);
|
||||
void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
|
||||
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
|
||||
void OnResuming(Platform::Object^ sender, Platform::Object^ args);
|
||||
void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
|
||||
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
|
||||
void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
|
||||
void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
|
||||
void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
|
||||
|
||||
private:
|
||||
SDL_winrtrenderer^ m_renderer;
|
||||
bool m_windowClosed;
|
||||
bool m_windowVisible;
|
||||
SDL_winrtrenderer^ m_renderer;
|
||||
bool m_windowClosed;
|
||||
bool m_windowVisible;
|
||||
const SDL_WindowData* m_sdlWindowData;
|
||||
bool m_useRelativeMouseMode;
|
||||
};
|
||||
|
|
@ -58,5 +58,5 @@ private:
|
|||
ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
|
||||
{
|
||||
public:
|
||||
virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
|
||||
virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ using namespace Windows::Graphics::Display;
|
|||
SDL_winrtrenderer::SDL_winrtrenderer() :
|
||||
m_mainTextureHelperSurface(NULL),
|
||||
m_loadingComplete(false),
|
||||
m_vertexCount(0)
|
||||
m_vertexCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -26,357 +26,357 @@ SDL_winrtrenderer::~SDL_winrtrenderer()
|
|||
// Initialize the Direct3D resources required to run.
|
||||
void SDL_winrtrenderer::Initialize(CoreWindow^ window)
|
||||
{
|
||||
m_window = window;
|
||||
|
||||
CreateDeviceResources();
|
||||
CreateWindowSizeDependentResources();
|
||||
m_window = window;
|
||||
|
||||
CreateDeviceResources();
|
||||
CreateWindowSizeDependentResources();
|
||||
}
|
||||
|
||||
// Recreate all device resources and set them back to the current state.
|
||||
void SDL_winrtrenderer::HandleDeviceLost()
|
||||
{
|
||||
// Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
|
||||
m_windowBounds.Width = 0;
|
||||
m_windowBounds.Height = 0;
|
||||
m_swapChain = nullptr;
|
||||
// Reset these member variables to ensure that UpdateForWindowSizeChange recreates all resources.
|
||||
m_windowBounds.Width = 0;
|
||||
m_windowBounds.Height = 0;
|
||||
m_swapChain = nullptr;
|
||||
|
||||
CreateDeviceResources();
|
||||
UpdateForWindowSizeChange();
|
||||
CreateDeviceResources();
|
||||
UpdateForWindowSizeChange();
|
||||
}
|
||||
|
||||
// These are the resources that depend on the device.
|
||||
void SDL_winrtrenderer::CreateDeviceResources()
|
||||
{
|
||||
// This flag adds support for surfaces with a different color channel ordering
|
||||
// than the API default. It is required for compatibility with Direct2D.
|
||||
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
// This flag adds support for surfaces with a different color channel ordering
|
||||
// than the API default. It is required for compatibility with Direct2D.
|
||||
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
|
||||
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
|
||||
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
#endif
|
||||
|
||||
// This array defines the set of DirectX hardware feature levels this app will support.
|
||||
// Note the ordering should be preserved.
|
||||
// Don't forget to declare your application's minimum required feature level in its
|
||||
// description. All applications are assumed to support 9.1 unless otherwise stated.
|
||||
D3D_FEATURE_LEVEL featureLevels[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0,
|
||||
D3D_FEATURE_LEVEL_9_3,
|
||||
D3D_FEATURE_LEVEL_9_2,
|
||||
D3D_FEATURE_LEVEL_9_1
|
||||
};
|
||||
// This array defines the set of DirectX hardware feature levels this app will support.
|
||||
// Note the ordering should be preserved.
|
||||
// Don't forget to declare your application's minimum required feature level in its
|
||||
// description. All applications are assumed to support 9.1 unless otherwise stated.
|
||||
D3D_FEATURE_LEVEL featureLevels[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0,
|
||||
D3D_FEATURE_LEVEL_9_3,
|
||||
D3D_FEATURE_LEVEL_9_2,
|
||||
D3D_FEATURE_LEVEL_9_1
|
||||
};
|
||||
|
||||
// Create the Direct3D 11 API device object and a corresponding context.
|
||||
ComPtr<ID3D11Device> device;
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
DX::ThrowIfFailed(
|
||||
D3D11CreateDevice(
|
||||
nullptr, // Specify nullptr to use the default adapter.
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
creationFlags, // Set set debug and Direct2D compatibility flags.
|
||||
featureLevels, // List of feature levels this app can support.
|
||||
ARRAYSIZE(featureLevels),
|
||||
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
|
||||
&device, // Returns the Direct3D device created.
|
||||
&m_featureLevel, // Returns feature level of device created.
|
||||
&context // Returns the device immediate context.
|
||||
)
|
||||
);
|
||||
// Create the Direct3D 11 API device object and a corresponding context.
|
||||
ComPtr<ID3D11Device> device;
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
DX::ThrowIfFailed(
|
||||
D3D11CreateDevice(
|
||||
nullptr, // Specify nullptr to use the default adapter.
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
nullptr,
|
||||
creationFlags, // Set set debug and Direct2D compatibility flags.
|
||||
featureLevels, // List of feature levels this app can support.
|
||||
ARRAYSIZE(featureLevels),
|
||||
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
|
||||
&device, // Returns the Direct3D device created.
|
||||
&m_featureLevel, // Returns feature level of device created.
|
||||
&context // Returns the device immediate context.
|
||||
)
|
||||
);
|
||||
|
||||
// Get the Direct3D 11.1 API device and context interfaces.
|
||||
DX::ThrowIfFailed(
|
||||
device.As(&m_d3dDevice)
|
||||
);
|
||||
// Get the Direct3D 11.1 API device and context interfaces.
|
||||
DX::ThrowIfFailed(
|
||||
device.As(&m_d3dDevice)
|
||||
);
|
||||
|
||||
DX::ThrowIfFailed(
|
||||
context.As(&m_d3dContext)
|
||||
);
|
||||
DX::ThrowIfFailed(
|
||||
context.As(&m_d3dContext)
|
||||
);
|
||||
|
||||
auto loadVSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimpleVertexShader.cso");
|
||||
auto loadPSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimplePixelShader.cso");
|
||||
auto loadPSTask = DX::ReadDataAsync("SDL_VS2012_WinRT\\SimplePixelShader.cso");
|
||||
|
||||
auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateVertexShader(
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
nullptr,
|
||||
&m_vertexShader
|
||||
)
|
||||
);
|
||||
auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateVertexShader(
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
nullptr,
|
||||
&m_vertexShader
|
||||
)
|
||||
);
|
||||
|
||||
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateInputLayout(
|
||||
vertexDesc,
|
||||
ARRAYSIZE(vertexDesc),
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
&m_inputLayout
|
||||
)
|
||||
);
|
||||
});
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateInputLayout(
|
||||
vertexDesc,
|
||||
ARRAYSIZE(vertexDesc),
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
&m_inputLayout
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreatePixelShader(
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
nullptr,
|
||||
&m_pixelShader
|
||||
)
|
||||
);
|
||||
});
|
||||
auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreatePixelShader(
|
||||
fileData->Data,
|
||||
fileData->Length,
|
||||
nullptr,
|
||||
&m_pixelShader
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
auto createVertexBuffer = (createPSTask && createVSTask).then([this] () {
|
||||
VertexPositionColor vertices[] =
|
||||
{
|
||||
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
|
||||
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
|
||||
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
|
||||
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
|
||||
};
|
||||
auto createVertexBuffer = (createPSTask && createVSTask).then([this] () {
|
||||
VertexPositionColor vertices[] =
|
||||
{
|
||||
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f, 1.0f)},
|
||||
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f)},
|
||||
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f)},
|
||||
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f)},
|
||||
};
|
||||
|
||||
m_vertexCount = ARRAYSIZE(vertices);
|
||||
m_vertexCount = ARRAYSIZE(vertices);
|
||||
|
||||
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
|
||||
vertexBufferData.pSysMem = vertices;
|
||||
vertexBufferData.SysMemPitch = 0;
|
||||
vertexBufferData.SysMemSlicePitch = 0;
|
||||
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateBuffer(
|
||||
&vertexBufferDesc,
|
||||
&vertexBufferData,
|
||||
&m_vertexBuffer
|
||||
)
|
||||
);
|
||||
});
|
||||
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
|
||||
vertexBufferData.pSysMem = vertices;
|
||||
vertexBufferData.SysMemPitch = 0;
|
||||
vertexBufferData.SysMemSlicePitch = 0;
|
||||
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateBuffer(
|
||||
&vertexBufferDesc,
|
||||
&vertexBufferData,
|
||||
&m_vertexBuffer
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
auto createMainSamplerTask = createVertexBuffer.then([this] () {
|
||||
D3D11_SAMPLER_DESC samplerDesc;
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 1;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
samplerDesc.BorderColor[0] = 0.0f;
|
||||
samplerDesc.BorderColor[1] = 0.0f;
|
||||
samplerDesc.BorderColor[2] = 0.0f;
|
||||
samplerDesc.BorderColor[3] = 0.0f;
|
||||
samplerDesc.MinLOD = 0.0f;
|
||||
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateSamplerState(
|
||||
&samplerDesc,
|
||||
&m_mainSampler
|
||||
)
|
||||
);
|
||||
});
|
||||
D3D11_SAMPLER_DESC samplerDesc;
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 1;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
samplerDesc.BorderColor[0] = 0.0f;
|
||||
samplerDesc.BorderColor[1] = 0.0f;
|
||||
samplerDesc.BorderColor[2] = 0.0f;
|
||||
samplerDesc.BorderColor[3] = 0.0f;
|
||||
samplerDesc.MinLOD = 0.0f;
|
||||
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateSamplerState(
|
||||
&samplerDesc,
|
||||
&m_mainSampler
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
createMainSamplerTask.then([this] () {
|
||||
m_loadingComplete = true;
|
||||
});
|
||||
createMainSamplerTask.then([this] () {
|
||||
m_loadingComplete = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Allocate all memory resources that change on a window SizeChanged event.
|
||||
void SDL_winrtrenderer::CreateWindowSizeDependentResources()
|
||||
{
|
||||
// Store the window bounds so the next time we get a SizeChanged event we can
|
||||
// avoid rebuilding everything if the size is identical.
|
||||
m_windowBounds = m_window->Bounds;
|
||||
// Store the window bounds so the next time we get a SizeChanged event we can
|
||||
// avoid rebuilding everything if the size is identical.
|
||||
m_windowBounds = m_window->Bounds;
|
||||
|
||||
// Calculate the necessary swap chain and render target size in pixels.
|
||||
float windowWidth = ConvertDipsToPixels(m_windowBounds.Width);
|
||||
float windowHeight = ConvertDipsToPixels(m_windowBounds.Height);
|
||||
// Calculate the necessary swap chain and render target size in pixels.
|
||||
float windowWidth = ConvertDipsToPixels(m_windowBounds.Width);
|
||||
float windowHeight = ConvertDipsToPixels(m_windowBounds.Height);
|
||||
|
||||
// The width and height of the swap chain must be based on the window's
|
||||
// landscape-oriented width and height. If the window is in a portrait
|
||||
// orientation, the dimensions must be reversed.
|
||||
m_orientation = DisplayProperties::CurrentOrientation;
|
||||
bool swapDimensions =
|
||||
m_orientation == DisplayOrientations::Portrait ||
|
||||
m_orientation == DisplayOrientations::PortraitFlipped;
|
||||
m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
|
||||
m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
|
||||
// The width and height of the swap chain must be based on the window's
|
||||
// landscape-oriented width and height. If the window is in a portrait
|
||||
// orientation, the dimensions must be reversed.
|
||||
m_orientation = DisplayProperties::CurrentOrientation;
|
||||
bool swapDimensions =
|
||||
m_orientation == DisplayOrientations::Portrait ||
|
||||
m_orientation == DisplayOrientations::PortraitFlipped;
|
||||
m_renderTargetSize.Width = swapDimensions ? windowHeight : windowWidth;
|
||||
m_renderTargetSize.Height = swapDimensions ? windowWidth : windowHeight;
|
||||
|
||||
if(m_swapChain != nullptr)
|
||||
{
|
||||
// If the swap chain already exists, resize it.
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->ResizeBuffers(
|
||||
2, // Double-buffered swap chain.
|
||||
static_cast<UINT>(m_renderTargetSize.Width),
|
||||
static_cast<UINT>(m_renderTargetSize.Height),
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
0
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, create a new one using the same adapter as the existing Direct3D device.
|
||||
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
|
||||
swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the window.
|
||||
swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
|
||||
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
|
||||
swapChainDesc.Stereo = false;
|
||||
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
|
||||
swapChainDesc.SampleDesc.Quality = 0;
|
||||
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
|
||||
swapChainDesc.Scaling = DXGI_SCALING_NONE;
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
|
||||
swapChainDesc.Flags = 0;
|
||||
if(m_swapChain != nullptr)
|
||||
{
|
||||
// If the swap chain already exists, resize it.
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->ResizeBuffers(
|
||||
2, // Double-buffered swap chain.
|
||||
static_cast<UINT>(m_renderTargetSize.Width),
|
||||
static_cast<UINT>(m_renderTargetSize.Height),
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
0
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, create a new one using the same adapter as the existing Direct3D device.
|
||||
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
|
||||
swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the window.
|
||||
swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
|
||||
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
|
||||
swapChainDesc.Stereo = false;
|
||||
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
|
||||
swapChainDesc.SampleDesc.Quality = 0;
|
||||
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
|
||||
swapChainDesc.Scaling = DXGI_SCALING_NONE;
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
|
||||
swapChainDesc.Flags = 0;
|
||||
|
||||
ComPtr<IDXGIDevice1> dxgiDevice;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice.As(&dxgiDevice)
|
||||
);
|
||||
ComPtr<IDXGIDevice1> dxgiDevice;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice.As(&dxgiDevice)
|
||||
);
|
||||
|
||||
ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
DX::ThrowIfFailed(
|
||||
dxgiDevice->GetAdapter(&dxgiAdapter)
|
||||
);
|
||||
ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
DX::ThrowIfFailed(
|
||||
dxgiDevice->GetAdapter(&dxgiAdapter)
|
||||
);
|
||||
|
||||
ComPtr<IDXGIFactory2> dxgiFactory;
|
||||
DX::ThrowIfFailed(
|
||||
dxgiAdapter->GetParent(
|
||||
__uuidof(IDXGIFactory2),
|
||||
&dxgiFactory
|
||||
)
|
||||
);
|
||||
ComPtr<IDXGIFactory2> dxgiFactory;
|
||||
DX::ThrowIfFailed(
|
||||
dxgiAdapter->GetParent(
|
||||
__uuidof(IDXGIFactory2),
|
||||
&dxgiFactory
|
||||
)
|
||||
);
|
||||
|
||||
Windows::UI::Core::CoreWindow^ window = m_window.Get();
|
||||
DX::ThrowIfFailed(
|
||||
dxgiFactory->CreateSwapChainForCoreWindow(
|
||||
m_d3dDevice.Get(),
|
||||
reinterpret_cast<IUnknown*>(window),
|
||||
&swapChainDesc,
|
||||
nullptr, // Allow on all displays.
|
||||
&m_swapChain
|
||||
)
|
||||
);
|
||||
|
||||
// Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
|
||||
// ensures that the application will only render after each VSync, minimizing power consumption.
|
||||
DX::ThrowIfFailed(
|
||||
dxgiDevice->SetMaximumFrameLatency(1)
|
||||
);
|
||||
}
|
||||
|
||||
// Set the proper orientation for the swap chain, and generate the
|
||||
// 3D matrix transformation for rendering to the rotated swap chain.
|
||||
DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
|
||||
switch (m_orientation)
|
||||
{
|
||||
case DisplayOrientations::Landscape:
|
||||
rotation = DXGI_MODE_ROTATION_IDENTITY;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
Windows::UI::Core::CoreWindow^ window = m_window.Get();
|
||||
DX::ThrowIfFailed(
|
||||
dxgiFactory->CreateSwapChainForCoreWindow(
|
||||
m_d3dDevice.Get(),
|
||||
reinterpret_cast<IUnknown*>(window),
|
||||
&swapChainDesc,
|
||||
nullptr, // Allow on all displays.
|
||||
&m_swapChain
|
||||
)
|
||||
);
|
||||
|
||||
// Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
|
||||
// ensures that the application will only render after each VSync, minimizing power consumption.
|
||||
DX::ThrowIfFailed(
|
||||
dxgiDevice->SetMaximumFrameLatency(1)
|
||||
);
|
||||
}
|
||||
|
||||
// Set the proper orientation for the swap chain, and generate the
|
||||
// 3D matrix transformation for rendering to the rotated swap chain.
|
||||
DXGI_MODE_ROTATION rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
|
||||
switch (m_orientation)
|
||||
{
|
||||
case DisplayOrientations::Landscape:
|
||||
rotation = DXGI_MODE_ROTATION_IDENTITY;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 0-degree Z-rotation
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
|
||||
case DisplayOrientations::Portrait:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE270;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
case DisplayOrientations::Portrait:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE270;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 90-degree Z-rotation
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE180;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation
|
||||
-1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE180;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 180-degree Z-rotation
|
||||
-1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE90;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
rotation = DXGI_MODE_ROTATION_ROTATE90;
|
||||
m_orientationTransform3D = XMFLOAT4X4( // 270-degree Z-rotation
|
||||
0.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw ref new Platform::FailureException();
|
||||
}
|
||||
default:
|
||||
throw ref new Platform::FailureException();
|
||||
}
|
||||
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->SetRotation(rotation)
|
||||
);
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->SetRotation(rotation)
|
||||
);
|
||||
|
||||
// Create a render target view of the swap chain back buffer.
|
||||
ComPtr<ID3D11Texture2D> backBuffer;
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->GetBuffer(
|
||||
0,
|
||||
__uuidof(ID3D11Texture2D),
|
||||
&backBuffer
|
||||
)
|
||||
);
|
||||
// Create a render target view of the swap chain back buffer.
|
||||
ComPtr<ID3D11Texture2D> backBuffer;
|
||||
DX::ThrowIfFailed(
|
||||
m_swapChain->GetBuffer(
|
||||
0,
|
||||
__uuidof(ID3D11Texture2D),
|
||||
&backBuffer
|
||||
)
|
||||
);
|
||||
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateRenderTargetView(
|
||||
backBuffer.Get(),
|
||||
nullptr,
|
||||
&m_renderTargetView
|
||||
)
|
||||
);
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateRenderTargetView(
|
||||
backBuffer.Get(),
|
||||
nullptr,
|
||||
&m_renderTargetView
|
||||
)
|
||||
);
|
||||
|
||||
// Create a depth stencil view.
|
||||
CD3D11_TEXTURE2D_DESC depthStencilDesc(
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT,
|
||||
static_cast<UINT>(m_renderTargetSize.Width),
|
||||
static_cast<UINT>(m_renderTargetSize.Height),
|
||||
1,
|
||||
1,
|
||||
D3D11_BIND_DEPTH_STENCIL
|
||||
);
|
||||
// Create a depth stencil view.
|
||||
CD3D11_TEXTURE2D_DESC depthStencilDesc(
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT,
|
||||
static_cast<UINT>(m_renderTargetSize.Width),
|
||||
static_cast<UINT>(m_renderTargetSize.Height),
|
||||
1,
|
||||
1,
|
||||
D3D11_BIND_DEPTH_STENCIL
|
||||
);
|
||||
|
||||
ComPtr<ID3D11Texture2D> depthStencil;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateTexture2D(
|
||||
&depthStencilDesc,
|
||||
nullptr,
|
||||
&depthStencil
|
||||
)
|
||||
);
|
||||
ComPtr<ID3D11Texture2D> depthStencil;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateTexture2D(
|
||||
&depthStencilDesc,
|
||||
nullptr,
|
||||
&depthStencil
|
||||
)
|
||||
);
|
||||
|
||||
// Set the rendering viewport to target the entire window.
|
||||
CD3D11_VIEWPORT viewport(
|
||||
0.0f,
|
||||
0.0f,
|
||||
m_renderTargetSize.Width,
|
||||
m_renderTargetSize.Height
|
||||
);
|
||||
// Set the rendering viewport to target the entire window.
|
||||
CD3D11_VIEWPORT viewport(
|
||||
0.0f,
|
||||
0.0f,
|
||||
m_renderTargetSize.Width,
|
||||
m_renderTargetSize.Height
|
||||
);
|
||||
|
||||
m_d3dContext->RSSetViewports(1, &viewport);
|
||||
m_d3dContext->RSSetViewports(1, &viewport);
|
||||
}
|
||||
|
||||
void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
|
||||
|
|
@ -384,17 +384,17 @@ void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
|
|||
const int pixelSizeInBytes = 4;
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc = {0};
|
||||
textureDesc.Width = w;
|
||||
textureDesc.Height = h;
|
||||
textureDesc.MipLevels = 1;
|
||||
textureDesc.ArraySize = 1;
|
||||
textureDesc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
|
||||
textureDesc.SampleDesc.Count = 1;
|
||||
textureDesc.SampleDesc.Quality = 0;
|
||||
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
textureDesc.MiscFlags = 0;
|
||||
textureDesc.Width = w;
|
||||
textureDesc.Height = h;
|
||||
textureDesc.MipLevels = 1;
|
||||
textureDesc.ArraySize = 1;
|
||||
textureDesc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
|
||||
textureDesc.SampleDesc.Count = 1;
|
||||
textureDesc.SampleDesc.Quality = 0;
|
||||
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
textureDesc.MiscFlags = 0;
|
||||
|
||||
const int numPixels = textureDesc.Width * textureDesc.Height;
|
||||
std::vector<uint8> initialTexturePixels(numPixels * pixelSizeInBytes, 0x00);
|
||||
|
|
@ -407,17 +407,17 @@ void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
|
|||
// initialTexturePixels[i+3] = 0xff;
|
||||
//}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initialTextureData = {0};
|
||||
initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
|
||||
initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
|
||||
initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateTexture2D(
|
||||
&textureDesc,
|
||||
&initialTextureData,
|
||||
&m_mainTexture
|
||||
)
|
||||
);
|
||||
D3D11_SUBRESOURCE_DATA initialTextureData = {0};
|
||||
initialTextureData.pSysMem = (void *)&(initialTexturePixels[0]);
|
||||
initialTextureData.SysMemPitch = textureDesc.Width * pixelSizeInBytes;
|
||||
initialTextureData.SysMemSlicePitch = numPixels * pixelSizeInBytes;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateTexture2D(
|
||||
&textureDesc,
|
||||
&initialTextureData,
|
||||
&m_mainTexture
|
||||
)
|
||||
);
|
||||
|
||||
if (m_mainTextureHelperSurface) {
|
||||
SDL_FreeSurface(m_mainTextureHelperSurface);
|
||||
|
|
@ -433,152 +433,152 @@ void SDL_winrtrenderer::ResizeMainTexture(int w, int h)
|
|||
DX::ThrowIfFailed(E_FAIL); // TODO, WinRT: generate a better error here, taking into account who's calling this function.
|
||||
}
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
|
||||
resourceViewDesc.Format = textureDesc.Format;
|
||||
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
resourceViewDesc.Texture2D.MostDetailedMip = 0;
|
||||
resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateShaderResourceView(
|
||||
m_mainTexture.Get(),
|
||||
&resourceViewDesc,
|
||||
&m_mainTextureResourceView)
|
||||
);
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
|
||||
resourceViewDesc.Format = textureDesc.Format;
|
||||
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
resourceViewDesc.Texture2D.MostDetailedMip = 0;
|
||||
resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dDevice->CreateShaderResourceView(
|
||||
m_mainTexture.Get(),
|
||||
&resourceViewDesc,
|
||||
&m_mainTextureResourceView)
|
||||
);
|
||||
}
|
||||
|
||||
// This method is called in the event handler for the SizeChanged event.
|
||||
void SDL_winrtrenderer::UpdateForWindowSizeChange()
|
||||
{
|
||||
if (m_window->Bounds.Width != m_windowBounds.Width ||
|
||||
m_window->Bounds.Height != m_windowBounds.Height ||
|
||||
m_orientation != DisplayProperties::CurrentOrientation)
|
||||
{
|
||||
ID3D11RenderTargetView* nullViews[] = {nullptr};
|
||||
m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
|
||||
m_renderTargetView = nullptr;
|
||||
m_d3dContext->Flush();
|
||||
CreateWindowSizeDependentResources();
|
||||
}
|
||||
if (m_window->Bounds.Width != m_windowBounds.Width ||
|
||||
m_window->Bounds.Height != m_windowBounds.Height ||
|
||||
m_orientation != DisplayProperties::CurrentOrientation)
|
||||
{
|
||||
ID3D11RenderTargetView* nullViews[] = {nullptr};
|
||||
m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
|
||||
m_renderTargetView = nullptr;
|
||||
m_d3dContext->Flush();
|
||||
CreateWindowSizeDependentResources();
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_winrtrenderer::Render(SDL_Surface * surface, SDL_Rect * rects, int numrects)
|
||||
{
|
||||
const float blackColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
m_d3dContext->ClearRenderTargetView(
|
||||
m_renderTargetView.Get(),
|
||||
blackColor
|
||||
);
|
||||
const float blackColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
m_d3dContext->ClearRenderTargetView(
|
||||
m_renderTargetView.Get(),
|
||||
blackColor
|
||||
);
|
||||
|
||||
// Only draw the screen once it is loaded (some loading is asynchronous).
|
||||
if (!m_loadingComplete)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Only draw the screen once it is loaded (some loading is asynchronous).
|
||||
if (!m_loadingComplete)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!m_mainTextureResourceView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the main texture (for SDL usage). Start by mapping the SDL
|
||||
// Update the main texture (for SDL usage). Start by mapping the SDL
|
||||
// window's main texture to CPU-accessible memory:
|
||||
D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dContext->Map(
|
||||
m_mainTexture.Get(),
|
||||
0,
|
||||
D3D11_MAP_WRITE_DISCARD,
|
||||
0,
|
||||
&textureMemory)
|
||||
);
|
||||
D3D11_MAPPED_SUBRESOURCE textureMemory = {0};
|
||||
DX::ThrowIfFailed(
|
||||
m_d3dContext->Map(
|
||||
m_mainTexture.Get(),
|
||||
0,
|
||||
D3D11_MAP_WRITE_DISCARD,
|
||||
0,
|
||||
&textureMemory)
|
||||
);
|
||||
|
||||
// Copy pixel data to the locked texture's memory:
|
||||
m_mainTextureHelperSurface->pixels = textureMemory.pData;
|
||||
m_mainTextureHelperSurface->pitch = textureMemory.RowPitch;
|
||||
SDL_BlitSurface(surface, NULL, m_mainTextureHelperSurface, NULL);
|
||||
// TODO, WinRT: only update the requested rects (passed to SDL_UpdateWindowSurface), rather than everything
|
||||
// TODO, WinRT: only update the requested rects (passed to SDL_UpdateWindowSurface), rather than everything
|
||||
|
||||
// Clean up a bit, then commit the texture's memory back to Direct3D:
|
||||
m_mainTextureHelperSurface->pixels = NULL;
|
||||
m_mainTextureHelperSurface->pitch = 0;
|
||||
m_d3dContext->Unmap(
|
||||
m_mainTexture.Get(),
|
||||
0);
|
||||
m_d3dContext->Unmap(
|
||||
m_mainTexture.Get(),
|
||||
0);
|
||||
|
||||
m_d3dContext->OMSetRenderTargets(
|
||||
1,
|
||||
m_renderTargetView.GetAddressOf(),
|
||||
nullptr
|
||||
);
|
||||
m_d3dContext->OMSetRenderTargets(
|
||||
1,
|
||||
m_renderTargetView.GetAddressOf(),
|
||||
nullptr
|
||||
);
|
||||
|
||||
UINT stride = sizeof(VertexPositionColor);
|
||||
UINT offset = 0;
|
||||
m_d3dContext->IASetVertexBuffers(
|
||||
0,
|
||||
1,
|
||||
m_vertexBuffer.GetAddressOf(),
|
||||
&stride,
|
||||
&offset
|
||||
);
|
||||
UINT stride = sizeof(VertexPositionColor);
|
||||
UINT offset = 0;
|
||||
m_d3dContext->IASetVertexBuffers(
|
||||
0,
|
||||
1,
|
||||
m_vertexBuffer.GetAddressOf(),
|
||||
&stride,
|
||||
&offset
|
||||
);
|
||||
|
||||
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
|
||||
m_d3dContext->IASetInputLayout(m_inputLayout.Get());
|
||||
m_d3dContext->IASetInputLayout(m_inputLayout.Get());
|
||||
|
||||
m_d3dContext->VSSetShader(
|
||||
m_vertexShader.Get(),
|
||||
nullptr,
|
||||
0
|
||||
);
|
||||
m_d3dContext->VSSetShader(
|
||||
m_vertexShader.Get(),
|
||||
nullptr,
|
||||
0
|
||||
);
|
||||
|
||||
m_d3dContext->PSSetShader(
|
||||
m_pixelShader.Get(),
|
||||
nullptr,
|
||||
0
|
||||
);
|
||||
m_d3dContext->PSSetShader(
|
||||
m_pixelShader.Get(),
|
||||
nullptr,
|
||||
0
|
||||
);
|
||||
|
||||
m_d3dContext->PSSetShaderResources(0, 1, m_mainTextureResourceView.GetAddressOf());
|
||||
m_d3dContext->PSSetShaderResources(0, 1, m_mainTextureResourceView.GetAddressOf());
|
||||
|
||||
m_d3dContext->PSSetSamplers(0, 1, m_mainSampler.GetAddressOf());
|
||||
m_d3dContext->PSSetSamplers(0, 1, m_mainSampler.GetAddressOf());
|
||||
|
||||
m_d3dContext->Draw(4, 0);
|
||||
m_d3dContext->Draw(4, 0);
|
||||
}
|
||||
|
||||
// Method to deliver the final image to the display.
|
||||
void SDL_winrtrenderer::Present()
|
||||
{
|
||||
// The application may optionally specify "dirty" or "scroll"
|
||||
// rects to improve efficiency in certain scenarios.
|
||||
DXGI_PRESENT_PARAMETERS parameters = {0};
|
||||
parameters.DirtyRectsCount = 0;
|
||||
parameters.pDirtyRects = nullptr;
|
||||
parameters.pScrollRect = nullptr;
|
||||
parameters.pScrollOffset = nullptr;
|
||||
|
||||
// The first argument instructs DXGI to block until VSync, putting the application
|
||||
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
|
||||
// frames that will never be displayed to the screen.
|
||||
HRESULT hr = m_swapChain->Present1(1, 0, ¶meters);
|
||||
// The application may optionally specify "dirty" or "scroll"
|
||||
// rects to improve efficiency in certain scenarios.
|
||||
DXGI_PRESENT_PARAMETERS parameters = {0};
|
||||
parameters.DirtyRectsCount = 0;
|
||||
parameters.pDirtyRects = nullptr;
|
||||
parameters.pScrollRect = nullptr;
|
||||
parameters.pScrollOffset = nullptr;
|
||||
|
||||
// The first argument instructs DXGI to block until VSync, putting the application
|
||||
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
|
||||
// frames that will never be displayed to the screen.
|
||||
HRESULT hr = m_swapChain->Present1(1, 0, ¶meters);
|
||||
|
||||
// Discard the contents of the render target.
|
||||
// This is a valid operation only when the existing contents will be entirely
|
||||
// overwritten. If dirty or scroll rects are used, this call should be removed.
|
||||
m_d3dContext->DiscardView(m_renderTargetView.Get());
|
||||
// Discard the contents of the render target.
|
||||
// This is a valid operation only when the existing contents will be entirely
|
||||
// overwritten. If dirty or scroll rects are used, this call should be removed.
|
||||
m_d3dContext->DiscardView(m_renderTargetView.Get());
|
||||
|
||||
// If the device was removed either by a disconnect or a driver upgrade, we
|
||||
// must recreate all device resources.
|
||||
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
||||
{
|
||||
HandleDeviceLost();
|
||||
}
|
||||
else
|
||||
{
|
||||
DX::ThrowIfFailed(hr);
|
||||
}
|
||||
// If the device was removed either by a disconnect or a driver upgrade, we
|
||||
// must recreate all device resources.
|
||||
if (hr == DXGI_ERROR_DEVICE_REMOVED)
|
||||
{
|
||||
HandleDeviceLost();
|
||||
}
|
||||
else
|
||||
{
|
||||
DX::ThrowIfFailed(hr);
|
||||
}
|
||||
}
|
||||
|
||||
// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
|
||||
float SDL_winrtrenderer::ConvertDipsToPixels(float dips)
|
||||
{
|
||||
static const float dipsPerInch = 96.0f;
|
||||
return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
|
||||
static const float dipsPerInch = 96.0f;
|
||||
return floor(dips * DisplayProperties::LogicalDpi / dipsPerInch + 0.5f); // Round to nearest integer.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,57 +5,57 @@
|
|||
|
||||
struct VertexPositionColor
|
||||
{
|
||||
DirectX::XMFLOAT3 pos;
|
||||
DirectX::XMFLOAT2 tex;
|
||||
DirectX::XMFLOAT3 pos;
|
||||
DirectX::XMFLOAT2 tex;
|
||||
};
|
||||
|
||||
// Helper class that initializes DirectX APIs for 3D rendering.
|
||||
ref class SDL_winrtrenderer
|
||||
{
|
||||
internal:
|
||||
SDL_winrtrenderer();
|
||||
SDL_winrtrenderer();
|
||||
|
||||
public:
|
||||
virtual ~SDL_winrtrenderer();
|
||||
virtual void Initialize(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void HandleDeviceLost();
|
||||
virtual void CreateDeviceResources();
|
||||
virtual void CreateWindowSizeDependentResources();
|
||||
virtual void UpdateForWindowSizeChange();
|
||||
virtual void Present();
|
||||
virtual float ConvertDipsToPixels(float dips);
|
||||
virtual void Initialize(Windows::UI::Core::CoreWindow^ window);
|
||||
virtual void HandleDeviceLost();
|
||||
virtual void CreateDeviceResources();
|
||||
virtual void CreateWindowSizeDependentResources();
|
||||
virtual void UpdateForWindowSizeChange();
|
||||
virtual void Present();
|
||||
virtual float ConvertDipsToPixels(float dips);
|
||||
|
||||
internal:
|
||||
virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects);
|
||||
virtual void Render(SDL_Surface * surface, SDL_Rect * rects, int numrects);
|
||||
void ResizeMainTexture(int w, int h);
|
||||
|
||||
protected private:
|
||||
// Direct3D Objects.
|
||||
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
|
||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
|
||||
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_mainTexture;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_mainTextureResourceView;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_mainSampler;
|
||||
// Direct3D Objects.
|
||||
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
|
||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
|
||||
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_mainTexture;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_mainTextureResourceView;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_mainSampler;
|
||||
|
||||
// UpdateWindowSurface helper objects
|
||||
SDL_Surface * m_mainTextureHelperSurface;
|
||||
|
||||
// Cached renderer properties.
|
||||
D3D_FEATURE_LEVEL m_featureLevel;
|
||||
Windows::Foundation::Size m_renderTargetSize;
|
||||
Windows::Foundation::Rect m_windowBounds;
|
||||
Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
|
||||
Windows::Graphics::Display::DisplayOrientations m_orientation;
|
||||
uint32 m_vertexCount;
|
||||
// Cached renderer properties.
|
||||
D3D_FEATURE_LEVEL m_featureLevel;
|
||||
Windows::Foundation::Size m_renderTargetSize;
|
||||
Windows::Foundation::Rect m_windowBounds;
|
||||
Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
|
||||
Windows::Graphics::Display::DisplayOrientations m_orientation;
|
||||
uint32 m_vertexCount;
|
||||
|
||||
// Transform used for display orientation.
|
||||
DirectX::XMFLOAT4X4 m_orientationTransform3D;
|
||||
// Transform used for display orientation.
|
||||
DirectX::XMFLOAT4X4 m_orientationTransform3D;
|
||||
|
||||
// Has the renderer finished loading?
|
||||
bool m_loadingComplete;
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ SamplerState theSampler : register(s0);
|
|||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float4 pos : SV_POSITION;
|
||||
|
||||
float2 tex : TEXCOORD0;
|
||||
float2 tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
//return float4(input.color,1.0f);
|
||||
return theTexture.Sample(theSampler, input.tex);
|
||||
//return float4(input.color,1.0f);
|
||||
return theTexture.Sample(theSampler, input.tex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@
|
|||
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float3 pos : POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float3 pos : POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexShaderOutput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertexShaderOutput main(VertexShaderInput input)
|
||||
{
|
||||
VertexShaderOutput output;
|
||||
output.pos = float4(input.pos, 1.0f);
|
||||
output.tex = input.tex;
|
||||
return output;
|
||||
VertexShaderOutput output;
|
||||
output.pos = float4(input.pos, 1.0f);
|
||||
output.tex = input.tex;
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user