opengl: forcing painting even with NSgraphicContext currentContext assigned. Seems to be Mojave specific behaviour not to provide context. bug #34983

git-svn-id: trunk@61060 -
This commit is contained in:
dmitry 2019-04-26 13:26:27 +00:00
parent 59587a0452
commit e653d0cc68
4 changed files with 75 additions and 11 deletions

View File

@ -1,10 +1,22 @@
object Form1: TForm1 object Form1: TForm1
Left = 419 Left = 302
Height = 300 Height = 300
Top = 287 Top = 181
Width = 400 Width = 400
HorzScrollBar.Page = 399 HorzScrollBar.Page = 399
VertScrollBar.Page = 299 VertScrollBar.Page = 299
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 300
ClientWidth = 400
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '2.1.0.0'
object Panel1: TPanel
Left = 97
Height = 50
Top = 49
Width = 170
Caption = 'Panel1'
TabOrder = 0
OnMouseMove = Panel1MouseMove
end
end end

View File

@ -15,25 +15,32 @@ interface
uses uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
OpenGLContext, GL, GLU; ExtCtrls, OpenGLContext, GL, GLU, CocoaInt
,CocoaWSCommon, CocoaPrivate;
type type
{ TForm1 } { TForm1 }
TForm1 = class(TForm) TForm1 = class(TForm)
Panel1: TPanel;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure OpenGLControl1Paint(Sender: TObject); procedure OpenGLControl1Paint(Sender: TObject);
procedure OpenGLControl1Resize(Sender: TObject); procedure OpenGLControl1Resize(Sender: TObject);
procedure OnAppIdle(Sender: TObject; var Done: Boolean); procedure OnAppIdle(Sender: TObject; var Done: Boolean);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
);
private private
public public
cube_rotationx: GLFloat; cube_rotationx: GLFloat;
cube_rotationy: GLFloat; cube_rotationy: GLFloat;
cube_rotationz: GLFloat; cube_rotationz: GLFloat;
OpenGLControl1: TOpenGLControl; OpenGLControl1: TOpenGLControl;
procedure OpenGLMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
end; end;
var var
Form1: TForm1; Form1: TForm1;
@ -52,16 +59,24 @@ begin
Parent:=Self; Parent:=Self;
OnPaint:=@OpenGLControl1Paint; OnPaint:=@OpenGLControl1Paint;
OnResize:=@OpenGLControl1Resize; OnResize:=@OpenGLControl1Resize;
OnMouseMove:=@OpenGLMouseMove;
AutoResizeViewport:=true; AutoResizeViewport:=true;
end; end;
Application.AddOnIdleHandler(@OnAppIdle); Application.AddOnIdleHandler(@OnAppIdle);
end; end;
procedure TForm1.OpenGLMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
Caption:=Format('%d %d',[x,y]);
end;
procedure TForm1.OpenGLControl1Paint(Sender: TObject); procedure TForm1.OpenGLControl1Paint(Sender: TObject);
var var
Speed: Double; Speed: Double;
begin begin
writeln('paint');
glClearColor(1.0, 1.0, 1.0, 1.0); glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -139,8 +154,15 @@ procedure TForm1.OnAppIdle(Sender: TObject; var Done: Boolean);
begin begin
Done:=false; Done:=false;
//DebugLn(['TForm1.OnAppIdle ']); //DebugLn(['TForm1.OnAppIdle ']);
//OpenGLControl1.Paint;
OpenGLControl1.Invalidate; OpenGLControl1.Invalidate;
end; end;
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Caption:=Format('panel: %d %d',[x,y]);
end;
end. end.

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="9"/> <Version Value="12"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<General> <General>
<Flags> <Flags>
<LRSInOutputDirectory Value="False"/> <LRSInOutputDirectory Value="False"/>
<CompatibilityMode Value="True"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
</General> </General>
<BuildModes Count="1"> <BuildModes Count="1">
@ -16,15 +16,19 @@
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions> </PublishOptions>
<RunParams> <RunParams>
<local> <local>
<FormatVersion Value="1"/> <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local> </local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>
@ -44,6 +48,7 @@
<Filename Value="mainunit.pas"/> <Filename Value="mainunit.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="MainUnit"/> <UnitName Value="MainUnit"/>
</Unit1> </Unit1>
@ -57,6 +62,9 @@
</SyntaxOptions> </SyntaxOptions>
</Parsing> </Parsing>
<Linking> <Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
<Options> <Options>
<Win32> <Win32>
<GraphicApplication Value="True"/> <GraphicApplication Value="True"/>

View File

@ -25,6 +25,7 @@ interface
uses uses
Classes, SysUtils, types, CocoaWSCommon, CocoaPrivate, CocoaUtils, LCLType, Classes, SysUtils, types, CocoaWSCommon, CocoaPrivate, CocoaUtils, LCLType,
LMessages, LCLMessageGlue,
Controls, LazLoggerBase, WSLCLClasses, gl, MacOSAll, CocoaAll; Controls, LazLoggerBase, WSLCLClasses, gl, MacOSAll, CocoaAll;
function LBackingScaleFactor(Handle: HWND): single; function LBackingScaleFactor(Handle: HWND): single;
@ -533,10 +534,31 @@ begin
end; end;
procedure TCocoaOpenGLView.drawRect(dirtyRect: NSRect); procedure TCocoaOpenGLView.drawRect(dirtyRect: NSRect);
var
ctx : NSGraphicsContext;
PS : TPaintStruct;
r : NSRect;
begin begin
ctx := NSGraphicsContext.currentContext;
inherited drawRect(dirtyRect); inherited drawRect(dirtyRect);
if CheckMainThread and Assigned(callback) then if CheckMainThread and Assigned(callback) then
callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect); begin
if ctx = nil then
begin
// In macOS 10.14 (mojave) current context is nil
// we still can paint anything releated to OpenGL!
// todo: consider creating a dummy context (for a bitmap)
FillChar(PS, SizeOf(TPaintStruct), 0);
r := frame;
r.origin.x:=0;
r.origin.y:=0;
PS.hdc := HDC(0);
PS.rcPaint := NSRectToRect(r);
LCLSendPaintMsg(Owner, HDC(0), @PS);
end
else
callback.Draw(ctx, bounds, dirtyRect);
end;
end; end;
end. end.