Browse Source

Direct X12 API Basis implementiert

Kolja Strohm 5 years ago
parent
commit
6885bc3358
9 changed files with 1710 additions and 1035 deletions
  1. 4 1
      Bildschirm.cpp
  2. 856 0
      DX11GraphicsApi.cpp
  3. 527 0
      DX12GraphicsApi.cpp
  4. 176 0
      DX9GraphicsApi.cpp
  5. 3 0
      Framework.vcxproj
  6. 9 0
      Framework.vcxproj.filters
  7. 4 1018
      GraphicsApi.cpp
  8. 38 0
      GraphicsApi.h
  9. 93 16
      main.h

+ 4 - 1
Bildschirm.cpp

@@ -439,7 +439,10 @@ Bildschirm3D::Bildschirm3D( WFenster * fenster )
     kameras( new RCArray< Kam3D >() ),
     rend3D( 0 )
 {
-    api = new DirectX11();
+    if( DirectX12::isAvailable() )
+        api = new DirectX12();
+    else
+        api = new DirectX11();
     api->initialize( fenster->getThis(), fenster->getKörperGröße(), 0 );
 }
 

+ 856 - 0
DX11GraphicsApi.cpp

@@ -0,0 +1,856 @@
+#include "GraphicsApi.h"
+#include "TexturModel.h"
+#include "TexturList.h"
+#include "Bild.h"
+#include "Fenster.h"
+#include "Shader.h"
+#include "DXBuffer.h"
+#include "Textur.h"
+#include "Globals.h"
+#include "DLLRegister.h"
+#include "UIVertexShader.h"
+#include "UIPixelShader.h"
+#include "Kam3D.h"
+#include "Welt3D.h"
+
+#include <d3d11.h>
+
+using namespace Framework;
+
+
+DirectX11::DirectX11()
+    : GraphicsApi( DIRECTX11 ),
+    d3d11Device( 0 ),
+    d3d11Context( 0 ),
+    d3d11SpawChain( 0 ),
+    uiTextur( 0 ),
+    vertexShader( 0 ),
+    pixelShader( 0 ),
+    sampleState( 0 ),
+    rtview( 0 ),
+    dsView( 0 ),
+    depthStencilBuffer( 0 ),
+    depthStencilState( 0 ),
+    depthDisabledStencilState( 0 ),
+    blendStateAlphaBlend( 0 ),
+    vp( 0 ),
+    texturModel( new TexturModel() ),
+    texturRegister( new TexturList() ),
+    texturRS( 0 ),
+    meshRS( 0 ),
+    defaultTextur( 0 ),
+    diffuseLights( 0 ),
+    pointLights( 0 ),
+    vertexBuffer( 0 ),
+    indexBuffer( 0 )
+{}
+
+DirectX11::~DirectX11()
+{
+    if( vertexBuffer )
+        vertexBuffer->release();
+    if( indexBuffer )
+        indexBuffer->release();
+    if( diffuseLights )
+        diffuseLights->release();
+    if( pointLights )
+        pointLights->release();
+    if( defaultTextur )
+        defaultTextur->release();
+    if( texturRS )
+        texturRS->Release();
+    if( meshRS )
+        meshRS->Release();
+    texturModel->release();
+    texturRegister->release();
+    if( blendStateAlphaBlend )
+    {
+        blendStateAlphaBlend->Release();
+        blendStateAlphaBlend = NULL;
+    }
+    if( uiTextur )
+    {
+        uiTextur->release();
+        uiTextur = NULL;
+    }
+    if( sampleState )
+    {
+        sampleState->Release();
+        sampleState = NULL;
+    }
+    if( pixelShader )
+    {
+        pixelShader->release();
+        pixelShader = NULL;
+    }
+    if( vertexShader )
+    {
+        vertexShader->release();
+        vertexShader = NULL;
+    }
+    if( depthDisabledStencilState )
+    {
+        depthDisabledStencilState->Release();
+        depthDisabledStencilState = NULL;
+    }
+    delete vp;
+    vp = 0;
+    if( dsView )
+    {
+        dsView->Release();
+        dsView = NULL;
+    }
+    if( depthStencilState )
+    {
+        depthStencilState->Release();
+        depthStencilState = NULL;
+    }
+    if( depthStencilBuffer )
+    {
+        depthStencilBuffer->Release();
+        depthStencilBuffer = NULL;
+    }
+    if( rtview )
+    {
+        rtview->Release();
+        rtview = NULL;
+    }
+    if( d3d11SpawChain )
+    {
+        d3d11SpawChain->Release();
+        d3d11SpawChain = NULL;
+    }
+    if( d3d11Device )
+    {
+        d3d11Device->Release();
+        d3d11Device = NULL;
+    }
+    if( d3d11Context )
+    {
+        d3d11Context->Release();
+        d3d11Context = NULL;
+        getDLLRegister()->releaseDLL( "d3d11.dll" );
+    }
+}
+
+typedef HRESULT( *D3D11CreateDeviceAndSwapChainFunction )( IDXGIAdapter *, D3D_DRIVER_TYPE,
+                                                           HMODULE, UINT, const D3D_FEATURE_LEVEL *,
+                                                           UINT, UINT, const DXGI_SWAP_CHAIN_DESC *,
+                                                           IDXGISwapChain **, ID3D11Device **,
+                                                           D3D_FEATURE_LEVEL *, ID3D11DeviceContext ** );
+
+void DirectX11::initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen )
+{
+    if( d3d11Device )
+        return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+    GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+    //--------------------------------------------------------------------
+    // Create Device
+
+    HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d11.dll", "d3d11.dll" );
+    if( !dll )
+    {
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    D3D11CreateDeviceAndSwapChainFunction createDeviceAndSwapChain = (D3D11CreateDeviceAndSwapChainFunction)GetProcAddress( dll, "D3D11CreateDeviceAndSwapChain" );
+    if( !createDeviceAndSwapChain )
+    {
+        getDLLRegister()->releaseDLL( "d3d11.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt D3D11CreateDeviceAndSwapChain fon DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+
+    // create a struct to hold information about the swap chain
+    DXGI_SWAP_CHAIN_DESC scd;
+
+    // clear out the struct for use
+    ZeroMemory( &scd, sizeof( DXGI_SWAP_CHAIN_DESC ) );
+
+    // fill the swap chain description struct
+    scd.BufferCount = 1;                                           // one back buffer
+    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;             // how swap chain is to be used
+    scd.OutputWindow = fenster ? fenster->getFensterHandle() : 0;  // the window to be used
+    scd.SampleDesc.Count = 1;
+    // Set the scan line ordering and scaling to unspecified.
+    scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
+    scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
+    scd.Windowed = !fullScreen;
+    scd.BufferDesc.Width = this->backBufferSize.x;
+    scd.BufferDesc.Height = this->backBufferSize.y;                 // windowed/full-screen mode
+    scd.BufferDesc.RefreshRate.Denominator = 1;
+    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;       // use 32-bit color
+                                                              // Discard the back buffer contents after presenting.
+    scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+
+    D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
+    D3D_FEATURE_LEVEL support = D3D_FEATURE_LEVEL_11_0;
+    // create a device, device context and swap chain using the information in the scd struct
+    UINT flag = 0;
+#ifdef _DEBUG
+    flag |= D3D11_CREATE_DEVICE_DEBUG;
+#endif
+    HRESULT result = createDeviceAndSwapChain( NULL,
+                                               D3D_DRIVER_TYPE_HARDWARE,
+                                               NULL,
+                                               flag,
+                                               &featureLevel,
+                                               1,
+                                               D3D11_SDK_VERSION,
+                                               &scd,
+                                               &d3d11SpawChain,
+                                               &d3d11Device,
+                                               &support,
+                                               &d3d11Context );
+    if( result != S_OK )
+    {
+        getDLLRegister()->releaseDLL( "d3d11.dll" );
+        std::cout << "ERROR: D3D11CreateDeviceAndSwapChain returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    ID3D11Texture2D *backBufferPtr;
+    // Get the pointer to the back buffer.
+    result = d3d11SpawChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID *)& backBufferPtr );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11SpawChain->GetBuffer returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    // Create the render target view with the back buffer pointer.
+    result = d3d11Device->CreateRenderTargetView( backBufferPtr, NULL, &rtview );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateRenderTargetView returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    // Release pointer to the back buffer as we no longer need it.
+    backBufferPtr->Release();
+    // Initialize the description of the depth buffer.
+    D3D11_TEXTURE2D_DESC depthBufferDesc;
+    ZeroMemory( &depthBufferDesc, sizeof( depthBufferDesc ) );
+    // Set up the description of the depth buffer.
+    depthBufferDesc.Width = this->backBufferSize.x;
+    depthBufferDesc.Height = this->backBufferSize.y;
+    depthBufferDesc.MipLevels = 1;
+    depthBufferDesc.ArraySize = 1;
+    depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+    depthBufferDesc.SampleDesc.Count = 1;
+    depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
+    depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+    // Create the texture for the depth buffer using the filled out description.
+    result = d3d11Device->CreateTexture2D( &depthBufferDesc, NULL, &depthStencilBuffer );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateTexture2D returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    // Initialize the description of the stencil state.
+    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
+    ZeroMemory( &depthStencilDesc, sizeof( depthStencilDesc ) );
+
+    // Set up the description of the stencil state.
+    depthStencilDesc.DepthEnable = true;
+    depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
+    depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
+    depthStencilDesc.StencilEnable = true;
+    depthStencilDesc.StencilReadMask = 0xFF;
+    depthStencilDesc.StencilWriteMask = 0xFF;
+    // Stencil operations if pixel is front-facing.
+    depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
+    depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+    // Stencil operations if pixel is back-facing.
+    depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
+    depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+    // Create the depth stencil state.
+    result = d3d11Device->CreateDepthStencilState( &depthStencilDesc, &depthStencilState );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
+
+    // Initialize the depth stencil view.
+    D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
+    ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) );
+
+    // Set up the depth stencil view description.
+    depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+    depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+
+    // Create the depth stencil view.
+    result = d3d11Device->CreateDepthStencilView( depthStencilBuffer, &depthStencilViewDesc, &dsView );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateDepthStencilView returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
+
+    vp = new D3D11_VIEWPORT();
+    memset( vp, 0, sizeof( D3D11_VIEWPORT ) );
+    vp->Width = (float)this->backBufferSize.x;
+    vp->Height = (float)this->backBufferSize.y;
+    vp->MinDepth = 0.0f;
+    vp->MaxDepth = 1.0f;
+    vp->TopLeftX = 0.0f;
+    vp->TopLeftY = 0.0f;
+
+    d3d11Context->RSSetViewports( 1, vp );
+
+    D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
+    // Clear the second depth stencil state before setting the parameters.
+    ZeroMemory( &depthDisabledStencilDesc, sizeof( depthDisabledStencilDesc ) );
+
+    // Now create a second depth stencil state which turns off the Z buffer for 2D rendering.  The only difference is 
+    // that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
+    depthDisabledStencilDesc.DepthEnable = false;
+    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
+    depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
+    depthDisabledStencilDesc.StencilEnable = true;
+    depthDisabledStencilDesc.StencilReadMask = 0xFF;
+    depthDisabledStencilDesc.StencilWriteMask = 0xFF;
+    depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
+    depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+    depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
+    depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+
+    // Create the state using the device.
+    result = d3d11Device->CreateDepthStencilState( &depthDisabledStencilDesc, &depthDisabledStencilState );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    //-------------------------------------------------
+    // Shaders
+    vertexShader = new DX11VertexShader( d3d11Device, d3d11Context );
+    vertexShader->setCompiledByteArray( (unsigned char *)UIVertexShader, sizeof( UIVertexShader ) );
+
+    pixelShader = new DX11PixelShader( d3d11Device, d3d11Context );
+    pixelShader->setCompiledByteArray( (unsigned char *)UIPixelShader, sizeof( UIPixelShader ) );
+
+    D3D11_INPUT_ELEMENT_DESC polygonLayout[ 4 ];
+    // Create the vertex input layout description.
+    // This setup needs to match the VertexType stucture in the ModelClass and in the shader.
+    polygonLayout[ 0 ].SemanticName = "POSITION";
+    polygonLayout[ 0 ].SemanticIndex = 0;
+    polygonLayout[ 0 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
+    polygonLayout[ 0 ].InputSlot = 0;
+    polygonLayout[ 0 ].AlignedByteOffset = 0;
+    polygonLayout[ 0 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
+    polygonLayout[ 0 ].InstanceDataStepRate = 0;
+
+    polygonLayout[ 1 ].SemanticName = "TEXCOORD";
+    polygonLayout[ 1 ].SemanticIndex = 0;
+    polygonLayout[ 1 ].Format = DXGI_FORMAT_R32G32_FLOAT;
+    polygonLayout[ 1 ].InputSlot = 0;
+    polygonLayout[ 1 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
+    polygonLayout[ 1 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
+    polygonLayout[ 1 ].InstanceDataStepRate = 0;
+
+    polygonLayout[ 2 ].SemanticName = "NORMAL";
+    polygonLayout[ 2 ].SemanticIndex = 0;
+    polygonLayout[ 2 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
+    polygonLayout[ 2 ].InputSlot = 0;
+    polygonLayout[ 2 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
+    polygonLayout[ 2 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
+    polygonLayout[ 2 ].InstanceDataStepRate = 0;
+
+    polygonLayout[ 3 ].SemanticName = "KNOCHEN_ID";
+    polygonLayout[ 3 ].SemanticIndex = 0;
+    polygonLayout[ 3 ].Format = DXGI_FORMAT_R32_UINT;
+    polygonLayout[ 3 ].InputSlot = 0;
+    polygonLayout[ 3 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
+    polygonLayout[ 3 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
+    polygonLayout[ 3 ].InstanceDataStepRate = 0;
+
+    vertexShader->erstelleInputLayout( polygonLayout, 4 );
+    vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 ); // matrizen für skelett annimationen
+    vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * 2, 1 ); // View and Projection Matrix
+
+    pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 0 ); // Kamera Position
+    pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 1 ); // materialkonstanten nach phong model
+    pixelShader->erstelleConstBuffer( sizeof( int ) * 2, 2 ); // materialkonstanten nach phong model
+    // TODO: Remove Following Test Code
+    int lc[] = { 1, 6 };
+    pixelShader->füllConstBuffer( (char *)lc, 2, sizeof( int ) * 2 );
+
+    // Create a texture sampler state description.
+    D3D11_SAMPLER_DESC samplerDesc;
+    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
+    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
+    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
+    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
+    samplerDesc.MipLODBias = 0.0f;
+    samplerDesc.MaxAnisotropy = 1;
+    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
+    samplerDesc.BorderColor[ 0 ] = 0;
+    samplerDesc.BorderColor[ 1 ] = 0;
+    samplerDesc.BorderColor[ 2 ] = 0;
+    samplerDesc.BorderColor[ 3 ] = 0;
+    samplerDesc.MinLOD = 0;
+    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
+
+    // Create the texture sampler state.
+    result = d3d11Device->CreateSamplerState( &samplerDesc, &sampleState );
+    if( result != S_OK )
+    {
+        std::cout << "ERROR: d3d11Device->CreateSamplerState returned " << result << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
+        return;
+    }
+    //---------------------------------------------------------------
+    // Framework Backbuffer Texture
+    Bild *renderB = new Bild( 1 );
+    renderB->setAlpha3D( 1 );
+    renderB->neuBild( this->backBufferSize.x, this->backBufferSize.y, 0 );
+
+    uiTextur = createOrGetTextur( "_f_Render_Bild", renderB );
+
+    texturModel->setSize( this->backBufferSize );
+    texturModel->setTextur( uiTextur->getThis() );
+
+    D3D11_BLEND_DESC blendState;
+    ZeroMemory( &blendState, sizeof( D3D11_BLEND_DESC ) );
+    blendState.AlphaToCoverageEnable = false;
+    blendState.IndependentBlendEnable = false;
+    blendState.RenderTarget[ 0 ].BlendEnable = true;
+    blendState.RenderTarget[ 0 ].SrcBlend = D3D11_BLEND_SRC_ALPHA;
+    blendState.RenderTarget[ 0 ].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
+    blendState.RenderTarget[ 0 ].BlendOp = D3D11_BLEND_OP_ADD;
+    blendState.RenderTarget[ 0 ].SrcBlendAlpha = D3D11_BLEND_ZERO;
+    blendState.RenderTarget[ 0 ].DestBlendAlpha = D3D11_BLEND_ONE;
+    blendState.RenderTarget[ 0 ].BlendOpAlpha = D3D11_BLEND_OP_ADD;
+    blendState.RenderTarget[ 0 ].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
+
+    d3d11Device->CreateBlendState( &blendState, &blendStateAlphaBlend );
+    d3d11Context->OMSetBlendState( blendStateAlphaBlend, 0, 0xFFFFFFFF );
+
+    // Setup Render Objekt
+
+    vertexShader->benutzeShader();
+    d3d11Context->PSSetSamplers( 0, 1, &sampleState );
+    pixelShader->benutzeShader();
+
+    D3D11_RASTERIZER_DESC rasterDesc;
+    ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
+    rasterDesc.AntialiasedLineEnable = false;
+    rasterDesc.CullMode = D3D11_CULL_BACK;
+    rasterDesc.DepthBiasClamp = 0.0f;
+    rasterDesc.DepthClipEnable = true;
+    rasterDesc.FillMode = D3D11_FILL_SOLID;
+    rasterDesc.FrontCounterClockwise = false;
+    rasterDesc.MultisampleEnable = false;
+    rasterDesc.ScissorEnable = false;
+    rasterDesc.SlopeScaledDepthBias = 0.0f;
+    d3d11Device->CreateRasterizerState( &rasterDesc, &texturRS );
+
+    ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
+    rasterDesc.AntialiasedLineEnable = false;
+    rasterDesc.CullMode = D3D11_CULL_BACK;
+    rasterDesc.DepthBiasClamp = 0.0f;
+    rasterDesc.DepthClipEnable = true;
+    rasterDesc.FillMode = D3D11_FILL_WIREFRAME;
+    rasterDesc.FrontCounterClockwise = false;
+    rasterDesc.MultisampleEnable = false;
+    rasterDesc.ScissorEnable = false;
+    rasterDesc.SlopeScaledDepthBias = 0.0f;
+    d3d11Device->CreateRasterizerState( &rasterDesc, &meshRS );
+
+    d3d11Context->RSSetState( texturRS );
+
+    Bild *b = new Bild();
+    b->neuBild( 10, 10, 0xFFFFFFFF );
+    defaultTextur = createOrGetTextur( "_default_textur", b );
+
+    vertexBuffer = new DX11Buffer( sizeof( Vertex3D ), d3d11Device, d3d11Context, D3D11_BIND_VERTEX_BUFFER );
+    indexBuffer = new DX11Buffer( sizeof( int ), d3d11Device, d3d11Context, D3D11_BIND_INDEX_BUFFER );
+
+    DiffuseLight dl[ 1 ];
+    dl[ 0 ].direction = Vec3< float >( -0.5f, -0.5f, -0.5f ).normalize();
+    dl[ 0 ].color = Vec3<float>( 1.f, 0.f, 0.f );
+    diffuseLights = new DX11StructuredBuffer( sizeof( DiffuseLight ), d3d11Device, d3d11Context );
+    diffuseLights->setData( dl );
+    diffuseLights->setLength( sizeof( dl ) );
+    diffuseLights->copieren();
+    PointLight pl[ 6 ];
+    pl[ 0 ].position = Vec3< float >( 0, 130, 0 );
+    pl[ 0 ].color = Vec3< float >( 1.f, 1.f, 0.f );
+    pl[ 0 ].radius = 100;
+    pl[ 1 ].position = Vec3< float >( 150, 130, 0 );
+    pl[ 1 ].color = Vec3< float >( 0.f, 1.f, 0.f );
+    pl[ 1 ].radius = 100;
+    pl[ 2 ].position = Vec3< float >( 150, 130, 150 );
+    pl[ 2 ].color = Vec3< float >( 0.f, 0.f, 1.f );
+    pl[ 2 ].radius = 100;
+    pl[ 3 ].position = Vec3< float >( -150, 130, 0 );
+    pl[ 3 ].color = Vec3< float >( 1.f, 0.f, 1.f );
+    pl[ 3 ].radius = 100;
+    pl[ 4 ].position = Vec3< float >( 0, 130, 150 );
+    pl[ 4 ].color = Vec3< float >( 0.f, 1.f, 1.f );
+    pl[ 4 ].radius = 100;
+    pl[ 5 ].position = Vec3< float >( -150, 130, 150 );
+    pl[ 5 ].color = Vec3< float >( 1.f, 0.f, 0.f );
+    pl[ 5 ].radius = 100;
+    pointLights = new DX11StructuredBuffer( sizeof( PointLight ), d3d11Device, d3d11Context );
+    pointLights->setData( pl );
+    pointLights->setLength( sizeof( pl ) * 6 );
+    pointLights->copieren();
+}
+
+void DirectX11::update()
+{
+    if( vertexBuffer )
+        vertexBuffer = (DX11Buffer *)vertexBuffer->release();
+    if( indexBuffer )
+        indexBuffer = (DX11Buffer *)indexBuffer->release();
+    if( texturRS )
+    {
+        texturRS->Release();
+        texturRS = NULL;
+    }
+    if( meshRS )
+    {
+        meshRS->Release();
+        meshRS = NULL;
+    }
+    texturRegister->leeren();
+    if( defaultTextur )
+        defaultTextur = defaultTextur->release();
+    if( blendStateAlphaBlend )
+    {
+        blendStateAlphaBlend->Release();
+        blendStateAlphaBlend = NULL;
+    }
+    if( uiTextur )
+    {
+        uiTextur->release();
+        uiTextur = NULL;
+    }
+    if( sampleState )
+    {
+        sampleState->Release();
+        sampleState = NULL;
+    }
+    if( pixelShader )
+    {
+        pixelShader->release();
+        pixelShader = NULL;
+    }
+    if( vertexShader )
+    {
+        vertexShader->release();
+        vertexShader = NULL;
+    }
+    if( depthDisabledStencilState )
+    {
+        depthDisabledStencilState->Release();
+        depthDisabledStencilState = NULL;
+    }
+    delete vp;
+    vp = 0;
+    if( dsView )
+    {
+        dsView->Release();
+        dsView = NULL;
+    }
+    if( depthStencilState )
+    {
+        depthStencilState->Release();
+        depthStencilState = NULL;
+    }
+    if( depthStencilBuffer )
+    {
+        depthStencilBuffer->Release();
+        depthStencilBuffer = NULL;
+    }
+    if( rtview )
+    {
+        rtview->Release();
+        rtview = NULL;
+    }
+    if( d3d11SpawChain )
+    {
+        d3d11SpawChain->Release();
+        d3d11SpawChain = NULL;
+    }
+    if( d3d11Device )
+    {
+        d3d11Device->Release();
+        d3d11Device = NULL;
+    }
+    if( d3d11Context )
+    {
+        d3d11Context->Release();
+        d3d11Context = NULL;
+    }
+    initialize( fenster->getThis(), backBufferSize, fullScreen );
+}
+
+void DirectX11::beginFrame( bool fill2D, bool fill3D, int fillColor )
+{
+    if( fill2D )
+        uiTextur->zBild()->setFarbe( fillColor );
+    if( fill3D )
+    {
+        float color[ 4 ];
+        // Setup the color to clear the buffer.
+        color[ 0 ] = ( ( fillColor >> 16 ) & 0xFF ) / 255.f; // R
+        color[ 1 ] = ( ( fillColor >> 8 ) & 0xFF ) / 255.f; // G
+        color[ 2 ] = ( fillColor & 0xFF ) / 255.f; // B
+        color[ 3 ] = ( ( fillColor >> 24 ) & 0xFF ) / 255.f; // A
+        d3d11Context->ClearRenderTargetView( rtview, color );
+        // Clear the depth buffer.
+        d3d11Context->ClearDepthStencilView( dsView, D3D11_CLEAR_DEPTH, 1, 0 );
+    }
+    // Bind the render target view and depth stencil buffer to the output render pipeline.
+    d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
+    // Set the depth stencil state.
+    d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
+}
+
+void DirectX11::renderObject( Model3D * zObj )
+{
+    vertexBuffer->setData( (void *)zObj->zVertexBuffer() );
+    vertexBuffer->setLength( sizeof( Vertex3D ) * zObj->getVertexAnzahl() );
+    vertexBuffer->copieren();
+    Mat4< float > trans = Mat4< float >::identity();
+    int anz = zObj->errechneMatrizen( trans, matrixBuffer );
+    if( vertexShader )
+        vertexShader->füllConstBuffer( (char *)matrixBuffer, 0, sizeof( Mat4< float > ) * anz );
+    float matirialBuffer[ 3 ]; // light factors (phong model)
+    matirialBuffer[ 0 ] = zObj->getAmbientFactor();
+    matirialBuffer[ 1 ] = zObj->getDiffusFactor();
+    matirialBuffer[ 2 ] = zObj->getSpecularFactor();
+    if( pixelShader )
+        pixelShader->füllConstBuffer( (char *)matirialBuffer, 1, sizeof( float ) * 3 );
+    unsigned int offset = 0;
+    unsigned int es = (unsigned)vertexBuffer->getElementLength();
+    ID3D11Buffer * vBuffer = vertexBuffer->zBuffer();
+    d3d11Context->IASetVertexBuffers( 0, 1, &vBuffer, &es, &offset );
+    Model3DTextur * zTextur = zObj->zTextur();
+    int ind = 0;
+    for( auto i = zObj->zModelData()->getPolygons(); i; i++ )
+    {
+        indexBuffer->setData( i->indexList );
+        indexBuffer->setLength( sizeof( int ) * i->indexAnz );
+        indexBuffer->copieren();
+        Textur *t = zTextur->zPolygonTextur( ind );
+        if( t &&t->brauchtUpdate() )
+            t->updateTextur();
+        DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
+        if( indexBuffer->getElementLength() == 2 )
+            f = DXGI_FORMAT_R16_UINT;
+        if( indexBuffer->getElementLength() == 1 )
+            f = DXGI_FORMAT_R8_UINT;
+        d3d11Context->IASetIndexBuffer( indexBuffer->zBuffer(), f, 0 );
+        d3d11Context->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
+        if( t )
+        {
+            ID3D11ShaderResourceView *v[ 3 ];
+            v[ 0 ] = *(DX11Textur *)t;
+            v[ 1 ] = *diffuseLights;
+            v[ 2 ] = *pointLights;
+            d3d11Context->PSSetShaderResources( 0, 3, v );
+            d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
+        }
+        else
+        {
+            d3d11Context->RSSetState( meshRS );
+            ID3D11ShaderResourceView *v[ 3 ];
+            v[ 0 ] = *(DX11Textur *)defaultTextur;
+            v[ 1 ] = *diffuseLights;
+            v[ 2 ] = *pointLights;
+            d3d11Context->PSSetShaderResources( 0, 3, v );
+            d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
+            d3d11Context->RSSetState( texturRS );
+        }
+        ind++;
+    }
+}
+
+// Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
+//  pos: Der Mittelpunkt der Kugel
+//  radius: Der Radius der Kugel
+//  dist: Einen Zeiger auf einen float, in dem das quadrat des Abstands zur Kammeraposition gespeichert wird, falls diese Funktion true zurückgiebt und der Zeiger nicht 0 ist
+bool DirectX11::isInFrustrum( const Vec3< float > & pos, float radius, float *dist ) const
+{
+    for( int i = 0; i < 6; i++ )
+    {
+        if( frustrum[ i ] * pos + radius < 0 )
+            return 0;
+    }
+    if( dist )
+        * dist = kamPos.abstand( pos );
+    return 1;
+}
+
+void DirectX11::renderKamera( Kam3D * zKamera )
+{
+    d3d11Context->RSSetViewports( 1, (D3D11_VIEWPORT *)zKamera->zViewPort() );
+
+    Mat4< float > tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
+
+    frustrum[ 0 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 0 ][ 0 ];
+    frustrum[ 0 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 0 ][ 1 ];
+    frustrum[ 0 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 0 ][ 2 ];
+    frustrum[ 0 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 0 ][ 3 ];
+
+    frustrum[ 1 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 0 ][ 0 ];
+    frustrum[ 1 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 0 ][ 1 ];
+    frustrum[ 1 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 0 ][ 2 ];
+    frustrum[ 1 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 0 ][ 3 ];
+
+    frustrum[ 2 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 1 ][ 0 ];
+    frustrum[ 2 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 1 ][ 1 ];
+    frustrum[ 2 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 1 ][ 2 ];
+    frustrum[ 2 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 1 ][ 3 ];
+
+    frustrum[ 3 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 1 ][ 0 ];
+    frustrum[ 3 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 1 ][ 1 ];
+    frustrum[ 3 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 1 ][ 2 ];
+    frustrum[ 3 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 1 ][ 3 ];
+
+    frustrum[ 4 ].x = tmp.elements[ 2 ][ 0 ];
+    frustrum[ 4 ].y = tmp.elements[ 2 ][ 1 ];
+    frustrum[ 4 ].z = tmp.elements[ 2 ][ 2 ];
+    frustrum[ 4 ].w = tmp.elements[ 2 ][ 3 ];
+
+    frustrum[ 5 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 2 ][ 0 ];
+    frustrum[ 5 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 2 ][ 1 ];
+    frustrum[ 5 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 2 ][ 2 ];
+    frustrum[ 5 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 2 ][ 3 ];
+
+    for( int i = 0; i < 6; i++ )
+        frustrum[ i ].normalize();
+
+    viewAndProj[ 0 ] = zKamera->getViewMatrix();
+    viewAndProj[ 1 ] = zKamera->getProjectionMatrix();
+    kamPos = zKamera->getWorldPosition();
+    if( vertexShader )
+        vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
+    if( pixelShader )
+        pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
+    Welt3D * w = zKamera->zWelt();
+    w->lock();
+    int alphaAnzahl = 0;
+    int maxDist = 0;
+    int minDist = 0x7FFFFFFF;
+    for( auto obj = w->getMembers(); obj; obj++ )
+    {
+        float dist;
+        if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
+        {
+            if( (int)dist > maxDist )
+                maxDist = (int)dist;
+            if( minDist < (int)dist )
+                minDist = (int)dist;
+            if( obj->hatAlpha() )
+                alphaAnzahl++;
+            else
+                renderObject( obj._ );
+        }
+    }
+    maxDist++;
+    if( alphaAnzahl )
+    {
+        int size = maxDist - minDist;
+        int *index = new int[ size ];
+        Model3D **sorted = new Model3D * [ size * alphaAnzahl ];
+        for( auto obj = w->getMembers(); obj; obj++ )
+        {
+            float dist;
+            if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
+            {
+                if( obj->hatAlpha() )
+                {
+                    int pos = (int)dist - minDist;
+                    sorted[ pos * alphaAnzahl + index[ pos ]++ ] = obj._;
+                }
+            }
+        }
+        for( int i = 0; i < size; i++ )
+        {
+            for( int j = 0; j < index[ i ]; j++ )
+            {
+                renderObject( sorted[ i * alphaAnzahl + j ] );
+            }
+        }
+        delete[] index;
+        delete[] sorted;
+    }
+    w->unlock();
+}
+
+void DirectX11::presentFrame()
+{
+    // Set the depth stencil state.
+    d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
+
+    uiTextur->updateTextur();
+
+    d3d11Context->RSSetViewports( 1, vp );
+
+    float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
+    Mat4< float > view = view.translation( Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
+    viewAndProj[ 0 ] = view;
+    viewAndProj[ 1 ] = view.projektion( (float)PI / 4.0f, screenAspect, 0.1f, 10000.f );
+    kamPos = Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f );
+    if( vertexShader )
+        vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
+    if( pixelShader )
+        pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
+
+    if( fenster && !IsIconic( fenster->getFensterHandle() ) )
+        renderObject( texturModel );
+
+    HRESULT result = d3d11SpawChain->Present( 0, 0 );
+    if( !SUCCEEDED( result ) )
+    {
+        update();
+        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
+    }
+}
+
+Bild *DirectX11::zUIRenderBild() const
+{
+    return uiTextur->zBild();
+}
+
+Textur *DirectX11::createOrGetTextur( const char *name, Bild * b )
+{
+    if( !d3d11Device )
+    {
+        if( b )
+            b->release();
+        return 0;
+    }
+    if( texturRegister->hatTextur( name ) )
+    {
+        Textur *ret = texturRegister->getTextur( name );
+        if( b )
+            ret->setBildZ( b );
+        return ret;
+    }
+    Textur *ret = new DX11Textur( d3d11Device, d3d11Context );
+    if( b )
+        ret->setBildZ( b );
+    texturRegister->addTextur( ret->getThis(), name );
+    return ret;
+}

+ 527 - 0
DX12GraphicsApi.cpp

@@ -0,0 +1,527 @@
+#include "GraphicsApi.h"
+#include "Globals.h"
+#include "DLLRegister.h"
+#include "Fenster.h"
+
+#include <d3d11.h>
+#include <d3d12.h>
+#include <dxgi1_5.h>
+
+using namespace Framework;
+
+
+DirectX12::DirectX12()
+    : GraphicsApi( DIRECTX12 ),
+    device( 0 ),
+    infoQueue( 0 ),
+    directCommandQueue( 0 ),
+    swapChain( 0 ),
+    rtvHeap( 0 ),
+    directCommandList( 0 ),
+    backBufferIndex( 0 ),
+    tearing( 0 ),
+    fence( 0 ),
+    fenceEvent( 0 )
+{
+    for( int i = 0; i < 2; i++ )
+    {
+        fenceValue[ i ] = 0;
+        backBuffer[ i ] = 0;
+        directCommandAllocator[ i ] = 0;
+    }
+}
+
+DirectX12::~DirectX12()
+{
+    if( directCommandQueue && fence && fenceEvent )
+    {
+        unsigned __int64 val = ++fenceValue[ backBufferIndex ];
+        directCommandQueue->Signal( fence, val );
+        if( fence->GetCompletedValue() < val )
+        {
+            fence->SetEventOnCompletion( val, fenceEvent );
+            WaitForSingleObject( fenceEvent, INFINITE );
+        }
+    }
+    if( fence )
+        fence->Release();
+    if( directCommandList )
+        directCommandList->Release();
+    for( int i = 0; i < 2; i++ )
+    {
+        if( directCommandAllocator[ i ] )
+            directCommandAllocator[ i ]->Release();
+        if( backBuffer[ i ] )
+            backBuffer[ i ]->Release();
+    }
+    if( rtvHeap )
+        rtvHeap->Release();
+    if( swapChain )
+        swapChain->Release();
+    if( directCommandQueue )
+        directCommandQueue->Release();
+    if( infoQueue )
+        infoQueue->Release();
+    if( device )
+    {
+        device->Release();
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+    }
+}
+
+typedef HRESULT( *CreateDXGIFactory2Function )( UINT, REFIID, void ** );
+
+typedef HRESULT( *D3D12CreateDeviceFunction )( IDXGIAdapter *, D3D_FEATURE_LEVEL,
+                                               REFIID, void ** );
+
+void DirectX12::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
+{
+    if( device )
+        return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+    GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+
+    HINSTANCE dxgiDLL = getDLLRegister()->ladeDLL( "dxgi.dll", "dxgi.dll" );
+    if( !dxgiDLL )
+    {
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "dxgi.dll konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    HINSTANCE d3d12DLL = getDLLRegister()->ladeDLL( "d3d12.dll", "d3d12.dll" );
+    if( !d3d12DLL )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 12 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    CreateDXGIFactory2Function createFactory = (CreateDXGIFactory2Function)GetProcAddress( dxgiDLL, "CreateDXGIFactory2" );
+    if( !createFactory )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt CreateDXGIFactory2 fon DXGI konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    D3D12CreateDeviceFunction createDevice = (D3D12CreateDeviceFunction)GetProcAddress( d3d12DLL, "D3D12CreateDevice" );
+    if( !createDevice )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt D3D12CreateDevice fon DirectX 12 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    IDXGIFactory4 *factory;
+    UINT createFactoryFlags = 0;
+#if defined(_DEBUG)
+    createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;
+#endif
+    HRESULT res = createFactory( createFactoryFlags, __uuidof( IDXGIFactory4 ), (void **)& factory );
+    if( FAILED( res ) )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        std::cout << "ERROR: createFactory returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "createFactory ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    int index = 0;
+    unsigned __int64 maxVideoMemory = 0;
+    IDXGIAdapter1 *best = 0;
+    do
+    {
+        IDXGIAdapter1 *current;
+        res = factory->EnumAdapters1( index++, &current );
+        if( res == S_OK )
+        {
+            DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
+            current->GetDesc1( &dxgiAdapterDesc1 );
+            if( ( dxgiAdapterDesc1.Flags &DXGI_ADAPTER_FLAG_SOFTWARE ) == 0 &&
+                dxgiAdapterDesc1.DedicatedVideoMemory > maxVideoMemory &&
+                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), 0 ) ) )
+            {
+                if( best )
+                    best->Release();
+                best = current;
+                maxVideoMemory = dxgiAdapterDesc1.DedicatedVideoMemory;
+            }
+            else
+                current->Release();
+        }
+    } while( res != DXGI_ERROR_NOT_FOUND );
+    res = createDevice( best, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), (void **)& device );
+    best->Release();
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        std::cout << "ERROR: createDevice returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "createDevice ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    res = device->QueryInterface( __uuidof( ID3D12InfoQueue ), (void **)& infoQueue );
+    if( SUCCEEDED( res ) )
+    {
+        infoQueue->SetBreakOnSeverity( D3D12_MESSAGE_SEVERITY_CORRUPTION, TRUE );
+        infoQueue->SetBreakOnSeverity( D3D12_MESSAGE_SEVERITY_ERROR, TRUE );
+        infoQueue->SetBreakOnSeverity( D3D12_MESSAGE_SEVERITY_WARNING, TRUE );
+
+        D3D12_MESSAGE_SEVERITY Severities[] =
+        {
+            D3D12_MESSAGE_SEVERITY_INFO
+        };
+
+        // Suppress individual messages by their ID
+        D3D12_MESSAGE_ID DenyIds[] = {
+            D3D12_MESSAGE_ID_CLEARRENDERTARGETVIEW_MISMATCHINGCLEARVALUE,   // I'm really not sure how to avoid this message.
+            D3D12_MESSAGE_ID_MAP_INVALID_NULLRANGE,                         // This warning occurs when using capture frame while graphics debugging.
+            D3D12_MESSAGE_ID_UNMAP_INVALID_NULLRANGE,                       // This warning occurs when using capture frame while graphics debugging.
+        };
+
+        D3D12_INFO_QUEUE_FILTER NewFilter = {};
+        NewFilter.DenyList.NumSeverities = _countof( Severities );
+        NewFilter.DenyList.pSeverityList = Severities;
+        NewFilter.DenyList.NumIDs = _countof( DenyIds );
+        NewFilter.DenyList.pIDList = DenyIds;
+
+        infoQueue->PushStorageFilter( &NewFilter );
+    }
+
+    D3D12_COMMAND_QUEUE_DESC desc = {};
+    desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
+    desc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
+    desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
+    desc.NodeMask = 0;
+    res = device->CreateCommandQueue( &desc, __uuidof( ID3D12CommandQueue ), (void **)& directCommandQueue );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateCommandQueue returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateCommandQueue ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+
+    IDXGIFactory5 *fac5 = 0;
+    factory->QueryInterface( __uuidof( IDXGIFactory5 ), (void **)& fac5 );
+    if( fac5 )
+    {
+        res = fac5->CheckFeatureSupport( DXGI_FEATURE_PRESENT_ALLOW_TEARING, &tearing, sizeof( tearing ) );
+        if( FAILED( res ) )
+            tearing = 0;
+        fac5->Release();
+    }
+
+    DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
+    swapChainDesc.Width = backBufferSize.x;
+    swapChainDesc.Height = backBufferSize.y;
+    swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+    swapChainDesc.Stereo = FALSE;
+    swapChainDesc.SampleDesc = { 1, 0 };
+    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+    swapChainDesc.BufferCount = 2;
+    swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
+    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
+    swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
+    swapChainDesc.Flags = tearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
+    IDXGISwapChain1 *tmpSwapChain;
+    res = factory->CreateSwapChainForHwnd( directCommandQueue, fenster->getFensterHandle(), &swapChainDesc, 0, 0, &tmpSwapChain );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateSwapChainForHwnd returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateSwapChainForHwnd ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    res = tmpSwapChain->QueryInterface( __uuidof( IDXGISwapChain4 ), (void**)&swapChain );
+    tmpSwapChain->Release();
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: QueryInterface returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "QueryInterface ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    factory->MakeWindowAssociation( fenster->getFensterHandle(), DXGI_MWA_NO_ALT_ENTER );
+
+    D3D12_DESCRIPTOR_HEAP_DESC rtvhdesc = {};
+    rtvhdesc.NumDescriptors = 2;
+    rtvhdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
+    res = device->CreateDescriptorHeap( &rtvhdesc, __uuidof( ID3D12DescriptorHeap ), (void **)& rtvHeap );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateDescriptorHeap returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateDescriptorHeap ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+
+    auto rtvDescriptorSize = device->GetDescriptorHandleIncrementSize( D3D12_DESCRIPTOR_HEAP_TYPE_RTV );
+    D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle( rtvHeap->GetCPUDescriptorHandleForHeapStart() );
+
+    for( int i = 0; i < 2; i++ )
+    {
+        ID3D12Resource *backBuffer;
+        res = swapChain->GetBuffer( i, __uuidof( ID3D12Resource ), (void **)& backBuffer );
+        if( FAILED( res ) )
+        {
+            factory->Release();
+            std::cout << "ERROR: GetBuffer returned " << res << "\n";
+            WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "GetBuffer ist Fehlgeschlagen." ), MB_ICONERROR );
+            return;
+        }
+
+        device->CreateRenderTargetView( backBuffer, nullptr, rtvHandle );
+
+        this->backBuffer[ i ] = backBuffer;
+
+        rtvHandle.ptr += rtvDescriptorSize;
+    }
+
+    res = device->CreateCommandAllocator( D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof( ID3D12CommandAllocator ), (void **)& directCommandAllocator[ 0 ] );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateCommandAllocator returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateCommandAllocator ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    res = device->CreateCommandAllocator( D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof( ID3D12CommandAllocator ), (void **)& directCommandAllocator[ 1 ] );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateCommandAllocator returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateCommandAllocator ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    res = device->CreateCommandList( 0, D3D12_COMMAND_LIST_TYPE_DIRECT, directCommandAllocator[ 0 ], nullptr, __uuidof( ID3D12GraphicsCommandList ), (void **)& directCommandList );
+    if( FAILED( res ) )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateCommandList returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateCommandList ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    device->CreateFence( 0, D3D12_FENCE_FLAG_NONE, __uuidof( ID3D12Fence ), (void **)&fence );
+    fenceEvent = CreateEvent( 0, 0, 0, 0 );
+    if( !fenceEvent )
+    {
+        factory->Release();
+        std::cout << "ERROR: CreateEvent returned 0\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "CreateEvent ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    factory->Release();
+}
+
+void DirectX12::update()
+{
+    if( !device || !swapChain || !fence || !directCommandQueue || !fenceEvent )
+        return;
+    unsigned __int64 val = ++fenceValue[ backBufferIndex ];
+    directCommandQueue->Signal( fence, val );
+    if( fence->GetCompletedValue() < val )
+    {
+        fence->SetEventOnCompletion( val, fenceEvent );
+        WaitForSingleObject( fenceEvent, INFINITE );
+    }
+    HINSTANCE dxgiDLL = getDLLRegister()->ladeDLL( "dxgi.dll", "dxgi.dll" );
+    if( !dxgiDLL )
+    {
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "dxgi.dll konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    CreateDXGIFactory2Function createFactory = (CreateDXGIFactory2Function)GetProcAddress( dxgiDLL, "CreateDXGIFactory2" );
+    if( !createFactory )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt CreateDXGIFactory2 fon DXGI konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
+    HRESULT res = swapChain->GetDesc( &swapChainDesc );
+    if( FAILED( res ) )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        std::cout << "ERROR: GetDesc returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "GetDesc ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    IDXGIFactory4 *factory;
+    UINT createFactoryFlags = 0;
+#if defined(_DEBUG)
+    createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;
+#endif
+    res = createFactory( createFactoryFlags, __uuidof( IDXGIFactory4 ), (void **)& factory );
+    if( FAILED( res ) )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        std::cout << "ERROR: createFactory returned " << res << "\n";
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "createFactory ist Fehlgeschlagen." ), MB_ICONERROR );
+        return;
+    }
+    for( int i = 0; i < 2; ++i )
+    {
+        backBuffer[ i ]->Release();
+        backBuffer[ i ] = 0;
+    }
+    res = swapChain->ResizeBuffers( 2, backBufferSize.x, backBufferSize.y,
+                                    swapChainDesc.BufferDesc.Format, swapChainDesc.Flags );
+    backBufferIndex = swapChain->GetCurrentBackBufferIndex();
+
+    auto rtvDescriptorSize = device->GetDescriptorHandleIncrementSize( D3D12_DESCRIPTOR_HEAP_TYPE_RTV );
+    D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle( rtvHeap->GetCPUDescriptorHandleForHeapStart() );
+    
+    for( int i = 0; i < 2; i++ )
+    {
+        ID3D12Resource *backBuffer;
+        res = swapChain->GetBuffer( i, __uuidof( ID3D12Resource ), (void **)& backBuffer );
+        if( FAILED( res ) )
+        {
+            getDLLRegister()->releaseDLL( "dxgi.dll" );
+            factory->Release();
+            std::cout << "ERROR: GetBuffer returned " << res << "\n";
+            WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "GetBuffer ist Fehlgeschlagen." ), MB_ICONERROR );
+            return;
+        }
+
+        device->CreateRenderTargetView( backBuffer, nullptr, rtvHandle );
+
+        this->backBuffer[ i ] = backBuffer;
+
+        rtvHandle.ptr += rtvDescriptorSize;
+    }
+    getDLLRegister()->releaseDLL( "dxgi.dll" );
+    factory->Release();
+}
+
+void DirectX12::beginFrame( bool fill2D, bool fill3D, int fillColor )
+{
+    D3D12_RESOURCE_BARRIER barrier;
+    ZeroMemory( &barrier, sizeof( barrier ) );
+    barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+    barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
+    barrier.Transition.pResource = this->backBuffer[ backBufferIndex ];
+    barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
+    barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
+    barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+
+    directCommandList->ResourceBarrier( 1, &barrier );
+
+    if( fill3D )
+    {
+        float color[ 4 ];
+        // Setup the color to clear the buffer.
+        color[ 0 ] = ( ( fillColor >> 16 ) & 0xFF ) / 255.f; // R
+        color[ 1 ] = ( ( fillColor >> 8 ) & 0xFF ) / 255.f; // G
+        color[ 2 ] = ( fillColor & 0xFF ) / 255.f; // B
+        color[ 3 ] = ( ( fillColor >> 24 ) & 0xFF ) / 255.f; // A
+
+        auto rtvDescriptorSize = device->GetDescriptorHandleIncrementSize( D3D12_DESCRIPTOR_HEAP_TYPE_RTV );
+        D3D12_CPU_DESCRIPTOR_HANDLE rtv = rtvHeap->GetCPUDescriptorHandleForHeapStart();
+        rtv.ptr += rtvDescriptorSize * backBufferIndex;
+
+        directCommandList->ClearRenderTargetView( rtv, color, 0, 0 );
+    }
+}
+
+void DirectX12::renderKamera( Kam3D * zKamera )
+{
+
+}
+
+void DirectX12::presentFrame()
+{
+    directCommandList->Close();
+    directCommandQueue->ExecuteCommandLists( 1, (ID3D12CommandList**)&directCommandList );
+
+    // TODO: Render Framework GUI
+
+    swapChain->Present( 0, tearing ? DXGI_PRESENT_ALLOW_TEARING : 0 );
+
+    directCommandQueue->Signal( fence, ++fenceValue[ backBufferIndex ] );
+
+    if( fence->GetCompletedValue() < fenceValue[ backBufferIndex ] )
+    {
+        fence->SetEventOnCompletion( fenceValue[ backBufferIndex ], fenceEvent );
+        WaitForSingleObject( fenceEvent, INFINITE );
+    }
+
+    backBufferIndex = swapChain->GetCurrentBackBufferIndex();
+
+    directCommandAllocator[ backBufferIndex ]->Reset();
+    directCommandList->Reset( directCommandAllocator[ backBufferIndex ], nullptr );
+}
+
+Textur *DirectX12::createOrGetTextur( const char *name, Bild * b )
+{
+    return 0;
+}
+
+Bild *DirectX12::zUIRenderBild() const
+{
+    return 0;
+}
+
+bool DirectX12::isAvailable()
+{
+    HINSTANCE dxgiDLL = getDLLRegister()->ladeDLL( "dxgi.dll", "dxgi.dll" );
+    if( !dxgiDLL )
+        return 0;
+    HINSTANCE d3d12DLL = getDLLRegister()->ladeDLL( "d3d12.dll", "d3d12.dll" );
+    if( !d3d12DLL )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        return 0;
+    }
+    CreateDXGIFactory2Function createFactory = (CreateDXGIFactory2Function)GetProcAddress( dxgiDLL, "CreateDXGIFactory2" );
+    if( !createFactory )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        return 0;
+    }
+    D3D12CreateDeviceFunction createDevice = (D3D12CreateDeviceFunction)GetProcAddress( d3d12DLL, "D3D12CreateDevice" );
+    if( !createDevice )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        return 0;
+    }
+    IDXGIFactory4 *factory;
+    UINT createFactoryFlags = 0;
+#if defined(_DEBUG)
+    createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;
+#endif
+    HRESULT res = createFactory( createFactoryFlags, __uuidof( IDXGIFactory4 ), (void **)& factory );
+    if( FAILED( res ) )
+    {
+        getDLLRegister()->releaseDLL( "dxgi.dll" );
+        getDLLRegister()->releaseDLL( "d3d12.dll" );
+        return 0;
+    }
+    int index = 0;
+    do
+    {
+        IDXGIAdapter1 *current;
+        res = factory->EnumAdapters1( index++, &current );
+        if( res == S_OK )
+        {
+            DXGI_ADAPTER_DESC1 dxgiAdapterDesc1;
+            current->GetDesc1( &dxgiAdapterDesc1 );
+            if( ( dxgiAdapterDesc1.Flags &DXGI_ADAPTER_FLAG_SOFTWARE ) == 0 &&
+                SUCCEEDED( createDevice( current, D3D_FEATURE_LEVEL_12_1, __uuidof( ID3D12Device2 ), 0 ) ) )
+            {
+                current->Release();
+                factory->Release();
+                getDLLRegister()->releaseDLL( "dxgi.dll" );
+                getDLLRegister()->releaseDLL( "d3d12.dll" );
+                return 1;
+            }
+            current->Release();
+        }
+    } while( res != DXGI_ERROR_NOT_FOUND );
+    factory->Release();
+    getDLLRegister()->releaseDLL( "dxgi.dll" );
+    getDLLRegister()->releaseDLL( "d3d12.dll" );
+    return 0;
+}

+ 176 - 0
DX9GraphicsApi.cpp

@@ -0,0 +1,176 @@
+#include "GraphicsApi.h"
+#include "Bild.h"
+#include "Globals.h"
+#include "DLLRegister.h"
+#include "Fenster.h"
+
+#include <d3d9.h>
+
+using namespace Framework;
+
+
+DirectX9::DirectX9()
+    : GraphicsApi( DIRECTX9 ),
+    pDirect3D( 0 ),
+    pDevice( 0 ),
+    pBackBuffer( 0 ),
+    backRect( new D3DLOCKED_RECT() )
+{
+    uiBild = new Bild( 1 );
+}
+
+DirectX9::~DirectX9()
+{
+    backRect->pBits = NULL;
+    delete backRect;
+    if( pBackBuffer )
+    {
+        pBackBuffer->Release();
+        pBackBuffer = NULL;
+    }
+    if( pDevice )
+    {
+        pDevice->Release();
+        pDevice = NULL;
+    }
+    if( pDirect3D )
+    {
+        pDirect3D->Release();
+        pDirect3D = NULL;
+        getDLLRegister()->releaseDLL( "d3d9.dll" );
+    }
+    uiBild->release();
+}
+
+typedef IDirect3D9 *( *D3D9CreateFunction )( UINT );
+
+void DirectX9::initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen )
+{
+    if( pDirect3D )
+        return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+    GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
+
+    HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d9.dll", "d3d9.dll" );
+    if( !dll )
+    {
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    D3D9CreateFunction direct3DCreate9 = (D3D9CreateFunction)GetProcAddress( dll, "Direct3DCreate9" );
+    if( !direct3DCreate9 )
+    {
+        getDLLRegister()->releaseDLL( "d3d9.dll" );
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt Direct3DCreate9 fon DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
+        return;
+    }
+    pDirect3D = direct3DCreate9( D3D_SDK_VERSION );
+
+    D3DPRESENT_PARAMETERS d3dpp;
+    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
+    d3dpp.Windowed = !fullScreen;
+    d3dpp.hDeviceWindow = fenster->getFensterHandle();
+    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
+    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
+    d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+    d3dpp.BackBufferHeight = this->backBufferSize.y;
+    d3dpp.BackBufferWidth = this->backBufferSize.x;
+
+    uiBild->neuBild( this->backBufferSize.x, this->backBufferSize.y, 0xFF000000 );
+
+    HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
+                                              D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
+    if( result != S_OK )
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
+    if( pDevice )
+        result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
+    if( result != S_OK )
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
+}
+
+void DirectX9::update()
+{
+    if( !pDirect3D )
+        return;
+    backRect->pBits = NULL;
+    if( pBackBuffer )
+    {
+        pBackBuffer->Release();
+        pBackBuffer = NULL;
+    }
+    if( pDevice )
+    {
+        pDevice->Release();
+        pDevice = NULL;
+    }
+    D3DPRESENT_PARAMETERS d3dpp;
+    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
+    d3dpp.Windowed = !fullScreen;
+    d3dpp.hDeviceWindow = fenster->getFensterHandle();
+    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
+    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
+    d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+    if( !backBufferSize.x || !backBufferSize.y )
+        backBufferSize = fenster->getKörperGröße();
+    d3dpp.BackBufferHeight = backBufferSize.y;
+    d3dpp.BackBufferWidth = backBufferSize.x;
+
+    uiBild->neuBild( backBufferSize.x, backBufferSize.y, 0xFF000000 );
+
+    HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
+                                              D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
+    if( result != S_OK )
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
+    if( pDevice )
+        result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
+    if( result != S_OK )
+        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
+}
+
+void DirectX9::beginFrame( bool fill2D, bool fill3D, int fillColor )
+{
+    if( fill2D )
+        uiBild->setFarbe( fillColor );
+}
+
+void DirectX9::presentFrame()
+{
+    if( !uiBild->getBuffer() )
+        return;
+    HRESULT result;
+    result = pBackBuffer->LockRect( backRect, 0, 0 );
+    if( result != S_OK )
+    {
+        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
+        update();
+    }
+    // kopieren zum Bildschrirm 
+    int *bgBuff = uiBild->getBuffer();
+    int tmpBr = sizeof( D3DCOLOR ) * uiBild->getBreite();
+    for( int y = 0, pitch = 0, bry = 0; y < uiBild->getHeight(); ++y, pitch += backRect->Pitch, bry += uiBild->getBreite() )
+        memcpy( &( (BYTE *)backRect->pBits )[ pitch ], ( void * ) & ( bgBuff[ bry ] ), tmpBr );
+    // Beende Bild 
+    result = pBackBuffer->UnlockRect();
+    if( result != S_OK )
+    {
+        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
+        update();
+    }
+    if( result != S_OK )
+    {
+        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
+        update();
+    }
+    result = pDevice->Present( 0, 0, 0, 0 );
+    if( result != S_OK )
+    {
+        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
+        update();
+    }
+}
+
+Bild *DirectX9::zUIRenderBild() const
+{
+    return uiBild;
+}

+ 3 - 0
Framework.vcxproj

@@ -292,6 +292,9 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <ClCompile Include="Diagramm.cpp" />
     <ClCompile Include="Dialog.cpp" />
     <ClCompile Include="DLLRegister.cpp" />
+    <ClCompile Include="DX11GraphicsApi.cpp" />
+    <ClCompile Include="DX12GraphicsApi.cpp" />
+    <ClCompile Include="DX9GraphicsApi.cpp" />
     <ClCompile Include="DXBuffer.cpp" />
     <ClCompile Include="Fenster.cpp" />
     <ClCompile Include="Fortschritt.cpp" />

+ 9 - 0
Framework.vcxproj.filters

@@ -503,6 +503,15 @@
     <ClCompile Include="DLLRegister.cpp">
       <Filter>Quelldateien\Framework\OS</Filter>
     </ClCompile>
+    <ClCompile Include="DX9GraphicsApi.cpp">
+      <Filter>Quelldateien\Framework\Grafik\DX</Filter>
+    </ClCompile>
+    <ClCompile Include="DX11GraphicsApi.cpp">
+      <Filter>Quelldateien\Framework\Grafik\DX</Filter>
+    </ClCompile>
+    <ClCompile Include="DX12GraphicsApi.cpp">
+      <Filter>Quelldateien\Framework\Grafik\DX</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="UIPixelShader.hlsl">

+ 4 - 1018
GraphicsApi.cpp

@@ -1,22 +1,10 @@
 #include "GraphicsApi.h"
 #include "Fenster.h"
 #include "Bild.h"
-#include "TexturModel.h"
-#include "Textur.h"
-#include "Shader.h"
-#include "Globals.h"
-#include "UIVertexShader.h"
-#include "UIPixelShader.h"
-#include "TexturList.h"
-#include "Kam3D.h"
-#include "DLLRegister.h"
-#include "Welt3D.h"
-#include "Model2D.h"
-#include "DXBuffer.h"
-#include <d3d11.h>
-#include <d3d9.h>
 
 using namespace Framework;
+
+
 GraphicsApi::GraphicsApi( GraphicApiType typ )
 {
     this->typ = typ;
@@ -37,6 +25,8 @@ void GraphicsApi::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool
     if( this->fenster )
         this->fenster->release();
     this->fenster = fenster;
+    if( !backBufferSize.x || !backBufferSize.y )
+        backBufferSize = fenster ? fenster->getKörperGröße() : Punkt( 0, 0 );
     this->backBufferSize = backBufferSize;
     this->fullScreen = fullScreen;
 }
@@ -92,1008 +82,4 @@ GraphicsApi *GraphicsApi::release()
     if( !--ref )
         delete this;
     return 0;
-}
-
-
-DirectX9::DirectX9()
-    : GraphicsApi( DIRECTX9 ),
-    pDirect3D( 0 ),
-    pDevice( 0 ),
-    pBackBuffer( 0 ),
-    backRect( new D3DLOCKED_RECT() )
-{
-    uiBild = new Bild( 1 );
-}
-
-DirectX9::~DirectX9()
-{
-    backRect->pBits = NULL;
-    delete backRect;
-    if( pBackBuffer )
-    {
-        pBackBuffer->Release();
-        pBackBuffer = NULL;
-    }
-    if( pDevice )
-    {
-        pDevice->Release();
-        pDevice = NULL;
-    }
-    if( pDirect3D )
-    {
-        pDirect3D->Release();
-        pDirect3D = NULL;
-    }
-    uiBild->release();
-}
-
-typedef IDirect3D9 *( *D3D9CreateFunction )( UINT );
-
-void DirectX9::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
-{
-    if( pDirect3D )
-        return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
-    GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
-
-    HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d9.dll", "d3d9.dll" );
-    if( !dll )
-    {
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
-        return;
-    }
-    D3D9CreateFunction direct3DCreate9 = (D3D9CreateFunction)GetProcAddress( dll, "Direct3DCreate9" );
-    if( !direct3DCreate9 )
-    {
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt Direct3DCreate9 fon DirectX 9 konnte nicht gefunden werden." ), MB_ICONERROR );
-        return;
-    }
-    pDirect3D = direct3DCreate9( D3D_SDK_VERSION );
-
-    D3DPRESENT_PARAMETERS d3dpp;
-    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
-    d3dpp.Windowed = !fullScreen;
-    d3dpp.hDeviceWindow = fenster->getFensterHandle();
-    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
-    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
-    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
-    d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
-    if( !backBufferSize.x || !backBufferSize.y )
-        backBufferSize = fenster->getKörperGröße();
-    d3dpp.BackBufferHeight = backBufferSize.y;
-    d3dpp.BackBufferWidth = backBufferSize.x;
-
-    uiBild->neuBild( backBufferSize.x, backBufferSize.y, 0xFF000000 );
-
-    HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
-                                              D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
-    if( result != S_OK )
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
-    if( pDevice )
-        result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
-    if( result != S_OK )
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
-}
-
-void DirectX9::update()
-{
-    if( !pDirect3D )
-        return;
-    backRect->pBits = NULL;
-    if( pBackBuffer )
-    {
-        pBackBuffer->Release();
-        pBackBuffer = NULL;
-    }
-    if( pDevice )
-    {
-        pDevice->Release();
-        pDevice = NULL;
-    }
-    D3DPRESENT_PARAMETERS d3dpp;
-    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
-    d3dpp.Windowed = !fullScreen;
-    d3dpp.hDeviceWindow = fenster->getFensterHandle();
-    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
-    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
-    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
-    d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
-    if( !backBufferSize.x || !backBufferSize.y )
-        backBufferSize = fenster->getKörperGröße();
-    d3dpp.BackBufferHeight = backBufferSize.y;
-    d3dpp.BackBufferWidth = backBufferSize.x;
-
-    uiBild->neuBild( backBufferSize.x, backBufferSize.y, 0xFF000000 );
-
-    HRESULT result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
-                                              D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
-    if( result != S_OK )
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
-    if( pDevice )
-        result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
-    if( result != S_OK )
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 9 konnte nicht initialisiert werden." ), MB_ICONERROR );
-}
-
-void DirectX9::beginFrame( bool fill2D, bool fill3D, int fillColor )
-{
-    if( fill2D )
-        uiBild->setFarbe( fillColor );
-}
-
-void DirectX9::presentFrame()
-{
-    if( !uiBild->getBuffer() )
-        return;
-    HRESULT result;
-    result = pBackBuffer->LockRect( backRect, 0, 0 );
-    if( result != S_OK )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        update();
-    }
-    // kopieren zum Bildschrirm 
-    int *bgBuff = uiBild->getBuffer();
-    int tmpBr = sizeof( D3DCOLOR ) * uiBild->getBreite();
-    for( int y = 0, pitch = 0, bry = 0; y < uiBild->getHeight(); ++y, pitch += backRect->Pitch, bry += uiBild->getBreite() )
-        memcpy( &( (BYTE *)backRect->pBits )[ pitch ], ( void * ) & ( bgBuff[ bry ] ), tmpBr );
-    // Beende Bild 
-    result = pBackBuffer->UnlockRect();
-    if( result != S_OK )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        update();
-    }
-    if( result != S_OK )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        update();
-    }
-    result = pDevice->Present( 0, 0, 0, 0 );
-    if( result != S_OK )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        update();
-    }
-}
-
-Bild *DirectX9::zUIRenderBild() const
-{
-    return uiBild;
-}
-
-
-DirectX11::DirectX11()
-    : GraphicsApi( DIRECTX11 ),
-    d3d11Device( 0 ),
-    d3d11Context( 0 ),
-    d3d11SpawChain( 0 ),
-    uiTextur( 0 ),
-    vertexShader( 0 ),
-    pixelShader( 0 ),
-    sampleState( 0 ),
-    rtview( 0 ),
-    dsView( 0 ),
-    depthStencilBuffer( 0 ),
-    depthStencilState( 0 ),
-    depthDisabledStencilState( 0 ),
-    blendStateAlphaBlend( 0 ),
-    vp( 0 ),
-    texturModel( new TexturModel() ),
-    texturRegister( new TexturList() ),
-    texturRS( 0 ),
-    meshRS( 0 ),
-    defaultTextur( 0 ),
-    diffuseLights( 0 ),
-    pointLights( 0 ),
-    vertexBuffer( 0 ),
-    indexBuffer( 0 )
-{}
-
-DirectX11::~DirectX11()
-{
-    if( vertexBuffer )
-        vertexBuffer->release();
-    if( indexBuffer )
-        indexBuffer->release();
-    if( diffuseLights )
-        diffuseLights->release();
-    if( pointLights )
-        pointLights->release();
-    if( defaultTextur )
-        defaultTextur->release();
-    if( texturRS )
-        texturRS->Release();
-    if( meshRS )
-        meshRS->Release();
-    texturModel->release();
-    texturRegister->release();
-    if( blendStateAlphaBlend )
-    {
-        blendStateAlphaBlend->Release();
-        blendStateAlphaBlend = NULL;
-    }
-    if( uiTextur )
-    {
-        uiTextur->release();
-        uiTextur = NULL;
-    }
-    if( sampleState )
-    {
-        sampleState->Release();
-        sampleState = NULL;
-    }
-    if( pixelShader )
-    {
-        pixelShader->release();
-        pixelShader = NULL;
-    }
-    if( vertexShader )
-    {
-        vertexShader->release();
-        vertexShader = NULL;
-    }
-    if( depthDisabledStencilState )
-    {
-        depthDisabledStencilState->Release();
-        depthDisabledStencilState = NULL;
-    }
-    delete vp;
-    vp = 0;
-    if( dsView )
-    {
-        dsView->Release();
-        dsView = NULL;
-    }
-    if( depthStencilState )
-    {
-        depthStencilState->Release();
-        depthStencilState = NULL;
-    }
-    if( depthStencilBuffer )
-    {
-        depthStencilBuffer->Release();
-        depthStencilBuffer = NULL;
-    }
-    if( rtview )
-    {
-        rtview->Release();
-        rtview = NULL;
-    }
-    if( d3d11SpawChain )
-    {
-        d3d11SpawChain->Release();
-        d3d11SpawChain = NULL;
-    }
-    if( d3d11Device )
-    {
-        d3d11Device->Release();
-        d3d11Device = NULL;
-    }
-    if( d3d11Context )
-    {
-        d3d11Context->Release();
-        d3d11Context = NULL;
-    }
-}
-
-typedef HRESULT( *D3D11CreateDeviceAndSwapChainFunction )( IDXGIAdapter *, D3D_DRIVER_TYPE,
-                                                           HMODULE, UINT, const D3D_FEATURE_LEVEL *,
-                                                           UINT, UINT, const DXGI_SWAP_CHAIN_DESC *,
-                                                           IDXGISwapChain * *, ID3D11Device * *,
-                                                           D3D_FEATURE_LEVEL *, ID3D11DeviceContext * * );
-
-void DirectX11::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
-{
-    if( d3d11Device )
-        return GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
-    GraphicsApi::initialize( fenster, backBufferSize, fullScreen );
-    //--------------------------------------------------------------------
-    // Create Device
-
-    HINSTANCE dll = getDLLRegister()->ladeDLL( "d3d11.dll", "d3d11.dll" );
-    if( !dll )
-    {
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
-        return;
-    }
-    D3D11CreateDeviceAndSwapChainFunction createDeviceAndSwapChain = (D3D11CreateDeviceAndSwapChainFunction)GetProcAddress( dll, "D3D11CreateDeviceAndSwapChain" );
-    if( !createDeviceAndSwapChain )
-    {
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "Der Einstiegspunkt D3D11CreateDeviceAndSwapChain fon DirectX 11 konnte nicht gefunden werden." ), MB_ICONERROR );
-        return;
-    }
-
-    // create a struct to hold information about the swap chain
-    DXGI_SWAP_CHAIN_DESC scd;
-
-    // clear out the struct for use
-    ZeroMemory( &scd, sizeof( DXGI_SWAP_CHAIN_DESC ) );
-
-    // fill the swap chain description struct
-    scd.BufferCount = 1;                                           // one back buffer
-    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;             // how swap chain is to be used
-    scd.OutputWindow = fenster ? fenster->getFensterHandle() : 0;  // the window to be used
-    scd.SampleDesc.Count = 1;
-    // Set the scan line ordering and scaling to unspecified.
-    scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
-    scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
-    scd.Windowed = !fullScreen;
-    if( !backBufferSize.x || !backBufferSize.y )
-        backBufferSize = fenster ? fenster->getKörperGröße() : Punkt( 0, 0 );
-    scd.BufferDesc.Width = backBufferSize.x;
-    scd.BufferDesc.Height = backBufferSize.y;                 // windowed/full-screen mode
-    scd.BufferDesc.RefreshRate.Denominator = 1;
-    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;       // use 32-bit color
-                                                              // Discard the back buffer contents after presenting.
-    scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-
-    D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
-    D3D_FEATURE_LEVEL support = D3D_FEATURE_LEVEL_11_0;
-    // create a device, device context and swap chain using the information in the scd struct
-    UINT flag = 0;
-#ifdef _DEBUG
-    flag |= D3D11_CREATE_DEVICE_DEBUG;
-#endif
-    HRESULT result = createDeviceAndSwapChain( NULL,
-                                               D3D_DRIVER_TYPE_HARDWARE,
-                                               NULL,
-                                               flag,
-                                               &featureLevel,
-                                               1,
-                                               D3D11_SDK_VERSION,
-                                               &scd,
-                                               &d3d11SpawChain,
-                                               &d3d11Device,
-                                               &support,
-                                               &d3d11Context );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: D3D11CreateDeviceAndSwapChain returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    ID3D11Texture2D *backBufferPtr;
-    // Get the pointer to the back buffer.
-    result = d3d11SpawChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID *)& backBufferPtr );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11SpawChain->GetBuffer returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    // Create the render target view with the back buffer pointer.
-    result = d3d11Device->CreateRenderTargetView( backBufferPtr, NULL, &rtview );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateRenderTargetView returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    // Release pointer to the back buffer as we no longer need it.
-    backBufferPtr->Release();
-    // Initialize the description of the depth buffer.
-    D3D11_TEXTURE2D_DESC depthBufferDesc;
-    ZeroMemory( &depthBufferDesc, sizeof( depthBufferDesc ) );
-    // Set up the description of the depth buffer.
-    depthBufferDesc.Width = backBufferSize.x;
-    depthBufferDesc.Height = backBufferSize.y;
-    depthBufferDesc.MipLevels = 1;
-    depthBufferDesc.ArraySize = 1;
-    depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
-    depthBufferDesc.SampleDesc.Count = 1;
-    depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
-    depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
-    // Create the texture for the depth buffer using the filled out description.
-    result = d3d11Device->CreateTexture2D( &depthBufferDesc, NULL, &depthStencilBuffer );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateTexture2D returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    // Initialize the description of the stencil state.
-    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
-    ZeroMemory( &depthStencilDesc, sizeof( depthStencilDesc ) );
-
-    // Set up the description of the stencil state.
-    depthStencilDesc.DepthEnable = true;
-    depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
-    depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
-    depthStencilDesc.StencilEnable = true;
-    depthStencilDesc.StencilReadMask = 0xFF;
-    depthStencilDesc.StencilWriteMask = 0xFF;
-    // Stencil operations if pixel is front-facing.
-    depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
-    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
-    depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
-    depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
-    // Stencil operations if pixel is back-facing.
-    depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
-    depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
-    depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
-    depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
-    // Create the depth stencil state.
-    result = d3d11Device->CreateDepthStencilState( &depthStencilDesc, &depthStencilState );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
-
-    // Initialize the depth stencil view.
-    D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
-    ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) );
-
-    // Set up the depth stencil view description.
-    depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
-    depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
-
-    // Create the depth stencil view.
-    result = d3d11Device->CreateDepthStencilView( depthStencilBuffer, &depthStencilViewDesc, &dsView );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateDepthStencilView returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
-
-    vp = new D3D11_VIEWPORT();
-    memset( vp, 0, sizeof( D3D11_VIEWPORT ) );
-    vp->Width = (float)backBufferSize.x;
-    vp->Height = (float)backBufferSize.y;
-    vp->MinDepth = 0.0f;
-    vp->MaxDepth = 1.0f;
-    vp->TopLeftX = 0.0f;
-    vp->TopLeftY = 0.0f;
-
-    d3d11Context->RSSetViewports( 1, vp );
-
-    D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
-    // Clear the second depth stencil state before setting the parameters.
-    ZeroMemory( &depthDisabledStencilDesc, sizeof( depthDisabledStencilDesc ) );
-
-    // Now create a second depth stencil state which turns off the Z buffer for 2D rendering.  The only difference is 
-    // that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
-    depthDisabledStencilDesc.DepthEnable = false;
-    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
-    depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
-    depthDisabledStencilDesc.StencilEnable = true;
-    depthDisabledStencilDesc.StencilReadMask = 0xFF;
-    depthDisabledStencilDesc.StencilWriteMask = 0xFF;
-    depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
-    depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
-    depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
-    depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
-    depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
-    depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
-    depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
-    depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
-
-    // Create the state using the device.
-    result = d3d11Device->CreateDepthStencilState( &depthDisabledStencilDesc, &depthDisabledStencilState );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateDepthStencilState returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    //-------------------------------------------------
-    // Shaders
-    vertexShader = new DX11VertexShader( d3d11Device, d3d11Context );
-    vertexShader->setCompiledByteArray( (unsigned char *)UIVertexShader, sizeof( UIVertexShader ) );
-
-    pixelShader = new DX11PixelShader( d3d11Device, d3d11Context );
-    pixelShader->setCompiledByteArray( (unsigned char *)UIPixelShader, sizeof( UIPixelShader ) );
-
-    D3D11_INPUT_ELEMENT_DESC polygonLayout[ 4 ];
-    // Create the vertex input layout description.
-    // This setup needs to match the VertexType stucture in the ModelClass and in the shader.
-    polygonLayout[ 0 ].SemanticName = "POSITION";
-    polygonLayout[ 0 ].SemanticIndex = 0;
-    polygonLayout[ 0 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
-    polygonLayout[ 0 ].InputSlot = 0;
-    polygonLayout[ 0 ].AlignedByteOffset = 0;
-    polygonLayout[ 0 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
-    polygonLayout[ 0 ].InstanceDataStepRate = 0;
-
-    polygonLayout[ 1 ].SemanticName = "TEXCOORD";
-    polygonLayout[ 1 ].SemanticIndex = 0;
-    polygonLayout[ 1 ].Format = DXGI_FORMAT_R32G32_FLOAT;
-    polygonLayout[ 1 ].InputSlot = 0;
-    polygonLayout[ 1 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
-    polygonLayout[ 1 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
-    polygonLayout[ 1 ].InstanceDataStepRate = 0;
-
-    polygonLayout[ 2 ].SemanticName = "NORMAL";
-    polygonLayout[ 2 ].SemanticIndex = 0;
-    polygonLayout[ 2 ].Format = DXGI_FORMAT_R32G32B32_FLOAT;
-    polygonLayout[ 2 ].InputSlot = 0;
-    polygonLayout[ 2 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
-    polygonLayout[ 2 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
-    polygonLayout[ 2 ].InstanceDataStepRate = 0;
-
-    polygonLayout[ 3 ].SemanticName = "KNOCHEN_ID";
-    polygonLayout[ 3 ].SemanticIndex = 0;
-    polygonLayout[ 3 ].Format = DXGI_FORMAT_R32_UINT;
-    polygonLayout[ 3 ].InputSlot = 0;
-    polygonLayout[ 3 ].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
-    polygonLayout[ 3 ].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
-    polygonLayout[ 3 ].InstanceDataStepRate = 0;
-
-    vertexShader->erstelleInputLayout( polygonLayout, 4 );
-    vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 ); // matrizen für skelett annimationen
-    vertexShader->erstelleConstBuffer( sizeof( Mat4< float > ) * 2, 1 ); // View and Projection Matrix
-
-    pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 0 ); // Kamera Position
-    pixelShader->erstelleConstBuffer( sizeof( float ) * 3, 1 ); // materialkonstanten nach phong model
-    pixelShader->erstelleConstBuffer( sizeof( int ) * 2, 2 ); // materialkonstanten nach phong model
-    // TODO: Remove Following Test Code
-    int lc[] = { 1, 6 };
-    pixelShader->füllConstBuffer( (char *)lc, 2, sizeof( int ) * 2 );
-
-    // Create a texture sampler state description.
-    D3D11_SAMPLER_DESC samplerDesc;
-    samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
-    samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
-    samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
-    samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
-    samplerDesc.MipLODBias = 0.0f;
-    samplerDesc.MaxAnisotropy = 1;
-    samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
-    samplerDesc.BorderColor[ 0 ] = 0;
-    samplerDesc.BorderColor[ 1 ] = 0;
-    samplerDesc.BorderColor[ 2 ] = 0;
-    samplerDesc.BorderColor[ 3 ] = 0;
-    samplerDesc.MinLOD = 0;
-    samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
-
-    // Create the texture sampler state.
-    result = d3d11Device->CreateSamplerState( &samplerDesc, &sampleState );
-    if( result != S_OK )
-    {
-        std::cout << "ERROR: d3d11Device->CreateSamplerState returned " << result << "\n";
-        WMessageBox( fenster->getFensterHandle(), new Text( "Fehler" ), new Text( "DirectX 11 konnte nicht initialisiert werden." ), MB_ICONERROR );
-        return;
-    }
-    //---------------------------------------------------------------
-    // Framework Backbuffer Texture
-    Bild *renderB = new Bild( 1 );
-    renderB->setAlpha3D( 1 );
-    renderB->neuBild( backBufferSize.x, backBufferSize.y, 0 );
-
-    uiTextur = createOrGetTextur( "_f_Render_Bild", renderB );
-
-    texturModel->setSize( backBufferSize );
-    texturModel->setTextur( uiTextur->getThis() );
-
-    D3D11_BLEND_DESC blendState;
-    ZeroMemory( &blendState, sizeof( D3D11_BLEND_DESC ) );
-    blendState.AlphaToCoverageEnable = false;
-    blendState.IndependentBlendEnable = false;
-    blendState.RenderTarget[ 0 ].BlendEnable = true;
-    blendState.RenderTarget[ 0 ].SrcBlend = D3D11_BLEND_SRC_ALPHA;
-    blendState.RenderTarget[ 0 ].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
-    blendState.RenderTarget[ 0 ].BlendOp = D3D11_BLEND_OP_ADD;
-    blendState.RenderTarget[ 0 ].SrcBlendAlpha = D3D11_BLEND_ZERO;
-    blendState.RenderTarget[ 0 ].DestBlendAlpha = D3D11_BLEND_ONE;
-    blendState.RenderTarget[ 0 ].BlendOpAlpha = D3D11_BLEND_OP_ADD;
-    blendState.RenderTarget[ 0 ].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
-
-    d3d11Device->CreateBlendState( &blendState, &blendStateAlphaBlend );
-    d3d11Context->OMSetBlendState( blendStateAlphaBlend, 0, 0xFFFFFFFF );
-
-    // Setup Render Objekt
-
-    vertexShader->benutzeShader();
-    d3d11Context->PSSetSamplers( 0, 1, &sampleState );
-    pixelShader->benutzeShader();
-
-    D3D11_RASTERIZER_DESC rasterDesc;
-    ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
-    rasterDesc.AntialiasedLineEnable = false;
-    rasterDesc.CullMode = D3D11_CULL_BACK;
-    rasterDesc.DepthBiasClamp = 0.0f;
-    rasterDesc.DepthClipEnable = true;
-    rasterDesc.FillMode = D3D11_FILL_SOLID;
-    rasterDesc.FrontCounterClockwise = false;
-    rasterDesc.MultisampleEnable = false;
-    rasterDesc.ScissorEnable = false;
-    rasterDesc.SlopeScaledDepthBias = 0.0f;
-    d3d11Device->CreateRasterizerState( &rasterDesc, &texturRS );
-
-    ZeroMemory( &rasterDesc, sizeof( rasterDesc ) );
-    rasterDesc.AntialiasedLineEnable = false;
-    rasterDesc.CullMode = D3D11_CULL_BACK;
-    rasterDesc.DepthBiasClamp = 0.0f;
-    rasterDesc.DepthClipEnable = true;
-    rasterDesc.FillMode = D3D11_FILL_WIREFRAME;
-    rasterDesc.FrontCounterClockwise = false;
-    rasterDesc.MultisampleEnable = false;
-    rasterDesc.ScissorEnable = false;
-    rasterDesc.SlopeScaledDepthBias = 0.0f;
-    d3d11Device->CreateRasterizerState( &rasterDesc, &meshRS );
-
-    d3d11Context->RSSetState( texturRS );
-
-    Bild *b = new Bild();
-    b->neuBild( 10, 10, 0xFFFFFFFF );
-    defaultTextur = createOrGetTextur( "_default_textur", b );
-
-    vertexBuffer = new DX11Buffer( sizeof( Vertex3D ), d3d11Device, d3d11Context, D3D11_BIND_VERTEX_BUFFER );
-    indexBuffer = new DX11Buffer( sizeof( int ), d3d11Device, d3d11Context, D3D11_BIND_INDEX_BUFFER );
-
-    DiffuseLight dl[ 1 ];
-    dl[ 0 ].direction = Vec3< float >( -0.5f, -0.5f, -0.5f ).normalize();
-    dl[ 0 ].color = Vec3<float>( 1.f, 0.f, 0.f );
-    diffuseLights = new DX11StructuredBuffer( sizeof( DiffuseLight ), d3d11Device, d3d11Context );
-    diffuseLights->setData( dl );
-    diffuseLights->setLength( sizeof( dl ) );
-    diffuseLights->copieren();
-    PointLight pl[ 6 ];
-    pl[ 0 ].position = Vec3< float >( 0, 130, 0 );
-    pl[ 0 ].color = Vec3< float >( 1.f, 1.f, 0.f );
-    pl[ 0 ].radius = 100;
-    pl[ 1 ].position = Vec3< float >( 150, 130, 0 );
-    pl[ 1 ].color = Vec3< float >( 0.f, 1.f, 0.f );
-    pl[ 1 ].radius = 100;
-    pl[ 2 ].position = Vec3< float >( 150, 130, 150 );
-    pl[ 2 ].color = Vec3< float >( 0.f, 0.f, 1.f );
-    pl[ 2 ].radius = 100;
-    pl[ 3 ].position = Vec3< float >( -150, 130, 0 );
-    pl[ 3 ].color = Vec3< float >( 1.f, 0.f, 1.f );
-    pl[ 3 ].radius = 100;
-    pl[ 4 ].position = Vec3< float >( 0, 130, 150 );
-    pl[ 4 ].color = Vec3< float >( 0.f, 1.f, 1.f );
-    pl[ 4 ].radius = 100;
-    pl[ 5 ].position = Vec3< float >( -150, 130, 150 );
-    pl[ 5 ].color = Vec3< float >( 1.f, 0.f, 0.f );
-    pl[ 5 ].radius = 100;
-    pointLights = new DX11StructuredBuffer( sizeof( PointLight ), d3d11Device, d3d11Context );
-    pointLights->setData( pl );
-    pointLights->setLength( sizeof( pl ) * 6 );
-    pointLights->copieren();
-}
-
-void DirectX11::update()
-{
-    if( vertexBuffer )
-        vertexBuffer = (DX11Buffer *)vertexBuffer->release();
-    if( indexBuffer )
-        indexBuffer = (DX11Buffer *)indexBuffer->release();
-    if( texturRS )
-    {
-        texturRS->Release();
-        texturRS = NULL;
-    }
-    if( meshRS )
-    {
-        meshRS->Release();
-        meshRS = NULL;
-    }
-    texturRegister->leeren();
-    if( defaultTextur )
-        defaultTextur = defaultTextur->release();
-    if( blendStateAlphaBlend )
-    {
-        blendStateAlphaBlend->Release();
-        blendStateAlphaBlend = NULL;
-    }
-    if( uiTextur )
-    {
-        uiTextur->release();
-        uiTextur = NULL;
-    }
-    if( sampleState )
-    {
-        sampleState->Release();
-        sampleState = NULL;
-    }
-    if( pixelShader )
-    {
-        pixelShader->release();
-        pixelShader = NULL;
-    }
-    if( vertexShader )
-    {
-        vertexShader->release();
-        vertexShader = NULL;
-    }
-    if( depthDisabledStencilState )
-    {
-        depthDisabledStencilState->Release();
-        depthDisabledStencilState = NULL;
-    }
-    delete vp;
-    vp = 0;
-    if( dsView )
-    {
-        dsView->Release();
-        dsView = NULL;
-    }
-    if( depthStencilState )
-    {
-        depthStencilState->Release();
-        depthStencilState = NULL;
-    }
-    if( depthStencilBuffer )
-    {
-        depthStencilBuffer->Release();
-        depthStencilBuffer = NULL;
-    }
-    if( rtview )
-    {
-        rtview->Release();
-        rtview = NULL;
-    }
-    if( d3d11SpawChain )
-    {
-        d3d11SpawChain->Release();
-        d3d11SpawChain = NULL;
-    }
-    if( d3d11Device )
-    {
-        d3d11Device->Release();
-        d3d11Device = NULL;
-    }
-    if( d3d11Context )
-    {
-        d3d11Context->Release();
-        d3d11Context = NULL;
-    }
-    initialize( fenster->getThis(), backBufferSize, fullScreen );
-}
-
-void DirectX11::beginFrame( bool fill2D, bool fill3D, int fillColor )
-{
-    if( fill2D )
-        uiTextur->zBild()->setFarbe( fillColor );
-    if( fill3D )
-    {
-        float color[ 4 ];
-        // Setup the color to clear the buffer.
-        color[ 0 ] = ( ( fillColor >> 16 ) & 0xFF ) / 255.f; // R
-        color[ 1 ] = ( ( fillColor >> 8 ) & 0xFF ) / 255.f; // G
-        color[ 2 ] = ( fillColor & 0xFF ) / 255.f; // B
-        color[ 3 ] = ( ( fillColor >> 24 ) & 0xFF ) / 255.f; // A
-        d3d11Context->ClearRenderTargetView( rtview, color );
-        // Clear the depth buffer.
-        d3d11Context->ClearDepthStencilView( dsView, D3D11_CLEAR_DEPTH, 1, 0 );
-    }
-    // Bind the render target view and depth stencil buffer to the output render pipeline.
-    d3d11Context->OMSetRenderTargets( 1, &rtview, dsView );
-    // Set the depth stencil state.
-    d3d11Context->OMSetDepthStencilState( depthStencilState, 1 );
-}
-
-void DirectX11::renderObject( Model3D * zObj )
-{
-    vertexBuffer->setData( (void *)zObj->zVertexBuffer() );
-    vertexBuffer->setLength( sizeof( Vertex3D ) * zObj->getVertexAnzahl() );
-    vertexBuffer->copieren();
-    Mat4< float > trans = Mat4< float >::identity();
-    int anz = zObj->errechneMatrizen( trans, matrixBuffer );
-    if( vertexShader )
-        vertexShader->füllConstBuffer( (char *)matrixBuffer, 0, sizeof( Mat4< float > ) * anz );
-    float matirialBuffer[ 3 ]; // light factors (phong model)
-    matirialBuffer[ 0 ] = zObj->getAmbientFactor();
-    matirialBuffer[ 1 ] = zObj->getDiffusFactor();
-    matirialBuffer[ 2 ] = zObj->getSpecularFactor();
-    if( pixelShader )
-        pixelShader->füllConstBuffer( (char *)matirialBuffer, 1, sizeof( float ) * 3 );
-    unsigned int offset = 0;
-    unsigned int es = (unsigned)vertexBuffer->getElementLength();
-    ID3D11Buffer * vBuffer = vertexBuffer->zBuffer();
-    d3d11Context->IASetVertexBuffers( 0, 1, &vBuffer, &es, &offset );
-    Model3DTextur * zTextur = zObj->zTextur();
-    int ind = 0;
-    for( auto i = zObj->zModelData()->getPolygons(); i; i++ )
-    {
-        indexBuffer->setData( i->indexList );
-        indexBuffer->setLength( sizeof( int ) * i->indexAnz );
-        indexBuffer->copieren();
-        Textur *t = zTextur->zPolygonTextur( ind );
-        if( t &&t->brauchtUpdate() )
-            t->updateTextur();
-        DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
-        if( indexBuffer->getElementLength() == 2 )
-            f = DXGI_FORMAT_R16_UINT;
-        if( indexBuffer->getElementLength() == 1 )
-            f = DXGI_FORMAT_R8_UINT;
-        d3d11Context->IASetIndexBuffer( indexBuffer->zBuffer(), f, 0 );
-        d3d11Context->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
-        if( t )
-        {
-            ID3D11ShaderResourceView *v[ 3 ];
-            v[ 0 ] = *(DX11Textur *)t;
-            v[ 1 ] = *diffuseLights;
-            v[ 2 ] = *pointLights;
-            d3d11Context->PSSetShaderResources( 0, 3, v );
-            d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
-        }
-        else
-        {
-            d3d11Context->RSSetState( meshRS );
-            ID3D11ShaderResourceView *v[ 3 ];
-            v[ 0 ] = *(DX11Textur *)defaultTextur;
-            v[ 1 ] = *diffuseLights;
-            v[ 2 ] = *pointLights;
-            d3d11Context->PSSetShaderResources( 0, 3, v );
-            d3d11Context->DrawIndexed( indexBuffer->getElementAnzahl(), 0, 0 );
-            d3d11Context->RSSetState( texturRS );
-        }
-        ind++;
-    }
-}
-
-// Überprüft, ob eine Kugel in dem Sichtbaren Raum der Welt liegt und gezeichnet werden muss
-//  pos: Der Mittelpunkt der Kugel
-//  radius: Der Radius der Kugel
-//  dist: Einen Zeiger auf einen float, in dem das quadrat des Abstands zur Kammeraposition gespeichert wird, falls diese Funktion true zurückgiebt und der Zeiger nicht 0 ist
-bool DirectX11::isInFrustrum( const Vec3< float > & pos, float radius, float *dist ) const
-{
-    for( int i = 0; i < 6; i++ )
-    {
-        if( frustrum[ i ] * pos + radius < 0 )
-            return 0;
-    }
-    if( dist )
-        * dist = kamPos.abstand( pos );
-    return 1;
-}
-
-void DirectX11::renderKamera( Kam3D * zKamera )
-{
-    d3d11Context->RSSetViewports( 1, (D3D11_VIEWPORT *)zKamera->zViewPort() );
-
-    Mat4< float > tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
-
-    frustrum[ 0 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 0 ][ 0 ];
-    frustrum[ 0 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 0 ][ 1 ];
-    frustrum[ 0 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 0 ][ 2 ];
-    frustrum[ 0 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 0 ][ 3 ];
-
-    frustrum[ 1 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 0 ][ 0 ];
-    frustrum[ 1 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 0 ][ 1 ];
-    frustrum[ 1 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 0 ][ 2 ];
-    frustrum[ 1 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 0 ][ 3 ];
-
-    frustrum[ 2 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 1 ][ 0 ];
-    frustrum[ 2 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 1 ][ 1 ];
-    frustrum[ 2 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 1 ][ 2 ];
-    frustrum[ 2 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 1 ][ 3 ];
-
-    frustrum[ 3 ].x = tmp.elements[ 3 ][ 0 ] + tmp.elements[ 1 ][ 0 ];
-    frustrum[ 3 ].y = tmp.elements[ 3 ][ 1 ] + tmp.elements[ 1 ][ 1 ];
-    frustrum[ 3 ].z = tmp.elements[ 3 ][ 2 ] + tmp.elements[ 1 ][ 2 ];
-    frustrum[ 3 ].w = tmp.elements[ 3 ][ 3 ] + tmp.elements[ 1 ][ 3 ];
-
-    frustrum[ 4 ].x = tmp.elements[ 2 ][ 0 ];
-    frustrum[ 4 ].y = tmp.elements[ 2 ][ 1 ];
-    frustrum[ 4 ].z = tmp.elements[ 2 ][ 2 ];
-    frustrum[ 4 ].w = tmp.elements[ 2 ][ 3 ];
-
-    frustrum[ 5 ].x = tmp.elements[ 3 ][ 0 ] - tmp.elements[ 2 ][ 0 ];
-    frustrum[ 5 ].y = tmp.elements[ 3 ][ 1 ] - tmp.elements[ 2 ][ 1 ];
-    frustrum[ 5 ].z = tmp.elements[ 3 ][ 2 ] - tmp.elements[ 2 ][ 2 ];
-    frustrum[ 5 ].w = tmp.elements[ 3 ][ 3 ] - tmp.elements[ 2 ][ 3 ];
-
-    for( int i = 0; i < 6; i++ )
-        frustrum[ i ].normalize();
-
-    viewAndProj[ 0 ] = zKamera->getViewMatrix();
-    viewAndProj[ 1 ] = zKamera->getProjectionMatrix();
-    kamPos = zKamera->getWorldPosition();
-    if( vertexShader )
-        vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
-    if( pixelShader )
-        pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
-    Welt3D * w = zKamera->zWelt();
-    w->lock();
-    int alphaAnzahl = 0;
-    int maxDist = 0;
-    int minDist = 0x7FFFFFFF;
-    for( auto obj = w->getMembers(); obj; obj++ )
-    {
-        float dist;
-        if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
-        {
-            if( (int)dist > maxDist )
-                maxDist = (int)dist;
-            if( minDist < (int)dist )
-                minDist = (int)dist;
-            if( obj->hatAlpha() )
-                alphaAnzahl++;
-            else
-                renderObject( obj._ );
-        }
-    }
-    maxDist++;
-    if( alphaAnzahl )
-    {
-        int size = maxDist - minDist;
-        int *index = new int[ size ];
-        Model3D **sorted = new Model3D * [ size * alphaAnzahl ];
-        for( auto obj = w->getMembers(); obj; obj++ )
-        {
-            float dist;
-            if( isInFrustrum( obj->getPos(), obj->getRadius(), &dist ) )
-            {
-                if( obj->hatAlpha() )
-                {
-                    int pos = (int)dist - minDist;
-                    sorted[ pos * alphaAnzahl + index[ pos ]++ ] = obj._;
-                }
-            }
-        }
-        for( int i = 0; i < size; i++ )
-        {
-            for( int j = 0; j < index[ i ]; j++ )
-            {
-                renderObject( sorted[ i * alphaAnzahl + j ] );
-            }
-        }
-        delete[] index;
-        delete[] sorted;
-    }
-    w->unlock();
-}
-
-void DirectX11::presentFrame()
-{
-    // Set the depth stencil state.
-    d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
-
-    uiTextur->updateTextur();
-
-    d3d11Context->RSSetViewports( 1, vp );
-
-    float screenAspect = (float)backBufferSize.x / (float)backBufferSize.y;
-    Mat4< float > view = view.translation( Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
-    viewAndProj[ 0 ] = view;
-    viewAndProj[ 1 ] = view.projektion( (float)PI / 4.0f, screenAspect, 0.1f, 10000.f );
-    kamPos = Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f );
-    if( vertexShader )
-        vertexShader->füllConstBuffer( (char *)viewAndProj, 1, sizeof( Mat4< float > ) * 2 );
-    if( pixelShader )
-        pixelShader->füllConstBuffer( (char *)& kamPos, 0, sizeof( float ) * 3 );
-
-    if( fenster && !IsIconic( fenster->getFensterHandle() ) )
-        renderObject( texturModel );
-
-    HRESULT result = d3d11SpawChain->Present( 0, 0 );
-    if( !SUCCEEDED( result ) )
-    {
-        update();
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-    }
-}
-
-Bild *DirectX11::zUIRenderBild() const
-{
-    return uiTextur->zBild();
-}
-
-Textur *DirectX11::createOrGetTextur( const char *name, Bild * b )
-{
-    if( !d3d11Device )
-    {
-        if( b )
-            b->release();
-        return 0;
-    }
-    if( texturRegister->hatTextur( name ) )
-    {
-        Textur *ret = texturRegister->getTextur( name );
-        if( b )
-            ret->setBildZ( b );
-        return ret;
-    }
-    Textur *ret = new DX11Textur( d3d11Device, d3d11Context );
-    if( b )
-        ret->setBildZ( b );
-    texturRegister->addTextur( ret->getThis(), name );
-    return ret;
 }

+ 38 - 0
GraphicsApi.h

@@ -4,6 +4,18 @@
 #include "Mat4.h"
 #include "Ebene3D.h"
 
+// DirectX 12 Types
+
+struct ID3D12Device2;
+struct ID3D12InfoQueue;
+struct ID3D12CommandQueue;
+struct IDXGISwapChain4;
+struct ID3D12DescriptorHeap;
+struct ID3D12Resource;
+struct ID3D12CommandAllocator;
+struct ID3D12GraphicsCommandList;
+struct ID3D12Fence;
+
 // DirectX 11 Types
 
 struct ID3D11Device;
@@ -163,6 +175,32 @@ namespace Framework
 
     class DirectX12 : public GraphicsApi
     {
+    private:
+        ID3D12Device2 *device;
+        ID3D12InfoQueue *infoQueue;
+        ID3D12CommandQueue *directCommandQueue;
+        IDXGISwapChain4 *swapChain;
+        ID3D12DescriptorHeap *rtvHeap;
+        ID3D12Resource *backBuffer[ 2 ];
+        ID3D12CommandAllocator *directCommandAllocator[ 2 ];
+        ID3D12GraphicsCommandList *directCommandList;
+        int backBufferIndex;
+        int tearing;
+        ID3D12Fence *fence;
+        HANDLE fenceEvent;
+        unsigned __int64 fenceValue[ 2 ];
+
+    public:
+        __declspec( dllexport ) DirectX12();
+        __declspec( dllexport ) ~DirectX12();
+        __declspec( dllexport ) void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
+        __declspec( dllexport ) void update() override;
+        __declspec( dllexport ) void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
+        __declspec( dllexport ) void renderKamera( Kam3D *zKamera ) override;
+        __declspec( dllexport ) void presentFrame() override;
+        __declspec( dllexport ) Textur *createOrGetTextur( const char *name, Bild *b ) override;
+        __declspec( dllexport ) Bild *zUIRenderBild() const override;
 
+        __declspec( dllexport ) static bool isAvailable();
     };
 }

+ 93 - 16
main.h

@@ -2,6 +2,9 @@
 #define main_H
 
 #ifdef _DEBUG
+#include <iostream>
+#include <sstream>
+#include <vector>
 #ifndef _LTMDB
 #define _CRTDBG_MAP_ALLOC
 #include <stdlib.h>
@@ -42,38 +45,109 @@ namespace Framework
     __declspec( dllexport ) void releaseFramework();
 }
 
-typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
+typedef BOOL( WINAPI *MINIDUMPWRITEDUMP )( HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam );
 
-void createMinidump(struct _EXCEPTION_POINTERS* apExceptionInfo)
+void createMinidump( struct _EXCEPTION_POINTERS *apExceptionInfo )
 {
-	HMODULE mhLib = ::LoadLibrary("dbghelp.dll");
-	MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(mhLib, "MiniDumpWriteDump");
+    HMODULE mhLib = ::LoadLibrary( "dbghelp.dll" );
+    MINIDUMPWRITEDUMP pDump = ( MINIDUMPWRITEDUMP )::GetProcAddress( mhLib, "MiniDumpWriteDump" );
 
-	HANDLE  hFile = ::CreateFile("error_core_memory_dump.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
-		FILE_ATTRIBUTE_NORMAL, NULL);
+    HANDLE  hFile = ::CreateFile( "error_core_memory_dump.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
+                                  FILE_ATTRIBUTE_NORMAL, NULL );
 
-	_MINIDUMP_EXCEPTION_INFORMATION ExInfo;
-	ExInfo.ThreadId = ::GetCurrentThreadId();
-	ExInfo.ExceptionPointers = apExceptionInfo;
-	ExInfo.ClientPointers = FALSE;
+    _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
+    ExInfo.ThreadId = ::GetCurrentThreadId();
+    ExInfo.ExceptionPointers = apExceptionInfo;
+    ExInfo.ClientPointers = FALSE;
 
-	pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
-	::CloseHandle(hFile);
+    pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
+    ::CloseHandle( hFile );
 }
 
-LONG WINAPI unhandledHandler(struct _EXCEPTION_POINTERS* apExceptionInfo)
+LONG WINAPI unhandledHandler( struct _EXCEPTION_POINTERS *apExceptionInfo )
 {
-	createMinidump(apExceptionInfo);
-	return EXCEPTION_CONTINUE_SEARCH;
+    createMinidump( apExceptionInfo );
+    return EXCEPTION_CONTINUE_SEARCH;
 }
 
+#ifdef _DEBUG
+template<typename TChar, typename TTraits>
+class OutputDebugStringBuf : public std::basic_stringbuf<TChar, TTraits>
+{
+public:
+    explicit OutputDebugStringBuf() : _buffer( 1 )
+    {
+        setg( nullptr, nullptr, nullptr );
+        setp( _buffer.data(), _buffer.data(), _buffer.data() + _buffer.size() );
+    }
+
+    ~OutputDebugStringBuf()
+    {}
+
+    static_assert( std::is_same<TChar, char>::value || std::is_same<TChar, wchar_t>::value, "OutputDebugStringBuf only supports char and wchar_t types" );
+
+    int sync() try
+    {
+        MessageOutputer<TChar, TTraits>()( pbase(), pptr() );
+        setp( _buffer.data(), _buffer.data(), _buffer.data() + _buffer.size() );
+        return 0;
+    } catch( ... )
+    {
+        return -1;
+    }
+
+    int overflow( int c = TTraits::eof() )
+    {
+        auto syncRet = sync();
+        if( c != TTraits::eof() )
+        {
+            _buffer[ 0 ] = c;
+            setp( _buffer.data(), _buffer.data() + 1, _buffer.data() + _buffer.size() );
+        }
+        return syncRet == -1 ? TTraits::eof() : 0;
+    }
+
+
+private:
+    std::vector<TChar>		_buffer;
+
+    template<typename TChar, typename TTraits>
+    struct MessageOutputer;
+
+    template<>
+    struct MessageOutputer<char, std::char_traits<char>>
+    {
+        template<typename TIterator>
+        void operator()( TIterator begin, TIterator end ) const
+        {
+            std::string s( begin, end );
+            OutputDebugStringA( s.c_str() );
+        }
+    };
+
+    template<>
+    struct MessageOutputer<wchar_t, std::char_traits<wchar_t>>
+    {
+        template<typename TIterator>
+        void operator()( TIterator begin, TIterator end ) const
+        {
+            std::wstring s( begin, end );
+            OutputDebugStringW( s.c_str() );
+        }
+    };
+};
+#endif
+
 
 int WINAPI WinMain( _In_ HINSTANCE hinst, _In_opt_ HINSTANCE hpinst, _In_ LPSTR cmd, int _In_ show )
 {
 #ifdef _DEBUG
     _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
+    OutputDebugStringBuf<char, std::char_traits<char>> charDebugOutput;
+    std::streambuf *buf = std::cout.rdbuf();
+    std::cout.rdbuf( &charDebugOutput );
 #else
-	SetUnhandledExceptionFilter(unhandledHandler);
+    SetUnhandledExceptionFilter( unhandledHandler );
 #endif
     Framework::initFramework( hinst );
     Framework::Startparam stp;
@@ -83,6 +157,9 @@ int WINAPI WinMain( _In_ HINSTANCE hinst, _In_opt_ HINSTANCE hpinst, _In_ LPSTR
     stp.show = show;
     int ret = Framework::Start( stp );
     Framework::releaseFramework();
+#ifdef _DEBUG
+    std::cout.rdbuf( buf );
+#endif
     return ret;
 }