D2d offscreen rendering finish up.
This commit is contained in:
parent
8c814ce89f
commit
c63138c455
32 changed files with 288 additions and 64 deletions
|
@ -15,31 +15,43 @@ void DirectX2dPainter::finishDrawing()
|
|||
mD2dInterface->getRenderTarget()->EndDraw();
|
||||
}
|
||||
|
||||
void DirectX2dPainter::clearBackground()
|
||||
D2D1::ColorF DirectX2dPainter::toD2dColor(const Color& color)
|
||||
{
|
||||
mD2dInterface->getRenderTarget()->Clear(D2D1::ColorF(D2D1::ColorF::White));
|
||||
return D2D1::ColorF(color.getR() / 255.0, color.getG() / 255.0, color.getB() / 255.0, static_cast<float>(color.getAlpha()));
|
||||
}
|
||||
|
||||
void DirectX2dPainter::clearBackground(const Color& color)
|
||||
{
|
||||
mD2dInterface->getRenderTarget()->Clear(toD2dColor(color));
|
||||
}
|
||||
|
||||
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();
|
||||
const auto loc = model->getTransform().getLocation();
|
||||
const auto scale_x = model->getTransform().getScaleX();
|
||||
const auto scale_y = model->getTransform().getScaleY();
|
||||
D2D1_RECT_F d2d_rect{ static_cast<float>(loc.getX()), static_cast<float>(loc.getY() + scale_x), static_cast<float>(loc.getX() + scale_y), static_cast<float>(loc.getY()) };
|
||||
|
||||
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()) };
|
||||
if (model->hasFillColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getFillColor()));
|
||||
rt->FillRectangle(d2d_rect, mSolidBrush.Get());
|
||||
}
|
||||
|
||||
rt->FillRectangle(d2d_rect, mWorkingBrush.Get());
|
||||
if (model->hasOutlineColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getOutlineColor()));
|
||||
rt->DrawRectangle(d2d_rect, mSolidBrush.Get(), 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DirectX2dPainter::setD2dInterface(DirectX2dInterface* d2dIterface)
|
||||
{
|
||||
mD2dInterface = d2dIterface;
|
||||
auto hr = mD2dInterface->getRenderTarget()->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black, 1.0f), &mSolidBrush);
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include <wrl.h>
|
||||
|
||||
class SceneModel;
|
||||
|
@ -7,12 +9,17 @@ class DirectX2dInterface;
|
|||
|
||||
struct ID2D1SolidColorBrush;
|
||||
|
||||
namespace D2D1
|
||||
{
|
||||
class ColorF;
|
||||
}
|
||||
|
||||
class DirectX2dPainter
|
||||
{
|
||||
public:
|
||||
void startDrawing();
|
||||
|
||||
void clearBackground();
|
||||
void clearBackground(const Color& color);
|
||||
|
||||
void finishDrawing();
|
||||
|
||||
|
@ -21,9 +28,9 @@ public:
|
|||
void setD2dInterface(DirectX2dInterface* d2dIterface);
|
||||
|
||||
private:
|
||||
void createRectangle();
|
||||
static D2D1::ColorF toD2dColor(const Color& color);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mWorkingBrush;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> mSolidBrush;
|
||||
|
||||
DirectX2dInterface* mD2dInterface{ nullptr };
|
||||
};
|
|
@ -24,7 +24,7 @@ void DirectXMesh::update(DrawingContext* context, ID3D12Device* device)
|
|||
const auto width = float(context->getSurface()->getWidth());
|
||||
const auto height = float(context->getSurface()->getHeight());
|
||||
|
||||
auto model_color = mModel->getColor().getAsVectorDouble();
|
||||
auto model_color = mModel->getFillColor().getAsVectorDouble();
|
||||
std::vector<float> color = { float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3]) };
|
||||
|
||||
auto transform = mModel->getTransform();
|
||||
|
|
|
@ -111,7 +111,7 @@ void DirectXPainter::paint()
|
|||
auto scene = mDrawingContext->getSurface()->getScene();
|
||||
|
||||
m2dPainter->startDrawing();
|
||||
m2dPainter->clearBackground();
|
||||
m2dPainter->clearBackground(scene->getBackgroundColor());
|
||||
|
||||
for (const auto item : scene->getItems())
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue