Permalink
Browse files

Implements a prototype GPU renderer

  • Loading branch information...
Ninputer committed Dec 27, 2011
1 parent 628e5a5 commit d75e5e2ab45c95d68dcccd5607734d2af46c02c7
@@ -60,7 +60,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d2d1.lib;dwrite.lib;windowscodecs.lib;Common.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d2d1.lib;d3d11.lib;dxgi.lib;dwrite.lib;windowscodecs.lib;Common.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
@@ -1,6 +1,8 @@
#include "stdafx.h"
#include "RenderArea.h"
#include "mandelbrot.h"
#include "d3d11.h"
#include "dxgi.h"
RenderAreaMessageHandler::RenderAreaMessageHandler(void)
{
@@ -13,7 +15,39 @@ RenderAreaMessageHandler::~RenderAreaMessageHandler(void)
HRESULT RenderAreaMessageHandler::OnCreate()
{
return S_OK;
using namespace Hilo::Direct2DHelpers;
using namespace D2D1;
if (m_renderTarget != nullptr)
{
return S_OK;
}
ComPtr<IWindow> window;
HRESULT hr = GetWindow(&window);
HWND hWnd;
if (SUCCEEDED(hr))
{
hr = window->GetWindowHandle(&hWnd);
}
RECT rect;
if (SUCCEEDED(hr))
{
hr = window->GetClientRect(&rect);
}
if (SUCCEEDED(hr))
{
hr = m_d2dFactory->CreateHwndRenderTarget(
RenderTargetProperties(),
HwndRenderTargetProperties(hWnd, SizeU(rect.right, rect.bottom)),
&m_renderTarget);
}
return hr;
}
HRESULT RenderAreaMessageHandler::OnEraseBackground()
@@ -23,12 +57,130 @@ HRESULT RenderAreaMessageHandler::OnEraseBackground()
HRESULT RenderAreaMessageHandler::OnRender()
{
using namespace Concurrency;
double real_center = -0.746826546356156;
double imag_center = 0.113746476309378;
double scale = 1000;
double d = 1 / scale;
const unsigned int width = 640;
const unsigned int height = 640;
std::vector<unsigned int> data(width * height);
array_view<unsigned int, 2> arrayview(width, height, data);
generate_mandelbrot(arrayview, 1024, real_center - d, imag_center - d, real_center + d, imag_center + d);
arrayview.synchronize();
ComPtr<ID2D1Bitmap> bitmap;
HRESULT hr = m_renderTarget->CreateBitmap(
D2D1::SizeU(width, height),
static_cast<void*>(data.data()),
width * sizeof(unsigned int),
D2D1::BitmapProperties(
D2D1::PixelFormat(
DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE
)),
&bitmap);
m_renderTarget->BeginDraw();
m_renderTarget->Clear();
m_renderTarget->DrawBitmap(bitmap,
D2D1::RectF(0.0, 0.0, static_cast<float>(width), static_cast<float>(height)));
m_renderTarget->EndDraw();
return S_OK;
}
/*
array<unsigned int, 2> a(64, 64);
parallel_for_each(a.grid, [&a](index<2> i) restrict(direct3d)
{
a[i] = 0xCCCCCCCC;
});
ComPtr<IUnknown> bufferPtr = direct3d::get_buffer(a);
ComPtr<ID3D11Buffer> buffer;
HRESULT hr = bufferPtr.QueryInterface(&buffer);
ComPtr<ID3D11Device> device;
if (SUCCEEDED(hr))
{
buffer->GetDevice(&device);
}
static const DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
//Create a texture
ComPtr<ID3D11Texture2D> texture;
D3D11_TEXTURE2D_DESC tdesc;
tdesc.Width = 64;
tdesc.Height = 64;
tdesc.MipLevels = 1;
tdesc.ArraySize = 1;
tdesc.SampleDesc.Count = 1;
tdesc.SampleDesc.Quality = 0;
tdesc.Usage = D3D11_USAGE_DEFAULT;
tdesc.Format = format;
tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tdesc.CPUAccessFlags = 0;
tdesc.MiscFlags = 0;
hr = device->CreateTexture2D(
&tdesc,
nullptr,
&texture);
ComPtr<ID3D11DeviceContext> context;
if (SUCCEEDED(hr))
{
device->GetImmediateContext(&context);
}
context->CopyResource(buffer, texture);
ComPtr<IDXGISurface> dxgiSurface;
hr = texture.QueryInterface(&dxgiSurface);
ComPtr<ID2D1Bitmap> sharedBitmap;
if (SUCCEEDED(hr))
{
D2D1_BITMAP_PROPERTIES bprop;
bprop.pixelFormat = D2D1::PixelFormat(
format,
D2D1_ALPHA_MODE_IGNORE);
bprop.dpiX = 0.0f;
bprop.dpiY = 0.0f;
hr = m_renderTarget->CreateSharedBitmap(
__uuidof(IDXGISurface),
dxgiSurface,
&bprop,
&sharedBitmap);
}
*/
HRESULT RenderAreaMessageHandler::OnSize(unsigned int width, unsigned int height)
{
return S_OK;
using namespace D2D1;
HRESULT hr = m_renderTarget->Resize(SizeU(width, height));
return hr;
}
HRESULT RenderAreaMessageHandler::OnLeftMouseButtonDown(D2D1_POINT_2F mousePosition)
@@ -63,6 +215,9 @@ HRESULT RenderAreaMessageHandler::OnKeyDown(unsigned int vKey)
HRESULT RenderAreaMessageHandler::Initialize()
{
MessageBox(nullptr, L"Hello", L"Test", 0);
return S_OK;
using namespace Hilo::Direct2DHelpers;
HRESULT hr = Direct2DUtility::GetD2DFactory(&m_d2dFactory);
return hr;
}
@@ -12,21 +12,6 @@
// Don't use min and max macros, we'll use std functions instead
#define NOMINMAX
// Windows Header Files:
#include <windows.h>
// Other Windows Headers
#include <D2d1.h>
#include <DWrite.h>
#include <PropKey.h>
#include <PropVarUtil.h>
#include <ShellApi.h>
#include <ShlObj.h>
#include <StructuredQuery.h>
#include <ThumbCache.h>
#include <UIAnimation.h>
#include <WinCodec.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
@@ -42,6 +27,21 @@
#include <string>
#include <vector>
// Windows Header Files:
#include <windows.h>
// Other Windows Headers
#include <D2d1.h>
#include <DWrite.h>
#include <PropKey.h>
#include <PropVarUtil.h>
#include <ShellApi.h>
#include <ShlObj.h>
#include <StructuredQuery.h>
#include <ThumbCache.h>
#include <UIAnimation.h>
#include <WinCodec.h>
// Commonly used headers
#include "ComPtr.h"
#include "SharedObject.h"
@@ -55,4 +55,14 @@
#ifndef HINST_THISCOMPONENT
extern "C" IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
#endif
// Use the correct version of the common control library based on the currently selected CPU architecture
// This is needed in order to use TaskDialog, since TaskDialog requires version 6.0 of Comctl32.dll
#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

0 comments on commit d75e5e2

Please sign in to comment.