Hook up d2d offscreen rendering.

This commit is contained in:
jmsgrogan 2023-01-11 17:16:55 +00:00
parent 0c84a53643
commit 53a9f7bd15
9 changed files with 130 additions and 58 deletions

View file

@ -6,7 +6,7 @@
RasterPainter::RasterPainter(DrawingContext* context)
: AbstractPainter(context),
mGrid(std::make_unique<Grid<unsigned char> >(Rectangle(Point(0, 0), Point(100, 100))))
mGrid(std::make_unique<Grid<unsigned char> >(ntk::Rectangle(Point(0, 0), Point(100, 100))))
{
}
@ -15,7 +15,7 @@ void RasterPainter::paint()
{
const auto width = mDrawingContext->getSurface()->getWidth();
const auto height = mDrawingContext->getSurface()->getHeight();
mGrid->resetBounds(Rectangle(Point(0, 0), Point(width, height)));
mGrid->resetBounds(ntk::Rectangle(Point(0, 0), Point(width, height)));
/*
for (unsigned idx=0; idx< context->getNumItems(); idx++)

View file

@ -1,10 +1,42 @@
#include "DirectX2dPainter.h"
#include "DirectX2dInterface.h"
#include "AbstractGeometricItem.h"
#include "Rectangle.h"
#include "SceneModel.h"
void DirectX2dPainter::paint(AbstractGeometricItem* item)
void DirectX2dPainter::startDrawing()
{
mD2dInterface->getRenderTarget()->BeginDraw();
}
void DirectX2dPainter::finishDrawing()
{
mD2dInterface->getRenderTarget()->EndDraw();
}
void DirectX2dPainter::clearBackground()
{
mD2dInterface->getRenderTarget()->Clear(D2D1::ColorF(D2D1::ColorF::White));
}
void DirectX2dPainter::paint(SceneModel* model)
{
auto rt = mD2dInterface->getRenderTarget();
auto hr = rt->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mWorkingBrush);
if (model->getGeometry()->getType() == AbstractGeometricItem::Type::RECTANGLE)
{
auto rect = dynamic_cast<ntk::Rectangle*>(model->getGeometry());
const auto loc = rect->getLocation();
const auto width = rect->getWidth();
const auto height = rect->getHeight();
D2D1_RECT_F d2d_rect{ static_cast<float>(loc.getX()), static_cast<float>(loc.getY() + height), static_cast<float>(loc.getX() + width), static_cast<float>(loc.getY()) };
rt->FillRectangle(d2d_rect, mWorkingBrush.Get());
}
}
void DirectX2dPainter::setD2dInterface(DirectX2dInterface* d2dIterface)

View file

@ -1,15 +1,29 @@
#pragma once
class AbstractGeometricItem;
#include <wrl.h>
class SceneModel;
class DirectX2dInterface;
struct ID2D1SolidColorBrush;
class DirectX2dPainter
{
public:
void paint(AbstractGeometricItem* item);
void startDrawing();
void clearBackground();
void finishDrawing();
void paint(SceneModel* model);
void setD2dInterface(DirectX2dInterface* d2dIterface);
private:
void createRectangle();
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mWorkingBrush;
DirectX2dInterface* mD2dInterface{ nullptr };
};

View file

@ -109,6 +109,10 @@ void DirectXPainter::paint()
}
auto scene = mDrawingContext->getSurface()->getScene();
m2dPainter->startDrawing();
m2dPainter->clearBackground();
for (const auto item : scene->getItems())
{
if (item->getType() == SceneItem::Type::MODEL && item->isVisible())
@ -116,10 +120,12 @@ void DirectXPainter::paint()
auto model = dynamic_cast<SceneModel*>(item);
if (model->getGeometry())
{
m2dPainter->paint(model->getGeometry());
m2dPainter->paint(model);
}
}
}
m2dPainter->finishDrawing();
}
void DirectXPainter::paintBackground(const D3D12_CPU_DESCRIPTOR_HANDLE& rtvHandle, ID3D12GraphicsCommandList* commandList)