22 #ifndef CARDSMOOTHEDGESHADERSTAGE_H_
23 #define CARDSMOOTHEDGESHADERSTAGE_H_
27 #if defined(HAVE_OPENGL) && defined(TARGET_DEVICE)
28 #define USE_SMOOTHEDGE_SHADER 1
30 #undef USE_SMOOTHEDGE_SHADER
33 #if defined(USE_SMOOTHEDGE_SHADER)
35 #include <QtOpenGL/qglcustomshaderstage_p.h>
38 class CardSmoothEdgeShaderStage :
public QGLCustomShaderStage
42 CardSmoothEdgeShaderStage()
49 static char const shaderSrc[] =
51 uniform highp vec2 Start; \n\
52 uniform highp vec2 Center; \n\
53 uniform highp float Delta; \n\
54 lowp vec4 customShader(lowp sampler2D imageTexture, highp vec2 textureCoords) \n\
56 highp vec2 CoordH = max((abs(textureCoords - (/*vec2(1.0,1.0) -*/ Center)) / Center), vec2(0.0)); \n\
57 lowp float AlphaH = smoothstep(1.0, (1.0-Delta), CoordH.y); \n\
58 highp vec2 CoordV = max((abs(textureCoords - Center)) / (Center), vec2(0.0)); \n\
59 lowp float AlphaV = smoothstep(1.0, (1.0-Delta), CoordV.x); \n\
60 lowp float Alpha = min(AlphaH, AlphaV); \n\
61 return vec4(texture2D(imageTexture, textureCoords).rgb * Alpha, Alpha); \n\
67 virtual void setUniforms(QGLShaderProgram* program) {
68 program->setUniformValue(
"Center", (m_dstWidth * 0.5f) / m_srcWidth, (m_dstHeight * 0.5f) / m_srcHeight);
69 program->setUniformValue(
"Delta", qFuzzyCompare(m_scale, 1.0f) ? 0.01f : 0.09f);
72 void setParameters(
int srcWidth,
int srcHeight,
int dstWidth,
int dstHeight) {
74 m_srcWidth = srcWidth;
75 m_srcHeight = srcHeight;
76 m_dstWidth = dstWidth;
77 m_dstHeight = dstHeight;
82 void setSourceParameters(
int srcWidth,
int srcHeight) {
84 m_srcWidth = srcWidth;
85 m_srcHeight = srcHeight;
90 void dumpParameters() {
91 qDebug() <<
"srcW" << m_srcWidth
92 <<
"srcH" << m_srcHeight
93 <<
"dstW" << m_dstWidth
94 <<
"dstH" << m_dstHeight
95 <<
"scale" << m_scale;
98 void clone(CardSmoothEdgeShaderStage* other)
const {
100 other->m_srcWidth = m_srcWidth;
101 other->m_srcHeight = m_srcHeight;
102 other->m_dstWidth = m_dstWidth;
103 other->m_dstHeight = m_dstHeight;
104 other->m_scale = m_scale;
107 void setScale(
float scale) {
111 else if (m_scale > 1.0f)