Saving currently locked texture

Started by
1 comment, last by savail 11 years, 9 months ago
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

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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

This topic is closed to new replies.

Advertisement