Blender V5.0
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)
static size_t line_number (const std::string &file_str, size_t pos)
static size_t line_number (const std::smatch &smatch)
static size_t char_number (const std::string &file_str, size_t pos)
static size_t char_number (const std::smatch &smatch)
static std::string line_str (const std::string &file_str, size_t pos)
static std::string line_str (const std::smatch &smatch)

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 159 of file glsl_preprocess.hh.

Member Enumeration Documentation

◆ SourceLanguage

Enumerator
UNKNOWN 
CPP 
MSL 
GLSL 
BLENDER_GLSL 

Definition at line 176 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 2451 of file glsl_preprocess.hh.

References str.

Referenced by line_count().

◆ char_number() [1/2]

size_t blender::gpu::shader::Preprocessor::char_number ( const std::smatch & smatch)
inlinestatic

Definition at line 2561 of file glsl_preprocess.hh.

References char_number().

◆ char_number() [2/2]

size_t blender::gpu::shader::Preprocessor::char_number ( const std::string & file_str,
size_t pos )
inlinestatic

Definition at line 2553 of file glsl_preprocess.hh.

References pos.

Referenced by char_number().

◆ 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 2485 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 2340 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 186 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 2456 of file glsl_preprocess.hh.

References char_count(), and str.

Referenced by line_number().

◆ line_number() [1/2]

size_t blender::gpu::shader::Preprocessor::line_number ( const std::smatch & smatch)
inlinestatic

Definition at line 2546 of file glsl_preprocess.hh.

References line_number().

◆ line_number() [2/2]

size_t blender::gpu::shader::Preprocessor::line_number ( const std::string & file_str,
size_t pos )
inlinestatic

Definition at line 2534 of file glsl_preprocess.hh.

References line_count(), and pos.

Referenced by line_number().

◆ line_str() [1/2]

std::string blender::gpu::shader::Preprocessor::line_str ( const std::smatch & smatch)
inlinestatic

Definition at line 2577 of file glsl_preprocess.hh.

References line_str().

◆ line_str() [2/2]

std::string blender::gpu::shader::Preprocessor::line_str ( const std::string & file_str,
size_t pos )
inlinestatic

Definition at line 2568 of file glsl_preprocess.hh.

References pos.

Referenced by line_str().

◆ process() [1/2]

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

Definition at line 285 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 2464 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 2442 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 2430 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 2506 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: