I am now writing a program to generate textures using GPU with the help of GL Shading Language. However, I am wondering whether it is possible for me to fetch the data stored in a texture and write it in an array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is not a big deal, if you have glGetTexImage*().
In case glGetTexImage*() is not available, you have to render a textured quad to a renderbuffer, which is attached to an FBO (if supported), or to the backbuffer and use glReadPixels() to read it back from either render target. Should the render target have insufficient size, multiple tiles must be rendered and retrieved separately.
When implementing either approach, pay attention to other states, which determine how and where pixels actually will be written to:
GL_PACK_ALIGNMENT(image line alignment; 1,2,4 or 8 bytes) requires appropriate memory allocation for the requested image size. For example, a 24bit DIB (.bmp) uses a line alignment of 4 bytes. Having 3 bytes per pixel, padding is required at the end if(image.width * 3) % 4 != 0.The total amount of additional padding bytes is:
readSize.y * ((alignment - readSize.x % alignment) % alignment).GL_PIXEL_PACK_BUFFER, the target buffer binding for pixel transfers (may be unused in your case and explicitly set to 0).