From e8801e7c09414753a8e01a6be303c7922bbe023f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 3 Oct 2016 14:17:03 +0200 Subject: Enable shader disk cache in Qt Quick Change-Id: I14ee97ee75664c5dfcd229a5be2be6294c936b2c Task-number: QTBUG-55496 Reviewed-by: Andy Nichols --- .../quick/scenegraph/openglunderqml/squircle.cpp | 32 +++++++++++----------- .../quick/scenegraph/rendernode/openglrenderer.cpp | 4 +-- examples/quick/scenegraph/shared/logorenderer.cpp | 8 ++---- 3 files changed, 20 insertions(+), 24 deletions(-) (limited to 'examples/quick/scenegraph') diff --git a/examples/quick/scenegraph/openglunderqml/squircle.cpp b/examples/quick/scenegraph/openglunderqml/squircle.cpp index 6b25756e61..b7082892b8 100644 --- a/examples/quick/scenegraph/openglunderqml/squircle.cpp +++ b/examples/quick/scenegraph/openglunderqml/squircle.cpp @@ -125,22 +125,22 @@ void SquircleRenderer::paint() initializeOpenGLFunctions(); m_program = new QOpenGLShaderProgram(); - m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, - "attribute highp vec4 vertices;" - "varying highp vec2 coords;" - "void main() {" - " gl_Position = vertices;" - " coords = vertices.xy;" - "}"); - m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, - "uniform lowp float t;" - "varying highp vec2 coords;" - "void main() {" - " lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));" - " i = smoothstep(t - 0.8, t + 0.8, i);" - " i = floor(i * 20.) / 20.;" - " gl_FragColor = vec4(coords * .5 + .5, i, i);" - "}"); + m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, + "attribute highp vec4 vertices;" + "varying highp vec2 coords;" + "void main() {" + " gl_Position = vertices;" + " coords = vertices.xy;" + "}"); + m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, + "uniform lowp float t;" + "varying highp vec2 coords;" + "void main() {" + " lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));" + " i = smoothstep(t - 0.8, t + 0.8, i);" + " i = floor(i * 20.) / 20.;" + " gl_FragColor = vec4(coords * .5 + .5, i, i);" + "}"); m_program->bindAttributeLocation("vertices", 0); m_program->link(); diff --git a/examples/quick/scenegraph/rendernode/openglrenderer.cpp b/examples/quick/scenegraph/rendernode/openglrenderer.cpp index 3de864b7b9..2edb6bd929 100644 --- a/examples/quick/scenegraph/rendernode/openglrenderer.cpp +++ b/examples/quick/scenegraph/rendernode/openglrenderer.cpp @@ -86,8 +86,8 @@ void OpenGLRenderNode::init() " gl_FragColor = col * opacity;\n" "}\n"; - m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); - m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); m_program->bindAttributeLocation("posAttr", 0); m_program->bindAttributeLocation("colAttr", 1); m_program->link(); diff --git a/examples/quick/scenegraph/shared/logorenderer.cpp b/examples/quick/scenegraph/shared/logorenderer.cpp index 06f4892a49..8eb2d44c1e 100644 --- a/examples/quick/scenegraph/shared/logorenderer.cpp +++ b/examples/quick/scenegraph/shared/logorenderer.cpp @@ -70,7 +70,6 @@ void LogoRenderer::initialize() glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - QOpenGLShader *vshader1 = new QOpenGLShader(QOpenGLShader::Vertex, &program1); const char *vsrc1 = "attribute highp vec4 vertex;\n" "attribute mediump vec3 normal;\n" @@ -85,19 +84,16 @@ void LogoRenderer::initialize() " color = clamp(color, 0.0, 1.0);\n" " gl_Position = matrix * vertex;\n" "}\n"; - vshader1->compileSourceCode(vsrc1); - QOpenGLShader *fshader1 = new QOpenGLShader(QOpenGLShader::Fragment, &program1); const char *fsrc1 = "varying mediump vec4 color;\n" "void main(void)\n" "{\n" " gl_FragColor = color;\n" "}\n"; - fshader1->compileSourceCode(fsrc1); - program1.addShader(vshader1); - program1.addShader(fshader1); + program1.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vsrc1); + program1.addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fsrc1); program1.link(); vertexAttr1 = program1.attributeLocation("vertex"); -- cgit v1.2.3