2015-11-21 23:45:02 +00:00
|
|
|
#include "Specter/View.hpp"
|
2015-11-26 00:24:01 +00:00
|
|
|
#include "Specter/ViewSystem.hpp"
|
2015-11-21 23:45:02 +00:00
|
|
|
|
|
|
|
namespace Specter
|
|
|
|
{
|
|
|
|
|
2015-11-26 00:24:01 +00:00
|
|
|
void View::System::init(boo::GLDataFactory* factory)
|
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"#version 330\n"
|
|
|
|
"layout(location=0) in vec3 posIn;\n"
|
|
|
|
"layout(location=1) in vec4 colorIn;\n"
|
|
|
|
SPECTER_VIEW_VERT_BLOCK_GLSL
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"out VertToFrag vtf;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" vtf.color = colorIn;\n"
|
2015-11-26 23:03:56 +00:00
|
|
|
" gl_Position = mv * vec4(posIn, 1.0);\n"
|
2015-11-26 00:24:01 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS =
|
|
|
|
"#version 330\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"in VertToFrag vtf;\n"
|
|
|
|
"layout(location=0) out vec4 colorOut;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" colorOut = vtf.color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* BlockNames[] = {"SpecterViewBlock"};
|
|
|
|
|
|
|
|
m_solidShader = factory->newShaderPipeline(VS, FS, 0, nullptr, 1, BlockNames,
|
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
|
|
|
false, false, false);
|
|
|
|
}
|
|
|
|
|
2015-11-27 22:20:22 +00:00
|
|
|
void View::System::init(boo::ID3DDataFactory* factory)
|
|
|
|
{
|
|
|
|
static const char* VS =
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float3 posIn : POSITION;\n"
|
|
|
|
" float4 colorIn : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
SPECTER_VIEW_VERT_BLOCK_HLSL
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.color = v.colorIn;\n"
|
|
|
|
" vtf.position = mul(mv, float4(v.posIn, 1.0));\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS =
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
|
|
|
" return vtf.color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
boo::VertexElementDescriptor vdescs[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}
|
|
|
|
};
|
|
|
|
m_vtxFmt = factory->newVertexFormat(2, vdescs);
|
|
|
|
|
|
|
|
ComPtr<ID3DBlob> vertBlob;
|
|
|
|
ComPtr<ID3DBlob> fragBlob;
|
|
|
|
ComPtr<ID3DBlob> pipeBlob;
|
|
|
|
m_solidShader = factory->newShaderPipeline(VS, FS, vertBlob, fragBlob, pipeBlob, m_vtxFmt,
|
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
|
|
|
false, false, false);
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:24:01 +00:00
|
|
|
View::View(ViewSystem& system)
|
|
|
|
{
|
|
|
|
m_bgVertBuf =
|
|
|
|
system.m_factory->newDynamicBuffer(boo::BufferUse::Vertex,
|
|
|
|
sizeof(Zeus::CVector3f), 4);
|
|
|
|
|
|
|
|
m_bgInstBuf =
|
|
|
|
system.m_factory->newDynamicBuffer(boo::BufferUse::Vertex,
|
|
|
|
sizeof(Zeus::CColor), 1);
|
|
|
|
|
2015-11-26 07:35:43 +00:00
|
|
|
m_viewVertBlockBuf =
|
2015-11-26 00:24:01 +00:00
|
|
|
system.m_factory->newDynamicBuffer(boo::BufferUse::Uniform,
|
|
|
|
sizeof(VertexBlock), 1);
|
|
|
|
|
|
|
|
if (!system.m_viewSystem.m_vtxFmt)
|
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor vdescs[] =
|
|
|
|
{
|
2015-11-27 22:20:22 +00:00
|
|
|
{m_bgVertBuf, nullptr, boo::VertexSemantic::Position4},
|
2015-11-26 00:24:01 +00:00
|
|
|
{m_bgInstBuf, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}
|
|
|
|
};
|
|
|
|
m_bgVtxFmt = system.m_factory->newVertexFormat(2, vdescs);
|
|
|
|
m_bgShaderBinding =
|
|
|
|
system.m_factory->newShaderDataBinding(system.m_viewSystem.m_solidShader, m_bgVtxFmt,
|
|
|
|
m_bgVertBuf, m_bgInstBuf, nullptr, 1,
|
2015-11-26 07:35:43 +00:00
|
|
|
(boo::IGraphicsBuffer**)&m_viewVertBlockBuf,
|
2015-11-27 22:20:22 +00:00
|
|
|
0, nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bgShaderBinding =
|
|
|
|
system.m_factory->newShaderDataBinding(system.m_viewSystem.m_solidShader, system.m_viewSystem.m_vtxFmt,
|
|
|
|
m_bgVertBuf, m_bgInstBuf, nullptr, 1,
|
|
|
|
(boo::IGraphicsBuffer**)&m_viewVertBlockBuf,
|
2015-11-26 00:24:01 +00:00
|
|
|
0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-26 23:03:56 +00:00
|
|
|
m_viewVertBlock.setViewRect(root, sub);
|
|
|
|
m_bgRect[0].assign(0.f, sub.size[1], 0.f);
|
|
|
|
m_bgRect[1].assign(0.f, 0.f, 0.f);
|
|
|
|
m_bgRect[2].assign(sub.size[0], sub.size[1], 0.f);
|
|
|
|
m_bgRect[3].assign(sub.size[0], 0.f, 0.f);
|
2015-11-26 07:35:43 +00:00
|
|
|
m_bgValidSlots = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:24:01 +00:00
|
|
|
void View::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
|
|
|
int pendingSlot = 1 << gfxQ->pendingDynamicSlot();
|
2015-11-26 07:35:43 +00:00
|
|
|
if ((m_bgValidSlots & pendingSlot) == 0)
|
2015-11-26 00:24:01 +00:00
|
|
|
{
|
2015-11-26 07:35:43 +00:00
|
|
|
m_viewVertBlockBuf->load(&m_viewVertBlock, sizeof(VertexBlock));
|
2015-11-26 00:24:01 +00:00
|
|
|
m_bgVertBuf->load(m_bgRect, sizeof(Zeus::CVector3f) * 4);
|
|
|
|
m_bgInstBuf->load(&m_bgColor, sizeof(Zeus::CColor));
|
2015-11-26 07:35:43 +00:00
|
|
|
m_bgValidSlots |= pendingSlot;
|
2015-11-26 00:24:01 +00:00
|
|
|
}
|
2015-11-26 07:35:43 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_bgShaderBinding);
|
2015-11-26 23:03:56 +00:00
|
|
|
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
|
2015-11-26 00:24:01 +00:00
|
|
|
gfxQ->draw(0, 4);
|
|
|
|
}
|
|
|
|
|
2015-11-21 23:45:02 +00:00
|
|
|
}
|