Commit 67c5a086 authored by D-AIRY's avatar D-AIRY

dds texture loader plugin

parent 0413941e
......@@ -146,7 +146,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
......@@ -167,7 +167,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
......
......@@ -146,7 +146,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
......@@ -167,7 +167,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level1</WarningLevel>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
......
......@@ -292,7 +292,7 @@ QT стиль документирования (!) и QT_AUTOBRIEF - корот
#ifndef __SKYXENGINE_H
#define __SKYXENGINE_H
#define SKYXENGINE_VERSION "X.3.4"
#define SKYXENGINE_VERSION "X.4.0-dev"
#define SKYXENGINE_VERSION4EDITORS "SkyXEngine version " ## SKYXENGINE_VERSION
......
......@@ -14,6 +14,7 @@
#include <GRegisterIndex.h>
#include <xcommon/IXTextureLoader.h>
#include "ResourceTexture.h"
extern CTimeManager *g_pTimers;
extern CPerfMon *g_pPerfMon;
......@@ -82,15 +83,50 @@ CCore::CCore(const char *szName)
}
loadPlugins();
#if 1
#if 0
IXTextureLoader *pLoader = (IXTextureLoader*)m_pPluginManager->getInterface(IXTEXTURELOADER_GUID);
if(pLoader->open("textures/tp/tp_sga_window_center_up.dds", ""))
/*if(pLoader->open("textures/tp/tp_sga_window_center_up.dds", ""))
{
CResourceTexture2D *pTex2D = new CResourceTexture2D();
XTextureInfo texInfo;
pLoader->getInfo(&texInfo);
if(!pLoader->loadAs2D(pTex2D))
{
printf(COLOR_LRED "Unable to load texture!" COLOR_RESET "\n");
}
pLoader->close();
pTex2D->Release();
}*/
//if(pLoader->open("textures/fire/test.dds", ""))
if(pLoader->open("textures/fire/fire_tiled_a.dds", ""))
{
CResourceTexture2D *pTex2D = new CResourceTexture2D();
XTextureInfo texInfo;
pLoader->getInfo(&texInfo);
if(!pLoader->loadAs2D(pTex2D))
{
printf(COLOR_LRED "Unable to load texture!" COLOR_RESET "\n");
}
pLoader->close();
pTex2D->Release();
}
if(pLoader->open("textures/sky/sky_hdr_hl2.dds", ""))
{
CResourceTextureCube *pTexCube = new CResourceTextureCube();
XTextureInfo texInfo;
pLoader->getInfo(&texInfo);
if(!pLoader->loadAsCube(pTexCube))
{
printf(COLOR_LRED "Unable to load texture!" COLOR_RESET "\n");
}
pLoader->close();
pTexCube->Release();
}
#endif
}
......
......@@ -42,9 +42,9 @@ void XMETHODCALLTYPE CResourceTexture2D::init(UINT uWidth, UINT uHeight, GXFORMA
}
else
{
UINT uSize = min(uWidth, uHeight);
UINT uSize = max(uWidth, uHeight);
uMipmapCount = 1;
while((uSize >>= 1) >= 4)
while((uSize >>= 1) >= 1)
{
++uMipmapCount;
}
......@@ -53,37 +53,69 @@ void XMETHODCALLTYPE CResourceTexture2D::init(UINT uWidth, UINT uHeight, GXFORMA
size_t sizeData = uFrameCount * (sizeof(void*) + uMipmapCount * sizeof(XImageMip));
size_t sizeFrame = getTextureBytes(format, uWidth, uHeight);
size_t sizeTmp = sizeFrame;
UINT uTmpWidth = uWidth;
UINT uTmpHeight = uHeight;
for(UINT i = 0; i < uMipmapCount; ++i)
{
sizeData += sizeTmp * uFrameCount;
sizeTmp >>= 2;
sizeData += getTextureBytes(format, uTmpWidth, uTmpHeight) * uFrameCount;
uTmpWidth >>= 1;
uTmpHeight >>= 1;
uTmpWidth = max(uTmpWidth, 1);
uTmpHeight = max(uTmpHeight, 1);
}
pDataBlob = new byte[sizeData];
pppData = (XImageMip**)pDataBlob;
ppData = (XImageMip**)pDataBlob;
byte *pTmp = pDataBlob + sizeof(void*) * uFrameCount;
for(UINT i = 0; i < uFrameCount; ++i)
{
pppData[i] = (XImageMip*)pTmp;
pTmp += sizeof(void*) * uMipmapCount;
ppData[i] = (XImageMip*)pTmp;
pTmp += sizeof(XImageMip) * uMipmapCount;
}
for(UINT i = 0; i < uFrameCount; ++i)
{
sizeTmp = sizeFrame;
for(UINT j = 0; i < uMipmapCount; ++i)
uTmpWidth = uWidth;
uTmpHeight = uHeight;
for(UINT j = 0; j < uMipmapCount; ++j)
{
pppData[i][j].pData = pTmp;
pppData[i][j].sizeData = sizeTmp;
pppData[i][j].isWritten = false;
pTmp += sizeTmp;
sizeTmp >>= 2;
ppData[i][j].pData = pTmp;
ppData[i][j].sizeData = getTextureBytes(format, uTmpWidth, uTmpHeight);
ppData[i][j].isWritten = false;
pTmp += ppData[i][j].sizeData;
uTmpWidth >>= 1;
uTmpHeight >>= 1;
uTmpWidth = max(uTmpWidth, 1);
uTmpHeight = max(uTmpHeight, 1);
}
}
}
XImageMip* XMETHODCALLTYPE CResourceTexture2D::getMip(UINT uMipmap, UINT uFrame)
{
assert(ppData);
assert(m_uMipmapCount > uMipmap);
assert(m_uFrameCount > uFrame);
if(!ppData || m_uMipmapCount <= uMipmap || m_uFrameCount <= uFrame)
{
return(NULL);
}
return(&ppData[uFrame][uMipmap]);
}
const XImageMip* XMETHODCALLTYPE CResourceTexture2D::getMip(UINT uMipmap, UINT uFrame) const
{
assert(ppData);
assert(m_uMipmapCount < uMipmap);
assert(m_uFrameCount < uFrame);
if(!ppData || m_uMipmapCount >= uMipmap || m_uFrameCount >= uFrame)
{
return(NULL);
}
return(&ppData[uFrame][uMipmap]);
}
const IXResourceTexture2D* XMETHODCALLTYPE CResourceTexture2D::as2D() const
{
return(this);
......@@ -132,42 +164,51 @@ void XMETHODCALLTYPE CResourceTextureCube::init(UINT uSize, GXFORMAT format, UIN
{
UINT uTmpSize = uSize;
uMipmapCount = 1;
while((uTmpSize >>= 1) >= 4)
while((uTmpSize >>= 1) >= 1)
{
++uMipmapCount;
}
}
}
size_t sizeData = uFrameCount * (sizeof(void*) + uMipmapCount * sizeof(XImageMip));
size_t sizeFrame = getTextureBytes(format, uSize, uSize) * 6;
size_t sizeTmp = sizeFrame;
size_t sizeData = uFrameCount * (sizeof(void*) + uMipmapCount * (sizeof(void*) + 6 * sizeof(XImageMip)));
UINT uTmpSize = uSize;
for(UINT i = 0; i < uMipmapCount; ++i)
{
sizeData += sizeTmp * uFrameCount;
sizeTmp >>= 2;
sizeData += getTextureBytes(format, uTmpSize, uTmpSize) * 6 * uFrameCount;
uTmpSize >>= 1;
uTmpSize = max(uTmpSize, 1);
}
pDataBlob = new byte[sizeData];
pppData = (XImageMip**)pDataBlob;
pppData = (XImageMip***)pDataBlob;
byte *pTmp = pDataBlob + sizeof(void*) * uFrameCount;
for(UINT i = 0; i < uFrameCount; ++i)
{
pppData[i] = (XImageMip*)pTmp;
pppData[i] = (XImageMip**)pTmp;
pTmp += sizeof(void*) * uMipmapCount;
for(int mip = 0; mip < uMipmapCount; ++mip)
{
pppData[i][mip] = (XImageMip*)pTmp;
pTmp += sizeof(XImageMip) * 6;
}
}
for(UINT i = 0; i < uFrameCount; ++i)
{
sizeTmp = sizeFrame;
for(UINT j = 0; i < uMipmapCount; ++i)
uTmpSize = uSize;
for(UINT j = 0; j < uMipmapCount; ++j)
{
pppData[i][j].pData = pTmp;
pppData[i][j].sizeData = sizeTmp;
pppData[i][j].isWritten = false;
pTmp += sizeTmp;
sizeTmp >>= 2;
for(int side = 0; side < 6; ++side)
{
pppData[i][j][side].pData = pTmp;
pppData[i][j][side].sizeData = getTextureBytes(format, uTmpSize, uTmpSize);
pppData[i][j][side].isWritten = false;
pTmp += pppData[i][j][side].sizeData;
}
uTmpSize >>= 1;
uTmpSize = max(uTmpSize, 1);
}
}
}
......@@ -181,3 +222,26 @@ IXResourceTextureCube* XMETHODCALLTYPE CResourceTextureCube::asCube()
{
return(this);
}
XImageMip* XMETHODCALLTYPE CResourceTextureCube::getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame)
{
assert(pppData);
assert(m_uMipmapCount > uMipmap);
assert(m_uFrameCount > uFrame);
if(!pppData || m_uMipmapCount <= uMipmap || m_uFrameCount <= uFrame)
{
return(NULL);
}
return(&pppData[uFrame][uMipmap][face]);
}
const XImageMip* XMETHODCALLTYPE CResourceTextureCube::getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame) const
{
assert(pppData);
assert(m_uMipmapCount < uMipmap);
assert(m_uFrameCount < uFrame);
if(!pppData || m_uMipmapCount >= uMipmap || m_uFrameCount >= uFrame)
{
return(NULL);
}
return(&pppData[uFrame][uMipmap][face]);
}
......@@ -41,29 +41,6 @@ public:
return(m_uMipmapCount);
}
XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) override
{
assert(pppData);
assert(m_uMipmapCount < uMipmap);
assert(m_uFrameCount < uFrame);
if(!pppData || m_uMipmapCount >= uMipmap || m_uFrameCount >= uFrame)
{
return(NULL);
}
return(&pppData[uFrame][uMipmap]);
}
const XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) const override
{
assert(pppData);
assert(m_uMipmapCount < uMipmap);
assert(m_uFrameCount < uFrame);
if(!pppData || m_uMipmapCount >= uMipmap || m_uFrameCount >= uFrame)
{
return(NULL);
}
return(&pppData[uFrame][uMipmap]);
}
const IXResourceTexture2D* XMETHODCALLTYPE as2D() const override
{
return(NULL);
......@@ -150,8 +127,8 @@ public:
if(bc)
{
int numBlocksWide = max(1, uWidth / 4);
int numBlocksHigh = max(1, uHeight / 4);
int numBlocksWide = max(1, (uWidth + 3) / 4);
int numBlocksHigh = max(1, (uHeight + 3) / 4);
return(numBlocksWide * numBlocksHigh * bcnumBytesPerBlock);
}
......@@ -185,8 +162,6 @@ protected:
float m_fFrameTime = 0.0f;
byte *pDataBlob = NULL;
XImageMip **pppData = NULL; // pppData[uFrame][uMip]
};
// Implemented in core
......@@ -201,12 +176,18 @@ public:
void XMETHODCALLTYPE init(UINT uWidth, UINT uHeight, GXFORMAT format, UINT uMipmapCount = IXRESOURCE_TEXTURE_AUTO_MIPS, UINT uFrameCount = 0) override;
XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) override;
const XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) const override;
const IXResourceTexture2D* XMETHODCALLTYPE as2D() const override;
IXResourceTexture2D* XMETHODCALLTYPE as2D() override;
protected:
UINT m_uWidth = 0;
UINT m_uHeight = 0;
XImageMip **ppData = NULL; // ppData[uFrame][uMip]
};
// Implemented in core
......@@ -220,11 +201,16 @@ public:
void XMETHODCALLTYPE init(UINT uSize, GXFORMAT format, UINT uMipmapCount = IXRESOURCE_TEXTURE_AUTO_MIPS, UINT uFrameCount = 0) override;
XImageMip* XMETHODCALLTYPE getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame = 0) override;
const XImageMip* XMETHODCALLTYPE getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame = 0) const override;
const IXResourceTextureCube* XMETHODCALLTYPE asCube() const override;
IXResourceTextureCube* XMETHODCALLTYPE asCube() override;
protected:
UINT m_uSize = 0;
XImageMip ***pppData = NULL; // pppData[uFrame][uMip][side]
};
......
This diff is collapsed.
......@@ -25,6 +25,10 @@ public:
bool XMETHODCALLTYPE loadAsCube(IXResourceTextureCube *pResource) override;
void XMETHODCALLTYPE getInfo(XTextureInfo *pTextureInfo) override;
void XMETHODCALLTYPE close() override;
GXFORMAT getFormat();
bool isBlockCompressed(GXFORMAT format);
protected:
IFileSystem *m_pFileSystem;
......@@ -33,6 +37,12 @@ protected:
DDS_HEADER m_ddsHeader;
bool m_hasDXT10Header = false;
DDS_HEADER_DXT10 m_dxt10Header;
GXFORMAT m_format;
int m_iXFrames = 1;
int m_iYFrames = 1;
float m_fFrameTime = 0.0;
int m_iSkipFrames = 0;
};
#endif
......@@ -26,6 +26,7 @@ struct XTextureInfo
//! Количество кадров
UINT uFrameCount;
float fFrameTime;
//! Количество мип-уровней
UINT uMipCount;
......
......@@ -28,9 +28,6 @@ public:
virtual UINT XMETHODCALLTYPE getMipmapCount() const = 0;
virtual XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) = 0;
virtual const XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) const = 0;
virtual const IXResourceTexture2D* XMETHODCALLTYPE as2D() const = 0;
virtual const IXResourceTextureCube* XMETHODCALLTYPE asCube() const = 0;
virtual IXResourceTexture2D* XMETHODCALLTYPE as2D() = 0;
......@@ -48,6 +45,9 @@ public:
virtual UINT XMETHODCALLTYPE getWidth() const = 0;
virtual UINT XMETHODCALLTYPE getHeight() const = 0;
virtual XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) = 0;
virtual const XImageMip* XMETHODCALLTYPE getMip(UINT uMipmap, UINT uFrame = 0) const = 0;
virtual void XMETHODCALLTYPE init(UINT uWidth, UINT uHeight, GXFORMAT format, UINT uMipmapCount = IXRESOURCE_TEXTURE_AUTO_MIPS, UINT uFrameCount = 0) = 0;
};
......@@ -57,6 +57,9 @@ class IXResourceTextureCube: public IXResourceTexture
public:
virtual UINT XMETHODCALLTYPE getSize() const = 0;
virtual XImageMip* XMETHODCALLTYPE getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame = 0) = 0;
virtual const XImageMip* XMETHODCALLTYPE getMip(GXCUBEMAP_FACES face, UINT uMipmap, UINT uFrame = 0) const = 0;
virtual void XMETHODCALLTYPE init(UINT uSize, GXFORMAT format, UINT uMipmapCount = IXRESOURCE_TEXTURE_AUTO_MIPS, UINT uFrameCount = 0) = 0;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment