Blender V4.5
blender::gpu::shader::Preprocessor Class Reference

#include <glsl_preprocess.hh>

Public Types

enum  SourceLanguage {
  UNKNOWN = 0 , CPP , MSL , GLSL ,
  BLENDER_GLSL
}

Public Member Functions

std::string process (SourceLanguage language, std::string str, const std::string &filename, bool do_parse_function, bool do_small_type_linting, report_callback report_error, metadata::Source &r_metadata)
std::string process (const std::string &str)

Static Public Member Functions

static SourceLanguage language_from_filename (const std::string &filename)
static std::string get_content_between_balanced_pair (const std::string &input, char start_delimiter, char end_delimiter, const bool backwards=false)
static std::string replace_char_between_balanced_pair (const std::string &input, const char start_delimiter, const char end_delimiter, const char from, const char to)
static std::vector< std::string > split_string (const std::string &str, const char delimiter)
static std::vector< std::string > split_string_not_between_balanced_pair (const std::string &str, const char delimiter, const char pair_start, const char pair_end)
static void replace_all (std::string &str, const std::string &from, const std::string &to)
static void replace_all (std::string &str, const char from, const char to)
static int64_t char_count (const std::string &str, char c)
static int64_t line_count (const std::string &str)
static void reference_search (std::string &str, std::function< void(int, int, char &)> callback)
static void default_argument_search (std::string &str, std::function< void(int, int, char &)> callback)
static void scopes_scan_for_char (std::string &str, char search_char, std::function< void(size_t, int, int, char &)> callback)

Detailed Description

Shader source preprocessor that allow to mutate GLSL into cross API source that can be interpreted by the different GPU backends. Some syntax are mutated or reported as incompatible.

Implementation speed is not a huge concern as we only apply this at compile time or on python shaders source.

Definition at line 150 of file glsl_preprocess.hh.

Member Enumeration Documentation

◆ SourceLanguage

Enumerator
UNKNOWN 
CPP 
MSL 
GLSL 
BLENDER_GLSL 

Definition at line 164 of file glsl_preprocess.hh.

Member Function Documentation

◆ char_count()

int64_t blender::gpu::shader::Preprocessor::char_count ( const std::string & str,
char c )
inlinestatic

Definition at line 1643 of file glsl_preprocess.hh.

References str.

Referenced by line_count().

◆ default_argument_search()

void blender::gpu::shader::Preprocessor::default_argument_search ( std::string & str,
std::function< void(int, int, char &)> callback )
inlinestatic

Definition at line 1677 of file glsl_preprocess.hh.

References pos, scopes_scan_for_char(), and str.

◆ get_content_between_balanced_pair()

std::string blender::gpu::shader::Preprocessor::get_content_between_balanced_pair ( const std::string & input,
char start_delimiter,
char end_delimiter,
const bool backwards = false )
inlinestatic

Definition at line 1532 of file glsl_preprocess.hh.

References balance(), i, and input.

Referenced by blender::gpu::tests::test_preprocess_utilities().

◆ language_from_filename()

SourceLanguage blender::gpu::shader::Preprocessor::language_from_filename ( const std::string & filename)
inlinestatic

Definition at line 174 of file glsl_preprocess.hh.

References CPP, GLSL, MSL, and UNKNOWN.

◆ line_count()

int64_t blender::gpu::shader::Preprocessor::line_count ( const std::string & str)
inlinestatic

Definition at line 1648 of file glsl_preprocess.hh.

References char_count(), and str.

◆ process() [1/2]

std::string blender::gpu::shader::Preprocessor::process ( const std::string & str)
inline

Definition at line 253 of file glsl_preprocess.hh.

References GLSL, process(), and str.

◆ process() [2/2]

std::string blender::gpu::shader::Preprocessor::process ( SourceLanguage language,
std::string str,
const std::string & filename,
bool do_parse_function,
bool do_small_type_linting,
report_callback report_error,
metadata::Source & r_metadata )
inline

◆ reference_search()

void blender::gpu::shader::Preprocessor::reference_search ( std::string & str,
std::function< void(int, int, char &)> callback )
inlinestatic

Definition at line 1656 of file glsl_preprocess.hh.

References pos, scopes_scan_for_char(), and str.

Referenced by blender::gpu::tests::test_preprocess_utilities().

◆ replace_all() [1/2]

void blender::gpu::shader::Preprocessor::replace_all ( std::string & str,
const char from,
const char to )
inlinestatic

Definition at line 1634 of file glsl_preprocess.hh.

References str.

◆ replace_all() [2/2]

void blender::gpu::shader::Preprocessor::replace_all ( std::string & str,
const std::string & from,
const std::string & to )
inlinestatic

Definition at line 1622 of file glsl_preprocess.hh.

References str.

Referenced by split_string_not_between_balanced_pair().

◆ replace_char_between_balanced_pair()

std::string blender::gpu::shader::Preprocessor::replace_char_between_balanced_pair ( const std::string & input,
const char start_delimiter,
const char end_delimiter,
const char from,
const char to )
inlinestatic

◆ scopes_scan_for_char()

void blender::gpu::shader::Preprocessor::scopes_scan_for_char ( std::string & str,
char search_char,
std::function< void(size_t, int, int, char &)> callback )
inlinestatic

Definition at line 1698 of file glsl_preprocess.hh.

References pos, and str.

Referenced by default_argument_search(), and reference_search().

◆ split_string()

std::vector< std::string > blender::gpu::shader::Preprocessor::split_string ( const std::string & str,
const char delimiter )
inlinestatic

◆ split_string_not_between_balanced_pair()

std::vector< std::string > blender::gpu::shader::Preprocessor::split_string_not_between_balanced_pair ( const std::string & str,
const char delimiter,
const char pair_start,
const char pair_end )
inlinestatic

The documentation for this class was generated from the following file: