2017-12-29 07:54:26 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cmath>
|
2015-08-18 22:43:30 +00:00
|
|
|
#include <boo/boo.hpp>
|
2015-10-31 04:28:21 +00:00
|
|
|
#include <boo/graphicsdev/GL.hpp>
|
2016-06-29 01:22:13 +00:00
|
|
|
#include <boo/graphicsdev/Vulkan.hpp>
|
2016-03-27 00:48:16 +00:00
|
|
|
#include <boo/graphicsdev/D3D.hpp>
|
|
|
|
#include <boo/graphicsdev/Metal.hpp>
|
2015-10-30 06:26:02 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
2016-03-04 23:02:18 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
2015-04-18 21:46:51 +00:00
|
|
|
|
2015-04-29 10:24:39 +00:00
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
class DolphinSmashAdapterCallback : public IDolphinSmashAdapterCallback
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
2015-05-05 07:16:06 +00:00
|
|
|
void controllerConnected(unsigned idx, EDolphinControllerType)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
2017-02-11 04:20:41 +00:00
|
|
|
// printf("CONTROLLER %u CONNECTED\n", idx);
|
2015-04-24 00:24:15 +00:00
|
|
|
}
|
2018-05-25 06:30:42 +00:00
|
|
|
void controllerDisconnected(unsigned idx)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
2017-02-11 04:20:41 +00:00
|
|
|
// printf("CONTROLLER %u DISCONNECTED\n", idx);
|
2015-04-24 00:24:15 +00:00
|
|
|
}
|
2015-05-05 07:16:06 +00:00
|
|
|
void controllerUpdate(unsigned idx, EDolphinControllerType,
|
2015-08-18 19:40:26 +00:00
|
|
|
const DolphinControllerState& state)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
2017-02-11 04:20:41 +00:00
|
|
|
// printf("CONTROLLER %u UPDATE %d %d\n", idx, state.m_leftStick[0], state.m_leftStick[1]);
|
|
|
|
// printf(" %d %d\n", state.m_rightStick[0], state.m_rightStick[1]);
|
|
|
|
// printf(" %d %d\n", state.m_analogTriggers[0], state.m_analogTriggers[1]);
|
2015-05-15 01:16:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 23:38:53 +00:00
|
|
|
class DualshockPadCallback : public IDualshockPadCallback
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
|
|
|
void controllerDisconnected()
|
|
|
|
{
|
|
|
|
printf("CONTROLLER DISCONNECTED\n");
|
|
|
|
}
|
2017-05-08 19:09:10 +00:00
|
|
|
void controllerUpdate(DualshockPad& pad, const DualshockPadState& state)
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
|
|
|
static time_t timeTotal;
|
|
|
|
static time_t lastTime = 0;
|
|
|
|
timeTotal = time(NULL);
|
|
|
|
time_t timeDif = timeTotal - lastTime;
|
|
|
|
/*
|
|
|
|
if (timeDif >= .15)
|
|
|
|
{
|
|
|
|
uint8_t led = ctrl->getLED();
|
|
|
|
led *= 2;
|
|
|
|
if (led > 0x10)
|
|
|
|
led = 2;
|
|
|
|
ctrl->setRawLED(led);
|
|
|
|
lastTime = timeTotal;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (state.m_psButtonState)
|
|
|
|
{
|
|
|
|
if (timeDif >= 1) // wait 30 seconds before issuing another rumble event
|
|
|
|
{
|
2017-05-08 19:09:10 +00:00
|
|
|
pad.startRumble(EDualshockMotor::Left);
|
|
|
|
pad.startRumble(EDualshockMotor::Right, 100);
|
2015-05-15 01:16:36 +00:00
|
|
|
lastTime = timeTotal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
else
|
|
|
|
ctrl->stopRumble(DS3_MOTOR_RIGHT | DS3_MOTOR_LEFT);*/
|
2015-05-22 00:35:46 +00:00
|
|
|
|
2015-05-15 01:16:36 +00:00
|
|
|
printf("CONTROLLER UPDATE %d %d\n", state.m_leftStick[0], state.m_leftStick[1]);
|
|
|
|
printf(" %d %d\n", state.m_rightStick[0], state.m_rightStick[1]);
|
|
|
|
printf(" %f %f %f\n", state.accPitch, state.accYaw, state.gyroZ);
|
2015-04-24 00:24:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
class GenericPadCallback : public IGenericPadCallback
|
|
|
|
{
|
|
|
|
void controllerConnected()
|
|
|
|
{
|
|
|
|
printf("CONTROLLER CONNECTED\n");
|
|
|
|
}
|
|
|
|
void controllerDisconnected()
|
|
|
|
{
|
|
|
|
printf("CONTROLLER DISCONNECTED\n");
|
|
|
|
}
|
|
|
|
void valueUpdate(const HIDMainItem& item, int32_t value)
|
|
|
|
{
|
|
|
|
const char* pageName = item.GetUsagePageName();
|
|
|
|
const char* usageName = item.GetUsageName();
|
|
|
|
if (pageName)
|
|
|
|
{
|
|
|
|
if (usageName)
|
2017-10-17 05:50:59 +00:00
|
|
|
printf("%s %s %d\n", pageName, usageName, int(value));
|
2017-09-15 17:20:52 +00:00
|
|
|
else
|
2017-10-17 05:50:59 +00:00
|
|
|
printf("%s %d %d\n", pageName, int(item.m_usage), int(value));
|
2017-09-15 17:20:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (usageName)
|
2017-10-17 05:50:59 +00:00
|
|
|
printf("page%d %s %d\n", int(item.m_usagePage), usageName, int(value));
|
2017-09-15 17:20:52 +00:00
|
|
|
else
|
2017-10-17 05:50:59 +00:00
|
|
|
printf("page%d %d %d\n", int(item.m_usagePage), int(item.m_usage), int(value));
|
2017-09-15 17:20:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-24 07:17:28 +00:00
|
|
|
class NintendoPowerACallback : public INintendoPowerACallback
|
|
|
|
{
|
|
|
|
void controllerDisconnected()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "CONTROLLER DISCONNECTED\n");
|
|
|
|
}
|
|
|
|
void controllerUpdate(const NintendoPowerAState& state)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%i %i\n"
|
|
|
|
"%i %i\n",
|
|
|
|
state.leftX, state.leftY,
|
|
|
|
state.rightX, state.rightY);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
class TestDeviceFinder : public DeviceFinder
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2017-10-24 03:09:50 +00:00
|
|
|
std::shared_ptr<DolphinSmashAdapter> m_smashAdapter;
|
2017-11-24 07:17:28 +00:00
|
|
|
std::shared_ptr<NintendoPowerA> m_nintendoPowerA;
|
2017-10-24 03:09:50 +00:00
|
|
|
std::shared_ptr<DualshockPad> m_ds3;
|
|
|
|
std::shared_ptr<GenericPad> m_generic;
|
2015-08-18 19:40:26 +00:00
|
|
|
DolphinSmashAdapterCallback m_cb;
|
2017-11-24 07:17:28 +00:00
|
|
|
NintendoPowerACallback m_nintendoPowerACb;
|
2015-08-18 23:32:19 +00:00
|
|
|
DualshockPadCallback m_ds3CB;
|
2017-09-15 17:20:52 +00:00
|
|
|
GenericPadCallback m_genericCb;
|
2015-04-22 21:48:23 +00:00
|
|
|
public:
|
2015-08-18 19:40:26 +00:00
|
|
|
TestDeviceFinder()
|
2018-10-07 02:49:22 +00:00
|
|
|
: DeviceFinder({dev_typeid(DolphinSmashAdapter), dev_typeid(NintendoPowerA), dev_typeid(GenericPad)})
|
2015-04-22 21:48:23 +00:00
|
|
|
{}
|
2015-08-18 19:40:26 +00:00
|
|
|
void deviceConnected(DeviceToken& tok)
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
auto dev = tok.openAndGetDevice();
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dev->getTypeHash() == dev_typeid(DolphinSmashAdapter))
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
m_smashAdapter = std::static_pointer_cast<DolphinSmashAdapter>(dev);
|
2017-10-24 03:09:50 +00:00
|
|
|
m_smashAdapter->setCallback(&m_cb);
|
2015-05-15 01:16:36 +00:00
|
|
|
}
|
2018-10-07 02:49:22 +00:00
|
|
|
else if (dev->getTypeHash() == dev_typeid(NintendoPowerA))
|
2017-11-24 07:17:28 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
m_nintendoPowerA = std::static_pointer_cast<NintendoPowerA>(dev);
|
2017-11-24 07:17:28 +00:00
|
|
|
m_nintendoPowerA->setCallback(&m_nintendoPowerACb);
|
|
|
|
}
|
2018-10-07 02:49:22 +00:00
|
|
|
else if (dev->getTypeHash() == dev_typeid(DualshockPad))
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
m_ds3 = std::static_pointer_cast<DualshockPad>(dev);
|
2017-10-24 03:09:50 +00:00
|
|
|
m_ds3->setCallback(&m_ds3CB);
|
|
|
|
m_ds3->setLED(EDualshockLED::LED_1);
|
2015-05-15 01:16:36 +00:00
|
|
|
}
|
2018-10-07 02:49:22 +00:00
|
|
|
else if (dev->getTypeHash() == dev_typeid(GenericPad))
|
2017-09-15 17:20:52 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
m_generic = std::static_pointer_cast<GenericPad>(dev);
|
2017-10-24 03:09:50 +00:00
|
|
|
m_generic->setCallback(&m_genericCb);
|
2017-09-15 17:20:52 +00:00
|
|
|
}
|
2015-04-22 21:48:23 +00:00
|
|
|
}
|
2015-08-18 19:40:26 +00:00
|
|
|
void deviceDisconnected(DeviceToken&, DeviceBase* device)
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2017-10-24 03:09:50 +00:00
|
|
|
if (m_smashAdapter.get() == device)
|
|
|
|
m_smashAdapter.reset();
|
|
|
|
if (m_ds3.get() == device)
|
|
|
|
m_ds3.reset();
|
|
|
|
if (m_generic.get() == device)
|
|
|
|
m_generic.reset();
|
2017-11-24 07:17:28 +00:00
|
|
|
if (m_nintendoPowerA.get() == device)
|
|
|
|
m_nintendoPowerA.reset();
|
2015-04-22 21:48:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
struct CTestWindowCallback : IWindowCallback
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-11-05 07:30:40 +00:00
|
|
|
bool m_fullscreenToggleRequested = false;
|
2015-11-04 01:58:36 +00:00
|
|
|
SWindowRect m_lastRect;
|
|
|
|
bool m_rectDirty = false;
|
2015-11-05 09:28:51 +00:00
|
|
|
bool m_windowInvalid = false;
|
2016-03-24 08:05:19 +00:00
|
|
|
|
2017-11-05 06:12:49 +00:00
|
|
|
void resized(const SWindowRect& rect, bool sync)
|
2015-11-04 01:58:36 +00:00
|
|
|
{
|
|
|
|
m_lastRect = rect;
|
|
|
|
m_rectDirty = true;
|
|
|
|
fprintf(stderr, "Resized %d, %d (%d, %d)\n", rect.size[0], rect.size[1], rect.location[0], rect.location[1]);
|
|
|
|
}
|
2015-11-02 09:31:06 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
void mouseDown(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-11-21 01:12:22 +00:00
|
|
|
fprintf(stderr, "Mouse Down %d (%f,%f)\n", int(button), coord.norm[0], coord.norm[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void mouseUp(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
|
|
|
{
|
2015-11-21 01:12:22 +00:00
|
|
|
fprintf(stderr, "Mouse Up %d (%f,%f)\n", int(button), coord.norm[0], coord.norm[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void mouseMove(const SWindowCoord& coord)
|
|
|
|
{
|
2018-01-21 22:01:52 +00:00
|
|
|
//fprintf(stderr, "Mouse Move (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-11-05 09:28:51 +00:00
|
|
|
void mouseEnter(const SWindowCoord &coord)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Mouse entered (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
|
|
|
}
|
|
|
|
void mouseLeave(const SWindowCoord &coord)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Mouse left (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
|
|
|
}
|
2015-05-12 09:38:37 +00:00
|
|
|
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
|
|
|
{
|
2015-11-05 07:30:40 +00:00
|
|
|
//fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
|
2015-05-04 04:28:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchDown(const STouchCoord& coord, uintptr_t tid)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Down %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchUp(const STouchCoord& coord, uintptr_t tid)
|
2015-05-12 09:38:37 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Up %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchMove(const STouchCoord& coord, uintptr_t tid)
|
2015-05-12 09:38:37 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Move %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
void charKeyDown(unsigned long charCode, EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void charKeyUp(unsigned long charCode, EModifierKey mods)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
2015-11-21 01:12:22 +00:00
|
|
|
if (key == ESpecialKey::Enter && (mods & EModifierKey::Alt) != EModifierKey::None)
|
2015-11-05 07:30:40 +00:00
|
|
|
m_fullscreenToggleRequested = true;
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void specialKeyUp(ESpecialKey key, EModifierKey mods)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-12 09:38:37 +00:00
|
|
|
|
2015-05-04 04:28:07 +00:00
|
|
|
}
|
2015-05-12 09:38:37 +00:00
|
|
|
void modKeyDown(EModifierKey mod, bool isRepeat)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void modKeyUp(EModifierKey mod)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-11-05 09:28:51 +00:00
|
|
|
void windowMoved(const SWindowRect& rect)
|
|
|
|
{
|
2018-01-20 05:50:01 +00:00
|
|
|
//fprintf(stderr, "Moved %d, %d (%d, %d)\n", rect.size[0], rect.size[1], rect.location[0], rect.location[1]);
|
2015-11-05 09:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroyed()
|
|
|
|
{
|
|
|
|
m_windowInvalid = true;
|
|
|
|
}
|
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
};
|
2016-03-24 08:05:19 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
struct TestApplicationCallback : IApplicationCallback
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2017-07-17 02:45:49 +00:00
|
|
|
std::shared_ptr<IWindow> mainWindow;
|
2015-08-18 19:40:26 +00:00
|
|
|
boo::TestDeviceFinder devFinder;
|
2015-05-12 09:38:37 +00:00
|
|
|
CTestWindowCallback windowCallback;
|
2015-10-29 04:44:38 +00:00
|
|
|
bool running = true;
|
2015-10-30 06:26:02 +00:00
|
|
|
|
2017-11-05 06:12:49 +00:00
|
|
|
boo::ObjToken<IShaderDataBinding> m_binding;
|
|
|
|
boo::ObjToken<ITextureR> m_renderTarget;
|
2016-03-24 08:05:19 +00:00
|
|
|
|
2017-11-05 06:12:49 +00:00
|
|
|
static void LoaderProc(TestApplicationCallback* self)
|
2015-10-30 06:26:02 +00:00
|
|
|
{
|
2015-11-05 00:00:29 +00:00
|
|
|
IGraphicsDataFactory* factory = self->mainWindow->getLoadContextDataFactory();
|
2016-03-24 08:05:19 +00:00
|
|
|
|
2018-05-25 06:30:42 +00:00
|
|
|
factory->commitTransaction([&](IGraphicsDataFactory::Context& ctx)
|
2015-10-30 06:26:02 +00:00
|
|
|
{
|
2016-03-30 19:14:17 +00:00
|
|
|
/* Create render target */
|
|
|
|
int x, y, w, h;
|
|
|
|
self->mainWindow->getWindowFrame(x, y, w, h);
|
2018-01-21 22:01:52 +00:00
|
|
|
self->m_renderTarget = ctx.newRenderTexture(w, h, boo::TextureClampMode::ClampToEdge, 1, 0);
|
2016-03-30 19:14:17 +00:00
|
|
|
|
|
|
|
/* Make Tri-strip VBO */
|
|
|
|
struct Vert
|
2015-10-30 06:26:02 +00:00
|
|
|
{
|
2016-06-30 04:54:29 +00:00
|
|
|
float pos[3];
|
|
|
|
float uv[2];
|
2016-03-30 19:14:17 +00:00
|
|
|
};
|
2018-01-16 06:29:43 +00:00
|
|
|
/*
|
2016-03-30 19:14:17 +00:00
|
|
|
static const Vert quad[4] =
|
|
|
|
{
|
|
|
|
{{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}}
|
2018-01-16 06:29:43 +00:00
|
|
|
};
|
|
|
|
*/
|
|
|
|
static const Vert quad[4] =
|
|
|
|
{
|
|
|
|
{{1.0,1.0},{1.0,1.0}},
|
|
|
|
{{-1.0,1.0},{0.0,1.0}},
|
|
|
|
{{1.0,-1.0},{1.0,0.0}},
|
|
|
|
{{-1.0,-1.0},{0.0,0.0}}
|
2016-03-30 19:14:17 +00:00
|
|
|
};
|
2017-11-05 06:12:49 +00:00
|
|
|
auto vbo = ctx.newStaticBuffer(BufferUse::Vertex, quad, sizeof(Vert), 4);
|
2016-03-30 19:14:17 +00:00
|
|
|
|
|
|
|
/* Make vertex format */
|
|
|
|
VertexElementDescriptor descs[2] =
|
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
{VertexSemantic::Position3},
|
|
|
|
{VertexSemantic::UV2}
|
2016-03-30 19:14:17 +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] = i;
|
|
|
|
tex[i][j][1] = j;
|
|
|
|
tex[i][j][2] = 0;
|
|
|
|
tex[i][j][3] = 0xff;
|
|
|
|
}
|
2017-11-05 06:12:49 +00:00
|
|
|
boo::ObjToken<ITexture> texture = ctx.newStaticTexture(256, 256, 1, TextureFormat::RGBA8,
|
2018-01-21 22:01:52 +00:00
|
|
|
boo::TextureClampMode::ClampToEdge, tex, 256*256*4).get();
|
2016-03-30 19:14:17 +00:00
|
|
|
|
|
|
|
/* Make shader pipeline */
|
2017-11-05 06:12:49 +00:00
|
|
|
boo::ObjToken<IShaderPipeline> pipeline;
|
2016-06-29 01:22:13 +00:00
|
|
|
auto plat = ctx.platform();
|
2018-10-07 02:49:22 +00:00
|
|
|
|
|
|
|
AdditionalPipelineInfo info =
|
|
|
|
{
|
|
|
|
BlendFactor::One, BlendFactor::Zero,
|
|
|
|
Primitive::TriStrips, boo::ZTest::LEqual,
|
|
|
|
true, true, false, CullMode::None
|
|
|
|
};
|
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#if BOO_HAS_GL
|
2016-08-24 04:33:20 +00:00
|
|
|
if (plat == IGraphicsDataFactory::Platform::OpenGL)
|
2016-03-30 19:14:17 +00:00
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"#version 330\n"
|
2018-10-07 02:49:22 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-03-30 19:14:17 +00:00
|
|
|
"layout(location=0) in vec3 in_pos;\n"
|
|
|
|
"layout(location=1) in vec2 in_uv;\n"
|
2018-10-07 02:49:22 +00:00
|
|
|
"SBINDING(0) out vec2 out_uv;\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = vec4(in_pos, 1.0);\n"
|
|
|
|
" out_uv = in_uv;\n"
|
|
|
|
"}\n";
|
2015-10-30 06:26:02 +00:00
|
|
|
|
2016-03-30 19:14:17 +00:00
|
|
|
static const char* FS =
|
|
|
|
"#version 330\n"
|
|
|
|
BOO_GLSL_BINDING_HEAD
|
|
|
|
"precision highp float;\n"
|
2016-07-08 00:05:22 +00:00
|
|
|
"TBINDING0 uniform sampler2D tex;\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
"layout(location=0) out vec4 out_frag;\n"
|
2018-10-07 02:49:22 +00:00
|
|
|
"SBINDING(0) in vec2 out_uv;\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2018-01-16 06:29:43 +00:00
|
|
|
" //out_frag = texture(tex, out_uv);\n"
|
|
|
|
" out_frag = vec4(out_uv.xy, 0.0, 1.0);\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
"}\n";
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2016-07-08 00:05:22 +00:00
|
|
|
|
2018-10-07 02:49:22 +00:00
|
|
|
auto vertex = ctx.newShaderStage((uint8_t*)VS, 0, PipelineStage::Vertex);
|
|
|
|
auto fragment = ctx.newShaderStage((uint8_t*)FS, 0, PipelineStage::Fragment);
|
|
|
|
|
|
|
|
pipeline = ctx.newShaderPipeline(vertex, fragment,
|
|
|
|
{{VertexSemantic::Position3},
|
|
|
|
{VertexSemantic::UV2}}, info);
|
2017-12-06 03:20:59 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2016-06-29 01:22:13 +00:00
|
|
|
#if BOO_HAS_VULKAN
|
2017-12-06 03:20:59 +00:00
|
|
|
if (plat == IGraphicsDataFactory::Platform::Vulkan)
|
2016-06-29 01:22:13 +00:00
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"#version 330\n"
|
2016-06-30 04:54:29 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-06-29 01:22:13 +00:00
|
|
|
"layout(location=0) in vec3 in_pos;\n"
|
|
|
|
"layout(location=1) in vec2 in_uv;\n"
|
2016-06-30 04:54:29 +00:00
|
|
|
"SBINDING(0) out vec2 out_uv;\n"
|
2016-06-29 01:22:13 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_Position = vec4(in_pos, 1.0);\n"
|
2016-06-30 04:54:29 +00:00
|
|
|
" out_uv = in_uv;\n"
|
2016-06-29 01:22:13 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS =
|
|
|
|
"#version 330\n"
|
|
|
|
BOO_GLSL_BINDING_HEAD
|
|
|
|
"precision highp float;\n"
|
|
|
|
"TBINDING0 uniform sampler2D texs[1];\n"
|
|
|
|
"layout(location=0) out vec4 out_frag;\n"
|
2016-06-30 04:54:29 +00:00
|
|
|
"SBINDING(0) in vec2 out_uv;\n"
|
2016-06-29 01:22:13 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2016-06-30 04:54:29 +00:00
|
|
|
" out_frag = texture(texs[0], out_uv);\n"
|
2016-06-29 01:22:13 +00:00
|
|
|
"}\n";
|
|
|
|
|
2018-10-07 02:49:22 +00:00
|
|
|
auto vertexSiprv = VulkanDataFactory::CompileGLSL(VS, PipelineStage::Vertex);
|
|
|
|
auto vertexShader = ctx.newShaderStage(vertexSiprv, PipelineStage::Vertex);
|
|
|
|
auto fragmentSiprv = VulkanDataFactory::CompileGLSL(FS, PipelineStage::Fragment);
|
|
|
|
auto fragmentShader = ctx.newShaderStage(fragmentSiprv, PipelineStage::Fragment);
|
|
|
|
pipeline = ctx.newShaderPipeline(vertexShader, fragmentShader, descs, info);
|
2017-12-06 03:20:59 +00:00
|
|
|
} else
|
2016-06-29 01:22:13 +00:00
|
|
|
#endif
|
2016-03-30 19:14:17 +00:00
|
|
|
#if _WIN32
|
2018-05-25 06:30:42 +00:00
|
|
|
if (plat == IGraphicsDataFactory::Platform::D3D11)
|
2016-03-30 19:14:17 +00:00
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"struct VertData {float3 in_pos : POSITION; float2 in_uv : UV;};\n"
|
|
|
|
"struct VertToFrag {float4 out_pos : SV_Position; float2 out_uv : UV;};\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag retval;\n"
|
|
|
|
" retval.out_pos = float4(v.in_pos, 1.0);\n"
|
|
|
|
" retval.out_uv = v.in_uv;\n"
|
|
|
|
" return retval;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* PS =
|
|
|
|
"SamplerState samp : register(s0);\n"
|
|
|
|
"Texture2D tex : register(t0);\n"
|
|
|
|
"struct VertToFrag {float4 out_pos : SV_Position; float2 out_uv : UV;};\n"
|
|
|
|
"float4 main(in VertToFrag d) : SV_Target0\n"
|
|
|
|
"{\n"
|
2018-01-20 03:02:29 +00:00
|
|
|
" //return tex.Sample(samp, d.out_uv);\n"
|
|
|
|
" return float4(d.out_uv.xy, 0.0, 1.0);\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
"}\n";
|
|
|
|
|
2018-10-14 19:59:19 +00:00
|
|
|
auto vertexSiprv = D3D11DataFactory::CompileHLSL(VS, PipelineStage::Vertex);
|
|
|
|
auto vertexShader = ctx.newShaderStage(vertexSiprv, PipelineStage::Vertex);
|
|
|
|
auto fragmentSiprv = D3D11DataFactory::CompileHLSL(PS, PipelineStage::Fragment);
|
|
|
|
auto fragmentShader = ctx.newShaderStage(fragmentSiprv, PipelineStage::Fragment);
|
|
|
|
pipeline = ctx.newShaderPipeline(vertexShader, fragmentShader, descs, info);
|
2017-12-06 03:20:59 +00:00
|
|
|
} else
|
2016-03-30 19:14:17 +00:00
|
|
|
#elif BOO_HAS_METAL
|
2017-12-06 03:20:59 +00:00
|
|
|
if (plat == IGraphicsDataFactory::Platform::Metal)
|
2016-03-30 19:14:17 +00:00
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertData {float3 in_pos [[ attribute(0) ]]; float2 in_uv [[ attribute(1) ]];};\n"
|
|
|
|
"struct VertToFrag {float4 out_pos [[ position ]]; float2 out_uv;};\n"
|
|
|
|
"vertex VertToFrag vmain(VertData v [[ stage_in ]])\n"
|
2015-11-05 00:00:29 +00:00
|
|
|
"{\n"
|
|
|
|
" VertToFrag retval;\n"
|
|
|
|
" retval.out_pos = float4(v.in_pos, 1.0);\n"
|
|
|
|
" retval.out_uv = v.in_uv;\n"
|
|
|
|
" return retval;\n"
|
|
|
|
"}\n";
|
|
|
|
|
2016-03-30 19:14:17 +00:00
|
|
|
static const char* FS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertToFrag {float4 out_pos [[ position ]]; float2 out_uv;};\n"
|
2018-01-07 05:17:14 +00:00
|
|
|
"fragment float4 fmain(VertToFrag d [[ stage_in ]],\n"
|
2018-06-12 01:13:34 +00:00
|
|
|
" sampler samp [[ sampler(3) ]],\n"
|
2018-01-07 05:17:14 +00:00
|
|
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
2015-11-05 00:00:29 +00:00
|
|
|
"{\n"
|
2016-03-30 19:14:17 +00:00
|
|
|
" return tex.sample(samp, d.out_uv);\n"
|
2015-11-05 00:00:29 +00:00
|
|
|
"}\n";
|
|
|
|
|
2018-10-19 00:56:27 +00:00
|
|
|
auto vertexMetal = MetalDataFactory::CompileMetal(VS, PipelineStage::Vertex);
|
|
|
|
auto vertexShader = ctx.newShaderStage(vertexMetal, PipelineStage::Vertex);
|
|
|
|
auto fragmentMetal = MetalDataFactory::CompileMetal(FS, PipelineStage::Fragment);
|
|
|
|
auto fragmentShader = ctx.newShaderStage(fragmentMetal, PipelineStage::Fragment);
|
|
|
|
pipeline = ctx.newShaderPipeline(vertexShader, fragmentShader, descs, info);
|
2017-12-06 03:20:59 +00:00
|
|
|
} else
|
2015-11-05 00:00:29 +00:00
|
|
|
#endif
|
2017-12-06 03:20:59 +00:00
|
|
|
{}
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2016-03-30 19:14:17 +00:00
|
|
|
/* Make shader data binding */
|
|
|
|
self->m_binding =
|
2018-10-07 02:49:22 +00:00
|
|
|
ctx.newShaderDataBinding(pipeline, vbo.get(), nullptr, nullptr, 0, nullptr, nullptr,
|
2017-03-14 07:02:53 +00:00
|
|
|
1, &texture, nullptr, nullptr);
|
2016-03-30 20:42:36 +00:00
|
|
|
|
|
|
|
return true;
|
2018-05-25 06:30:42 +00:00
|
|
|
} BooTrace);
|
2015-10-30 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 04:44:38 +00:00
|
|
|
int appMain(IApplication* app)
|
2015-04-18 23:12:22 +00:00
|
|
|
{
|
2018-10-07 02:49:22 +00:00
|
|
|
mainWindow = app->newWindow(_SYS_STR("YAY!"));
|
2015-05-12 09:38:37 +00:00
|
|
|
mainWindow->setCallback(&windowCallback);
|
2015-05-06 00:50:57 +00:00
|
|
|
mainWindow->showWindow();
|
2015-11-04 01:58:36 +00:00
|
|
|
windowCallback.m_lastRect = mainWindow->getWindowFrame();
|
2015-10-31 19:21:23 +00:00
|
|
|
//mainWindow->setFullscreen(true);
|
2015-05-06 00:50:57 +00:00
|
|
|
devFinder.startScanning();
|
2015-10-29 04:44:38 +00:00
|
|
|
|
2015-10-30 06:26:02 +00:00
|
|
|
IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
|
2015-11-04 01:02:05 +00:00
|
|
|
|
2018-01-20 05:50:01 +00:00
|
|
|
LoaderProc(this);
|
2015-10-30 06:26:02 +00:00
|
|
|
|
2015-10-31 04:28:21 +00:00
|
|
|
size_t frameIdx = 0;
|
2015-10-31 06:39:11 +00:00
|
|
|
size_t lastCheck = 0;
|
2015-10-29 04:44:38 +00:00
|
|
|
while (running)
|
|
|
|
{
|
2015-11-05 09:28:51 +00:00
|
|
|
if (windowCallback.m_windowInvalid)
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-31 04:28:21 +00:00
|
|
|
mainWindow->waitForRetrace();
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-04 01:58:36 +00:00
|
|
|
if (windowCallback.m_rectDirty)
|
|
|
|
{
|
|
|
|
gfxQ->resizeRenderTexture(m_renderTarget, windowCallback.m_lastRect.size[0], windowCallback.m_lastRect.size[1]);
|
|
|
|
windowCallback.m_rectDirty = false;
|
|
|
|
}
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-05 07:30:40 +00:00
|
|
|
if (windowCallback.m_fullscreenToggleRequested)
|
|
|
|
{
|
|
|
|
mainWindow->setFullscreen(!mainWindow->isFullscreen());
|
|
|
|
windowCallback.m_fullscreenToggleRequested = false;
|
|
|
|
}
|
|
|
|
|
2015-11-05 00:00:29 +00:00
|
|
|
gfxQ->setRenderTarget(m_renderTarget);
|
|
|
|
SWindowRect r = windowCallback.m_lastRect;
|
|
|
|
r.location[0] = 0;
|
|
|
|
r.location[1] = 0;
|
|
|
|
gfxQ->setViewport(r);
|
2015-11-27 22:14:05 +00:00
|
|
|
gfxQ->setScissor(r);
|
2018-01-20 05:50:01 +00:00
|
|
|
//float rgba[] = {std::max(0.f, sinf(frameIdx / 60.0)), std::max(0.f, cosf(frameIdx / 60.0)), 0.0, 1.0};
|
|
|
|
float gammaT = sinf(frameIdx / 60.0) + 1.f;
|
2018-01-21 22:01:52 +00:00
|
|
|
if (gammaT < 1.f)
|
|
|
|
gammaT = gammaT * 0.5f + 0.5f;
|
|
|
|
//printf("%f\n", gammaT);
|
2018-01-20 05:50:01 +00:00
|
|
|
mainWindow->getDataFactory()->setDisplayGamma(gammaT);
|
2018-01-16 06:29:43 +00:00
|
|
|
//gfxQ->setClearColor(rgba);
|
2015-10-31 04:28:21 +00:00
|
|
|
gfxQ->clearTarget();
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-04 01:58:36 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_binding);
|
|
|
|
gfxQ->draw(0, 4);
|
|
|
|
gfxQ->resolveDisplay(m_renderTarget);
|
2015-10-31 04:28:21 +00:00
|
|
|
gfxQ->execute();
|
|
|
|
|
2015-11-02 09:31:06 +00:00
|
|
|
//fprintf(stderr, "%zu\n", frameIdx);
|
2015-10-31 19:21:23 +00:00
|
|
|
++frameIdx;
|
2015-10-31 06:39:11 +00:00
|
|
|
|
|
|
|
if ((frameIdx - lastCheck) > 100)
|
|
|
|
{
|
|
|
|
lastCheck = frameIdx;
|
2015-10-31 19:21:23 +00:00
|
|
|
//mainWindow->setFullscreen(!mainWindow->isFullscreen());
|
2015-10-31 06:39:11 +00:00
|
|
|
}
|
2015-10-29 04:44:38 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 22:01:52 +00:00
|
|
|
gfxQ->stopRenderer();
|
2018-01-20 05:50:01 +00:00
|
|
|
m_renderTarget.reset();
|
|
|
|
m_binding.reset();
|
2015-10-29 04:44:38 +00:00
|
|
|
return 0;
|
2015-04-18 23:12:22 +00:00
|
|
|
}
|
2015-05-06 00:50:57 +00:00
|
|
|
void appQuitting(IApplication*)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-10-29 04:44:38 +00:00
|
|
|
running = false;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-08-31 03:40:58 +00:00
|
|
|
void appFilesOpen(IApplication*, const std::vector<SystemString>& paths)
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
2015-05-13 22:21:13 +00:00
|
|
|
fprintf(stderr, "OPENING: ");
|
2015-08-31 03:40:58 +00:00
|
|
|
for (const SystemString& path : paths)
|
|
|
|
{
|
|
|
|
#if _WIN32
|
|
|
|
fwprintf(stderr, L"%s ", path.c_str());
|
|
|
|
#else
|
2015-05-13 22:21:13 +00:00
|
|
|
fprintf(stderr, "%s ", path.c_str());
|
2015-08-31 03:40:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-05-13 22:21:13 +00:00
|
|
|
fprintf(stderr, "\n");
|
2015-05-15 01:16:36 +00:00
|
|
|
}
|
2015-05-06 00:50:57 +00:00
|
|
|
};
|
2015-05-04 04:28:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#if !WINDOWS_STORE
|
2015-11-21 01:12:22 +00:00
|
|
|
#if _WIN32
|
|
|
|
int wmain(int argc, const boo::SystemChar** argv)
|
|
|
|
#else
|
2015-11-06 03:20:58 +00:00
|
|
|
int main(int argc, const boo::SystemChar** argv)
|
2015-11-21 01:12:22 +00:00
|
|
|
#endif
|
2015-11-05 00:00:29 +00:00
|
|
|
{
|
2016-09-08 06:14:35 +00:00
|
|
|
logvisor::RegisterStandardExceptions();
|
2016-03-04 23:02:18 +00:00
|
|
|
logvisor::RegisterConsoleLogger();
|
2015-11-05 00:00:29 +00:00
|
|
|
boo::TestApplicationCallback appCb;
|
2015-11-21 01:12:22 +00:00
|
|
|
int ret = ApplicationRun(boo::IApplication::EPlatformType::Auto,
|
2018-10-07 02:49:22 +00:00
|
|
|
appCb, _SYS_STR("boo"), _SYS_STR("boo"), argc, argv, {}, 1, 1, true);
|
2015-11-05 00:00:29 +00:00
|
|
|
printf("IM DYING!!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2015-11-06 03:20:58 +00:00
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#else
|
2017-10-24 03:09:50 +00:00
|
|
|
using namespace Windows::ApplicationModel::Core;
|
|
|
|
|
|
|
|
[Platform::MTAThread]
|
|
|
|
int WINAPIV main(Platform::Array<Platform::String^>^ params)
|
|
|
|
{
|
|
|
|
logvisor::RegisterStandardExceptions();
|
|
|
|
logvisor::RegisterConsoleLogger();
|
|
|
|
boo::TestApplicationCallback appCb;
|
2017-12-06 03:20:59 +00:00
|
|
|
boo::ViewProvider^ viewProvider =
|
2018-10-14 19:59:19 +00:00
|
|
|
ref new boo::ViewProvider(appCb, _SYS_STR("boo"), _SYS_STR("boo"), _SYS_STR("boo"), params, false);
|
2017-10-24 03:09:50 +00:00
|
|
|
CoreApplication::Run(viewProvider);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-12-06 03:20:59 +00:00
|
|
|
#endif
|
2017-10-24 03:09:50 +00:00
|
|
|
|
2017-12-06 03:20:59 +00:00
|
|
|
#if _WIN32 && !WINDOWS_STORE
|
2015-11-06 03:20:58 +00:00
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
|
2015-11-05 00:00:29 +00:00
|
|
|
{
|
2015-11-06 03:20:58 +00:00
|
|
|
int argc = 0;
|
2018-05-28 20:23:20 +00:00
|
|
|
const boo::SystemChar** argv;
|
|
|
|
if (lpCmdLine[0])
|
|
|
|
argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc));
|
2015-11-07 01:43:12 +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];
|
2015-11-06 03:20:58 +00:00
|
|
|
|
2016-03-04 23:02:18 +00:00
|
|
|
logvisor::CreateWin32Console();
|
2018-05-28 20:23:20 +00:00
|
|
|
return wmain(argc + 1, booArgv);
|
2015-11-05 00:00:29 +00:00
|
|
|
}
|
|
|
|
#endif
|