Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ShaderEditor Class Referencefinal

Shader editor that can be used to tweak shaders on the fly, reloading them and exposing parameters for adjustements. More...

#include <ShaderEditor.hpp>

Classes

struct  BoolOption
 Boolean flag parameter. More...
 
struct  ColorOption
 RGB Color parameter. More...
 
struct  FloatOption
 Float parameter. More...
 
struct  IntOption
 Integer parameter. More...
 
struct  VecOption
 4D Vector parameter. More...
 

Public Member Functions

 ShaderEditor (RenderingConfig &config, Window &window)
 
void draw () override
 
void update () override
 
void resize () override
 
 ~ShaderEditor () override
 
void loadShader (const std::string &path)
 
- Public Member Functions inherited from CameraApp
 CameraApp (RenderingConfig &config, Window &window)
 
virtual void update () override
 
virtual void physics (double fullTime, double frameTime)
 
- Public Member Functions inherited from Application
 Application (RenderingConfig &config, Window &window)
 
virtual void draw ()=0
 
virtual void update ()
 
virtual void finish ()
 
virtual void resize ()=0
 
double timeElapsed ()
 
double frameTime ()
 
double frameRate ()
 
Windowwindow ()
 
virtual ~Application ()
 
 Application (const Application &)=delete
 
Applicationoperator= (const Application &)=delete
 
 Application (Application &&)=delete
 
Applicationoperator= (Application &&)=delete
 

Private Types

enum class  LayoutMode : int { HORIZONTAL , VERTICAL , FREEFORM }
 GUI layout options. More...
 

Private Member Functions

void handleShortcuts ()
 
void displayUniforms (uint columnsCount)
 
std::string reload (const std::string &shaderPath, bool syncUniforms)
 
void restoreUniforms ()
 
std::string generateParametersString (const std::string &prefix, bool exportValues)
 

Private Attributes

Texture _frame0
 Content texture.
 
Texture _frame1
 Content texture.
 
Texture_currFrame
 Content texture indirection.
 
Texture_prevFrame
 Content texture indirection.
 
std::string _shaderPath
 Path of the current shader on disk.
 
std::string _shaderName
 Name of the current shader (for display).
 
std::unique_ptr< Program_currProgram
 Current shader program.
 
Program_passthrough
 Passthrough program.
 
GPUQuery _timer = GPUQuery(GPUQuery::Type::TIME_ELAPSED)
 Timer for the user shader pass.
 
std::vector< const Texture * > _textures
 List of all predefined textures.
 
Texture _noise
 Random 2D RGBA uniform noise in [0,1].
 
Texture _perlin
 Random 2D RGBA periodic Perlin noise in [0,1].
 
Texture _directions
 Random 3D directions on the sphere.
 
Texture _noise3D
 Random 3D RGBA uniform noise in [0,1].
 
Texture _perlin3D
 Random 3D RGBA periodic Perlin noise in [0,1].
 
const Texture_fallbackTex = nullptr
 Display texture for non-2D inputs.
 
std::vector< BoolOption_flags
 Predefined boolean parameters.
 
std::vector< IntOption_integers
 Predefined integer parameters.
 
std::vector< FloatOption_floats
 Predefined float parameters.
 
std::vector< VecOption_vectors
 Predefined vector parameters.
 
std::vector< ColorOption_colors
 Predefined color parameters.
 
uint _frame = 0
 Current frame ID.
 
double _currentTime = 0.0
 Current time.
 
double _startTime = 0.0
 Time at which the shader began to play.
 
bool _paused = false
 Should time/frame count flow.
 
bool _showGUI = true
 Show the GUI parameters panel.
 
bool _windowed = false
 Should the result be displayed in a subwindow.
 
LayoutMode _layout = LayoutMode::HORIZONTAL
 The GUI panel layout.
 
std::string _compilationLog
 Compilation log, will be displayed in a fixed panel if not empty.
 

Additional Inherited Members

- Protected Member Functions inherited from CameraApp
void freezeCamera (bool shouldFreeze)
 
- Protected Attributes inherited from CameraApp
ControllableCamera _userCamera
 The interactive camera.
 
- Protected Attributes inherited from Application
RenderingConfig_config
 The current configuration.
 
std::unique_ptr< DebugViewer_debug
 Debug viewer.
 

Detailed Description

Shader editor that can be used to tweak shaders on the fly, reloading them and exposing parameters for adjustements.

Inherits CameraApp.

Member Enumeration Documentation

◆ LayoutMode

enum class ShaderEditor::LayoutMode : int
strongprivate

GUI layout options.

Enumerator
HORIZONTAL 

Panel to the left, result to the right.

VERTICAL 

Panel at the bottom, result at the top.

FREEFORM 

Panels can be freely moved around.

Constructor & Destructor Documentation

◆ ShaderEditor()

ShaderEditor::ShaderEditor ( RenderingConfig config,
Window window 
)
explicit

Constructor.

Parameters
configthe configuration to apply
windowthe window to render to

◆ ~ShaderEditor()

ShaderEditor::~ShaderEditor ( )
override

Destructor.

Member Function Documentation

◆ displayUniforms()

void ShaderEditor::displayUniforms ( uint  columnsCount)
private

Display the uniform GUI elements.

Parameters
columnsCountmaximum number of columns to use for small elements (booleans,...)

◆ draw()

void ShaderEditor::draw ( )
overridevirtual

Draw call.

Implements Application.

◆ generateParametersString()

std::string ShaderEditor::generateParametersString ( const std::string &  prefix,
bool  exportValues 
)
private

Helper generation of a string listing all predefined tweakable uniforms.

Parameters
prefixprefix to append before each element type ("uniform" or "const" for instance)
exportValuesshould the current values be writtent ("float f0 = 3.0;" for instance)
Returns
the generated string

◆ handleShortcuts()

void ShaderEditor::handleShortcuts ( )
private

React to user key inputs.

◆ loadShader()

void ShaderEditor::loadShader ( const std::string &  path)

Load an external shader from disk.

Parameters
paththe path to the file on disk

◆ reload()

std::string ShaderEditor::reload ( const std::string &  shaderPath,
bool  syncUniforms 
)
private

Reload the shader and get the potential error message.

Parameters
shaderPathpath to the shader to reload on disk
syncUniformsshould the predefined uniforms be extracted from the shader and their values transferred to the GUI
Returns
the compilation error log or an empty string

◆ resize()

void ShaderEditor::resize ( )
overridevirtual

Handle a window resize event, the configuration has been updated with the new size.

Implements Application.

◆ restoreUniforms()

void ShaderEditor::restoreUniforms ( )
private

Restore the values of all predefined uniforms that are present in the shader with default values.

◆ update()

void ShaderEditor::update ( )
overridevirtual

Per-frame update.

Reimplemented from CameraApp.


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