gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
gVirtualXRay::Shader Class Reference

Shader is a class to handle shaders written in GLSL. More...

#include <Shader.h>

Collaboration diagram for gVirtualXRay::Shader:
Collaboration graph

Public Member Functions

 Shader ()
 Default constructor. More...
 
 ~Shader ()
 Destructor. More...
 
void enable () const
 Enable the current shader. More...
 
void release ()
 
void loadFiles (const std::string &aVertexShaderFilename, const std::string &aFragmentShaderFilename)
 Load the vertex and fragment shaders from files. More...
 
void loadFile (const std::string &aComputeShaderFilename)
 Load the compute shader from a file. More...
 
void setLabels (const std::string &aVertexShaderLabel, const std::string &aFragmentShaderLabel)
 Set the vertex and fragment shader labels. This is useful for debugging. More...
 
void setLabel (const std::string &aComputeShaderLabel)
 Set the compute shader label. This is useful for debugging. More...
 
void loadVertexShaderFile (const std::string &aVertexShaderFilename)
 Load the vertex shader from a file. More...
 
void loadFragmentShaderFile (const std::string &aFragmentShaderFilename)
 Load the fragment shader from a file. More...
 
void loadComputeShaderFile (const std::string &aComputeShaderFilename)
 Load the compute shader from a file. More...
 
void loadSource (const std::string &aVertexShaderSourceCode, const std::string &aFragmentShaderSourceCode)
 Load the shader source code. More...
 
void loadSource (const std::string &aComputeShaderSourceCode)
 Load the shader source code. More...
 
void loadVertexShaderSource (const std::string &aVertexShaderSourceCode)
 Load the vertex shader from a string. More...
 
void loadFragmentShaderSource (const std::string &aFragmentShaderSourceCode)
 Load the fragment shader from a string. More...
 
void loadComputeShaderSource (const std::string &aComputeShaderSourceCode)
 Load the compute shader from a string. More...
 
unsigned int getProgramHandle () const
 Accessor on the shader program handle. More...
 
bool isValid () const
 Accessor on the validity status of the shader. More...
 

Static Public Member Functions

static void disable ()
 Disable the current shader (if any) More...
 

Protected Member Functions

int loadFile (const std::string &aShaderFilename, char **&aShaderSource)
 Load a text file and store its content. More...
 
unsigned int compileShader (int aShaderType, int aLineNumber, char **aShaderSource)
 Compile the vertex shader or the fragment shader. More...
 
void linkProgram ()
 Link the vertex and fragment programs. More...
 
void releaseVertexSourceMemory ()
 Release the memory held by the vertex shader. More...
 
void releaseFragmentSourceMemory ()
 Release the memory held by the fragment shader. More...
 
void releaseComputeSourceMemory ()
 Release the memory held by the compute shader. More...
 
void releaseSourceMemory (int &aLineNumber, char **&aShaderSource)
 Release the memory held by the vertex shader or the fragment shader. More...
 

Protected Attributes

std::string m_vertex_shader_label
 Label of the vertex shader. More...
 
std::string m_fragment_shader_label
 Label of the fragment shader. More...
 
std::string m_compute_shader_label
 Label of the compute shader. More...
 
std::string m_vertex_shader_filename
 Name of the file containing the vertex shader. More...
 
std::string m_fragment_shader_filename
 Name of the file containing the fragment shader. More...
 
std::string m_compute_shader_filename
 Name of the file containing the compute shader. More...
 
char ** m_vertex_source
 Source code of the vertex shader. More...
 
int m_vertex_source_number_of_lines
 Number of line of the vertex shader. More...
 
char ** m_fragment_source
 Source code of the fragment shader. More...
 
int m_fragment_source_number_of_lines
 Number of line of the fragment shader. More...
 
char ** m_compute_source
 Source code of the vertex shader. More...
 
int m_compute_source_number_of_lines
 Number of line of the vertex shader. More...
 
bool m_valid
 
unsigned int m_shader_program_id
 ID of the shader program. More...
 
unsigned int m_vertex_shader_id
 ID of the vertex shader. More...
 
unsigned int m_fragment_shader_id
 ID of the fragment shader. More...
 
unsigned int m_compute_shader_id
 ID of the compute shader. More...
 

Static Protected Attributes

static bool m_shader_capable
 Flag set to true when a shader if fully valid. More...
 

Detailed Description

Shader is a class to handle shaders written in GLSL.

Definition at line 87 of file Shader.h.

Constructor & Destructor Documentation

◆ Shader()

gVirtualXRay::Shader::Shader ( )

Default constructor.

◆ ~Shader()

gVirtualXRay::Shader::~Shader ( )

Destructor.

Member Function Documentation

◆ compileShader()

unsigned int gVirtualXRay::Shader::compileShader ( int  aShaderType,
int  aLineNumber,
char **  aShaderSource 
)
protected

Compile the vertex shader or the fragment shader.

Parameters
aShaderTypetype of shader (GL_VERTEX_SHADER, GL_FRAGMENT_SHADER or GL_COMPUTE_SHADER)
aLineNumberthe number of lines of the source code
aShaderSourcesource code of the vertex or fragment shader
Returns
the corresponding ID

◆ disable()

static void gVirtualXRay::Shader::disable ( )
static

Disable the current shader (if any)

◆ enable()

void gVirtualXRay::Shader::enable ( ) const

Enable the current shader.

◆ getProgramHandle()

unsigned int gVirtualXRay::Shader::getProgramHandle ( ) const
inline

Accessor on the shader program handle.

Returns
the shader program handle

Definition at line 87 of file Shader.inl.

◆ isValid()

bool gVirtualXRay::Shader::isValid ( ) const
inline

Accessor on the validity status of the shader.

Returns
true if the shader is valid, false if it is not

Definition at line 95 of file Shader.inl.

◆ linkProgram()

void gVirtualXRay::Shader::linkProgram ( )
protected

Link the vertex and fragment programs.

◆ loadComputeShaderFile()

void gVirtualXRay::Shader::loadComputeShaderFile ( const std::string &  aComputeShaderFilename)

Load the compute shader from a file.

Parameters
aComputeShaderFilenamefile name of the compute shader

◆ loadComputeShaderSource()

void gVirtualXRay::Shader::loadComputeShaderSource ( const std::string &  aComputeShaderSourceCode)

Load the compute shader from a string.

Parameters
aComputeShaderSourceCodethe compute shader source code

◆ loadFile() [1/2]

void gVirtualXRay::Shader::loadFile ( const std::string &  aComputeShaderFilename)

Load the compute shader from a file.

Parameters
aComputeShaderFilenamefile name of the compute shader

◆ loadFile() [2/2]

int gVirtualXRay::Shader::loadFile ( const std::string &  aShaderFilename,
char **&  aShaderSource 
)
protected

Load a text file and store its content.

Parameters
aShaderFilenamefile name of the vertex or fragment shader
aShaderSourcesource code of the vertex or fragment shader
Returns
the number of lines in the file

◆ loadFiles()

void gVirtualXRay::Shader::loadFiles ( const std::string &  aVertexShaderFilename,
const std::string &  aFragmentShaderFilename 
)

Load the vertex and fragment shaders from files.

Parameters
aVertexShaderFilenamefile name of the vertex shader
aFragmentShaderFilenamefile name of the fragment shader

◆ loadFragmentShaderFile()

void gVirtualXRay::Shader::loadFragmentShaderFile ( const std::string &  aFragmentShaderFilename)

Load the fragment shader from a file.

Parameters
aFragmentShaderFilenamefile name of the fragment shader

◆ loadFragmentShaderSource()

void gVirtualXRay::Shader::loadFragmentShaderSource ( const std::string &  aFragmentShaderSourceCode)

Load the fragment shader from a string.

Parameters
aFragmentShaderSourceCodethe fragment shader source code

◆ loadSource() [1/2]

void gVirtualXRay::Shader::loadSource ( const std::string &  aVertexShaderSourceCode,
const std::string &  aFragmentShaderSourceCode 
)

Load the shader source code.

Parameters
aVertexShaderSourceCodesource code of the vertex shader
aFragmentShaderSourceCodesource code of the fragment shader

◆ loadSource() [2/2]

void gVirtualXRay::Shader::loadSource ( const std::string &  aComputeShaderSourceCode)

Load the shader source code.

Parameters
aComputeShaderSourceCodesource code of the compute shader

◆ loadVertexShaderFile()

void gVirtualXRay::Shader::loadVertexShaderFile ( const std::string &  aVertexShaderFilename)

Load the vertex shader from a file.

Parameters
aVertexShaderFilenamefile name of the vertex shader

◆ loadVertexShaderSource()

void gVirtualXRay::Shader::loadVertexShaderSource ( const std::string &  aVertexShaderSourceCode)

Load the vertex shader from a string.

Parameters
aVertexShaderSourceCodethe vertex shader source code

◆ release()

void gVirtualXRay::Shader::release ( )

Reset (delete the current shader if it is loaded, and restore default values).

◆ releaseComputeSourceMemory()

void gVirtualXRay::Shader::releaseComputeSourceMemory ( )
inlineprotected

Release the memory held by the compute shader.

Definition at line 119 of file Shader.inl.

◆ releaseFragmentSourceMemory()

void gVirtualXRay::Shader::releaseFragmentSourceMemory ( )
inlineprotected

Release the memory held by the fragment shader.

Definition at line 111 of file Shader.inl.

◆ releaseSourceMemory()

void gVirtualXRay::Shader::releaseSourceMemory ( int &  aLineNumber,
char **&  aShaderSource 
)
protected

Release the memory held by the vertex shader or the fragment shader.

Parameters
aLineNumberthe number of lines of the source code
aShaderSourcesource code of the vertex or fragment shader

◆ releaseVertexSourceMemory()

void gVirtualXRay::Shader::releaseVertexSourceMemory ( )
inlineprotected

Release the memory held by the vertex shader.

Definition at line 103 of file Shader.inl.

◆ setLabel()

void gVirtualXRay::Shader::setLabel ( const std::string &  aComputeShaderLabel)
inline

Set the compute shader label. This is useful for debugging.

Parameters
aComputeShaderLabellabel of the compute shader

Definition at line 79 of file Shader.inl.

◆ setLabels()

void gVirtualXRay::Shader::setLabels ( const std::string &  aVertexShaderLabel,
const std::string &  aFragmentShaderLabel 
)
inline

Set the vertex and fragment shader labels. This is useful for debugging.

Parameters
aVertexShaderLabellabel of the vertex shader
aFragmentShaderLabellabel of the fragment shader

Definition at line 69 of file Shader.inl.

Field Documentation

◆ m_compute_shader_filename

std::string gVirtualXRay::Shader::m_compute_shader_filename
protected

Name of the file containing the compute shader.

Definition at line 342 of file Shader.h.

◆ m_compute_shader_id

unsigned int gVirtualXRay::Shader::m_compute_shader_id
protected

ID of the compute shader.

Definition at line 388 of file Shader.h.

◆ m_compute_shader_label

std::string gVirtualXRay::Shader::m_compute_shader_label
protected

Label of the compute shader.

Definition at line 330 of file Shader.h.

◆ m_compute_source

char** gVirtualXRay::Shader::m_compute_source
protected

Source code of the vertex shader.

Definition at line 362 of file Shader.h.

◆ m_compute_source_number_of_lines

int gVirtualXRay::Shader::m_compute_source_number_of_lines
protected

Number of line of the vertex shader.

Definition at line 366 of file Shader.h.

◆ m_fragment_shader_filename

std::string gVirtualXRay::Shader::m_fragment_shader_filename
protected

Name of the file containing the fragment shader.

Definition at line 338 of file Shader.h.

◆ m_fragment_shader_id

unsigned int gVirtualXRay::Shader::m_fragment_shader_id
protected

ID of the fragment shader.

Definition at line 384 of file Shader.h.

◆ m_fragment_shader_label

std::string gVirtualXRay::Shader::m_fragment_shader_label
protected

Label of the fragment shader.

Definition at line 326 of file Shader.h.

◆ m_fragment_source

char** gVirtualXRay::Shader::m_fragment_source
protected

Source code of the fragment shader.

Definition at line 354 of file Shader.h.

◆ m_fragment_source_number_of_lines

int gVirtualXRay::Shader::m_fragment_source_number_of_lines
protected

Number of line of the fragment shader.

Definition at line 358 of file Shader.h.

◆ m_shader_capable

bool gVirtualXRay::Shader::m_shader_capable
staticprotected

Flag set to true when a shader if fully valid.

Definition at line 318 of file Shader.h.

◆ m_shader_program_id

unsigned int gVirtualXRay::Shader::m_shader_program_id
protected

ID of the shader program.

Definition at line 376 of file Shader.h.

◆ m_valid

bool gVirtualXRay::Shader::m_valid
protected

Flag set to true if the vertex shader, the fragment shader and the shader program are all valid

Definition at line 372 of file Shader.h.

◆ m_vertex_shader_filename

std::string gVirtualXRay::Shader::m_vertex_shader_filename
protected

Name of the file containing the vertex shader.

Definition at line 334 of file Shader.h.

◆ m_vertex_shader_id

unsigned int gVirtualXRay::Shader::m_vertex_shader_id
protected

ID of the vertex shader.

Definition at line 380 of file Shader.h.

◆ m_vertex_shader_label

std::string gVirtualXRay::Shader::m_vertex_shader_label
protected

Label of the vertex shader.

Definition at line 322 of file Shader.h.

◆ m_vertex_source

char** gVirtualXRay::Shader::m_vertex_source
protected

Source code of the vertex shader.

Definition at line 346 of file Shader.h.

◆ m_vertex_source_number_of_lines

int gVirtualXRay::Shader::m_vertex_source_number_of_lines
protected

Number of line of the vertex shader.

Definition at line 350 of file Shader.h.


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