mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-05 15:30:00 +01:00
Initial commit (2)
This commit is contained in:
267
CMakeLists.txt
Normal file
267
CMakeLists.txt
Normal file
@@ -0,0 +1,267 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.8.0)
|
||||
project(vmix VERSION 0.0.1 LANGUAGES CXX C)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")
|
||||
set(CMAKE_INCLUDE_CURRENTDIR ON)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules )
|
||||
include(MacroLogFeature)
|
||||
|
||||
if(UNIX)
|
||||
if (APPLE)
|
||||
add_definitions(-DAPPLE)
|
||||
else()
|
||||
add_definitions(-DLINUX)
|
||||
endif()
|
||||
add_definitions(-DUNIX)
|
||||
elseif(WIN32)
|
||||
add_definitions(-DWIN32)
|
||||
add_definitions(-DMINGW32)
|
||||
endif(UNIX)
|
||||
|
||||
# Include the CMake RC module
|
||||
include(CMakeRC)
|
||||
|
||||
#
|
||||
# GSTREAMER
|
||||
#
|
||||
|
||||
find_package(GStreamer 1.0.0 COMPONENTS base)
|
||||
macro_log_feature(GSTREAMER_FOUND "GStreamer"
|
||||
"Open Source Multiplatform Multimedia Framework"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
macro_log_feature(GSTREAMER_BASE_LIBRARY_FOUND "GStreamer base library"
|
||||
"${GSTREAMER_BASE_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" FALSE "1.0.0")
|
||||
|
||||
find_package(GStreamerPluginsBase 1.0.0 COMPONENTS app audio video pbutils gl)
|
||||
macro_log_feature(GSTREAMER_APP_LIBRARY_FOUND "GStreamer app library"
|
||||
"${GSTREAMER_APP_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
|
||||
macro_log_feature(GSTREAMER_AUDIO_LIBRARY_FOUND "GStreamer audio library"
|
||||
"${GSTREAMER_AUDIO_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
|
||||
macro_log_feature(GSTREAMER_VIDEO_LIBRARY_FOUND "GStreamer video library"
|
||||
"${GSTREAMER_VIDEO_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
|
||||
macro_log_feature(GSTREAMER_PBUTILS_LIBRARY_FOUND "GStreamer pbutils library"
|
||||
"${GSTREAMER_PBUTILS_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
|
||||
macro_log_feature(GSTREAMER_GL_LIBRARY_FOUND "GStreamer opengl library"
|
||||
"${GSTREAMER_GL_LIBRARY}"
|
||||
"http://gstreamer.freedesktop.org/" TRUE "1.0.0")
|
||||
|
||||
# Various preprocessor definitions for GST
|
||||
add_definitions(-DGST_DISABLE_XML -DGST_DISABLE_LOADSAVE)
|
||||
|
||||
# Basics
|
||||
find_package(GLIB2)
|
||||
macro_log_feature(GLIB2_FOUND "GLib" "GTK general-purpose utility library" "http://www.gtk.org/" TRUE)
|
||||
|
||||
find_package(GObject)
|
||||
macro_log_feature(GOBJECT_FOUND "GObject" "GTK object-oriented framework" "http://www.gtk.org/" TRUE)
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
set(THREAD_LIBRARY Threads::Threads)
|
||||
|
||||
find_package(PNG REQUIRED)
|
||||
set(PNG_LIBRARY PNG::PNG)
|
||||
|
||||
|
||||
#
|
||||
# GLFW3
|
||||
#
|
||||
find_package(glfw3 3.3 REQUIRED)
|
||||
macro_log_feature(glfw3_FOUND "GLFW3" "Open Source, multi-platform library for OpenGL" "http://www.glfw.org/" TRUE)
|
||||
set(GLFW_LIBRARY glfw)
|
||||
|
||||
set(OpenGL_GL_PREFERENCE "GLVND")
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
#
|
||||
# GLM
|
||||
#
|
||||
find_package(glm REQUIRED)
|
||||
macro_log_feature(glm_FOUND "GLM" "OpenGL Mathematics" "https://glm.g-truc.net" TRUE)
|
||||
set(GLM_LIBRARY glm)
|
||||
|
||||
#
|
||||
# GLAD
|
||||
#
|
||||
set(GLAD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/include)
|
||||
add_library(GLAD "${CMAKE_CURRENT_SOURCE_DIR}/ext/glad/src/glad.c")
|
||||
message(STATUS "Compiling 'GLAD' generated at https://glad.dav1d.de/ -- ${GLAD_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# DEAR IMGUI
|
||||
#
|
||||
set(IMGUI_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui/imgui.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui//imgui_demo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui//imgui_draw.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui//imgui_widgets.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui/examples/imgui_impl_glfw.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui/examples/imgui_impl_opengl3.cpp
|
||||
)
|
||||
set(IMGUI_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/imgui)
|
||||
add_library(IMGUI "${IMGUI_SRCS}")
|
||||
target_compile_definitions(IMGUI PRIVATE "IMGUI_IMPL_OPENGL_LOADER_GLAD")
|
||||
message(STATUS "Compiling 'Dear ImGui' from https://github.com/ocornut/imgui.git -- ${IMGUI_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# ImGui Color Text Editor
|
||||
#
|
||||
set(TEXTEDIT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/ImGuiColorTextEdit)
|
||||
set(TEXTEDIT_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext/ImGuiColorTextEdit/TextEditor.cpp
|
||||
)
|
||||
message(STATUS "Including 'ImGuiColorTextEdit' from https://github.com/BalazsJako/ImGuiColorTextEdit -- ${TEXTEDIT_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# TINY XML 2
|
||||
#
|
||||
set(TINYXML2_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/tinyxml2)
|
||||
add_library(TINYXML2 "${CMAKE_CURRENT_SOURCE_DIR}/ext/tinyxml2/tinyxml2.cpp")
|
||||
message(STATUS "Compiling 'TinyXML2' from https://github.com/leethomason/tinyxml2.git -- ${TINYXML2_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# STB
|
||||
#
|
||||
set(STB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/stb)
|
||||
add_definitions(-DIMGUI_USE_STB_SPRINTF)
|
||||
message(STATUS "Including 'STB Nothings' from https://github.com/nothings/stb -- ${STB_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# DIRENT
|
||||
#
|
||||
if(WIN32)
|
||||
set(DIRENT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext)
|
||||
message(STATUS "Including 'Dirent' from https://github.com/tronkko/dirent -- ${DIRENT_INCLUDE_DIR}.")
|
||||
endif( WIN32 )
|
||||
|
||||
#
|
||||
# TINY FILE DIALOG
|
||||
#
|
||||
set(TINYFD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/tinyfiledialogs)
|
||||
add_library(TINYFD "${CMAKE_CURRENT_SOURCE_DIR}/ext/tinyfiledialogs/tinyfiledialogs.c")
|
||||
message(STATUS "Compiling 'TinyFileDialog' from https://github.com/native-toolkit/tinyfiledialogs.git -- ${TINYFD_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# BOXER - NATIVE MESSAGE DIALOG
|
||||
#
|
||||
#add_subdirectory(ext/Boxer)
|
||||
#set(BOXER_INCLUDE_DIR ${Boxer_SOURCE_DIR}/include)
|
||||
#set(BOXER_LIBRARY Boxer)
|
||||
#message(STATUS "Including 'Boxer' from https://github.com/aaronmjacobs/Boxer.git -- ${BOXER_INCLUDE_DIR}.")
|
||||
|
||||
#
|
||||
# NATIVE FILE DIALOG
|
||||
#
|
||||
# add_subdirectory(ext/nfd)
|
||||
# set(NFD_INCLUDE_DIR ${NFD_SOURCE_DIR}/include)
|
||||
# set(NFD_LIBRARY NFD)
|
||||
# message(STATUS "Including 'NativeFileDialog' from http://www.frogtoss.com/labs -- ${NFD_INCLUDE_DIR}.")
|
||||
|
||||
# find_package(PkgConfig REQUIRED)
|
||||
# pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
|
||||
|
||||
#
|
||||
# Application
|
||||
#
|
||||
|
||||
# Setup the environment
|
||||
include_directories(
|
||||
${GSTREAMER_INCLUDE_DIR}
|
||||
${GSTREAMER_AUDIO_INCLUDE_DIR}
|
||||
${GSTREAMER_VIDEO_INCLUDE_DIR}
|
||||
${GSTREAMER_BASE_INCLUDE_DIR}
|
||||
${GSTREAMER_APP_INCLUDE_DIR}
|
||||
${GSTREAMER_PBUTILS_INCLUDE_DIR}
|
||||
${GSTREAMER_GL_INCLUDE_DIR}
|
||||
${GLIB2_INCLUDE_DIR}
|
||||
${GLAD_INCLUDE_DIR}
|
||||
${GLM_INCLUDE_DIRS}
|
||||
${IMGUI_INCLUDE_DIR}
|
||||
${IMGUI_INCLUDE_DIR}/examples
|
||||
${TEXTEDIT_INCLUDE_DIR}
|
||||
${TINYXML2_INCLUDE_DIR}
|
||||
${TINYFD_INCLUDE_DIR}
|
||||
${STB_INCLUDE_DIR}
|
||||
${DIRENT_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
||||
set(VMIX_BINARY "vmix")
|
||||
set(VMIX_SRCS
|
||||
main.cpp
|
||||
ShaderManager.cpp
|
||||
RenderingManager.cpp
|
||||
SettingsManager.cpp
|
||||
ResourceManager.cpp
|
||||
UserInterfaceManager.cpp
|
||||
FileDialog.cpp
|
||||
ImGuiToolkit.cpp
|
||||
GstToolkit.cpp
|
||||
MediaPlayer.cpp
|
||||
Log.cpp
|
||||
)
|
||||
|
||||
set(VMIX_RSC_FILES
|
||||
./rsc/shaders/simple-shader.fs
|
||||
./rsc/shaders/simple-shader.vs
|
||||
./rsc/shaders/texture-shader.fs
|
||||
./rsc/shaders/texture-shader.vs
|
||||
./rsc/fonts/Hack-Regular.ttf
|
||||
./rsc/fonts/Roboto-Regular.ttf
|
||||
./rsc/fonts/Roboto-Bold.ttf
|
||||
./rsc/fonts/Roboto-Italic.ttf
|
||||
./rsc/fonts/fa-regular-400.ttf
|
||||
./rsc/fonts/fa-solid-900.ttf
|
||||
./rsc/images/glmixer_256x256.png
|
||||
./rsc/images/icons.dds
|
||||
./rsc/images/seed_512.jpg
|
||||
)
|
||||
|
||||
add_executable(${VMIX_BINARY}
|
||||
${VMIX_SRCS}
|
||||
${TEXTEDIT_SRCS}
|
||||
)
|
||||
|
||||
set_property(TARGET ${VMIX_BINARY} PROPERTY CXX_STANDARD 17)
|
||||
set_property(TARGET ${VMIX_BINARY} PROPERTY C_STANDARD 11)
|
||||
|
||||
target_compile_definitions(${VMIX_BINARY} PUBLIC "IMGUI_IMPL_OPENGL_LOADER_GLAD")
|
||||
|
||||
cmrc_add_resource_library(vmix-resources ALIAS vmix::rc NAMESPACE vmix WHENCE rsc ${VMIX_RSC_FILES})
|
||||
message(STATUS "Using 'CMakeRC ' from https://github.com/vector-of-bool/cmrc.git -- ${CMAKE_MODULE_PATH}.")
|
||||
|
||||
|
||||
target_link_libraries(${VMIX_BINARY} LINK_PRIVATE
|
||||
${GLFW_LIBRARY}
|
||||
${OPENGL_LIBRARY}
|
||||
${GLM_LIBRARY}
|
||||
GLAD
|
||||
${CMAKE_DL_LIBS}
|
||||
${GOBJECT_LIBRARIES}
|
||||
${GSTREAMER_LIBRARY}
|
||||
${GSTREAMER_BASE_LIBRARY}
|
||||
${GSTREAMER_APP_LIBRARY}
|
||||
${GSTREAMER_AUDIO_LIBRARY}
|
||||
${GSTREAMER_VIDEO_LIBRARY}
|
||||
${GSTREAMER_PBUTILS_LIBRARY}
|
||||
${GSTREAMER_GL_LIBRARY}
|
||||
${NFD_LIBRARY}
|
||||
${PNG_LIBRARY}
|
||||
${THREAD_LIBRARY}
|
||||
TINYXML2
|
||||
IMGUI
|
||||
TINYFD
|
||||
vmix::rc
|
||||
)
|
||||
|
||||
macro_display_feature_log()
|
||||
1033
FileDialog.cpp
Normal file
1033
FileDialog.cpp
Normal file
File diff suppressed because it is too large
Load Diff
110
FileDialog.h
Normal file
110
FileDialog.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef __IMGUI_FILE_DIALOG_H_
|
||||
#define __IMGUI_FILE_DIALOG_H_
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#define MAX_FILE_DIALOG_NAME_BUFFER 1024
|
||||
|
||||
struct FileInfoStruct
|
||||
{
|
||||
char type = ' ';
|
||||
std::string filePath;
|
||||
std::string fileName;
|
||||
std::string ext;
|
||||
};
|
||||
|
||||
class FileDialog
|
||||
{
|
||||
private:
|
||||
std::vector<FileInfoStruct> m_FileList;
|
||||
std::map<std::string, ImVec4> m_FilterColor;
|
||||
std::string m_SelectedFileName;
|
||||
std::string m_SelectedExt;
|
||||
std::string m_CurrentPath;
|
||||
std::vector<std::string> m_CurrentPath_Decomposition;
|
||||
std::string m_Name;
|
||||
bool m_ShowDialog;
|
||||
bool m_ShowDrives;
|
||||
|
||||
public:
|
||||
static char FileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER];
|
||||
static char DirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER];
|
||||
static char SearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER];
|
||||
static int FilterIndex;
|
||||
bool IsOk;
|
||||
bool m_AnyWindowsHovered;
|
||||
bool m_CreateDirectoryMode;
|
||||
|
||||
private:
|
||||
std::string dlg_key;
|
||||
std::string dlg_name;
|
||||
const char *dlg_filters;
|
||||
std::string dlg_path;
|
||||
std::string dlg_defaultFileName;
|
||||
std::string dlg_defaultExt;
|
||||
std::function<void(std::string, bool*)> dlg_optionsPane;
|
||||
size_t dlg_optionsPaneWidth;
|
||||
std::string searchTag;
|
||||
std::string dlg_userString;
|
||||
|
||||
public:
|
||||
static FileDialog* Instance()
|
||||
{
|
||||
static FileDialog *_instance = new FileDialog();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
FileDialog(); // Prevent construction
|
||||
FileDialog(const FileDialog&) {}; // Prevent construction by copying
|
||||
FileDialog& operator =(const FileDialog&) { return *this; }; // Prevent assignment
|
||||
~FileDialog(); // Prevent unwanted destruction
|
||||
|
||||
public:
|
||||
void OpenDialog(const std::string& vKey, const char* vName, const char* vFilters,
|
||||
const std::string& vPath, const std::string& vDefaultFileName,
|
||||
std::function<void(std::string, bool*)> vOptionsPane, size_t vOptionsPaneWidth = 250, const std::string& vUserString = "");
|
||||
void OpenDialog(const std::string& vKey, const char* vName, const char* vFilters,
|
||||
const std::string& vDefaultFileName,
|
||||
std::function<void(std::string, bool*)> vOptionsPane, size_t vOptionsPaneWidth = 250, const std::string& vUserString = "");
|
||||
void OpenDialog(const std::string& vKey, const char* vName, const char* vFilters,
|
||||
const std::string& vPath, const std::string& vDefaultFileName, const std::string& vUserString = "");
|
||||
void OpenDialog(const std::string& vKey, const char* vName, const char* vFilters,
|
||||
const std::string& vFilePathName, const std::string& vUserString = "");
|
||||
|
||||
void CloseDialog(const std::string& vKey);
|
||||
bool Render(const std::string& vKey, ImVec2 geometry);
|
||||
std::string GetFilepathName();
|
||||
std::string GetCurrentPath();
|
||||
std::string GetCurrentFileName();
|
||||
std::string GetCurrentFilter();
|
||||
std::string GetUserString();
|
||||
|
||||
void SetFilterColor(std::string vFilter, ImVec4 vColor);
|
||||
bool GetFilterColor(std::string vFilter, ImVec4 *vColor);
|
||||
void ClearFilterColor();
|
||||
|
||||
private:
|
||||
void SetPath(const std::string& vPath);
|
||||
void ScanDir(const std::string& vPath);
|
||||
void SetCurrentDir(const std::string& vPath);
|
||||
bool CreateDir(const std::string& vPath);
|
||||
void ComposeNewPath(std::vector<std::string>::iterator vIter);
|
||||
void GetDrives();
|
||||
};
|
||||
|
||||
|
||||
#endif // __IMGUI_FILE_DIALOG_H_
|
||||
27
GstToolkit.cpp
Normal file
27
GstToolkit.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "GstToolkit.h"
|
||||
|
||||
|
||||
string GstToolkit::to_string(guint64 t) {
|
||||
|
||||
if (t == GST_CLOCK_TIME_NONE)
|
||||
return "00:00:00.00";
|
||||
|
||||
guint ms = GST_TIME_AS_MSECONDS(t);
|
||||
guint s = ms / 1000;
|
||||
|
||||
std::ostringstream oss;
|
||||
if (s / 3600)
|
||||
oss << std::setw(2) << std::setfill('0') << s / 3600 << ':';
|
||||
if ((s % 3600) / 60)
|
||||
oss << std::setw(2) << std::setfill('0') << (s % 3600) / 60 << ':';
|
||||
oss << std::setw(2) << std::setfill('0') << (s % 3600) % 60 << '.';
|
||||
oss << std::setw(2) << std::setfill('0') << (ms % 1000) / 10;
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
15
GstToolkit.h
Normal file
15
GstToolkit.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __GSTGUI_TOOLKIT_H_
|
||||
#define __GSTGUI_TOOLKIT_H_
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace GstToolkit
|
||||
{
|
||||
|
||||
string to_string(guint64 t);
|
||||
|
||||
};
|
||||
|
||||
#endif // __GSTGUI_TOOLKIT_H_
|
||||
52
SettingsManager.h
Normal file
52
SettingsManager.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef vlmixer_app_settings
|
||||
#define vlmixer_app_settings
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
class WindowSettings
|
||||
{
|
||||
public:
|
||||
int x,y,w,h;
|
||||
string name;
|
||||
bool fullscreen;
|
||||
|
||||
WindowSettings() : x(0), y(0), w(100), h(100), name("Untitled"), fullscreen(false)
|
||||
{
|
||||
}
|
||||
|
||||
WindowSettings(int x, int y, int w, int h, const string& name)
|
||||
{
|
||||
this->x=x;
|
||||
this->y=y;
|
||||
this->w=w;
|
||||
this->h=h;
|
||||
this->name=name;
|
||||
this->fullscreen=false;
|
||||
}
|
||||
};
|
||||
|
||||
class AppSettings
|
||||
{
|
||||
public:
|
||||
string name;
|
||||
string filename;
|
||||
list<WindowSettings> windows;
|
||||
float scale;
|
||||
int color;
|
||||
|
||||
AppSettings(const string& name);
|
||||
};
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
static AppSettings application;
|
||||
|
||||
static void Save();
|
||||
static void Load();
|
||||
static void Check();
|
||||
};
|
||||
|
||||
#endif /* vlmixer_app_settings */
|
||||
123
ShaderManager.cpp
Normal file
123
ShaderManager.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#include "ShaderManager.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
Shader::Shader() {
|
||||
}
|
||||
|
||||
void Shader::load(const std::string& vertex_file, const std::string& fragment_file) {
|
||||
|
||||
init(Resource::getText(vertex_file), Resource::getText(fragment_file));
|
||||
}
|
||||
|
||||
void Shader::init(const std::string& vertex_code, const std::string& fragment_code) {
|
||||
vertex_code_ = vertex_code;
|
||||
fragment_code_ = fragment_code;
|
||||
compile();
|
||||
link();
|
||||
}
|
||||
|
||||
void Shader::compile() {
|
||||
const char* vcode = vertex_code_.c_str();
|
||||
vertex_id_ = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_id_, 1, &vcode, NULL);
|
||||
glCompileShader(vertex_id_);
|
||||
|
||||
const char* fcode = fragment_code_.c_str();
|
||||
fragment_id_ = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_id_, 1, &fcode, NULL);
|
||||
glCompileShader(fragment_id_);
|
||||
checkCompileErr();
|
||||
}
|
||||
|
||||
void Shader::link() {
|
||||
id_ = glCreateProgram();
|
||||
glAttachShader(id_, vertex_id_);
|
||||
glAttachShader(id_, fragment_id_);
|
||||
glLinkProgram(id_);
|
||||
checkLinkingErr();
|
||||
glDeleteShader(vertex_id_);
|
||||
glDeleteShader(fragment_id_);
|
||||
}
|
||||
|
||||
void Shader::use() {
|
||||
glUseProgram(id_);
|
||||
}
|
||||
|
||||
void Shader::enduse() {
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<int>(const std::string& name, int val) {
|
||||
glUniform1i(glGetUniformLocation(id_, name.c_str()), val);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<bool>(const std::string& name, bool val) {
|
||||
glUniform1i(glGetUniformLocation(id_, name.c_str()), val);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<float>(const std::string& name, float val) {
|
||||
glUniform1f(glGetUniformLocation(id_, name.c_str()), val);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<glm::mat4>(const std::string& name, glm::mat4 val) {
|
||||
glm::mat4 m(val);
|
||||
// std::cout << glm::to_string(m) << std::endl;
|
||||
glUniformMatrix4fv(glGetUniformLocation(id_, name.c_str()), 1, GL_FALSE, glm::value_ptr(m));
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<float>(const std::string& name, float val1, float val2) {
|
||||
glUniform2f(glGetUniformLocation(id_, name.c_str()), val1, val2);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Shader::setUniform<float>(const std::string& name, float val1, float val2, float val3) {
|
||||
glUniform3f(glGetUniformLocation(id_, name.c_str()), val1, val2, val3);
|
||||
}
|
||||
|
||||
// template<>
|
||||
// void Shader::setUniform<float*>(const std::string& name, float* val) {
|
||||
// glUniformMatrix4fv(glGetUniformLocation(id_, name.c_str()), 1, GL_FALSE, val);
|
||||
// }
|
||||
|
||||
void Shader::checkCompileErr() {
|
||||
int success;
|
||||
char infoLog[1024];
|
||||
glGetShaderiv(vertex_id_, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(vertex_id_, 1024, NULL, infoLog);
|
||||
std::cout << "Error compiling Vertex Shader:\n" << infoLog << std::endl;
|
||||
std::cout << vertex_code_ << std::endl;
|
||||
}
|
||||
glGetShaderiv(fragment_id_, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(fragment_id_, 1024, NULL, infoLog);
|
||||
std::cout << "Error compiling Fragment Shader:\n" << infoLog << std::endl;
|
||||
std::cout << fragment_code_ << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::checkLinkingErr() {
|
||||
int success;
|
||||
char infoLog[1024];
|
||||
glGetProgramiv(id_, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(id_, 1024, NULL, infoLog);
|
||||
std::cout << "Error Linking Shader Program:\n" << infoLog << std::endl;
|
||||
}
|
||||
}
|
||||
31
ShaderManager.h
Normal file
31
ShaderManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef vlmixer_shader
|
||||
#define vlmixer_shader
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
Shader();
|
||||
void load(const std::string& vertex_rsc, const std::string& fragment_rsc);
|
||||
void init(const std::string& vertex_code, const std::string& fragment_code);
|
||||
void use();
|
||||
template<typename T> void setUniform(const std::string& name, T val);
|
||||
template<typename T> void setUniform(const std::string& name, T val1, T val2);
|
||||
template<typename T> void setUniform(const std::string& name, T val1, T val2, T val3);
|
||||
|
||||
static void enduse();
|
||||
|
||||
private:
|
||||
void checkCompileErr();
|
||||
void checkLinkingErr();
|
||||
void compile();
|
||||
void link();
|
||||
unsigned int vertex_id_, fragment_id_, id_;
|
||||
std::string vertex_code_;
|
||||
std::string fragment_code_;
|
||||
|
||||
};
|
||||
|
||||
#endif /* vlmixer_shader */
|
||||
59
defines.h
Normal file
59
defines.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef VMIX_DEFINES_H
|
||||
#define VMIX_DEFINES_H
|
||||
|
||||
#define APP_NAME "vmix"
|
||||
#define APP_TITLE "v-mix -- Video Live Mixer"
|
||||
#define APP_VERSION "0.0.1"
|
||||
|
||||
#define MINI(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAXI(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define ABS(a) (((a) < 0) ? -(a) : (a))
|
||||
#define SIGN(a) (((a) < 0) ? -1.0 : 1.0)
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||
#define EPSILON 0.00001
|
||||
#define LOG100(val) (50.0/log(10.0)*log((float)val + 1.0))
|
||||
#define EXP100(val) (exp(log(10.0)/50.0*(float)(val))-1.0)
|
||||
#define EUCLIDEAN(P1, P2) sqrt((P1.x() - P2.x()) * (P1.x() - P2.x()) + (P1.y() - P2.y()) * (P1.y() - P2.y()))
|
||||
|
||||
#define SOURCE_UNIT 10.0
|
||||
#define CIRCLE_SQUARE_DIST(x,y) ( (x*x + y*y) / (SOURCE_UNIT * SOURCE_UNIT * CIRCLE_SIZE * CIRCLE_SIZE) )
|
||||
|
||||
#define TEXTURE_REQUIRED_MAXIMUM 2048
|
||||
#define CATALOG_TEXTURE_HEIGHT 96
|
||||
#define SELECTBUFSIZE 512
|
||||
#define CIRCLE_SIZE 8.0
|
||||
#define DEFAULT_LIMBO_SIZE 1.5
|
||||
#define MIN_LIMBO_SIZE 1.1
|
||||
#define MAX_LIMBO_SIZE 3.0
|
||||
#define DEFAULT_ICON_SIZE 1.75
|
||||
#define MIN_ICON_SIZE 1.0
|
||||
#define MAX_ICON_SIZE 2.5
|
||||
#define MIN_DEPTH_LAYER 0.0
|
||||
#define MAX_DEPTH_LAYER 40.0
|
||||
#define MIN_SCALE 0.1
|
||||
#define MAX_SCALE 200.0
|
||||
#define DEPTH_EPSILON 0.1
|
||||
#define DEPTH_DEFAULT_SPACING 1.0
|
||||
#define BORDER_SIZE 0.4
|
||||
#define CENTER_SIZE 1.2
|
||||
#define PROPERTY_DECIMALS 8
|
||||
#define COLOR_SOURCE 230, 230, 0
|
||||
#define COLOR_SOURCE_STATIC 230, 40, 40
|
||||
#define COLOR_SELECTION 10, 210, 40
|
||||
#define COLOR_SELECTION_AREA 50, 210, 50
|
||||
#define COLOR_BGROUND 52, 52, 52
|
||||
#define COLOR_CIRCLE 210, 30, 210
|
||||
#define COLOR_CIRCLE_MOVE 230, 30, 230
|
||||
#define COLOR_DRAWINGS 180, 180, 180
|
||||
#define COLOR_LIMBO 35, 35, 35
|
||||
#define COLOR_LIMBO_CIRCLE 210, 160, 210
|
||||
#define COLOR_FADING 25, 25, 25
|
||||
#define COLOR_FLASHING 250, 250, 250
|
||||
#define COLOR_FRAME 210, 30, 210
|
||||
#define COLOR_FRAME_MOVE 230, 30, 230
|
||||
#define COLOR_CURSOR 10, 100, 255
|
||||
|
||||
#define XML_PREFERENCE_FILE "vlmixer.xml"
|
||||
|
||||
#endif // VMIX_DEFINES_H
|
||||
Reference in New Issue
Block a user