replaced OpenGLContext AttrList with properties

git-svn-id: trunk@8516 -
This commit is contained in:
mattias 2006-01-14 16:29:40 +00:00
parent 4383348bda
commit 3ccf12c61c
5 changed files with 148 additions and 58 deletions

View File

@ -29,8 +29,10 @@ procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass;
SharedControl: TWinControl; AttrList: PInteger): HWND;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, RGBA: boolean): HWND;
function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
RGBA: boolean): PInteger;
const
DefaultOpenGLContextInitAttrList: array [0..14] of LongInt = (
@ -88,7 +90,7 @@ end;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
AttrList: PInteger): HWND;
DoubleBuffered, RGBA: boolean): HWND;
var
disp: GDHandle;
aglPixFmt: TAGLPixelFormat;
@ -99,6 +101,7 @@ var
R: FPCMacOSAll.Rect;
Info: PWidgetInfo;
ParentWindow: WindowPtr;
AttrList: PInteger;
begin
if AWinControl.Parent=nil then
RaiseGDBException('GLCarbonAGLContext.LOpenGLCreateContext no parent');
@ -121,7 +124,9 @@ begin
// create the AGL context
disp := GetMainDevice ();
AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA);
aglPixFmt := aglChoosePixelFormat (@disp, 1, AttrList);
System.FreeMem(AttrList);
aglContext := aglCreateContext (aglPixFmt, NIL);
aglDestroyPixelFormat(aglPixFmt);
@ -135,6 +140,44 @@ begin
CreateAGLControlInfo(Control,AGLContext);
end;
function CreateOpenGLContextAttrList(DoubleBuffered: boolean; RGBA: boolean
): PInteger;
var
p: integer;
procedure Add(i: integer);
begin
if Result<>nil then
Result[p]:=i;
inc(p);
end;
procedure CreateList;
begin
Add(AGL_WINDOW);
if DoubleBuffered then
Add(AGL_DOUBLEBUFFER);
if RGBA then
Add(AGL_RGBA);
Add(AGL_NO_RECOVERY);
Add(AGL_MAXIMUM_POLICY);
Add(AGL_SINGLE_RENDERER);
Add(AGL_RED_SIZE); Add(1);
Add(AGL_GREEN_SIZE); Add(1);
Add(AGL_BLUE_SIZE); Add(1);
Add(AGL_DEPTH_SIZE); Add(1);
Add(AGL_NONE);
end;
begin
Result:=nil;
p:=0;
CreateList;
GetMem(Result,SizeOf(integer)*p);
p:=0;
CreateList;
end;
function CreateAGLControlInfo(Control: ControlRef; AGLContext: TAGLContext
): PAGLControlInfo;
begin

View File

@ -129,19 +129,10 @@ procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass;
SharedControl: TWinControl; AttrList: PInteger): HWND;
const
DefaultOpenGLContextInitAttrList: array [0..10] of LongInt = (
GDK_GL_RGBA,
GDK_GL_RED_SIZE, 1,
GDK_GL_GREEN_SIZE, 1,
GDK_GL_BLUE_SIZE, 1,
GDK_GL_DEPTH_SIZE, 1,
GDK_GL_DOUBLEBUFFER,
GDK_GL_None
);
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, RGBA: boolean): HWND;
function CreateOpenGLContextAttrList(DoubleBuffered: boolean;
RGBA: boolean): PInteger;
implementation
@ -696,41 +687,68 @@ begin
Result:=gtk_gl_area_make_current(glarea);
end;
const
InitAttrList: array [1..11] of LongInt = (
GDK_GL_RGBA,
GDK_GL_RED_SIZE, 1,
GDK_GL_GREEN_SIZE, 1,
GDK_GL_BLUE_SIZE, 1,
GDK_GL_DEPTH_SIZE, 1,
GDK_GL_DOUBLEBUFFER,
GDK_GL_None
);
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
AttrList: PInteger): HWND;
DoubleBuffered, RGBA: boolean): HWND;
var
NewWidget: PGtkWidget;
SharedArea: PGtkGLArea;
AttrList: PInteger;
begin
if WSPrivate=nil then ;
if AttrList=nil then
AttrList:=@InitAttrList;
if SharedControl<>nil then begin
SharedArea:=PGtkGLArea(SharedControl.Handle);
if not GTK_IS_GL_AREA(SharedArea) then
RaiseGDBException('LOpenGLCreateContext');
NewWidget:=gtk_gl_area_share_new(AttrList,SharedArea);
end else begin
NewWidget:=gtk_gl_area_new(AttrList);
AttrList:=CreateOpenGLContextAttrList(DoubleBuffered,RGBA);
try
if SharedControl<>nil then begin
SharedArea:=PGtkGLArea(SharedControl.Handle);
if not GTK_IS_GL_AREA(SharedArea) then
RaiseGDBException('LOpenGLCreateContext');
NewWidget:=gtk_gl_area_share_new(AttrList,SharedArea);
end else begin
NewWidget:=gtk_gl_area_new(AttrList);
end;
Result:=HWND(NewWidget);
{$IFDEF LCLGtk}
TGTKWidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget,true);
{$ELSE}
TGTK2WidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget,true);
{$ENDIF}
finally
FreeMem(AttrList);
end;
Result:=HWND(NewWidget);
{$IFDEF LCLGtk}
TGTKWidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget,true);
{$ELSE}
TGTK2WidgetSet(WidgetSet).FinishComponentCreate(AWinControl,NewWidget,true);
{$ENDIF}
end;
function CreateOpenGLContextAttrList(DoubleBuffered: boolean; RGBA: boolean
): PInteger;
var
p: integer;
procedure Add(i: integer);
begin
if Result<>nil then
Result[p]:=i;
inc(p);
end;
procedure CreateList;
begin
if DoubleBuffered then
Add(GDK_GL_DOUBLEBUFFER);
if RGBA then
Add(GDK_GL_RGBA);
Add(GDK_GL_RED_SIZE); Add(1);
Add(GDK_GL_GREEN_SIZE); Add(1);
Add(GDK_GL_BLUE_SIZE); Add(1);
Add(GDK_GL_DEPTH_SIZE); Add(1);
Add(GDK_GL_None);
end;
begin
Result:=nil;
p:=0;
CreateList;
GetMem(Result,SizeOf(integer)*p);
p:=0;
CreateList;
end;
end.

View File

@ -27,8 +27,8 @@ procedure LOpenGLViewport(Left, Top, Width, Height: integer);
procedure LOpenGLSwapBuffers(Handle: HWND);
function LOpenGLMakeCurrent(Handle: HWND): boolean;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass;
SharedControl: TWinControl; AttrList: PInteger): HWND;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, RGBA: boolean): HWND;
procedure InitWGL;
procedure InitOpenGLContextGLWindowClass;
@ -248,8 +248,8 @@ begin
end;
function LOpenGLCreateContext(AWinControl: TWinControl;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl; AttrList: PInteger
): HWND;
WSPrivate: TWSPrivateClass; SharedControl: TWinControl;
DoubleBuffered, RGBA: boolean): HWND;
var
Params: TCreateWindowExParams;
pfd: PIXELFORMATDESCRIPTOR;
@ -283,8 +283,11 @@ begin
with pfd do begin
nSize:=sizeOf(pfd);
nVersion:=1;
dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
or PFD_TYPE_RGBA;
dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
if DoubleBuffered then
dwFlags:=dwFlags or PFD_DOUBLEBUFFER;
if RGBA then
dwFlags:=dwFlags or PFD_TYPE_RGBA;
iPixelType:=24; // color depth
cDepthBits:=16; // Z-Buffer
iLayerType:=PFD_MAIN_PLANE;

View File

@ -52,20 +52,24 @@ type
private
FAutoResizeViewport: boolean;
FCanvas: TCanvas; // only valid at designtime
FDoubleBuffered: boolean;
FFrameDiffTime: integer;
FOnMakeCurrent: TOpenGlCtrlMakeCurrentEvent;
FOnPaint: TNotifyEvent;
FCurrentFrameTime: integer; // in msec
FLastFrameTime: integer; // in msec
FOpenGLInitAttrList: PLongInt;
FRGBA: boolean;
FSharedOpenGLControl: TCustomOpenGLControl;
FSharingOpenGlControls: TList;
function GetSharingControls(Index: integer): TCustomOpenGLControl;
procedure SetAutoResizeViewport(const AValue: boolean);
procedure SetDoubleBuffered(const AValue: boolean);
procedure SetRGBA(const AValue: boolean);
procedure SetSharedControl(const AValue: TCustomOpenGLControl);
protected
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
procedure UpdateFrameTimeDiff;
procedure OpenGLAttributesChanged;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -84,10 +88,10 @@ type
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property SharedControl: TCustomOpenGLControl read FSharedOpenGLControl
write SetSharedControl;
property OpenGLInitAttrList: PLongInt read FOpenGLInitAttrList
write FOpenGLInitAttrList;
property AutoResizeViewport: boolean read FAutoResizeViewport
write SetAutoResizeViewport;
property DoubleBuffered: boolean read FDoubleBuffered write SetDoubleBuffered default true;
property RGBA: boolean read FRGBA write SetRGBA default true;
end;
{ TOpenGLControl }
@ -201,6 +205,20 @@ begin
LOpenGLViewport(0,0,Width,Height);
end;
procedure TCustomOpenGLControl.SetDoubleBuffered(const AValue: boolean);
begin
if FDoubleBuffered=AValue then exit;
FDoubleBuffered:=AValue;
OpenGLAttributesChanged;
end;
procedure TCustomOpenGLControl.SetRGBA(const AValue: boolean);
begin
if FRGBA=AValue then exit;
FRGBA:=AValue;
OpenGLAttributesChanged;
end;
procedure TCustomOpenGLControl.SetSharedControl(
const AValue: TCustomOpenGLControl);
begin
@ -261,10 +279,18 @@ begin
FLastFrameTime:=FCurrentFrameTime;
end;
procedure TCustomOpenGLControl.OpenGLAttributesChanged;
begin
if HandleAllocated
and ([csLoading,csDesigning,csDestroying]*ComponentState=[]) then
RecreateWnd(Self);
end;
constructor TCustomOpenGLControl.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FOpenGLInitAttrList:=@DefaultOpenGLContextInitAttrList[0];
FDoubleBuffered:=true;
FRGBA:=true;
ControlStyle:=ControlStyle-[csSetCaption];
if (csDesigning in ComponentState) then begin
FCanvas := TControlCanvas.Create;
@ -383,19 +409,19 @@ function TWSOpenGLControl.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND;
var
OpenGlControl: TCustomOpenGLControl;
AttrList: PLongint;
AttrControl: TCustomOpenGLControl;
begin
if csDesigning in AWinControl.ComponentState then
Result:=inherited CreateHandle(AWinControl,AParams)
else begin
OpenGlControl:=AWinControl as TCustomOpenGLControl;
if OpenGlControl.SharedControl<>nil then
AttrList:=OpenGlControl.SharedControl.OpenGLInitAttrList
AttrControl:=OpenGlControl.SharedControl
else
AttrList:=OpenGlControl.OpenGLInitAttrList;
AttrControl:=OpenGlControl;
Result:=LOpenGLCreateContext(OpenGlControl,WSPrivate,
OpenGlControl.SharedControl,
AttrList);
AttrControl.DoubleBuffered,AttrControl.RGBA);
end;
end;

View File

@ -3046,7 +3046,7 @@ begin
if frmCompilerOptions.ShowModal=mrOk then begin
RescanCompilerDefines(true);
Project1.DefineTemplates.AllChanged;
IncreaseCompilerParseStamp;
IncreaseCompilerGraphStamp;
end;
finally
frmCompilerOptions.Free;