Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from vcmi/test_lazarus_2_0
Browse files Browse the repository at this point in the history
Updated for Lazarus 2 0
  • Loading branch information
alexvins authored Feb 5, 2019
2 parents 60d35e1 + 0951b5d commit 41eeeeb
Show file tree
Hide file tree
Showing 47 changed files with 2,226 additions and 1,116 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
dist: xenial

language: generic

addons:
apt:
update: true
packages:
- libgtk2.0-dev
- libgl1-mesa-dev

install:
- sudo apt-get update
- sudo apt -y install libgtk2.0-dev

- wget -t 10 -O lazarus-project_1.8.2-0_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%201.8.2/lazarus-project_1.8.2-0_amd64.deb/download
- wget -t 10 -O fpc_3.0.4-2_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%201.8.2/fpc_3.0.4-2_amd64.deb/download
- wget -t 10 -O fpc-src_3.0.4-2_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%201.8.2/fpc-src_3.0.4-2_amd64.deb/download
- sudo dpkg -i fpc-src_3.0.4-2_amd64.deb fpc_3.0.4-2_amd64.deb lazarus-project_1.8.2-0_amd64.deb
before_install:
- wget -t 10 -O lazarus-project_2.0.0-0_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.0/lazarus-project_2.0.0-0_amd64.deb/download
- wget -t 10 -O fpc-laz_3.0.4-1_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.0/fpc-laz_3.0.4-1_amd64.deb/download
- wget -t 10 -O fpc-src_3.0.4-2_amd64.deb https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.0/fpc-src_3.0.4-2_amd64.deb/download
- sudo dpkg -i fpc-src_3.0.4-2_amd64.deb fpc-laz_3.0.4-1_amd64.deb lazarus-project_2.0.0-0_amd64.deb

script:
- make
- make build_tests
- make test

notifications:
Expand Down
4 changes: 2 additions & 2 deletions 3rd_party/opengl/vcmi.glcarbonaglcontext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface
WSLCLClasses, CarbonUtils,
Controls;

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLReleaseContext(Handle: HWND): boolean;
Expand Down Expand Up @@ -57,7 +57,7 @@ function GetAGLContext(Control: ControlRef): TAGLContext;

implementation

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
begin
glViewport(Left,Top,Width,Height);
end;
Expand Down
114 changes: 83 additions & 31 deletions 3rd_party/opengl/vcmi.glcocoanscontext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ interface
Classes, SysUtils, types, CocoaWSCommon, CocoaPrivate, CocoaUtils, LCLType,
Controls, LazLoggerBase, WSLCLClasses, gl, MacOSAll, CocoaAll;

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
function LBackingScaleFactor(Handle: HWND): single;
procedure LSetWantsBestResolutionOpenGLSurface(const AValue: boolean; Handle: HWND);
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLReleaseContext(Handle: HWND): boolean;
procedure LOpenGLClip(Handle: HWND);
function LOpenGLCreateContext(AWinControl: TWinControl;
{%H-}WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered: boolean;
DoubleBuffered, AMacRetinaMode: boolean;
MajorVersion, MinorVersion: Cardinal;
MultiSampling, AlphaBits, DepthBits, StencilBits, AUXBuffers: Cardinal;
const {%H-}AParams: TCreateParams): HWND;
Expand All @@ -52,6 +54,12 @@ function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
NSOpenGLProfileVersion4_1Core = $4100; //requires OSX SDK 10.10 or later, https://github.com/google/gxui/issues/98

type
NSOpenGLViewFix = objccategory external (NSOpenGLView)
procedure setWantsBestResolutionOpenGLSurface(bool: NSInteger); message 'setWantsBestResolutionOpenGLSurface:';
end;
NSScreenFix = objccategory external (NSScreen)
function backingScaleFactor: CGFloat ; message 'backingScaleFactor';
end;
TDummyNoWarnObjCNotUsed = objc.BOOL;
TDummyNoWarnObjCBaseNotUsed = objcbase.NSInteger;

Expand All @@ -62,14 +70,15 @@ function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
Owner: TWinControl;
//nsGL: NSOpenGLContext;
callback: TLCLCommonCallback;
function acceptsFirstResponder: Boolean; override;
function becomeFirstResponder: Boolean; override;
function resignFirstResponder: Boolean; override;
backingScaleFactor: Single;
function acceptsFirstResponder: LCLObjCBoolean; override;
function becomeFirstResponder: LCLObjCBoolean; override;
function resignFirstResponder: LCLObjCBoolean; override;
procedure drawRect(dirtyRect: NSRect); override;
procedure dealloc; override;
function lclGetCallback: ICommonCallback; override;
procedure lclClearCallback; override;
function lclIsHandle: Boolean; override;
function lclIsHandle: Boolean; message 'lclIsHandle'; {override;}//???
function lclIsEnabled: Boolean; override;
// mouse
procedure mouseDown(event: NSEvent); override;
Expand Down Expand Up @@ -102,9 +111,40 @@ function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean;*)

implementation

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
//value > 1 if screen is scaled, e.g. default for MOST retina displays is 2
function LBackingScaleFactor(Handle: HWND): single;
begin
result := TCocoaOpenGLView(Handle).backingScaleFactor;
end;
procedure LSetWantsBestResolutionOpenGLSurface(const AValue: boolean; Handle: HWND);
var
View: TCocoaOpenGLView;
begin
if Handle=0 then exit;
View:=TCocoaOpenGLView(Handle);
if not View.respondsToSelector(objcselector('setWantsBestResolutionOpenGLSurface:')) then exit;
if AValue then
View.setWantsBestResolutionOpenGLSurface(1)
else
View.setWantsBestResolutionOpenGLSurface(0);
if (AValue) and (NSScreen.mainScreen.respondsToSelector(objcselector('backingScaleFactor'))) then //MacOS >=10.7
View.backingScaleFactor := NSScreen.mainScreen.backingScaleFactor
else
View.backingScaleFactor := 1;
end;
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
var
View: NSOpenGLView absolute Handle;
lFinalWidth, lFinalHeight: Integer;
begin
glViewport(Left,Top,Width,Height);
lFinalWidth := Width;
lFinalHeight := Height;
if View <> nil then
begin
lFinalWidth := Round(Width * LBackingScaleFactor(Handle));
lFinalHeight := Round(Height * LBackingScaleFactor(Handle));
end;
glViewport(Left,Top,lFinalWidth,lFinalHeight);
end;

procedure LOpenGLSwapBuffers(Handle: HWND);
Expand Down Expand Up @@ -140,7 +180,8 @@ procedure LOpenGLClip(Handle: HWND);
end;

function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl; DoubleBuffered: boolean;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, AMacRetinaMode: boolean;
MajorVersion, MinorVersion: Cardinal;
MultiSampling, AlphaBits, DepthBits, StencilBits,
AUXBuffers: Cardinal; const AParams: TCreateParams): HWND;
Expand Down Expand Up @@ -180,6 +221,7 @@ function LOpenGLCreateContext(AWinControl: TWinControl;
View.Owner:=AWinControl;
//View.nsGL := aNSOpenGLContext;
View.callback:=TLCLCommonCallback.Create(View, AWinControl);
LSetWantsBestResolutionOpenGLSurface(AMacRetinaMode, HWND(View));
//View.setPixelFormat(PixFmt);
Result:=TLCLIntfHandle(View);
end;
Expand Down Expand Up @@ -215,7 +257,7 @@ procedure AddUInt32(i: NSOpenGLPixelFormatAttribute);
//else
//AddUInt32(NSOpenGLProfileLegacy); // NSOpenGLProfileLegacy is default and sufficient, later versions depend on SDK we are building against
AddUInt32(NSOpenGLPFAOpenGLProfile);
if (MajorVersion>=3) and (MinorVersion>=3) then
if ((MajorVersion>=4) and (MinorVersion>=1)) or ((MajorVersion>=3) and (MinorVersion>=3)) then
AddUInt32(NSOpenGLProfileVersion4_1Core) //OpenGL 4.1, GLSL 4.1
else if (MajorVersion>=3) and (MinorVersion>=2) then
AddUInt32(NSOpenGLProfileVersion3_2Core)
Expand Down Expand Up @@ -268,6 +310,7 @@ function GetCGLContextObj(OpenGLControlHandle: HWND): CGLContextObj;
if OpenGLControlHandle=0 then exit;
View:=TCocoaOpenGLView(OpenGLControlHandle);
Result:=CGLContextObj(View.openGLContext.CGLContextObj);
NSScreen.mainScreen.colorSpace;
end;

(*
Expand Down Expand Up @@ -347,18 +390,18 @@ function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean;

{ TCocoaOpenGLView }

function TCocoaOpenGLView.acceptsFirstResponder: Boolean;
function TCocoaOpenGLView.acceptsFirstResponder: LCLObjCBoolean;
begin
Result := True;
end;

function TCocoaOpenGLView.becomeFirstResponder: Boolean;
function TCocoaOpenGLView.becomeFirstResponder: LCLObjCBoolean;
begin
Result:=inherited becomeFirstResponder;
callback.BecomeFirstResponder;
end;

function TCocoaOpenGLView.resignFirstResponder: Boolean;
function TCocoaOpenGLView.resignFirstResponder: LCLObjCBoolean;
begin
Result:=inherited resignFirstResponder;
callback.ResignFirstResponder;
Expand Down Expand Up @@ -391,44 +434,51 @@ function TCocoaOpenGLView.lclIsEnabled: Boolean;

procedure TCocoaOpenGLView.mouseDown(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited mouseDown(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited mouseDown(event);
end;

procedure TCocoaOpenGLView.mouseUp(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited mouseUp(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited mouseUp(event);
end;

procedure TCocoaOpenGLView.rightMouseDown(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited rightMouseDown(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited rightMouseDown(event);
end;

procedure TCocoaOpenGLView.rightMouseUp(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited rightMouseUp(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited rightMouseUp(event);
end;

procedure TCocoaOpenGLView.otherMouseDown(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited otherMouseDown(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited otherMouseDown(event);
end;

procedure TCocoaOpenGLView.otherMouseUp(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
inherited otherMouseUp(event);
if Assigned(callback)
then callback.MouseUpDownEvent(event)
else inherited otherMouseUp(event);
end;

procedure TCocoaOpenGLView.mouseDragged(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseMove(event) then
inherited mouseDragged(event);
if Assigned(callback)
then callback.MouseMove(event)
else inherited mouseDragged(event);
end;

procedure TCocoaOpenGLView.mouseEntered(event: NSEvent);
Expand All @@ -443,14 +493,16 @@ procedure TCocoaOpenGLView.mouseExited(event: NSEvent);

procedure TCocoaOpenGLView.mouseMoved(event: NSEvent);
begin
if not Assigned(callback) or not callback.MouseMove(event) then
inherited mouseMoved(event);
if Assigned(callback)
then callback.MouseMove(event)
else inherited mouseMoved(event);
end;

procedure TCocoaOpenGLView.scrollWheel(event: NSEvent);
begin
if not Assigned(callback) or not callback.scrollWheel(event) then
inherited scrollWheel(event);
if Assigned(callback)
then callback.scrollWheel(event)
else inherited scrollWheel(event);
end;

procedure TCocoaOpenGLView.keyDown(event: NSEvent);
Expand Down
4 changes: 2 additions & 2 deletions 3rd_party/opengl/vcmi.glgtkglxcontext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function gdk_x11_get_default_xdisplay:PDisplay;cdecl;external;
function gdk_x11_get_default_screen:gint;cdecl;external;
{$ENDIF}

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLViewport({%H-}Handle: HWND; Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLReleaseContext({%H-}Handle: HWND): boolean;
Expand Down Expand Up @@ -768,7 +768,7 @@ procedure gtk_gl_area_swap_buffers(gl_area: PGtkGLArea);
gdk_gl_swap_buffers(GTK_WIDGET(gl_area)^.window);
end;

procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLViewport(Handle: HWND; Left, Top, Width, Height: integer);
begin
glViewport(Left,Top,Width,Height);
end;
Expand Down
Loading

0 comments on commit 41eeeeb

Please sign in to comment.