Changeset 443
- Timestamp:
- Nov 22, 2012, 12:28:54 PM (12 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/GraphicTest.lpi
r442 r443 73 73 </Item3> 74 74 </RequiredPackages> 75 <Units Count=" 5">75 <Units Count="6"> 76 76 <Unit0> 77 77 <Filename Value="GraphicTest.lpr"/> … … 102 102 <UnitName Value="UFastBitmap"/> 103 103 </Unit4> 104 <Unit5> 105 <Filename Value="UDrawForm.pas"/> 106 <IsPartOfProject Value="True"/> 107 <ComponentName Value="DrawForm"/> 108 <ResourceBaseClass Value="Form"/> 109 <UnitName Value="UDrawForm"/> 110 </Unit5> 104 111 </Units> 105 112 </ProjectOptions> … … 130 137 <Linking> 131 138 <Debugging> 132 <UseHeaptrc Value="True"/>133 139 <UseExternalDbgSyms Value="True"/> 134 140 </Debugging> … … 143 149 <UseMsgFile Value="True"/> 144 150 </CompilerMessages> 151 <CustomOptions Value="-dopengl"/> 145 152 <CompilerPath Value="$(CompPath)"/> 146 153 </Other> -
GraphicTest/GraphicTest.lpr
r317 r443 9 9 Interfaces, // this includes the LCL widgetset 10 10 Forms, lazopenglcontext, UMainForm, UPlatform, UDrawMethod, UFastBitmap, 11 bgrabitmappack ;11 bgrabitmappack, UDrawForm; 12 12 13 13 {$R *.res} … … 17 17 Application.Initialize; 18 18 Application.CreateForm(TMainForm, MainForm); 19 Application.CreateForm(TDrawForm, DrawForm); 19 20 Application.Run; 20 21 end. -
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; -
GraphicTest/UMainForm.lfm
r338 r443 1 1 object MainForm: TMainForm 2 2 Left = 187 3 Height = 4 214 Top = 685 Width = 7353 Height = 440 4 Top = 107 5 Width = 549 6 6 Caption = 'Graphic test' 7 ClientHeight = 4 218 ClientWidth = 7357 ClientHeight = 440 8 ClientWidth = 549 9 9 OnClose = FormClose 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 12 OnShow = FormShow 13 LCLVersion = '0.9.31' 14 object PageControl1: TPageControl 15 Left = 384 16 Height = 401 17 Top = 16 18 Width = 348 19 ActivePage = TabSheet1 20 Anchors = [akTop, akRight, akBottom] 21 TabIndex = 0 22 TabOrder = 0 23 object TabSheet1: TTabSheet 24 Caption = 'TImage' 25 ClientHeight = 368 26 ClientWidth = 342 27 object Image1: TImage 28 Left = 6 29 Height = 300 30 Top = 7 31 Width = 332 32 Anchors = [akTop, akLeft, akRight, akBottom] 33 end 34 end 35 object TabSheet2: TTabSheet 36 Caption = 'TPaintBox' 37 ClientHeight = 368 38 ClientWidth = 342 39 object PaintBox1: TPaintBox 40 Left = 6 41 Height = 279 42 Top = 7 43 Width = 350 44 Anchors = [akTop, akLeft, akRight, akBottom] 45 end 46 end 47 object TabSheet3: TTabSheet 48 Caption = 'OpenGL' 49 end 50 end 13 LCLVersion = '1.1' 51 14 object ListViewMethods: TListView 52 15 Left = 8 53 Height = 3 4516 Height = 364 54 17 Top = 8 55 Width = 36818 Width = 537 56 19 Anchors = [akTop, akLeft, akRight, akBottom] 57 20 Columns = < … … 79 42 ReadOnly = True 80 43 RowSelect = True 81 TabOrder = 144 TabOrder = 0 82 45 ViewStyle = vsReport 83 46 OnData = ListViewMethodsData … … 87 50 Left = 8 88 51 Height = 25 89 Top = 3 6052 Top = 379 90 53 Width = 115 91 54 Anchors = [akLeft, akBottom] 92 55 Caption = 'Test one method' 93 56 OnClick = ButtonSingleTestClick 94 TabOrder = 257 TabOrder = 1 95 58 end 96 59 object ButtonBenchmark: TButton 97 60 Left = 136 98 61 Height = 25 99 Top = 3 6062 Top = 379 100 63 Width = 112 101 64 Anchors = [akLeft, akBottom] 102 65 Caption = 'Test all methods' 103 66 OnClick = ButtonBenchmarkClick 104 TabOrder = 367 TabOrder = 2 105 68 end 106 69 object FloatSpinEdit1: TFloatSpinEdit 107 70 Left = 88 108 Height = 2 5109 Top = 38871 Height = 21 72 Top = 411 110 73 Width = 58 111 74 Anchors = [akLeft, akBottom] … … 113 76 MaxValue = 100 114 77 MinValue = 0 115 TabOrder = 478 TabOrder = 3 116 79 Value = 1 117 80 end … … 119 82 Left = 256 120 83 Height = 25 121 Top = 3 6084 Top = 379 122 85 Width = 75 123 86 Anchors = [akLeft, akBottom] 124 87 Caption = 'Stop' 125 88 OnClick = ButtonStopClick 126 TabOrder = 589 TabOrder = 4 127 90 end 128 91 object Label1: TLabel 129 92 Left = 8 130 Height = 1 6131 Top = 393132 Width = 9293 Height = 13 94 Top = 415 95 Width = 69 133 96 Anchors = [akLeft, akBottom] 134 97 Caption = 'Step duration:' … … 137 100 object Label2: TLabel 138 101 Left = 152 139 Height = 1 6140 Top = 393141 Width = 8102 Height = 13 103 Top = 415 104 Width = 5 142 105 Anchors = [akLeft, akBottom] 143 106 Caption = 's' -
GraphicTest/UMainForm.pas
r442 r443 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 9 ExtCtrls, StdCtrls, DateUtils, UPlatform, LCLType, IntfGraphics, fpImage, 10 Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod 11 {$IFDEF opengl}, GL, OpenGLContext{$ENDIF}; 10 Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod; 12 11 13 12 const … … 24 23 ButtonSingleTest: TButton; 25 24 FloatSpinEdit1: TFloatSpinEdit; 26 Image1: TImage;27 25 Label1: TLabel; 28 26 Label2: TLabel; 29 27 ListViewMethods: TListView; 30 PageControl1: TPageControl;31 PaintBox1: TPaintBox;32 TabSheet1: TTabSheet;33 TabSheet2: TTabSheet;34 TabSheet3: TTabSheet;35 28 Timer1: TTimer; 36 29 procedure ButtonBenchmarkClick(Sender: TObject); 37 30 procedure ButtonSingleTestClick(Sender: TObject); 38 31 procedure ButtonStopClick(Sender: TObject); 39 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);40 32 procedure FormCreate(Sender: TObject); 41 33 procedure FormDestroy(Sender: TObject); 42 34 procedure FormShow(Sender: TObject); 35 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 43 36 procedure ListViewMethodsData(Sender: TObject; Item: TListItem); 44 37 procedure ListViewMethodsSelectItem(Sender: TObject; Item: TListItem; … … 46 39 procedure Timer1Timer(Sender: TObject); 47 40 private 48 {$IFDEF opengl}49 OpenGLControl1: TOpenGLControl;50 TextureId: GLuint;51 TextureData: Pointer;52 {$ENDIF}53 41 MethodIndex: Integer; 54 42 SingleTestActive: Boolean; 55 43 AllTestActive: Boolean; 56 procedure OpenGLControl1Resize(Sender: TObject);57 {$IFDEF opengl}58 procedure InitGL;59 {$ENDIF}60 44 procedure UpdateMethodList; 61 45 procedure UpdateInterface; 62 46 public 47 FrameSize: TPoint; 63 48 DrawMethods: TObjectList; // TObjectList<TDrawMethod> 64 Bitmap: TBitmap;65 49 Scenes: TObjectList; // TObjectList<TFastBitmap> 66 50 SceneIndex: Integer; … … 73 57 74 58 {$R *.lfm} 59 60 uses 61 UDrawForm; 62 75 63 76 64 { TMainForm } … … 82 70 I: Integer; 83 71 begin 84 TabSheet1.DoubleBuffered := True;72 FrameSize := Point(320, 240); 85 73 Randomize; 86 74 Scenes := TObjectList.Create; 87 75 for I := 0 to SceneFrameCount - 1 do begin 88 76 NewScene := TFastBitmap.Create; 89 NewScene.Size := Point(320, 240);77 NewScene.Size := FrameSize; 90 78 NewScene.RandomImage; 91 79 Scenes.Add(NewScene); 92 80 end; 93 Bitmap := TBitmap.Create;94 Bitmap.PixelFormat := pf24bit;95 Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);96 Image1.Picture.Bitmap.PixelFormat := pf24bit;97 Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);98 99 {$IFDEF opengl}100 OpenGLControl1 := TOpenGLControl.Create(Self);101 with OpenGLControl1 do begin102 Name := 'OpenGLControl1';103 Parent := TabSheet3;104 SetBounds(0, 0, 320, 240);105 InitGL;106 //OnPaint := OpenGLControl1Paint;107 OnResize := OpenGLControl1Resize;108 end;109 GetMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height * SizeOf(Integer));110 {$ENDIF}111 81 112 82 DrawMethods := TObjectList.Create; 113 83 for I := 0 to High(DrawMethodClasses) do begin 114 84 NewDrawMethod := DrawMethodClasses[I].Create; 115 NewDrawMethod.Bitmap := Image1.Picture.Bitmap;116 NewDrawMethod.PaintBox := PaintBox1;117 {$IFDEF opengl}118 NewDrawMethod.OpenGLBitmap := TextureData;119 NewDrawMethod.OpenGLControl := OpenGLControl1;120 {$ENDIF}121 NewDrawMethod.Init;122 85 DrawMethods.Add(NewDrawMethod); 123 86 end; … … 136 99 if MethodIndex >= 0 then 137 100 with TDrawMethod(DrawMethods[MethodIndex]) do begin 138 PageControl1.TabIndex := Integer(PaintObject);101 Init(DrawForm, FrameSize); 139 102 Application.ProcessMessages; 140 103 repeat … … 145 108 StepDuration := NowPrecise - StepStartTime; 146 109 until not SingleTestActive; 110 Done; 147 111 end; 148 112 finally … … 156 120 var 157 121 I: Integer; 158 C: Integer;159 122 StartTime: TDateTime; 160 123 StepStartTime: TDateTime; … … 167 130 for I := 0 to DrawMethods.Count - 1 do 168 131 with TDrawMethod(DrawMethods[I]) do begin 132 Init(DrawForm, FrameSize); 169 133 MethodIndex := I; 170 PageControl1.TabIndex := Integer(PaintObject);171 134 StartTime := NowPrecise; 172 135 repeat … … 177 140 StepDuration := NowPrecise - StepStartTime; 178 141 until ((NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value) or not AllTestActive; 142 Done; 179 143 end; 180 144 finally … … 199 163 begin 200 164 ListViewMethods.Clear; 201 {$IFDEF opengl}FreeMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height);{$ENDIF}202 165 FreeAndNil(DrawMethods); 203 166 FreeAndNil(Scenes); 204 FreeAndNil(Bitmap);205 167 end; 206 168 … … 209 171 UpdateMethodList; 210 172 UpdateInterface; 173 DrawForm.Show; 211 174 end; 212 175 … … 238 201 end; 239 202 240 procedure TMainForm.OpenGLControl1Resize(Sender: TObject);241 begin242 {$IFDEF opengl}243 glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);244 {$ENDIF}245 end;246 247 {$IFDEF opengl}248 procedure TMainForm.InitGL;249 begin250 glMatrixMode(GL_PROJECTION);251 glLoadIdentity;252 glOrtho(0, OpenGLControl1.Width, OpenGLControl1.Height, 0, 0, 1);253 // glOrtho(0, 1, 1, 0, 0, 1);254 glMatrixMode(GL_MODELVIEW);255 glLoadIdentity();256 glDisable(GL_DEPTH_TEST);257 glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);258 //gluPerspective( 45.0, (GLfloat)(OpenGLControl1.Width)/(GLfloat)(OpenGLControl1.Height), 0.1f, 500.0 );259 260 //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);261 //glTranslatef (0.0, 0.0,-3.0);262 // glClearColor(0.0, 0.0, 0.0, 1.0);263 264 glGenTextures(1, @TextureId);265 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);266 end;267 {$ENDIF}268 269 203 procedure TMainForm.UpdateMethodList; 270 204 begin
Note:
See TracChangeset
for help on using the changeset viewer.