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
Left = 419
Left = 302
Height = 300
Top = 287
Top = 181
Width = 400
HorzScrollBar.Page = 399
VertScrollBar.Page = 299
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 400
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

View File

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

View File

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

View File

@ -25,6 +25,7 @@ interface
uses
Classes, SysUtils, types, CocoaWSCommon, CocoaPrivate, CocoaUtils, LCLType,
LMessages, LCLMessageGlue,
Controls, LazLoggerBase, WSLCLClasses, gl, MacOSAll, CocoaAll;
function LBackingScaleFactor(Handle: HWND): single;
@ -533,10 +534,31 @@ begin
end;
procedure TCocoaOpenGLView.drawRect(dirtyRect: NSRect);
var
ctx : NSGraphicsContext;
PS : TPaintStruct;
r : NSRect;
begin
ctx := NSGraphicsContext.currentContext;
inherited drawRect(dirtyRect);
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.