Skip to main content
GameDev.net gamedev.net
🔒 Locked

copying a texture

Started by me_here_me Feb 26, 2008 at 5:26 AM 2 replies 900+ views
Original Post
me_here_me
me_here_me
Hi, I have a 2D texture and I want to copy a portion of it into an array for further processing. At the moment I am retrieving the whole of the texture into an array using the following code:

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, txNormalsMapMesh);
		glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tempdata2);

The problem is that I am retrieving the whole texture into an array where as I only need a subset of it (a rectangular region), starting from position (x, y) with offset (xOffset, yOffset). Is there any openGL method that makes it possible? best withes
swiftcoder
swiftcoder
In general, reading textures back from the GPU is a really bad idea, performance-wise. You will stall the entire pipeline, which is going to do a number on your frame rates.

There is generally a better way to accomplish the same thing, such as making a copy of the texture data in main memory when you load the texture.

If you really *have* to do this for some reason, you may want to look into PBOs (Pixel Buffer Objects) and FBOs (Frame Buffer Objects), which should allow you to reduce the performance problems.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
me_here_me
me_here_me
Thanks for your replies.

glReadPixels can be used to read data from a frame buffer, but I dont think the same can be used for reading textures too.

I am looking into PBO, if it lets me copy portions of the texture.

regards

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.