image loading reworked
This commit is contained in:
1573
src/EterImageLib/DDSTextureLoader9.cpp
Normal file
1573
src/EterImageLib/DDSTextureLoader9.cpp
Normal file
File diff suppressed because it is too large
Load Diff
145
src/EterImageLib/DDSTextureLoader9.h
Normal file
145
src/EterImageLib/DDSTextureLoader9.h
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
// File: DDSTextureLoader9.h
|
||||||
|
//
|
||||||
|
// Functions for loading a DDS texture and creating a Direct3D runtime resource for it
|
||||||
|
//
|
||||||
|
// Note these functions are useful as a light-weight runtime loader for DDS files. For
|
||||||
|
// a full-featured DDS file reader, writer, and texture processing pipeline see
|
||||||
|
// the 'Texconv' sample and the 'DirectXTex' library.
|
||||||
|
//
|
||||||
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
//
|
||||||
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef DIRECT3D_VERSION
|
||||||
|
#define DIRECT3D_VERSION 0x900
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <d3d9.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectX
|
||||||
|
{
|
||||||
|
// Standard version
|
||||||
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_Outptr_ LPDIRECT3DBASETEXTURE9* texture,
|
||||||
|
bool generateMipsIfMissing = false) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_Outptr_ LPDIRECT3DBASETEXTURE9* texture,
|
||||||
|
bool generateMipsIfMissing = false) noexcept;
|
||||||
|
|
||||||
|
// Extended version
|
||||||
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
bool generateMipsIfMissing,
|
||||||
|
_Outptr_ LPDIRECT3DBASETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
bool generateMipsIfMissing,
|
||||||
|
_Outptr_ LPDIRECT3DBASETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
// Type-specific standard versions
|
||||||
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_Outptr_ LPDIRECT3DTEXTURE9* texture,
|
||||||
|
bool generateMipsIfMissing = false) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_Outptr_ LPDIRECT3DTEXTURE9* texture,
|
||||||
|
bool generateMipsIfMissing = false) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_Outptr_ LPDIRECT3DCUBETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_Outptr_ LPDIRECT3DCUBETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromMemory(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_Outptr_ LPDIRECT3DVOLUMETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFile(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_Outptr_ LPDIRECT3DVOLUMETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
// Type-specific extended versions
|
||||||
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
bool generateMipsIfMissing,
|
||||||
|
_Outptr_ LPDIRECT3DTEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
bool generateMipsIfMissing,
|
||||||
|
_Outptr_ LPDIRECT3DTEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
_Outptr_ LPDIRECT3DCUBETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
_Outptr_ LPDIRECT3DCUBETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromMemoryEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
|
||||||
|
_In_ size_t ddsDataSize,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
_Outptr_ LPDIRECT3DVOLUMETEXTURE9* texture) noexcept;
|
||||||
|
|
||||||
|
HRESULT CreateDDSTextureFromFileEx(
|
||||||
|
_In_ LPDIRECT3DDEVICE9 d3dDevice,
|
||||||
|
_In_z_ const wchar_t* fileName,
|
||||||
|
_In_ DWORD usage,
|
||||||
|
_In_ D3DPOOL pool,
|
||||||
|
_Outptr_ LPDIRECT3DVOLUMETEXTURE9* texture) noexcept;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,143 +0,0 @@
|
|||||||
#ifndef AFX_IMAGE_DXTC_H__4B89D8D0_7857_11D4_9630_00A0C996DE3D__INCLUDED_
|
|
||||||
#define AFX_IMAGE_DXTC_H__4B89D8D0_7857_11D4_9630_00A0C996DE3D__INCLUDED_
|
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
|
||||||
#pragma once
|
|
||||||
#endif // _MSC_VER > 1000
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
enum EPixFormat
|
|
||||||
{
|
|
||||||
PF_ARGB,
|
|
||||||
PF_DXT1,
|
|
||||||
PF_DXT2,
|
|
||||||
PF_DXT3,
|
|
||||||
PF_DXT4,
|
|
||||||
PF_DXT5,
|
|
||||||
PF_UNKNOWN
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_MIPLEVELS 12
|
|
||||||
|
|
||||||
#ifndef DUMMYUNIONNAMEN
|
|
||||||
#if defined(__cplusplus) || !defined(NONAMELESSUNION)
|
|
||||||
#define DUMMYUNIONNAMEN(n)
|
|
||||||
#else
|
|
||||||
#define DUMMYUNIONNAMEN(n) u##n
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct _XDDPIXELFORMAT
|
|
||||||
{
|
|
||||||
DWORD dwSize; // size of structure
|
|
||||||
DWORD dwFlags; // pixel format flags
|
|
||||||
DWORD dwFourCC; // (FOURCC code)
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
DWORD dwRGBBitCount; // how many bits per pixel
|
|
||||||
DWORD dwYUVBitCount; // how many bits per pixel
|
|
||||||
DWORD dwZBufferBitDepth; // how many total bits/pixel in z buffer (including any stencil bits)
|
|
||||||
DWORD dwAlphaBitDepth; // how many bits for alpha channels
|
|
||||||
DWORD dwLuminanceBitCount; // how many bits per pixel
|
|
||||||
DWORD dwBumpBitCount; // how many bits per "buxel", total
|
|
||||||
DWORD dwPrivateFormatBitCount;// Bits per pixel of private driver formats. Only valid in texture
|
|
||||||
// format list and if DDPF_D3DFORMAT is set
|
|
||||||
} DUMMYUNIONNAMEN(1);
|
|
||||||
union
|
|
||||||
{
|
|
||||||
DWORD dwRBitMask; // mask for red bit
|
|
||||||
DWORD dwYBitMask; // mask for Y bits
|
|
||||||
DWORD dwStencilBitDepth; // how many stencil bits (note: dwZBufferBitDepth-dwStencilBitDepth is total Z-only bits)
|
|
||||||
DWORD dwLuminanceBitMask; // mask for luminance bits
|
|
||||||
DWORD dwBumpDuBitMask; // mask for bump map U delta bits
|
|
||||||
DWORD dwOperations; // DDPF_D3DFORMAT Operations
|
|
||||||
} DUMMYUNIONNAMEN(2);
|
|
||||||
union
|
|
||||||
{
|
|
||||||
DWORD dwGBitMask; // mask for green bits
|
|
||||||
DWORD dwUBitMask; // mask for U bits
|
|
||||||
DWORD dwZBitMask; // mask for Z bits
|
|
||||||
DWORD dwBumpDvBitMask; // mask for bump map V delta bits
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
WORD wFlipMSTypes; // Multisample methods supported via flip for this D3DFORMAT
|
|
||||||
WORD wBltMSTypes; // Multisample methods supported via blt for this D3DFORMAT
|
|
||||||
} MultiSampleCaps;
|
|
||||||
|
|
||||||
} DUMMYUNIONNAMEN(3);
|
|
||||||
union
|
|
||||||
{
|
|
||||||
DWORD dwBBitMask; // mask for blue bits
|
|
||||||
DWORD dwVBitMask; // mask for V bits
|
|
||||||
DWORD dwStencilBitMask; // mask for stencil bits
|
|
||||||
DWORD dwBumpLuminanceBitMask; // mask for luminance in bump map
|
|
||||||
} DUMMYUNIONNAMEN(4);
|
|
||||||
union
|
|
||||||
{
|
|
||||||
DWORD dwRGBAlphaBitMask; // mask for alpha channel
|
|
||||||
DWORD dwYUVAlphaBitMask; // mask for alpha channel
|
|
||||||
DWORD dwLuminanceAlphaBitMask;// mask for alpha channel
|
|
||||||
DWORD dwRGBZBitMask; // mask for Z channel
|
|
||||||
DWORD dwYUVZBitMask; // mask for Z channel
|
|
||||||
} DUMMYUNIONNAMEN(5);
|
|
||||||
} XDDPIXELFORMAT;
|
|
||||||
|
|
||||||
|
|
||||||
class CDXTCImage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CDXTCImage();
|
|
||||||
virtual ~CDXTCImage();
|
|
||||||
|
|
||||||
void Initialize();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
public:
|
|
||||||
const BYTE * m_pbCompBufferByLevels[MAX_MIPLEVELS];
|
|
||||||
std::vector<BYTE> m_bCompVector[MAX_MIPLEVELS];
|
|
||||||
|
|
||||||
int m_nCompSize;
|
|
||||||
int m_nCompLineSz;
|
|
||||||
|
|
||||||
char m_strFormat[32];
|
|
||||||
EPixFormat m_CompFormat;
|
|
||||||
|
|
||||||
long m_lPitch;
|
|
||||||
DWORD m_dwMipMapCount;
|
|
||||||
bool m_bMipTexture; // texture has mipmaps?
|
|
||||||
DWORD m_dwFlags;
|
|
||||||
|
|
||||||
int m_nWidth; // in pixels of uncompressed image
|
|
||||||
int m_nHeight;
|
|
||||||
|
|
||||||
XDDPIXELFORMAT m_xddPixelFormat;
|
|
||||||
|
|
||||||
bool LoadFromFile(const char * filename); // true if success
|
|
||||||
bool LoadFromMemory(const BYTE * c_pbMap);
|
|
||||||
bool LoadHeaderFromMemory(const BYTE * c_pbMap);
|
|
||||||
bool Copy(int miplevel, BYTE * pbDest, long lDestPitch);
|
|
||||||
|
|
||||||
void Decompress(int miplevel, DWORD * pdwDest);
|
|
||||||
void DecompressDXT1(int miplevel, DWORD * pdwDest);
|
|
||||||
void DecompressDXT3(int miplevel, DWORD * pdwDest);
|
|
||||||
void DecompressDXT5(int miplevel, DWORD * pdwDest);
|
|
||||||
void DecompressARGB(int miplevel, DWORD * pdwDest);
|
|
||||||
|
|
||||||
VOID DecodePixelFormat(CHAR* strPixelFormat, XDDPIXELFORMAT* pddpf);
|
|
||||||
|
|
||||||
void Unextract(BYTE * pbDest, int iWidth, int iHeight, int iPitch);
|
|
||||||
/*
|
|
||||||
struct TimingInfo; // defined in Image_DXTC.cpp
|
|
||||||
void RunTimingSession(); // run a few methods & time the code
|
|
||||||
|
|
||||||
// must use dxt5 texture
|
|
||||||
void Time_Decomp5_01(int ntimes, TimingInfo * info);
|
|
||||||
void Time_Decomp5_02(int ntimes, TimingInfo * info);
|
|
||||||
void Time_Decomp5_03(int ntimes, TimingInfo * info);
|
|
||||||
void Time_Decomp5_04(int ntimes, TimingInfo * info);
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // #ifndef AFX_IMAGE_DXTC_H__4B89D8D0_7857_11D4_9630_00A0C996DE3D__INCLUDED_
|
|
||||||
7
src/EterImageLib/STBImageImplementation.cpp
Normal file
7
src/EterImageLib/STBImageImplementation.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "StdAfx.h"
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
|
#include <stb_image.h>
|
||||||
|
#include <stb_image_write.h>
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
#include "StdAfx.h"
|
#include "StdAfx.h"
|
||||||
#include "../eterBase/MappedFile.h"
|
#include "EterBase/MappedFile.h"
|
||||||
#include "../eterPack/EterPackManager.h"
|
#include "EterPack/EterPackManager.h"
|
||||||
#include "GrpImageTexture.h"
|
#include "GrpImageTexture.h"
|
||||||
|
#include "EterImageLib/DDSTextureLoader9.h"
|
||||||
|
|
||||||
|
#include <stb_image.h>
|
||||||
|
|
||||||
bool CGraphicImageTexture::Lock(int* pRetPitch, void** ppRetPixels, int level)
|
bool CGraphicImageTexture::Lock(int* pRetPitch, void** ppRetPixels, int level)
|
||||||
{
|
{
|
||||||
@@ -76,130 +79,66 @@ bool CGraphicImageTexture::Create(UINT width, UINT height, D3DFORMAT d3dFmt, DWO
|
|||||||
return CreateDeviceObjects();
|
return CreateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphicImageTexture::CreateFromTexturePointer(const CGraphicTexture * c_pSrcTexture)
|
void CGraphicImageTexture::CreateFromTexturePointer(const CGraphicTexture* c_pSrcTexture)
|
||||||
{
|
{
|
||||||
if (m_lpd3dTexture)
|
if (m_lpd3dTexture)
|
||||||
m_lpd3dTexture->Release();
|
m_lpd3dTexture->Release();
|
||||||
|
|
||||||
m_width = c_pSrcTexture->GetWidth();
|
m_width = c_pSrcTexture->GetWidth();
|
||||||
m_height = c_pSrcTexture->GetHeight();
|
m_height = c_pSrcTexture->GetHeight();
|
||||||
m_lpd3dTexture = c_pSrcTexture->GetD3DTexture();
|
m_lpd3dTexture = c_pSrcTexture->GetD3DTexture();
|
||||||
|
|
||||||
if (m_lpd3dTexture)
|
if (m_lpd3dTexture)
|
||||||
m_lpd3dTexture->AddRef();
|
m_lpd3dTexture->AddRef();
|
||||||
|
|
||||||
m_bEmpty = false;
|
m_bEmpty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c_pbBuf*/)
|
bool CGraphicImageTexture::CreateFromDDSTexture(UINT bufSize, const void* c_pvBuf)
|
||||||
{
|
{
|
||||||
int mipmapCount = image.m_dwMipMapCount == 0 ? 1 : image.m_dwMipMapCount;
|
if (FAILED(DirectX::CreateDDSTextureFromMemoryEx(ms_lpd3dDevice, reinterpret_cast<const uint8_t*>(c_pvBuf), bufSize, 0, D3DPOOL_MANAGED, false, &m_lpd3dTexture)))
|
||||||
|
|
||||||
D3DFORMAT format;
|
|
||||||
LPDIRECT3DTEXTURE9 lpd3dTexture;
|
|
||||||
D3DPOOL pool = ms_bSupportDXT ? D3DPOOL_MANAGED : D3DPOOL_SCRATCH;;
|
|
||||||
|
|
||||||
if(image.m_CompFormat == PF_DXT5)
|
|
||||||
format = D3DFMT_DXT5;
|
|
||||||
else if(image.m_CompFormat == PF_DXT3)
|
|
||||||
format = D3DFMT_DXT3;
|
|
||||||
else
|
|
||||||
format = D3DFMT_DXT1;
|
|
||||||
|
|
||||||
UINT uTexBias=0;
|
|
||||||
if (IsLowTextureMemory())
|
|
||||||
uTexBias=1;
|
|
||||||
|
|
||||||
UINT uMinMipMapIndex=0;
|
|
||||||
if (uTexBias>0)
|
|
||||||
{
|
|
||||||
if (mipmapCount>uTexBias)
|
|
||||||
{
|
|
||||||
uMinMipMapIndex=uTexBias;
|
|
||||||
image.m_nWidth>>=uTexBias;
|
|
||||||
image.m_nHeight>>=uTexBias;
|
|
||||||
mipmapCount-=uTexBias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(D3DXCreateTexture( ms_lpd3dDevice, image.m_nWidth, image.m_nHeight,
|
|
||||||
mipmapCount, 0, format, pool, &lpd3dTexture)))
|
|
||||||
{
|
|
||||||
TraceError("CreateDDSTexture: Cannot creatre texture");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
for (DWORD i = 0; i < mipmapCount; ++i)
|
D3DSURFACE_DESC desc;
|
||||||
{
|
m_lpd3dTexture->GetLevelDesc(0, &desc);
|
||||||
D3DLOCKED_RECT lockedRect;
|
m_width = desc.Width;
|
||||||
|
m_height = desc.Height;
|
||||||
|
m_bEmpty = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (FAILED(lpd3dTexture->LockRect(i, &lockedRect, NULL, 0)))
|
bool CGraphicImageTexture::CreateFromSTB(UINT bufSize, const void* c_pvBuf)
|
||||||
{
|
{
|
||||||
TraceError("CreateDDSTexture: Cannot lock texture");
|
int width, height, channels;
|
||||||
}
|
unsigned char* data = stbi_load_from_memory((stbi_uc*)c_pvBuf, bufSize, &width, &height, &channels, 4); // force RGBA
|
||||||
else
|
if (data) {
|
||||||
{
|
LPDIRECT3DTEXTURE9 texture;
|
||||||
image.Copy(i+uMinMipMapIndex, (BYTE*)lockedRect.pBits, lockedRect.Pitch);
|
if (SUCCEEDED(ms_lpd3dDevice->CreateTexture(width, height, 1, 0, channels == 4 ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, nullptr))) {
|
||||||
lpd3dTexture->UnlockRect(i);
|
D3DLOCKED_RECT rect;
|
||||||
}
|
if (SUCCEEDED(texture->LockRect(0, &rect, nullptr, 0))) {
|
||||||
}
|
uint8_t* dstData = (uint8_t*)rect.pBits;
|
||||||
|
uint8_t* srcData = (uint8_t*)data;
|
||||||
if(ms_bSupportDXT)
|
for (size_t i = 0; i < width * height; ++i, dstData += 4, srcData += 4) {
|
||||||
{
|
dstData[0] = srcData[2];
|
||||||
m_lpd3dTexture = lpd3dTexture;
|
dstData[1] = srcData[1];
|
||||||
}
|
dstData[2] = srcData[0];
|
||||||
else
|
dstData[3] = srcData[3];
|
||||||
{
|
|
||||||
if(image.m_CompFormat == PF_DXT3 || image.m_CompFormat == PF_DXT5)
|
|
||||||
format = D3DFMT_A4R4G4B4;
|
|
||||||
else
|
|
||||||
format = D3DFMT_A1R5G5B5;
|
|
||||||
|
|
||||||
UINT imgWidth=image.m_nWidth;
|
|
||||||
UINT imgHeight=image.m_nHeight;
|
|
||||||
|
|
||||||
extern bool GRAPHICS_CAPS_HALF_SIZE_IMAGE;
|
|
||||||
|
|
||||||
if (GRAPHICS_CAPS_HALF_SIZE_IMAGE && uTexBias>0 && mipmapCount==0)
|
|
||||||
{
|
|
||||||
imgWidth>>=uTexBias;
|
|
||||||
imgHeight>>=uTexBias;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(D3DXCreateTexture( ms_lpd3dDevice, imgWidth, imgHeight,
|
|
||||||
mipmapCount, 0, format, D3DPOOL_MANAGED, &m_lpd3dTexture)))
|
|
||||||
{
|
|
||||||
TraceError("CreateDDSTexture: Cannot creatre texture");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDirect3DTexture9* pkTexSrc=lpd3dTexture;
|
|
||||||
IDirect3DTexture9* pkTexDst=m_lpd3dTexture;
|
|
||||||
|
|
||||||
for(int i=0; i<mipmapCount; ++i) {
|
|
||||||
|
|
||||||
IDirect3DSurface9* ppsSrc = NULL;
|
|
||||||
IDirect3DSurface9* ppsDst = NULL;
|
|
||||||
|
|
||||||
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
|
|
||||||
{
|
|
||||||
if (SUCCEEDED(pkTexDst->GetSurfaceLevel(i, &ppsDst)))
|
|
||||||
{
|
|
||||||
D3DXLoadSurfaceFromSurface(ppsDst, NULL, NULL, ppsSrc, NULL, NULL, D3DX_FILTER_NONE, 0);
|
|
||||||
ppsDst->Release();
|
|
||||||
}
|
}
|
||||||
ppsSrc->Release();
|
|
||||||
|
texture->UnlockRect(0);
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
m_bEmpty = false;
|
||||||
|
m_lpd3dTexture = texture;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
texture->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stbi_image_free(data);
|
||||||
lpd3dTexture->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_width = image.m_nWidth;
|
return !m_bEmpty;
|
||||||
m_height = image.m_nHeight;
|
|
||||||
m_bEmpty = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter)
|
bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter)
|
||||||
@@ -207,41 +146,24 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB
|
|||||||
assert(ms_lpd3dDevice != NULL);
|
assert(ms_lpd3dDevice != NULL);
|
||||||
assert(m_lpd3dTexture == NULL);
|
assert(m_lpd3dTexture == NULL);
|
||||||
|
|
||||||
static CDXTCImage image;
|
m_bEmpty = true;
|
||||||
|
|
||||||
if (image.LoadHeaderFromMemory((const BYTE *) c_pvBuf)) // DDS인가 확인
|
if (!CreateFromDDSTexture(bufSize, c_pvBuf)) {
|
||||||
{
|
if (!CreateFromSTB(bufSize, c_pvBuf)) {
|
||||||
return (CreateDDSTexture(image, (const BYTE *) c_pvBuf));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
D3DXIMAGE_INFO imageInfo;
|
|
||||||
if (FAILED(D3DXCreateTextureFromFileInMemoryEx(
|
|
||||||
ms_lpd3dDevice,
|
|
||||||
c_pvBuf,
|
|
||||||
bufSize,
|
|
||||||
D3DX_DEFAULT,
|
|
||||||
D3DX_DEFAULT,
|
|
||||||
D3DX_DEFAULT,
|
|
||||||
0,
|
|
||||||
d3dFmt,
|
|
||||||
D3DPOOL_MANAGED,
|
|
||||||
dwFilter,
|
|
||||||
dwFilter,
|
|
||||||
0xffff00ff,
|
|
||||||
&imageInfo,
|
|
||||||
NULL,
|
|
||||||
&m_lpd3dTexture)))
|
|
||||||
{
|
|
||||||
TraceError("CreateFromMemoryFile: Cannot create texture");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_width = imageInfo.Width;
|
D3DXIMAGE_INFO imageInfo;
|
||||||
m_height = imageInfo.Height;
|
if (FAILED(D3DXCreateTextureFromFileInMemoryEx(ms_lpd3dDevice, c_pvBuf, bufSize
|
||||||
|
, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT, 0, d3dFmt, D3DPOOL_MANAGED
|
||||||
|
, dwFilter, dwFilter, 0xffff00ff, &imageInfo, NULL, &m_lpd3dTexture))) {
|
||||||
|
TraceError("CreateFromMemoryFile: Cannot create texture");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
D3DFORMAT format=imageInfo.Format;
|
m_width = imageInfo.Width;
|
||||||
switch(imageInfo.Format) {
|
m_height = imageInfo.Height;
|
||||||
|
|
||||||
|
D3DFORMAT format = imageInfo.Format;
|
||||||
|
switch (imageInfo.Format) {
|
||||||
case D3DFMT_A8R8G8B8:
|
case D3DFMT_A8R8G8B8:
|
||||||
format = D3DFMT_A4R4G4B4;
|
format = D3DFMT_A4R4G4B4;
|
||||||
break;
|
break;
|
||||||
@@ -250,50 +172,41 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB
|
|||||||
case D3DFMT_R8G8B8:
|
case D3DFMT_R8G8B8:
|
||||||
format = D3DFMT_A1R5G5B5;
|
format = D3DFMT_A1R5G5B5;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT uTexBias=0;
|
UINT uTexBias = 0;
|
||||||
|
|
||||||
extern bool GRAPHICS_CAPS_HALF_SIZE_IMAGE;
|
extern bool GRAPHICS_CAPS_HALF_SIZE_IMAGE;
|
||||||
if (GRAPHICS_CAPS_HALF_SIZE_IMAGE)
|
if (GRAPHICS_CAPS_HALF_SIZE_IMAGE)
|
||||||
uTexBias=1;
|
uTexBias = 1;
|
||||||
|
|
||||||
if (IsLowTextureMemory())
|
if (IsLowTextureMemory()) {
|
||||||
if (uTexBias || format!=imageInfo.Format)
|
if (uTexBias || format != imageInfo.Format) {
|
||||||
{
|
IDirect3DTexture9* pkTexSrc = m_lpd3dTexture;
|
||||||
IDirect3DTexture9* pkTexSrc=m_lpd3dTexture;
|
IDirect3DTexture9* pkTexDst;
|
||||||
IDirect3DTexture9* pkTexDst;
|
|
||||||
|
|
||||||
|
|
||||||
if (SUCCEEDED(D3DXCreateTexture(
|
|
||||||
ms_lpd3dDevice,
|
|
||||||
imageInfo.Width>>uTexBias,
|
|
||||||
imageInfo.Height>>uTexBias,
|
|
||||||
imageInfo.MipLevels,
|
|
||||||
0,
|
|
||||||
format,
|
|
||||||
D3DPOOL_MANAGED,
|
|
||||||
&pkTexDst)))
|
|
||||||
{
|
|
||||||
m_lpd3dTexture=pkTexDst;
|
|
||||||
|
|
||||||
for(int i=0; i<imageInfo.MipLevels; ++i) {
|
|
||||||
|
|
||||||
IDirect3DSurface9* ppsSrc = NULL;
|
|
||||||
IDirect3DSurface9* ppsDst = NULL;
|
|
||||||
|
|
||||||
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
|
if (SUCCEEDED(D3DXCreateTexture(ms_lpd3dDevice
|
||||||
{
|
, imageInfo.Width >> uTexBias, imageInfo.Height >> uTexBias
|
||||||
if (SUCCEEDED(pkTexDst->GetSurfaceLevel(i, &ppsDst)))
|
, imageInfo.MipLevels, 0, format, D3DPOOL_MANAGED, &pkTexDst))) {
|
||||||
{
|
m_lpd3dTexture = pkTexDst;
|
||||||
D3DXLoadSurfaceFromSurface(ppsDst, NULL, NULL, ppsSrc, NULL, NULL, D3DX_FILTER_LINEAR, 0);
|
for (int i = 0; i < imageInfo.MipLevels; ++i) {
|
||||||
ppsDst->Release();
|
|
||||||
|
IDirect3DSurface9* ppsSrc = NULL;
|
||||||
|
IDirect3DSurface9* ppsDst = NULL;
|
||||||
|
|
||||||
|
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc))) {
|
||||||
|
if (SUCCEEDED(pkTexDst->GetSurfaceLevel(i, &ppsDst))) {
|
||||||
|
D3DXLoadSurfaceFromSurface(ppsDst, NULL, NULL, ppsSrc, NULL, NULL, D3DX_FILTER_LINEAR, 0);
|
||||||
|
ppsDst->Release();
|
||||||
|
}
|
||||||
|
ppsSrc->Release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ppsSrc->Release();
|
|
||||||
|
pkTexSrc->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pkTexSrc->Release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GrpTexture.h"
|
#include "GrpTexture.h"
|
||||||
#include "../eterImageLib/DXTCImage.h"
|
|
||||||
|
|
||||||
class CGraphicImageTexture : public CGraphicTexture
|
class CGraphicImageTexture : public CGraphicTexture
|
||||||
{
|
{
|
||||||
@@ -17,7 +16,8 @@ class CGraphicImageTexture : public CGraphicTexture
|
|||||||
void CreateFromTexturePointer(const CGraphicTexture* c_pSrcTexture);
|
void CreateFromTexturePointer(const CGraphicTexture* c_pSrcTexture);
|
||||||
bool CreateFromDiskFile(const char* c_szFileName, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
|
bool CreateFromDiskFile(const char* c_szFileName, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
|
||||||
bool CreateFromMemoryFile(UINT bufSize, const void* c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
|
bool CreateFromMemoryFile(UINT bufSize, const void* c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
|
||||||
bool CreateDDSTexture(CDXTCImage & image, const BYTE * c_pbBuf);
|
bool CreateFromDDSTexture(UINT bufSize, const void* c_pvBuf);
|
||||||
|
bool CreateFromSTB(UINT bufSize, const void* c_pvBuf);
|
||||||
|
|
||||||
void SetFileName(const char * c_szFileName);
|
void SetFileName(const char * c_szFileName);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "MarkImage.h"
|
#include "MarkImage.h"
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#include <stb_image.h>
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#include <stb_image_write.h>
|
||||||
#include "stb_image.h"
|
|
||||||
#include "stb_image_write.h"
|
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
#include <IL/il.h>
|
#include <IL/il.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user