View Issue Details

IDProjectCategoryView StatusLast Update
0027066PatchesPackagespublic2014-12-04 14:30
ReporterCedric Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformlinuxOSkubuntu trusty 
Summary0027066: compiling lazopenGlContext package with QT
DescriptionThe lazopenglcontext package in the trunk not compile with the QT widget set without this patch.
Additional InformationOnce the patch has been applied, it is possible to install the lazopenglcontext package in the IDE targetting QT. The OpenGLControl_Demo work in QT with the next patch. (with "OpenGLControl1.Invalidate" the image blinking)


Index: exampleform.pp
===================================================================
--- exampleform.pp (révision 46910)
+++ exampleform.pp (copie de travail)
@@ -402,8 +402,8 @@
 
 procedure TExampleForm.IdleFunc(Sender: TObject; var Done: Boolean);
 begin
- OpenGLControl1.Invalidate;
- //OpenGLControl1Paint(Self);
+ //OpenGLControl1.Invalidate;
+ OpenGLControl1Paint(Self);
   Done:=false; // tell lcl to handle messages and return immediatly
 end;
TagsNo tags attached.
Fixed in Revision46934
LazTarget-
WidgetsetQT
Attached Files

Relationships

related to 0015589 resolvedMattias Gaertner Lazarus TOpenGLControl doesn't support QT 
related to 0027065 closedMattias Gaertner Lazarus compiling lazopenGlContext package with QT 

Activities

Cedric

2014-11-21 11:17

reporter  

patch.diff (8,114 bytes)   
Index: glqtcontext.pas
===================================================================
--- glqtcontext.pas	(révision 46910)
+++ glqtcontext.pas	(copie de travail)
@@ -18,7 +18,7 @@
 uses
   Classes, SysUtils, Controls, LCLProc, LCLType, X, XUtil, XLib, gl,
   InterfaceBase,
-  WSLCLClasses,
+  WSLCLClasses,glx,
   // Bindings
   qt4,
   qtwidgets, qtobjects, qtproc, qtint,
@@ -64,43 +64,20 @@
 function LOpenGLMakeCurrent(Handle: HWND): boolean;
 function LOpenGLReleaseContext(Handle: HWND): boolean;
 function LOpenGLCreateContext(AWinControl: TWinControl;
-             WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
-             DoubleBuffered, RGBA: boolean;
-             const MultiSampling, AlphaBits, DepthBits, StencilBits: Cardinal;
-             const AParams: TCreateParams): HWND;
+                          WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
+                          DoubleBuffered, RGBA: boolean;
+                          const RedBits, GreenBits, BlueBits, MajorVersion, MinorVersion,
+                          MultiSampling, AlphaBits, DepthBits, StencilBits, AUXBuffers: Cardinal;
+                          const AParams: TCreateParams): HWND;
+
 procedure LOpenGLDestroyContextInfo(AWinControl: TWinControl);
-function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
-                                     RGBA: boolean): PInteger;
+function CreateOpenGLContextAttrList(DoubleBuffered: boolean; RGBA: boolean;
+             const RedBits, GreenBits, BlueBits, AlphaBits, DepthBits,
+             StencilBits,  AUXBuffers: Cardinal): PInteger;
 
+
 implementation
 
-type
-  //PGLXPixmap = ^GLXPixmap;
-  GLXPixmap = TXID;
-
-  //PGLXDrawable = ^GLXDrawable;
-  GLXDrawable = TXID;
-
-{ GLX 1.0 functions. }
-
-function glXChooseVisual(dpy:PDisplay; screen:longint; attrib_list:Plongint):PXVisualInfo;cdecl;external;
-procedure glXCopyContext(dpy:PDisplay; src:TGLXContext; dst:TGLXContext; mask: cardinal);cdecl;external;
-function glXCreateContext(dpy:PDisplay; vis:PXVisualInfo; share_list:TGLXContext; direct:TBool):TGLXContext;cdecl;external;
-function glXCreateGLXPixmap(dpy:PDisplay; vis:PXVisualInfo; pixmap:TPixmap):GLXPixmap;cdecl;external;
-procedure glXDestroyContext(dpy:PDisplay; ctx:TGLXContext);cdecl;external;
-procedure glXDestroyGLXPixmap(dpy:PDisplay; pix:GLXPixmap);cdecl;external;
-function glXGetConfig(dpy:PDisplay; vis:PXVisualInfo; attrib:longint; value:Plongint):longint;cdecl;external;
-function glXGetCurrentContext:TGLXContext;cdecl;external;
-function glXGetCurrentDrawable:GLXDrawable;cdecl;external;
-function glXIsDirect(dpy:PDisplay; ctx:TGLXContext):TBool;cdecl;external;
-function glXMakeCurrent(dpy:PDisplay; drawable:GLXDrawable; ctx:TGLXContext):TBool;cdecl;external;
-function glXQueryExtension(dpy:PDisplay; error_base:Plongint; event_base:Plongint):TBool;cdecl;external;
-function glXQueryVersion(dpy:PDisplay; major:Plongint; minor:Plongint):TBool;cdecl;external;
-procedure glXSwapBuffers(dpy:PDisplay; drawable:GLXDrawable);cdecl;external;
-procedure glXUseXFont(font:TFont; first:longint; count:longint; list_base:longint);cdecl;external;
-procedure glXWaitGL;cdecl;external;
-procedure glXWaitX;cdecl;external;
-
 function XVisualAsString(AVisual: PVisual): string;
 begin
   if AVisual=nil then begin
@@ -143,7 +120,7 @@
 
 function TQtGLWidget.GetGLXDrawable: GLXDrawable;
 begin
-  Result:=0; {$ERROR ToDo: get GLXDrawable}
+  result:=QWidget_winID(Widget);
 end;
 
 procedure LOpenGLViewport(Left, Top, Width, Height: integer);
@@ -173,9 +150,9 @@
   Result:=false;
 
   Widget:=TQtGLWidget(Handle);
-  Result:=boolean(glXMakeCurrent(Widget.xdisplay,
+  Result:=glXMakeCurrent(Widget.xdisplay,
                                  Widget.GetGLXDrawable,
-                                 Widget.glxcontext));
+                                 Widget.glxcontext);
 end;
 
 function LOpenGLReleaseContext(Handle: HWND): boolean;
@@ -190,26 +167,33 @@
   Result := glXMakeCurrent(Widget.xdisplay, 0, nil);
 end;
 
-end;
 
-function LOpenGLCreateContext(AWinControl: TWinControl;
+{function LOpenGLCreateContext(AWinControl: TWinControl;
   WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
   DoubleBuffered, RGBA: boolean;
   const MultiSampling, AlphaBits, DepthBits, StencilBits: Cardinal;
-  const AParams: TCreateParams): HWND;
+  const AParams: TCreateParams): HWND;}
+function LOpenGLCreateContext(AWinControl: TWinControl;
+                          WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
+                          DoubleBuffered, RGBA: boolean;
+                          const RedBits, GreenBits, BlueBits, MajorVersion, MinorVersion,
+                          MultiSampling, AlphaBits, DepthBits, StencilBits, AUXBuffers: Cardinal;
+                          const AParams: TCreateParams): HWND;
+
 var
   AttrList: PInteger;
   NewQtWidget: TQtGLWidget;
-  direct: TBool;
+  direct: boolean;
 begin
   if WSPrivate=nil then ;
-  AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA);
+  AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA,RedBits,GreenBits,BlueBits,AlphaBits,DepthBits,StencilBits,AUXBuffers);
   try
     NewQtWidget:=TQtGLWidget.Create(AWinControl,AParams);
+    NewQtWidget.HasPaint:=true;
     NewQtWidget.xdisplay := QX11Info_display;
     NewQtWidget.visual:=glXChooseVisual(NewQtWidget.xdisplay,
       DefaultScreen(NewQtWidget.xdisplay), @attrList[0]);
-    direct:=0;
+    direct:=false;
     NewQtWidget.glxcontext := glXCreateContext(NewQtWidget.xdisplay,
                                                NewQtWidget.visual, nil, direct);
     NewQtWidget.ref_count := 1;
@@ -228,10 +212,12 @@
   // nothing to do
 end;
 
-function CreateOpenGLContextAttrList(DoubleBuffered: boolean; RGBA: boolean
-  ): PInteger;
+function CreateOpenGLContextAttrList(DoubleBuffered: boolean; RGBA: boolean;
+  const RedBits, GreenBits, BlueBits, AlphaBits, DepthBits, StencilBits,
+  AUXBuffers: Cardinal): PInteger;
 var
   p: integer;
+  UseFBConfig: boolean;
 
   procedure Add(i: integer);
   begin
@@ -242,26 +228,56 @@
 
   procedure CreateList;
   begin
+    p:=0;
+    if UseFBConfig then begin
+      Add(GLX_X_RENDERABLE); Add(1);
+      Add(GLX_X_VISUAL_TYPE); Add(GLX_TRUE_COLOR);
+    end;
     if DoubleBuffered then
-      Add(QT_GL_DOUBLEBUFFER);
+    begin
+      if UseFBConfig then
+        begin Add(GLX_DOUBLEBUFFER); Add(1); end else
+        Add(GLX_DOUBLEBUFFER);
+    end;
     if RGBA then
-      Add(QT_GL_RGBA);
-    Add(QT_GL_RED_SIZE);  Add(1);
-    Add(QT_GL_GREEN_SIZE);  Add(1);
-    Add(QT_GL_BLUE_SIZE);  Add(1);
-    Add(QT_GL_DEPTH_SIZE);  Add(1);
-    Add(QT_GL_STENCIL_SIZE); Add(1);
-    Add(QT_GL_None);
+    begin
+      if not UseFBConfig then Add(GLX_RGBA);
+      { For UseFBConfig, glXChooseFBConfig already defaults to RGBA }
+    end;
+    Add(GLX_RED_SIZE);  Add(RedBits);
+    Add(GLX_GREEN_SIZE);  Add(GreenBits);
+    Add(GLX_BLUE_SIZE);  Add(BlueBits);
+    if AlphaBits>0 then
+    begin
+      Add(GLX_ALPHA_SIZE);  Add(AlphaBits);
+    end;
+    if DepthBits>0 then
+    begin
+      Add(GLX_DEPTH_SIZE);  Add(DepthBits);
+    end;
+    if StencilBits>0 then
+    begin
+      Add(GLX_STENCIL_SIZE);  Add(StencilBits);
+    end;
+    if AUXBuffers>0 then
+    begin
+      Add(GLX_AUX_BUFFERS);  Add(AUXBuffers);
+    end;
+
+    Add(0); { 0 = X.None (be careful: GLX_NONE is something different) }
   end;
 
 begin
+  {$IFDEF VerboseMultiSampling}
+  debugln(['CreateOpenGLContextAttrList MultiSampling=',MultiSampling]);
+  {$ENDIF}
+  UseFBConfig := false; //GLX_version_1_3(GetDefaultXDisplay);
   Result:=nil;
-  p:=0;
   CreateList;
   GetMem(Result,SizeOf(integer)*p);
-  p:=0;
   CreateList;
 end;
 
+
 end.
 
Index: openglcontext.pas
===================================================================
--- openglcontext.pas	(révision 46910)
+++ openglcontext.pas	(copie de travail)
@@ -46,6 +46,8 @@
 {$ENDIF}
 {$IFDEF LCLQT}
   {$DEFINE UseQTGLX}
+  {$DEFINE UsesModernGL}
+  {$DEFINE HasRGBBits}
   {$DEFINE OpenGLTargetDefined}
 {$ENDIF}
 {$IFNDEF OpenGLTargetDefined}
patch.diff (8,114 bytes)   

Mattias Gaertner

2014-11-21 13:15

manager   ~0079247

Thanks. Applied.

About the example:
If Invalidate does not work, it means we cannot paint during normal paint message.
Painting outside the paint message is a hack. But at least it works, so I will document it.

Andrey Zubarev

2014-11-21 23:58

reporter   ~0079255

If use this path - hack inside glqtcontext, but not in programs and examples

Index: .
===================================================================
--- . (revision 46937)
+++ . (working copy)
@@ -189,6 +189,11 @@
   AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA,RedBits,GreenBits,BlueBits,AlphaBits,DepthBits,StencilBits,AUXBuffers);
   try
     NewQtWidget:=TQtGLWidget.Create(AWinControl,AParams);
+
+ NewQtWidget.setAttribute(QtWA_PaintOnScreen);
+ NewQtWidget.setAttribute(QtWA_NoSystemBackground);
+ NewQtWidget.setAttribute(QtWA_OpaquePaintEvent);
+
     NewQtWidget.HasPaint:=true;
     NewQtWidget.xdisplay := QX11Info_display;
     NewQtWidget.visual:=glXChooseVisual(NewQtWidget.xdisplay,

Andrey Zubarev

2014-11-22 00:00

reporter   ~0079256

related http://bugs.freepascal.org/view.php?id=15589

Mattias Gaertner

2014-11-22 00:14

manager   ~0079258

Thanks. Works! :)

Issue History

Date Modified Username Field Change
2014-11-21 11:17 Cedric New Issue
2014-11-21 11:17 Cedric File Added: patch.diff
2014-11-21 13:15 Mattias Gaertner Fixed in Revision => 46934
2014-11-21 13:15 Mattias Gaertner LazTarget => -
2014-11-21 13:15 Mattias Gaertner Note Added: 0079247
2014-11-21 13:15 Mattias Gaertner Status new => resolved
2014-11-21 13:15 Mattias Gaertner Resolution open => fixed
2014-11-21 13:15 Mattias Gaertner Assigned To => Mattias Gaertner
2014-11-21 13:25 Mattias Gaertner Relationship added related to 0027065
2014-11-21 23:58 Andrey Zubarev Note Added: 0079255
2014-11-22 00:00 Andrey Zubarev Note Added: 0079256
2014-11-22 00:14 Mattias Gaertner Note Added: 0079258
2014-11-22 10:16 Juha Manninen Relationship added related to 0015589
2014-12-04 14:30 Cedric Status resolved => closed