Lazarus
Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: cd on April 21, 2012, 02:31:41 am
-
hi circular
look at screenshots
first is done with FillPolyLinearMapping(..., True)
second with FillPolyLinearMapping(..., False)
is it a bug or i do smth wrong?
-
It seems like a bug. Maybe a SSE issue.
Texture interpolation should give the same result except with interpolation between pixels.
Try to disable SSE by changing this in BGRASSE :
FLAG_ENABLED_SSE = true;
To this :
FLAG_ENABLED_SSE = false;
I will have a look at this.
-
yes you are right
that should be sse - with sse disabled the bug is not seen any more.
how much does sse affect speed?
-
Ok, i found the bug in SSE code. Try to replace lineartexscan2.inc by
{$IFDEF PARAM_USESSE} {$asmmode intel}
asm
xorps xmm4,xmm4
xorps xmm5,xmm5
movlps xmm4, texPos
movlps xmm5, texStep
{$IFNDEF PARAM_USEINTERPOLATION}
{$IFDEF PARAM_USESSE2}
cvtps2dq xmm3,xmm4
movlps intTexPos,xmm3
{$ENDIF}
{$ENDIF}
end;
{$ENDIF}
for i := ix1 to ix2 do
begin
DrawPixelInlineWithAlphaCheck(pdest,
{$IFDEF PARAM_USELIGHTING} ApplyLightnessFast( {$ENDIF}
{$IFDEF PARAM_USEINTERPOLATION}
scanAtFunc(texPos.x,texPos.y)
{$ELSE}
{$IFDEF PARAM_USESSE2}
scanAtIntegerFunc(intTexPos.x,intTexPos.y)
{$ELSE}
scanAtIntegerFunc(round(texPos.x),round(texPos.y))
{$ENDIF}
{$ENDIF}
{$IFDEF PARAM_USELIGHTING} ,light) {$ENDIF}
);
{$IFDEF PARAM_USESSE}
asm
addps xmm4,xmm5
{$IFNDEF PARAM_USEINTERPOLATION}
{$IFDEF PARAM_USESSE2}
cvtps2dq xmm3,xmm4
movlps intTexPos,xmm3
{$ELSE}
movlps texPos,xmm4
{$ENDIF}
{$ELSE}
movlps texPos,xmm4
{$ENDIF}
end;
{$ELSE}
texPos += texStep;
{$ENDIF}
{$IFDEF PARAM_USELIGHTING}
NextLight;
{$ENDIF}
inc(pdest);
end;
how much does sse affect speed?
It depends on what you are doing. For FillPolyLinearMapping without texture interpolation, I get 10% faster with SSE. For other things, you may get the same speed, or sometimes really faster. Use EpikTimer to check this and show time with something like :
b.TextOut(0,0,inttostr(round(timer.Elapsed*1000))+' ms',CSSOrange);
-
thank you, now it works with sse lfag enabled.
will now continue hacking your library. It made a valuable progress since i first tried it on 30 March 2010! =) looking forward to using it in my next project!
-
Ok thanks for testing.
I've updated the library with the above changes on subversion.
If you have any idea on how to improve the library, feel free to propose.
-
a real layering as in graphics32 would be nice.
to improve fps in a full-form gui i now use a per-tile drawing mechanism (tile size is changable). only those tiles are used in drawing which are affected. of course there is an option to draw all - which is called on form invalidation. that would be nice if the library did it for me. this optimisation drastically improved gui responce - i'm now able to create really fast and beautiful gesture gui with my 17" touchscreen (computer is rather slow, straight-forward approach gave 10-12 fps, tile-based is up to 50 "fps" when excluding stationary bitmap areas). i can send you a test application if you think this could be implemented in library.
-
That's interesting. Of course you can send me some test application. How big is it?
Would it be like an enhancement of BGRALayers ?
-
the code
change
draw_debug := False
to
draw_debug := true
on line 123 of unit1 to see tiles working.
this is a test project for myself so it is not very good written and there is not much comments. but if smth is unclear i can answer here.
-
Ok. I understand what you did. That's interesting.
Note that drawing on a canvas outside an OnPaint event does not work on MacOS. Does someone know how to bypass this ?
If we need to paint everything, well, the speed will not be so high. It would still be useful if the rendering of the tile content is slow, so that it works like a buffer.
We can try to go toward implementing it in the library. First of all, it should be in a class. To do so, create a separate unit with a type definition, something like :
type TTiledSurface = class
...
And every procedure that is linked to this subject should be moved into it (MarkDrawTiles, Draw). Some variable names are not really understandable, for example b_image for BackgroundImage. Also add BackgroundColor, so that if there is no BackgroundImage, the tile is filled with this color.
CreateImages should be split into two parts. One is about freeing previous tiles and resizing the array.
Another is about what the user wants to do. In your example, you set the background image. This can be handled for example in a virtual procedure. Do you know what this is ?