working composite
This commit is contained in:
parent
2de32140be
commit
87a686d090
6 changed files with 83 additions and 56 deletions
|
@ -436,9 +436,9 @@ namespace K::Graphics {
|
||||||
static f32 pack[4]{};
|
static f32 pack[4]{};
|
||||||
pack[0] = static_cast<f32>(mode);
|
pack[0] = static_cast<f32>(mode);
|
||||||
|
|
||||||
bgfx::touch(K::Graphics::K_VIEW_DRAW);
|
bgfx::touch(K::Graphics::K_VIEW_COMP_COMPOSITE);
|
||||||
bgfx::setViewMode(K::Graphics::K_VIEW_DRAW, bgfx::ViewMode::Sequential);
|
bgfx::setViewMode(K::Graphics::K_VIEW_COMP_COMPOSITE, bgfx::ViewMode::Sequential);
|
||||||
bgfx::setViewClear(K::Graphics::K_VIEW_DRAW, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
bgfx::setViewClear(K::Graphics::K_VIEW_COMP_COMPOSITE, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
||||||
bgfx::setViewFrameBuffer(K::Graphics::K_VIEW_COMP_COMPOSITE, fb);
|
bgfx::setViewFrameBuffer(K::Graphics::K_VIEW_COMP_COMPOSITE, fb);
|
||||||
bgfx::setViewTransform(K::Graphics::K_VIEW_COMP_COMPOSITE, composite_view, proj);
|
bgfx::setViewTransform(K::Graphics::K_VIEW_COMP_COMPOSITE, composite_view, proj);
|
||||||
bgfx::setViewRect(K::Graphics::K_VIEW_COMP_COMPOSITE, 0, 0, w, h);
|
bgfx::setViewRect(K::Graphics::K_VIEW_COMP_COMPOSITE, 0, 0, w, h);
|
||||||
|
@ -447,7 +447,7 @@ namespace K::Graphics {
|
||||||
bgfx::setVertexBuffer(0, vbh);
|
bgfx::setVertexBuffer(0, vbh);
|
||||||
bgfx::setIndexBuffer(ibh);
|
bgfx::setIndexBuffer(ibh);
|
||||||
bgfx::setTexture(0, composite_A, composite);
|
bgfx::setTexture(0, composite_A, composite);
|
||||||
bgfx::setTexture(0, composite_B, from);
|
bgfx::setTexture(1, composite_B, from);
|
||||||
bgfx::setUniform(composite_mode, pack);
|
bgfx::setUniform(composite_mode, pack);
|
||||||
bgfx::setState((BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS));
|
bgfx::setState((BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS));
|
||||||
bgfx::submit(K::Graphics::K_VIEW_COMP_COMPOSITE, composite_pg);
|
bgfx::submit(K::Graphics::K_VIEW_COMP_COMPOSITE, composite_pg);
|
||||||
|
|
|
@ -95,8 +95,10 @@ namespace K {
|
||||||
UI::Draw(state);
|
UI::Draw(state);
|
||||||
|
|
||||||
const bgfx::Stats* stat = bgfx::getStats();
|
const bgfx::Stats* stat = bgfx::getStats();
|
||||||
|
const bgfx::Caps* caps = bgfx::getCaps();
|
||||||
bgfx::dbgTextClear();
|
bgfx::dbgTextClear();
|
||||||
bgfx::dbgTextPrintf(0, window_height/16 - 3, 0xf8, " %u FPS", stat->cpuTimerFreq / stat->cpuTimeFrame);
|
bgfx::dbgTextPrintf(0, window_height/16 - 4, 0xf8, " %s %u FPS", caps->supported & BGFX_CAPS_RENDERER_MULTITHREADED ? "Multithreaded" : "Singlethreaded", stat->cpuTimerFreq / stat->cpuTimeFrame);
|
||||||
|
bgfx::dbgTextPrintf(0, window_height/16 - 3, 0xf8, " Max Views: %u :: Max FBs %u :: Max Texture Samplers %u", caps->limits.maxViews, caps->limits.maxFrameBuffers, caps->limits.maxTextureSamplers);
|
||||||
bgfx::dbgTextPrintf(0, window_height/16 - 2, 0xf8, " Project Keishiki :: %s :: Build %s %s", BX_COMPILER_NAME, __DATE__, __TIME__);
|
bgfx::dbgTextPrintf(0, window_height/16 - 2, 0xf8, " Project Keishiki :: %s :: Build %s %s", BX_COMPILER_NAME, __DATE__, __TIME__);
|
||||||
bgfx::dbgTextPrintf(0, window_height/16 - 1, 0xf8, " SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
bgfx::dbgTextPrintf(0, window_height/16 - 1, 0xf8, " SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,11 @@ namespace {
|
||||||
bool draw_nodes = true;
|
bool draw_nodes = true;
|
||||||
|
|
||||||
// Viewport
|
// Viewport
|
||||||
bgfx::FrameBufferHandle composite_fb = BGFX_INVALID_HANDLE, render_fb = BGFX_INVALID_HANDLE;
|
bgfx::TextureHandle composite = BGFX_INVALID_HANDLE,
|
||||||
|
composite_blit = BGFX_INVALID_HANDLE,
|
||||||
|
render = BGFX_INVALID_HANDLE;
|
||||||
|
bgfx::FrameBufferHandle composite_fb = BGFX_INVALID_HANDLE,
|
||||||
|
render_fb = BGFX_INVALID_HANDLE;
|
||||||
K::VisualTrack bg{};
|
K::VisualTrack bg{};
|
||||||
f32 proj[16], transform[16];
|
f32 proj[16], transform[16];
|
||||||
}
|
}
|
||||||
|
@ -53,8 +57,14 @@ namespace K::UI {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupViewport(CompState& s) {
|
void SetupViewport(CompState& s) {
|
||||||
composite_fb = bgfx::createFrameBuffer(s.width, s.height, bgfx::TextureFormat::RGBA8);
|
composite = bgfx::createTexture2D(s.width, s.height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT);
|
||||||
render_fb = bgfx::createFrameBuffer(s.width, s.height, bgfx::TextureFormat::RGBA8);
|
composite_blit = bgfx::createTexture2D(s.width, s.height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_BLIT_DST);
|
||||||
|
render = bgfx::createTexture2D(s.width, s.height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_RT);
|
||||||
|
bgfx::Attachment comp{}, ren{};
|
||||||
|
comp.init(composite, bgfx::Access::ReadWrite);
|
||||||
|
ren.init(render, bgfx::Access::ReadWrite);
|
||||||
|
composite_fb = bgfx::createFrameBuffer(1, &comp);
|
||||||
|
render_fb = bgfx::createFrameBuffer(1, &ren);
|
||||||
|
|
||||||
bg.pg = K::Graphics::load_shader_program("Checkerboard");
|
bg.pg = K::Graphics::load_shader_program("Checkerboard");
|
||||||
bg.add_uniform("f_hw", ShaderGraph::Type::T_XYZ);
|
bg.add_uniform("f_hw", ShaderGraph::Type::T_XYZ);
|
||||||
|
@ -69,7 +79,10 @@ namespace K::UI {
|
||||||
|
|
||||||
void DestroyViewport(CompState& s) {
|
void DestroyViewport(CompState& s) {
|
||||||
bgfx::destroy(composite_fb);
|
bgfx::destroy(composite_fb);
|
||||||
|
bgfx::destroy(composite);
|
||||||
|
bgfx::destroy(composite_blit);
|
||||||
bgfx::destroy(render_fb);
|
bgfx::destroy(render_fb);
|
||||||
|
bgfx::destroy(render);
|
||||||
|
|
||||||
bgfx::destroy(bg.pg);
|
bgfx::destroy(bg.pg);
|
||||||
bgfx::destroy(bg.uniforms.begin()->second.first);
|
bgfx::destroy(bg.uniforms.begin()->second.first);
|
||||||
|
@ -88,11 +101,13 @@ namespace K::UI {
|
||||||
if (ImGui::Begin("Viewport", &draw_viewport)) {
|
if (ImGui::Begin("Viewport", &draw_viewport)) {
|
||||||
ImTextureID idx = nullptr;
|
ImTextureID idx = nullptr;
|
||||||
|
|
||||||
bgfx::TextureHandle composite = bg.get_frame(composite_fb, s.width, s.height);
|
bg.get_frame(composite_fb, s.width, s.height);
|
||||||
for (auto& layer : s.layers) {
|
bgfx::blit(Graphics::K_VIEW_COMP_COMPOSITE, composite_blit, 0, 0, composite);
|
||||||
if (!layer.enabled) continue;
|
for (auto it = s.layers.rbegin(); it != s.layers.rend(); it++) {
|
||||||
Graphics::Composite(composite_fb, composite, layer.track.get_frame(render_fb, s.width, s.height),
|
if (!it->enabled) continue;
|
||||||
&layer == &s.layers.front() ? Graphics::K_V_AlphaOver : layer.mode, s.width, s.height, proj, transform);
|
Graphics::Composite(composite_fb, composite_blit, it->track.get_frame(render_fb, s.width, s.height),
|
||||||
|
it == s.layers.rbegin() ? Graphics::K_V_AlphaOver : it->mode, s.width, s.height, proj, transform);
|
||||||
|
bgfx::blit(Graphics::K_VIEW_COMP_COMPOSITE, composite_blit, 0, 0, composite);
|
||||||
}
|
}
|
||||||
idx = ImGui::toId(composite, 0, 0);
|
idx = ImGui::toId(composite, 0, 0);
|
||||||
if (idx != nullptr)
|
if (idx != nullptr)
|
||||||
|
@ -347,7 +362,7 @@ namespace K::UI {
|
||||||
ImGui::InputFloat3(("##" + it->first).c_str(), &arg.x);
|
ImGui::InputFloat3(("##" + it->first).c_str(), &arg.x);
|
||||||
}, it->second.second);
|
}, it->second.second);
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
if (ImGui::Button("Delete Uniform")) {
|
if (ImGui::Button(("Delete Uniform##" + it->first).c_str())) {
|
||||||
bgfx::destroy(it->second.first);
|
bgfx::destroy(it->second.first);
|
||||||
it = s.layers[s.active].track.uniforms.erase(it);
|
it = s.layers[s.active].track.uniforms.erase(it);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
namespace K::Graphics {
|
namespace K::Graphics {
|
||||||
enum VIEW_ID {
|
enum VIEW_ID {
|
||||||
K_VIEW_TOP = 0,
|
|
||||||
K_VIEW_COMP_COMPOSITE,
|
K_VIEW_COMP_COMPOSITE,
|
||||||
K_VIEW_DRAW
|
K_VIEW_DRAW,
|
||||||
|
K_VIEW_TOP,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Init(u16 width, u16 height);
|
bool Init(u16 width, u16 height);
|
||||||
|
|
|
@ -24,17 +24,17 @@ namespace K {
|
||||||
Dict<String, std::pair<bgfx::UniformHandle, ShaderGraph::T_Map<ShaderGraph::T_Count>::type>> uniforms;
|
Dict<String, std::pair<bgfx::UniformHandle, ShaderGraph::T_Map<ShaderGraph::T_Count>::type>> uniforms;
|
||||||
// Vector<String> samplers;
|
// Vector<String> samplers;
|
||||||
bgfx::TextureHandle get_frame(bgfx::FrameBufferHandle fb, u32 w, u32 h) const {
|
bgfx::TextureHandle get_frame(bgfx::FrameBufferHandle fb, u32 w, u32 h) const {
|
||||||
bgfx::touch(K::Graphics::K_VIEW_DRAW);
|
bgfx::touch(K::Graphics::K_VIEW_COMP_COMPOSITE);
|
||||||
bgfx::setViewMode(K::Graphics::K_VIEW_DRAW, bgfx::ViewMode::Sequential);
|
bgfx::setViewMode(K::Graphics::K_VIEW_COMP_COMPOSITE, bgfx::ViewMode::Sequential);
|
||||||
bgfx::setViewClear(K::Graphics::K_VIEW_DRAW, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
bgfx::setViewClear(K::Graphics::K_VIEW_COMP_COMPOSITE, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
||||||
bgfx::setViewFrameBuffer(K::Graphics::K_VIEW_DRAW, fb);
|
bgfx::setViewFrameBuffer(K::Graphics::K_VIEW_COMP_COMPOSITE, fb);
|
||||||
float view[16];
|
float view[16];
|
||||||
bx::mtxTranslate(view, 0.f, 0.f, 1.0f);
|
bx::mtxTranslate(view, 0.f, 0.f, 1.0f);
|
||||||
float proj[16];
|
float proj[16];
|
||||||
bx::mtxOrtho(proj, 0.0f, static_cast<f32>(w), 0.0f, static_cast<f32>(h),
|
bx::mtxOrtho(proj, 0.0f, static_cast<f32>(w), 0.0f, static_cast<f32>(h),
|
||||||
0.1f, 100.0f, 0.f, bgfx::getCaps()->homogeneousDepth);
|
0.1f, 100.0f, 0.f, bgfx::getCaps()->homogeneousDepth);
|
||||||
bgfx::setViewTransform(K::Graphics::K_VIEW_DRAW, view, proj);
|
bgfx::setViewTransform(K::Graphics::K_VIEW_COMP_COMPOSITE, view, proj);
|
||||||
bgfx::setViewRect(K::Graphics::K_VIEW_DRAW, 0, 0, w, h);
|
bgfx::setViewRect(K::Graphics::K_VIEW_COMP_COMPOSITE, 0, 0, w, h);
|
||||||
// TODO Find a better way to pack...
|
// TODO Find a better way to pack...
|
||||||
for (auto& [_name, u] : uniforms) {
|
for (auto& [_name, u] : uniforms) {
|
||||||
f32 pack[4]{};
|
f32 pack[4]{};
|
||||||
|
@ -59,7 +59,7 @@ namespace K {
|
||||||
bgfx::setUniform(u.first, pack);
|
bgfx::setUniform(u.first, pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics::DrawTexture(K::Graphics::K_VIEW_DRAW, Graphics::mmaker->tx, 0, 0, w, h,
|
Graphics::DrawTexture(K::Graphics::K_VIEW_COMP_COMPOSITE, Graphics::mmaker->tx, 0, 0, w, h,
|
||||||
(BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) &
|
(BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) &
|
||||||
~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), pg);
|
~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), pg);
|
||||||
return bgfx::getTexture(fb);
|
return bgfx::getTexture(fb);
|
||||||
|
@ -72,36 +72,46 @@ namespace K {
|
||||||
std::ofstream f("temp.frag");
|
std::ofstream f("temp.frag");
|
||||||
f << shader;
|
f << shader;
|
||||||
f.close();
|
f.close();
|
||||||
if (std::system(
|
|
||||||
#if BX_PLATFORM_WINDOWS
|
String s{};
|
||||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
switch (bgfx::getRendererType()) {
|
||||||
|
case bgfx::RendererType::Noop:
|
||||||
|
case bgfx::RendererType::Direct3D11:
|
||||||
|
case bgfx::RendererType::Direct3D12: s = "./ext/bgfx/cmake/bgfx/shaderc "
|
||||||
"-f temp.frag "
|
"-f temp.frag "
|
||||||
"--type fragment "
|
"--type fragment "
|
||||||
"--platform windows "
|
"--platform windows "
|
||||||
"--profile " "ps_5_0" " "
|
"--profile " "ps_5_0" " "
|
||||||
"--varyingdef temp.varying.def.sc "
|
"--varyingdef temp.varying.def.sc "
|
||||||
"-i ./ "
|
"-i ./ "
|
||||||
"-o shaders/" "dx11" "/temp.frag.bin"
|
"-o shaders/" "dx11" "/temp.frag.bin"; break;
|
||||||
#elif BX_PLATFORM_LINUX
|
case bgfx::RendererType::Metal: s = "./ext/bgfx/cmake/bgfx/shaderc "
|
||||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
|
||||||
"-f temp.frag "
|
|
||||||
"--type fragment "
|
|
||||||
"--platform windows "
|
|
||||||
"--profile " "spirv" " "
|
|
||||||
"--varyingdef temp.varying.def.sc "
|
|
||||||
"-i ./ "
|
|
||||||
"-o shaders/" "spirv" "/temp.frag.bin"
|
|
||||||
#elif BX_PLATFORM_OSX
|
|
||||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
|
||||||
"-f temp.frag "
|
"-f temp.frag "
|
||||||
"--type fragment "
|
"--type fragment "
|
||||||
"--platform osx "
|
"--platform osx "
|
||||||
"--profile " "metal" " "
|
"--profile " "metal" " "
|
||||||
"--varyingdef temp.varying.def.sc "
|
"--varyingdef temp.varying.def.sc "
|
||||||
"-i ./ "
|
"-i ./ "
|
||||||
"-o shaders/" "metal" "/temp.frag.bin"
|
"-o shaders/" "metal" "/temp.frag.bin"; break;
|
||||||
#endif
|
case bgfx::RendererType::OpenGL: s = "./ext/bgfx/cmake/bgfx/shaderc "
|
||||||
) == 0) {
|
"-f temp.frag "
|
||||||
|
"--type fragment "
|
||||||
|
"--platform windows "
|
||||||
|
"--profile " "140" " "
|
||||||
|
"--varyingdef temp.varying.def.sc "
|
||||||
|
"-i ./ "
|
||||||
|
"-o shaders/" "glsl" "/temp.frag.bin"; break;
|
||||||
|
case bgfx::RendererType::Vulkan: s = "./ext/bgfx/cmake/bgfx/shaderc "
|
||||||
|
"-f temp.frag "
|
||||||
|
"--type fragment "
|
||||||
|
"--platform windows "
|
||||||
|
"--profile " "spirv" " ""--varyingdef temp.varying.def.sc "
|
||||||
|
"-i ./ "
|
||||||
|
"-o shaders/" "spirv" "/temp.frag.bin"; break;
|
||||||
|
default: LogError("Unsupported renderer"); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::system(s.c_str()) == 0) {
|
||||||
if (isValid(pg)) bgfx::destroy(pg);
|
if (isValid(pg)) bgfx::destroy(pg);
|
||||||
pg = Graphics::load_shader_program("temp");
|
pg = Graphics::load_shader_program("temp");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ $input v_texcoord0
|
||||||
|
|
||||||
uniform vec4 f_mode;
|
uniform vec4 f_mode;
|
||||||
SAMPLER2D(v_A, 0);
|
SAMPLER2D(v_A, 0);
|
||||||
SAMPLER2D(v_B, 0);
|
SAMPLER2D(v_B, 1);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue