2016-03-04 23:03:47 +00:00
|
|
|
#include "specter/View.hpp"
|
|
|
|
#include "specter/ViewResources.hpp"
|
|
|
|
#include "specter/RootView.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
|
|
|
|
2017-12-06 03:25:33 +00:00
|
|
|
#if BOO_HAS_GL
|
2016-02-23 02:33:59 +00:00
|
|
|
static const char* GLSLSolidVS =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-23 02:33:59 +00:00
|
|
|
"layout(location=0) in vec3 posIn;\n"
|
|
|
|
"layout(location=1) in vec4 colorIn;\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
SPECTER_GLSL_VIEW_VERT_BLOCK
|
2016-02-23 02:33:59 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
"SBINDING(0) out VertToFrag vtf;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" vtf.color = colorIn * mulColor;\n"
|
|
|
|
" gl_Position = mv * vec4(posIn, 1.0);\n"
|
2016-07-02 03:45:47 +00:00
|
|
|
" gl_Position = FLIPFROMGL(gl_Position);\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"}\n";
|
2015-11-26 00:24:01 +00:00
|
|
|
|
2016-02-23 02:33:59 +00:00
|
|
|
static const char* GLSLSolidFS =
|
|
|
|
"#version 330\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-23 02:33:59 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
|
|
|
"};\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
"SBINDING(0) in VertToFrag vtf;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"layout(location=0) out vec4 colorOut;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
|
|
|
" colorOut = vtf.color;\n"
|
|
|
|
"}\n";
|
2015-11-26 00:24:01 +00:00
|
|
|
|
2016-02-23 02:33:59 +00:00
|
|
|
static const char* GLSLTexVS =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-23 02:33:59 +00:00
|
|
|
"layout(location=0) in vec3 posIn;\n"
|
|
|
|
"layout(location=1) in vec2 uvIn;\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
SPECTER_GLSL_VIEW_VERT_BLOCK
|
2016-02-23 02:33:59 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
" vec4 uv;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"};\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
"SBINDING(0) out VertToFrag vtf;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
" vtf.uv.xy = uvIn;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
" vtf.color = mulColor;\n"
|
|
|
|
" gl_Position = mv * vec4(posIn, 1.0);\n"
|
2016-07-02 03:45:47 +00:00
|
|
|
" gl_Position = FLIPFROMGL(gl_Position);\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"}\n";
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2016-02-23 02:33:59 +00:00
|
|
|
static const char* GLSLTexFS =
|
|
|
|
"#version 330\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
BOO_GLSL_BINDING_HEAD
|
2016-02-23 02:33:59 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" vec4 color;\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
" vec4 uv;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"};\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
"SBINDING(0) in VertToFrag vtf;\n"
|
2016-02-24 03:19:07 +00:00
|
|
|
"TBINDING0 uniform sampler2D tex;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"layout(location=0) out vec4 colorOut;\n"
|
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2016-07-01 02:32:50 +00:00
|
|
|
" colorOut = texture(tex, vtf.uv.xy) * vtf.color;\n"
|
2016-02-23 02:33:59 +00:00
|
|
|
"}\n";
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2016-04-15 03:25:50 +00:00
|
|
|
static const char* BlockNames[] = {"SpecterViewBlock"};
|
2016-07-08 00:06:42 +00:00
|
|
|
static const char* TexNames[] = {"tex"};
|
2016-04-15 03:25:50 +00:00
|
|
|
|
2016-03-30 19:15:32 +00:00
|
|
|
void View::Resources::init(boo::GLDataFactory::Context& ctx, const IThemeData& theme)
|
2016-02-23 02:33:59 +00:00
|
|
|
{
|
2016-03-30 19:15:32 +00:00
|
|
|
m_solidShader = ctx.newShaderPipeline(GLSLSolidVS, GLSLSolidFS, 0, nullptr, 1, BlockNames,
|
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-14 07:02:24 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, false,
|
|
|
|
boo::CullMode::None);
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2016-07-08 00:06:42 +00:00
|
|
|
m_texShader = ctx.newShaderPipeline(GLSLTexVS, GLSLTexFS, 1, TexNames, 1, BlockNames,
|
2016-03-30 19:15:32 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-14 07:02:24 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, false,
|
|
|
|
boo::CullMode::None);
|
2015-11-26 00:24:01 +00:00
|
|
|
}
|
2017-12-06 03:25:33 +00:00
|
|
|
#endif
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2015-11-28 04:05:27 +00:00
|
|
|
#if _WIN32
|
2015-11-26 00:24:01 +00:00
|
|
|
|
2016-03-30 20:43:49 +00:00
|
|
|
void View::Resources::init(boo::ID3DDataFactory::Context& ctx, const IThemeData& theme)
|
2015-11-27 22:20:22 +00:00
|
|
|
{
|
2015-11-30 00:21:42 +00:00
|
|
|
static const char* SolidVS =
|
2015-11-27 22:20:22 +00:00
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float3 posIn : POSITION;\n"
|
|
|
|
" float4 colorIn : COLOR;\n"
|
|
|
|
"};\n"
|
2016-02-24 20:28:37 +00:00
|
|
|
SPECTER_HLSL_VIEW_VERT_BLOCK
|
2015-11-27 22:20:22 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" vtf.color = v.colorIn * mulColor;\n"
|
2015-11-27 22:20:22 +00:00
|
|
|
" vtf.position = mul(mv, float4(v.posIn, 1.0));\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
2015-11-30 00:21:42 +00:00
|
|
|
static const char* SolidFS =
|
2015-11-27 22:20:22 +00:00
|
|
|
"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";
|
|
|
|
|
2015-11-30 00:21:42 +00:00
|
|
|
static const char* TexVS =
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float3 posIn : POSITION;\n"
|
|
|
|
" float2 uvIn : UV;\n"
|
|
|
|
"};\n"
|
2016-02-24 20:28:37 +00:00
|
|
|
SPECTER_HLSL_VIEW_VERT_BLOCK
|
2015-11-30 00:21:42 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" float4 color : COLOR;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.uv = v.uvIn;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" vtf.color = mulColor;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" vtf.position = mul(mv, float4(v.posIn, 1.0));\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* TexFS =
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" float4 color : COLOR;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"Texture2D tex : register(t0);\n"
|
|
|
|
"SamplerState samp : register(s0);\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" return tex.Sample(samp, vtf.uv) * vtf.color;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
"}\n";
|
|
|
|
|
2015-11-30 03:41:53 +00:00
|
|
|
boo::VertexElementDescriptor solidvdescs[] =
|
2015-11-27 22:20:22 +00:00
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
2015-12-05 00:42:46 +00:00
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color}
|
2015-11-27 22:20:22 +00:00
|
|
|
};
|
2016-03-30 20:43:49 +00:00
|
|
|
m_solidVtxFmt = ctx.newVertexFormat(2, solidvdescs);
|
2015-11-27 22:20:22 +00:00
|
|
|
|
2017-03-05 23:01:57 +00:00
|
|
|
m_solidShader = ctx.newShaderPipeline(SolidVS, SolidFS, nullptr, nullptr, nullptr, m_solidVtxFmt,
|
2016-03-30 20:43:49 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:31:16 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, true, boo::CullMode::None);
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2015-11-30 03:41:53 +00:00
|
|
|
boo::VertexElementDescriptor texvdescs[] =
|
2015-11-30 00:21:42 +00:00
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
2016-03-30 20:43:49 +00:00
|
|
|
m_texVtxFmt = ctx.newVertexFormat(2, texvdescs);
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2017-03-05 23:01:57 +00:00
|
|
|
m_texShader = ctx.newShaderPipeline(TexVS, TexFS, nullptr, nullptr, nullptr, m_texVtxFmt,
|
2016-03-30 20:43:49 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:31:16 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, true, boo::CullMode::None);
|
2015-11-27 22:20:22 +00:00
|
|
|
}
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-02-23 02:33:59 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-03-30 20:43:49 +00:00
|
|
|
void View::Resources::init(boo::MetalDataFactory::Context& ctx, const IThemeData& theme)
|
2015-11-28 04:05:27 +00:00
|
|
|
{
|
2015-11-30 00:21:42 +00:00
|
|
|
static const char* SolidVS =
|
2015-11-28 04:05:27 +00:00
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float3 posIn [[ attribute(0) ]];\n"
|
|
|
|
" float4 colorIn [[ attribute(1) ]];\n"
|
|
|
|
"};\n"
|
2016-02-24 21:07:25 +00:00
|
|
|
SPECTER_METAL_VIEW_VERT_BLOCK
|
2015-11-28 04:05:27 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position [[ position ]];\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SpecterViewBlock& view [[ buffer(2) ]])\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" vtf.color = v.colorIn * view.mulColor;\n"
|
2015-11-28 04:05:27 +00:00
|
|
|
" vtf.position = view.mv * float4(v.posIn, 1.0);\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2015-11-30 00:21:42 +00:00
|
|
|
static const char* SolidFS =
|
2015-11-28 04:05:27 +00:00
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position [[ position ]];\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n"
|
|
|
|
"{\n"
|
|
|
|
" return vtf.color;\n"
|
|
|
|
"}\n";
|
2015-11-30 00:21:42 +00:00
|
|
|
|
|
|
|
static const char* TexVS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float3 posIn [[ attribute(0) ]];\n"
|
|
|
|
" float2 uvIn [[ attribute(1) ]];\n"
|
|
|
|
"};\n"
|
2016-02-24 21:07:25 +00:00
|
|
|
SPECTER_METAL_VIEW_VERT_BLOCK
|
2015-11-30 00:21:42 +00:00
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position [[ position ]];\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" float4 color;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" float2 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SpecterViewBlock& view [[ buffer(2) ]])\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.uv = v.uvIn;\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" vtf.color = view.mulColor;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" vtf.position = view.mv * float4(v.posIn, 1.0);\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* TexFS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position [[ position ]];\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" float4 color;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
" float2 uv;\n"
|
|
|
|
"};\n"
|
2018-01-07 05:19:23 +00:00
|
|
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
|
|
|
" sampler samp [[ sampler(0) ]],\n"
|
|
|
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
"{\n"
|
2015-12-15 21:53:15 +00:00
|
|
|
" return tex.sample(samp, vtf.uv) * vtf.color;\n"
|
2015-11-30 00:21:42 +00:00
|
|
|
"}\n";
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2015-11-30 03:41:53 +00:00
|
|
|
boo::VertexElementDescriptor solidvdescs[] =
|
2015-11-28 04:05:27 +00:00
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
2015-12-05 00:42:46 +00:00
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color}
|
2015-11-28 04:05:27 +00:00
|
|
|
};
|
2016-03-30 21:08:29 +00:00
|
|
|
m_solidVtxFmt = ctx.newVertexFormat(2, solidvdescs);
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2018-01-07 05:19:23 +00:00
|
|
|
m_solidShader = ctx.newShaderPipeline(SolidVS, SolidFS, nullptr, nullptr, m_solidVtxFmt,
|
2016-03-30 21:08:29 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-12-20 06:06:21 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None);
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2015-11-30 03:41:53 +00:00
|
|
|
boo::VertexElementDescriptor texvdescs[] =
|
2015-11-30 00:21:42 +00:00
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
2016-03-30 21:08:29 +00:00
|
|
|
m_texVtxFmt = ctx.newVertexFormat(2, texvdescs);
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2018-01-07 05:19:23 +00:00
|
|
|
m_texShader = ctx.newShaderPipeline(TexVS, TexFS, nullptr, nullptr, m_texVtxFmt,
|
2016-03-30 21:08:29 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-12-20 06:06:21 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None);
|
2015-11-28 04:05:27 +00:00
|
|
|
}
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-02-23 02:33:59 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
|
|
|
|
2016-03-30 19:15:32 +00:00
|
|
|
void View::Resources::init(boo::VulkanDataFactory::Context& ctx, const IThemeData& theme)
|
2016-02-23 02:33:59 +00:00
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor solidvdescs[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color}
|
|
|
|
};
|
2016-03-30 19:15:32 +00:00
|
|
|
m_solidVtxFmt = ctx.newVertexFormat(2, solidvdescs);
|
2016-02-23 02:33:59 +00:00
|
|
|
|
2016-03-30 19:15:32 +00:00
|
|
|
m_solidShader = ctx.newShaderPipeline(GLSLSolidVS, GLSLSolidFS, m_solidVtxFmt,
|
2016-07-01 02:32:50 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:31:16 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, true, boo::CullMode::None);
|
2016-02-23 02:33:59 +00:00
|
|
|
|
|
|
|
boo::VertexElementDescriptor texvdescs[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
2016-03-30 19:15:32 +00:00
|
|
|
m_texVtxFmt = ctx.newVertexFormat(2, texvdescs);
|
2016-02-23 02:33:59 +00:00
|
|
|
|
2016-03-30 19:15:32 +00:00
|
|
|
m_texShader = ctx.newShaderPipeline(GLSLTexVS, GLSLTexFS, m_texVtxFmt,
|
2016-07-01 02:32:50 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-17 23:31:16 +00:00
|
|
|
boo::Primitive::TriStrips, boo::ZTest::None, false, true, true, boo::CullMode::None);
|
2016-02-23 02:33:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 04:05:27 +00:00
|
|
|
#endif
|
2015-11-27 22:20:22 +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)
|
2015-12-03 03:26:50 +00:00
|
|
|
: 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)
|
2017-01-29 03:57:48 +00:00
|
|
|
m_viewVertBlockBuf.access() = m_viewVertBlock;
|
2016-12-10 02:33:54 +00:00
|
|
|
m_bgVertsBinding.load<decltype(m_bgRect)>(m_bgRect);
|
2015-11-26 07:35:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 06:40:23 +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)
|
2017-01-29 03:57:48 +00:00
|
|
|
m_viewVertBlockBuf.access() = vb;
|
2016-12-10 02:33:54 +00:00
|
|
|
m_bgVertsBinding.load<decltype(m_bgRect)>(m_bgRect);
|
2016-01-10 06:40:23 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-05-20 06:13:54 +00:00
|
|
|
res.m_factory->BooCommitTransaction(commitFunc);
|
2015-11-30 00:21:42 +00:00
|
|
|
}
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-12-10 02:33:54 +00:00
|
|
|
void View::VertexBufferBindingSolid::init(boo::IGraphicsDataFactory::Context& ctx,
|
2016-03-30 19:15:32 +00:00
|
|
|
ViewResources& res, size_t count,
|
2016-12-12 20:10:32 +00:00
|
|
|
const hecl::UniformBufferPool<ViewBlock>::Token& viewBlockBuf)
|
2016-01-08 00:06:21 +00:00
|
|
|
{
|
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();
|
2016-12-10 02:33:54 +00:00
|
|
|
auto uBufInfo = viewBlockBuf.getBufferInfo();
|
|
|
|
|
2017-11-05 06:16:45 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {uBufInfo.first.get()};
|
2016-12-11 01:53:39 +00:00
|
|
|
size_t bufOffs[] = {size_t(uBufInfo.second)};
|
2016-12-10 02:33:54 +00:00
|
|
|
size_t bufSizes[] = {sizeof(ViewBlock)};
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
if (!res.m_viewRes.m_solidVtxFmt)
|
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor vdescs[] =
|
|
|
|
{
|
2017-11-05 06:16:45 +00:00
|
|
|
{vBufInfo.first.get(), nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{vBufInfo.first.get(), nullptr, boo::VertexSemantic::Color}
|
2016-01-08 00:06:21 +00:00
|
|
|
};
|
2016-12-10 02:33:54 +00:00
|
|
|
m_vtxFmt = ctx.newVertexFormat(2, vdescs, vBufInfo.second);
|
2016-03-30 19:15:32 +00:00
|
|
|
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_solidShader,
|
2017-11-05 06:16:45 +00:00
|
|
|
m_vtxFmt, vBufInfo.first.get(), nullptr,
|
2016-12-10 02:33:54 +00:00
|
|
|
nullptr, 1, bufs, nullptr, bufOffs,
|
2017-03-14 07:02:24 +00:00
|
|
|
bufSizes, 0, nullptr, nullptr, nullptr, vBufInfo.second);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-30 19:15:32 +00:00
|
|
|
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_solidShader,
|
|
|
|
res.m_viewRes.m_solidVtxFmt,
|
2017-11-05 06:16:45 +00:00
|
|
|
vBufInfo.first.get(), nullptr,
|
2016-12-10 02:33:54 +00:00
|
|
|
nullptr, 1, bufs, nullptr, bufOffs,
|
2017-03-14 07:02:24 +00:00
|
|
|
bufSizes, 0, nullptr, nullptr, nullptr, vBufInfo.second);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-12-10 02:33:54 +00:00
|
|
|
void View::VertexBufferBindingTex::init(boo::IGraphicsDataFactory::Context& ctx,
|
2016-03-30 19:15:32 +00:00
|
|
|
ViewResources& res, size_t count,
|
2016-12-12 20:10:32 +00:00
|
|
|
const hecl::UniformBufferPool<ViewBlock>::Token& viewBlockBuf,
|
2017-11-05 06:16:45 +00:00
|
|
|
const boo::ObjToken<boo::ITexture>& texture)
|
2016-01-08 00:06:21 +00:00
|
|
|
{
|
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();
|
2016-12-10 02:33:54 +00:00
|
|
|
auto uBufInfo = viewBlockBuf.getBufferInfo();
|
|
|
|
|
2017-11-05 06:16:45 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {uBufInfo.first.get()};
|
2016-12-11 01:53:39 +00:00
|
|
|
size_t bufOffs[] = {size_t(uBufInfo.second)};
|
2016-12-10 02:33:54 +00:00
|
|
|
size_t bufSizes[] = {sizeof(ViewBlock)};
|
2017-11-05 06:16:45 +00:00
|
|
|
boo::ObjToken<boo::ITexture> tex[] = {texture};
|
2016-02-24 20:28:37 +00:00
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
if (!res.m_viewRes.m_texVtxFmt)
|
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor vdescs[] =
|
|
|
|
{
|
2017-11-05 06:16:45 +00:00
|
|
|
{vBufInfo.first.get(), nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{vBufInfo.first.get(), nullptr, boo::VertexSemantic::UV4}
|
2016-01-08 00:06:21 +00:00
|
|
|
};
|
2016-12-10 02:33:54 +00:00
|
|
|
m_vtxFmt = ctx.newVertexFormat(2, vdescs, vBufInfo.second);
|
2016-03-30 19:15:32 +00:00
|
|
|
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_texShader,
|
2017-11-05 06:16:45 +00:00
|
|
|
m_vtxFmt, vBufInfo.first.get(), nullptr,
|
2016-12-10 02:33:54 +00:00
|
|
|
nullptr, 1, bufs, nullptr, bufOffs,
|
2017-03-14 07:02:24 +00:00
|
|
|
bufSizes, 1, tex, nullptr, nullptr, vBufInfo.second);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-30 19:15:32 +00:00
|
|
|
m_shaderBinding = ctx.newShaderDataBinding(res.m_viewRes.m_texShader,
|
|
|
|
res.m_viewRes.m_texVtxFmt,
|
2017-11-05 06:16:45 +00:00
|
|
|
vBufInfo.first.get(), nullptr,
|
2016-12-10 02:33:54 +00:00
|
|
|
nullptr, 1, bufs, nullptr, bufOffs,
|
2017-03-14 07:02:24 +00:00
|
|
|
bufSizes, 1, tex, nullptr, nullptr, vBufInfo.second);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-30 00:21:42 +00:00
|
|
|
|
2015-11-21 23:45:02 +00:00
|
|
|
}
|