#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_DIRECT3D11CONVERTERS_H #define NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11CONVERTERS_H #include "Nuclex/Graphics/Rasterization/Usage.h" #include "Nuclex/Graphics/Rasterization/PixelFormat.h" #include "Nuclex/Graphics/Rasterization/Topology.h" #include "Nuclex/Graphics/Rasterization/FillMode.h" #include "Nuclex/Graphics/Rasterization/CullMode.h" #include #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #define NO_MINMAX #include #include #define INITGUID 1 #define D3D11_NO_HELPERS #include // Direct3D 11.1 requires Windows 8 or later. #if defined(NUCLEX_GRAPHICS_DIRECT3D11_1) #include #endif namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // /// Converts an agnostic usage into a Direct3D usage /// Usage that will be converted /// The equivalent Direct3D usage inline D3D11_USAGE direct3DUsageFromUsage(Usage::Enum usage) { switch(usage) { case Usage::Immutable: { return D3D11_USAGE_IMMUTABLE; } case Usage::GpuChangeable: { return D3D11_USAGE_DEFAULT; } case Usage::CpuToGpuTransfer: { return D3D11_USAGE_DYNAMIC; } case Usage::GpuToCpuTransfer: { return D3D11_USAGE_STAGING; } default: { throw std::runtime_error("Unsupported resource usage"); } } } // ------------------------------------------------------------------------------------------- // /// Converts an agnostic usage into a Direct3D CPU access flag /// Usage that will be converted /// The equivalent Direct3D CPU access flag inline D3D11_CPU_ACCESS_FLAG direct3DCpuAccessFromUsage(Usage::Enum usage) { switch(usage) { case Usage::Immutable: { return D3D11_CPU_ACCESS_FLAG(0); } case Usage::GpuChangeable: { return D3D11_CPU_ACCESS_FLAG(0); } case Usage::CpuToGpuTransfer: { return D3D11_CPU_ACCESS_WRITE; } case Usage::GpuToCpuTransfer: { return D3D11_CPU_ACCESS_READ; } default: { throw std::runtime_error("Unsupported resource usage"); } } } // ------------------------------------------------------------------------------------------- // /// Converts an agnostic pixel format into a Direct3D pixel format /// Pixel format that will be converted /// The equivalent Direct3D pixel format inline DXGI_FORMAT direct3DFormatFromPixelFormat(PixelFormat::Enum pixelFormat) { switch(pixelFormat) { case PixelFormat::R8_Unsigned: { return DXGI_FORMAT_R8_UNORM; } case PixelFormat::R8_G8_Signed: { return DXGI_FORMAT_R8G8_SNORM; } case PixelFormat::B5_G6_R5_Unsigned: { return DXGI_FORMAT_B5G6R5_UNORM; } case PixelFormat::B4_G4_R4_A4_Unsigned: { return DXGI_FORMAT_B4G4R4A4_UNORM; } case PixelFormat::R8_G8_B8_A8_Unsigned: { return DXGI_FORMAT_R8G8B8A8_UNORM; } case PixelFormat::R8_G8_B8_A8_Signed: { return DXGI_FORMAT_R8G8B8A8_SNORM; } case PixelFormat::BC1_Compressed: { return DXGI_FORMAT_BC1_UNORM; } case PixelFormat::BC2_Compressed: { return DXGI_FORMAT_BC2_UNORM; } case PixelFormat::BC3_Compressed: { return DXGI_FORMAT_BC3_UNORM; } case PixelFormat::Modern_A8_Unsigned: { return DXGI_FORMAT_A8_UNORM; } case PixelFormat::Modern_R16_Unsigned: { return DXGI_FORMAT_R16_UNORM; } case PixelFormat::Modern_R16_G16_Unsigned: { return DXGI_FORMAT_R16G16_UNORM; } case PixelFormat::Modern_R16_G16_Float: { return DXGI_FORMAT_R16G16_FLOAT; } case PixelFormat::Modern_R16_G16_B16_A16_Unsigned: { return DXGI_FORMAT_R16G16B16A16_UNORM; } case PixelFormat::Modern_R16_G16_B16_A16_Float: { return DXGI_FORMAT_R16G16B16A16_FLOAT; } default: { throw std::runtime_error("Unsupported pixel format"); } } } // ------------------------------------------------------------------------------------------- // /// Converts an agnostic pixel format into a Direct3D pixel format /// Pixel format that will be converted /// The equivalent Direct3D pixel format inline D3D11_PRIMITIVE_TOPOLOGY direct3DTopologyFromTopology(Topology::Enum topology) { switch(topology) { case Topology::Point: { return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; } case Topology::LineList: { return D3D11_PRIMITIVE_TOPOLOGY_LINELIST; } case Topology::PolyLine: { return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP; } case Topology::TriangleList: { return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; } case Topology::TriangleStrip: { return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; } default: { throw std::runtime_error("Unsupported primitive topology"); } } } // ------------------------------------------------------------------------------------------- // /// Converts a fill mode into a Direct3D fill mode /// Fill mode that will be converted /// The equivalent Direct3D fill mode inline D3D11_FILL_MODE direct3DFillModeFromFillMode(FillMode::Enum fillMode) { switch(fillMode) { case FillMode::Wireframe: { return D3D11_FILL_WIREFRAME; } case FillMode::Solid: { return D3D11_FILL_SOLID; } default: { throw std::runtime_error("Unsupported fill mode"); } } } // ------------------------------------------------------------------------------------------- // /// Converts a cull mode into a Direct3D cull mode /// Cull mode that will be converted /// The equivalent Direct3D cull mode inline D3D11_CULL_MODE direct3DCullModeFromCullMode(CullMode::Enum cullMode) { switch(cullMode) { // TODO: Given their naming, do D3D cull modes interact with isFrontFaceClockwise? case CullMode::None: { return D3D11_CULL_NONE; } case CullMode::Clockwise: { return D3D11_CULL_FRONT; } case CullMode::CounterClockwise: { return D3D11_CULL_BACK; } default: { throw std::runtime_error("Unsupported cull mode"); } } } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization #endif // NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11CONVERTERS_H