2009-02-09 21:15:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSTexture7.h"
|
|
|
|
|
|
|
|
GSTexture7::GSTexture7(int type, IDirectDrawSurface7* system)
|
2009-08-02 23:07:30 +00:00
|
|
|
: m_system(system)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
memset(&m_desc, 0, sizeof(m_desc));
|
|
|
|
|
|
|
|
m_desc.dwSize = sizeof(m_desc);
|
|
|
|
|
|
|
|
system->GetSurfaceDesc(&m_desc);
|
2009-07-16 21:36:07 +00:00
|
|
|
|
|
|
|
m_size.x = (int)m_desc.dwWidth;
|
|
|
|
m_size.y = (int)m_desc.dwHeight;
|
2009-08-02 23:07:30 +00:00
|
|
|
|
|
|
|
m_type = type;
|
|
|
|
|
|
|
|
m_format = (int)m_desc.ddpfPixelFormat.dwFourCC;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture7::GSTexture7(int type, IDirectDrawSurface7* system, IDirectDrawSurface7* video)
|
2009-08-02 23:07:30 +00:00
|
|
|
: m_system(system)
|
2009-02-09 21:15:56 +00:00
|
|
|
, m_video(video)
|
|
|
|
{
|
|
|
|
memset(&m_desc, 0, sizeof(m_desc));
|
|
|
|
|
|
|
|
m_desc.dwSize = sizeof(m_desc);
|
|
|
|
|
|
|
|
video->GetSurfaceDesc(&m_desc);
|
2009-07-16 21:36:07 +00:00
|
|
|
|
|
|
|
m_size.x = (int)m_desc.dwWidth;
|
|
|
|
m_size.y = (int)m_desc.dwHeight;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
m_type = type;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-08-02 23:07:30 +00:00
|
|
|
m_format = (int)m_desc.ddpfPixelFormat.dwFourCC;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
bool GSTexture7::Update(const GSVector4i& r, const void* data, int pitch)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r2 = r;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
DDSURFACEDESC2 desc;
|
|
|
|
|
|
|
|
memset(&desc, 0, sizeof(desc));
|
|
|
|
|
|
|
|
desc.dwSize = sizeof(desc);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(SUCCEEDED(hr = m_system->Lock(r2, &desc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY, NULL)))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8* src = (uint8*)data;
|
|
|
|
uint8* dst = (uint8*)desc.lpSurface;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-04 15:14:04 +00:00
|
|
|
int bytes = std::min<int>(pitch, desc.lPitch);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
for(int i = 0, j = r.height(); i < j; i++, src += pitch, dst += desc.lPitch)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// memcpy(dst, src, bytes);
|
|
|
|
|
|
|
|
// HACK!!!
|
|
|
|
|
|
|
|
GSVector4i* s = (GSVector4i*)src;
|
|
|
|
GSVector4i* d = (GSVector4i*)dst;
|
|
|
|
|
|
|
|
int w = bytes >> 4;
|
|
|
|
|
|
|
|
for(int x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
GSVector4i c = s[x];
|
|
|
|
|
|
|
|
c = (c & 0xff00ff00) | ((c & 0x00ff0000) >> 16) | ((c & 0x000000ff) << 16);
|
|
|
|
|
|
|
|
d[x] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
hr = m_system->Unlock(r2);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(m_video)
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
hr = m_video->Blt(r2, m_system, r2, DDBLT_WAIT, NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-12 19:09:17 +00:00
|
|
|
bool GSTexture7::Map(GSMap& m, const GSVector4i* r)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2009-05-28 02:57:01 +00:00
|
|
|
if(r != NULL)
|
|
|
|
{
|
|
|
|
// ASSERT(0); // not implemented
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
DDSURFACEDESC2 desc;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(SUCCEEDED(hr = m_system->Lock(NULL, &desc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL)))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-12 19:09:17 +00:00
|
|
|
m.bits = (uint8*)desc.lpSurface;
|
|
|
|
m.pitch = (int)desc.lPitch;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSTexture7::Unmap()
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = m_system->Unlock(NULL);
|
|
|
|
|
|
|
|
if(m_video)
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
hr = m_video->Blt(NULL, m_system, NULL, DDBLT_WAIT, NULL);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
bool GSTexture7::Save(const string& fn, bool dds)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectDrawSurface7* GSTexture7::operator->()
|
|
|
|
{
|
|
|
|
return m_video ? m_video : m_system;
|
|
|
|
}
|
|
|
|
|
|
|
|
GSTexture7::operator IDirectDrawSurface7*()
|
|
|
|
{
|
|
|
|
return m_video ? m_video : m_system;
|
|
|
|
}
|