Skip to content

Commit

Permalink
Common: Embed the FFNx logo inside the dll
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu committed Jan 26, 2023
1 parent d32dbb1 commit 5da7b73
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 10 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ find_package(OPENPSF REQUIRED)
find_package(tomlplusplus CONFIG REQUIRED)
find_package(STEAMWORKSSDK CONFIG REQUIRED)
find_package(xxHash CONFIG REQUIRED)
find_package(CMakeRC CONFIG REQUIRED)

set(RELEASE_NAME "FFNx")

Expand All @@ -96,6 +97,13 @@ file(GLOB_RECURSE source_files "${CMAKE_SOURCE_DIR}/src/*.cpp")

configure_file(misc/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)

cmrc_add_resource_library(
${RELEASE_NAME}-resources
ALIAS ${RELEASE_NAME}::rc
NAMESPACE ${RELEASE_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/.logo/logo_nobg.png
)

add_library(${RELEASE_NAME} SHARED ${source_files} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
target_include_directories(
${RELEASE_NAME}
Expand All @@ -111,6 +119,7 @@ target_include_directories(
)
target_link_libraries(
${RELEASE_NAME}
${RELEASE_NAME}::rc
dbghelp
shlwapi
psapi
Expand Down Expand Up @@ -293,11 +302,6 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/misc/${RELEASE_NAME}.time.toml
${CMAKE_BINARY_DIR}/bin/time/config.toml

# FFNx logo .png
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/.logo/logo_nobg.png
${CMAKE_BINARY_DIR}/bin/ffnx/logo.png
)

# CPU INFO
Expand Down
85 changes: 81 additions & 4 deletions src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "ff7/widescreen.h"
#include "ff7/time.h"

CMRC_DECLARE(FFNx);

Renderer newRenderer;
RendererCallbacks bgfxCallbacks;

Expand Down Expand Up @@ -803,17 +805,18 @@ void Renderer::reset()
bgfx::reset(window_size_x, window_size_y, bgfxInit.resolution.reset, bgfxInit.resolution.format);
}

#define FFNX_LOGO_PATH ".logo/logo_nobg.png"

void Renderer::prepareFFNxLogo()
{
if (bgfx::isValid(FFNxLogoHandle))
bgfx::destroy(FFNxLogoHandle);

static char fullpath[64]{ 0 };

sprintf(fullpath, "%s/ffnx/logo.png", basedir);
auto fs = cmrc::FFNx::get_filesystem();
auto logo = fs.open(FFNX_LOGO_PATH);

uint32_t width, height, mipCount = 0;
FFNxLogoHandle = createTextureHandle(fullpath, &width, &height, &mipCount, true);
FFNxLogoHandle = createTextureHandle(&logo, FFNX_LOGO_PATH, &width, &height, &mipCount, true);
if (!FFNxLogoHandle.idx) FFNxLogoHandle = BGFX_INVALID_HANDLE;
}

Expand Down Expand Up @@ -1472,6 +1475,29 @@ bimg::ImageContainer* Renderer::createImageContainer(const char* filename, bimg:
return img;
}

bimg::ImageContainer* Renderer::createImageContainer(cmrc::file* file, bimg::TextureFormat::Enum targetFormat)
{
bimg::ImageContainer* img = nullptr;

if (file->size() > 0)
{
img = bimg::imageParse(&defaultAllocator, file->begin(), file->size());
}

if (img && targetFormat != bimg::TextureFormat::Enum::UnknownDepth && targetFormat != img->m_format)
{
if (trace_all || trace_renderer) ffnx_trace("Renderer::%s: convert image to format %d\n", __func__, targetFormat);

bimg::ImageContainer* converted = bimg::imageConvert(&defaultAllocator, targetFormat, *img);

bimg::imageFree(img);

img = converted;
}

return img;
}

bgfx::TextureHandle Renderer::createTextureHandle(char* filename, uint32_t* width, uint32_t* height, uint32_t* mipCount, bool isSrgb)
{
bgfx::TextureHandle ret = FFNX_RENDERER_INVALID_HANDLE;
Expand Down Expand Up @@ -1523,6 +1549,57 @@ bgfx::TextureHandle Renderer::createTextureHandle(char* filename, uint32_t* widt
return ret;
}

bgfx::TextureHandle Renderer::createTextureHandle(cmrc::file* file, char* filename, uint32_t* width, uint32_t* height, uint32_t* mipCount, bool isSrgb)
{
bgfx::TextureHandle ret = FFNX_RENDERER_INVALID_HANDLE;
bimg::ImageContainer* img = createImageContainer(file);

if (img != nullptr)
{
if (gl_check_texture_dimensions(img->m_width, img->m_height, filename) && doesItFitInMemory(img->m_size))
{
uint64_t flags = BGFX_SAMPLER_NONE;

if (isSrgb) flags |= BGFX_TEXTURE_SRGB;
else flags |= BGFX_TEXTURE_NONE;

const bgfx::Memory* mem = bgfx::makeRef(img->m_data, img->m_size, RendererReleaseImageContainer, img);
if (img->m_cubeMap)
{
ret = bgfx::createTextureCube(
img->m_width,
1 < img->m_numMips,
img->m_numLayers,
bgfx::TextureFormat::Enum(img->m_format),
flags,
mem
);
}
else
{

ret = bgfx::createTexture2D(
img->m_width,
img->m_height,
1 < img->m_numMips,
img->m_numLayers,
bgfx::TextureFormat::Enum(img->m_format),
flags,
mem
);
}

*width = img->m_width;
*height = img->m_height;
*mipCount = img->m_numMips;

if (trace_all || trace_renderer) ffnx_trace("Renderer::%s: %u => %ux%u from filename %s\n", __func__, ret.idx, width, height, filename);
}
}

return ret;
}

uint32_t Renderer::createTextureLibPng(char* filename, uint32_t* width, uint32_t* height, bool isSrgb)
{
bgfx::TextureHandle ret = FFNX_RENDERER_INVALID_HANDLE;
Expand Down
3 changes: 3 additions & 0 deletions src/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <bgfx/platform.h>
#include <bgfx/bgfx.h>
#include <libpng16/png.h>
#include <cmrc/cmrc.hpp>
#include "log.h"
#include "gl.h"
#include "overlay.h"
Expand Down Expand Up @@ -378,7 +379,9 @@ class Renderer {
uint32_t createTexture(uint8_t* data, size_t width, size_t height, int stride = 0, RendererTextureType type = RendererTextureType::BGRA, bool isSrgb = true);
uint32_t createTexture(char* filename, uint32_t* width, uint32_t* height, uint32_t* mipCount, bool isSrgb = true);
bimg::ImageContainer* createImageContainer(const char* filename, bimg::TextureFormat::Enum targetFormat = bimg::TextureFormat::Enum::UnknownDepth);
bimg::ImageContainer* createImageContainer(cmrc::file* file, bimg::TextureFormat::Enum targetFormat = bimg::TextureFormat::Enum::UnknownDepth);
bgfx::TextureHandle createTextureHandle(char* filename, uint32_t* width, uint32_t* height, uint32_t* mipCount, bool isSrgb = true);
bgfx::TextureHandle createTextureHandle(cmrc::file* file, char* filename, uint32_t* width, uint32_t* height, uint32_t* mipCount, bool isSrgb = true);
uint32_t createTextureLibPng(char* filename, uint32_t* width, uint32_t* height, bool isSrgb = true);
bool saveTexture(const char* filename, uint32_t width, uint32_t height, const void* data);
void deleteTexture(uint16_t texId);
Expand Down
8 changes: 7 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"features": [
"tools"
]
}
},
"cmakerc"
],
"overrides": [
{
Expand Down Expand Up @@ -131,6 +132,11 @@
"name": "cpuinfo",
"version": "2022-07-19",
"port-version": 0
},
{
"name": "cmakerc",
"version": "2022-09-08",
"port-version": 0
}
]
}

0 comments on commit 5da7b73

Please sign in to comment.