Jump to content
  • Advertisement
Sign in to follow this  
savail

OpenGL Saving currently locked texture

This topic is 2255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,
I'm looking for a function in DirectX similar to this one in OpenGL: glGetIntegerv - http://msdn.microsof...7(v=vs.85).aspx
I'm not sure if I call it right but I need to save currently locked texture to a temporary LPDIRECT3DTEXTURE9 variable.
What I'm trying to reproduce from Opengl on DirectX is this:
GLuint old_tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex));

Would be very grateful for help!

edit: hmm actually I'm not sure if the above part of code is really needed in DirectX. The full code I'm trying to reproduce in DirectX comes from CEGUI source file and is as follows:

void OpenGLTexture::saveToMemory(void* buffer)
{
// save old texture binding
GLuint old_tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex));
glBindTexture(GL_TEXTURE_2D, d_ogltexture);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// restore previous texture binding.
glBindTexture(GL_TEXTURE_2D, old_tex);
}


I didn't paste whole code at first becouse I thought I could manage with this part but it seems like I really can't find proper functions in DirectX :(. I've been searching a lot and tried using D3DXSaveTextureToFileInMemory instead of glGetTexImage, but it doesn't seem to work Edited by savail

Share this post


Link to post
Share on other sites
Advertisement
Definitely not needed in D3D - this is an artefact of the design of OpenGL which needs you to bind a texture in order to modfy it, access it, etc, whereas D3D doesn't have that requirement.

The reason why it's used in the GL sample is because a texture may be bound for drawing with. If you change the texture binding in order to save out the texels, then you also change the binding for drawing, so the next draw call will likely be done with an incorrect texture. To work around that the approach is to save the current texture binding, bind the new one, save out the data, then put the texture binding back the way it was.

With D3D you don't need to "bind" a texture to do anything other than draw, so accessing the texels in this manner won't affect the state for drawing.

Share this post


Link to post
Share on other sites
hmm k thanks for putting it straight for me ^^. I wanted to make a fix for myself on my own but it seems I'll have to ask Crazy Eddie for help again tongue.png Edited by savail

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!