Moved GLSL handling to separate file
This commit is contained in:
parent
601cf6cb34
commit
8264663ec8
13 changed files with 348 additions and 325 deletions
5
Makefile
5
Makefile
|
@ -10,13 +10,18 @@ IMGUI = imgui.o imgui_demo.o imgui_draw.o
|
|||
DEMO = \
|
||||
main.o \
|
||||
imgui_impl_sdl.o \
|
||||
\
|
||||
utilities.o \
|
||||
texture.o \
|
||||
rendertarget.o \
|
||||
programs.o \
|
||||
\
|
||||
raymarcher.o \
|
||||
\
|
||||
bloom.o \
|
||||
dof.o \
|
||||
combine.o \
|
||||
\
|
||||
profiling.o
|
||||
|
||||
DEMO_DEPS = $(DEMO:%.o=.%.d)
|
||||
|
|
1
bloom.cc
1
bloom.cc
|
@ -2,6 +2,7 @@
|
|||
#include "utilities.hh"
|
||||
#include "texture.hh"
|
||||
#include "rendertarget.hh"
|
||||
#include "programs.hh"
|
||||
#include "bloom.hh"
|
||||
#include "profiling.hh"
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "utilities.hh"
|
||||
#include "texture.hh"
|
||||
#include "rendertarget.hh"
|
||||
#include "programs.hh"
|
||||
#include "combine.hh"
|
||||
#include "bloom.hh"
|
||||
#include "profiling.hh"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# include "texture.hh"
|
||||
# include "rendertarget.hh"
|
||||
# include "utilities.hh"
|
||||
# include "programs.hh"
|
||||
# undef REAL_BUILD
|
||||
#endif
|
||||
|
||||
|
|
5
dof.cc
5
dof.cc
|
@ -1,6 +1,7 @@
|
|||
#include "externals.hh"
|
||||
#include "utilities.hh"
|
||||
#include "texture.hh"
|
||||
#include "utilities.hh"
|
||||
#include "programs.hh"
|
||||
#include "rendertarget.hh"
|
||||
#include "dof.hh"
|
||||
#include "profiling.hh"
|
||||
|
@ -29,6 +30,8 @@ T_DoFPass::T_DoFPass(
|
|||
filterParams_{ 10 , 2 , 5 , 16 } ,
|
||||
nSamples_( 16 )
|
||||
{
|
||||
txPass1_.wrap( E_TexWrap::CLAMP_EDGE );
|
||||
|
||||
spPass1_.addFile( "dof-common.glsl" );
|
||||
spPass1_.addFile( "dof-pass1.glsl" );
|
||||
spPass1_.load( );
|
||||
|
|
2
dof.hh
2
dof.hh
|
@ -4,7 +4,7 @@
|
|||
# include "externals.hh"
|
||||
# include "texture.hh"
|
||||
# include "rendertarget.hh"
|
||||
# include "utilities.hh"
|
||||
# include "programs.hh"
|
||||
# undef REAL_BUILD
|
||||
#endif
|
||||
|
||||
|
|
1
main.cc
1
main.cc
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "utilities.hh"
|
||||
#include "programs.hh"
|
||||
#include "texture.hh"
|
||||
#include "rendertarget.hh"
|
||||
#include "raymarcher.hh"
|
||||
|
|
260
programs.cc
Normal file
260
programs.cc
Normal file
|
@ -0,0 +1,260 @@
|
|||
#include "externals.hh"
|
||||
#include "utilities.hh"
|
||||
#include "programs.hh"
|
||||
|
||||
|
||||
/*= T_ShaderCode =============================================================*/
|
||||
|
||||
T_ShaderCode::T_ShaderCode(
|
||||
__rd__ const int nparts )
|
||||
: code( nparts , nullptr )
|
||||
{ }
|
||||
|
||||
T_ShaderCode::~T_ShaderCode( )
|
||||
{
|
||||
for ( char* str : code ) {
|
||||
delete[] str;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_ShaderCode::setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ char const* const string )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
const int len( strlen( string ) + 1 );
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
char* const output( new char[ extraLen + len ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
strcpy( output + extraLen , string );
|
||||
code[ index ] = output;
|
||||
}
|
||||
|
||||
void T_ShaderCode::setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ void const* const data ,
|
||||
__rd__ const int size )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
char* const output( new char[ extraLen + size + 1 ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
memcpy( output + extraLen , data , size );
|
||||
output[ extraLen + size ] = 0;
|
||||
code[ index ] = output;
|
||||
}
|
||||
|
||||
bool T_ShaderCode::loadPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ std::string const& source ,
|
||||
__rw__ std::vector< std::string >& errors )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
FILE * f = fopen( source.c_str( ) , "r" );
|
||||
if ( !f ) {
|
||||
std::string error( "File not found: " );
|
||||
error += source;
|
||||
errors.push_back( error );
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
fseek( f , 0 , SEEK_END );
|
||||
const size_t size( ftell( f ) );
|
||||
fseek( f , 0 , SEEK_SET );
|
||||
|
||||
char* const output( new char[ extraLen + size + 1 ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
if ( fread( output + extraLen , 1 , size , f ) != size ) {
|
||||
fclose( f );
|
||||
delete[] output;
|
||||
std::string error( "Could not read file: " );
|
||||
error += source;
|
||||
errors.push_back( error );
|
||||
return false;
|
||||
}
|
||||
output[ extraLen + size ] = 0;
|
||||
fclose( f );
|
||||
code[ index ] = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
GLuint T_ShaderCode::createProgram(
|
||||
__rd__ GLenum type ,
|
||||
__rw__ std::vector< std::string >& errors ) const
|
||||
{
|
||||
GLenum sid = glCreateShaderProgramv( type , code.size( ) , &code[ 0 ] );
|
||||
if ( sid == 0 ) {
|
||||
errors.push_back( "Failed to create GL program" );
|
||||
return sid;
|
||||
}
|
||||
|
||||
int infoLogLength;
|
||||
glGetProgramiv( sid , GL_INFO_LOG_LENGTH , &infoLogLength );
|
||||
if ( infoLogLength ) {
|
||||
char buffer[ infoLogLength + 1 ];
|
||||
glGetProgramInfoLog( sid , infoLogLength , nullptr , buffer );
|
||||
char* start( buffer );
|
||||
char* found( strchr( buffer , '\n' ) );
|
||||
while ( found ) {
|
||||
*found = 0;
|
||||
errors.push_back( start );
|
||||
start = found + 1;
|
||||
found = strchr( start , '\n' );
|
||||
}
|
||||
if ( start < &buffer[ infoLogLength - 1 ] ) {
|
||||
errors.push_back( start );
|
||||
}
|
||||
}
|
||||
|
||||
int lnk;
|
||||
glGetProgramiv( sid , GL_LINK_STATUS , &lnk );
|
||||
if ( !lnk ) {
|
||||
glDeleteProgram( sid );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sid;
|
||||
}
|
||||
|
||||
|
||||
/*= T_ShaderProgram ==========================================================*/
|
||||
|
||||
T_ShaderProgram::T_ShaderProgram(
|
||||
__rd__ const GLenum programType ,
|
||||
__rw__ T_FilesWatcher& watcher )
|
||||
: files_( watcher , [this] { load( ); } ) ,
|
||||
programType_( programType ) , program_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
T_ShaderProgram::~T_ShaderProgram( )
|
||||
{
|
||||
if ( program_ != 0 ) {
|
||||
glDeleteProgram( program_ );
|
||||
}
|
||||
}
|
||||
|
||||
void T_ShaderProgram::addChunk(
|
||||
__rd__ std::string const& string )
|
||||
{
|
||||
chunksOrFiles_.push_back( true );
|
||||
parts_.push_back( string );
|
||||
}
|
||||
|
||||
void T_ShaderProgram::addFile(
|
||||
__rd__ std::string const& source )
|
||||
{
|
||||
chunksOrFiles_.push_back( false );
|
||||
parts_.push_back( source );
|
||||
}
|
||||
|
||||
void T_ShaderProgram::load( )
|
||||
{
|
||||
const auto n( parts_.size( ) );
|
||||
errors_.clear( );
|
||||
files_.clear( );
|
||||
if ( program_ != 0 ) {
|
||||
glDeleteProgram( program_ );
|
||||
program_ = 0;
|
||||
}
|
||||
|
||||
T_ShaderCode sc( n );
|
||||
printf( "LOAD PROGRAM" );
|
||||
for ( auto i = 0u ; i < n ; i ++ ) {
|
||||
if ( chunksOrFiles_[ i ] ) {
|
||||
printf( " %d:(chunk)" , i );
|
||||
sc.setPart( i , parts_[ i ].c_str( ) );
|
||||
} else {
|
||||
printf( " %d:%s" , i , parts_[ i ].c_str( ) );
|
||||
if ( sc.loadPart( i , parts_[ i ].c_str( ) , errors_ ) ) {
|
||||
files_.watch( parts_[ i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
|
||||
if ( errors_.size( ) == 0 ) {
|
||||
program_ = sc.createProgram( programType_ , errors_ );
|
||||
if ( program_ != 0 ) {
|
||||
GLint x;
|
||||
glGetProgramInterfaceiv( program_ , GL_PROGRAM_OUTPUT ,
|
||||
GL_ACTIVE_RESOURCES , &x );
|
||||
printf( "-> LOADED (%d output(s)" , x );
|
||||
for ( int i = 0 ; i < x ; i ++ ) {
|
||||
static const GLenum query[] = {
|
||||
GL_NAME_LENGTH , GL_LOCATION
|
||||
};
|
||||
int output[ 2 ];
|
||||
glGetProgramResourceiv( program_ , GL_PROGRAM_OUTPUT ,
|
||||
i , 2 , query , 2 , nullptr ,
|
||||
output );
|
||||
|
||||
char rName[ output[ 0 ] + 1 ];
|
||||
glGetProgramResourceName( program_ ,
|
||||
GL_PROGRAM_OUTPUT , i ,
|
||||
sizeof( rName ) , nullptr ,
|
||||
rName );
|
||||
printf( "%s %s@%d" , i == 0 ? ":" : "" , rName ,
|
||||
output[ 1 ] );
|
||||
}
|
||||
printf( ")\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( errors_.size( ) ) {
|
||||
printf( "\n--------------------------------------------------------------------------------\n\n" );
|
||||
for ( auto const& str : errors_ ) {
|
||||
printf( "ERR: %s\n" , str.c_str( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool T_ShaderProgram::activate( ) const
|
||||
{
|
||||
if ( program_ != 0 ) {
|
||||
glUseProgram( program_ );
|
||||
}
|
||||
return program_ != 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::unique_ptr< T_ShaderProgram > FsQuad_;
|
||||
}
|
||||
|
||||
T_ShaderProgram const& T_ShaderProgram::FullscreenQuad(
|
||||
__rw__ T_FilesWatcher& watcher )
|
||||
{
|
||||
if ( !FsQuad_ ) {
|
||||
FsQuad_ = std::make_unique< T_ShaderProgram >(
|
||||
GL_VERTEX_SHADER , watcher );
|
||||
FsQuad_->addFile( "fsquad.glsl" );
|
||||
FsQuad_->load( );
|
||||
}
|
||||
return *FsQuad_;
|
||||
}
|
72
programs.hh
Normal file
72
programs.hh
Normal file
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
#ifndef REAL_BUILD
|
||||
# include "externals.hh"
|
||||
# include "utilities.hh"
|
||||
#endif
|
||||
|
||||
/*= T_ShaderCode =============================================================*/
|
||||
|
||||
struct T_ShaderCode
|
||||
{
|
||||
T_ShaderCode( ) = delete;
|
||||
T_ShaderCode( T_ShaderCode const& ) = delete;
|
||||
T_ShaderCode( T_ShaderCode&& ) = delete;
|
||||
|
||||
explicit T_ShaderCode( __rd__ const int nparts );
|
||||
~T_ShaderCode( );
|
||||
|
||||
void setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ char const* const string );
|
||||
void setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ void const* const data ,
|
||||
__rd__ const int size );
|
||||
bool loadPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ std::string const& source ,
|
||||
__rw__ std::vector< std::string >& errors );
|
||||
|
||||
GLuint createProgram(
|
||||
__rd__ GLenum type ,
|
||||
__rw__ std::vector< std::string >& errors ) const;
|
||||
|
||||
private:
|
||||
std::vector< char* > code;
|
||||
};
|
||||
|
||||
struct T_ShaderProgram
|
||||
{
|
||||
T_ShaderProgram( ) = delete;
|
||||
T_ShaderProgram( T_ShaderProgram const& ) = delete;
|
||||
T_ShaderProgram( T_ShaderProgram&& ) = delete;
|
||||
|
||||
T_ShaderProgram(
|
||||
__rd__ GLenum programType ,
|
||||
__rw__ T_FilesWatcher& watcher );
|
||||
~T_ShaderProgram( );
|
||||
|
||||
void addChunk( __rd__ std::string const& string );
|
||||
void addFile( __rd__ std::string const& source );
|
||||
|
||||
void load( );
|
||||
bool activate( ) const;
|
||||
|
||||
GLuint id( ) const { return program_; }
|
||||
|
||||
static T_ShaderProgram const& FullscreenQuad(
|
||||
__rw__ T_FilesWatcher& watcher );
|
||||
|
||||
private:
|
||||
T_WatchedFiles files_;
|
||||
|
||||
std::vector< bool > chunksOrFiles_;
|
||||
std::vector< std::string > parts_;
|
||||
|
||||
std::vector< std::string > errors_;
|
||||
|
||||
GLenum programType_;
|
||||
GLuint program_;
|
||||
};
|
||||
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#include "utilities.hh"
|
||||
#include "texture.hh"
|
||||
#include "rendertarget.hh"
|
||||
#include "programs.hh"
|
||||
#include "raymarcher.hh"
|
||||
#include "profiling.hh"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# include "texture.hh"
|
||||
# include "rendertarget.hh"
|
||||
# include "utilities.hh"
|
||||
# include "programs.hh"
|
||||
# undef REAL_BUILD
|
||||
#endif
|
||||
|
||||
|
|
257
utilities.cc
257
utilities.cc
|
@ -157,263 +157,6 @@ bool T_WatchedFiles::watch(
|
|||
}
|
||||
|
||||
|
||||
/*= T_ShaderCode =============================================================*/
|
||||
|
||||
T_ShaderCode::T_ShaderCode(
|
||||
__rd__ const int nparts )
|
||||
: code( nparts , nullptr )
|
||||
{ }
|
||||
|
||||
T_ShaderCode::~T_ShaderCode( )
|
||||
{
|
||||
for ( char* str : code ) {
|
||||
delete[] str;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void T_ShaderCode::setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ char const* const string )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
const int len( strlen( string ) + 1 );
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
char* const output( new char[ extraLen + len ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
strcpy( output + extraLen , string );
|
||||
code[ index ] = output;
|
||||
}
|
||||
|
||||
void T_ShaderCode::setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ void const* const data ,
|
||||
__rd__ const int size )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
char* const output( new char[ extraLen + size + 1 ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
memcpy( output + extraLen , data , size );
|
||||
output[ extraLen + size ] = 0;
|
||||
code[ index ] = output;
|
||||
}
|
||||
|
||||
bool T_ShaderCode::loadPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ std::string const& source ,
|
||||
__rw__ std::vector< std::string >& errors )
|
||||
{
|
||||
assert( code[ index ] == nullptr );
|
||||
|
||||
FILE * f = fopen( source.c_str( ) , "r" );
|
||||
if ( !f ) {
|
||||
std::string error( "File not found: " );
|
||||
error += source;
|
||||
errors.push_back( error );
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[ 32 ];
|
||||
const int extraLen( index == 0 ? 0
|
||||
: snprintf( buffer , sizeof( buffer ) ,
|
||||
"\n#line 0 %d\n" , index ) );
|
||||
|
||||
fseek( f , 0 , SEEK_END );
|
||||
const size_t size( ftell( f ) );
|
||||
fseek( f , 0 , SEEK_SET );
|
||||
|
||||
char* const output( new char[ extraLen + size + 1 ] );
|
||||
if ( index != 0 ) {
|
||||
memcpy( output , buffer , extraLen );
|
||||
}
|
||||
if ( fread( output + extraLen , 1 , size , f ) != size ) {
|
||||
fclose( f );
|
||||
delete[] output;
|
||||
std::string error( "Could not read file: " );
|
||||
error += source;
|
||||
errors.push_back( error );
|
||||
return false;
|
||||
}
|
||||
output[ extraLen + size ] = 0;
|
||||
fclose( f );
|
||||
code[ index ] = output;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
GLuint T_ShaderCode::createProgram(
|
||||
__rd__ GLenum type ,
|
||||
__rw__ std::vector< std::string >& errors ) const
|
||||
{
|
||||
GLenum sid = glCreateShaderProgramv( type , code.size( ) , &code[ 0 ] );
|
||||
if ( sid == 0 ) {
|
||||
errors.push_back( "Failed to create GL program" );
|
||||
return sid;
|
||||
}
|
||||
|
||||
int infoLogLength;
|
||||
glGetProgramiv( sid , GL_INFO_LOG_LENGTH , &infoLogLength );
|
||||
if ( infoLogLength ) {
|
||||
char buffer[ infoLogLength + 1 ];
|
||||
glGetProgramInfoLog( sid , infoLogLength , nullptr , buffer );
|
||||
char* start( buffer );
|
||||
char* found( strchr( buffer , '\n' ) );
|
||||
while ( found ) {
|
||||
*found = 0;
|
||||
errors.push_back( start );
|
||||
start = found + 1;
|
||||
found = strchr( start , '\n' );
|
||||
}
|
||||
if ( start < &buffer[ infoLogLength - 1 ] ) {
|
||||
errors.push_back( start );
|
||||
}
|
||||
}
|
||||
|
||||
int lnk;
|
||||
glGetProgramiv( sid , GL_LINK_STATUS , &lnk );
|
||||
if ( !lnk ) {
|
||||
glDeleteProgram( sid );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sid;
|
||||
}
|
||||
|
||||
|
||||
/*= T_ShaderProgram ==========================================================*/
|
||||
|
||||
T_ShaderProgram::T_ShaderProgram(
|
||||
__rd__ const GLenum programType ,
|
||||
__rw__ T_FilesWatcher& watcher )
|
||||
: files_( watcher , [this] { load( ); } ) ,
|
||||
programType_( programType ) , program_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
T_ShaderProgram::~T_ShaderProgram( )
|
||||
{
|
||||
if ( program_ != 0 ) {
|
||||
glDeleteProgram( program_ );
|
||||
}
|
||||
}
|
||||
|
||||
void T_ShaderProgram::addChunk(
|
||||
__rd__ std::string const& string )
|
||||
{
|
||||
chunksOrFiles_.push_back( true );
|
||||
parts_.push_back( string );
|
||||
}
|
||||
|
||||
void T_ShaderProgram::addFile(
|
||||
__rd__ std::string const& source )
|
||||
{
|
||||
chunksOrFiles_.push_back( false );
|
||||
parts_.push_back( source );
|
||||
}
|
||||
|
||||
void T_ShaderProgram::load( )
|
||||
{
|
||||
const auto n( parts_.size( ) );
|
||||
errors_.clear( );
|
||||
files_.clear( );
|
||||
if ( program_ != 0 ) {
|
||||
glDeleteProgram( program_ );
|
||||
program_ = 0;
|
||||
}
|
||||
|
||||
T_ShaderCode sc( n );
|
||||
printf( "LOAD PROGRAM" );
|
||||
for ( auto i = 0u ; i < n ; i ++ ) {
|
||||
if ( chunksOrFiles_[ i ] ) {
|
||||
printf( " %d:(chunk)" , i );
|
||||
sc.setPart( i , parts_[ i ].c_str( ) );
|
||||
} else {
|
||||
printf( " %d:%s" , i , parts_[ i ].c_str( ) );
|
||||
if ( sc.loadPart( i , parts_[ i ].c_str( ) , errors_ ) ) {
|
||||
files_.watch( parts_[ i ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
|
||||
if ( errors_.size( ) == 0 ) {
|
||||
program_ = sc.createProgram( programType_ , errors_ );
|
||||
if ( program_ != 0 ) {
|
||||
GLint x;
|
||||
glGetProgramInterfaceiv( program_ , GL_PROGRAM_OUTPUT ,
|
||||
GL_ACTIVE_RESOURCES , &x );
|
||||
printf( "-> LOADED (%d output(s)" , x );
|
||||
for ( int i = 0 ; i < x ; i ++ ) {
|
||||
static const GLenum query[] = {
|
||||
GL_NAME_LENGTH , GL_LOCATION
|
||||
};
|
||||
int output[ 2 ];
|
||||
glGetProgramResourceiv( program_ , GL_PROGRAM_OUTPUT ,
|
||||
i , 2 , query , 2 , nullptr ,
|
||||
output );
|
||||
|
||||
char rName[ output[ 0 ] + 1 ];
|
||||
glGetProgramResourceName( program_ ,
|
||||
GL_PROGRAM_OUTPUT , i ,
|
||||
sizeof( rName ) , nullptr ,
|
||||
rName );
|
||||
printf( "%s %s@%d" , i == 0 ? ":" : "" , rName ,
|
||||
output[ 1 ] );
|
||||
}
|
||||
printf( ")\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( errors_.size( ) ) {
|
||||
printf( "\n--------------------------------------------------------------------------------\n\n" );
|
||||
for ( auto const& str : errors_ ) {
|
||||
printf( "ERR: %s\n" , str.c_str( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool T_ShaderProgram::activate( ) const
|
||||
{
|
||||
if ( program_ != 0 ) {
|
||||
glUseProgram( program_ );
|
||||
}
|
||||
return program_ != 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::unique_ptr< T_ShaderProgram > FsQuad_;
|
||||
}
|
||||
|
||||
T_ShaderProgram const& T_ShaderProgram::FullscreenQuad(
|
||||
__rw__ T_FilesWatcher& watcher )
|
||||
{
|
||||
if ( !FsQuad_ ) {
|
||||
FsQuad_ = std::make_unique< T_ShaderProgram >(
|
||||
GL_VERTEX_SHADER , watcher );
|
||||
FsQuad_->addFile( "fsquad.glsl" );
|
||||
FsQuad_->load( );
|
||||
}
|
||||
return *FsQuad_;
|
||||
}
|
||||
|
||||
|
||||
/*= T_Camera =================================================================*/
|
||||
|
||||
void T_Camera::handleDND(
|
||||
|
|
66
utilities.hh
66
utilities.hh
|
@ -107,72 +107,6 @@ struct T_WatchedFiles
|
|||
};
|
||||
|
||||
|
||||
/*= T_ShaderCode =============================================================*/
|
||||
|
||||
struct T_ShaderCode
|
||||
{
|
||||
T_ShaderCode( ) = delete;
|
||||
T_ShaderCode( T_ShaderCode const& ) = delete;
|
||||
T_ShaderCode( T_ShaderCode&& ) = delete;
|
||||
|
||||
explicit T_ShaderCode( __rd__ const int nparts );
|
||||
~T_ShaderCode( );
|
||||
|
||||
void setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ char const* const string );
|
||||
void setPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ void const* const data ,
|
||||
__rd__ const int size );
|
||||
bool loadPart(
|
||||
__rd__ const int index ,
|
||||
__rd__ std::string const& source ,
|
||||
__rw__ std::vector< std::string >& errors );
|
||||
|
||||
GLuint createProgram(
|
||||
__rd__ GLenum type ,
|
||||
__rw__ std::vector< std::string >& errors ) const;
|
||||
|
||||
private:
|
||||
std::vector< char* > code;
|
||||
};
|
||||
|
||||
struct T_ShaderProgram
|
||||
{
|
||||
T_ShaderProgram( ) = delete;
|
||||
T_ShaderProgram( T_ShaderProgram const& ) = delete;
|
||||
T_ShaderProgram( T_ShaderProgram&& ) = delete;
|
||||
|
||||
T_ShaderProgram(
|
||||
__rd__ GLenum programType ,
|
||||
__rw__ T_FilesWatcher& watcher );
|
||||
~T_ShaderProgram( );
|
||||
|
||||
void addChunk( __rd__ std::string const& string );
|
||||
void addFile( __rd__ std::string const& source );
|
||||
|
||||
void load( );
|
||||
bool activate( ) const;
|
||||
|
||||
GLuint id( ) const { return program_; }
|
||||
|
||||
static T_ShaderProgram const& FullscreenQuad(
|
||||
__rw__ T_FilesWatcher& watcher );
|
||||
|
||||
private:
|
||||
T_WatchedFiles files_;
|
||||
|
||||
std::vector< bool > chunksOrFiles_;
|
||||
std::vector< std::string > parts_;
|
||||
|
||||
std::vector< std::string > errors_;
|
||||
|
||||
GLenum programType_;
|
||||
GLuint program_;
|
||||
};
|
||||
|
||||
|
||||
/*= T_Camera =================================================================*/
|
||||
|
||||
struct T_Camera
|
||||
|
|
Loading…
Reference in a new issue