diff --git a/BeefySysLib/BeefySysLib.vcxproj b/BeefySysLib/BeefySysLib.vcxproj index 7954e8ca..03d89b6a 100644 --- a/BeefySysLib/BeefySysLib.vcxproj +++ b/BeefySysLib/BeefySysLib.vcxproj @@ -177,6 +177,7 @@ third_party\AK\lib\release;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86;$(FrameworkSDKDir)\lib $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath);$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;C:\Program Files (x86)\Microsoft DirectX SDK (June 2007)\Include;C:\temp\wx\wxMSW-2.8.12\include;C:\temp\wx\wxMSW-2.8.12\include\msvc $(SolutionDir)\IDE\dist\ + $(ProjectName)64_Static @@ -414,11 +415,12 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\" MaxSpeed - true + false true - WIN32;NDEBUG;_WINDOWS;_USRDLL;BFSYSLIB_DYNAMIC;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;BFSYSLIB_DYNAMIC;BF_NO_FBX;FT2_BUILD_LIBRARY;%(PreprocessorDefinitions) MultiThreaded - ./; ./platform/win/; third_party/agg-2.4/include; third_party/agg-2.4/include/platform/win32; third_party/; third_party/libffi/i686-pc-cygwin; third_party/libffi/i686-pc-cygwin/include; third_party/libffi/include + ./;./platform/win/;./platform/sdl/;third_party/agg-2.4/include;third_party/agg-2.4/include/platform/win32;third_party/;third_party/libffi/i686-pc-cygwin;third_party/libffi/i686-pc-cygwin/include;third_party/libffi/include;third_party/SDL2-2.0.1/include;../extern/fbxsdk/include;third_party/freetype/include;../BeefLibs/SDL2/include + false Windows @@ -482,7 +484,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"false true true - true + false false @@ -492,7 +494,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"true false true - true + false false @@ -2001,7 +2003,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"true false true - true + false false @@ -2010,7 +2012,7 @@ copy /y "$(OutDir)$(TargetName).lib" "$(SolutionDir)\BeefLibs\Beefy2D\dist\"true false true - true + false false diff --git a/BeefySysLib/Common.cpp b/BeefySysLib/Common.cpp index abedc863..62d937a3 100644 --- a/BeefySysLib/Common.cpp +++ b/BeefySysLib/Common.cpp @@ -1380,6 +1380,16 @@ void Beefy::BFFatalError(const char* message, const char* file, int line) BFFatalError(String(message), String(file), line); } -void MakeUpper(const StringImpl& theString) +bool Beefy::ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize) { + if (str.StartsWith("@")) + { + int colon = (int)str.IndexOf(':'); + String addrStr = str.Substring(1, colon - 1); + String lenStr = str.Substring(colon + 1); + outPtr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16); + outSize = (int)strtol(lenStr.c_str(), NULL, 10); + return true; + } + return false; } diff --git a/BeefySysLib/Common.h b/BeefySysLib/Common.h index 609faf68..adb6a07b 100644 --- a/BeefySysLib/Common.h +++ b/BeefySysLib/Common.h @@ -242,6 +242,7 @@ bool FileExists(const StringImpl& path, String* outActualName = NULL); bool DirectoryExists(const StringImpl& path, String* outActualName = NULL); bool RecursiveCreateDirectory(const StringImpl& dirName); bool RecursiveDeleteDirectory(const StringImpl& dirName); +bool ParseMemorySpan(const StringImpl& str, void*& outPtr, int& outSize); #define CHARTAG(val) FromBIGEndian(val) diff --git a/BeefySysLib/gfx/FTFont.cpp b/BeefySysLib/gfx/FTFont.cpp index 4a14c9e2..15821b2a 100644 --- a/BeefySysLib/gfx/FTFont.cpp +++ b/BeefySysLib/gfx/FTFont.cpp @@ -147,13 +147,24 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize) String useFileName = fileName; int faceIdx = 0; - int atPos = (int)useFileName.IndexOf('@'); + int atPos = (int)useFileName.IndexOf('@', 1); if (atPos != -1) { faceIdx = atoi(useFileName.c_str() + atPos + 1); useFileName.RemoveToEnd(atPos); } - auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace); + + void* memPtr = NULL; + int memLen = 0; + if (ParseMemorySpan(fileName, memPtr, memLen)) + { + FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace); + } + else + { + FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace); + } + face->mFTFace = ftFace; } else diff --git a/BeefySysLib/gfx/RenderDevice.cpp b/BeefySysLib/gfx/RenderDevice.cpp index 046a53ca..80bac63b 100644 --- a/BeefySysLib/gfx/RenderDevice.cpp +++ b/BeefySysLib/gfx/RenderDevice.cpp @@ -150,14 +150,12 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags) if (!handled) { imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0; - if (fileName.StartsWith("@")) - { - int colon = (int)fileName.IndexOf(':'); - String addrStr = fileName.Substring(1, colon - 1); - String lenStr = fileName.Substring(colon + 1); - void* addr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16); - int len = (int)strtol(lenStr.c_str(), NULL, 10); - if (!imageData->LoadFromMemory(addr, len)) + + void* memPtr = NULL; + int memLen = 0; + if (ParseMemorySpan(fileName, memPtr, memLen)) + { + if (!imageData->LoadFromMemory(memPtr, memLen)) { failed = true; delete imageData; diff --git a/BeefySysLib/platform/win/DXRenderDevice.cpp b/BeefySysLib/platform/win/DXRenderDevice.cpp index ed539a18..d4cb4d2e 100644 --- a/BeefySysLib/platform/win/DXRenderDevice.cpp +++ b/BeefySysLib/platform/win/DXRenderDevice.cpp @@ -5,6 +5,7 @@ #include "img/ImageData.h" #include "util/PerfTimer.h" #include "util/BeefPerf.h" +#include "Span.h" #include "FileStream.h" #include "DDS.h" @@ -225,12 +226,14 @@ void DXShader::ReleaseNative() mConstBuffer = NULL; } -extern "C" -typedef HRESULT(WINAPI* Func_D3DX10CompileFromFileW)(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, +extern "C" typedef HRESULT(WINAPI* Func_D3DX10CompileFromFileW)(LPCWSTR pSrcFile, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs); - static Func_D3DX10CompileFromFileW gFunc_D3DX10CompileFromFileW; +extern "C" typedef HRESULT(WINAPI* Func_D3DX10Compile)(void* srcData, size_t srcSize, char* sourceName, CONST D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude, + LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags1, UINT Flags2, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs); +static Func_D3DX10Compile gFunc_D3DX10Compile; + static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer) { HRESULT hr; @@ -239,7 +242,7 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co bool useCache = false; auto srcDate = ::BfpFile_GetTime_LastWrite(filePath.c_str()); auto cacheDate = ::BfpFile_GetTime_LastWrite(outObj.c_str()); - if (cacheDate >= srcDate) + if ((cacheDate != 0) && (cacheDate >= srcDate)) useCache = true; if (!useCache) @@ -257,16 +260,37 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co if (!useCache) { - if (gFunc_D3DX10CompileFromFileW == NULL) - { - auto lib = LoadLibraryA("D3DCompiler_47.dll"); - if (lib != NULL) - gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile"); - } + bool useCompile = true; + HRESULT dxResult; ID3D10Blob* errorMessage = NULL; - auto dxResult = gFunc_D3DX10CompileFromFileW(UTF8Decode(filePath).c_str(), NULL, NULL, entry.c_str(), profile.c_str(), - D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage); + if (useCompile) + { + if (gFunc_D3DX10Compile == NULL) + { + auto lib = LoadLibraryA("D3DCompiler_47.dll"); + if (lib != NULL) + gFunc_D3DX10Compile = (Func_D3DX10Compile)::GetProcAddress(lib, "D3DCompile"); + } + + int memSize = 0; + uint8* memPtr = LoadBinaryData(filePath, &memSize); + + dxResult = gFunc_D3DX10Compile(memPtr, memSize, "Shader", NULL, NULL, entry.c_str(), profile.c_str(), + D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage); + } + else + { + if (gFunc_D3DX10CompileFromFileW == NULL) + { + auto lib = LoadLibraryA("D3DCompiler_47.dll"); + if (lib != NULL) + gFunc_D3DX10CompileFromFileW = (Func_D3DX10CompileFromFileW)::GetProcAddress(lib, "D3DCompileFromFile"); + } + + dxResult = gFunc_D3DX10CompileFromFileW(UTF8Decode(filePath).c_str(), NULL, NULL, entry.c_str(), profile.c_str(), + D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage); + } if (DXFAILED(dxResult)) { @@ -310,6 +334,36 @@ static bool LoadDXShader(const StringImpl& filePath, const StringImpl& entry, co return true; } +static bool LoadDXShader(Span fileData, const StringImpl& entry, const StringImpl& profile, ID3D10Blob** outBuffer) +{ + HRESULT hr; + + if (gFunc_D3DX10Compile == NULL) + { + auto lib = LoadLibraryA("D3DCompiler_47.dll"); + if (lib != NULL) + gFunc_D3DX10Compile = (Func_D3DX10Compile)::GetProcAddress(lib, "D3DCompile"); + } + + ID3D10Blob* errorMessage = NULL; + auto dxResult = gFunc_D3DX10Compile(fileData.mVals, fileData.mSize, "ShaderSource", NULL, NULL, entry.c_str(), profile.c_str(), + D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_STRICTNESS, 0, outBuffer, &errorMessage); + + if (DXFAILED(dxResult)) + { + if (errorMessage != NULL) + { + BF_FATAL(StrFormat("Vertex shader load failed: %s", (char*)errorMessage->GetBufferPointer()).c_str()); + errorMessage->Release(); + } + else + BF_FATAL("Shader load failed"); + return false; + } + + return true; +} + bool DXShader::Load() { //HRESULT hr; @@ -318,8 +372,35 @@ bool DXShader::Load() ID3D10Blob* vertexShaderBuffer = NULL; ID3D10Blob* pixelShaderBuffer = NULL; - LoadDXShader(mSrcPath + ".fx", "VS", "vs_4_0", &vertexShaderBuffer); - LoadDXShader(mSrcPath + ".fx", "PS", "ps_4_0", &pixelShaderBuffer); + void* memPtr = NULL; + int memSize = 0; + if (ParseMemorySpan(mSrcPath, memPtr, memSize)) + { + int crPos = (int)mSrcPath.IndexOf('\n'); + if (crPos != -1) + { + void* memPtr2 = NULL; + int memSize2 = 0; + if (ParseMemorySpan(mSrcPath.Substring(crPos + 1), memPtr2, memSize2)) + { + D3D10CreateBlob(memSize, &vertexShaderBuffer); + memcpy(vertexShaderBuffer->GetBufferPointer(), memPtr, memSize); + D3D10CreateBlob(memSize2, &pixelShaderBuffer); + memcpy(pixelShaderBuffer->GetBufferPointer(), memPtr2, memSize2); + } + } + else + { + Span span((uint8*)memPtr, memSize); + LoadDXShader(span, "VS", "vs_4_0", &vertexShaderBuffer); + LoadDXShader(span, "PS", "ps_4_0", &pixelShaderBuffer); + } + } + else + { + LoadDXShader(mSrcPath + ".fx", "VS", "vs_4_0", &vertexShaderBuffer); + LoadDXShader(mSrcPath + ".fx", "PS", "ps_4_0", &pixelShaderBuffer); + } defer( { diff --git a/BeefySysLib/util/BeefPerf.h b/BeefySysLib/util/BeefPerf.h index b08f42fc..d6730b7d 100644 --- a/BeefySysLib/util/BeefPerf.h +++ b/BeefySysLib/util/BeefPerf.h @@ -320,7 +320,7 @@ public: #define BP_EXPORT BF_EXPORT #define BP_CALLTYPE BF_CALLTYPE #else -#define BP_EXPORT +#define BP_EXPORT extern "C" #define BP_CALLTYPE #endif