JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::OpenGLGraphicsContextCustomShader Struct Reference

Used to create custom shaders for use with an openGL 2D rendering context. More...

#include <juce_OpenGLGraphicsContext.h>

Collaboration diagram for juce::OpenGLGraphicsContextCustomShader:

Public Member Functions

 OpenGLGraphicsContextCustomShader (const String &fragmentShaderCode)
 Creates a custom shader. More...
 
 ~OpenGLGraphicsContextCustomShader ()
 Destructor. More...
 
Result checkCompilation (LowLevelGraphicsContext &)
 Attempts to compile the program if necessary, and returns an error message if it fails. More...
 
void fillRect (LowLevelGraphicsContext &, Rectangle< int > area) const
 Applies the shader to a rectangle within the graphics context. More...
 
const StringgetFragmentShaderCode () const noexcept
 Returns the code that was used to create this object. More...
 
OpenGLShaderProgramgetProgram (LowLevelGraphicsContext &) const
 Returns the program, if it has been linked and is active. More...
 

Public Attributes

std::function< void(OpenGLShaderProgram &)> onShaderActivated
 Optional lambda that will be called when the shader is activated, to allow user code to do setup tasks. More...
 

Private Attributes

String code
 
String hashName
 

Detailed Description

Used to create custom shaders for use with an openGL 2D rendering context.

Given a GL-based rendering context, you can write a fragment shader that applies some kind of per-pixel effect.

@tags{OpenGL}

Constructor & Destructor Documentation

◆ OpenGLGraphicsContextCustomShader()

juce::OpenGLGraphicsContextCustomShader::OpenGLGraphicsContextCustomShader ( const String fragmentShaderCode)

Creates a custom shader.

The shader code will not be compiled until actually needed, so it's OK to call this constructor when no GL context is active.

The code should be a normal fragment shader. As well as the usual GLSL variables, there is also an automatically declared varying vec2 called "pixelPos", which indicates the pixel position within the graphics context of the pixel being drawn. There is also a varying value "pixelAlpha", which indicates the alpha by which the pixel should be multiplied, so that the edges of any clip-region masks are anti-aliased correctly.

◆ ~OpenGLGraphicsContextCustomShader()

juce::OpenGLGraphicsContextCustomShader::~OpenGLGraphicsContextCustomShader ( )

Destructor.

Member Function Documentation

◆ checkCompilation()

Result juce::OpenGLGraphicsContextCustomShader::checkCompilation ( LowLevelGraphicsContext )

Attempts to compile the program if necessary, and returns an error message if it fails.

◆ fillRect()

void juce::OpenGLGraphicsContextCustomShader::fillRect ( LowLevelGraphicsContext ,
Rectangle< int area 
) const

Applies the shader to a rectangle within the graphics context.

◆ getFragmentShaderCode()

const String& juce::OpenGLGraphicsContextCustomShader::getFragmentShaderCode ( ) const
inlinenoexcept

Returns the code that was used to create this object.

◆ getProgram()

OpenGLShaderProgram* juce::OpenGLGraphicsContextCustomShader::getProgram ( LowLevelGraphicsContext ) const

Returns the program, if it has been linked and is active.

This can be called when you're about to use fillRect, to set up any uniforms/textures that the program may require.

Member Data Documentation

◆ code

String juce::OpenGLGraphicsContextCustomShader::code
private

◆ hashName

String juce::OpenGLGraphicsContextCustomShader::hashName
private

◆ onShaderActivated

std::function<void (OpenGLShaderProgram&)> juce::OpenGLGraphicsContextCustomShader::onShaderActivated

Optional lambda that will be called when the shader is activated, to allow user code to do setup tasks.


The documentation for this struct was generated from the following file: