Re: [fpc-pascal] dglOpenGL <-> GL, GLu, GLExt

2013-02-23 Thread Juha Manninen
On Sun, Feb 17, 2013 at 11:12 PM, Marco van de Voort  wrote:
>> Q: how am I supposed to initialize OpenGL when using units provided by FPC?
>
> The unit does it at startup. That has as disadvantage that the filename
> can't be changed (or at least that first try can't be avoided).
>
> After that, you iirc need to do load from unit
> glext to load the extensions for later versions.


Thanks Marco.

I didn't quite understand what is load.

My experiments advance slowly. The original DeleD code validate OpenGL
by checking if
@glActiveTextureARB, @glClientActiveTextureARB and @glMultiTexCoord2fARB
are assigned.

With dglopengl it stops working when I replace
  H_RC := wglCreateContext(H_DC);
with the cross-platform OpenGLContext:
  fOpenGLControl1:=TOpenGLControl.Create(Self);
and replace
  wglMakeCurrent(H_DC, H_RC);
with
  OpenGLControl1.MakeCurrent;

When using GLExt (provided by FPC), the test still fails but then I
can remove it and the code does not crash later.
So, maybe it is better to use GL and GLExt.
If I put the same test in the OpenGlControl demo in Lazarus, it does
not fail! I don't see what makes the difference.

Cross-platform OpenGL still does not work though. Deled 3-D uses form
inheritance and all forms needing OpenGL drawing window inherit from
TOGLForm. I copy below the Create method where I had to comment out
most code to make it compile.
I create fOpenGLControl1 the same way than in the Lazarus example, but
I don't know what to put into the OnPaint and OnResize event handlers.
Now the code does not crash but obviously does not draw anything either.

I guess I must study the topic more. I will commit my code to the
DeleD SVN branch although it is broken. Maybe someone could have a
look at it.

Regards,
Juha




constructor TOGLForm.Create(AOwner: TComponent);
//var PixelFormat: Integer;
   // our windows pixel format
//PFD: PixelFormatDescriptor;
   // describes the pixel format
begin
inherited;
Initialize;
Set8087CW($133f);// disable fpu exceptions when doing OpenGL rendering

//ZeroMemory(@PFD, SizeOf(PFD));
   // describe our Pixel Format Descriptor
//with PFD do begin
//nSize := SizeOf(PFD);
//nVersion := 1;
//dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or
PFD_DOUBLEBUFFER or 0;
//iPixelType := PFD_TYPE_RGBA;
//cColorBits := 16;
//cDepthBits := 16;
//end;

// now set pixel format + initialize rendering context
//H_DC := Canvas.Handle;
//PixelFormat := ChoosePixelFormat(H_DC, @PFD);
   // choose a pixel format based on our description
//if PixelFormat = 0 then begin
//KillWindow;
//MessageBox(0, 'Unable to choose pixel format', 'Error',
MB_OK or MB_ICONERROR);
//Exit;
//end;
//if not SetPixelFormat(H_DC, PixelFormat, @PFD) then begin
   // attach the pixel format to the window
//KillWindow;
//MessageBox(0, 'Unable to set pixel format', 'Error', MB_OK
or MB_ICONERROR);
//Exit;
//end;
//H_RC := wglCreateContext(H_DC);
   // get the rendering context handle
//if H_RC = 0 then begin
//KillWindow;
//MessageBox(0, 'Unable to create rendering context', 'Error',
MB_OK or MB_ICONERROR);
//Exit;
//end;
//ActivateRenderingContext(H_DC,H_RC);
fOpenGLControl1:=TOpenGLControl.Create(Self);
with fOpenGLControl1 do begin
  Name:='OpenGLControl1';
  Parent:=Self;
  SetBounds(10,90,380,200);
  //OnPaint:=@OpenGLControl1Paint;
  //OnResize:=@OpenGLControl1Resize;
end;
if not fOpenGLControl1.MakeCurrent then begin
  // initialize the endering context
KillWindow;
MessageBox(0, 'Unable to activate rendering context', 'Error',
MB_OK or MB_ICONERROR);
Exit;
end;
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] dglOpenGL <-> GL, GLu, GLExt

2013-02-23 Thread Sven Barth

On 23.02.2013 14:45, Juha Manninen wrote:

On Sun, Feb 17, 2013 at 11:12 PM, Marco van de Voort  wrote:

Q: how am I supposed to initialize OpenGL when using units provided by FPC?


The unit does it at startup. That has as disadvantage that the filename
can't be changed (or at least that first try can't be avoided).

After that, you iirc need to do load from unit
glext to load the extensions for later versions.



Thanks Marco.

I didn't quite understand what is load.


In unit GLext you have functions like Load_GL_version_1_3 which will 
load all core functions provided in OpenGL 1.3 or 
Load_GL_ARB_multitexture which will load all ARB functions related to 
multitexturing (of course you should only do this if your version 
supports/needs this). This is necessary, because in different OpenGL 
versions different APIs were either part of the "core API" or where at 
least standardized, but still optional in the "ARB API" or where 
provided by specific vendors only "Ext API". So you need to decide first 
which OpenGL version you want to support where you might need to test 
first whether the version is supported at all at your client's computer 
by creating an approbiate context (Note: I don't know how this can be 
influenced with TOpenGLControl).


E.g. for current computer graphics you'll most likely want to have 
support for shaders for which you need to have at least OpenGL 2.0. If 
you want to have geometry shaders as well you need to use OpenGL 3.0 or 
newer. With newer versions you also can't use the fixed function 
pipeline anymore (glBegin() ... glEnd() ) [with the capabilities of 
shaders this isn't feasible anymore]




My experiments advance slowly. The original DeleD code validate OpenGL
by checking if
 @glActiveTextureARB, @glClientActiveTextureARB and @glMultiTexCoord2fARB
are assigned.



The Load_GL_... return a Boolean to tell you whether the functions could 
be loaded. I just checked the code of e.g. Load_GL_ARB_multitexture and 
it does even check for you whether the extension is supported.



I create fOpenGLControl1 the same way than in the Lazarus example, but
I don't know what to put into the OnPaint and OnResize event handlers.
Now the code does not crash but obviously does not draw anything either.


OnResize can be used to recalculate the projection matrix if the Window 
with the OpenGL control was resized.


OnPaint is the event where you do your rendering (and AFAIK call 
OpenGLControl.SwapBuffers at the end).



constructor TOGLForm.Create(AOwner: TComponent);
//var PixelFormat: Integer;
// our windows pixel format
//PFD: PixelFormatDescriptor;
// describes the pixel format
begin
 inherited;
 Initialize;
 Set8087CW($133f);// disable fpu exceptions when doing OpenGL rendering


Note: If you really want to disable FPU exceptions you should use 
SetExceptionMask ( 
http://www.freepascal.org/docs-html/rtl/math/setexceptionmask.html ) 
instead as Set8087CW is supported on x86 only.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] dglOpenGL <-> GL, GLu, GLExtt

2013-02-23 Thread Marco van de Voort
In our previous episode, Juha Manninen said:
> 
> I didn't quite understand what is load.

A function loadgl4.1 or loadglext4.1 or so. There was one for each version
in glext to preload certain extensions (which afaik you can only load if you
have created a proper context)
 
> My experiments advance slowly. The original DeleD code validate OpenGL
> by checking if
> @glActiveTextureARB, @glClientActiveTextureARB and @glMultiTexCoord2fARB
> are assigned.
> 
> With dglopengl it stops working when I replace
>   H_RC := wglCreateContext(H_DC);
> with the cross-platform OpenGLContext:
>   fOpenGLControl1:=TOpenGLControl.Create(Self);
> and replace
>   wglMakeCurrent(H_DC, H_RC);
> with
>   OpenGLControl1.MakeCurrent;

>From what I see it is TWSOpenGLControl.CreateHandle that creates the
context. Put a breakpoint on the lopenglcreatecontext function and make sure
you hit the breakpoint when you create the topenglcontrol. I don't know
what these WS components are good for.

Note also that openglcontrol seems to use its own headers (at least on
Windows). I've only used opengl on Windows though (its for work)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TProcess InheritHandles has no effect

2013-02-23 Thread Luca Olivetti
Al 26/05/11 13:14, En/na Luca Olivetti ha escrit:
> According to the documentation InheritHandles only works in windows.
> However the windows implementation of TProcess.Execute has in the first
> line
> 
> FInheritHandles:=true
> 
> so it doesn't work even under windows.
> 
> fpc 2.4.2, but I checked in svn and it's the same.

And in 2.6.0 and, again, in svn.



Bye
-- 
Luca

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] dglOpenGL <-> GL, GLu, GLExt

2013-02-23 Thread Reimar Grabowski
On Sat, 23 Feb 2013 15:20:12 +0100
Sven Barth  wrote:

Just a little addition:
 
> In unit GLext you have functions like Load_GL_version_1_3 which will 
> load all core functions provided in OpenGL 1.3
and lower. So Load_GL_version_2_0 will call Load_GL_version_1_5 which will call 
Load_GL_Version_1_4 ...
A graphics card/driver supporting one OpenGL version is required to support the 
lower versions, too.

R.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Performance problems with Image Conversions

2013-02-23 Thread Andrew Brunner

Hi guys,

I just finished (a beta) of a collage app for Aurawin.  I'm seeing a 
huge load on my servers when scaling images using the Image factory 
classes for JPEG, and PNG.


Prefix:
6 Core AMD 64 32GB RAM Ubuntu 12.10 x64
8 Core AMD 64 32GB RAM Ubuntu 12.10 x64
FPC/Lazarus daily svn/trunk

Overview:
1.) end-user grabs references to files (stored on my server)
2.) back-end core object scales camera photos to something more net 
friendly 512px max to scale.

3.) server streams photos back to client over the web and
4.) server assembles XML stream of Mime encoded file data for things like
https://aurawin.com/cb?3

Specifics

The pics in this sample take about 30 seconds to go from their originals 
to 512px.  The app waits for the collage to save to the cloud.  The 
problem gets worse for larger collages with more images.


iX,iY are no larger than 512

class function Image.Transform(Stream:TStream; var 
sContentType,srcKind,dstKind:string; var iX,iY:Integer):boolean;

var
  FReader  : TFPCustomImageReader;
  FWriter  : TFPCustomImageWriter;
  cReader  : TFPCustomImageReaderClass;
  cWriter  : TFPCustomImageWriterClass;
  Factor   : Double;
  FTransparent : boolean;
  dstImg   : TFPMemoryImage;
  srcImg   : TFPMemoryImage;
  srcCanvas: TFPImageCanvas;
  dstCanvas: TFPImageCanvas;


  procedure FreeImageData;
  begin
if (srcCanvas<>nil) then
  srcCanvas.Free();
if (dstCanvas<>nil) then
  dstCanvas.Free();
if (FReader<>nil) then
  FReader.Free();
if FWriter<>nil then
  FWriter.Free();
if srcImg<>nil then
  srcImg.Free();
if dstImg<>nil then
  dstImg.Free();
  end;
begin
  Result:=false;
  if SameText(srcKind,Image.Kind.GIF.Name) then begin
sContentType:=hHTTP.ctPNG;
dstKind:=Image.Kind.PNG.Name;
FTransparent:=true;
  end else if SameText(srcKind,Image.Kind.PNG.Name) then begin
dstKind:=Image.Kind.PNG.Name;
FTransparent:=true;
  end else begin
sContentType:=hHTTP.ctJPG;
dstKind:=Image.Kind.JPG.Name;
FTransparent:=false;
  end;
  cReader:=FPImage.ImageHandlers.ImageReader[srcKind];
  cWriter:=FPImage.ImageHandlers.ImageWriter[dstKind];
  dstCanvas:=nil; srcCanvas:=nil; FReader:=nil; FWriter:=nil; 
srcImg:=nil; dstImg:=nil;

  Result:=(cReader<>nil) and (cWriter<>nil);
  if Result then begin
Try
  FReader:=cReader.Create();
  FWriter:=cWriter.Create();

  if SameText(dstKind,Image.Kind.PNG.Name) then begin
TFPWriterPNG(FWriter).Indexed:=false;
TFPWriterPNG(FWriter).UseAlpha:=true;
  end;

  srcImg:=TFPMemoryImage.Create(0,0);
  srcImg.UsePalette:=false;
  Stream.Position:=0;
  Try
srcImg.LoadFromStream(Stream,FReader);
Stream.Position:=0;

if (srcImg.Width>=srcImg.Height) then begin
  Factor:=iX/srcImg.Width;
end else begin
  Factor:=iY/srcImg.Height;
end;

if (srcImg.Width>iX) or (srcImg.Height>iY) then begin
  if FTransparent then begin
if SameText(srcKind,Image.Kind.GIF.Name) then begin
  FTransparent:=TFPReaderGIF(FReader).Transparent;
  TFPWriterPNG(FWriter).UseAlpha:=true;
end;
  end;

  iX:= Round(srcImg.Width * Factor);
  iY:= Round(srcImg.Height * Factor);

  dstImg:=TFPMemoryImage.Create(iX,iY);
  dstImg.UsePalette:=false;
  dstCanvas:=TFPImageCanvas.create(dstImg);
  dstCanvas.StretchDraw(0,0,iX,iY,srcImg);

  Stream.Size:=0;
  dstImg.SaveToStream(Stream,FWriter);
  Stream.Position:=0;
  Result:=true;
end;
  Except
Stream.Size:=0;
Stream.Position:=0;
Result:=false;
  end;
Finally
  FreeImageData();
end;
  end;
end;

Further, when a user views images via my preview app, I don't send the 
originals, I scale those too using the same methods.  The speed is 
killing my server's performance.


Does anyone have any idea how to speed up the underlining code?

--
Andrew Brunner

Aurawin LLC
15843 Garrison Circle
Austin, TX 78717

https://aurawin.com

Aurawin is a great new way to store, share, and explore all your content
featuring our innovative cloud social computing platform.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal