demotool/c-shaders.hh

109 lines
2.1 KiB
C++
Raw Permalink Normal View History

#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
/*= COMMON PROPERTIES ========================================================*/
// Type of shader
enum class E_ShaderType {
VERTEX , FRAGMENT , GEOMETRY ,
COMPUTE ,
__COUNT__
};
// Errors in shader code - the errors it represents may come from either
// the input loader, the shader loader or the driver.
struct T_ShaderError
{
T_FSPath source;
uint32_t line;
T_String error;
T_ShaderError( ) = default;
T_ShaderError( T_FSPath source ,
const uint32_t line ,
T_String error )
: source( std::move( source ) ) , line( line ) ,
error( std::move( error ) )
{ }
T_ShaderError( T_FSPath source ,
const uint32_t line ,
T_StringBuilder& error )
: source( std::move( source ) ) , line( line ) ,
error( std::move( error ) )
{ }
};
/*= INPUT FILES ==============================================================*/
// Type of input chunk
enum class E_ShaderInputChunk {
CODE ,
INCLUDE ,
};
// Input chunk data
struct T_ShaderInputChunk
{
E_ShaderInputChunk type;
T_Union< T_String , T_FSPath > data;
uint32_t lines;
T_ShaderInputChunk( ) = default;
T_ShaderInputChunk(
T_String text ,
const uint32_t lines )
: type( E_ShaderInputChunk::CODE ) ,
data( std::move( text ) ) ,
lines( lines )
{ }
T_ShaderInputChunk(
T_FSPath path ,
const uint32_t lines )
: type( E_ShaderInputChunk::INCLUDE ) ,
data( std::move( path ) ) ,
lines( lines )
{ }
};
// Input file type
enum class E_ShaderInput {
CHUNK , // Chunk that may be repeated
LIBRARY , // Library (will only be loaded once)
// "Main" shader source files
VERTEX , FRAGMENT , GEOMETRY ,
COMPUTE
};
// Preprocessing errors
struct T_ShaderInputError
{
uint32_t line;
T_String error;
T_ShaderInputError(
const uint32_t line ,
T_String error )
: line( line ) , error( std::move( error ) )
{ }
};
// Source file
struct T_ShaderInput
{
E_ShaderInput type = E_ShaderInput::CHUNK;
T_Array< T_ShaderInputChunk > chunks;
T_Array< T_ShaderInputError > errors;
bool load( T_FSPath const& path );
};
using P_ShaderInput = T_OwnPtr< T_ShaderInput >;