cgv
cgv::render::shader_code Class Reference

#include <shader_code.h>

Inheritance diagram for cgv::render::shader_code:
cgv::render::render_component

Public Member Functions

 shader_code ()
 create shader a shader code object
 
 ~shader_code ()
 calls the destruct method
 
void destruct (const context &ctx)
 destruct shader code More...
 
bool read_code (const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, std::string defines="")
 read shader code from file More...
 
bool set_code (const context &ctx, const std::string &source, ShaderType st)
 set shader code from string
 
void set_defines (std::string &source, const std::string &defines)
 set shader code defines
 
ShaderType get_shader_type () const
 return the shader type of this code
 
bool compile (const context &ctx)
 compile attached source; returns true if successful
 
bool read_and_compile (const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, bool show_error=true, std::string defines="")
 read shader code from file, compile and print error message if necessary More...
 
bool is_compiled () const
 return whether shader has been compiled successfully
 
virtual bool is_created () const
 return whether component has been created
 
void put_id_void (void *ptr) const
 
template<typename T >
void put_id (T &id) const
 cast the refence to rendering api specific representation of component id to the specified type
 

Static Public Member Functions

static std::string find_file (const std::string &file_name)
 
static std::string get_last_error (const std::string &file_name, const std::string &last_error)
 
static std::string read_code_file (const std::string &file_name, std::string *_last_error=0)
 read shader code from file and return string with content or empty string if read failed
 
static ShaderType detect_shader_type (const std::string &file_name)
 

Public Attributes

const contextctx_ptr
 keep pointer to my context
 
std::string last_error
 a string that contains the last error
 

Protected Attributes

ShaderType st
 store the shader type
 

Detailed Description

a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added to a shader program.

Member Function Documentation

◆ destruct()

void cgv::render::shader_code::destruct ( const context ctx)

destruct shader code

destruct shader

◆ detect_shader_type()

ShaderType cgv::render::shader_code::detect_shader_type ( const std::string &  file_name)
static

detect the shader type from the extension of the given file_name, i.e.

  • glvs ... ST_VERTEX
  • glgs ... ST_GEOMETRY
  • glfs ... ST_FRAGMENT
  • glcs ... ST_COMPUTE

◆ find_file()

std::string cgv::render::shader_code::find_file ( const std::string &  file_name)
static

Check if file exists. If not, check if a resource file of this file_name has been registered. If not search it recursively in the shader_path of the shader_config that can be accessed with the function get_shader_config(). This path is initialized to the environment variable CGV_SHADER_PATH or empty if that is not defined.

◆ get_last_error()

std::string cgv::render::shader_code::get_last_error ( const std::string &  file_name,
const std::string &  last_error 
)
static

format given last error in a way that developer environments can locate errors in the source file

query the last error in a way that developer environments can locate errors in the source file

◆ put_id_void()

void cgv::render::render_component::put_id_void ( void *  ptr) const
inherited

copy the rendering api specific id the component to the memory location of the given pointer. For opengl this the passed pointer should be of type GLint or GLuint.

◆ read_and_compile()

bool cgv::render::shader_code::read_and_compile ( const context ctx,
const std::string &  file_name,
ShaderType  st = ST_DETECT,
bool  show_error = true,
std::string  defines = "" 
)

read shader code from file, compile and print error message if necessary

read shader code with read_code and compile. If show_error is true print error messages formated with the get_last_error method in case an error arose.

◆ read_code()

bool cgv::render::shader_code::read_code ( const context ctx,
const std::string &  file_name,
ShaderType  st = ST_DETECT,
std::string  defines = "" 
)

read shader code from file

read shader code from file that is searched for with find_file. If the shader type defaults to ST_DETECT, the detect_shader_type() method is applied to the file name.


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