I try to enhance OpenGLContext copyTexture allowing an alpha multiplier (and later an AffineTransform).
When I simply add an additional Uniform to the Params struct, I get an GL_INVALID_OPERATION on set (float).
struct Params
{
Params (juce::OpenGLShaderProgram& prog)
: positionAttribute (prog, "position"),
screenSize (prog, "screenSize"),
imageTexture (prog, "imageTexture"),
textureBounds (prog, "textureBounds"),
vOffsetAndScale (prog, "vOffsetAndScale"),
alphaMultiplier (prog, "alphaMultiplier") // < new addition
{}
void set (const float targetWidth, const float targetHeight, const juce::Rectangle<float>& bounds, bool flipVertically, float alpha) const
{
const GLfloat m[] = { bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() };
textureBounds.set (m, 4);
JUCE_CHECK_OPENGL_ERROR
imageTexture.set (0);
JUCE_CHECK_OPENGL_ERROR
screenSize.set (targetWidth, targetHeight);
JUCE_CHECK_OPENGL_ERROR
vOffsetAndScale.set (flipVertically ? 0.0f : 1.0f,
flipVertically ? 1.0f : -1.0f);
JUCE_CHECK_OPENGL_ERROR
alphaMultiplier.set (alpha);
JUCE_CHECK_OPENGL_ERROR // <== here GL_INVALID_OPERATION is triggered
}
juce::OpenGLShaderProgram::Attribute positionAttribute;
juce::OpenGLShaderProgram::Uniform screenSize, imageTexture, textureBounds, vOffsetAndScale, alphaMultiplier;
// ^-----------
};
I tried with or without adding the uniform in the shader:
prog.addFragmentShader (juce::OpenGLHelpers::translateFragmentShaderToV3 (
"uniform sampler2D imageTexture;"
"varying " JUCE_HIGHP " vec2 texturePos;"
"uniform " JUCE_HIGHP " float alphaMultiplier;" // < tried with or without this line
"void main()"
"{"
"gl_FragColor = texture2D (imageTexture, texturePos);"
"}"));
Is there anything else I need to do to add an additional parameter to the shader?
Any hint is much appreciated!
