Commit 632abc27 authored by D-AIRY's avatar D-AIRY

dds plugin (begin)

parent bea739b4
......@@ -351,6 +351,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "xCore", "xCore", "{74D74409
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sxambient", "..\..\sxambient\vs2013\sxambient.vcxproj", "{6FE14C5C-6052-4D96-A89F-0843D91F89AD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ddsplugin", "..\..\ddsplugin\vs2013\ddsplugin.vcxproj", "{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
......@@ -659,6 +661,14 @@ Global
{6FE14C5C-6052-4D96-A89F-0843D91F89AD}.Release|Win32.Build.0 = Release|Win32
{6FE14C5C-6052-4D96-A89F-0843D91F89AD}.Release|x64.ActiveCfg = Release|x64
{6FE14C5C-6052-4D96-A89F-0843D91F89AD}.Release|x64.Build.0 = Release|x64
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Debug|Win32.ActiveCfg = Debug|Win32
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Debug|Win32.Build.0 = Debug|Win32
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Debug|x64.ActiveCfg = Debug|x64
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Debug|x64.Build.0 = Debug|x64
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Release|Win32.ActiveCfg = Release|Win32
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Release|Win32.Build.0 = Release|Win32
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Release|x64.ActiveCfg = Release|x64
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -720,6 +730,7 @@ Global
{D2386C4E-7032-487B-8EAD-951778AD6EBC} = {74D74409-BAC7-4DD0-8C74-117516B4A01C}
{74D74409-BAC7-4DD0-8C74-117516B4A01C} = {13D5622C-8643-4BD8-A730-B5C919DAFDDC}
{6FE14C5C-6052-4D96-A89F-0843D91F89AD} = {E6B16854-D4A4-4B56-8E1C-482DD523F205}
{FE640066-C8E8-41FB-AD13-89BC03BFFBFB} = {7C1F0E50-7A19-4AB4-B559-11EF078F4787}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
......
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{A449BBF6-87B9-4A5C-ADF0-2EBF183111CA}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{53F9B2A7-D46D-438A-9854-263F22AFCF5C}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{E8C70B41-9EA3-4F97-84C0-4CCFC5D0A117}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\source\ddsplugin\dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\source\ddsplugin\plugin_main.cpp" />
<ClCompile Include="..\..\..\source\ddsplugin\TextureLoader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\source\ddsplugin\TextureLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\source\ddsplugin\DDSFile.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -13,6 +13,8 @@
#include <GRegisterIndex.h>
#include <xcommon/IXTextureLoader.h>
extern CTimeManager *g_pTimers;
extern CPerfMon *g_pPerfMon;
extern CCore *g_pCore;
......@@ -80,6 +82,17 @@ CCore::CCore(const char *szName)
}
loadPlugins();
#if 1
IXTextureLoader *pLoader = (IXTextureLoader*)m_pPluginManager->getInterface(IXTEXTURELOADER_GUID);
if(pLoader->open("textures/tp/tp_sga_window_center_up.dds", ""))
{
XTextureInfo texInfo;
pLoader->getInfo(&texInfo);
pLoader->close();
}
#endif
}
CCore::~CCore()
{
......
This diff is collapsed.
#include "TextureLoader.h"
#include "DDSFile.h"
CTextureLoader::CTextureLoader(IFileSystem* pFileSystem):
m_pFileSystem(pFileSystem)
{
}
UINT XMETHODCALLTYPE CTextureLoader::getVersion()
{
return(IXTEXTURELOADER_VERSION);
}
UINT XMETHODCALLTYPE CTextureLoader::getExtCount() const
{
return(1);
}
const char* XMETHODCALLTYPE CTextureLoader::getExt(UINT uIndex) const
{
assert(uIndex < getExtCount());
switch(uIndex)
{
case 0:
return("dds");
}
return(NULL);
}
const char* XMETHODCALLTYPE CTextureLoader::getExtText(UINT uIndex) const
{
assert(uIndex < getExtCount());
switch(uIndex)
{
case 0:
return("DirectDraw Surface");
}
return(NULL);
}
const char* XMETHODCALLTYPE CTextureLoader::getAuthor() const
{
return("D-AIRY @ DogmaNet");
}
const char* XMETHODCALLTYPE CTextureLoader::getCopyright() const
{
return("Copyright © Vitaliy Buturlin, Evgeny Danilovich, 2019");
}
const char* XMETHODCALLTYPE CTextureLoader::getDescription() const
{
return("DDS texture loader");
}
void XMETHODCALLTYPE CTextureLoader::getInfo(XTextureInfo *pTextureInfo)
{
pTextureInfo->type = getType();
pTextureInfo->uWidth = m_ddsHeader.width;
pTextureInfo->uHeight = m_ddsHeader.height;
pTextureInfo->uDepth = m_ddsHeader.depth;
pTextureInfo->uMipCount = 1;
if(m_ddsHeader.flags & DDS_HEADER_FLAGS_MIPMAP)
{
pTextureInfo->uMipCount = m_ddsHeader.mipMapCount;
}
}
bool XMETHODCALLTYPE CTextureLoader::open(const char *szFileName, const char *szArg)
{
assert(!m_pCurrentFile && "File already opened!");
if(m_pCurrentFile)
{
return(false);
}
m_pCurrentFile = m_pFileSystem->openFile(szFileName);
if(!m_pCurrentFile)
{
return(false);
}
IFile *pFile = m_pCurrentFile;
uint32_t uMagick = 0;
memset(&m_ddsHeader, 0, sizeof(m_ddsHeader));
memset(&m_dxt10Header, 0, sizeof(m_dxt10Header));
pFile->readBin(&uMagick, sizeof(uMagick));
if(uMagick != DDS_MAGIC)
{
return(false);
}
if(pFile->readBin(&m_ddsHeader, sizeof(m_ddsHeader)) != sizeof(m_ddsHeader))
{
return(false);
}
m_hasDXT10Header = (m_ddsHeader.ddspf.flags & DDS_FOURCC) && m_ddsHeader.ddspf.fourCC == MAKEFOURCC('D', 'X', '1', '0');
if(m_hasDXT10Header && pFile->readBin(&m_dxt10Header, sizeof(m_dxt10Header)) != sizeof(m_dxt10Header))
{
return(false);
}
return(true);
}
GXTEXTURE_TYPE XMETHODCALLTYPE CTextureLoader::getType() const
{
if(m_ddsHeader.caps2 & DDS_FLAGS_VOLUME)
{
return(GXTEXTURE_TYPE_3D);
}
if(m_ddsHeader.caps & DDS_SURFACE_FLAGS_CUBEMAP)
{
return(GXTEXTURE_TYPE_CUBE);
}
if(m_ddsHeader.caps & DDS_SURFACE_FLAGS_TEXTURE)
{
return(GXTEXTURE_TYPE_2D);
}
return(GXTEXTURE_TYPE_UNKNOWN);
}
bool XMETHODCALLTYPE CTextureLoader::loadAs2D(IXResourceTexture2D *pResource)
{
if(getType() != GXTEXTURE_TYPE_2D)
{
return(false);
}
return(true);
}
bool XMETHODCALLTYPE CTextureLoader::loadAsCube(IXResourceTextureCube *pResource)
{
if(getType() != GXTEXTURE_TYPE_CUBE)
{
return(false);
}
return(true);
}
void XMETHODCALLTYPE CTextureLoader::close()
{
mem_release(m_pCurrentFile);
}
#ifndef __TEXTURELOADER_H
#define __TEXTURELOADER_H
#include <xcommon/IXTextureLoader.h>
#include <xcommon/IFileSystem.h>
#include "DDSFile.h"
class CTextureLoader: public IXTextureLoader
{
public:
CTextureLoader(IFileSystem* pFileSystem);
UINT XMETHODCALLTYPE getVersion() override;
UINT XMETHODCALLTYPE getExtCount() const override;
const char* XMETHODCALLTYPE getExt(UINT uIndex) const override;
const char* XMETHODCALLTYPE getExtText(UINT uIndex) const override;
const char* XMETHODCALLTYPE getAuthor() const override;
const char* XMETHODCALLTYPE getCopyright() const override;
const char* XMETHODCALLTYPE getDescription() const override;
bool XMETHODCALLTYPE open(const char *szFileName, const char *szArg) override;
GXTEXTURE_TYPE XMETHODCALLTYPE getType() const override;
bool XMETHODCALLTYPE loadAs2D(IXResourceTexture2D *pResource) override;
bool XMETHODCALLTYPE loadAsCube(IXResourceTextureCube *pResource) override;
void XMETHODCALLTYPE getInfo(XTextureInfo *pTextureInfo) override;
void XMETHODCALLTYPE close() override;
protected:
IFileSystem *m_pFileSystem;
IFile *m_pCurrentFile = NULL;
DDS_HEADER m_ddsHeader;
bool m_hasDXT10Header = false;
DDS_HEADER_DXT10 m_dxt10Header;
};
#endif
/***********************************************************
Copyright Vitaliy Buturlin, Evgeny Danilovich, 2017, 2018
See the license in LICENSE
***********************************************************/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#include <xcommon/IXPlugin.h>
#include "TextureLoader.h"
class CDDSPlugin: public IXPlugin
{
public:
void XMETHODCALLTYPE startup(IXCore *pCore) override
{
m_pCore = pCore;
}
void XMETHODCALLTYPE shutdown() override
{
}
UINT XMETHODCALLTYPE getInterfaceCount() override
{
return(1);
}
const XGUID* XMETHODCALLTYPE getInterfaceGUID(UINT id) override
{
static XGUID s_guid;
switch(id)
{
case 0:
s_guid = IXTEXTURELOADER_GUID;
break;
default:
return(NULL);
}
return(&s_guid);
}
IXUnknown* XMETHODCALLTYPE getInterface(const XGUID &guid) override
{
if(guid == IXTEXTURELOADER_GUID)
{
return(new CTextureLoader(m_pCore->getFileSystem()));
}
return(NULL);
}
protected:
IXCore *m_pCore;
};
DECLARE_XPLUGIN(CDDSPlugin);
......@@ -3,11 +3,11 @@
#include <gdefines.h>
#include <core/IFile.h>
#include <graphix/graphix.h>
#include <xcommon/resource/IXResourceTexture.h>
// {95FBCCB6-D40F-4FC6-AFF4-8A52BD75DB3C}
#define IXTEXTURELOADER_GUID DEFINE_GUID(0x95fbccb6, 0xd40f, 0x4fc6, 0xaf, 0xf4, 0x8a, 0x52, 0xbd, 0x75, 0xdb, 0x3c)
#define IXTEXTURELOADER_GUID DEFINE_XGUID(0x95fbccb6, 0xd40f, 0x4fc6, 0xaf, 0xf4, 0x8a, 0x52, 0xbd, 0x75, 0xdb, 0x3c)
#define IXTEXTURELOADER_VERSION 1
//! возможная информация о текстуре
struct XTextureInfo
......@@ -41,8 +41,10 @@ public:
virtual const char* XMETHODCALLTYPE getCopyright() const = 0;
virtual const char* XMETHODCALLTYPE getDescription() const = 0;
virtual bool XMETHODCALLTYPE open(IFile *pFile) = 0;
virtual bool XMETHODCALLTYPE load(IXResourceTexture *pResource) = 0;
virtual bool XMETHODCALLTYPE open(const char *szFileName, const char *szArg) = 0;
virtual GXTEXTURE_TYPE XMETHODCALLTYPE getType() const = 0;
virtual bool XMETHODCALLTYPE loadAs2D(IXResourceTexture2D *pResource) = 0;
virtual bool XMETHODCALLTYPE loadAsCube(IXResourceTextureCube *pResource) = 0;
virtual void XMETHODCALLTYPE getInfo(XTextureInfo *pTextureInfo) = 0;
virtual void XMETHODCALLTYPE close() = 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