I am using Canvas
in QML to draw rotating Rectangle
with OpenGL. Here is the code:
//...
property variant points: []
onPointsChanged:{
canvas.requestPaint();
}
//...
Canvas{
//...
onPaint:{
var ctx = canvas.getContext('2d')
ctx.clearRect(0,0, width, height);
ctx.beginPath()
ctx.strokeStyle = 'red'
ctx.lineWidth = 3
for(var i = 0; i < points.length; i++){
var p1 = convertPoint(points[i])
if(i == 0){
ctx.moveTo(p1.x, p1.y)
continue
}
ctx.lineTo(p1.x, p1.y)
}
ctx.stroke()
ctx.restore()
}
function convertPoint(p){
var x = p.x * width;
var y = p.y * height;
return Qt.point(x,y);
}
}
There are 4 points counted in c++ code and sent to qml every 30ms. Problem is that this paint operation takes 50% of CPU usage when compile under MinGW and when compile under MSVC2010 operation takes 17% of CPU, which is still a lot. It is some bug or what is bad?