#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2013 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#pragma endregion // CPL License
#ifndef NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RASTERIZER_IMPL_H
#define NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RASTERIZER_IMPL_H
#include "Nuclex/Graphics/Config.h"
#include "Nuclex/Graphics/Size.h"
#include "Nuclex/Graphics/Rasterization/Direct3D11Rasterizer.h"
#include "Direct3D11RasterizerResources.h"
#include "Direct3D11RasterizerSettings.h"
#include "Direct3D11RasterizerState.h"
#include "Direct3D11InputLayoutManager.h"
// WinRT doesn't allow 'public' members in ref classes, so we need to use different
// access specifiers depending on whether we're Win32 + ISO C++ or WinRT + C++/CX.
#if defined(NUCLEX_GRAPHICS_WINRT)
#define internal internal
#else
#define internal public
#endif
namespace Nuclex { namespace Graphics { namespace Rasterization {
// ------------------------------------------------------------------------------------------- //
#if defined(NUCLEX_GRAPHICS_WINRT)
/// Manages the private implementation of the Direct3D 11 rasterizer
ref struct Direct3D11Rasterizer::Impl {
/// Initializes a new Direct3D 11 polygon renderer
/// Window into which to render
internal: Impl(Windows::UI::Core::CoreWindow ^window);
#else
/// Manages the private implementation of the Direct3D 11 rasterizer
struct Direct3D11Rasterizer::Impl {
/// Initializes a new Direct3D 11 polygon renderer
/// Handle of the window into which to render
public: Impl(HWND windowHandle);
#endif
/// Destroy the Direct3D 11 polygon renderer
public: ~Impl();
/// Retrieves the Direct3D device currently created
/// The current Direct3D device
internal: const ID3D11DeviceNPtr &GetDirect3DDevice() const;
/// Retrieves the context of the current Direct3D device
/// The context of the current Direct3D device
internal: const ID3D11DeviceContextNPtr &GetDirect3DDeviceContext() const;
/// Retrieves the swap chain used for the Direct3D device's view
/// The swap chain used to present the view of the Direct3D device>/returns>
internal: const IDXGISwapChainNPtr &GetSwapChain() const;
/// Returns the size of the viewing area
/// The size of the viewing area
internal: Size GetViewSize() const;
/// Prepares a default swap chain description
/// The default swap chain description
private: static DXGI_SWAP_CHAIN_DESCN getDefaultSwapChainDescription();
/// Retrieves the Direct3D 11 device's graphics resource factory
/// Direct3D 11 whose resource facotry will be returned
/// The graphics resource factory for the Direct3D 11 device
private: static IDXGIFactoryNPtr getDxgiFactory(const ID3D11DevicePtr &device);
/// Creates the Direct3D device the rasterizer will use
private: void createDirect3DDevice();
/// Creates the swap chain through which the image is presented
private: void createSwapChain();
/// Called when the window could have been resized
/// New width of the window
/// New height of the window
private: void viewResized(std::size_t width, std::size_t height);
#if defined(NUCLEX_GRAPHICS_WINRT)
/// Called when the size of the window has changed
/// Window whose size has changed
/// Contains the new window size
private: void sizeChanged(
Windows::UI::Core::CoreWindow ^window,
Windows::UI::Core::WindowSizeChangedEventArgs ^arguments
);
#else
/// Subclasses the game's window to listen in on Window messages
private: void subclassWindow();
/// Unsubclasses the game's window again
private: void unsubclassWindow();
/// Message procedure used to intercept messages to the game's window
/// Handle of the window received the message
/// Type of message being sent to the window
/// First message-dependent parameter
/// Second message-dependent parameter
private: static LRESULT CALLBACK windowProcedure(
HWND windowHandle, UINT message, WPARAM parameter1, LPARAM parameter2
);
#endif
/// Responsible for the rasterizer's resource management
internal: Direct3D11RasterizerResources Resources;
/// Responsible for the rasterizer's settings management
internal: Direct3D11RasterizerSettings Settings;
/// Responsible for the rasterizer's state management
internal: Direct3D11RasterizerState State;
/// Responsible for creating and caching shader input layouts
internal: Direct3D11InputLayoutManager InputLayouts;
#if defined(NUCLEX_GRAPHICS_WINRT)
/// Window the rasterizer renders into
private: Platform::Agile window;
/// Token for the subscription to the SizeChanged event
private: Windows::Foundation::EventRegistrationToken sizeChangedEventToken;
#else
/// Handle of the window the rasterizer renders into
private: HWND windowHandle;
/// The subclassed window's old window message procedure
private: WNDPROC oldWindowProc;
#endif
/// Direct3D device the rasterizer uses for rendering
private: ID3D11DeviceNPtr device;
/// Direct3D device context through which state is managed
private: ID3D11DeviceContextNPtr context;
/// Swap chain used to present the rendered image on the screen
private: IDXGISwapChainNPtr swapChain;
/// Direct3D feature level the device actually supports
private: D3D_FEATURE_LEVEL supportedFeatureLevel;
/// Settings for the swap chain used to present the rendered image
private: DXGI_SWAP_CHAIN_DESCN swapChainDescription;
/// Current width of the rendering window's client rectangle
private: std::size_t width;
/// Current height of the rendering window's client rectangle
private: std::size_t height;
};
// ------------------------------------------------------------------------------------------- //
}}} // namespace Nuclex::Graphics::Rasterization
#undef internal
#endif // NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RASTERIZER_IMPL_H