openglcontrol gtk2: reduced debugging output, fixed crash on destroy

git-svn-id: trunk@12479 -
This commit is contained in:
mattias 2007-10-15 22:00:28 +00:00
parent 22f37ad0a2
commit b2748c46db
7 changed files with 43 additions and 47 deletions

View File

@ -1,13 +1,10 @@
object Form1: TForm1 object Form1: TForm1
Caption = 'Form1' Left = 419
ClientHeight = 300 Height = 300
ClientWidth = 400 Top = 287
OnCreate = FormCreate Width = 400
PixelsPerInch = 112
HorzScrollBar.Page = 399 HorzScrollBar.Page = 399
VertScrollBar.Page = 299 VertScrollBar.Page = 299
Left = 290 Caption = 'Form1'
Height = 300 OnCreate = FormCreate
Top = 163
Width = 400
end end

View File

@ -1,6 +1,7 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[ LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'Cl' 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#163#1#6'Height'#3','#1#3'Top'#3#31#1#5'Wi'
+'ientWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'#13'PixelsPerInch'#2'p'#18'H' +'dth'#3#144#1#18'HorzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3'+'#1#7
+'orzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3'+'#1#4'Left'#3'"'#1#6'H' +'Caption'#6#5'Form1'#8'OnCreate'#7#10'FormCreate'#0#0
+'eight'#3','#1#3'Top'#3#163#0#5'Width'#3#144#1#0#0
]); ]);

View File

@ -20,7 +20,7 @@ unit MainUnit;
interface interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
OpenGLContext, GL, GLU; OpenGLContext, GL, GLU;
type type
@ -31,6 +31,7 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure OpenGLControl1Paint(Sender: TObject); procedure OpenGLControl1Paint(Sender: TObject);
procedure OpenGLControl1Resize(Sender: TObject); procedure OpenGLControl1Resize(Sender: TObject);
procedure OnAppIdle(Sender: TObject; var Done: Boolean);
private private
public public
cube_rotationx: GLFloat; cube_rotationx: GLFloat;
@ -59,6 +60,8 @@ begin
OnResize:=@OpenGLControl1Resize; OnResize:=@OpenGLControl1Resize;
AutoResizeViewport:=true; AutoResizeViewport:=true;
end; end;
Application.AddOnIdleHandler(@OnAppIdle);
end; end;
procedure TForm1.OpenGLControl1Paint(Sender: TObject); procedure TForm1.OpenGLControl1Paint(Sender: TObject);
@ -136,7 +139,13 @@ procedure TForm1.OpenGLControl1Resize(Sender: TObject);
begin begin
if Sender=nil then ; if Sender=nil then ;
if OpenGLControl1.Height <= 0 then exit; if OpenGLControl1.Height <= 0 then exit;
end;
procedure TForm1.OnAppIdle(Sender: TObject; var Done: Boolean);
begin
Done:=false;
//DebugLn(['TForm1.OnAppIdle ']);
OpenGLControl1.Invalidate;
end; end;
initialization initialization

View File

@ -27,10 +27,10 @@
</RunParams> </RunParams>
<RequiredPackages Count="2"> <RequiredPackages Count="2">
<Item1> <Item1>
<PackageName Value="LazOpenGLContext"/> <PackageName Value="LCL"/>
</Item1> </Item1>
<Item2> <Item2>
<PackageName Value="LCL"/> <PackageName Value="LazOpenGLContext"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="2"> <Units Count="2">
@ -40,7 +40,7 @@
<UnitName Value="TestOpenGLContext1"/> <UnitName Value="TestOpenGLContext1"/>
<CursorPos X="1" Y="13"/> <CursorPos X="1" Y="13"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<UsageCount Value="142"/> <UsageCount Value="144"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="mainunit.pas"/> <Filename Value="mainunit.pas"/>
@ -48,10 +48,10 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ResourceFilename Value="mainunit.lrs"/> <ResourceFilename Value="mainunit.lrs"/>
<UnitName Value="MainUnit"/> <UnitName Value="MainUnit"/>
<CursorPos X="16" Y="26"/> <CursorPos X="19" Y="51"/>
<TopLine Value="11"/> <TopLine Value="37"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="142"/> <UsageCount Value="144"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit1> </Unit1>
</Units> </Units>

View File

@ -149,7 +149,7 @@ type
TGdkGLContextPrivate = record TGdkGLContextPrivate = record
xdisplay: PDisplay; xdisplay: PDisplay;
glxcontext: TGLXContext; glxcontext: TGLXContext;
ref_count: guint; ref_count: gint;
end; end;
PGdkGLContextPrivate = ^TGdkGLContextPrivate; PGdkGLContextPrivate = ^TGdkGLContextPrivate;
@ -272,7 +272,6 @@ begin
dpy := GetDefaultXDisplay; dpy := GetDefaultXDisplay;
{$IFDEF Lclgtk2} {$IFDEF Lclgtk2}
DebugLn('get_xvisualinfo dpy=',XDisplayAsString(dpy)); DebugLn('get_xvisualinfo dpy=',XDisplayAsString(dpy));
DebugLn('get_xvisualinfo visual=',GdkVisualAsString(Visual)); DebugLn('get_xvisualinfo visual=',GdkVisualAsString(Visual));
RaiseGDBException('not implemented for gtk2'); RaiseGDBException('not implemented for gtk2');
{$ENDIF} {$ENDIF}
@ -347,13 +346,11 @@ begin
RaiseGDBException(''); RaiseGDBException('');
{$ENDIF} {$ENDIF}
//writeln('gdk_gl_choose_visual A ');
if attrList=nil then begin if attrList=nil then begin
Result:=nil; Result:=nil;
exit; exit;
end; end;
//writeln('gdk_gl_choose_visual B ');
dpy := GetDefaultXDisplay; dpy := GetDefaultXDisplay;
vi := glXChooseVisual(dpy,DefaultScreen(dpy), attrlist); vi := glXChooseVisual(dpy,DefaultScreen(dpy), attrlist);
if (vi=nil) then begin if (vi=nil) then begin
@ -361,7 +358,6 @@ begin
exit; exit;
end; end;
//writeln('gdk_gl_choose_visual C ');
visual := gdkx_visual_get(vi^.visualid); visual := gdkx_visual_get(vi^.visualid);
XFree(vi); XFree(vi);
Result:=visual; Result:=visual;
@ -406,9 +402,7 @@ begin
dpy := GetDefaultXDisplay; dpy := GetDefaultXDisplay;
{$IFDEF lclgtk2} {$IFDEF lclgtk2}
DebugLn(['gdk_gl_context_share_new AAA1']);
vi:=glXChooseVisual(dpy, DefaultScreen(dpy), @attrList[0]); vi:=glXChooseVisual(dpy, DefaultScreen(dpy), @attrList[0]);
DebugLn(['gdk_gl_context_share_new AAA2']);
{$ELSE} {$ELSE}
if visual=nil then exit; if visual=nil then exit;
vi := get_xvisualinfo(visual); vi := get_xvisualinfo(visual);
@ -420,7 +414,6 @@ begin
direct=1) direct=1)
else else
glxcontext := glXCreateContext(dpy, vi, nil, direct=1); glxcontext := glXCreateContext(dpy, vi, nil, direct=1);
DebugLn(['gdk_gl_context_share_new AAA3']);
XFree(vi); XFree(vi);
if (glxcontext = nil) then exit; if (glxcontext = nil) then exit;
@ -458,6 +451,7 @@ begin
if context=nil then exit; if context=nil then exit;
PrivateContext := PGdkGLContextPrivate(context); PrivateContext := PGdkGLContextPrivate(context);
inc(PrivateContext^.ref_count); inc(PrivateContext^.ref_count);
//DebugLn(['gdk_gl_context_ref ref_count=',PrivateContext^.ref_count]);
Result:=context; Result:=context;
end; end;
@ -469,13 +463,15 @@ begin
PrivateContext:=PGdkGLContextPrivate(context); PrivateContext:=PGdkGLContextPrivate(context);
if (PrivateContext^.ref_count > 1) then dec(PrivateContext^.ref_count);
dec(PrivateContext^.ref_count) if (PrivateContext^.ref_count = 0) then begin
else begin //DebugLn(['gdk_gl_context_unref START ref_count=',PrivateContext^.ref_count]);
if (PrivateContext^.glxcontext = glXGetCurrentContext()) then if (PrivateContext^.glxcontext = glXGetCurrentContext()) then
glXMakeCurrent(PrivateContext^.xdisplay, None, nil); glXMakeCurrent(PrivateContext^.xdisplay, None, nil);
glXDestroyContext(PrivateContext^.xdisplay, PrivateContext^.glxcontext); glXDestroyContext(PrivateContext^.xdisplay, PrivateContext^.glxcontext);
PrivateContext^.glxcontext:=nil;
g_free(PrivateContext); g_free(PrivateContext);
//DebugLn(['gdk_gl_context_unref END']);
end; end;
end; end;
@ -531,13 +527,13 @@ procedure gtk_gl_area_init(
); cdecl; ); cdecl;
begin begin
if theClass=nil then ; if theClass=nil then ;
DebugLn(['gtk_gl_area_init START']); //DebugLn(['gtk_gl_area_init START']);
PGtkGLArea(gl_area)^.glcontext:=nil; PGtkGLArea(gl_area)^.glcontext:=nil;
{$IFDEF LclGtk2} {$IFDEF LclGtk2}
gtk_widget_set_double_buffered(PGtkWidget(gl_area),gdkFALSE); gtk_widget_set_double_buffered(PGtkWidget(gl_area),gdkFALSE);
GTK_WIDGET_UNSET_FLAGS(PGtkWidget(gl_area),GTK_NO_WINDOW); GTK_WIDGET_UNSET_FLAGS(PGtkWidget(gl_area),GTK_NO_WINDOW);
{$ENDIF} {$ENDIF}
DebugLn(['gtk_gl_area_init END']); //DebugLn(['gtk_gl_area_init END']);
end; end;
function GTK_TYPE_GL_AREA: TGtkType; function GTK_TYPE_GL_AREA: TGtkType;
@ -621,12 +617,10 @@ var
gl_area: PGtkGLArea; gl_area: PGtkGLArea;
begin begin
Result:=nil; Result:=nil;
DebugLn(['gtk_gl_area_share_new START']); //DebugLn(['gtk_gl_area_share_new START']);
//writeln('gtk_gl_area_share_new A ');
if (share<>nil) and (not GTK_IS_GL_AREA(share)) then if (share<>nil) and (not GTK_IS_GL_AREA(share)) then
exit; exit;
{$IFNDEF MSWindows} {$IFNDEF MSWindows}
//writeln('gtk_gl_area_share_new B ');
{$IFDEF lclgtk2} {$IFDEF lclgtk2}
visual := nil; visual := nil;
{$ELSE} {$ELSE}
@ -635,14 +629,10 @@ begin
{$ENDIF} {$ENDIF}
{$ENDIF non MSWindows} {$ENDIF non MSWindows}
//writeln('gtk_gl_area_share_new C ');
DebugLn(['gtk_gl_area_share_new BBB1']);
sharelist := nil; sharelist := nil;
if share<>nil then sharelist:=share^.glcontext; if share<>nil then sharelist:=share^.glcontext;
glcontext := gdk_gl_context_share_new(visual, sharelist, 1, attrlist); glcontext := gdk_gl_context_share_new(visual, sharelist, 1, attrlist);
if (glcontext = nil) then exit; if (glcontext = nil) then exit;
DebugLn(['gtk_gl_area_share_new BBB2']);
//writeln('gtk_gl_area_share_new D ');
{$IFNDEF MSWindows} {$IFNDEF MSWindows}
if visual<>nil then begin if visual<>nil then begin
@ -654,8 +644,6 @@ begin
gl_area := gtk_type_new (gtk_gl_area_get_type); gl_area := gtk_type_new (gtk_gl_area_get_type);
gl_area^.glcontext := glcontext; gl_area^.glcontext := glcontext;
//writeln('gtk_gl_area_share_new E ',gl_area<>nil);
DebugLn(['gtk_gl_area_share_new BBB3']);
{$IFNDEF MSWindows} {$IFNDEF MSWindows}
if visual<>nil then begin if visual<>nil then begin
@ -674,9 +662,9 @@ begin
if not GTK_IS_GL_AREA(glarea) then exit; if not GTK_IS_GL_AREA(glarea) then exit;
if not GTK_WIDGET_REALIZED(PGtkWidget(glarea)) then exit; if not GTK_WIDGET_REALIZED(PGtkWidget(glarea)) then exit;
DebugLn(['gtk_gl_area_make_current START']); //DebugLn(['gtk_gl_area_make_current START']);
Result:=gdk_gl_make_current(PGtkWidget(glarea)^.window, glarea^.glcontext); Result:=gdk_gl_make_current(PGtkWidget(glarea)^.window, glarea^.glcontext);
DebugLn(['gtk_gl_area_make_current END']); //DebugLn(['gtk_gl_area_make_current END']);
end; end;
function gtk_gl_area_begingl(glarea: PGtkGLArea): boolean; function gtk_gl_area_begingl(glarea: PGtkGLArea): boolean;
@ -737,14 +725,14 @@ begin
AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA); AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA);
try try
if SharedControl<>nil then begin if SharedControl<>nil then begin
SharedArea:=PGtkGLArea(SharedControl.Handle); SharedArea:=PGtkGLArea(PtrUInt(SharedControl.Handle));
if not GTK_IS_GL_AREA(SharedArea) then if not GTK_IS_GL_AREA(SharedArea) then
RaiseGDBException('LOpenGLCreateContext'); RaiseGDBException('LOpenGLCreateContext');
NewWidget:=gtk_gl_area_share_new(AttrList,SharedArea); NewWidget:=gtk_gl_area_share_new(AttrList,SharedArea);
end else begin end else begin
NewWidget:=gtk_gl_area_new(AttrList); NewWidget:=gtk_gl_area_new(AttrList);
end; end;
Result:=HWND(NewWidget); Result:=HWND(Pointer(NewWidget));
PGtkobject(NewWidget)^.flags:=PGtkobject(NewWidget)^.flags or GTK_CAN_FOCUS; PGtkobject(NewWidget)^.flags:=PGtkobject(NewWidget)^.flags or GTK_CAN_FOCUS;
{$IFDEF LCLGtk} {$IFDEF LCLGtk}
TGTKWidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget); TGTKWidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget);

View File

@ -2,7 +2,7 @@
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<PathDelim Value="/"/> <PathDelim Value="/"/>
<Version Value="5"/> <Version Value="6"/>
<General> <General>
<Flags> <Flags>
<MainUnitHasCreateFormStatements Value="False"/> <MainUnitHasCreateFormStatements Value="False"/>

View File

@ -62,6 +62,7 @@ begin
FState:=NewState; FState:=NewState;
//debugln('TCustomCheckBox.DoChange CHANGED ',dbgsname(Self),' ',dbgs(ord(FState))); //debugln('TCustomCheckBox.DoChange CHANGED ',dbgsname(Self),' ',dbgs(ord(FState)));
inherited Click; // emulate delphi OnClick behaviour inherited Click; // emulate delphi OnClick behaviour
inherited CLick;
end; end;
procedure TCustomCheckBox.Click; procedure TCustomCheckBox.Click;