2017-10-06 14:29:01 +02:00
|
|
|
#include "externals.hh"
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui.hh"
|
2017-11-23 23:31:24 +01:00
|
|
|
#include "ui-odbg.hh"
|
2017-10-06 14:29:01 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-24 13:46:43 +01:00
|
|
|
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_ } ,
|
|
|
|
};
|
2017-10-06 14:29:01 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= T_OutputDebugger =========================================================*/
|
|
|
|
|
|
|
|
T_OutputDebugger::T_OutputDebugger( )
|
|
|
|
: selectorItems_( nullptr )
|
|
|
|
{
|
2017-11-24 13:46:43 +01:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
using namespace ebcl;
|
2017-11-24 13:46:43 +01:00
|
|
|
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" ,
|
2017-10-06 14:29:01 +02:00
|
|
|
[]( uint32_t id ) { glProgramUniform1f( id , 3 , .1 ); } );
|
2017-11-24 13:46:43 +01:00
|
|
|
registerSubmode( E_ODbgMode::DEPTH , "Depth (linear / 100)" , "*dbg-depth-linear" ,
|
2017-10-06 14:29:01 +02:00
|
|
|
[]( uint32_t id ) { glProgramUniform1f( id , 3 , .01 ); } );
|
2017-11-24 13:46:43 +01:00
|
|
|
registerSubmode( E_ODbgMode::DEPTH , "Depth (Reinhard)" , "*dbg-depth-reinhard" );
|
2017-10-06 14:29:01 +02:00
|
|
|
initSubmodeCombo( );
|
|
|
|
}
|
|
|
|
|
|
|
|
T_OutputDebugger::~T_OutputDebugger( )
|
|
|
|
{
|
|
|
|
clearSelectorItems( );
|
|
|
|
for ( auto ptr : smCombo_ ) {
|
|
|
|
delete[] ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::makeUI( )
|
|
|
|
{
|
|
|
|
if ( !enabled_ ) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-19 10:21:08 +01:00
|
|
|
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
2017-11-21 16:30:15 +01:00
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
2017-11-19 10:21:08 +01:00
|
|
|
SetNextWindowPos( ImVec2( 0 , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
Begin( "Output debugger" , &enabled_ , ImGuiWindowFlags_NoCollapse );
|
2017-10-06 14:29:01 +02:00
|
|
|
|
|
|
|
// Main selector
|
|
|
|
if ( selectorItems_ == nullptr ) {
|
|
|
|
makeSelectorItems( );
|
|
|
|
}
|
|
|
|
int csi = -1;
|
|
|
|
for ( auto i = 0u ; i < selectorMapping_.size( ) ; i ++ ) {
|
|
|
|
if ( selectorMapping_[ i ] == selected_ ) {
|
|
|
|
csi = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert( csi != -1 );
|
2017-11-19 10:21:08 +01:00
|
|
|
if ( Combo( "Output" , &csi , selectorItems_ ) ) {
|
2017-10-06 14:29:01 +02:00
|
|
|
selected_ = selectorMapping_[ csi ];
|
|
|
|
}
|
|
|
|
if ( selected_ == -1 ) {
|
2017-11-19 10:21:08 +01:00
|
|
|
End( );
|
2017-10-06 14:29:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LOD selector
|
|
|
|
auto& t( outputs_[ selected_ ] );
|
|
|
|
if ( t.levels > 1 ) {
|
|
|
|
char lodCombo[ t.levels * 4 + 1 ];
|
|
|
|
char* ptr = lodCombo;
|
|
|
|
for ( auto i = 0u ; i < t.levels ; i ++ ) {
|
|
|
|
ptr += 1 + snprintf( ptr , sizeof( lodCombo ) - ( ptr - lodCombo ) , "%d" , i );
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
2017-11-19 10:21:08 +01:00
|
|
|
Combo( "Level" , &t.lod , lodCombo );
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Submode selector
|
2017-11-19 10:21:08 +01:00
|
|
|
Combo( "Display" , &t.submode , smCombo_[ int( t.mode ) ] );
|
2017-10-06 14:29:01 +02:00
|
|
|
|
2017-11-19 10:21:08 +01:00
|
|
|
End( );
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::registerTexture(
|
2017-11-04 09:29:06 +01:00
|
|
|
T_Texture& texture ,
|
|
|
|
const E_ODbgMode mode ,
|
|
|
|
T_String const& name )
|
2017-10-06 14:29:01 +02:00
|
|
|
{
|
|
|
|
texture.debugIndex_ = registerTexture(
|
|
|
|
texture.id_ , texture.levels_ , mode , name );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::debugOutput( )
|
|
|
|
{
|
|
|
|
assert( selected_ != -1 );
|
|
|
|
|
|
|
|
glClearColor( 0 , 0 , 0 , 1 );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT );
|
|
|
|
|
|
|
|
auto const& info( outputs_[ selected_ ] );
|
|
|
|
auto const& sm( submodes_[ int( info.mode ) ][ info.submode ] );
|
|
|
|
if ( !sm.pipeline.valid( ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
auto& tm( UI::Textures( ) );
|
2017-10-06 14:29:01 +02:00
|
|
|
glBindTextureUnit( 0 , info.id );
|
|
|
|
glBindSampler( 0 , tm.sampler( "nearest-border" )->id( ) );
|
|
|
|
|
|
|
|
auto const& dspSize( ImGui::GetIO( ).DisplaySize );
|
|
|
|
auto pid( sm.pipeline.program( E_ShaderType::FRAGMENT ) );
|
|
|
|
sm.pipeline.enable( );
|
|
|
|
glProgramUniform1i( pid , 0 , 0 );
|
|
|
|
glProgramUniform1i( pid , 1 , info.lod );
|
|
|
|
glProgramUniform2f( pid , 2 , dspSize.x , dspSize.y );
|
|
|
|
if ( sm.setup ) {
|
|
|
|
sm.setup( pid );
|
|
|
|
}
|
|
|
|
|
|
|
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void T_OutputDebugger::registerSubmode(
|
2017-11-04 09:29:06 +01:00
|
|
|
const E_ODbgMode mode ,
|
|
|
|
T_String const& name ,
|
2017-11-24 13:46:43 +01:00
|
|
|
char const* const shader ,
|
2017-11-04 09:29:06 +01:00
|
|
|
F_SubmodeSetup setup )
|
2017-10-06 14:29:01 +02:00
|
|
|
{
|
|
|
|
assert( mode != E_ODbgMode::__COUNT__ );
|
2017-11-03 09:08:19 +01:00
|
|
|
submodes_[ int( mode ) ].add( T_Submode_{
|
2017-10-06 14:29:01 +02:00
|
|
|
name ,
|
2017-11-23 22:44:20 +01:00
|
|
|
UI::Shaders( ).pipeline({
|
2017-11-24 13:46:43 +01:00
|
|
|
"*fullscreen" , shader }) ,
|
2017-10-06 14:29:01 +02:00
|
|
|
setup
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::initSubmodeCombo( )
|
|
|
|
{
|
|
|
|
for ( auto sm = 0u ; sm < int( E_ODbgMode::__COUNT__ ) ; sm ++ ) {
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings.clear( );
|
2017-10-06 14:29:01 +02:00
|
|
|
for ( auto const& m : submodes_[ sm ] ) {
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings << m.name << '\0';
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings << '\0';
|
2017-10-06 14:29:01 +02:00
|
|
|
|
2017-11-04 09:29:06 +01:00
|
|
|
smCombo_[ sm ] = new char[ imguiStrings.size( ) ];
|
|
|
|
memcpy( smCombo_[ sm ] , imguiStrings.data( ) , imguiStrings.size( ) );
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int32_t T_OutputDebugger::registerTexture(
|
2017-11-04 09:29:06 +01:00
|
|
|
const GLuint id ,
|
|
|
|
const uint32_t levels ,
|
|
|
|
const E_ODbgMode mode ,
|
|
|
|
T_String const& name )
|
2017-10-06 14:29:01 +02:00
|
|
|
{
|
|
|
|
assert( mode != E_ODbgMode::__COUNT__ );
|
|
|
|
assert( id != 0 );
|
|
|
|
assert( name.length( ) );
|
|
|
|
|
|
|
|
nRegistered_ ++;
|
|
|
|
const auto n( outputs_.size( ) );
|
|
|
|
for ( auto i = 0u ; i < n ; i ++ ) {
|
|
|
|
if ( outputs_[ i ].id == 0 ) {
|
|
|
|
outputs_[ i ] = T_Texture_{ id , levels , mode , name , 0 , 0 };
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2017-11-03 09:08:19 +01:00
|
|
|
outputs_.add( T_Texture_{ id , levels , mode , name , 0 , 0 } );
|
2017-10-06 14:29:01 +02:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::unregisterTexture(
|
2017-11-04 09:29:06 +01:00
|
|
|
const uint32_t index )
|
2017-10-06 14:29:01 +02:00
|
|
|
{
|
|
|
|
assert( index < outputs_.size( ) );
|
|
|
|
assert( outputs_[ index ].id != 0 );
|
|
|
|
assert( nRegistered_ > 0 );
|
|
|
|
outputs_[ index ].id = 0;
|
|
|
|
if ( selected_ >= 0 && index == uint32_t( selected_ ) ) {
|
|
|
|
selected_ = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void T_OutputDebugger::clearSelectorItems( )
|
|
|
|
{
|
|
|
|
if ( selectorItems_ != nullptr ) {
|
|
|
|
delete[] selectorItems_;
|
|
|
|
selectorItems_ = nullptr;
|
|
|
|
selectorMapping_.clear( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_OutputDebugger::makeSelectorItems( )
|
|
|
|
{
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings.clear( );
|
|
|
|
imguiStrings << NormalOutput_ << '\0';
|
|
|
|
|
2017-10-06 14:29:01 +02:00
|
|
|
uint32_t nrLeft = nRegistered_, i = 0;
|
2017-11-03 09:08:19 +01:00
|
|
|
selectorMapping_.add( -1 );
|
2017-10-06 14:29:01 +02:00
|
|
|
while ( nrLeft ) {
|
|
|
|
assert( i < outputs_.size( ) );
|
|
|
|
if ( outputs_[ i ].id != 0 ) {
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings << outputs_[ i ].name << '\0';
|
2017-11-03 09:08:19 +01:00
|
|
|
selectorMapping_.add( i );
|
2017-10-06 14:29:01 +02:00
|
|
|
nrLeft --;
|
|
|
|
}
|
|
|
|
i ++;
|
|
|
|
}
|
2017-11-04 09:29:06 +01:00
|
|
|
imguiStrings << '\0';
|
2017-10-06 14:29:01 +02:00
|
|
|
|
|
|
|
assert( selectorMapping_.size( ) == 1 + nRegistered_ );
|
2017-11-04 09:29:06 +01:00
|
|
|
|
|
|
|
selectorItems_ = new char[ imguiStrings.size( ) ];
|
|
|
|
memcpy( selectorItems_ , imguiStrings.data( ) , imguiStrings.size( ) );
|
2017-10-06 14:29:01 +02:00
|
|
|
}
|