The Vish Visualization Shell 0.3
Vish
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Wizt::Programmable Class Referenceabstract

A helper class to create a shader program from either intrinsic code, or external files, as given under the specified name in Programmable::CompileShader(). More...

#include <ocean/Anemonia/Programmable.hpp>

Inheritance diagram for Wizt::Programmable:
Wizt::ProgrammableGeometry

Classes

struct  ShaderPrefix
 
struct  ShaderSegment
 

Public Types

typedef RenderBasin::Program Program
 Shortcut typedef.
 

Public Member Functions

RefPtr< RenderBasin::ProgramCompileShader (VRenderContext &Context, const std::string &Name, const RenderBasin::Program::Setup &SetupFunction=nullptr, const RefPtr< RenderBasin::Program > &ExistingProgram=NullPtr(), const glsl &LocalVertexShaderPrefixCode="", const glsl &LocalGeometryShaderPrefixCode="", const glsl &LocalFragmentShaderPrefixCode="") const
 Compile the shader into an OpenGL Program.
 
void enableViewportArray (bool EnableFragmentLayerViewport=true)
 
virtual glsl fragment_shader (VRenderContext &Context) const =0
 Vertexshader GLGS code.
 
virtual glsl geometry_shader (VRenderContext &Context) const
 Geometry GLGS code, not used here, only in subclass ProgrammableGeometry .
 
virtual glsl GeometryShaderPrefix (VRenderContext &Context) const
 Optional context-dependent prefix shader code.
 
std::pair< glsl, string > getCode (VRenderContext &Context, const std::string &Name, const std::string &Ext, std::string(Programmable::*shader)(VRenderContext &Context) const, const string &PrefixCode) const
 Return the combination of GLSL source code and the filename from which it was read.
 
void setGLSLVersion (const string &v_version, const string &g_version, const string &f_version)
 Set the version number string, e.g.
 
void setGLSLVersion (const string &version)
 Set the version number string, e.g.
 
virtual glsl vertex_shader (VRenderContext &Context) const =0
 Vertexshader GLGS code.
 

Static Public Member Functions

static string OptionalFileRead (const string &filename, const string &text)
 Read some string from the given file, using the given text as default if no such file exists.
 
static glsl setNumberOfLightSources (VRenderContext &Context, const std::string &VariableName="lightNum")
 Produce GLSL code including the number of light sources that are currently active in the render context.
 

Public Attributes

glsl f_prefix
 Optional shader code to be always prefixed in the fragment shader.
 
glsl g_prefix
 Optional static shader code to be always prefixed in the geometry shader.
 
RenderBasin::GeometryInputType GeometryInput
 Input type for geometry shaders.
 
RenderBasin::GeometryOutputType GeometryOutput
 Output type for geometry shaders.
 
glsl v_prefix
 Optional shader code to be always prefixed in the vertex shader.
 

Static Public Attributes

static const char default_fragment_shader []
 Default fragment code.
 
static const char default_geometry_shader []
 Default geometry code.
 
static const char default_vertex_shader []
 Default vertex shader.
 

Detailed Description

A helper class to create a shader program from either intrinsic code, or external files, as given under the specified name in Programmable::CompileShader().

If no files exist, then the virtual functions are called. If files exist, they are read in and their content used instead. If files exist but have zero length, then they will be overwritten and the internal code will be inserted into them.

Todo:
As of now, there is no path searching implemented. Shader code will be used from the current directory, whatever this might be.

Member Function Documentation

◆ enableViewportArray()

void Wizt::Programmable::enableViewportArray ( bool  EnableFragmentLayerViewport = true)
       During construction, i.e. after calling setGLSLVersion(),
       calling this function will enable the
       <A HREF="https://registry.khronos.org/OpenGL/extensions/ARB/ARB_viewport_array.txt">
       viewport arrays extension
       </A> and optionally also
       <A HREF="https://registry.khronos.org/OpenGL/extensions/ARB/ARB_fragment_layer_viewport.txt">
       fragment layer support
       </A>.
       If enabled, the geometry shader (required) must write to the variable
       \b gl_ViewportIndex to specify which viewport to address for the next
       primitive. Note that its \b max_vertices specification must be multiplied
       accordingly by the maximum number of viewports, e.g. 16 as supported by
       OpenGL.
       With the fragment layer extension, the \b gl_ViewportIndex also becomes available
       in the fragment shader as a read-only input directive.

       The rendering infrastructure provides two global variables that designate the
       range of viewports as enabled by the user interface:
       @code

uniform int vish_MinViewportIndex = 0; uniform int vish_MaxViewportIndex = 1; The macro vish_for_Viewport(i) may be used to iterate over all enabled viewports in the geometry shader, the macro vish_ViewportValue01(i) computes a float value in the range from 0.0 to 1.0 depending on the viewport for use in the geometry shader. Equivalently, the function vish_ViewportValue01() provides such a scaled floating point value in the fragment shader (without argument, for the respective gl_ViewportIndex that is available in the fragment shader).

◆ OptionalFileRead()

string Wizt::Programmable::OptionalFileRead ( const string &  filename,
const string &  text 
)
static

Read some string from the given file, using the given text as default if no such file exists.

If a file of the given name exists and contains nothing more than a question mark, then the file will be created using that default text.

◆ setGLSLVersion() [1/2]

void Wizt::Programmable::setGLSLVersion ( const string &  v_version,
const string &  g_version,
const string &  f_version 
)

Set the version number string, e.g.

"130", on for the various shaders. This function will overwrite all existing values of the shader prefixes. Appending values after calling this function is an option.

◆ setGLSLVersion() [2/2]

void Wizt::Programmable::setGLSLVersion ( const string &  version)

Set the version number string, e.g.

"130", on all shader prefixes. This function will overwrite all existing values of the shader prefixes. If shader version numbers need to be different, or special enable flags are to be set, then call the alternative functions with multiple arguments. Appending values after calling this function is an option.

◆ setNumberOfLightSources()

std::string Wizt::Programmable::setNumberOfLightSources ( VRenderContext Context,
const std::string &  VariableName = "lightNum" 
)
static

Produce GLSL code including the number of light sources that are currently active in the render context.

This call will define an integer constant such as:

const int lightNum = ...; // number of active light sources

Member Data Documentation

◆ g_prefix

glsl Wizt::Programmable::g_prefix

Optional static shader code to be always prefixed in the geometry shader.

The default code sets the version to 120 and enables geometry shader

#version 120\n
#extension GL_EXT_geometry_shader4 : enable

Referenced by Wizt::ProgrammableGeometry::CompileGeometryShader().

◆ v_prefix

glsl Wizt::Programmable::v_prefix

Optional shader code to be always prefixed in the vertex shader.

For instance, the version setting may go here.

Referenced by Wizt::ProgrammableGeometry::CompileGeometryShader().