Parcourir la source

update GraphicsApi Interface to be able to implement raytracing within the DirectX 12 implementation

Kolja Strohm il y a 1 mois
Parent
commit
3ad6193fb1
17 fichiers modifiés avec 148 ajouts et 879 suppressions
  1. 61 115
      DX11GraphicsApi.cpp
  2. 14 294
      DX12GraphicsApi.cpp
  3. 0 104
      DX12PixelShader.hlsl
  4. 0 77
      DX12VertexShader.hlsl
  5. 0 68
      DX9GraphicsApi.cpp
  6. 10 3
      DXBuffer.cpp
  7. 0 36
      Framework.vcxproj
  8. 0 6
      Framework.vcxproj.filters
  9. 1 14
      GraphicsApi.cpp
  10. 9 24
      GraphicsApi.h
  11. 1 1
      M3File.cpp
  12. 20 45
      Model3D.cpp
  13. 26 22
      Model3D.h
  14. 3 21
      Model3DList.cpp
  15. 3 5
      Model3DList.h
  16. 0 30
      Screen.cpp
  17. 0 14
      Screen.h

+ 61 - 115
DX11GraphicsApi.cpp

@@ -48,11 +48,20 @@ DirectX11::DirectX11()
       meshRS(0),
       defaultTexture(0),
       diffuseLights(0),
-      pointLights(0)
+      pointLights(0),
+      indexBuffers(0),
+      vertexBuffers(0)
 {}
 
 DirectX11::~DirectX11()
 {
+    for (int i = 0; i <= lastModelId; i++)
+    {
+        indexBuffers[i]->release();
+        vertexBuffers[i]->release();
+    }
+    delete[] indexBuffers;
+    delete[] vertexBuffers;
     if (diffuseLights) diffuseLights->release();
     if (pointLights) pointLights->release();
     if (defaultTexture) defaultTexture->release();
@@ -149,8 +158,6 @@ typedef HRESULT(__stdcall* D3D11CreateDeviceAndSwapChainFunction)(IDXGIAdapter*,
 void DirectX11::initialize(
     NativeWindow* fenster, Vec2<int> backBufferSize, bool fullScreen)
 {
-    if (d3d11Device)
-        return GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
     GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
     //--------------------------------------------------------------------
     // Create Device
@@ -581,102 +588,6 @@ void DirectX11::initialize(
         sizeof(PointLight), d3d11Device, d3d11Context, deviceLock);
 }
 
-void DirectX11::update()
-{
-    modelList->removeAll();
-    if (texturModel)
-    {
-        texturModel->release();
-        texturModel = 0;
-    }
-    if (pointLights)
-        pointLights = (DX11StructuredBuffer*)pointLights->release();
-    if (diffuseLights)
-        diffuseLights = (DX11StructuredBuffer*)diffuseLights->release();
-    if (texturRS)
-    {
-        texturRS->Release();
-        texturRS = NULL;
-    }
-    if (meshRS)
-    {
-        meshRS->Release();
-        meshRS = NULL;
-    }
-    texturRegister->clear();
-    if (defaultTexture) defaultTexture = (Texture*)defaultTexture->release();
-    if (blendStateAlphaBlend)
-    {
-        blendStateAlphaBlend->Release();
-        blendStateAlphaBlend = NULL;
-    }
-    if (uiTexture)
-    {
-        uiTexture->release();
-        uiTexture = 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(dynamic_cast<NativeWindow*>(fenster->getThis()),
-        backBufferSize,
-        fullScreen);
-}
-
 void DirectX11::beginFrame(bool fill2D, bool fill3D, int fillColor)
 {
     if (fill2D) uiTexture->zImage()->setColor(fillColor);
@@ -708,7 +619,30 @@ void DirectX11::renderObject(Model3D* zObj)
 {
     if (!zObj->zModelData()) return;
     int curId = zObj->zModelData()->getId();
-    zObj->zModelData()->updateGPUMemory();
+    if (curId < 0 || curId > lastModelId)
+    {
+        Framework::Logging::warning()
+            << "DirectX11::renderObject: Model ID out of range: " << curId
+            << " The model was not properly registered with DirectX11 during "
+               "its creation. It can not be rendered by DirectX11.";
+        return;
+    }
+    if (zObj->zModelData()->wasIndexBufferChanged())
+    {
+        this->indexBuffers[curId]->setData(
+            (void*)zObj->zModelData()->getIndexBuffer());
+        this->indexBuffers[curId]->setLength(
+            zObj->zModelData()->getIndexCount() * sizeof(int));
+        this->indexBuffers[curId]->copyToGPU();
+    }
+    if (zObj->zModelData()->wasVertexBufferChanged())
+    {
+        this->vertexBuffers[curId]->setData(
+            (void*)zObj->zModelData()->zVertexBuffer());
+        this->vertexBuffers[curId]->setLength(
+            zObj->zModelData()->getVertexCount() * sizeof(Vertex3D));
+        this->vertexBuffers[curId]->copyToGPU();
+    }
     Mat4<float> trans = Mat4<float>::identity();
     int anz = zObj->calculateMatrices(trans, matrixBuffer);
     if (vertexShader)
@@ -722,10 +656,8 @@ void DirectX11::renderObject(Model3D* zObj)
         pixelShader->fillConstBuffer(
             (char*)matirialBuffer, 1, sizeof(float) * 3);
     unsigned int offset = 0;
-    unsigned int es
-        = (unsigned)zObj->zModelData()->zDXVertexBuffer()->getElementLength();
-    ID3D11Buffer* vBuffer
-        = ((DX11Buffer*)zObj->zModelData()->zDXVertexBuffer())->zBuffer();
+    unsigned int es = (unsigned)this->vertexBuffers[curId]->getElementLength();
+    ID3D11Buffer* vBuffer = this->vertexBuffers[curId]->zBuffer();
     deviceLock.lock();
     d3d11Context->IASetVertexBuffers(0, 1, &vBuffer, &es, &offset);
     deviceLock.unlock();
@@ -753,13 +685,12 @@ void DirectX11::renderObject(Model3D* zObj)
             pixelShader->fillConstBuffer((char*)&e, 3, sizeof(TextureEffect));
     }
     DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
-    if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 2)
+    if (this->indexBuffers[curId]->getElementLength() == 2)
         f = DXGI_FORMAT_R16_UINT;
-    if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 1)
+    if (this->indexBuffers[curId]->getElementLength() == 1)
         f = DXGI_FORMAT_R8_UINT;
     deviceLock.lock();
-    d3d11Context->IASetIndexBuffer(
-        ((DX11Buffer*)zObj->zModelData()->zDXIndexBuffer())->zBuffer(), f, 0);
+    d3d11Context->IASetIndexBuffer(this->indexBuffers[curId]->zBuffer(), f, 0);
     d3d11Context->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
     deviceLock.unlock();
     zObj->beforeRender(this, vertexShader, pixelShader);
@@ -918,8 +849,7 @@ void DirectX11::renderKamera(Cam3D* zKamera)
         for (auto obj : alphaModels)
         {
             sorted[dist.val() * alphaModels.getEntryCount()
-                   + index[dist.val()]++]
-                = obj;
+                   + index[dist.val()]++] = obj;
             dist++;
         }
         for (int i = 0; i < size; i++)
@@ -1042,7 +972,6 @@ void DirectX11::presentFrame()
         deviceLock.lock();
         HRESULT res = d3d11Device->GetDeviceRemovedReason();
         deviceLock.unlock();
-        update();
         WMessageBox(fenster ? fenster->getWindowHandle() : 0,
             new Text("Fehler"),
             new Text("Es ist ein Fehler beim rendern aufgetreten."),
@@ -1173,7 +1102,7 @@ bool DirectX11::isAvailable()
     return 0;
 }
 
-DXBuffer* DirectX11::createIndexBuffer()
+DX11Buffer* DirectX11::createIndexBuffer()
 {
     return new DX11Buffer(sizeof(int),
         d3d11Device,
@@ -1182,7 +1111,7 @@ DXBuffer* DirectX11::createIndexBuffer()
         deviceLock);
 }
 
-DXBuffer* DirectX11::createVertexBuffer()
+DX11Buffer* DirectX11::createVertexBuffer()
 {
     return new DX11Buffer(sizeof(Vertex3D),
         d3d11Device,
@@ -1276,7 +1205,7 @@ DX11PixelShader* DirectX11::initializePixelShader(
     return pixelShader;
 }
 
-DLLEXPORT ID3D11DeviceContext* DirectX11::zContext()
+ID3D11DeviceContext* DirectX11::zContext()
 {
     return d3d11Context;
 }
@@ -1285,4 +1214,21 @@ DXBuffer* DirectX11::createStructuredBuffer(int eSize)
 {
     return new DX11StructuredBuffer(
         eSize, d3d11Device, d3d11Context, deviceLock);
-}
+}
+
+Model3DData* DirectX11::createModel(const char* name)
+{
+    Model3DData* result = GraphicsApi::createModel(name);
+    if (result)
+    {
+        DX11Buffer** newIndexBuffers = new DX11Buffer*[lastModelId + 1];
+        DX11Buffer** newVertexBuffers = new DX11Buffer*[lastModelId + 1];
+        memcpy(
+            newIndexBuffers, indexBuffers, sizeof(DX11Buffer*) * lastModelId);
+        memcpy(
+            newVertexBuffers, vertexBuffers, sizeof(DX11Buffer*) * lastModelId);
+        indexBuffers[lastModelId] = createIndexBuffer();
+        vertexBuffers[lastModelId] = createVertexBuffer();
+    }
+    return result;
+}

+ 14 - 294
DX12GraphicsApi.cpp

@@ -3,7 +3,7 @@
 #include <dxgi1_6.h>
 #include <dxgidebug.h>
 
-#include "Image.h"
+#include "Camera3D.h"
 #include "d3dx12.h"
 #include "DLLRegister.h"
 #include "DX12Buffer.h"
@@ -12,15 +12,15 @@
 #include "DX12Shader.h"
 #include "DX12Texture.h"
 #include "DX12VertexShader.h"
-#include "Window.h"
 #include "Globals.h"
 #include "GraphicsApi.h"
-#include "Camera3D.h"
+#include "Image.h"
 #include "Model3D.h"
 #include "Model3DList.h"
 #include "Shader.h"
 #include "TextureList.h"
 #include "TextureModel.h"
+#include "Window.h"
 #include "World3D.h"
 
 using namespace Framework;
@@ -116,8 +116,6 @@ typedef HRESULT(__stdcall* DXGIGetDebugInterface1Function)(
 void DirectX12::initialize(
     NativeWindow* fenster, Vec2<int> backBufferSize, bool fullScreen)
 {
-    if (device)
-        return GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
     GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
 
     HINSTANCE dxgiDLL = getDLLRegister()->loadDLL("dxgi.dll", "dxgi.dll");
@@ -139,6 +137,7 @@ void DirectX12::initialize(
             MB_ICONERROR);
         return;
     }
+    // CreateDXGIFactory2
     CreateDXGIFactory2Function createFactory
         = (CreateDXGIFactory2Function)GetProcAddress(
             dxgiDLL, "CreateDXGIFactory2");
@@ -154,6 +153,7 @@ void DirectX12::initialize(
             MB_ICONERROR);
         return;
     }
+    // D3D12CreateDevice
     D3D12CreateDeviceFunction createDevice
         = (D3D12CreateDeviceFunction)GetProcAddress(
             d3d12DLL, "D3D12CreateDevice");
@@ -168,9 +168,11 @@ void DirectX12::initialize(
             MB_ICONERROR);
         return;
     }
+    // D3D12SerializeVersionedRootSignature
     PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE d3d12svrsf
         = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)GetProcAddress(
             d3d12DLL, "D3D12SerializeVersionedRootSignature");
+    // D3D12SerializeRootSignature
     PFN_D3D12_SERIALIZE_ROOT_SIGNATURE d3d12srsf
         = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(
             d3d12DLL, "D3D12SerializeRootSignature");
@@ -179,11 +181,13 @@ void DirectX12::initialize(
     IDXGIInfoQueue* dxgiInfoQueue;
     if (debugDX)
     {
+        // D3D12GetDebugInterface
         D3D12GetDebugInterfaceFunction getDebugInterface
             = (D3D12GetDebugInterfaceFunction)GetProcAddress(
                 d3d12DLL, "D3D12GetDebugInterface");
         if (SUCCEEDED(getDebugInterface(__uuidof(ID3D12Debug), (void**)&debug)))
             debug->EnableDebugLayer();
+        // DXGIGetDebugInterface1
         DXGIGetDebugInterface1Function dxgiDebugInterface
             = (DXGIGetDebugInterface1Function)GetProcAddress(
                 dxgiDLL, "DXGIGetDebugInterface1");
@@ -224,6 +228,7 @@ void DirectX12::initialize(
 
         if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
         {
+            adapter->Release();
             // Don't select the Basic Render Driver adapter.
             continue;
         }
@@ -245,6 +250,7 @@ void DirectX12::initialize(
             Logging::info() << buff;
             break;
         }
+        adapter->Release();
     }
     if (!adapter)
     {
@@ -396,6 +402,7 @@ void DirectX12::initialize(
     D3D12_DESCRIPTOR_HEAP_DESC rtvhdesc = {};
     rtvhdesc.NumDescriptors = 2; // back buffer count
     rtvhdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
+    rtvhdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
     res = device->CreateDescriptorHeap(
         &rtvhdesc, __uuidof(ID3D12DescriptorHeap), (void**)&rtvHeap);
     if (FAILED(res))
@@ -770,171 +777,6 @@ void DirectX12::initialize(
     factory->Release();
 }
 
-void DirectX12::update()
-{
-    if (!device || !swapChain || !directCommandQueue) return;
-    directCommandQueue->flush();
-    copyCommandQueue->flush();
-    computeCommandQueue->flush();
-    modelList->removeAll();
-    HINSTANCE dxgiDLL = getDLLRegister()->loadDLL("dxgi.dll", "dxgi.dll");
-    if (!dxgiDLL)
-    {
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("dxgi.dll konnte nicht gefunden werden."),
-            MB_ICONERROR);
-        return;
-    }
-    CreateDXGIFactory2Function createFactory
-        = (CreateDXGIFactory2Function)GetProcAddress(
-            dxgiDLL, "CreateDXGIFactory2");
-    if (!createFactory)
-    {
-        getDLLRegister()->releaseDLL("dxgi.dll");
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("Der Einstiegspunkt CreateDXGIFactory2 fon DXGI konnte "
-                     "nicht gefunden werden."),
-            MB_ICONERROR);
-        return;
-    }
-    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
-    HRESULT res = swapChain->GetDesc(&swapChainDesc);
-    if (FAILED(res))
-    {
-        getDLLRegister()->releaseDLL("dxgi.dll");
-        Logging::error() << "ERROR: GetDesc returned " << res << "\n";
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("GetDesc ist Fehlgeschlagen."),
-            MB_ICONERROR);
-        return;
-    }
-    IDXGIFactory4* factory;
-    UINT createFactoryFlags = 0;
-#if defined(_DEBUG)
-    createFactoryFlags = DXGI_CREATE_FACTORY_DEBUG;
-#endif
-    res = createFactory(
-        createFactoryFlags, __uuidof(IDXGIFactory4), (void**)&factory);
-    if (FAILED(res))
-    {
-        getDLLRegister()->releaseDLL("dxgi.dll");
-        Logging::error() << "ERROR: createFactory returned " << res << "\n";
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("createFactory ist Fehlgeschlagen."),
-            MB_ICONERROR);
-        return;
-    }
-    for (int i = 0; i < 2; ++i)
-    {
-        backBuffer[i]->Release();
-        backBuffer[i] = 0;
-    }
-    res = swapChain->ResizeBuffers(2,
-        backBufferSize.x,
-        backBufferSize.y,
-        swapChainDesc.BufferDesc.Format,
-        swapChainDesc.Flags);
-    backBufferIndex = swapChain->GetCurrentBackBufferIndex();
-
-    auto rtvDescriptorSize = device->GetDescriptorHandleIncrementSize(
-        D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
-    D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle(
-        rtvHeap->GetCPUDescriptorHandleForHeapStart());
-
-    for (int i = 0; i < 2; i++)
-    {
-        ID3D12Resource* backBuffer;
-        res = swapChain->GetBuffer(
-            i, __uuidof(ID3D12Resource), (void**)&backBuffer);
-        if (FAILED(res))
-        {
-            getDLLRegister()->releaseDLL("dxgi.dll");
-            factory->Release();
-            Logging::error() << "ERROR: GetBuffer returned " << res << "\n";
-            WMessageBox(fenster->getWindowHandle(),
-                new Text("Fehler"),
-                new Text("GetBuffer ist Fehlgeschlagen."),
-                MB_ICONERROR);
-            return;
-        }
-
-        device->CreateRenderTargetView(backBuffer, nullptr, rtvHandle);
-
-        this->backBuffer[i] = backBuffer;
-
-        rtvHandle.ptr += rtvDescriptorSize;
-    }
-    getDLLRegister()->releaseDLL("dxgi.dll");
-
-    delete viewPort;
-    viewPort = new D3D12_VIEWPORT();
-    viewPort->Width = (float)this->backBufferSize.x;
-    viewPort->Height = (float)this->backBufferSize.y;
-    viewPort->MinDepth = 0.0f;
-    viewPort->MaxDepth = 1.0f;
-    viewPort->TopLeftX = 0.0f;
-    viewPort->TopLeftY = 0.0f;
-
-    depthBuffer->Release();
-
-    D3D12_CLEAR_VALUE optimizedClearValue = {};
-    optimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;
-    optimizedClearValue.DepthStencil = {1.0f, 0};
-    CD3DX12_HEAP_PROPERTIES heapProps
-        = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
-    CD3DX12_RESOURCE_DESC heapDesc
-        = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D32_FLOAT,
-            this->backBufferSize.x,
-            this->backBufferSize.y,
-            1,
-            0,
-            1,
-            0,
-            D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
-    res = device->CreateCommittedResource(&heapProps,
-        D3D12_HEAP_FLAG_NONE,
-        &heapDesc,
-        D3D12_RESOURCE_STATE_DEPTH_WRITE,
-        0,
-        __uuidof(ID3D12Resource),
-        (void**)&depthBuffer);
-    if (FAILED(res))
-    {
-        factory->Release();
-        Logging::error() << "ERROR: CreateCommittedResource returned " << res
-                         << "\n";
-        WMessageBox(fenster->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("CreateCommittedResource ist Fehlgeschlagen."),
-            MB_ICONERROR);
-        return;
-    }
-
-    D3D12_DEPTH_STENCIL_VIEW_DESC dsv = {};
-    dsv.Format = DXGI_FORMAT_D32_FLOAT;
-    dsv.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
-    dsv.Texture2D.MipSlice = 0;
-    dsv.Flags = D3D12_DSV_FLAG_NONE;
-
-    device->CreateDepthStencilView(
-        depthBuffer, &dsv, dsvHeap->GetCPUDescriptorHandleForHeapStart());
-
-    if (uiTexture) uiTexture->release();
-
-    Image* renderB = new Image(1);
-    renderB->setAlpha3D(1);
-    renderB->newImage(this->backBufferSize.x, this->backBufferSize.y, 0);
-    uiTexture = createOrGetTexture("_f_Render_Image", renderB);
-
-    texturModel->setTexture(dynamic_cast<Texture*>(uiTexture->getThis()));
-
-    factory->Release();
-}
-
 void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
 {
     D3D12_RESOURCE_BARRIER barrier;
@@ -972,117 +814,6 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
     pixelShader->fillConstBuffer((char*)lc, 4, sizeof(int) * 2);
 }
 
-void DirectX12::renderObject(Model3D* zObj)
-{
-    Mat4<float> trans = Mat4<float>::identity();
-    zObj->zModelData()->zDXVertexBuffer()->copyToGPU();
-    zObj->zModelData()->zDXIndexBuffer()->copyToGPU();
-    int anz = zObj->calculateMatrices(trans, matrixBuffer);
-    if (vertexShader)
-        vertexShader->fillConstBuffer(
-            (char*)matrixBuffer, 1, sizeof(Mat4<float>) * anz);
-    float matirialBuffer[3]; // light factors (phong model)
-    matirialBuffer[0] = zObj->getAmbientFactor();
-    matirialBuffer[1] = zObj->getDiffusFactor();
-    matirialBuffer[2] = zObj->getSpecularFactor();
-    if (pixelShader)
-        pixelShader->fillConstBuffer(
-            (char*)matirialBuffer, 3, sizeof(float) * 3);
-    unsigned int offset = 0;
-    unsigned int es
-        = (unsigned)zObj->zModelData()->zDXVertexBuffer()->getElementLength();
-    Model3DTexture* zTexture = zObj->zTexture();
-    int ind = 0;
-    zObj->beforeRender(this, vertexShader, pixelShader);
-    for (auto i = zObj->zModelData()->getPolygons(); i; i++)
-    {
-        if (zObj->needRenderPolygon(ind))
-        {
-            Texture* t = zTexture->zPolygonTexture(ind);
-            // if( t &&t->needsUpdate() )
-            //     t->updateTextur();
-            DXGI_FORMAT f = DXGI_FORMAT_R32_UINT;
-            if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 2)
-                f = DXGI_FORMAT_R16_UINT;
-            if (zObj->zModelData()->zDXIndexBuffer()->getElementLength() == 1)
-                f = DXGI_FORMAT_R8_UINT;
-            indexBufferView->Format = f;
-            if (t)
-            {
-                /*ID3D11ShaderResourceView *v[ 3 ];
-                v[ 0 ] = *(DX11Texture *)t;
-                v[ 1 ] = *diffuseLights;
-                v[ 2 ] = *pointLights;
-                d3d11Context->PSSetShaderResources( 0, 3, v );
-                d3d11Context->DrawIndexed( indexBuffer->getElementCount(), 0, 0
-                );*/
-                directCommandQueue->getCommandList()->SetPipelineState(
-                    pipeline);
-                directCommandQueue->getCommandList()->SetGraphicsRootSignature(
-                    signature);
-                directCommandQueue->getCommandList()->SetDescriptorHeaps(
-                    1, &shaderBufferHeap);
-                directCommandQueue->getCommandList()
-                    ->SetGraphicsRootDescriptorTable(0,
-                        shaderBufferHeap->GetGPUDescriptorHandleForHeapStart());
-                directCommandQueue->getCommandList()->RSSetViewports(
-                    1, viewPort);
-                directCommandQueue->getCommandList()->RSSetScissorRects(
-                    1, allowedRenderArea);
-                auto rtvDescriptorSize
-                    = device->GetDescriptorHandleIncrementSize(
-                        D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
-                D3D12_CPU_DESCRIPTOR_HANDLE rtv
-                    = rtvHeap->GetCPUDescriptorHandleForHeapStart();
-                rtv.ptr += rtvDescriptorSize * backBufferIndex;
-                directCommandQueue->getCommandList()->OMSetRenderTargets(
-                    1, &rtv, 0, 0);
-                indexBufferView->SizeInBytes
-                    = zObj->zModelData()->zDXIndexBuffer()->getElementCount()
-                    * zObj->zModelData()->zDXIndexBuffer()->getElementLength();
-                indexBufferView->BufferLocation
-                    = ((DX12Buffer*)zObj->zModelData()->zDXIndexBuffer())
-                          ->zBuffer()
-                          ->GetGPUVirtualAddress();
-                directCommandQueue->getCommandList()->IASetIndexBuffer(
-                    indexBufferView);
-                vertexBufferView->SizeInBytes
-                    = zObj->zModelData()->zDXVertexBuffer()->getElementCount()
-                    * zObj->zModelData()->zDXVertexBuffer()->getElementLength();
-                vertexBufferView->BufferLocation
-                    = ((DX12Buffer*)zObj->zModelData()->zDXVertexBuffer())
-                          ->zBuffer()
-                          ->GetGPUVirtualAddress();
-                directCommandQueue->getCommandList()->IASetVertexBuffers(
-                    0, 1, vertexBufferView);
-                directCommandQueue->getCommandList()->IASetPrimitiveTopology(
-                    D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-                directCommandQueue->getCommandList()->DrawIndexedInstanced(
-                    zObj->zModelData()->zDXIndexBuffer()->getElementCount(),
-                    1,
-                    0,
-                    0,
-                    0);
-            }
-            else
-            {
-                /*d3d11Context->RSSetState( meshRS );
-                ID3D11ShaderResourceView *v[ 3 ];
-                v[ 0 ] = *(DX11Texture *)defaultTexture;
-                v[ 1 ] = *diffuseLights;
-                v[ 2 ] = *pointLights;
-                d3d11Context->PSSetShaderResources( 0, 3, v );
-                d3d11Context->DrawIndexed( indexBuffer->getElementCount(), 0, 0
-                ); d3d11Context->RSSetState( texturRS );*/
-                // directCommandQueue->getCommandList()->DrawIndexedInstanced(
-                // indexBuffer->getElementCount(), 1, 0, 0, 0 );
-            }
-        }
-        ind++;
-    }
-    zObj->afterRender(this, pixelShader, vertexShader);
-}
-
 // Checks whether a sphere is in the visible space of the world and
 // needs to be drawn
 //  pos: The center of the sphere
@@ -1201,7 +932,8 @@ Texture* DirectX12::createOrGetTexture(const char* name, Image* b)
         if (b) ret->setImageZ(b);
         return ret;
     }
-    Texture* ret = new DX12Texture(device, copyCommandQueue, directCommandQueue);
+    Texture* ret
+        = new DX12Texture(device, copyCommandQueue, directCommandQueue);
     if (b) ret->setImageZ(b);
     texturRegister->addTexture(dynamic_cast<Texture*>(ret->getThis()), name);
     ret->updateTextur();
@@ -1299,18 +1031,6 @@ bool DirectX12::isAvailable()
     return 0;
 }
 
-DXBuffer* DirectX12::createIndexBuffer()
-{
-    return new DX12IndexBuffer(
-        sizeof(int), device, copyCommandQueue, directCommandQueue);
-}
-
-DXBuffer* DirectX12::createVertexBuffer()
-{
-    return new DX12VertexBuffer(
-        sizeof(Vertex3D), device, copyCommandQueue, directCommandQueue);
-}
-
 DXBuffer* DirectX12::createStructuredBuffer(int eSize)
 {
     throw "Sorry, support for structured buffers will come eventualy"; // TODO:

+ 0 - 104
DX12PixelShader.hlsl

@@ -1,104 +0,0 @@
-/////////////                                                                                           
-// GLOBALS //                                                                                           
-/////////////                                                                                           
-Texture2D shaderTexture : register( t0 );
-SamplerState SampleType : register( s0 );
-
-// Matrizen fuer die einzelnen Knochen des Modells
-struct MatrixBuffer
-{
-    matrix knochenMatrix[ 128 ];
-};
-
-// The projection and view matrix
-struct KameraBuffer2
-{
-    matrix view;
-    matrix projection;
-};
-
-// The position of the kamera
-struct KameraBuffer
-{
-    float4 kPosition;
-};
-
-// these values should sum up to 1
-struct Material
-{
-    float ambientFactor;
-    float diffusFactor;
-    float specularFactor;
-};
-
-struct LightCount
-{
-    int diffuseLightCount;
-    int pointLightCount;
-};
-
-ConstantBuffer<KameraBuffer2> Kamera2 : register( b0 );
-ConstantBuffer<MatrixBuffer> Skelett : register( b1 );
-ConstantBuffer<KameraBuffer> Kamera : register( b2 );
-ConstantBuffer<Material> Object : register( b3 );
-ConstantBuffer<LightCount> Light : register( b4 );
-
-// lights
-struct DiffuseLight
-{
-    float3 direction;
-    float3 color;
-};
-
-struct PointLight
-{
-    float3 position;
-    float3 color;
-    float radius;
-};
-
-//StructuredBuffer< DiffuseLight > difuseLights : register( t1 );
-//StructuredBuffer< PointLight > pointLights : register( t2 );
-
-//////////////                                                                                          
-// TYPEDEFS //                                                                                          
-//////////////                                                                                          
-struct PixelInputType
-{
-    float4 worldPos : POSITION;
-    float4 position : SV_POSITION;
-    float2 tex : TEXCOORD;
-    float3 normal : NORMAL;
-};
-
-////////////////////////////////////////////////////////////////////////////////                        
-// Pixel Shader                                                                                         
-////////////////////////////////////////////////////////////////////////////////                        
-float4 main( PixelInputType input ) : SV_TARGET
-{
-    float3 diffuseLight = float3( 0, 0, 0 );
-    float3 specularLight = float3( 0, 0, 0 );
-   /* for( int j = 0; j < Light.diffuseLightCount; j++ )
-    {
-        if( dot( input.normal, -difuseLights[ j ].direction ) < 0 )
-            continue;
-        diffuseLight += difuseLights[ j ].color * dot( input.normal, -difuseLights[ j ].direction );
-    }
-    for( int i = 0; i < Light.pointLightCount; i++ )
-    {
-        float3 lightDir = pointLights[ i ].position - input.worldPos.xyz;
-        float factor = pointLights[ i ].radius / length( lightDir );
-        float f = dot( input.normal, normalize( lightDir ) );
-        if( f > 0 )
-        {
-            diffuseLight += pointLights[ i ].color * f * factor;
-            f = dot( normalize( reflect( normalize( -lightDir ), input.normal ) ), normalize( Kamera.kPosition.xyz - input.worldPos.xyz ) );
-            if( f > 0 )
-                specularLight += pointLights[ i ].color * f * factor;
-        }
-    }*/
-    float4 materialColor = shaderTexture.Sample( SampleType, input.tex );
-    float4 textureColor = saturate( materialColor * Object.ambientFactor + float4( diffuseLight.x, diffuseLight.y, diffuseLight.z, 0 ) * Object.diffusFactor + float4( specularLight.x, specularLight.y, specularLight.z, 0 ) * Object.specularFactor );
-    textureColor.a = materialColor.a;
-    return textureColor;
-}

+ 0 - 77
DX12VertexShader.hlsl

@@ -1,77 +0,0 @@
-
-Texture2D shaderTexture : register(t0);
-SamplerState SampleType : register(s0);
-
-// Matrizen fuer die einzelnen Knochen des Modells
-struct MatrixBuffer
-{
-	matrix knochenMatrix[128];
-};
-
-// The projection and view matrix
-struct KameraBuffer
-{
-	matrix view;
-	matrix projection;
-};
-
-// The position of the kamera
-struct KameraBuffer2
-{
-	float4 kPosition;
-};
-
-// these values should sum up to 1
-struct Material
-{
-	float ambientFactor;
-	float diffusFactor;
-	float specularFactor;
-};
-
-struct LightCount
-{
-	int diffuseLightCount;
-	int pointLightCount;
-};
-
-ConstantBuffer<KameraBuffer> Kamera : register(b0);
-ConstantBuffer<MatrixBuffer> Skelett : register(b1);
-ConstantBuffer<KameraBuffer2> Kamera2 : register(b2);
-ConstantBuffer<Material> Object : register(b3);
-ConstantBuffer<LightCount> Light : register(b4);
-
-struct VertexInputType
-{
-	float3 position : POSITION;
-	float2 tex : TEXCOORD;
-	float3 normal : NORMAL;
-	uint knochen : KNOCHEN_ID;
-	uint id : VERTEX_ID;
-};
-
-struct PixelInputType
-{
-	float4 worldPos : POSITION;
-	float4 position : SV_POSITION;
-	float2 tex : TEXCOORD;
-	float3 normal : NORMAL;
-};
-
-PixelInputType main(VertexInputType input)
-{
-	//return input;                                                                     
-	PixelInputType output;
-	output.normal = normalize(mul(input.normal, (float3x3)Skelett.knochenMatrix[input.knochen]));
-
-	// Change the position vector to be 4 units for proper matrix calculations.         
-	float4 position = float4(input.position.x, input.position.y, input.position.z, 1.f);
-	// Store the texture coordinates for the pixel shader.                              
-	output.tex = input.tex;
-
-	// Calculate the position of the vertex against the world, view, and projection matrices. 
-	output.worldPos = mul(position, Skelett.knochenMatrix[input.knochen]);
-	output.position = mul(output.worldPos, Kamera.view);
-	output.position = mul(output.position, Kamera.projection);
-	return output;
-}

+ 0 - 68
DX9GraphicsApi.cpp

@@ -50,8 +50,6 @@ typedef IDirect3D9*(__stdcall* D3D9CreateFunction)(UINT);
 void DirectX9::initialize(
     NativeWindow* fenster, Vec2<int> backBufferSize, bool fullScreen)
 {
-    if (pDirect3D)
-        return GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
     GraphicsApi::initialize(fenster, backBufferSize, fullScreen);
 
     HINSTANCE dll = getDLLRegister()->loadDLL("d3d9.dll", "d3d9.dll");
@@ -112,56 +110,6 @@ void DirectX9::initialize(
             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->getWindowHandle();
-    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->getBodySize();
-    d3dpp.BackBufferHeight = backBufferSize.y;
-    d3dpp.BackBufferWidth = backBufferSize.x;
-
-    uiImage->newImage(backBufferSize.x, backBufferSize.y, 0xFF000000);
-
-    HRESULT result = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT,
-        D3DDEVTYPE_HAL,
-        fenster->getWindowHandle(),
-        D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,
-        &d3dpp,
-        &pDevice);
-    if (result != S_OK)
-        WMessageBox(fenster->getWindowHandle(),
-            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->getWindowHandle(),
-            new Text("Fehler"),
-            new Text("DirectX 9 konnte nicht initialisiert werden."),
-            MB_ICONERROR);
-}
-
 void DirectX9::beginFrame(bool fill2D, bool fill3D, int fillColor)
 {
     if (fill2D) uiImage->setColor(fillColor);
@@ -210,7 +158,6 @@ void DirectX9::presentFrame()
             new Text("Fehler"),
             new Text("Es ist ein Fehler beim rendern aufgetreten."),
             MB_ICONERROR);
-        update();
     }
     // kopieren zum Screen
     int* bgBuff = uiImage->getBuffer();
@@ -226,7 +173,6 @@ void DirectX9::presentFrame()
             new Text("Fehler"),
             new Text("Es ist ein Fehler beim rendern aufgetreten."),
             MB_ICONERROR);
-        update();
     }
     if (result != S_OK)
     {
@@ -234,7 +180,6 @@ void DirectX9::presentFrame()
             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)
@@ -243,7 +188,6 @@ void DirectX9::presentFrame()
             new Text("Fehler"),
             new Text("Es ist ein Fehler beim rendern aufgetreten."),
             MB_ICONERROR);
-        update();
     }
 }
 
@@ -259,18 +203,6 @@ Image* DirectX9::zUIRenderImage() const
     return uiImage;
 }
 
-DXBuffer* DirectX9::createIndexBuffer()
-{
-    throw "Unsupported Operation for DirectX9 Graphics API. Use DirectX11 or "
-          "12";
-}
-
-DXBuffer* DirectX9::createVertexBuffer()
-{
-    throw "Unsupported Operation for DirectX9 Graphics API. Use DirectX11 or "
-          "12";
-}
-
 DXBuffer* DirectX9::createStructuredBuffer(int eSize)
 {
     throw "Unsupported Operation for DirectX9 Graphics API. Use DirectX11 or "

+ 10 - 3
DXBuffer.cpp

@@ -40,15 +40,22 @@ void DXBuffer::setChanged()
 //  laen: The length in bytes
 void DXBuffer::setLength(int len)
 {
-    this->len = len;
+    if (this->len != len)
+    {
+        this->len = len;
+        changed = 1;
+    }
 }
 
 // Sets what will be copied on the next call to 'copy'
 //  data: A pointer to the data
 void DXBuffer::setData(void* data)
 {
-    this->data = data;
-    changed = 1;
+    if (this->data != data)
+    {
+        this->data = data;
+        changed = 1;
+    }
 }
 
 // Returns the length of an element in bytes

+ 0 - 36
Framework.vcxproj

@@ -403,42 +403,6 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <FxCompile Include="DX12PixelShader.hlsl">
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.1</ShaderModel>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">DX12PixelShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">DX12PixelShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DX12PixelShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DX12PixelShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12PixelShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12PixelShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">DX12PixelShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">DX12PixelShader.h</HeaderFileOutput>
-    </FxCompile>
-    <FxCompile Include="DX12VertexShader.hlsl">
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
-      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.1</ShaderModel>
-      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.1</ShaderModel>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">DX12VertexShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">DX12VertexShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DX12VertexShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DX12VertexShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12VertexShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">DX12VertexShader.h</HeaderFileOutput>
-      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">DX12VertexShaderBytes</VariableName>
-      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">DX12VertexShader.h</HeaderFileOutput>
-    </FxCompile>
     <FxCompile Include="DX11PixelShader.hlsl">
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>

+ 0 - 6
Framework.vcxproj.filters

@@ -653,18 +653,12 @@
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
-    <FxCompile Include="DX12VertexShader.hlsl">
-      <Filter>Framework\Graphics\DX\Shader</Filter>
-    </FxCompile>
     <FxCompile Include="DX11VertexShader.hlsl">
       <Filter>Framework\Graphics\DX\Shader</Filter>
     </FxCompile>
     <FxCompile Include="DX11PixelShader.hlsl">
       <Filter>Framework\Graphics\DX\Shader</Filter>
     </FxCompile>
-    <FxCompile Include="DX12PixelShader.hlsl">
-      <Filter>Framework\Graphics\DX\Shader</Filter>
-    </FxCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="ClassDiagram.cd" />

+ 1 - 14
GraphicsApi.cpp

@@ -39,18 +39,6 @@ void GraphicsApi::initialize(
     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(Cam3D* zKamera) {}
@@ -105,8 +93,7 @@ Model3DData* GraphicsApi::createModel(const char* name)
         rwLock.unlockRead();
         return 0;
     }
-    Model3DData* model = new Model3DData(
-        createVertexBuffer(), createIndexBuffer(), nextModelId++);
+    Model3DData* model = new Model3DData(nextModelId++);
     rwLock.lockWrite();
     modelList->addModel(model, name);
     rwLock.unlockWrite();

+ 9 - 24
GraphicsApi.h

@@ -71,6 +71,7 @@ namespace Framework
     class Model3DList;
     class DXBuffer;
     class Model3DData;
+    class ID3D12GraphicsCommandList4;
 
     enum GraphicApiType;
 
@@ -99,17 +100,11 @@ namespace Framework
 
         bool fullScreen;
 
-        DLLEXPORT virtual DXBuffer* createIndexBuffer() = 0;
-        DLLEXPORT virtual DXBuffer* createVertexBuffer() = 0;
-
     public:
         DLLEXPORT GraphicsApi(GraphicApiType typ);
         DLLEXPORT virtual ~GraphicsApi();
         DLLEXPORT virtual void initialize(
             NativeWindow* fenster, Vec2<int> backBufferSize, bool fullScreen);
-        DLLEXPORT virtual void setBackBufferSize(Vec2<int> size);
-        DLLEXPORT virtual void setFullScreen(bool fullScreen);
-        DLLEXPORT virtual void update() = 0;
         DLLEXPORT virtual void beginFrame(
             bool fill2D = 0, bool fill3D = 0, int fillColor = 0);
         DLLEXPORT virtual void renderKamera(Cam3D* zKamera);
@@ -145,16 +140,12 @@ namespace Framework
         _D3DLOCKED_RECT* backRect;
         Image* uiImage;
 
-        DLLEXPORT virtual DXBuffer* createIndexBuffer() override;
-        DLLEXPORT virtual DXBuffer* createVertexBuffer() override;
-
     public:
         DLLEXPORT DirectX9();
         DLLEXPORT ~DirectX9();
         DLLEXPORT void initialize(NativeWindow* fenster,
             Vec2<int> backBufferSize,
             bool fullScreen) override;
-        DLLEXPORT void update() override;
         DLLEXPORT void beginFrame(
             bool fill2D, bool fill3D, int fillColor) override;
         DLLEXPORT void renderKamera(Cam3D* zKamera) override;
@@ -193,10 +184,12 @@ namespace Framework
         Vec3<float> kamPos;
         Plane3D<float> frustrum[6];
         int lastModelId = -1;
+        DX11Buffer** indexBuffers;
+        DX11Buffer** vertexBuffers;
 
         void renderObject(Model3D* zObj);
-        DLLEXPORT virtual DXBuffer* createIndexBuffer() override;
-        DLLEXPORT virtual DXBuffer* createVertexBuffer() override;
+        DX11Buffer* createIndexBuffer();
+        DX11Buffer* createVertexBuffer();
 
     protected:
         Critical deviceLock;
@@ -214,7 +207,6 @@ namespace Framework
         DLLEXPORT void initialize(NativeWindow* fenster,
             Vec2<int> backBufferSize,
             bool fullScreen) override;
-        DLLEXPORT void update() override;
         DLLEXPORT void beginFrame(
             bool fill2D, bool fill3D, int fillColor) override;
         DLLEXPORT void renderKamera(Cam3D* zKamera) override;
@@ -224,6 +216,7 @@ namespace Framework
             const char* name, Image* b) override;
         DLLEXPORT Image* zUIRenderImage() const override;
         DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
+        DLLEXPORT virtual Model3DData* createModel(const char* name) override;
         //! Checks whether a sphere is in the visible space of the world and
         //! needs to be drawn \param pos The center of the sphere \param
         //! radius The radius of the sphere \param dist A pointer to a
@@ -270,9 +263,7 @@ namespace Framework
         DX12VertexShader* vertexShader;
         DX12PixelShader* pixelShader;
 
-        void renderObject(Model3D* zObj);
-        DLLEXPORT virtual DXBuffer* createIndexBuffer() override;
-        DLLEXPORT virtual DXBuffer* createVertexBuffer() override;
+        DLLEXPORT void updateBottomLevelAccelerationStructure();
 
     public:
         DLLEXPORT DirectX12();
@@ -280,10 +271,11 @@ namespace Framework
         DLLEXPORT void initialize(NativeWindow* fenster,
             Vec2<int> backBufferSize,
             bool fullScreen) override;
-        DLLEXPORT void update() override;
         DLLEXPORT void beginFrame(
             bool fill2D, bool fill3D, int fillColor) override;
         DLLEXPORT void renderKamera(Cam3D* zKamera) override;
+        DLLEXPORT virtual void renderKamera(
+            Cam3D* zKamera, Texture* zTarget) override;
         //! TODO: DLLEXPORT void renderKamera( Cam3D* zKamera, Texture* zTarget
         //! ) override;
         DLLEXPORT void presentFrame() override;
@@ -291,13 +283,6 @@ namespace Framework
             const char* name, Image* b) override;
         DLLEXPORT Image* zUIRenderImage() const override;
         DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
-        //! Checks whether a sphere is in the visible space of the world and
-        //! needs to be drawn \param pos The center of the sphere \param
-        //! radius The radius of the sphere \param dist A pointer to a
-        //! float where the square of the distance to the camera position
-        //! is stored if this function returns true and the pointer is not 0
-        DLLEXPORT bool isInFrustrum(
-            const Vec3<float>& pos, float radius, float* dist = 0) const;
 
         DLLEXPORT static bool isAvailable();
     };

+ 1 - 1
M3File.cpp

@@ -380,7 +380,7 @@ Model3DData* M3File::loadModel(
         }
         else
         {
-            model = new Model3DData(0, 0, -1);
+            model = new Model3DData(-1);
         }
         int vAnz;
         d.read((char*)&vAnz, 4);

+ 20 - 45
Model3D.cpp

@@ -309,11 +309,10 @@ Polygon3D::~Polygon3D()
 // Contents of the Model3DData class
 
 // Constructor
-Model3DData::Model3DData(
-    DXBuffer* dxVertexBuffer, DXBuffer* dxIndexBuffer, int id)
+Model3DData::Model3DData(int id)
     : ReferenceCounter(),
-      dxIndexBuffer(dxIndexBuffer),
-      dxVertexBuffer(dxVertexBuffer),
+      vertexBufferChanged(0),
+      indexBufferChanged(0),
       id(id)
 {
     skelett = 0;
@@ -333,24 +332,9 @@ Model3DData::~Model3DData()
 {
     clearModel();
     polygons->release();
-    if (dxIndexBuffer)
-    {
-        dxIndexBuffer->release();
-    }
-    if (dxVertexBuffer)
-    {
-        dxVertexBuffer->release();
-    }
     delete[] indexBuffer;
 }
 
-// updates the DX Buffer gpu memory if changed
-DLLEXPORT void Model3DData::updateGPUMemory()
-{
-    dxIndexBuffer->copyToGPU();
-    dxVertexBuffer->copyToGPU();
-}
-
 // Deletes all model data
 void Model3DData::clearModel()
 {
@@ -397,22 +381,29 @@ void Model3DData::calculateNormals()
 //! Creates a buffer for all polygon indices
 void Model3DData::buildIndexBuffer()
 {
-    delete[] indexBuffer;
-    indexCount = 0;
+    int indexCount = 0;
     for (Polygon3D* p : *polygons)
         indexCount += p->indexAnz;
-    indexBuffer = new int[indexCount];
+    if (indexCount != this->indexCount)
+    {
+        delete[] indexBuffer;
+        indexBuffer = new int[indexCount];
+        this->indexCount = indexCount;
+        indexBufferChanged = 1;
+    }
     int current = 0;
     for (Polygon3D* p : *polygons)
     {
-        memcpy(indexBuffer + current, p->indexList, sizeof(int) * p->indexAnz);
+        for (int i = 0; i < p->indexAnz; i++)
+        {
+            if (indexBuffer[current + i] != p->indexList[i])
+            {
+                indexBufferChanged = 1;
+                indexBuffer[current + i] = p->indexList[i];
+            }
+        }
         current += p->indexAnz;
     }
-    if (dxIndexBuffer)
-    {
-        dxIndexBuffer->setLength((int)(indexCount * sizeof(int)));
-        dxIndexBuffer->setData(indexBuffer);
-    }
 }
 
 // Sets the pointer to a default skeleton
@@ -446,11 +437,7 @@ void Model3DData::setVertecies(Vertex3D* vertexList, int anz)
         if (vertexList[i].pos.z > maxPos.z) maxPos.z = vertexList[i].pos.z;
         vertexList[i].id = i;
     }
-    if (dxVertexBuffer)
-    {
-        dxVertexBuffer->setLength((int)(anz * sizeof(Vertex3D)));
-        dxVertexBuffer->setData(vertexList);
-    }
+    vertexBufferChanged = 1;
 }
 
 // Adds a polygon to the model
@@ -648,18 +635,6 @@ int Model3DData::getIndexCount() const
     return indexCount;
 }
 
-//! Returns the index buffer
-DXBuffer* Model3DData::zDXIndexBuffer() const
-{
-    return dxIndexBuffer;
-}
-
-//! Returns the vertex buffer
-DXBuffer* Model3DData::zDXVertexBuffer() const
-{
-    return dxVertexBuffer;
-}
-
 //! Returns the minimum point of the bounding box of the model
 Vec3<float> Model3DData::getMinPos() const
 {

+ 26 - 22
Model3D.h

@@ -1,21 +1,21 @@
 #pragma once
 
 #include "Array.h"
+#include "Drawing3D.h"
 #include "Mat4.h"
 #include "Vec2.h"
-#include "Drawing3D.h"
 
 struct ID3D11Buffer;
 
 namespace Framework
 {
-    struct Polygon2D;    //! Model2D.h
+    struct Polygon2D;     //! Model2D.h
     class Texture;        //! Texture.h
-    class Model2DData;   //! Model2D.h
-    class DXBuffer;      //! DXBuffer.h
-    class Render3D;      //! Render3D.h
+    class Model2DData;    //! Model2D.h
+    class DXBuffer;       //! DXBuffer.h
+    class Render3D;       //! Render3D.h
     class Model3DTexture; //! Model3D.h
-    class Model3DList;   //! Model3DList.h
+    class Model3DList;    //! Model3DList.h
     class World3D;        //! World3D.h
     class DXBuffer;
     class Shader;
@@ -136,9 +136,9 @@ namespace Framework
         Vec2<float> tPos;   //! The texture coordinates of the vertex
         Vec3<float> normal; //! The normal (points outward and is perpendicular
                             //! to the model's surface)
-        int knochenId; //! The ID of the bone with which the vertex moves
-                       //! during animation
-        int id;        //! The index of the vertex in the vertex buffer
+        int knochenId;      //! The ID of the bone with which the vertex moves
+                            //! during animation
+        int id;             //! The index of the vertex in the vertex buffer
     };
 
     //! A structure that stores all triangles of a 3D polygon
@@ -168,20 +168,17 @@ namespace Framework
         float radius;
         int* indexBuffer;
         int indexCount;
-        DXBuffer* dxIndexBuffer;
-        DXBuffer* dxVertexBuffer;
         Vec3<float> minPos;
         Vec3<float> maxPos;
+        bool vertexBufferChanged;
+        bool indexBufferChanged;
         int id;
 
     public:
         //! Constructor
-        DLLEXPORT Model3DData(
-            DXBuffer* dxVertexBuffer, DXBuffer* dxIndexBuffer, int id);
+        DLLEXPORT Model3DData(int id);
         //! Destructor
         DLLEXPORT ~Model3DData();
-        //! updates the DX Buffer gpu memory if changed
-        DLLEXPORT void updateGPUMemory();
         //! Deletes all model data
         DLLEXPORT void clearModel();
         //! Calculates the normals for the model's vertices
@@ -222,7 +219,8 @@ namespace Framework
         //! world space \param matBuffer An array of matrices filled with
         //! bone matrices \param scaleFactor The scaling of the model
         //! \param kamMatrix The combined view and projection matrices
-        //! \return The number of matrices used. 0 if no default skeleton was set
+        //! \return The number of matrices used. 0 if no default skeleton was
+        //! set
         int kalkulateMatrix(const Mat4<float>& modelMatrix,
             Mat4<float>* matBuffer,
             float scaleFactor,
@@ -258,14 +256,18 @@ namespace Framework
         DLLEXPORT const int* getIndexBuffer() const;
         //! Returns the number of indices in the index buffer
         DLLEXPORT int getIndexCount() const;
-        //! Returns the index buffer
-        DLLEXPORT DXBuffer* zDXIndexBuffer() const;
-        //! Returns the vertex buffer
-        DLLEXPORT DXBuffer* zDXVertexBuffer() const;
         //! Returns the minimum point of the model's bounding box
         DLLEXPORT Vec3<float> getMinPos() const;
         //! Returns the maximum point of the model's bounding box
         DLLEXPORT Vec3<float> getMaxPos() const;
+        //! Returns true if the index buffer has changed
+        DLLEXPORT bool wasIndexBufferChanged() const;
+        //! Sets the flag indicating that the index buffer has changed
+        DLLEXPORT void setIndexBufferChanged(bool changed);
+        //! Returns true if the vertex buffer has changed
+        DLLEXPORT bool wasVertexBufferChanged() const;
+        //! Sets the flag indicating that the vertex buffer has changed
+        DLLEXPORT void setVertexBufferChanged() const;
     };
 
     //! Stores a list of textures and which texture to use for which polygon
@@ -363,8 +365,10 @@ namespace Framework
         //! \param dir The direction of the ray in world coordinates
         //! \param zWorld The world from which the ray originates
         //! \return The color of the intersection point
-        DLLEXPORT virtual int traceRay(
-            Vec3<float>& point, Vec3<float>& dir, int pId, World3D* zWorld) const;
+        DLLEXPORT virtual int traceRay(Vec3<float>& point,
+            Vec3<float>& dir,
+            int pId,
+            World3D* zWorld) const;
         //! Returns the ID of the data if registered in a Model3DList.
         //! (see Framework::zM3DRegister())
         DLLEXPORT int getDataId() const;

+ 3 - 21
Model3DList.cpp

@@ -42,23 +42,6 @@ bool Model3DList::addModel(Model3DData* mdl, const char* name)
     return 1;
 }
 
-// Removes a model from the list
-//  name: The name of the model
-void Model3DList::removeModel(const char* name)
-{
-    int index = 0;
-    for (auto i : *names)
-    {
-        if (i->isEqual(name))
-        {
-            names->remove(index);
-            models->remove(index);
-            return;
-        }
-        index++;
-    }
-}
-
 // Checks whether a model has been stored under a specific name
 //  name: The name
 //  return: true if a model with the name exists
@@ -106,9 +89,8 @@ Model3DData* Model3DList::zModel(const char* name) const
     return 0;
 }
 
-//! remove All models
-DLLEXPORT void Model3DList::removeAll()
+// Returns a list of all models ordered by id
+RCArray<Model3DData>* Model3DList::zModels() const
 {
-    models->clear();
-    names->clear();
+    return models;
 }

+ 3 - 5
Model3DList.h

@@ -33,9 +33,6 @@ namespace Framework
         //! \param mdl The model
         //! \param name The name under which the model is stored in the list
         DLLEXPORT bool addModel(Model3DData* mdl, const char* name);
-        //! Removes a model from the list
-        //! \param name The name of the model
-        DLLEXPORT void removeModel(const char* name);
         //! Checks whether a model is stored under a specific name
         //! \param name The name \return true if a model with the name exists
         DLLEXPORT bool hasModel(const char* name) const;
@@ -45,7 +42,8 @@ namespace Framework
         //! Returns a specific model without increased reference counter
         //! \param name The name of the model
         DLLEXPORT Model3DData* zModel(const char* name) const;
-        //! remove All models
-        DLLEXPORT void removeAll();
+        //! Returns a list of all models ordered by the order in which they were
+        //! added to the list
+        DLLEXPORT RCArray<Model3DData>* zModels() const;
     };
 } // namespace Framework

+ 0 - 30
Screen.cpp

@@ -80,14 +80,6 @@ void Screen::setFill(bool f)
     fill = f;
 }
 
-// Updates the objects that manage the graphics card
-void Screen::update()
-{
-    rwLock.lockRead();
-    api->update();
-    rwLock.unlockRead();
-}
-
 void Screen::setTestRend(
     bool tr) // specifies whether to check for updates before rendering
 {
@@ -150,13 +142,6 @@ void Screen::setFillColor(int f) // sets the fill color
     rend = 1;
 }
 
-void Screen::setFullscreen(bool vollbild) // sets fullscreen
-{
-    rwLock.lockRead();
-    api->setFullScreen(vollbild);
-    rwLock.unlockRead();
-}
-
 void Screen::tick(double tickval)
 {
     actionsLock.lockRead();
@@ -201,21 +186,6 @@ void Screen::tick(double tickval)
     rwLock.unlockRead();
 }
 
-void Screen::setBackBufferSize(
-    int Width, int height) // sets the size of the back buffer
-{
-    rwLock.lockRead();
-    api->setBackBufferSize(Vec2<int>(Width, height));
-    rwLock.unlockRead();
-}
-
-void Screen::setBackBufferSize(Point& size)
-{
-    rwLock.lockRead();
-    api->setBackBufferSize(size);
-    rwLock.unlockRead();
-}
-
 void Screen::doMouseEvent(MouseEvent& me) // sends mouse event
 {
     int fBr = api->getBackBufferSize().x;

+ 0 - 14
Screen.h

@@ -115,8 +115,6 @@ namespace Framework
         //! frame (set by default) \param f 1 if the image should be reset
         //! before drawing
         DLLEXPORT virtual void setFill(bool f);
-        //! Updates the objects that manage the graphics card
-        DLLEXPORT virtual void update();
         //! Specifies whether it is checked before drawing if the image differs
         //! from the last one (set by default) \param tr 1 if drawing should
         //! only occur when necessary
@@ -150,22 +148,10 @@ namespace Framework
         //! Sets the color used to fill the image before drawing, if
         //! setFill(1) was set \param f The color in A8R8G8B8 format
         DLLEXPORT virtual void setFillColor(int f);
-        //! Specifies whether the image should be presented in fullscreen mode.
-        //! (not set by default) \param fullscreen 1 for fullscreen mode
-        DLLEXPORT virtual void setFullscreen(bool fullscreen);
         //! Processes the time elapsed since the last call of this function.
         //! Calls the tick functions of all drawings in the image
         //! \param tickval The elapsed time in seconds
         DLLEXPORT virtual void tick(double tickval);
-        //! Sets the resolution of the displayed image. It is automatically
-        //! scaled by the graphics card to fill the window
-        //! \param Width The width of the image in pixels
-        //! \param height The height of the image in pixels
-        DLLEXPORT virtual void setBackBufferSize(int Width, int height);
-        //! Sets the resolution of the displayed image. It is automatically
-        //! scaled by the graphics card to fill the window
-        //! \param size The width and height in pixels
-        DLLEXPORT virtual void setBackBufferSize(Point& size);
         //! Processes a mouse event. Called automatically by the framework.
         //! Passes the event to all drawings in the image
         //! \param me The event