From 0709051effbcdeb2513df6f4d2c639ca56296bd4 Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 4 Sep 2013 00:22:36 +0000 Subject: [PATCH] OpenGLControl: Implement release context method. Issue #24925, patch from Anton Kavalenka git-svn-id: trunk@42582 - --- components/opengl/glcarbonaglcontext.pas | 6 ++++++ components/opengl/glgtkglxcontext.pas | 10 ++++++++++ components/opengl/glqtcontext.pas | 15 +++++++++++++++ components/opengl/glwin32wglcontext.pas | 6 ++++++ components/opengl/openglcontext.pas | 8 ++++++++ 5 files changed, 45 insertions(+) diff --git a/components/opengl/glcarbonaglcontext.pas b/components/opengl/glcarbonaglcontext.pas index 5b631ef498..27d5142851 100644 --- a/components/opengl/glcarbonaglcontext.pas +++ b/components/opengl/glcarbonaglcontext.pas @@ -24,6 +24,7 @@ uses procedure LOpenGLViewport(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; @@ -82,6 +83,11 @@ begin Result:=aglSetCurrentContext(AGLContext)<>0; end; +function LOpenGLReleaseContext(Handle: HWND): boolean; +begin + Result := aglSetCurrentContext(nil)<>GL_FALSE; +end; + procedure LOpenGLClip(Handle: HWND); var AGLContext: TAGLContext; diff --git a/components/opengl/glgtkglxcontext.pas b/components/opengl/glgtkglxcontext.pas index 2b7d019c46..bd38b1c324 100644 --- a/components/opengl/glgtkglxcontext.pas +++ b/components/opengl/glgtkglxcontext.pas @@ -157,6 +157,7 @@ function gdk_x11_get_default_screen:gint;cdecl;external; procedure LOpenGLViewport(Left, Top, Width, Height: integer); procedure LOpenGLSwapBuffers(Handle: HWND); function LOpenGLMakeCurrent(Handle: HWND): boolean; +function LOpenGLReleaseContext(Handle: HWND): boolean; function LOpenGLCreateContext(AWinControl: TWinControl; WSPrivate: TWSPrivateClass; SharedControl: TWinControl; DoubleBuffered, RGBA: boolean; @@ -907,6 +908,15 @@ begin Result:=gtk_gl_area_make_current(glarea); end; +function LOpenGLReleaseContext(Handle: HWND): boolean; +var pd:PDIsplay; +begin + Result := false; + pd := glXGetCurrentDisplay(); + if Assigned(pd) then + Result := glXMakeCurrent(pd, 0, nil); +end; + {$IFDEF LCLGtk2} function gtkglarea_size_allocateCB(Widget: PGtkWidget; Size: pGtkAllocation; Data: gPointer): GBoolean; cdecl; diff --git a/components/opengl/glqtcontext.pas b/components/opengl/glqtcontext.pas index f601c95a6d..c0a8e85f25 100644 --- a/components/opengl/glqtcontext.pas +++ b/components/opengl/glqtcontext.pas @@ -62,6 +62,7 @@ type procedure LOpenGLViewport(Left, Top, Width, Height: integer); procedure LOpenGLSwapBuffers(Handle: HWND); function LOpenGLMakeCurrent(Handle: HWND): boolean; +function LOpenGLReleaseContext(Handle: HWND): boolean; function LOpenGLCreateContext(AWinControl: TWinControl; WSPrivate: TWSPrivateClass; SharedControl: TWinControl; DoubleBuffered, RGBA: boolean; @@ -177,6 +178,20 @@ begin Widget.glxcontext)); end; +function LOpenGLReleaseContext(Handle: HWND): boolean; +var + Widget: TQtGLWidget; +begin + Result := false; + if Handle=0 then + RaiseGDBException('LOpenGLSwapBuffers Handle=0'); + + Widget:=TQtGLWidget(Handle); + Result := glXMakeCurrent(Widget.xdisplay, 0, nil); +end; + +end; + function LOpenGLCreateContext(AWinControl: TWinControl; WSPrivate: TWSPrivateClass; SharedControl: TWinControl; DoubleBuffered, RGBA: boolean; diff --git a/components/opengl/glwin32wglcontext.pas b/components/opengl/glwin32wglcontext.pas index 711e7f2e30..793ef73bcd 100644 --- a/components/opengl/glwin32wglcontext.pas +++ b/components/opengl/glwin32wglcontext.pas @@ -20,6 +20,7 @@ uses procedure LOpenGLViewport(Left, Top, Width, Height: integer); procedure LOpenGLSwapBuffers(Handle: HWND); function LOpenGLMakeCurrent(Handle: HWND): boolean; +function LOpenGLReleaseContext(Handle: HWND): boolean; function LOpenGLCreateContext(AWinControl: TWinControl; WSPrivate: TWSPrivateClass; SharedControl: TWinControl; DoubleBuffered, RGBA: boolean; @@ -246,6 +247,11 @@ begin Result:=wglMakeCurrent(Info^.DC,Info^.WGLContext); end; +function LOpenGLReleaseContext(Handle: HWND): boolean; +begin + Result:=wglMakeCurrent(0,0); +end; + function GlWindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam; LParam: Windows.LParam): LResult; stdcall; var diff --git a/components/opengl/openglcontext.pas b/components/opengl/openglcontext.pas index 646d609a80..99916c3150 100644 --- a/components/opengl/openglcontext.pas +++ b/components/opengl/openglcontext.pas @@ -148,6 +148,7 @@ type procedure DoOnPaint; virtual; procedure SwapBuffers; virtual; function MakeCurrent(SaveOldToStack: boolean = false): boolean; virtual; + function ReleaseContext: boolean; virtual; function RestoreOldOpenGLControl: boolean; function SharingControlCount: integer; property SharingControls[Index: integer]: TCustomOpenGLControl read GetSharingControls; @@ -548,6 +549,13 @@ begin end; end; +function TCustomOpenGLControl.ReleaseContext: boolean; +begin + Result:=false; + if not HandleAllocated then exit; + Result:=LOpenGLReleaseContext(Handle); +end; + function TCustomOpenGLControl.RestoreOldOpenGLControl: boolean; var RestoredControl: TCustomOpenGLControl;