Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
5.7.1
-
None
-
Ubuntu 16.04
Qt3D git commit 17d5edb5b1e8b6aa1a5480e1673dc7afd2872ed5
-
d220a4cfe578e908ad89f8d5d85e6601acade355
Description
Textures are corrupted when resized in deferred rendering. In the below example, a button is pressed which changes the size of the texture. The texture immediately becomes corrupted (random data) after pressing the button.
This is not a problem in the binary released version of Qt 5.7, but in the current version on git (commit 17d5edb5b1e8b6aa1a5480e1673dc7afd2872ed5).
The following example reproduces the behavior:
import QtQuick 2.0 as QQ2 import QtQuick.Controls 1.4 as QQ2 import QtQuick.Window 2.0 as QQ2 import QtQuick.Scene3D 2.0 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 QQ2.Window { id: root width: 1280 height: 720 visible: true QQ2.Scene3D { anchors.fill: parent aspects: ["logic", "input"] Entity { components : [ RenderSettings { activeFrameGraph: Viewport { normalizedRect : Qt.rect(0.0, 0.0, 1.0, 1.0) RenderTarget { id: gBuffer property alias color : colorAttachment property alias depth : depthAttachment property real width: 1024 property real height: 1024 attachments : [ RenderTargetOutput { objectName : "color" attachmentPoint : RenderTargetOutput.Color0 texture : Texture2D { id : colorAttachment width : gBuffer.width height : gBuffer.height format : Texture.RGBA32F generateMipMaps : false magnificationFilter : Texture.Linear minificationFilter : Texture.Linear wrapMode { x: WrapMode.ClampToEdge y: WrapMode.ClampToEdge } } }, RenderTargetOutput { objectName : "depth" attachmentPoint : RenderTargetOutput.Depth texture : Texture2D { id : depthAttachment width : gBuffer.width height : gBuffer.height format : Texture.D32F generateMipMaps : false magnificationFilter : Texture.Linear minificationFilter : Texture.Linear wrapMode { x: WrapMode.ClampToEdge y: WrapMode.ClampToEdge } } } ] } RenderSurfaceSelector { CameraSelector { id : sceneCameraSelector camera: camera // Fill G-Buffer LayerFilter { id: sceneLayerFilter layers: sceneEntity.layer RenderTargetSelector { id : gBufferTargetSelector target: gBuffer ClearBuffers { buffers: ClearBuffers.ColorDepthBuffer clearColor: "red" RenderPassFilter { id : geometryPass matchAny : FilterKey { name : "pass"; value : "geometry" } } } } } TechniqueFilter { parameters: [ Parameter { name: "color"; value : gBuffer.color }, Parameter { name: "winSize"; value : Qt.size(1024, 1024) } ] RenderStateSet { // Render FullScreen Quad renderStates: [ BlendEquation { blendFunction: BlendEquation.Add }, BlendEquationArguments { sourceRgb: BlendEquationArguments.SourceAlpha; destinationRgb: BlendEquationArguments.DestinationColor } ] LayerFilter { id: screenQuadLayerFilter layers: screenQuadLayer ClearBuffers { buffers: ClearBuffers.ColorDepthBuffer clearColor: "red" RenderPassFilter { matchAny : FilterKey { name : "pass"; value : "final" } parameters: Parameter { name: "winSize"; value : Qt.size(1024, 768) } } } } } } } } } renderPolicy: RenderSettings.Always }, InputSettings {} ] Entity { id: sceneEntity readonly property Layer layer: sceneLayer // Global elements Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 16/9 nearPlane : 1.0 farPlane : 1000.0 position: Qt.vector3d( 0.0, 0.0, -25.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 ) } SphereMesh { id : sphereMesh rings: 50 slices: 100 } Effect { id : sceneMaterialEffect techniques : [ // OpenGL 3.1 Technique { graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 1; majorVersion : 3 } renderPasses : RenderPass { filterKeys : FilterKey { name : "pass"; value : "geometry" } shaderProgram : ShaderProgram { id : sceneShaderGL3 vertexShaderCode: " #version 140 in vec4 vertexPosition; in vec3 vertexNormal; out vec4 color0; out vec3 position0; out vec3 normal0; uniform mat4 mvp; uniform mat4 modelView; uniform mat3 modelViewNormal; uniform vec4 meshColor; void main() { color0 = meshColor; position0 = vec3(modelView * vertexPosition); normal0 = normalize(modelViewNormal * vertexNormal); gl_Position = mvp * vertexPosition; } " fragmentShaderCode:" #version 140 in vec4 color0; in vec3 position0; in vec3 normal0; out vec4 color; out vec3 position; out vec3 normal; void main() { color = color0; position = position0; normal = normal0; } " } } } ] } Layer { id: sceneLayer } // Scene Entity { id : sphere1 property Material material : Material { effect : sceneMaterialEffect parameters : Parameter { name : "meshColor"; value : "dodgerblue" } } components : [ sphereMesh, sphere1.material, sphere1.transform, sphere1.light, sceneLayer ] } } Entity { id: screenQuadEntity components : [ Layer { id: screenQuadLayer }, PlaneMesh { width: 2.0 height: 2.0 meshResolution: Qt.size(2, 2) }, Transform { // We rotate the plane so that it faces us rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90) }, Material { effect : Effect { techniques : [ Technique { graphicsApiFilter {api : GraphicsApiFilter.OpenGL; profile : GraphicsApiFilter.CoreProfile; minorVersion : 1; majorVersion : 3 } renderPasses : RenderPass { filterKeys : FilterKey { name : "pass"; value : "final" } shaderProgram : ShaderProgram { id : finalShaderGL3 vertexShaderCode: " #version 140 in vec4 vertexPosition; uniform mat4 modelMatrix; void main() { gl_Position = modelMatrix * vertexPosition; } " fragmentShaderCode: " #version 140 uniform sampler2D color; uniform vec2 winSize; out vec4 fragColor; void main() { vec2 texCoord = gl_FragCoord.xy / winSize; fragColor = texture(color, texCoord); } " } } } ] } } ] } } } QQ2.Button { text: "Click me to corrupt texture" onClicked: gBuffer.width += 1 } }
The attached example is a different version that reproduces the bug when the window is resized. This is achieved by binding the texture size to the window size.
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-55163 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
167522,4 | deferred-renderer-cpp: properly handle window size changes | 5.7 | qt/qt3d | Status: MERGED | +2 | 0 |
167523,4 | deferred-renderer-qml: properly handle window size changes | 5.7 | qt/qt3d | Status: MERGED | +2 | 0 |