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