2015-11-12 04:32:53 +00:00
|
|
|
#include <boo/boo.hpp>
|
2016-03-04 23:02:44 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
2018-01-14 02:39:32 +00:00
|
|
|
#include "hecl/Console.hpp"
|
|
|
|
#include "hecl/CVarManager.hpp"
|
2018-10-07 02:53:57 +00:00
|
|
|
#include "athena/MemoryWriter.hpp"
|
2016-03-04 23:02:44 +00:00
|
|
|
#include "hecl/Runtime.hpp"
|
2018-10-07 02:53:57 +00:00
|
|
|
#include "hecl/Backend/Backend.hpp"
|
2016-03-04 23:02:44 +00:00
|
|
|
#include "hecl/HMDLMeta.hpp"
|
2018-10-07 02:53:57 +00:00
|
|
|
#include "hecl/Pipeline.hpp"
|
2017-12-29 07:56:31 +00:00
|
|
|
#include <cmath>
|
2015-11-17 06:42:42 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
2015-11-12 04:32:53 +00:00
|
|
|
|
2018-01-14 02:39:32 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2015-11-12 04:32:53 +00:00
|
|
|
struct HECLWindowCallback : boo::IWindowCallback
|
|
|
|
{
|
|
|
|
bool m_sizeDirty = false;
|
|
|
|
boo::SWindowRect m_latestSize;
|
2018-01-14 07:37:00 +00:00
|
|
|
virtual ~HECLWindowCallback();
|
|
|
|
void resized(const boo::SWindowRect& rect, bool /*sync*/)
|
2015-11-12 04:32:53 +00:00
|
|
|
{
|
|
|
|
m_sizeDirty = true;
|
|
|
|
m_latestSize = rect;
|
|
|
|
}
|
2015-11-13 02:12:09 +00:00
|
|
|
|
|
|
|
bool m_destroyed = false;
|
|
|
|
void destroyed()
|
|
|
|
{
|
|
|
|
m_destroyed = true;
|
|
|
|
}
|
2018-01-14 02:39:32 +00:00
|
|
|
|
|
|
|
void charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
|
|
|
hecl::Console::instance()->handleCharCode(charCode, mods, isRepeat);
|
|
|
|
}
|
|
|
|
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
|
|
|
hecl::Console::instance()->handleSpecialKeyDown(key, mods, isRepeat);
|
|
|
|
}
|
|
|
|
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods)
|
|
|
|
{
|
|
|
|
hecl::Console::instance()->hecl::Console::handleSpecialKeyUp(key, mods);
|
|
|
|
}
|
2015-11-12 04:32:53 +00:00
|
|
|
};
|
|
|
|
|
2018-01-14 07:37:00 +00:00
|
|
|
HECLWindowCallback::~HECLWindowCallback()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-12 04:32:53 +00:00
|
|
|
struct HECLApplicationCallback : boo::IApplicationCallback
|
|
|
|
{
|
|
|
|
HECLWindowCallback m_windowCb;
|
2018-01-14 02:39:32 +00:00
|
|
|
hecl::Runtime::FileStoreManager m_fileStoreMgr;
|
|
|
|
hecl::CVarManager m_cvarManager;
|
|
|
|
hecl::Console m_console;
|
2017-07-17 02:46:39 +00:00
|
|
|
std::shared_ptr<boo::IWindow> m_mainWindow;
|
2015-11-12 04:32:53 +00:00
|
|
|
bool m_running = true;
|
2015-11-17 06:42:42 +00:00
|
|
|
|
2018-01-14 02:39:32 +00:00
|
|
|
HECLApplicationCallback()
|
2018-10-14 20:09:15 +00:00
|
|
|
: m_fileStoreMgr(_SYS_STR("heclTest")),
|
2018-01-14 02:39:32 +00:00
|
|
|
m_cvarManager(m_fileStoreMgr),
|
|
|
|
m_console(&m_cvarManager)
|
|
|
|
{
|
2018-10-07 02:53:57 +00:00
|
|
|
m_console.registerCommand("quit"sv, "Quits application"sv, "",
|
|
|
|
std::bind(&HECLApplicationCallback::quit, this, std::placeholders::_1, std::placeholders::_2));
|
2018-01-14 02:39:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 07:37:00 +00:00
|
|
|
virtual ~HECLApplicationCallback();
|
|
|
|
|
2015-11-12 04:32:53 +00:00
|
|
|
int appMain(boo::IApplication* app)
|
|
|
|
{
|
2017-11-21 09:33:28 +00:00
|
|
|
hecl::VerbosityLevel = 2;
|
|
|
|
|
2015-11-16 04:30:06 +00:00
|
|
|
/* Setup boo window */
|
2018-10-14 20:09:15 +00:00
|
|
|
m_mainWindow = app->newWindow(_SYS_STR("HECL Test"));
|
2015-11-12 04:32:53 +00:00
|
|
|
m_mainWindow->setCallback(&m_windowCb);
|
2015-11-16 04:30:06 +00:00
|
|
|
|
2017-11-05 06:15:03 +00:00
|
|
|
boo::ObjToken<boo::ITextureR> renderTex;
|
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> vubo;
|
2018-10-07 02:53:57 +00:00
|
|
|
boo::ObjToken<boo::IShaderPipeline> pipeline, pipeline2;
|
|
|
|
boo::ObjToken<boo::IShaderDataBinding> binding, binding2;
|
2015-11-17 06:42:42 +00:00
|
|
|
|
2015-11-16 04:30:06 +00:00
|
|
|
struct VertexUBO
|
|
|
|
{
|
|
|
|
float modelview[4][4] = {};
|
|
|
|
float modelviewInv[4][4] = {};
|
|
|
|
float projection[4][4] = {};
|
|
|
|
VertexUBO()
|
|
|
|
{
|
|
|
|
modelview[0][0] = 1.0;
|
|
|
|
modelview[1][1] = 1.0;
|
|
|
|
modelview[2][2] = 1.0;
|
|
|
|
modelview[3][3] = 1.0;
|
|
|
|
modelviewInv[0][0] = 1.0;
|
|
|
|
modelviewInv[1][1] = 1.0;
|
|
|
|
modelviewInv[2][2] = 1.0;
|
|
|
|
modelviewInv[3][3] = 1.0;
|
|
|
|
projection[0][0] = 1.0;
|
|
|
|
projection[1][1] = 1.0;
|
|
|
|
projection[2][2] = 1.0;
|
|
|
|
projection[3][3] = 1.0;
|
|
|
|
}
|
|
|
|
} vuboData;
|
|
|
|
|
2018-01-15 12:34:02 +00:00
|
|
|
/* Make ramp texture */
|
|
|
|
using Pixel = uint8_t[4];
|
|
|
|
static Pixel tex[256][256];
|
|
|
|
for (int i=0 ; i<256 ; ++i)
|
|
|
|
for (int j=0 ; j<256 ; ++j)
|
|
|
|
{
|
|
|
|
tex[i][j][0] = uint8_t(i);
|
2018-10-07 02:53:57 +00:00
|
|
|
tex[i][j][1] = uint8_t(j);
|
2018-01-15 12:34:02 +00:00
|
|
|
tex[i][j][2] = 0;
|
|
|
|
tex[i][j][3] = 0xff;
|
|
|
|
}
|
|
|
|
|
2018-10-07 02:53:57 +00:00
|
|
|
boo::IGraphicsDataFactory* gfxF = m_mainWindow->getMainContextDataFactory();
|
|
|
|
if (gfxF->platform() == boo::IGraphicsDataFactory::Platform::Vulkan)
|
|
|
|
vuboData.modelview[1][1] = -1.f;
|
|
|
|
|
|
|
|
/* Pipeline converter */
|
|
|
|
std::unique_ptr<hecl::PipelineConverterBase> conv = hecl::NewPipelineConverter(gfxF);
|
|
|
|
|
|
|
|
/* Compile HECL shader */
|
|
|
|
static std::string testShader = "HECLOpaque(Texture(0, UV(0)))";
|
|
|
|
//static std::string testShader = "HECLOpaque(vec3(1.0,1.0,1.0),1.0)";
|
|
|
|
hecl::Backend::ShaderTag testShaderTag(testShader, 0, 1, 0, 0, boo::Primitive::TriStrips,
|
2018-11-09 23:31:51 +00:00
|
|
|
hecl::Backend::ReflectionType::None, false, false, false, false);
|
2018-10-07 02:53:57 +00:00
|
|
|
hecl::Frontend::Frontend FE;
|
2018-10-14 20:09:15 +00:00
|
|
|
hecl::Frontend::IR ir = FE.compileSource(testShader, "booTest");
|
|
|
|
hecl::HECLIR irObj(ir, testShaderTag, 0);
|
2018-10-07 02:53:57 +00:00
|
|
|
|
|
|
|
gfxF->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx)
|
2015-11-17 06:42:42 +00:00
|
|
|
{
|
2018-10-07 02:53:57 +00:00
|
|
|
pipeline = conv->convert(ctx, irObj);
|
|
|
|
pipeline2 = conv->convert(ctx, Shader_test{});
|
|
|
|
|
|
|
|
boo::SWindowRect mainWindowRect = m_mainWindow->getWindowFrame();
|
|
|
|
renderTex = ctx.newRenderTexture(size_t(mainWindowRect.size[0]), size_t(mainWindowRect.size[1]),
|
|
|
|
boo::TextureClampMode::Repeat, 1, 0);
|
|
|
|
|
|
|
|
/* Generate meta structure (usually statically serialized) */
|
|
|
|
hecl::HMDLMeta testMeta;
|
|
|
|
testMeta.topology = hecl::HMDLTopology::TriStrips;
|
|
|
|
testMeta.vertStride = 32;
|
|
|
|
testMeta.vertCount = 4;
|
|
|
|
testMeta.indexCount = 4;
|
|
|
|
testMeta.colorCount = 0;
|
|
|
|
testMeta.uvCount = 1;
|
|
|
|
testMeta.weightCount = 0;
|
|
|
|
testMeta.bankCount = 0;
|
|
|
|
|
|
|
|
/* Binary form of meta structure */
|
|
|
|
atUint8 testMetaBuf[HECL_HMDL_META_SZ];
|
|
|
|
athena::io::MemoryWriter testMetaWriter(testMetaBuf, HECL_HMDL_META_SZ);
|
|
|
|
testMeta.write(testMetaWriter);
|
|
|
|
|
|
|
|
/* Make Tri-strip VBO */
|
|
|
|
struct Vert
|
2015-11-17 06:42:42 +00:00
|
|
|
{
|
2018-10-07 02:53:57 +00:00
|
|
|
float pos[3];
|
|
|
|
float norm[3];
|
|
|
|
float uv[2];
|
|
|
|
};
|
|
|
|
static const Vert quad[4] =
|
2015-11-17 06:42:42 +00:00
|
|
|
{
|
2018-10-07 02:53:57 +00:00
|
|
|
{{0.5,0.5},{},{1.0,1.0}},
|
|
|
|
{{-0.5,0.5},{},{0.0,1.0}},
|
|
|
|
{{0.5,-0.5},{},{1.0,0.0}},
|
|
|
|
{{-0.5,-0.5},{},{0.0,0.0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Now simple IBO */
|
|
|
|
static const uint32_t ibo[4] = {0,1,2,3};
|
|
|
|
|
|
|
|
/* Construct quad mesh against boo factory */
|
|
|
|
hecl::Runtime::HMDLData testData(ctx, testMetaBuf, quad, ibo);
|
|
|
|
|
|
|
|
boo::ObjToken<boo::ITexture> texture =
|
|
|
|
ctx.newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, tex, 256*256*4).get();
|
|
|
|
|
|
|
|
/* Make vertex uniform buffer */
|
|
|
|
vubo = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(VertexUBO), 1).get();
|
|
|
|
|
|
|
|
/* Assemble data binding */
|
|
|
|
binding = testData.newShaderDataBindng(ctx, pipeline, 1, &vubo, nullptr, 1, &texture);
|
|
|
|
binding2 = testData.newShaderDataBindng(ctx, pipeline2, 1, &vubo, nullptr, 1, &texture);
|
|
|
|
return true;
|
|
|
|
} BooTrace);
|
|
|
|
|
2015-11-16 04:30:06 +00:00
|
|
|
|
2015-11-17 06:42:42 +00:00
|
|
|
m_mainWindow->showWindow();
|
|
|
|
m_windowCb.m_latestSize = m_mainWindow->getWindowFrame();
|
|
|
|
boo::IGraphicsCommandQueue* gfxQ = m_mainWindow->getCommandQueue();
|
2015-11-16 04:30:06 +00:00
|
|
|
|
|
|
|
size_t frameIdx = 0;
|
2015-11-12 04:32:53 +00:00
|
|
|
while (m_running)
|
|
|
|
{
|
|
|
|
m_mainWindow->waitForRetrace();
|
|
|
|
|
2015-11-13 02:12:09 +00:00
|
|
|
if (m_windowCb.m_destroyed)
|
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-12 04:32:53 +00:00
|
|
|
if (m_windowCb.m_sizeDirty)
|
|
|
|
{
|
|
|
|
gfxQ->resizeRenderTexture(renderTex,
|
2018-01-14 07:37:00 +00:00
|
|
|
size_t(m_windowCb.m_latestSize.size[0]),
|
|
|
|
size_t(m_windowCb.m_latestSize.size[1]));
|
2015-11-12 04:32:53 +00:00
|
|
|
m_windowCb.m_sizeDirty = false;
|
|
|
|
}
|
|
|
|
|
2018-01-14 02:39:32 +00:00
|
|
|
m_console.proc();
|
|
|
|
|
2015-11-12 04:32:53 +00:00
|
|
|
gfxQ->setRenderTarget(renderTex);
|
2015-11-16 04:30:06 +00:00
|
|
|
boo::SWindowRect r = m_windowCb.m_latestSize;
|
|
|
|
r.location[0] = 0;
|
|
|
|
r.location[1] = 0;
|
|
|
|
gfxQ->setViewport(r);
|
2015-11-27 22:17:09 +00:00
|
|
|
gfxQ->setScissor(r);
|
2018-01-14 07:37:00 +00:00
|
|
|
float rgba[] = {sinf(frameIdx / 60.0f), cosf(frameIdx / 60.0f), 0.0f, 1.0f};
|
2015-11-16 04:30:06 +00:00
|
|
|
gfxQ->setClearColor(rgba);
|
2015-11-12 04:32:53 +00:00
|
|
|
gfxQ->clearTarget();
|
2015-11-16 04:30:06 +00:00
|
|
|
|
2018-01-14 07:37:00 +00:00
|
|
|
vuboData.modelview[3][0] = sinf(frameIdx / 60.0f) * 0.5f;
|
|
|
|
vuboData.modelview[3][1] = cosf(frameIdx / 60.0f) * 0.5f;
|
2017-11-05 06:15:03 +00:00
|
|
|
vubo.cast<boo::IGraphicsBufferD>()->load(&vuboData, sizeof(vuboData));
|
2015-11-16 04:30:06 +00:00
|
|
|
|
2018-10-07 02:53:57 +00:00
|
|
|
gfxQ->setShaderDataBinding(binding2);
|
2016-07-01 02:31:23 +00:00
|
|
|
gfxQ->drawIndexed(0, 4);
|
2015-11-12 04:32:53 +00:00
|
|
|
gfxQ->resolveDisplay(renderTex);
|
2018-01-14 02:39:32 +00:00
|
|
|
m_console.draw(gfxQ);
|
2015-11-12 04:32:53 +00:00
|
|
|
gfxQ->execute();
|
2015-11-16 04:30:06 +00:00
|
|
|
|
|
|
|
++frameIdx;
|
2015-11-12 04:32:53 +00:00
|
|
|
}
|
2015-11-17 06:42:42 +00:00
|
|
|
|
2018-01-14 07:37:00 +00:00
|
|
|
m_cvarManager.serialize();
|
2015-12-05 00:42:21 +00:00
|
|
|
gfxQ->stopRenderer();
|
2015-11-12 04:32:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-01-14 07:37:00 +00:00
|
|
|
void appQuitting(boo::IApplication* /*app*/)
|
2015-11-12 04:32:53 +00:00
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
}
|
2018-01-14 02:39:32 +00:00
|
|
|
|
2018-01-14 07:37:00 +00:00
|
|
|
void quit(hecl::Console* /*con*/, const std::vector<std::string>& /*args*/)
|
2018-01-14 02:39:32 +00:00
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
}
|
2015-11-12 04:32:53 +00:00
|
|
|
};
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
void AthenaExcHandler(athena::error::Level level,
|
2018-01-14 07:37:00 +00:00
|
|
|
const char* file, const char* /*function*/,
|
2015-11-16 04:30:06 +00:00
|
|
|
int line, const char* fmt, ...)
|
2015-11-23 03:09:46 +00:00
|
|
|
{
|
2016-03-04 23:02:44 +00:00
|
|
|
static logvisor::Module Log("heclTest::AthenaExcHandler");
|
2015-11-23 03:09:46 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2018-01-14 07:37:00 +00:00
|
|
|
Log.reportSource(logvisor::Level(level), file, uint32_t(line), fmt, ap);
|
2015-11-23 03:09:46 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2015-11-16 04:30:06 +00:00
|
|
|
|
2017-12-06 03:22:31 +00:00
|
|
|
#if !WINDOWS_STORE
|
2015-11-12 04:32:53 +00:00
|
|
|
#if _WIN32
|
|
|
|
int wmain(int argc, const boo::SystemChar** argv)
|
|
|
|
#else
|
|
|
|
int main(int argc, const boo::SystemChar** argv)
|
|
|
|
#endif
|
|
|
|
{
|
2015-11-16 04:30:06 +00:00
|
|
|
atSetExceptionHandler(AthenaExcHandler);
|
2016-09-08 06:15:39 +00:00
|
|
|
logvisor::RegisterStandardExceptions();
|
2016-03-04 23:02:44 +00:00
|
|
|
logvisor::RegisterConsoleLogger();
|
2015-11-12 04:32:53 +00:00
|
|
|
HECLApplicationCallback appCb;
|
2015-11-21 01:13:06 +00:00
|
|
|
int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto,
|
2018-10-14 20:09:15 +00:00
|
|
|
appCb, _SYS_STR("heclTest"), _SYS_STR("HECL Test"), argc, argv);
|
2015-11-12 04:32:53 +00:00
|
|
|
printf("IM DYING!!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2017-12-06 03:22:31 +00:00
|
|
|
#else
|
|
|
|
using namespace Windows::ApplicationModel::Core;
|
2015-11-12 04:32:53 +00:00
|
|
|
|
2017-12-06 03:22:31 +00:00
|
|
|
[Platform::MTAThread]
|
|
|
|
int WINAPIV main(Platform::Array<Platform::String^>^ params)
|
|
|
|
{
|
|
|
|
logvisor::RegisterStandardExceptions();
|
|
|
|
logvisor::RegisterConsoleLogger();
|
|
|
|
HECLApplicationCallback appCb;
|
|
|
|
boo::ViewProvider^ viewProvider =
|
2018-10-14 20:09:15 +00:00
|
|
|
ref new boo::ViewProvider(appCb, _SYS_STR("heclTest"), _SYS_STR("HECL Test"), _SYS_STR("heclTest"), params, false);
|
2017-12-06 03:22:31 +00:00
|
|
|
CoreApplication::Run(viewProvider);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _WIN32 && !WINDOWS_STORE
|
2015-11-12 04:32:53 +00:00
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2018-05-28 20:24:16 +00:00
|
|
|
const boo::SystemChar** argv;
|
|
|
|
if (lpCmdLine[0])
|
|
|
|
argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc));
|
2015-11-12 04:32:53 +00:00
|
|
|
static boo::SystemChar selfPath[1024];
|
|
|
|
GetModuleFileNameW(nullptr, selfPath, 1024);
|
|
|
|
static const boo::SystemChar* booArgv[32] = {};
|
|
|
|
booArgv[0] = selfPath;
|
|
|
|
for (int i=0 ; i<argc ; ++i)
|
|
|
|
booArgv[i+1] = argv[i];
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
logvisor::CreateWin32Console();
|
2018-05-28 20:24:16 +00:00
|
|
|
return wmain(argc + 1, booArgv);
|
2015-11-12 04:32:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-01-14 07:37:00 +00:00
|
|
|
|
|
|
|
HECLApplicationCallback::~HECLApplicationCallback()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|