Even more de-std::-ifying

This commit is contained in:
Emmanuel BENOîT 2017-11-03 11:55:26 +01:00
parent 69d80c910a
commit a28fc34394
14 changed files with 212 additions and 200 deletions

View file

@ -5,7 +5,7 @@
#include "odbg.hh" #include "odbg.hh"
namespace { namespace {
static const std::string Name_( "BLOOOOM!" ); static char const* const Name_( "BLOOOOM!" );
} }
#define PSTART() Globals::Profiler( ).start( Name_ ) #define PSTART() Globals::Profiler( ).start( Name_ )
@ -28,8 +28,8 @@ T_BloomPass::T_BloomPass(
Globals::ODbg( ).registerTexture( txBlur0_ , E_ODbgMode::HDR , "Bloom" ); Globals::ODbg( ).registerTexture( txBlur0_ , E_ODbgMode::HDR , "Bloom" );
for ( auto i = 0u ; i < BloomLevels ; i ++ ) { for ( auto i = 0u ; i < BloomLevels ; i ++ ) {
rtBlur0_.push_back( T_RendertargetSetup( ).add( txBlur0_ , i ).create( ) ); rtBlur0_.add( T_RendertargetSetup( ).add( txBlur0_ , i ).create( ) );
rtBlur1_.push_back( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) ); rtBlur1_.add( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) );
} }
auto& sm( Globals::Shaders( ) ); auto& sm( Globals::Shaders( ) );

View file

@ -31,7 +31,7 @@ struct T_BloomPass
T_TextureSampler sampler_; T_TextureSampler sampler_;
T_Texture txBlur0_ , txBlur1_; T_Texture txBlur0_ , txBlur1_;
std::vector< T_Rendertarget > rtBlur0_ , rtBlur1_; T_AutoArray< T_Rendertarget , BloomLevels > rtBlur0_ , rtBlur1_;
float filterParams_[ 3 ]; float filterParams_[ 3 ];
float blurWeights_[ 4 ]; float blurWeights_[ 4 ];

View file

@ -6,10 +6,10 @@
/*= T_Camera =================================================================*/ /*= T_Camera =================================================================*/
void T_Camera::handleDND( void T_Camera::handleDND(
__rd__ ImVec2 const& move , ImVec2 const& move ,
__rd__ const bool hasCtrl , const bool hasCtrl ,
__rd__ const bool hasShift , const bool hasShift ,
__rd__ const bool lmb // Left mouse button const bool lmb // Left mouse button
) )
{ {
if ( move.x == 0 || move.y == 0 ) { if ( move.x == 0 || move.y == 0 ) {
@ -35,9 +35,9 @@ void T_Camera::handleDND(
} }
void T_Camera::handleWheel( void T_Camera::handleWheel(
__rd__ const float wheel , const float wheel ,
__rd__ const bool hasCtrl , const bool hasCtrl ,
__rd__ const bool hasShift const bool hasShift
) )
{ {
const float delta( wheel * ( hasCtrl ? 1.f : .1f) ); const float delta( wheel * ( hasCtrl ? 1.f : .1f) );

View file

@ -23,15 +23,15 @@ struct T_Camera
{ update( ); } { update( ); }
void handleDND( void handleDND(
__rd__ ImVec2 const& move , ImVec2 const& move ,
__rd__ const bool hasCtrl , const bool hasCtrl ,
__rd__ const bool hasShift , const bool hasShift ,
__rd__ const bool lmb // Left mouse button const bool lmb // Left mouse button
); );
void handleWheel( void handleWheel(
__rd__ const float wheel , const float wheel ,
__rd__ const bool hasCtrl , const bool hasCtrl ,
__rd__ const bool hasShift const bool hasShift
); );
void makeUI( ); void makeUI( );

View file

@ -6,7 +6,7 @@
#include "globals.hh" #include "globals.hh"
namespace { namespace {
static const std::string Name_( "Combine" ); static char const* const Name_( "Combine" );
} }
#define PSTART() Globals::Profiler( ).start( Name_ ) #define PSTART() Globals::Profiler( ).start( Name_ )
@ -14,8 +14,8 @@ namespace {
T_CombinePass::T_CombinePass( T_CombinePass::T_CombinePass(
__rw__ T_Texture& image , T_Texture& image ,
__rw__ T_Texture& bloom ) T_Texture& bloom )
: txImage_( image ) , txBloom_( bloom ) , : txImage_( image ) , txBloom_( bloom ) ,
txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) , txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) ,
rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) , rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) ,

View file

@ -10,8 +10,8 @@ struct T_CombinePass
T_CombinePass( T_CombinePass const& ) = delete; T_CombinePass( T_CombinePass const& ) = delete;
T_CombinePass( T_CombinePass&& ) = delete; T_CombinePass( T_CombinePass&& ) = delete;
T_CombinePass( __rw__ T_Texture& image , T_CombinePass( T_Texture& image ,
__rw__ T_Texture& bloom ); T_Texture& bloom );
void render( ); void render( );
void makeUI( ); void makeUI( );

View file

@ -18,51 +18,47 @@ void cops::Execute(
} }
T_Operations& T_Program::function( T_Operations& T_Program::function(
std::string const& name , T_String const& name ,
const uint32_t args ) const uint32_t args )
{ {
const auto p( functions.find( name ) ); T_Function* op( functions.get( name ) );
if ( p == functions.end( ) ) { if ( !op ) {
return functions.emplace( name , T_Function{ name , args } ).first->second.operations; functions.add( T_Function{ name , args } );
op = functions.get( name );
} }
assert( p->second.arguments == args ); assert( op->arguments == args );
return p->second.operations; return op->operations;
} }
/*= X_OpFailure ==============================================================*/ /*= X_OpFailure ==============================================================*/
X_OpFailure::X_OpFailure( X_OpFailure::X_OpFailure(
std::string const& source , T_String const& source ,
uint32_t line , uint32_t line ,
std::string const& error ) noexcept T_String&& error ) noexcept
: std::exception( ) , source_( source ) , line_( line ) , : std::exception( ) , source_( source ) , line_( line ) ,
error_( error ) error_( std::move( error ) )
{ {
std::ostringstream oss; ebcl::T_StringBuilder sb;
oss << "Program error (" << source << ", l. " << line << "): " << error; sb << "Program error (" << source << ", l. " << line << "): " << error
fullMessage_ = oss.str( ); << '\0';
fullMessage_ = std::move( sb );
} }
char const* X_OpFailure::what( ) const noexcept char const* X_OpFailure::what( ) const noexcept
{ {
return fullMessage_.c_str( ); return fullMessage_.data( );
} }
/*= T_Context ================================================================*/ /*= T_Context ================================================================*/
T_Context& T_Context::store( T_Context& T_Context::store(
std::string const& name , T_String const& name ,
const float value ) const float value )
{ {
const auto vPos( varPos.find( name ) ); vars.set( name , value );
if ( vPos == varPos.end( ) ) {
varPos.emplace( name , varValues.size( ) );
varValues.push_back( value );
} else {
varValues[ vPos->second ] = value;
}
return *this; return *this;
} }
@ -77,9 +73,15 @@ T_Op::~T_Op( ) { }
X_OpFailure T_Op::error( X_OpFailure T_Op::error(
std::string const& message ) const noexcept ebcl::T_StringBuilder& message ) const noexcept
{ {
return X_OpFailure( source , line , message ); return X_OpFailure( source , line , std::move( message ) );
}
X_OpFailure T_Op::error(
T_String const& message ) const noexcept
{
return X_OpFailure( source , line , T_String( message ) );
} }
@ -93,25 +95,27 @@ OPLoadConstant::OPLoadConstant(
void OPLoadConstant::execute( void OPLoadConstant::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
ctx.opStack.push_back( constant ); ctx.opStack.add( constant );
} }
/*= OPLoadVariable ===========================================================*/ /*= OPLoadVariable ===========================================================*/
OPLoadVariable::OPLoadVariable( OPLoadVariable::OPLoadVariable(
std::string const& variable ) T_String const& variable )
: T_Op( OP_LOAD_VARIABLE ) , variable( variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable )
{ } { }
void OPLoadVariable::execute( void OPLoadVariable::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
const auto vPos( ctx.varPos.find( variable ) ); auto const* v( ctx.vars.get( variable ) );
if ( vPos == ctx.varPos.end( ) ) { if ( !v ) {
throw error( "variable '" + variable + "' not found" ); ebcl::T_StringBuilder sb;
sb << "variable '" << variable << "' not found" << '\0';
throw error( sb );
} }
ctx.opStack.push_back( ctx.varValues[ vPos->second ] ); ctx.opStack.add( *v );
} }
@ -126,14 +130,14 @@ void OPLoadInput::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) ); const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) );
ctx.opStack.push_back( Globals::Sync( ).inputs( )[ i ] ); ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] );
} }
/*= OPStoreVariable ==========================================================*/ /*= OPStoreVariable ==========================================================*/
OPStoreVariable::OPStoreVariable( OPStoreVariable::OPStoreVariable(
std::string const& variable ) T_String const& variable )
: T_Op( OP_LOAD_VARIABLE ) , variable( variable ) : T_Op( OP_LOAD_VARIABLE ) , variable( variable )
{ } { }
@ -144,8 +148,8 @@ void OPStoreVariable::execute(
throw error( "stack is empty" ); throw error( "stack is empty" );
} }
ctx.store( variable , ctx.opStack.back( ) ); ctx.store( variable , ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
} }
@ -157,9 +161,9 @@ void OPAdd::execute(
if ( ctx.opStack.size( ) < 2 ) { if ( ctx.opStack.size( ) < 2 ) {
throw error( "missing operands in stack" ); throw error( "missing operands in stack" );
} }
const float v( ctx.opStack.back( ) ); const float v( ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
ctx.opStack.back( ) += v; ctx.opStack.last( ) += v;
} }
void OPMul::execute( void OPMul::execute(
@ -168,9 +172,9 @@ void OPMul::execute(
if ( ctx.opStack.size( ) < 2 ) { if ( ctx.opStack.size( ) < 2 ) {
throw error( "missing operands in stack" ); throw error( "missing operands in stack" );
} }
const float v( ctx.opStack.back( ) ); const float v( ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
ctx.opStack.back( ) *= v; ctx.opStack.last( ) *= v;
} }
void OPNeg::execute( void OPNeg::execute(
@ -179,16 +183,16 @@ void OPNeg::execute(
if ( ctx.opStack.empty( ) ) { if ( ctx.opStack.empty( ) ) {
throw error( "missing operand in stack" ); throw error( "missing operand in stack" );
} }
ctx.opStack.back( ) = -ctx.opStack.back( ); ctx.opStack.last( ) = -ctx.opStack.last( );
} }
void OPInv::execute( void OPInv::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.empty( ) || ctx.opStack.back( ) == 0 ) { if ( ctx.opStack.empty( ) || ctx.opStack.last( ) == 0 ) {
throw error( "missing operand in stack" ); throw error( "missing operand in stack" );
} }
ctx.opStack.back( ) = 1.0f / ctx.opStack.back( ); ctx.opStack.last( ) = 1.0f / ctx.opStack.last( );
} }
@ -202,12 +206,12 @@ void OPDup::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) <= stackIndex ) { if ( ctx.opStack.size( ) <= stackIndex ) {
std::ostringstream oss; ebcl::T_StringBuilder sb;
oss << "stack does not have " << ( stackIndex + 1 ) sb << "stack does not have " << ( stackIndex + 1 )
<< " items (only " << ctx.opStack.size( ) << ")"; << " items (only " << ctx.opStack.size( ) << ")";
throw error( oss.str( ) ); throw error( sb );
} }
ctx.opStack.push_back( *( ctx.opStack.end( ) - stackIndex - 1 ) ); ctx.opStack.add( *( ctx.opStack.end( ) - stackIndex - 1 ) );
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -220,10 +224,9 @@ void OPXchg::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( ctx.opStack.size( ) <= stackIndex ) { if ( ctx.opStack.size( ) <= stackIndex ) {
std::string err( "stack does not have " ); ebcl::T_StringBuilder sb( "stack does not have " );
err += stackIndex + 1; sb << ( stackIndex + 1 ) << " items";
err += " items"; throw error( sb );
throw error( err );
} }
if ( stackIndex ) { if ( stackIndex ) {
std::swap( *( ctx.opStack.end( ) - 1 ) , *( ctx.opStack.end( ) - stackIndex - 1 ) ); std::swap( *( ctx.opStack.end( ) - 1 ) , *( ctx.opStack.end( ) - stackIndex - 1 ) );
@ -247,10 +250,9 @@ void OPSetUniform::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
if ( count == 0 || ctx.opStack.size( ) < count + 2 ) { if ( count == 0 || ctx.opStack.size( ) < count + 2 ) {
std::string err( "stack does not have " ); ebcl::T_StringBuilder sb( "stack does not have " );
err += count + 2; sb << ( count + 2 ) << " items";
err += " items"; throw error( sb );
throw error( err );
} }
typedef void (*F_SetUniform_)( int , int , int , void* ); typedef void (*F_SetUniform_)( int , int , int , void* );
@ -260,17 +262,17 @@ void OPSetUniform::execute(
}; };
const F_SetUniform_ func{ *(F_SetUniform_*) funcs[ count + ( integer ? 4 : 0 ) - 1 ] }; const F_SetUniform_ func{ *(F_SetUniform_*) funcs[ count + ( integer ? 4 : 0 ) - 1 ] };
const GLuint program( ctx.opStack.back( ) ); const GLuint program( ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
const GLuint uniform( ctx.opStack.back( ) ); const GLuint uniform( ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
if ( integer ) { if ( integer ) {
int values[ count ]; int values[ count ];
auto i = count; auto i = count;
while ( i != 0 ) { while ( i != 0 ) {
values[ count - i ] = int( ctx.opStack.back( ) ); values[ count - i ] = int( ctx.opStack.last( ) );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
i --; i --;
} }
func( program , uniform , 1 , values ); func( program , uniform , 1 , values );
@ -278,8 +280,8 @@ void OPSetUniform::execute(
float values[ count ]; float values[ count ];
auto i = count; auto i = count;
while ( i != 0 ) { while ( i != 0 ) {
values[ count - i ] = ctx.opStack.back( ); values[ count - i ] = ctx.opStack.last( );
ctx.opStack.pop_back( ); ctx.opStack.removeLast( );
i --; i --;
} }
func( program , uniform , 1 , values ); func( program , uniform , 1 , values );
@ -388,32 +390,34 @@ void OPFullscreen::execute(
/*= Flow control =============================================================*/ /*= Flow control =============================================================*/
OPCall::OPCall( OPCall::OPCall(
std::string const& function ) T_String const& function )
: T_Op( OP_CALL ) , function( function ) : T_Op( OP_CALL ) , function( function )
{ } { }
void OPCall::execute( void OPCall::execute(
T_Context& ctx ) const T_Context& ctx ) const
{ {
auto fp( ctx.program->functions.find( function ) ); auto const* fp( ctx.program->functions.get( function ) );
if ( fp == ctx.program->functions.end( ) ) { if ( !fp ) {
throw error( "function '" + function + "' not found" ); ebcl::T_StringBuilder sb( "function '" );
sb << function << "' not found" << '\0';
throw error( sb );
} }
auto const& func( fp->second ); auto const& func( *fp );
const auto ssz( ctx.opStack.size( ) ); const auto ssz( ctx.opStack.size( ) );
if ( ssz < func.arguments ) { if ( ssz < func.arguments ) {
std::string err; ebcl::T_StringBuilder sb( "function '" );
err = "function '" + function + "' requires "; sb << function << "' requires " << func.arguments << " argument"
err += func.arguments; << ( func.arguments > 1 ? "s" : "" ) << '\0';
err += " argument"; throw error( sb );
err += ( func.arguments > 1 ? "s" : "" );
throw error( err );
} }
Execute( func.operations , ctx ); Execute( func.operations , ctx );
if ( ctx.opStack.size( ) < ssz ) { if ( ctx.opStack.size( ) < ssz ) {
throw error( "function '" + function + "' ate the stack" ); ebcl::T_StringBuilder sb( "function '" );
sb << function << "' ate the stack" << '\0';
throw error( sb );
} }
ctx.opStack.resize( ssz - func.arguments ); ctx.opStack.resize( ssz - func.arguments );
} }

View file

@ -16,14 +16,13 @@ namespace cops {
float const* time; float const* time;
T_SyncData const* sync; T_SyncData const* sync;
std::vector< float > varValues; T_KeyValueTable< T_String , float > vars;
std::map< std::string , uint32_t > varPos;
std::vector< float > opStack; T_Array< float > opStack;
T_Context& store( T_Context& store(
__rd__ std::string const& name , T_String const& name ,
__rd__ const float value ); const float value );
}; };
class X_OpFailure : public std::exception class X_OpFailure : public std::exception
@ -34,24 +33,24 @@ namespace cops {
DEF_MOVE( X_OpFailure ); DEF_MOVE( X_OpFailure );
X_OpFailure( X_OpFailure(
__rd__ std::string const& source , T_String const& source ,
__rd__ uint32_t line , uint32_t line ,
__rd__ std::string const& error ) noexcept; T_String&& error ) noexcept;
std::string const& source( ) const noexcept T_String const& source( ) const noexcept
{ return source_; } { return source_; }
uint32_t line( ) const noexcept uint32_t line( ) const noexcept
{ return line_; } { return line_; }
std::string const& error( ) const noexcept T_String const& error( ) const noexcept
{ return error_; } { return error_; }
char const* what( ) const noexcept override; char const* what( ) const noexcept override;
private: private:
std::string source_; T_String source_;
uint32_t line_; uint32_t line_;
std::string error_; T_String error_;
std::string fullMessage_; T_String fullMessage_;
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
@ -83,51 +82,53 @@ namespace cops {
struct T_Op struct T_Op
{ {
explicit T_Op( explicit T_Op(
__rd__ const E_Op op ); const E_Op op );
virtual ~T_Op( ) = 0; virtual ~T_Op( ) = 0;
E_Op op( ) const noexcept E_Op op( ) const noexcept
{ return op_; } { return op_; }
virtual void execute( virtual void execute(
__rw__ T_Context& ctx ) const = 0; T_Context& ctx ) const = 0;
std::string source{}; T_String source{};
uint32_t line{0}; uint32_t line{0};
protected: protected:
X_OpFailure error( X_OpFailure error(
__rd__ std::string const& message ) const noexcept; ebcl::T_StringBuilder& message ) const noexcept;
X_OpFailure error(
T_String const& message ) const noexcept;
private: private:
E_Op op_; E_Op op_;
}; };
using P_Op = std::unique_ptr< T_Op >; using P_Op = T_OwnPtr< T_Op >;
using T_Operations = std::vector< P_Op >; using T_Operations = T_Array< P_Op >;
template< typename T > template< typename T >
inline T_Operations& operator <<( inline T_Operations& operator <<(
__rw__ T_Operations& ops , T_Operations& ops ,
__rw__ T&& item ) T&& item )
{ {
ops.emplace_back( new T( std::move( item ) ) ); ops.add( NewOwned< T >( std::move( item ) ) );
return ops; return ops;
} }
void Execute( void Execute(
__rd__ T_Operations const& operations , T_Operations const& operations ,
__rw__ T_Context& context ); T_Context& context );
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct T_Function struct T_Function
{ {
std::string name; T_String name;
uint32_t arguments; uint32_t arguments;
T_Operations operations; T_Operations operations;
T_Function( __rd__ std::string const& name , T_Function( T_String const& name ,
__rd__ const uint32_t arguments ) const uint32_t arguments )
: name( name ) , arguments( arguments ) : name( name ) , arguments( arguments )
{ } { }
DEF_COPY( T_Function ); DEF_COPY( T_Function );
@ -136,14 +137,20 @@ namespace cops {
struct T_Program struct T_Program
{ {
std::map< std::string , T_Function > functions; T_ObjectTable< T_String , T_Function > functions;
T_Operations main; T_Operations main;
T_Operations& function( T_Program( )
__rd__ std::string const& name , : functions( []( T_Function const& f ) -> T_String {
__rd__ const uint32_t args ); return f.name;
} )
{ }
void execute( __rw__ T_Context& context ) T_Operations& function(
T_String const& name ,
const uint32_t args );
void execute( T_Context& context )
{ {
context.program = this; context.program = this;
Execute( main , context ); Execute( main , context );
@ -155,37 +162,37 @@ namespace cops {
struct OPLoadConstant : public T_Op struct OPLoadConstant : public T_Op
{ {
explicit OPLoadConstant( explicit OPLoadConstant(
__rd__ const float constant ); const float constant );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
float constant; float constant;
}; };
struct OPLoadVariable : public T_Op struct OPLoadVariable : public T_Op
{ {
explicit OPLoadVariable( explicit OPLoadVariable(
__rd__ std::string const& variable ); T_String const& variable );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
std::string variable; T_String variable;
}; };
struct OPLoadInput : public T_Op struct OPLoadInput : public T_Op
{ {
explicit OPLoadInput( explicit OPLoadInput(
__rd__ std::string const& input ); std::string const& input );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
std::string input; std::string input;
}; };
struct OPStoreVariable : public T_Op struct OPStoreVariable : public T_Op
{ {
explicit OPStoreVariable( explicit OPStoreVariable(
__rd__ std::string const& variable ); T_String const& variable );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
std::string variable; T_String variable;
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
@ -194,28 +201,28 @@ namespace cops {
{ {
OPAdd( ) : T_Op( OP_ADD ) {} OPAdd( ) : T_Op( OP_ADD ) {}
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
struct OPMul : public T_Op struct OPMul : public T_Op
{ {
OPMul( ) : T_Op( OP_MUL ) {} OPMul( ) : T_Op( OP_MUL ) {}
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
struct OPNeg : public T_Op struct OPNeg : public T_Op
{ {
OPNeg( ) : T_Op( OP_NEG ) {} OPNeg( ) : T_Op( OP_NEG ) {}
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
struct OPInv : public T_Op struct OPInv : public T_Op
{ {
OPInv( ) : T_Op( OP_INV ) {} OPInv( ) : T_Op( OP_INV ) {}
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
@ -224,7 +231,7 @@ namespace cops {
{ {
explicit OPDup( uint32_t stackIndex = 0 ); explicit OPDup( uint32_t stackIndex = 0 );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t stackIndex; uint32_t stackIndex;
}; };
@ -232,7 +239,7 @@ namespace cops {
{ {
explicit OPXchg( uint32_t stackIndex = 1 ); explicit OPXchg( uint32_t stackIndex = 1 );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t stackIndex; uint32_t stackIndex;
}; };
@ -241,10 +248,10 @@ namespace cops {
struct OPSetUniform : public T_Op struct OPSetUniform : public T_Op
{ {
OPSetUniform( OPSetUniform(
__rd__ const uint32_t count , const uint32_t count ,
__rd__ const bool integer ); const bool integer );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t count; uint32_t count;
bool integer; bool integer;
@ -253,9 +260,9 @@ namespace cops {
struct OPUsePipeline : public T_Op struct OPUsePipeline : public T_Op
{ {
explicit OPUsePipeline( explicit OPUsePipeline(
__rd__ const uint32_t index ); const uint32_t index );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t pipeline; uint32_t pipeline;
}; };
@ -263,11 +270,11 @@ namespace cops {
struct OPUseTexture : public T_Op struct OPUseTexture : public T_Op
{ {
OPUseTexture( OPUseTexture(
__rd__ const uint32_t binding , const uint32_t binding ,
__rd__ const uint32_t texture , const uint32_t texture ,
__rd__ const uint32_t sampler = 0 ); const uint32_t sampler = 0 );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t binding; uint32_t binding;
uint32_t texture; uint32_t texture;
@ -277,9 +284,9 @@ namespace cops {
struct OPUseFramebuffer : public T_Op struct OPUseFramebuffer : public T_Op
{ {
explicit OPUseFramebuffer( explicit OPUseFramebuffer(
__rd__ const uint32_t framebuffer ); const uint32_t framebuffer );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
uint32_t framebuffer; uint32_t framebuffer;
}; };
@ -288,7 +295,7 @@ namespace cops {
{ {
OPSetViewport( ) : T_Op( OP_SET_VIEWPORT ) { } OPSetViewport( ) : T_Op( OP_SET_VIEWPORT ) { }
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
@ -297,14 +304,14 @@ namespace cops {
{ {
OPClear( ) : T_Op( OP_CLEAR ) { } OPClear( ) : T_Op( OP_CLEAR ) { }
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
struct OPFullscreen : public T_Op struct OPFullscreen : public T_Op
{ {
OPFullscreen( ) : T_Op( OP_FULLSCREEN ) { } OPFullscreen( ) : T_Op( OP_FULLSCREEN ) { }
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
@ -312,11 +319,11 @@ namespace cops {
struct OPCall : public T_Op struct OPCall : public T_Op
{ {
explicit OPCall( explicit OPCall(
__rd__ std::string const& function ); T_String const& function );
void execute( void execute(
__rw__ T_Context& ctx ) const override; T_Context& ctx ) const override;
std::string function; T_String function;
}; };
} // namespace cops } // namespace cops

2
dof.cc
View file

@ -7,7 +7,7 @@
namespace { namespace {
static const std::string Name_( "DoF" ); static char const* const Name_( "DoF" );
} }
#define PSTART() Globals::Profiler( ).start( Name_ ) #define PSTART() Globals::Profiler( ).start( Name_ )

2
ebcl

@ -1 +1 @@
Subproject commit 90048ad3cc4bd8ce777672149a0c69eb9c8115e0 Subproject commit 3745631e023e250c8d3b9267689fc5e596cc3e7a

View file

@ -4,7 +4,7 @@
#include "globals.hh" #include "globals.hh"
namespace { namespace {
static const std::string Name_( "FXAA" ); static char const* const Name_( "FXAA" );
} }
#define PSTART() Globals::Profiler( ).start( Name_ ) #define PSTART() Globals::Profiler( ).start( Name_ )

View file

@ -27,8 +27,8 @@ void T_Profiler::endFrame( )
{ {
const auto n( sections_.size( ) ); const auto n( sections_.size( ) );
while ( secDurations_.size( ) < n ) { while ( secDurations_.size( ) < n ) {
secDurations_.push_back( 0 ); secDurations_.add( 0 );
secStarts_.push_back( 0 ); secStarts_.add( 0 );
} }
for ( auto i = 0u ; i < n ; i ++ ) { for ( auto i = 0u ; i < n ; i ++ ) {
@ -48,16 +48,16 @@ void T_Profiler::endFrame( )
} }
void T_Profiler::start( void T_Profiler::start(
__rd__ std::string const& section ) T_String const& section )
{ {
const auto n( sections_.size( ) ); const auto n( sections_.size( ) );
const auto pos( find( section ) ); const auto pos( find( section ) );
if ( pos == n ) { if ( pos == n ) {
sections_.push_back( section ); sections_.add( section );
samples_.push_back( T_SamplesList_{ } ); samples_.add( T_SamplesList_{ } );
starts_.push_back( 0u ); starts_.add( 0u );
chain_.push_back( Invalid ); chain_.add( Invalid );
parents_.push_back( Invalid ); parents_.add( Invalid );
} }
chain_[ pos ] = previous_; chain_[ pos ] = previous_;
@ -75,7 +75,7 @@ void T_Profiler::start(
} }
void T_Profiler::end( void T_Profiler::end(
__rd__ std::string const& section ) T_String const& section )
{ {
const auto pos( find( section ) ); const auto pos( find( section ) );
const auto n( sections_.size( ) ); const auto n( sections_.size( ) );
@ -91,7 +91,8 @@ void T_Profiler::end(
auto& samples( samples_[ pos ] ); auto& samples( samples_[ pos ] );
if ( samples.size( ) == 0 || ( samples.size( ) < History if ( samples.size( ) == 0 || ( samples.size( ) < History
&& samples[ 0 ].nSamples == Samples ) ) { && samples[ 0 ].nSamples == Samples ) ) {
samples.insert( samples.begin( ) , T_ProfilerSamples{ 0 , 0 } ); samples.insert( 0 , T_ProfilerSamples{ 0 , 0 } );
} else if ( samples.size( ) == History && samples[ 0 ].nSamples == Samples ) { } else if ( samples.size( ) == History && samples[ 0 ].nSamples == Samples ) {
for ( auto i = 1u ; i < History ; i ++ ) { for ( auto i = 1u ; i < History ; i ++ ) {
samples[ i ] = samples[ i - 1 ]; samples[ i ] = samples[ i - 1 ];
@ -127,7 +128,7 @@ void T_Profiler::makeUI( )
float angle( 0 ); float angle( 0 );
for ( auto i = 0u ; i < n ; i ++ ) { for ( auto i = 0u ; i < n ; i ++ ) {
if ( displayed_.size( ) == i ) { if ( displayed_.size( ) == i ) {
displayed_.push_back( true ); displayed_.add( true );
} }
angle = fmod( angle + 137 , 360 ); angle = fmod( angle + 137 , 360 );
ImVec4 color( 0 , 0 , 0 , 1 ); ImVec4 color( 0 , 0 , 0 , 1 );
@ -135,11 +136,11 @@ void T_Profiler::makeUI( )
color.x , color.y , color.z ); color.x , color.y , color.z );
ImGui::PushStyleColor( ImGuiCol_Text , color ); ImGui::PushStyleColor( ImGuiCol_Text , color );
std::ostringstream str; ebcl::T_StringBuilder sb;
str << sections_[ i ] << " (" sb << sections_[ i ] << " ("
<< int( round( secDurations_[ i ] ) ) << int( round( secDurations_[ i ] ) )
<< "ms)"; << "ms)" << '\0';
ImGui::Checkbox( str.str( ).c_str( ) , (bool*) &displayed_[ i ] ); ImGui::Checkbox( sb.data( ) , (bool*) &displayed_[ i ] );
ImGui::PopStyleColor( ); ImGui::PopStyleColor( );
} }
ImGui::EndChild( ); ImGui::EndChild( );
@ -208,7 +209,7 @@ void T_Profiler::makeUI( )
} }
float T_Profiler::computeDuration( float T_Profiler::computeDuration(
__rd__ const uint32_t section ) const const uint32_t section ) const
{ {
auto const& samples( samples_[ section ] ); auto const& samples( samples_[ section ] );
float total = 0; float total = 0;
@ -221,7 +222,7 @@ float T_Profiler::computeDuration(
} }
uint32_t T_Profiler::find( uint32_t T_Profiler::find(
__rd__ std::string const& section ) const T_String const& section ) const
{ {
const auto n( sections_.size( ) ); const auto n( sections_.size( ) );
auto pos( 0u ); auto pos( 0u );

View file

@ -18,46 +18,46 @@ struct T_Profiler
void clear( ); void clear( );
void startFrame( ); void startFrame( );
void start( __rd__ std::string const& section ); void start( T_String const& section );
void end( __rd__ std::string const& section ); void end( T_String const& section );
void endFrame( ); void endFrame( );
uint32_t sections( ) const noexcept uint32_t sections( ) const noexcept
{ return sections_.size( ); } { return sections_.size( ); }
std::string const& nameOf( T_String const& nameOf(
__rd__ const uint32_t section ) const const uint32_t section ) const
{ return sections_[ section ]; } { return sections_[ section ]; }
float durationOf( __rd__ const uint32_t section ) const float durationOf( const uint32_t section ) const
{ return secDurations_[ section ]; } { return secDurations_[ section ]; }
float startOf( __rd__ const uint32_t section ) const float startOf( const uint32_t section ) const
{ return secStarts_[ section ]; } { return secStarts_[ section ]; }
void makeUI( ); void makeUI( );
bool& uiEnabled( ) { return uiEnabled_; } bool& uiEnabled( ) { return uiEnabled_; }
private: private:
using T_SamplesList_ = std::vector< T_ProfilerSamples >; using T_SamplesList_ = T_Array< T_ProfilerSamples >;
using T_Data_ = std::vector< T_SamplesList_ >; using T_Data_ = T_Array< T_SamplesList_ >;
uint32_t find( __rd__ std::string const& section ) const; uint32_t find( T_String const& section ) const;
float computeDuration( float computeDuration(
__rd__ const uint32_t section ) const; const uint32_t section ) const;
uint32_t previous_; uint32_t previous_;
uint32_t current_; uint32_t current_;
std::vector< std::string > sections_; T_Array< T_String > sections_;
std::vector< uint32_t > chain_; T_Array< uint32_t > chain_;
std::vector< uint32_t > parents_; T_Array< uint32_t > parents_;
T_Data_ samples_; T_Data_ samples_;
std::vector< uint64_t > starts_; T_Array< uint64_t > starts_;
std::vector< float > secDurations_; T_Array< float > secDurations_;
std::vector< float > secStarts_; T_Array< float > secStarts_;
bool uiEnabled_ = false; bool uiEnabled_ = false;
std::vector< int > displayed_; T_Array< int > displayed_;
}; };

View file

@ -6,7 +6,7 @@
namespace { namespace {
static const std::string Name_( "Raymarcher" ); static char const* const Name_( "Raymarcher" );
} }
#define PSTART() Globals::Profiler( ).start( Name_ ) #define PSTART() Globals::Profiler( ).start( Name_ )