port from perforce
This commit is contained in:
166
hgplus/particles/main.cpp
Normal file
166
hgplus/particles/main.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#include "data.h"
|
||||
#include "shaders.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
#ifdef FULLSCREEN
|
||||
ShowCursor(0);
|
||||
hWnd = CreateWindowExA(0, (LPCSTR)ATOM_STATIC, 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
//ShowWindow(hWnd, SW_SHOW);
|
||||
#else
|
||||
#ifdef _DEBUG
|
||||
WNDCLASSEX wndclass;
|
||||
wndclass.cbSize = sizeof (wndclass);
|
||||
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wndclass.lpfnWndProc = (WNDPROC)DefWindowProc;
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = 0;
|
||||
wndclass.hInstance = NULL;
|
||||
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||
wndclass.lpszMenuName = NULL;
|
||||
wndclass.lpszClassName = "BluFlame intro window class";
|
||||
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
RegisterClassEx(&wndclass);
|
||||
|
||||
hWnd = CreateWindowExA(0,
|
||||
wndclass.lpszClassName,
|
||||
"Intro",
|
||||
WS_EX_APPWINDOW,
|
||||
GetSystemMetrics(SM_CXSCREEN) - WIDTH - 16,
|
||||
0,
|
||||
WIDTH + 16,
|
||||
HEIGHT + 40,
|
||||
NULL,
|
||||
NULL,
|
||||
GetModuleHandle(NULL),
|
||||
NULL
|
||||
);
|
||||
ShowWindow(hWnd, SW_NORMAL);
|
||||
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
#else
|
||||
hWnd = CreateWindowExA(0, (LPCSTR)ATOM_STATIC, 0, WS_POPUP | WS_VISIBLE, 0, 0, WIDTH, HEIGHT, 0, 0, 0, 0);
|
||||
#endif
|
||||
#endif
|
||||
swapChainDesc.OutputWindow = hWnd;
|
||||
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, 0, D3D11_SDK_VERSION, (DXGI_SWAP_CHAIN_DESC*)&swapChainDesc, &swapChain, &device, NULL, &context);
|
||||
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture);
|
||||
|
||||
device->CreateTexture2D(&depthBufferDesc, NULL, &depthBuffer);
|
||||
|
||||
device->CreateBuffer(&constantBufferDesc, NULL, &constantBuffer);
|
||||
|
||||
device->CreateBuffer(&particleBufferDesc, NULL, &particleBuffer1);
|
||||
device->CreateUnorderedAccessView(particleBuffer1, &particleUavDesc, &particleBuffer1UAV);
|
||||
device->CreateShaderResourceView(particleBuffer1, &particleSrvDesc, &particleBuffer1SRV);
|
||||
|
||||
device->CreateBuffer(&particleBufferDesc, NULL, &particleBuffer2);
|
||||
device->CreateUnorderedAccessView(particleBuffer2, &particleUavDesc, &particleBuffer2UAV);
|
||||
device->CreateShaderResourceView(particleBuffer2, &particleSrvDesc, &particleBuffer2SRV);
|
||||
|
||||
device->CreateRenderTargetView(backBufferTexture, &backBufferRtvDesc, &backBufferRtv);
|
||||
device->CreateDepthStencilState(&depthStencilStateDesc, &depthStencilState);
|
||||
device->CreateDepthStencilView(depthBuffer, &depthStencilViewDesc, &depthStencilView);
|
||||
|
||||
device->CreateBlendState(&alphaBlendDesc, &alphaBlendState);
|
||||
|
||||
#ifndef _DEBUG
|
||||
CreateShaders();
|
||||
#else
|
||||
#ifndef SHADERDEBUG
|
||||
InitShader();
|
||||
shaderCompileEvent = ::CreateEvent(NULL, FALSE, FALSE, TEXT("WriteEvent"));
|
||||
SetThreadPriority((HANDLE)CreateThread(0, 0, &filemon, 0, 0, 0), THREAD_PRIORITY_BELOW_NORMAL);
|
||||
#endif
|
||||
CreateShaders();
|
||||
#endif
|
||||
|
||||
ID3D11UnorderedAccessView* uavs[] = { particleBuffer1UAV, particleBuffer2UAV };
|
||||
ID3D11ShaderResourceView* srvs[] = { particleBuffer1SRV, particleBuffer2SRV };
|
||||
|
||||
UINT indices[] = { -1, 0, 0, 0 };
|
||||
context->CSSetUnorderedAccessViews(0, 2, uavs, indices);
|
||||
context->CSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
context->CSSetShader(initShader, NULL, 0);
|
||||
context->Dispatch(1, 1, 1);
|
||||
|
||||
float demoTime = 0.0f;
|
||||
LARGE_INTEGER startTime;
|
||||
QueryPerformanceCounter(&startTime);
|
||||
do {
|
||||
#ifdef _DEBUG
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
#endif
|
||||
context->ClearRenderTargetView(backBufferRtv, zero);
|
||||
context->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
|
||||
auto uavtemp = uavs[1];
|
||||
uavs[1] = uavs[0];
|
||||
uavs[0] = uavtemp;
|
||||
auto srvtemp = srvs[1];
|
||||
srvs[1] = srvs[0];
|
||||
srvs[0] = srvtemp;
|
||||
context->ClearUnorderedAccessViewUint(uavs[1], (UINT*)zero);
|
||||
context->CSSetUnorderedAccessViews(0, 2, uavs, indices);
|
||||
|
||||
context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
auto constantBufferVertexData = (ConstantBufferType*)mappedResource.pData;
|
||||
|
||||
LARGE_INTEGER time;
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceCounter(&time);
|
||||
QueryPerformanceFrequency(&freq);
|
||||
float deltaTime = (float(time.QuadPart - startTime.QuadPart) / freq.QuadPart);
|
||||
//deltaTime *= 0.05f;
|
||||
startTime = time;
|
||||
demoTime += deltaTime;
|
||||
constantBufferVertexData->demoTime = demoTime;
|
||||
constantBufferVertexData->deltaTime = deltaTime;
|
||||
constantBufferVertexData->dummy1 = 1.0f;
|
||||
constantBufferVertexData->dummy2 = 1.0f;
|
||||
|
||||
context->Unmap(constantBuffer, 0);
|
||||
|
||||
context->CSSetShader(updateShader, NULL, 0);
|
||||
context->Dispatch(1024, 1024, 1);
|
||||
context->CSSetUnorderedAccessViews(0, 2, (ID3D11UnorderedAccessView* const *)zero, NULL);
|
||||
|
||||
UINT strides[] = { 48 };
|
||||
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||
context->VSSetConstantBuffers(0, 1, &constantBuffer);
|
||||
context->VSSetShader(particleVertexShader, NULL, 0);
|
||||
context->GSSetShader(particleGeometryShader, NULL, 0);
|
||||
context->PSSetShader(particlePixelShader, NULL, 0);
|
||||
context->OMSetRenderTargets(1, &backBufferRtv, NULL/*depthStencilView*/);
|
||||
//context->OMSetDepthStencilState(depthStencilState, 1);
|
||||
context->OMSetBlendState(alphaBlendState, NULL, 0xffffffff);
|
||||
context->RSSetViewports(1, &swapChainViewport);
|
||||
context->VSSetShaderResources(0, 1, &srvs[1]);
|
||||
|
||||
context->DrawInstanced(1024 * 1024, 1, 0, 0);
|
||||
|
||||
context->VSSetShaderResources(0, 1, (ID3D11ShaderResourceView* const*)zero);
|
||||
|
||||
swapChain->Present(1, 0);
|
||||
|
||||
//::Sleep(1000 * 0.05);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifndef SHADERDEBUG
|
||||
if (::WaitForSingleObject(shaderCompileEvent, 0) == WAIT_OBJECT_0)
|
||||
{
|
||||
::Sleep(50);
|
||||
CreateShaders();
|
||||
::Sleep(50);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
} while (!GetAsyncKeyState(VK_ESCAPE));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user