Changeset 443 for GraphicTest/UDrawMethod.pas
- Timestamp:
- Nov 22, 2012, 12:28:54 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/UDrawMethod.pas
r442 r443 6 6 7 7 uses 8 Classes, SysUtils, ExtCtrls, UPlatform, UFastBitmap, Graphics, 8 Classes, SysUtils, ExtCtrls, UPlatform, UFastBitmap, Graphics, Controls, 9 9 LCLType, IntfGraphics, fpImage, GraphType, BGRABitmap, BGRABitmapTypes, 10 10 LclIntf{$IFDEF opengl}, GL, GLExt, OpenGLContext{$ENDIF}; … … 18 18 TDrawMethod = class 19 19 private 20 F Bitmap: TBitmap;20 FControl: TControl; 21 21 TempBitmap: TBitmap; 22 FPaintBox: TPaintBox;23 procedure SetBitmap(const AValue: TBitmap); virtual;24 procedure SetPaintBox(const AValue: TPaintBox);25 22 public 26 23 Caption: string; … … 29 26 StepDuration: TDateTime; 30 27 PaintObject: TPaintObject; 31 {$IFDEF opengl} 32 OpenGLBitmap: Pointer; 33 OpenGLControl: TOpenGLControl; 34 TextureId: GLuint; 35 {$ENDIF} 36 procedure Init; virtual; 28 procedure Init(Parent: TWinControl; Size: TPoint); virtual; 29 procedure Done; virtual; 37 30 constructor Create; virtual; 38 31 destructor Destroy; override; 39 32 procedure DrawFrame(FastBitmap: TFastBitmap); virtual; 40 33 procedure DrawFrameTiming(FastBitmap: TFastBitmap); 41 property Bitmap: TBitmap read FBitmap write SetBitmap; 42 property PaintBox: TPaintBox read FPaintBox write SetPaintBox; 34 property Control: TControl read FControl; 43 35 end; 44 36 45 37 TDrawMethodClass = class of TDrawMethod; 46 38 39 { TDrawMethodImage } 40 41 TDrawMethodImage = class(TDrawMethod) 42 Image: TImage; 43 procedure Init(Parent: TWinControl; Size: TPoint); override; 44 procedure Done; override; 45 end; 46 47 { TDrawMethodPaintBox } 48 49 TDrawMethodPaintBox = class(TDrawMethod) 50 PaintBox: TPaintBox; 51 procedure Paint(Sender: TObject); virtual; 52 procedure Init(Parent: TWinControl; Size: TPoint); override; 53 procedure Done; override; 54 end; 55 47 56 { TDummyMethod } 48 57 … … 54 63 { TCanvasPixels } 55 64 56 TCanvasPixels = class(TDrawMethod )65 TCanvasPixels = class(TDrawMethodImage) 57 66 constructor Create; override; 58 67 procedure DrawFrame(FastBitmap: TFastBitmap); override; … … 61 70 { TCanvasPixelsUpdateLock } 62 71 63 TCanvasPixelsUpdateLock = class(TDrawMethod )72 TCanvasPixelsUpdateLock = class(TDrawMethodImage) 64 73 constructor Create; override; 65 74 procedure DrawFrame(FastBitmap: TFastBitmap); override; … … 68 77 { TLazIntfImageColorsCopy } 69 78 70 TLazIntfImageColorsCopy = class(TDrawMethod )79 TLazIntfImageColorsCopy = class(TDrawMethodImage) 71 80 TempIntfImage: TLazIntfImage; 72 81 constructor Create; override; … … 77 86 { TLazIntfImageColorsNoCopy } 78 87 79 TLazIntfImageColorsNoCopy = class(TDrawMethod )88 TLazIntfImageColorsNoCopy = class(TDrawMethodImage) 80 89 TempIntfImage: TLazIntfImage; 81 procedure SetBitmap(const AValue: TBitmap); override;90 procedure Init(Parent: TWinControl; Size: TPoint); override; 82 91 constructor Create; override; 83 92 destructor Destroy; override; … … 87 96 { TBitmapRawImageData } 88 97 89 TBitmapRawImageData = class(TDrawMethod )98 TBitmapRawImageData = class(TDrawMethodImage) 90 99 constructor Create; override; 91 100 procedure DrawFrame(FastBitmap: TFastBitmap); override; … … 94 103 { TBitmapRawImageDataPaintBox } 95 104 96 TBitmapRawImageDataPaintBox = class(TDrawMethod) 97 constructor Create; override; 105 TBitmapRawImageDataPaintBox = class(TDrawMethodPaintBox) 106 constructor Create; override; 107 procedure Paint(Sender: TObject); override; 98 108 procedure DrawFrame(FastBitmap: TFastBitmap); override; 99 109 end; … … 101 111 { TBitmapRawImageDataMove } 102 112 103 TBitmapRawImageDataMove = class(TDrawMethod )113 TBitmapRawImageDataMove = class(TDrawMethodImage) 104 114 constructor Create; override; 105 115 procedure DrawFrame(FastBitmap: TFastBitmap); override; … … 108 118 { TBGRABitmapPaintBox } 109 119 110 TBGRABitmapPaintBox = class(TDrawMethod )120 TBGRABitmapPaintBox = class(TDrawMethodPaintBox) 111 121 BGRABitmap: TBGRABitmap; 112 procedure SetBitmap(const AValue: TBitmap); override; 122 procedure Paint(Sender: TObject); override; 123 procedure Init(Parent: TWinControl; Size: TPoint); override; 113 124 constructor Create; override; 114 125 destructor Destroy; override; … … 117 128 118 129 {$IFDEF opengl} 130 { TDrawMethodOpenGL } 131 132 TDrawMethodOpenGL = class(TDrawMethod) 133 OpenGLControl: TOpenGLControl; 134 TextureId: GLuint; 135 OpenGLBitmap: Pointer; 136 procedure InitGL; 137 procedure OpenGLControlResize(Sender: TObject); 138 procedure Init(AParent: TWinControl; Size: TPoint); override; 139 procedure Done; override; 140 end; 141 119 142 { TOpenGLMethod } 120 143 121 TOpenGLMethod = class(TDrawMethod) 122 procedure SetBitmap(const AValue: TBitmap); override; 123 constructor Create; override; 124 procedure Init; override; 144 TOpenGLMethod = class(TDrawMethodOpenGL) 145 constructor Create; override; 125 146 destructor Destroy; override; 126 147 procedure DrawFrame(FastBitmap: TFastBitmap); override; … … 129 150 { TOpenGLPBOMethod } 130 151 131 TOpenGLPBOMethod = class(TDrawMethod )152 TOpenGLPBOMethod = class(TDrawMethodOpenGL) 132 153 pboIds: array[0..1] of GLuint; 133 154 Index, NextIndex: Integer; 134 procedure SetBitmap(const AValue: TBitmap); override; 135 procedure Init; override; 155 procedure Init(AParent: TWinControl; Size: TPoint); override; 136 156 constructor Create; override; 137 157 destructor Destroy; override; … … 149 169 implementation 150 170 171 172 { TDrawMethodPaintBox } 173 174 procedure TDrawMethodPaintBox.Paint(Sender: TObject); 175 begin 176 177 end; 178 179 procedure TDrawMethodPaintBox.Init(Parent: TWinControl; Size: TPoint); 180 begin 181 inherited Init(Parent, Size); 182 PaintBox := TPaintBox.Create(Parent); 183 PaintBox.Parent := Parent; 184 PaintBox.SetBounds(0, 0, Size.X, Size.Y); 185 PaintBox.OnPaint := Paint; 186 PaintBox.Show; 187 end; 188 189 procedure TDrawMethodPaintBox.Done; 190 begin 191 FreeAndNil(PaintBox); 192 inherited Done; 193 end; 194 195 { TDrawMethodImage } 196 197 procedure TDrawMethodImage.Init(Parent: TWinControl; Size: TPoint); 198 begin 199 inherited Init(Parent, Size); 200 Image := TImage.Create(Parent); 201 Image.Parent := Parent; 202 Image.SetBounds(0, 0, Size.X, Size.Y); 203 Image.Picture.Bitmap.SetSize(Size.X, Size.Y); 204 Image.Picture.Bitmap.PixelFormat := pf32bit; 205 Image.Show; 206 end; 207 208 procedure TDrawMethodImage.Done; 209 begin 210 FreeAndNil(Image); 211 inherited Done; 212 end; 213 151 214 { TDummyMethod } 152 215 … … 158 221 159 222 procedure TDummyMethod.DrawFrame(FastBitmap: TFastBitmap); 223 begin 224 end; 225 226 { TBitmapRawImageDataMove } 227 228 constructor TBitmapRawImageDataMove.Create; 229 begin 230 inherited; 231 Caption := 'TBitmap.RawImage.Data Move'; 232 end; 233 234 procedure TBitmapRawImageDataMove.DrawFrame(FastBitmap: TFastBitmap); 160 235 var 161 236 Y, X: Integer; … … 167 242 BytePerRow: Integer; 168 243 begin 169 P := Bitmap.PixelFormat;244 P := Image.Picture.Bitmap.PixelFormat; 170 245 with FastBitmap do 171 246 try 172 //Bitmap.BeginUpdate(False); 173 RawImage := Bitmap.RawImage; 174 RowPtr := PInteger(RawImage.Data); 175 BytePerPixel := RawImage.Description.BitsPerPixel div 8; 176 BytePerRow := RawImage.Description.BytesPerLine; 177 finally 178 //Bitmap.EndUpdate(False); 179 end; 180 end; 181 182 { TBitmapRawImageDataMove } 183 184 constructor TBitmapRawImageDataMove.Create; 185 begin 186 inherited; 187 Caption := 'TBitmap.RawImage.Data Move'; 188 end; 189 190 procedure TBitmapRawImageDataMove.DrawFrame(FastBitmap: TFastBitmap); 191 var 192 Y, X: Integer; 193 PixelPtr: PInteger; 194 RowPtr: PInteger; 195 P: TPixelFormat; 196 RawImage: TRawImage; 197 BytePerPixel: Integer; 198 BytePerRow: Integer; 199 begin 200 P := Bitmap.PixelFormat; 201 with FastBitmap do 202 try 203 Bitmap.BeginUpdate(False); 204 RawImage := Bitmap.RawImage; 247 Image.Picture.Bitmap.BeginUpdate(False); 248 RawImage := Image.Picture.Bitmap.RawImage; 205 249 RowPtr := PInteger(RawImage.Data); 206 250 BytePerPixel := RawImage.Description.BitsPerPixel div 8; … … 208 252 Move(FastBitmap.PixelsData^, RowPtr^, Size.Y * BytePerRow); 209 253 finally 210 Bitmap.EndUpdate(False);254 Image.Picture.Bitmap.EndUpdate(False); 211 255 end; 212 256 end; … … 215 259 { TOpenGLPBOMethod } 216 260 217 procedure TOpenGLPBOMethod.SetBitmap(const AValue: TBitmap);218 begin219 inherited SetBitmap(AValue);220 end;221 222 261 //procedure glGenBuffersARB2 : procedure(n : GLsizei; buffers : PGLuint); extdecl; 223 262 224 procedure TOpenGLPBOMethod.Init ;263 procedure TOpenGLPBOMethod.Init(AParent: TWinControl; Size: TPoint); 225 264 var 226 265 DataSize: Integer; 227 266 glExtensions: string; 228 267 begin 268 inherited; 269 229 270 OpenGLControl.MakeCurrent; 230 271 DataSize := OpenGLControl.Width * OpenGLControl.Height * SizeOf(Integer); … … 268 309 var 269 310 X, Y: Integer; 270 P: P Integer;271 R: P Integer;311 P: PCardinal; 312 R: PCardinal; 272 313 Ptr: ^GLubyte; 273 314 TextureShift: TPoint; … … 317 358 if Assigned(ptr) then begin 318 359 // update data directly on the mapped buffer 319 P := P Integer(Ptr);360 P := PCardinal(Ptr); 320 361 with FastBitmap do 321 362 for Y := 0 to Size.Y - 2 do begin … … 358 399 { TOpenGLMethod } 359 400 360 procedure TOpenGLMethod.SetBitmap(const AValue: TBitmap);361 begin362 inherited SetBitmap(AValue);363 end;364 365 401 constructor TOpenGLMethod.Create; 366 402 begin … … 370 406 end; 371 407 372 procedure TOpenGLMethod.Init;373 begin374 inherited Init;375 //OpenGLControl.MakeCurrent;376 end;377 378 408 destructor TOpenGLMethod.Destroy; 379 409 begin … … 384 414 var 385 415 X, Y: Integer; 386 P: P Integer;387 R: P Integer;416 P: PCardinal; 417 R: PCardinal; 388 418 const 389 419 GL_CLAMP_TO_EDGE = $812F; … … 440 470 end; 441 471 472 { TDrawMethodOpenGL } 473 474 procedure TDrawMethodOpenGL.Init(AParent: TWinControl; Size: TPoint); 475 begin 476 inherited Init(aParent, Size); 477 OpenGLControl := TOpenGLControl.Create(AParent); 478 with OpenGLControl do begin 479 Name := 'OpenGLControl'; 480 Parent := AParent; 481 SetBounds(0, 0, Size.X, Size.Y); 482 InitGL; 483 //OnPaint := OpenGLControl1Paint; 484 OnResize := OpenGLControlResize; 485 end; 486 GetMem(OpenGLBitmap, OpenGLControl.Width * OpenGLControl.Height * SizeOf(Integer)); 487 end; 488 489 procedure TDrawMethodOpenGL.Done; 490 begin 491 FreeMem(OpenGLBitmap, OpenGLControl.Width * OpenGLControl.Height); 492 FreeAndNil(OpenGLControl); 493 inherited; 494 end; 495 496 procedure TDrawMethodOpenGL.OpenGLControlResize(Sender: TObject); 497 begin 498 glViewport(0, 0, OpenGLControl.Width, OpenGLControl.Height); 499 end; 500 501 procedure TDrawMethodOpenGL.InitGL; 502 begin 503 glMatrixMode(GL_PROJECTION); 504 glLoadIdentity; 505 glOrtho(0, OpenGLControl.Width, OpenGLControl.Height, 0, 0, 1); 506 // glOrtho(0, 1, 1, 0, 0, 1); 507 glMatrixMode(GL_MODELVIEW); 508 glLoadIdentity(); 509 glDisable(GL_DEPTH_TEST); 510 glViewport(0, 0, OpenGLControl.Width, OpenGLControl.Height); 511 //gluPerspective( 45.0, (GLfloat)(OpenGLControl1.Width)/(GLfloat)(OpenGLControl1.Height), 0.1f, 500.0 ); 512 513 //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); 514 //glTranslatef (0.0, 0.0,-3.0); 515 // glClearColor(0.0, 0.0, 0.0, 1.0); 516 517 glGenTextures(1, @TextureId); 518 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 519 end; 520 442 521 {$ENDIF} 443 522 444 523 { TBGRABitmapPaintBox } 445 524 446 procedure TBGRABitmapPaintBox.SetBitmap(const AValue: TBitmap); 447 begin 448 inherited; 449 BGRABitmap.SetSize(Bitmap.Width, Bitmap.Height); 525 procedure TBGRABitmapPaintBox.Paint(Sender: TObject); 526 begin 527 //BGRABitmap.Draw(Bitmap.Canvas, 0, 0, True); 528 BGRABitmap.Draw(PaintBox.Canvas, 0, 0, True); 529 end; 530 531 procedure TBGRABitmapPaintBox.Init(Parent: TWinControl; Size: TPoint); 532 begin 533 inherited Init(Parent, Size); 534 BGRABitmap.SetSize(PaintBox.Width, PaintBox.Height); 450 535 end; 451 536 … … 483 568 end; 484 569 BGRABitmap.InvalidateBitmap; // changed by direct access 485 //BGRABitmap.Draw(Bitmap.Canvas, 0, 0, True); 486 BGRABitmap.Draw(PaintBox.Canvas, 0, 0, True); 570 PaintBox.Repaint; 487 571 end; 488 572 … … 494 578 Caption := 'TBitmap.RawImage.Data PaintBox'; 495 579 PaintObject := poPaintBox; 580 end; 581 582 procedure TBitmapRawImageDataPaintBox.Paint(Sender: TObject); 583 var 584 hPaint, hBmp: HDC; 585 begin 586 hBmp := TempBitmap.Canvas.Handle; 587 hPaint := PaintBox.Canvas.Handle; 588 PaintBox.Canvas.CopyRect(Rect(0, 0, PaintBox.Width, PaintBox.Height), TempBitmap.Canvas, 589 Rect(0, 0, TempBitmap.Width, TempBitmap.Height)); 590 // PaintBox.Canvas.Draw(0, 0, TempBitmap); 591 //BitBlt(hPaint, 0, 0, TempBitmap.Width, TempBitmap.Height, hBmp, 0, 0, srcCopy); 496 592 end; 497 593 … … 505 601 BytePerPixel: Integer; 506 602 BytePerRow: Integer; 507 hPaint, hBmp: HDC;508 603 begin 509 604 P := TempBitmap.PixelFormat; … … 526 621 TempBitmap.EndUpdate(False); 527 622 end; 528 hBmp := TempBitmap.Canvas.Handle; 529 hPaint := PaintBox.Canvas.Handle; 530 PaintBox.Canvas.CopyRect(Rect(0, 0, Bitmap.Width, Bitmap.Height), TempBitmap.Canvas, 531 Rect(0, 0, TempBitmap.Width, TempBitmap.Height)); 532 // PaintBox.Canvas.Draw(0, 0, TempBitmap); 533 //BitBlt(hPaint, 0, 0, TempBitmap.Width, TempBitmap.Height, hBmp, 0, 0, srcCopy); 623 PaintBox.Repaint; 534 624 end; 535 625 … … 552 642 BytePerRow: Integer; 553 643 begin 554 P := Bitmap.PixelFormat;644 P := Image.Picture.Bitmap.PixelFormat; 555 645 with FastBitmap do 556 646 try 557 Bitmap.BeginUpdate(False);558 RawImage := Bitmap.RawImage;647 Image.Picture.Bitmap.BeginUpdate(False); 648 RawImage := Image.Picture.Bitmap.RawImage; 559 649 RowPtr := PCardinal(RawImage.Data); 560 650 BytePerPixel := RawImage.Description.BitsPerPixel div 8; … … 569 659 end; 570 660 finally 571 Bitmap.EndUpdate(False);661 Image.Picture.Bitmap.EndUpdate(False); 572 662 end; 573 663 end; … … 575 665 { TLazIntfImageColorsNoCopy } 576 666 577 procedure TLazIntfImageColorsNoCopy. SetBitmap(const AValue: TBitmap);578 begin 579 inherited SetBitmap(AValue);667 procedure TLazIntfImageColorsNoCopy.Init(Parent: TWinControl; Size: TPoint); 668 begin 669 inherited Init(Parent, Size); 580 670 TempIntfImage.Free; 581 TempIntfImage := Bitmap.CreateIntfImage;671 TempIntfImage := Image.Picture.Bitmap.CreateIntfImage; 582 672 end; 583 673 … … 602 692 for Y := 0 to Size.Y - 1 do 603 693 TempIntfImage.Colors[X, Y] := TColorToFPColor(SwapBRComponent(Pixels[X, Y])); 604 Bitmap.LoadFromIntfImage(TempIntfImage);694 Image.Picture.Bitmap.LoadFromIntfImage(TempIntfImage); 605 695 end; 606 696 end; … … 626 716 begin 627 717 with FastBitmap do begin 628 TempIntfImage.LoadFromBitmap( Bitmap.Handle,629 Bitmap.MaskHandle);718 TempIntfImage.LoadFromBitmap(Image.Picture.Bitmap.Handle, 719 Image.Picture.Bitmap.MaskHandle); 630 720 for X := 0 to Size.X - 1 do 631 721 for Y := 0 to Size.Y - 1 do 632 722 TempIntfImage.Colors[X, Y] := TColorToFPColor(SwapBRComponent(Pixels[X, Y])); 633 Bitmap.LoadFromIntfImage(TempIntfImage);723 Image.Picture.Bitmap.LoadFromIntfImage(TempIntfImage); 634 724 end; 635 725 end; … … 649 739 with FastBitmap do 650 740 try 651 Bitmap.BeginUpdate(True);741 Image.Picture.Bitmap.BeginUpdate(True); 652 742 for Y := 0 to Size.Y - 1 do 653 743 for X := 0 to Size.X - 1 do 654 Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));744 Image.Picture.Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y])); 655 745 finally 656 Bitmap.EndUpdate(False);746 Image.Picture.Bitmap.EndUpdate(False); 657 747 end; 658 748 end; … … 673 763 for Y := 0 to Size.Y - 1 do 674 764 for X := 0 to Size.X - 1 do 675 Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y]));765 Image.Picture.Bitmap.Canvas.Pixels[X, Y] := TColor(SwapBRComponent(Pixels[X, Y])); 676 766 end; 677 767 end; … … 679 769 { TDrawMethod } 680 770 681 procedure TDrawMethod.SetBitmap(const AValue: TBitmap); 682 begin 683 if FBitmap = AValue then exit; 684 FBitmap := AValue; 685 TempBitmap.SetSize(FBitmap.Width, FBitmap.Height); 686 end; 687 688 procedure TDrawMethod.SetPaintBox(const AValue: TPaintBox); 689 begin 690 if FPaintBox = AValue then Exit; 691 FPaintBox := AValue; 692 end; 693 694 procedure TDrawMethod.Init; 771 procedure TDrawMethod.Init(Parent: TWinControl; Size: TPoint); 772 begin 773 if (TempBitmap.Width <> Size.X) or (TempBitmap.Height <> Size.Y) then 774 TempBitmap.SetSize(Size.X, Size.Y); 775 end; 776 777 procedure TDrawMethod.Done; 695 778 begin 696 779 … … 704 787 destructor TDrawMethod.Destroy; 705 788 begin 706 TempBitmap.Free;789 FreeAndNil(TempBitmap); 707 790 inherited Destroy; 708 791 end;
Note:
See TracChangeset
for help on using the changeset viewer.