Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statically link shaders, update cmake version, c++ version and add CPM for cmake package managment #63

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
cmake_minimum_required(VERSION 3.16)
project(AnimeEffects VERSION 1.5.0 LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.21)
project(AnimeEffects C CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(get_cpm)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
else()
set(B_PRODUCTION_MODE ON)
endif()
CPMAddPackage("gh:batterycenter/embed#v1.2.19")

include(GNUInstallDirs)
# You need to add the Qt directory to your path if you're on Windows, otherwise you'll have a very bad time
find_package(Qt6 REQUIRED COMPONENTS Core5Compat Core Gui OpenGL OpenGLWidgets Xml Concurrent Widgets Multimedia)
Expand Down
24 changes: 24 additions & 0 deletions cmake/modules/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.2)
set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
16 changes: 16 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ add_library(${PROJECT_NAME}
TimeLine.cpp TimeLine.h
TimeLineEvent.cpp TimeLineEvent.h
)

set(SHADERS_DIR ../../data/shader)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/ClipperWritingFrag.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/ClipperWritingVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/GridDrawingFrag.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/GridDrawingVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/HSVAdjustFrag.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/HSVAdjustVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/LayerDrawingFrag.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/LayerDrawingVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/MeshTransformVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/PartialScreenCopyingFrag.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/PartialScreenCopyingVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/TestBlurVert.glsl)

target_include_directories(${PROJECT_NAME} PUBLIC
..
)
Expand All @@ -83,6 +98,7 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC
AE_PROJECT_FORMAT_OLDEST_MAJOR_VERSION=0
AE_PROJECT_FORMAT_OLDEST_MINOR_VERSION=4
USE_GL_CORE_PROFILE
SHADERS_DIR="${SHADERS_DIR}"
)

target_link_libraries(${PROJECT_NAME} PUBLIC
Expand Down
13 changes: 7 additions & 6 deletions src/core/DestinationTexturizer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gl/Global.h"
#include "gl/Util.h"
#include "core/DestinationTexturizer.h"
#include "battery/embed.hpp"

namespace {
static const int kAttachmentId = 0;
Expand Down Expand Up @@ -104,13 +105,13 @@ void DestinationTexturizer::createShader() {
auto shader = &mShader;

gl::ExtendShader source;
if (!source.openFromFileVert("./data/shader/PartialScreenCopyingVert.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open vertex shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/PartialScreenCopyingVert.glsl">();
source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size()));
}
if (!source.openFromFileFrag("./data/shader/PartialScreenCopyingFrag.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open fragment shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/PartialScreenCopyingFrag.glsl">();
source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size()));
}

if (!source.resolveVariation()) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/LayerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LayerNode::LayerNode(const QString& aName, ShaderHolder& aShaderHolder):
mTimeLine(),
mShaderHolder(aShaderHolder),
mIsClipped(),
mMeshTransformer("./data/shader/MeshTransformVert.glsl"),
mMeshTransformer(),
mCurrentMesh(),
mClippees() {}

Expand Down
4 changes: 2 additions & 2 deletions src/core/MeshTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace core {

//-------------------------------------------------------------------------------------------------
MeshTransformer::MeshTransformer(const QString& aShaderPath):
MeshTransformer::MeshTransformer():
mResource(*(new MeshTransformerResource())), mResourceOwns(true), mOutPositions(), mOutXArrows(), mOutYArrows() {
mResource.setup(aShaderPath);
mResource.setup();
}

MeshTransformer::MeshTransformer(MeshTransformerResource& aResource):
Expand Down
2 changes: 1 addition & 1 deletion src/core/MeshTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace core {

class MeshTransformer: private util::NonCopyable {
public:
MeshTransformer(const QString& aShaderPath);
MeshTransformer();
MeshTransformer(MeshTransformerResource& aResource);
~MeshTransformer();

Expand Down
7 changes: 4 additions & 3 deletions src/core/MeshTransformerResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#include "gl/Global.h"
#include "gl/ExtendShader.h"
#include "core/MeshTransformerResource.h"
#include "battery/embed.hpp"

namespace core {

//-------------------------------------------------------------------------------------------------
MeshTransformerResource::MeshTransformerResource() {}

void MeshTransformerResource::setup(const QString& aShaderPath) {
QString code;
loadFile(aShaderPath, code);
void MeshTransformerResource::setup() {
auto tmp = b::embed<"../../data/shader/MeshTransformVert.glsl">();
auto code = QString::fromUtf8(tmp.data(), tmp.size());

buildShader(mProgram[0], code, false, false);
buildShader(mProgram[1], code, true, false);
Expand Down
2 changes: 1 addition & 1 deletion src/core/MeshTransformerResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace core {
class MeshTransformerResource {
public:
MeshTransformerResource();
void setup(const QString& aShaderPath);
void setup();
gl::EasyShaderProgram& program(bool aUseSkinning, bool aUseDualQuaternion);
const gl::EasyShaderProgram& program(bool aUseSkinning, bool aUseDualQuaternion) const;

Expand Down
50 changes: 26 additions & 24 deletions src/core/ShaderHolder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gl/ExtendShader.h"
#include "gl/Global.h"
#include "core/ShaderHolder.h"
#include "battery/embed.hpp"

namespace core {

Expand Down Expand Up @@ -37,13 +38,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveShader(img::BlendMode aBlendMode, bo
auto shader = mShaders[index];

gl::ExtendShader source;
if (!source.openFromFileVert("./data/shader/LayerDrawingVert.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open vertex shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/LayerDrawingVert.glsl">();
source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size()));
}
if (!source.openFromFileFrag("./data/shader/LayerDrawingFrag.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open fragment shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/LayerDrawingFrag.glsl">();
source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size()));
}

auto blendFunc = QString("Blend") + img::getBlendFuncNameFromBlendMode(aBlendMode);
Expand Down Expand Up @@ -90,13 +91,14 @@ gl::EasyShaderProgram& ShaderHolder::reserveHSVShader() {
auto shader = mHSVShaders[index];

gl::ExtendShader source;
if (!source.openFromFileVert("./data/shader/HSVAdjustVert.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open vertex shader file.", source.log());

{
auto tmp = b::embed<"../../data/shader/HSVAdjustVert.glsl">();
source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size()));
}
if (!source.openFromFileFrag("./data/shader/HSVAdjustFrag.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open fragment shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/HSVAdjustFrag.glsl">();
source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size()));
}

if (!source.resolveVariation()) {
Expand Down Expand Up @@ -134,13 +136,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveGridShader() {
auto shader = mGridShaders[0];

gl::ExtendShader source;
if (!source.openFromFileVert("./data/shader/GridDrawingVert.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open vertex shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/GridDrawingVert.glsl">();
source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size()));
}
if (!source.openFromFileFrag("./data/shader/GridDrawingFrag.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open fragment shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/GridDrawingFrag.glsl">();
source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size()));
}

if (!source.resolveVariation()) {
Expand Down Expand Up @@ -175,13 +177,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveClipperShader(bool aIsClippee) {
auto shader = mClipperShaders[aIsClippee];

gl::ExtendShader source;
if (!source.openFromFileVert("./data/shader/ClipperWritingVert.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open vertex shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/ClipperWritingVert.glsl">();
source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size()));
}
if (!source.openFromFileFrag("./data/shader/ClipperWritingFrag.glsl")) {
XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() +
"Failed to open fragment shader file.", source.log());
{
auto tmp = b::embed<"../../data/shader/ClipperWritingFrag.glsl">();
source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size()));
}

source.setVariationValue("IS_CLIPPEE", aIsClippee ? "1" : "0");
Expand Down
7 changes: 7 additions & 0 deletions src/ctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ add_library(${PROJECT_NAME}
time/time_Scaler.cpp time/time_Scaler.h
ExportParams.h
)

set(SHADERS_DIR ../../data/shader)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDBlurVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDEraseVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDFocusVertexVert.glsl)
b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FreeFormDeformVert.glsl)

target_include_directories(${PROJECT_NAME} PUBLIC
..
)
Expand Down
9 changes: 2 additions & 7 deletions src/ctrl/FFDEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ FFDEditor::FFDEditor(Project& aProject, DriverResources& aDriverResources, UILog
if (!mDriverResources.meshTransformerResource()) {
gl::Global::makeCurrent();
mDriverResources.grabMeshTransformerResoure(new core::MeshTransformerResource());
mDriverResources.meshTransformerResource()->setup("./data/shader/MeshTransformVert.glsl");
mDriverResources.meshTransformerResource()->setup();
}
if (!mDriverResources.ffdTaskResource()) {
gl::Global::makeCurrent();
mDriverResources.grabFFDTaskResource(new ffd::TaskResource());
mDriverResources.ffdTaskResource()->setup(
"./data/shader/FreeFormDeformVert.glsl",
"./data/shader/FFDEraseVert.glsl",
"./data/shader/FFDFocusVertexVert.glsl",
"./data/shader/FFDBlurVert.glsl"
);
mDriverResources.ffdTaskResource()->setup();
}

#if 0
Expand Down
22 changes: 11 additions & 11 deletions src/ctrl/ffd/ffd_TaskResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
#include "gl/Global.h"
#include "gl/ExtendShader.h"
#include "ctrl/ffd/ffd_TaskResource.h"
#include "battery/embed.hpp"

namespace ctrl {
namespace ffd {

//-------------------------------------------------------------------------------------------------
TaskResource::TaskResource() {}

void TaskResource::setup(
const QString& aBrushPath, const QString& aEraserPath, const QString& aFocuserPath, const QString& aBlurPath
) {
void TaskResource::setup() {
// load brush shader
{
QString code;
loadFile(aBrushPath, code);
auto tmp = b::embed<"../../data/shader/FreeFormDeformVert.glsl">();
auto code = QString::fromUtf8(tmp.data(), tmp.size());

for (int hard = 0; hard < kHardness; ++hard) {
buildShader(mProgram[kTypeDeformer * kHardness + hard], code, kTypeDeformer, hard);
Expand All @@ -24,8 +23,8 @@ namespace ffd {

// load eraser shader
{
QString code;
loadFile(aEraserPath, code);
auto tmp = b::embed<"../../data/shader/FFDEraseVert.glsl">();
auto code = QString::fromUtf8(tmp.data(), tmp.size());

for (int hard = 0; hard < kHardness; ++hard) {
buildShader(mProgram[kTypeEraser * kHardness + hard], code, kTypeEraser, hard);
Expand All @@ -34,16 +33,17 @@ namespace ffd {

// load focuser shader
{
QString code;
loadFile(aFocuserPath, code);
auto tmp = b::embed<"../../data/shader/FFDFocusVertexVert.glsl">();
auto code = QString::fromUtf8(tmp.data(), tmp.size());

buildShader(mProgram[kTypeFocuser * kHardness], code, kTypeFocuser, 0);
}

// load blur path
{
QString code;
loadFile(aBlurPath, code);
auto tmp = b::embed<"../../data/shader/FFDBlurVert.glsl">();
auto code = QString::fromUtf8(tmp.data(), tmp.size());

buildBlurShader(mBlurProgram, code);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/ctrl/ffd/ffd_TaskResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace ffd {

TaskResource();

void setup(
const QString& aBrushPath, const QString& aEraserPath, const QString& aFocuserPath, const QString& aBlurPath
);
void setup();

gl::EasyShaderProgram& program(int aType, int aHard);
const gl::EasyShaderProgram& program(int aType, int aHard) const;
Expand Down
8 changes: 8 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
AudioPlaybackWidget.cpp
AudioPlaybackWidget.h
)

b_embed(${PROJECT_NAME} ../../data/encode/VideoEncode.txt)
b_embed(${PROJECT_NAME} ../../data/locale/translation_ja.qm)
b_embed(${PROJECT_NAME} ../../data/locale/translation_zh.qm)
b_embed(${PROJECT_NAME} ../../data/locale/preference.txt)
b_embed(${PROJECT_NAME} ../../data/locale/preference_ja.txt)
b_embed(${PROJECT_NAME} ../../data/locale/preference_zh.txt)

target_include_directories(${PROJECT_NAME} PRIVATE
..
)
Expand Down
8 changes: 3 additions & 5 deletions src/gui/GeneralSettingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,10 @@ GeneralSettingDialog::GeneralSettingDialog(GUIResources& aGUIResources, QWidget*
ffmpegNotif.exec();
return;
}
// Test file
QString testFile = QFileInfo("./data/themes/classic/icon/filew.png").absoluteFilePath();

// Sample gif test
QProcess gif;
gif.start(ffmpeg, {"-i", testFile, "gif.gif"}, QProcess::ReadWrite);
const QStringList testInput = {"-f", "lavfi", "-i", "testsrc=duration=1:size=24x20:rate=2"};
gif.start(ffmpeg, testInput + QStringList{"gif.gif"}, QProcess::ReadWrite);
gif.waitForFinished();
bool exportSuccess = gif.exitStatus() == 0 && QFileInfo::exists("gif.gif");
qDebug() << "Gif exists: " << QFileInfo::exists("gif.gif")
Expand All @@ -443,7 +441,7 @@ GeneralSettingDialog::GeneralSettingDialog(GUIResources& aGUIResources, QWidget*

// Palettegen test
QProcess palettegen;
palettegen.start(ffmpeg, {"-i", testFile, "-vf", "palettegen", "palette.png"}, QProcess::ReadWrite);
palettegen.start(ffmpeg, testInput + QStringList{"-vf", "palettegen", "palette.png"}, QProcess::ReadWrite);
palettegen.waitForFinished();
bool pGenSuccess = palettegen.exitStatus() == 0 && QFileInfo::exists("palette.png");
if (!pGenSuccess) {
Expand Down
Loading