Browse Source

Direct X code wird in Graphics API ausgelagert
DirectX9 wird wenn benötigt dynamisch geladen

Kolja Strohm 5 years ago
parent
commit
49191afa5a
16 changed files with 1260 additions and 777 deletions
  1. 117 618
      Bildschirm.cpp
  2. 6 36
      Bildschirm.h
  3. 11 43
      Cube.cpp
  4. 5 12
      Cube.h
  5. 99 0
      DLLRegister.cpp
  6. 34 0
      DLLRegister.h
  7. 5 1
      Framework.vcxproj
  8. 12 0
      Framework.vcxproj.filters
  9. 10 8
      Global.cpp
  10. 5 3
      Globals.h
  11. 783 0
      GraphicsApi.cpp
  12. 131 0
      GraphicsApi.h
  13. 2 13
      TexturModel.cpp
  14. 3 6
      TexturModel.h
  15. 18 18
      UIPixelShader.h
  16. 19 19
      UIVertexShader.h

+ 117 - 618
Bildschirm.cpp

@@ -15,6 +15,7 @@
 #include "Textur.h"
 #include "TexturModel.h"
 #include "TexturList.h"
+#include "GraphicsApi.h"
 #ifdef WIN32
 #include "Kam3D.h"
 #include <DirectXMath.h>
@@ -34,8 +35,8 @@ using namespace Framework;
 // Inhalt der Bildschirmklass aus Bildschirm.h
 // Konstruktor 
 Bildschirm::Bildschirm( WFenster *f )
-    : fenster( f ),
-    renderB( new Bild( 1 ) ),
+    : api( 0 ),
+    fenster( f ),
     ref( 1 ),
     members( new RCArray<Zeichnung>() ),
     fillColor( 0xFF000000 ),
@@ -43,24 +44,19 @@ Bildschirm::Bildschirm( WFenster *f )
     onTop( 0 ),
     renderOnTop( 0 ),
     renderZeichnungen( 1 ),
-    vollbild( 0 ),
     rendering( 0 ),
     renderZeit( new ZeitMesser() ),
-    backBufferSize( 0, 0 ),
     tips( new RCArray< ToolTip >() ),
     tipAnzahl( 0 ),
     testRend( 1 ),
     fill( 1 ),
     rend( 0 )
-{
-}
+{}
 
 // Destruktor 
 Bildschirm::~Bildschirm()
 {
     lock();
-    if( renderB )
-        renderB->release();
 #ifdef WIN32
     if( fenster )
         fenster->release();
@@ -71,6 +67,8 @@ Bildschirm::~Bildschirm()
     renderZeit->release();
     if( onTop )
         onTop->release();
+    if( api )
+        api->release();
     unlock();
 }
 
@@ -90,6 +88,14 @@ void Bildschirm::setFill( bool f )
     fill = f;
 }
 
+// Aktualisiert die Objekte, mit der die Grafikkarte verwaltet wird
+void Bildschirm::update()
+{
+    lock();
+    api->update();
+    unlock();
+}
+
 void Bildschirm::setTestRend( bool tr ) // legt fest, ob vo rendern auf updates geprüft werden soll
 {
     testRend = tr;
@@ -109,7 +115,7 @@ void Bildschirm::setOnTop( bool onTop ) // legt fest, ob das onTop Zeichnung ger
     rend = 1;
 }
 
-void Bildschirm::setOnTopZeichnung( Zeichnung *obj ) // setzt das OnTop Zeichnung
+void Bildschirm::setOnTopZeichnung( Zeichnung * obj ) // setzt das OnTop Zeichnung
 {
     lock();
     if( onTop )
@@ -125,7 +131,7 @@ void Bildschirm::setdeckFarbe( int f ) // setzt die deckFarbe
     rend = 1;
 }
 
-void Bildschirm::addMember( Zeichnung *obj ) // Fügt ein Zeichnung hinzu
+void Bildschirm::addMember( Zeichnung * obj ) // Fügt ein Zeichnung hinzu
 {
     lock();
     members->add( obj );
@@ -133,7 +139,7 @@ void Bildschirm::addMember( Zeichnung *obj ) // F
     unlock();
 }
 
-void Bildschirm::removeMember( Zeichnung *zObj ) // Entfernt ein Zeichnung
+void Bildschirm::removeMember( Zeichnung * zObj ) // Entfernt ein Zeichnung
 {
     lock();
     for( int i = 0; i < members->getEintragAnzahl(); i++ )
@@ -145,6 +151,15 @@ void Bildschirm::removeMember( Zeichnung *zObj ) // Entfernt ein Zeichnung
     unlock();
 }
 
+// Zeichnet ein Bild und präsentiert es auf dem Bildschirm
+void Bildschirm::render()
+{
+    lock();
+    api->update();
+    rend = 1;
+    unlock();
+}
+
 void Bildschirm::setFillFarbe( int f ) // setzt die Fill Farbe
 {
     fillColor = f;
@@ -154,8 +169,7 @@ void Bildschirm::setFillFarbe( int f ) // setzt die Fill Farbe
 void Bildschirm::setVollbild( bool vollbild ) // setzt vollbild
 {
     lock();
-    this->vollbild = vollbild;
-    rend = 1;
+    api->setFullScreen( vollbild );
     unlock();
 }
 
@@ -181,33 +195,30 @@ void Bildschirm::tick( double tickval )
 void Bildschirm::setBackBufferSize( int breite, int height ) // setzt die Größe des Backbuffers
 {
     lock();
-    backBufferSize.x = breite;
-    backBufferSize.y = height;
-    rend = 1;
+    api->setBackBufferSize( Vec2< int >( breite, height ) );
     unlock();
 }
 
-void Bildschirm::setBackBufferSize( Punkt &size )
+void Bildschirm::setBackBufferSize( Punkt & size )
 {
     lock();
-    backBufferSize = size;
-    rend = 1;
+    api->setBackBufferSize( size );
     unlock();
 }
 
-void Bildschirm::doMausEreignis( MausEreignis &me ) // sendet maus Ereignis
+void Bildschirm::doMausEreignis( MausEreignis & me ) // sendet maus Ereignis
 {
-    int fBr = backBufferSize.x;
-    int fHi = backBufferSize.y;
+    int fBr = api->getBackBufferSize().x;
+    int fHi = api->getBackBufferSize().y;
 #ifdef WIN32
-	if( fenster )
-	{
-		fBr = fenster->getKörperBreite();
-		fHi = fenster->getKörperHöhe();
-	}
+    if( fenster )
+    {
+        fBr = fenster->getKörperBreite();
+        fHi = fenster->getKörperHöhe();
+    }
 #endif
-    me.mx = (int)( me.mx * backBufferSize.x / (double)fBr + 0.5 );
-    me.my = (int)( me.my * backBufferSize.y / (double)fHi + 0.5 );
+    me.mx = (int)( me.mx * api->getBackBufferSize().x / (double)fBr + 0.5 );
+    me.my = (int)( me.my * api->getBackBufferSize().y / (double)fHi + 0.5 );
     lock();
     if( !renderOnTop )
     {
@@ -225,7 +236,7 @@ void Bildschirm::doMausEreignis( MausEreignis &me ) // sendet maus Ereignis
     unlock();
 }
 
-void Bildschirm::doTastaturEreignis( TastaturEreignis &te ) // sendet tastatur Ereignis
+void Bildschirm::doTastaturEreignis( TastaturEreignis & te ) // sendet tastatur Ereignis
 {
     lock();
     if( !renderOnTop )
@@ -238,7 +249,7 @@ void Bildschirm::doTastaturEreignis( TastaturEreignis &te ) // sendet tastatur E
     unlock();
 }
 
-void Bildschirm::addToolTip( ToolTip *tip ) // fügt ToolTip hinzu
+void Bildschirm::addToolTip( ToolTip * tip ) // fügt ToolTip hinzu
 {
     lock();
     tips->add( tip, tipAnzahl );
@@ -247,7 +258,7 @@ void Bildschirm::addToolTip( ToolTip *tip ) // f
     unlock();
 }
 
-bool Bildschirm::removeToolTip( ToolTip *zTip ) // entfernt ToolTip
+bool Bildschirm::removeToolTip( ToolTip * zTip ) // entfernt ToolTip
 {
     lock();
     bool gefunden = 0;
@@ -270,15 +281,15 @@ bool Bildschirm::removeToolTip( ToolTip *zTip ) // entfernt ToolTip
 // constant 
 Bild *Bildschirm::getRenderBild() const
 {
-    return renderB->getThis();
+    return api->zUIRenderBild()->getThis();
 }
 
 Bild *Bildschirm::zRenderBild() const
 {
-    return renderB;
+    return api->zUIRenderBild();
 }
 
-Iterator<Zeichnung*> Bildschirm::getMembers() const // gibt die Zeichnunge zurück
+Iterator<Zeichnung *> Bildschirm::getMembers() const // gibt die Zeichnunge zurück
 {
     return members->getIterator();
 }
@@ -290,12 +301,12 @@ int Bildschirm::getFillFarbe() const // gibt die F
 
 bool Bildschirm::istVolbild() const // gibt zurück, ob vollbild an ist
 {
-    return vollbild;
+    return api->isFullScreen();
 }
 
-const Punkt &Bildschirm::getBackBufferSize() const // gibt die Größe des Backbuffers zurück
+const Punkt Bildschirm::getBackBufferSize() const // gibt die Größe des Backbuffers zurück
 {
-    return backBufferSize;
+    return api->getBackBufferSize();
 }
 
 void Bildschirm::warteAufRendern() const // wartet auf die render Funktion
@@ -335,7 +346,7 @@ int MonitorEnum( HMONITOR m, HDC dc, LPRECT r, LPARAM p )
     mon->y = r->top;
     mon->breite = r->right - r->left;
     mon->height = r->bottom - r->top;
-    ( ( Array< Monitor* >* )p )->add( mon );
+    ( ( Array< Monitor * > * )p )->add( mon );
     return 1;
 }
 
@@ -347,7 +358,7 @@ Monitor Framework::getMonitor( int id )
         m.existiert = 0;
         return m;
     }
-    Array< Monitor* > *monitore = new Array< Monitor* >();
+    Array< Monitor * > *monitore = new Array< Monitor * >();
     EnumDisplayMonitors( 0, 0, (MONITORENUMPROC)MonitorEnum, (LPARAM)monitore );
     int anz = monitore->getEintragAnzahl();
     if( id >= monitore->getEintragAnzahl() )
@@ -367,144 +378,52 @@ Monitor Framework::getMonitor( int id )
 }
 // Bildschirm2D
 // Konstruktor 
-Bildschirm2D::Bildschirm2D( WFenster *fenster )
-    : Bildschirm( fenster ),
-    pDirect3D( 0 ),
-    pDevice( 0 ),
-    pBackBuffer( 0 ),
-    backRect( new D3DLOCKED_RECT() )
-{}
-
-// Destruktor 
-Bildschirm2D::~Bildschirm2D()
-{
-    cleanUpDirectX();
-    delete backRect;
-}
-
-// private
-void Bildschirm2D::cleanUpDirectX()
+Bildschirm2D::Bildschirm2D( WFenster * fenster )
+    : Bildschirm( fenster )
 {
-    backRect->pBits = NULL;
-    if( pDevice )
-    {
-        pDevice->Release();
-        pDevice = NULL;
-    }
-    if( pDirect3D )
-    {
-        pDirect3D->Release();
-        pDirect3D = NULL;
-    }
-    if( pBackBuffer )
-    {
-        pBackBuffer->Release();
-        pBackBuffer = NULL;
-    }
+    api = new DirectX9();
+    api->initialize( fenster->getThis(), fenster->getKörperGröße(), 0 );
 }
 
-// nicht constant 
-void Bildschirm2D::update() // aktualisiert directX
-{
-    lock();
-    HRESULT result;
-
-    cleanUpDirectX();
-
-    pDirect3D = Direct3DCreate9( D3D_SDK_VERSION );
-
-    D3DPRESENT_PARAMETERS d3dpp;
-    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
-    d3dpp.Windowed = !vollbild;
-    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;
-    if( renderB )
-        renderB->release();
-    renderB = new Bild( 1 );
-    renderB->neuBild( backBufferSize.x, backBufferSize.y, fillColor );
-
-    result = pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, fenster->getFensterHandle(),
-                                      D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &d3dpp, &pDevice );
-    if( pDevice )
-        result = pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
-    rend = 1;
-    unlock();
-}
+// Destruktor 
+Bildschirm2D::~Bildschirm2D()
+{}
 
 void Bildschirm2D::render() // Zeichnet das Bild
 {
     if( !rend && testRend )
         return;
     rendering = 1;
-    int count = 0;
-    if( renderB && pDevice )
+    Bild * ui = api->zUIRenderBild();
+    if( ui )
     {
         lock();
         renderZeit->messungStart();
-        if( fill )
-            renderB->setFarbe( fillColor );
+        api->beginFrame( fill && ( rend || !testRend ), 0, fillColor );
         if( renderZeichnungen )
         {
-            if( renderOnTop && deckFarbe && ( deckFarbe & ( fillColor | 0xFF000000 ) ) == deckFarbe )
+            if( renderOnTop &&deckFarbe && ( deckFarbe &( fillColor | 0xFF000000 ) ) == deckFarbe )
             {
-                renderB->setAlpha( 255 - (unsigned char)( deckFarbe >> 24 ) );
+                ui->setAlpha( 255 - (unsigned char)( deckFarbe >> 24 ) );
                 for( auto i = members->getIterator(); i; i++ )
-                    i->render( *renderB ); // zeichnen nach zwischenbuffer
-                renderB->releaseAlpha();
+                    i->render( *ui ); // zeichnen nach zwischenbuffer
+                ui->releaseAlpha();
             }
             else
             {
                 for( auto i = members->getIterator(); i; i++ )
-                    i->render( *renderB ); // zeichnen nach zwischenbuffer
-                if( renderOnTop && deckFarbe )
-                    renderB->alphaRegion( 0, 0, renderB->getBreite(), renderB->getHeight(), deckFarbe );
+                    i->render( *ui ); // zeichnen nach zwischenbuffer
+                if( renderOnTop &&deckFarbe )
+                    ui->alphaRegion( 0, 0, ui->getBreite(), ui->getHeight(), deckFarbe );
             }
             for( int i = 0; i < tipAnzahl; ++i )
-                tips->z( i )->render( *renderB );
+                tips->z( i )->render( *ui );
         }
-        if( renderOnTop && onTop )
-            onTop->render( *renderB );
-        Bild *tmp = renderB->getThis();
-        unlock();
-        // Beginne Bild 
-        HRESULT result;
-        if( !fillColor )
-            result = pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 0.0f, 0 );
-        result = pBackBuffer->LockRect( backRect, 0, 0 );
-        // kopieren zum Bildschrirm 
-        int *bgBuff = tmp->getBuffer();
-        int tmpBr = sizeof( D3DCOLOR )* tmp->getBreite();
-        for( int y = 0, pitch = 0, bry = 0; y < tmp->getHeight(); ++y, pitch += backRect->Pitch, bry += tmp->getBreite() )
-            memcpy( &( (BYTE *)backRect->pBits )[ pitch ], ( void* )&( bgBuff[ bry ] ), tmpBr );
-        // Beende Bild 
-        result = pBackBuffer->UnlockRect();
-        tmp->release();
-        result = pDevice->Present( 0, 0, 0, 0 );
+        if( renderOnTop &&onTop )
+            onTop->render( *ui );
+        api->presentFrame();
         renderZeit->messungEnde();
-        if( result != S_OK )
-        {
-            ++count;
-            update();
-        }
-        else if( count )
-            --count;
-    }
-    if( !pDevice )
-    {
-        ++count;
-        update();
-    }
-    if( count > 10 )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        count = 0;
+        unlock();
     }
     rendering = 0;
     rend = 0;
@@ -512,115 +431,23 @@ void Bildschirm2D::render() // Zeichnet das Bild
 
 // Bildschirm3D
 // Konstruktor 
-Bildschirm3D::Bildschirm3D( WFenster *fenster )
+Bildschirm3D::Bildschirm3D( WFenster * fenster )
     : Bildschirm( fenster ),
-    d3d11Device( 0 ),
-    d3d11Context( 0 ),
-    d3d11SpawChain( 0 ),
-    frameworkTextur( 0 ),
-    vertexShader( 0 ),
-    pixelShader( 0 ),
-    sampleState( 0 ),
-    rtview( 0 ),
-    dsView( 0 ),
-    depthStencilBuffer( 0 ),
-    depthStencilState( 0 ),
-    depthDisabledStencilState( 0 ),
-    blendStateAlphaBlend( 0 ),
     kameras( new RCArray< Kam3D >() ),
-    rend3D( 0 ),
-    vp( 0 ),
-    renderObj( new Render3D() ),
-    texturModel( new TexturModel() )
-{}
+    rend3D( 0 )
+{
+    api = new DirectX11();
+    api->initialize( fenster->getThis(), fenster->getKörperGröße(), 0 );
+}
 
 // Destruktor 
 Bildschirm3D::~Bildschirm3D()
 {
     kameras->release();
-    texturModel->release();
-    cleanUpDirectX();
-}
-
-// private
-void Bildschirm3D::cleanUpDirectX()
-{
-    if( renderObj )
-    {
-        renderObj->release();
-        renderObj = 0;
-    }
-    if( blendStateAlphaBlend )
-    {
-        blendStateAlphaBlend->Release();
-        blendStateAlphaBlend = NULL;
-    }
-    if( frameworkTextur )
-    {
-        frameworkTextur->release();
-        frameworkTextur = 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;
-    }
 }
 
 // nicht constant 
-void Bildschirm3D::addKamera( Kam3D *obj ) // Fügt ein Zeichnung hinzu
+void Bildschirm3D::addKamera( Kam3D * obj ) // Fügt ein Zeichnung hinzu
 {
     lock();
     kameras->add( obj );
@@ -628,7 +455,7 @@ void Bildschirm3D::addKamera( Kam3D *obj ) // F
     unlock();
 }
 
-void Bildschirm3D::removeKamera( Kam3D *zObj ) // Entfernt ein Zeichnung
+void Bildschirm3D::removeKamera( Kam3D * zObj ) // Entfernt ein Zeichnung
 {
     lock();
     for( int i = 0; kameras->z( i ); i++ )
@@ -643,290 +470,16 @@ void Bildschirm3D::removeKamera( Kam3D *zObj ) // Entfernt ein Zeichnung
     unlock();
 }
 
-void Bildschirm3D::update() // aktualisiert directX
-{
-    lock();
-    HRESULT result;
-    cleanUpDirectX();
-    //--------------------------------------------------------------------
-    // Create Device
-
-    // 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 = !vollbild;
-    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;
-    if( renderB )
-        renderB->release();
-    renderB = new Bild( 1 );
-    renderB->setAlpha3D( 1 );
-    renderB->neuBild( backBufferSize.x, backBufferSize.y, fillColor );
-
-    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
-    result = D3D11CreateDeviceAndSwapChain( 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";
-        return;
-    }
-    ID3D11Texture2D *backBufferPtr;
-    // Get the pointer to the back buffer.
-    result = d3d11SpawChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (LPVOID*)&backBufferPtr );
-    // Create the render target view with the back buffer pointer.
-    result = d3d11Device->CreateRenderTargetView( backBufferPtr, NULL, &rtview );
-    // 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 );
-
-    // 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 );
-
-    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 );
-
-    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 );
-
-    //-------------------------------------------------
-    // Shaders
-    vertexShader = new VertexShader();
-    vertexShader->setCompiledByteArray( d3d11Device, (unsigned char*)UIVertexShader, sizeof( UIVertexShader ) );
-
-    pixelShader = new PixelShader();
-    pixelShader->setCompiledByteArray( d3d11Device, (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( d3d11Device, polygonLayout, 4 );
-    vertexShader->erstelleConstBuffer( d3d11Device, sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 ); // matrizen für skelett annimationen
-    vertexShader->erstelleConstBuffer( d3d11Device, sizeof( Mat4< float > ) * 2, 1 ); // View and Projection Matrix
-
-    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( float ) * 3, 0 ); // Kamera Position
-    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( float ) * 3, 1 ); // materialkonstanten nach phong model
-    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( int ) * 2, 2 ); // materialkonstanten nach phong model
-    // TODO: Remove Following Test Code
-    int lc[] = { 1, 6 };
-    pixelShader->füllConstBuffer( d3d11Context, (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 );
-
-    //---------------------------------------------------------------
-    // Framework Backbuffer Texture
-
-    frameworkTextur = new Textur();
-    frameworkTextur->setBildZ( renderB->getThis() );
-    texturRegister->addTextur( frameworkTextur->getThis(), "f_Render_Bild" );
-
-    texturModel->setSize( backBufferSize );
-    texturModel->setTextur( frameworkTextur->getId() );
-
-    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
-    if( renderObj )
-        renderObj->release();
-    renderObj = new Render3D();
-    d3d11Device->AddRef();
-    renderObj->setDevice( d3d11Device );
-    d3d11Context->AddRef();
-    renderObj->setContext( d3d11Context );
-
-    renderObj->benutzeShader( VERTEX, vertexShader->getThis() );
-    d3d11Context->PSSetSamplers( 0, 1, &sampleState );
-    renderObj->benutzeShader( PIXEL, pixelShader->getThis() );
-
-    rend = 1;
-    unlock();
-}
-
 void Bildschirm3D::tick( double tickval )
 {
     lock();
     __super::tick( tickval );
     for( auto i = kameras->getIterator(); i; i++ )
         rend3D |= i->tick( tickval );
-    rend3D |= texturModel->tick( tickval );
     unlock();
 }
 
-void Bildschirm3D::doMausEreignis( MausEreignis &me ) // sendet maus Ereignis
+void Bildschirm3D::doMausEreignis( MausEreignis & me ) // sendet maus Ereignis
 {
     lock();
     __super::doMausEreignis( me );
@@ -935,7 +488,7 @@ void Bildschirm3D::doMausEreignis( MausEreignis &me ) // sendet maus Ereignis
     unlock();
 }
 
-void Bildschirm3D::doTastaturEreignis( TastaturEreignis &te ) // sendet tastatur Ereignis
+void Bildschirm3D::doTastaturEreignis( TastaturEreignis & te ) // sendet tastatur Ereignis
 {
     lock();
     __super::doTastaturEreignis( te );
@@ -949,103 +502,49 @@ void Bildschirm3D::render() // Zeichnet das Bild
     if( !rend && !rend3D && testRend )
         return;
     rendering = 1;
-    int count = 0;
-    if( renderB && d3d11Device )
+    lock();
+    renderZeit->messungStart();
+    // Clear the back buffer.
+    api->beginFrame( fill && ( rend || !testRend ), fill && ( rend3D || !testRend || rend ), fillColor );
+    if( rend3D || !testRend || rend )
     {
-        lock();
-        renderZeit->messungStart();
-        float color[ 4 ];
-        // Setup the color to clear the buffer to.
-        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
-        // Clear the back buffer.
-        if( rend3D || !testRend || rend )
+        // Render 3d Objects
+        for( auto i = kameras->getIterator(); i; i++ )
+            api->renderKamera( i._ );
+        rend3D = 0;
+    }
+    // render User Interface
+    Bild *ui = api->zUIRenderBild();
+    if( ( rend || !testRend ) && ui )
+    {
+        if( renderZeichnungen )
         {
-            if( fill )
+            if( renderOnTop &&deckFarbe && ( deckFarbe &( fillColor | 0xFF000000 ) ) == deckFarbe )
             {
-                d3d11Context->ClearRenderTargetView( rtview, color );
-                // Clear the depth buffer.
-                d3d11Context->ClearDepthStencilView( dsView, D3D11_CLEAR_DEPTH, 1, 0 );
+                ui->setAlpha( 255 - (unsigned char)( deckFarbe >> 24 ) );
+                for( auto i = members->getIterator(); i; i++ )
+                    i->render( *ui ); // zeichnen nach zwischenbuffer
+                ui->releaseAlpha();
             }
-            // 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 );
-
-            for( auto i = kameras->getIterator(); i; i++ )
-                i->render( renderObj );
-            rend3D = 0;
-        }
-        // Set the depth stencil state.
-        d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
-
-        if( rend || !testRend )
-        {
-            if( fill )
-                renderB->setFarbe( fillColor );
-            if( renderZeichnungen )
+            else
             {
-                if( renderOnTop && deckFarbe && ( deckFarbe & ( fillColor | 0xFF000000 ) ) == deckFarbe )
-                {
-                    renderB->setAlpha( 255 - (unsigned char)( deckFarbe >> 24 ) );
-                    for( auto i = members->getIterator(); i; i++ )
-                        i->render( *renderB ); // zeichnen nach zwischenbuffer
-                    renderB->releaseAlpha();
-                }
-                else
-                {
-                    for( auto i = members->getIterator(); i; i++ )
-                        i->render( *renderB ); // zeichnen nach zwischenbuffer
-                    if( renderOnTop && deckFarbe )
-                        renderB->alphaRegion( 0, 0, renderB->getBreite(), renderB->getHeight(), deckFarbe );
-                }
-                for( int i = 0; i < tipAnzahl; ++i )
-                    tips->z( i )->render( *renderB );
+                for( auto i = members->getIterator(); i; i++ )
+                    i->render( *ui ); // zeichnen nach zwischenbuffer
+                if( renderOnTop &&deckFarbe )
+                    ui->alphaRegion( 0, 0, ui->getBreite(), ui->getHeight(), deckFarbe );
             }
-            if( renderOnTop && onTop )
-                onTop->render( *renderB );
+            for( int i = 0; i < tipAnzahl; ++i )
+                tips->z( i )->render( *ui );
         }
-        // Beginne Bild 
-        HRESULT result;
-
-        if( rend || !testRend )
-            frameworkTextur->updateTextur( renderObj );
-
-        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 ) );
-        renderObj->setKameraMatrix( view, view.projektion( DirectX::XM_PI / 4.0f, screenAspect, 0.1f, 10000.f ), Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
-        if( fenster && !IsIconic( fenster->getFensterHandle() ) )
-            texturModel->render( renderObj );
-        unlock();
-
-        result = d3d11SpawChain->Present( 0, 0 );
-        renderZeit->messungEnde();
+        if( renderOnTop &&onTop )
+            onTop->render( *ui );
+    }
+    api->presentFrame();
+    renderZeit->messungEnde();
+    unlock();
 #ifdef _DEBUG
-        //std::cout << renderZeit->getSekunden() << "\n";
+    //std::cout << renderZeit->getSekunden() << "\n";
 #endif
-        if( !SUCCEEDED( result ) )
-        {
-            ++count;
-            update();
-        }
-        else if( count )
-            --count;
-    }
-    if( !d3d11Device )
-    {
-        ++count;
-        update();
-    }
-    if( count > 10 )
-    {
-        WMessageBox( fenster ? fenster->getFensterHandle() : 0, new Text( "Fehler" ), new Text( "Es ist ein Fehler beim rendern aufgetreten." ), MB_ICONERROR );
-        count = 0;
-    }
     rendering = 0;
     rend = 0;
 }

+ 6 - 36
Bildschirm.h

@@ -46,6 +46,8 @@ namespace Framework
     class DXIndexBuffer; // DXBuffer.h
     class Textur; // Textur.h
     class TexturModel; // TexturModel.h
+    class GraphicsApi; // GraphicsApi.h
+    class DirectX9; // GraphicsApi.h
 
     // Eine Struktur, die Informationen über einen Monitor beinhaltet
     struct Monitor
@@ -58,8 +60,8 @@ namespace Framework
     class Bildschirm
     {
     protected:
+        GraphicsApi *api;
         WFenster *fenster;
-        Bild *renderB;
         int ref;
         RCArray<Zeichnung> *members;
         int fillColor;
@@ -67,10 +69,8 @@ namespace Framework
         Zeichnung *onTop;
         bool renderOnTop;
         bool renderZeichnungen;
-        bool vollbild;
         bool rendering;
         ZeitMesser *renderZeit;
-        Punkt backBufferSize;
         Critical cs;
         RCArray< ToolTip > *tips;
         int tipAnzahl;
@@ -94,7 +94,7 @@ namespace Framework
         //  f: 1, falls das Bild vor dem Zeichnen zurückgesetzt werden soll
         __declspec( dllexport ) virtual void setFill( bool f );
         // Aktualisiert die Objekte, mit der die Grafikkarte verwaltet wird
-        __declspec( dllexport ) virtual void update() = 0;
+        __declspec( dllexport ) virtual void update();
         // Legt fest, ob von dem Zeichnen überprüft wird, ob sich das Bild vom letzten unterscheidet (Standartmäßig gesetzt)
         //  tr: 1, wenn nur gezeichnet werden soll, wenn es notwendig ist
         __declspec( dllexport ) virtual void setTestRend( bool tr );
@@ -117,7 +117,7 @@ namespace Framework
         //  obj: Die Zeichnung (ohne erhöhten reference Counter)
         __declspec( dllexport ) virtual void removeMember( Zeichnung *zObj );
         // Zeichnet ein Bild und präsentiert es auf dem Bildschirm
-        __declspec( dllexport ) virtual void render() = 0;
+        __declspec( dllexport ) virtual void render();
         // Setzt die Farbe, mit der das Bild for dem Zeichnen gefüllt wird, wenn setFüll( 1 ) gesetzt wurde
         //  f: Die Farbe im A8R8G8B8 Format
         __declspec( dllexport ) virtual void setFillFarbe( int f );
@@ -160,7 +160,7 @@ namespace Framework
         // Gibt zurück, ob man sich im Vollbildmodus befindet
         __declspec( dllexport ) virtual bool istVolbild() const;
         // Gibt die Auflösung in Pixeln zurück, in der gezeichnet wird
-        __declspec( dllexport ) virtual const Punkt &getBackBufferSize() const;
+        __declspec( dllexport ) virtual const Punkt getBackBufferSize() const;
         // Wartet, bis das Zeichnen des aktuellen Bildes abgeschlossen ist
         __declspec( dllexport ) virtual void warteAufRendern() const;
         // Gibt die Zeit in Sekunden zurück, die benötigt wurde, um das letzte Bild zu zeichnen
@@ -176,22 +176,12 @@ namespace Framework
     // Diese Klasse verwaltet das Bild auf dem Bildschirm ohne 3D Elemente
     class Bildschirm2D : public Bildschirm
     {
-    private:
-        IDirect3D9			*pDirect3D;
-        IDirect3DDevice9	*pDevice;
-        IDirect3DSurface9	*pBackBuffer;
-        _D3DLOCKED_RECT		*backRect;
-
-        void cleanUpDirectX();
-
     public:
         // Konstruktor 
         //  fenster: Das Fenster, dessen Inhalt verwaltet werden soll
         __declspec( dllexport ) Bildschirm2D( WFenster *fenster );
         // Destruktor 
         __declspec( dllexport ) virtual ~Bildschirm2D();
-        // Aktualisiert die Objekte, mit der die Grafikkarte verwaltet wird
-        __declspec( dllexport ) virtual void update();
         // Zeichnet ein Bild und präsentiert es auf dem Bildschirm
         __declspec( dllexport ) virtual void render();
     };
@@ -200,27 +190,9 @@ namespace Framework
     class Bildschirm3D : public Bildschirm
     {
     private:
-        ID3D11Device *d3d11Device;
-        ID3D11DeviceContext *d3d11Context;
-        IDXGISwapChain *d3d11SpawChain;
-        Textur *frameworkTextur;
-        ID3D11SamplerState* sampleState;
-        ID3D11RenderTargetView *rtview;
-        ID3D11DepthStencilView *dsView;
-        ID3D11Texture2D *depthStencilBuffer;
-        ID3D11DepthStencilState *depthStencilState;
-        ID3D11DepthStencilState *depthDisabledStencilState;
-        ID3D11BlendState *blendStateAlphaBlend;
         RCArray< Kam3D > *kameras;
-        PixelShader *pixelShader;
-        VertexShader *vertexShader;
-        Render3D *renderObj;
-        D3D11_VIEWPORT *vp;
-        TexturModel *texturModel;
         bool rend3D;
 
-        void cleanUpDirectX();
-
     public:
         // Konstruktor 
         //  fenster: Das Fenster, dessen Inhalt verwaltet werden soll
@@ -244,8 +216,6 @@ namespace Framework
         // Gibt das Ereignis automatisch an alle sich im Bild befindenden Zeichnungen und Kameras weiter
         //  te: Das Ereignis
         __declspec( dllexport ) void doTastaturEreignis( TastaturEreignis &te );
-        // Aktualisiert die Objekte, mit der die Grafikkarte verwaltet wird
-        __declspec( dllexport ) void update();
         // Zeichnet ein Bild und präsentiert es auf dem Bildschirm
         __declspec( dllexport ) void render();
     };

+ 11 - 43
Cube.cpp

@@ -173,55 +173,23 @@ Cube::Cube( float size )
 }
 
 // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
-//  textur: Die Textur als Bild
-void Cube::setTextur( Bild *textur )
+//  textur: Die Textur
+void Cube::setTextur( Textur *textur )
 {
-    Textur *t = new Textur();
-    t->setBildZ( textur );
-    this->textur->setPolygonTextur( LINKS, t->getThis() );
-    this->textur->setPolygonTextur( OBEN, t->getThis() );
-    this->textur->setPolygonTextur( RECHTS, t->getThis() );
-    this->textur->setPolygonTextur( UNTEN, t->getThis() );
-    this->textur->setPolygonTextur( VORNE, t->getThis() );
-    this->textur->setPolygonTextur( HINTEN, t );
-    rend = 1;
-}
-
-// Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
-//  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
-void Cube::setTextur( int id )
-{
-    Textur *t = texturRegister->getTextur( id );
-    if( !t )
-        return;
-    this->textur->setPolygonTextur( LINKS, t->getThis() );
-    this->textur->setPolygonTextur( OBEN, t->getThis() );
-    this->textur->setPolygonTextur( RECHTS, t->getThis() );
-    this->textur->setPolygonTextur( UNTEN, t->getThis() );
-    this->textur->setPolygonTextur( VORNE, t->getThis() );
-    this->textur->setPolygonTextur( HINTEN, t );
-    rend = 1;
-}
-
-// Setzt die Textur von einer bestimmten Seite des Würfels
-//  textur: Die Textur als Bild
-//  s: Die Seite, die gesetzt werden soll
-void Cube::setTextur( Bild *textur, CubeSeite s )
-{
-    Textur *t = new Textur();
-    t->setBildZ( textur );
-    this->textur->setPolygonTextur( s, t );
+    this->textur->setPolygonTextur( LINKS, textur->getThis() );
+    this->textur->setPolygonTextur( OBEN, textur->getThis() );
+    this->textur->setPolygonTextur( RECHTS, textur->getThis() );
+    this->textur->setPolygonTextur( UNTEN, textur->getThis() );
+    this->textur->setPolygonTextur( VORNE, textur->getThis() );
+    this->textur->setPolygonTextur( HINTEN, textur );
     rend = 1;
 }
 
 // Setzt die Textur von einer bestimmten Seite des Würfels
-//  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
+//  textur: Die Textur
 //  s: Die Seite, die gesetzt werden soll
-void Cube::setTextur( int id, CubeSeite s )
+void Cube::setTextur( Textur *textur, CubeSeite s )
 {
-    Textur *t = texturRegister->getTextur( id );
-    if( !t )
-        return;
-    this->textur->setPolygonTextur( s, t );
+    this->textur->setPolygonTextur( s, textur );
     rend = 1;
 }

+ 5 - 12
Cube.h

@@ -4,7 +4,7 @@
 
 namespace Framework
 {
-    class Bild;
+    class Textur;
 
     enum CubeSeite
     {
@@ -24,18 +24,11 @@ namespace Framework
         //  size: Die Größe des Würfels
         __declspec( dllexport ) Cube( float size );
         // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
-        //  textur: Die Textur als Bild
-        __declspec( dllexport ) void setTextur( Bild *textur );
-        // Setzt die Textur des Würfels, so dass sie an allen Seiten gleich ist
-        //  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
-        __declspec( dllexport ) void setTextur( int id );
-        // Setzt die Textur von einer bestimmten Seite des Würfels
-        //  textur: Die Textur als Bild
-        //  s: Die Seite, die gesetzt werden soll
-        __declspec( dllexport ) void setTextur( Bild *textur, CubeSeite s );
+        //  textur: Die Textur
+        __declspec( dllexport ) void setTextur( Textur *textur );
         // Setzt die Textur von einer bestimmten Seite des Würfels
-        //  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
+        //  textur: Die Textur
         //  s: Die Seite, die gesetzt werden soll
-        __declspec( dllexport ) void setTextur( int id, CubeSeite s );
+        __declspec( dllexport ) void setTextur( Textur *textur, CubeSeite s );
     };
 }

+ 99 - 0
DLLRegister.cpp

@@ -0,0 +1,99 @@
+#include "DLLRegister.h"
+
+using namespace Framework;
+
+// Inhalt der DLLDateien Klasse aus DLLDateien.h
+// Konstruktor
+DLLRegister::DLLRegister()
+{
+    dlls = new Array< DLLDatei * >();
+    ref = 1;
+}
+
+// Destruktor
+DLLRegister::~DLLRegister()
+{
+    cs.lock();
+    int anz = dlls->getEintragAnzahl();
+    for( int i = 0; i < anz; i++ )
+    {
+        DLLDatei *tmp = dlls->get( i );
+        if( tmp )
+        {
+            tmp->name->release();
+            FreeLibrary( tmp->handle );
+        }
+        delete tmp;
+    }
+    dlls->release();
+    cs.unlock();
+}
+
+// nicht constant
+HINSTANCE DLLRegister::ladeDLL( char *name, char *pfad )
+{
+    cs.lock();
+    int anz = dlls->getEintragAnzahl();
+    for( int i = 0; i < anz; i++ )
+    {
+        DLLDatei *tmp = dlls->get( i );
+        if( tmp &&tmp->name->istGleich( name ) )
+        {
+            tmp->ref++;
+            cs.unlock();
+            return tmp->handle;
+        }
+    }
+    HINSTANCE h = LoadLibrary( pfad );
+    if( !h )
+    {
+        cs.unlock();
+        return 0;
+    }
+    DLLDatei *dll = new DLLDatei();
+    dll->name = new Text( name );
+    dll->handle = h;
+    dll->ref = 1;
+    dlls->add( dll );
+    cs.unlock();
+    return h;
+}
+
+void DLLRegister::releaseDLL( char *name )
+{
+    cs.lock();
+    int anz = dlls->getEintragAnzahl();
+    for( int i = 0; i < anz; i++ )
+    {
+        DLLDatei *tmp = dlls->get( i );
+        if( tmp &&tmp->name->istGleich( name ) )
+        {
+            tmp->ref--;
+            if( !tmp->ref )
+            {
+                tmp->name->release();
+                FreeLibrary( tmp->handle );
+                delete tmp;
+                dlls->remove( i );
+            }
+            cs.unlock();
+            return;
+        }
+    }
+    cs.unlock();
+}
+
+// Reference Counting
+DLLRegister *DLLRegister::getThis()
+{
+    ref++;
+    return this;
+}
+
+DLLRegister *DLLRegister::release()
+{
+    ref--;
+    if( !ref )
+        delete this;
+    return 0;
+}

+ 34 - 0
DLLRegister.h

@@ -0,0 +1,34 @@
+#pragma once
+
+#include "Array.h"
+#include "Critical.h"
+
+namespace Framework
+{
+    struct DLLDatei
+    {
+        Text *name;
+        HINSTANCE handle;
+        int ref;
+    };
+
+    class DLLRegister
+    {
+    private:
+        Array< DLLDatei * > *dlls;
+        Critical cs;
+        int ref;
+
+    public:
+        // Konstruktor
+        __declspec(dllexport) DLLRegister();
+        // Destruktor
+        __declspec( dllexport ) ~DLLRegister();
+        // nicht constant       
+        __declspec( dllexport ) HINSTANCE ladeDLL( char *name, char *pfad );
+        __declspec( dllexport ) void releaseDLL( char *name );
+        // Reference Counting   
+        __declspec( dllexport ) DLLRegister *getThis();
+        __declspec( dllexport ) DLLRegister *release();
+    };
+}

+ 5 - 1
Framework.vcxproj

@@ -125,7 +125,7 @@
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>d3dcompiler.lib;d3d9.lib;d3d11.lib;DXGI.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>d3dcompiler.lib;d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <CustomBuildStep>
       <Command>copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\Klient\Start\Start\framework.dll"
@@ -208,6 +208,8 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <ClInclude Include="Critical.h" />
     <ClInclude Include="Cube.h" />
     <ClInclude Include="Dialog.h" />
+    <ClInclude Include="DLLRegister.h" />
+    <ClInclude Include="GraphicsApi.h" />
     <ClInclude Include="DXBuffer.h" />
     <ClInclude Include="Datei.h" />
     <ClInclude Include="DateiDialog.h" />
@@ -290,10 +292,12 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <ClCompile Include="DateiSystem.cpp" />
     <ClCompile Include="Diagramm.cpp" />
     <ClCompile Include="Dialog.cpp" />
+    <ClCompile Include="DLLRegister.cpp" />
     <ClCompile Include="DXBuffer.cpp" />
     <ClCompile Include="Fenster.cpp" />
     <ClCompile Include="Fortschritt.cpp" />
     <ClCompile Include="Global.cpp" />
+    <ClCompile Include="GraphicsApi.cpp" />
     <ClCompile Include="InitDatei.cpp" />
     <ClCompile Include="JSON.cpp" />
     <ClCompile Include="Kam3D.cpp" />

+ 12 - 0
Framework.vcxproj.filters

@@ -312,6 +312,12 @@
     <ClInclude Include="UIInitialization.h">
       <Filter>Headerdateien\Framework</Filter>
     </ClInclude>
+    <ClInclude Include="GraphicsApi.h">
+      <Filter>Headerdateien\Framework\Grafik\DX</Filter>
+    </ClInclude>
+    <ClInclude Include="DLLRegister.h">
+      <Filter>Headerdateien\Framework\OS</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Maus.cpp">
@@ -497,6 +503,12 @@
     <ClCompile Include="UIInitialization.cpp">
       <Filter>Quelldateien\Framework</Filter>
     </ClCompile>
+    <ClCompile Include="GraphicsApi.cpp">
+      <Filter>Quelldateien\Framework\Grafik\DX</Filter>
+    </ClCompile>
+    <ClCompile Include="DLLRegister.cpp">
+      <Filter>Quelldateien\Framework\OS</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="UIPixelShader.hlsl">

+ 10 - 8
Global.cpp

@@ -14,6 +14,7 @@
 #include "Thread.h"
 #include "Datei.h"
 #include "Zeit.h"
+#include "DLLRegister.h"
 
 void Framework::initFramework( HINSTANCE__ *hInst )
 {
@@ -33,8 +34,8 @@ void Framework::initFramework( HINSTANCE__ *hInst )
 	Model3DList::init();
 	m3dRegister = new Model3DList();
 	TexturList::init();
-	texturRegister = new TexturList();
     thRegister = new ThreadRegister();
+    dlls = new DLLRegister();
     logEnabled = 0;
     logFile = 0;
     _hinst = hInst;
@@ -49,10 +50,10 @@ void Framework::releaseFramework()
     delete thRegister;
 	m3dRegister->release();
 	Model3DList::destroy();
-	texturRegister->release();
 	TexturList::destroy();
     if( logFile )
         logFile->release();
+    dlls->release();
     istInitialisiert = 0;
 }
 
@@ -97,12 +98,6 @@ Framework::Model3DList *Framework::zM3DRegister()
 	return m3dRegister;
 }
 
-// Gibt das Textur Register des Frameworks ohne erhöhten reference Counter zurück
-Framework::TexturList *Framework::zTexturRegister()
-{
-	return texturRegister;
-}
-
 // Legt fest ob Log Nachrichten gespeichert werden sollen
 void Framework::setLogEnabled( bool le )
 {
@@ -138,6 +133,13 @@ void Framework::logLine( char *txt )
         logC.unlock();
     }
 }
+
+// Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL Dateien hinterlegt sind
+Framework::DLLRegister *Framework::getDLLRegister()
+{
+    return Framework::dlls;
+}
+
 #ifdef WIN32
 // gibt eine Referenz auf die Maus zurück
 Framework::Maus &Framework::getMaus()

+ 5 - 3
Globals.h

@@ -17,6 +17,8 @@ namespace Framework
     class Model3DList; // Model3DList.h
     class TexturList; // TexturList.h
     class Datei; // Datei.h
+    class DLLRegister; // DLLRegister.h
+
 #ifdef WIN32
     class Maus; // Maus.h
     class WFensterArray; // Fenster.h
@@ -30,13 +32,13 @@ namespace Framework
     Global bool TastenStand[ 255 ];
     Global bool MausStand[ 3 ];
     Global Model3DList *m3dRegister;
-    Global TexturList *texturRegister;
     Global bool istInitialisiert;
     Global ThreadRegister *thRegister;
     Global bool logEnabled;
     Global Datei *logFile;
     Global Critical logC;
     Global HINSTANCE__ *_hinst;
+    Global DLLRegister *dlls;
 
 #ifdef WIN32
     // Gibt die Koordinaten der Maus auf dem Bildschirm zurück
@@ -57,8 +59,6 @@ namespace Framework
     __declspec( dllexport ) void setTastenStand( unsigned char taste, bool st );
     // Gibt das Model3DData Register des Frameworks ohne erhöhten reference Counter zurück
     __declspec( dllexport ) Model3DList *zM3DRegister();
-    // Gibt das Textur Register des Frameworks ohne erhöhten reference Counter zurück
-    __declspec( dllexport ) TexturList *zTexturRegister();
     // Initialisiert das Framework
     // Wird in der (WinMain) des Frameworks automatisch aufgerufen
     __declspec( dllexport ) void initFramework( HINSTANCE__ *hInst = 0 );
@@ -76,6 +76,8 @@ namespace Framework
     // Speichert eine Zeile in die Logdatei
     //  txt: die zu Speichernde Nachricht
     __declspec( dllexport ) void logLine( char *txt );
+    // Gibt das DLL Register zurück, in dem alle zurzeit dynamisch geladenen DLL Dateien hinterlegt sind
+    __declspec( dllexport ) DLLRegister *getDLLRegister();
 #ifdef WIN32
     // gibt eine Referenz auf die Maus zurück
     __declspec( dllexport ) Maus &getMaus();

+ 783 - 0
GraphicsApi.cpp

@@ -0,0 +1,783 @@
+#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 "Render3D.h"
+#include "TexturList.h"
+#include "Kam3D.h"
+#include "DLLRegister.h"
+#include <d3d11.h>
+#include <d3d9.h>
+
+using namespace Framework;
+GraphicsApi::GraphicsApi( GraphicApiType typ )
+{
+    this->typ = typ;
+    fenster = 0;
+    backBufferSize = Vec2<int>( 0, 0 );
+    fullScreen = 0;
+    ref = 1;
+}
+
+GraphicsApi::~GraphicsApi()
+{
+    if( fenster )
+        fenster->release();
+}
+
+void GraphicsApi::initialize( WFenster * fenster, Vec2<int> backBufferSize, bool fullScreen )
+{
+    if( this->fenster )
+        this->fenster->release();
+    this->fenster = fenster;
+    this->backBufferSize = backBufferSize;
+    this->fullScreen = fullScreen;
+}
+
+void GraphicsApi::setBackBufferSize( Vec2< int > size )
+{
+    backBufferSize = size;
+    update();
+}
+
+void GraphicsApi::setFullScreen( bool fullScreen )
+{
+    this->fullScreen = fullScreen;
+    update();
+}
+
+void GraphicsApi::beginFrame( bool fill2D, bool fill3D, int fillColor )
+{}
+
+void GraphicsApi::renderKamera( Kam3D *zKamera )
+{}
+
+GraphicApiType GraphicsApi::getTyp() const
+{
+    return typ;
+}
+
+Vec2< int > GraphicsApi::getBackBufferSize() const
+{
+    return backBufferSize;
+}
+
+bool GraphicsApi::isFullScreen() const
+{
+    return fullScreen;
+}
+
+GraphicsApi *GraphicsApi::getThis()
+{
+    ref++;
+    return this;
+}
+
+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;
+    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" );
+    D3D9CreateFunction direct3DCreate9 = (D3D9CreateFunction)GetProcAddress( dll, "Direct3DCreate9" );
+
+    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() ),
+    renderObj( new Render3D() ),
+    texturRegister( new TexturList() )
+{}
+
+DirectX11::~DirectX11()
+{
+    if( renderObj )
+    {
+        renderObj->release();
+        renderObj = 0;
+    }
+    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;
+    }
+}
+
+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
+
+    // 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 = D3D11CreateDeviceAndSwapChain( 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 VertexShader();
+    vertexShader->setCompiledByteArray( d3d11Device, (unsigned char *)UIVertexShader, sizeof( UIVertexShader ) );
+
+    pixelShader = new PixelShader();
+    pixelShader->setCompiledByteArray( d3d11Device, (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( d3d11Device, polygonLayout, 4 );
+    vertexShader->erstelleConstBuffer( d3d11Device, sizeof( Mat4< float > ) * MAX_KNOCHEN_ANZ, 0 ); // matrizen für skelett annimationen
+    vertexShader->erstelleConstBuffer( d3d11Device, sizeof( Mat4< float > ) * 2, 1 ); // View and Projection Matrix
+
+    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( float ) * 3, 0 ); // Kamera Position
+    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( float ) * 3, 1 ); // materialkonstanten nach phong model
+    pixelShader->erstelleConstBuffer( d3d11Device, sizeof( int ) * 2, 2 ); // materialkonstanten nach phong model
+    // TODO: Remove Following Test Code
+    int lc[] = { 1, 6 };
+    pixelShader->füllConstBuffer( d3d11Context, (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 = new Textur();
+    uiTextur->setBildZ( renderB );
+    texturRegister->addTextur( uiTextur->getThis(), "f_Render_Bild" );
+
+    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
+    if( renderObj )
+        renderObj->release();
+    renderObj = new Render3D();
+    d3d11Device->AddRef();
+    renderObj->setDevice( d3d11Device );
+    d3d11Context->AddRef();
+    renderObj->setContext( d3d11Context );
+
+    renderObj->benutzeShader( VERTEX, vertexShader->getThis() );
+    d3d11Context->PSSetSamplers( 0, 1, &sampleState );
+    renderObj->benutzeShader( PIXEL, pixelShader->getThis() );
+}
+
+void DirectX11::update()
+{
+    if( renderObj )
+    {
+        renderObj->release();
+        renderObj = 0;
+    }
+    texturModel->release();
+    texturRegister->leeren();
+    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::renderKamera( Kam3D *zKamera )
+{
+    zKamera->render( renderObj );
+}
+
+void DirectX11::presentFrame()
+{
+    // Set the depth stencil state.
+    d3d11Context->OMSetDepthStencilState( depthDisabledStencilState, 1 );
+
+    uiTextur->updateTextur( renderObj );
+
+    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 ) );
+    renderObj->setKameraMatrix( view, view.projektion( (float)PI / 4.0f, screenAspect, 0.1f, 10000.f ), Vec3< float >( 0.f, 0.f, backBufferSize.y * 1.2075f ) );
+    if( fenster && !IsIconic( fenster->getFensterHandle() ) )
+        texturModel->render( renderObj );
+
+    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();
+}

+ 131 - 0
GraphicsApi.h

@@ -0,0 +1,131 @@
+#pragma once
+
+#include "Vec2.h"
+
+// DirectX 11 Types
+
+struct ID3D11Device;
+struct ID3D11DeviceContext;
+struct IDXGISwapChain;
+struct ID3D11Texture2D;
+struct ID3D11SamplerState;
+struct ID3D11ShaderResourceView;
+struct ID3D11RenderTargetView;
+struct ID3D11DepthStencilView;
+struct ID3D11DepthStencilState;
+struct ID3D11RasterizerState;
+struct ID3D11BlendState;
+struct D3D11_VIEWPORT;
+
+// DirectX 9 Types
+
+struct IDirect3D9;
+struct IDirect3DDevice9;
+struct IDirect3DSurface9;
+struct _D3DLOCKED_RECT;
+
+namespace Framework
+{
+    class WFenster;
+    class Bild;
+    class Textur;
+    class PixelShader;
+    class VertexShader;
+    class TexturModel;
+    class Render3D;
+    class TexturList;
+    class Kam3D;
+
+    enum GraphicApiType
+    {
+        NOT_SUPPORTED, // no graphic api supported
+        DIRECTX9, // only 2d
+        DIRECTX11, // 3d simple phong model without shadows
+        DIRECTX12 // 3d phong model with raytraycing
+    };
+
+    class GraphicsApi
+    {
+    protected:
+        GraphicApiType typ;
+        WFenster *fenster;
+        Vec2<int> backBufferSize;
+        bool fullScreen;
+
+    private:
+        int ref;
+
+    public:
+        GraphicsApi( GraphicApiType typ );
+        virtual ~GraphicsApi();
+        virtual void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen );
+        virtual void setBackBufferSize( Vec2< int > size );
+        virtual void setFullScreen( bool fullScreen );
+        virtual void update() = 0;
+        virtual void beginFrame( bool fill2D = 0, bool fill3D = 0, int fillColor = 0 );
+        virtual void renderKamera( Kam3D *zKamera );
+        virtual void presentFrame() = 0;
+        GraphicApiType getTyp() const;
+        Vec2< int > getBackBufferSize() const;
+        bool isFullScreen() const;
+        virtual Bild *zUIRenderBild() const = 0;
+        GraphicsApi *getThis();
+        GraphicsApi *release();
+    };
+
+    class DirectX9 : public GraphicsApi
+    {
+    private:
+        IDirect3D9 *pDirect3D;
+        IDirect3DDevice9 *pDevice;
+        IDirect3DSurface9 *pBackBuffer;
+        _D3DLOCKED_RECT *backRect;
+        Bild *uiBild;
+
+    public:
+        DirectX9();
+        ~DirectX9();
+        void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
+        void update() override;
+        void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
+        void presentFrame() override;
+        Bild *zUIRenderBild() const override;
+    };
+
+    class DirectX11 : public GraphicsApi
+    {
+    private:
+        ID3D11Device *d3d11Device;
+        ID3D11DeviceContext *d3d11Context;
+        IDXGISwapChain *d3d11SpawChain;
+        Textur *uiTextur;
+        VertexShader *vertexShader;
+        PixelShader *pixelShader;
+        ID3D11SamplerState *sampleState;
+        ID3D11RenderTargetView *rtview;
+        ID3D11DepthStencilView *dsView;
+        ID3D11Texture2D *depthStencilBuffer;
+        ID3D11DepthStencilState *depthStencilState;
+        ID3D11DepthStencilState *depthDisabledStencilState;
+        ID3D11BlendState *blendStateAlphaBlend;
+        D3D11_VIEWPORT *vp;
+        TexturModel *texturModel;
+        Render3D *renderObj;
+        TexturList *texturRegister;
+
+    public:
+        DirectX11();
+        ~DirectX11();
+        void initialize( WFenster *fenster, Vec2<int> backBufferSize, bool fullScreen ) override;
+        void update() override;
+        void beginFrame( bool fill2D, bool fill3D, int fillColor ) override;
+        void renderKamera( Kam3D *zKamera ) override;
+        void presentFrame() override;
+        Bild *zUIRenderBild() const override;
+    };
+
+    class DirectX12 : public GraphicsApi
+    {
+
+    };
+}

+ 2 - 13
TexturModel.cpp

@@ -42,21 +42,10 @@ TexturModel::TexturModel()
     textur = new Model3DTextur();
 }
 
-// Setzt die Textur die angezeigt werden soll
-//  textur: Die Textur als Bild
-void TexturModel::setTextur( Bild *textur )
-{
-    Textur *t = new Textur();
-    t->setBildZ( textur );
-    this->textur->setPolygonTextur( 0, t );
-    rend = 1;
-}
-
 // Setzt die Textur die angezeigt werden soll 
-//  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
-void TexturModel::setTextur( int id )
+//  t: Die Textur
+void TexturModel::setTextur( Textur *t )
 {
-    Textur *t = texturRegister->getTextur( id );
     if( !t )
         return;
     this->textur->setPolygonTextur( 0, t );

+ 3 - 6
TexturModel.h

@@ -4,7 +4,7 @@
 
 namespace Framework
 {
-    class Bild; // Bild.h
+    class Textur;
 
     // Ein 3D Modell, das zur Darstellung einer Textur im dreidimensionalen Raum verwendet werden kann
     class TexturModel : public Model3D
@@ -12,12 +12,9 @@ namespace Framework
     public:
         // Konstruktor
         __declspec( dllexport ) TexturModel();
-        // Setzt die Textur die angezeigt werden soll
-        //  textur: Die Textur als Bild
-        __declspec( dllexport ) void setTextur( Bild *textur );
         // Setzt die Textur die angezeigt werden soll 
-        //  id: Die id der Textur. Sie muss im Textur Register des Frameworks registriert sein
-        __declspec( dllexport ) void setTextur( int id );
+        //  t: Die Textur
+        __declspec( dllexport ) void setTextur( Textur *t );
         // Setzt die Größe, in der Die Textur angezeigt wird
         //  gr: Ein Vektor, der für x und y die breite und höhe beinhaltet
         __declspec( dllexport ) void setSize( Vec2< float > gr );

+ 18 - 18
UIPixelShader.h

@@ -262,10 +262,10 @@ ret
 
 const BYTE UIPixelShader[] =
 {
-     68,  88,  66,  67,  45, 249, 
-    169, 157, 175,  49,   2, 247, 
-    219, 116, 228,  81,  63,  37, 
-    218,  26,   1,   0,   0,   0, 
+     68,  88,  66,  67, 232,  86, 
+    248, 223, 236, 211,  56, 103, 
+     78, 101, 231, 223, 206,  95, 
+    170, 222,   1,   0,   0,   0, 
     136, 104,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     124,   5,   0,   0,  12,   6, 
@@ -1480,10 +1480,10 @@ const BYTE UIPixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    154, 220,  80,  92,   1,   0, 
-      0,   0,  42, 208,   4, 239, 
-    233,  22, 207,  77, 129, 179, 
-    197, 137, 209,  11,  47, 185, 
+      4, 215,  82,  92,   1,   0, 
+      0,   0, 175, 136, 106, 248, 
+     57, 129,   4,  70, 150,  75, 
+     21,  29, 141,  80, 154,  11, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1655,7 +1655,7 @@ const BYTE UIPixelShader[] =
     242,  56,   1,   0,  43, 236, 
       3,   0,  28,  19,   2,   0, 
      65,  36,   1,   0, 236, 179, 
-      1,   0,  85,  79,   1,   0, 
+      1,   0,  97, 167,   3,   0, 
     125,  10,   2,   0, 125, 181, 
       2,   0, 200,  81,   2,   0, 
     193,  33,   3,   0,  65, 185, 
@@ -2419,8 +2419,8 @@ const BYTE UIPixelShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  13,  10, 
      27, 226,  48,   1, 128,   0, 
-      0,   0, 232, 180, 219,  90, 
-     39, 184, 212,   1,   1,   0, 
+      0,   0, 186,   7, 139,  51, 
+     85, 185, 212,   1,   1,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -3406,7 +3406,7 @@ const BYTE UIPixelShader[] =
       0,   0,  23,   0,   1,   0, 
       5,  16,   0,   0,  14,   0, 
      23,  21,   0,  16,   0,   0, 
-      3,   2,  48,   4,   0,   0, 
+      3,   2, 224,   3,   0,   0, 
     242, 241,  10,   0,  24,  21, 
       8,  16,   0,   0,   1,   0, 
       1,   0,  10,   0,  24,  21, 
@@ -4400,7 +4400,7 @@ const BYTE UIPixelShader[] =
       9,   0, 160,   7,   0,   0, 
       0,   0,   0,   0, 244,   9, 
       0,   0,   1,   0,   0,   0, 
-     56, 122,  17,   4,   0,   0, 
+    144, 122, 197,   3,   0,   0, 
       0,   0,   0,   0,   0,   0, 
      84, 101, 120, 116, 117, 114, 
     101,  80, 105, 120, 101, 108, 
@@ -4466,11 +4466,11 @@ const BYTE UIPixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 154, 220, 
-     80,  92,   1,   0,   0,   0, 
-     42, 208,   4, 239, 233,  22, 
-    207,  77, 129, 179, 197, 137, 
-    209,  11,  47, 185, 135,   0, 
+    148,  46,  49,   1,   4, 215, 
+     82,  92,   1,   0,   0,   0, 
+    175, 136, 106, 248,  57, 129, 
+      4,  70, 150,  75,  21,  29, 
+    141,  80, 154,  11, 135,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 

+ 19 - 19
UIVertexShader.h

@@ -119,10 +119,10 @@ ret
 
 const BYTE UIVertexShader[] =
 {
-     68,  88,  66,  67,  77, 107, 
-     59,  76, 219, 111, 133,  83, 
-     11, 126,  79,   3, 117,  12, 
-    162, 229,   1,   0,   0,   0, 
+     68,  88,  66,  67, 115, 180, 
+    240, 189, 230,   4, 149,  82, 
+     98, 201,  38,  47, 175,  47, 
+     72,  26,   1,   0,   0,   0, 
     168,  77,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      20,   2,   0,   0, 168,   2, 
@@ -873,10 +873,10 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    137, 165,  80,  92,   1,   0, 
-      0,   0, 191,  13,  30, 146, 
-    241, 109,  80,  72, 139,  18, 
-     63, 138, 222,   6, 183,  16, 
+      5, 215,  82,  92,   1,   0, 
+      0,   0, 221,  54, 104, 121, 
+     27,  80,  49,  66, 179, 178, 
+     69, 255,  51,  99, 230, 172, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1556,8 +1556,8 @@ const BYTE UIVertexShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  32,  32, 
      27, 226,  48,   1, 128,   0, 
-      0,   0,   8, 235, 113, 136, 
-      6, 184, 212,   1,   1,   0, 
+      0,   0, 118,   7, 216,  51, 
+     85, 185, 212,   1,   1,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2934,13 +2934,13 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   1,   0, 
       0,   0,   0,   0,   0,   0, 
     196,   3,   0,   0,  32,   0, 
-      0,  96,   0,   0, 183,  16, 
+      0,  96,   0,   0, 230, 172, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   2,   0,   9,   0, 
      80,   5,   0,   0,   0,   0, 
       0,   0, 236,   2,   0,   0, 
-      1,   0,   0,   0,  40, 121, 
-     69,   0,   0,   0,   0,   0, 
+      1,   0,   0,   0, 144, 120, 
+    192,   3,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  86, 
     101, 114, 116, 101, 120,  83, 
@@ -2950,7 +2950,7 @@ const BYTE UIVertexShader[] =
       1,   0,   0,   0,   0,   0, 
       0,   0, 196,   3,   0,   0, 
      32,   0,   0,  96,   0,   0, 
-    183,  16,   0,   0,   0,   0, 
+    230, 172,   0,   0,   0,   0, 
       0,   0,   0,   0,   2,   0, 
       2,   0,   7,   0,   0,   0, 
       0,   0,   1,   0, 255, 255, 
@@ -3006,11 +3006,11 @@ const BYTE UIVertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 137, 165,  80,  92, 
-      1,   0,   0,   0, 191,  13, 
-     30, 146, 241, 109,  80,  72, 
-    139,  18,  63, 138, 222,   6, 
-    183,  16, 136,   0,   0,   0, 
+     49,   1,   5, 215,  82,  92, 
+      1,   0,   0,   0, 221,  54, 
+    104, 121,  27,  80,  49,  66, 
+    179, 178,  69, 255,  51,  99, 
+    230, 172, 136,   0,   0,   0, 
      47,  76, 105, 110, 107,  73, 
     110, 102, 111,   0,  47, 110, 
      97, 109, 101, 115,   0,  47,