Split d2d integration into own class.
This commit is contained in:
parent
0d3674faac
commit
0c84a53643
25 changed files with 361 additions and 155 deletions
|
@ -48,6 +48,7 @@ if(UNIX)
|
|||
else()
|
||||
list(APPEND graphics_LIB_INCLUDES
|
||||
directx/DirectXInterface.cpp
|
||||
directx/DirectX2dInterface.cpp
|
||||
directx/DirectXMesh.cpp
|
||||
directx/DirectXPainter.cpp
|
||||
directx/DirectX2dPainter.cpp
|
||||
|
@ -56,7 +57,8 @@ else()
|
|||
directx/DirectXShaderProgram.cpp
|
||||
)
|
||||
list(APPEND graphics_HEADERS
|
||||
directx/DirectXInterface.h
|
||||
directx/DirectXInterface.h
|
||||
directx/DirectX2dInterface.h
|
||||
directx/DirectXMesh.h
|
||||
directx/DirectXPainter.h
|
||||
directx/DirectX2dPainter.h
|
||||
|
|
67
src/graphics/directx/DirectX2dInterface.cpp
Normal file
67
src/graphics/directx/DirectX2dInterface.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "DirectX2dInterface.h"
|
||||
|
||||
#include "DirectXInterface.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <dxgi.h>
|
||||
#include <d2d1_3.h>
|
||||
#include <d2d1_1.h>
|
||||
#include <dwrite.h>
|
||||
|
||||
DirectX2dInterface::DirectX2dInterface(DirectXInterface* dxInterface)
|
||||
: mDxInterface(dxInterface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DirectX2dInterface::isValid() const
|
||||
{
|
||||
return mIsValid;
|
||||
}
|
||||
|
||||
ID2D1Factory3* DirectX2dInterface::getFactory() const
|
||||
{
|
||||
return mFactory.Get();
|
||||
}
|
||||
|
||||
IDWriteFactory* DirectX2dInterface::getDirectWriteFactory() const
|
||||
{
|
||||
return mDWriteFactory.Get();
|
||||
}
|
||||
|
||||
ID2D1DeviceContext2* DirectX2dInterface::getContext() const
|
||||
{
|
||||
return mDeviceContext.Get();
|
||||
}
|
||||
|
||||
void DirectX2dInterface::initializeStandalone(IWICBitmap* bitmap, bool useSoftware)
|
||||
{
|
||||
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
|
||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mFactory);
|
||||
|
||||
auto hr = mFactory->CreateWicBitmapRenderTarget(bitmap, D2D1::RenderTargetProperties(), &mRenderTarget);
|
||||
}
|
||||
|
||||
ID2D1RenderTarget* DirectX2dInterface::getRenderTarget() const
|
||||
{
|
||||
return mRenderTarget.Get();
|
||||
}
|
||||
|
||||
bool DirectX2dInterface::initialize(IDXGIDevice* device)
|
||||
{
|
||||
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
|
||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mFactory);
|
||||
|
||||
mFactory->CreateDevice(device, &mDevice);
|
||||
|
||||
D2D1_DEVICE_CONTEXT_OPTIONS deviceOptions = D2D1_DEVICE_CONTEXT_OPTIONS_NONE;
|
||||
mDevice->CreateDeviceContext(deviceOptions, &mDeviceContext);
|
||||
|
||||
return initializeDirectWrite();
|
||||
}
|
||||
|
||||
bool DirectX2dInterface::initializeDirectWrite()
|
||||
{
|
||||
return SUCCEEDED(::DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &mDWriteFactory));
|
||||
}
|
44
src/graphics/directx/DirectX2dInterface.h
Normal file
44
src/graphics/directx/DirectX2dInterface.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include <wrl.h>
|
||||
#include <dwrite.h>
|
||||
#include <d2d1_3.h>
|
||||
|
||||
class DirectXInterface;
|
||||
|
||||
struct IDWriteFactory;
|
||||
struct ID2D1Factory3;
|
||||
struct ID2D1Device2;
|
||||
struct ID2D1DeviceContext2;
|
||||
struct ID2D1RenderTarget;
|
||||
struct IWICBitmap;
|
||||
struct IDXGIDevice;
|
||||
|
||||
class DirectX2dInterface
|
||||
{
|
||||
public:
|
||||
DirectX2dInterface(DirectXInterface* dxInterface);
|
||||
|
||||
ID2D1Factory3* getFactory() const;
|
||||
ID2D1DeviceContext2* getContext() const;
|
||||
IDWriteFactory* getDirectWriteFactory() const;
|
||||
ID2D1RenderTarget* getRenderTarget() const;
|
||||
|
||||
bool initialize(IDXGIDevice* device);
|
||||
void initializeStandalone(IWICBitmap* bitmap, bool useSoftware = true);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
bool initializeDirectWrite();
|
||||
|
||||
bool mIsValid{ false };
|
||||
|
||||
DirectXInterface* mDxInterface{ nullptr };
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1Factory3> mFactory;
|
||||
Microsoft::WRL::ComPtr<ID2D1Device2> mDevice;
|
||||
Microsoft::WRL::ComPtr<ID2D1DeviceContext2> mDeviceContext;
|
||||
Microsoft::WRL::ComPtr<IDWriteFactory> mDWriteFactory;
|
||||
Microsoft::WRL::ComPtr<ID2D1RenderTarget> mRenderTarget;
|
||||
};
|
|
@ -1,6 +1,13 @@
|
|||
#include "DirectX2dPainter.h"
|
||||
|
||||
void DirectX2dPainter::paint(ID2D1DeviceContext2* context, AbstractGeometricItem* item)
|
||||
#include "DirectX2dInterface.h"
|
||||
|
||||
void DirectX2dPainter::paint(AbstractGeometricItem* item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DirectX2dPainter::setD2dInterface(DirectX2dInterface* d2dIterface)
|
||||
{
|
||||
mD2dInterface = d2dIterface;
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
class AbstractGeometricItem;
|
||||
|
||||
struct ID2D1DeviceContext2;
|
||||
class DirectX2dInterface;
|
||||
|
||||
class DirectX2dPainter
|
||||
{
|
||||
public:
|
||||
void paint(ID2D1DeviceContext2* context, AbstractGeometricItem* item);
|
||||
void paint(AbstractGeometricItem* item);
|
||||
|
||||
void setD2dInterface(DirectX2dInterface* d2dIterface);
|
||||
|
||||
private:
|
||||
DirectX2dInterface* mD2dInterface{ nullptr };
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
#include "DirectXInterface.h"
|
||||
|
||||
#include "DirectX2dInterface.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <dxgi.h>
|
||||
|
@ -9,10 +10,11 @@
|
|||
#include <d3d12.h>
|
||||
#include <d3d12sdklayers.h>
|
||||
|
||||
#include <d2d1_3.h>
|
||||
#include <d2d1_1.h>
|
||||
DirectXInterface::DirectXInterface()
|
||||
: mD2dInterface(std::make_unique<DirectX2dInterface>(this))
|
||||
{
|
||||
|
||||
#include <dwrite.h>
|
||||
}
|
||||
|
||||
void DirectXInterface::getHardwareAdapter(IDXGIAdapter1** ppAdapter)
|
||||
{
|
||||
|
@ -53,21 +55,6 @@ IDXGIFactory7* DirectXInterface::getDxgiFactory() const
|
|||
return mDxgiFactory.Get();
|
||||
}
|
||||
|
||||
ID2D1Factory3* DirectXInterface::getD2dFactory() const
|
||||
{
|
||||
return mD2dFactory.Get();
|
||||
}
|
||||
|
||||
IDWriteFactory* DirectXInterface::getDirectWriteFactory() const
|
||||
{
|
||||
return mDWriteFactory.Get();
|
||||
}
|
||||
|
||||
ID2D1DeviceContext2* DirectXInterface::getD2dContext() const
|
||||
{
|
||||
return mD2dDeviceContext.Get();
|
||||
}
|
||||
|
||||
ID3D12CommandQueue* DirectXInterface::getCommandQueue() const
|
||||
{
|
||||
return mCommandQueue.Get();
|
||||
|
@ -78,6 +65,11 @@ ID3D11DeviceContext* DirectXInterface::getD3d11DeviceContext() const
|
|||
return mD3d11DeviceContext.Get();
|
||||
}
|
||||
|
||||
DirectX2dInterface* DirectXInterface::getD2dInterface() const
|
||||
{
|
||||
return mD2dInterface.get();
|
||||
}
|
||||
|
||||
void DirectXInterface::initialize()
|
||||
{
|
||||
MLOG_INFO("Initialize DirectX");
|
||||
|
@ -89,15 +81,15 @@ void DirectXInterface::initialize()
|
|||
|
||||
createCommandQueue();
|
||||
|
||||
mIsValid = initializeD2d();
|
||||
}
|
||||
|
||||
void DirectXInterface::initializeD2dStandalone()
|
||||
{
|
||||
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
|
||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mD2dFactory);
|
||||
|
||||
if (!initializeD11on12())
|
||||
{
|
||||
mIsValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice> dxgiDevice;
|
||||
mD3d11On12Device.As(&dxgiDevice);
|
||||
mIsValid = mD2dInterface->initialize(dxgiDevice.Get());
|
||||
}
|
||||
|
||||
bool DirectXInterface::createD3dFactory()
|
||||
|
@ -161,26 +153,6 @@ bool DirectXInterface::createCommandQueue()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DirectXInterface::initializeD2d()
|
||||
{
|
||||
if (!initializeD11on12())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
D2D1_FACTORY_OPTIONS d2dFactoryOptions = {};
|
||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &d2dFactoryOptions, &mD2dFactory);
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice> dxgiDevice;
|
||||
mD3d11On12Device.As(&dxgiDevice);
|
||||
|
||||
mD2dFactory->CreateDevice(dxgiDevice.Get(), &mD2dDevice);
|
||||
|
||||
D2D1_DEVICE_CONTEXT_OPTIONS deviceOptions = D2D1_DEVICE_CONTEXT_OPTIONS_NONE;
|
||||
mD2dDevice->CreateDeviceContext(deviceOptions, &mD2dDeviceContext);
|
||||
|
||||
return initializeDirectWrite();
|
||||
}
|
||||
|
||||
bool DirectXInterface::initializeD11on12()
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> d3d11Device;
|
||||
|
@ -193,9 +165,4 @@ bool DirectXInterface::initializeD11on12()
|
|||
}
|
||||
d3d11Device.As(&mD3d11On12Device);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DirectXInterface::initializeDirectWrite()
|
||||
{
|
||||
return SUCCEEDED(::DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &mDWriteFactory));
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <wrl.h>
|
||||
#include <dwrite.h>
|
||||
#include <d2d1_3.h>
|
||||
#include <d3d11on12.h>
|
||||
#include <dxgi1_6.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DirectX2dInterface;
|
||||
|
||||
struct ID3D12Device;
|
||||
struct IDXGIFactory7;
|
||||
struct IDXGIAdapter1;
|
||||
|
@ -14,27 +16,21 @@ struct ID3D12CommandQueue;
|
|||
struct ID3D11DeviceContext;
|
||||
struct ID3D11On12Device;
|
||||
|
||||
struct IDWriteFactory;
|
||||
struct ID2D1Factory3;
|
||||
struct ID2D1Device2;
|
||||
struct ID2D1DeviceContext2;
|
||||
|
||||
class DirectXInterface
|
||||
{
|
||||
public:
|
||||
DirectXInterface();
|
||||
|
||||
IDXGIFactory7* getDxgiFactory() const;
|
||||
ID3D12Device* getD3dDevice() const;
|
||||
ID3D12CommandQueue* getCommandQueue() const;
|
||||
|
||||
ID3D11On12Device* get11On12Device() const;
|
||||
ID3D11DeviceContext* getD3d11DeviceContext() const;
|
||||
ID2D1Factory3* getD2dFactory() const;
|
||||
ID2D1DeviceContext2* getD2dContext() const;
|
||||
IDWriteFactory* getDirectWriteFactory() const;
|
||||
|
||||
DirectX2dInterface* getD2dInterface() const;
|
||||
|
||||
void initialize();
|
||||
void initializeD2dStandalone();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
|
@ -44,9 +40,7 @@ private:
|
|||
|
||||
void getHardwareAdapter(IDXGIAdapter1** ppAdapter);
|
||||
|
||||
bool initializeD2d();
|
||||
bool initializeD11on12();
|
||||
bool initializeDirectWrite();
|
||||
|
||||
bool mIsValid{ false };
|
||||
|
||||
|
@ -54,11 +48,8 @@ private:
|
|||
Microsoft::WRL::ComPtr<ID3D12Device> mD3dDevice;
|
||||
Microsoft::WRL::ComPtr<ID3D12CommandQueue> mCommandQueue;
|
||||
|
||||
// 2D Rendering - e.g. text
|
||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext> mD3d11DeviceContext;
|
||||
Microsoft::WRL::ComPtr<ID3D11On12Device> mD3d11On12Device;
|
||||
Microsoft::WRL::ComPtr<ID2D1Factory3> mD2dFactory;
|
||||
Microsoft::WRL::ComPtr<ID2D1Device2> mD2dDevice;
|
||||
Microsoft::WRL::ComPtr<ID2D1DeviceContext2> mD2dDeviceContext;
|
||||
Microsoft::WRL::ComPtr<IDWriteFactory> mDWriteFactory;
|
||||
|
||||
std::unique_ptr<DirectX2dInterface> mD2dInterface;
|
||||
};
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "DirectXShaderProgram.h"
|
||||
#include "DirectXMesh.h"
|
||||
#include "DirectXInterface.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
|
@ -23,18 +24,23 @@ DirectXMeshPainter::DirectXMeshPainter()
|
|||
mShaderProgram = std::make_unique<DirectXShaderProgram>(shader_path, shader_path);
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::setDxInterface(DirectXInterface* dxInterface)
|
||||
{
|
||||
mDxInterface = dxInterface;
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::initializeShader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::initializeD3d(ID3D12Device* device)
|
||||
void DirectXMeshPainter::initializeD3d()
|
||||
{
|
||||
createRootSignature(device);
|
||||
createPipelineStateObject(device);
|
||||
createRootSignature();
|
||||
createPipelineStateObject();
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::createRootSignature(ID3D12Device* device)
|
||||
void DirectXMeshPainter::createRootSignature()
|
||||
{
|
||||
CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
|
||||
rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
|
||||
|
@ -42,10 +48,10 @@ void DirectXMeshPainter::createRootSignature(ID3D12Device* device)
|
|||
Microsoft::WRL::ComPtr<ID3DBlob> signature;
|
||||
Microsoft::WRL::ComPtr<ID3DBlob> error;
|
||||
D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error);
|
||||
device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&mRootSignature));
|
||||
mDxInterface->getD3dDevice()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&mRootSignature));
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::createPipelineStateObject(ID3D12Device* device)
|
||||
void DirectXMeshPainter::createPipelineStateObject()
|
||||
{
|
||||
auto vert_shader = mShaderProgram->getVertexShader();
|
||||
auto pixel_shader = mShaderProgram->getPixelShader();
|
||||
|
@ -70,7 +76,7 @@ void DirectXMeshPainter::createPipelineStateObject(ID3D12Device* device)
|
|||
psoDesc.NumRenderTargets = 1;
|
||||
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
psoDesc.SampleDesc.Count = 1;
|
||||
device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&mPipelineState));
|
||||
mDxInterface->getD3dDevice()->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&mPipelineState));
|
||||
}
|
||||
|
||||
ID3D12PipelineState* DirectXMeshPainter::getPipelineState() const
|
||||
|
@ -96,7 +102,7 @@ void DirectXMeshPainter::updateCommandList(ID3D12GraphicsCommandList* commandLis
|
|||
}
|
||||
}
|
||||
|
||||
void DirectXMeshPainter::updateBuffers(DrawingContext* context, ID3D12Device* device)
|
||||
void DirectXMeshPainter::updateBuffers(DrawingContext* context)
|
||||
{
|
||||
mDxMeshes.clear();
|
||||
auto scene = context->getSurface()->getScene();
|
||||
|
@ -106,7 +112,7 @@ void DirectXMeshPainter::updateBuffers(DrawingContext* context, ID3D12Device* de
|
|||
{
|
||||
auto model = dynamic_cast<SceneModel*>(item);
|
||||
auto dx_mesh = std::make_unique<DirectXMesh>(model);
|
||||
dx_mesh->update(context, device);
|
||||
dx_mesh->update(context, mDxInterface->getD3dDevice());
|
||||
mDxMeshes.push_back(std::move(dx_mesh));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
class DrawingContext;
|
||||
class DirectXShaderProgram;
|
||||
class DirectXMesh;
|
||||
class DirectXInterface;
|
||||
|
||||
class DirectXMeshPainter
|
||||
{
|
||||
|
@ -18,14 +19,18 @@ public:
|
|||
ID3D12PipelineState* getPipelineState() const;
|
||||
ID3D12RootSignature* getRootSignature() const;
|
||||
|
||||
void initializeD3d(ID3D12Device* device);
|
||||
void initializeD3d();
|
||||
|
||||
void updateBuffers(DrawingContext* context, ID3D12Device* device);
|
||||
void setDxInterface(DirectXInterface* dxInterface);
|
||||
|
||||
void updateBuffers(DrawingContext* context);
|
||||
void updateCommandList(ID3D12GraphicsCommandList* commandList);
|
||||
private:
|
||||
void initializeShader();
|
||||
void createRootSignature(ID3D12Device* device);
|
||||
void createPipelineStateObject(ID3D12Device* device);
|
||||
void createRootSignature();
|
||||
void createPipelineStateObject();
|
||||
|
||||
DirectXInterface* mDxInterface{ nullptr };
|
||||
|
||||
std::vector<std::unique_ptr<DirectXMesh> > mDxMeshes;
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#include "DirectX2dPainter.h"
|
||||
#include "DirectXMesh.h"
|
||||
#include "DirectXInterface.h"
|
||||
#include "DirectX2dInterface.h"
|
||||
|
||||
#include <wincodec.h>
|
||||
#include "Win32WicImage.h"
|
||||
|
||||
#include "File.h"
|
||||
|
||||
|
@ -45,27 +49,63 @@ DirectXTextPainter* DirectXPainter::getTextPainter() const
|
|||
return mTextPainter.get();
|
||||
}
|
||||
|
||||
void DirectXPainter::initializeMesh(ID3D12Device* device)
|
||||
void DirectXPainter::setDxInterface(DirectXInterface* dxInterface)
|
||||
{
|
||||
mMeshPainter->initializeD3d(device);
|
||||
mRawDxInterface = dxInterface;
|
||||
resetPainters();
|
||||
}
|
||||
|
||||
void DirectXPainter::initializeText(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
||||
DirectXInterface* DirectXPainter::getDxInterface() const
|
||||
{
|
||||
mTextPainter->initialize(d2dContext, directWriteFactory);
|
||||
if (mDxInterface)
|
||||
{
|
||||
return mDxInterface.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mRawDxInterface;
|
||||
}
|
||||
}
|
||||
|
||||
void DirectXPainter::updateMesh(ID3D12Device* device)
|
||||
void DirectXPainter::initializeMesh()
|
||||
{
|
||||
mMeshPainter->updateBuffers(mDrawingContext, device);
|
||||
mMeshPainter->initializeD3d();
|
||||
}
|
||||
|
||||
void DirectXPainter::initializeText()
|
||||
{
|
||||
mTextPainter->initialize();
|
||||
}
|
||||
|
||||
void DirectXPainter::updateMesh()
|
||||
{
|
||||
mMeshPainter->updateBuffers(mDrawingContext);
|
||||
}
|
||||
|
||||
void DirectXPainter::initializeDxInterface()
|
||||
{
|
||||
mDxInterface = std::make_unique<DirectXInterface>();
|
||||
|
||||
auto backing_image = mDrawingContext->getSurface()->getImage();
|
||||
auto wic_bitmap = dynamic_cast<Win32WicImage*>(backing_image->getPlatformImage())->getBitmap();
|
||||
|
||||
mDxInterface->getD2dInterface()->initializeStandalone(wic_bitmap);
|
||||
|
||||
resetPainters();
|
||||
}
|
||||
|
||||
void DirectXPainter::resetPainters()
|
||||
{
|
||||
m2dPainter->setD2dInterface(mDxInterface->getD2dInterface());
|
||||
mTextPainter->setD2dInterface(mDxInterface->getD2dInterface());
|
||||
mMeshPainter->setDxInterface(getDxInterface());
|
||||
}
|
||||
|
||||
void DirectXPainter::paint()
|
||||
{
|
||||
if (!mDxInterface)
|
||||
{
|
||||
mDxInterface = std::make_unique<DirectXInterface>();
|
||||
mDxInterface->initializeD2dStandalone();
|
||||
initializeDxInterface();
|
||||
}
|
||||
|
||||
auto scene = mDrawingContext->getSurface()->getScene();
|
||||
|
@ -76,7 +116,7 @@ void DirectXPainter::paint()
|
|||
auto model = dynamic_cast<SceneModel*>(item);
|
||||
if (model->getGeometry())
|
||||
{
|
||||
m2dPainter->paint(mDxInterface->getD2dContext(), model->getGeometry());
|
||||
m2dPainter->paint(model->getGeometry());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +133,7 @@ void DirectXPainter::paintMesh(ID3D12GraphicsCommandList* commandList)
|
|||
mMeshPainter->updateCommandList(commandList);
|
||||
}
|
||||
|
||||
void DirectXPainter::paintText(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
||||
void DirectXPainter::paintText()
|
||||
{
|
||||
auto scene = mDrawingContext->getSurface()->getScene();
|
||||
for (const auto item : scene->getItems())
|
||||
|
@ -101,7 +141,7 @@ void DirectXPainter::paintText(ID2D1DeviceContext2* d2dContext, IDWriteFactory*
|
|||
if (item->getType() == SceneItem::Type::TEXT && item->isVisible())
|
||||
{
|
||||
auto text = dynamic_cast<SceneText*>(item);
|
||||
mTextPainter->paint(text, mDrawingContext, d2dContext, directWriteFactory);
|
||||
mTextPainter->paint(text, mDrawingContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,29 +19,36 @@ class DirectXPainter : public AbstractPainter
|
|||
{
|
||||
public:
|
||||
DirectXPainter(DrawingContext* context);
|
||||
void paint() override;
|
||||
|
||||
|
||||
DirectXMeshPainter* getMeshPainter() const;
|
||||
DirectXTextPainter* getTextPainter() const;
|
||||
|
||||
void initializeMesh(ID3D12Device* device);
|
||||
void initializeMesh();
|
||||
void initializeText();
|
||||
|
||||
void initializeText(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory);
|
||||
void paint() override;
|
||||
|
||||
void paintBackground(const D3D12_CPU_DESCRIPTOR_HANDLE& rtvHandle, ID3D12GraphicsCommandList* commandList);
|
||||
|
||||
void paintMesh(ID3D12GraphicsCommandList* commandList);
|
||||
void paintText();
|
||||
|
||||
void paintText(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory);
|
||||
void setDxInterface(DirectXInterface* dxInterface);
|
||||
|
||||
bool supportsGeometryPrimitives() const override;
|
||||
|
||||
void updateMesh(ID3D12Device* device);
|
||||
void updateMesh();
|
||||
|
||||
private:
|
||||
DirectXInterface* getDxInterface() const;
|
||||
|
||||
void initializeDxInterface();
|
||||
void resetPainters();
|
||||
|
||||
std::unique_ptr<DirectXMeshPainter> mMeshPainter;
|
||||
std::unique_ptr<DirectXTextPainter> mTextPainter;
|
||||
std::unique_ptr<DirectX2dPainter> m2dPainter;
|
||||
|
||||
DirectXInterface* mRawDxInterface{ nullptr };
|
||||
std::unique_ptr<DirectXInterface> mDxInterface;
|
||||
};
|
|
@ -7,9 +7,10 @@
|
|||
#include "FontGlyph.h"
|
||||
|
||||
#include "DirectXShaderProgram.h"
|
||||
#include "TextData.h"
|
||||
|
||||
#include "TextData.h"
|
||||
#include "SceneText.h"
|
||||
#include "DirectX2dInterface.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "File.h"
|
||||
|
@ -25,19 +26,24 @@ DirectXTextPainter::DirectXTextPainter()
|
|||
|
||||
}
|
||||
|
||||
void DirectXTextPainter::initialize(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
||||
void DirectXTextPainter::setD2dInterface(DirectX2dInterface* d2dIterface)
|
||||
{
|
||||
initializeBrush(d2dContext);
|
||||
mD2dInterface = d2dIterface;
|
||||
}
|
||||
|
||||
void DirectXTextPainter::initializeBrush(ID2D1DeviceContext2* d2dContext)
|
||||
void DirectXTextPainter::initialize()
|
||||
{
|
||||
d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
||||
initializeBrush();
|
||||
}
|
||||
|
||||
void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize)
|
||||
void DirectXTextPainter::initializeBrush()
|
||||
{
|
||||
directWriteFactory->CreateTextFormat(
|
||||
mD2dInterface->getContext()->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mTextBrush);
|
||||
}
|
||||
|
||||
void DirectXTextPainter::updateTextFormat(float fontSize)
|
||||
{
|
||||
mD2dInterface->getDirectWriteFactory()->CreateTextFormat(
|
||||
L"Verdana",
|
||||
NULL,
|
||||
DWRITE_FONT_WEIGHT_NORMAL,
|
||||
|
@ -51,19 +57,19 @@ void DirectXTextPainter::updateTextFormat(IDWriteFactory* directWriteFactory, fl
|
|||
//mTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
|
||||
}
|
||||
|
||||
void DirectXTextPainter::paint(SceneText* text, DrawingContext* context, ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory)
|
||||
void DirectXTextPainter::paint(SceneText* text, DrawingContext* context)
|
||||
{
|
||||
const auto location = text->getTransform().getLocation();
|
||||
D2D1_RECT_F textRect = D2D1::RectF(static_cast<float>(location.getX()), static_cast<float>(location.getY()), static_cast<float>(location.getX() + 200), static_cast<float>(location.getY() + 100));
|
||||
|
||||
updateTextFormat(directWriteFactory, static_cast<float>(text->getTextData().mFont.getSize()));
|
||||
updateTextFormat(static_cast<float>(text->getTextData().mFont.getSize()));
|
||||
|
||||
auto content = StringUtils::convert(text->getTextData().mContent);
|
||||
|
||||
d2dContext->BeginDraw();
|
||||
d2dContext->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
d2dContext->DrawText(content.c_str(), static_cast<UINT32>(content.size()), mTextFormat.Get(), &textRect, mTextBrush.Get());
|
||||
d2dContext->EndDraw();
|
||||
mD2dInterface->getContext()->BeginDraw();
|
||||
mD2dInterface->getContext()->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
mD2dInterface->getContext()->DrawText(content.c_str(), static_cast<UINT32>(content.size()), mTextFormat.Get(), &textRect, mTextBrush.Get());
|
||||
mD2dInterface->getContext()->EndDraw();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
class DrawingContext;
|
||||
class DirectXShaderProgram;
|
||||
class DirectX2dInterface;
|
||||
|
||||
class TextData;
|
||||
class SceneText;
|
||||
|
@ -24,14 +25,17 @@ class DirectXTextPainter
|
|||
public:
|
||||
DirectXTextPainter();
|
||||
|
||||
void initialize(ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory);
|
||||
void initialize();
|
||||
|
||||
void paint(SceneText* text, DrawingContext* context, ID2D1DeviceContext2* d2dContext, IDWriteFactory* directWriteFactory);
|
||||
void paint(SceneText* text, DrawingContext* context);
|
||||
|
||||
void setD2dInterface(DirectX2dInterface* d2dIterface);
|
||||
|
||||
private:
|
||||
void initializeBrush(ID2D1DeviceContext2* d2dContext);
|
||||
void updateTextFormat(IDWriteFactory* directWriteFactory, float fontSize);
|
||||
void initializeBrush();
|
||||
void updateTextFormat(float fontSize);
|
||||
|
||||
DirectX2dInterface* mD2dInterface{ nullptr };
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mTextBrush;
|
||||
Microsoft::WRL::ComPtr<IDWriteTextFormat> mTextFormat;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue