boo/lib/nx/WindowNX.cpp

114 lines
4.2 KiB
C++
Raw Normal View History

2018-10-07 02:49:22 +00:00
#include "boo/IWindow.hpp"
2018-10-07 02:49:22 +00:00
#include "boo/IGraphicsContext.hpp"
#include "boo/graphicsdev/NX.hpp"
#include <logvisor/logvisor.hpp>
2018-10-07 02:49:22 +00:00
#include <switch.h>
2018-12-08 05:17:51 +00:00
namespace boo {
2018-10-07 02:49:22 +00:00
std::unique_ptr<IGraphicsCommandQueue> _NewNXCommandQueue(NXContext* ctx, IGraphicsContext* parent);
std::unique_ptr<IGraphicsDataFactory> _NewNXDataFactory(IGraphicsContext* parent, NXContext* ctx);
2018-12-08 05:17:51 +00:00
struct GraphicsContextNX : IGraphicsContext {
NXContext* m_nxCtx;
std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
2018-10-07 02:49:22 +00:00
public:
2018-12-08 05:17:51 +00:00
explicit GraphicsContextNX(NXContext* nxCtx) : m_nxCtx(nxCtx) {
m_dataFactory = _NewNXDataFactory(this, nxCtx);
m_commandQueue = _NewNXCommandQueue(nxCtx, this);
}
EGraphicsAPI getAPI() const override { return EGraphicsAPI::NX; }
EPixelFormat getPixelFormat() const override { return EPixelFormat::RGBA8; }
void setPixelFormat(EPixelFormat pf) override {}
bool initializeContext(void* handle) override { return m_nxCtx->initialize(); }
void makeCurrent() override {}
void postInit() override {}
void present() override {}
IGraphicsCommandQueue* getCommandQueue() override { return m_commandQueue.get(); }
IGraphicsDataFactory* getDataFactory() override { return m_dataFactory.get(); }
IGraphicsDataFactory* getMainContextDataFactory() override { return m_dataFactory.get(); }
IGraphicsDataFactory* getLoadContextDataFactory() override { return m_dataFactory.get(); }
2018-10-07 02:49:22 +00:00
};
2018-12-08 05:17:51 +00:00
class WindowNX : public IWindow {
std::string m_title;
std::unique_ptr<GraphicsContextNX> m_gfxCtx;
IWindowCallback* m_callback = nullptr;
2018-10-07 02:49:22 +00:00
public:
2018-12-08 05:17:51 +00:00
WindowNX(std::string_view title, NXContext* nxCtx) : m_title(title), m_gfxCtx(new GraphicsContextNX(nxCtx)) {
m_gfxCtx->initializeContext(nullptr);
}
void setCallback(IWindowCallback* cb) override { m_callback = cb; }
2018-12-08 05:17:51 +00:00
void closeWindow() override {}
void showWindow() override {}
void hideWindow() override {}
2018-12-08 05:17:51 +00:00
SystemString getTitle() override { return m_title; }
void setTitle(SystemStringView title) override { m_title = title; }
2018-12-08 05:17:51 +00:00
void setCursor(EMouseCursor cursor) override {}
void setWaitCursor(bool wait) override {}
2018-12-08 05:17:51 +00:00
void setWindowFrameDefault() override {}
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const override {
2018-12-08 05:17:51 +00:00
u32 width, height;
gfxGetFramebufferResolution(&width, &height);
xOut = 0;
yOut = 0;
wOut = width;
hOut = height;
}
void getWindowFrame(int& xOut, int& yOut, int& wOut, int& hOut) const override {
2018-12-08 05:17:51 +00:00
u32 width, height;
gfxGetFramebufferResolution(&width, &height);
xOut = 0;
yOut = 0;
wOut = width;
hOut = height;
}
void setWindowFrame(float x, float y, float w, float h) override {}
void setWindowFrame(int x, int y, int w, int h) override {}
float getVirtualPixelFactor() const override { return 1.f; }
2018-12-08 05:17:51 +00:00
bool isFullscreen() const override { return true; }
void setFullscreen(bool fs) override {}
2018-12-08 05:17:51 +00:00
void claimKeyboardFocus(const int coord[2]) override {}
bool clipboardCopy(EClipboardType type, const uint8_t* data, size_t sz) override { return false; }
std::unique_ptr<uint8_t[]> clipboardPaste(EClipboardType type, size_t& sz) override { return {}; }
2018-12-08 05:17:51 +00:00
void waitForRetrace() override {}
2018-12-08 05:17:51 +00:00
uintptr_t getPlatformHandle() const override { return 0; }
bool _incomingEvent([[maybe_unused]] void* event) override { return false; }
void _cleanup() override {}
2018-12-08 05:17:51 +00:00
ETouchType getTouchType() const override { return ETouchType::Display; }
2018-12-08 05:17:51 +00:00
void setStyle(EWindowStyle style) override {}
EWindowStyle getStyle() const override { return EWindowStyle::None; }
2018-12-08 05:17:51 +00:00
void setTouchBarProvider(void*) override {}
2018-12-08 05:17:51 +00:00
IGraphicsCommandQueue* getCommandQueue() override { return m_gfxCtx->getCommandQueue(); }
IGraphicsDataFactory* getDataFactory() override { return m_gfxCtx->getDataFactory(); }
IGraphicsDataFactory* getMainContextDataFactory() override { return m_gfxCtx->getMainContextDataFactory(); }
IGraphicsDataFactory* getLoadContextDataFactory() override { return m_gfxCtx->getLoadContextDataFactory(); }
2018-10-07 02:49:22 +00:00
};
2018-12-08 05:17:51 +00:00
std::shared_ptr<IWindow> _WindowNXNew(std::string_view title, NXContext* nxCtx) {
std::shared_ptr<IWindow> ret = std::make_shared<WindowNX>(title, nxCtx);
return ret;
2018-10-07 02:49:22 +00:00
}
2018-12-08 05:17:51 +00:00
} // namespace boo