Hello,
I have some serious problems with the ChoosePixelFormat function. In
my application I evaluate an expression in the form a / b. The problem
is that the result of the expression is different before
ChoosePixelFormat call and after. I know that an expression evaluation
has nothing to do with an ChoosePixelFormat call, but the
ChoosePixelFormat call is exactly the point after which the expression
gets evaluated differently. I attach a small test app in Delphi to
demonstrate it. Also I must say that it works correctly on different
computers, also if I decrease the hardware acceleration level, the
problem is gone even on my computer. Is it possible that there is
something wrong with ATI's ChoosePixelFormat? I have ATI Saphire
HD2400 Pro.
The test app.
procedure Test;
type
TMyReal = array[0..7] of Byte;
TMyExt = array[0..9] of Byte;
const
// mem dump of value 117.98115
MemDump: TMyReal = ($CD, $9C, $5E, $29, $CB, $7E, $5D, $40);
// mem dump of value 2359.623
MemDumpSub: TMyExt = ($00, $00, $10, $D9, $CE, $F7, $79, $93, $0A,
$40);
procedure SetExt(const ADump: TMyExt; var x: Extended);
var
p: PByte;
i: Integer;
begin
p:=@x;
for i:=0 to 9 do begin
p^:=ADump[i];
Inc(p);
end;
end;
procedure SetReal(const ADump: TMyReal; var x: Real);
var
p: PByte;
i: Integer;
begin
p:=@x;
for i:=0 to 7 do begin
p^:=ADump[i];
Inc(p);
end;
end;
var
sub: Extended;
c: Real;
tmp_ext: Extended;
begin
// set the values
SetExt(MemDumpSub, sub);
SetReal(MemDump, c);
// problematic expression
tmp_ext:=sub / c;
// show the result
writeln(Trunc(tmp_ext));
end;
procedure MyChoosePixelFormat(DC: HDC);
var
PFDescriptor: TPixelFormatDescriptor;
PixelFormat: Integer;
begin
FillChar(PFDescriptor, SizeOf(PFDescriptor), 0);
with PFDescriptor do begin
nSize := SizeOf(PFDescriptor);
nVersion := 1;
dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or
PFD_DOUBLEBUFFER;
iPixelType := PFD_TYPE_RGBA;
cColorBits := 24;
cDepthBits := 32;
cStencilBits := 0;
cAccumBits := 0;
cAuxBuffers := 0;
iLayerType := PFD_MAIN_PLANE
end;
PixelFormat:=ChoosePixelFormat(DC, @PFDescriptor);
if PixelFormat = 0 then
raise Exception.Create('Could not set pixel format');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
writeln('before ChoosePixelFormat');
Test;
MyChoosePixelFormat(Canvas.Handle);
writeln('after ChoosePixelFormat');
Test;
end;
jindra
|
|
0
|
|
|
|
Reply
|
jindra
|
4/23/2008 1:11:04 PM |
|
On Apr 23, 3:11 pm, jindra <jpa...@gmail.com> wrote:
> Hello,
> I have some serious problems with the ChoosePixelFormat function. In
> my application I evaluate an expression in the form a / b. The problem
> is that the result of the expression is different before
> ChoosePixelFormat call and after. I know that an expression evaluation
> has nothing to do with an ChoosePixelFormat call, but the
> ChoosePixelFormat call is exactly the point after which the expression
> gets evaluated differently. I attach a small test app in Delphi to
> demonstrate it. Also I must say that it works correctly on different
> computers, also if I decrease the hardware acceleration level, the
> problem is gone even on my computer. Is it possible that there is
> something wrong with ATI's ChoosePixelFormat? I have ATI Saphire
> HD2400 Pro.
>
> The test app.
>
> procedure Test;
> type
> TMyReal = array[0..7] of Byte;
> TMyExt = array[0..9] of Byte;
> const
> // mem dump of value 117.98115
> MemDump: TMyReal = ($CD, $9C, $5E, $29, $CB, $7E, $5D, $40);
> // mem dump of value 2359.623
> MemDumpSub: TMyExt = ($00, $00, $10, $D9, $CE, $F7, $79, $93, $0A,
> $40);
>
> procedure SetExt(const ADump: TMyExt; var x: Extended);
> var
> p: PByte;
> i: Integer;
> begin
> p:=@x;
> for i:=0 to 9 do begin
> p^:=ADump[i];
> Inc(p);
> end;
> end;
>
> procedure SetReal(const ADump: TMyReal; var x: Real);
> var
> p: PByte;
> i: Integer;
> begin
> p:=@x;
> for i:=0 to 7 do begin
> p^:=ADump[i];
> Inc(p);
> end;
> end;
>
> var
> sub: Extended;
> c: Real;
> tmp_ext: Extended;
> begin
> // set the values
> SetExt(MemDumpSub, sub);
> SetReal(MemDump, c);
>
> // problematic expression
> tmp_ext:=sub / c;
>
> // show the result
> writeln(Trunc(tmp_ext));
> end;
>
> procedure MyChoosePixelFormat(DC: HDC);
> var
> PFDescriptor: TPixelFormatDescriptor;
> PixelFormat: Integer;
> begin
> FillChar(PFDescriptor, SizeOf(PFDescriptor), 0);
> with PFDescriptor do begin
> nSize := SizeOf(PFDescriptor);
> nVersion := 1;
> dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or
> PFD_DOUBLEBUFFER;
> iPixelType := PFD_TYPE_RGBA;
> cColorBits := 24;
> cDepthBits := 32;
> cStencilBits := 0;
> cAccumBits := 0;
> cAuxBuffers := 0;
> iLayerType := PFD_MAIN_PLANE
> end;
>
> PixelFormat:=ChoosePixelFormat(DC, @PFDescriptor);
> if PixelFormat = 0 then
> raise Exception.Create('Could not set pixel format');
> end;
>
> procedure TForm1.FormCreate(Sender: TObject);
> begin
> writeln('before ChoosePixelFormat');
> Test;
>
> MyChoosePixelFormat(Canvas.Handle);
>
> writeln('after ChoosePixelFormat');
> Test;
> end;
>
> jindra
Arrgh, responding to myself ... that was because the function
ChoosePixelFormat (as well as DescribePixelFormat and probably some
other) *changed* the control word of FPU, before the ChoosePixelFormat
call it was $137F, after it was $127F, which has probably affected the
computation.
Is it normal that some function changes the control word and does not
put it back before exit?
Jindra
|
|
0
|
|
|
|
Reply
|
jindra
|
4/24/2008 11:37:58 AM
|
|
On Apr 24, 1:37 pm, jindra <jpa...@gmail.com> wrote:
> Is it normal that some function changes the control word and does not
> put it back before exit?
>
No idea.
This is an OpenGL newsgroup, not a Delphi newsgroup.
--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.
|
|
0
|
|
|
|
Reply
|
fungus
|
4/24/2008 12:55:23 PM
|
|
jindra wrote:
> Is it normal that some function changes the control word and does not
> put it back before exit?
I have seen OpenGL drivers that turn on floating point exceptions and
don't turn them off again, so this doesn't surprise me. My solution was
to save and restore the control word each time I called an OpenGL function.
|
|
0
|
|
|
|
Reply
|
Jonno
|
4/24/2008 1:05:53 PM
|
|
"jindra" <jparus@gmail.com> wrote in message
news:e16198c1-2826-451d-afe9-c2da6eec61ca@d1g2000hsg.googlegroups.com...
> On Apr 23, 3:11 pm, jindra <jpa...@gmail.com> wrote:
>> Hello,
>> I have some serious problems with the ChoosePixelFormat function. In
>> my application I evaluate an expression in the form a / b. The problem
>> is that the result of the expression is different before
>> ChoosePixelFormat call and after. I know that an expression evaluation
>> has nothing to do with an ChoosePixelFormat call, but the
>> ChoosePixelFormat call is exactly the point after which the expression
>> gets evaluated differently. I attach a small test app in Delphi to
>> demonstrate it. Also I must say that it works correctly on different
>> computers, also if I decrease the hardware acceleration level, the
>> problem is gone even on my computer. Is it possible that there is
>> something wrong with ATI's ChoosePixelFormat? I have ATI Saphire
>> HD2400 Pro.
>>
>> The test app.
>>
>> procedure Test;
>> type
>> TMyReal = array[0..7] of Byte;
>> TMyExt = array[0..9] of Byte;
>> const
>> // mem dump of value 117.98115
>> MemDump: TMyReal = ($CD, $9C, $5E, $29, $CB, $7E, $5D, $40);
>> // mem dump of value 2359.623
>> MemDumpSub: TMyExt = ($00, $00, $10, $D9, $CE, $F7, $79, $93, $0A,
>> $40);
>>
>> procedure SetExt(const ADump: TMyExt; var x: Extended);
>> var
>> p: PByte;
>> i: Integer;
>> begin
>> p:=@x;
>> for i:=0 to 9 do begin
>> p^:=ADump[i];
>> Inc(p);
>> end;
>> end;
>>
>> procedure SetReal(const ADump: TMyReal; var x: Real);
>> var
>> p: PByte;
>> i: Integer;
>> begin
>> p:=@x;
>> for i:=0 to 7 do begin
>> p^:=ADump[i];
>> Inc(p);
>> end;
>> end;
>>
>> var
>> sub: Extended;
>> c: Real;
>> tmp_ext: Extended;
>> begin
>> // set the values
>> SetExt(MemDumpSub, sub);
>> SetReal(MemDump, c);
>>
>> // problematic expression
>> tmp_ext:=sub / c;
>>
>> // show the result
>> writeln(Trunc(tmp_ext));
>> end;
>>
>> procedure MyChoosePixelFormat(DC: HDC);
>> var
>> PFDescriptor: TPixelFormatDescriptor;
>> PixelFormat: Integer;
>> begin
>> FillChar(PFDescriptor, SizeOf(PFDescriptor), 0);
>> with PFDescriptor do begin
>> nSize := SizeOf(PFDescriptor);
>> nVersion := 1;
>> dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or
>> PFD_DOUBLEBUFFER;
>> iPixelType := PFD_TYPE_RGBA;
>> cColorBits := 24;
>> cDepthBits := 32;
>> cStencilBits := 0;
>> cAccumBits := 0;
>> cAuxBuffers := 0;
>> iLayerType := PFD_MAIN_PLANE
>> end;
>>
>> PixelFormat:=ChoosePixelFormat(DC, @PFDescriptor);
>> if PixelFormat = 0 then
>> raise Exception.Create('Could not set pixel format');
>> end;
>>
>> procedure TForm1.FormCreate(Sender: TObject);
>> begin
>> writeln('before ChoosePixelFormat');
>> Test;
>>
>> MyChoosePixelFormat(Canvas.Handle);
>>
>> writeln('after ChoosePixelFormat');
>> Test;
>> end;
>>
>> jindra
>
> Arrgh, responding to myself ... that was because the function
> ChoosePixelFormat (as well as DescribePixelFormat and probably some
> other) *changed* the control word of FPU, before the ChoosePixelFormat
> call it was $137F, after it was $127F, which has probably affected the
> computation.
>
> Is it normal that some function changes the control word and does not
> put it back before exit?
>
> Jindra
What the heck is a control word and what does it have to do with OpenGl (or
good programming in general).
Yeah, it's a bad idea to go pokin under the covers of the FPU.
jbw
|
|
0
|
|
|
|
Reply
|
jbwest
|
4/25/2008 12:53:52 AM
|
|
On Apr 24, 2:55 pm, fungus <openglMYSO...@artlum.com> wrote:
> On Apr 24, 1:37 pm, jindra <jpa...@gmail.com> wrote:
>
> > Is it normal that some function changes the control word and does not
> > put it back before exit?
>
> No idea.
>
> This is an OpenGL newsgroup, not a Delphi newsgroup.
>
> --
> <\___/>
> / O O \
> \_____/ FTB. Remove my socks for email address.
yes, but during the ChoosePixelFormat call, OpenGl32.dll, atioglx2.dll
get loaded, that's why I suspect that this problem is OpenGL related
(maybe ATI related) and that's why I ask in OpenGL group, also when I
decrease the hardware acceleration (Troubleshooting panel from Display
properties) the atioglx2.dll is not loaded and the expression is
evaluated OK (i.e., the control word is not switched)
jindra
|
|
0
|
|
|
|
Reply
|
jindra
|
4/25/2008 8:31:35 AM
|
|
On Apr 24, 3:05=A0pm, Jonno <jo...@noreply.com> wrote:
> jindra wrote:
> > Is it normal that some function changes the control word and does not
> > put it back before exit?
That's true, it seems that OpenGL cannot live with floating point
exceptions enabled , however in my case the (probably) OpenGL realted
function ChoosePixelFormat changed the precision of floating point
operations and did not put it back, which I consider very bad.
>
> I have seen OpenGL drivers that turn on floating point exceptions and
> don't turn them off again, so this doesn't surprise me. My solution was
> to save and restore the control word each time I called an OpenGL function=
..
Yes, that's exactly how I must proceed.
jindra
|
|
0
|
|
|
|
Reply
|
jindra
|
4/25/2008 8:58:19 AM
|
|
|
6 Replies
263 Views
(page loaded in 0.065 seconds)
Similiar Articles: SetPixelFormat crash - comp.graphics.api.openglChoosePixelFormat and DescribePixelFormat work fine, as expected. However it crashes at ... There should be a folder in there with the name >> of the graphics card ("ATI ... GL_AUX buffers - comp.graphics.api.opengl... 0, 0, 0, 0, 16, 0, 3, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(PixelFormat=ChoosePixelFormat(hDC ... problem: > I would like to use GL_AUX buffers in combination with ATI_draw ... font smoothing - comp.graphics.api.openglFor example my ATI 9500 does not support it. If you want compatibility I don ... pfd.cDepthBits = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat (*hDC ... PIXELFORMATDESCRIPTOR - comp.graphics.api.openglMOBILITY RADEON 9000 Chip : MOBILITY RADEON 9000 AGP ... pfd =3D { sizeof ... Appendix C - OpenGL Programming Guide - GLProgramming.com ChoosePixelFormat() tries to find ... SetPixelFormat crash - comp.graphics.api.opengl | Computer GroupChoosePixelFormat and DescribePixelFormat work fine, as expected. However it crashes at ... There should be a folder in there with the name >> of the graphics card ("ATI ... AMD Driver AutodetectAMD Driver Autodetect detects your graphics card and operating system and tells you if a new driver is available. If there is a new driver, the tool will download it ... 7/23/2012 8:46:50 AM
|