Sign in to follow this  
savail

OpenGL Saving currently locked texture

Recommended Posts

Hey,
I'm looking for a function in DirectX similar to this one in OpenGL: glGetIntegerv - [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ee872027%28v=vs.85%29.aspx"]http://msdn.microsof...7(v=vs.85).aspx[/url]
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:
[CODE]GLuint old_tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, reinterpret_cast<GLint*>(&old_tex));[/CODE]
Would be very grateful for help!

[size=5][b]edit[/b]:[/size] 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:
[CODE]
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);
}
[/CODE]

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
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 [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] Edited by savail

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this