D3D11/12 support

This commit is contained in:
Jack Andersen 2015-11-27 12:20:22 -10:00
parent ecbed6e82c
commit a800ff73ee
6 changed files with 181 additions and 6 deletions

@ -1 +1 @@
Subproject commit a13928491e6a4da070b7767e744511203f47b59c
Subproject commit f075c38a4cb65ce4d1e812a308de45b41cb88eb8

View File

@ -42,6 +42,11 @@ protected:
"{\n"\
" mat4 mv;\n"\
"};\n"
#define SPECTER_VIEW_VERT_BLOCK_HLSL\
"cbuffer SpecterViewBlock : register(b0)\n"\
"{\n"\
" float4x4 mv;\n"\
"};\n"
boo::IGraphicsBufferD* m_viewVertBlockBuf;
public:

View File

@ -1,3 +1,7 @@
#ifndef NOMINMAX
#define NOMINMAX 1
#endif
#include "Specter/FontCache.hpp"
#include <LogVisor/LogVisor.hpp>
#include <Athena/MemoryReader.hpp>
@ -16,7 +20,7 @@ extern "C" size_t DROIDSANS_PERMISSIVE_SZ;
extern "C" const uint8_t BMONOFONT[];
extern "C" size_t BMONOFONT_SZ;
extern const FT_Driver_ClassRec tt_driver_class;
extern "C" const FT_Driver_ClassRec tt_driver_class;
namespace Specter
{
@ -574,7 +578,7 @@ FontTag FontCache::prepCustomFont(boo::IGraphicsDataFactory* gf,
return tag;
/* Now check filesystem cache */
HECL::SystemString cachePath = m_cacheRoot + _S('/') + HECL::Format("%" PRIx64, tag.hash());
HECL::SystemString cachePath = m_cacheRoot + _S('/') + HECL::SysFormat(_S("%" PRIx64), tag.hash());
#if 0
HECL::Sstat st;
if (!HECL::Stat(cachePath.c_str(), &st) && S_ISREG(st.st_mode))
@ -582,7 +586,7 @@ FontTag FontCache::prepCustomFont(boo::IGraphicsDataFactory* gf,
Athena::io::FileReader r(cachePath);
if (!r.hasError())
{
atUint32 magic = r.readUint32Big();
atUint32 magic = r.readUint32Big();b
if (r.position() == 4 && magic == 'FONT')
{
m_cachedAtlases.emplace(tag, std::make_unique<FontAtlas>(gf, face, dpi, subpixel, r));

View File

@ -28,7 +28,7 @@ void RootView::resized(const boo::SWindowRect& rect)
resized(rect, rect);
}
void RootView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
void RootView::resized(const boo::SWindowRect& root, const boo::SWindowRect&)
{
m_rootRect = root;
m_rootRect.location[0] = 0;
@ -114,6 +114,7 @@ void RootView::draw(boo::IGraphicsCommandQueue* gfxQ)
}
gfxQ->setRenderTarget(m_renderTex);
gfxQ->setViewport(m_rootRect);
gfxQ->setScissor(m_rootRect);
View::draw(gfxQ);
m_textView.draw(gfxQ);
gfxQ->resolveDisplay(m_renderTex);

View File

@ -79,6 +79,107 @@ void TextView::System::init(boo::GLDataFactory* factory, FontCache* fcache)
false, false, false);
}
void TextView::System::init(boo::ID3DDataFactory* factory, FontCache* fcache)
{
m_fcache = fcache;
static const char* VS =
"struct VertData\n"
"{\n"
" float3 posIn[4] : POSITION;\n"
" float4x4 mvMtx : MODELVIEW;\n"
" float3 uvIn[4] : UV;\n"
" float4 colorIn : COLOR;\n"
"};\n"
SPECTER_VIEW_VERT_BLOCK_HLSL
"struct VertToFrag\n"
"{\n"
" float4 position : SV_Position;\n"
" float3 uv : UV;\n"
" float4 color : COLOR;\n"
"};\n"
"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n"
"{\n"
" VertToFrag vtf;\n"
" vtf.uv = v.uvIn[vertId];\n"
" vtf.color = v.colorIn;\n"
" vtf.position = mul(mv, mul(v.mvMtx, float4(v.posIn[vertId], 1.0)));\n"
" return vtf;\n"
"}\n";
static const char* FSReg =
"Texture2DArray fontTex : register(t0);\n"
"SamplerState samp : register(s0);\n"
"struct VertToFrag\n"
"{\n"
" float4 position : SV_Position;\n"
" float3 uv : UV;\n"
" float4 color : COLOR;\n"
"};\n"
"float4 main(in VertToFrag vtf) : SV_Target0\n"
"{\n"
" float4 colorOut = vtf.color;\n"
" colorOut.a = fontTex.Sample(samp, vtf.uv).r;\n"
" return colorOut;\n"
"}\n";
static const char* FSSubpixel =
"Texture2DArray fontTex : register(t0);\n"
"SamplerState samp : register(s0);\n"
"struct VertToFrag\n"
"{\n"
" float4 position : SV_Position;\n"
" float3 uv : UV;\n"
" float4 color : COLOR;\n"
"};\n"
"struct BlendOut\n"
"{\n"
" float4 colorOut : SV_Target0;\n"
" float4 blendOut : SV_Target1;\n"
"};\n"
"BlendOut main(in VertToFrag vtf)\n"
"{\n"
" BlendOut ret;\n"
" ret.colorOut = vtf.color;\n"
" ret.blendOut = fontTex.Sample(samp, vtf.uv);\n"
" return ret;\n"
"}\n";
boo::VertexElementDescriptor vdescs[] =
{
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0},
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1},
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2},
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3},
{nullptr, nullptr, boo::VertexSemantic::ModelView | boo::VertexSemantic::Instanced, 0},
{nullptr, nullptr, boo::VertexSemantic::ModelView | boo::VertexSemantic::Instanced, 1},
{nullptr, nullptr, boo::VertexSemantic::ModelView | boo::VertexSemantic::Instanced, 2},
{nullptr, nullptr, boo::VertexSemantic::ModelView | boo::VertexSemantic::Instanced, 3},
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0},
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1},
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2},
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3},
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}
};
m_vtxFmt = factory->newVertexFormat(13, vdescs);
ComPtr<ID3DBlob> blobVert;
ComPtr<ID3DBlob> blobFrag;
ComPtr<ID3DBlob> blobPipe;
m_regular =
factory->newShaderPipeline(VS, FSReg, blobVert, blobFrag, blobPipe, m_vtxFmt,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
false, false, false);
blobVert.Reset();
blobFrag.Reset();
blobPipe.Reset();
m_subpixel =
factory->newShaderPipeline(VS, FSSubpixel, blobVert, blobFrag, blobPipe, m_vtxFmt,
boo::BlendFactor::SrcColor1, boo::BlendFactor::InvSrcColor1,
false, false, false);
}
TextView::TextView(ViewSystem& system, FontTag font, size_t capacity)
: View(system),
m_capacity(capacity),
@ -113,6 +214,14 @@ TextView::TextView(ViewSystem& system, FontTag font, size_t capacity)
(boo::IGraphicsBuffer**)&m_viewVertBlockBuf,
1, texs);
}
else
{
boo::ITexture* texs[] = {m_fontAtlas.texture()};
m_shaderBinding = system.m_factory->newShaderDataBinding(system.m_textSystem.m_regular, system.m_textSystem.m_vtxFmt,
nullptr, m_glyphBuf, nullptr, 1,
(boo::IGraphicsBuffer**)&m_viewVertBlockBuf,
1, texs);
}
m_glyphs.reserve(capacity);
}

View File

@ -42,6 +42,54 @@ void View::System::init(boo::GLDataFactory* factory)
false, false, false);
}
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);
}
View::View(ViewSystem& system)
{
m_bgVertBuf =
@ -60,7 +108,7 @@ View::View(ViewSystem& system)
{
boo::VertexElementDescriptor vdescs[] =
{
{m_bgVertBuf, nullptr, boo::VertexSemantic::Position4, 0},
{m_bgVertBuf, nullptr, boo::VertexSemantic::Position4},
{m_bgInstBuf, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}
};
m_bgVtxFmt = system.m_factory->newVertexFormat(2, vdescs);
@ -70,6 +118,14 @@ View::View(ViewSystem& system)
(boo::IGraphicsBuffer**)&m_viewVertBlockBuf,
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,
0, nullptr);
}
}