2017-10-14 12:00:47 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef REAL_BUILD
|
|
|
|
# include "externals.hh"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct T_SyncData;
|
|
|
|
|
|
|
|
namespace cops {
|
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
struct T_Program;
|
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
struct T_Context
|
|
|
|
{
|
2017-10-15 10:22:24 +02:00
|
|
|
T_Program const* program;
|
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
float const* time;
|
|
|
|
T_SyncData const* sync;
|
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_KeyValueTable< T_String , float > vars;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Array< float > opStack;
|
2017-10-15 09:34:03 +02:00
|
|
|
|
|
|
|
T_Context& store(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& name ,
|
|
|
|
const float value );
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class X_OpFailure : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
X_OpFailure( ) = delete;
|
|
|
|
DEF_COPY( X_OpFailure );
|
|
|
|
DEF_MOVE( X_OpFailure );
|
|
|
|
|
|
|
|
X_OpFailure(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& source ,
|
|
|
|
uint32_t line ,
|
|
|
|
T_String&& error ) noexcept;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& source( ) const noexcept
|
2017-10-14 12:00:47 +02:00
|
|
|
{ return source_; }
|
|
|
|
uint32_t line( ) const noexcept
|
|
|
|
{ return line_; }
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& error( ) const noexcept
|
2017-10-14 12:00:47 +02:00
|
|
|
{ return error_; }
|
|
|
|
|
|
|
|
char const* what( ) const noexcept override;
|
|
|
|
|
|
|
|
private:
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String source_;
|
2017-10-14 12:00:47 +02:00
|
|
|
uint32_t line_;
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String error_;
|
|
|
|
T_String fullMessage_;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
enum E_Op
|
|
|
|
{
|
|
|
|
OP_LOAD_CONSTANT ,
|
|
|
|
OP_LOAD_VARIABLE ,
|
|
|
|
OP_LOAD_INPUT ,
|
|
|
|
OP_STORE_VARIABLE ,
|
|
|
|
//
|
|
|
|
OP_ADD , OP_MUL ,
|
|
|
|
OP_NEG , OP_INV ,
|
|
|
|
//
|
|
|
|
OP_DUP , OP_XCHG ,
|
|
|
|
//
|
|
|
|
OP_SET_UNIFORM ,
|
|
|
|
OP_USE_PIPELINE ,
|
|
|
|
OP_USE_TEXTURE ,
|
|
|
|
OP_USE_FRAMEBUFFER ,
|
2017-10-14 21:10:46 +02:00
|
|
|
OP_SET_VIEWPORT ,
|
|
|
|
//
|
|
|
|
OP_CLEAR ,
|
2017-10-15 10:22:24 +02:00
|
|
|
OP_FULLSCREEN ,
|
|
|
|
//
|
|
|
|
OP_CALL
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct T_Op
|
|
|
|
{
|
|
|
|
explicit T_Op(
|
2017-11-03 11:55:26 +01:00
|
|
|
const E_Op op );
|
2017-10-14 12:00:47 +02:00
|
|
|
virtual ~T_Op( ) = 0;
|
|
|
|
|
|
|
|
E_Op op( ) const noexcept
|
|
|
|
{ return op_; }
|
|
|
|
|
|
|
|
virtual void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const = 0;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String source{};
|
2017-10-15 10:22:24 +02:00
|
|
|
uint32_t line{0};
|
2017-10-14 12:00:47 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
X_OpFailure error(
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder& message ) const noexcept;
|
|
|
|
X_OpFailure error(
|
|
|
|
T_String const& message ) const noexcept;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
E_Op op_;
|
|
|
|
};
|
2017-11-03 11:55:26 +01:00
|
|
|
using P_Op = T_OwnPtr< T_Op >;
|
|
|
|
using T_Operations = T_Array< P_Op >;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-10-15 09:34:03 +02:00
|
|
|
template< typename T >
|
|
|
|
inline T_Operations& operator <<(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Operations& ops ,
|
|
|
|
T&& item )
|
2017-10-15 09:34:03 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
ops.add( NewOwned< T >( std::move( item ) ) );
|
2017-10-15 09:34:03 +02:00
|
|
|
return ops;
|
|
|
|
}
|
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
void Execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Operations const& operations ,
|
|
|
|
T_Context& context );
|
2017-10-15 10:22:24 +02:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct T_Function
|
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String name;
|
2017-10-15 10:22:24 +02:00
|
|
|
uint32_t arguments;
|
|
|
|
T_Operations operations;
|
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Function( T_String const& name ,
|
|
|
|
const uint32_t arguments )
|
2017-10-15 10:22:24 +02:00
|
|
|
: name( name ) , arguments( arguments )
|
|
|
|
{ }
|
|
|
|
DEF_COPY( T_Function );
|
|
|
|
DEF_MOVE( T_Function );
|
|
|
|
};
|
|
|
|
|
|
|
|
struct T_Program
|
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
T_ObjectTable< T_String , T_Function > functions;
|
2017-10-15 10:22:24 +02:00
|
|
|
T_Operations main;
|
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Program( )
|
|
|
|
: functions( []( T_Function const& f ) -> T_String {
|
|
|
|
return f.name;
|
|
|
|
} )
|
|
|
|
{ }
|
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
T_Operations& function(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& name ,
|
|
|
|
const uint32_t args );
|
2017-10-15 10:22:24 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
void execute( T_Context& context )
|
2017-10-15 10:22:24 +02:00
|
|
|
{
|
|
|
|
context.program = this;
|
|
|
|
Execute( main , context );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
/*====================================================================*/
|
|
|
|
|
|
|
|
struct OPLoadConstant : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPLoadConstant(
|
2017-11-03 11:55:26 +01:00
|
|
|
const float constant );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
float constant;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OPLoadVariable : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPLoadVariable(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& variable );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
|
|
|
T_String variable;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPLoadInput : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPLoadInput(
|
2017-11-04 09:17:31 +01:00
|
|
|
T_String const& input );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-11-04 09:17:31 +01:00
|
|
|
T_String input;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPStoreVariable : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPStoreVariable(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& variable );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
|
|
|
T_String variable;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct OPAdd : public T_Op
|
|
|
|
{
|
|
|
|
OPAdd( ) : T_Op( OP_ADD ) {}
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPMul : public T_Op
|
|
|
|
{
|
|
|
|
OPMul( ) : T_Op( OP_MUL ) {}
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPNeg : public T_Op
|
|
|
|
{
|
|
|
|
OPNeg( ) : T_Op( OP_NEG ) {}
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPInv : public T_Op
|
|
|
|
{
|
|
|
|
OPInv( ) : T_Op( OP_INV ) {}
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct OPDup : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPDup( uint32_t stackIndex = 0 );
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
uint32_t stackIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OPXchg : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPXchg( uint32_t stackIndex = 1 );
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
uint32_t stackIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct OPSetUniform : public T_Op
|
|
|
|
{
|
|
|
|
OPSetUniform(
|
2017-11-03 11:55:26 +01:00
|
|
|
const uint32_t count ,
|
|
|
|
const bool integer );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
|
|
|
uint32_t count;
|
|
|
|
bool integer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OPUsePipeline : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPUsePipeline(
|
2017-11-03 11:55:26 +01:00
|
|
|
const uint32_t index );
|
2017-10-14 12:00:47 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 12:00:47 +02:00
|
|
|
|
|
|
|
uint32_t pipeline;
|
|
|
|
};
|
|
|
|
|
2017-10-14 21:10:46 +02:00
|
|
|
struct OPUseTexture : public T_Op
|
|
|
|
{
|
|
|
|
OPUseTexture(
|
2017-11-03 11:55:26 +01:00
|
|
|
const uint32_t binding ,
|
|
|
|
const uint32_t texture ,
|
|
|
|
const uint32_t sampler = 0 );
|
2017-10-14 21:10:46 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 21:10:46 +02:00
|
|
|
|
|
|
|
uint32_t binding;
|
|
|
|
uint32_t texture;
|
|
|
|
uint32_t sampler;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OPUseFramebuffer : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPUseFramebuffer(
|
2017-11-03 11:55:26 +01:00
|
|
|
const uint32_t framebuffer );
|
2017-10-14 21:10:46 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 21:10:46 +02:00
|
|
|
|
|
|
|
uint32_t framebuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OPSetViewport : public T_Op
|
|
|
|
{
|
|
|
|
OPSetViewport( ) : T_Op( OP_SET_VIEWPORT ) { }
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 21:10:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct OPClear : public T_Op
|
|
|
|
{
|
|
|
|
OPClear( ) : T_Op( OP_CLEAR ) { }
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 21:10:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OPFullscreen : public T_Op
|
|
|
|
{
|
|
|
|
OPFullscreen( ) : T_Op( OP_FULLSCREEN ) { }
|
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-14 21:10:46 +02:00
|
|
|
};
|
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
/*--------------------------------------------------------------------*/
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
struct OPCall : public T_Op
|
|
|
|
{
|
|
|
|
explicit OPCall(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& function );
|
2017-10-15 10:22:24 +02:00
|
|
|
void execute(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Context& ctx ) const override;
|
2017-10-15 10:22:24 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String function;
|
2017-10-15 10:22:24 +02:00
|
|
|
};
|
2017-10-14 12:00:47 +02:00
|
|
|
|
|
|
|
} // namespace cops
|