2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "D3DBase.h"
|
|
|
|
#include "D3DTexture.h"
|
|
|
|
|
2011-01-07 09:42:44 +00:00
|
|
|
#include "CPUDetect.h"
|
|
|
|
|
2011-01-07 05:58:05 +00:00
|
|
|
#if _M_SSE >= 0x401
|
|
|
|
#include <smmintrin.h>
|
|
|
|
#include <emmintrin.h>
|
|
|
|
#elif _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
|
|
|
#include <tmmintrin.h>
|
|
|
|
#endif
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
namespace DX9
|
|
|
|
{
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
namespace D3D
|
|
|
|
{
|
|
|
|
|
2011-01-07 05:58:05 +00:00
|
|
|
void ConvertRGBA_BGRA_SSE2(u32 *dst, const int dstPitch, u32 *pIn, const int width, const int height, const int pitch)
|
|
|
|
{
|
|
|
|
// Converts RGBA to BGRA:
|
|
|
|
// TODO: this would be totally unnecessary if we just change the TextureDecoder_RGBA to decode
|
|
|
|
// to BGRA instead.
|
|
|
|
for (int y = 0; y < height; y++, pIn += pitch)
|
|
|
|
{
|
|
|
|
u8 *pIn8 = (u8 *)pIn;
|
|
|
|
u8 *pBits = (u8 *)((u8*)dst + (y * dstPitch));
|
|
|
|
|
|
|
|
// Batch up loads/stores into 16 byte chunks to use SSE2 efficiently:
|
|
|
|
int sse2blocks = (width * 4) / 16;
|
|
|
|
int sse2remainder = (width * 4) & 15;
|
|
|
|
|
|
|
|
// Do conversions in batches of 16 bytes:
|
|
|
|
if (sse2blocks > 0)
|
|
|
|
{
|
|
|
|
// Generate a constant of all FF bytes:
|
|
|
|
const __m128i allFFs128 = _mm_cmpeq_epi32(_mm_setzero_si128(), _mm_setzero_si128());
|
|
|
|
__m128i *src128 = (__m128i *)pIn8;
|
|
|
|
__m128i *dst128 = (__m128i *)pBits;
|
|
|
|
|
|
|
|
// Increment by 16 bytes at a time:
|
|
|
|
for (int i = 0; i < sse2blocks; ++i, ++dst128, ++src128)
|
|
|
|
{
|
|
|
|
// Load up 4 colors simultaneously:
|
|
|
|
__m128i rgba = _mm_loadu_si128(src128);
|
|
|
|
// Swap the R and B components:
|
|
|
|
// Isolate the B component and shift it left 16 bits:
|
|
|
|
// ABGR
|
|
|
|
const __m128i bMask = _mm_srli_epi32(allFFs128, 24);
|
|
|
|
const __m128i bNew = _mm_slli_epi32(_mm_and_si128(rgba, bMask), 16);
|
|
|
|
// Isolate the R component and shift it right 16 bits:
|
|
|
|
const __m128i rMask = _mm_slli_epi32(bMask, 16);
|
|
|
|
const __m128i rNew = _mm_srli_epi32(_mm_and_si128(rgba, rMask), 16);
|
|
|
|
// Now mask off the old R and B components from the rgba data to get 0g0a:
|
|
|
|
const __m128i _g_a = _mm_or_si128(
|
|
|
|
_mm_and_si128(
|
|
|
|
rgba,
|
|
|
|
_mm_or_si128(
|
|
|
|
_mm_slli_epi32(bMask, 8),
|
|
|
|
_mm_slli_epi32(rMask, 8)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
_mm_or_si128(rNew, bNew)
|
|
|
|
);
|
|
|
|
// Finally, OR up all the individual components to get BGRA:
|
|
|
|
const __m128i bgra = _mm_or_si128(_g_a, _mm_or_si128(rNew, bNew));
|
|
|
|
_mm_storeu_si128(dst128, bgra);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take the remainder colors at the end of the row that weren't able to
|
|
|
|
// be included into the last 16 byte chunk:
|
|
|
|
if (sse2remainder > 0)
|
|
|
|
{
|
|
|
|
for (int x = (sse2blocks * 16); x < (width * 4); x += 4)
|
|
|
|
{
|
|
|
|
pBits[x + 0] = pIn8[x + 2];
|
|
|
|
pBits[x + 1] = pIn8[x + 1];
|
|
|
|
pBits[x + 2] = pIn8[x + 0];
|
|
|
|
pBits[x + 3] = pIn8[x + 3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory fence to make sure the stores are good:
|
|
|
|
_mm_mfence();
|
|
|
|
}
|
|
|
|
|
2011-01-07 07:54:04 +00:00
|
|
|
void ConvertRGBA_BGRA_SSSE3(u32 *dst, const int dstPitch, u32 *pIn, const int width, const int height, const int pitch)
|
|
|
|
{
|
|
|
|
__m128i mask = _mm_set_epi8(15, 12, 13, 14, 11, 8, 9, 10, 7, 4, 5, 6, 3, 0, 1, 2);
|
|
|
|
for (int y = 0; y < height; y++, pIn += pitch)
|
|
|
|
{
|
|
|
|
u8 *pIn8 = (u8 *)pIn;
|
|
|
|
u8 *pBits = (u8 *)((u8*)dst + (y * dstPitch));
|
|
|
|
|
|
|
|
// Batch up loads/stores into 16 byte chunks to use SSE2 efficiently:
|
|
|
|
int ssse3blocks = (width * 4) / 16;
|
|
|
|
int ssse3remainder = (width * 4) & 15;
|
|
|
|
|
|
|
|
// Do conversions in batches of 16 bytes:
|
|
|
|
if (ssse3blocks > 0)
|
|
|
|
{
|
|
|
|
__m128i *src128 = (__m128i *)pIn8;
|
|
|
|
__m128i *dst128 = (__m128i *)pBits;
|
|
|
|
|
|
|
|
// Increment by 16 bytes at a time:
|
|
|
|
for (int i = 0; i < ssse3blocks; ++i, ++dst128, ++src128)
|
|
|
|
{
|
|
|
|
_mm_storeu_si128(dst128, _mm_shuffle_epi8(_mm_loadu_si128(src128), mask));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take the remainder colors at the end of the row that weren't able to
|
|
|
|
// be included into the last 16 byte chunk:
|
|
|
|
if (ssse3remainder > 0)
|
|
|
|
{
|
|
|
|
for (int x = (ssse3blocks * 16); x < (width * 4); x += 4)
|
|
|
|
{
|
|
|
|
pBits[x + 0] = pIn8[x + 2];
|
|
|
|
pBits[x + 1] = pIn8[x + 1];
|
|
|
|
pBits[x + 2] = pIn8[x + 0];
|
|
|
|
pBits[x + 3] = pIn8[x + 3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory fence to make sure the stores are good:
|
|
|
|
_mm_mfence();
|
|
|
|
}
|
2011-01-07 05:58:05 +00:00
|
|
|
|
2010-04-14 13:57:16 +00:00
|
|
|
LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt, bool swap_r_b, int levels)
|
2008-12-26 17:02:46 +00:00
|
|
|
{
|
|
|
|
u32* pBuffer = (u32*)buffer;
|
|
|
|
LPDIRECT3DTEXTURE9 pTexture;
|
|
|
|
|
|
|
|
// crazy bitmagic, sorry :)
|
|
|
|
bool isPow2 = !((width&(width-1)) || (height&(height-1)));
|
2009-02-13 14:14:45 +00:00
|
|
|
bool bExpand = false;
|
|
|
|
|
2009-09-01 19:48:45 +00:00
|
|
|
if (fmt == D3DFMT_A8P8) {
|
2009-02-13 14:14:45 +00:00
|
|
|
fmt = D3DFMT_A8L8;
|
|
|
|
bExpand = true;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2008-12-26 17:02:46 +00:00
|
|
|
HRESULT hr;
|
2010-04-14 13:57:16 +00:00
|
|
|
if (levels > 0)
|
|
|
|
hr = dev->CreateTexture(width, height, levels, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
|
2008-12-26 17:02:46 +00:00
|
|
|
else
|
|
|
|
hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-13 17:46:33 +00:00
|
|
|
if (FAILED(hr))
|
2008-12-26 17:02:46 +00:00
|
|
|
return 0;
|
|
|
|
int level = 0;
|
|
|
|
D3DLOCKED_RECT Lock;
|
2009-09-13 17:46:33 +00:00
|
|
|
pTexture->LockRect(level, &Lock, NULL, 0);
|
|
|
|
switch (fmt)
|
2008-12-26 17:02:46 +00:00
|
|
|
{
|
2009-02-12 13:54:08 +00:00
|
|
|
case D3DFMT_L8:
|
|
|
|
case D3DFMT_A8:
|
2009-02-14 09:04:40 +00:00
|
|
|
case D3DFMT_A4L4:
|
2009-02-12 13:54:08 +00:00
|
|
|
{
|
2009-09-01 19:48:45 +00:00
|
|
|
const u8 *pIn = buffer;
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
2009-02-12 13:54:08 +00:00
|
|
|
}
|
2009-09-01 19:48:45 +00:00
|
|
|
break;
|
2009-02-12 22:32:33 +00:00
|
|
|
case D3DFMT_R5G6B5:
|
|
|
|
{
|
|
|
|
const u16 *pIn = (u16*)buffer;
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width * 2);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-02-12 13:54:08 +00:00
|
|
|
case D3DFMT_A8L8:
|
|
|
|
{
|
2009-09-01 19:48:45 +00:00
|
|
|
if (bExpand) { // I8
|
2009-02-13 14:14:45 +00:00
|
|
|
const u8 *pIn = buffer;
|
|
|
|
// TODO(XK): Find a better way that does not involve either unpacking
|
|
|
|
// or downsampling (i.e. A4L4)
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
for(int i = 0; i < width * 2; i += 2) {
|
|
|
|
pBits[i] = pIn[i / 2];
|
|
|
|
pBits[i + 1] = pIn[i / 2];
|
|
|
|
}
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
} else { // IA8
|
|
|
|
const u16 *pIn = (u16*)buffer;
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width * 2);
|
|
|
|
pIn += pitch;
|
2009-02-12 13:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-12-26 17:02:46 +00:00
|
|
|
case D3DFMT_A8R8G8B8:
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-05-29 09:32:44 +00:00
|
|
|
if(pitch * 4 == Lock.Pitch && !swap_r_b)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-05-29 09:32:44 +00:00
|
|
|
memcpy(Lock.pBits,buffer,Lock.Pitch*height);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-12-07 18:48:31 +00:00
|
|
|
else
|
2010-05-29 09:32:44 +00:00
|
|
|
{
|
2009-12-07 18:48:31 +00:00
|
|
|
u32* pIn = pBuffer;
|
2010-05-02 14:05:14 +00:00
|
|
|
if (!swap_r_b) {
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width * 4);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-07 07:54:04 +00:00
|
|
|
#if _M_SSE >= 0x301
|
|
|
|
// Uses SSSE3 intrinsics to optimize RGBA -> BGRA swizzle:
|
2011-01-07 09:42:44 +00:00
|
|
|
if (cpu_info.bSSSE3) {
|
|
|
|
ConvertRGBA_BGRA_SSSE3((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
|
|
|
|
} else
|
2011-01-07 07:54:04 +00:00
|
|
|
#endif
|
2011-01-07 09:42:44 +00:00
|
|
|
// Uses SSE2 intrinsics to optimize RGBA -> BGRA swizzle:
|
|
|
|
{
|
|
|
|
ConvertRGBA_BGRA_SSE2((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
|
|
|
|
}
|
2011-01-07 07:54:04 +00:00
|
|
|
#if 0
|
2010-05-02 14:05:14 +00:00
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8 *pIn8 = (u8 *)pIn;
|
|
|
|
u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
for (int x = 0; x < width * 4; x += 4) {
|
|
|
|
pBits[x + 0] = pIn8[x + 2];
|
|
|
|
pBits[x + 1] = pIn8[x + 1];
|
|
|
|
pBits[x + 2] = pIn8[x + 0];
|
|
|
|
pBits[x + 3] = pIn8[x + 3];
|
|
|
|
}
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
2011-01-07 05:58:05 +00:00
|
|
|
#endif
|
2009-12-07 18:48:31 +00:00
|
|
|
}
|
2010-05-29 09:32:44 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
break;
|
|
|
|
case D3DFMT_DXT1:
|
2010-02-03 14:13:03 +00:00
|
|
|
memcpy(Lock.pBits,buffer,((width+3)/4)*((height+3)/4)*8);
|
2008-12-26 17:02:46 +00:00
|
|
|
break;
|
2009-09-01 19:48:45 +00:00
|
|
|
default:
|
|
|
|
PanicAlert("D3D: Invalid texture format %i", fmt);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
pTexture->UnlockRect(level);
|
|
|
|
return pTexture;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-12-07 18:48:31 +00:00
|
|
|
LPDIRECT3DTEXTURE9 CreateOnlyTexture2D(const int width, const int height, D3DFORMAT fmt)
|
|
|
|
{
|
|
|
|
LPDIRECT3DTEXTURE9 pTexture;
|
|
|
|
// crazy bitmagic, sorry :)
|
|
|
|
bool isPow2 = !((width&(width-1)) || (height&(height-1)));
|
|
|
|
bool bExpand = false;
|
|
|
|
HRESULT hr;
|
|
|
|
// TODO(ector): Allow mipmaps for non-pow textures on newer cards?
|
|
|
|
// TODO(ector): Use the game-specified mipmaps?
|
|
|
|
if (!isPow2)
|
|
|
|
hr = dev->CreateTexture(width, height, 1, 0, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
|
|
|
|
else
|
|
|
|
hr = dev->CreateTexture(width, height, 0, D3DUSAGE_AUTOGENMIPMAP, fmt, D3DPOOL_MANAGED, &pTexture, NULL);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return 0;
|
|
|
|
return pTexture;
|
|
|
|
}
|
|
|
|
|
2010-04-14 13:57:16 +00:00
|
|
|
void ReplaceTexture2D(LPDIRECT3DTEXTURE9 pTexture, const u8* buffer, const int width, const int height, const int pitch, D3DFORMAT fmt, bool swap_r_b, int level)
|
2008-12-26 17:02:46 +00:00
|
|
|
{
|
|
|
|
u32* pBuffer = (u32*)buffer;
|
|
|
|
D3DLOCKED_RECT Lock;
|
2009-09-01 19:48:45 +00:00
|
|
|
pTexture->LockRect(level, &Lock, NULL, 0);
|
2008-12-26 17:02:46 +00:00
|
|
|
u32* pIn = pBuffer;
|
2009-09-19 13:14:55 +00:00
|
|
|
|
|
|
|
bool bExpand = false;
|
|
|
|
|
|
|
|
if (fmt == D3DFMT_A8P8) {
|
|
|
|
fmt = D3DFMT_A8L8;
|
|
|
|
bExpand = true;
|
|
|
|
}
|
2010-01-21 19:31:48 +00:00
|
|
|
switch (fmt)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2008-12-26 17:02:46 +00:00
|
|
|
case D3DFMT_A8R8G8B8:
|
2010-05-29 09:32:44 +00:00
|
|
|
if(pitch * 4 == Lock.Pitch && !swap_r_b)
|
|
|
|
{
|
|
|
|
memcpy(Lock.pBits, pBuffer, Lock.Pitch*height);
|
|
|
|
}
|
|
|
|
else if (!swap_r_b)
|
|
|
|
{
|
2008-12-26 17:02:46 +00:00
|
|
|
for (int y = 0; y < height; y++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-01-21 19:31:48 +00:00
|
|
|
u32 *pBits = (u32*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
2008-12-26 17:02:46 +00:00
|
|
|
memcpy(pBits, pIn, width * 4);
|
|
|
|
pIn += pitch;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2010-05-29 09:32:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-07 07:54:04 +00:00
|
|
|
#if _M_SSE >= 0x301
|
|
|
|
// Uses SSSE3 intrinsics to optimize RGBA -> BGRA swizzle:
|
2011-01-07 09:42:44 +00:00
|
|
|
if (cpu_info.bSSSE3) {
|
|
|
|
ConvertRGBA_BGRA_SSSE3((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
|
|
|
|
} else
|
2011-01-07 07:54:04 +00:00
|
|
|
#endif
|
2011-01-07 09:42:44 +00:00
|
|
|
// Uses SSE2 intrinsics to optimize RGBA -> BGRA swizzle:
|
|
|
|
{
|
|
|
|
ConvertRGBA_BGRA_SSE2((u32 *)Lock.pBits, Lock.Pitch, pIn, width, height, pitch);
|
|
|
|
}
|
2011-01-07 07:54:04 +00:00
|
|
|
#if 0
|
2010-01-21 19:31:48 +00:00
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8 *pIn8 = (u8 *)pIn;
|
|
|
|
u8 *pBits = (u8 *)((u8*)Lock.pBits + (y * Lock.Pitch));
|
2010-05-29 09:32:44 +00:00
|
|
|
for (int x = 0; x < width * 4; x += 4)
|
|
|
|
{
|
2010-01-21 19:31:48 +00:00
|
|
|
pBits[x + 0] = pIn8[x + 2];
|
|
|
|
pBits[x + 1] = pIn8[x + 1];
|
|
|
|
pBits[x + 2] = pIn8[x + 0];
|
|
|
|
pBits[x + 3] = pIn8[x + 3];
|
|
|
|
}
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
2011-01-07 05:58:05 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
break;
|
2009-09-19 13:14:55 +00:00
|
|
|
case D3DFMT_L8:
|
|
|
|
case D3DFMT_A8:
|
|
|
|
case D3DFMT_A4L4:
|
|
|
|
{
|
|
|
|
const u8 *pIn = buffer;
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case D3DFMT_R5G6B5:
|
|
|
|
{
|
|
|
|
const u16 *pIn = (u16*)buffer;
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width * 2);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case D3DFMT_A8L8:
|
|
|
|
{
|
|
|
|
if (bExpand) { // I8
|
|
|
|
const u8 *pIn = buffer;
|
|
|
|
// TODO(XK): Find a better way that does not involve either unpacking
|
|
|
|
// or downsampling (i.e. A4L4)
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
for(int i = 0; i < width * 2; i += 2) {
|
|
|
|
pBits[i] = pIn[i / 2];
|
|
|
|
pBits[i + 1] = pIn[i / 2];
|
|
|
|
}
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
} else { // IA8
|
|
|
|
const u16 *pIn = (u16*)buffer;
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch));
|
|
|
|
memcpy(pBits, pIn, width * 2);
|
|
|
|
pIn += pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-12-26 17:02:46 +00:00
|
|
|
case D3DFMT_DXT1:
|
2010-02-03 14:13:03 +00:00
|
|
|
memcpy(Lock.pBits,buffer,((width+3)/4)*((height+3)/4)*8);
|
2008-12-26 17:02:46 +00:00
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
pTexture->UnlockRect(level);
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2008-12-26 17:02:46 +00:00
|
|
|
} // namespace
|
2011-01-29 20:16:51 +00:00
|
|
|
|
|
|
|
} // namespace DX9
|