mirror of
https://git.vladimir.cc/vladimir/lazopenglcontextex.git
synced 2026-08-25 17:37:31 +00:00
fix(cocoa): real double buffering instead of fake glFlush swap
NSOpenGLPFADoubleBuffer was commented out, so DoubleBuffered:=True on the control was silently ignored and the context stayed single-buffered. LOpenGLSwapBuffers then only called glFlush(), leaving the front buffer on screen mid-draw: frames tore and views could show partially rendered content. Request the double-buffer pixel format when DoubleBuffered is set, and present through NSOpenGLContext.flushBuffer. Falls back to glFlush() when no context exists yet. Note: this is a correctness fix, not a performance one -- measured on an M1 Pro the app's CPU usage is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
dd9717b982
commit
3ebbbf5a18
+16
-6
@@ -140,13 +140,23 @@ begin
|
||||
end;
|
||||
|
||||
procedure LOpenGLSwapBuffers(Handle: HWND);
|
||||
//var
|
||||
// View: TCocoaOpenGLView; //TCocoaOpenGLView
|
||||
var
|
||||
View: TCocoaOpenGLView;
|
||||
Ctx: NSOpenGLContext;
|
||||
begin
|
||||
if Handle=0 then exit;
|
||||
View:=TCocoaOpenGLView(Handle);
|
||||
Ctx:=View.openGLContext;
|
||||
if Ctx=nil then
|
||||
begin
|
||||
// single-buffered fallback (no context yet)
|
||||
glFlush();
|
||||
// View:=TCocoaOpenGLView(Handle);
|
||||
// View.nsGL.flushBuffer;
|
||||
exit;
|
||||
end;
|
||||
// Present the back buffer. The old glFlush() left the single-buffered
|
||||
// front buffer on screen mid-draw, so frames tore and the view could show
|
||||
// partially rendered content.
|
||||
Ctx.flushBuffer;
|
||||
end;
|
||||
|
||||
function LOpenGLMakeCurrent(Handle: HWND): boolean;
|
||||
@@ -283,8 +293,8 @@ var
|
||||
begin
|
||||
AddUInt32(NSOpenGLPFAAuxBuffers); AddUInt32(AUXBuffers);
|
||||
end;
|
||||
//if DoubleBuffered then //requires fix for nsGL
|
||||
// AddUInt32(NSOpenGLPFADoubleBuffer); //this doen't work with Lazarus
|
||||
if DoubleBuffered then //present via real flushBuffer in LOpenGLSwapBuffers
|
||||
AddUInt32(NSOpenGLPFADoubleBuffer);
|
||||
AddUInt32(NSOpenGLPFAMaximumPolicy); //allows future changes to make attributes more demanding, e.g. add multisampling
|
||||
|
||||
AddUInt32(NSOpenGLPFANoRecovery); //see apple web page: "not generally useful" but might help with multisample
|
||||
|
||||
Reference in New Issue
Block a user