Jump to content
  • Advertisement
Sign in to follow this  
qventura

Flickering probleme with SlimDX / D3D10 / WPF

This topic is 2497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
I got a strange flickering problem in my scene ...
When i move the camera (pan or zoom), the NeedToRender boolean is seted as true, it call the render function

public bool Render()
{
if (isReadyToRender() && NeedToRender)
{
worldEffectVariable.SetMatrix(worldMatrix);
viewEffectVariable.SetMatrix(camera.ViewMatrix);
projectionEffectVariable.SetMatrix(camera.ProjectionMatrix);
D3DDevice.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
D3DDevice.ClearRenderTargetView(renderView, new Color4(new Vector4(1.0f, 0.0f, 0.0f, 1.0f)));
foreach (IModel model in ModelsToRender)
{
if (model.GetType() == typeof(TexturedModel))
{
Matrix objectTranformMatrix = Matrix.Scaling((float)((TexturedModel)model).Width / 2.0f, (float)((TexturedModel)model).Height / 2.0f, 1.0f);
objectTranformMatrix = Matrix.Multiply(objectTranformMatrix, Matrix.Translation((float)((TexturedModel)model).Width / 2.0f, (float)((TexturedModel)model).Height / 2.0f, 0.0f));
objectTransformEffectVariable.SetMatrix(objectTranformMatrix);
currentRenderer = texturedRenderer;
texturedRenderer.GetTexture(model.Id, out currentTexture);
textureEffectVariable.SetResource(currentTexture);
}
else if (model.GetType() == typeof(SphereTargetModel))
{
Matrix objectTranformMatrix = Matrix.Translation(((SphereTargetModel)model).CurrentPosition.X, ((SphereTargetModel)model).CurrentPosition.Y, -20.0f);
objectTransformEffectVariable.SetMatrix(objectTranformMatrix);
colorEffectVariable.Set(Convertor.ToVector4(((SphereTargetModel)model).Color)); currentRenderer = sphereRenderer;
}
else
{
currentRenderer = diskRenderer;
}
technique = effect.GetTechniqueByName(currentRenderer.TypeName);
pass = technique.GetPassByIndex(0);
layout = new InputLayout(D3DDevice, pass.Description.Signature, currentRenderer.InputElements); D3DDevice.InputAssembler.SetInputLayout(layout);
D3DDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
D3DDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(currentRenderer.VerticesBuffer, currentRenderer.VertexSize, 0));
D3DDevice.InputAssembler.SetIndexBuffer(currentRenderer.IndicesBuffer, Format.R16_UInt, 0);

for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
D3DDevice.DrawIndexed(currentRenderer.IndicesNumber, 0, 0);
}
layout.Dispose();
}
D3DDevice.Flush();
camera.HasChanged = false;
sceneHasChanged = false;

renderingTime = DateTime.Now.Subtract(beginTime);
if (renderingTime.Milliseconds != 0)
{
Console.WriteLine("DX10 : RenderingTime = " + renderingTime.Milliseconds + " FPS = " + (1000 / renderingTime.Milliseconds));
}
return true;
}
return false;
}


Here is my OnRendering function, called by my WPF Control


public void OnRendering(object sender, EventArgs e) {
if (RenderEngine.Render())
{
if (RenderEngine.BackBufferSurface != null)
{
D3DTarget.Invalidate();
}
}
}




Invalidate is called only when something append in my rendering engine

D3DTarget is a "D3DImageSlimDX", qnd here is the Invalidate function

public void Invalidate()
{
if (SharedTexture != null)
{
Lock();
AddDirtyRect(new Int32Rect(0, 0, PixelWidth, PixelHeight));
Unlock();
}
}


The strange thing is that the flickering appear for every object of my scene (ObjetcsToRender) EXCEPT the first one

By the way, I've got the same probleme with my D3D9 Engine .... I think that's a DirtyRect problem but i'm not sure !

[Edit]
Just adding my device initialization:

public void InitDevice()
{
ReleaseDevice();
Texture2DDescription colordesc = new Texture2DDescription();
colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
colordesc.Format = Format.B8G8R8A8_UNorm;
colordesc.Width = ControlWidth;
colordesc.Height = ControlHeight;
colordesc.MipLevels = 1;
colordesc.SampleDescription = new SampleDescription(1, 0);
colordesc.Usage = ResourceUsage.Default;
colordesc.OptionFlags = ResourceOptionFlags.Shared;
colordesc.CpuAccessFlags = CpuAccessFlags.None;
colordesc.ArraySize = 1;
Texture2DDescription depthdesc = new Texture2DDescription();
depthdesc.BindFlags = BindFlags.DepthStencil;
depthdesc.Format = Format.D32_Float_S8X24_UInt;
depthdesc.Width = ControlWidth;
depthdesc.Height = ControlHeight;
depthdesc.MipLevels = 1;
depthdesc.SampleDescription = new SampleDescription(1, 0);
depthdesc.Usage = ResourceUsage.Default;
depthdesc.OptionFlags = ResourceOptionFlags.None;
depthdesc.CpuAccessFlags = CpuAccessFlags.None;
depthdesc.ArraySize = 1;
BackBufferSurface = new Texture2D(D3DDevice, colordesc);
DepthTexture = new Texture2D(D3DDevice, depthdesc);
renderView = new RenderTargetView(D3DDevice, BackBufferSurface);
depthView = new DepthStencilView(D3DDevice, DepthTexture);
D3DDevice.OutputMerger.SetTargets(depthView, renderView);
D3DDevice.Rasterizer.SetViewports(new Viewport(0, 0, ControlWidth, ControlHeight, 0.0f, 1.0f));
D3DDevice.Flush();
deviceReadyToRender = true;
}


Thanks in advance,

Q

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!