PDA

View Full Version : glReadPixels halts my app



nighthawk07
03-08-2011, 01:18 AM
I have written an application to capture opengl es screen.
And been using the glReadPixels command. In the following manner:

glReadPixels(x, y, mwidth, mheight, GL_RGBA, GL_UNSIGNED_BYTE, @mydata[0]);

Seems that that command halts my application while reaching the glgConvertTo_32<GLGConverter_ABGR8_ARGB8, (GLGMEMORY)2>of the pixels to my buffer. (this asm command is being used internally in the glReadPixels command process).
I've been using fpc in order to code the application, and been allocation buffer space using the SetLength(MyArray, dataLength);

I made sure that the mwidth,mheight I am using is a mod divizion zero. So that therre is no need to reconvert these variables using the internal glReadPixels command.

It seems that anything I try to run the glReadPixels command fails, both in the emulation of ios and on the device itself.
I do not know what the exact problem is and been trying to override the halting of the application by using glReadPixels with a small amount of data, comparing to the allocate array. or increasing the allocated space in the buffer so it would have to fit the array dimensions.

Please let me know what buffer to send to the glReadPixels.

V-man
03-08-2011, 06:10 AM
http://www.opengl.org/wiki/Common_Mistakes#Unsupported_formats_.234

nighthawk07
03-08-2011, 06:50 AM
When being set to GL_BGRA -- Seems that that command halts (crashes) my application while reaching the _memcpy command. On this case I thought that there must be something wrong with the way I am allocating memory buffer to read the pixels into.
I've been using fpc in order to code the application, and
1. Tried allocation buffer space using the SetLength(MyArray, dataLength);
2. Tried allocating buffer space using the "new" command
3. Tried both functions GetMem, and AllocMem to allocate buffer space
On all these cases the glReadPixels command fails on the same trace asm _memcpy command.
I tried to override the halting (crashing) of the application by using glReadPixels with a small amount of data, comparing to the allocated array. or increasing the allocated space in the buffer so it would have to fit the array dimensions.

It seems that anything I try to run the glReadPixels command fails, both in the emulation of ios and on the device itself. I do not know what the exact problem is.

Please let me know what buffer to send to the glReadPixels.

Alfonse Reinheart
03-08-2011, 09:42 AM
Has it occurred to you that "dataLength" may be wrong?

nighthawk07
03-08-2011, 10:54 AM
I tried, as I said, reducing the width and height to minimum -- datalength = width * height * 4;

Dark Photon
03-09-2011, 05:54 PM
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); ?

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
See "7. Watch your Pixel Store Alignment"

nighthawk07
03-09-2011, 07:30 PM
I tried the UNPACK_ALIGNMENT,1 -- didn't work.
The glReadPixels, works properly on the emulation mode. Under the iMac, But it doesn't work on the device itself.
I tried using the minimum amount of pixels to read, And the GDB just raises an error that it can not access memory at the Memory Buffer array.

Are there different ways defining the memory buffer?

I know of two, a static definition of a memory buffer (either localy in the function, or globally in the application). Or Dynamic allocation of memory. The only way I could make the function work is on the emulation when defining static memory buffer localy in the function. It wouldn't run though, on any circumstances on the ios device itself.

Alfonse Reinheart
03-09-2011, 08:01 PM
glReadPixels(x, y, mwidth, mheight, GL_RGBA, GL_UNSIGNED_BYTE, @mydata[0]);

Is that '@' sign a typo or is that in your code? Because I'm fairly sure that there is no '@' operator in C/C++.

If you're using Objective C/C++, and the '@' sign is an operator of that language, then what exactly does it do? Does it return an actual C/C++ pointer type, or does it return some kind of Objective C/C++ thing?

nighthawk07
03-09-2011, 08:57 PM
After four days of struggle, observing the problem logically I found the following:
glReadPixels recives as a memory buffer a PGLVoid which is defined as:
type
GLVOID = pointer;
PGLVoid = ^GLVoid;

All I had to do is define a PGLVoid variable set it to the location of the memory buffer, and send the glReadPixels function the variable with MyArray^

Dan Bartlett
03-10-2011, 03:49 AM
He mentions he's using fpc, which is the Free Pascal Compiler. In Pascal, "@" is the address operator, it just returns the pointer to that variable.

PGLVoid should just be defined as PGLVoid = Pointer, and GLVOID shouldn't be defined at all, since Delphi/Pascal has no equivalent to void, but void* is equivalent to the Delphi untyped "Pointer" type.