22 #ifndef CARDROUNDEDCORNERSHADERSTAGE_H_
23 #define CARDROUNDEDCORNERSHADERSTAGE_H_
27 #if defined(USE_ROUNDEDCORNER_SHADER)
29 #include <QtOpenGL/qglcustomshaderstage_p.h>
32 class CardRoundedCornerShaderStage :
public QGLCustomShaderStage
36 CardRoundedCornerShaderStage()
46 static char const shaderSrc[] =
48 uniform highp vec2 Start; \n\
49 uniform highp vec2 Center; \n\
50 uniform highp float Delta; \n\
51 uniform highp float Active; \n\
52 lowp vec4 customShader(lowp sampler2D imageTexture, highp vec2 textureCoords) \n\
54 highp vec2 Coord = max((abs(textureCoords - Center) - Start) / (Center - Start), vec2(0.0)); \n\
55 lowp float Alpha = smoothstep(1.0, 1.0 - Delta, length(Coord)); \n\
56 return vec4(texture2D(imageTexture, textureCoords).rgb * Alpha * Active, Alpha); \n\
62 virtual void setUniforms(QGLShaderProgram* program) {
64 float horizRadiusFactor = 0.5f - (m_radius * 1.0f)/m_dstWidth;
65 float vertRadiusFactor = 0.5f - (m_radius * 1.0f)/m_dstHeight;
69 if (m_dstWidth > m_dstHeight) {
70 horizRadiusFactor = 0.491f;
71 vertRadiusFactor = 0.49f;
74 horizRadiusFactor = 0.491f;
75 vertRadiusFactor = 0.49f;
79 if (m_dstWidth > m_dstHeight) {
80 horizRadiusFactor = 0.491f;
81 vertRadiusFactor = 0.473f;
84 horizRadiusFactor = 0.483f;
85 vertRadiusFactor = 0.478f;
88 else if (m_radius>45){
89 horizRadiusFactor = 0.481f;
90 vertRadiusFactor = 0.487f;
93 if (m_dstWidth > m_dstHeight) {
94 horizRadiusFactor = 0.491f;
95 vertRadiusFactor = 0.473f;
98 horizRadiusFactor = 0.491f;
99 vertRadiusFactor = 0.478f;
105 float CenterX=(m_dstWidth * 0.5f) / m_srcWidth;
106 float CenterY=(m_dstHeight * 0.5f) / m_srcHeight;
108 horizRadiusFactor = qMin(horizRadiusFactor, CenterX);
109 vertRadiusFactor = qMin(vertRadiusFactor, CenterY);
119 program->setUniformValue(
"Start", horizRadiusFactor, vertRadiusFactor);
120 program->setUniformValue(
"Center", (m_dstWidth * 0.5f) / m_srcWidth, (m_dstHeight * 0.5f) / m_srcHeight);
121 program->setUniformValue(
"Delta", qFuzzyCompare(m_scale, 1.0f) ? 0.01f : 0.3f);
122 program->setUniformValue(
"Active", m_active);
125 void setParameters(
int srcWidth,
int srcHeight,
int dstWidth,
int dstHeight,
int radius,
float active = 1.0f) {
127 m_srcWidth = srcWidth;
128 m_srcHeight = srcHeight;
129 m_dstWidth = dstWidth;
130 m_dstHeight = dstHeight;
137 void setSourceParameters(
int srcWidth,
int srcHeight) {
139 m_srcWidth = srcWidth;
140 m_srcHeight = srcHeight;
145 void dumpParameters() {
146 qDebug() <<
"srcW" << m_srcWidth
147 <<
"srcH" << m_srcHeight
148 <<
"dstW" << m_dstWidth
149 <<
"dstH" << m_dstHeight
150 <<
"radius" << m_radius
151 <<
"scale" << m_scale
152 <<
"active" << m_active;
155 void clone(CardRoundedCornerShaderStage* other)
const {
157 other->m_srcWidth = m_srcWidth;
158 other->m_srcHeight = m_srcHeight;
159 other->m_dstWidth = m_dstWidth;
160 other->m_dstHeight = m_dstHeight;
161 other->m_radius = m_radius;
162 other->m_scale = m_scale;
163 other->m_active = m_active;
166 void setScale(
float scale) {
170 else if (m_scale > 1.0f)