VISIGen for Windows

This commit is contained in:
Jack Andersen 2017-02-24 21:59:37 -10:00
parent 40179c02dc
commit c312aa355b
9 changed files with 170 additions and 14 deletions

View File

@ -89,6 +89,8 @@ bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPat
if (!areaPath.isFile())
continue;
Log.report(logvisor::Info, _S("Visiting %s"), area.path.getRelativePath().c_str());
hecl::ProjectPath memRelayPath(area.path, _S("/!memoryrelays.yaml"));
std::vector<atUint32> memRelays;

View File

@ -7,7 +7,7 @@
#include "DataSpec/DNACommon/AROTBuilder.hpp"
#include "ScriptObjects/ScriptTypes.hpp"
extern const hecl::SystemString ExeDir;
extern hecl::SystemString ExeDir;
namespace DataSpec
{

View File

@ -138,7 +138,7 @@ int main(int argc, const boo::SystemChar** argv)
if (hecl::SystemChar* cwd = hecl::Getcwd(CwdBuf, 1024))
{
if (argv[0][0] != _S('/') && argv[0][0] != _S('\\'))
if (hecl::PathRelative(argv[0]))
ExeDir = hecl::SystemString(cwd) + _S('/');
hecl::SystemString Argv0(argv[0]);
hecl::SystemString::size_type lastIdx = Argv0.find_last_of(_S("/\\"));

2
hecl

@ -1 +1 @@
Subproject commit 1a9260afd0a5bcf9e77203bd4b5cde4334eb1b3f
Subproject commit e82e477d247ae666f532acc7f9cfc2e2c6cbdddc

@ -1 +1 @@
Subproject commit 67a7efea539964b2f2a816135ee5719e5ae104a1
Subproject commit ccceebc331453fd3f71440ab8f14511572e36918

View File

@ -10,6 +10,8 @@ endif()
if(APPLE)
set(PLAT_SRCS MainMac.mm)
set_source_files_properties(MainMac.mm PROPERTIES COMPILE_FLAGS -fobjc-arc)
elseif(WIN32)
set(PLAT_SRCS MainWin.cpp)
endif()
add_executable(visigen ${PLAT_SRCS}

152
visigen/MainWin.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "VISIRenderer.hpp"
#include <Windows.h>
#include <WinUser.h>
#include <Shlwapi.h>
#include <strsafe.h>
#include "athena/Global.hpp"
#include "logvisor/logvisor.hpp"
#include <thread>
static logvisor::Module AthenaLog("Athena");
static void AthenaExc(athena::error::Level level, const char* file,
const char*, int line, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
AthenaLog.report(logvisor::Level(level), fmt, ap);
va_end(ap);
}
static float s_Percent = 0.f;
static DWORD s_mainThreadId;
static void UpdatePercent(float percent)
{
s_Percent = percent;
PostThreadMessage(s_mainThreadId, WM_USER+1, 0, 0);
}
const DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
VISIRenderer* s_Renderer;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_SIZING)
{
RECT& dragRect = reinterpret_cast<RECT&>(lParam);
RECT tmpRect = dragRect;
tmpRect.bottom = tmpRect.top + 512;
tmpRect.right = tmpRect.left + 768;
AdjustWindowRect(&tmpRect, dwStyle, FALSE);
dragRect = tmpRect;
return TRUE;
}
else if (uMsg == WM_CLOSE)
{
s_Renderer->Terminate();
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int wmain(int argc, const hecl::SystemChar** argv)
{
logvisor::RegisterStandardExceptions();
logvisor::RegisterConsoleLogger();
atSetExceptionHandler(AthenaExc);
VISIRenderer renderer(argc, argv);
s_Renderer = &renderer;
WNDCLASS wndClass =
{
CS_NOCLOSE,
WindowProc,
0,
0,
GetModuleHandle(nullptr),
0,
0,
0,
0,
L"VISIGenWindow"
};
RegisterClassW(&wndClass);
RECT clientRect = {0, 0, 768, 512};
AdjustWindowRect(&clientRect, dwStyle, FALSE);
HWND window = CreateWindowW(L"VISIGenWindow", L"VISIGen", dwStyle,
100, 100,
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top,
NULL, NULL, NULL, NULL);
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, //Flags
PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette.
32, //Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, //Number of bits for the depthbuffer
8, //Number of bits for the stencilbuffer
0, //Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
HDC deviceContext = GetDC(window);
int pf = ChoosePixelFormat(deviceContext, &pfd);
SetPixelFormat(deviceContext, pf, &pfd);
HGLRC glContext = wglCreateContext(deviceContext);
ShowWindow(window, SW_SHOW);
s_mainThreadId = GetCurrentThreadId();
/* Spawn client thread */
std::thread clientThread([&]()
{
wglMakeCurrent(deviceContext, glContext);
renderer.Run(UpdatePercent);
PostThreadMessage(s_mainThreadId, WM_USER, 0, 0);
});
/* Pump messages */
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0))
{
if (!msg.hwnd)
{
/* PostThreadMessage events */
switch (msg.message)
{
case WM_USER:
/* Quit message from client thread */
PostQuitMessage(0);
continue;
case WM_USER+1:
/* Update window title from client thread */
wchar_t title[256];
StringCbPrintfW(title, 512, L"VISIGen [%g%%]", s_Percent * 100.f);
SetWindowTextW(window, title);
continue;
default: break;
}
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
renderer.Terminate();
if (clientThread.joinable())
clientThread.join();
wglDeleteContext(glContext);
return renderer.ReturnVal();
}

View File

@ -51,7 +51,7 @@ const VISIBuilder::Leaf& VISIBuilder::PVSRenderCache::GetLeaf(const zeus::CVecto
void VISIBuilder::Progress::report(int divisions)
{
m_prog += 1.f / divisions;
printf(" %g\%% \r", m_prog * 100.f);
printf(" %g%% \r", m_prog * 100.f);
fflush(stdout);
if (m_updatePercent)
m_updatePercent(m_prog);
@ -88,21 +88,21 @@ void VISIBuilder::Node::buildChildren(int level, int divisions, const zeus::CAAB
// Inward subdivide
zeus::CAABox Z[2];
if (flags & 0x4)
curAabb.splitZ(Z[1], Z[0]);
curAabb.splitZ(Z[0], Z[1]);
else
Z[0] = curAabb;
for (int i=0 ; i<splits[2] ; ++i)
{
zeus::CAABox Y[2];
if (flags & 0x2)
Z[i].splitY(Y[1], Y[0]);
Z[i].splitY(Y[0], Y[1]);
else
Y[0] = Z[i];
for (int j=0 ; j<splits[1] ; ++j)
{
zeus::CAABox X[2];
if (flags & 0x1)
Y[j].splitX(X[1], X[0]);
Y[j].splitX(X[0], X[1]);
else
X[0] = Y[j];
for (int k=0 ; k<splits[0] ; ++k)

View File

@ -42,9 +42,9 @@ static const char* FS =
" colorOut = vtf.color;\n"
"}\n";
static const uint32_t AABBIdxs[19] =
static const uint32_t AABBIdxs[20] =
{
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 7, 3, 5, 5, 0, 0, 2, 6, 4
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 7, 3, 5, 5, 0, 0, 2, 6, 4
};
bool VISIRenderer::SetupShaders()
@ -107,7 +107,7 @@ bool VISIRenderer::SetupShaders()
glGenBuffers(1, &m_aabbIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_aabbIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 19 * 4, &AABBIdxs, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 20 * 4, AABBIdxs, GL_STATIC_DRAW);
glGenQueries(1, &m_query);
@ -306,7 +306,7 @@ void VISIRenderer::RenderPVSOpaque(RGBA8* bufOut, const zeus::CVector3f& pos, bo
// Non-transparents first
if (!surf.transparent)
glDrawElements(model.topology, surf.count, GL_UNSIGNED_INT,
reinterpret_cast<void*>(surf.first * 4));
reinterpret_cast<void*>(uintptr_t(surf.first * 4)));
else
needTransparent = true;
}
@ -355,7 +355,7 @@ void VISIRenderer::RenderPVSTransparent(const std::function<void(int)>& passFunc
{
glBeginQuery(GL_ANY_SAMPLES_PASSED, m_query);
glDrawElements(model.topology, surf.count, GL_UNSIGNED_INT,
reinterpret_cast<void*>(surf.first * 4));
reinterpret_cast<void*>(uintptr_t(surf.first * 4)));
glEndQuery(GL_ANY_SAMPLES_PASSED);
GLint res;
glGetQueryObjectiv(m_query, GL_QUERY_RESULT, &res);
@ -401,7 +401,7 @@ void VISIRenderer::RenderPVSEntitiesAndLights(const std::function<void(int)>& pa
}
glBindVertexArray(ent.vao);
glBeginQuery(GL_ANY_SAMPLES_PASSED, m_query);
glDrawElements(GL_TRIANGLE_STRIP, 19, GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_INT, 0);
glEndQuery(GL_ANY_SAMPLES_PASSED);
GLint res;
glGetQueryObjectiv(m_query, GL_QUERY_RESULT, &res);