Output debugger - Use built-in shaders

This commit is contained in:
Emmanuel BENOîT 2017-11-24 13:46:43 +01:00
parent 8e73f81ecd
commit d846fac3f6
11 changed files with 96 additions and 33 deletions

View file

@ -12,7 +12,14 @@ BUILDER_LIBS = $(LIBEBCL) -latomic
TOOL_LIBS = $(shell sdl2-config --libs) -lGL -lGLEW -ldl $(BUILDER_LIBS) 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 IMGUI = imgui.cpp imgui_draw.cpp
@ -60,6 +67,9 @@ BUILDER = \
# END 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)))) IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI))))
COMMON_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(COMMON)))) COMMON_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(COMMON))))
TOOL_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(TOOL)))) TOOL_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(TOOL))))
@ -91,7 +101,7 @@ tourista-builder: $(LIBEBCL) $(BUILDER_BUILD)
$(BUILDER_BUILD) $(BUILDER_LIBS) $(BUILDER_BUILD) $(BUILDER_LIBS)
clean: 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 depclean: clean
rm -f $(ALL_DEPS) rm -f $(ALL_DEPS)
@ -103,10 +113,6 @@ fullclean: depclean
.PHONY: all clean fullclean .PHONY: all clean fullclean
$(FILEDUMPS): fd-%.h: %
xxd -i $< $@
outdir: outdir:
@if ! [ -d "$(OUTDIR)" ]; then mkdir "$(OUTDIR)"; fi @if ! [ -d "$(OUTDIR)" ]; then mkdir "$(OUTDIR)"; fi
.PHONY: outdir .PHONY: outdir
@ -119,21 +125,21 @@ $(IMGUI_OBJS): $(OUTDIR)/%.o: 3rdparty/imgui/%.cpp | outdir
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
-include $(DEMO_DEPS) -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) -c -o $@ $<
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $<
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
-include $(COMMON_DEPS) -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) -c -o $@ $<
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< $(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $<
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
-include $(BUILDER_DEPS) -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) -c -o $@ $<
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -M -MF $(@:%.o=%.d) -MT $@ $< $(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)/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 $(OUTDIR)/font-awesome.inl: 3rdparty/font-awesome/fonts/fontawesome-webfont.ttf $(OUTDIR)/font-to-c

View file

@ -1,7 +1,5 @@
#version 450 core #version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD; layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_OutputSize; layout( location = 2 ) uniform vec2 u_OutputSize;

View file

@ -1,7 +1,5 @@
#version 450 core #version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD; layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_OutputSize; layout( location = 2 ) uniform vec2 u_OutputSize;

View file

@ -1,7 +1,5 @@
#version 450 core #version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD; layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_OutputSize; layout( location = 2 ) uniform vec2 u_OutputSize;

View file

@ -1,7 +1,5 @@
#version 450 core #version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD; layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_OutputSize; layout( location = 2 ) uniform vec2 u_OutputSize;

View file

@ -1,7 +1,5 @@
#version 450 core #version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture; layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform int u_LOD; layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_OutputSize; layout( location = 2 ) uniform vec2 u_OutputSize;

View file

@ -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);}

View file

@ -4,7 +4,36 @@
namespace { 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( ) T_OutputDebugger::T_OutputDebugger( )
: selectorItems_( nullptr ) : 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; using namespace ebcl;
registerSubmode( E_ODbgMode::LDR , "Colors" , "copy" ); registerSubmode( E_ODbgMode::LDR , "Colors" , "*copy" );
registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "copy" ); registerSubmode( E_ODbgMode::LDR_ALPHA , "Colors" , "*copy" );
registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "alpha-channel" ); registerSubmode( E_ODbgMode::LDR_ALPHA , "Alpha channel" , "*dbg-alpha" );
registerSubmode( E_ODbgMode::HDR , "Colors (raw)" , "copy" ); registerSubmode( E_ODbgMode::HDR , "Colors (raw)" , "*copy" );
registerSubmode( E_ODbgMode::HDR , "Colors (Reinhart)" , "reinhart" ); registerSubmode( E_ODbgMode::HDR , "Colors (Reinhard)" , "*dbg-reinhard" );
registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 10)" , "depth-linear" , registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 10)" , "*dbg-depth-linear" ,
[]( uint32_t id ) { glProgramUniform1f( id , 3 , .1 ); } ); []( 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 ); } ); []( 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( ); initSubmodeCombo( );
} }
@ -130,16 +167,14 @@ void T_OutputDebugger::debugOutput( )
void T_OutputDebugger::registerSubmode( void T_OutputDebugger::registerSubmode(
const E_ODbgMode mode , const E_ODbgMode mode ,
T_String const& name , T_String const& name ,
T_String const& shader , char const* const shader ,
F_SubmodeSetup setup ) F_SubmodeSetup setup )
{ {
assert( mode != E_ODbgMode::__COUNT__ ); assert( mode != E_ODbgMode::__COUNT__ );
ebcl::T_StringBuilder sb( "debug/" );
sb << shader << ".glsl" << '\0';
submodes_[ int( mode ) ].add( T_Submode_{ submodes_[ int( mode ) ].add( T_Submode_{
name , name ,
UI::Shaders( ).pipeline({ UI::Shaders( ).pipeline({
"fullscreen.v.glsl" , sb.data( ) }) , "*fullscreen" , shader }) ,
setup setup
} ); } );
} }

View file

@ -59,7 +59,7 @@ struct T_OutputDebugger
void registerSubmode( void registerSubmode(
const E_ODbgMode mode , const E_ODbgMode mode ,
T_String const& name , T_String const& name ,
T_String const& shader , char const* shader ,
F_SubmodeSetup setup = F_SubmodeSetup( ) ); F_SubmodeSetup setup = F_SubmodeSetup( ) );
void initSubmodeCombo( ); void initSubmodeCombo( );

22
ui.cc
View file

@ -11,12 +11,28 @@
namespace { namespace {
const char FullscreenShader_[] = {
# include "bs-fullscreen.inl"
, 0
};
const char CopyShader_[] = {
# include "bs-copy.inl"
, 0
};
struct UIData_ struct UIData_
{ {
T_UIApp window; T_UIApp window;
T_Profiler profiler; T_Profiler profiler;
T_TextureManager textures; T_TextureManager textures;
T_ShaderManager shaders; 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_OutputDebugger odbg;
T_UISync sync; T_UISync sync;
}; };
@ -55,6 +71,12 @@ T_TextureManager& UI::Textures( ) noexcept
T_ShaderManager& UI::Shaders( ) noexcept T_ShaderManager& UI::Shaders( ) noexcept
{ return M_GET_( shaders ); } { 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 T_OutputDebugger& UI::ODbg( ) noexcept
{ return M_GET_( odbg ); } { return M_GET_( odbg ); }

3
ui.hh
View file

@ -6,6 +6,7 @@
struct T_OutputDebugger; struct T_OutputDebugger;
struct T_Profiler; struct T_Profiler;
struct T_ShaderManager; struct T_ShaderManager;
struct T_ShaderProgram;
struct T_TextureManager; struct T_TextureManager;
struct T_UIApp; struct T_UIApp;
struct T_UISync; struct T_UISync;
@ -21,6 +22,8 @@ struct UI
static T_Profiler& Profiler( ) noexcept; static T_Profiler& Profiler( ) noexcept;
static T_TextureManager& Textures( ) noexcept; static T_TextureManager& Textures( ) noexcept;
static T_ShaderManager& Shaders( ) noexcept; static T_ShaderManager& Shaders( ) noexcept;
static T_ShaderProgram& FullscreenShader( ) noexcept;
static T_ShaderProgram& CopyShader( ) noexcept;
static T_OutputDebugger& ODbg( ) noexcept; static T_OutputDebugger& ODbg( ) noexcept;
static T_UISync& Sync( ) noexcept; static T_UISync& Sync( ) noexcept;