metaforce/specter/lib/View.cpp

124 lines
4.4 KiB
C++
Raw Normal View History

2016-03-04 23:03:47 +00:00
#include "specter/View.hpp"
#include "specter/ViewResources.hpp"
#include "specter/RootView.hpp"
2018-10-07 02:58:28 +00:00
#include "hecl/Pipeline.hpp"
2015-11-21 23:45:02 +00:00
2016-03-04 23:03:47 +00:00
namespace specter
2015-11-21 23:45:02 +00:00
{
2016-03-04 23:03:47 +00:00
static logvisor::Module Log("specter::View");
2015-11-21 23:45:02 +00:00
zeus::CMatrix4f g_PlatformMatrix;
2018-10-07 02:58:28 +00:00
void View::Resources::init(boo::IGraphicsDataFactory::Context& ctx, const IThemeData& theme)
2016-02-23 02:33:59 +00:00
{
switch (ctx.platform())
{
case boo::IGraphicsDataFactory::Platform::Vulkan:
g_PlatformMatrix.m[1][1] = -1.f;
break;
default:
break;
}
2018-10-07 02:58:28 +00:00
m_solidShader = hecl::conv->convert(ctx, Shader_SpecterViewShaderSolid{});
m_texShader = hecl::conv->convert(ctx, Shader_SpecterViewShaderTex{});
2016-02-23 02:33:59 +00:00
}
2016-03-30 19:15:32 +00:00
void View::buildResources(boo::IGraphicsDataFactory::Context& ctx, ViewResources& res)
2015-11-26 00:24:01 +00:00
{
2017-01-29 03:57:48 +00:00
m_viewVertBlockBuf = res.m_viewRes.m_bufPool.allocateBlock(res.m_factory);
m_bgVertsBinding.init(ctx, res, 4, m_viewVertBlockBuf);
2015-11-29 02:55:30 +00:00
}
2015-12-29 02:02:43 +00:00
View::View(ViewResources& res)
: m_rootView(*static_cast<RootView*>(this)),
2016-03-30 19:15:32 +00:00
m_parentView(*static_cast<RootView*>(this)) {}
2015-11-26 00:24:01 +00:00
2015-12-29 02:02:43 +00:00
View::View(ViewResources& res, View& parentView)
2015-12-05 00:42:46 +00:00
: m_rootView(parentView.rootView()),
2016-03-30 19:15:32 +00:00
m_parentView(parentView) {}
2015-11-29 02:55:30 +00:00
void View::updateSize()
{
resized(m_rootView.rootRect(), m_subRect);
2015-11-26 00:24:01 +00:00
}
2015-11-26 23:03:56 +00:00
void View::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
2015-11-26 07:35:43 +00:00
{
2015-11-29 02:55:30 +00:00
m_subRect = sub;
2015-11-26 23:03:56 +00:00
m_viewVertBlock.setViewRect(root, sub);
2015-12-05 00:42:46 +00:00
m_bgRect[0].m_pos.assign(0.f, sub.size[1], 0.f);
m_bgRect[1].m_pos.assign(0.f, 0.f, 0.f);
m_bgRect[2].m_pos.assign(sub.size[0], sub.size[1], 0.f);
m_bgRect[3].m_pos.assign(sub.size[0], 0.f, 0.f);
2016-03-30 19:15:32 +00:00
if (m_viewVertBlockBuf)
m_viewVertBlockBuf.access().finalAssign(m_viewVertBlock);
m_bgVertsBinding.load<decltype(m_bgRect)>(m_bgRect);
2015-11-26 07:35:43 +00:00
}
void View::resized(const ViewBlock& vb, const boo::SWindowRect& sub)
{
m_subRect = sub;
m_bgRect[0].m_pos.assign(0.f, sub.size[1], 0.f);
m_bgRect[1].m_pos.assign(0.f, 0.f, 0.f);
m_bgRect[2].m_pos.assign(sub.size[0], sub.size[1], 0.f);
m_bgRect[3].m_pos.assign(sub.size[0], 0.f, 0.f);
2016-03-30 19:15:32 +00:00
if (m_viewVertBlockBuf)
m_viewVertBlockBuf.access().finalAssign(vb);
m_bgVertsBinding.load<decltype(m_bgRect)>(m_bgRect);
}
2015-11-26 00:24:01 +00:00
void View::draw(boo::IGraphicsCommandQueue* gfxQ)
{
2016-03-30 19:15:32 +00:00
if (m_bgVertsBinding.m_shaderBinding)
{
gfxQ->setShaderDataBinding(m_bgVertsBinding);
gfxQ->draw(0, 4);
}
2015-11-26 00:24:01 +00:00
}
2016-03-30 19:15:32 +00:00
void View::commitResources(ViewResources& res, const boo::FactoryCommitFunc& commitFunc)
2015-11-30 00:21:42 +00:00
{
res.m_factory->commitTransaction(commitFunc BooTrace);
2015-11-30 00:21:42 +00:00
}
2016-02-24 20:28:37 +00:00
void View::VertexBufferBindingSolid::init(boo::IGraphicsDataFactory::Context& ctx,
2016-03-30 19:15:32 +00:00
ViewResources& res, size_t count,
const hecl::UniformBufferPool<ViewBlock>::Token& viewBlockBuf)
{
2017-01-29 03:57:48 +00:00
m_vertsBuf = res.m_viewRes.m_solidPool.allocateBlock(res.m_factory, count);
auto vBufInfo = m_vertsBuf.getBufferInfo();
auto uBufInfo = viewBlockBuf.getBufferInfo();
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {uBufInfo.first.get()};
2016-12-11 01:53:39 +00:00
size_t bufOffs[] = {size_t(uBufInfo.second)};
size_t bufSizes[] = {sizeof(ViewBlock)};
2016-02-24 20:28:37 +00:00
2018-10-07 02:58:28 +00:00
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_solidShader,
vBufInfo.first.get(), nullptr,
nullptr, 1, bufs, nullptr, bufOffs,
bufSizes, 0, nullptr, nullptr, nullptr, vBufInfo.second);
}
2016-02-24 20:28:37 +00:00
void View::VertexBufferBindingTex::init(boo::IGraphicsDataFactory::Context& ctx,
2016-03-30 19:15:32 +00:00
ViewResources& res, size_t count,
const hecl::UniformBufferPool<ViewBlock>::Token& viewBlockBuf,
const boo::ObjToken<boo::ITexture>& texture)
{
2017-01-29 03:57:48 +00:00
m_vertsBuf = res.m_viewRes.m_texPool.allocateBlock(res.m_factory, count);
auto vBufInfo = m_vertsBuf.getBufferInfo();
auto uBufInfo = viewBlockBuf.getBufferInfo();
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {uBufInfo.first.get()};
2016-12-11 01:53:39 +00:00
size_t bufOffs[] = {size_t(uBufInfo.second)};
size_t bufSizes[] = {sizeof(ViewBlock)};
boo::ObjToken<boo::ITexture> tex[] = {texture};
2016-02-24 20:28:37 +00:00
2018-10-07 02:58:28 +00:00
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_texShader,
vBufInfo.first.get(), nullptr,
nullptr, 1, bufs, nullptr, bufOffs,
bufSizes, 1, tex, nullptr, nullptr, vBufInfo.second);
}
2015-11-30 00:21:42 +00:00
2015-11-21 23:45:02 +00:00
}