demotool/c-shaders.hh

99 lines
1.9 KiB
C++
Raw 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_String source;
uint32_t line;
T_String error;
T_ShaderError( ) = default;
T_ShaderError( T_String source ,
const uint32_t line ,
T_String error )
: source( std::move( source ) ) , line( line ) ,
error( std::move( error ) )
{ }
T_ShaderError( T_String 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_String text;
uint32_t lines;
T_ShaderInputChunk( ) = default;
T_ShaderInputChunk(
const E_ShaderInputChunk type ,
T_String text ,
const uint32_t lines )
: type( type ) , text( std::move( text ) ) , 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_String const& path );
};
using P_ShaderInput = T_OwnPtr< T_ShaderInput >;