OpenGL DirectX Interface

This page is for the conversion process from DirectX (Xbox) to DirectX (win32) to OpenGL/SDL. Ideally we want a wrapper interface class that hides the actual dirty work behind the scenes.

List of D3DTexture functions
Suggestion: We create a wrapper class that has these functions. D3D is easy - it just falls straight through.

OpenGL we keep both a local texture copy (ie local copy of pixel data) as well as the uploaded copy. On CreateTexture we simply create the local copy and blank it out. LockRect then returns this data. UnlockRect then uploads to the GPU. Release frees the texture.

class GLTexture { GLTexture { m_local = 0; m_pitch = 0; m_refCount = 0; m_refCount = 1; }; LockRect(LOCK_RECT lr) { lr.pitch = m_pitch; lr.bits = m_local; }; UnlockRect {   glEnable( GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, m_GlHandle ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glPixelStorei( GL_PACK_ROW_LENGTH, 0); glPixelStorei( GL_PACK_SKIP_PIXELS, 0); glTexImage2D( GL_TEXTURE_2D, 0, 4, m_width, m_height, 0, m_format, GL_UNSIGNED_BYTE, m_localImage); };

AddRef { m_refCount++; }; Release { if (m_refCount > 0) m_refCount--; if (!m_refCount) { if (m_glHandle) glDeleteTexture(m_glHandle); if (m_localImage) delete[] m_localImage; m_localImage = NULL; m_glHandle = 0; delete this; } }; private: BYTE *m_localImage; DWORD m_pitch; DWORD m_refCount; int  m_glHandle; }

Alternatively, glGetTexImage2D and/or glTexImage2D may be usable for lock/unlock perhaps, but I don't know if glGetTexImage2D allows alteration of the data or whether it's a copy (though there doesn't appear to be a way that the data is freed if it's a copy).