mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 09:59:23 +02:00
opengl: Patch from bug #32026, add possibility to render at design time
git-svn-id: trunk@55392 -
This commit is contained in:
parent
0aa859bd87
commit
85a49e41f2
@ -103,7 +103,7 @@ type
|
|||||||
TOpenGlCtrlMakeCurrentEvent = procedure(Sender: TObject;
|
TOpenGlCtrlMakeCurrentEvent = procedure(Sender: TObject;
|
||||||
var Allow: boolean) of object;
|
var Allow: boolean) of object;
|
||||||
|
|
||||||
TOpenGLControlOption = (ocoMacRetinaMode);
|
TOpenGLControlOption = (ocoMacRetinaMode, ocoRenderAtDesignTime);
|
||||||
TOpenGLControlOptions = set of TOpenGLControlOption;
|
TOpenGLControlOptions = set of TOpenGLControlOption;
|
||||||
|
|
||||||
{ TCustomOpenGLControl }
|
{ TCustomOpenGLControl }
|
||||||
@ -160,6 +160,7 @@ type
|
|||||||
procedure SetStencilBits(const AValue: Cardinal);
|
procedure SetStencilBits(const AValue: Cardinal);
|
||||||
procedure SetAUXBuffers(const AValue: Cardinal);
|
procedure SetAUXBuffers(const AValue: Cardinal);
|
||||||
procedure SetSharedControl(const AValue: TCustomOpenGLControl);
|
procedure SetSharedControl(const AValue: TCustomOpenGLControl);
|
||||||
|
function IsOpenGLRenderAllowed: boolean;
|
||||||
protected
|
protected
|
||||||
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
|
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
|
||||||
procedure WMSize(var Message: TLMSize); message LM_SIZE;
|
procedure WMSize(var Message: TLMSize); message LM_SIZE;
|
||||||
@ -339,9 +340,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomOpenGLControl.SetOptions(AValue: TOpenGLControlOptions);
|
procedure TCustomOpenGLControl.SetOptions(AValue: TOpenGLControlOptions);
|
||||||
|
var
|
||||||
|
RemovedRenderAtDesignTime: boolean;
|
||||||
begin
|
begin
|
||||||
if FOptions=AValue then Exit;
|
if FOptions=AValue then Exit;
|
||||||
|
|
||||||
|
RemovedRenderAtDesignTime:=
|
||||||
|
(ocoRenderAtDesignTime in FOptions) and
|
||||||
|
(not (ocoRenderAtDesignTime in AValue));
|
||||||
|
|
||||||
FOptions:=AValue;
|
FOptions:=AValue;
|
||||||
|
|
||||||
|
{ if you remove the flag ocoRenderAtDesignTime at design-time,
|
||||||
|
we need to destroy the handle. The call to OpenGLAttributesChanged
|
||||||
|
would not do this, so do it explicitly by calling ReCreateWnd
|
||||||
|
(ReCreateWnd will destroy handle, and not create new one,
|
||||||
|
since IsOpenGLRenderAllowed = false). }
|
||||||
|
if (csDesigning in ComponentState) and
|
||||||
|
RemovedRenderAtDesignTime and
|
||||||
|
HandleAllocated then
|
||||||
|
ReCreateWnd(Self);
|
||||||
|
|
||||||
OpenGLAttributesChanged();
|
OpenGLAttributesChanged();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -433,16 +452,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
// recreate handle if needed
|
// recreate handle if needed
|
||||||
if HandleAllocated and (not (csDesigning in ComponentState)) then
|
if HandleAllocated and IsOpenGLRenderAllowed then
|
||||||
ReCreateWnd(Self);
|
ReCreateWnd(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ OpenGL rendering allowed, because not in design-mode or because we
|
||||||
|
should render even in design-mode. }
|
||||||
|
function TCustomOpenGLControl.IsOpenGLRenderAllowed: boolean;
|
||||||
|
begin
|
||||||
|
Result := (not (csDesigning in ComponentState)) or
|
||||||
|
(ocoRenderAtDesignTime in Options);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomOpenGLControl.WMPaint(var Message: TLMPaint);
|
procedure TCustomOpenGLControl.WMPaint(var Message: TLMPaint);
|
||||||
begin
|
begin
|
||||||
Include(FControlState, csCustomPaint);
|
Include(FControlState, csCustomPaint);
|
||||||
inherited WMPaint(Message);
|
inherited WMPaint(Message);
|
||||||
//debugln('TCustomGTKGLAreaControl.WMPaint A ',dbgsName(Self),' ',dbgsName(FCanvas));
|
//debugln('TCustomGTKGLAreaControl.WMPaint A ',dbgsName(Self),' ',dbgsName(FCanvas));
|
||||||
if (csDesigning in ComponentState) and (FCanvas<>nil) then begin
|
if (not IsOpenGLRenderAllowed) and (FCanvas<>nil) then begin
|
||||||
with FCanvas do begin
|
with FCanvas do begin
|
||||||
if Message.DC <> 0 then
|
if Message.DC <> 0 then
|
||||||
Handle := Message.DC;
|
Handle := Message.DC;
|
||||||
@ -482,8 +509,8 @@ end;
|
|||||||
|
|
||||||
procedure TCustomOpenGLControl.OpenGLAttributesChanged;
|
procedure TCustomOpenGLControl.OpenGLAttributesChanged;
|
||||||
begin
|
begin
|
||||||
if HandleAllocated
|
if HandleAllocated and
|
||||||
and ([csLoading,csDesigning,csDestroying]*ComponentState=[]) then
|
( ([csLoading,csDestroying]*ComponentState=[]) and IsOpenGLRenderAllowed ) then
|
||||||
RecreateWnd(Self);
|
RecreateWnd(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -508,7 +535,7 @@ begin
|
|||||||
FMultiSampling:=1;
|
FMultiSampling:=1;
|
||||||
FDepthBits:=DefaultDepthBits;
|
FDepthBits:=DefaultDepthBits;
|
||||||
ControlStyle:=ControlStyle-[csSetCaption];
|
ControlStyle:=ControlStyle-[csSetCaption];
|
||||||
if (csDesigning in ComponentState) then begin
|
if not IsOpenGLRenderAllowed then begin
|
||||||
FCanvas := TControlCanvas.Create;
|
FCanvas := TControlCanvas.Create;
|
||||||
TControlCanvas(FCanvas).Control := Self;
|
TControlCanvas(FCanvas).Control := Self;
|
||||||
end else
|
end else
|
||||||
@ -538,7 +565,7 @@ procedure TCustomOpenGLControl.Paint;
|
|||||||
begin
|
begin
|
||||||
if IsVisible and HandleAllocated then begin
|
if IsVisible and HandleAllocated then begin
|
||||||
UpdateFrameTimeDiff;
|
UpdateFrameTimeDiff;
|
||||||
if ([csDesigning,csDestroying]*ComponentState=[]) then begin
|
if IsOpenGLRenderAllowed and ([csDestroying]*ComponentState=[]) then begin
|
||||||
if not MakeCurrent then exit;
|
if not MakeCurrent then exit;
|
||||||
if AutoResizeViewport then
|
if AutoResizeViewport then
|
||||||
LOpenGLViewport(Handle,0,0,Width,Height);
|
LOpenGLViewport(Handle,0,0,Width,Height);
|
||||||
@ -551,7 +578,8 @@ end;
|
|||||||
procedure TCustomOpenGLControl.RealizeBounds;
|
procedure TCustomOpenGLControl.RealizeBounds;
|
||||||
begin
|
begin
|
||||||
if IsVisible and HandleAllocated
|
if IsVisible and HandleAllocated
|
||||||
and ([csDesigning,csDestroying]*ComponentState=[])
|
and IsOpenGLRenderAllowed
|
||||||
|
and ([csDestroying]*ComponentState=[])
|
||||||
and AutoResizeViewport then begin
|
and AutoResizeViewport then begin
|
||||||
if MakeCurrent then
|
if MakeCurrent then
|
||||||
LOpenGLViewport(Handle,0,0,Width,Height);
|
LOpenGLViewport(Handle,0,0,Width,Height);
|
||||||
@ -573,7 +601,7 @@ function TCustomOpenGLControl.MakeCurrent(SaveOldToStack: boolean): boolean;
|
|||||||
var
|
var
|
||||||
Allowed: Boolean;
|
Allowed: Boolean;
|
||||||
begin
|
begin
|
||||||
if csDesigning in ComponentState then exit(false);
|
if not IsOpenGLRenderAllowed then exit(false);
|
||||||
if Assigned(FOnMakeCurrent) then begin
|
if Assigned(FOnMakeCurrent) then begin
|
||||||
Allowed:=true;
|
Allowed:=true;
|
||||||
OnMakeCurrent(Self,Allowed);
|
OnMakeCurrent(Self,Allowed);
|
||||||
@ -642,14 +670,14 @@ var
|
|||||||
OpenGlControl: TCustomOpenGLControl;
|
OpenGlControl: TCustomOpenGLControl;
|
||||||
AttrControl: TCustomOpenGLControl;
|
AttrControl: TCustomOpenGLControl;
|
||||||
begin
|
begin
|
||||||
if csDesigning in AWinControl.ComponentState then
|
OpenGlControl:=AWinControl as TCustomOpenGLControl;
|
||||||
|
if not OpenGlControl.IsOpenGLRenderAllowed then
|
||||||
begin
|
begin
|
||||||
// do not use "inherited CreateHandle", because the LCL changes the hierarchy at run time
|
// do not use "inherited CreateHandle", because the LCL changes the hierarchy at run time
|
||||||
Result:=TWSWinControlClass(ClassParent).CreateHandle(AWinControl,AParams);
|
Result:=TWSWinControlClass(ClassParent).CreateHandle(AWinControl,AParams);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
OpenGlControl:=AWinControl as TCustomOpenGLControl;
|
|
||||||
if OpenGlControl.SharedControl<>nil then
|
if OpenGlControl.SharedControl<>nil then
|
||||||
AttrControl:=OpenGlControl.SharedControl
|
AttrControl:=OpenGlControl.SharedControl
|
||||||
else
|
else
|
||||||
@ -695,4 +723,3 @@ initialization
|
|||||||
RegisterWSComponent(TCustomOpenGLControl,TWSOpenGLControl);
|
RegisterWSComponent(TCustomOpenGLControl,TWSOpenGLControl);
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user