I found some strange behavior with View zooming.
I'm using empty scene with a grid rendered with Vertices for testing.
When I starting app it has default zoom 1,35 and app consumes < 1% CPU (most of the time 0%, sometimes 1%).
But when I change zooming there is some strange happens at threshold between value 3,1046 and 3,1726.
When I reach its threshold CPU usage jumping up to 26% (100% load of single CPU core) and remains at that level on any zoom which is higher that this threshold.
If I change zoom back, CPU load jumps down to 0%.
What happens? Why there is so abrupt increasing of CPU load?
I think zoom should not affect it. At least not so brokenly.
I measured it with VSyncEnabled and SetFrameLimit(0).
I tested with no VSync and it seems that this threshold doesn't affect fps. But what happens with CPU load?
It happens with window size 800x800. When I change window size threshold also shifted.
For example with window size 400x400:
Zoom CPU load
6,2112 0%
6,3452 26% (100% load of single CPU core)
Window size 900x900:
Zoom CPU load
2,7601 0%
2,8201 26%
I'm using SFML.NET binding with CSFML 2.2 and SFML 2.2 on Windows 7 x64 and nVidia GeForce 460, driver version 10.18.13.5390
I tried to comment grid rendering, so render loop consists of render debug text only and this issue disappears.
I can zoom out up to the value 55 and CPU load stay on 0%...
Render grid code is the following:
private void RenderGrid
() { var alpha
= 0
.2F
* _camera
.Scale; alpha
= alpha
< 0F
? 0F
: alpha
; alpha
= alpha
> 1F
? 1F
: alpha
; var color
= new Color
(0x00, 0x00, 0x00,
(byte)(255 * alpha
)); const float step
= 50F
; var size
= (Vector2f
)_window
.Size / _camera
.Scale + new Vector2f
(step, step
) * 2F
; var offset
= _camera
.Center - size
/ 2F
- new Vector2f
(step, step
); var vertices
= new List
<Vertex
>(); for (var y
= step
- (offset
.Y % step
); y
< size
.Y; y
+= step
) { var sx
= offset
.X + 0
.5F
; var sy
= offset
.Y + y
+ 0
.5F
; vertices
.Add(new Vertex
(new Vector2f
(sx, sy
), color
)); vertices
.Add(new Vertex
(new Vector2f
(sx
+ size
.X, sy
), color
)); } for (var x
= step
- (offset
.X % step
); x
< size
.X; x
+= step
) { var sx
= offset
.X + x
+ 0
.5F
; var sy
= offset
.Y + 0
.5F
; vertices
.Add(new Vertex
(new Vector2f
(sx, sy
), color
)); vertices
.Add(new Vertex
(new Vector2f
(sx, sy
+ size
.Y), color
)); } _window
.Draw(vertices
.ToArray(), PrimitiveType
.Lines); } _camera.Scale is used in the following way:
_viewWorld.Size = (Vector2f)_window.Size;
_viewWorld.Zoom(1F / _camera.Scale);
_viewWorld.Center = _camera.Center;
_window.SetView(_viewWorld);
Actually I mention values which is assigned to view.Zoom. i.e.: Zoom = 1F / _camera.Scale;
I tried to hardcode alpha channel of color:
var alpha = 1F;
alpha = alpha < 0F ? 0F : alpha;
alpha = alpha > 1F ? 1F : alpha;
But it didn't affect the issue...
I measured vertex count which triggers jump of CPU load and it seems that it's constant. CPU load jumps from 0% to 26% when vertex count grows from 204 to 208 and it independent from window size...
I tested memory allocation for vertex list by allocating fixed size array for 500 vertices, but it not affect the result. CPU load jumps from zero to the maximum when vertex count is more than 204...
Finally I tested if the issue really affected by zoom. To do it I replaced zoom with fixed value 3F. And actually zoom doesn't affect the issue. It depends on vertex count only.
So, CPU load jumps when line count is higher than 204/2=102 lines.
Why?