opengl: cocoa: init with attributes

git-svn-id: trunk@49816 -
This commit is contained in:
mattias 2015-09-11 15:52:12 +00:00
parent b690381ab0
commit ff1747c1eb

View File

@ -94,13 +94,13 @@ type
end; end;
function GetCGLContextObj(OpenGLControlHandle: HWND): CGLContextObj; function GetCGLContextObj(OpenGLControlHandle: HWND): CGLContextObj;
function CreateCGLContextAttrList(DoubleBuffered: boolean; (*function CreateCGLContextAttrList(DoubleBuffered: boolean;
{$IFDEF UsesModernGL} {$IFDEF UsesModernGL}
MajorVersion, MinorVersion: Cardinal; MajorVersion, MinorVersion: Cardinal;
{$ENDIF} {$ENDIF}
MultiSampling, AlphaBits, DepthBits, MultiSampling, AlphaBits, DepthBits,
StencilBits, AUXBuffers: cardinal): PInteger; StencilBits, AUXBuffers: cardinal): PInteger;
function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean; function IsCGLPixelFormatAvailable(Attribs: PInteger): boolean;*)
implementation implementation
@ -151,6 +151,7 @@ var
p: NSView; p: NSView;
ns: NSRect; ns: NSRect;
aNSOpenGLContext: NSOpenGLContext; aNSOpenGLContext: NSOpenGLContext;
CGLContext: CGLContextObj;
begin begin
Result:=0; Result:=0;
@ -158,20 +159,26 @@ begin
if (AParams.WndParent <> 0) then if (AParams.WndParent <> 0) then
p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent)); p := CocoaUtils.GetNSObjectView(NSObject(AParams.WndParent));
//CGLContext:=GetCGLContextObj(AParams.WndParent);
//CGLSetCurrentContext(CGLContext);
if Assigned(p) then if Assigned(p) then
LCLToNSRect(types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height), LCLToNSRect(types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height),
p.frame.size.height, ns) p.frame.size.height, ns)
else else
ns := GetNSRect(AParams.X, AParams.Y, AParams.Width, AParams.Height); ns := GetNSRect(AParams.X, AParams.Y, AParams.Width, AParams.Height);
Attrs:=CreateOpenGLContextAttrList(DoubleBuffered,MajorVersion,MinorVersion, Attrs:=CreateOpenGLContextAttrList(DoubleBuffered,MajorVersion,MinorVersion, MultiSampling,AlphaBits,DepthBits,StencilBits,AUXBuffers);
MultiSampling,AlphaBits,DepthBits,StencilBits,AUXBuffers);
try try
PixFmt:=NSOpenGLPixelFormat(NSOpenGLPixelFormat.alloc).initWithAttributes(Attrs); PixFmt:=NSOpenGLPixelFormat(NSOpenGLPixelFormat.alloc).initWithAttributes(Attrs);
aNSOpenGLContext:=NSOpenGLContext(NSOpenGLContext.alloc).initWithFormat_shareContext(PixFmt,nil); aNSOpenGLContext:=NSOpenGLContext(NSOpenGLContext.alloc).initWithFormat_shareContext(PixFmt,nil);
debugln(['LOpenGLCreateContext ',aNSOpenGLContext<>nil]); debugln(['LOpenGLCreateContext ',aNSOpenGLContext<>nil]);
//View := TCocoaOpenGLView(TCocoaOpenGLView.alloc).initWithFrame_pixelFormat(ns,PixFmt); View := TCocoaOpenGLView(TCocoaOpenGLView.alloc).initWithFrame_pixelFormat(ns,PixFmt);
View := TCocoaOpenGLView(TCocoaOpenGLView.alloc).initWithFrame(ns);
//View := TCocoaOpenGLView(TCocoaOpenGLView.alloc).initWithFrame(ns);
//CGLContext:=GetCGLContextObj(AParams.WndParent);
//
//View := TCocoaOpenGLView(TCocoaOpenGLView(TCocoaOpenGLView.alloc).lclInitWithCreateParams(AParams)); //View := TCocoaOpenGLView(TCocoaOpenGLView(TCocoaOpenGLView.alloc).lclInitWithCreateParams(AParams));
if not Assigned(View) then Exit; if not Assigned(View) then Exit;
finally finally
@ -203,8 +210,7 @@ function CreateOpenGLContextAttrList(DoubleBuffered: boolean; MajorVersion,
AUXBuffers: cardinal): NSOpenGLPixelFormatAttributePtr; AUXBuffers: cardinal): NSOpenGLPixelFormatAttributePtr;
var var
p: integer; p: integer;
procedure Addx(i: NSOpenGLPixelFormatAttribute);
procedure Add(i: NSOpenGLPixelFormatAttribute);
begin begin
if Result<>nil then if Result<>nil then
Result[p]:=i; Result[p]:=i;
@ -213,59 +219,82 @@ var
procedure CreateList; procedure CreateList;
begin begin
Add(NSOpenGLPFAProfile); Addx(NSOpenGLPFAAccelerated);
if (MajorVersion=3) and (MinorVersion=2) then Addx(NSOpenGLPFAProfile);
Add(NSOpenGLProfileVersion3_2Core) Addx(NSOpenGLProfileLegacy);
else if (MajorVersion=4) and (MinorVersion=1) then Addx(NSOpenGLPFAColorSize); Addx(24);
Add(NSOpenGLProfileVersion4_1Core) Addx(NSOpenGLPFAAlphaSize); Addx(8);
else Addx(NSOpenGLPFAMinimumPolicy);
Add(NSOpenGLProfileLegacy); Addx(NSOpenGLPFADepthSize); Addx(24);
if MultiSampling > 1 then
//Add(NSOpenGLPFAColorSize); Add(24);
//Add(NSOpenGLPFADepthSize); Add(16);
Add(NSOpenGLPFADoubleBuffer);
Add(0);
exit;
if DoubleBuffered then
Add(NSOpenGLPFADoubleBuffer);
//if (MajorVersion>=3) and (MinorVersion>=2) then
// Add(NSOpenGLPFA);
Add(NSOpenGLPFANoRecovery);
Add(NSOpenGLPFAMaximumPolicy);
Add(NSOpenGLPFASingleRenderer);
Add(NSOpenGLPFAColorSize); Add(24);
if AlphaBits>0 then
begin begin
Add(NSOpenGLPFAAlphaSize); Add(AlphaBits); Addx(NSOpenGLPFAMultisample);
end; Addx(NSOpenGLPFASampleBuffers); Addx(1);
if DepthBits>0 then Addx(NSOpenGLPFASamples); Addx(MultiSampling);
begin
Add(NSOpenGLPFADepthSize); Add(DepthBits);
end; end;
if StencilBits>0 then if StencilBits>0 then
begin begin
Add(NSOpenGLPFAStencilSize); Add(StencilBits); Addx(NSOpenGLPFAStencilSize); Addx(StencilBits);
end; end;
if AUXBuffers>0 then if AUXBuffers>0 then
begin begin
Add(NSOpenGLPFAAuxBuffers); Add(AUXBuffers); Addx(NSOpenGLPFAAuxBuffers); Addx(AUXBuffers);
end;
Addx(0); // end of list
(*
Addx(NSOpenGLPFAProfile);
if (MajorVersion=3) and (MinorVersion=2) then
Addx(NSOpenGLProfileVersion3_2Core)
else if (MajorVersion=4) and (MinorVersion=1) then
Addx(NSOpenGLProfileVersion4_1Core)
else
Addx(NSOpenGLProfileLegacy);
//Addx(NSOpenGLPFAColorSize); Addx(24);
//Addx(NSOpenGLPFADepthSize); Addx(16);
Addx(NSOpenGLPFADoubleBuffer);
Addx(0);
exit;
Addx(NSOpenGLPFAAccelerated);
if DoubleBuffered then
Addx(NSOpenGLPFADoubleBuffer);
//if (MajorVersion>=3) and (MinorVersion>=2) then
// Addx(NSOpenGLPFA);
Addx(NSOpenGLPFANoRecovery);
Addx(NSOpenGLPFAMaximumPolicy);
Addx(NSOpenGLPFASingleRenderer);
Addx(NSOpenGLPFAColorSize); Addx(32); //CR 24
if AlphaBits>0 then
begin
Addx(NSOpenGLPFAAlphaSize); Addx(AlphaBits);
end;
if DepthBits>0 then
begin
Addx(NSOpenGLPFADepthSize); Addx(DepthBits);
end;
if StencilBits>0 then
begin
Addx(NSOpenGLPFAStencilSize); Addx(StencilBits);
end;
if AUXBuffers>0 then
begin
Addx(NSOpenGLPFAAuxBuffers); Addx(AUXBuffers);
end; end;
if MultiSampling > 1 then if MultiSampling > 1 then
begin begin
Add(NSOpenGLPFAMultisample); Addx(NSOpenGLPFAMultisample);
Add(NSOpenGLPFASampleBuffers); Add(1); Addx(NSOpenGLPFASampleBuffers); Addx(1);
Add(NSOpenGLPFASamples); Add(MultiSampling); Addx(NSOpenGLPFASamples); Addx(MultiSampling);
end; end;
Addx(0); // end of list *)
Add(0); // end of list
end; end;
begin begin
Result:=nil; Result:=nil;
p:=0; p:=0;
CreateList; CreateList;
GetMem(Result,SizeOf(NSOpenGLPixelFormatAttribute)*p); GetMem(Result,SizeOf(NSOpenGLPixelFormatAttribute)*(p+1));
p:=0; p:=0;
CreateList; CreateList;
end; end;
@ -280,7 +309,7 @@ begin
Result:=CGLContextObj(View.openGLContext.CGLContextObj); Result:=CGLContextObj(View.openGLContext.CGLContextObj);
end; end;
function CreateCGLContextAttrList(DoubleBuffered: boolean; MultiSampling, (*function CreateCGLContextAttrList(DoubleBuffered: boolean; MultiSampling,
AlphaBits, DepthBits, StencilBits, AUXBuffers: cardinal): PInteger; AlphaBits, DepthBits, StencilBits, AUXBuffers: cardinal): PInteger;
var var
p: integer; p: integer;
@ -351,7 +380,7 @@ begin
exit(false); exit(false);
Result:=true; Result:=true;
// ToDo: free aPixFormatObj // ToDo: free aPixFormatObj
end; end; *)
{ TCocoaOpenGLView } { TCocoaOpenGLView }