From d846fac3f6f44fc74dee76bcbe53311fbf0bd0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 24 Nov 2017 13:46:43 +0100 Subject: [PATCH] Output debugger - Use built-in shaders --- Makefile | 29 ++++++--- {shaders/debug => toolshaders}/copy.glsl | 2 - .../dbg-alpha.glsl | 2 - .../dbg-depth-linear.glsl | 2 - .../dbg-depth-reinhard.glsl | 2 - .../dbg-reinhard.glsl | 2 - toolshaders/fullscreen.glsl | 2 + ui-odbg.cc | 61 +++++++++++++++---- ui-odbg.hh | 2 +- ui.cc | 22 +++++++ ui.hh | 3 + 11 files changed, 96 insertions(+), 33 deletions(-) rename {shaders/debug => toolshaders}/copy.glsl (95%) rename shaders/debug/alpha-channel.glsl => toolshaders/dbg-alpha.glsl (95%) rename shaders/debug/depth-linear.glsl => toolshaders/dbg-depth-linear.glsl (96%) rename shaders/debug/depth-reinhart.glsl => toolshaders/dbg-depth-reinhard.glsl (95%) rename shaders/debug/reinhart.glsl => toolshaders/dbg-reinhard.glsl (95%) create mode 100644 toolshaders/fullscreen.glsl diff --git a/Makefile b/Makefile index 4ec0c9a..52bacc6 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,14 @@ BUILDER_LIBS = $(LIBEBCL) -latomic TOOL_LIBS = $(shell sdl2-config --libs) -lGL -lGLEW -ldl $(BUILDER_LIBS) -FILEDUMPS = +BUILTIN_SHADERS = \ + copy \ + dbg-alpha \ + dbg-depth-linear \ + dbg-depth-reinhard \ + dbg-reinhard \ + fullscreen \ +# END BUILTIN_SHADERS IMGUI = imgui.cpp imgui_draw.cpp @@ -60,6 +67,9 @@ BUILDER = \ # END BUILDER +BUILTIN_SHADERS_SRC = $(addprefix toolshaders/, $(addsuffix .glsl, $(BUILTIN_SHADERS))) +BUILTIN_SHADERS_H = $(addprefix $(OUTDIR)/bs-, $(addsuffix .inl, $(BUILTIN_SHADERS))) + IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI)))) COMMON_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(COMMON)))) TOOL_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(TOOL)))) @@ -91,7 +101,7 @@ tourista-builder: $(LIBEBCL) $(BUILDER_BUILD) $(BUILDER_BUILD) $(BUILDER_LIBS) clean: - rm -f $(ALL_OBJS) $(FILEDUMPS) tourista tourista-builder $(PCH) $(OUTDIR)/font-awesome.inl + rm -f $(ALL_OBJS) $(BUILTIN_SHADERS_H) tourista tourista-builder $(PCH) $(OUTDIR)/font-awesome.inl depclean: clean rm -f $(ALL_DEPS) @@ -103,10 +113,6 @@ fullclean: depclean .PHONY: all clean fullclean -$(FILEDUMPS): fd-%.h: % - xxd -i $< $@ - - outdir: @if ! [ -d "$(OUTDIR)" ]; then mkdir "$(OUTDIR)"; fi .PHONY: outdir @@ -119,21 +125,21 @@ $(IMGUI_OBJS): $(OUTDIR)/%.o: 3rdparty/imgui/%.cpp | outdir #------------------------------------------------------------------------------- -include $(DEMO_DEPS) -$(TOOL_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(FILEDUMPS) +$(TOOL_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(BUILTIN_SHADERS_H) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< #------------------------------------------------------------------------------- -include $(COMMON_DEPS) -$(COMMON_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(FILEDUMPS) +$(COMMON_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< #------------------------------------------------------------------------------- -include $(BUILDER_DEPS) -$(BUILDER_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(FILEDUMPS) +$(BUILDER_OBJS): $(OUTDIR)/%.o: %.cc $(PCH) | outdir $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< @@ -147,6 +153,11 @@ $(PCH): externals.hh #------------------------------------------------------------------------------- +$(BUILTIN_SHADERS_H): $(OUTDIR)/bs-%.inl: toolshaders/%.glsl | outdir + xxd -i < $< > $@ + +#------------------------------------------------------------------------------- + $(OUTDIR)/ui-app.o: ui-app.cc $(OUTDIR)/font-awesome.inl $(OUTDIR)/font-awesome.inl: 3rdparty/font-awesome/fonts/fontawesome-webfont.ttf $(OUTDIR)/font-to-c diff --git a/shaders/debug/copy.glsl b/toolshaders/copy.glsl similarity index 95% rename from shaders/debug/copy.glsl rename to toolshaders/copy.glsl index 42bd304..a1f3022 100644 --- a/shaders/debug/copy.glsl +++ b/toolshaders/copy.glsl @@ -1,7 +1,5 @@ #version 450 core -//! type fragment - layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 1 ) uniform int u_LOD; layout( location = 2 ) uniform vec2 u_OutputSize; diff --git a/shaders/debug/alpha-channel.glsl b/toolshaders/dbg-alpha.glsl similarity index 95% rename from shaders/debug/alpha-channel.glsl rename to toolshaders/dbg-alpha.glsl index 80705e0..fef27f2 100644 --- a/shaders/debug/alpha-channel.glsl +++ b/toolshaders/dbg-alpha.glsl @@ -1,7 +1,5 @@ #version 450 core -//! type fragment - layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 1 ) uniform int u_LOD; layout( location = 2 ) uniform vec2 u_OutputSize; diff --git a/shaders/debug/depth-linear.glsl b/toolshaders/dbg-depth-linear.glsl similarity index 96% rename from shaders/debug/depth-linear.glsl rename to toolshaders/dbg-depth-linear.glsl index ad8393d..85042f2 100644 --- a/shaders/debug/depth-linear.glsl +++ b/toolshaders/dbg-depth-linear.glsl @@ -1,7 +1,5 @@ #version 450 core -//! type fragment - layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 1 ) uniform int u_LOD; layout( location = 2 ) uniform vec2 u_OutputSize; diff --git a/shaders/debug/depth-reinhart.glsl b/toolshaders/dbg-depth-reinhard.glsl similarity index 95% rename from shaders/debug/depth-reinhart.glsl rename to toolshaders/dbg-depth-reinhard.glsl index 6ef88df..8a87b85 100644 --- a/shaders/debug/depth-reinhart.glsl +++ b/toolshaders/dbg-depth-reinhard.glsl @@ -1,7 +1,5 @@ #version 450 core -//! type fragment - layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 1 ) uniform int u_LOD; layout( location = 2 ) uniform vec2 u_OutputSize; diff --git a/shaders/debug/reinhart.glsl b/toolshaders/dbg-reinhard.glsl similarity index 95% rename from shaders/debug/reinhart.glsl rename to toolshaders/dbg-reinhard.glsl index 3d1cec3..9577f3b 100644 --- a/shaders/debug/reinhart.glsl +++ b/toolshaders/dbg-reinhard.glsl @@ -1,7 +1,5 @@ #version 450 core -//! type fragment - layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 1 ) uniform int u_LOD; layout( location = 2 ) uniform vec2 u_OutputSize; diff --git a/toolshaders/fullscreen.glsl b/toolshaders/fullscreen.glsl new file mode 100644 index 0000000..3aa6892 --- /dev/null +++ b/toolshaders/fullscreen.glsl @@ -0,0 +1,2 @@ +#version 450 core +out gl_PerVertex{vec4 gl_Position;}; void main(){gl_Position=vec4(vec2(gl_VertexID>>1,gl_VertexID&1)*2-1,0,1);} diff --git a/ui-odbg.cc b/ui-odbg.cc index 0546ac9..65f7081 100644 --- a/ui-odbg.cc +++ b/ui-odbg.cc @@ -4,7 +4,36 @@ namespace { - char const NormalOutput_[] = "(DISABLED)"; +const char NormalOutput_[] = "(DISABLED)"; + +const char ShdAlpha_[] = { +# include "bs-dbg-alpha.inl" + , 0 +}; +const char ShdReinhard_[] = { +# include "bs-dbg-reinhard.inl" + , 0 +}; +const char ShdDepthLinear_[] = { +# include "bs-dbg-depth-linear.inl" + , 0 +}; +const char ShdDepthReinhard_[] = { +# include "bs-dbg-depth-reinhard.inl" + , 0 +}; + +struct T_DebugShaders_ +{ + char const* name; + char const* source; +}; +const T_DebugShaders_ Shaders_[] = { + { "*dbg-alpha" , ShdAlpha_ } , + { "*dbg-depth-linear" , ShdDepthLinear_ } , + { "*dbg-depth-reinhard" , ShdDepthReinhard_ } , + { "*dbg-reinhard" , ShdReinhard_ } , +}; } @@ -14,17 +43,25 @@ namespace { T_OutputDebugger::T_OutputDebugger( ) : selectorItems_( nullptr ) { + T_ShaderProgram programs[ IM_ARRAYSIZE( Shaders_ ) ]; + for ( auto i = 0 ; i < IM_ARRAYSIZE( Shaders_ ) ; i ++ ) { + programs[ i ] = UI::Shaders( ).program( + Shaders_[ i ].name , + E_ShaderType::FRAGMENT , + Shaders_[ i ].source ); + } + using namespace ebcl; - registerSubmode( E_ODbgMode::LDR , "Colors" , "copy" ); - registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "copy" ); - registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "alpha-channel" ); - registerSubmode( E_ODbgMode::HDR , "Colors (raw)" , "copy" ); - registerSubmode( E_ODbgMode::HDR , "Colors (Reinhart)" , "reinhart" ); - registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 10)" , "depth-linear" , + registerSubmode( E_ODbgMode::LDR , "Colors" , "*copy" ); + registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "*copy" ); + registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "*dbg-alpha" ); + registerSubmode( E_ODbgMode::HDR , "Colors (raw)" , "*copy" ); + registerSubmode( E_ODbgMode::HDR , "Colors (Reinhard)" , "*dbg-reinhard" ); + registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 10)" , "*dbg-depth-linear" , []( uint32_t id ) { glProgramUniform1f( id , 3 , .1 ); } ); - registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 100)" , "depth-linear" , + registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 100)" , "*dbg-depth-linear" , []( uint32_t id ) { glProgramUniform1f( id , 3 , .01 ); } ); - registerSubmode( E_ODbgMode::DEPTH , "Depth (Reinhart)" , "depth-reinhart" ); + registerSubmode( E_ODbgMode::DEPTH , "Depth (Reinhard)" , "*dbg-depth-reinhard" ); initSubmodeCombo( ); } @@ -130,16 +167,14 @@ void T_OutputDebugger::debugOutput( ) void T_OutputDebugger::registerSubmode( const E_ODbgMode mode , T_String const& name , - T_String const& shader , + char const* const shader , F_SubmodeSetup setup ) { assert( mode != E_ODbgMode::__COUNT__ ); - ebcl::T_StringBuilder sb( "debug/" ); - sb << shader << ".glsl" << '\0'; submodes_[ int( mode ) ].add( T_Submode_{ name , UI::Shaders( ).pipeline({ - "fullscreen.v.glsl" , sb.data( ) }) , + "*fullscreen" , shader }) , setup } ); } diff --git a/ui-odbg.hh b/ui-odbg.hh index 2b9aa52..19f4564 100644 --- a/ui-odbg.hh +++ b/ui-odbg.hh @@ -59,7 +59,7 @@ struct T_OutputDebugger void registerSubmode( const E_ODbgMode mode , T_String const& name , - T_String const& shader , + char const* shader , F_SubmodeSetup setup = F_SubmodeSetup( ) ); void initSubmodeCombo( ); diff --git a/ui.cc b/ui.cc index 434f7ae..fcf381b 100644 --- a/ui.cc +++ b/ui.cc @@ -11,12 +11,28 @@ namespace { +const char FullscreenShader_[] = { +# include "bs-fullscreen.inl" + , 0 +}; + +const char CopyShader_[] = { +# include "bs-copy.inl" + , 0 +}; + struct UIData_ { T_UIApp window; T_Profiler profiler; T_TextureManager textures; T_ShaderManager shaders; + T_ShaderProgram fsShader{ + shaders.program( "*fullscreen" , E_ShaderType::VERTEX , FullscreenShader_ ) + }; + T_ShaderProgram copyShader{ + shaders.program( "*copy" , E_ShaderType::FRAGMENT , CopyShader_ ) + }; T_OutputDebugger odbg; T_UISync sync; }; @@ -55,6 +71,12 @@ T_TextureManager& UI::Textures( ) noexcept T_ShaderManager& UI::Shaders( ) noexcept { return M_GET_( shaders ); } +T_ShaderProgram& UI::FullscreenShader( ) noexcept + { return M_GET_( fsShader ); } + +T_ShaderProgram& UI::CopyShader( ) noexcept + { return M_GET_( copyShader ); } + T_OutputDebugger& UI::ODbg( ) noexcept { return M_GET_( odbg ); } diff --git a/ui.hh b/ui.hh index a649ac4..32feefe 100644 --- a/ui.hh +++ b/ui.hh @@ -6,6 +6,7 @@ struct T_OutputDebugger; struct T_Profiler; struct T_ShaderManager; +struct T_ShaderProgram; struct T_TextureManager; struct T_UIApp; struct T_UISync; @@ -21,6 +22,8 @@ struct UI static T_Profiler& Profiler( ) noexcept; static T_TextureManager& Textures( ) noexcept; static T_ShaderManager& Shaders( ) noexcept; + static T_ShaderProgram& FullscreenShader( ) noexcept; + static T_ShaderProgram& CopyShader( ) noexcept; static T_OutputDebugger& ODbg( ) noexcept; static T_UISync& Sync( ) noexcept;