mirror of
				https://github.com/Swordfish90/cool-retro-term.git
				synced 2025-11-04 09:02:14 +00:00 
			
		
		
		
	Unload burnin effect when not in use.
This commit is contained in:
		@@ -2,10 +2,10 @@ import QtQuick 2.0
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import "utils.js" as Utils
 | 
					import "utils.js" as Utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Item {
 | 
					Loader {
 | 
				
			||||||
    id: burnInEffect
 | 
					    id: burnInEffect
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    readonly property alias source: burnInEffectSource
 | 
					    property ShaderEffectSource source: item ? item.source : null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    property real lastUpdate: 0
 | 
					    property real lastUpdate: 0
 | 
				
			||||||
    property real prevLastUpdate: 0
 | 
					    property real prevLastUpdate: 0
 | 
				
			||||||
@@ -16,10 +16,12 @@ Item {
 | 
				
			|||||||
    property real _minBurnInFadeTime: 160
 | 
					    property real _minBurnInFadeTime: 160
 | 
				
			||||||
    property real _maxBurnInFadeTime: 1600
 | 
					    property real _maxBurnInFadeTime: 1600
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    active: appSettings.burnIn !== 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function completelyUpdate() {
 | 
					    function completelyUpdate() {
 | 
				
			||||||
        prevLastUpdate = lastUpdate;
 | 
					        prevLastUpdate = lastUpdate;
 | 
				
			||||||
        lastUpdate = timeManager.time;
 | 
					        lastUpdate = timeManager.time;
 | 
				
			||||||
        burnInEffectSource.scheduleUpdate();
 | 
					        item.source.scheduleUpdate();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function restartBlurSource(){
 | 
					    function restartBlurSource(){
 | 
				
			||||||
@@ -28,40 +30,8 @@ Item {
 | 
				
			|||||||
        completelyUpdate()
 | 
					        completelyUpdate()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ShaderEffectSource {
 | 
					    sourceComponent: Item {
 | 
				
			||||||
        id: burnInEffectSource
 | 
					        property alias source: burnInEffectSource
 | 
				
			||||||
 | 
					 | 
				
			||||||
        sourceItem: burnInShaderEffect
 | 
					 | 
				
			||||||
        live: false
 | 
					 | 
				
			||||||
        recursive: true
 | 
					 | 
				
			||||||
        hideSource: true
 | 
					 | 
				
			||||||
        wrapMode: kterminalSource.wrapMode
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        format: ShaderEffectSource.RGBA
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        visible: false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Connections {
 | 
					 | 
				
			||||||
            target: kterminal
 | 
					 | 
				
			||||||
            onImagePainted: completelyUpdate()
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        // Restart blurred source settings change.
 | 
					 | 
				
			||||||
        Connections{
 | 
					 | 
				
			||||||
            target: appSettings
 | 
					 | 
				
			||||||
            onBurnInChanged: burnInEffect.restartBlurSource();
 | 
					 | 
				
			||||||
            onTerminalFontChanged: burnInEffect.restartBlurSource();
 | 
					 | 
				
			||||||
            onRasterizationChanged: burnInEffect.restartBlurSource();
 | 
					 | 
				
			||||||
            onBurnInQualityChanged: burnInEffect.restartBlurSource();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Connections {
 | 
					 | 
				
			||||||
            target: kterminalScrollbar
 | 
					 | 
				
			||||||
            onOpacityChanged: burnInEffect.restartBlurSource()
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ShaderEffect {
 | 
					 | 
				
			||||||
        id: burnInShaderEffect
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        property int burnInScaling: scaleTexture * appSettings.burnInQuality
 | 
					        property int burnInScaling: scaleTexture * appSettings.burnInQuality
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -73,54 +43,94 @@ Item {
 | 
				
			|||||||
                ? kterminal.height * Math.max(1, burnInScaling)
 | 
					                ? kterminal.height * Math.max(1, burnInScaling)
 | 
				
			||||||
                : kterminal.height * scaleTexture * appSettings.burnInQuality
 | 
					                : kterminal.height * scaleTexture * appSettings.burnInQuality
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        property variant txt_source: kterminalSource
 | 
					        ShaderEffectSource {
 | 
				
			||||||
        property variant burnInSource: burnInEffectSource
 | 
					            id: burnInEffectSource
 | 
				
			||||||
        property real burnInTime: burnInFadeTime
 | 
					 | 
				
			||||||
        property alias lastUpdate: burnInEffect.lastUpdate
 | 
					 | 
				
			||||||
        property alias prevLastUpdate: burnInEffect.prevLastUpdate
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        blending: false
 | 
					            anchors.fill: parent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fragmentShader:
 | 
					            sourceItem: burnInShaderEffect
 | 
				
			||||||
            "#ifdef GL_ES
 | 
					            live: false
 | 
				
			||||||
                    precision mediump float;
 | 
					            recursive: true
 | 
				
			||||||
                #endif\n" +
 | 
					            hideSource: true
 | 
				
			||||||
 | 
					            wrapMode: kterminalSource.wrapMode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            "uniform lowp float qt_Opacity;" +
 | 
					            format: ShaderEffectSource.RGBA
 | 
				
			||||||
            "uniform lowp sampler2D txt_source;" +
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            "varying highp vec2 qt_TexCoord0;
 | 
					            visible: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
             uniform lowp sampler2D burnInSource;
 | 
					            Connections {
 | 
				
			||||||
             uniform highp float burnInTime;
 | 
					                target: kterminal
 | 
				
			||||||
 | 
					                onImagePainted: completelyUpdate()
 | 
				
			||||||
             uniform highp float lastUpdate;
 | 
					            }
 | 
				
			||||||
 | 
					            // Restart blurred source settings change.
 | 
				
			||||||
             uniform highp float prevLastUpdate;" +
 | 
					            Connections{
 | 
				
			||||||
 | 
					                target: appSettings
 | 
				
			||||||
            "float max3(vec3 v) {
 | 
					                onBurnInChanged: burnInEffect.restartBlurSource();
 | 
				
			||||||
                 return max (max (v.x, v.y), v.z);
 | 
					                onTerminalFontChanged: burnInEffect.restartBlurSource();
 | 
				
			||||||
            }" +
 | 
					                onRasterizationChanged: burnInEffect.restartBlurSource();
 | 
				
			||||||
 | 
					                onBurnInQualityChanged: burnInEffect.restartBlurSource();
 | 
				
			||||||
            "void main() {
 | 
					 | 
				
			||||||
                vec2 coords = qt_TexCoord0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                vec3 txtColor = texture2D(txt_source, coords).rgb * 0.70;
 | 
					 | 
				
			||||||
                vec4 accColor = texture2D(burnInSource, coords);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                float prevMask = accColor.a;
 | 
					 | 
				
			||||||
                float currMask = 1.0 - max3(txtColor);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                highp float blurDecay = prevMask * clamp((lastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0);
 | 
					 | 
				
			||||||
                vec3 blurColor = accColor.rgb - vec3(blurDecay);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                blurColor = clamp(blurColor, vec3(0.0), vec3(1.0));
 | 
					 | 
				
			||||||
                vec3 color = max(blurColor, txtColor);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                gl_FragColor = vec4(color, currMask);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        "
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        onStatusChanged: if (log) console.log(log) //Print warning messages
 | 
					            Connections {
 | 
				
			||||||
 | 
					                target: kterminalScrollbar
 | 
				
			||||||
 | 
					                onOpacityChanged: burnInEffect.restartBlurSource()
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ShaderEffect {
 | 
				
			||||||
 | 
					            id: burnInShaderEffect
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            property variant txt_source: kterminalSource
 | 
				
			||||||
 | 
					            property variant burnInSource: burnInEffectSource
 | 
				
			||||||
 | 
					            property real burnInTime: burnInFadeTime
 | 
				
			||||||
 | 
					            property real lastUpdate: burnInEffect.lastUpdate
 | 
				
			||||||
 | 
					            property real prevLastUpdate: burnInEffect.prevLastUpdate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            anchors.fill: parent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            blending: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            fragmentShader:
 | 
				
			||||||
 | 
					                "#ifdef GL_ES
 | 
				
			||||||
 | 
					                        precision mediump float;
 | 
				
			||||||
 | 
					                    #endif\n" +
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                "uniform lowp float qt_Opacity;" +
 | 
				
			||||||
 | 
					                "uniform lowp sampler2D txt_source;" +
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                "varying highp vec2 qt_TexCoord0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                 uniform lowp sampler2D burnInSource;
 | 
				
			||||||
 | 
					                 uniform highp float burnInTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                 uniform highp float lastUpdate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                 uniform highp float prevLastUpdate;" +
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                "float max3(vec3 v) {
 | 
				
			||||||
 | 
					                     return max (max (v.x, v.y), v.z);
 | 
				
			||||||
 | 
					                }" +
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                "void main() {
 | 
				
			||||||
 | 
					                    vec2 coords = qt_TexCoord0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    vec3 txtColor = texture2D(txt_source, coords).rgb * 0.5;
 | 
				
			||||||
 | 
					                    vec4 accColor = texture2D(burnInSource, coords);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    float prevMask = accColor.a;
 | 
				
			||||||
 | 
					                    float currMask = 1.0 - max3(txtColor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    highp float blurDecay = prevMask * clamp((lastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0);
 | 
				
			||||||
 | 
					                    vec3 blurColor = accColor.rgb - vec3(blurDecay);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    blurColor = clamp(blurColor, vec3(0.0), vec3(1.0));
 | 
				
			||||||
 | 
					                    vec3 color = max(blurColor, txtColor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    gl_FragColor = vec4(color, currMask);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            onStatusChanged: if (log) console.log(log) //Print warning messages
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user