matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
engine::resources::ShaderCompiler Class Reference

Compiles GLSL shaders from a single source file. Vertex, Fragment and Geometry shaders are seperated by the // #shader vertex|fragment|geometry directive. All the code following the directive belongs to the source of the shader specified in the #shader directive. Here is an example: More...

#include <ShaderCompiler.hpp>

Public Member Functions

ShaderParsingResult parse_source ()
 Splits a single shader source string into vertex, fragment, [geometry] shader strings.
 

Static Public Member Functions

static Shader compile_from_source (std::string shader_name, std::string shader_source)
 Compiles a shader from source.
 
static Shader compile_from_file (std::string shader_name, const std::filesystem::path &shader_path)
 Compiles a shader from file.
 

Private Member Functions

graphics::OpenGL::ShaderProgramId compile (const ShaderParsingResult &shader_sources)
 Compile shader sources into a OpenGL shader program.
 
 ShaderCompiler (std::string shader_name, std::string shader_source)
 
std::string * now_parsing (ShaderParsingResult &result, const std::string &line)
 Returns the output field from the ShaderParsingResult for which to continue appending lines of the m_sources. Detects if the line contains // #shader directive and returns a pointer to the appropriate field in the ShaderParsingResult.
 
uint32_t compile (const std::string &shader_source, ShaderType type)
 Compiles a single shader (Vertex|Fragment|Geometry) (not the whole program).
 

Private Attributes

std::string m_shader_name
 
std::string m_sources
 

Detailed Description

Compiles GLSL shaders from a single source file. Vertex, Fragment and Geometry shaders are seperated by the // #shader vertex|fragment|geometry directive. All the code following the directive belongs to the source of the shader specified in the #shader directive. Here is an example:

//#shader vertex
#version 330 core
layout (location = 0) in vec3 aPos;
void main() {
gl_Position = vec4(aPos, 1.0);
}
//#shader fragment
#version 330 core
out vec4 FragColor;
void main() {
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
}
int main(int argc, char **argv)
Definition TestApp.cpp:14

Constructor & Destructor Documentation

◆ ShaderCompiler()

engine::resources::ShaderCompiler::ShaderCompiler ( std::string  shader_name,
std::string  shader_source 
)
inlineprivate

Member Function Documentation

◆ compile_from_source()

Shader engine::resources::ShaderCompiler::compile_from_source ( std::string  shader_name,
std::string  shader_source 
)
static

Compiles a shader from source.

Parameters
shader_name
shader_sourcestring for the vertex, fragment, [geometry] shader
Returns
Compiled Shader object that can be used for drawing.

◆ compile_from_file()

Shader engine::resources::ShaderCompiler::compile_from_file ( std::string  shader_name,
const std::filesystem::path &  shader_path 
)
static

Compiles a shader from file.

Parameters
shader_name
shader_pathcontaining the source for the vertex, fragment, [geometry] shader
Returns
Compiled Shader object that can be used for drawing.

◆ parse_source()

ShaderParsingResult engine::resources::ShaderCompiler::parse_source ( )

Splits a single shader source string into vertex, fragment, [geometry] shader strings.

Returns
ShaderParsingResult

◆ compile() [1/2]

OpenGL::ShaderProgramId engine::resources::ShaderCompiler::compile ( const ShaderParsingResult shader_sources)
private

Compile shader sources into a OpenGL shader program.

Returns
A graphics::OpenGL::ShaderProgramId referencing OpenGL shader program.

◆ now_parsing()

std::string * engine::resources::ShaderCompiler::now_parsing ( ShaderParsingResult result,
const std::string &  line 
)
private

Returns the output field from the ShaderParsingResult for which to continue appending lines of the m_sources. Detects if the line contains // #shader directive and returns a pointer to the appropriate field in the ShaderParsingResult.

◆ compile() [2/2]

uint32_t engine::resources::ShaderCompiler::compile ( const std::string &  shader_source,
ShaderType  type 
)
private

Compiles a single shader (Vertex|Fragment|Geometry) (not the whole program).

Parameters
shader_source
typeof the shader to compile Vertex|Fragment|Geometry
Returns
OpenGL id to a compiled shader.

Member Data Documentation

◆ m_shader_name

std::string engine::resources::ShaderCompiler::m_shader_name
private

◆ m_sources

std::string engine::resources::ShaderCompiler::m_sources
private

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