Selaa lähdekoodia

split code files by direct x version

Kolja Strohm 1 kuukausi sitten
vanhempi
commit
17af46188f
26 muutettua tiedostoa jossa 924 lisäystä ja 956 poistoa
  1. 146 0
      DX11Buffer.cpp
  2. 64 0
      DX11Buffer.h
  3. 7 4
      DX11GraphicsApi.cpp
  4. 103 0
      DX11GraphicsApi.h
  5. 183 0
      DX11Shader.cpp
  6. 99 0
      DX11Shader.h
  7. 0 0
      DX12BLASModel.cpp
  8. 27 0
      DX12BLASModel.h
  9. 4 108
      DX12Buffer.cpp
  10. 3 43
      DX12Buffer.h
  11. 50 66
      DX12GraphicsApi.cpp
  12. 95 0
      DX12GraphicsApi.h
  13. 5 4
      DX12Shader.cpp
  14. 5 5
      DX12Shader.h
  15. 3 1
      DX9GraphicsApi.cpp
  16. 47 0
      DX9GraphicsApi.h
  17. 1 149
      DXBuffer.cpp
  18. 0 58
      DXBuffer.h
  19. 9 0
      Framework.vcxproj
  20. 47 11
      Framework.vcxproj.filters
  21. 1 217
      GraphicsApi.h
  22. 20 0
      Model3D.cpp
  23. 1 1
      Model3D.h
  24. 4 14
      Screen.cpp
  25. 0 179
      Shader.cpp
  26. 0 96
      Shader.h

+ 146 - 0
DX11Buffer.cpp

@@ -0,0 +1,146 @@
+#include "DX11Buffer.h"
+
+#include "Logging.h"
+
+#ifdef WIN32
+#    include <d3d11.h>
+#    include <d3d12.h>
+
+#    include "d3dx12.h"
+
+// Contents of the DX11Buffer class
+
+// Constructor
+// eSize: The length of an element in bytes
+Framework::DX11Buffer::DX11Buffer(int eSize,
+    ID3D11Device* device,
+    ID3D11DeviceContext* context,
+    int bindFlags,
+    Critical& deviceLock)
+    : DXBuffer(eSize),
+      deviceLock(deviceLock)
+{
+    buffer = 0;
+    description = new D3D11_BUFFER_DESC();
+    memset(description, 0, sizeof(description));
+    description->Usage = D3D11_USAGE_DYNAMIC;
+    description->CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+    description->BindFlags = bindFlags;
+
+    this->device = device;
+    this->context = context;
+}
+
+// Destructor
+Framework::DX11Buffer::~DX11Buffer()
+{
+    if (buffer) buffer->Release();
+    delete description;
+}
+
+// Copies the data into the buffer if it has changed
+//  zRObj: The object used to communicate with the graphics card
+void Framework::DX11Buffer::copyToGPU(int byteCount)
+{
+    if (!len) return;
+    if (byteCount < 0) byteCount = len;
+    if (description->ByteWidth < (unsigned)len)
+    {
+        if (buffer) buffer->Release();
+        buffer = 0;
+    }
+    if (!buffer)
+    {
+        description->ByteWidth = len;
+        deviceLock.lock();
+        device->CreateBuffer(description, 0, &buffer);
+        deviceLock.unlock();
+        if (data) changed = 1;
+    }
+    if (changed)
+    {
+        HRESULT res;
+        D3D11_MAPPED_SUBRESOURCE map;
+        deviceLock.lock();
+        if ((description->Usage | D3D11_USAGE_DYNAMIC) == description->Usage)
+            res = context->Map(
+                buffer, 0, D3D11_MAP::D3D11_MAP_WRITE_DISCARD, 0, &map);
+        else
+            res = context->Map(buffer, 0, D3D11_MAP::D3D11_MAP_WRITE, 0, &map);
+        deviceLock.unlock();
+        if (res == S_OK)
+        {
+            memcpy(map.pData, data, byteCount);
+            deviceLock.lock();
+            context->Unmap(buffer, 0);
+            deviceLock.unlock();
+            changed = 0;
+        }
+        else
+        {
+            Logging::error()
+                << "Could not update buffer: " << std::hex << res << std::endl;
+        }
+    }
+}
+
+// Returns the buffer
+ID3D11Buffer* Framework::DX11Buffer::zBuffer() const
+{
+    return buffer;
+}
+
+// Contents of the DXStructuredBuffer class
+
+// Constructor
+// eSize: The length of an element in bytes
+Framework::DX11StructuredBuffer::DX11StructuredBuffer(int eSize,
+    ID3D11Device* device,
+    ID3D11DeviceContext* context,
+    Critical& deviceLock)
+    : DX11Buffer(eSize,
+          device,
+          context,
+          D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE,
+          deviceLock)
+{
+    description->MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
+    description->StructureByteStride = eSize;
+    description->Usage = D3D11_USAGE_DEFAULT;
+    view = 0;
+}
+
+// Destructor
+Framework::DX11StructuredBuffer::~DX11StructuredBuffer()
+{
+    if (view) view->Release();
+}
+
+// Copies the data into the buffer if it has changed
+//  zRObj: The object used to communicate with the graphics card
+void Framework::DX11StructuredBuffer::copyToGPU(int byteCount)
+{
+    ID3D11Buffer* old = buffer;
+    DX11Buffer::copyToGPU(byteCount);
+    if (buffer != old)
+    {
+        if (view) view->Release();
+        D3D11_SHADER_RESOURCE_VIEW_DESC desc = {};
+        desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
+        desc.BufferEx.FirstElement = 0;
+        desc.Format = DXGI_FORMAT_UNKNOWN;
+        desc.BufferEx.NumElements
+            = description->ByteWidth / description->StructureByteStride;
+        deviceLock.lock();
+        device->CreateShaderResourceView(buffer, &desc, &view);
+        deviceLock.unlock();
+    }
+}
+
+// Returns the used shader resource view
+Framework::DX11StructuredBuffer::operator ID3D11ShaderResourceView*() const
+{
+    return view;
+}
+
+#endif

+ 64 - 0
DX11Buffer.h

@@ -0,0 +1,64 @@
+#pragma once
+
+#include "DXBuffer.h"
+
+#ifdef WIN32
+struct ID3D11Buffer;
+struct D3D11_BUFFER_DESC;
+struct ID3D11ShaderResourceView;
+struct ID3D11Device;
+struct ID3D11DeviceContext;
+#endif
+
+namespace Framework
+{
+#ifdef WIN32
+    //! A buffer with data in graphics memory
+    class DX11Buffer : public DXBuffer
+    {
+    protected:
+        D3D11_BUFFER_DESC* description;
+        ID3D11Buffer* buffer;
+        ID3D11Device* device;
+        ID3D11DeviceContext* context;
+        Critical& deviceLock;
+
+    public:
+        //! Constructor
+        //! eSize: The length of an element in bytes
+        DLLEXPORT DX11Buffer(int eSize,
+            ID3D11Device* device,
+            ID3D11DeviceContext* context,
+            int bindFlags,
+            Critical& deviceLock);
+        //! Destructor
+        DLLEXPORT virtual ~DX11Buffer();
+        //! Copies the data into the buffer if it has changed
+        DLLEXPORT virtual void copyToGPU(int byteCount = -1) override;
+        //! Returns the buffer
+        DLLEXPORT ID3D11Buffer* zBuffer() const;
+    };
+
+    //! A buffer of indices from the vertex buffer, where every three
+    //! form a triangle that is drawn
+    class DX11StructuredBuffer : public DX11Buffer
+    {
+    private:
+        ID3D11ShaderResourceView* view;
+
+    public:
+        //! Constructor
+        //! eSize: The length of an element in bytes
+        DLLEXPORT DX11StructuredBuffer(int eSize,
+            ID3D11Device* device,
+            ID3D11DeviceContext* context,
+            Critical& deviceLock);
+        //! Destructor
+        DLLEXPORT virtual ~DX11StructuredBuffer();
+        //! Copies the data into the buffer if it has changed
+        DLLEXPORT void copyToGPU(int byteCount = -1) override;
+        //! Returns the used shader resource view
+        DLLEXPORT operator ID3D11ShaderResourceView*() const;
+    };
+#endif
+} // namespace Framework

+ 7 - 4
DX11GraphicsApi.cpp

@@ -1,15 +1,16 @@
+#include "DX11GraphicsApi.h"
+
 #include <d3d11.h>
 #include <dxgi1_5.h>
 
 #include "Camera3D.h"
 #include "DLLRegister.h"
-#include "DXBuffer.h"
+#include "DX11Buffer.h"
+#include "DX11Shader.h"
 #include "Globals.h"
-#include "GraphicsApi.h"
 #include "Image.h"
 #include "Logging.h"
-#include "Model3DList.h"
-#include "Shader.h"
+#include "Screen.h"
 #include "Texture.h"
 #include "TextureList.h"
 #include "TextureModel.h"
@@ -634,6 +635,7 @@ void DirectX11::renderObject(Model3D* zObj)
         this->indexBuffers[curId]->setLength(
             zObj->zModelData()->getIndexCount() * sizeof(int));
         this->indexBuffers[curId]->copyToGPU();
+        zObj->zModelData()->setIndexBufferChanged(0);
     }
     if (zObj->zModelData()->wasVertexBufferChanged())
     {
@@ -642,6 +644,7 @@ void DirectX11::renderObject(Model3D* zObj)
         this->vertexBuffers[curId]->setLength(
             zObj->zModelData()->getVertexCount() * sizeof(Vertex3D));
         this->vertexBuffers[curId]->copyToGPU();
+        zObj->zModelData()->setVertexBufferChanged(0);
     }
     Mat4<float> trans = Mat4<float>::identity();
     int anz = zObj->calculateMatrices(trans, matrixBuffer);

+ 103 - 0
DX11GraphicsApi.h

@@ -0,0 +1,103 @@
+#pragma once
+
+#include "GraphicsApi.h"
+#include "Plane3D.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;
+
+namespace Framework
+{
+    class DX11StructuredBuffer;
+    class DX11PixelShader;
+    class DX11VertexShader;
+    class DX11Buffer;
+    class TextureList;
+    class Model3D;
+    class TextureModel;
+
+    class DirectX11 : public GraphicsApi
+    {
+    private:
+        ID3D11Device* d3d11Device;
+        ID3D11DeviceContext* d3d11Context;
+        IDXGISwapChain* d3d11SpawChain;
+        Texture* uiTexture;
+        DX11VertexShader* vertexShader;
+        DX11PixelShader* pixelShader;
+        ID3D11SamplerState* sampleState;
+        ID3D11RenderTargetView* rtview;
+        ID3D11DepthStencilView* dsView;
+        ID3D11Texture2D* depthStencilBuffer;
+        ID3D11DepthStencilState* depthStencilState;
+        ID3D11DepthStencilState* depthDisabledStencilState;
+        ID3D11BlendState* blendStateAlphaBlend;
+        D3D11_VIEWPORT* vp;
+        TextureModel* texturModel;
+        TextureList* texturRegister;
+        Texture* defaultTexture;
+        DX11StructuredBuffer* diffuseLights;
+        DX11StructuredBuffer* pointLights;
+        Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
+        Mat4<float> viewAndProj[2];
+        Vec3<float> kamPos;
+        Plane3D<float> frustrum[6];
+        int lastModelId = -1;
+        DX11Buffer** indexBuffers;
+        DX11Buffer** vertexBuffers;
+
+        void renderObject(Model3D* zObj);
+        DX11Buffer* createIndexBuffer();
+        DX11Buffer* createVertexBuffer();
+
+    protected:
+        Critical deviceLock;
+        ID3D11RasterizerState* texturRS;
+        ID3D11RasterizerState* meshRS;
+        DLLEXPORT virtual DX11VertexShader* initializeVertexShader(
+            unsigned char* byteCode, int size);
+        DLLEXPORT virtual DX11PixelShader* initializePixelShader(
+            unsigned char* byteCode, int size);
+        DLLEXPORT ID3D11DeviceContext* zContext();
+
+    public:
+        DLLEXPORT DirectX11();
+        DLLEXPORT ~DirectX11();
+        DLLEXPORT void initialize(NativeWindow* fenster,
+            Vec2<int> backBufferSize,
+            bool fullScreen) override;
+        DLLEXPORT void beginFrame(
+            bool fill2D, bool fill3D, int fillColor) override;
+        DLLEXPORT void renderKamera(Cam3D* zKamera) override;
+        DLLEXPORT void renderKamera(Cam3D* zKamera, Texture* zTarget) override;
+        DLLEXPORT void presentFrame() override;
+        DLLEXPORT Texture* createOrGetTexture(
+            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
+        //! 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 bool isInFrustrum(
+            const Vec3<float>& pos, Vec3<float> radius, float* dist = 0) const;
+
+        DLLEXPORT static bool isAvailable();
+    };
+} // namespace Framework

+ 183 - 0
DX11Shader.cpp

@@ -0,0 +1,183 @@
+#include "DX11Shader.h"
+
+#include <d3d11.h>
+
+#include "DX11Buffer.h"
+
+Framework::DX11Shader::DX11Shader(
+    ID3D11Device* device, ID3D11DeviceContext* context, Critical& deviceLock)
+    : Shader(),
+      deviceLock(deviceLock)
+{
+    this->device = device;
+    this->context = context;
+}
+
+Framework::DX11Shader::~DX11Shader() {}
+
+// Creates a constant buffer that passes constant data to the shader
+// A maximum of 14 buffers can be created
+//  zD3d11Device: The device used to create the buffer
+//  groesse: The size of the buffer in bytes
+//  index: The position of the buffer in the buffer array. Existing buffer
+//  is replaced. Buffer 1 cannot be created if buffer 0 has not yet
+//  been created, etc.
+bool Framework::DX11Shader::createConstBuffer(int groesse, int index)
+{
+    if (index < 0 || index >= 14) return 0;
+    bool ok = 1;
+    while ((groesse / 16) * 16
+           != groesse) // only multiples of 16 are allowed as size
+        groesse++;
+    while (!constBuffers->has(index))
+        constBuffers->add(0);
+    constBuffers->set(
+        new Framework::DX11Buffer(
+            1, device, context, D3D11_BIND_CONSTANT_BUFFER, deviceLock),
+        index);
+    constBuffers->z(index)->setLength(groesse);
+    return 1;
+}
+
+// Contents of the PixelShader class
+
+// Constructor
+Framework::DX11PixelShader::DX11PixelShader(
+    ID3D11Device* device, ID3D11DeviceContext* context, Critical& deviceLock)
+    : DX11Shader(device, context, deviceLock)
+{
+    pixelShader = 0;
+}
+
+// Destructor
+Framework::DX11PixelShader::~DX11PixelShader()
+{
+    if (pixelShader) pixelShader->Release();
+}
+
+// Sets the compiled shader
+//  bytes: The bytes of the compiled code
+//  length: the length of the byte array
+//  return: true if bytes is valid, false otherwise
+bool Framework::DX11PixelShader::setCompiledByteArray(
+    unsigned char* bytes, int length)
+{
+    deviceLock.lock();
+    HRESULT result = device->CreatePixelShader(bytes, length, 0, &pixelShader);
+    deviceLock.unlock();
+    return result == S_OK;
+}
+
+// After calling this function, this shader is used as pixel shader
+//  zD3d11Context: The context object used with the shader
+void Framework::DX11PixelShader::useShader()
+{
+    int maxI = constBuffers->getLastIndex();
+    for (int i = 0; i <= maxI; i++)
+    {
+        if (!constBuffers->z(i)) continue;
+        if (!((Framework::DX11Buffer*)constBuffers->z(i))->zBuffer())
+            constBuffers->z(i)->copyToGPU();
+        ID3D11Buffer* buf
+            = ((Framework::DX11Buffer*)constBuffers->z(i))->zBuffer();
+        deviceLock.lock();
+        context->PSSetConstantBuffers(i, 1, &buf);
+        deviceLock.unlock();
+    }
+    if (pixelShader)
+    {
+        deviceLock.lock();
+        context->PSSetShader(pixelShader, 0, 0);
+        deviceLock.unlock();
+    }
+}
+
+// Contents of the VertexShader class
+
+// Constructor
+Framework::DX11VertexShader::DX11VertexShader(ID3D11Device* device,
+    ID3D11DeviceContext* context,
+    Framework::Critical& deviceLock)
+    : DX11Shader(device, context, deviceLock)
+{
+    vertexShader = 0;
+    inputLayout = 0;
+    shaderByteBuffer = 0;
+    byteBufferSize = 0;
+}
+
+// Destructor
+Framework::DX11VertexShader::~DX11VertexShader()
+{
+    if (vertexShader) vertexShader->Release();
+    if (inputLayout) inputLayout->Release();
+}
+
+// Sets the compiled shader
+//  bytes: The bytes of the compiled code
+//  length: the length of the byte array
+//  return: true if bytes is valid, false otherwise
+bool Framework::DX11VertexShader::setCompiledByteArray(
+    unsigned char* bytes, int length)
+{
+    shaderByteBuffer = (unsigned char*)bytes;
+    byteBufferSize = length;
+    deviceLock.lock();
+    HRESULT result
+        = device->CreateVertexShader(bytes, length, 0, &vertexShader);
+    deviceLock.unlock();
+    return result == S_OK;
+}
+
+// Creates an InputLayout for the shader
+// Must only be called after compile
+//  zD3d11Device: The device used to create the layout
+//  descArray: An array with initialization data
+//  anz: The number of elements in the array
+bool Framework::DX11VertexShader::createInputLayout(
+    D3D11_INPUT_ELEMENT_DESC* descArray, int anz)
+{
+    if (!shaderByteBuffer) return 0;
+    if (inputLayout) inputLayout->Release();
+    inputLayout = 0;
+    deviceLock.lock();
+    HRESULT res = device->CreateInputLayout(
+        descArray, anz, shaderByteBuffer, byteBufferSize, &inputLayout);
+    deviceLock.unlock();
+    if (res == S_OK)
+    {
+        shaderByteBuffer = 0;
+        byteBufferSize = 0;
+    }
+    return res == S_OK;
+}
+
+// After calling this function, this shader is used as vertex shader
+//  zD3d11Context: The context object used with the shader
+void Framework::DX11VertexShader::useShader()
+{
+    int maxI = constBuffers->getLastIndex();
+    for (int i = 0; i <= maxI; i++)
+    {
+        if (!constBuffers->z(i)) continue;
+        if (!((Framework::DX11Buffer*)constBuffers->z(i))->zBuffer())
+            constBuffers->z(i)->copyToGPU();
+        ID3D11Buffer* buf
+            = ((Framework::DX11Buffer*)constBuffers->z(i))->zBuffer();
+        deviceLock.lock();
+        context->VSSetConstantBuffers(i, 1, &buf);
+        deviceLock.unlock();
+    }
+    if (inputLayout)
+    {
+        deviceLock.lock();
+        context->IASetInputLayout(inputLayout);
+        deviceLock.unlock();
+    }
+    if (vertexShader)
+    {
+        deviceLock.lock();
+        context->VSSetShader(vertexShader, 0, 0);
+        deviceLock.unlock();
+    }
+}

+ 99 - 0
DX11Shader.h

@@ -0,0 +1,99 @@
+#pragma once
+
+#include "Shader.h"
+
+struct ID3D10Blob;
+struct ID3D11PixelShader;
+struct ID3D11VertexShader;
+struct ID3D11Device;
+struct ID3D11DeviceContext;
+struct D3D11_INPUT_ELEMENT_DESC;
+struct ID3D11Buffer;
+struct ID3D11InputLayout;
+
+namespace Framework
+{
+    class DX11Shader : public Shader
+    {
+    protected:
+        ID3D11Device* device;
+        ID3D11DeviceContext* context;
+        Critical& deviceLock;
+
+    public:
+        DLLEXPORT DX11Shader(ID3D11Device* device,
+            ID3D11DeviceContext* context,
+            Critical& deviceLock);
+        DLLEXPORT virtual ~DX11Shader();
+        //! Creates a constant buffer that passes constant data to the shader.
+        //! A maximum of 14 buffers can be created.
+        //!  zD3d11Device: The device with which the buffer should be created
+        //! \param size The size of the buffer in bytes
+        //! \param index The position of the buffer in the buffer array. An
+        //! existing buffer will be replaced. Buffer 1 cannot be created
+        //! if buffer 0 has not been created yet, etc.
+        DLLEXPORT virtual bool createConstBuffer(int size, int index) override;
+    };
+
+    //! Manages a pixel shader
+    class DX11PixelShader : public DX11Shader
+    {
+    private:
+        ID3D11PixelShader* pixelShader;
+
+    public:
+        //! Constructor
+        DLLEXPORT DX11PixelShader(ID3D11Device* device,
+            ID3D11DeviceContext* context,
+            Critical& deviceLock);
+        //! Destructor
+        DLLEXPORT ~DX11PixelShader();
+        //! Sets the compiled shader
+        //!  zD3d11Device: The device with which the shader should be created
+        //! \param bytes The bytes of the compiled code
+        //! \param length The length of the byte array
+        //! \return true if bytes is valid, false otherwise
+        DLLEXPORT bool setCompiledByteArray(
+            unsigned char* bytes, int length) override;
+        //! After calling this function, this shader is used as a pixel shader
+        //!  zD3d11Context: The context object with which the shader should
+        //!  be used
+        DLLEXPORT void useShader() override;
+    };
+
+    //! Manages a vertex shader
+    class DX11VertexShader : public DX11Shader
+    {
+    private:
+        ID3D11VertexShader* vertexShader;
+        ID3D11InputLayout* inputLayout;
+        unsigned char* shaderByteBuffer;
+        int byteBufferSize;
+
+    public:
+        //! Constructor
+        DLLEXPORT DX11VertexShader(ID3D11Device* device,
+            ID3D11DeviceContext* context,
+            Critical& deviceLock);
+        //! Destructor
+        DLLEXPORT ~DX11VertexShader();
+        //! Sets the compiled shader
+        //!  zD3d11Device: The device with which the shader should be created
+        //! \param bytes The bytes of the compiled code
+        //! \param length The length of the byte array
+        //! \return true if bytes is valid, false otherwise
+        DLLEXPORT bool setCompiledByteArray(
+            unsigned char* bytes, int length) override;
+        //! Creates an input layout for the shader.
+        //! May only be called after compile.
+        //!  zD3d11Device: The device with which the layout should be created
+        //! \param descArray An array with initialization data
+        //! \param anz The number of elements in the array
+        DLLEXPORT bool createInputLayout(
+            D3D11_INPUT_ELEMENT_DESC* descArray, int anz);
+        //! After calling this function, this shader is used as a vertex shader
+        //!  zD3d11Context: The context object with which the shader should
+        //!  be used
+        DLLEXPORT void useShader() override;
+    };
+} // namespace Framework

+ 0 - 0
DX12BLASModel.cpp


+ 27 - 0
DX12BLASModel.h

@@ -0,0 +1,27 @@
+#pragma once
+
+#include "Array.h"
+#include "DX12Buffer.h"
+
+namespace Framework
+{
+    class Model3DData;
+
+    class DX12BLASModel : public ReferenceCounter
+    {
+    private:
+        Model3DData* zModelData;
+        RCArray<DX12Buffer>* vertexBuffers;
+        RCArray<DX12Buffer>* indexBuffers;
+
+    public:
+        DX12BLASModel(Model3DData* zModelData);
+        ~DX12BLASModel();
+
+        void calculateBuffers();
+        int getBufferCount() const;
+        const RCArray<DX12Buffer>* zVertexBuffers() const;
+        const RCArray<DX12Buffer>* zIndexBuffers() const;
+    };
+
+} // namespace Framework

+ 4 - 108
DX12Buffer.cpp

@@ -8,17 +8,15 @@ using namespace Framework;
 
 // Constructor
 // eSize: length of an element in bytes
-DX12Buffer::DX12Buffer(
-    int eSize, ID3D12Device* device, ID3D12GraphicsCommandList* list, int flags)
+DX12Buffer::DX12Buffer(int eSize, ID3D12Device5* device, int flags)
     : DXBuffer(eSize),
       buffer(0),
-      intermediate(0),
-      device(device),
-      list(list)
+      device(device)
 {
     description = new D3D12_RESOURCE_DESC();
     ZeroMemory(description, sizeof(D3D12_RESOURCE_DESC));
     description->Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
+    description->Alignment = 0;
     description->Height = 1;
     description->DepthOrArraySize = 1;
     description->MipLevels = 1;
@@ -31,7 +29,6 @@ DX12Buffer::DX12Buffer(
 // Destructor
 DX12Buffer::~DX12Buffer()
 {
-    if (intermediate) intermediate->Release();
     if (buffer) buffer->Release();
     delete description;
 }
@@ -41,9 +38,8 @@ void DX12Buffer::copyToGPU(int byteCount)
 {
     if (!len) return;
     if (byteCount < 0) byteCount = len;
-    if (description->Width < len)
+    if (description->Width != len)
     {
-        if (intermediate) intermediate->Release();
         if (buffer) buffer->Release();
         buffer = 0;
         description->Width = len;
@@ -63,15 +59,6 @@ void DX12Buffer::copyToGPU(int byteCount)
             0,
             __uuidof(ID3D12Resource),
             (void**)&buffer);
-        hprop.Type = D3D12_HEAP_TYPE_UPLOAD;
-        device->CreateCommittedResource(&hprop,
-            D3D12_HEAP_FLAG_NONE,
-            description,
-            D3D12_RESOURCE_STATE_GENERIC_READ,
-            0,
-            __uuidof(ID3D12Resource),
-            (void**)&intermediate);
-        if (data) changed = 1;
     }
     if (changed && data)
     {
@@ -83,7 +70,6 @@ void DX12Buffer::copyToGPU(int byteCount)
         memcpy(pData, data, byteCount);
         r.End = byteCount;
         buffer->Unmap(0, &r);
-        // list->CopyBufferRegion( buffer, 0, intermediate, 0, len );
         changed = 0;
     }
 }
@@ -92,94 +78,4 @@ void DX12Buffer::copyToGPU(int byteCount)
 ID3D12Resource* DX12Buffer::zBuffer() const
 {
     return buffer;
-}
-
-DX12IndexBuffer::DX12IndexBuffer(int eSize,
-    ID3D12Device* device,
-    DX12CopyCommandQueue* copy,
-    DX12DirectCommandQueue* direct)
-    : DX12Buffer(
-          eSize, device, copy->getCommandList(), D3D12_RESOURCE_FLAG_NONE),
-      copy(copy),
-      direct(direct)
-{
-    ibs = 0;
-}
-
-DX12IndexBuffer::~DX12IndexBuffer() {}
-
-// Copies the data into the buffer if it has changed
-void DX12IndexBuffer::copyToGPU(int byteCount)
-{
-    /*if( ibs )
-    {
-        D3D12_RESOURCE_BARRIER barrier;
-        barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
-        barrier.Transition.pResource = buffer;
-        barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_INDEX_BUFFER;
-        barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
-        barrier.Transition.Subresource = 0;
-        barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-        direct->getCommandList()->ResourceBarrier( 1, &barrier );
-        direct->execute();
-        ibs = 0;
-    }*/
-    DX12Buffer::copyToGPU(byteCount);
-    // copy->execute();
-    /*D3D12_RESOURCE_BARRIER barrier;
-    barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
-    barrier.Transition.pResource = buffer;
-    barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
-    barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_INDEX_BUFFER;
-    barrier.Transition.Subresource = 0;
-    barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-    direct->getCommandList()->ResourceBarrier( 1, &barrier );
-    direct->execute();
-    ibs = 1;*/
-}
-
-DX12VertexBuffer::DX12VertexBuffer(int eSize,
-    ID3D12Device* device,
-    DX12CopyCommandQueue* copy,
-    DX12DirectCommandQueue* direct)
-    : DX12Buffer(
-          eSize, device, copy->getCommandList(), D3D12_RESOURCE_FLAG_NONE),
-      copy(copy),
-      direct(direct)
-{
-    vbs = 0;
-}
-
-DX12VertexBuffer::~DX12VertexBuffer() {}
-
-// Copies the data into the buffer if it has changed
-void DX12VertexBuffer::copyToGPU(int byteCount)
-{
-    /*if( vbs )
-    {
-        D3D12_RESOURCE_BARRIER barrier;
-        barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
-        barrier.Transition.pResource = buffer;
-        barrier.Transition.StateBefore =
-    D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
-        barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
-        barrier.Transition.Subresource = 0;
-        barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-        direct->getCommandList()->ResourceBarrier( 1, &barrier );
-        direct->execute();
-        vbs = 0;
-    }*/
-    DX12Buffer::copyToGPU(byteCount);
-    // copy->execute();
-    /*D3D12_RESOURCE_BARRIER barrier;
-    barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
-    barrier.Transition.pResource = buffer;
-    barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
-    barrier.Transition.StateAfter =
-    D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
-    barrier.Transition.Subresource = 0;
-    barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
-    direct->getCommandList()->ResourceBarrier( 1, &barrier );
-    direct->execute();
-    vbs = 1;*/
 }

+ 3 - 43
DX12Buffer.h

@@ -2,9 +2,8 @@
 #include "DXBuffer.h"
 
 struct ID3D12Resource;
-struct ID3D12Device;
+struct ID3D12Device5;
 struct D3D12_RESOURCE_DESC;
-struct ID3D12GraphicsCommandList;
 
 namespace Framework
 {
@@ -14,17 +13,12 @@ namespace Framework
     protected:
         D3D12_RESOURCE_DESC* description;
         ID3D12Resource* buffer;
-        ID3D12Resource* intermediate;
-        ID3D12Device* device;
-        ID3D12GraphicsCommandList* list;
+        ID3D12Device5* device;
 
     public:
         //! Constructor
         //! eSize: The length of an element in bytes
-        DLLEXPORT DX12Buffer(int eSize,
-            ID3D12Device* device,
-            ID3D12GraphicsCommandList* list,
-            int bindFlags);
+        DLLEXPORT DX12Buffer(int eSize, ID3D12Device5* device, int bindFlags);
         //! Destructor
         DLLEXPORT virtual ~DX12Buffer();
         //! Copies the data into the buffer if it has changed
@@ -32,38 +26,4 @@ namespace Framework
         //! Returns the buffer
         DLLEXPORT ID3D12Resource* zBuffer() const;
     };
-
-    class DX12IndexBuffer : public DX12Buffer
-    {
-    private:
-        bool ibs;
-        DX12DirectCommandQueue* direct;
-        DX12CopyCommandQueue* copy;
-
-    public:
-        DX12IndexBuffer(int eSize,
-            ID3D12Device* device,
-            DX12CopyCommandQueue* copy,
-            DX12DirectCommandQueue* direct);
-        ~DX12IndexBuffer();
-        //! Copies the data into the buffer if it has changed
-        DLLEXPORT void copyToGPU(int byteCount = -1) override;
-    };
-
-    class DX12VertexBuffer : public DX12Buffer
-    {
-    private:
-        bool vbs;
-        DX12DirectCommandQueue* direct;
-        DX12CopyCommandQueue* copy;
-
-    public:
-        DX12VertexBuffer(int eSize,
-            ID3D12Device* device,
-            DX12CopyCommandQueue* copy,
-            DX12DirectCommandQueue* direct);
-        ~DX12VertexBuffer();
-        //! Copies the data into the buffer if it has changed
-        DLLEXPORT void copyToGPU(int byteCount = -1) override;
-    };
 } // namespace Framework

+ 50 - 66
DX12GraphicsApi.cpp

@@ -1,3 +1,5 @@
+#include "DX12GraphicsApi.h"
+
 #include <d3d11.h>
 #include <d3d12.h>
 #include <dxgi1_6.h>
@@ -6,17 +8,17 @@
 #include "Camera3D.h"
 #include "d3dx12.h"
 #include "DLLRegister.h"
-#include "DX12Buffer.h"
+#include "DX12BLASModel.h"
 #include "DX12CommandQueue.h"
 #include "DX12PixelShader.h"
 #include "DX12Shader.h"
 #include "DX12Texture.h"
 #include "DX12VertexShader.h"
 #include "Globals.h"
-#include "GraphicsApi.h"
 #include "Image.h"
 #include "Model3D.h"
 #include "Model3DList.h"
+#include "Screen.h"
 #include "Shader.h"
 #include "TextureList.h"
 #include "TextureModel.h"
@@ -103,6 +105,34 @@ DirectX12::~DirectX12()
     if (debug) debug->Release();
 }
 
+void DirectX12::updateBottomLevelAccelerationStructure()
+{
+    bool updateRequired = 0;
+    for (Model3DData* model : *modelList->zModels())
+    {
+        if (model->wasIndexBufferChanged() || model->wasVertexBufferChanged())
+        {
+            updateRequired = true;
+            break;
+        }
+    }
+    int bufferIndex = 0;
+    if (updateRequired)
+    {
+        for (Model3DData* model : *modelList->zModels())
+        {
+            int id = model->getId();
+            if (model->wasIndexBufferChanged()
+                || model->wasVertexBufferChanged())
+            {
+                blasModels[id]->calculateBuffers();
+            }
+            bufferIndex += blasModels[id]->getBufferCount();
+        }
+        // TODO: create BLAS from calculated buffers
+    }
+}
+
 typedef HRESULT(__stdcall* CreateDXGIFactory2Function)(UINT, REFIID, void**);
 
 typedef HRESULT(__stdcall* D3D12CreateDeviceFunction)(
@@ -788,7 +818,8 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
     barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
     barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
 
-    directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
+    // TODO
+    // directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
 
     if (fill2D) uiTexture->zImage()->setColor(fillColor);
     if (fill3D)
@@ -806,72 +837,26 @@ void DirectX12::beginFrame(bool fill2D, bool fill3D, int fillColor)
             = rtvHeap->GetCPUDescriptorHandleForHeapStart();
         rtv.ptr += rtvDescriptorSize * backBufferIndex;
 
-        directCommandQueue->getCommandList()->OMSetRenderTargets(1, &rtv, 0, 0);
-        directCommandQueue->getCommandList()->ClearRenderTargetView(
-            rtv, color, 0, 0);
+        // TODO
+        // directCommandQueue->getCommandList()->OMSetRenderTargets(1, &rtv, 0,
+        // 0);
+        //  directCommandQueue->getCommandList()->ClearRenderTargetView(
+        //      rtv, color, 0, 0);
     }
     int lc[] = {0, 0};
     pixelShader->fillConstBuffer((char*)lc, 4, sizeof(int) * 2);
-}
 
-// Checks whether a sphere is in the visible space of the world and
-// needs to be drawn
-//  pos: The center of the sphere
-//  radius: The radius of the sphere
-//  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
-bool DirectX12::isInFrustrum(
-    const Vec3<float>& pos, float radius, float* dist) const
-{
-    for (int i = 0; i < 6; i++)
-    {
-        if (frustrum[i] * pos + radius < 0) return 0;
-    }
-    if (dist) *dist = kamPos.distance(pos);
-    return 1;
+    uiTexture->updateTextur();
 }
 
 void DirectX12::renderKamera(Cam3D* zKamera)
 {
-    directCommandQueue->getCommandList()->RSSetViewports(
-        1, (D3D12_VIEWPORT*)zKamera->zViewPort());
+    // TODO
+    // directCommandQueue->getCommandList()->RSSetViewports(
+    //     1, (D3D12_VIEWPORT*)zKamera->zViewPort());
 
     Mat4<float> tmp = zKamera->getProjectionMatrix() * zKamera->getViewMatrix();
 
-    frustrum[0].x = tmp.elements[3][0] + tmp.elements[0][0];
-    frustrum[0].y = tmp.elements[3][1] + tmp.elements[0][1];
-    frustrum[0].z = tmp.elements[3][2] + tmp.elements[0][2];
-    frustrum[0].w = tmp.elements[3][3] + tmp.elements[0][3];
-
-    frustrum[1].x = tmp.elements[3][0] - tmp.elements[0][0];
-    frustrum[1].y = tmp.elements[3][1] - tmp.elements[0][1];
-    frustrum[1].z = tmp.elements[3][2] - tmp.elements[0][2];
-    frustrum[1].w = tmp.elements[3][3] - tmp.elements[0][3];
-
-    frustrum[2].x = tmp.elements[3][0] - tmp.elements[1][0];
-    frustrum[2].y = tmp.elements[3][1] - tmp.elements[1][1];
-    frustrum[2].z = tmp.elements[3][2] - tmp.elements[1][2];
-    frustrum[2].w = tmp.elements[3][3] - tmp.elements[1][3];
-
-    frustrum[3].x = tmp.elements[3][0] + tmp.elements[1][0];
-    frustrum[3].y = tmp.elements[3][1] + tmp.elements[1][1];
-    frustrum[3].z = tmp.elements[3][2] + tmp.elements[1][2];
-    frustrum[3].w = tmp.elements[3][3] + tmp.elements[1][3];
-
-    frustrum[4].x = tmp.elements[2][0];
-    frustrum[4].y = tmp.elements[2][1];
-    frustrum[4].z = tmp.elements[2][2];
-    frustrum[4].w = tmp.elements[2][3];
-
-    frustrum[5].x = tmp.elements[3][0] - tmp.elements[2][0];
-    frustrum[5].y = tmp.elements[3][1] - tmp.elements[2][1];
-    frustrum[5].z = tmp.elements[3][2] - tmp.elements[2][2];
-    frustrum[5].w = tmp.elements[3][3] - tmp.elements[2][3];
-
-    for (int i = 0; i < 6; i++)
-        frustrum[i].normalize();
-
     viewAndProj[0] = zKamera->getViewMatrix();
     viewAndProj[1] = zKamera->getProjectionMatrix();
     kamPos = zKamera->getWorldPosition();
@@ -882,13 +867,16 @@ void DirectX12::renderKamera(Cam3D* zKamera)
         pixelShader->fillConstBuffer((char*)&kamPos, 2, sizeof(float) * 3);
     World3D* w = zKamera->zWorld();
     w->render([this](Model3D* obj) {
-        if (isInFrustrum(obj->getPos(), obj->getRadius())) renderObject(obj);
+        // TODO: create or update top level aceleration structure if a model was
+        // changed
     });
+    // TODO: call ray tracing
 }
 
 void DirectX12::presentFrame()
 {
-    directCommandQueue->getCommandList()->RSSetViewports(1, viewPort);
+    // TODO
+    // directCommandQueue->getCommandList()->RSSetViewports(1, viewPort);
 
     viewAndProj[0] = Mat4<float>::identity();
     viewAndProj[1] = Mat4<float>::identity();
@@ -896,11 +884,6 @@ void DirectX12::presentFrame()
         vertexShader->fillConstBuffer(
             (char*)viewAndProj, 0, sizeof(Mat4<float>) * 2);
 
-    uiTexture->updateTextur();
-
-    if (fenster && !IsIconic(fenster->getWindowHandle()))
-        renderObject(texturModel);
-
     D3D12_RESOURCE_BARRIER barrier;
     ZeroMemory(&barrier, sizeof(barrier));
     barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
@@ -910,7 +893,8 @@ void DirectX12::presentFrame()
     barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
     barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
 
-    directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
+    // TODO
+    // directCommandQueue->getCommandList()->ResourceBarrier(1, &barrier);
     copyCommandQueue->execute();
     directCommandQueue->execute();
 

+ 95 - 0
DX12GraphicsApi.h

@@ -0,0 +1,95 @@
+#pragma once
+
+#include "DX12Buffer.h"
+#include "GraphicsApi.h"
+
+//! DirectX 12 Types
+
+struct ID3D12Debug;
+struct ID3D12Device5;
+struct ID3D12InfoQueue;
+struct ID3D12CommandQueue;
+struct IDXGISwapChain4;
+struct ID3D12DescriptorHeap;
+struct ID3D12Resource;
+struct ID3D12CommandAllocator;
+struct ID3D12GraphicsCommandList;
+struct ID3D12Fence;
+struct D3D12_VIEWPORT;
+struct D3D12_VERTEX_BUFFER_VIEW;
+struct D3D12_INDEX_BUFFER_VIEW;
+struct ID3D12RootSignature;
+struct ID3D12PipelineState;
+
+namespace Framework
+{
+    class DX12Buffer;
+    class DX12DirectCommandQueue;
+    class DX12CopyCommandQueue;
+    class DX12ComputeCommandQueue;
+    class DX12PixelShader;
+    class DX12VertexShader;
+    class DX12VertexBuffer;
+    class DX12IndexBuffer;
+    class ID3D12GraphicsCommandList4;
+    class DX12BLASModel;
+    class TextureList;
+    class TextureModel;
+
+    class DirectX12 : public GraphicsApi
+    {
+    private:
+        ID3D12Debug* debug;
+        ID3D12Device5* device;
+        ID3D12InfoQueue* infoQueue;
+        DX12DirectCommandQueue* directCommandQueue;
+        DX12CopyCommandQueue* copyCommandQueue;
+        DX12ComputeCommandQueue* computeCommandQueue;
+        IDXGISwapChain4* swapChain;
+        ID3D12DescriptorHeap* rtvHeap;
+        ID3D12DescriptorHeap* dsvHeap;
+        ID3D12DescriptorHeap* shaderBufferHeap;
+        ID3D12Resource* depthBuffer;
+        ID3D12Resource* backBuffer[2];
+        int backBufferIndex;
+        int tearing;
+        D3D12_VIEWPORT* viewPort;
+        tagRECT* allowedRenderArea;
+        D3D12_VERTEX_BUFFER_VIEW* vertexBufferView;
+        D3D12_INDEX_BUFFER_VIEW* indexBufferView;
+        ID3D12RootSignature* signature;
+        ID3D12PipelineState* pipeline;
+        Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
+        Mat4<float> viewAndProj[2];
+        Vec3<float> kamPos;
+        TextureModel* texturModel;
+        Texture* uiTexture;
+        TextureList* texturRegister;
+        DX12VertexShader* vertexShader;
+        DX12PixelShader* pixelShader;
+        DX12BLASModel** blasModels;
+
+        DLLEXPORT void updateBottomLevelAccelerationStructure();
+
+    public:
+        DLLEXPORT DirectX12();
+        DLLEXPORT ~DirectX12();
+        DLLEXPORT void initialize(NativeWindow* fenster,
+            Vec2<int> backBufferSize,
+            bool fullScreen) 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;
+        DLLEXPORT Texture* createOrGetTexture(
+            const char* name, Image* b) override;
+        DLLEXPORT Image* zUIRenderImage() const override;
+        DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
+
+        DLLEXPORT static bool isAvailable();
+    };
+} // namespace Framework

+ 5 - 4
DX12Shader.cpp

@@ -5,7 +5,7 @@
 
 using namespace Framework;
 
-DX12Shader::DX12Shader(ID3D12Device* device,
+DX12Shader::DX12Shader(ID3D12Device5* device,
     DX12CopyCommandQueue* copy,
     DX12DirectCommandQueue* direct)
     : Shader()
@@ -36,7 +36,8 @@ bool DX12Shader::createConstBuffer(int size, int index)
         size++;
     while (!constBuffers->has(index))
         constBuffers->add(0);
-    constBuffers->set(new DX12VertexBuffer(1, device, copy, direct), index);
+    constBuffers->set(
+        new Framework::DX12Buffer(1, device, D3D12_HEAP_FLAG_NONE), index);
     constBuffers->z(index)->setLength(size);
     constBuffers->z(index)->copyToGPU();
     return 1;
@@ -86,14 +87,14 @@ void DX12Shader::getViewDesc(int index, D3D12_CONSTANT_BUFFER_VIEW_DESC& view)
     view.BufferLocation = zB->zBuffer()->GetGPUVirtualAddress();
 }
 
-DX12PixelShader::DX12PixelShader(ID3D12Device* device,
+DX12PixelShader::DX12PixelShader(ID3D12Device5* device,
     DX12CopyCommandQueue* copy,
     DX12DirectCommandQueue* direct)
     : DX12Shader(device, copy, direct)
 {}
 
 // Constructor
-DX12VertexShader::DX12VertexShader(ID3D12Device* device,
+DX12VertexShader::DX12VertexShader(ID3D12Device5* device,
     DX12CopyCommandQueue* copy,
     DX12DirectCommandQueue* direct)
     : DX12Shader(device, copy, direct)

+ 5 - 5
DX12Shader.h

@@ -3,7 +3,7 @@
 #include "DX12Buffer.h"
 #include "Shader.h"
 
-struct ID3D12Device;
+struct ID3D12Device5;
 struct ID3D12GraphicsCommandList;
 struct D3D12_INPUT_ELEMENT_DESC;
 struct D3D12_ROOT_PARAMETER1;
@@ -14,14 +14,14 @@ namespace Framework
     class DX12Shader : public Shader
     {
     protected:
-        ID3D12Device* device;
+        ID3D12Device5* device;
         DX12CopyCommandQueue* copy;
         DX12DirectCommandQueue* direct;
         unsigned char* shaderByteBuffer;
         int byteBufferSize;
 
     public:
-        DX12Shader(ID3D12Device* device,
+        DX12Shader(ID3D12Device5* device,
             DX12CopyCommandQueue* copy,
             DX12DirectCommandQueue* direct);
         virtual ~DX12Shader();
@@ -58,7 +58,7 @@ namespace Framework
     class DX12PixelShader : public DX12Shader
     {
     public:
-        DX12PixelShader(ID3D12Device* device,
+        DX12PixelShader(ID3D12Device5* device,
             DX12CopyCommandQueue* copy,
             DX12DirectCommandQueue* direct);
     };
@@ -71,7 +71,7 @@ namespace Framework
 
     public:
         //! Constructor
-        DX12VertexShader(ID3D12Device* device,
+        DX12VertexShader(ID3D12Device5* device,
             DX12CopyCommandQueue* copy,
             DX12DirectCommandQueue* direct);
         //! Destructor

+ 3 - 1
DX9GraphicsApi.cpp

@@ -1,10 +1,12 @@
+#include "DX9GraphicsApi.h"
+
 #include <d3d9.h>
 
 #include "Camera3D.h"
 #include "DLLRegister.h"
 #include "Globals.h"
-#include "GraphicsApi.h"
 #include "Image.h"
+#include "Screen.h"
 #include "Texture.h"
 #include "Timer.h"
 #include "Window.h"

+ 47 - 0
DX9GraphicsApi.h

@@ -0,0 +1,47 @@
+#pragma once
+
+#include "GraphicsApi.h"
+
+//! DirectX 9 Types
+
+struct IDirect3D9;
+struct IDirect3DDevice9;
+struct IDirect3DSurface9;
+struct _D3DLOCKED_RECT;
+struct tagRECT;
+
+namespace Framework
+{
+    class NativeWindow; //! NativeWindow.h
+    class Image;        //! Image.h
+    class Cam3D;        //! Camera3D.h
+    class Texture;      //! Texture.h
+    class Model3DData;  //! Model3D.h
+
+    //! A graphics API that uses DirectX 9. Only supports 2D rendering
+    class DirectX9 : public GraphicsApi
+    {
+    private:
+        IDirect3D9* pDirect3D;
+        IDirect3DDevice9* pDevice;
+        IDirect3DSurface9* pBackBuffer;
+        _D3DLOCKED_RECT* backRect;
+        Image* uiImage;
+
+    public:
+        DLLEXPORT DirectX9();
+        DLLEXPORT ~DirectX9();
+        DLLEXPORT void initialize(NativeWindow* fenster,
+            Vec2<int> backBufferSize,
+            bool fullScreen) override;
+        DLLEXPORT void beginFrame(
+            bool fill2D, bool fill3D, int fillColor) override;
+        DLLEXPORT void renderKamera(Cam3D* zKamera) override;
+        DLLEXPORT void presentFrame() override;
+        DLLEXPORT Texture* createOrGetTexture(
+            const char* name, Image* b) override;
+        DLLEXPORT Image* zUIRenderImage() const override;
+
+        DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
+    };
+} // namespace Framework

+ 1 - 149
DXBuffer.cpp

@@ -1,15 +1,5 @@
 #include "DXBuffer.h"
 
-#include <iostream>
-
-#include "Logging.h"
-#ifdef WIN32
-#    include <d3d11.h>
-#    include <d3d12.h>
-
-#    include "d3dx12.h"
-#endif
-
 using namespace Framework;
 
 // Contents of the DXBuffer class
@@ -68,142 +58,4 @@ int DXBuffer::getElementLength() const
 int DXBuffer::getElementCount() const
 {
     return len / elLen;
-}
-
-#ifdef WIN32
-// Contents of the DX11Buffer class
-
-// Constructor
-// eSize: The length of an element in bytes
-DX11Buffer::DX11Buffer(int eSize,
-    ID3D11Device* device,
-    ID3D11DeviceContext* context,
-    int bindFlags,
-    Critical& deviceLock)
-    : DXBuffer(eSize),
-      deviceLock(deviceLock)
-{
-    buffer = 0;
-    description = new D3D11_BUFFER_DESC();
-    memset(description, 0, sizeof(description));
-    description->Usage = D3D11_USAGE_DYNAMIC;
-    description->CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    description->BindFlags = bindFlags;
-
-    this->device = device;
-    this->context = context;
-}
-
-// Destructor
-DX11Buffer::~DX11Buffer()
-{
-    if (buffer) buffer->Release();
-    delete description;
-}
-
-// Copies the data into the buffer if it has changed
-//  zRObj: The object used to communicate with the graphics card
-void DX11Buffer::copyToGPU(int byteCount)
-{
-    if (!len) return;
-    if (byteCount < 0) byteCount = len;
-    if (description->ByteWidth < (unsigned)len)
-    {
-        if (buffer) buffer->Release();
-        buffer = 0;
-    }
-    if (!buffer)
-    {
-        description->ByteWidth = len;
-        deviceLock.lock();
-        device->CreateBuffer(description, 0, &buffer);
-        deviceLock.unlock();
-        if (data) changed = 1;
-    }
-    if (changed)
-    {
-        HRESULT res;
-        D3D11_MAPPED_SUBRESOURCE map;
-        deviceLock.lock();
-        if ((description->Usage | D3D11_USAGE_DYNAMIC) == description->Usage)
-            res = context->Map(
-                buffer, 0, D3D11_MAP::D3D11_MAP_WRITE_DISCARD, 0, &map);
-        else
-            res = context->Map(buffer, 0, D3D11_MAP::D3D11_MAP_WRITE, 0, &map);
-        deviceLock.unlock();
-        if (res == S_OK)
-        {
-            memcpy(map.pData, data, byteCount);
-            deviceLock.lock();
-            context->Unmap(buffer, 0);
-            deviceLock.unlock();
-            changed = 0;
-        }
-        else
-        {
-            Logging::error()
-                << "Could not update buffer: " << std::hex << res << std::endl;
-        }
-    }
-}
-
-// Returns the buffer
-ID3D11Buffer* DX11Buffer::zBuffer() const
-{
-    return buffer;
-}
-
-// Contents of the DXStructuredBuffer class
-
-// Constructor
-// eSize: The length of an element in bytes
-DX11StructuredBuffer::DX11StructuredBuffer(int eSize,
-    ID3D11Device* device,
-    ID3D11DeviceContext* context,
-    Critical& deviceLock)
-    : DX11Buffer(eSize,
-          device,
-          context,
-          D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE,
-          deviceLock)
-{
-    description->MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
-    description->StructureByteStride = eSize;
-    description->Usage = D3D11_USAGE_DEFAULT;
-    view = 0;
-}
-
-// Destructor
-DX11StructuredBuffer::~DX11StructuredBuffer()
-{
-    if (view) view->Release();
-}
-
-// Copies the data into the buffer if it has changed
-//  zRObj: The object used to communicate with the graphics card
-void DX11StructuredBuffer::copyToGPU(int byteCount)
-{
-    ID3D11Buffer* old = buffer;
-    DX11Buffer::copyToGPU(byteCount);
-    if (buffer != old)
-    {
-        if (view) view->Release();
-        D3D11_SHADER_RESOURCE_VIEW_DESC desc = {};
-        desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
-        desc.BufferEx.FirstElement = 0;
-        desc.Format = DXGI_FORMAT_UNKNOWN;
-        desc.BufferEx.NumElements
-            = description->ByteWidth / description->StructureByteStride;
-        deviceLock.lock();
-        device->CreateShaderResourceView(buffer, &desc, &view);
-        deviceLock.unlock();
-    }
-}
-
-// Returns the used shader resource view
-DX11StructuredBuffer::operator ID3D11ShaderResourceView*() const
-{
-    return view;
-}
-
-#endif
+}

+ 0 - 58
DXBuffer.h

@@ -4,14 +4,6 @@
 #include "OperatingSystem.h"
 #include "ReferenceCounter.h"
 
-#ifdef WIN32
-struct ID3D11Buffer;
-struct D3D11_BUFFER_DESC;
-struct ID3D11ShaderResourceView;
-struct ID3D11Device;
-struct ID3D11DeviceContext;
-#endif
-
 namespace Framework
 {
     class DX12CopyCommandQueue;
@@ -50,54 +42,4 @@ namespace Framework
         //! Returns the number of elements in the buffer
         DLLEXPORT int getElementCount() const;
     };
-
-#ifdef WIN32
-    //! A buffer with data in graphics memory
-    class DX11Buffer : public DXBuffer
-    {
-    protected:
-        D3D11_BUFFER_DESC* description;
-        ID3D11Buffer* buffer;
-        ID3D11Device* device;
-        ID3D11DeviceContext* context;
-        Critical& deviceLock;
-
-    public:
-        //! Constructor
-        //! eSize: The length of an element in bytes
-        DLLEXPORT DX11Buffer(int eSize,
-            ID3D11Device* device,
-            ID3D11DeviceContext* context,
-            int bindFlags,
-            Critical& deviceLock);
-        //! Destructor
-        DLLEXPORT virtual ~DX11Buffer();
-        //! Copies the data into the buffer if it has changed
-        DLLEXPORT virtual void copyToGPU(int byteCount = -1) override;
-        //! Returns the buffer
-        DLLEXPORT ID3D11Buffer* zBuffer() const;
-    };
-
-    //! A buffer of indices from the vertex buffer, where every three
-    //! form a triangle that is drawn
-    class DX11StructuredBuffer : public DX11Buffer
-    {
-    private:
-        ID3D11ShaderResourceView* view;
-
-    public:
-        //! Constructor
-        //! eSize: The length of an element in bytes
-        DLLEXPORT DX11StructuredBuffer(int eSize,
-            ID3D11Device* device,
-            ID3D11DeviceContext* context,
-            Critical& deviceLock);
-        //! Destructor
-        DLLEXPORT virtual ~DX11StructuredBuffer();
-        //! Copies the data into the buffer if it has changed
-        DLLEXPORT void copyToGPU(int byteCount = -1) override;
-        //! Returns the used shader resource view
-        DLLEXPORT operator ID3D11ShaderResourceView*() const;
-    };
-#endif
 } // namespace Framework

+ 9 - 0
Framework.vcxproj

@@ -205,6 +205,12 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <ClInclude Include="Array.h" />
     <ClInclude Include="Assembly.h" />
     <ClInclude Include="AsynchronCall.h" />
+    <ClInclude Include="DX11Buffer.h" />
+    <ClInclude Include="DX11GraphicsApi.h" />
+    <ClInclude Include="DX11Shader.h" />
+    <ClInclude Include="DX12BLASModel.h" />
+    <ClInclude Include="DX12GraphicsApi.h" />
+    <ClInclude Include="DX9GraphicsApi.h" />
     <ClInclude Include="SelectionBox.h" />
     <ClInclude Include="Console.h" />
     <ClInclude Include="DataValidator.h" />
@@ -313,6 +319,9 @@ copy "x64\Release\Framework.dll" "..\..\Spiele Platform\SMP\Fertig\x64\framework
     <ClCompile Include="Animation3D.cpp" />
     <ClCompile Include="Assembly.cpp" />
     <ClCompile Include="AsynchronCall.cpp" />
+    <ClCompile Include="DX11Buffer.cpp" />
+    <ClCompile Include="DX11Shader.cpp" />
+    <ClCompile Include="DX12BLASModel.cpp" />
     <ClCompile Include="SelectionBox.cpp" />
     <ClCompile Include="Console.cpp" />
     <ClCompile Include="DataValidator.cpp" />

+ 47 - 11
Framework.vcxproj.filters

@@ -29,9 +29,6 @@
     <Filter Include="Framework\Graphics\DX">
       <UniqueIdentifier>{cbb56eda-8286-4f8b-9a06-47b5af838106}</UniqueIdentifier>
     </Filter>
-    <Filter Include="Framework\Graphics\DX\Shader">
-      <UniqueIdentifier>{37ae3fd2-27b5-4878-a15c-2c7fe2c8779f}</UniqueIdentifier>
-    </Filter>
     <Filter Include="Framework\Graphics\DX\DX12">
       <UniqueIdentifier>{2f5e8a0f-d55f-427f-ba12-dc88fe967dd5}</UniqueIdentifier>
     </Filter>
@@ -65,6 +62,18 @@
     <Filter Include="Framework\Assembly">
       <UniqueIdentifier>{a20b9fa9-ed63-4ac0-9ba1-998568fdd574}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Framework\Graphics\DX\DX9">
+      <UniqueIdentifier>{b6b1d125-4055-4290-8585-c9f721b3791f}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Framework\Graphics\DX\DX11">
+      <UniqueIdentifier>{b2405340-a4cd-428b-8bf1-c0b755ad9ec4}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Framework\Graphics\DX\DX11\Shader">
+      <UniqueIdentifier>{37ae3fd2-27b5-4878-a15c-2c7fe2c8779f}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Framework\Graphics\DX\DX12\Shader">
+      <UniqueIdentifier>{debb503a-e2be-42b1-9907-c2a252a44faf}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Model2D.h">
@@ -388,6 +397,24 @@
     <ClInclude Include="Assembly.h">
       <Filter>Framework\Assembly</Filter>
     </ClInclude>
+    <ClInclude Include="DX12BLASModel.h">
+      <Filter>Framework\Graphics\DX\DX12</Filter>
+    </ClInclude>
+    <ClInclude Include="DX12GraphicsApi.h">
+      <Filter>Framework\Graphics\DX\DX12</Filter>
+    </ClInclude>
+    <ClInclude Include="DX9GraphicsApi.h">
+      <Filter>Framework\Graphics\DX\DX9</Filter>
+    </ClInclude>
+    <ClInclude Include="DX11GraphicsApi.h">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClInclude>
+    <ClInclude Include="DX11Buffer.h">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClInclude>
+    <ClInclude Include="DX11Shader.h">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Model3DCollection.h">
@@ -444,12 +471,6 @@
     <ClCompile Include="Screen.cpp">
       <Filter>Framework\Graphics\DX</Filter>
     </ClCompile>
-    <ClCompile Include="DX9GraphicsApi.cpp">
-      <Filter>Framework\Graphics\DX</Filter>
-    </ClCompile>
-    <ClCompile Include="DX11GraphicsApi.cpp">
-      <Filter>Framework\Graphics\DX</Filter>
-    </ClCompile>
     <ClCompile Include="DXBuffer.cpp">
       <Filter>Framework\Graphics\DX</Filter>
     </ClCompile>
@@ -651,13 +672,28 @@
     <ClCompile Include="Assembly.cpp">
       <Filter>Framework\Assembly</Filter>
     </ClCompile>
+    <ClCompile Include="DX12BLASModel.cpp">
+      <Filter>Framework\Graphics\DX\DX12</Filter>
+    </ClCompile>
+    <ClCompile Include="DX9GraphicsApi.cpp">
+      <Filter>Framework\Graphics\DX\DX9</Filter>
+    </ClCompile>
+    <ClCompile Include="DX11GraphicsApi.cpp">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClCompile>
+    <ClCompile Include="DX11Buffer.cpp">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClCompile>
+    <ClCompile Include="DX11Shader.cpp">
+      <Filter>Framework\Graphics\DX\DX11</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="DX11VertexShader.hlsl">
-      <Filter>Framework\Graphics\DX\Shader</Filter>
+      <Filter>Framework\Graphics\DX\DX11\Shader</Filter>
     </FxCompile>
     <FxCompile Include="DX11PixelShader.hlsl">
-      <Filter>Framework\Graphics\DX\Shader</Filter>
+      <Filter>Framework\Graphics\DX\DX11\Shader</Filter>
     </FxCompile>
   </ItemGroup>
   <ItemGroup>

+ 1 - 217
GraphicsApi.h

@@ -1,77 +1,17 @@
 #pragma once
 
+#include "DXBuffer.h"
 #include "Mat4.h"
-#include "Plane3D.h"
-#include "Screen.h"
 #include "Vec2.h"
 
-//! DirectX 12 Types
-
-struct ID3D12Debug;
-struct ID3D12Device5;
-struct ID3D12InfoQueue;
-struct ID3D12CommandQueue;
-struct IDXGISwapChain4;
-struct ID3D12DescriptorHeap;
-struct ID3D12Resource;
-struct ID3D12CommandAllocator;
-struct ID3D12GraphicsCommandList;
-struct ID3D12Fence;
-struct D3D12_VIEWPORT;
-struct D3D12_VERTEX_BUFFER_VIEW;
-struct D3D12_INDEX_BUFFER_VIEW;
-struct ID3D12RootSignature;
-struct ID3D12PipelineState;
-
-//! 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;
-struct tagRECT;
-
 namespace Framework
 {
     class NativeWindow;
     class Image;
     class Texture;
-    class DX11PixelShader;
-    class DX11VertexShader;
-    class TextureModel;
-    class Render3D;
-    class TextureList;
     class Cam3D;
-    class Model3D;
-    class DX11Buffer;
-    class DX11StructuredBuffer;
-    class DX12Buffer;
-    class DX12DirectCommandQueue;
-    class DX12CopyCommandQueue;
-    class DX12ComputeCommandQueue;
-    class DX12PixelShader;
-    class DX12VertexShader;
-    class DX12VertexBuffer;
-    class DX12IndexBuffer;
     class Model3DList;
-    class DXBuffer;
     class Model3DData;
-    class ID3D12GraphicsCommandList4;
 
     enum GraphicApiType;
 
@@ -130,160 +70,4 @@ namespace Framework
         //! \param eSize the size of one element of the buffer in bytes
         DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) = 0;
     };
-
-    class DirectX9 : public GraphicsApi
-    {
-    private:
-        IDirect3D9* pDirect3D;
-        IDirect3DDevice9* pDevice;
-        IDirect3DSurface9* pBackBuffer;
-        _D3DLOCKED_RECT* backRect;
-        Image* uiImage;
-
-    public:
-        DLLEXPORT DirectX9();
-        DLLEXPORT ~DirectX9();
-        DLLEXPORT void initialize(NativeWindow* fenster,
-            Vec2<int> backBufferSize,
-            bool fullScreen) override;
-        DLLEXPORT void beginFrame(
-            bool fill2D, bool fill3D, int fillColor) override;
-        DLLEXPORT void renderKamera(Cam3D* zKamera) override;
-        DLLEXPORT void presentFrame() override;
-        DLLEXPORT Texture* createOrGetTexture(
-            const char* name, Image* b) override;
-        DLLEXPORT Image* zUIRenderImage() const override;
-
-        DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
-    };
-
-    class DirectX11 : public GraphicsApi
-    {
-    private:
-        ID3D11Device* d3d11Device;
-        ID3D11DeviceContext* d3d11Context;
-        IDXGISwapChain* d3d11SpawChain;
-        Texture* uiTexture;
-        DX11VertexShader* vertexShader;
-        DX11PixelShader* pixelShader;
-        ID3D11SamplerState* sampleState;
-        ID3D11RenderTargetView* rtview;
-        ID3D11DepthStencilView* dsView;
-        ID3D11Texture2D* depthStencilBuffer;
-        ID3D11DepthStencilState* depthStencilState;
-        ID3D11DepthStencilState* depthDisabledStencilState;
-        ID3D11BlendState* blendStateAlphaBlend;
-        D3D11_VIEWPORT* vp;
-        TextureModel* texturModel;
-        TextureList* texturRegister;
-        Texture* defaultTexture;
-        DX11StructuredBuffer* diffuseLights;
-        DX11StructuredBuffer* pointLights;
-        Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
-        Mat4<float> viewAndProj[2];
-        Vec3<float> kamPos;
-        Plane3D<float> frustrum[6];
-        int lastModelId = -1;
-        DX11Buffer** indexBuffers;
-        DX11Buffer** vertexBuffers;
-
-        void renderObject(Model3D* zObj);
-        DX11Buffer* createIndexBuffer();
-        DX11Buffer* createVertexBuffer();
-
-    protected:
-        Critical deviceLock;
-        ID3D11RasterizerState* texturRS;
-        ID3D11RasterizerState* meshRS;
-        DLLEXPORT virtual DX11VertexShader* initializeVertexShader(
-            unsigned char* byteCode, int size);
-        DLLEXPORT virtual DX11PixelShader* initializePixelShader(
-            unsigned char* byteCode, int size);
-        DLLEXPORT ID3D11DeviceContext* zContext();
-
-    public:
-        DLLEXPORT DirectX11();
-        DLLEXPORT ~DirectX11();
-        DLLEXPORT void initialize(NativeWindow* fenster,
-            Vec2<int> backBufferSize,
-            bool fullScreen) override;
-        DLLEXPORT void beginFrame(
-            bool fill2D, bool fill3D, int fillColor) override;
-        DLLEXPORT void renderKamera(Cam3D* zKamera) override;
-        DLLEXPORT void renderKamera(Cam3D* zKamera, Texture* zTarget) override;
-        DLLEXPORT void presentFrame() override;
-        DLLEXPORT Texture* createOrGetTexture(
-            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
-        //! 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 bool isInFrustrum(
-            const Vec3<float>& pos, Vec3<float> radius, float* dist = 0) const;
-
-        DLLEXPORT static bool isAvailable();
-    };
-
-    class DirectX12 : public GraphicsApi
-    {
-    private:
-        ID3D12Debug* debug;
-        ID3D12Device5* device;
-        ID3D12InfoQueue* infoQueue;
-        DX12DirectCommandQueue* directCommandQueue;
-        DX12CopyCommandQueue* copyCommandQueue;
-        DX12ComputeCommandQueue* computeCommandQueue;
-        IDXGISwapChain4* swapChain;
-        ID3D12DescriptorHeap* rtvHeap;
-        ID3D12DescriptorHeap* dsvHeap;
-        ID3D12DescriptorHeap* shaderBufferHeap;
-        ID3D12Resource* depthBuffer;
-        ID3D12Resource* backBuffer[2];
-        int backBufferIndex;
-        int tearing;
-        D3D12_VIEWPORT* viewPort;
-        tagRECT* allowedRenderArea;
-        D3D12_VERTEX_BUFFER_VIEW* vertexBufferView;
-        D3D12_INDEX_BUFFER_VIEW* indexBufferView;
-        ID3D12RootSignature* signature;
-        ID3D12PipelineState* pipeline;
-        Mat4<float> matrixBuffer[MAX_KNOCHEN_ANZ];
-        Mat4<float> viewAndProj[2];
-        Vec3<float> kamPos;
-        Plane3D<float> frustrum[6];
-        TextureModel* texturModel;
-        Texture* uiTexture;
-        TextureList* texturRegister;
-        DX12VertexShader* vertexShader;
-        DX12PixelShader* pixelShader;
-
-        DLLEXPORT void updateBottomLevelAccelerationStructure();
-
-    public:
-        DLLEXPORT DirectX12();
-        DLLEXPORT ~DirectX12();
-        DLLEXPORT void initialize(NativeWindow* fenster,
-            Vec2<int> backBufferSize,
-            bool fullScreen) 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;
-        DLLEXPORT Texture* createOrGetTexture(
-            const char* name, Image* b) override;
-        DLLEXPORT Image* zUIRenderImage() const override;
-        DLLEXPORT virtual DXBuffer* createStructuredBuffer(int eSize) override;
-
-        DLLEXPORT static bool isAvailable();
-    };
 } // namespace Framework

+ 20 - 0
Model3D.cpp

@@ -647,6 +647,26 @@ Vec3<float> Model3DData::getMaxPos() const
     return maxPos;
 }
 
+bool Framework::Model3DData::wasIndexBufferChanged() const
+{
+    return indexBufferChanged;
+}
+
+void Framework::Model3DData::setIndexBufferChanged(bool changed)
+{
+    indexBufferChanged = changed;
+}
+
+bool Framework::Model3DData::wasVertexBufferChanged() const
+{
+    return vertexBufferChanged;
+}
+
+void Framework::Model3DData::setVertexBufferChanged(bool changed)
+{
+    vertexBufferChanged = changed;
+}
+
 // Contents of the Model3DTexture class
 
 // Constructor

+ 1 - 1
Model3D.h

@@ -267,7 +267,7 @@ namespace Framework
         //! 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;
+        DLLEXPORT void setVertexBufferChanged(bool changed);
     };
 
     //! Stores a list of textures and which texture to use for which polygon

+ 4 - 14
Screen.cpp

@@ -1,28 +1,18 @@
 #include "Screen.h"
 
-#include <iostream>
-
 #include "Drawing.h"
-#include "File.h"
-#include "Globals.h"
-#include "GraphicsApi.h"
+#include "DX11GraphicsApi.h"
+#include "DX12GraphicsApi.h"
+#include "DX9GraphicsApi.h"
 #include "Image.h"
-#include "Logging.h"
-#include "Mat3.h"
-#include "Model3D.h"
 #include "MouseEvent.h"
 #include "Text.h"
 #include "Timer.h"
 #include "ToolTip.h"
 #include "Window.h"
-#ifdef WIN32
-#    include <d3d11.h>
-#    include <d3d9.h>
-#    include <D3Dcompiler.h>
-#    include <DirectXMath.h>
 
+#ifdef WIN32
 #    include "Camera3D.h"
-#    include "comdef.h"
 #endif
 
 using namespace Framework;

+ 0 - 179
Shader.cpp

@@ -1,12 +1,6 @@
 #include "Shader.h"
 
-#include <d3d11.h>
-#include <d3d12.h>
-#include <iostream>
-
 #include "DXBuffer.h"
-#include "File.h"
-#include "Text.h"
 
 using namespace Framework;
 
@@ -78,177 +72,4 @@ int Shader::getFirstUninitializedBufferIndex() const
         if (!constBuffers->has(index) || !constBuffers->z(index)) return index;
     }
     return constBuffers->getEntryCount();
-}
-
-DX11Shader::DX11Shader(
-    ID3D11Device* device, ID3D11DeviceContext* context, Critical& deviceLock)
-    : Shader(),
-      deviceLock(deviceLock)
-{
-    this->device = device;
-    this->context = context;
-}
-
-DX11Shader::~DX11Shader() {}
-
-// Creates a constant buffer that passes constant data to the shader
-// A maximum of 14 buffers can be created
-//  zD3d11Device: The device used to create the buffer
-//  groesse: The size of the buffer in bytes
-//  index: The position of the buffer in the buffer array. Existing buffer
-//  is replaced. Buffer 1 cannot be created if buffer 0 has not yet
-//  been created, etc.
-bool DX11Shader::createConstBuffer(int groesse, int index)
-{
-    if (index < 0 || index >= 14) return 0;
-    bool ok = 1;
-    while ((groesse / 16) * 16
-           != groesse) // only multiples of 16 are allowed as size
-        groesse++;
-    while (!constBuffers->has(index))
-        constBuffers->add(0);
-    constBuffers->set(
-        new DX11Buffer(
-            1, device, context, D3D11_BIND_CONSTANT_BUFFER, deviceLock),
-        index);
-    constBuffers->z(index)->setLength(groesse);
-    return 1;
-}
-
-// Contents of the PixelShader class
-
-// Constructor
-DX11PixelShader::DX11PixelShader(
-    ID3D11Device* device, ID3D11DeviceContext* context, Critical& deviceLock)
-    : DX11Shader(device, context, deviceLock)
-{
-    pixelShader = 0;
-}
-
-// Destructor
-DX11PixelShader::~DX11PixelShader()
-{
-    if (pixelShader) pixelShader->Release();
-}
-
-// Sets the compiled shader
-//  bytes: The bytes of the compiled code
-//  length: the length of the byte array
-//  return: true if bytes is valid, false otherwise
-bool DX11PixelShader::setCompiledByteArray(unsigned char* bytes, int length)
-{
-    deviceLock.lock();
-    HRESULT result = device->CreatePixelShader(bytes, length, 0, &pixelShader);
-    deviceLock.unlock();
-    return result == S_OK;
-}
-
-// After calling this function, this shader is used as pixel shader
-//  zD3d11Context: The context object used with the shader
-void DX11PixelShader::useShader()
-{
-    int maxI = constBuffers->getLastIndex();
-    for (int i = 0; i <= maxI; i++)
-    {
-        if (!constBuffers->z(i)) continue;
-        if (!((DX11Buffer*)constBuffers->z(i))->zBuffer())
-            constBuffers->z(i)->copyToGPU();
-        ID3D11Buffer* buf = ((DX11Buffer*)constBuffers->z(i))->zBuffer();
-        deviceLock.lock();
-        context->PSSetConstantBuffers(i, 1, &buf);
-        deviceLock.unlock();
-    }
-    if (pixelShader)
-    {
-        deviceLock.lock();
-        context->PSSetShader(pixelShader, 0, 0);
-        deviceLock.unlock();
-    }
-}
-
-// Contents of the VertexShader class
-
-// Constructor
-DX11VertexShader::DX11VertexShader(
-    ID3D11Device* device, ID3D11DeviceContext* context, Critical& deviceLock)
-    : DX11Shader(device, context, deviceLock)
-{
-    vertexShader = 0;
-    inputLayout = 0;
-    shaderByteBuffer = 0;
-    byteBufferSize = 0;
-}
-
-// Destructor
-DX11VertexShader::~DX11VertexShader()
-{
-    if (vertexShader) vertexShader->Release();
-    if (inputLayout) inputLayout->Release();
-}
-
-// Sets the compiled shader
-//  bytes: The bytes of the compiled code
-//  length: the length of the byte array
-//  return: true if bytes is valid, false otherwise
-bool DX11VertexShader::setCompiledByteArray(unsigned char* bytes, int length)
-{
-    shaderByteBuffer = (unsigned char*)bytes;
-    byteBufferSize = length;
-    deviceLock.lock();
-    HRESULT result
-        = device->CreateVertexShader(bytes, length, 0, &vertexShader);
-    deviceLock.unlock();
-    return result == S_OK;
-}
-
-// Creates an InputLayout for the shader
-// Must only be called after compile
-//  zD3d11Device: The device used to create the layout
-//  descArray: An array with initialization data
-//  anz: The number of elements in the array
-bool DX11VertexShader::createInputLayout(
-    D3D11_INPUT_ELEMENT_DESC* descArray, int anz)
-{
-    if (!shaderByteBuffer) return 0;
-    if (inputLayout) inputLayout->Release();
-    inputLayout = 0;
-    deviceLock.lock();
-    HRESULT res = device->CreateInputLayout(
-        descArray, anz, shaderByteBuffer, byteBufferSize, &inputLayout);
-    deviceLock.unlock();
-    if (res == S_OK)
-    {
-        shaderByteBuffer = 0;
-        byteBufferSize = 0;
-    }
-    return res == S_OK;
-}
-
-// After calling this function, this shader is used as vertex shader
-//  zD3d11Context: The context object used with the shader
-void DX11VertexShader::useShader()
-{
-    int maxI = constBuffers->getLastIndex();
-    for (int i = 0; i <= maxI; i++)
-    {
-        if (!constBuffers->z(i)) continue;
-        if (!((DX11Buffer*)constBuffers->z(i))->zBuffer())
-            constBuffers->z(i)->copyToGPU();
-        ID3D11Buffer* buf = ((DX11Buffer*)constBuffers->z(i))->zBuffer();
-        deviceLock.lock();
-        context->VSSetConstantBuffers(i, 1, &buf);
-        deviceLock.unlock();
-    }
-    if (inputLayout)
-    {
-        deviceLock.lock();
-        context->IASetInputLayout(inputLayout);
-        deviceLock.unlock();
-    }
-    if (vertexShader)
-    {
-        deviceLock.lock();
-        context->VSSetShader(vertexShader, 0, 0);
-        deviceLock.unlock();
-    }
 }

+ 0 - 96
Shader.h

@@ -3,21 +3,9 @@
 #include "Array.h"
 #include "Critical.h"
 
-struct ID3D10Blob;
-struct ID3D11PixelShader;
-struct ID3D11VertexShader;
-struct ID3D11Device;
-struct ID3D11DeviceContext;
-struct D3D11_INPUT_ELEMENT_DESC;
-struct ID3D11Buffer;
-struct ID3D11InputLayout;
-
 namespace Framework
 {
-    class Text;
     class DXBuffer;
-    class DX12CopyCommandQueue;
-    class DX12DirectCommandQueue;
 
     enum ShaderType
     {
@@ -75,88 +63,4 @@ namespace Framework
         //! Returns the index of the first uninitialized buffer
         DLLEXPORT int getFirstUninitializedBufferIndex() const;
     };
-
-    class DX11Shader : public Shader
-    {
-    protected:
-        ID3D11Device* device;
-        ID3D11DeviceContext* context;
-        Critical& deviceLock;
-
-    public:
-        DLLEXPORT DX11Shader(ID3D11Device* device,
-            ID3D11DeviceContext* context,
-            Critical& deviceLock);
-        DLLEXPORT virtual ~DX11Shader();
-        //! Creates a constant buffer that passes constant data to the shader.
-        //! A maximum of 14 buffers can be created.
-        //!  zD3d11Device: The device with which the buffer should be created
-        //! \param size The size of the buffer in bytes
-        //! \param index The position of the buffer in the buffer array. An
-        //! existing buffer will be replaced. Buffer 1 cannot be created
-        //! if buffer 0 has not been created yet, etc.
-        DLLEXPORT virtual bool createConstBuffer(int size, int index) override;
-    };
-
-    //! Manages a pixel shader
-    class DX11PixelShader : public DX11Shader
-    {
-    private:
-        ID3D11PixelShader* pixelShader;
-
-    public:
-        //! Constructor
-        DLLEXPORT DX11PixelShader(ID3D11Device* device,
-            ID3D11DeviceContext* context,
-            Critical& deviceLock);
-        //! Destructor
-        DLLEXPORT ~DX11PixelShader();
-        //! Sets the compiled shader
-        //!  zD3d11Device: The device with which the shader should be created
-        //! \param bytes The bytes of the compiled code
-        //! \param length The length of the byte array
-        //! \return true if bytes is valid, false otherwise
-        DLLEXPORT bool setCompiledByteArray(
-            unsigned char* bytes, int length) override;
-        //! After calling this function, this shader is used as a pixel shader
-        //!  zD3d11Context: The context object with which the shader should
-        //!  be used
-        DLLEXPORT void useShader() override;
-    };
-
-    //! Manages a vertex shader
-    class DX11VertexShader : public DX11Shader
-    {
-    private:
-        ID3D11VertexShader* vertexShader;
-        ID3D11InputLayout* inputLayout;
-        unsigned char* shaderByteBuffer;
-        int byteBufferSize;
-
-    public:
-        //! Constructor
-        DLLEXPORT DX11VertexShader(ID3D11Device* device,
-            ID3D11DeviceContext* context,
-            Critical& deviceLock);
-        //! Destructor
-        DLLEXPORT ~DX11VertexShader();
-        //! Sets the compiled shader
-        //!  zD3d11Device: The device with which the shader should be created
-        //! \param bytes The bytes of the compiled code
-        //! \param length The length of the byte array
-        //! \return true if bytes is valid, false otherwise
-        DLLEXPORT bool setCompiledByteArray(
-            unsigned char* bytes, int length) override;
-        //! Creates an input layout for the shader.
-        //! May only be called after compile.
-        //!  zD3d11Device: The device with which the layout should be created
-        //! \param descArray An array with initialization data
-        //! \param anz The number of elements in the array
-        DLLEXPORT bool createInputLayout(
-            D3D11_INPUT_ELEMENT_DESC* descArray, int anz);
-        //! After calling this function, this shader is used as a vertex shader
-        //!  zD3d11Context: The context object with which the shader should
-        //!  be used
-        DLLEXPORT void useShader() override;
-    };
 } // namespace Framework