feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake

1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
wangzhengyang
2022-05-10 09:54:44 +08:00
parent ecdd171c6f
commit 718c41634f
10018 changed files with 3593797 additions and 186748 deletions

View File

@ -0,0 +1,76 @@
#pragma once
#include <wrl.h>
// Helper class for basic timing.
ref class BasicTimer sealed
{
public:
// Initializes internal timer values.
BasicTimer()
{
if (!QueryPerformanceFrequency(&m_frequency))
{
throw ref new Platform::FailureException();
}
Reset();
}
// Reset the timer to initial values.
void Reset()
{
Update();
m_startTime = m_currentTime;
m_total = 0.0f;
m_delta = 1.0f / 60.0f;
}
// Update the timer's internal values.
void Update()
{
if (!QueryPerformanceCounter(&m_currentTime))
{
throw ref new Platform::FailureException();
}
m_total = static_cast<float>(
static_cast<double>(m_currentTime.QuadPart - m_startTime.QuadPart) /
static_cast<double>(m_frequency.QuadPart)
);
if (m_lastTime.QuadPart == m_startTime.QuadPart)
{
// If the timer was just reset, report a time delta equivalent to 60Hz frame time.
m_delta = 1.0f / 60.0f;
}
else
{
m_delta = static_cast<float>(
static_cast<double>(m_currentTime.QuadPart - m_lastTime.QuadPart) /
static_cast<double>(m_frequency.QuadPart)
);
}
m_lastTime = m_currentTime;
}
// Duration in seconds between the last call to Reset() and the last call to Update().
property float Total
{
float get() { return m_total; }
}
// Duration in seconds between the previous two calls to Update().
property float Delta
{
float get() { return m_delta; }
}
private:
LARGE_INTEGER m_frequency;
LARGE_INTEGER m_currentTime;
LARGE_INTEGER m_startTime;
LARGE_INTEGER m_lastTime;
float m_total;
float m_delta;
};

View File

@ -0,0 +1,416 @@
#include "pch.h"
#include "CubeRenderer.h"
using namespace DirectX;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
CubeRenderer::CubeRenderer() :
m_loadingComplete(false),
m_indexCount(0)
{
}
void CubeRenderer::CreateTextureFromByte(byte* buffer, int width, int height)
{
int pixelSize = 4;
if (m_texture.Get() == nullptr)
{
CD3D11_TEXTURE2D_DESC textureDesc(
DXGI_FORMAT_B8G8R8A8_UNORM, // format
static_cast<UINT>(width), // width
static_cast<UINT>(height), // height
1, // arraySize
1, // mipLevels
D3D11_BIND_SHADER_RESOURCE, // bindFlags
D3D11_USAGE_DYNAMIC, // usage
D3D11_CPU_ACCESS_WRITE, // cpuaccessFlags
1, // sampleCount
0, // sampleQuality
0 // miscFlags
);
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = buffer;
data.SysMemPitch = pixelSize*width;
data.SysMemSlicePitch = pixelSize*width*height;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&textureDesc,
&data,
m_texture.ReleaseAndGetAddressOf()
)
);
m_d3dDevice->CreateShaderResourceView(m_texture.Get(), NULL, m_SRV.ReleaseAndGetAddressOf());
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory(&sampDesc, sizeof(sampDesc));
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
m_d3dDevice->CreateSamplerState(&sampDesc, m_cubesTexSamplerState.ReleaseAndGetAddressOf());
}
else
{
int nRowSpan = width * pixelSize;
D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT hr = m_d3dContext->Map(m_texture.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
BYTE* mappedData = static_cast<BYTE*>(mappedResource.pData);
for (int i = 0; i < height; ++i)
{
memcpy(mappedData + (i*mappedResource.RowPitch), buffer + (i*nRowSpan), nRowSpan);
}
m_d3dContext->Unmap(m_texture.Get(), 0);
}
}
void CubeRenderer::CreateDeviceResources()
{
Direct3DBase::CreateDeviceResources();
D3D11_BLEND_DESC blendDesc;
ZeroMemory( &blendDesc, sizeof(blendDesc) );
D3D11_RENDER_TARGET_BLEND_DESC rtbd;
ZeroMemory( &rtbd, sizeof(rtbd) );
rtbd.BlendEnable = TRUE;
rtbd.SrcBlend = D3D11_BLEND_SRC_ALPHA;
rtbd.DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = 0x0f;
blendDesc.AlphaToCoverageEnable = false;
blendDesc.RenderTarget[0] = rtbd;
m_d3dDevice->CreateBlendState(&blendDesc, &m_transparency);
D3D11_RASTERIZER_DESC cmdesc;
ZeroMemory(&cmdesc, sizeof(D3D11_RASTERIZER_DESC));
cmdesc.FillMode = D3D11_FILL_SOLID;
cmdesc.CullMode = D3D11_CULL_BACK;
cmdesc.DepthClipEnable = TRUE;
cmdesc.FrontCounterClockwise = true;
m_d3dDevice->CreateRasterizerState(&cmdesc, &m_CCWcullMode);
cmdesc.FrontCounterClockwise = false;
m_d3dDevice->CreateRasterizerState(&cmdesc, &m_CWcullMode);
auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");
auto loadPSTask = DX::ReadDataAsync("SimplePixelShader.cso");
auto createVSTask = loadVSTask.then([this](Platform::Array<byte>^ fileData) {
DX::ThrowIfFailed(
m_d3dDevice->CreateVertexShader(
fileData->Data,
fileData->Length,
nullptr,
&m_vertexShader
)
);
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
DX::ThrowIfFailed(
m_d3dDevice->CreateInputLayout(
vertexDesc,
ARRAYSIZE(vertexDesc),
fileData->Data,
fileData->Length,
&m_inputLayout
)
);
});
auto createPSTask = loadPSTask.then([this](Platform::Array<byte>^ fileData) {
DX::ThrowIfFailed(
m_d3dDevice->CreatePixelShader(
fileData->Data,
fileData->Length,
nullptr,
&m_pixelShader
)
);
CD3D11_BUFFER_DESC constantBufferDesc(sizeof(ModelViewProjectionConstantBuffer), D3D11_BIND_CONSTANT_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&constantBufferDesc,
nullptr,
&m_constantBuffer
)
);
});
auto createCubeTask = (createPSTask && createVSTask).then([this] () {
Vertex v[] =
{
// Front Face
Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f),
Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f),
Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 0.0f),
Vertex( 1.0f, -1.0f, -1.0f, 1.0f, 1.0f),
// Back Face
Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f),
Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 1.0f),
Vertex( 1.0f, 1.0f, 1.0f, 0.0f, 0.0f),
Vertex(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f),
// Top Face
Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f),
Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f),
Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f),
Vertex( 1.0f, 1.0f, -1.0f, 1.0f, 1.0f),
// Bottom Face
Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f),
Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f),
Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 0.0f),
Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 0.0f),
// Left Face
Vertex(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f),
Vertex(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f),
Vertex(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f),
Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f),
// Right Face
Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 1.0f),
Vertex( 1.0f, 1.0f, -1.0f, 0.0f, 0.0f),
Vertex( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f),
Vertex( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f),
};
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
vertexBufferData.pSysMem = v;
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(v), D3D11_BIND_VERTEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&vertexBufferDesc,
&vertexBufferData,
&m_vertexBuffer
)
);
DWORD indices[] = {
// Front Face
0, 2, 1,
0, 3, 2,
// Back Face
4, 6, 5,
4, 7, 6,
// Top Face
8, 10, 9,
8, 11, 10,
// Bottom Face
12, 14, 13,
12, 15, 14,
// Left Face
16, 18, 17,
16, 19, 18,
// Right Face
20, 22, 21,
20, 23, 22
};
m_indexCount = ARRAYSIZE(indices);
D3D11_SUBRESOURCE_DATA indexBufferData = {0};
indexBufferData.pSysMem = indices;
indexBufferData.SysMemPitch = 0;
indexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC indexBufferDesc(sizeof(indices), D3D11_BIND_INDEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&indexBufferDesc,
&indexBufferData,
&m_indexBuffer
)
);
});
createCubeTask.then([this] () {
m_loadingComplete = true;
});
}
void CubeRenderer::CreateWindowSizeDependentResources()
{
Direct3DBase::CreateWindowSizeDependentResources();
float aspectRatio = m_windowBounds.Width / m_windowBounds.Height;
float fovAngleY = 70.0f * XM_PI / 180.0f;
if (aspectRatio < 1.0f)
{
fovAngleY /= aspectRatio;
}
XMStoreFloat4x4(
&m_constantBufferData.projection,
XMMatrixTranspose(
XMMatrixPerspectiveFovRH(
fovAngleY,
aspectRatio,
0.01f,
100.0f
)
)
);
}
void CubeRenderer::Update(float timeTotal, float timeDelta)
{
(void) timeDelta; // Unused parameter.
XMVECTOR eye = XMVectorSet(0.0f, 0.0f, 3.f, 0.0f);
XMVECTOR at = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMStoreFloat4x4(&m_constantBufferData.view, XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
XMStoreFloat4x4(&m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY(timeTotal * XM_PIDIV4)));
}
void CubeRenderer::Render()
{
std::lock_guard<std::mutex> lock(m_mutex);
Render(m_renderTargetView, m_depthStencilView);
}
void CubeRenderer::Render(Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView, Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depthStencilView)
{
const float black[] = {0, 0, 0, 1.0 };
m_d3dContext->ClearRenderTargetView(
renderTargetView.Get(),
black
);
m_d3dContext->ClearDepthStencilView(
depthStencilView.Get(),
D3D11_CLEAR_DEPTH,
1.0f,
0
);
// Only draw the cube once it is loaded (loading is asynchronous).
if (!m_SRV || !m_loadingComplete)
{
return;
}
m_d3dContext->OMSetRenderTargets(
1,
renderTargetView.GetAddressOf(),
depthStencilView.Get()
);
m_d3dContext->UpdateSubresource(
m_constantBuffer.Get(),
0,
NULL,
&m_constantBufferData,
0,
0
);
UINT stride = sizeof(Vertex);
UINT offset = 0;
m_d3dContext->IASetVertexBuffers(
0,
1,
m_vertexBuffer.GetAddressOf(),
&stride,
&offset
);
m_d3dContext->IASetIndexBuffer(
m_indexBuffer.Get(),
DXGI_FORMAT_R32_UINT,
0
);
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_d3dContext->IASetInputLayout(m_inputLayout.Get());
m_d3dContext->VSSetShader(
m_vertexShader.Get(),
nullptr,
0
);
m_d3dContext->VSSetConstantBuffers(
0,
1,
m_constantBuffer.GetAddressOf()
);
m_d3dContext->PSSetShader(
m_pixelShader.Get(),
nullptr,
0
);
m_d3dContext->PSSetShaderResources( 0, 1, m_SRV.GetAddressOf());
m_d3dContext->PSSetSamplers( 0, 1, m_cubesTexSamplerState.GetAddressOf());
//float blendFactor[] = {0.75f, 0.75f, 0.75f, 1.0f};
m_d3dContext->OMSetBlendState(m_transparency.Get(), nullptr, 0xffffffff);
m_d3dContext->RSSetState(m_CCWcullMode.Get());
m_d3dContext->DrawIndexed(
m_indexCount,
0,
0
);
m_d3dContext->RSSetState(m_CWcullMode.Get());
m_d3dContext->DrawIndexed(
m_indexCount,
0,
0
);
}

View File

@ -0,0 +1,61 @@
#pragma once
#include "Direct3DBase.h"
#include <d3d11.h>
#include <mutex>
struct ModelViewProjectionConstantBuffer
{
DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};
struct Vertex //Overloaded Vertex Structure
{
Vertex(){}
Vertex(float x, float y, float z,
float u, float v)
: pos(x,y,z), texCoord(u, v){}
DirectX::XMFLOAT3 pos;
DirectX::XMFLOAT2 texCoord;
};
// This class renders a simple spinning cube.
ref class CubeRenderer sealed : public Direct3DBase
{
public:
CubeRenderer();
// Direct3DBase methods.
virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;
// Method for updating time-dependent objects.
void Update(float timeTotal, float timeDelta);
void CreateTextureFromByte(byte * buffer,int width,int height);
private:
void Render(Microsoft::WRL::ComPtr<ID3D11RenderTargetView> renderTargetView, Microsoft::WRL::ComPtr<ID3D11DepthStencilView> depthStencilView);
bool m_loadingComplete;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_texture;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_SRV;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_cubesTexSamplerState;
uint32 m_indexCount;
ModelViewProjectionConstantBuffer m_constantBufferData;
std::mutex m_mutex;
Microsoft::WRL::ComPtr<ID3D11BlendState> m_transparency;
Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_CCWcullMode;
Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_CWcullMode;
};

View File

@ -0,0 +1,162 @@
#include "pch.h"
#include "Direct3DBase.h"
using namespace DirectX;
using namespace Microsoft::WRL;
using namespace Windows::UI::Core;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
// Constructor.
Direct3DBase::Direct3DBase()
{
}
// Initialize the Direct3D resources required to run.
void Direct3DBase::Initialize()
{
CreateDeviceResources();
}
// These are the resources that depend on the device.
void Direct3DBase::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color channel ordering
// than the API default. It is required for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required feature level in its
// description. All applications are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3
};
// Create the Direct3D 11 API device object and a corresponding context.
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
DX::ThrowIfFailed(
D3D11CreateDevice(
nullptr, // Specify nullptr to use the default adapter.
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
creationFlags, // Set set debug and Direct2D compatibility flags.
featureLevels, // List of feature levels this app can support.
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION.
&device, // Returns the Direct3D device created.
&m_featureLevel, // Returns feature level of device created.
&context // Returns the device immediate context.
)
);
// Get the Direct3D 11.1 API device and context interfaces.
DX::ThrowIfFailed(
device.As(&m_d3dDevice)
);
DX::ThrowIfFailed(
context.As(&m_d3dContext)
);
}
// Allocate all memory resources that depend on the window size.
void Direct3DBase::CreateWindowSizeDependentResources()
{
// Create a descriptor for the render target buffer.
CD3D11_TEXTURE2D_DESC renderTargetDesc(
DXGI_FORMAT_B8G8R8A8_UNORM,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
1,
1,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE
);
renderTargetDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
// Allocate a 2-D surface as the render target buffer.
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&renderTargetDesc,
nullptr,
&m_renderTarget
)
);
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
m_renderTarget.Get(),
nullptr,
&m_renderTargetView
)
);
// Create a depth stencil view.
CD3D11_TEXTURE2D_DESC depthStencilDesc(
DXGI_FORMAT_D24_UNORM_S8_UINT,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
1,
1,
D3D11_BIND_DEPTH_STENCIL
);
ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&depthStencilDesc,
nullptr,
&depthStencil
)
);
CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
m_d3dDevice->CreateDepthStencilView(
depthStencil.Get(),
&depthStencilViewDesc,
&m_depthStencilView
)
);
// Set the rendering viewport to target the entire window.
CD3D11_VIEWPORT viewport(
0.0f,
0.0f,
m_renderTargetSize.Width,
m_renderTargetSize.Height
);
m_d3dContext->RSSetViewports(1, &viewport);
}
void Direct3DBase::UpdateForRenderResolutionChange(float width, float height)
{
m_renderTargetSize.Width = width;
m_renderTargetSize.Height = height;
ID3D11RenderTargetView* nullViews[] = {nullptr};
m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews), nullViews, nullptr);
m_renderTarget = nullptr;
m_renderTargetView = nullptr;
m_depthStencilView = nullptr;
m_d3dContext->Flush();
CreateWindowSizeDependentResources();
}
void Direct3DBase::UpdateForWindowSizeChange(float width, float height)
{
m_windowBounds.Width = width;
m_windowBounds.Height = height;
}

View File

@ -0,0 +1,37 @@
#pragma once
#include "DirectXHelper.h"
// Helper class that initializes DirectX APIs for 3D rendering.
ref class Direct3DBase abstract
{
internal:
Direct3DBase();
public:
virtual void Initialize();
virtual void CreateDeviceResources();
virtual void CreateWindowSizeDependentResources();
virtual void UpdateForRenderResolutionChange(float width, float height);
virtual void UpdateForWindowSizeChange(float width, float height);
virtual void Render() = 0;
internal:
virtual ID3D11Texture2D* GetTexture()
{
return m_renderTarget.Get();
}
protected private:
// Direct3D Objects.
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_renderTarget;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
// Cached renderer properties.
D3D_FEATURE_LEVEL m_featureLevel;
Windows::Foundation::Size m_renderTargetSize;
Windows::Foundation::Rect m_windowBounds;
};

View File

@ -0,0 +1,77 @@
#include "pch.h"
#include "Direct3DContentProvider.h"
using namespace PhoneXamlDirect3DApp1Comp;
Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) :
m_controller(controller)
{
m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] ()
{
if (m_host)
{
m_host->RequestAdditionalFrame();
}
});
m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] ()
{
if (m_host)
{
m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
}
});
}
// IDrawingSurfaceContentProviderNative interface
HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host)
{
m_host = host;
return m_controller->Connect(host);
}
void Direct3DContentProvider::Disconnect()
{
m_controller->Disconnect();
m_host = nullptr;
m_synchronizedTexture = nullptr;
}
HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty)
{
return m_controller->PrepareResources(presentTargetTime, contentDirty);
}
HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle)
{
HRESULT hr = S_OK;
if (!m_synchronizedTexture)
{
hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture);
}
// Set output parameters.
textureSubRectangle->left = 0.0f;
textureSubRectangle->top = 0.0f;
textureSubRectangle->right = static_cast<FLOAT>(size->width);
textureSubRectangle->bottom = static_cast<FLOAT>(size->height);
m_synchronizedTexture.CopyTo(synchronizedTexture);
// Draw to the texture.
if (SUCCEEDED(hr))
{
hr = m_synchronizedTexture->BeginDraw();
if (SUCCEEDED(hr))
{
hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle);
}
m_synchronizedTexture->EndDraw();
}
return hr;
}

View File

@ -0,0 +1,33 @@
#pragma once
#include "pch.h"
#include <wrl/module.h>
#include <Windows.Phone.Graphics.Interop.h>
#include <DrawingSurfaceNative.h>
#include "Direct3DInterop.h"
class Direct3DContentProvider : public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>,
ABI::Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider,
IDrawingSurfaceContentProviderNative>
{
public:
Direct3DContentProvider(PhoneXamlDirect3DApp1Comp::Direct3DInterop^ controller);
void ReleaseD3DResources();
// IDrawingSurfaceContentProviderNative
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);
void STDMETHODCALLTYPE Disconnect();
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);
private:
HRESULT InitializeTexture(_In_ const DrawingSurfaceSizeF* size);
PhoneXamlDirect3DApp1Comp::Direct3DInterop^ m_controller;
Microsoft::WRL::ComPtr<IDrawingSurfaceRuntimeHostNative> m_host;
Microsoft::WRL::ComPtr<IDrawingSurfaceSynchronizedTextureNative> m_synchronizedTexture;
};

View File

@ -0,0 +1,186 @@
#include "pch.h"
#include "Direct3DInterop.h"
#include "Direct3DContentProvider.h"
#include <windows.storage.streams.h>
#include <wrl.h>
#include <robuffer.h>
#include <opencv2\imgproc\types_c.h>
using namespace Windows::Storage::Streams;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Microsoft::WRL;
using namespace Windows::Phone::Graphics::Interop;
using namespace Windows::Phone::Input::Interop;
namespace PhoneXamlDirect3DApp1Comp
{
void Direct3DInterop::ApplyGrayFilter(const cv::Mat& image)
{
cv::Mat intermediateMat;
cv::cvtColor(image, intermediateMat, COLOR_RGBA2GRAY);
cv::cvtColor(intermediateMat, image, COLOR_GRAY2BGRA);
}
void Direct3DInterop::ApplyCannyFilter(const cv::Mat& image)
{
cv::Mat intermediateMat;
cv::Canny(image, intermediateMat, 80, 90);
cv::cvtColor(intermediateMat, image, COLOR_GRAY2BGRA);
}
void Direct3DInterop::ApplySepiaFilter(const cv::Mat& image)
{
const float SepiaKernelData[16] =
{
/* B */0.131f, 0.534f, 0.272f, 0.f,
/* G */0.168f, 0.686f, 0.349f, 0.f,
/* R */0.189f, 0.769f, 0.393f, 0.f,
/* A */0.000f, 0.000f, 0.000f, 1.f
};
const cv::Mat SepiaKernel(4, 4, CV_32FC1, (void*)SepiaKernelData);
cv::transform(image, image, SepiaKernel);
}
Direct3DInterop::Direct3DInterop() :
m_timer(ref new BasicTimer())
{
}
IDrawingSurfaceContentProvider^ Direct3DInterop::CreateContentProvider()
{
ComPtr<Direct3DContentProvider> provider = Make<Direct3DContentProvider>(this);
return reinterpret_cast<IDrawingSurfaceContentProvider^>(provider.Detach());
}
// IDrawingSurfaceManipulationHandler
void Direct3DInterop::SetManipulationHost(DrawingSurfaceManipulationHost^ manipulationHost)
{
manipulationHost->PointerPressed +=
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerPressed);
manipulationHost->PointerMoved +=
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerMoved);
manipulationHost->PointerReleased +=
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerReleased);
}
void Direct3DInterop::RenderResolution::set(Windows::Foundation::Size renderResolution)
{
if (renderResolution.Width != m_renderResolution.Width ||
renderResolution.Height != m_renderResolution.Height)
{
m_renderResolution = renderResolution;
if (m_renderer)
{
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height);
RecreateSynchronizedTexture();
}
}
}
// Event Handlers
void Direct3DInterop::OnPointerPressed(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args)
{
// Insert your code here.
}
void Direct3DInterop::OnPointerMoved(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args)
{
// Insert your code here.
}
void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args)
{
// Insert your code here.
}
// Interface With Direct3DContentProvider
HRESULT Direct3DInterop::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host)
{
m_renderer = ref new CubeRenderer();
m_renderer->Initialize();
m_renderer->UpdateForWindowSizeChange(WindowBounds.Width, WindowBounds.Height);
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height);
// Restart timer after renderer has finished initializing.
m_timer->Reset();
return S_OK;
}
void Direct3DInterop::Disconnect()
{
m_renderer = nullptr;
}
HRESULT Direct3DInterop::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty)
{
*contentDirty = true;
return S_OK;
}
HRESULT Direct3DInterop::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle)
{
m_timer->Update();
m_renderer->Update(m_timer->Total, m_timer->Delta);
m_renderer->Render();
RequestAdditionalFrame();
return S_OK;
}
ID3D11Texture2D* Direct3DInterop::GetTexture()
{
return m_renderer->GetTexture();
}
void Direct3DInterop::CreateTexture(const Platform::Array<int>^ buffer,int width,int height, OCVFilterType filter)
{
if (m_renderer)
{
cv::Mat Lena = cv::Mat(height, width, CV_8UC4);
memcpy(Lena.data, buffer->Data, 4 * height*width);
switch (filter)
{
case OCVFilterType::ePreview:
break;
case OCVFilterType::eGray:
ApplyGrayFilter(Lena);
break;
case OCVFilterType::eCanny:
ApplyCannyFilter(Lena);
break;
case OCVFilterType::eSepia:
ApplySepiaFilter(Lena);
break;
}
m_renderer->CreateTextureFromByte(Lena.data, width, height);
}
}
byte* GetPointerToPixelData( Windows::Storage::Streams::IBuffer ^ pixelBuffer)
{
// Query the IBufferByteAccess interface.
ComPtr<IBufferByteAccess> bufferByteAccess;
reinterpret_cast<IInspectable*>( pixelBuffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess));
// Retrieve the buffer data.
byte* pixels = nullptr;
bufferByteAccess->Buffer(&pixels);
return pixels;
}
}

View File

@ -0,0 +1,80 @@
#pragma once
#include "pch.h"
#include "BasicTimer.h"
#include "CubeRenderer.h"
#include <DrawingSurfaceNative.h>
#include <ppltasks.h>
#include <windows.storage.streams.h>
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\features2d\features2d.hpp>
namespace PhoneXamlDirect3DApp1Comp
{
public enum class OCVFilterType
{
ePreview,
eGray,
eCanny,
eSepia,
eNumOCVFilterTypes
};
public delegate void RequestAdditionalFrameHandler();
public delegate void RecreateSynchronizedTextureHandler();
[Windows::Foundation::Metadata::WebHostHidden]
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
{
public:
Direct3DInterop();
Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();
// IDrawingSurfaceManipulationHandler
virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);
event RequestAdditionalFrameHandler^ RequestAdditionalFrame;
event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;
property Windows::Foundation::Size WindowBounds;
property Windows::Foundation::Size NativeResolution;
property Windows::Foundation::Size RenderResolution
{
Windows::Foundation::Size get(){ return m_renderResolution; }
void set(Windows::Foundation::Size renderResolution);
}
void CreateTexture(const Platform::Array<int>^ buffer, int with, int height, OCVFilterType filter);
protected:
// Event Handlers
void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
internal:
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);
void STDMETHODCALLTYPE Disconnect();
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);
ID3D11Texture2D* GetTexture();
private:
CubeRenderer^ m_renderer;
BasicTimer^ m_timer;
Windows::Foundation::Size m_renderResolution;
void ApplyGrayFilter(const cv::Mat& image);
void ApplyCannyFilter(const cv::Mat& image);
void ApplySepiaFilter(const cv::Mat& image);
void UpdateImage(const cv::Mat& image);
cv::Mat Lena;
unsigned int frameWidth, frameHeight;
};
}

View File

@ -0,0 +1,41 @@
#pragma once
#include <wrl/client.h>
#include <ppl.h>
#include <ppltasks.h>
namespace DX
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch Win32 API errors.
throw Platform::Exception::CreateException(hr);
}
}
// Function that reads from a binary file asynchronously.
inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
{
using namespace Windows::Storage;
using namespace Concurrency;
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file)
{
return file->OpenReadAsync();
}).then([] (Streams::IRandomAccessStreamWithContentType^ stream)
{
unsigned int bufferSize = static_cast<unsigned int>(stream->Size);
auto fileBuffer = ref new Streams::Buffer(bufferSize);
return stream->ReadAsync(fileBuffer, bufferSize, Streams::InputStreamOptions::None);
}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^
{
auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
return fileData;
});
}
}

View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C0F94AFA-466F-4FC4-B5C1-6CD955F3FF88}</ProjectGuid>
<RootNamespace>PhoneXamlDirect3DApp1Comp</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<WinMDAssembly>true</WinMDAssembly>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
<!-- If OutDir was set outside of the project file, then we will append ProjectName -->
<OutDir Condition="'$(OutDirWasSpecified)' == 'true'">$(OutDir)\$(MSBuildProjectName)\</OutDir>
<!-- else, OutDir needs to have project specific directory in order to handle files with unique names -->
<OutDir Condition="'$(OutDirWasSpecified)' != 'true' and '$(Platform)' == 'Win32'">$(SolutionDir)$(Configuration)\$(MSBuildProjectName)\</OutDir>
<OutDir Condition="'$(OutDirWasSpecified)' != 'true' and '$(Platform)' != 'Win32'">$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutDir>
<!-- After OutDir has been fixed, disable Microsoft.common.targets from fixing it again -->
<OutDirWasSpecified>false</OutDirWasSpecified>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110_wp80</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110_wp80</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_wp80</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_wp80</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="opencv.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Import Project="opencv.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="opencv.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<Import Project="opencv.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalUsingDirectories>$(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<CompileAsWinRT>true</CompileAsWinRT>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>ole32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>_WINRT_DLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalUsingDirectories>$(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<CompileAsWinRT>true</CompileAsWinRT>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<IgnoreSpecificDefaultLibraries>ole32.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateWindowsMetadata>true</GenerateWindowsMetadata>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="platform.winmd">
<IsWinMDFile>true</IsWinMDFile>
<Private>false</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BasicTimer.h" />
<ClInclude Include="Direct3DInterop.h" />
<ClInclude Include="CubeRenderer.h" />
<ClInclude Include="DirectXHelper.h" />
<ClInclude Include="Direct3DBase.h" />
<ClInclude Include="Direct3DContentProvider.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Direct3DInterop.cpp" />
<ClCompile Include="CubeRenderer.cpp" />
<ClCompile Include="Direct3DBase.cpp" />
<ClCompile Include="Direct3DContentProvider.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<FxCompile Include="SimplePixelShader.hlsl">
<ShaderType>Pixel</ShaderType>
<ShaderModel>4.0_level_9_3</ShaderModel>
</FxCompile>
<FxCompile Include="SimpleVertexShader.hlsl">
<ShaderType>Vertex</ShaderType>
<ShaderModel>4.0_level_9_3</ShaderModel>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsPhone\v$(TargetPlatformVersion)\Microsoft.Cpp.WindowsPhone.$(TargetPlatformVersion).targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\packages\NokiaImagingSDK.1.0.272.0\build\native\NokiaImagingSDK.targets" Condition="Exists('..\..\packages\NokiaImagingSDK.1.0.272.0\build\native\NokiaImagingSDK.targets')" />
</ImportGroup>
</Project>

View File

@ -0,0 +1,25 @@
Texture2D shaderTexture;
SamplerState SampleType;
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 main(PixelInputType input) : SV_TARGET
{
float4 textureColor;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
return textureColor;
}

View File

@ -0,0 +1,39 @@
cbuffer ModelViewProjectionConstantBuffer : register(b0)
{
matrix model;
matrix view;
matrix projection;
};
struct VertexInputType
{
float4 position : POSITION;
float2 tex : TEXCOORD0;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
};
////////////////////////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType main(VertexInputType input)
{
PixelInputType output;
// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, model);
output.position = mul(output.position, view);
output.position = mul(output.position, projection);
// Store the texture coordinates for the pixel shader.
output.tex = input.tex;
return output;
}

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<OpenCV_Bin>$(OPENCV_WINRT_INSTALL_DIR)\WP\8.0\$(PlatformTarget)\$(PlatformTarget)\vc11\bin\</OpenCV_Bin>
<OpenCV_Lib>$(OPENCV_WINRT_INSTALL_DIR)\WP\8.0\$(PlatformTarget)\$(PlatformTarget)\vc11\lib\</OpenCV_Lib>
<OpenCV_Include>$(OPENCV_WINRT_INSTALL_DIR)\WP\8.0\$(PlatformTarget)\include\</OpenCV_Include>
<!--debug suffix for OpenCV dlls and libs -->
<DebugSuffix Condition="'$(Configuration)'=='Debug'">d</DebugSuffix>
<DebugSuffix Condition="'$(Configuration)'!='Debug'"></DebugSuffix>
</PropertyGroup>
<ItemGroup>
<!--Add required OpenCV dlls here-->
<None Include="$(OpenCV_Bin)opencv_core300$(DebugSuffix).dll">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="$(OpenCV_Bin)opencv_imgproc300$(DebugSuffix).dll">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="$(OpenCV_Bin)opencv_features2d300$(DebugSuffix).dll">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="$(OpenCV_Bin)opencv_flann300$(DebugSuffix).dll">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="$(OpenCV_Bin)opencv_ml300$(DebugSuffix).dll">
<DeploymentContent>true</DeploymentContent>
</None>
</ItemGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(OpenCV_Include);$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<!--Add required OpenCV libs here-->
<AdditionalDependencies>opencv_core300$(DebugSuffix).lib;opencv_imgproc300$(DebugSuffix).lib;opencv_features2d300$(DebugSuffix).lib;opencv_flann300$(DebugSuffix).lib;opencv_ml300$(DebugSuffix).lib;d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OpenCV_Lib);%(AdditionalLibraryDirectories);</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
</Project>

View File

@ -0,0 +1,7 @@
#pragma once
#include <wrl/client.h>
#include <d3d11_1.h>
#include <DirectXMath.h>
#include <memory>
#include <agile.h>