From e0330e18d7ee11537048546f87b0274420ce562d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 8 Oct 2012 11:05:28 +0000 Subject: [PATCH] gpu: fix some Direct3D programming errors; we cannot call SetVertexDeclaration with a null argument, and the texture stuff was completely messed up. --- src/gpu/texture.cpp | 26 +++++++++----------------- src/gpu/vertexbuffer.cpp | 4 ++-- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/gpu/texture.cpp b/src/gpu/texture.cpp index 654de2e3..6b977ed1 100644 --- a/src/gpu/texture.cpp +++ b/src/gpu/texture.cpp @@ -81,12 +81,12 @@ Texture::Texture(ivec2 size) #if defined USE_D3D9 g_d3ddevice->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, - D3DPOOL_SYSTEMMEM, &m_tex, NULL); + D3DPOOL_DEFAULT, &m_data->m_tex, NULL); #elif defined _XBOX /* By default the X360 will swizzle the texture. Ask for linear. */ g_d3ddevice->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1, D3DUSAGE_WRITEONLY, D3DFMT_LIN_A8R8G8B8, - D3DPOOL_DEFAULT, &m_tex, NULL); + D3DPOOL_DEFAULT, &m_data->m_tex, NULL); #else glGenTextures(1, &m_data->m_texid); glBindTexture(GL_TEXTURE_2D, m_data->m_texid); @@ -118,13 +118,9 @@ void Texture::SetData(void *data) { #if defined _XBOX || defined USE_D3D9 D3DLOCKED_RECT rect; -# if defined _XBOX - m_data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE); -# else - m_data->m_tex->LockRect(0, &rect, NULL, - D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); -# endif - memcpy(rect.pBits, data, rect.Pitch * rect.Height); + m_data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD); + + memcpy(rect.pBits, data, rect.Pitch * m_data->m_size.y); m_data->m_tex->UnlockRect(0); @@ -139,18 +135,14 @@ void Texture::SetSubData(ivec2 origin, ivec2 size, void *data) { #if defined _XBOX || defined USE_D3D9 D3DLOCKED_RECT rect; -# if defined _XBOX - m_data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE); -# else - m_data->m_tex->LockRect(0, &rect, NULL, - D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); -# endif + m_data->m_tex->LockRect(0, &rect, NULL, 0); + for (int j = 0; j < size.y; j++) { uint8_t *dst = (uint8_t *)rect.pBits + (origin.y + j) * rect.Pitch; /* FIXME: the source or destination pitch isn't necessarily 4! */ - uint8_t *src = (uint8_t *)data + j * size.y * 4; - memcpy(dst, src, size.y * 4); + uint8_t *src = (uint8_t *)data + j * size.x * 4; + memcpy(dst, src, size.x * 4); } m_data->m_tex->UnlockRect(0); diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp index 0a629dc3..c3d24f50 100644 --- a/src/gpu/vertexbuffer.cpp +++ b/src/gpu/vertexbuffer.cpp @@ -275,8 +275,8 @@ void VertexDeclaration::Unbind() if (FAILED(g_d3ddevice->SetStreamSource(stream, 0, 0, 0))) Abort(); } - if (FAILED(g_d3ddevice->SetVertexDeclaration(NULL))) - Abort(); + /* "NULL is an invalid input to SetVertexDeclaration" (DX9 guide), so + * we just don't touch the current vertex declaration. */ #elif !defined __CELLOS_LV2__ for (int i = 0; i < m_count; i++) {